akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int H, N;
    cin >> H >> N;
    vint A(N), B(N);
    rep(i, N)
            cin >>
        A[i] >> B[i];
    vll dp(H + 1e4 + 2);
    for (int i = 1; i <= H + 1e4 + 1; i++)
    {
        ll m = INF / 2;
        for (int j = 0; j < N; j++)
        {
            if (i - A[j] >= 0)
                chmin(m, dp[i - A[j]] + B[j]);
        }
        dp[i] = m;
    }
    ll ans = INF / 2;
    for (int i = H; i <= H + 1e4 + 1; i++)
    {
        chmin(ans, dp[i]);
    }
    cout << ans;
    return 0;
}

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

int main(void){
  int m, f, r;

  cin >> m >> f >> r;
  while( m != -1 || f != -1 || r != -1 ){
    if( m == -1 || f == -1){
      cout << 'F' << endl;
    }else{
      if( m+f >= 80 ){
	cout << 'A' << endl;
      }else if( m+f >= 65 ){
	cout << 'B' << endl;
      }else if( m+f >= 50 ){
	cout << 'C' << endl;
      }else if( m+f >= 30 ){
	if( r >= 50 ){
	  cout << 'C' << endl;
	}else{
	  cout << 'D' << endl;
	}
      }else{
	cout << 'F' << endl;
      }
    }
    
    cin >> m >> f >> r;
  }
  
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


/* mint、表示は変数名.x */
struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降はMODが素数のみ
  mint inv() const {
    return pow(MOD - 2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

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

  sort(all(C), greater<ll>());


  vector<mint> fact2(N + 1);
  fact2[0] = 1;
  rep(i, N) {
    fact2[i + 1] = fact2[i] * 2;
  }

  mint ans = 0;
  rep(i, N) {
    mint temp = fact2[N - 1 - i];
    if (i > 0)
      temp *= fact2[i - 1] * (i + 2);
    ans += temp * C[i];
  }
  ans *= fact2[N];

  cout << ans.x << endl;
}

Measured memory_bytes: 3328
// https://atcoder.jp/contests/abc062/tasks/arc074_a

#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll H, W, m;

vector<ll> pc(vector<ll> mc, ll p)
{
  mc.push_back(p);
  return mc;
}

void cut(ll h, ll w, vector<ll> c)
{
  ll s = c.size();
  if (s == 2)
  {
    c.push_back(h * w);
    sort(ALL(c));
    m = min(m, c[2] - c[0]);
  }
  else
  {
    ll ch = h / (3 - s), cw = w / (3 - s);
    if (0 < ch)
      cut(h - ch, w, pc(c, ch * w));
    if (0 < cw)
      cut(h, w - cw, pc(c, cw * h));
    if (h % (3 - s) != 0)
      cut(h - (ch + 1), w, pc(c, (ch + 1) * w));
    if (w % (3 - s) != 0)
      cut(h, w - (cw + 1), pc(c, (cw + 1) * h));
  }
  return;
}

int main()
{
  m = INF;
  cin >> H >> W;

  cut(H, W, {});

  cout << m << '\n';

  return 0;
}


Measured memory_bytes: 256
N,Ma,Mb = map(int,input().split())

sz = 401
table = [[99999999]*(sz+1) for _ in range(sz+1)]
table[0][0] = 0
for n in range(N):
  a,b,c = map(int,input().split())
  for i in range(sz,-1,-1):
    for j in range(sz,-1,-1):
      if table[i][j]!=99999999:
        table[i+a][j+b] = min(table[i+a][j+b],table[i][j]+c)
#print(table)

ans = 99999999
i,j = Ma,Mb
while i<=sz and j<=sz:
  ans = min(ans,table[i][j])
  i += Ma
  j += Mb
print(ans if ans!=99999999 else -1)


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

using namespace std;
typedef pair<int, int> pii;
const int MAXN = 2010;

#define fi first
#define se second

int N, K;
vector<int> adj[MAXN];
int dist[MAXN];

pii dfs (int x, int p, int d) {
	pii res((d <= K / 2), (d <= (K + 1) / 2));
	for (int t : adj[x]) {
		if (t != p) { 
			pii p = dfs(t, x, d + 1);
			res.fi += p.fi;
			res.se += p.se;
		}
	}
	return res;
}

int main() {
	scanf("%d %d", &N, &K);
	for (int i = 1; i < N; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int r = 0, mxdiff = 0;
		for (int t : adj[i]) {
			pii p = dfs(t, i, 1);
			r += p.fi;
			mxdiff = max(mxdiff, p.se - p.fi);
		}
		ans = max(ans, r + mxdiff + 1);
	}
	printf("%d\n", N - ans);
}


Measured memory_bytes: 512
from heapq import heappush, heappop
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
q = []
for i, x in enumerate(b):
	l, r = b[(i-1)%n], b[(i+1)%n]
	if l + r < x:
		heappush(q, (-x, i))

ng = False
while q:
	x, i = -q[0][0], q[0][1]
	#print(x, i)
	y = a[i]
	if y > x:
		ng = True
		break
	elif y == x:
		heappop(q)
		continue
	else:
		l, r = b[(i-1)%n], b[(i+1)%n]
		quo = (x-1)//(l+r)
		mod = x - quo*(l+r)
		if y >= mod:
			if (x-y) % (l+r) != 0:
				ng = True
				break
			else:
				ans += (x-y) // (l+r)
				b[i] = y
		else:
			ans += quo
			b[i] = mod
		heappop(q)
		if b[(i-2)%n] + b[i] < l:
			heappush(q, (-l, (i-1)%n))
		if b[(i+2)%n] + b[i] < r:
			heappush(q, (-r, (i+1)%n))
		#print(b[i])
			
if ng or a != b:
	print(-1)
else:
	print(ans)

Measured memory_bytes: 129816
#include <iostream>

using namespace std;

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

    int cur = 0, ans = cur <= x;
    for (int i = 0; i < n; i++) {
        int l;
        cin >> l;
        cur += l;
        ans += cur <= x;
    }

    cout << ans << endl;

    return 0;
}

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

int main () {
    int a, b;
    vector<int> avec, bvec;
    cin >> a >> b;

    int x = ceil(a / 0.08);
    while(int(x * 0.08) <= a){
        avec.push_back(x);
        // cout << x << endl;
        x++;
    }

    int y = ceil(b / 0.1);
    while(int(y * 0.1) <= b){
        bvec.push_back(y);
        // cout << y << endl;
        y++;
    }

    rep(i, avec.size()){
        rep(j, bvec.size()){
            if(avec[i] == bvec[j]) {
                cout << avec[i] << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;

}

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S = "MARCH";
  vector<long long> V(5);

  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < 5; j++) {
      if (s.at(0) == S.at(j)) V.at(j)++;
    }
  }

  long long ans = 0;

  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += V.at(i) * V.at(j) * V.at(k);
      }
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <malloc.h>
typedef struct {
    int N;
    int E;
    int W;
    int S;
    int D;
    int Z;
} Dice;

void Move(char dir,Dice *d){
    int tmp;
    switch(dir){
        case 'S':
            tmp = d->D;
            d->D = d->N;
            d->N = d->Z;
            d->Z = d->S;
            d->S = tmp;
            break;
        case 'E':
            tmp = d->D;
            d->D = d->W;
            d->W = d->Z;
            d->Z = d->E;
            d->E = tmp;
            break;
        case 'N':
            tmp = d->D;
            d->D = d->S;
            d->S = d->Z;
            d->Z = d->N;
            d->N = tmp;
            break;
        case 'W':
            tmp = d->D;
            d->D = d->E;
            d->E = d->Z;
            d->Z = d->W;
            d->W = tmp;
            break;
    }
}

int main(void){
    Dice *a = (Dice *) malloc(sizeof(Dice));
    char ch;
    scanf("%d %d %d %d %d %d\n",&a->D,&a->S,&a->E,&a->W,&a->N,&a->Z);
    while(scanf("%c",&ch) != EOF){
        Move(ch,a);
    }
    printf("%d\n",a->D);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int X[4] = { 0,0,1,-1 }, Y[4] = { 1,-1,0,0 };

int H, W, cnt[2];
ll res;
bool b[400][400];
char c[400][400];

void dfs(int x, int y) {
	b[x][y] = true;
	if (c[x][y] == '.')
		++cnt[0];
	else
		++cnt[1];
	for (int i = 0; i != 4; ++i) {
		int xx = x + X[i], yy = y + Y[i];
		if (xx == -1 || yy == -1 || xx == H || yy == W || b[xx][yy])continue;
		if (c[x][y] != c[xx][yy])
			dfs(xx, yy);
	}
}

int main() {
	cin >> H >> W;
	for (int i = 0; i != H; ++i) {
		for (int j = 0; j != W; ++j) {
			cin >> c[i][j];
		}
	}
	for (int i = 0; i != H; ++i) {
		for (int j = 0; j != W; ++j) {
			if (!b[i][j]) {
				dfs(i, j);
				res += (ll)cnt[0] * cnt[1];
				cnt[0] = cnt[1] = 0;
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 13056
def resolve():
    Q = int(input())
    # pair = [tuple(map(int, input().split())) for _ in range(Q)]

    def get_primes(n):
        is_prime = [True] * (n + 1)
        is_prime[0] = False
        is_prime[1] = False
        for i in range(2, int(n ** 0.5) + 1):
            if not is_prime[i]:
                continue
            for j in range(i * 2, n + 1, i):
                is_prime[j] = False
        return [is_prime[i] for i in range(n + 1)]

    primes = get_primes(10**5+1)
    cum = [0] * (10**5 + 1)
    for i in range(2, 10**5+1):
        cum[i] += cum[i-1]
        if i % 2 and primes[i] and primes[(i+1)//2]:
            cum[i] += 1
    for _ in range(Q):
        l, r = map(int, input().split())
        print(cum[r] - cum[l-1])
resolve()

Measured memory_bytes: 54304
using System;
using System.Collections.Generic;

public class CSharp{
    public static void Main(){
        Kyopuro chokudai = new Kyopuro();
		chokudai.AtCoder(10, 10);
	}
}

public class Kyopuro{

	int n;
	int[] x2, x5;
	
    public void AtCoder(int p, int q){
		string[] input;
		input = Console.ReadLine().Split(' ');
		n = int.Parse(input[0]);
		x2 = new int[n];
		x5 = new int[n];

		long[][] y = new long[200][];
		long[][] z = new long[200][];
		for (int i=0; i<200; i++) {
			y[i] = new long[200];
			z[i] = new long[200];
		}

		for (int i = 0; i < n; i++) {
			input = Console.ReadLine().Split('.');
			int d = 0;
			long v = 0;
			long b = 1;
			if (input.Length == 2) {
				d = input[1].Length;
				b = (long)Math.Pow(10, d);
				v += long.Parse(input[1]);
			}
			v += long.Parse(input[0]) * b;
			x2[i] = 100 + d;
			x5[i] = 100 + d;
			while (v % 2 == 0) {
				x2[i]--;
				v /= 2;
			}
			while (v % 5 == 0) {
				x5[i]--;
				v /= 5;
			}
			y[x2[i]][x5[i]]++;
		}
		for (int i=0; i<199; i++){
			for (int j=0; j<199; j++) {
				z[i+1][j+1] = z[i][j+1] + z[i+1][j] - z[i][j] + y[i+1][j+1];
			}
		}
		long ans = 0;
		for (int i=0; i<n; i++){
			ans += z[200 - x2[i]][200 - x5[i]];
			if (x2[i] <= 100 && x5[i] <= 100) ans--;
		}
		
		Console.WriteLine(ans / 2);

    }
    public static void DebugWL(object x){ System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 47996
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   int x;
   cin>>x;
   if(x){
    cout<<0<<"\n";
   }else{
    cout<<1<<"\n";
   }
   
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
    int ans = 0;
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (i % 2 == 1 && x % 2 == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3140
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end
n , k = gi
l = gi

l.sort!
ans = 0
rep k do
ans += l.pop
end
puts ans

Measured memory_bytes: 2300
N = int(input())
A = [int(a) - 1 for a in input().split()]
liked = [set() for _ in range(N)]
for i in range(N):
    liked[A[i]].add(i)

count = 0
for i in range(N):
    if A[i] in liked[i]:
        count += 1

print(count // 2)

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

using namespace std;

typedef long long ll;

const int MAXN = 100005;

// BIT
int bit[MAXN * 2], N;

inline int lowbit(int x) { return x & -x; }

inline void add(int x)
{
	for (int i = x; i <= N; i += lowbit(i))
		bit[i] += 1;
}

inline int query(int x)
{
	int ret = 0;
	for (int i = x; i > 0; i ^= lowbit(i))
		ret += bit[i];
	return ret;	
}

int a[MAXN], b[MAXN];

vector<int> v;

ll pos;

int n;

bool check(int m)
{
	for (int i = 1; i <= n; i++)
		b[i] = (m <= a[i] ? 1 : 0);
	for (int i = 1; i <= N; i++)
		bit[i] = 0;
	ll cnt = 0; int cur = 0;
	add(n + 1);
	for (int i = 1; i <= n; i++)
	{
		cur += (b[i] ? 1 : -1);
		cnt += query(n + 1 + cur);
		add(n + 1 + cur);
	}
//	cerr << "cnt: " << cnt << endl;
	cnt = (ll)n * (n + 1) / 2 - cnt;
	return cnt < pos;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], v.emplace_back(a[i]);
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	N = 2 * n + 1, pos = (ll)n * (n + 1) / 4 + 1;
	int l = 0, r = v.size() - 1;
	while (l < r)
	{
		int mid = (l + r + 1) >> 1;
		if (check(v[mid]))
			l = mid;
		else
			r = mid - 1;
	}
	cout << v[l] << endl;
	return 0;	
}


Measured memory_bytes: 2296
//by Sshwy
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=500,P=1e9+7;
int pw(int a,int m){
    int res=1;
    while(m)m&1?res=1ll*res*a%P:0,a=1ll*a*a%P,m>>=1;
    return res;
}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,m,k;

int dfn[N],low[N],totdfn;
int s[N],tp;
int totvcc;
vector<int> vcc[N],g[N];

void tarjan(int u,int p){
    dfn[u]=low[u]=++totdfn;
    s[++tp]=u;
    for(int v:g[u]){
        if(!dfn[v]){
            tarjan(v,u);
            low[u]=min(low[u],low[v]);
            if(dfn[u]<=low[v]){
                ++totvcc, vcc[totvcc].pb(u);
                do { vcc[totvcc].pb(s[tp]); }while(s[tp--]!=v);
            }
        }
        else low[u]=min(low[u],dfn[v]);
    }
}

int E[N][N],c[N][N];
int calc(int x,int k){
    int res=0;
    FOR(d,0,x-1){
        res=(res+pw(k,gcd(x,d)))%P;
    }
    res=1ll*res*pw(x,P-2)%P;
    return res;
}
int calc(vector<int> & A){
    if(A.size()==2)return k;//单独边
    int cnt=0;
    for(int i:A)for(int j:A)cnt+=E[i][j];
    assert(cnt%2==0);
    cnt/=2;
    if(cnt==A.size())return calc(cnt,k);
    return c[cnt+k-1][k-1];
}
int main(){
    scanf("%d%d%d",&n,&m,&k);

    c[0][0]=1;
    FOR(i,1,200){
        c[i][0]=1;
        FOR(j,1,i)c[i][j]=(c[i-1][j-1]+c[i-1][j])%P;
    }

    FOR(i,1,m){
        int u,v;
        scanf("%d%d",&u,&v);
        E[u][v]=E[v][u]=1;
        g[u].pb(v),g[v].pb(u);
    }
    FOR(i,1,n)if(!dfn[i])tarjan(i,0);

    int ans=1;
    FOR(i,1,totvcc){
        ans=ans*1ll*calc(vcc[i])%P;
    }

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

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

class MaxBinaryIndexedTree {
	std::vector<int> vec;
public:
	MaxBinaryIndexedTree(int size) : vec(size, -1) {};
	int operator[](int position) const {
		int result = -1;
		while (position >= 0) {
			result = std::max(result, vec[position]);
			position -= (position + 1) & ~position;
		}
		return result;
	}
	void update(int position, int value) {
		while (position < vec.size()) {
			vec[position] = std::max(vec[position], value);
			position += (position + 1) & ~position;
		}
	}
};
int main() {
	int n; std::cin >> n;
	std::vector<int> permutation(n); for (auto& p : permutation) std::cin >> p;
	std::vector<int> indices(n); for (auto i = 0; i < n; ++i) indices[i] = i;
	std::sort(indices.begin(), indices.end(), [&permutation](int a, int b) {return permutation[a] > permutation[b]; });
	MaxBinaryIndexedTree forward(n), backward(n);
	long long int result = 0;
	forward.update(indices.front(), indices.front());
	backward.update(n - 1 - indices.front(), n - 1 - indices.front());
	for (auto i = 1; i < n; ++i) {
		const auto idx = indices[i];
		const auto val = permutation[idx];
		const auto left_first = forward[idx];
		const auto left_second = forward[left_first - 1];
		const auto right_first = n - 1 - backward[n - 1 - idx];
		const auto right_second = n - 1 - backward[n - 1 - right_first - 1];
		long long int left_left_length, left_right_length = idx - left_first;
		if (left_first == -1) {
			left_left_length = 0;
		}
		else {
			left_left_length = left_first - left_second;
		}
		long long int right_right_length, right_left_length = right_first - idx;
		if (right_first == n) {
			right_right_length = 0;
		}
		else {
			right_right_length = right_second - right_first;
		}
		forward.update(idx, idx);
		backward.update(n - 1 - idx, n - 1 - idx);
		result += (left_left_length * right_left_length + left_right_length * right_right_length) * val;
	}
	std::cout << result << std::endl;

}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int nfound = 0;

    for (int i = 1; i <= N; i++) {
      if (i % 2 == 0) {
        continue;
      }
      int n = 0;
      for (int j = 1; j <= i; j++) {
        if (j % 2 == 0) {
          continue;
        }
        if (i % j == 0) {
          n++;
        }
      }
      if (n == 8) {
        nfound++;
      }
    }
    System.out.println(nfound);
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define UP(a,b) ((a + (b - 1)) / b)
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);
llong n;
int main(){ _;
  cin>>n;
  V a(n),b(n);
  REP(i,n) cin>>a[i]>>b[i];
  llong diff=0;

  REPR(i,n-1){
    diff += UP((a[i]+diff),b[i])*b[i]-(a[i]+diff);
  }
  cout<<diff<<endl;

  return 0;
}


Measured memory_bytes: 1920
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

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

    Int H, W, M;
    cin >> H >> W >> M;

    set<pair<Int, Int>> s;
    vector<Int> hcnt(H), wcnt(W);
    for (Int i = 0; i < M; i++) {
        Int h, w;
        cin >> h >> w;
        h--;
        w--;

        s.insert({h, w});
        hcnt[h]++;
        wcnt[w]++;
    }

    Int a = 0, b = 0;
    for (Int i = 0; i < H; i++) {
        chmax(a, hcnt[i]);
    }
    for (Int i = 0; i < W; i++) {
        chmax(b, wcnt[i]);
    }

    vector<Int> hmax, wmax;
    for (Int i = 0; i < H; i++) {
        if (hcnt[i] == a) {
            hmax.push_back(i);
        }
    }
    for (Int i = 0; i < W; i++) {
        if (wcnt[i] == b) {
            wmax.push_back(i);
        }
    }
    Int ans = a + b - 1;
    for (auto h : hmax) {
        for (auto w : wmax) {
            if (s.find({h, w}) == s.end()) {
                ans++;
                cout << ans << endl;
                return 0;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
void add(ll& x, ll y) {
    x += y;
    x %= MOD;
}
ll qpow(ll x, ll k) {
    ll r = 1;
    while(k) {
        if(k & 1) r = r * x % MOD;
        k >>= 1;
        x = x * x % MOD;
    }
    return r;
}
ll d[N];
ll C(int i, int j) {
    return d[i] * qpow(d[i-j], MOD-2) % MOD * qpow(d[j], MOD - 2) % MOD;
}
ll sum(ll n) {
    return n*(n+1)/2;
}
int main() {
    d[0] = 1;
    for(int i = 1; i < N; i++) {
        d[i] = d[i-1] * i % MOD;
    }
    ll ans = 0;
    ll n, m, k;
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            ll tmp = C(n*m-2, k-2);
            ll x = (sum(m-j) + sum(j-1))*n%MOD;
            ll y = (sum(n-i) + sum(i-1))*m%MOD;
            ans += (x+y)*tmp%MOD;
            ans %= MOD;
        }
    }
    cout << ans*qpow(2,MOD-2)%MOD << '\n';
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);

  string s, t; cin >> s >> t;

  //ll ans = 0;
  string ans = "No";

  vector<int> sl(26, 0), tl(26, 0);
  rep(i, s.size()) sl[s[i] - 'a']++;
  rep(i, t.size()) tl[t[i] - 'a']++;
  int sfirst, tlast;
  rep(i, 26){
    if (sl[i] != 0){
      sfirst = i;
      break;
    }
  }
  for (int i = 25; i >= 0; i--){
    if (tl[i] != 0){
      tlast = i;
      break;
    }
  }
  if (sfirst < tlast) ans = "Yes";
  if (s.size() < t.size() && ans == "No"){
    ans = "Yes";
    rep(i, s.size()) if (s[i] != t[i]) ans = "No";
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
while True:	
	a,b,c=map(int,input().split())
	if a==-1 and b==-1 and c==-1:
		break
	if	a==-1 or b==-1:
		print("F")
	elif a+b >= 80:
		print("A")
	elif a+b >= 65:
		print("B")
	elif a+b >= 50  or c >=50:
		print("C")
	elif a+b >= 30:
		print("D")
	elif a+b < 30:
		print("F")



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string a, b;
	cin>>a>>b;
	int cnt;
	if(a[0]==b[0])
		cnt++;
	if(a[1]==b[1])
		cnt++;
	if(a[2]==b[2])
		cnt++;
		
	cout<<cnt<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int fa[100000+5];
int find(int a){
    return a==fa[a]?a:fa[a]=find(fa[a]);
}
void merge(int a,int b){
    fa[find(a)]=find(b);
}
int main(){
    int n,m,cnt=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        merge(a,b);
    }
    for(int i=1;i<=n;i++){
        if(find(i)==i)
            cnt++;
    }
    cout<<cnt-1;
    //getchar();
    //getchar();
    return 0;
}

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

using namespace std;

long merge_invcount(vector<int>& v)
{
	long n = v.size();
	if (n <= 1) return 0;

	long count = 0;
	vector<int> left(v.begin(), v.begin() + n / 2);
	vector<int> right(v.begin()+n/2, v.end());
	count += merge_invcount(left);
	count += merge_invcount(right);

	long index_v = 0;
	long index_left = 0;
	long index_right = 0;
	while (index_v < n) {
		if (index_left < left.size() && (index_right == right.size() || left[index_left] <= right[index_right])) {
			v[index_v] = left[index_left];
			index_v++;
			index_left++;
		}
		else {
			count += n / 2 - index_left;
			v[index_v] = right[index_right];
			index_v++;
			index_right++;
		}
	}

	return count;
}

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

	vector<int> numbers;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		numbers.push_back(num);
	}

	long Answer = merge_invcount(numbers);
	cout << Answer << endl;

	return 0;
}


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

int main(){
  int x=0;
  int N;
  cin>>N;
  vector<char> S(N);
  vector<int> A(N);
  for(int i=0;i<N;i++){
      cin>>S.at(i);
  }
  for(int i=0;i<N;i++){
     if(S.at(i)=='I'){
       x++;
     }
    if(S.at(i)=='D'){
      x--;
    }
    A.at(i)=x;
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  if(A.at(0)>=0)
  cout<<A.at(0)<<endl;
  if(A.at(0)<0)
    cout<<0<<endl;
}

Measured memory_bytes: 256
let N = stdin.ReadLine() |> int

let S =
    [| for _ in [ 1..N ] do
        yield stdin.ReadLine() |]

let counter j =
    S
    |> Array.filter (fun s -> s = j)
    |> Array.length
    |> string

"AC x " + (counter "AC") |> stdout.WriteLine
"WA x " + (counter "WA") |> stdout.WriteLine
"TLE x " + (counter "TLE") |> stdout.WriteLine
"RE x " + (counter "RE") |> stdout.WriteLine


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

int main()
{
    int long long ans=0,i,n,l;
  cin>>n;
  vector<int>v(n);
  for(i=0;i<n;i++)
    cin>>v[i];
  sort(v.begin(),v.end());
  if(n==1)
    cout<<"0";
  else if(n==2)
    cout<<v[1];
  else{
    l=n;
    ans=v[n-1];
    l=l-2;
    for(i=n-2;i>=0&&l>0;i--){
        if(l==1){
            l--;
            ans=ans+v[i];
        }
        else{
            ans=ans+v[i]*2;
            l=l-2;
        }
    }
    cout<<ans;
  }

   return 0;
}



Measured memory_bytes: 4048
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 20;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

bool rec(string t) {
    if(t == "ABC")return true;
    else if(t.size()<=3)return false;
    vector<int> pos;
    int p=0;
    while((p = t.find("ABC",p))!=-1){
        pos.push_back(p);
        p++;
    }
    if(pos.size()==0)return false;
    reverse(pos.begin(),pos.end());
    string gg = "A";
    REP(i,3){
        string tmp, g = gg;
        g[0]+=i;
        tmp = t;
        REP(j,pos.size()){
            tmp.replace(pos[j],3,"");
        }
        if(tmp.find(g) != tmp.npos)continue;
        tmp = t;
        REP(j,pos.size()){
            tmp.replace(pos[j],3,g);
        }
        if(rec(tmp))return true;
    }
    return false;
}

int main() {
    string s;
    cin >> s;
    if(rec(s))cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}




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

int main() {
  int n,m;
  int a;
  int b;
  int ans=0;
  cin>>n>>m;
  if (n>=m) {
    a=n;
    b=m;
  } else {
    a=m;
    b=n;
  }
  for (int i=0;i<a;++i) {
    ans+=b*(std::pow(10, i));
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define Whitebeard ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int main()
{
    Whitebeard;
string a;int e=0,h;
cin>>h>>a;
for(int i=0;i<a.length()-2;i++){
if(a.substr(i,3)=="ABC"){e++;}

}
cout<<e;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
template <class T> using V = vector<T>;
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

/*--------------------------------------------------------------------------------

--------------------------------------------------------------------------------*/

const ll mod = 998244353;

void solve(){
    ll n, k;
    cin >> n >> k;
    V<ll> l(k), r(k);
    rep(i, 0, k) cin >> l[i] >> r[i];
    V<ll> dp(n+5);
    dp[1] = 1;
    rep(i, 1, n){
        dp[i] += dp[i-1];
        rep(j, 0, k){
            ll lf = i+l[j], ri = i+r[j]+1;
            if(lf > n) continue;
            if(ri > n) ri = n+1;
            dp[lf] += dp[i]%mod;
            dp[lf] %= mod;
            dp[ri] -= dp[i]%mod;
            dp[ri] %= mod;
        }
        //debug
        // Rep(i, 1, n) cout << dp[i] << " \n"[i==n];
        //
    }
    ll ans = dp[n]%mod;
    if(ans < 0) ans += mod;
    cout << ans << endl;

    return;
}

int main(){
    solve();

    return 0;
}

Measured memory_bytes: 4840
main = do
  a <- readLn :: IO Int
  b <- readLn
  c <- readLn
  d <- readLn
  e <- readLn
  k <- readLn
  -- a < b < c < d < e
  if and [abs (x - y) <= k | x <- [a,b,c,d,e], y <- [a,b,c,d,e]]
    then putStrLn "Yay!"
    else putStrLn ":("


Measured memory_bytes: 508
program main
    implicit none
    integer*8::N,C,i,j,k,ans=0
    integer*8,allocatable::x(:),v(:),sum1(:),sum2(:),dp1(:),dp2(:),dp3(:),dp4(:)
    read(*,*)N,C
    allocate(x(N))
    allocate(v(N))
    allocate(sum1(N))
    allocate(sum2(N))
    allocate(dp1(N))
    allocate(dp2(N))
    allocate(dp3(N))
    allocate(dp4(N))
    do i=1,N
        sum1(i)=0
        sum2(i)=0
        dp1(i)=0
        dp2(i)=0
        dp3(i)=0
        dp4(i)=0
    end do
    do i=1,N
        read(*,*)x(i),v(i)
    end do
    sum1(1)=v(1)
    do i=2,N
        sum1(i)=sum1(i-1)+v(i)
    end do
    sum2(N)=v(N)
    do i=N-1,1,-1
        sum2(i)=sum2(i+1)+v(i)
    end do
    dp1(1)=max(0,sum1(1)-2*x(1))
    dp3(1)=max(0,sum1(1)-x(1))
    do i=2,N
        dp1(i)=max(dp1(i-1),sum1(i)-2*x(i))
        dp3(i)=max(dp3(i-1),sum1(i)-x(i))
    end do
    dp2(N)=max(0,sum2(N)-2*(C-x(N)))
    dp4(N)=max(0,sum2(N)-(C-x(N)))
    do i=N-1,1,-1
        dp2(i)=max(dp2(i+1),sum2(i)-2*(C-x(i)))
        dp4(i)=max(dp4(i+1),sum2(i)-(C-x(i)))
    end do

    ans=max(ans,dp3(N),dp4(1))
    do i=1,N-1
        ans=max(ans,dp1(i)+dp4(i+1))
    end do
    do i=N,2,-1
        ans=max(ans,dp2(i)+dp3(i-1))
    end do
    print*,ans
end program


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

int main() {
  while(true){
    int h,w;cin>>h>>w;
    if(h==0&&w==0)break;
    rep(i,h){
      rep(j,w){
        if((i+j)%2==0)cout<<"#";
        else cout<<".";
        if(w-j==1){
          cout<<endl;
        }
      }
    }
    cout<<endl;
  }
}


Measured memory_bytes: 3052
#include <iostream>
    #include<cstdlib>
    using namespace std;
    int main() {
    	int W, a, b;
    	cin >> W >> a >> b;
    	if (abs(a - b) <= W) {
    		cout << 0 << endl;
    	}
    	else if (b - (a + W) > a - (b + W)) {
    		cout << b - (a + W) << endl;
    	}
    	else if (b - (a + W) < a - (b + W)) {
    		cout << a - (b + W) << endl;
    	}
    	return 0;
    }

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

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

int is_prime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			return 0;
		}
	}
	return 1;
}

int main(){
	int n,m;    
	scanf("%d %d",&n,&m);
	int ans=1;
	if(m%n==0){
		printf("%d\n",m/n);
	}
	else if(is_prime(m)==1){
		printf("1\n");
	} 
	else{
		for(int i=1;i<=max((int)sqrt(m),n);i++){
			if(m%i==0){
				int tmp=m/i;
				if(m/tmp>=n){
					ans=tmp;
					break;
				}
				else if(m/i>=n){
					ans=i;
				}
			}
		}
		printf("%d\n",ans);
	}	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int dx=y1-y2;
    int dy=x2-x1;
    cout<<x2+dx<<" "<<y2+dy<<" ";
    cout<<x1+dx<<" "<<y1+dy<<endl;
}


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

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

    string s;
    cin >> s;

    int i = 0;
    for (char c : s) {
        if (i++ % 2 == 0) cout << c;
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define MX 100000
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, w[105], v[105]; lnt m, f[MX+5];
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++)
		read(w[i]), read(v[i]);
	memset(f, 0x3f, sizeof f), f[0] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = MX; j >= v[i]; j--)
			f[j] = min(f[j], f[j-v[i]]+w[i]);
	for (int i = MX; ~i; i--) if (f[i] <= m)
		return printf("%d\n", i), 0;
	return 0;
}


Measured memory_bytes: 1024
c0,c1,c2,c3 = 0,0,0,0
res = {"AC":c0, "WA":c1, "TLE":c2, "RE":c3}
n = int(input())
for i in range(n):
    s = input()
    res[s] += 1
for key,val in res.items():
    print(key+" x "+str(val))

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << a[N-1]-a[0] << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 200;
int n,m,a[N],ans,k;
vector<int>f;
void solve(int x){
    int tmp,y;
    for (int i = x; i >= 0; --i){
        f.clear();
        tmp = 0;
        for (int j = 0; j < i; ++j)
            f.push_back(a[j]),tmp+=a[j];
        for (int j = n-1; j >= n - (x - i); --j)
            f.push_back(a[j]),tmp+=a[j];   
        sort(f.begin(),f.end());
        y = min((int)f.size(),k-x);
        for(int j = 0; j < y; ++j)
            if (f[j] < 0) tmp -= f[j];
        ans = max(ans, tmp);
    }
}
int main(){
    scanf("%d%d",&n,&k);
    for (int i = 0; i < n; ++i) scanf("%d",&a[i]); 
    for(int i = 1; i <= min(n,k); ++i)
        solve(i);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<ll,ll>
typedef long long ll;
const int maxn=1e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	ll a,b,n;
	scanf("%lld%lld%lld",&n,&a,&b);
	if(((b-a)&1)==0)printf("%lld\n",(b-a)/2);
	else
	{
		printf("%lld\n",min(a-1,n-b)+1+(b-a-1)/2);
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,k,arr[10000],a = 0;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	for(int i=1;i<=n-1;i++){
		for(int j=1;j<=n-i;j++){
			if(arr[j]<arr[j+1]){
			    int b=arr[j];
			    arr[j]=arr[j+1];
			    arr[j+1]=b;
			}
		}
	}
	for(int i=1;i<=k;i++){
		a+=arr[i];
	}
	cout<<a<<endl;
	return 0;
} 

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Description: ????????????
// Verifyed: various problem 
const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
const P O=0.0L;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P c;R r;};

istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdot(P o,P a,P b){return sgn(dot(o,a,b));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}


// Circle // verified: AOJ 1183 
enum RCC{OUT=2,ON_OUT=1,ISC=0,ON_IN=-1,IN=-2};
int rcc(C a,C b){ R d=abs(a.c-b.c);return sgn(d-a.r-b.r)+sgn(d-abs(a.r-b.r));}


// cross point between circle and line 
// verified: AOJ CGL_7_D
P cir(C c,R t){return c.c+polar(c.r,t);}
VP cross(C c, L l){
	P h=proj(l,c.c),e=polar(sq(norm(c.r)-norm(h-c.c)),arg(l.t-l.s));
	return VP{h-e,h+e};
}

int main(void){
	int q;
	C c;
	cin >> c.c >> c.r;
		
	cin >> q;
	cout.precision(20);
	rep(i,q){
		P a,b;
		cin >> a >> b;
		L l={a,b};
		VP res=cross(c,l);
		if(sgn(real(res[0])-real(res[1])>0)) swap(res[0],res[1]);
		if(sgn(real(res[0])-real(res[1]))==0 and sgn(imag(res[0])-imag(res[1]))>0) swap(res[0],res[1]);
		cout << fixed << res[0] << " " << res[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3524
from collections import deque


N, M = [int(i) for i in input().split()]
gp = [[] for _ in range(N)]
for _ in range(M):
    a, b = [int(i) for i in input().split()]
    gp[a-1].append(b-1)
    gp[b-1].append(a-1)

signs = [-1] * N
que = deque()
que.append((-2, 0))
seen = set()
while(que):
    fr, de = que.popleft()
    if(de in seen):
        continue
    signs[de] = fr
    seen.add(de)
    for next_de in gp[de]:
        if(next_de not in seen):
            que.append((de, next_de))

if(len(seen) == N):
    print('Yes')
    for s in signs[1:]:
        print(s+1)
else:
    print('No')

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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

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

const int MX = 1e5 + 5;

int N, a[MX];

int sgn(int aa) {
    if(aa < 0)
        return -1;
    return 1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    REP(i, 0, N) {
        cin >> a[i];
    }
    sort(a, a+N);
    
    vector<pair<int, int>> res; 

    if(sgn(a[0]) == sgn(a[N-1])) {
        if(sgn(a[0]) == -1) reverse(a, a+N);
        int cur = a[0] - a[1];
        res.pb({a[0], a[1]});
        a[1] = cur;
        REP(i, 1, N-1) {
            if(i == N-2 && sgn(a[N-1]) == 1) {
                res.pb({a[i+1], a[i]});
            } else {
                res.pb({a[i], a[i+1]});
            }
            cur = cur - a[i+1];
            a[i+1] = cur;
        }
    } else {
        int ind = 0;
        while(sgn(a[ind]) == -1) {
            ++ind;
        }
        --ind;
        int cur = a[ind];
        REP(i, ind, N-1) {
            res.pb({a[i], a[i+1]});
            cur = cur - a[i+1];
            a[i+1] = cur;
        } 
        swap(res.back().ff, res.back().ss);
        cur = res.back().ff - res.back().ss;
        REP(i, 0, ind) {
            res.pb({cur, a[i]});
            cur = cur - a[i];
        }
    }

    assert(sz(res) == N-1);

    cout << res[N-2].ff - res[N-2].ss << "\n";

    for(auto x: res) {
        cout << x.ff << " " << x.ss << "\n";
    }
    return 0;
}


Measured memory_bytes: 4708
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=100010;
const ll mod=1e9+7;

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

int main(){  
  int n;
  cin >> n;
  int ans=-1;
  rep(i,n){
    ll a; cin >> a;
    if(ans==-1){ ans = a; continue; }
    ans = gcd(ans, a);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <functional>
#include <set>
#include <iterator>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

/* Union-find
int par[100010];
int trank[100010];

void init(int n) {
   for (int i=0;i<n;i++) {
      par[i] = i;
      trank[i] = 0;
   }
}
int find(int x) {
   if (par[x] == x) {
      return x;
   } else {
      return par[x] = find(par[x]);
   }
}
void unite(int x, int y) {
   x = find(x);
   y = find(y);
   if (x == y) return;
   if (trank[x] < trank[y]) {
      par[x] = y;
   } else {
      par[y] = x;
      if (trank[x] == trank[y]) trank[x]++;
   }
}
bool same(int x, int y) {
   return find(x) == find(y);
}
*/


char S[300010];
int N;
int E_needed[300010];
int W_needed[300010];

int main() {
   cin >> N;
   cin >> S;
   for (int i=0;i<N;i++) {
      E_needed[i+1] = E_needed[i];
      if (S[i] == 'W') {
         E_needed[i+1] += 1;
      }
   }
   for (int i=N-1;i>=1;i--) {
      W_needed[i-1] = W_needed[i];
      if (S[i] == 'E') {
         W_needed[i-1] += 1;
      }
   }
   int ans = 1000000; // INF
   for (int i=0;i<N;i++) {
      int thisans = W_needed[i] + E_needed[i];
      ans = min(ans, thisans);
   }
   cout << ans << endl;
}

Measured memory_bytes: 2944