akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long arr[3001];
pair<long long,long long>ar[3001][3001];
int main()
{
	long long n,i,j;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",arr+i);
		ar[i][i].first=arr[i];
		ar[i][i].second=0;
	}
	i=1,j=2;
	long long c=j;
	while(1)
	{
		if(j==n+1 && i==1)
			break;
		c=j;
		while(j!=n+1)
		{
			if(ar[i][j-1].second+arr[j] > ar[i+1][j].second+arr[i])
			{
				ar[i][j].first=ar[i][j-1].second+arr[j];
				ar[i][j].second=ar[i][j-1].first;
			}
			else
			{
				ar[i][j].first=ar[i+1][j].second+arr[i];
				ar[i][j].second=ar[i+1][j].first;
			}
			j++;
			i++;
		}
		i=1;
		c++;
		j=c;
	}
	/*for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
			printf("%lld,%lld ",ar[i][j].first,ar[i][j].second);
		printf("\n");
	}*/
	printf("%lld\n",ar[1][n].first-ar[1][n].second);
}


Measured memory_bytes: 139648
from re import*
s,t=open(0)
t=t[:-1]
u=''.join('(%s|\?)'%t for t in t)
a=[]
j=len(t)
for i in range(len(s)-j):
  if match(u,s[i:i+j]):
    a.append(sub('\?','a',s[:i])+t+sub('\?','a',s[i+j:]))
print(min(a or['UNRESTORABLE']))

Measured memory_bytes: 38960
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;
bool graph[8][8];
 
const int NUMBER_OF_SAMPLES = 100000000;
int main(){
    int m,n;    cin >> n >> m;
    vector<int>a(n);
    double all=0;
    rep(i,n){
     cin >> a[i];
     all+=a[i];
    }
    int k=0;

    for(int i=0;i<n;i++){
    if(a[i] >= all/(4.0*m) )k++;

    }
    
    if(k >= m) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    


}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.{readLine, readInt}
    while (true) {
      val Array(nx, ny) = readLine().split(' ').map(_.toInt)
      if (nx == 0 && ny == 0) return
      val n = readInt()
      val stop = (0 until n).map(_ => readLine().split(' ').map(_.toInt)).map{case Array(x, y) => (x, y)}.toSet
      println(count(nx, ny, stop))
    }
  }

  def count(nx: Int, ny: Int, stop: Set[(Int, Int)]): Int = {
    val memo = Array.fill(nx + 1, ny + 1)(0)
    memo(1)(1) = 1
    for {
      x <- 1 to nx
      y <- 1 to ny if !stop.contains((x, y)) && (x, y) != (1, 1)
    } {
      memo(x)(y) = memo(x - 1)(y) + memo(x)(y - 1)
    }
    memo(nx)(ny)
  }
}



Measured memory_bytes: 44416
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####



def main():
	ss = input().split('T')
	x, y = map(int, input().split())
	 
	dpx = dict()
	dpy = dict()
	 
	dpx[0+len(ss[0])] = True
	dpy[0] = True
	 
	direct = 1 #0:x, 1:y
	 
	 
	for s in ss[1:]:
		tmp = dict()
		n = len(s)
		if direct%2 == 0: 
			for k, v in dpx.items():
				tmp[k+n] = True
				tmp[k-n] = True
			dpx = tmp
		else:
			for k, v in dpy.items():
				tmp[k+n] = True
				tmp[k-n] = True
			dpy = tmp

		# print(dpx, dpy)
		direct += 1
	 	

	if x in dpx and y in dpy:
	    print('Yes')
	else:
	    print('No')


if __name__ == '__main__':
	main()

Measured memory_bytes: 4584
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
ll D[10] = {};
ll K;
bool check(ll n) {
	ll t = n;
	bool ok = false;
	while (t > 0) {
		ll c = t % 10;

		rep(i, 0, K) {
			if (D[i] == c) {
				ok |= true;
			}
		}
		if (ok)break;

		t /= 10;
	}
	return ok;
}

int main() {
	ll N; cin >> N;
	ll maxV = 0;
	ll minV = 1 << 29;
	ll a[100];
	rep(i, 0, N) {
		cin >> a[i];
		maxV = max(maxV, a[i]);
		minV = min(minV, a[i]);
	}
	ll ans = 1 << 29;
	repe(j, minV, maxV) {
		ll sum = 0;
		rep(i, 0, N) {
			sum +=  (a[i] - j)*(a[i] - j);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a, b, q=0;
	char op;
	while (!q) {
		cin >> a >> op >> b;
		switch (op) {
			default:
				q = 1;
				break;
			case '+':
				cout << a + b << endl;
				break;
			case '-':
				cout << a - b << endl;
				break;
			case '*':
				cout << a * b << endl;
				break;
			case '/':
				cout << (int)(a / b) << endl;
				break;
		}
	}	
	return 0;
}


Measured memory_bytes: 3092
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    char[] c = null;
    
    sc.close();
    
    int count = 0;
    for(int i = a ; i <= b ; i++){
      c = String.valueOf(i).toCharArray();
      if( c[0] == c[4] && c[1] == c[3]){
        count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 30548
#include<stdio.h>

int main(){
	int sec=0;
	scanf("%d",&sec);
	int h=sec/3600;
	int m=(sec-h*3600)/60;
	int s=sec-(h*3600+m*60);
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}



Measured memory_bytes: 2756
#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)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i, n) cin >> a[i], a[i]--;

    vector<int> ql(q), qr(q), qi(q);
    rep(i, q) cin >> ql[i] >> qr[i], ql[i]--;
    iota(qi.begin(), qi.end(), 0);

    int width = n / sqrt(q);
    sort(qi.begin(), qi.end(), [&](int i, int j) {
        if (ql[i] / width != ql[j] / width) return ql[i] < ql[j];
        else {
            if ((ql[i] / width) % 2 == 0) return qr[i] < qr[j];
            else return qr[i] > qr[j];
        }
    });

    vector<int> cnt(n), ans(q);
    int sum = 0;
    int l = 0, r = 0;

    auto add = [&](int i) { if (cnt[a[i]]++ == 0) sum++;};
    auto del = [&](int i) { if (--cnt[a[i]] == 0) --sum;};
    
    for (int i : qi) {
        while (ql[i] < l) add(--l);
        while (r < qr[i]) add(r++);
        while (l < ql[i]) del(l++);
        while (qr[i] < r) del(--r);
        ans[i] = sum;
    }
    
    rep(i, q) cout << ans[i] << '\n';
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime 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()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<bool>> f(h, vector<bool>(w, true));

  ll ans = 0;

  rep(i, h) rep(j, w) {
    if(!f[i][j]) continue;
    char start = s[i][j];
    ll even = 0, odd = 0;

    queue<P> q;
    auto update = [&](P now) {
      int i = now.first, j = now.second;
      if(s[i][j] == start) ++even;
      else ++odd;
      rep(k, 4) {
        int ni=i+di[k], nj=j+dj[k];
        if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if(s[i][j] != s[ni][nj] && f[ni][nj]) {
          f[ni][nj] = false;
          q.push(P(ni, nj));
        }
      }
    };

    q.push(P(i, j));
    f[i][j] = false;

    while(!q.empty()) {
      P now = q.front(); q.pop();
      update(now);
    }
    ans += even*odd;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<int> x;

void plus_1() {
    int kx = x.size();
    /*
    rep(i, x.size()) {
        cout << x[kx-1-i];
    }
    cout << endl;
    */

    x[0] += 1;
    int dk = 0;
    rep(k, kx-1) {
        if (x[k] > x[k+1] + 1 || x[k] == 10) {
            x[k+1] += 1;
            // x[k] = max(0, x[k+1] - 1);
            dk += 1;
        } else {
            break;
        }
    }
    reprev(k, dk) {
        x[k] = max(0, x[k+1] - 1);
    }
    if (x[kx-1] == 10) {
        rep(k, kx) {
            x[k] = 0;
        }
        x.emplace_back(1);
    }
}

ll plus_k(int k) {
    x.emplace_back(1);
    rep(i, k-1) {
        plus_1();
    }
    ll ans = 0;
    rep(i, x.size()) {
        ans += x[i] * pow(ll(10), i);
    }
    return ans;
}

int main() {
    cout << fixed << setprecision(10);
    
    int k; cin >> k;
    ll ans;
    ans = plus_k(k);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b

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

int main()
{
    long H, W;
    cin >> H >> W;

    long cnt_odd = (H + 1) / 2;
    long cnt_even = H - cnt_odd;
    long pos_in_odd = (W + 1) / 2;
    long pos_in_even = W - pos_in_odd;

    long ans;
    if (H > 1 & W > 1)
    {
        ans = cnt_odd * pos_in_odd + cnt_even * pos_in_even;
    }
    else
    {
        ans = 1;
    }

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


Measured memory_bytes: 3572
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        String s = stdIn.next();
        char c[] = s.toCharArray();
        char z = 'Z';
        
        for(int i = 0; i < s.length(); i++){
            if(c[i] + (n % 26) > z){
                c[i] += n % 26 - 26;
            }else{
                c[i] += n % 26;
            }
            
        }
        
        
        for(int i = 0; i < s.length(); i++){
            if(i != s.length() - 1){
                System.out.print(c[i]);
            }else{
                System.out.println(c[i]);
            }
        }
    }
}


Measured memory_bytes: 27860
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    ll n, a, b; cin >> n >> a >> b;
    ll ans = n/(a+b)*a;
    if (n%(a+b) >= a) ans += a;
    else if (n%(a+b) >= 0) ans += n%(a+b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
m=N-1

D=0
while m>=0:
 if V[m]-C[m]>=0:
  D=D+V[m]-C[m]
 else:D=D
 m=m-1

print(D)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

#define M 1046527
#define NIL (-1)
#define L 14

int getChar(char);
long long getKey(char st[]){
  long long sum=0,p=1,i;
  for(i=0;i<strlen(st);i++){
    sum+=p*(getChar(st[i]));
    p*=5;
  }
  return sum;
}
int h1(int);
int h2(int);
int find(char*);
int insert(char*);

char H[M][L];

int main(){
  int i,n,h;
  char st[L],com[9];
  
  for(i=0;i<M;i++)
    H[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,st);
  if(com[0]=='i')
    insert(st);
  else {
    if(find(st))
      printf("yes\n");
    else printf("no\n");
  }
  }
  return 0;
}
int getChar(char c){
  if(c=='A')return 1;
  else if (c=='C')return 2;
  else if(c=='G')return 3;
  else if(c=='T')return 4;
  else return 0;
}

int h1(int k){
  return k % M;
}
int h2(int k){
  return 1+(k%(M-1));
}
int find(char* st){
  long long k,i,h;
  k=getKey(st);
  for(i=0;;i++){
    h=(h1(k)+i*h2(k))%M;
    if(strcmp(H[h],st)==0)
      return 1;
    else if(strlen(H[h])==0)
      return 0;
  }
  return 0;
}
int insert(char* st){
  long long k,i,h;
  k=getKey(st);
  for(i=0;;i++){
    h=(h1(k)+i*h2(k))%M;
    if(strcmp(H[h],st)==0)
      return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],st);
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 16056
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P,ll> B;
const int MOD = 1000000007;
const ll INF=2e18;
const double EPS=1e-10;

ll N,R;
int main(){
    while(cin>>R>>N,R!=0){
        ll minL=INF,maxR=-INF;
        map<ll,ll> lHeight;
        map<ll,ll> rHeight;
        for(ll i=0;i<N;i++){
            ll l,r,h;
            cin>>l>>r>>h;
            minL=min(minL,l);
            maxR=max(maxR,r);
            for(ll j=l;j<r;j++){
                if(lHeight.count(j)!=0){
                    lHeight[j]=max(lHeight[j],h);
                }else{
                    lHeight[j]=h;
                }
            }
            for(ll j=l+1;j<=r;j++){
                if(rHeight.count(j)!=0){
                    rHeight[j]=max(rHeight[j],h);
                }else{
                    rHeight[j]=h;
                }
            }
        }
        double ans=INF;
        //R-t+h==R*R-w*w;
        //2R-t
        for(ll w=-R+1;w<R;w++){
            ll h=min(lHeight[w],rHeight[w]);
            if(R>abs(w))
                ans=min(ans,R+h-sqrt(R*R-w*w));
        }
        cout<<setprecision(10)<<ans<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3304
// C - To Infinity
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	string S; ll K; cin>>S>>K;
	int ans = 0;
	for(char s:S){
		ll x = s-'0';
		if(x > 1){
			ans = x;
			break;
		}
		else{
			K--;
			if(K<=0){
				ans = x;
				break;
			}
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int N, M;
vector< int > cg[1000], rg[1000], g[1000];
bool v[1000];
vector< int > order;
int cmp[1000];
bool connect[1000][1000];
bool in[1000];
long long dp[1000];

void dfs(int idx)
{
  for(int to : cg[idx]) if(!v[to]++) dfs(to);
  order.push_back(idx);
}
void rdfs(int idx, int k)
{
  cmp[idx] = k;
  for(int to : rg[idx]) if(cmp[to] == -1) rdfs(to, k);
}
int scc()
{
  int k = 0;
  for(int i = 0; i < N; i++) if(!v[i]) dfs(i);
  memset(cmp, -1, sizeof(cmp));
  reverse(order.begin(), order.end());
  for(int i : order) if(cmp[i] == -1) rdfs(i, k++);
  return(k);
}

long long rec(int idx)
{
  if(dp[idx]) return(dp[idx]);
  long long ret = 1;
  for(int to : g[idx]) (ret *= rec(to)) %= mod;
  return(dp[idx] = (ret + 1) % mod);
}

int main()
{
  cin >> N >> M;
  
  while(M--) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    cg[B].push_back(A);
    rg[A].push_back(B);
  }
  int c = scc();
  for(int i = 0; i < N; i++) {
    for(int to : cg[i]) {
      if(cmp[i] == cmp[to]) continue;
      if(connect[cmp[i]][cmp[to]]++) continue;
      g[cmp[i]].push_back(cmp[to]);
      in[cmp[to]] = true;
    }
  }
  long long ret = 1;
  for(int i = 0; i < c; i++) {
    if(!in[i]) (ret *= rec(i)) %= mod;
  }
  cout << ret << endl;
}

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

int main(){
	string s ; cin >> s ;
	for(int i=1;i<s.size();i++){
		if(i==1){
			if(s.at(0)==s.at(1)){
				cout << "1 2" << endl ;
				return 0 ;
			}
		}else{
			if(s.at(i)==s.at(i-1)){
				cout << i << " " << i+1 << endl ;
				return 0 ;
			}
			if(s.at(i)==s.at(i-2)){
				cout << i-1 << " " << i+1 << endl ;
				return 0 ;
			}
		}
	}
	cout << "-1 -1" << endl ;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

map< int , int > mp[nax];
int main()
{
	string s;
	cin >> s;
	cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
	return 0;
} 




Measured memory_bytes: 93952
#include <iostream>
#include <climits>

using namespace std;

#define N 1000000
#define MAXVALUE 1000000000

struct Card
{
    int key;
    char symbol;
};

Card CARD[N], CARD2[N];
int length;

void swap(Card*, Card*);
int partition(int, int);
void quicksort(int , int);

void merge(int, int, int);
void mergesort(int, int);

int main() {
    int index = 0;

    cin >> length;
    for(int i=0; i < length; ++i) {
        cin >> CARD[i].symbol >> CARD[i].key;
        CARD2[i].symbol = CARD[i].symbol;
        CARD2[i].key = CARD[i].key;
    }

    quicksort(0, length-1);
    mergesort(0, length);

    bool stability = true;
    for(int i=0; i < length; ++i) {
        if(CARD[i].symbol != CARD2[i].symbol) stability = false;
    }

    if(stability == true)
        cout << "Stable" << endl;
    
    else 
        cout << "Not stable" << endl;

    for(int i=0; i<length; ++i) {
        cout << CARD[i].symbol << " " << CARD[i].key << endl;
    }

    return 0;
}

void swap(Card *p1, Card *p2) {
    Card tmp;
    tmp = *p2;
    *p2 = *p1;
    *p1 = tmp;
}

int partition(const int p, const int r) {
    int x = CARD[r].key, i = p-1;

    for(int j=p; j < r; ++j) {
        if(CARD[j].key <= x) {
            i++;
            swap(&CARD[i], &CARD[j]);
        }
    }
    swap(&CARD[i+1], &CARD[r]);

    return (i+1);
}

void quicksort(int p, int r) {
    if(p < r) {
        int q;
        q = partition(p, r);
        quicksort(p, q-1);
        quicksort(q+1, r);
    }
}

void merge(int left, int mid, int right) {
    int i=0, j=0;
    int n1 = mid - left, n2 = right - mid;
    Card *L = new Card[n1+1], *R = new Card[n2+1];

    for(i=0; i<n1; ++i) {
        L[i] = CARD2[left+i];
    } 

    for(i=0; i<n2; ++i) {
        R[i] = CARD2[mid+i];
    }

    L[n1].key = R[n2].key = INT_MAX;
    i = j = 0;
    for(int k = left; k < right; ++k) {
        if(L[i].key <= R[j].key) {
            CARD2[k] = L[i];
            i++;
        }

        else {
            CARD2[k] = R[j];
            j++;
        }
    }
}   

void mergesort(int left, int right) {
    if(left+1 < right) {
        int mid = (left + right) / 2;
        mergesort(left, mid);
        mergesort(mid, right);
        merge(left, mid, right);
    }
}


Measured memory_bytes: 21908
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[3010];
vector<int> vec[3010];

bool dfs(int v, int p, int k) {
	bool bl = false;
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i] == p)continue;
		if (a[v] > a[vec[v][i]])bl = true;
	}
	if (!bl) {
		if (k % 2)return true;
		else return false;
	}
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i] == p)continue;
		if (a[v] <= a[vec[v][i]])continue;
		if (k % 2 && !dfs(vec[v][i], v, k + 1))return false;
		if (k % 2 == 0 && dfs(vec[v][i], v, k + 1))return true;
	}
	if (k % 2)return true;
	else return false;
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		if (dfs(i, 0, 0))cout << i << " ";
	}
	cout << endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int n,l,max,sum;
    max = 0;
    sum = 0;
    cin >> n;

    for(int i = 0; i < n; ++i)
    {
        cin >> l;
        if(l > max)
        {
            sum += max;
            max = l;
        }
        else sum += l;
    }

    if(sum > max) cout << "Yes";
    else cout << "No";

    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
bool visited[51][51];
int h, w;
int A[] = {1, 1, 1, 0, 0, -1, -1, -1};
int B[] = {0, 1, -1, 1, -1, 0, 1, -1};
void dfs(int x, int y, vv(int) & c) {
    if (x < 0 || x >= h || y < 0 || y >= w || c[x][y] == 0)
        return;
    if (visited[x][y])
        return;
    visited[x][y] = true;
    //cout<<"(x,y)=="<<x<<","<<y<<endl;
    rep(i, 8) {
        dfs(x + A[i], y + B[i], c);
    }
}

int main() {
   while (1) {
        cin >> w >> h;
        if(w==0 && h==0) return 0;
        vv(int) c;
        rep(i, h) {
            c.push_back({});
            rep(j, w) {
                int a;
                cin >> a;
                c[i].push_back(a);
            }
        }
        rep(i, 51) {
            rep(j, 51) {
                visited[i][j] = false;
            }
        }
        int ans = 0;
        rep(i, h) {
            rep(j, w) {
                if (visited[i][j] || c[i][j] == 0)
                    continue;
                dfs(i, j, c);
                //cout<<"dfs"<<endl;
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3276
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint s;

llint keta(llint x)
{
	llint ret = 0;
	for(;x;x/=10) ret++;
	return ret;
}

llint pow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (pow(a, n-1)%mod)) % mod;
	}
	else{
		return pow((a*a)%mod, n/2) % mod;
	}
}

int main(void)
{
	cin >> s;
	llint l, r = 0, sum = 0;
	
	llint ans = 0;
	for(l = 1; l <= 1e6; l++){
		sum -= keta(l-1);
		for(; sum < s; r++, sum += keta(r));
		if(keta(r) - keta(l) < 2) continue;
		if(sum == s) ans++, ans %= mod;
	}
	
	llint ub = s;
	//if(keta(l) > 1) ub = min(s, (s+keta(l)-2) / (keta(l)-1));
	llint num[] = {0, 9, 90, 900, 9000, 90000, 900000, 9000000, 90000000, 900000000};
	for(llint i = 1; i <= ub; i++){
		llint q = s / i, r = s % i;
		if(r){
			if((q > 9 || num[q] >= i-r) && (q+1 > 9 || num[q+1] >= r) ) ans++, ans %= mod;
		}
		else{
			if(q > 9 || num[q] >= i){
				llint cnt = (9 * pow(10, q-1) + (mod-i) + 1) % mod;
				//cout << q << " " << cnt << endl;
				ans += cnt, ans %= mod;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[105];

int main(){
	int n;
	int hasil=0;
	cin>>n;
	int x=1;
	for(int i=1;i<=n;i++){
		
		cin>>a[i];
		if(a[i]%2==1&&x%2==1)hasil++;
		x++;
	}

	cout<<hasil<<endl;
	
}

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

int main() {
  int a,b,c; cin >> a >> b >> c;
  int s = a + b;
  int t = a + c;
  int u = b + c;
  if (s <= t && s <= u) cout << s;
  else if (t <= s && t <= u) cout << t;
  else cout << u;
}

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(ll i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const ll MAX = 1e6;
const ll MOD = 1e9+7;

ll N;

//階乗とその逆元
ll fac[MAX+1],facInv[MAX+1];

ll power(ll e, ll x){ //e^x % MOD
	if (x == 0) return 1LL;
	if (x % 2 != 0) return ((power(e, x-1) * e) % MOD);
	ll temp = power(e, x / 2);
	return (temp * temp) % MOD;
}

ll nck(ll n, ll k){
	if (!(n >= k && k >= 0)) return 0;
	ll temp = (fac[n] * facInv[n-k]) % MOD;
	return ((temp * facInv[k]) % MOD);
}

void fact(void){
	//階乗とその逆元
	fac[0] = facInv[0] = 1; //0! = 1
	//(x!)^(-1) ≡ (x!)^(p-2) (mod p)
	Rep(1, MAX, i) fac[i] = (fac[i-1] * i) % MOD;
	facInv[MAX] = power(fac[MAX], MOD-2);
	Rep(1, MAX-1, i) facInv[MAX-i] = (facInv[MAX-i+1] * (MAX-i+1)) % MOD;
}

ll calc(ll k) {
	ll a = 2*k - N, b = N - k - 1LL;
	return (nck(a+b, b)*fac[k]%MOD)*fac[N-k-1LL]%MOD;
}

void solve(void){
	cin >> N;
	fact();
	vector <ll> res(N);
	rep(N, i) res[i] = calc(i);
	ll ans = 0LL;
	Rep(1, N-1, i) {
		ans += i*(res[i]-res[i-1]+MOD)%MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 23680
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))

sum1, sum2 = [0], [0]
for i in range(n):
    sum1.append(sum1[i] + a1[i])
for i in range(n-1, -1, -1):
    sum2.append(sum2[n-i-1] + a2[i])

ans = 0
for i in range(1, n+1):
    count = sum1[i] + sum2[n-i+1]
    if ans < count:
        ans = count

print(ans)

Measured memory_bytes: 3064
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine());

        BigInteger prod = new BigInteger("1");
        StringTokenizer st = new StringTokenizer(br.readLine());

        String[] arr = new String[n];

        for (int i = 0; i < n; i++) {
            arr[i] = (st.nextToken());
            if (arr[i].equals("0")) {
                pw.println("0");
                pw.close();
                return;
            }
        }

        for (String x : arr) {
            prod = prod.multiply(new BigInteger(x));
            if (prod.compareTo(new BigInteger("1000000000000000000")) > 0) {
                pw.println("-1");
                pw.close();
                return;
            }
        }

        pw.println(prod);
        pw.close();
    }
}


Measured memory_bytes: 61772
#include <bits/stdc++.h>
#define foru(i, a, b) for(int i = int(a); i <= int(b); i++)
using namespace std;

const int N = 5005;

int n, m, dp[N][N];

int main() {
    //freopen("a.txt", "r", stdin);

    scanf("%d%d", &n, &m);
    foru(i, 1, m) {
        int ai, bi, xi;
        scanf("%d%d%d", &ai, &bi, &xi);
        dp[ai][bi] = xi + 1;
    }
    int ans = 0;

    foru(i, 1, n) foru(j, 1, i) {
        dp[i][j] = max(dp[i][j], max(dp[i-1][j-1], dp[i-1][j]) - 1);
        if (dp[i][j]) ans++;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 97376
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}


vector<vector<Int>> vv(100005);

Int P[100005];
Int Y[100005];

int main(){
    cin.tie(0);

    Int N; cin >> N;
    Int M; cin >> M;
    for (int i = 0; i < M; i++){
        cin >> P[i] >> Y[i];
        vv[P[i]].push_back(Y[i]);
    }
    for (int i = 1; i <= N; i++){
        sort(vv[i].begin(), vv[i].end());
    }
    for (int i = 0; i < M; i++){
        int left = (lower_bound(vv[P[i]].begin(), vv[P[i]].end(), Y[i]) - vv[P[i]].begin());
        left++;
        printf("%06d", P[i]);
        printf("%06d", left);
        printf("\n");
    }
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if((a <= b && b <= a+w)||(a<= b+w && b+w <= a+w)){
    cout << 0 << endl;
  }
  else {
    int x=abs(b-w-a);
    int y=abs(a-b-w);
    int answer = min(x,y);
    cout << answer  <<endl;}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		string a[40];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int sum=0;
			int i2 = -1;
			for (int j = i; j < n; j++) {
				sum += a[j].length();
				if (sum == 5) {
					i2 = j+1;
					break;
				}
			}
			if (i2 == -1) goto stop;
			if (i2 != -1) {
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 5) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				bool l = true;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				ans = i;
				break;
			}
		stop:;
		}
		cout << ans+1 << endl;
	}
}

Measured memory_bytes: 3136
import java.util.Scanner;
 
public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) break;
            if(m == -1 || f == -1) { System.out.println('F'); continue; }
            if(m + f >= 80) { System.out.println('A'); continue; }
                if(m + f >= 65) { System.out.println('B'); continue; }
                if(m + f >= 50) { System.out.println('C'); continue; }
            if(m + f >= 30) {
                    if(r >= 50) System.out.println('C');
                else System.out.println('D');
                continue;
            }
            System.out.println('F');
             
        }
    }
}


Measured memory_bytes: 26472
import itertools
n = int(input())
l = list(map(int, input().split()))

l.sort()
ans = 0
f = l[0]
for i in range(len(l)):
    less = l[:i]
    for v in itertools.combinations(less, 2):
        if v[0] != v[1]:
            if l[i] < v[0] + v[1]:
                if not l[i] in v: 
                    ans += 1
print(ans)

Measured memory_bytes: 9192
using System;

namespace ALDS1_1
{
    class Program
    {
        static int IsPrime(int n)
        {
            int i;

            if (n < 2)
                return 0;
            else if (n == 2)
                return 1;

            if (n % 2 == 0)
                return 0;

            for (i = 3; i <= n / i; i += 2)
                if (n % i == 0)
                    return 0;
            return 1;
        }
        static void Main(string[] args)
        {
            int ans = 0;
            int N = int.Parse(Console.ReadLine());
            for (int i = 0; i < N; i++)
            {
                int A = int.Parse(Console.ReadLine());
                if (A % 2 == 0 && A != 2)
                {
                    goto Go;
                }
                if (IsPrime(A) == 1)
                    ans++;
                Go:;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 9060
N,M = map(int,input().split())
r = [[] for _ in range(N)]
for _ in range(M):
    A_,B_ = map(int,input().split())
    r[A_-1].append(B_-1)
    r[B_-1].append(A_-1)

ans = [0]*N
t = [0]*N
p = [0]

def k(p,t,ans):
    s = []
    for i in p:
        a = r[i]
        for z in a:
            if t[z] == 0:
                s.append(z)
                ans[z] = i
                t[z] = 1
    p = s
    return p,t,ans

while len(p) > 0:
    p,t,ans = k(p,t,ans)

for i in range(N-1):
    if r[i+1] == 0:
        print('No')
        exit()
print('Yes')
for i in range(N-1):
    print(ans[i+1]+1)

Measured memory_bytes: 34556
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i);
#define all(x) (x).begin(),(x).end();
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll x, y, cnt=0;
	cin >> x >> y;
	while (x <= y)x*=2,cnt++;
	cout << cnt << endl;
}


Measured memory_bytes: 256
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func NextFloat() float64 {
  n, _ := strconv.ParseFloat(NextLine(), 64)
  return n
}
func NextFloatVec() []float64 {
  L := strings.Split(NextLine(), " ")
  N := make([]float64, len(L))
  for i := range N {
    N[i], _ = strconv.ParseFloat(L[i], 64)
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

const p = 998244353

func Solve() {
  N := NextInt()
  A := make([]int, N)
  for i := range A {
    A[i] = NextInt()
  }
  S := SumInt(A...)
  L := S / 2 + 1
  DP := make([][]int, N + 1)
  DP2 := make([][]int, N + 1)
  for i := range DP {
    DP[i] = make([]int, L + 1)
    DP2[i] = make([]int, L + 1)
  }
  DP[0][0] = 1
  DP2[0][0] = 1
  for i, a := range A {
    for j := range DP[i] {
      DP[i + 1][j] += 2 * DP[i][j]
      DP[i + 1][j] %= p
      DP[i + 1][MinInt(j + a, L)] += DP[i][j]
      DP[i + 1][MinInt(j + a, L)] %= p
      DP2[i + 1][j] += DP2[i][j]
      DP2[i + 1][j] %= p
      DP2[i + 1][MinInt(j + a, L)] += DP2[i][j]
      DP2[i + 1][MinInt(j + a, L)] %= p
    }
  }
  P := 1
  for i := 0; i < N; i++ {
    P = P * 3 % p
  }
  ans := (P + 3 * (p - DP[N][L])) % p
  if S % 2 < 1 { ans = (ans + 3 * (p - DP[N][S / 2] + DP2[N][S / 2])) % p}
  Write(ans)
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 218752
#include <iostream>
#include <vector>
#include <ios>
#include <limits.h>
using namespace std;
int n, k, sum;

int GetMax(int a, int b) { return (a > b ? a : b); }

int ceilOfAverage(int s, int q)
{
	return ((double)s / (double)q + 0.9999);
}

bool partition(const vector<int>& vN, int minCand)
{
	int i, subsum = 0, s = vN.size(), w = 0, p = 0, r;
	for (i = 0; i < s; ++i){
		if (w + vN[i] <= minCand){
			w += vN[i];
		}else{
			subsum += w;
			w = vN[i];
			++p;
			if (p == k)
				return false;
			if (i != s - 1){
				r = ceilOfAverage(sum - subsum, k - p);
				if (r > minCand)
					return false;
			}
		}
	}

	return true;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	vector<int> vN(n, 0);
	int maxV = INT_MIN;
	for (int i = 0; i < n; ++i){
		cin >> vN[i];
		sum += vN[i];
		if (vN[i] > maxV)
			maxV = vN[i];
	}
	int l, r, m;
	l = GetMax(ceilOfAverage(sum, k), maxV);
	r = l + maxV;
	while (l < r){
		m = (l + r) / 2;
		if (partition(vN, m)) r = m;
		else l = m + 1;
	}

	cout << l << "\n";

	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String S = in.next();
		
		int[] dp = new int[n];
		int westCount = 0;
		dp[0] = 0;
		if(S.charAt(0)=='W') westCount++;
		
		for(int i=1;i<n;i++) {
			if(S.charAt(i)=='W') {
				dp[i] = dp[i-1];
				westCount++;
			}else{
				dp[i] = Math.min(dp[i-1]+1, westCount);
			}
		}
		
		System.out.println(dp[n-1]);
		
		in.close();
	}

}


Measured memory_bytes: 28928
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
ans = 0
s_dic = {i:0 for i in s}

for j in range(n):
	if s[j] in s_dic :
		s_dic[s[j]] += 1

print(sum(s_dic[k] * (s_dic[k] - 1) // 2 for k in s_dic))


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

int main() {
  int a,b;
  cin >> a >> b;
  for(int c = 1; c <= 3; c++){
    if(a * b * c % 2 == 1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a < b:
    if (b + t*w) > (a + t*v) :
        print("NO")
    else:
        print("YES")
else:
    if (b-t*w) < (a-t*v):
        print("NO")
    else:
        print("YES")

Measured memory_bytes: 61612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define DUMP(v) for(auto& x : v) cerr << x << " "; cerr << endl;
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

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

  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);

  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];

  vector<ll> bc(y * z);
  rep(i, y) {
    rep(j, z) {
      bc.push_back(b[i] + c[j]);
    }
  }

  sort(bc.rbegin(), bc.rend());
  bc.resize(min(3000, int(bc.size())));

  vector<ll> abc;
  rep(i, x) {
    rep(j, bc.size()) {
      abc.push_back(a[i] + bc[j]);
    }
  }

  sort(abc.rbegin(), abc.rend());

  rep(i, k) {
    cout << abc[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 58740
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
const double EPS = 1e-6 ; 
int H , n ;
vector<int> A , B ; 
int dp[(int)1e3 + 5][(int) 1e4 + 5] ;
int dfs(int x, int cur){
    if ( cur >= H ) return 0 ; 
    if ( x == n ){
        return INF ;
    }
    if ( dp[x][cur] != -1 ) return dp[x][cur] ; 
    int choice1 = INF ; 
    int choice2 = INF ; 
    choice1 = dfs(x + 1, cur) ;
    choice2 = B[x] + dfs(x, cur + A[x]) ;
    return dp[x][cur] = min(choice1, choice2) ; 
}
signed main(){
    fastio
    memset(dp, -1, sizeof dp) ;
    cin >> H >> n ; 
    A.resize(n) ;
    B.resize(n) ;
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i] ; 
    }
    int ans = dfs(0, 0) ;
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N,K;cin>>N>>K;
  vll p(N);rep(i,N)cin>>p[i];
  sort(all(p));
  ll ans=0;
  rep(i,K){
    ans += p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
vector<vector<int>> v(200001);
vector<ll> score(200001,0);
vector<bool> f(200001, false);

//使用する関数
void dfs(int a, ll s) {
	//cout << a << endl;
	if (f[a])return;
	//cout << "done" << endl;
	f[a] = true;
	score[a] += s;
	REP(i, v[a].size()) {
		dfs(v[a][i], score[a]);
	}
}

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

	REP(i, n-1) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	REP(i, q) {
		int p, x;
		cin >> p >> x;
		score[p] += x;
	}
	dfs(1, 0);

	REPS(i, n) {
		cout << score[i];
		if (i == n) {
			cout << endl;
		}
		else {
			cout << " ";
		}
	}

}

Measured memory_bytes: 21120
program redistribution
  implicit none
  integer :: s
  integer(8) :: m(3, 3) = 0
  read(*,*) s
  if (s < 6) then
    write(*,'(i0)') s / 3
    stop
  end if
  m(1, 1) = 1
  m(2, 1) = 1
  m(3, 2) = 1
  m(1, 3) = 1
  m = modmatpow(m, s - 6)
  write(*,'(i0)') mod(m(1, 1) + m(1, 1) + m(1, 2) + m(1, 3), 1000000007_8)
contains
  function modmatmul(x, y) result(res)
    integer(8), parameter :: modu = 1000000007_8
    integer(8), intent(in) :: x(3, 3), y(3, 3)
    integer(8) :: tmp, res(3, 3)
    integer :: i, j, k
    do j = 1, 3
      do i = 1, 3
        res(i, j) = 0
      end do
      do k = 1, 3
        tmp = y(k, j)
        do i = 1, 3
          res(i, j) = mod(res(i, j) + x(i, k) * tmp, modu)
        end do
      end do
    end do
  end
  function modmatpow(x, n) result(res)
    integer(8), intent(in) :: x(3, 3)
    integer, intent(in) :: n
    integer(8) :: res(3, 3), tmp(3, 3)
    integer :: m
    res(1, 1) = 1
    res(2, 1) = 0
    res(3, 1) = 0
    res(1, 2) = 0
    res(2, 2) = 1
    res(3, 2) = 0
    res(1, 3) = 0
    res(2, 3) = 0
    res(3, 3) = 1
    tmp = x
    m = n
    do while (m > 0)
      if (btest(m, 0)) res = modmatmul(res, tmp)
      tmp = modmatmul(tmp, tmp)
      m = rshift(m, 1)
    end do
  end
end program redistribution

Measured memory_bytes: 2840
a, b, c = map(int, input().split())
ans = 0

while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == b == c:
        print(-1)
        exit()
    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
    ans += 1
print(ans)


Measured memory_bytes: 2940