akhauriyash/Code-Regression huggingface dataset:
a,b,c=map(int,input().split())
if(a==5):
  if(b==7 and c==5 or b==5 and c==7):
    print("YES")
  else:
    print("NO")
elif(a==7):
  if(b==c==5):
    print("YES")
  else:
    print("NO")
else:
  print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main(void) {
	ll ans = 0, n,in;
	cin >> n;
	rep(i, n) {
		cin >> in;
		while (1) {
			if (in % 2 == 0) {
				in /= 2;
				ans++ ;
			}
			else break;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
import math
import copy

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# inputb = input().split()
# inputbint = [int(x) for x in inputb]
# inputList = list(b)

# x = int(inputb[0])
# y = int(inputb[1])

inputList=[]
for i in range(a):
    inputNum = input().split()
    # inputNum = [float(x) for x in inputNum]
    inputList.append(inputNum)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

sum = 0
btc2jpy = 380000.0
for i in range(a):
    tmp = float(inputList[i][0])
    if str(inputList[i][1]) == "JPY":
        sum += tmp
    else:
        sum += btc2jpy * tmp

print(sum)









Measured memory_bytes: 3444
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


const int MOD = 1e9+7;


void solve() {
    int H, W; cin >> H >> W;
    vector<string> a(H);
    for (int i = 0; i < H; i++) cin >> a[i];

    vector<vector<long long>> dp(H, vector<long long>(W));
    dp[0][0] = 1;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i+1 < H && a[i+1][j] == '.') {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
            if (j+1 < W && a[i][j+1] == '.') {
                dp[i][j+1] += dp[i][j];
                dp[i][j+1] %= MOD;
            }
        }
    }

    cout << dp[H-1][W-1] << endl;
}


int main() {
    solve();
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

ll a[100002];
P p[100002];

int main() {
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);

  for (int i = 0; i < m; i++) {
    cin >> p[i].second >> p[i].first;
  }
  sort(p, p + m);

  int ai = 0;
  for (int i = m - 1; i >= 0; i--) {
    ll b = p[i].second;
    ll c = p[i].first;
    while (ai < n && b > 0) {
      if (c > a[ai]) {
        a[ai] = c;
      } else {
        break;
      }
      ai++;
      b--;
    }
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  cout << ans << endl;
}


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

int main() {
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        long long a, b, res;
        cin >> a >> b;
        long long q = ceil(sqrt(a * b));
        if (a == b) {
            res = 2 * (a - 1);
        } else if(a * b > q * (q - 1)) {
            res = 2 * (q - 1) - 1;
        } else {
            res = 2 * (q - 2);
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        private int[] S;

        public void Run()
        {
            var line = Console.ReadLine();
            S = new int[3];

            S[0] = int.Parse(line[0].ToString());
            S[1] = int.Parse(line[1].ToString());
            S[2] = int.Parse(line[2].ToString());

            int ret = 0;
            for(int i = 0; i <= 2; i++)
                if (S[i] == 1)
                    ret++;

            Console.WriteLine(ret);
        }
       
    }
    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11092
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int dp[1<<18][51];

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> b(n);
  rep(i,n) cin >> b[i];
  rep(mask,1<<n)rep(last,51) dp[mask][last]=inf;
  dp[0][0]=0;
  rep(mask,1<<n)rep(last,51)if(dp[mask][last]!=inf){
    vector<i_i> zeros;
    int itr=0;
    rep(i,n){
      if(mask&(1<<i)) continue;
      zeros.emplace_back(i,itr++);
    }
    for(auto v:zeros){
      bool f=abs(__builtin_popcount(mask)-v.first)%2;
      if(f==0&&a[v.first]<last||f==1&&b[v.first]<last) continue;
      chmin(dp[mask|(1<<v.first)][f==0?a[v.first]:b[v.first]],dp[mask][last]+v.second);
    }
  }
  int ans=inf;
  rep(last,51) chmin(ans,dp[(1<<n)-1][last]);
  if (ans==inf) ans=-1;
  cout << ans << endl;
}

Measured memory_bytes: 52608
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N, vector<ll> a) {
  vector<ll> cum(N, 0);
  cum[0] = a[0];
  FOR(i, 1, N)
    cum[i] = cum[i - 1] + a[i];

  ll ans(abs(cum.back() - 2 * a[0]));
  FOR(i, 1, N - 1)
    ans = min(ans, abs(cum.back() - 2 * cum[i]));

  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> a(N);
  REP(i, N) {
    cin >> a[i];
  }

  solve(N, move(a));

  return 0;
}


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

int main(void){
    int n;
    while(cin >> n){
        if(n == 0)  break;
        int sum=0, dp[100001]={0};
        for(int i=1; i<=n; i++){
        sum = i;
        for(int j=1; sum<n; j++){
            sum += (i+j);
            dp[sum]+=1;
        }
    }
        cout << dp[n] <<endl;
    }
    return 0;
}



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

using namespace std;

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

#define pb push_back
#define mp make_pair

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, m;
    cin >> n >> m;
    ll ans = min(n, m / 2);
    n -= ans;
    m -= ans * 2;
    if(m == 0) cout << ans << endl;
    else{
        ans += m / 4;
        cout << ans << endl;
    }
    return 0;
}


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

#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++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

    vector<int> v;
    for (int i = 1; i <= n; i++)
        v.push_back(i);

    vector<int> p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    int a, b;
    int cnt = 1;
    do
    {
        bool flag1 = 0, flag2 = 0;
        rep(i, n)
        {
            if (p[i] != v[i])
                flag1 = 1;
            if (q[i] != v[i])
                flag2 = 1;
        }
        if (flag1 == 0)
            a = cnt;

        if (flag2 == 0)
            b = cnt;
        cnt++;

    } while (next_permutation(ALL(v)));

    OP(abs(a - b));
    return 0;
}

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


Measured memory_bytes: 1024
local N = io.read("n")
local h = {}
for i=1,N do
    h[i] = io.read("n")
end

local cnt = 0
for i=1,100 do
    local btb = false
    for j=1,N do
        if h[j] == 0 then
            if btb then
                btb = false
            end
        else
            if not btb then
                btb = true
                cnt = cnt + 1
            end
            h[j] = h[j] - 1
        end
    end
end

print(cnt)

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<P> graph[300005];
vector<int> len(300005, INT_MAX/2);

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  rep(i, m) {
    int u, v; cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v+n, 0);
    graph[u+n].emplace_back(v+2*n, 0);
    graph[u+2*n].emplace_back(v, 1);
  }

  int s, t; cin >> s >> t;
  s--; t--;
  len[s] = 0;
  deque<P> que;
  que.emplace_back(0, s);
  while(!que.empty()) {
    P p = que.front(); que.pop_front();
    int u = p.second;
    int l = p.first;
    if (len[u] < l) continue;
    for(auto e: graph[u]) {
      if (len[e.first] > l + e.second) {
        len[e.first] = l + e.second;
        if (e.second == 0) {
          que.emplace_front(len[e.first], e.first);
        } else {
          que.emplace_back(len[e.first], e.first);
        }
      }
    }
  }

  if (len[t] == INT_MAX/2) {
    cout << -1 << endl;
  } else {
    cout << len[t] << endl;
  }
}

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

using namespace std;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N), I(N);
  for (auto &x : A) cin >> x;

  for (int i = 0; i < N; i++) {
    if (i < N - 1) {
      I[i] = A[i + 1] - A[i];
    } else {
      I[i] = A[0] - A[i] + K;
    }
  }

  int sum = accumulate(I.begin(), I.end(), 0);
  int max = *max_element(I.begin(), I.end());

  cout << sum - max << endl;
}


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

using namespace std;
typedef long long LL;

int main(){
  int X;
  cin >> X;
  int A, B;
  cin >> A >> B;
  X-=A;
  X%=B;
  cout << X << endl;

  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
import sys
def main():
  input=sys.stdin.readline
  a,b,q=map(int,input().split())
  s=[int(input()) for i in range(a)]
  t=[int(input()) for i in range(b)]
  x=[int(input()) for i in range(q)]
  inf=10**11
  minf=-10**11
  s=[minf]+s+[inf]
  t=[minf]+t+[inf]
  for i in range(q):
    ns=bisect_left(s,x[i])
    nt=bisect_left(t,x[i])
    ans=float('inf')
    for j in [s[ns],s[ns-1]]:
      for k in [t[nt],t[nt-1]]:
        ans=min(ans,min(abs(x[i]-j),abs(x[i]-k))+abs(max(j,k)-min(j,k)))
    print(ans)
if __name__=='__main__':
  main()


Measured memory_bytes: 16772
using System;

class B
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
		var q = Math.DivRem(h[0], h[1] + h[2], out var r);
		Console.WriteLine(q * h[1] + Math.Min(r, h[1]));
	}
}


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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll n; cin >> n;
	ll arr[n+5];
	rep(i,1,n) cin >> arr[i];
	
	
	sort(arr + 1, arr + n + 1);
	
	
	ll f[N] = {};
	
	rep(i,1,n){
	    f[arr[i]]++;
	}
	
	rep(i,1,N-1){
	    f[i] += f[i-1];
	}
	
	ll ans = 0;
	
	rep(i,1,N-1){
	    if(f[i-1] == n - f[i-1]) ans++;   
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
 int b, r, g, c, s, t;
 while (cin >> b >> r >> g >> c >> s >> t, b|r|g|c|s|t) {
  cout << 100-(t*3 - b*5-b*15 - r*3-r*15 - (b*5+r*3)*15 - g*7 - c*2 -s*3) << endl;
 } 
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-7;
long double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");

vector<vector<int>> cycles;
vector<long long> cost;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	vector<int> c(n);
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
		p[i] --;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
	}
	vector<int> used(n, 0);
	for (int i = 0; i < n; i++)
	{
		if (!used[i])
		{
			cycles.push_back(vector<int>());
			cost.push_back(0);
			int pt = i;
			do
			{
				used[pt] = 1;
				cycles.back().push_back(pt);
				cost.back() += c[pt];
				pt = p[pt];
			} while (pt != i);
		}
	}
	vector<long long> res;
	for (int i = 0; i < cycles.size(); i++)
	{
		long long dt = k / cycles[i].size();
		if (dt == 0)
		{
			long long cur = 0;
			long long x = c[cycles[i][0]];
			for (int st = 0; st < cycles[i].size(); st++)
			{
				long long sum = 0;
				for (int j = 0; j < k; j++)
				{
					sum += c[cycles[i][(st + j) % cycles[i].size()]];
					x = max(sum, x);
				}
			}
			res.push_back(cur + x);
		}
		else
		{
			long long cur = max(0ll, (dt - 1) *  cost[i]);
			long long x = c[cycles[i][0]];
			for (int st = 0; st < cycles[i].size(); st++)
			{
				long long sum = 0;
				for (int j = 0; j < k % cycles[i].size() + cycles[i].size(); j++)
				{
					sum += c[cycles[i][(st + j) % cycles[i].size()]];
					x = max(sum, x);
				}
			}
			res.push_back(cur + x);
		}
	}
	long long ans = res[0];
	for (int i = 1; i < res.size(); i++)
	{
		ans = max(ans, res[i]);
	}
	cout << ans;
}

int main()
{
	cout << setprecision(2) << fixed;
	cin.tie();
	cout.tie();
	//freopen("input.txt", "r", stdin);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
	gg;
}

Measured memory_bytes: 3772
def main():
    #input data
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N,A,B = map(int,input().split())
    mod=10**9+7
    #solve
    #二項係数の和=2**n
    #2**n-1-nCa-nCb
    def modinv(a, mod=10**9+7):
        return pow(a, mod-2, mod)
    def cmb(n, r, mod=10**9+7):
        r = min(r, n-r)
        res = 1
        for i in range(r):
            res = res * (n - i) * modinv(i+1, mod) % mod
        return res
                
    ans = pow(2,N,mod)-1-cmb(N,A,mod)-cmb(N,B,mod)
    print(ans%mod)

if __name__=='__main__':
    main()

Measured memory_bytes: 9060
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, 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

using namespace std;
using namespace __gnu_pbds;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
    IOS
    ll n;
    cin>>n;
    vll v(n);
    ll sum=0;
    ll def=0;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        sum=sum+v[i];
        def=def+v[i]*v[i];
    }
    ll lb=sum/n;
    ll ub=lb+1;
    ll ret1=n*lb*lb-2LL*lb*sum;
    ll ret2=n*ub*ub-2LL*ub*sum;
    ll mini=min(ret1,ret2);
    ll res=def+mini;
    cout<<res<<"\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;

class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    String s = sc.next();
    
    int count = s.length() - s.replace("ABC", "").length();
    
    
    System.out.println( count / 3 );
    
  }
}

Measured memory_bytes: 22100
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <ios>
#include <iomanip>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;

bool is_prime(int x){
    if(x==1) return false;
    if(x==2) return true;
    for(int i = 2;i*i<=x;i++){
        if(x%i==0) return false;
    }
    return true;
}

void solve() {
    int Q; cin >> Q;
    vi l(Q),r(Q);
    int left = 1000000, right = 0;
    rep(i,Q){
        cin >> l[i] >> r[i];
        left = min(left, l[i]);
        right = max(r[i], right);
    }

    vi prime_list;
    rng(i,left,right+1){
        int j = (i+1)/2;
        if(is_prime(i) && is_prime(j)){
            prime_list.pb(i);
        }
    }

    rep(i,Q){
        int count = upper_bound(ALL(prime_list), r[i]) - lower_bound(ALL(prime_list), l[i]);
        print(count);
    }
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    // int q; cin >> q;
	// while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3964
import sys
from collections import deque
import copy
import math

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]
    head = 0
    tail = len(S) - 1
    count = 0
    #for i in range(len(S)/2 + len(S) % 2):
    while 1:
        if head >= tail:
            break
        if S[head] != S[tail]:
            if S[head] == "x":
                count += 1
                head += 1
            elif S[tail] == "x":
                count += 1
                tail -= 1
            else:
                print -1
                return
        else:
            head += 1
            tail -= 1
    print count


if __name__ == '__main__':
    main()


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

using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int upperBound = a[i] + a[j];
            int left = j, right = n;
            while (left + 1 < right) {
                int mid = (left + right) / 2;
                if (a[mid] >= upperBound) {
                    right = mid;
                } else {
                    left = mid;
                }
            }
            ret += left - j;
        }
    }
    cout << ret << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define M 1000000000+7
#define pie 3.141592653589793238
using namespace std;

signed main(){
    int n;cin>>n;
    int a[n+1],b[n+1],c[n];
    for(int i=1;i<=n;i++)
    	cin>>a[i];
   	for(int i=1;i<=n;i++)
   		cin>>b[i];
   	for(int i=1;i<n;i++)
   		cin>>c[i];

   	int ans=0;
   	int p=-1;
   	for(int i=1;i<=n;i++){
   		ans+=b[a[i]];
   		if(p == a[i] - 1){
   			ans+=c[p];
   		}
   		p=a[i];
   	}
   	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    string s;
    cin >> s;
    for(int i = 0;i < s.size();i++)
    {
        if(i % 2 == 0){cout << s[i];}
    }
    return 0;
}

Measured memory_bytes: 576
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s = iterator.next().unwrap();

    if s == "AAA" || s == "BBB" {
        return String::from("No");
    } else {
        return String::from("Yes");
    }
}


Measured memory_bytes: 4352
visitted = []

def dfs(matrix, num_nodes, current_node):
    global visited

    for next_node in range(num_nodes):
        if matrix[current_node][next_node] == False:
            continue
        elif visited[next_node] == True:
            continue
        else:
            visited[next_node] = True
            dfs(matrix, num_nodes, next_node)

def main():
    N, M = map(int, input().split(" "))

    adjacent_matrix = [[False for _ in range(N)] for _ in range(N)]
    edges = []
    for _ in range(M):
        node1, node2 = map(int, input().split(" "))
        edges.append([node1 - 1, node2 - 1])
        adjacent_matrix[node1 - 1][node2 - 1] = adjacent_matrix[node2 - 1][node1 -1] = True

    global visited
    visited = [False] * N

    num_bridges = 0
    for e in edges:
        adjacent_matrix[e[0]][e[1]] = adjacent_matrix[e[1]][e[0]] = False

        dfs(adjacent_matrix, N, 0)

        is_connected = True
        for v in visited:
            if v == False:
                is_connected = False
                break

        if is_connected == False:
            num_bridges += 1

        for i in range(N):
            visited[i] = False

        adjacent_matrix[e[0]][e[1]] = adjacent_matrix[e[1]][e[0]] = True

    print(num_bridges)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)		substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int32_t main()
{
	FIO;
	int n; cin >> n;
	string s; cin >> s;

	int w = 0, r = 0;

	for (int i = 0; i < n; ++i)
	{
		if (s[i] == 'W')
			w++;
		else
			r++;
	}

	int in_w = 0;

	for (int i = n - w; i < w; ++i)
		if (s[i] == 'W')
			in_w++;

	int in_r = 0;
	for (int i = 0; i < r; ++i)
		if (s[i] == 'R')
			in_r++;

	//cout << w << ' ' << in_w << '\n';
	//cout << r << ' ' << in_r << '\n';

	cout << min(w - in_w, r - in_r) << '\n';
	return 0;
}

Measured memory_bytes: 3780
nyuryoku = []

try:
    while True:
        s = input()
        if s == '':
            break
        nyuryoku.append(s)

except EOFError:
    pass

for s in nyuryoku:

 list = [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]

 print(list[int(s)-1])

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n%2!=0)
  {
    int k=n/2;
    cout<<k<<endl;
  }
  else
  {
    int k=n/2;
    cout<<k-1<<endl;
  }
  return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


i64 G[2][100];
i64 dp[2][100];

int main() {
    i64 H = 2;
    i64 W; cin >> W;

    REP(y, H) REP(x, W) cin >> G[y][x];

    REP(y, H) {
        REP(x, W) {
            REP(i, 2) {
                i64 py = y - (i == 0);
                i64 px = x - (i == 1);
                if (py < 0 || px < 0) chmax(dp[y][x], G[y][x]);
                else chmax(dp[y][x], dp[py][px] + G[y][x]);
            }
        }
    }

    cout << dp[1][W - 1] << endl;

    return 0;
}

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

using namespace std;

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

int c=0;
for(int i=0;i<s.size();i++)
{
    if(s[i]!=t[i]){c++;}
}
cout<<c;

    return 0;
}


Measured memory_bytes: 3844
! 2019.12.28 
!
      program answer
      implicit none
      integer(8) :: N
      integer(8) :: A,B
      integer(8) :: large
      integer(8) :: small
      integer(8) :: step
      integer(8) :: dif
      integer(8) :: ans
      intrinsic mod,abs
!
      read(*,*) N,A,B
      if(mod(abs(A-B),2) == 0) then
        ans = abs(A-B)/2
      else
        if(A > B) then
          large = A
          small = B
        else
          large = B
          small = A
        end if
        if(N-large < small-1) then
          step = N-large
        else
          step = small-1
        end if
        dif = large - small
        ans = step + dif/2 + 1
      end if
      write(*,*) ans
      end program answer

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

typedef uint32_t u32;
typedef int64_t s64;

struct Comb {
	std::vector<std::vector<s64> > a;
	Comb(int n) { // O(n^2)
		a.resize(n+1);
		for (int i = 0; i <= n; i++) {
			a[i].resize(i+1, 1);
			for (int j = 1; j < i; j++) a[i][j] = a[i-1][j] + a[i-1][j - 1];
		}
	}
	s64 ncr(int n, int r) {
		assert(n >= 0);
		assert(n <= (int)a.size());
		assert(r >= 0);
		assert(r <= n);
		return a[n][r];
	}
};

int64_t gu(int m, int k, const std::vector<int> &revised) {
	int n = revised.size();
	assert(n <= 25);
	int cnt = 0;
	for (int i = 1; i < 1 << n; i++) {
		u32 tmp0 = 0, tmp1 = ~0;
		for (int j = 0; j < n; j++) if (i >> j & 1) tmp0 |= revised[j], tmp1 &= revised[j];
		if (__builtin_popcount(i) <= k && tmp0 == (1U << m) - 1 && !tmp1) cnt++;
	}
	return cnt;
}
int64_t fast(int m, int k, const std::vector<int> &revised) {
	int n = revised.size();
	Comb com(n + 1);
	int64_t ncrsum[n + 1][n + 1];
	for (int i = 0; i <= n; i++) {
		ncrsum[i][0] = com.ncr(i, 0);
		for (int j = 1; j <= i; j++) ncrsum[i][j] = ncrsum[i][j - 1] + com.ncr(i, j);
		for (int j = i; j < n; j++) ncrsum[i][j + 1] = ncrsum[i][j];
	}
	int64_t res = 0;
	for (int i = 0; i < 1 << m; i++) {
		std::map<int, int> ma;
		for (auto j : revised) ma[j & i]++;
		int64_t cur = 0;
		for (auto j : ma) cur += ncrsum[j.second][k] - 1;
		if (__builtin_popcount(i) & 1) res -= cur;
		else res += cur;
	}
	return res;
}

std::mt19937 rnd;
bool random_check(int m, int n) {
	int k = std::uniform_int_distribution<>(1, n)(rnd);
	std::vector<int> revised(n);
	for (auto &i : revised) i = std::uniform_int_distribution<>(0, (1 << m) - 1)(rnd);
	auto r0 = gu(m, k, revised);
	auto r1 = fast(m, k, revised);
	if (r0 != r1) {
		std::cerr << "FAILED" << std::endl;
		std::cerr << m << " " << k << std::endl;
		for (auto i : revised) std::cerr << i << " ";
		std::cerr << std::endl;
		std::cerr << r0 << " " << r1 << std::endl;
		return false;
	}
	return true;
}

int main() {
	int n = ri(), k = ri();
	
	u32 s = ri(); // and
	u32 t = ri(); // or
	if ((s & t) != s) {
		puts("0");
		return 0;
	}
	u32 a[n];
	for (auto &i : a) i = ri();
	
	u32 mask = ~s & t;
	std::vector<int> all;
	
	std::vector<int> revised;
	for (int i = 0; i < 18; i++) if (mask >> i & 1) all.push_back(i);
	int m = all.size();
	for (auto i : a) {
		if ((i & s) != s) continue;
		if (~t & i) continue;
		int cur = 0;
		for (int j = 0; j < (int) all.size(); j++) if (i >> all[j] & 1) cur |= 1 << j;
		revised.push_back(cur);
	}
	n = revised.size();
	printf("%" PRId64 "\n", revised.size() <= 20 ? gu(m, k, revised) : fast(m, k, revised));
	
	return 0;
}


Measured memory_bytes: 3836
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
n,q=map(int,input().split())
g=[deque([]) for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
add=[0]*n
for _ in range(q):
    a,b=map(int,input().split())
    add[a-1]+=b
st=set()  ; ans=[0]*n ; stack=[[0,add[0]]]
while stack:
    s=stack[-1]
    if s[0] not in st : 
        st.add(s[0])
        ans[s[0]]+=s[1]
    if not g[s[0]] : 
        stack.pop()
        continue
    while g[s[0]]:
        if g[s[0]][0] in st:
            g[s[0]].popleft()
        else:
            stack.append([g[s[0]][0],s[1]+add[g[s[0]][0]]])
            break
print(*ans)
        
      

Measured memory_bytes: 204624
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

k = I()
q = deque([1])
cost = [INF] * k
cost[1] = 1
while q:
    u = q.popleft()
    if cost[u * 10 % k] > cost[u]:
        cost[u * 10 % k] = cost[u]
        q.appendleft(u * 10 % k)
    if cost[(u + 1) % k] > cost[u] + 1:
        cost[(u + 1) % k] = cost[u] + 1
        q += [(u + 1) % k]


print(cost[0])


Measured memory_bytes: 85280
n = int(input())
a = list(map(int, input().split()))

sum = a[0]
count1 = 0
count2 = 0

sum1 = 0
sum2 = 0

for i in range(n) :
    sum1 += a[i]
    sum2 += a[i]
    if i % 2 == 0 :
        if sum1 >= 0 :
            count1 += abs(sum1) + 1
            sum1 = -1
        if sum2 <= 0 :
            count2 += abs(sum2) + 1
            sum2 = 1
    elif i % 2 == 1 :
        if sum1 <= 0 :
            count1 += abs(sum1) + 1
            sum1 = 1
        if sum2 >= 0 :
            count2 += abs(sum2) + 1
            sum2 = -1

print(min(count1, count2))


Measured memory_bytes: 14468
def calc(exp)
  stack = []
  exp.each do |s|
    if s =~ /\d+/
      stack.push s.to_i
    else
      v2 = stack.pop
      v1 = stack.pop
      case s
      when '+'
        v = v1+v2
      when '-'
        v = v1-v2
      when '*'
        v = v1*v2
      end
      stack.push v
    end
  end
  stack[0]
end
  
puts calc(STDIN.readline.split(/\s/))

Measured memory_bytes: 8696
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
ll n,k;
cin>>n>>k;
V<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
sort(all(a));
ll ans=0;
for(int i=0;i<n-k;i++)ans+=a[i];
cout<<ans<<endl;


}



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

#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define ll long long

int main()
{
  IOS;
  char a;
  cin >> a;
  if (a>=65 && a<=90)
    cout << "A" << endl;
  else if (a>=97 && a<=122)
    cout << "a" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>

int main(int argc, char const* argv[])
{
    int a, b, t;
    std::cin >> a >> b >> t;

    int result = 0;
    for(int i=1; i * a <= t; ++i)
    {
        result += b;
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int n,b,f,r,v,i,j,room[15][10]={{0}};

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d%d%d",&b,&f,&r,&v);

    room[4*b+f-5][r-1]+=v;

  }

  for(i=0;i<15;i++){
    for(j=0;j<10;j++){
      if(i==3 || i==7 || i==11 )printf("##");
      else printf(" %d",room[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <chrono>
#include <complex>
#include <cstdint>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <regex>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = int64_t;
namespace ac {
    uint64_t xorRand() {
        static uint64_t x = 123456789ULL, y = 362436069ULL, z = 521288629ULL, w = 88675123ULL;
        uint64_t t = (x ^ (x << 11));
        x = y; y = z; z = w;
        return (w = (w ^ (w >> 19ULL)) ^ (t ^ (t >> 8ULL)));
    }
}
using namespace ac;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll a, b, c, d, e, f;
        in >> a >> b >> c >> d >> e >> f;
        double mp = 0;
        ll aw = 0, as = 0;
        for (int i = 0; i < 10004; i++) {
            ll nw = 0, ns = 0;
            ll tw = 0, ts = 0;
            for (int j = 0; j < 3003; j++) {
                bool is_sugar = false;
                ll t = xorRand() % (a + b + 100 * c + 100 * d);
                if (t < a) {
                    tw = nw + 100 * a;
                    if (tw + ts <= f) {
                        nw += 100 * a;
                    }
                    else {
                        tw = nw;
                    }
                }
                else if (t < a + b) {
                    tw = nw + 100 * b;
                    if (tw + ts <= f) {
                        nw += 100 * b;
                    }
                    else {
                        tw = nw;
                    }
                }
                else if (t < a + b + 100 * c) {
                    ts = ns + c;
                    if (tw + ts <= f && 100 * ts <= e * tw) {
                        ns += c;
                        is_sugar = true;
                    }
                    else {
                        ts = ns;
                    }
                }
                else {
                    ts = ns + d;
                    if (tw + ts <= f && 100 * ts <= e * tw) {
                        ns += d;
                        is_sugar = true;
                    }
                    else {
                        ts = ns;
                    }
                }
            }
            if ((nw + ns) > 0 && mp <= 100.0 * ns / (nw + ns)) {
                mp = 100.0 * ns / (nw + ns);
                aw = nw;
                as = ns;
            }
        }
        out << (as + aw) << ' ' << as << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

struct Combination {
	static const int MAX = 1000000;
	vector<ll> fac, finv, inv;

	Combination() {
		COMinit();
	}

	// テーブルを作る前処理
	void COMinit() {
		fac.resize(MAX); finv.resize(MAX), inv.resize(MAX);
	    fac[0] = fac[1] = 1;
	    finv[0] = finv[1] = 1;
	    inv[1] = 1;
	    for (int i = 2; i < MAX; i++){
	        fac[i] = fac[i - 1] * i % MOD;
	        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
	        finv[i] = finv[i - 1] * inv[i] % MOD;
	    }
	}
	 
	// 二項係数計算
	ll COM(int n, int k){
	    if (n < k) return 0;
	    if (n < 0 || k < 0) return 0;
	    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
};

ll X, Y;

int main(void){
	cin>>X>>Y;

	if ((X + Y) % 3 != 0) {
		cout<< 0 <<endl;
		return 0;
	}

	Combination comb;
	cout<< comb.COM((X + Y) / 3, (2 * Y - X) / 3) <<endl;
	
	return 0;
}

Measured memory_bytes: 23680
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

int main() {
  int N, M, T;
  cin >> N >> M >> T;
  vector<int> A(N);
  int ans = 0, now = 0;
  REP(i, N) {
    int A;
    cin >> A;
    if (A - now >= M) {
      ans += A - now - M;
    }
    now = A + M;
  }
  ans += max(0, T - now);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3116
# https://atcoder.jp/contests/cf16-final/tasks/codefestival_2016_final_b

N = int(input())

# [1,N]の部分集合で合計がちょうどNになる.最大値が最小
# 合計が初めてNを超えるときまでの集合を使って作ることができる
# そして差の数字は必ずその集合の中に含まれる

su = 0
for i in range(N + 1):
    su += i
    if su >= N:
        break
# iまでの数字で必ずNは作れる
ans = list(range(1, i + 1))
if su - N != 0:
    ans.remove(su - N)
print(*ans, sep='\n')


Measured memory_bytes: 71768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	ll n,k; cin>>n>>k;
	vl p(n),c(n);
	rep(i,0,n)cin>>p[i],p[i]--;
	rep(i,0,n)cin>>c[i];

	ll ans=-1e18;

	rep(i,0,n){
		ll x=i,tot=0;
		vl vec(0);
		while(1){
			vec.push_back(c[x]);
			tot += c[x];
			x=p[x];
			if(x==i)break;
		}
		ll l=vec.size();
		ll now=0;
		rep(i,0,l){
			if(k<=i)break;
			now+=vec[i];
			ll sco=0;
			if(tot>0)sco=((k-i-1)/l)*tot;
			chmax(ans,now+sco);
		}
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 3824
N,K = map(int,input().split())
A = list(map(lambda x:int(x)-1,input().split()))

F = [False]*N
L = []
cnt = 0
ans = -1
x = 0
first = -1
while 1:
    if first==x:break
    if cnt==K:
        ans = x
        break
    if F[x]:
        if first==-1:
            first = x
        L.append(x)
    F[x]=True
    cnt += 1
    x = A[x]
if ans==-1:
    N = len(L)
    ans = L[(K-cnt)%N]
print(ans+1)

Measured memory_bytes: 32380
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, m; scanf("%d%d", &n, &m); m += n - 1;
	std::vector<std::vector<int>> g(n);
	std::vector<int> h(n, 0);
	for(int i = 0; i < m; i++) {
		int a, b; scanf("%d%d", &a, &b);
		
		g[a - 1].push_back(b - 1);
		h[b - 1]++;
	}
	
	std::vector<int> ans(n, -1);
	for(int i = 0; i < n; i++) {
		if(!h[i]) {
			std::queue<int> qu; qu.push(i);
			while(!qu.empty()) {
				auto p = qu.front(); qu.pop();
				
				for(auto e : g[p]) {
					ans[e] = p;
					if(--h[e] == 0) {
						qu.push(e);
					}
				}
			}
			break;
		}
	}
	for(auto v : ans) printf("%d\n", v + 1);
	return 0;
}


Measured memory_bytes: 7040