akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend()))

int dp[3010][3010];

int main () {

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

    rep(i,3010) {
        dp[0][i]=0;
        dp[i][0]=0;
    }

    rep(i,s.size()) {
        rep(j,t.size()) {
            if (s[i]==t[j]) {
                dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1]);
            }
            else {
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
    cout << res << endl;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N;
int A[111111];

signed main() {
  cin >> N;
  int mCnt = 0;
  rep (i, N) {
    cin >> A[i];
    if (A[i] < 0) mCnt++;
  }

  int ans = 0;
  if (mCnt % 2 == 0) {
    rep (i, N) {
      ans += abs(A[i]);
    }
  } else {
    rep (i, N) {
      A[i] = abs(A[i]);
    }
    sort(A, A+N);
    ans -= A[0];
    repp (i, 1, N) {
      ans += A[i];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
/* Justin Choi */
#include <bits/stdc++.h>
using namespace std;

string FILENAME = "filename";
#define io ifstream fin(FILENAME + ".in"); ofstream fout(FILENAME + ".out")
#define fwrite(X) fout << X;
#define fwriteln(X) fout << X << endl;
#define qio ios_base::sync_with_stdio(false); cin.tie(NULL)

#define forl(V, N) for(int V = 0; V < N; V++)
#define for1(V, N) for(int V = 1; V <= N; V++)
#define fore(E, X) for(auto &E:X)
#define newl cout << endl
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define rem(X) X.top(); X.pop()
#define setmin(A, B) A = min(A, B)
#define setmax(A, B) A = max(A, B)

#define graph unordered_map<int, unordered_set<int>>
#define um unordered_map
#define us unordered_set
#define vi vector<int>
#define pi pair<int, int>
#define ll long long
#define pb push_back
#define mp make_pair
#define ins insert

int main() {
    qio; int a, b, c; cin >> a >> b >> c;
    us<int> z; z.ins(a); z.ins(b); z.ins(c);
    if(z.size() == 2) println("Yes");
    else println("No");
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int a[10];
  string s; cin >> s;
  for(int i=0;i<4;i++) a[i] = s[i] - '0';
  
  for(int bit=0;bit<(1<<3);bit++){
    int sum = a[0];
    for(int i=0;i<3;i++){
      if(bit&(1<<i)) sum += a[i+1];
      else sum -= a[i+1];
    }
    if(sum==7){
      cout << a[0];
      for(int i=0;i<3;i++){
        if(bit&(1<<i)){
          cout << '+' << a[i+1];
        }else{
          cout << '-' << a[i+1];
        }
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
s = input()

alphaset = set()
for i in range(97, 97+27):
    alphaset.add(chr(i))
    

if len(s) < 26:
    for c in list(s):
        alphaset.remove(c)
        
    alphalist = list(alphaset)
    alphalist.sort()
    
    print(s + alphalist[0])
    
else:
    if s == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        
    else:
        c = list(s)
        point = 100
        for i in range(25,0,-1):
            if c[i-1] > c[i]:
                continue
            else:
                old = c[i-1]
                for ci in c[:i]:
                    alphaset.remove(ci)
                    
                alphalist = list(alphaset)
                alphalist.sort()
                
                j = 0
                while old > alphalist[j]:
                    j += 1
                c[i-1] = alphalist[j]
                point = i
                break
        
        print("".join(c[:point]))
            

Measured memory_bytes: 3188
from collections import defaultdict

def foo():
	H, W = map(int, input().split())
	s = ""
	for _ in range(H):
		s += input()

	counter = defaultdict(int)
	for c in s:
		counter[c] += 1

	x1, x2 = H // 2, H % 2
	y1, y2 = W // 2, W % 2

	n = x1 * y1
	k = 0
	for c in counter:
		if k == n:
			break
		while k != n and counter[c] >= 4:
			k += 1
			counter[c] -= 4

	if k != n:
		print("No")
		return

	if x2 == 1:
		n = y1
		k = 0
		for c in counter:
			if k == n:
				break
			while k != n and counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return

	if y2 == 1:
		n = x1
		k = 0
		for c in counter:
			if k == n:
				break
			while k != n and counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return
			
	print("Yes")

foo()



Measured memory_bytes: 3316
#include <cstdio>
#include <vector>

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  std::vector<double> sum(n + 1);
  double ret = 0;
  for (int i = 1; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    sum[i] = (p + 1) * 0.5 + sum[i - 1];
    if (i >= k && sum[i] - sum[i - k] >= ret) ret = sum[i] - sum[i - k];
  }
  printf("%.10f\n", ret);
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
h = [int(i) for i in input().split()]

current = h[0]
count = 0
max_count = -1
for i in range(1, n):
    if current < h[i]:
        if max_count < count:
            max_count = count
        count = 0
    else:
        count += 1
    current = h[i]
if max_count < count:
    max_count = count
print(max_count)

Measured memory_bytes: 14228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll a[n+1];
  ll sa=0,sb=0;
  for(ll i=1;i<=n;i++){
    cin>>a[i];
    if(i%2==0)sa+=max((ll)0,a[i]);
    else sb+=max((ll)0,a[i]);
  }
  if(max(sa,sb)==0){
    ll ma=-1000000000000;
    ll num;
    for(ll i=1;i<=n;i++){
      if(ma<a[i]){
        ma=a[i];
        num=i;
      }
    }
      cout<<ma<<endl;
      cout<<n-1<<endl;
      for(ll i=1;i<num;i++)cout<<1<<endl;
      for(ll i=n-num+1;i>1;i--)cout<<i<<endl;
      return 0;
  }
  if(sa>=sb){
    cout<<sa<<endl;
    vector<ll> ans,v;
    for(ll i=n;i>=1;i--){
      if(i%2==0&&a[i]>0)v.push_back(i);
    }
    for(ll i=0;i<v.size()-1;i++){
      ll mid=(v[i]+v[i+1])/2;
      for(ll j=mid;j>v[i+1];j--)ans.push_back(j);
    }
    ll as=ans.size();
    v[0]=v[v.size()-1];
    for(ll i=n-as*2;i>v[0];i--)ans.push_back(i);
    for(ll i=1;i<v[0];i++)ans.push_back(1);
    cout<<ans.size()<<endl;
    for(ll i=0;i<ans.size();i++)cout<<ans[i]<<endl;
  }
  else{
    cout<<sb<<endl;
    vector<ll> ans,v;
    for(ll i=n;i>=1;i--){
      if(i%2==1&&a[i]>0)v.push_back(i);
    }
    for(ll i=0;i<v.size()-1;i++){
      ll mid=(v[i]+v[i+1])/2;
      for(ll j=mid;j>v[i+1];j--)ans.push_back(j);
    }
    ll as=ans.size();
    v[0]=v[v.size()-1];
    for(ll i=n-as*2;i>v[0];i--)ans.push_back(i);
    for(ll i=1;i<v[0];i++)ans.push_back(1);
    cout<<ans.size()<<endl;
    for(ll i=0;i<ans.size();i++)cout<<ans[i]<<endl;
  }
}  
      
      
  

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
static const llint MOD = 1e9 + 7;

// rambda
//第一要素が同一ならば第二要素の小さい方を返す
// return get<0>( x ) == get<0>( y ) ? get<1>( x ) < get<1>( y ) : get<0>( x ) > get<0>( y );
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    llint n, k;
    cin >> n >> k;

    vector<llint> a(n);
    vector<llint> p;
    vector<llint> m;
    llint cntminus = 0;
    for(llint in=0;in<n;in++) {
        cin >> a[in];
        if (a[in]>=0) {
            p.push_back(a[in]);
        }
        else {
            m.push_back(a[in]); 
            cntminus++;
        }
    }

    llint ans = 1LL;
    if(n==k) {
        for(llint ik=0;ik<k;ik++) {
            ans *= a[ik];
            ans %= MOD;
        }
        if(ans<0) ans += MOD;
        cout << ans << endl;
        return 0;
    }
    else if(cntminus==n&&k%2==1) {
        sort(a.begin(), a.end(), greater<llint>());
        for(llint ik=0;ik<k;ik++) {
            ans *= a[ik];
            ans %= MOD;
        }
        if(ans<0) ans += MOD;
        cout << ans << endl;
        return 0;
    }
    else {
        sort(p.begin(), p.end(), greater<llint>());
        sort(m.begin(), m.end());

        vector<llint> s;
        llint st = 0;
        if(k%2==1) {
            s.push_back(p[0]);
            k--;
            for(int i=0;i<static_cast<int>(p.size())-1;i++) {
                p[i] = p[i+1];
            }
            st = 1;
        }

        vector<tuple<llint, llint, llint>> pm2;
        for(llint i=0;i<static_cast<int>(p.size()-st)/2;i++) {
            pm2.push_back(make_tuple(p[2*i], p[2*i+1], p[2*i]*p[2*i+1]));
        }
        for(llint i=0;i<static_cast<int>(m.size())/2;i++) {
            pm2.push_back(make_tuple(-m[2*i],-m[2*i+1], m[2*i]*m[2*i+1]));
        }

        sort(begin(pm2), end(pm2), compTuple);
        for(int i=0;i<k/2;i++) {
            int mul1 = get<0>(pm2[i]);
            int mul2 = get<1>(pm2[i]);
            s.push_back(mul1);
            s.push_back(mul2);
        }
        for(auto is:s) {
            ans *= is;
            ans %= MOD;
        }
        if(ans<0) ans += MOD;
        cout << ans << endl;
    }
    return 0;
}


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


void solve(long long K, long long N, std::vector<long long> A){
    long long deltaSum = 0;
    long long maxDelta = 0;
    rep(i,N-1){
        deltaSum += A[i+1] - A[i];
        if(A[i+1] - A[i] > maxDelta){
            maxDelta = A[i+1] - A[i];
        }
    }
    deltaSum += abs(A[0] - A[N-1] + K);
    if(abs(A[0] - A[N-1] + K) > maxDelta){
        maxDelta = abs(A[0] - A[N-1] + K);
    }

    cout << deltaSum - maxDelta << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, A);
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define repi(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  int N,T,A; cin >> N >> T >> A;
  int diff = 1000000;
  int ans;
  rep(i,N) {
    int H; cin >> H;
    int temp = T * 1000 - H * 6;
    int diff_ = abs(temp - A * 1000);
    if(diff_ < diff) {
      diff = diff_;
      ans = i+1;     
    }
  }
  cout << ans << endl;
  return 0;
}


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

main(){
    int H=1, W=1;
    while(H&&W){
        cin >> H >> W;
        if(H&&W){
            for(int i=1; i<=H; ++i){
                for(int j=1; j<=W; ++j) cout << (i%2?(j%2?"#":"."):(j%2?".":"#"));
                cout << endl;
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3104
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main()
{
	char in[15];
	scanf("%s", in);
	for (int i = 0; i < 4; ++i) putchar(in[i]);
	putchar(' ');
	for (int i = 0; i < 8; ++i) putchar(in[i + 4]); puts("");
	return 0;
}


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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#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, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  int n; cin >> n;
  cout << n*n*n << "\n";
  return 0;
}




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

int main()
{
	int m, nmin, nmax, res;
	while (cin >> m >> nmin >> nmax, m || nmin || nmax) {
		int gmax = 0;
		for (int i = 0, tmp, btm = 100000; i < m; i++) {
			cin >> tmp;
			if (i >= nmin && i <= nmax && btm != 100000 && btm != tmp && btm - tmp >= gmax) {
				res = i;
				gmax = btm - tmp;
			}
			btm = tmp;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
const ll mod = 1000000007;

int main()
{
    ll N;
    std::cin >> N;

    std::vector<ll> A(N);
    for(ll i=0; i < N; i++) std::cin >> A[i];

    ll ans = 0;
    ll x = A[0];
    for(ll i=1; i < N; i++) {
        ans = (ans + x*A[i]) % mod;
        x = (x + A[i]) % mod;
    }
    std::cout << ans << std::endl;
}

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

long long dp[51][2560] = {0};
 
int main(){
  int N, A;
  cin >> N >> A;
  
  dp[0][0] = 1;
  for (int i = 1; i <= N; i ++){
    int x;
    cin >> x;
    for (int j = i - 1; j >= 0; j --){
      for (int k = 0; k <= 2501; k ++){
        dp[j + 1][k + x] += dp[j][k];
      }
    }
  }
  
  
  long long totalWays = 0;
  for (int i = 1; i <= N; i ++){
    totalWays += dp[i][i * A];
  }
  
  cout << totalWays << '\n';
  
}


Measured memory_bytes: 4204
def check_aiko(arr):
    if all(arr[0] == a for a in arr):
        return True

    rps = [1, 2, 3]
    for t in rps:
        if t not in arr:
            return False

    return True


def check_v(arr):
    rps = {}
    o = []
    for t in arr:
        if t not in rps:
            rps[t] = 0
    if 1 in rps.keys() and 2 in rps.keys():
        rps[1], rps[2] = 1, 2
    elif 2 in rps.keys() and 3 in rps.keys():
        rps[2], rps[3] = 1, 2
    elif 1 in rps.keys() and 3 in rps.keys():
        rps[3], rps[1] = 1, 2

    for n in arr:
        o.append(rps.get(n))
    return o


def algorithm():
    g = []
    out = []

    while True:
        inp = int(input())
        if inp == 0:
            break

        g.append(inp)
        if len(g) == 5:
            if check_aiko(g):
                out = [3] * 5
            else:
                out = check_v(g)

            for o in out:
                print(o)
            g.clear()
            out.clear()


def main():
    algorithm()


if __name__ == '__main__':
    main()

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

int main(){
 int N;cin>>N;
 int A[110000];
 int J[110000];
 for(int i=0;i<N;i++){
   cin>>A[i];
   J[A[i]]=i+1;
 }
 for(int i=1;i<=N;i++){
   cout<<J[i]<<endl;
 }
  
}

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

using namespace std;

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

int issubseq(const vector<P>& a, const vector<P>& b){
	int pos = -1, i, j;
	if(a.size() < b.size()) return pos;
	for(i = 0;i < a.size() - b.size() + 1;++i){
		for(j = 0;j < b.size();++j){
			if(a[i + j].first != b[j].first) break;
			if(j == 0 || j == b.size() - 1){
				if(a[i + j].second < b[j].second) break;
			}
			else{
				if(a[i + j].second != b[j].second) break;
			}
		}
		if(j == b.size()) {
			pos = i;
			break;
		}
		else {
			i += j;
		}
	}
	return pos;
}

int main(){
	int idx;
	string s;
	vector<string> tokens[3];
	vector<P> vp[3], ans, t;
	for(int i = 0;i < 3;++i){
		for(;cin >> s, s != "$";){
			tokens[i].emplace_back(s);
		}
		for(int j = 0;j < tokens[i].size();j += 2){
			vp[i].emplace_back(make_pair(tokens[i][j], stoi(tokens[i][j + 1])));
		}
	}
	idx = issubseq(vp[0], vp[1]);
	if(idx == -1){
		for(const auto& v : vp[0]){
			cout << v.first << " " << v.second << " ";
		}
		cout << '$' << endl;
	}
	else {
		for(int i = 0;i < vp[0].size();++i){
			if(i == idx) {
				int l = vp[1].size() - 1;
				P p = vp[0][i];
				if(l) {
					if(p.second - vp[1][0].second > 0) {
						t.emplace_back(p.first, p.second - vp[1][0].second);
					}
				}
				for(int j = 0;j < vp[2].size();++j){
					t.emplace_back(vp[2][j]);
				}
				p = vp[0][i + l];
				if(p.second - vp[1][l].second > 0) {
					t.emplace_back(p.first, p.second - vp[1][l].second);
				}
				i += l;
			}
			else {
				t.emplace_back(vp[0][i]);
			}
		}
		reverse(t.begin(), t.end());
		for(int i = 0;i < t.size();++i) {
			if(!ans.empty()) {
				if(t[i].first == ans[0].first) {
					ans[0].second += t[i].second;
					continue;
				}
			}
			ans.insert(ans.begin(), t[i]);
		}
		for(const auto &v : ans) {
			cout << v.first << " " << v.second << " ";
		}
		cout << '$' << endl;
	}
	return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
//#define ll __int64
#define ll long long

int main(){
    ll a,b;
    cin>>a>>b;
    if(a==b){
        cout<<0<<endl;
        return 0;
    }
    if(a<b)swap(a,b);
    ll k=(a-b)/2+b;
    if(abs(a-k)==abs(b-k)){
        cout<<k<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = list(map(int,input().split()))
arr.sort(reverse = True)
ans = arr[0]
odd = False
mult = n-2
if mult%2!=0:
    mult-=1
    odd = True
mult//=2
ans += sum(arr[1:1+mult])*2
if odd:
    ans+=arr[1+mult]
print(ans)
"""
Sample:
7
1 2 3 4 5 6 7


2537146
7+6+6+5+5+4
"""

Measured memory_bytes: 31408
#include <stdio.h>
#define N 25
#define NE -1

struct node{
  int p;
  int left;
  int right;
};

struct node tree[N];

void mae(int);
void In(int);
void Post(int);

int main(){

  int i, n, num, left, right, root, p[N];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    p[i]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d", &num, &left, &right);
    tree[num].p=num;
    tree[tree[num].p].left=left;
    tree[tree[num].p].right=right;
    if(left!=NE) p[tree[num].left]=1;
    if(right!=NE) p[tree[num].right]=1;
  }

  for(i=0;i<n;i++){
    if(p[i]==0) root=i;
  }


  printf("Preorder\n");
  mae(root);
  printf("\n");

  printf("Inorder\n");
  In(root);
  printf("\n");

  printf("Postorder\n");
  Post(root);
  printf("\n");

  return 0;
}

void mae(int id){
  if(id==NE) return;

  else{
    printf(" %d",id);
    mae(tree[id].left);
    mae(tree[id].right);
  }
}


void In(int id){
  if(id==NE) return;
  else{
    In(tree[id].left);
    printf(" %d", id);
    In(tree[id].right);
  }
}

void Post(int id){
  if(id==NE) return;
  else{
    Post(tree[id].left);
    Post(tree[id].right);
    printf(" %d", id);
  }
}



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,x; cin>>n>>x;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  vsort(a);
  
  ll ans=0;
  rep(i,n){
    if(a[i]>x) break;
    if(i<n-1){
      x-=a[i];
      ans++;
    }else{
      if(x==a[i]) ans++;
    }
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
	ll n, k; cin >> n >> k;
	ll res = 0;
	for (ll i = k; i <= n + 1; i++) {
		ll l = (i - 1) * i / 2;
		ll r = n * i - l;
		res += r - l + 1;
		res %= MOD;
	}
	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 3636
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/28 14:40:18 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	ll	n;
	cin >> n;
	vector<ll>	A(n);
	vector<ll>	B(n);
	vector<ll>	C(n);
	vector<ll>	D;
	rep(i, n)
		cin >> A.at(i);
	rep(i, n)
		cin >> B.at(i);
	// if (accumulate(A.begin(), A.end(), 0LL) < accumulate(B.begin(), B.end(), 0LL))
	// ll	sum;
	// sum = 0;
	rep(i, n)
		C.at(i) = B.at(i) - A.at(i);
	sort(C.begin(), C.end());
	if (C.at(n - 1) <= 0)
	{
		cout << 0 << endl;
		return ;
	}
	if (accumulate(C.begin(), C.end(), 0LL) > 0)
	{
		cout << -1 << endl;
		return ;
	}
	ll	sum;
	sum = 0;
	// rrep(i, n - 1)
	// {
	// 	if (C.at(i) < 0)
	// 	{
	// 		D.push_back(abs(C.at(i)) + sum);
	// 		sum += abs(C.at(i));
	// 	}
	// }
	rep(i, n)
	{
		if (C.at(i) >= 0)
			break ;
		D.push_back(abs(C.at(i)) + sum);
		sum = D.at(i);
	}
	sum = 0;
	ll	lack;
	lack = 0;
	rrep(i, n - 1)
	{
		if (C.at(i) <= 0)
			break ;
		sum += C.at(i);
		lack++;
	}
	int	i;
	i = lower_bound(D.begin(), D.end(), sum) - D.begin() + 1;
	cout << i + lack << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


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

using namespace std;

#define MAX 21
typedef vector<int> Vec;
typedef vector<Vec> Mat;

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

int memo[MAX][MAX][MAX][MAX];

int grundy(int x1, int y1, int x2, int y2, Mat &f)
{
    if (x1 > x2 || y1 > y2) {
        return 0;
    }

    if (memo[y1][x1][y2][x2] != -1) {
        return memo[y1][x1][y2][x2];
    }
        
    set<int> st;
    for (int i = y1; i <= y2; i++) {
        for (int j = x1; j <= x2; j++) {
            if (f[i][j] == 0) {
                st.insert(grundy(x1, y1, j-1, i-1, f) ^
                          grundy(j+1, y1, x2, i-1, f) ^
                          grundy(x1, i+1, j-1, y2, f) ^
                          grundy(j+1, i+1, x2, y2, f));
            }
        }
    }   
    
    int res = 0;
    while (st.count(res)) res++;
    return (memo[y1][x1][y2][x2] = res);
}

int main()
{    
    cin >> H >> W;
    Mat f(H);
    for (int i = 0; i < H; i++) {
        f[i].resize(W);
        for (int j = 0; j < W; j++) {
            char ch;
            cin >> ch;
            f[i][j] = (ch == 'X');
        }
    }
    memset(memo, -1, sizeof(memo));
    cout << (grundy(0, 0, W-1, H-1, f) != 0 ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 1972
#include<stdio.h>
#include<math.h>

int main() {
	int n, m, a, l;
	scanf("%d %d", &n, &m);
	l = n;
	for (int i = 0; i < m; i++) {
		scanf("%d", &a);
		l = l - a;
	}
	if (l >= 0) {
		printf("%d", l);
	}
	else {
		printf("-1");
	}
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];
pll B[100005];

int main()
{
    ll N, M;
    cin >> N >> M;
    REP(i, N)
    {
        cin >> A[i];
    }
    REP(i, M)
    {
        cin >> B[i].first >> B[i].second;
    }
    sort(A, A + N);
    sort(B, B + M, [](pll a, pll b) { return a.second > b.second; });

    int index = 0;
    REP(i, M)
    {
        bool f = false;
        REP(j, B[i].first)
        {
            if (A[index] < B[i].second)
            {
                A[index++] = B[i].second;
            }
            else
            {
                f = true;
            }
            if (index == N)
                f = true;
            if (f)
                break;
        }
        if (f)
            break;
    }

    ll sum = 0;
    REP(i, N)
    {
        sum += A[i];
    }
    cout << sum << endl;
    return 0;
}

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

int main(){    
    int N;  cin >> N;
    vector<string> w(N);
    for(int i=0; i<N; i++) cin >> w[i];

    bool ans = true;
    for(int i=1; i<N; i++){
        if(w[i][0] != w[i-1][w[i-1].length()-1]) ans = false;
        for(int j=0;j<i; j++){
            if(w[i]==w[j]) ans = false;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 10010;

int main() {
    string s;
    cin >> s;
    
    reverse(all(s));
    s += '0';
    ll n = s.size();
    
    vvl dp(n+10, vl(2, INF));  // dp[i][j] : 下からi桁目まで決めて繰り下がりがj回のときの合計枚数の最小値
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, 2) {
            ll ni = s[i] - '0';
            ni += j;
            rep(ai, 10) {
                ll nj = 0;
                ll bi = ai - ni;
                if(bi < 0) {
                    nj = 1;
                    bi += 10;
                }
                chmin(dp[i+1][nj], dp[i][j] + ai + bi);
            }
        }
    }

    out(dp[n][0]);
    re0;
}

Measured memory_bytes: 55940
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	string str;
	cin >> n >> str;
	int re = count(str.begin(), str.end(), 'E');
	int rw = n - re;
	int le = 0;
	int lw = 0;
	int ans = n;
	for (auto& c : str)
	{
		if (c == 'E') re--;
		else rw--;
		ans = min(ans, lw + re);
		if (c == 'E') le++;
		else lw++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_C = 200010;
 
int main() {
    ll n;
    cin >> n;

    vl c(n);
    rep(i, n) {
        cin >> c[i];
    }

    vl v(n);
    vl w(MAX_C, -1);
    rep(i, n) {
        v[i] = w[c[i]];
        w[c[i]] = i;
    }

    vl dp(n);  // dp[i] : 石iまでの列の個数
    dp[0] = 1;
    exrep(i, 1, n-1) {
        dp[i] += dp[i-1];
        if(v[i] >= 0 && v[i] != i-1) {
            dp[i] += dp[v[i]];
        }
        dp[i] %= mod;
    }

    out(dp[n-1]);
    re0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

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

    int a[101] = {0};
    rep(i,n){
        int t;
        cin >> t;
        a[t] = 1;
    }

    int diff = 0;
    int t = 0;
    while(1){
        t = x - diff;
        if((t>0 && a[t]==0) || t<=0){
            cout << t << endl;
            break;
        }
        t = x + diff;
        if((t <= 100 &&a[t]==0) || t>=101){
            cout << t << endl;
            break;
        }
        diff++;
    }

    return 0;
}


Measured memory_bytes: 3632
n = int(input())
h = list(map(int, input().split()))

now = h[0]
cnt = 0
max_cnt = 0

for i in range(n):
    # 次が同じかそれ以下なら
    # nowを更新しカウントアップ
    if i == 0:
        cnt = 0
    elif now >= h[i]:
        now = h[i]
        cnt = cnt + 1
    # それ以上なら最大カウントを超えてれば更新
    else:
        if max_cnt < cnt:
            max_cnt = cnt
        cnt = 0
        now = h[i]
    if i == n-1:
        if max_cnt < cnt:
            max_cnt = cnt

print(max_cnt)

Measured memory_bytes: 14224
#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 << 12;
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 (ll 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++)

struct edge {
    ll to, cost;
};

ll n, dmin[100005], q, k;
vector<edge> G[100005];

ll dijkstra(ll s) {
    fill(dmin, dmin + n, INF);
    priority_queue<P, vector<P>, greater<P> > que;
    dmin[s] = 0;
    que.push({0, s});

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll u = p.second;
        if (p.first > dmin[u]) continue;
        for (int i = 0; i < G[u].size(); i++) {
            edge e = G[u][i];
            if (dmin[e.to] > dmin[u] + e.cost) {
                dmin[e.to] = dmin[u] + e.cost;
                que.push({dmin[e.to], e.to});
            }
        }
    }
}

int main() {
    cin >> n;
    REP(i, n-1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    cin >> q >> k;
    k--;
    dijkstra(k);
    REP(i,q){
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        cout << dmin[x] + dmin[y] << endl; 
    }
    return 0;
}


Measured memory_bytes: 11120
#include <iostream>
using namespace std;
#define REP(i,n) for(int(i)=0;i<n;i++)



int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (b < c) {
        cout << 0 << endl;
    } else if (a < c && b < d) {
        cout << b - c << endl;
    } else if (a < c) {
        cout << d - c << endl;
    } else if (d <= a) {
        cout << 0 << endl;
    } else if (b < d) {
        cout << b - a << endl;
    } else {
        cout << d - a << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

long long ruijou(int n, int k){
    if(k==0) return 1;
    int x=k/2;
    long long t=ruijou(n,x);
    
    if(k%2==1) return n*t*t;
    else return t*t;
}

int main(){
    set<string> data;
    string S;
    cin>>S;

    int K;
    cin>>K;

    for(int i=0;i<S.size();i++){
        int p=S.size()-i;
        for(int j=1;j<=min(p,K);j++){
            data.insert(S.substr(i,j));
        }
    }

    auto itr=data.begin();
    if(K>=2){
        for(int i=0;i<K-1;i++) itr++;
    }

    cout<<*itr<<endl;

    
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
	
int main(){
  int n;
  scanf("%d",&n);
  int dp[n]{0};
  int a[n];
  for(int i = 0; i< n; ++i){
    scanf("%d",&a[i]);
  }

  dp[1] = abs(a[1]-a[0]);

  for (int i =2; i <n;++i){
    dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);}
  printf("%d",dp[n-1]);
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

int main()
{
	string w;
	cin >> w;

	vector<int> a(26);
	for (int i = 0; i < w.length(); i++)
	{
		int x = w.at(i) - 'a';
		a.at(x)++;
	}

	bool ok = true;
	for (int i = 0; i < 26; i++)
	{
		if (a.at(i) % 2 != 0)
		{
			ok = false;
			break;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
int N;
/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    lng now = 1;
    FOR(i, 1, N) {
        now *= i;
        now %= MOD;
    }
    cout << now << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vi VX(N+1);
	vi VY(M+1);
	REP(i, N) cin >> VX[i];
	REP(i, M)cin >> VY[i];
	VX[N] = X;
	VY[M] = Y;
	so(VX); so(VY);
	int Z = VX[N] + 1;
	if (Z > VY[0]) {
		cout << "War" << endl;
		PAU;
		return 0;
	}
	cout << "No War" << endl;
	PAU;
	return 0;
}


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

using namespace std;

typedef long long ll;
const int nax = 1e9+7;


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

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

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

    map<int, int> m;
    for(int i = 0; i < 3; i++) {
        int a;
        cin >> a;
        m[a]++;
    } 
    if(m[5] == 2 && m[7] == 1) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }

	return 0;
}


Measured memory_bytes: 3620
import copy
n,m = map(int,input().split())

#取得
scores = list()
for i in range(n):
    score = list(map(int,input().split()))
    scores.append(score)

smax=None
for x in range(2):
    scores_=copy.deepcopy(scores)
    
    for i in range(n):
        scores_[i][0] = pow(-1,x)*scores[i][0]
    for y in range(2):
        for i in range(n):
            scores_[i][1] = pow(-1,y)*scores[i][1]
        for z in range(2):
            for i in range(n):
                scores_[i][2] = pow(-1,z)*scores[i][2]
        
            sumlist=list()
            for i in range(n):
                sumlist.append(sum(scores_[i]))
            sumlist.sort()
            
            tmp=0
            for eat in range(m):
                tmp+=sumlist[-1]
                sumlist.pop()
            if smax==None or tmp>smax:
                smax=tmp
print(smax)

Measured memory_bytes: 4212
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println(problem106b(n))
}

fun problem106b(n: Int): Int {
    fun countDivisor(n: Long): Long {
        var count = 0L
        for (i in 1..n) {
            if (n % i == 0L) count++
        }
        return count
    }
    var count = 0
    for (i in 1..n) {
        if (i % 2 != 0 && countDivisor(i.toLong()) == 8L) count++
    }
    return count
}

Measured memory_bytes: 29600
open System.Linq
open System.Collections.Generic

let [| N; M |] = stdin.ReadLine().Split() |> Array.map int

let S = new List<int []>()

for i in [ 1..M ] do
    stdin.ReadLine().Split()
    |> Array.map int
    |> S.Add

let result = new List<string>()

for i in [ 0..999 ] do
    let s = i.ToString()
    if s.Length = N then
        if S.All(fun x -> (s.[x.[0] - 1] |> int) - ('0' |> int) = x.[1]) then s |> result.Add

if result.Count > 0 then result.[0]
else "-1"
|> stdout.WriteLine

Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
int a,n;
string b[105];
int main()
{
    cin>>a>>n;
	for(int s=0;s<a;s++)
	{
		cin>>b[s];
	}
	sort(b,b+a);
	for(int s=0;s<a;s++)
	cout<<b[s];
	cout<<endl;
}

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



int main(){
  while(1){
    int n,w,h,s,t;
    int a[1000][1000]={};
    
    cin >> n;
    if(n==0){break;}
    cin >> w >> h;
    
    for(int i=0;i<n;i++){
      int b,c;
      cin>>b>>c;
      a[b][c]=1;
    }
    
    cin>>s>>t;
    int count=0;
    for(int x=1;x<=s;x++){
      for(int y=1;y<=t;y++){
	if(a[x][y]==1){
	  count++;
	}
      }
    }
    
    int mx=count,cd=count;
    for(int y=1 ; y<=h-t+10 ; y++){
      for(int x=1 ; x<=w-s+10 ; x++){
	for(int i=y ; i < y+t ; i++){
	  if(a[x][i]==1) cd--;
	  if(a[x+s][i]==1) cd++;
	}
	mx=max(cd,mx);
      }
      
      for(int i=1 ; i<=s ; i++){
	if(a[i][y]==1) count--;
	if(a[i][y+t]==1) count++;
      }
      mx=max(count,mx);
      cd=count;
    }
    
    cout << mx << endl;
    
  }
  
  return 0;
}



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

int main()
{
   int n;
   cin>>n;
   int a=0,w=0,t=0,r=0;
   string s;
   while(n--)
   {
       cin>>s;
       if(s.at(0)=='A')
       a++;
       else if(s.at(0)=='W')
       w++;
       else if(s.at(0)=='T')
       t++;
       else if(s.at(0)=='R')
       r++;
   }
   cout<<"AC x "<<a<<endl;
   cout<<"WA x "<<w<<endl;
   cout<<"TLE x "<<t<<endl;
   cout<<"RE x "<<r<<endl;
}

Measured memory_bytes: 3620
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Segment Tree
template <typename Operator>
struct SegmentTree {
    Operator OP;
    using NodeType = decltype(OP.NodeE);
    int length;
    vector<NodeType> node;
    SegmentTree (int n) {
        length = 1;
        while (length < n) length <<= 1;
        node.assign(length << 1, OP.NodeE);
    }
    SegmentTree (vector<NodeType> &vec) {
        length = 1;
        while (length < vec.size()) length <<= 1;
        node.assign(2 * length, OP.NodeE);
        rep(i, vec.size()) node[i + length] = vec[i];
        for (int i = length - 1; i > 0; --i) node[i] = OP.func(node[(i << 1) + 0], node[(i << 1) + 1]);
    }
    void update(int idx, NodeType val) {
        idx += length;
        node[idx] = OP.change(node[idx], val);
        while (idx >>= 1) node[idx] = OP.func(node[(idx << 1) + 0], node[(idx << 1) + 1]);
    }
    NodeType get(int l, int r) {
        l += length;
        r += length;
        NodeType vl = OP.NodeE, vr = OP.NodeE;
        while (r > l) {
            if (l & 1) vl = OP.func(vl, node[l++]);
            if (r & 1) vr = OP.func(node[--r], vr);
            l >>= 1;
            r >>= 1;
        }
        return OP.func(vl, vr);
    }
};
struct RMQ {
    using NodeType = ll;
    NodeType NodeE = 0LL;
    NodeType change(NodeType x, NodeType y) {return y;}
    NodeType func(NodeType x, NodeType y) {return max(x, y);}
};

// Main
int main() {
    int n;
    cin >> n;
    vector<int> h(n), a(n);
    rep(i, n) {cin >> h[i]; --h[i];}
    rep(i, n) cin >> a[i];
    
    SegmentTree<RMQ> st(n);
    rep(i, n) {
        ll x = st.get(0, h[i]);
        st.update(h[i], x + a[i]);
    }
    
    cout << st.get(0, n) << "\n";
    return 0;
}


Measured memory_bytes: 8968