akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <tuple>
#include <cstring>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
#define eb emplace_back

int w,h;
char g[55][55];
int flg[55][55];

void draw(int i, int j, int c){
    rep(d,4){
        int di[] = {0,1,0,-1};
        int dj[] = {1,0,-1,0};
        int ni = i+di[d];
        int nj = j+dj[d];
        if(ni >= h || ni < 0 || nj >= w || nj < 0) continue;
        if(g[ni][nj]!='.' || flg[ni][nj]&c) continue;
        flg[ni][nj] |= c;
        draw(ni,nj,c);
    }
}

int main(){
    while(cin >> w >> h && w){
        rep(i,h) cin >> g[i];
        memset(flg,0,sizeof(flg));
        rep(i,h)rep(j,w)if(g[i][j]!='.') draw(i,j,g[i][j]=='W' ? 1 : 2);
        int cb = 0, cw = 0;
        rep(i,h)rep(j,w){
            if(flg[i][j]==1) cw++;
            if(flg[i][j]==2) cb++;
        }
        cout << cb << " " << cw << endl;
    }
}

Measured memory_bytes: 1276
n,x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
while True:
    if count > n-1:
        if x == a[n-1]:
            print(count)
            exit()
        else:
            print(count-1)
            exit()
    if a[count] < x:
        x-=a[count]
        count += 1
    elif a[count] == x:
        print(count+1)
        exit()
    else:
        print(count)
        exit()

Measured memory_bytes: 3064
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>

#define MAXCHAR 255
#define ll long long

using namespace std;
const ll dividend = 1000000007;
const ll limit = pow(10, 18);
const ll bigNum = pow(10, 9);

ll funcComb(int n, int k) 
{
	ll output = 1;
	int sum = n + k;
	vector<int> dividends;
	for (int i = 0; i < k; i++)
	{
		dividends.push_back(k - i);
	}
	for (int i = 0; i < k; i++)
	{
		output *= sum - i;
		for (auto it = dividends.begin(); it != dividends.end(); it++)
		{
			if (*it == 0)
				continue;
			if (output % *it == 0)
			{
				output /= *it;
				*it = 0;
			}
		}
		if (output > dividend)
		{
			output %= dividend;
		}
	}

	return output;
}

vector<bool> outputs;

int main()
{
	for (int i = 0; i < 5; i++)
	{
		int a;
		cin >> a;
		if (a == 0)
			cout << i + 1 << endl;
	}


	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)


int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	ll t = c - a - b;
	if (t <= 0) {
		cout << "No" << endl;
		return 0;
	}

	if (4 * a * b < t * t) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
	return 0;

}

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;


int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    vector<int> cnt(26,-1);
    for(int i=0;i<n;i++){
        int x = s[i] -'a';
        if(cnt[x]==-1){
            cnt[x] = t[i] - 'a';
        }else{
            if(cnt[x] != t[i]-'a'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cnt = vector<int>(26,-1);
    for(int i=0;i<n;i++){
        int x = t[i] -'a';
        if(cnt[x]==-1){
            cnt[x] = s[i] - 'a';
        }else{
            if(cnt[x] != s[i]-'a'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 916
#include <iostream>
#include <string>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  string a[h];
  for(int i=0;i<h;i++){
    cin>>a[i];
    a[i]='#'+a[i]+'#';
  }
  for(int i=0;i<w+2;i++)cout<<'#';
  cout<<endl;
  for(int i=0;i<h;i++)cout<<a[i]<<endl;
  for(int i=0;i<w+2;i++)cout<<'#';
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int a,b,c,d;

int gcd(int x , int y){
	return y > 0 ? gcd(y,x%y) : x;
}

int main(){
	scanf("%d%d%d%d" , &a , &b , &c , &d);
	a = abs(a-c);
	b = abs(b-d);
	if(a == 0 || b == 0){
		printf("0\n");
		return 0;
	}
	int g = gcd(a,b);
	a /= g;
	b /= g;
	printf("%lld\n" , (long long)(a + b - 1) * g);
	return 0;
}


Measured memory_bytes: 128
<?php
//error_reporting(0);
//$H = trim(fgets(STDIN));
list($S,$T) = explode(" ",trim(fgets(STDIN)));
list($A,$B) = explode(" ",trim(fgets(STDIN)));
$U = trim(fgets(STDIN));
//$P = explode(" ",trim(fgets(STDIN)));
//$H = array_map('intval',explode(" ",trim(fgets(STDIN))));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}

if ($U==$S) {
  $A-=1;
}
if ($U==$T) {
  $B-=1;
}
printf("%d %d\n",$A,$B);


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

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

    int ans = 0;
    for (int i = N; i > 0; i--) {
        ans += (to_string(i).size() % 2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
A =  int(input())
B =  int(input())
C =  int(input())
X =  int(input())
ans = 0
 
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            tmp = 500*i + 100*j + 50*k
            if tmp == X:
                ans += 1
                
                
print(ans)

Measured memory_bytes: 40464
#include<iostream>
#include<algorithm>
using namespace std;
int num[500];
int main()
{
   int n,s;
   cin>>n>>s;
   for(int i=1;i<=n;i++)
   cin>>num[i];
   sort(num+1,num+n+1);
   int sum=0;
   for(int i=n;i>=n-s+1;i--)
   {
   	  sum+=num[i];
   }
   cout<<sum<<endl;
   return 0;
}

Measured memory_bytes: 256
// {{{ by WangYenJen
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll;
typedef pair<int,int> pii;
// macro
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin() , (x).end()
#define REP(i , n) for(int i = 0; i < int(n); i++)
#define REP1(i , a , b) for(int i = a; i <= int(b); i++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LC o<<1 , l , m
#define RC o<<1|1 , m + 1 , r
#define MS(x , v) memset(x , (v) , sizeof(x))
// input
inline bool SR(int &x) {
	return scanf("%d",&x) == 1;
}
inline bool SR(ll &x) {
	return scanf("%lld",&x) == 1;
}
inline bool SR(double &x) {
	return scanf("%lf",&x) == 1;
}
inline bool SR(char *s) {
	return scanf("%s",s) == 1;
}
inline bool RI() {
	return true;
}
template<typename I , typename... T> inline bool RI(I &x , T&... tail) {
	return SR(x) && RI(tail...);
}
// output
inline void SP(const int x) {
	printf("%d",x);
}
inline void SP(const ll x) {
	printf("%lld",x);
}
inline void SP(const double x) {
	printf("%.16lf",x);
}
inline void SP(const char *s) {
	printf("%s",s);
}
inline void PL() {
	puts("");
}
template<typename I , typename... T> inline void PL(const I x , const T... tail) {
	SP(x);
	if(sizeof...(tail)) putchar(' ');
	PL(tail...);
}
// debug
#define WangYenJen
#ifdef WangYenJen
template<typename I> void _DOING(const char *s , I&& x) {
    cerr << s << " = " << x << endl;
}
template<typename I , typename... T> void _DOING(const char *s , I&& x , T&&... tail) {
    int c = 0;
    while(*s != ',' || c != 0) {
        if(*s == '(' || *s == '[' || *s == '{') c++;
        if(*s == ')' || *s == ']' || *s == '}') c--;
        cerr << *s++;
    }
    cerr << " = " << x << " , ";
    _DOING(s + 1 , tail...);
}
#define debug(...) \
do {\
    fprintf(stderr , "%s:%d - ",__PRETTY_FUNCTION__,__LINE__);\
    _DOING(#__VA_ARGS__ , __VA_ARGS__);\
} while(0);
#else
#define debug(...)
#endif
// random function
inline int RAND() {
	static int x = 880301;
	return (x = x * 0xdefaced + 1) & 0x7fffffff;
}
// }}}

int main() {
    ll a , b , c;
    ll ans;
    RI(a , b , c);
    if(c&1) ans = a * b;
    else ans = 0;
    if(a&1) ans = min(ans , b * c);
    else ans = 0;
    if(b&1) ans = min(ans , a * c);
    else ans = 0;
    PL(ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (x + r > W || x - r < 0) {
        cout << "No" << endl;
    } else if (y + r > H || y - r < 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int MAX_N = 3010;
int MAX_T = 3010;

mat dp(MAX_N, vec(MAX_T, 0));

int main(){
    int n, t;
    cin >> n >> t;
    P a[n];
    rep(i, n) cin >> a[i].first >> a[i].second;
    sort(a, a + n);
    rep(i, n){
        rep(j, t){
            if(j >= a[i].first){
                dp[i+1][j] = max(dp[i][j-a[i].first]+a[i].second, dp[i][j]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    int ans = 0;
    rep(i, n){
        ans = max(dp[i][t-1] + a[i].second, ans);
    }
    // rep(i, n+1){
    //     rep(j, t){
    //         cout << dp[i][j] << " ";
    //     }cout << endl;
    // }
    cout << ans << endl;
}

Measured memory_bytes: 38872
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f

using namespace std;

const int N = 1000, M = 1000;

int n, m, k;
char s[N][M];
int a[N][M];
int bel[N], sum[N];

int main() {
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < n; i++) scanf("%s", s[i]);
    for (int i = 0; i < n; i++) 
        for (int j = 0; j < m; j++) 
            a[i][j] = s[i][j] - '0';
    int ans = n + m;
    for (int mask = 0; mask < (1 << (n - 1)); mask++) {
        int tot = 0, res = 0;
        for (int i = 0; i < n; i++) {
            bel[i] = tot;
            if (mask >> i & 1)
                ++tot;
        }
        memset(sum, 0, sizeof sum);
        for (int i = 0; i < m; i++) {
            int flg = 0;
            for (int j = 0; j < n; j++) {
                sum[bel[j]] += a[j][i];
                if (sum[bel[j]] > k) 
                    flg = 1;
            }
            if (flg) {
                memset(sum, 0, sizeof sum);
                res++;
                for (int j = 0; j < n; j++) {
                    sum[bel[j]] += a[j][i];
                    if (sum[bel[j]] > k) res = n + m;
                }
            }
            if (res == n + m) break;
        }
        ans = min(ans, res + tot);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2304
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:(input())

"""========main code==============="""

t=ii()
s=set()
for _ in range(t):
    n=ip()
    s.add(n)
print(len(s))    

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  double res = 0;
  vector<double> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    res += 1 / A[i];
  }
  cout << fixed << setprecision(6) << 1 / res << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a%2==0 || b%2==0){
            System.out.println("Even");
        }
        else{
            System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 22868
#include<cstdio>
#include<cstring>
typedef long long ll;
const int MAXN = 5000;
const int MOD = int(1E9) + 7;
char s[MAXN + 5];
ll dp[MAXN + 5][MAXN + 5];
int main() {
	int N;
	scanf("%d", &N);
	scanf("%s", s+1);
	int len = strlen(s+1);
	dp[0][0] = 1;
	for(int i=1;i<=N;i++) {
		dp[i][0] = (dp[i-1][0] + 2LL * dp[i-1][1]) % MOD;
		for(int j=1;j<=i;j++)
			dp[i][j] = (2LL * dp[i-1][j+1] + dp[i-1][j-1]) % MOD;
	}
	printf("%lld\n", dp[N][len]);
}

Measured memory_bytes: 193920
# coding: utf-8


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = list(map(int, args[1].split()))

    ret = ['Yes' if A[i-k] < A[i] else 'No' for i in range(k, n)]
    return '\n'.join(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 33576
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int n, a[200000], m = 0;
	vector<int> q;
	cin >> n;
	rep(i, n) cin >> a[i];
	for(int i = n; i != 0; i--) {
		if(a[i - 1] != 0) {
			for(int j = 1; j * j <= i; j++) {
				if(i % j == 0) {
					a[j - 1] ^= 1;
					if(j * j != i) a[i / j - 1] ^= 1;
				}
			}
			m++;
			q.push_back(i);
		}
	}
	cout << m << endl;
	rep(i, q.size()) cout << q[i] << (i + 1 == i_len ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 2424
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=4e5;
int n;
int c[maxn][4];
ll val[maxn],ans;
void rot(int *c){
	per(i,3,1)swap(c[i],c[(i+1)%4]);
}
ll getv(int *c){
	ll res=0;
	rep(i,0,3)res=1000*res+c[i];
	return res;
}
ll get(int *c){
	ll res=getv(c);
	rot(c);res=min(res,getv(c));
	rot(c);res=min(res,getv(c));
	rot(c);res=min(res,getv(c));
	return res;
}
int main(){
	read(n);
	rep(i,1,n)rep(j,0,3)read(c[i][j]);
	rep(i,1,n)val[i]=get(c[i]);
	rep(i,1,n)rep(j,i+1,n){
		rep(k,0,3){
			ll res=1;
			rot(c[j]);
			ll v[4];
			rep(l,0,3){
				int now[4];
				now[0]=c[j][(5-l)%4];
				now[1]=c[j][(4-l)%4];
				now[2]=c[i][(l+1)%4];
				now[3]=c[i][l];
				v[l]=get(now);
				int t=0,cnt=0;
				t+=(getv(now)==v[l]);
				rot(now);t+=(getv(now)==v[l]);
				rot(now);t+=(getv(now)==v[l]);
				rot(now);t+=(getv(now)==v[l]);
				rep(p,i+1,n)if(p!=j&&val[p]==v[l])cnt++;
				rep(ll,0,l-1)if(v[ll]==v[l])cnt--;
				if(cnt<=0){
					res=0;
					break;
				}
				res*=t*cnt;
			}
			ans+=res;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>

int main(void)
{
	char S[2] ;
	int a,prc;
	prc=0;
	scanf("%s",S);
	for(a=0;a<3;a++){
		if(S[a]=='o'){
			prc=prc+100;
	}
	}
	prc=prc+700;

printf("%d",prc);	

	
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const double PI = 3.14159265358979323846;
const int MAX = 1e10;
const int MOD = 1e9+7;

const int MAX_N = 100005;


int main(int argc, char *args[]) {
	int n; cin >> n;
	vector<ll> x(n);
	vector<ll> l(n);
	vector<pair<ll, ll> > range(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> l[i];
		range[i].first = x[i] + l[i];
		range[i].second = x[i] - l[i];
	}
	sort(range.begin(), range.end());
	ll ans = 0, t = -MAX;
	for (int i = 0; i < n; i++) {
		if (t <= range[i].second) {
			ans++;
			t = range[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(void) {
  string a, b, c;
  cin >> a >> b >> c;
  
  transform(b.begin(), b.end(), b.begin(), ::toupper);
  cout << "A" << b.at(0) << "C" << endl;
}
  

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		Deque<Character> q = new ArrayDeque<>();
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) != 'B') {
				q.offerLast(s.charAt(i));
			} else {
				if (q.isEmpty()) {

				} else {
					q.pollLast();
				}
			}
		}
		while (!q.isEmpty()) {
			System.out.print(q.pollFirst());
		}
		System.out.println();

	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010],b[100010],ans=0;
    cin>>n;
    rep(i,n+1) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n){
        if(a[i]<=b[i]){
            ans+=a[i];
            b[i]-=a[i];
        } else{
            ans+=b[i];
            b[i]=0;
        }
        if(a[i+1]<=b[i]){
            ans+=a[i+1];
            a[i+1]=0;
        } else{
            ans+=b[i];
            a[i+1]-=b[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
S = input()

S = S[::-1]
result = 0
t = [0] * 2019
m = 1
n = 0
for i in range(len(S)):
    t[n] += 1
    n += int(S[i]) * m
    n %= 2019
    result += t[n]
    m *= 10
    m %= 2019
print(result)


Measured memory_bytes: 9284
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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

int n;
char s[101]={};

cin >> n;
rep(i,n) cin >> s[i];

rep(i,n){
    if (s[i] == 'Y')
    {
        cout << "Four" << endl;
        return 0;
    }
    
}
cout << "Three" << endl;



//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M1 					1000000007
#define M2 					998244353
#define ll 					long long int
#define pll 				pair<ll,ll>
#define mll 				map<ll,ll>
#define F 					first
#define S 					second
#define PB 					push_back
#define mp 					make_pair
#define lb 					lower_bound
#define ub 					upper_bound
#define V(a) 				vector<a>
#define endl 				'\n'
#define test(t) 			while(t--)
#define PI 					acos(-1.0)
#define rep(i,a,b) 			for(ll i=a;i<b;i++)
#define repp(i,b,a) 		for(ll i=b-1;i>=a;i--)
#define clr(ar, val)		memset(ar, val, sizeof(ar))
#define setbits(x) 			__builtin_popcountll(x)
#define zrobits(x) 			__builtin_ctzll(x)
#define ps(y) 				fixed << setprecision(y)
#define all(x) 				begin(x),end(x)
#define allr(x) 			rbegin(x),rend(x)
const int inf= 				0x3f3f3f3f;
const ll INF= 				0x3f3f3f3f3f3f3f3f;
const int dx[4]= 			{ 0, -1, 0, 1 };
const int dy[4]= 			{ -1, 0, 1, 0 };

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll CalculateMex(set<ll> Set){
    ll Mex = 0;
    while(Set.find(Mex)!=Set.end()){
        Mex++;
    }
    return Mex;
}

ll floor_div(ll a, ll b) {
	return a / b - (((a ^ b) < 0) and a % b);
}
ll ceil_div(ll a, ll b){
    return a / b + (((a ^ b) >= 0) and a % b);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

string  s;
ll k;
ll dp[120][5][2];

ll dp_it(ll pos, ll ct, bool tight){
    if (pos == s.size()){
        if(ct == k) return 1;
        else return 0;
    }

    if (dp[pos][ct][tight] != -1) return dp[pos][ct][tight];

    ll ub = (tight?s[pos] - '0':9);

    ll ans = 0;
    if  (ct < k){
        rep(i,0,ub+1){
            ans += dp_it(pos+1,ct + (i!=0),tight&((s[pos]-'0')==i));
        }
    }
    else ans+= dp_it(pos+1,ct,tight&((s[pos]-'0')==0));

    return dp[pos][ct][tight] = ans;

}
void solve()
{
    cin >> s;
    cin >> k;
    clr(dp,-1);
    cout << dp_it(0,0,1) << endl;

}

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    test(t){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> LLLL;

int main(int argc, char *argv[])
{
	LL n, k;
	cin >> n >> k;
	vector<LLLL> v;
	for (LL i = 0; i < n; ++i) {
		LL x, y;
		cin >> x >> y;
		v.push_back(LLLL(x, y));
	}
	sort(v.begin(), v.end());
	LL ans = 1LL << 62;
	for (LL i = 0; i < n; ++i) {
		vector<LL> w;
		LL left = 1LL << 62, right = -(1LL << 62);
		for (LL j = i; j < n; ++j) {
			left = min(left, v[j].first);
			right = max(right, v[j].first);
			w.push_back(v[j].second);
			if (right > left && w.size() >= k) {
				sort(w.begin(), w.end());
				for (LL l = 0; l <= w.size() - k; ++l) {
					for (LL m = l + k - 1; m < w.size(); ++m) {
						LL d = w[m] - w[l];
						if (d > 0) {
							ans = min(ans, (right - left) * d);
							break;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

s, e = set(), set()
for ab in AB:
    a, b = ab
    if a == 1:
        s.add(b)
    elif b == N:
        e.add(a)
if len(s & e) >= 1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 86396
#include <stdio.h>

long long int dp[60][60][2510] = {{{1}}};	// i個からj個選んで和をsにする選び方の総数

// O(N^3X)の解法
int main(void)
{
	int i, j, A, N, s, x;
	long long int ans = 0;

	scanf("%d%d", &N, &A);
	dp[0][0][0] = 1;
	for (i = 1; i <= N; i++) {
		scanf("%d", &x);
		for (j = 0; j <= N; j++) {
			for (s = 0; s <= 2500; s++) {
				if (s < x) {
					dp[i][j][s] = dp[i - 1][j][s];
				} else if (j >= 1 && s >= x) {
					dp[i][j][s] = dp[i - 1][j - 1][s - x]	// xを選択した場合
								+ dp[i - 1][j][s];			// xを選択しなかった場合
				} 
			}
		}
	}

	for (i = 1; i <= N; i++) {
		ans += dp[N][i][i * A];
	}

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

	return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int INF = 1000000007;
const ll MOD = 1000000007;

const int N = 1000005;

vector<pii> dir;
int dist[N], comp[1005][1005], num;
bool seen[1005][1005];
int h, w;
int ch, cw, dh, dw;
vector<int> graph[N];
string grid[1005];
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for(int i=-2; i<=2; i++)
    {
        for(int j=-2; j<=2; j++)
        {
            if(abs(i) <= 1 && abs(j) <= 1 && (i == 0 || j == 0))
                continue;
            dir.PB({i, j});
        }
    }

    cin >> h >> w;
    cin >> ch >> cw >> dh >> dw;
    ch--;
    cw--;
    dh--;
    dw--;
    for(int i=0; i<h; i++)
    {
        cin >> grid[i];
    }

    for(int i=0; i<N; i++)
    {
        dist[i] = INF;
    }

    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            if(seen[i][j] || grid[i][j] == '#')
                continue;
            queue<pii> q;
            q.push({i, j});
            seen[i][j] = true;
            while(!q.empty())
            {
                int r = q.front().f, c = q.front().s;
                comp[r][c] = num;
                q.pop();
                for(int i=0; i<4; i++)
                {
                    int newr = r + dr[i], newc = c + dc[i];
                    if(newr < 0 || newc < 0 || newr >= h || newc >= w)
                        continue;
                    if(grid[newr][newc] == '#')
                        continue;
                    if(!seen[newr][newc])
                    {
                        seen[newr][newc] = true;
                        q.push({newr, newc});
                    }
                }
            }
            num++;
        }
    }

    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            if(grid[i][j] == '#')
                continue;
            for(pii p : dir)
            {
                int newi = p.f + i, newj = p.s + j;
                if(newi < 0 || newj < 0 || newi >= h || newj >= w)
                    continue;
                if(grid[newi][newj] == '#')
                    continue;
                if(comp[newi][newj] == comp[i][j])
                    continue;
                graph[comp[i][j]].PB(comp[newi][newj]);
                graph[comp[newi][newj]].PB(comp[i][j]);
            }
        }
    }
    queue<int> q;
    dist[comp[ch][cw]] = 0;
    q.push(comp[ch][cw]);
    while(!q.empty())
    {
        int x = q.front();
        q.pop();
        for(int y : graph[x])
        {
            if(dist[y] > dist[x]+1)
            {
                dist[y] = dist[x]+1;
                q.push(y);
            }

        }
    }

    if(dist[comp[dh][dw]] == INF)
    {
        cout << -1;
    }
    else
    {
        cout << dist[comp[dh][dw]];
    }
    return 0;
}


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

int main() {
	int size;
	scanf("%d", &size);
	int ord[100];
	int num[100];
	int i;
	for (i = 0; i < 100; i++)ord[i] = i+1;
	for (i = 0; i < size; i++) {
		scanf("%d", &num[i]);
	}
	int s=0;
	for (i = 0; i < size; i++) {
		if (ord[i] != num[i])s++;
	}
	if (s == 0 || s == 2)printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>

using namespace std;

int num;

string toc(int num){
  string out;
  while(num > 0){
    out += num%10 + '0';
    num /= 10;
  }
  while(out.length() < 8) out += '0';
  reverse(out.begin(),out.end());
  return out;
}

int toi(string in){
  int out = 0;
  int plus = 1;
  for(int i = in.length()-1; i >= 0; i--){
    out += (in[i] - '0') * plus;
    plus *= 10;
  }
  return out;
}
void solve(){
  for(int i = 0; i < 10; i++){
    string sub;
    num = num*num;
    string str = toc(num);
    int flg = 0;
    for(int j = 2; j < 6; j++){
      sub += str[j];
      if(str[j] != '0') flg = 1;
      if(flg) cout << str[j];
      if(!flg && j == 5) cout << str[j];
    }
    cout << endl;
    num = toi(sub);
  }
}

int main(){
  int in;
  cin >> in;
  int rev = 0;
  for(int i = 0; i < in; i++){
    rev++;
    cin >> num;
    cout << "Case " << rev <<":" <<endl;
    solve();
  }
  return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && a==c) cout << 1 << endl;
  else if(a != b && a != c && b != c) cout << 3 << endl;
  else cout << 2 << endl;
}

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

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


Measured memory_bytes: 256
n,m,x,y = map(int,input().split())

maxx = max(list(map(int,input().split())))
miny = min(list(map(int,input().split())))

if x < y :
    candidate = []
    for i in range(x+1,y+1) :
        candidate.append(i)

    for i in candidate :
        if maxx < i and i <= miny :
            print("No War")
            exit(0)

print("War")


Measured memory_bytes: 3060
import heapq

N,M = map(int,input().split())
b = list(map(int,input().split()))
a = []

for i in range(N):
	a.append((b[i],1))

for i in range(M):
	bb,cc = map(int,input().split())
	a.append((cc,bb))

a.sort()
a.reverse()

#for j in a:
#	print(j)

cnt = 0
ans = 0

for i in range(N):
	if cnt + a[i][1] > N:
		ans += a[i][0]*(N-cnt)
		break

	ans += a[i][0]*a[i][1]
	cnt += a[i][1]

print(ans)

Measured memory_bytes: 36028
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#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){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

bitset<7> num[10] = { 126, 48, 109, 121, 51, 91, 95, 114, 127, 123};

int main()
{
	int n;
	while(cin >> n && n + 1)
	{
		bitset<7> prv;

		rep(i, n)
		{
			int in;
			cin >> in;

			bitset<7> buf = (num[in] ^ prv);
			
			rep(i, 7)
				cout << buf[i] << (i == 6 ? "\n" : "");

			prv = num[in];
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  string y[7]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
  int num[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
 
  while(1){
    int m,d;
    cin >> m >> d;
    if( m == 0 && d == 0 ) break;
    while( m != 0 ){
      d += num[m-1];
      m--;
    }
    cout << y[d%7] << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1192
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let s: Vec<char> = util::line().chars().collect();

    let ans = s.iter()
        .collect::<HashSet<_>>()
        .into_iter()
        .map(|&c| {
            let is: Vec<_> = s.iter()
                .enumerate()
                .filter(|&(_, &x)| x == c)
                .map(|(i, _)| i)
                .collect();

            [s.len() - is.iter().cloned().max().unwrap() - 1,
             is.windows(2).map(|x| x[1] - x[0] - 1).max().unwrap_or(0),
             is[0]]
                    .into_iter()
                    .cloned()
                    .max()
                    .unwrap()
        })
        .min()
        .unwrap();

    println!("{}", ans);
}


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

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  
  int tmp = 0;
  int tmp_index = K;
  for(int i=min(A,B);i>=1;i--){
    if(A%i == 0 && B%i == 0){
      tmp = i;
      tmp_index--;
    }
    if(tmp_index == 0){
      break;
    }
  }
  cout << tmp <<endl;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    int result = 1000000000;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < 100; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum = sum + (x[j] - i) * (x[j] - i);
        }
        result = min(result, sum);
    }
    cout << result << endl;
}

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

int n, sum = 0, ans = 100000000, now = 0;
vector<int> w;

int main() {
  cin >> n;
  w.resize(n);
  for(int i = 0; i < n; ++i) cin >> w[i];
  for(int i = 0; i < n; ++i) sum += w[i];
  for(int i = 0; i < n; ++i) {
    now += w[i];
    ans = min(ans, abs(now - (sum - now)));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce, partial
import sys


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

def lcm(a, b):
	return a * b // gcd(a, b)

def func(a, b, l):
	mod = 10**9 + 7
	return (a +  l*modinv(b, mod)) % mod

def modinv(a, b):
	return pow(a,b-2,b)

def main():
	mod = 10**9 + 7
	N = int(input())
	A = tuple(map(int, input().split()))

	l = reduce(lcm, A) % mod
	A = (0,) + A
	
	ans = reduce(partial(func, l=l), A)
	print(ans)
	

if __name__ == "__main__":
	main()


Measured memory_bytes: 68440
#include <stdio.h>

int main(){
	int i;
	double j,k,c;

	scanf("%lf",&k);

	for(i=1; i<=k; i++){
		if(i%2!=0){
			j++;
		}
	}
	
	c=j/k;
	printf("%f",c);
	return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
//
//#define MAXN 500010
//#define ll long long
//#define mod 1000000007
//
//using namespace std;
//
//int n, m, k;
//ll ans, tot;
//
//string s;
//
//struct node {
//	int v, t;
//}a[MAXN];
//
//bool cmp(node x, node y) {
//	if (x.v > y.v) {
//		return 1;
//	}
//	else if (x.t < y.t) {
//		return 1;
//	}
//	else return 0;
//}
//	int t[MAXN];
//	int h[MAXN];
//	int q[MAXN] = {0};
//
//int main(){
//	scanf("%d%d%d%d%d", &n, &m, &t[1], &t[2], &t[3]);
//	h[1] = n;
//	h[2] = m;
//	for (int i = 1; i <= t[1]; i++) {
//		int num;
//		scanf("%d", &num);
//		a[++tot].v = num; a[tot].t = 1;
//	}
//	for (int i = 1; i <= t[2]; i++) {
//		int num;
//		scanf("%d", &num);
//		a[++tot].v = num; a[tot].t = 2;
//	}
//	for (int i = 1; i <= t[3]; i++) {
//		int num;
//		scanf("%d", &num);
//		a[++tot].v = num; a[tot].t = 3;
//	}
//	
//	sort(a + 1, a + tot + 1, cmp);
////	for (int i = 1; i <= tot; i++) {
////		cout << a[i].v << " " << a[i].t << endl;
////	}
//	for (int i = 1; i <= tot; i++) {
//		if (q[a[i].t] < h[a[i].t] && a[i].t != 3) {
//			q[a[i].t]++;
//			ans = (ll)(ans + a[i].v);
//		}
//		if (a[i].t == 3) {
//			if (q[1] < h[1]) {
//				q[1]++;
//				ans = (ll)(ans + a[i].v);	
//			}
//			else if (q[2] < h[2]) {
//				q[2]++;
//				ans = (ll)(ans + a[i].v);
//			}
//		}
//	}
//	cout << ans << endl;
//	return 0;
//}

#include <bits/stdc++.h>

#define rr register
#define int long long
#define MAXN 1000010

using namespace std;

int X,Y,A,B,C;

int a[MAXN],b[MAXN],c[MAXN];
int d[MAXN],cnt;

bool cmp(int x, int y){
	return x > y;
}

signed main(void){
	cin >> X >> Y >> A >> B >> C;
	for (int i = 1; i <= A; ++i) {
		cin >> a[i];
	}
	for(int i = 1; i <= B; ++i) {
		cin >> b[i];
	}
	for (int i = 1; i <= C; ++i) {
		cin >> c[i];
	}
	
	sort(a+1,a+1+A);
	sort(b+1,b+1+B);
	sort(c+1,c+1+C,cmp);
	
	for (int i = A - X + 1; i <= A; ++i) {
		d[++cnt] = a[i];
	}
	for (int i = B - Y + 1; i <= B; ++i) {
		d[++cnt] = b[i];
	}
	sort(d + 1, d + 1 + cnt);
	int pt = 1;
	for (int i = 1; i <= cnt; ++i) {
		if (pt > C) {
			break;
		}
		if (c[pt] < d[i]) {
			break;
		}
		++pt;
	}
	int ans = 0;
	for (int i = 1; i <= pt - 1; ++i) {
		ans += c[i];
	}
	for (int i = pt; i <= cnt; ++i) {
		ans += d[i];
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 11904
N = int(input())
X_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(min(X_ls), max(X_ls) + 1):
    val = 0
    for j in X_ls:
        val += (i - j) ** 2
    if rst == -1:
        rst = val
    else:
        rst = min(rst, val)
print(rst)

Measured memory_bytes: 9068
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::*;
use std::collections::*;
use std::ops::*;
use procon::*;

const BITSIZE: usize = 30;

pub fn intercalate<T: ToString>(xs: &[T], separator: &str) -> String {
    xs.into_iter()
        .map(|x| x.to_string())
        .collect::<Vec<_>>()
        .join(separator)
}

fn shakutori(A: &[u64], B: &Vec<u64>, l: &mut usize, low: u64, high: u64) -> usize {
    let N = A.len();
    let mut parity = 0;
    let mut l = *l;
    let mut r = l;

    for &a in A {
        while l < N && a + B[l] < low {
            l += 1;
        }
        assert!(l == N || a + B[l] >= low);

        // r = r.max(l);
        r = if l < r { r } else { l };
        while r < N && a + B[r] < high {
            r += 1;
        }
        assert!(r == N || a + B[r] >= high);

        /*
        eprintln!("a={} l={} r={}", a, l, r);
        */
        parity ^= (r - l) & 1;
    }

    parity
}

pub fn main() {
    let _N = read_line().parse::<usize>().unwrap();
    let A: Vec<u64> = read_words();
    let B: Vec<u64> = read_words();
    let mut x = 0;

    for k in 0..BITSIZE {
        let T = 1 << k;
        let mut A = A.iter().cloned().map(|a| a % (2 * T)).collect::<Vec<_>>();
        // A.sort_by_key(|&x| std::cmp::Reverse(x));
        A.sort();
        A.reverse();

        let mut B = B.iter().cloned().map(|b| b % (2 * T)).collect::<Vec<_>>();
        B.sort();

        let mut l1 = 0;
        let mut l2 = 0;

        // a + b が T 以上 2T 未満になるような (a, b) の個数の偶奇
        let p1 = shakutori(A.as_slice(), &B, &mut l1, T, 2 * T);

        let p2 = shakutori(A.as_slice(), &B, &mut l2, 3 * T, 4 * T);

        /*
        eprintln!(
            "k={} p={} A={} B={}",
            k,
            p1 ^ p2,
            intercalate(&A, ", "),
            intercalate(&B, ", ")
        );
        */

        x |= (p1 ^ p2) << k;
    }

    println!("{}", x);
    return;
}

pub mod procon {
    use std;
    use std::collections::*;
    use std::io;
    use std::mem;
    use std::str::FromStr;

    pub fn read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim_right().to_owned()
    }

    pub fn read_words<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace()
            .map(|word| T::from_str(word).unwrap())
            .collect()
    }

    pub fn read_vec(len: usize) -> Vec<String> {
        let mut vec = Vec::new();
        while vec.len() < len {
            let line = read_line();
            for word in line.split_whitespace() {
                vec.push(word.to_owned());
            }
        }
        assert!(vec.len() == len);
        vec
    }
}


Measured memory_bytes: 14108
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=20005;

int n,a[N],sz,tim,tot,cnt,last[N*6],low[N*6],dfn[N*6],stack[N*6],bel[N*6],top,pos[N];
bool inst[N*6];
struct edge{int to,next;}e[N*300];
struct tree{int num;}t[N*5];
pair<int,int> w[N];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
}

void tarjan(int x)
{
	dfn[x]=low[x]=++tim;
	stack[++top]=x;inst[x]=1;
	for (int i=last[x];i;i=e[i].next)
		if (!dfn[e[i].to])
		{
			tarjan(e[i].to);
			low[x]=min(low[x],low[e[i].to]);
		}
		else if (inst[e[i].to]) low[x]=min(low[x],dfn[e[i].to]);
	if (dfn[x]==low[x])
	{
		tot++;int y=0;
		while (y!=x)
		{
			y=stack[top];top--;
			inst[y]=0;bel[y]=tot;
		}
	}
}

void build(int d,int l,int r)
{
	t[d].num=++sz;
	if (d>1) addedge(t[d/2].num,sz);
	if (l==r)
	{
		int id=w[l].second;
		id+=id<=n?n:-n;
		addedge(t[d].num,id);
		return;
	}
	int mid=(l+r)/2;
	build(d*2,l,mid);build(d*2+1,mid+1,r);
}

void ins(int d,int l,int r,int x,int y,int z)
{
	if (x>y) return;
	if (l==x&&r==y) {addedge(z,t[d].num);return;}
	int mid=(l+r)/2;
	ins(d*2,l,mid,x,min(y,mid),z);
	ins(d*2+1,mid+1,r,max(x,mid+1),y,z);
}

pair<int,int> get_lim(int x,int len)
{
	int l=1,r=x;
	pair<int,int> ans;
	while (l<=r)
	{
		int mid=(l+r)/2;
		if (w[x].first-w[mid].first<len) r=mid-1;
		else l=mid+1;
	}
	ans.first=r+1;
	l=x;r=n*2;
	while (l<=r)
	{
		int mid=(l+r)/2;
		if (w[mid].first-w[x].first<len) l=mid+1;
		else r=mid-1;
	}
	ans.second=l-1;
	return ans;
}

bool check(int len)
{
	for (int i=1;i<=n*2+n*4;i++) last[i]=low[i]=dfn[i]=0;
	sz=n*2;cnt=0;
	build(1,1,n*2);
	for (int i=1;i<=n*2;i++)
	{
		int id=w[i].second;
		pair<int,int> u=get_lim(i,len);
		ins(1,1,n*2,u.first,i-1,id);
		ins(1,1,n*2,i+1,u.second,id);
	}
	tot=tim=0;
	for (int i=1;i<=n*2;i++) if (!dfn[i]) tarjan(i);
	for (int i=1;i<=n;i++) if (bel[i]==bel[i+n]) return 0;
	return 1;
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++)
	{
		a[i]=read();a[i+n]=read();
		w[i*2-1]=make_pair(a[i],i);
		w[i*2]=make_pair(a[i+n],i+n);
	}
	sort(w+1,w+n*2+1);
	for (int i=1;i<=n*2;i++) pos[w[i].second]=i;
	int l=0,r=1000000000;
	while (l<=r)
	{
		int mid=(l+r)/2;
		if (check(mid)) l=mid+1;
		else r=mid-1;
	}
	printf("%d",l-1);
	return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using ll=long double;
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define rep( i, a, n ) for( long long int i=a; i<n; i++ )
#define repp( i, a, n, p ) for( long long int i=a; i<n; i+=p )
#define per( i, a, n ) for( long long int i=n-1; i>=a; i-- )

int main () {
  long long int n, m;
  cin >> n >> m;
  long long int arr[n];
  ll req=0;
  rep ( i, 0, n ) {
    cin >> arr[i];
    req += arr[i];
  }

  req /= 4;
  req /= m;

  ll count =0;
  rep ( i, 0, n ) {
    if ( arr[i] >= req ) 
      count++;
  }
  if ( count >= m ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <sstream>
#include <iomanip>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt;

int main(){
	ll x;
	cin>>x;
	for(ll i=0; i<=100000; i++){
		for(ll j=-10000; j<=100000; j++){
			ll p=pow(i,5);
			ll q=pow(j,5);
			if(p-q==x){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
}


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

int gcd(int p, int q)
{
    if(q==0)
        return p;
    else
        return gcd(q,(p%q));
}

int main()
{
    long long K,sum=0;
    cin >> K;

    for(int i=1;i<=K;i++)
        for(int j=1;j<=K;j++)
            for(int l=1;l<=K;l++) {
                sum += gcd(gcd(i, j), l);
            }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3644