akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF (ll)2e9
#define MOD ((ll)1e9+7)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL<<(n))

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<class InputIterator>
InputIterator adv(InputIterator x, typename std::iterator_traits<InputIterator>::difference_type n) {
    advance(x, n);
    return x;
}

class mod {
    static ll fact[];
public:

    template<class... A>
    static ll mul(A... args) {
        ll res = 1;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res * i) % MOD;
        }
        return res;
    }

    static ll power(ll base, ll exp) {
        if (exp == 0) return 1;
        if (exp & 1) {
            return mul(base, power(base, exp - 1));
        } else {
            ll p = power(base, exp / 2);
            return mul(p, p);
        }
    }

    static ll factorial(int n) {
        if (fact[n] != 0) return fact[n];
        if (n == 0) return 1;
        return fact[n] = mul(n, factorial(n - 1));
    }

    static ll inverse(int n) {
        return power(n, MOD - 2);
    }

    static ll comb(int n, int r) {
        if (r < 0 || r > n) return 0;
        return mul(factorial(n), inverse(factorial(n - r)), inverse(factorial(r)));
    }

    template<class... A>
    static ll div(ll dividend, A... args) {
        ll res = dividend;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = mul(res, inverse(i));
        }
        return res;
    }

    template<class... A>
    static ll add(A... args) {
        ll res = 0;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res * i) % MOD;
        }
        return res;
    }

    template<class... A>
    static ll sub(ll l, A... args) {
        ll res = l;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res - i + MOD) % MOD;
        }
        return res;
    }
};

ll mod::fact[(int) 1e6 + 1];

int ni() {
    int i;
    cin >> i;
    return i;
}

ll nll() {
    ll l;
    cin >> l;
    return l;
}

int main() {
    ll N = nll();

    ll s = (ll)sqrt(N)+10;
    ll ans = INF;
    for (ll a=1; a<s; a++) {
        ll b = N/a;
        if (a * b == N) {
            ll M = max(a, b);
            ll count = 0;
            while(M>0) {
                count++;
                M /= 10;
            }
            ans = min(ans, count);
        }
    }

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

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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 単項演算子
	constexpr ModInt& operator++()
	{
		if (integer_ + 1 == mod_) integer_ = 0;
		else integer_++;
		return *this;
	}

	constexpr ModInt& operator--()
	{
		if (integer_ == 0) integer_ = mod_ - 1;
		else integer_--;
		return *this;
	}

	constexpr ModInt operator+()
	{
		return *this;
	}

	constexpr ModInt operator-()
	{
		if (integer_ == 0) return ModInt(0ll);
		else return ModInt(mod_ - integer_);
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}

	static constexpr int64_t mod{mod_};
};
using Mint = ModInt<>;

int main()
{
	int64_t N;
	scanf("%lld", &N);
	std::cout << (Mint(10)^N) - (Mint(9)^N) * Mint(2) + (Mint(8)^N) << '\n';

	return 0;
}

Measured memory_bytes: 3736
#include <cstdio>
#include <set>

int main() {
    int n;
    scanf("%d", &n);
    
    std::multiset<int> ms;
    int a, b, c;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d %d", &a, &b, &c);
        ms.insert(a);
        ms.insert(b);
        ms.insert(c);

        auto it = ms.begin();
        a = *it++;
        b = *it++;
        c = *it;
        
        printf(a*a + b*b == c*c ? "YES\n" : "NO\n");
        ms.clear();
    }
}

Measured memory_bytes: 1000
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  ll ans = 0;
  ll sum = 0;
  map<ll, ll> mp;
  mp[0] = 1;
  rep(i, n) {
    ll a;
    cin >> a;
    sum += a;
    ans += mp[sum];
    mp[sum]++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main()
 {
 	int n=5,i;
 	int a[n];
 	for(i=0;i<n;i++)
 		cin>>a[i];
 	for(i=0;i<n;i++)
 	{
 		if(a[i]==0)
 			cout<<i+1<<endl;
	 }
 	
 	
 	return 0;
}
 	
 					

Measured memory_bytes: 3588
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
	char s[4];
	cin >> s;
	if (!strcmp(s, "SUN")) cout << 7 << endl;
	if (!strcmp(s, "MON")) cout << 6 << endl;
	if (!strcmp(s, "TUE")) cout << 5 << endl;
	if (!strcmp(s, "WED")) cout << 4 << endl;
	if (!strcmp(s, "THU")) cout << 3 << endl;
	if (!strcmp(s, "FRI")) cout << 2 << endl;
	if (!strcmp(s, "SAT")) cout << 1 << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

ll N, X[1000], Y[1000];

int main() {
    cin >> N;
    REP(i, N) cin >> X[i] >> Y[i];

    bool ok = true;
    REP(i, N - 1) {
        ok &= ((X[i] + Y[i] + 10000000000) % 2) == ((X[i + 1] + Y[i + 1] + 10000000000) % 2);
    }
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> d = {1};
    bool even = (X[0] + Y[0] + 10000000000) % 2 == 0;
    if (even) d.push_back(1);
    REP(i, 30) d.push_back(d[d.size() - 1] * 2);

    cout << d.size() << endl;
    for (int n : d) cout << n << " "; cout << endl;

    reverse(ALL(d));
    REP(i, N) {
        string ans = "";
        for (int n : d) {
            if (abs(X[i]) > abs(Y[i])) {
                if (X[i] > 0) {
                    ans += "R";
                    X[i] -= n;
                }
                else {
                    ans += "L";
                    X[i] += n;
                }
            }
            else {
                if (Y[i] > 0) {
                    ans += "U";
                    Y[i] -= n;
                }
                else {
                    ans += "D";
                    Y[i] += n;
                }
            }
        }
        reverse(ALL(ans));
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n,m,ans;

main(){
	cin>>n;
	int a,b;
	cin>>ans;
	rep(i,n-1){
		cin>>b;
		ans=__gcd(ans,b);
		//dans;
	}
	dans;
}






Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;
int main() {
    int b,p,x,m=1,n;
    cin >> x;
    for(b=2; b<=1000; b++){
        for(p=2;p<=1000;p++){
            n = int(pow(b,p));
            if(n <= x) m = max(m, n);
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 512
s = raw_input()
ans = len(s)
for ch in set(s):
    t = ch + s + ch
    occ = [i for i in range(len(t)) if t[i] == ch]
    d = [occ[i+1] - occ[i] - 1  for i in range(len(occ)-1)]
    ans = min(ans, max(d))
print ans


Measured memory_bytes: 2568
#B - Count Balls
N,A,B = map(int,input().split())

balls = N - (A+B)*(N//(A+B))#最後の一回の操作で加えることのできるボールの個数
if balls <= A:
    ans = A * (N//(A+B)) + balls
else:
    ans = A * (N//(A+B)) + A
print(ans)

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

bool search(vector<int>& S, int target)
{
    int l = 0;
    int u = S.size() - 1;
    while (l <= u) {
        int m = l + (u - l) / 2;
        if (S[m] == target) {
            return true;
        }
        if (S[m] < target) {
            l = m + 1;
        } else {
            u = m - 1;
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    vector<int> S(n);
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }

    int ans = 0;
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        if (search(S, x)) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3140
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define PI			2*acos(0.0)
int main()
{
    int n,i;
    cin >>n;
    int a[n+1],c=0,y1,y2=0;
    for(i=1;i<=n;i++)
    {
        cin >>a[i];
        if(a[i]!=i)
        {
            if(c==0)
            {
                c++;
                y1=i;
            }
            else if(c==1)
            {
                c++;
                if(a[i]==y1)
                {
                    y2=1;
                }
            }
            
        }
    }
    if(c==2&&y2==1)
    {
        cout <<"YES";
    }
    else if(c==0)
    {
        cout <<"YES";
    }
    else
        cout <<"NO";
    return 0;
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> cards;
    for(int i = 1; i <= 2*n; ++i) {
        cards.push_back(i);
    }

    while(m--) {
        int k;
        cin >> k;
        if(k == 0) {
            vector<int> upper(cards.begin(), cards.begin()+n);
            vector<int> lower(cards.begin()+n, cards.end());
            for(int i = 0; i < n; ++i) {
                cards[i*2] = upper[i];
                cards[i*2+1] = lower[i];
            }
        }
        else {
            vector<int> upper(cards.begin(), cards.begin()+k);
            vector<int> lower(cards.begin()+k, cards.end());
            copy(upper.begin(), upper.end(), copy(lower.begin(), lower.end(), cards.begin()));
        }
    }
    for(int i = 0; i < cards.size(); ++i) {
        cout << cards[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
N = int(input())
ans = []
for h in range(1,3500):
  for n in range(1,3500):
    if (4*h*n - N*(h+n))>0 and (N*h*n)%(4*h*n - N*(h+n))==0:
        print(h,n,(N*h*n)//(4*h*n - N*(h+n)))
        exit()

Measured memory_bytes: 9168
N = int(input())
a = list(map(int, input().split()))

m = d = t = 0
for i in range(len(a)):
  if a[i] == 1:
    m += 1
  elif a[i] == 2:
    d += 1
  else:
    t += 1
    
M = t + d + m
D = [[[0] * (M + 1) for i in range(d + t + 1)] for j in range(t + 1)]

su = 0
D[t][d][m] = 1

divTable = [1]
for i in range(1, 10000):
  divTable.append(1.0 / i)


for i in range(t, -1, -1):
  for j in range(d + t - i, -1, -1):
    for k in range(M - i - j, -1, -1):
      y = D[i][j][k]
      if y != 0:
        div = y * divTable[i + j + k]
        if i + j + k != 0:
          su += N * div
        if i >= 1:
          D[i - 1][j + 1][k] += i * div
        if j >= 1: 
          D[i][j - 1][k + 1] += j * div
        if k >= 1:
          D[i][j][k - 1] += k * div

print(su)


Measured memory_bytes: 512904
#include <stdio.h>
    #include <stdlib.h>
     
    int main(void)
{
        int n;
        scanf("%d", &n);
     
        int i;
        int number[n];
        for(i = 0; i < n; i++){
            scanf("%d", &number[i]);
        }
        if(n == 1){
            printf("Yes\n");
        }
        else{
            int flag = number[0]; 
            for(i = 0; i < n-1; i++){
                if(number[i] - number[i+1] > 1 || flag - number[i+1] > 1){
                    printf("No\n");
                    break;
                }
                if(flag < number[i+1]){
                    flag = number[i];
                }
                if(i == n-2){
                    printf("Yes\n");
                }
            }
     
        }
     
     
        return 0;
    }

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;


string a[3];

int func(int i){
    int result=0;
    if(a[0][i]!=a[1][i] && a[0][i]!=a[2][i] && a[1][i]!=a[2][i])result=2;
    if(a[0][i]==a[1][i] && a[0][i]==a[2][i])result=0;
    else if(a[0][i]==a[1][i] || a[0][i]==a[2][i] || a[1][i]==a[2][i])result =1;
    return result;
}

int main(){
    int count=0;
    int n;
    cin >> n >> a[0] >> a[1] >> a[2];
    for(int i=0;i<n;i++){
        count += func(i);
        //cout << count ;
    }
    cout << count << endl;

}

Measured memory_bytes: 256
// THANK YOU MR SOLVING!!!!!!!!

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using std::sort;
using std::reverse;

using ll = long long;

#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())
#define push_back emplace_back
#define endl '\n'

class solver {
private:
    double TIME;

    static const ll INF = static_cast<ll>(1e9) + 7;
    static const int MAXN = static_cast<ll>(1e6) + 17;
    const int MAGIC = 62;

    int n;
    vector< vector<int> > g, dp;

public:
    static bool FLAG;

    solver() {
        TIME = static_cast<double>(clock()) / CLOCKS_PER_SEC;
    }

    bool read() {
        if (!(cin >> n))
            return false;

        g.resize(n);

        forn (i, n - 1) {
            int u, v;
            cin >> u >> v;
            g[u - 1].push_back(v - 1);
            g[v - 1].push_back(u - 1);
        }

        return true;
    }

    void dfs(int v, int p) {
        for (auto to : g[v])
            if (to != p)
                dfs(to, v);

        int sum = 0, mn = INF;

        for (auto to : g[v])
            if (to != p) {
                sum += max(dp[to][0], dp[to][1]);
                mn = min(mn, max(dp[to][0], dp[to][1]) - dp[to][0]);
            }

        dp[v][0] = sum;

        if (sz(g[v]) - (v != p) > 0)
            dp[v][1] = 1 + sum - mn;
    }

    void solve() {
        dp.resize(n, vector<int>(2, 0));
        dfs(0, 0);
        int mt = max(dp[0][0], dp[0][1]);

        if (mt * 2 == n)
            cout << "Second\n";
        else
            cout << "First\n";
    }

    ~solver() {
#ifdef SEREZHKA
        if (FLAG)
            cerr << "Time elapsed: " << static_cast<double>(clock()) / CLOCKS_PER_SEC - TIME << endl;
#endif
    }
};

bool solver::FLAG = true;

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(5);

#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');
#else
    std::mt19937 rand(time(NULL));
#endif

    while (solver::FLAG) {
        solver solution;

        if (!solution.read())
            solver::FLAG = false;
        else
            solution.solve();
    }

    return 0;
}


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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vpr){
    if(!vpr.empty()){
        auto x = vpr.front();
        ostr << x.first << " " << x.second;
        for(auto itr = ++vpr.begin(); itr != vpr.end(); itr++){
            x = *itr;
            ostr << endl << x.first << " " << x.second;
        }
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
// vll x(n); x[i]=a;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;
typedef vector<vector<ll>> vvll;
// vvll x(m,vi(n)); x[i][j]=a;

#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll n, ans = 0;
    cin >> n;
    vll a(n);
    cin >> a;
    REP(i,n) ans ^= a[i];
    if(ans == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#include <map>

#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k;
  int n;
  cin >> n >> k;
  vector<int> to(n+1);
  REP(i,n) {
    int a;
    cin >> a;
    to[i+1] = a;
  }

  ll lens = 0;
  vector<int> seen(n+1);
  ll pos = 1;
  seen[1] = 1;
  vector<int> path(1);
  path[0] = 1;

  ll last = 0;

  for(;;) {// times;
    pos = to[pos];
    if( seen[pos] == 1 ) { // aready in seen
      path.push_back(pos);
      last = pos;
      break;
    }
    else {
      seen[pos] = 1;
      path.push_back(pos);
    }
  }
  ll lenp = path.size();
  ll lenr = 0;
  ll st = 0;
  for(int i = 0; i < lenp; ++i ) {
    if(path[i] == last) {
      st = i;
      //cout << st << endl;
      lenr = lenp - 1 - i;
      break;
    }
  }
//
//  REP(i,lenp) {
//    cout << path[i] << "  ";
//  }
//  cout << endl;

  path.pop_back();
  lenp--;

  if( k <= lenp) {
    cout << path[k] << endl;

  }
  else {
    k -= st;
    ll r = k % lenr;
    int ret = path[r+st];
    cout << ret << endl;
  }
  return 0;

}



Measured memory_bytes: 5376
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void solve(){
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;++i)
	cin>>arr[i];
	int num=1;
	int idx=-1;
	for(int i=0;i<n;++i)
	if(arr[i]==num)
	{
		idx=i;
		num++;
		break;
	}
	if(idx==-1){
		cout<<idx;
		return ;
	}
	int ans=idx;
	int pre=idx;
	for(int i=idx;i<n;++i){
		if(arr[i]==num){
			ans+=i-pre-1;
			pre=i;
			num++;
		}
	}
	ans+=n-1-pre;
	cout<<ans;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;//cin>>t;
	t=1;
	while(t--)//
	solve();
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
	     if ((B%A)==0){
	         System.out.println(A + B);
         } else {
             System.out.println(B - A);
         }
	     scanner.close();
    }
}

Measured memory_bytes: 21844
/// Template by Zayed ///

///************************************************************///
/// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>

#include <string>
#include <cstring>
#include <sstream>

#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
//#include<unordered_map>
#include <set>
//#include<unordered_set>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
///************************************************************///
using namespace std;
int caseno = 1;
///************************************************************///
#define NL '\n'
#define SF scanf
#define PF printf
#define PC() printf("Case %d: ", caseno++)//NOTES:printf
//#define PC cout << "Case "//NOTES:cout
//#define CN cout << caseno++ << ": "//NOTES:cout
#define CLR(ar) memset(ar, 0, sizeof(ar))
#define SET(ar) memset(ar, -1, sizeof(ar))
#define READ() freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST std::ios_base::sync_with_stdio(0);
///************************************************************///
typedef long long LL;//NOTES:"%lld"
typedef unsigned long long ULL;//NOTES:"%llu"
///************************************************************///
#define INF (1 << 31) - 1
#define MOD 1000000007
#define PRIME 999998727899999 			// (largest prime below 10^16)
#define PB push_back
#define pii pair<int, int>
#define pic pair<int, char>
#define pci pair<char, int>
#define pLL pair<LL, LL>
#define pis pair<int, string>
#define psi pair<string, int>
#define pss pair<string, string>
#define PI 2 * acos(0.0)
#define EPS 1e-11
///************************************************************///
// Numeric Functions
template < class T > inline void SWAP(T &a, T &b) { T t = a; a = b; b = t; }
inline LL POW(LL base, LL power){
	LL res = base; if (power == 0) return 1;
	for (int I = 0; I < power - 1; I++) res *= base; return res;
}
// Translator Functions
int ToInt(string s) { int r = 0; istringstream sin(s); sin >> r; return r; }//NOTES:ToInt(
double ToDouble(string s) { double r = 0; istringstream sin(s); sin >> r; return r; }//NOTES:ToDouble(
string ToString(int n) { string s; stringstream convert; convert << n; s = convert.str(); return s; }//NOTES:ToString(
///************************************************************///

/*
*******4 Direction Array*******
int dx[] = {0, 0, - 1, 1}, dy[] = {-1, 1, 0, 0};
*******8 Direction Array*******
int dx[] = {0, 0, -1, +1, -1, -1, +1, +1}, dy[] = {-1, +1, 0, 0, -1, +1, -1, +1};
********Knight Moves********
int dx[] = {-2, -2, -1, -1, +1, +1, +2, +2}, dy[] = {-1, +1, -2, +2, -2, +2, -1, +1};
*/

const int SIZE = 1e6;


int main()
{
	BOOST
	///READ();
	///WRITE();
	int T, I, J, K, N, n, m, cnt = 0, len, A, B, C, D;

	cin >> A >> B >> C >> D;

	m = min(B, D) - max(A, C);

	if(m < 0)
		cout << 0 << NL;
	else
		cout << m << NL;

	return 0;
}






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

using namespace std;
typedef long long ll;

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

  set<string> has = {};

  ll ans = 0;
  for (auto i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    if (has.count(s) == 0)
    {
      has.insert(s);
      ans++;
    }
  }

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


Measured memory_bytes: 19148
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
vector<ll> v[2009];
ll vis[2009],dis[2009];
ll ans[2009];
void bfs(ll node,ll n)
{
    queue<ll> q;
    q.push(node);

    for(ll i=1;i<=n;i++)
    {
        dis[i]  =0;
        vis[i]  = 0;
    }
    vis[node] = 1;
    while(!q.empty())
    {
        ll temp = q.front();

        q.pop();

        for(ll i=0;i<v[temp].size();i++)
        {
            if(vis[v[temp][i]]==0)
            {
                vis[v[temp][i]]= 1;
                q.push(v[temp][i]);
                dis[v[temp][i]] = dis[temp] +1;
            }
        }
    }
    for(ll i =node+1;i<=n;i++)
    {

        ans[dis[i]]++;
    }
}
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    sf(n);
    sff(x,y);
    v[x].pb(y);
    v[y].pb(x);
    for(i=1;i<=n-1;i++)
    {
        v[i].pb(i+1);
        v[i+1].pb(i);
    }
    for(i=1;i<n;i++)
    {
        bfs(i,n);
    }
    for(i=1;i<=n-1;i++)
    {
        cout<<ans[i]<<endl;
    }

    return 0;
}



Measured memory_bytes: 384
#include <climits>
#include <iostream>
#include <iterator>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

void mergeSort(vector<pair<char, int>>::iterator a, vector<pair<char, int>>::iterator b) {
	if (b > next(a)) {
		mergeSort(a, next(a, (b - a) / 2));
		mergeSort(next(a, (b - a) / 2), b);
		queue<pair<char, int>> c, d;
		for (vector<pair<char, int>>::iterator i = a; i != next(a, (b - a) / 2); ++i) c.push(*i);
		c.emplace(0, INT_MAX);
		for (vector<pair<char, int>>::iterator i = next(a, (b - a) / 2); i != b; ++i) d.push(*i);
		d.emplace(0, INT_MAX);
		for (vector<pair<char, int>>::iterator i = a; i != b; ++i) {
			if (c.front().second <= d.front().second) {
				*i = c.front();
				c.pop();
			}
			else {
				*i = d.front();
				d.pop();
			}
		}
	}
}

void quickSort(vector<pair<char, int>>::iterator a, vector<pair<char, int>>::iterator b) {
	if (a < b) {
		vector<pair<char, int>>::iterator i = a;
		for (vector<pair<char, int>>::iterator j = a; j != prev(b); ++j) {
			if (prev(b)->second >= j->second) {
				swap(*i, *j);
				++i;
			}
		}
		swap(*i, *prev(b));
		quickSort(a, i);
		quickSort(next(i), b);
	}
}

int main() {
	int n;
	cin >> n;
	vector<pair<char, int>> a(n);
	for (pair<char, int>& i : a) cin >> i.first >> i.second;
	vector<pair<char, int>> b = a;
	mergeSort(a.begin(), a.end());
	quickSort(b.begin(), b.end());
	if (a == b) cout << "Stable";
	else cout << "Not stable";
	cout << endl;
	for (pair<char, int>& i : b) cout << i.first << ' ' << i.second << endl;
}


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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    int x,y,ca,cb,cc; cin >> x >> y >> ca >> cb >> cc;
    vi a(ca), b(cb), c(cc);
    forn(i, ca) cin >> a[i]; 
    forn(i, cb) cin >> b[i]; 
    forn(i, cc) cin >> c[i]; 

    sort(all(a), greater<int>());
    sort(all(b), greater<int>());
    sort(all(c), greater<int>());

    priority_queue<int> q;
    forn(i, x) q.push(a[i]);
    forn(i, y) q.push(b[i]);
    forn(i, cc) q.push(c[i]);

    ll ans = 0;
    int t = x + y;
    forn(i, t) ans += q.top(), q.pop(); 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3572
import sys
input=sys.stdin.readline


def solve():
    N = int(input())
    S = input()
    Q = int(input())
    *k, = map(int, input().split())

    acd = [0]*(N+1)
    acm = [0]*(N+1)
    acc = [0]*(N+1)
    acmc = [0]*(N+2)

    for i in range(1, N+1):
        acd[i] = acd[i-1] + (S[i-1]=="D")
        acm[i] = acm[i-1] + (S[i-1]=="M")
        acc[i] = acc[i-1] + (S[i-1]=="C")

    ans = 0
    for i in range(1, N+1):
        if S[i-1]=="M":
            ans += acd[i-1]*(acc[N]-acc[i])

    for i in range(1, N)[::-1]:
        acmc[i] += acmc[i+1]
        if S[i-1]=="M":
            acmc[i] += acc[N]-acc[i]

    for i in k:
        v = 0
        for j in range(1, N+1):
            if S[j-1]=="D":
                v += (acm[min(N, i+j-1)]-acm[j]) * (acc[N]-acc[min(N, i+j-1)]) + acmc[min(i+j, N)]
        print(ans-v)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 83312
n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]

left = 0
right = 10000 * n

def Chech(P,k,arr):
    weight = 0
    n_trucks = 1
    for i,a in enumerate(arr):
        # iの荷物について積むかどうか決め、それに応じてトラックの数を増加させる
        if P < a:
            return i
        if weight +a <= P:
            weight += a
        else:
            n_trucks += 1  # Pを超えるなら次のtruckを用意
            weight = a  # 新たなトラックに積んでいる
        if n_trucks == k + 1:  # k+1台目のtruckは存在しない。これまでに積んだ荷物の数を返す
            return i

    return len(arr)  # すべて運べるならlen(arr)を返すとする

# right - left > 0　だと無限ループに入るっぽい
while right - left > 1:
    mid = (left+right)//2
    v = Chech(mid,k,W)

    if v >= n:
        right = mid
    else:
        left = mid

print(right)


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

int main(){
    int N; vector<Int> A(100);
    cin >> N;
    rep(i,N) cin >> A[i];

    Int ans = 0;
    rep(i, N){
        rep(j, N){
            ans = max(ans, abs(A[i]-A[j]));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,l;
	string a;
	string ans;
	cin >> n >> l;
	vector <string> v;
	while(n--){
		cin >> a ;
		//cout << a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	for(auto x:v){
		cout << x;
	}
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3596
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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



class DDisjointSetOfCommonDivisors {
public:
    int dy[4]={-1,1,0,0};
    int dx[4]={0,0,1,-1};

    void primeFactorDecomposition(ll n, unordered_map<ll, ll> &primeFactor) {
        ll maxFactor = sqrt(n) + 1;
        FOR(i, 2, maxFactor) {
            while(n % i == 0) {
                n /= i;
                primeFactor[i]++;
            }
        }
        if (n != 1) {
            primeFactor[n] += 1;
        }
    }

	void solve(std::istream& in, std::ostream& out) {
        ll A, B;
        in >> A >> B;
        unordered_map<ll, ll> primeFactor1, primeFactor2;
        primeFactorDecomposition(A, primeFactor1);
        primeFactorDecomposition(B, primeFactor2);
        ll ans = 1;
        for(auto x: primeFactor1) {
            if (primeFactor2[x.first]) {
                ans++;
            }
        }
        out << ans << endl;
	}
};


int main() {
    ios::sync_with_stdio(false);
	DDisjointSetOfCommonDivisors solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(100001, 0);
    rep(i, n){
        int A;
        cin >> A;
        a[A]++;
    }

    int ans = 0;
    rep(i, 99999){
        int sum = a[i] + a[i + 1] + a[i + 2];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import sys
a = []
for l in sys.stdin:
    a.append(l)
h1, m1, h2, m2, k  = a[0].split()
H1, M1, H2, M2, K = int(h1), int(m1), int(h2), int(m2), int(k)
time = 60 * H2 + M2 - (60*H1 + M1) - K
print(time)


Measured memory_bytes: 9172
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int s = sc.nextInt();
    int point = 0;
    for(int i = 0;i <= k;i++){
      for(int j = 0;j <= k;j++){
        int z = s-i-j;
        if(0 <= z && z <= k){
          point++;
        }
      }
    }
    System.out.println(point);
  }
}


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

using namespace std;

#define LL long long
#define reg register
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a )
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a )
#define debug(x) cerr<<#x<<" = "<<x<<endl;

template<class T>inline bool Max(T &a,T b) {
	return a<b?a=b,1:0;
}
template<class T>inline bool Min(T &a,T b) {
	return a>b?a=b,1:0;
}

inline int Read(void) {
	int res=0,flag=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')flag=0;
	do res=(res<<1)+(res<<3)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return flag?res:-res;
}

const int N=2e3+5,M=1e6+5,mod=1e9+7;
const int dx[4]= {1,-1,0,0},dy[4]= {0,0,1,-1};

int n,m;

char S[5];

int main(void) {
	scanf("%s",S);
	int f=0;
	rep(i,1,3)if(S[i]==S[i-1])f=1;
	if(f)printf("Bad");
	else printf("Good");
	return 0;
}

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


class Main{	
	
	public static void main (String[] args)throws IOException{
		InputStreamReader in = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(in);
		
		String name = reader.readLine();
		char[] data = name.toCharArray();
		
		for(int i=data.length-1;i>=0;i--){
			System.out.print(data[i]);
		}
		System.out.println();
		
	}
}

Measured memory_bytes: 9184
n = gets.to_i
nums = gets.split.map(&:to_i).sort {|a, b| b <=> a}
sum_a = 0
sum_b = 0

(1..n).each do |i|
  if (i%2).zero?
    sum_b += nums[i-1]
  else
    sum_a += nums[i-1]
  end
end

puts sum_a - sum_b

Measured memory_bytes: 1788
//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


namespace {
    // printElems(&a[0], &a[n]);　みたいな感じで使う。
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << ' ';
        }
        std::cout << std::endl;
    }
}

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 1LL<<60;


ll wlist[105];
ll vlist[105];
ll dp[105][200005];


int main(){
	int n,w;
	cin >> n >> w;
	rep1(i,n) cin >> wlist[i] >> vlist[i];
	rep(i,104)rep1(j,200005) dp[i][j]= BIG;
	rep(i,105) dp[i][0] = 0;
	//prints("1 1 ", dp[1][1],' ', dp[0][1]);

	rep1(j,n){
		//prints(wlist[j],vlist[j]);

		rep1(i,100005){
			dp[j][i] = min(dp[j-1][i],dp[j-1][max(0LL,i-vlist[j])]+wlist[j]);
		}
	}
	ll m = 0;
	repr(i,100005) if(dp[n][i] <= w) {m = i; break;}

	prints(m);



	return 0;
}



Measured memory_bytes: 164096
from itertools import accumulate


def expectation(n):
    n = int(n)
    return n * (n + 1) // 2 / n


N, K = map(int, input().split())
acc_E = [0.0] + list(accumulate(map(expectation, input().split())))
print(max(acc_E[i + K] - acc_E[i] for i in range(N - K + 1)))


Measured memory_bytes: 23664
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
queue < int > q;
int n;
const int maxN = 1e5 + 10;
vector < int > g[maxN];
int dist[maxN][2];
void calc(int v, int id) {
    for (int i = 1; i <= n; i++) dist[i][id] = -1;
    dist[v][id] = 0;
    q.push(v);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int to : g[v]) {
            if (dist[to][id] == -1) {
                dist[to][id] = dist[v][id] + 1;
                q.push(to);
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    calc(1, 0);
    calc(n, 1);
    int bal = 0;
    for (int i = 1; i <= n; i++) {
        if (dist[i][0] <= dist[i][1]) bal++;
        else bal--;
    }
    cout << ((bal > 0) ? "Fennec" : "Snuke");
    return 0;
}

Measured memory_bytes: 6656
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let (a, b, t) = get!(usize, usize, usize);

    println!("{}", t / a * b);
}


Measured memory_bytes: 8572
n=int(input())
a=list(map(int, input().split()))
b=[0]*n
ans=0

for i in range(n):
    b[a[i]-1]+=1
for i in range(n):
    ans+=(b[i]*(b[i]-1))//2
for i in range(n):
    print(ans-b[a[i]-1]+1)


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

int N,K;
int sum[100010] = {};
string S;
int main(){
    cin >> N >> K >> S;
    for(int i=0;i<N;i++){
        if(S[i]!=S[i+1]) sum[i+1] = 1;
        sum[i+1] += sum[i];
    }
/*    for(int i=0;i<=N;i++) cerr << sum[i] << " ";
    cerr << endl;
*/    int l = 1,r = N+1;
    while(l+1<r){
        int m = (l+r)/2;
        bool judge = false;
        for(int i=1;i+m-1<=N;i++){
            int c = sum[i+m-1]-sum[i-1];
            if(S[i-1]=='1') c--;
            if(S[i+m-2]=='1') c--;
            if(c/2+1<=K) judge = true;
        }
        if(judge) l = m;
        else r = m;
    }
    cout << l << endl;
}

Measured memory_bytes: 896