akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}


char s[N],t[N];
int A[N],B[N];

int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	scanf("%s %s",s,t);
	int n = strlen(s), m = strlen(t);
	REP(i,n){
		if(s[i]=='A') A[i]++;
		else A[i]--;
		if(i) A[i]+=A[i-1];
	}
	REP(i,m){
		if(t[i]=='A') B[i]++;
		else B[i]--;
		if(i) B[i]+=B[i-1];
	}
	int q; scanf("%d",&q);
	REP(i,q){
		int a,b,c,d; scanf("%d %d %d %d",&a,&b,&c,&d);
		int p = 0, q = 0;
		a--,b--,c--,d--;
		p = A[b], q = B[d];
		if(a) p-=A[a-1];
		if(c) q-=B[c-1];
		p%=3, q%=3;
		if(p<0) p+=3;
		if(q<0) q+=3;
		if(p==q) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}




Measured memory_bytes: 7296
N  = int(input())
H = [int(i) for i in input().split()]

count = 0

for i in range(N-1):
	if i != 0 and H[i-1] == H[i]:
		if H[i] > H[i+1] and H[i] != 1:
			H[i] -= 1
	else:
		if H[i] != 1:
			H[i] -= 1


for i in range(N-1):
	if H[i] > H[i+1]:
		print('No')
		break
	count += 1

if count == N-1:
	print('Yes')

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, K;
	cin >> A >> B >> K;
	int a = min(A, K);
	A -= a;
	K -= a;

	a = min(B, K);
	B -= a;
	K -= a;

	cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int rank[2];
    int money = 0;
    cin >> rank[0] >> rank[1];
    for(int i =0;i<2;i++) {
        if(rank[i] <= 3) {
            money += 100000*(4-rank[i]);
        }
    }
    if(money == 600000) {
        money += 400000;
    }
    cout << money << endl;
    return 0;
}

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

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif
//#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = (int) 5e5 + 2;
int ar[NN];
int a[NN];
int b[NN];
int n, m, k;
string s;
vector<int> primes;
int dp[10000001];
int M = 1e7 + 1;

void f(int x, int j, int cnt){
    if (dp[x] != -1) return;
    dp[x] = cnt;
    if (j == primes.size()) return;
    for (int i = j; i < primes.size(); i++){
        int z = primes[i];
        if (x * z >= M) break;
        for (int p = 1; ; p++, z *= primes[i]){
            if (x * z >= M) break;
            f(x * z, i+1, cnt * (p+1));
        }
    }
}

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

    vector<int> nums(M, 1);
    for (int i = 2; i * i <= M; i++){
        for (int j = i*i; j <= M; j+=i){
            nums[j] = 0;
        }
    }
    for (int i = 2; i <= M; i++){
        if (nums[i]) primes.pb(i);
    }
    memset(dp, -1, sizeof dp);
    f(1, 0, 1);
//    cout << dp[3] << endl;

//    return 0;




    int T = 1;
//    cin >> T;
    while (T--) {
        cin >> n;
        int ans = 0;
        for (int i = 1; i <= n; i++){
            ans += i * dp[i];
//            ans += i * f(i, 1);
        }
        cout << ans << endl;

    }
}


Measured memory_bytes: 164860
#include <iostream>

int main(){
  int n;
  std::cin >> n;
  int dp[n+1];
  dp[0]=1; dp[1]=1;
  for(int i=2;i<=n;i++) dp[i]=dp[i-1]+dp[i-2];
  std::cout << dp[n] << std::endl;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int a;
	string s;
	cin >> a >> s;

	if(a<3200){
		cout << "red" << endl;
	}
	else{
		cout << s << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
if n % 2 == 0:
    ans = sum(a[:n // 2]) * 2 - a[0]
else:
    ans = sum(a[:n // 2 + 1]) * 2 - a[0] - a[n // 2]
print(ans)

Measured memory_bytes: 31444
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;


const int MAX_N = 1e5+10;
int nxt[MAX_N][32];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl x(n);
    rep(i, n) cin >> x[i];
    ll L;
    int Q;
    cin >> L >> Q;

    rep(i, n) {
        auto it = upper_bound(all(x), x[i] + L);
        --it;
        nxt[i][0] = it - x.begin();
    }
    REP(j, 1, 32) {
        rep(i, n) {
            nxt[i][j] = nxt[nxt[i][j-1]][j-1];
        }
    }
    rep(q, Q) {
        ll a, b;
        cin >> a >> b;
        --a;
        --b;
        if(a > b) swap(a, b);
        ll ans = 0LL;
        int cur = a;
        while(cur < b) {
            rep(i, 32) {
                if(nxt[cur][i] >= b) {
                    if(i == 0) {
                        ans += 1;
                        cur = nxt[cur][i];
                    }
                    else {
                        ans += (1LL<<(i-1));
                        cur = nxt[cur][i-1];
                    }
                    break;
                }
            }
            // cout << " " << cur << " -> " << nxt[cur][i] << " " << (1LL<<i) << "day ("  << i << ")" << '\n'; 
        }
        // cout << a << " -> " << b << " (" << cur<<")" << '\n';
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin>>S;
  cin>>T;
  for(int i=0;i<S.size();i++){
    if(S.at(i)==T.at(i)){
      continue;
    }
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 3628
#include <iostream>

int main() {
    int h,w;
    while(true) {
        std::cin >> h >> w;
        if((h|w) == 0) break;
        std::string s1(w, '#'); for(auto i=1; i<w; i+=2) s1.replace(i, 1, 1, '.');
        std::string s2(w, '.'); for(auto i=1; i<w; i+=2) s2.replace(i, 1, 1, '#');
        for(auto i=0; i<h; i++) {
            std::cout << ((i%2) ? s2 : s1) << std::endl;
        }
        std::cout << std::endl;
    }
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int x, a; cin >> x >> a;
  cout << (x < a ? 0 : 10) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, K, s{}, m{}; cin >> N >> K;
  vector<int> ps(N); for (auto &p : ps) cin >> p;
  for (int i = 0; i < N; ++i)
    {s += ps[i]; if (i >= K) s -= ps[i - K];
    m = max(m, s);}
  cout << fixed << setprecision(12) << (m + K) / 2. << endl;}

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

int main() {
  char a,b,c,d;
  cin >> a >> b >> c >> d;
  vector<char> vec={a,b,c,d};
  sort(vec.begin(),vec.end());
  string ans = "No";
  if (vec[0]==vec[1] && vec[1] != vec[2] && vec[2]== vec[3]) ans = "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;

struct edge { int to, cost; };
int main() {
	string s;
	cin >> s;
	int ans = 0;
	while (s.size()>1) {
		if (s[0] == s[s.size() - 1]) {
			if (s.size() == 2)break;
			s = s.substr(1, s.size() - 2);
		}
		else {
			if (s[0] == 'x') {
				ans++;
				s = s.substr(1, s.size() - 1);
			}
			else if (s[s.size() - 1] == 'x') {
				ans++;
				s=s.substr(0,s.size()-1);
	        }
			else {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {

  int a,b,c ; cin >> a >> b >> c ;
  int sum = a+b+c ; 
  int maxi = max({a,b,c});
  
  (maxi == sum -maxi) ? cout << "Yes" :cout << "No" ;

}

Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a <= b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vi a(n);
    rep(i, n)cin >> a[i];
    resort(a);
    int sum = a[0];
    int k = 1;
    if(n%2==1) {
        rep(i, n/2-1) {
            sum+=a[k]*2;
            k++;
        }
        sum+=a[k];
    }
    else {
        rep(i, n/2-1) {
            sum+=a[k]*2;
            k++;
        }
    }
    /*rep(i, (n-1)/2-1) {
        sum+=a[k]*2;
        k++;
    }
    if(n%2) sum+=a[k];*/
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4856
#include<iostream>
using namespace std;
#define int long long int
int32_t main()
{
     int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
     int k;
     cin>>k;
     cout<<arr[k-1]<<endl;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

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


Measured memory_bytes: 256
H, W, A, B = map(int, input().split())

mod = 10**9 + 7

fact = [1] * (H + W - 1)
invfact = [1] * (H + W - 1)

for i in range(1, H + W - 1):
    fact[i] = fact[i - 1] * i % mod
for i in range(1, H + W - 1):
    invfact[i] = pow(fact[i], mod-2, mod)

def nCr(n,r):
    return fact[n] * invfact[r] * invfact[n-r]

result = 0
for i in range(1, H - A + 1):
    result += (nCr((B-1)+(i-1), i-1) * nCr((W-B-1)+(H-i), W-B-1)) % mod
print(int(result % mod))

Measured memory_bytes: 19808
//libs

#include <bits/stdc++.h>

//other stuff

using namespace std;

//function call

//main

int main(){	
    	string S;
    	cin >> S;
    	int ret = 10000;
    	for(int i = 0;i < 26;i++) {
        	int cnt = 0;
        	int cnt2 = -1;
        	for(int j = 0;j < S.size();j++) {
            	if(S.at(j) == 'a' + i) {
               		cnt = max(cnt,j - cnt2 - 1);
              		cnt2 = j;
            	}
        	}
      		int A = S.size();
        	cnt = max(cnt,A - cnt2 - 1);
        	ret = min(ret,cnt);
	}
    	cout << ret << endl;
return 0;
}

//functions



Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
int sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int n ; cin >> n ;
	int x,y ;
	x = y = 0 ;
	int t = 0 ;
	for(int i=0;i<n;i++){
		int a,b,c ;
		cin >> a >> b >> c ;
		if(a-t<sa(x,b)+sa(y,c)){
			cout << "No" << endl ;
			return 0 ;
		}
		if((a-t-sa(x,b)-sa(y,c))%2==1){
			cout << "No" << endl ;
			return 0 ;
		}
		t = a ;
		x = b ;
		y = c ;
	}
	cout << "Yes" << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i;
  string a,b;
  cin>>a>>b;
  int g=a.length();
  int y=b.length();
  int x=0;
  for(i=0;i<g;i++)
  {
  	if(a[i]==b[i])
  	{
  	   x=1;	
	}
	else
	{
		x=0;
		break;
	}
  }
  if(x==1 && y-g==1)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.util.Scanner;
import java.util.OptionalInt;

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt();
            }

            int min = Arrays.stream(a).min().getAsInt();
            int max = Arrays.stream(a).max().getAsInt();
            long cost = Long.MAX_VALUE;
            for (int i = min; i <= max; i++) {
                final int y = i;
                long temp = Arrays.stream(a).mapToLong(x -> (long) Math.pow(x - y, 2)).sum();
                cost = Math.min(cost, temp);
            }
            out.println(cost);
        }

    }
}



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


int main() {
    string s;cin >> s;
    int num = s.size()-2;
    string n = to_string(num);
    cout << s.at(0)+n+s.at(num+1) << endl;

  }       

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n;
  char s[10001];
  
  scanf("%d %s",&n,s);
  for(int i=0;s[i]!='\0';i++){
    if(s[i]+n>'Z'){
      s[i]+=n;
      s[i]-='Z'-'A'+1;
    }
    else{
      s[i]+=n;
    }
  }
  printf("%s\n",s);
  return 0;
}

Measured memory_bytes: 128
/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
 
#include <iostream>
#include<stdio.h>
#include<cmath>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<string.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<string.h>
#include<stack>
#include<queue>
#include<deque>
 
#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 100000007
 
using namespace std;
 
ll a[305][305],n,k;
 
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    ll n;
    sfl(n);
    string s;
    map<string,ll>counting;
    for(ll i=0;i<n;i++)
    {
    	cin>>s;
    	counting[s]++;
    }
    printf("AC x %lld\n",counting["AC"]);
    printf("WA x %lld\n",counting["WA"]);
    printf("TLE x %lld\n",counting["TLE"]);
    printf("RE x %lld\n",counting["RE"]);
    return 0;
}

Measured memory_bytes: 3288
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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


n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
print(uf.group_count()-1)


Measured memory_bytes: 75432
#include <iostream>
#include <stdlib.h>
using namespace std;

int gcd(int a, int b) {
	if (a%b == 0)
		return b;
	if (b%a == 0)
		return a;
	int i, n, m;
	if (a < b) {
		n = b;
		m = a;
		i = a;
	}
	else {
		n = a;
		m = b;
		i = b;
	}
	for (; i > 1; i--) {
		if (n%i == 0 && m%i == 0)
			break;
	}
	return i;
}

int main() {
	int n, X, d; cin >> n >> X;
	int *x = new int[n];
	cin >> x[0];
	d = abs(X - x[0]);
	for (int i = 1; i < n; i++) {
		cin >> x[i];
		d = gcd(d, abs(X - x[i]));
	}
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

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

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;

const int M = 5 * 1e5 + 10;

int d[M];

int main()
{
	For(i, 2, M){
		if (i % 7 == 1 || i % 7 == 6){
			d[i] = 1;
		}
	}
	For(i, 2, M){
		if (d[i]){
			for (int j = i*2; j < M;j += i){
				d[j] = 0;
			}
		}
	}

	int n;
	while (cin >> n && n != 1){
		
		cout << n << ":";
		For(i, 2, n+1){
			if (d[i] && n % i == 0){
				cout << " " << i;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
n, x, y = map(int, input().split())
ans = [0 for _ in range(n)]
for i in range(1, n+1):
    for j in range(i+1, n+1):
        ans[min(j-i, abs(i-x)+abs(j-y)+1)] += 1


for i in range(1, n):
    print(ans[i])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    int N, K;
    cin >> N;
    cin >> S;
    cin >> K;
    char trans = S[K - 1];
    for (int i = 0; i < N; i++)
    {
        if (S[i] != trans)
        {
            cout << '*';
        }
        else
        {
            cout << S[i];
        }
    }
    cout << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0; i < 4; i++){
    if(s.at(i) == '+'){
      count++;
    }
    else if(s.at(i) == '-'){
      count--;
    }
  }
  cout << count <<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

int main(){

  int n, a;
  vector<llong> v;

  scanf("%d %d", &n, &a);
  REP(i,n){
    llong t;
    scanf("%lld", &t);
    v.pb(t);
  }
  
  vector<vector<vector<llong>>> dp(n + 1, vector<vector<llong>>(n + 1, vector<llong>(n * a + 10, 0))); 

  dp[0][0][0] = 1;
  FOR(i,0,n + 1){
    FOR(j,0,n + 1){
      REP(k,a * n + 1){
        if(j == 0 && k == 0) dp[i][j][k] = 1;
        else if(i > 0 && k - v[i - 1] >= 0 && j > 0){
          dp[i][j][k] += dp[i - 1][j - 1][k - v[i - 1]] + dp[i - 1][j][k];
        }
        else if(i > 0)
          dp[i][j][k] += dp[i - 1][j][k];
        else
          dp[i][j][k] = 0;
      }
    }
  }

  long long res = 0;
  FOR(i,1,n + 1){
    res += dp[n][i][i * a];
  }

  printf("%lld\n", res);
  return 0;
}



Measured memory_bytes: 52352
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	string st;
	int a,sum=0;
	while(cin>>st){
		a=0;
		for(int i=0;i<=(int)st.size();i++){
			if('0'<=st[i]&&st[i]<='9')
			a=a*10+st[i]-'0';
			else{
				sum+=a;
				a=0;
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 3104
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<int> > G(N);
	vector<int> indeg(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		G[--a].push_back(--b);
		++indeg[b];
	}
	queue<int> que;
	for (int i = 0; i < N; ++i) {
		if (indeg[i] == 0) {
			que.push(i);
		}
	}
	vector<int> dist(N);
	int ans = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		ans = dist[u];
		for (int i : G[u]) {
			--indeg[i];
			if (indeg[i] == 0) {
				dist[i] = dist[u] + 1;
				que.push(i);
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;

const long long INF = 1LL << 60;

long long dp[10001];

int main(void)
{
    int health;
    int magics_count;
    vector<int> damages;
    vector<int> costs;

    for(int i = 0; i <= 10001; i++){
        dp[i] = INF;
    }

    cin >> health >> magics_count;

    for(int i = 0; i < magics_count; i++){
        int d, c;
        cin >> d >> c;
        damages.push_back(d);
        costs.push_back(c);

    }

    dp[0] = 0;
    for(int dmg = 0; dmg <= health; dmg++){
        for(int m = 0; m < magics_count; m++){
            int reach_damage = min(dmg + damages[m], health);
            dp[reach_damage] = min(dp[reach_damage], dp[dmg] + costs[m]);
        }
    }

    cout << dp[health] << endl;

    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>

using namespace std;


const int MAX_N = 100005;

int n,a[MAX_N][3],dp[MAX_N][3];

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		for (int j=0; j<3; j++)
			scanf("%d",&a[i][j]);
	for (int i=1; i<=n; i++)
		for (int j=0; j<3; j++)
			dp[i][j]=a[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
	printf("%d\n",max(dp[n][0],max(dp[n][1],dp[n][2])));
	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
    int n;
    int a[101] = {};
    cin>>n;
    for(int i = 0;i<n;i++){
        cin>>a[i];
    }
    int ans = 10000000;
    for(int i = -100;i<=100;i++){
        int sum = 0;
        for(int j=0;j<n;j++){
            sum+=(i-a[j])*(i-a[j]);
        }
        if(sum<ans){
            ans=sum;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int a, b;
    string s;
    cin >> a >> b;
    cin >> s;
    if ((s.size() == a + b + 1) && (s[a] == '-')) {
        string without_hyphen = s.substr(0, a) + s.substr(a+1, b);
        if (without_hyphen.find_first_not_of("0123456789") == std::string::npos) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  a--;
  b--;
  vvi color(100, vi(100,0)); //0:black, 1: white
  for(int y = 50; y < 100; y++){
    rep(x, 100) color[y][x] = 1;
  }
  cout << "100 100" << endl;
  rep(y, 50){
    if(y % 2 == 0){
      for(int x = 0; x < 100; x++){
        if(a && x % 2 == 0){
          cout << '.';
          a--;
        }else cout << '#';
      }
    }else{
      rep(x, 100)
      cout << '#';
    }
    cout << endl;
  }
  for(int y = 99; y >= 50; y--){
    if(y % 2 == 0){
      for(int x = 0; x < 100; x += 2){
        if(b){
          //cout << '#';
          color[y][x] = 0;
          b--;
        }//else cout << '.';
      }
    }else{
      
    }
  }
  for(int y = 50; y < 100; y++){
    rep(x, 100){
      if(!color[y][x]) cout << '#';
      else cout << '.';
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
using Yorukatsu048.Questions;
using Yorukatsu048.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu048.Questions
{
    /// <summary>
    /// ARC069 C
    /// </summary>
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var sc = inputStream.ReadLongArray();
            var s = sc[0];
            var c = sc[1];

            var scc = Math.Min(s, c / 2);
            s -= scc;
            c -= 2 * scc;

            if (c > 0)
            {
                scc += c / 4;
            }

            yield return scc;
        }
    }
}


namespace Yorukatsu048
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionC();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu048.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu048.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double x_p1 = scan.nextDouble();
		double y_p1 = scan.nextDouble();
		double x_p2 = scan.nextDouble();
		double y_p2 = scan.nextDouble();
		double vx = x_p2 - x_p1;
		double vy = y_p2 - y_p1;
		int q = scan.nextInt();
		double l = norm(x_p1, y_p1, x_p2, y_p2);

		for(int i = 0; i < q; i++) {
			double x = scan.nextDouble();
			double y = scan.nextDouble();
			double ux = x - x_p1;
			double uy = y - y_p1;
			double t = dot(ux, uy, vx, vy);
			double k = t / l;
			double ax = k * vx + x_p1;
			double ay = k * vy + y_p1;
			double bx = 2 * ax - x;
			double by = 2 * ay - y;
			System.out.println(bx + " " + by);
		}
		scan.close();

	}
	static double dot(double x1, double y1, double x2, double y2) {
		return x1 * x2 + y1 * y2;
	}
	static double norm(double x1, double y1, double x2, double y2) {
		return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	}
}


Measured memory_bytes: 42104
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define MOD 1000000007
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n / 10 == 9 || n % 10 == 9) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 29
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}

struct Rect {int h; int pos;};

int solve(vector<int> v)
{
  stack<Rect> S;
  v.push_back(0);
  int ans = 0;
  FOR(i,0,v.size())
  {
    Rect rect;
    rect.h = v[i];
    rect.pos = i;
    if(S.empty()) S.push(rect);
    else
    {
      if(S.top().h < rect.h) S.push(rect);
      else if(S.top().h > rect.h)
      {
        int t = i;
        while(!S.empty() && S.top().h >= rect.h)
        {
          Rect pre = S.top(); S.pop();
          int area = pre.h * (i-pre.pos);
          ans = max(ans,area);
          t = pre.pos;
        }
        rect.pos = t;
        S.push(rect);
      }
    }
  }
  return ans;
}

int main()
{
  int ans = 0;
  int h,w; cin>>h>>w;
  vector<vector<int> > T(h,vector<int>(w,0));
  vector<vector<int> > U(h,vector<int>(w,0));
  REP(i,h) REP(j,w)
  {
    int t; cin >> t;
    T[i][j] = (t+1)%2;
  }
  REP(i,w) U[0][i] = T[0][i];
  FOR(i,1,h-1) REP(j,w) U[i][j] = T[i][j] ? U[i-1][j]+1 : 0;
  REP(i,h) ans = max(ans,solve(U[i]));
  cout << ans << endl;
  return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    for (int i = 0; i <= 5050; i++) {
        int Amulti = A*i;
        if (Amulti % B == C) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
s = sum(A)
for i in range(N):
    if A[i] <= B[i]:
        B[i] -= A[i]
        A[i] = 0
        if A[i + 1] >= B[i]:
            A[i + 1] -= B[i]
        else:
            A[i + 1] = 0
    else:
        A[i] -= B[i]
t = sum(A)
print(str(s - t))


Measured memory_bytes: 18624
# abc159_d.py
import sys
import time
import unittest
from io import StringIO
from collections import defaultdict


def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    dd = defaultdict(int)
    idx = 0
    cmb = [0] * (N + 1)
    for a in A:
        dd[a] += 1
        idx += 1
        cmb[idx] = cmb[idx - 1] + (idx - 1)
    sum = 0
    for j in dd.keys():
        sum += cmb[dd[j]]
    for i in range(N):
        print(sum - (cmb[dd[A[i]]] - cmb[dd[A[i]] - 1]))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def checkTLE(self, input):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin

    def debugIO(self, input):
        stdin = sys.stdin
        sys.stdin = StringIO(input)
        resolve()
        sys.stdin = stdin

    def setUp(self):
        self.startTime = time.time()

    def tearDown(self):
        t = time.time() - self.startTime
        print('%s: %.3f' % (self.id(), t), flush=True)

    def test_入力例_1(self):
        input = """5
1 1 2 1 2"""
        output = """2
2
3
2
3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0
0
0
0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
3 3 3 3 3"""
        output = """6
6
6
6
6"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """8
1 2 1 4 2 1 4 1"""
        output = """5
7
5
7
7
5
7
5"""
        self.assertIO(input, output)


if __name__ == "__main__":
    if "IS_LOCAL" in locals():
        suite = unittest.TestLoader().loadTestsFromTestCase(TestClass)
        unittest.TextTestRunner(verbosity=0).run(suite)
    else:
        resolve()


Measured memory_bytes: 33616
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int n,minv=inf;
int w[maxn],s[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>w[i];
		s[i]=s[i-1]+w[i];
	}
	for(int i=1;i<=n;i++)
		minv=min(minv,abs(s[i]-(s[n]-s[i])));
	cout<<minv<<endl;
	return 0;
}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

#define T 26

int D;
ll C[30];
ll S[400][30];
ll ANS[400];

void input(){
    cin >> D;
    REP(i,T)
        scanf("%lld", &C[i]);
    REP(i,D)
        REP(j,T)
            scanf("%lld", &S[i][j]);
}

void output(){
    REP(i,D)
        printf("%lld\n", ANS[i]+1);
}

// O(DT) = O(365 * 26) = O(10 ** 4)
void calc_score(ll score[], ll ans[]){
    vector<int> last(T, -1);
    ll s = 0;
    REP(d,D){
        s += S[d][ans[d]];
        last[ans[d]] = d;

        REP(i,T){
            s -= C[i] * (d - last[i]);
        }
        score[d] = s;
    }
}

int main(){
    input();


    // greedy
    vector<ll> last(T, -1);
    REP(d, D){
        ll high = -1e15;
        ll t;
        ll minus = 0;
        REP(i, T){
            minus += C[i] * (d - last[i]);
        }

        REP(i, T){
            ll m = minus - C[i] * (d - last[i]);
            ll plus = S[d][i];
            ll val = plus - m;
            if(high < val){
                high = val;
                t = i;
            }
        }
        ANS[d] = t;
        last[t] = d;
    }

    //ll V[400];
    ll S[400];
    calc_score(S, ANS);
    ll score = S[D-1];

    //REP(i,15000){
    REP(i,200000){
        int day = rand() % 365;
        int cont = rand() % 26;
        int pre_val = ANS[day];
        ll pre_score = score;

        ANS[day] = cont;
        calc_score(S, ANS);

        if(S[D-1] <= pre_score){
            ANS[day]  = pre_val;
        }
        else{
            //printf("%lld -> %lld\n", pre_score, S[D-1]);
            score = S[D-1];
        }
    }
    //REP(d,D)
    //    cout << score[d] << endl;

    //REP(d,D)
    //    ANS[d] = V[d];
    output();
    return 0;
}


Measured memory_bytes: 3884
#include<stdio.h>
int main(void)
{
	int s,h,m,x,y,z;
	scanf("%d",&s);
	h=s/3600;
	x=3600*h;
	s=s-x;
	m=s/60;
	y=60*m;
	z=s-y;
	printf("%d:%d:%d\n",h,m,z);
	return 0;
}


Measured memory_bytes: 2760
#include<bits/stdc++.h>
using namespace std;
int main () {
  int n;
  cin >> n;
  int p[n];
  int k=0;
  for ( int i = 0; i < n; i++ ){
    cin >> p[i];
    if(p[i] != i+1){
        k++;
    }
  }
  if(k<=2){
      cout << "YES" << endl;
  }else{
      cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
 
int N, Q;
vector<int> edges[202020];
long long num[202020];
 
void dfs(int i, int p){
    for (int j : edges[i]){
        if (j != p){
            num[j] += num[i];
            dfs(j, i);
        }
    }
}
 
int main(){
    cin >> N >> Q;
    
    //グラフの入力を受け取る
    for (int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b); //?????
        edges[b].push_back(a); //?????
    }
    
  
    for (int i = 0; i < Q; i++){
        int p, x;
        cin >> p >> x;
        num[p-1] += x;
    }
    
    
    dfs(0, -1);
    
    for (int i = 0; i < N; i++) cout << num[i] << " ";
}

Measured memory_bytes: 24320
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var list = input[1].split(" ");
  if(list.indexOf("Y") != -1){
     myout("Four");
     }else{
       myout("Three");
     }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 7372
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
int main(){
    int n; cin >> n;
    n = n%10;
    if(n == 3) puts("bon");
    else if(n == 0||n == 1 || n==6 ||n == 8) puts("pon");
    else puts("hon");
    return 0;
}

Measured memory_bytes: 3588