akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;
namespace Arithmetics {
	template<typename T>
	T original_pow(T a, T b) {
		T ans = 1;
		rep(i, b) {
			ans *= a;
		}

		return  ans;
	}
	template<typename T>
	T gcd(T a, T b) {
		if (a > b) {
			T c = a;
			a = b;
			b = c;
		}
		if (a == 0) {
			return b;
		}

		return gcd(b % a, a);
	}
	template<typename T>
	T gcd_of_all(vector<T> v) {
		T temp = v[0];
		for (T elem : v) {
			temp = gcd(temp, elem);
		}

		return temp;
	}
	template<typename T>
	T lcm(T a, T b) {
		T GCD = gcd(a, b);
		return a * b / GCD;
	}
	template<typename T>
	T lcm_of_all(vector<T> v) {
		T temp = v[0];
		for (T elem : v) {
			temp = lcm(temp, elem);
		}
		return temp;
	}
}
using namespace Arithmetics;
void prob138() {
	int N; cin >> N;
	priority_queue<double,vector<double>,greater<double>> pq;
	for (int i = 0; i < N; i++) {
		double x;
		cin >> x;
		pq.push(x);
	}

	for (int i = 0; i < N - 1; i++) {
		double x = pq.top(); pq.pop();
		double y = pq.top(); pq.pop();
		double z = (x + y) / 2;
		pq.push(z);
	}

	printf("%.10lf\n", pq.top());
}

void prob136() {
	int N; cin >> N;
	int max = 0, min = int_INF;
	bool flag = false;
	rep(i, N) {
		int x; cin >> x;
		if (x > max) {
			max = x; min = int_INF;
		}
		x <= min ? min = x : 1;
		if (max - min > 1) {
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

void prob140() {
	int N; cin >> N;
	vector<int> B(N + 1);
	B[0] = int_INF; B[N] = int_INF;
	for (int i = 1; i < N; i++) {
		cin >> B[i];
	}
	ll ans = 0;
	for (int j = 0; j < N; j++) {
		ans += min(B[j], B[j + 1]);
	}

	cout << ans << endl;
}

void prob141() {
	int N, K, Q; cin >> N >> K >> Q;
	vi Contestants(N);
	rep(i, Q) {
		int x;
		cin >> x;
		Contestants[--x]++;
	}

	rep(i, N) {
		if (Contestants[i] + K - Q > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

void prob148() {
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
}
bool is_prime[100000000 + 1];
vi Eratosthenes(const int N) { // return primes up to N
	vector<int> P;
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}
void prob149() {
	int x; cin >> x;
	vi Eratos = Eratosthenes(1000003);
	auto iter = lower_bound(Eratos.begin(), Eratos.end(), x);
	int index = distance(Eratos.begin(), iter);
	cout << Eratos[index] << endl;
}
int main() {
	prob149();
}

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,m;
  long ans = 0;
  cin >> n >> m;
  if(n==1){
    if(m==1)ans = 1;
    else ans = m-2;
  }else if(m==1) ans = n-2;
  else ans = n*m-2*(n+m)+4;

  cout << ans;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    s = "".join(sorted(input()))
    dic = {s:1}
    ans = 0
    for _ in range(N-1):
        s = "".join(sorted(input()))
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    for i in dic.values():
        ans += (i*(i-1))//2
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 17852
V,m = map(int,input().split())

from collections import defaultdict
g = defaultdict(list)
deg = defaultdict(int)
for _ in range(m):
    x,y = map(int,input().split())
    g[x-1].append(y-1)
    deg[y-1] += 1
    
# V: 頂点数
# G[v] = [w, ...]:
#    有向グラフ上の頂点vから到達できる頂点w
# deg[v]:
#    頂点vに到達できる頂点の数

from collections import deque
ans = list(v for v in range(V) if deg[v]==0)
deq = deque(ans)
used = [0]*V
while deq:
    v = deq.popleft()
    for t in g[v]:
        deg[t] -= 1
        if deg[t]==0:
            deq.append(t)
            ans.append(t)

# ans: トポロジカル順序に並べた頂点

dp = [0 for i in range(V)]

for a in ans:
    for b in g[a]:
        dp[b] = dp[a] + 1

print(max(dp)) 

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    REP(i,N) cin >> m[i];
    int res = 100100;
    REP(i,N) res = min(res,m[i]);
    int cost = 0;
    REP(i,N)cost += m[i];
    int count = N;
    while(cost <= X){
        cost += res;
        count++;
    }
    cout << count - 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint n;
	cin >> n;
	vector<lint> nums(n);
	loop(i, n)
	{
		cin >> nums[i];
		nums[i] -= (i + 1);
	}
	sort(nums.begin(), nums.end());

	//loop(i, n)cout << nums[i];
	//cout << endl;

	lint mid = n / 2;
	lint ans = 0;
	loop(i, n)
	{
		ans += abs(nums[i] - nums[mid]);
	}
	cout << ans << endl;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int N, K, d;
  cin >> N >> K;
  vector<bool> D(9, true);
  rep(i, 0, K) cin >> d, D[d] = false;

  queue<int> que;
  que.push(0);
  vector<int> ans;
  while (!que.empty()) {
    int q = que.front();
    que.pop();
    rep(i, 0, 10) if (D[i]) {
      int next = q * 10 + i;
      if (next == 0)
        continue;
      else if (next >= N)
        pb(ans, next);
      else
        que.push(next);
    }
  }

  cout << ans[0] << '\n';
  return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int R; cin >> R;
  if (R < 1200) cout << "ABC" << endl;
  else if (R < 2800) cout << "ARC" << endl;
  else               cout << "AGC" << endl;
}


Measured memory_bytes: 3608
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

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

    char ch;

    cin>>ch;

    if(ch >= 'A' && ch <= 'Z')
        cout<<"A"<<endl;
    else
        cout<<"a"<<endl;

    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>

int strToInt(int i,char* str)
{
  int rtnnum;
  
  switch(str[i])
    {
    case '1':
      rtnnum = 1;
      break;
    case '2':
      rtnnum = 2;
      break;
    case '3':
      rtnnum = 3;
      break;
    case '4':
      rtnnum = 4;
      break;
    case '5':
      rtnnum = 5;
      break;
    case '6':
      rtnnum = 6;
      break;
    case '7':
      rtnnum = 7;
      break;
    case '8':
      rtnnum = 8;
      break;
    case '9':
      rtnnum = 9;
      break;
    case '0':
      rtnnum = 0;
      break;
    }
  return rtnnum;
}

int main(void){
  char num[1000]={0};
  int sum;
  int i;

  while(1)
    {
      gets(num);
      if(num[0]=='0')
        {
          break;
        }
      sum=0;
      for(i=0;i<1000;i++)
        {
          if(num[i] == '\0')
            {
              break;
            }
          sum += strToInt(i,num);
        }
      printf("%d\n",sum);
    }
  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const double PI = acos(-1);
const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

const int D = 55;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n, x, m;
    cin >> n >> x >> m;
    auto next = make_vec(D + 1, m, -1LL);
    auto sum = make_vec(D + 1, m, 0LL);
    for(ll i = 0; i < m; ++i){
        next[0][i] = i * i % m;
        sum[0][i] = i;
    }
    rep(i, D){
        rep(j, m){
            next[i + 1][j] = next[i][next[i][j]];
            // j(開始点)から2^i個分の総和 + jから2^i個辿った先から2^i個分の総和 = jから2^(i+1)個分の総和
            sum[i + 1][j] = sum[i][j] + sum[i][next[i][j]];
        }
    }
    ll ans = 0;
    int cur = x;
    for(int i = D; i >= 0; --i){
        if(n & (1LL << i)){
            ans += sum[i][cur];
            cur = next[i][cur];
        }
    }
    print(ans);





}


Measured memory_bytes: 91588
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int n;
double dp[305][305][305];

double rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;
    double res = 0.0;
    if (i > 0) res += rec(i-1, j, k) * i;
    if (j > 0) res += rec(i+1, j-1, k) * j;
    if (k > 0) res += rec(i, j+1, k-1) * k;
    res += n;
    res /= i+j+k;
    return dp[i][j][k] = res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n;
    int one = 0, two = 0, three = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if (a == 1) one++;
        else if (a == 2) two++;
        else three++;
    }
    memset(dp, -1, sizeof(dp));
    cout << fixed << setprecision(15) << rec(one, two, three) << endl;
}

Measured memory_bytes: 221952
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    int a, b, c, k;
    int max;
    int t;
    cin >> a >> b >> c >> k;

    if (a >= b) {
        if (a >= c) {
            max = a;
            t = 1;
        }
        else {
            max = c;
            t = 3;
        }
    }
    else {
        if (b >= c) {
            max = b;
            t = 2;
        }
        else {
            max = c;
            t = 3;
        }
    }

    for (int i = 0; i < k; i++) {
        max = 2*max;
    }

    if (t == 1) {
        cout << max+b+c << endl;
    }
    else if(t == 2) {
        cout << a+max+c << endl;
    }
    else {
        cout << a+b+max << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a[31] = {0},i,input;
    for(i = 1;i <= 28;i++){
        scanf("%d",&input);
        a[input] = 1;
    }
    for(i = 1;i <= 30;i++){
        if(a[i] != 1){
            printf("%d\n",i);
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
using namespace std;
#define ll long int
int main()
{
ll n;
cin>>n;
ll res=0;
ll a=(n/500);
res+=a*1000;
n=n%500;
a=(n/5);
res+=a*5;
cout<<res;


return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int h, n;
long long sum;

int main() { 

  cin >> h >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
  }

  cout << ((sum >= h) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >> F;
  double max_concentration = 0.0;
  int max_sugar, max_water;
  bool max_set = false;
  for(int a = 0; 100*A*a<=F; a++){
    for(int b = 0; 100*B*b<=F-100*A*a; b++){
      if(a==0&&b==0) continue;
      int sugar_limit = min(F-100*A*a-100*B*b,(A*a+B*b)*E);
      int sugar_max = 0;
      for(int c = 0; C*c<=sugar_limit; c++){
        for(int d = 0; D*d<=sugar_limit-C*c; d++){
          if(C*c+D*d>sugar_max) sugar_max = C*c+D*d;
        }
      }
      double concentration = 1.0*sugar_max/(100*A*a+100*B*b+sugar_max);
      if(!max_set||concentration>max_concentration){
        max_concentration = concentration;
        max_sugar = sugar_max;
        max_water = (A*a+B*b)*100;
        max_set = true;
      }
    }
  }
  cout << max_sugar+max_water << " " << max_sugar << endl;
}


Measured memory_bytes: 256
#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>
typedef long long ll;
using namespace std;

void LinearApporoximation() {
	int N;
	cin >> N;
	const int MAX_N = 200010;
	ll  t[MAX_N];
	for (int i = 0; i < N; i++)
	{
		cin >> t[i];
		t[i] -= (i + 1);
	}

	sort(t, t + N);
	ll v ;
	if (N % 2 == 0)
	{
		v = (t[N / 2] + t[N / 2 - 1]) / 2;
	}
	else {
		v = t[N / 2];
	}
	ll res = 0;
	for (int i = 0; i < N; i++)
	{
		res += abs(t[i] - v);
	}
	cout << res << endl;
}

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

Measured memory_bytes: 1792
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
p = list(map(int, input().split()))

q = []

for value in p:
    q.append((value + 1) / 2)

sm = [sum(q[:K])]
for i in range(1, N-K+1):
    sm.append(sm[-1] - q[i-1] + q[i+K-1])

print(max(sm))

Measured memory_bytes: 25632
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
  int n,a,b,i,g=0,p=0;
  string s;
  cin >> n >> a >> b >> s;
  for (i=0;i<n;i++){
    if (s[i]=='a' && p<a+b){
      cout << "Yes" << endl;
      p++;
    }else if (s[i]=='b' && p<a+b && g<b){
      cout << "Yes" << endl;
      p++;
      g++;
    }else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

int main() {

  ll N, x;
  cin >> N >> x;

  vector<ll> c(N);
  rep(i, N) { cin >> c[i]; }

  ll cnt = 0;
  if (c[0] > x) {
    cnt = c[0] - x;
    c[0] = x;
  }
  repi(i, 1, N) {
    if (c[i-1] + c[i] > x) {
      ll tmp = c[i];
      c[i] = x - c[i - 1];
      cnt += tmp - c[i];
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 1024
n,*a=`dd`.split.map &:to_i
p (1...2*n).bsearch(&->x{
	b=a.map{|e|e<x}
	1.upto(n-1){|i|
		return b[n+i-1] if b[n+i-1]==b[n+i-2]
		return b[n-i-1] if b[n-i-1]==b[n-i-0]
	}
	b[0]
})-1

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

using ll = long long;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)

/***** MAIN *****/
signed main() {
  int n;
  scanf("%d", &n);
  int bars[n];
  ll sum_from_begin[n] = {}, sum_from_end[n] = {};
  REP(i, n) {
    scanf("%d", &bars[i]);
    if(i == 0) sum_from_begin[i] = bars[i];
    else {
      sum_from_begin[i] = sum_from_begin[i-1] + bars[i];
    }
  }
  sum_from_end[0] = sum_from_begin[n-1];
  REPS(i, 1, n) {
    sum_from_end[i] = sum_from_end[i-1] - bars[i-1];
  }
  ll ans = abs(sum_from_begin[0] - sum_from_end[1]);
  if(ans == 0) {
    cout << 0 << "\n";
    return 0;
  }
  REPS(i, 1, n-1) {
    ans = min(ans, abs(sum_from_begin[i] - sum_from_end[i+1]));
    if(ans == 0) {
    cout << 0 << "\n";
    return 0;
  }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/

Measured memory_bytes: 4096
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

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

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n = II()
if n == 1 or n == 2:
    print(n)
else:
    max_element = 0
    index = 1
    for i in range(1, n+1):
        for j in range(i):
            if index == n + 1:
                break
            max_element = i
            index += 1
    s = 0
    for num in range(max_element, 0, -1):
        s += num
        if s <= n:
            print(num)
        else:
            s -= num


Measured memory_bytes: 71512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(u==s){
        cout<<a-1<<" "<<b<<endl;
    }
    else{
        cout<<a<<" "<<b-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (T& x : v) is >> x;
    return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    if (!v.empty()) {
        os << v.front();
        for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];
    }
    return os;
}

int main() {
#ifdef LBT
    freopen("test.in", "r", stdin);
    int nol_cl = clock();
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M));
    cin >> A;
    vector<pair<int, pair<int, int>>> pos;
    pos.reserve(N * M);
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < M; ++j) pos.emplace_back(A[i][j], make_pair(i, j));
    sort(pos.begin(), pos.end());
    int ans = numeric_limits<int>::max();
    for (int rep = 1; rep <= 4; ++rep) {
        int mx = numeric_limits<int>::min(), mn = numeric_limits<int>::max();
        vector<int> R(N);
        for (int i = 0; i < N * M - 1; ++i) {
            int x, y;
            tie(x, y) = pos[i].second;
            while (x >= 0 && R[x] <= y) {
                while (R[x] <= y) {
                    mx = max(mx, A[x][R[x]]);
                    mn = min(mn, A[x][R[x]]);
                    ++R[x];
                }
                --x;
            }
            ans = min(ans, max(pos.back().first - pos[i + 1].first, mx - mn));
        }
        if (rep & 1) {
            reverse(A.begin(), A.end());
            for (auto& pr : pos) pr.second.first = N - 1 - pr.second.first;
        } else if (rep & 2) {
            for (int i = 0; i < N; ++i) reverse(A[i].begin(), A[i].end());
            for (auto& pr : pos) pr.second.second = M - 1 - pr.second.second;
        }
    }
    cout << ans << '\n';

#ifdef LBT
    LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
    return 0;
}


Measured memory_bytes: 65472
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 field[3001][3001];
s64 dp[3001][3001][4];

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

    int r, c, k;
    cin >> r >> c >> k;

    // vector< vs64 > field(r + 1, vs64(c + 1, 0));
    rep (i, k)
    {
        int r, c, v;
        cin >> r >> c >> v;
        field[r][c] = v;
    }

    // vector< vector< vs64 > > dp(r + 1, vector<vs64>(c + 1, vs64(4)));
    // rep (i, r + 1) rep (j, c + 1) rep (k, 4) dp[i][j][k] = 0;

    rep (i, r + 1)
    {
        rep (j, c + 1)
        {
            rep (k, 4)
            {
                if (i < r)
                {
                    if (field[i + 1][j] > 0)
                    {
                        dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][k] + field[i + 1][j]);
                    }
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
                }
                if (j < c)
                {
                    if (field[i][j + 1] > 0 && k < 3)
                    {
                        dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + field[i][j + 1]);
                    }
                    dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
                }
            }
        }
    }

    s64 ans = 0;
    rep (i, 4) ans = max(ans, dp[r][c][i]);
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 355284
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin>>n;
    vector<ll> vec(5);
    rep(i,n) {
        string s;
        cin>>s;
        if(s[0]=='M') vec[0]++;
        if(s[0]=='A') vec[1]++;
        if(s[0]=='R') vec[2]++;
        if(s[0]=='C') vec[3]++;
        if(s[0]=='H') vec[4]++;
    }
    
    vector<int> perm={0,1,2,3,4};
    ll ans=0;
    do{
        ans+=vec[perm[0]]*vec[perm[1]]*vec[perm[2]];
    }while(next_permutation(all(perm)));
    cout<<ans/12<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  string ans = "Good";
  string s; cin >> s;
  for (int i = 1; i < s.size(); i++) {
    if (s[i - 1] == s[i]) {
      ans = "Bad";
      break;
    }
  }

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


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

#define mod 1000000007
#define modd 998244353
#define PI 3.1415926
#define ll long long
#define ld long double
#define pb push_back
#define popb pop_back
#define beg begin()
#define en end()
#define sz(v) (int)((v).size())
#define all(v) (v).begin(),(v).end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define endl "\n"
#define forn(i,a,n) for(int i=a;i<int(n);++i)
#define forb(i,a,n) for(int i=int(n)-1;i>=a;--i)
#define cout(ans) cout<< ans << "\n"
#define couts(ans) cout<< ans <<" "
#define coutss(a,b) cout<< a <<" "<< b << "\n"
#define coutsm(a,b,c) cout<< a <<" "<< b <<" "<< c << "\n"
#define maxx *max_element
#define minn *min_element


void speed()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
}





void solve()
{      
    int n;cin>>n;
    int a[n];
    int cnt=0;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<n;++j)
        {
            for(int k=j+1;k<n;++k)
            {
                if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k])
                {
                    cnt++;
                }
            }
        }
    }
    cout(cnt);

}


int main()
{   
    speed();
    int tc=1;
    // cin>>tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {


	public static void main (String[] args)  {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int c = Math.max(a,b);
		int d = Math.min(a, b);
		
		
		String str = "";
		for (int i=0;i<c;i++) {
			str += d;
		}
		
		System.out.println(str);
		
	}
	
	
}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#define INF 1 << 30
using namespace std;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef VP::iterator VPI;

int n, m, p, d[10002], ans = INF;

int main()
{
	cin >> n >> m >> p;
	d[0] = 0;
	d[m + 1] = n;
	for (int i = 1; i <= m; i++){
		int in;
		cin >> in;
		d[i] = (in - p < 0) ? in - p + n : in - p;
	}
	sort(d, d + m + 2);

	for (int i = 1; i <= m + 1; i++){
		int distl = max(d[m + 1] - d[i], d[i - 1] - d[0]);
		int dists = min(d[m + 1] - d[i], d[i - 1] - d[0]);
		ans = min(ans, (distl + dists * 2) * 100);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	int n,m,q,now = 0;
	bool ok[200000] = {};
	deque<int> deq;
	cin >> n >> m >> q;
	for(int i = 1;i < n;i++) deq.push_back(i);
	for(int i = 0;i < m;i++){
		int a;
		cin >> a;
		if(a % 2){
			for(int j = 0;j < a;j++){
				deq.push_front(now);
				now = deq.back();
				deq.pop_back();
			}
		}
		else{
			for(int j = 0;j < a;j++){
				deq.push_back(now);
				now = deq.front();
				deq.pop_front();
			}
		}
		now = deq.front();
		deq.pop_front();
	}
	for(int i = 0;i < deq.size();i++) ok[deq[i]] = true;
	ok[now] = true;
	for(int i = 0;i < q;i++){
		int t;
		cin >> t;
		if(ok[t]) cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3932
#include <bits/stdc++.h>
#define fast_read ios::sync_with_stdio(0);cin.tie(0);
#define ll long long
using namespace std;

int main()
{
    fast_read;
    ll n , a , b;
    cin>>n>>a>>b;
    if (n * a < b)cout<<n * a<<endl;
    else cout<<b<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int l=1,r=1e9,mid;
char s[5];

char Query(ll x){printf("? %lld\n",x);fflush(stdout);scanf("%s",s);return*s;}
void Answer(int x){printf("! %d\n",x);exit(0);}

void powten(){
	int t=1;
	while(true){
		if(Query(t+1)=='Y')Answer(t);
		t*=10;
	}
	exit(0);
}

int main(){
	do{
		if(l==r)powten();
	}while(Query(l*=10)=='Y');
	r=min(r,l-1),l/=10,mid=(l+r)>>1;
	while(l<r){
		if(Query(mid*10ll+9)=='Y')
			r=mid;
		else
			l=mid+1;
		mid=(l+r)>>1;
	}
	Answer(mid);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ll long long
        #define ld long double

        int dx[4] = {0,0,-1,1};
        int dy[4] = {1,-1,0,0};
        int main()
        {
            tani_nachi_ke  

            int n,m;
            cin >> n >> m;
            string s[n];
            for(int i = 0; i < n; i++)
                cin >> s[i];

            int dp[n][m][n][m];
            memset(dp,-1,sizeof(dp));
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < m; j++)
                {
                    if(s[i][j] == '#')continue;
                    bool is[n][m];
                    memset(is,0,sizeof(is));
                    is[i][j] = 1;
                    dp[i][j][i][j] = 0;
                    queue<pair<int,int>> q;
                    q.push({i,j});
                    while(!q.empty())
                    {
                        auto u = q.front();
                        q.pop();
                        int x = u.ff;
                        int y = u.ss;   
                        // cout << i << " " <<  j << " " << x << " " << y << endl;
                        for(int l = 0; l < 4; l++)
                        {
                            int nx = dx[l] + x;
                            int ny = dy[l] + y;
                            // cout << nx << " " << ny << endl;

                            if(nx < 0 || ny < 0 || nx >= n || ny >= m || s[nx][ny] == '#')
                                continue;

                            if(is[nx][ny])
                                continue;
                            is[nx][ny] = 1;

                            dp[i][j][nx][ny] = dp[i][j][x][y] + 1;
                            q.push({nx,ny});

                        }
                    }
                }
            }

            int ans = 0;
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < m; j++)
                {
                    for(int l = 0; l < n; l++)
                    {
                        for(int r = 0; r < m; r++)
                        {
                            if(s[i][j] != '#' && s[l][r] != '#')
                                ans = max(dp[i][j][l][r],ans);
                        }
                    }
                }
            }
            cout << ans << '\n';



           return 0;
        }

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	
	vector <int> p(n), q(n);
	for(int i=0;i<n;i++) {cin>>p[i];p[i]--;}
	for(int i=0;i<n;i++) {cin>>q[i];q[i]--;}
	
	vector<int> V(n);
	map<vector<int>, int> ord;
	int count = 0;
	for(int i=0;i<n;i++) V[i]=i;
	do{
		ord[V] = count;
		count++;
	}while(next_permutation(V.begin(),V.end()));

	cout << abs(ord[p] - ord[q]) << endl;

	return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>

using namespace std;

int main(void) {
	long long a, b, x;
	cin >> a >> b >> x;
	long long count = 0;
	count += b / x;
	count -= a / x;
	if (a%x == 0) {
		count++;
	}
	cout << count;
	return 0;
}

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

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

  int ren = 0;

  rep(i,n){
    int a,b;
    cin >> a >> b;
    if(a == b) ++ren;
    else ren =0;
    if(ren == 3){
      cout << "Yes" << endl;
      return 0;
    }
  }

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

Measured memory_bytes: 3632
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\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 end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll A,B,C;
    in >> A >> B >> C;
    //vector<ll> X(N);
    if(A+B+C >= 22) out << "bust" << endl;
    else out << "win" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int n, inp, x, a[105], b[105];

int main(){

    cin >> n;

    for(int i = 0; i < n-1; i++){
        cin >> b[i];
    }

    for(int i = 0; i < n; i++){
        if(i == 0){
            a[0] = b[0];
        } else if (i+1 == n){
            a[n-1] = b[n-2];
        } else{
            a[i] = min(b[i], b[i-1]);
        }
    }

    for(int i = 0; i < n; i++){
        x = x + a[i];
    }

    cout << x;


}



Measured memory_bytes: 256
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int a, b; cin >> a >> b;
    if(a < 0 && b < 0){ // negative * negative
        if(abs(a - b) & 1) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    } else if(a <= 0 && 0 <= b) {
        cout << "Zero" << endl;
    } else {
        cout << "Positive" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char a[10];
	scanf("%s",a);
	int i,g=0,j,sum=0,n=0;
	for(j=1;j<4;j++)
	{
	if(a[0]==a[j])
		sum++;
	}
	if(sum!=1) g=1;
	for(i=0;i<4;i++)
	{
		for(j=i+1;j<4;j++)
	{ 
	if(a[i]==a[j])
	a[j]='0'; 
	} 
	}
	for(i=0;i<4;i++)
	{
		if(a[i]!='0')
		n++; 
	}
	if(n!=2) g=1;
	if(g==1) printf("No\n");
	else printf("Yes\n");
	
}

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

int dfs(vector<vector<int>>& g, vector<int>& mem, int start) {
    int len = 0;
    for(auto x: g[start]) {
        if(mem[x] > -1) {
            len = max(len, mem[x] + 1);
        }
        else {
            len = max(len, dfs(g, mem, x) + 1);
        }
    }
    mem[start] = len;
    return mem[start];
}

int main() {
    int n, m, x, y;
    cin >> n >> m;
    vector<vector<int>> g(n+1);
    vector<int> mem(n+1, -1);
    for(int i = 0; i < m; i++) {
        cin >> x >> y;
        g[x].push_back(y);
    }
    // for(auto x: g) {
    //     for(auto y: x) {
    //         cout << y <<" ";
    //     }
    //     cout <<endl;
    // }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(mem[i] > -1) {
            ans = max(ans, mem[i]);
        }
        else {
            ans = max(ans, dfs(g, mem, i));
        }
    }
    cout <<ans;
    return 0;
}

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

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    vector<unsigned long> cnt(N);
    for(unsigned long i{0}, d; i < K; ++i){
        cin >> d;
        for(unsigned long j{0}, A; j < d; ++j){
            cin >> A;
            ++cnt[A - 1];
        }
    }
    cout << count(cnt.begin(), cnt.end(), 0UL) << endl;
    return 0;
}

Measured memory_bytes: 3632
K = int(input())

def S(n):
    return sum(int(c) for c in str(n))
d9 = 0
cnt = 0
upper = 1
while cnt < K:
    n = int(str(upper) + ('9' * d9))
    if n <= S(n) * (10 ** d9):
        print(n)
        cnt += 1
        upper += 1
    else:
        d9 += 1
        upper //= 10


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define bug(x) cout<<#x<<" : "<<x<<endl
#define de puts("#")
#define ll long long
using namespace std;
const int maxn=1e5+5;
const int maxm=1e6+5;
int n;
char a[maxn];
map<string,int>mp;

int main(){
	scanf("%d",&n);
	ll ans=0;
	for(int i=1;i<=n;i++){
		scanf("%s",a);
		int len=strlen(a);
		sort(a,a+len);
		string res="";
		for(int i=0;i<len;i++)res+=a[i];
		mp[res]++;
		ans+=mp[res]-1;
	}
	printf("%lld\n",ans);	
	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
typedef long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
char ans[N];
int32_t main(){
    ll n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    /*
    if (k>=n){
        string y="";
        char c='A';
        ll cnt=1;
        for (int i=1;i<=n;i++){
            y+=c;
            c+=cnt;
            cnt*=-1;
        }
        reverse(y.begin(),y.end());
        kill(y);
    }
    */
    ll cnt=0;
    if (s[0]=='A') cnt++;
    ans[0]='B';
    for (int i=1;i<n && i+cnt<=k;i++){
        char c=s[i];
        if (i%2==0){
            if (c=='A'){
                if (i+cnt<k){
                    cnt++;
                }
                else{
                    ans[0]='A';
                }
            }
        }
        else{
            if (c=='B'){
                if (i+cnt<k){
                    cnt++;
                }
                else{
                    ans[0]='A';
                }
            }
        }
    }
    if (n-1+cnt<=k){
        string y="";
        char c='A';
        ll cnt1=1;
        for (int i=1;i<=n;i++){
            y+=c;
            c+=cnt1;
            cnt1*=-1;
        }
        reverse(y.begin(),y.end());
        if (n%2==0){
            kill(y);
        }
        else{
            y[0]='B';
            ll z=n-1+cnt;
            if (k%2==z%2){
                kill(y);
            }
            y[0]='A';
            kill(y);
        }
    }
    for (int i=1;i<n;i++){
        ll z=i+k-cnt;
        if (z>=n){
            if (i%2==(n-1)%2){
                ans[i]='A';
            }
            else{
                ans[i]='B';
            }
        }
        else{
            if (z%2==i%2){
                ans[i]=s[z];
            }
            else{
                if (s[z]=='A') ans[i]='B';
                else ans[i]='A';
            }
        }
    }
    for (int i=0;i<n;i++) cout << ans[i];

}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
int GCD(int a,int b){
    if(a%b==0)return b;
    else return GCD(b,a%b);
}
int a[1005];
int main() {
  int n,m;
  double sum=0;
  cin>>n>>m;
  
  for(int i=1;i<=n;i++)
  {
  	cin>>a[i];sum+=a[i];
  }
  double mm=sum/(4*m);
  sort(a+1,a+1+n);
  reverse(a+1,a+1+n);
  for(int i=1;i<=m;i++)
  {
  	if(a[i]<mm)
  	{
  		cout<<"No"<<endl;return 0;
	  }
  }
  cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
x = list(map(int,input().split()))
y = [(x[i],i+1) for i in range(n)]
y.sort()
rng = [(y[0][1],(n-1)*n//2+1)]
bef = deque([y[0][1]]*(y[0][1]-1))
for i in range(1,n):
  a,b = rng[-1]
  rng.append((a+y[i][1],b+n-y[i-1][1]+1))
  bef.extend([y[i][1]]*(y[i][1]-1))
ans = []
cnt = 0
for i in range(n):
  goal = y[i][0]
  if cnt>goal or not rng[i][0] <= y[i][0] <= rng[i][1]:
    print("No")
    exit()
  while cnt+1<goal:
    if not bef:
      print("No")
      exit()
    ans.append(bef.popleft())
    cnt += 1
  ans.append(y[i][1])
  cnt += 1
  bef.extend([y[i][1]]*(n-y[i][1]))
while bef:
  ans.append(bef.popleft())
print("Yes")
print(*ans,sep=" ")

Measured memory_bytes: 71920
n=int(input())
u=[int(j) for j in input().split()]
m=[int(j) for j in input().split()]

ans=0

for i in range(n):
  t=0
  t=sum(u[:i+1])+sum(m[i:])
  if ans<t:
    ans=t
print(ans)

    
    
  
  

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

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

    ll a, b, c, k;

    cin >> a >> b >> c >> k;

    ll res = 0;
    if(k <= a) res = k;
    else if(a+b >= k) res = a;
    else{
        if(k <= a+b+c) res = a - (k-(a+b));
        else res = a-c;
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 3664