akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

int main(){
    int n;
    cin >> n;
    vector <long> a(n);
    rep(i,n) cin >> a[i];

    vector<long> ans(0);

    if(n%2==0){//n even
        for(int i=n-1; i>=1; i-=2){
            ans.push_back(a[i]);
        }
        for(int i=0; i<=n-2; i+=2){
            ans.push_back(a[i]);
        }

        
    }

    else{//n odd
        for(int i=n-1; i>=0; i-=2){
            ans.push_back(a[i]);
        }
        for(int i=1; i<=n-2; i+=2){
            ans.push_back(a[i]);
        }
    }


    for(int i=0; i<n; i++){
        if(i==n-1) cout << ans[i] << endl;
        else cout << ans[i] << " ";
    }

}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  const int N = 100000 + 10;
  int n;
  lli e, t;
  while (cin >> n >> e >> t) {
    lli x[N];
    for (int i = 0; i < n; ++i) {
      cin >> x[i];
    }
    x[n] = e;

    lli dp[N];
    fill(dp, dp + N, 1LL << 60);
    dp[0] = 0;

    lli mn = 1LL << 60;
    for (int i = 0, j = -1; i < n; ++i) {
      while (t < 2 * (x[i] - x[j + 1])) {
        mn = min(mn, dp[j] - 2 * x[j + 1]);
        ++j;
      }
      dp[i] = min(dp[j] + t, 2 * x[i] + mn);
    }
    cout << dp[n - 1] + e << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
using System;

namespace AGC006A{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var S = sr.Next<string>();
            var T = sr.Next<string>();

            for(var i = N; i >= 0; i--){
                if(S.Substring(N - i, i) == T.Substring(0, i)){
                    Console.WriteLine(N * 2 - i);
                    return;
                }
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 3032
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;
typedef long long ll;

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

    if(n % 2 != 0){
        cout << n / 2 << endl;
    }else{
        cout << n / 2 - 1 << endl;
    }
    // cout << fixed;
    // cout << setprecision(10);

    // if (x >= a * a * b / 2)
    // {

    //     cout << atan(2 * (pow(a, 2) * b - x) / pow(a, 3) )* 180 / M_PI << endl;
    // }
    // else
    // {
    //     cout << atan(a * b * b / (2 * x)) * 180 / M_PI << endl;
    // }

    // ll answer = 1;

    // ll last = n;

    // for (ll i = 1; i < n; i++)
    // {
    //     if (i > last || i * i > n)
    //     {
    //         break;
    //     }

    //     if (n % i == 0)
    //     {
    //         if (i < n - i)
    //         {
    //             answer = (i - 1) + (n / i - 1);
    //             last = n / i;
    //         }
    //         else
    //         {
    //             break;
    //         }
    //     }
    // }

    // cout << answer << endl;

    // bool flg = false;

    // for (int i = 1; i <= 9; i++)
    // {
    //     if (n % i == 0)
    //     {
    //         if ((n / i) >= 1 && (n / i) <= 9)
    //         {
    //             flg = true;
    //             break;
    //         }
    //     }
    // }

    // if (!flg)
    // {
    //     cout << "No" << endl;
    // }
    // else
    // {
    //     cout << "Yes" << endl;
    // }

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

    // vector<ll> a;
    // for (int i = 0; i < n; i++)
    // {
    //     int j;
    //     cin >> j;
    //     a.push_back(j);
    // }

    //sort(a,a+n); ソート
}


Measured memory_bytes: 256
def main():
    N = int(input())
    for h in range(1, 3501):
        for n in range(1, 3501):
            if (4*h*n-N*h-N*n) > 0 and (N*h*n)%(4*h*n-N*h-N*n) == 0:
                    w = (N*h*n)//(4*h*n-N*h-N*n)
                    print(h,n,w)
                    return

main()


Measured memory_bytes: 3064
from collections import deque

n = int(input())
a = list(map(int,input().split()))

b = deque()
if n%2 == 0:
  for i in range(n):
    if i%2 == 0:
      b.append(a[i])
    else:
      b.appendleft(a[i])
else:
  for i in range(n):
    if i%2 == 1:
      b.append(a[i])
    else:
      b.appendleft(a[i])
    
b = list(b)    

for i in range(n):
  print(b[i], end=" ")

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

int main() {
  int N, M, X, Y; cin >> N >> M >> X >> Y;
  int maxx = -10000;
  int miny = 10000;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    maxx = max(maxx, x);
  }
  for (int i = 0; i < M; i++) {
    int y;
    cin >> y;
    miny = min(miny, y);
  }
  if (X <= maxx && maxx + 1 <= miny && miny <= Y) {
    cout << "No War" << endl;
  }
  else cout << "War" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
int A[210000];
int main()
{
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
        scanf("%d", A + i);
    std::sort(A, A + N);
    for (int i = 0; i < N - 1; i++)
    {
        if (A[i] == A[i + 1])
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
}

Measured memory_bytes: 896
object Main extends App {
  import scala.io.StdIn._


  val n = readInt
  val frames = readLine.trim.split(' ').map(_.toInt)
  println(frames.indices.minBy{i ⇒ math.abs(frames(i) * n - frames.sum)})
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}

Measured memory_bytes: 27324
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{

  string A,B,C;
  cin>>A>>B>>C;
  if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0])
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
  
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    int n;
    cin >> n;

    int x = 0;
    vi a(n);

    for(int i = 0; i < n; i++) {
        cin >> a[i];
        x ^= a[i];
    }
    for(int i = 0; i < n; i++) {
        cout << (x ^ a[i]) << " ";
    }
    return 0;
}


Measured memory_bytes: 3984
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
bool wolf[100001];
int main() {
	int N;
	cin >> N;
	string s;
	cin >> s;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			wolf[0] = i;
			wolf[1] = j;
			for (int k = 1; k < N; k++) {
				wolf[k + 1] = wolf[k - 1] ^ (s[k] == 'x') ^ wolf[k];
			}
			if (wolf[0] != wolf[N]) continue;
			if ((wolf[1] ^ (s[0] == 'x') ^ wolf[0]) != wolf[N - 1]) continue;
			for (int k = 0; k < N; k++) {
				if (wolf[k]) cout << "W";
				else cout << "S";
			}
			cout << endl;
			return 0;
		 }
	}
	cout << "-1" << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int n, i, ans;
	scanf("%d", &n);
	
	ans = 100000;
	
	for (i = 0; i < n; i++){
		ans += (ans / 20);
		if (ans % 1000 != 0){
			ans = ans / 1000 * 1000 + 1000;
		}
	}
	
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <ctime>


using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;


ll binpow(ll a, ll n) {
    if (!n) return 1;
    if (n & 1) return (a * binpow(a, n - 1)) % mod;
    return binpow((a * a) % mod, n / 2);
}



int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
//    std::random_device rd;
//    std::mt19937 g(rd());
    auto start = clock();

    int n; cin >> n;
    vector<ll> a;
    for (int i = 0; i < n; ++i)  {
        ll x; cin >> x;
        a.pb(x);
    }
    ll ans = 0;
    ll fact = 1;
    for (ll i = 1; i < n; ++i) {
        fact *= i;
        fact %= mod;
    }
    ll cur = fact;
    for (int i = 1; i < n; ++i) {
        ans += cur * (a[i] - a[i - 1]);
        ans %= mod;
        cur += fact * binpow(i + 1, mod - 2);
        cur %= mod;
    }
    cout << ans << endl;


    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}

Measured memory_bytes: 1400
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;

int p[MAXN], p1[MAXN];

int myabs(int x) {
	if (x < 0) return -x;
	return x;
}

int main() {
	int n;
	cin >> n;
	int N = n;
	REP(i, n) scanf("%d",&p[i]);
	REP(i, n) p1[i] = myabs(i - (n - i - 1));
	if (n % 2) n--;
	n /= 2;
	ll pot = 1;
	REP(i, n) {
		pot *= 2;
		pot %= ((int)1e9 + 7);
	}

	sort(p, p + N);

	sort(p1, p1 + N);

	bool ok = 1;
	REP(i, N) ok &= (p[i] == p1[i]);

	if (!ok) pot = 0;

	cout << pot << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    char buf[100+1];
    int len;
    
    while (gets(buf)){
        for (int i=0; buf[i]!='\0'; i++){
            if (buf[i] != '@'){
                printf("%c", buf[i]);
            } else {
                len = buf[++i] - '0';
                i++;
                for (int j=0; j<len; j++){
                    printf("%c", buf[i]);
                }
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 908
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,count = 0;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i) >= k)count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}




int main() {
   int n;
  cin >> n;
  n%=1000;
  n=1000-n;
  if(n==1000) n=0;
  pt(n);

    return 0;
}


Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    char a; cin >> a;
    if (a >= 'a') cout << 'a' << endl;
    else cout << 'A' << endl;
}


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

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

int main() {
  int n;
  long long p;
  long long c = 0;
  string s;
  string ans;
  ans = "Yes";
  cin >> s;

  if ( s == "AAA" || s == "BBB") ans = "No";

  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(raw_input())
s=range(1,14)
h=range(1,14)
c=range(1,14)
d=range(1,14)

for i in range(n):
    hd,r=raw_input().split()
    if hd=='S':
        s[int(r)-1]=0
    elif hd=='H':
        h[int(r)-1]=0
    elif hd=='C':
        c[int(r)-1]=0
    elif hd=='D':
        d[int(r)-1]=0

a='S '
for i in range(13):
    if s[i]!=0:
        print a +str(s[i])
a='H '
for i in range(13):
    if h[i]!=0:
        print a +str(h[i])
a='C '
for i in range(13):
    if c[i]!=0:
        print a +str(c[i])
a='D '
for i in range(13):
    if d[i]!=0:
        print a +str(d[i])

Measured memory_bytes: 4284
#include<stdio.h>

struct test{
    signed short mid;
    signed short fin;
    signed short re;
    unsigned char eval;
};
unsigned char evaluate(signed short mid, signed short fin, signed short re);
int main(){
    struct test test[50];
    unsigned short i;
    short unsigned count = 0;
    for(i = 0;i < 50;i++){
        scanf("%d %d %d", &test[i].mid, &test[i].fin, &test[i].re);
        if(test[i].mid == -1 && test[i].fin == -1 && test[i].re == -1){
            break;
        }
        test[i].eval = evaluate(test[i].mid, test[i].fin, test[i].re);
        count++;
    }
    for(i = 0;i < count;i++){
        printf("%c\n", test[i].eval);
    }
    return 0;
}

unsigned char evaluate(signed short mid, signed short fin, signed short re){
    if(mid == -1 || fin == -1){
        return 'F';
    }
    if(mid + fin >= 80){
        return 'A';
    }
    else if(mid + fin >= 65){
        return 'B';
    }
    else if(mid + fin >= 50){
        return 'C';
    }
    else if(mid + fin >= 30){
        if(re >= 50){
            return 'C';
        }
        else{
            return 'D';
        }
    }
    else{
        return 'F';
    }
}


Measured memory_bytes: 2100
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n == 1) {
        System.out.println("Hello World");
        return;
      }
      System.out.println(sc.nextInt() + sc.nextInt());
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll H, W, A, B;
    cin >> H >> W >> A >> B;

    Rep (i, H) {
        Rep (j, W) {
            if (i < B && j < A || i >= B && j >= A) {
                cout << 0;
            } else {
                cout << 1;
            }
        }
        cout << "\n";
    }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
	string s;
	cin>>s;
	int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
	if(a+b+c+d==7){printf("%d+%d+%d+%d=7",a,b,c,d);}
	else if(a+b+c-d==7){printf("%d+%d+%d-%d=7",a,b,c,d);}
	else if(a+b-c+d==7){printf("%d+%d-%d+%d=7",a,b,c,d);}
	else if(a+b-c-d==7){printf("%d+%d-%d-%d=7",a,b,c,d);}
	else if(a-b+c+d==7){printf("%d-%d+%d+%d=7",a,b,c,d);}
	else if(a-b+c-d==7){printf("%d-%d+%d-%d=7",a,b,c,d);}
	else if(a-b-c+d==7){printf("%d-%d-%d+%d=7",a,b,c,d);}
	else if(a-b-c-d==7){printf("%d-%d-%d-%d=7",a,b,c,d);}

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[1010];
bool ap[303];
int l;
int main()
{
	scanf("%s",s);
	l=strlen(s);
	memset(ap,0,sizeof(ap));
	for(int i=0;i<l;i++)
		ap[s[i]]=true;
	if(ap['E']==ap['W']&&ap['N']==ap['S'])
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
n, ma, mb = map(int, input().split())
abc = []
for _ in range(n):
    a, b, c = map(int, input().split())
    abc.append((a, b, c))
dp = {(0, 0): 0}
for a, b, c in abc:
    newdp = dp.copy()
    for (ka, kb), p in dp.items():
        k = (a+ka, b+kb)
        if k in newdp:
            newdp[k] = min(newdp[k], p+c)
        else:
            newdp[k] = p+c
    dp = newdp
INF = 10**10
ans = INF
for (a, b), c in dp.items():
    if ma*b!=mb*a or a==b==0:
        continue
    ans = min(ans, c)
if ans==INF:
    print(-1)
else:
    print(ans)

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pi 3.1415926535
#define mod1 1000000007
#define mod2 1000000009
#define no_of_digits(n) floor(log10(n)) + 1
#define lcm(a, b) (a/__gcd(a,b)*b

using namespace std;


int main()
{
  
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a;
  set<int>s;
  for(int i = 0; i < 3; i++){
    cin >> a;
    s.insert(a);
  }
  cout << ((s.size() == 2)?"Yes":"No");
  return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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



int main(void) {
	stack<int>sta;
	string s;
	int a, b;


	while (cin >> s) {
		switch (s[0]) {
		case '+':
			a = sta.top();
			sta.pop();
			b = sta.top();
			sta.pop();
			sta.push(a + b);
			break;
		case '-':
			a = sta.top();
			sta.pop();
			b = sta.top();
			sta.pop();
			sta.push(b - a);
			break;
		case '*':
			a = sta.top();
			sta.pop();
			b = sta.top();
			sta.pop();
			sta.push(a * b);
			break;
		default:
			sta.push(atoi(s.c_str()));
			break;
		}
	}

	cout << sta.top() << endl;
	return 0;
}




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

using namespace std;

#define REP(i,b) for(int i=0;i<b;i++)

struct Data{
	int l,r,a,m;
};

Data Comb(Data a,Data b){
	return Data{
		max(a.l,a.a+b.l),
		max(a.r+b.a,b.r),
		a.a+b.a,
		max({a.m,b.m,a.r+b.l})
	};
}

const int unSet=114514;

struct Node{
	typedef Node* NP;
	NP l,r,p;
	Data d;
	bool rev;
	int v,g,s;
	Node():l(NULL),r(NULL),p(NULL),rev(false){}
	void Propagate(){
		if(rev){
			swap(l,r);
			swap(d.l,d.r);
			if(l) l->rev^=true;
			if(r) r->rev^=true;
			rev=false;
		}
		if(g!=unSet){
			v=g;
			int c=(g<0?1:s)*g;
			d={c,c,g*s,c};
			if(l) l->g=g;
			if(r) r->g=g;
			g=unSet;
		}
	}
	void Update(){
		d={v,v,v,v};
		s=1;
		if(l){
			l->Propagate();
			d=Comb(l->d,d);
			s+=l->s;
		}
		if(r){
			r->Propagate();
			d=Comb(d,r->d);
			s+=r->s;
		}
	}
	int Pos(){
		if(p&&p->l==this) return -1;
		if(p&&p->r==this) return 1;
		return 0;
	}
	void Prepare(){
		if(Pos())
			p->Prepare();
		Propagate();
	}
	void Rotate(){
		NP q=p,c;
		if(Pos()==1){
			c=l;
			l=p;
			p->r=c;
		}else{
			c=r;
			r=p;
			p->l=c;
		}
		if(c) c->p=p;
		p=p->p;
		q->p=this;
		if(p&&p->l==q) p->l=this;
		if(p&&p->r==q) p->r=this;
		q->Update();
	}
	void Splay(){
		Prepare();
		while(Pos()){
			int a=Pos(),b=p->Pos();
			if(a==b) p->Rotate();
			Rotate();
		}
		Update();
	}
	void Expose(){
		for(NP x=this;x;x=x->p) x->Splay();
		for(NP x=this;x->p;x=x->p){
			x->p->r=x;
			x->p->Update();
		}
		Splay();
	}
	void Evert(){
		Expose();
		if(l){
			l->rev^=true;
			l=NULL;
			Update();
		}
	}
	void Link(NP x){
		Evert();
		p=x;
	}
	void Set(int q){
		Expose();
		r=NULL;
		g=q;
	}
	int Get(){
		Expose();
		r=NULL;
		Update();
		return d.m;
	}
} ns[200000];

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	REP(i,n)
		scanf("%d",&ns[i].g);
	REP(i,n-1){
		int s,e;
		scanf("%d%d",&s,&e);
		ns[s-1].Link(ns+e-1);
	}
	REP(i,q){
		int t,a,b,c;
		scanf("%d%d%d%d",&t,&a,&b,&c);
		if(t==1){
			ns[a-1].Evert();
			ns[b-1].Set(c);
		}else if(t==2){
			ns[a-1].Evert();
			printf("%d\n",ns[b-1].Get());
		}
	}
}

Measured memory_bytes: 14156
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define ll long long int
#define ii pair < ll, ll >
#define mp make_pair
#define F first
#define S second

using namespace std;

ll bin(ll t){
    ll lo = 0, hi = t, mid, res = t;
    while(lo <= hi){
        mid = (lo + hi)/2;
        if( t <= mid*(mid+1)/2 ){
            res = mid;
            hi = mid - 1;
        }else lo = mid + 1;
    }
    return res;
}

int main()
{
    ll x;
    cin >> x;
    cout << bin(x);
    return 0;
}

















Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
ll extgcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;y=0;
        return a;
    }
    ll d=extgcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
pair<ll, ll> ChineseRem(const vector<ll> &b, const vector<ll> &m) {
  ll r = 0, M = 1;
  for (int i = 0; i < (int)b.size(); ++i) {
    ll p, q;
    ll d = extgcd(M, m[i], p, q);
    if ((b[i] - r) % d != 0) return make_pair(0, -1);
    ll tmp = (b[i] - r) / d * p % (m[i]/d);
    r += M * tmp;
    M *= m[i]/d;
  }
  r=(r%M+M)%M;
  return make_pair(r, M);
}
vector<ll> divisor(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
		}
	}
	sort(ret.begin(),ret.end());
	return(ret);
}
int main(){
    ll n;
    cin>>n;
    n*=2;
    V<ll> d=divisor(n);
    ll ans=inf;
    for(ll v:d){
        V<ll> b={0,n/v-1},m={v,n/v};
         P res=crt(b,m);
          if(res.fi!=0){
            chmin(ans,res.fi);
          }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3768
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	char a[100];
	f(i, 100)a[i] = 0;
	int k, s;
	int n, m;
	bool v = true;
	int x, y, z;
	int ans = 0;

	scanf("%d %d", &n,&m);
	scanf("%s", a);

	f(i, n){
		if (a[i] < 48 || a[i]>57)v = false;
	}
	if (a[n] != '-')v = false;
		f(i, m){
		if (a[n+i+1] < 48 || a[n+i+1]>57)v = false;
	}

	if (v)printf("Yes\n");
	else printf("No\n");

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

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

void koch(double x1, double y1, double x2, double y2, int n)
{
	if(n <= 0) return;

	double sx = (x2 - x1)/3.0 + x1, sy = (y2 - y1)/3.0 + y1;
	double tx = (x2 - x1)/3.0 * 2 + x1, ty = (y2 - y1)/3.0 * 2 + y1;
	double ux = (tx-sx)*cos(M_PI/3.0) - (ty-sy)*sin(M_PI/3.0) + sx;
	double uy = (tx-sx)*sin(M_PI/3.0) + (ty-sy)*cos(M_PI/3.0) + sy;

	koch(x1, y1, sx, sy, n - 1);
	printf("%0.8f %8f\n", sx, sy);
	koch(sx, sy, ux, uy, n - 1);
	printf("%0.8f %8f\n", ux, uy);
	koch(ux, uy, tx, ty, n - 1);
	printf("%0.8f %8f\n", tx, ty);
	koch(tx, ty, x2, y2, n - 1);

}

int main()
{
	int n;
	cin >> n;
	double x1 = 0, y1 = 0, x2 = 100.0, y2 = 0;
	printf("%0.8f %8f\n", x1, y1);
	koch(x1, y1, x2, y2, n);
	printf("%0.8f %8f\n", x2, y2);
	return 0;
}

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

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(void){
  string n;
  int count = 0;
  cin >> n;
  for(int i = 0; i < 4; i++) {
    if(ctoi(n[i])==2){
      count++;
    }
  }
  cout << count;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
struct edge{ll to,cost;};
vector<vector<edge>> graph;
vector<vector<bool>> used;
vector<ll> A;
vector<ll> d1,d2;
int n,m;
void dijkstra(ll s){
    d1.resize(n);
    for(int i=0;i<n;i++)d1.at(i)=inf;//訪れていない頂点をinfで初期化
    d1.at(s)=0;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push(P(0,s));//始点を０で置く
    while(!q.empty()){
        P a=q.top();
        q.pop();
        if(d1.at(a.se)<a.fi)continue;
        for(int i=0;i<graph.at(a.se).size();i++){
            edge e=graph.at(a.se).at(i);
            if(d1.at(e.to)>d1.at(a.se)+e.cost){
                d1.at(e.to)=d1.at(a.se)+e.cost;//訪れていないorより低いコストの経路を発見した時、値を更新
                q.push(P(d1.at(e.to),e.to));//コストの低いところ優先のbfs
            }
        }
    }
    q.push(P(0,s));
    while(!q.empty()){
        P a=q.top();
        q.pop();
        if(d1.at(a.se)<a.fi)continue;
        for(int i=0;i<graph.at(a.se).size();i++){
            edge e=graph.at(a.se).at(i);
            if(d1.at(e.to)==d1.at(a.se)+e.cost){
                used[a.se][e.to]=false;
                used[e.to][a.se]=false;
                q.push(P(d1.at(e.to),e.to));
            }
        }
    }
    return;
}
int main(){
    cin>>n>>m;
  used.resize(n,vector<bool>(n,false));
  graph.resize(n);
  for(int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    graph[--a].push_back((edge){--b,c});
    graph[b].push_back((edge){a,c});
    used[a][b]=true;
    used[b][a]=true;
  }
  int cnt=0;
  for(int i=0;i<n;i++)dijkstra(i);
  for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)if(used[i][j])cnt++;
  }
  cout<<cnt/2<<endl;
}



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

using namespace std;

typedef long long LL;

int n, m, coin;
vector<int> adj[100005];

bool odd = false;
bool vis[100005];
int k[100005], a[100005], col[100005]; //y = kx + a

int dn, up; // circle
LL ans = 0LL;

void dfs(int x, int pre = 0) {
	vis[x] = 1;
	for (int i = 0; i < adj[x].size(); ++i) {
		int y = adj[x][i];
		if (y == pre)
			continue;
		if (!vis[y]) {
			col[y] = col[x] ^ 1;
			dfs(y, x);
		} else {
			dn = x, up = y;
			if (col[x] == col[y])
				odd = true;
		}
	}
}

int top;
int stk[100005];

void get(int x, int pre = 0) {
	for (int i = 0; i < adj[x].size(); ++i) {
		int y = adj[x][i];
		if (y != pre && !(x == up && y == dn || x == dn && y == up)) {
			get(y, x);
			k[x] += k[y];
			a[x] += a[y];
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	col[1] = 1;
	dfs(1);
	for (int i = 1; i <= n; ++i)
		a[i] = col[i] ? 1 : -1;
	for (int i = 1; i <= n; ++i)
		coin += a[i];
	if (m == n - 1) {
		if (coin)
			return 0 * puts("-1");
	} else {
		if (odd) {
			if (coin & 1)
				return 0 * puts("-1");
			a[up] -= coin / 2;
			a[dn] -= coin / 2;
			ans += abs(coin / 2);
		} else {
			if (coin)
				return 0 * puts("-1");
			k[up] = -1;
			k[dn] = 1;
		}
	}
	get(1);
	for (int i = 1; i <= n; ++i)
		if (!k[i])
			ans += abs(a[i]);
		else {
			if (k[i]) a[i] = -a[i];
			stk[++top] = a[i];
		}
	stk[++top] = 0;
	sort(stk + 1, stk + top + 1);
	int x = stk[(top + 1) / 2];
	for (int i = 1; i <= top; ++i)
		ans += abs(x - stk[i]);
	printf("%lld\n", ans);
}

Measured memory_bytes: 15232
require 'pp'

n = gets.chomp!.to_i
chs = gets.chomp!.chars

right_e = chs.count {|ch| ch == 'E' }
left_w = 0

result = []

n.times do |i|
    if chs[i] == "E"
        right_e -= 1
    end

    result << right_e + left_w

    if chs[i] == "W"
        left_w += 1
    end
end

puts result.min


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = 1e9;
  while (r - l > 1){
    int x = (l + r) / 2;
    auto f = [&](int x){
      ll now = 0;
      rep(i, n) now += (a[i] - 1) / x;
      return now <= k;
    };
    if (f(x)) r = x; else l = x;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 3988
#include<cstdio>

int main(){
  int a;
  int b;
  scanf("%d %d",&a,&b);
  int d,r;
  double f;
  d = a / b;
  r = a % b;
  f = 1.0 * a / b;
  printf("%d %d %f\n",d,r,f);
   return 0;
}

Measured memory_bytes: 1064
from functools import lru_cache
import sys
sys.setrecursionlimit(10**9)
@lru_cache(maxsize=None)
def f(n):
    if 0 < n and n  < 10:
        return n
    else:
        n = str(n)
        if int(n[-1]) == 0:
            return f(int(n)-1)
        if int(n[0]) < int(n[-1]):
            k = len(n) - 2
            n = int(n)
            if k > 0:
                return f(n-1) + int('1'*k)*2
            else:
                return f(n-1)
        elif int(n[0]) > int(n[-1]):
            k = len(n) - 1
            n = int(n)
            s = int('1'*k)*2
            return  f(n-1) + s
        else:
            k = len(n) - 2
            if k > 0:
                N = int(n)
                return f(N-1) + int('1'*k)*2  + int(n[1:-1])*2 + 3
            else:
                N = int(n)
                return f(N-1) + 3
                
p = int(input())
print(f(p))

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007

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

   int H,W;
   cin>>H>>W;
   vector<vector<int> >c(10,vector<int>(10));
   for(int y=0;y<10;y++){
      for(int x=0;x<10;x++){
         cin>>c[y][x];
      }
   }

   for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
         for(int k=0;k<10;k++){
            c[j][k]=min(c[j][i]+c[i][k],c[j][k]);
         }
      }
   }

   map<int,int>A;
   for(int y=0;y<H;y++){
      for(int x=0;x<W;x++){
         int a;
         cin>>a;
         A[a]++;
      }
   }

   //for(int i=0;i<10;i++)cout<<i<<" "<<A[i]<<endl;
   //for(int y=0;y<10;y++){for(int x=0;x<10;x++){cout<<c[x][y]<<" ";}cout<<endl;}
   

   ll ans = 0;
   for(int i=0;i<10;i++){
      if(i==1)continue;
      ans+=c[i][1]*A[i];
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        StringBuilder ans = new StringBuilder();
        while(true) {
            string[] inpt = Reader.ReadLine().Split(' ');
            long num1 = int.Parse(inpt[0]);
            long num2 = int.Parse(inpt[2]);

            string enzansi = inpt[1];

            long ansNum = 0;

            if (enzansi.Equals("+"))
            {
                ansNum = num1 + num2;
            }
            else if (enzansi.Equals("-"))
            {
                ansNum = num1 - num2;
            }
            else if (enzansi.Equals("*"))
            {
                ansNum = num1 * num2;
            }
            else if (enzansi.Equals("/"))
            {
                ansNum = num1 / num2;
            }
            else
            {
                break;
            }
            ans.AppendLine(ansNum.ToString("#######################################0"));
        }
        Console.Write(ans.ToString());
    
    }




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


1 + 2
56 - 18
13 * 2
100 / 10
27 + 81
0 ? 0


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 9260
K = int(input())
my_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

ans = my_list[K-1]

print(ans)


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

int main(void) {
	int a1,a2,a3;

	cin >> a1 >> a2 >> a3;
	if (a1 + a2 + a3 > 21)
	{
		cout << "bust" << endl;
	}
	else
	{
		cout << "win" << endl;
	}
	return 0;
}


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

using namespace std;

int num(vector<int>& v, int n) {
    int cnt = 0;
    for (int i = 2; i < v.size(); i++) {
        if (v.at(i) >= n) {
            cnt += 1;
        }
    }
    return cnt;
}

int main() {
    int N;
    cin >> N;
    vector<int> cnt(N + 1);
    for (int i = 2; i <= N; i++) {
        int n = i;
        for (int j = 2; j <= i; j++) {
            while (n % j == 0) {
                cnt[j] += 1;
                n /= j;
            }
            if (n == 1) {
                break;
            }
        }
    }
    // 75 = 5*15 = 3*25 = 3*5*5
    int ans = num(cnt, 74);
    ans += num(cnt, 14) * (num(cnt, 4) - 1);
    ans += num(cnt, 24) * (num(cnt, 2) - 1);
    ans += num(cnt, 4) * (num(cnt, 4) - 1) * (num(cnt, 2) - 2) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll dp[100100][2],n,a[100100];

ll Rec(int i , bool flipped){

    if(i == n)   return 0;

    if(dp[i][flipped] != -1)  return dp[i][flipped];

    ll Res = -1e18, x = (flipped ? -a[i] : a[i]);

    Res = max(Res , x + Rec(i + 1 , false));
    if(i + 1 < n)
    Res = max(Res , -x + Rec(i + 1 , true));

    return dp[i][flipped] = Res;
}


int main()
{
    cin >> n;
    memset(dp , -1 , sizeof(dp));
    for(int i = 0;i<n;i++)  cin >> a[i];
    cout << Rec(0 , 0);
    return 0;
}


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

using namespace std;

using ll = long long;

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

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<>());

    if (s < t) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


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

int main() {
    string S;
    cin >> S;
    // if (S.at(0) == S.at(1)) {
    //     cout << "Bad" << endl;
    // } else if (S.at(1) == S.at(2)) {
    //     cout << "Bad" << endl;
    // } else if (S.at(2) == S.at(3)) {
    //     cout << "Bad" << endl;
    // } else {
    //     cout << "Good" << endl;
    // }

    bool b = true;

    for (int i = 0; i < 3; i = i + 1) {
        if (S.at(i) == S.at(i + 1)) {
            cout << "Bad" << endl;
            b = false;
            break;
        }
    }

    if (b) {
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
import math
import fractions

n, m = [int(i) for i in input().split()]
s = input()
t = input()

ans = n * m // fractions.gcd(n, m)

for scnt in range(n):
    if scnt * m % n == 0:
        tcnt = scnt * m // n
        if s[scnt] != t[tcnt]:
            ans = -1
            break

print(ans)

Measured memory_bytes: 5684
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(0);   

  #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout);
      }
  #endif  

  int n,m,v,p;
  cin>>n>>m>>v>>p;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n,greater<>());
  int l=0,r=n-1;
  int mx=-1;
  while (l<=r)
  {
    int mid=l+(r-l)/2;
    int z=mid+1-p;
    if(z<=0)
    {
      l=mid+1;
      mx=max(mx,mid);
    }
    else
    {
      vector<int>temp;
      int fi=a[mid]+m;
      for(int i=p-1;i<n;i++)
      {
        if(i!=mid)
          temp.push_back(a[i]);
      }
      reverse(temp.begin(),temp.end());
      int x=(v-p)*m;
      x=max(x,0LL);
      bool flag=true;
      for(auto i:temp)
      {
        int y=fi-i;
        if(y<0)
          flag=false;
        x-=min(x,min(m,y));
      }
      if(x>0)
        flag=false;
      if(flag)
      {
        mx=max(mx,mid);
        l=mid+1;
      }
      else
      {
        r=mid-1;
      }      
    }    
  }

  cout<<mx+1;

}

Measured memory_bytes: 2916
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const double EPS = 1e-8;
const int MOD = 1000 * 1000 * 1000 + 7;

const int MAX = 5 * 100 * 1000 + 47;



char S[MAX];
int LST[MAX];
VI V[MAX];
int DP[MAX];
int main()
{
    int n;
    scanf("%d", &n);
    scanf("%s", S);
    int lst = -1;
    FOR(i, 0, n)
    {
        LST[i] = lst;
        if (S[i] == '0')lst = i;
    }
    
    FOR(i, 0, n)
    {
        if (S[i] == '0')continue;
        int l = LST[i];
        if (l == -1)continue;
        if (l == i - 1)
        {
            int ll = LST[l];
            FOR(j, ll + 1, l)
                V[i].PB(j);
        }
        else
        {
            if (l >= 1 && S[l-1] == '1')
                V[i].PB(l-1);
        }
    }
    
    //FOR(i, 0, n)
    //{
    //    cout << i << " : ";
    //    FOR(j, 0, SZ(V[i]))
    //    cout << V[i][j] << " ";
    //    cout << endl;
    //}
    
    FOR(i, 0, n)
    {
        if (i)DP[i] = DP[i-1];
        FOR(j, 0, SZ(V[i]))
        {
            int to = V[i][j];
            int res = 0;
            if (to)res += DP[to-1];
            res += i - to - 1;
            DP[i] = max(DP[i], res);
        }
    }
    printf("%d\n", DP[n-1]);
    
}


Measured memory_bytes: 34560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

string solve() {
    ll A, B;
    cin >> A >> B;
    if ( A == 1 ) A = 14;
    if ( B == 1 ) B = 14;
    if ( A > B ) return "Alice";
    else if ( A < B ) return "Bob";
    else return "Draw";
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,m,c=1;
    cin>>n>>m;
    vector<pair<long int ,long int>>v(m);
    for(int i=0;i<m;i++)
    cin>>v[i].first>>v[i].second;
    long int k=v[0].first,l=v[0].second;
    for(int i=1;i<m;i++)
    {
           k=max(k,v[i].first);
           l=min(l,v[i].second);
    }
    if(l-k+1>0)
    {
      cout<<l-k+1;
    }
    else
        cout<<0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
res = 0

for i in range(0,n):
    zan = 0
    tres = 0
    ta = a[i]
    tb = b[i]

    if tb >= ta:
        res += ta
        zan = tb-ta
        tres = min(a[i+1],zan)
        a[i+1] -= tres
        res += tres

    else:
        res += tb
        
print(res)


Measured memory_bytes: 18476
#include<stdio.h>
int main()
{
    int d;
    scanf("%d",&d);
    if(d==25)
    {
        printf("Christmas\n");
    }
    else if(d==24)
    {
        printf("Christmas Eve\n");
    }
    else if(d==23)
        printf("Christmas Eve Eve\n");
    else if(d==22)
    {
        printf("Christmas Eve Eve Eve\n");
    }
    return 0;
}



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

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

    int N;
    vector<int> h;

    cin >> N;
    for (int i = 0; i < N; i++) {
        int buf;
        cin >> buf;
        h.push_back(buf);
    }

    int cost[100000];
    memset(cost, 0x7f, sizeof(cost));
    cost[0] = 0;
    for (int i = 0; i < N-1; i++) {
        for (int s = 1; s <= 2; s++) {
            int c = cost[i] + abs(h[i]-h[i+s]);
            cost[i+s] = min(cost[i+s], c);
        }
    }
    cout << cost[N-1] << endl;

    return 0;
}



Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
        
int main(){
  string s;
  cin >> s;
  
  int count = 0; 
  int ans = 0;
  for(int i=0;i<s.length();i++){
  	if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
    	count++;
      	ans = max(ans, count);
  	} else {
      count = 0;
    }
  }
  cout << ans << endl;
 }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int N, M, X, Y;
    int x, y;
    int maxx = -100, miny = 100;

    cin >> N >> M >> X >> Y;
    for (int i = 0; i < N; ++i) { cin >> x; if (x > maxx) maxx = x;}
    for (int i = 0; i < M; ++i) { cin >> y; if (y < miny) miny = y;}
    cout << ( (maxx < miny && miny > X && maxx < Y) ? "No War" : "War") << endl;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
AB = []
for i in range(N):
    a,b = map(int,input().split())
    AB.append((a,b))
AB.sort(key=lambda x:x[0])
num = 0
money = 0
for i in range(N):
    if AB[i][1]+num >= M:
        money += AB[i][0]*(M-num)
        break
    num += AB[i][1]
    money += AB[i][0]*AB[i][1]
print(money)

Measured memory_bytes: 18180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    LL x,t; cin>>x>>t;
    if(t-x>0) cout<<0<<endl;
    else cout<< x-t << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
  
class Main{
  
static final PrintWriter out=new PrintWriter(System.out);

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PriorityQueue<Integer> pque=new PriorityQueue<Integer>(10,new Comparator<Integer>(){
public int compare(Integer n1,Integer n2){
return n1>n2?-1:n1<n2?1:0;
}
});
int n;
while(true){
StringTokenizer st=new StringTokenizer(br.readLine());
String command=st.nextToken();
if("insert".equals(command)){
n=Integer.parseInt(st.nextToken());
pque.offer(n);
}
else if("end".equals(command)) break;
else out.println(pque.poll());
}
out.flush();
}
}

Measured memory_bytes: 181828
import sys
for line in sys.stdin.readlines():
    a, b, c, d, e, f = map(float, line.split())
    x = (c * e - b * f)/(a * e - b * d) 
    y = (c * d - a * f)/(b * d - a * e)
    
    if ((c * e - b * f == 0) | (a * e - b * d == 0)):
        x = 0
    if ((c * d - a * f == 0) | (b * d - a * e == 0)):
        y = 0
    
    print('{:.3f}'.format(x), '{:.3f}'.format(y))


Measured memory_bytes: 5584