akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  long long sumA = 0;
  for (int i = 0; i < N; i++){
    cin >> A[i];
    sumA += A[i];
  }
  vector<int> B(N);
  long long sumB = 0;
  for (int i = 0; i < N; i++){
    cin >> B[i];
    sumB += B[i];
  }
  if (sumA < sumB){
    cout << -1 << endl;
  } else {
    vector<int> D(N);
    for (int i = 0; i < N; i++){
      D[i] = A[i] - B[i];
    }
    sort(D.begin(), D.end());
    vector<int> D1, D2;
    for (int i = 0; i < N; i++){
      if (D[i] < 0){
        D1.push_back(D[i]);
      } else {
        D2.push_back(D[i]);
      }
    }
    int ans = D1.size();
    long long f = 0;
    for (int i = 0; i < ans; i++){
      f -= D1[i];
    }
    reverse(D2.begin(), D2.end());
    long long Dsum = 0;
    for (int i = 0; i < D2.size(); i++){
      if (Dsum >= f){
        break;
      }
      ans++;
      Dsum += D2[i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2044
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    s = input()
    if s == "Sunny":
        print("Cloudy")
    elif s == "Cloudy":
        print("Rainy")
    else:
        print("Sunny")
    return


# B
def B():
    s = S()
    for i in range(len(s)):
        if i % 2:
            if s[i] not in ["L", "U", "D"]:
                print("No")
                return
        else:
            if s[i] not in ["R", "U", "D"]:
                print("No")
                return
    print("Yes")
    return


# C
def C():
    n, k, q = LI()
    a = IR(q)
    sc = [0] * n
    for i in a:
        sc[i - 1] += 1
    for i in sc:
        print("Yes" if i > q - k else "No")
    return


# D
def D():
    n, m = LI()
    a = LI()
    q = []
    for i in range(n):
        heappush(q, -a[i])
    for i in range(m):
        x = heappop(q)
        x *= -1
        x >>= 1
        heappush(q, -x)
    print(-sum(q))
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    D()
    return


# Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 60952
#include<bits/stdc++.h> 
using namespace std;   
int gcd(int a,int b)
{
	while(a&&b)
	{
		if(a>b) a%=b;
		else  b%=a;
	}
	return a?a:b;
}
int main()  
{  
    int n,k;
	scanf("%d%d",&n,&k);
	int a[100005];
	int kk;
	int mx=-1,mn=1000000005;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(i==0)
			kk=a[i];
		else
			kk=gcd(kk,a[i]);
		mx=max(a[i],mx);
		mn=min(a[i],mn);
	}
	bool f=0;
	if(k>mx||k<mn)
	{
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		if(abs(k-a[i])%kk==0)
		{
			f=1;
			break;
		}
	}
	if(f==1)
		cout<<"POSSIBLE"<<endl;
	else
		cout<<"IMPOSSIBLE"<<endl;
}  

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            int win = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'o')
                {
                    win++;
                }
            }
            WriteLine(
                (15 - s.Length) + win >= 8 ? "YES":"NO"
                );
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int S =sc.nextInt();
		int W =sc.nextInt();

		if(S<=W) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}

	}

}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    if(X < Y){
        swap(X, Y);
        swap(A, B);
    }
    //Cは2枚でA,B各二枚になる
    //とりあえず全探索する？
    ll ans = 1000000000000;
    for(ll i = 0; i <= X; i++){
            ll k = X - i;
            ll j = Y - k;
            if(k < 0) k = 0;
            else if(j < 0) j = 0;
            ll tmpA = i + k;
            ll tmpB = j + k;
            ll price = i * A + j * B + k * C * 2;
            if(tmpA >= X && tmpB >= Y){
                if(ans > price)  ans = price;
            }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int gcd(int n1,int n2)
{
	int r=1;
	if(n2 == 0)
		return n1;
	if(n1 == 0)
		return n2;
	while(r!=0){
		r=n1%n2;
		n1=n2;
		n2=r;
	}
	return n1;
}

int main(void)
{
	int i,n,m;
	scanf("%d",&n);
	int a[n];
	int l[n];
	int r[n];
	int max=0;
	
	l[0]=0;
	r[0]=0;
	
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	
	for(i=0;i<n;i++)
		l[i+1]=gcd(l[i],a[i]);
	for(i=0;i<n;i++)
		r[i+1]=gcd(r[i],a[n-1-i]);

	for(i=0;i<n;i++)
	{
		m=gcd(l[i],r[n-1-i]);
		if(m>max)
			max=m;
	}
	printf("%d",max);
	return 0;
}


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

int x,y;

int main()
{
    cin>>x>>y;
    char v[x][y];
    for (int i=0; i<x; i++){
        for (int j=0; j<y; j++) cin>>v[i][j];
    }

    for (int i=0; i<x+2; i++){
        if (i==0 || i==x+1){
            for (int j=0; j<y+2; j++) cout<<'#';
        }
        else {
            for (int j=0; j<y+2; j++){
                if (j==0 || j==y+1) cout<<'#';
                else cout<<v[i-1][j-1];
            }
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sqrt
import kotlin.math.tan

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val lList = readLongList()

    var ans = 0L
    for (i in 0 until n) {
        for (j in (i + 1) until n) {
            for (k in (j + 1) until n) {
                val a = listOf(lList[i], lList[j], lList[k]).sortedDescending()
                if (a.toSet().size != 3) {
                    continue
                }

                if (a[0] < a[1] + a[2]) {
                    ans++
                }
            }
        }
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main() {

	string a;

	cin >> a;

	if (a[0]=='9'||a[1]=='9') {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=1005;
char
tp5[N][N]={
			"aabc.",
			"..bcd",
			"fee.d",
			"f.ghh",
			"iigjj"
		},
tp7[N][N]={
			"ab...c.",
			"ab...c.",
			"..dee.f",
			"..d.g.f",
			"..hhg.i",
			"jj..kki",
			"llmm.nn"
		};
int n; char a[N][N];
inline void odd_paint(CI sx=0)
{
	for (RI i=sx;i<n;i+=2)
	a[i][i]=a[i][i+1]='a',a[i+1>=n?i+1-n+sx:i+1][i]=a[i+1>=n?i+1-n+sx:i+1][i+1]='b',
	a[i+2>=n?i+2-n+sx:i+2][i]=a[i+3>=n?i+3-n+sx:i+3][i]='c',a[i+2>=n?i+2-n+sx:i+2][i+1]=a[i+3>=n?i+3-n+sx:i+3][i+1]='d';
}
inline void print(CI n,char c[N][N])
{
	for (RI i=0;i<n;++i)
	{
		for (RI j=0;j<n;++j) putchar(c[i][j]); if (i!=n-1) putchar('\n');
	}
}
int main()
{
	RI i,j; scanf("%d",&n); if (n==2) return puts("-1"),0;
	if (n==5) return print(5,tp5),0;
	if (n==7) return print(7,tp7),0;
	for (i=0;i<n;++i) for (j=0;j<n;++j) a[i][j]='.';
	if (n%3==0)
	{
		for (i=0;i<n;i+=3) for (j=0;j<n;j+=3)
		a[i][j]=a[i][j+1]='a',a[i+1][j+2]=a[i+2][j+2]='b';
		return print(n,a),0;
	}
	if (n%2==0) return odd_paint(),print(n,a),0;
	for (i=0;i<5;++i) for (j=0;j<5;++j) a[i][j]=tp5[i][j];
	return odd_paint(5),print(n,a),0;
}

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

int main() {
	char str[10];
	for(int i = 0; i < 10; i++){
		cin >> str[i];
	}
	str[3] = '8';
	for(int j  = 0; j < 10; j++){
		cout << str[j];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
//This Code was made by Chinese_zjc_.
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <time.h>
// #include<windows.h>
#define int long long
#define double long double
using namespace std;
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
int l1[200005], l2[200005], n, ans;
struct point
{
    int x, y;
} p[200005];
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> p[i].x >> p[i].y;
        l1[i] = p[i].x - p[i].y;
        l2[i] = p[i].x + p[i].y;
    }
    sort(l1 + 1, l1 + 1 + n);
    sort(l2 + 1, l2 + 1 + n);
    for (int i = 1; i <= n; ++i)
    {
        ans = max(ans, p[i].x - (l1[1] + p[i].y));
        ans = max(ans, (l1[n] + p[i].y) - p[i].x);
        ans = max(ans, p[i].x - (l2[1] - p[i].y));
        ans = max(ans, (l2[n] - p[i].y) - p[i].x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9904
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> ac_flags(n+1, 0);
    vector<int> wa_count(n+1, 0);
    int ac = 0;
    rep(i, m) {
        int p; string s;
        cin >> p >> s;
        // まだ正解していないかつ今回正解した
        if (ac_flags[p] != 1 && s == "AC") {
            ac_flags[p] = 1;
            ac++;
        }
        // まだ正解していないかつ今回不正解だった
        if (ac_flags[p] != 1 && s == "WA") wa_count[p]++;
    }
    int wa = 0;
    rep(i, n+1) {
        if (ac_flags[i]) wa += wa_count[i];
    }
    cout << ac << " " << wa << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

import(
 "fmt"
  "strings"
)
  
func main() {
 var n, k int
   fmt.Scan(&n, &k)
   var s string
   fmt.Scan(&s)
  
  ss := strings.Split(s, "")
  
  sum := 0
  for i := 0; i < n-1; i++ {
    if ss[i] == ss[i+1] {
    	sum++
    }
  }
  sum += k*2
  if (sum > n -1) {
  	sum = n -1
  }
  
  fmt.Print(sum)
}

Measured memory_bytes: 2944
#include <iostream>
#include <stdlib.h>

using namespace std;
int binarySearch(int n, int* s, int q, int* t)
{
    int sum = 0;
    for (int i = 0; i < q; i++) {
	for (int j = 0; j < n; j++) {
	    if (t[i] < s[j]) {
		break;
	    }
	    if (t[i] == s[j]) {
		sum++;
		break;
	    }
	}
    }
    return sum;
}
int main()
{
    int n = 0;
    int q = 0;
    cin >> n;

    int* s = (int*)malloc(sizeof(int) * n);
    for (int i = 0; i < n; i++) {
	scanf("%d", &s[i]);
    }
    cin >> q;
    int* t = (int*)malloc(sizeof(int) * q);
    for (int i = 0; i < q; i++) {
	scanf("%d", &t[i]);
    }
    int sum = binarySearch(n, s, q, t);
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 3764
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        long abs = a[n - 1] / 2;
        if (a[n - 1] % 2 != 0) {
            abs++;
        }
        long ans = a[n-1];
        long A = 0;
        for (int i = 0; i < n - 1; i++) {
            long b = Math.abs(a[i] - abs);
            if (ans > b) {
                ans = b;
                A = a[i];
            }
        }
        System.out.println(a[n - 1] + " " + A);
    }
}

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

int main(){
	int a, s[2]={0};
		
	for(int i=0; i<2; ++i){
		for(int j=0; j<4; ++j){
			scanf(" %d", &a);
			s[i]+=a;
		}
	}
	
	if(s[0]>=s[1]) printf("%d\n", s[0]);
	else printf("%d\n", s[1]);

	return 0;
}

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

using namespace std;

int main(int argc, char const* argv[]) {
  string s;

  cin >> s;

  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    int t = 86400;
    int t2 = 10800;
    vector<int> cnt(t,0);
    vector<int> sc(t+1,0);
    int temp = a[0];
    temp%=t;
    REP(i,n-1){
        cnt[temp]++;
        temp+=b[i];
        temp+=a[i+1];
        temp%=t;
    }
    sc[0] = 0;
    REP(i,t){
        sc[i+1] = sc[i]+cnt[i];
    }
    int res = 0;
    REP(i,t){
        int temp2 = 0;
        if(i+t2<t){
            temp2 = sc[i+t2+1]-sc[i];
        }else{
            temp2 += sc[t]-sc[i];
            temp2 += sc[i+t2+1-t]-sc[0];
        }
        
        chmax(res,temp2);
    }
    put(res);
    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}


int main(void){
int n;
int v[55];
scanf("%d",&n);

for(int i=0;i<n;i++){
    scanf("%d",&v[i]);
}
qsort(v,n,sizeof(int),cmp);

double ans=(double)(v[0]+v[1])/2.0;

for(int i=2;i<n;i++){
    ans=(double)(ans+v[i])/2.0;
}
printf("%lf",ans);
} 


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
string s,temp;
cin>>s;
temp=s;
ll sum=0,n;
n=stoi(s);
for(int i=0;i<temp.size();i++)
{
    sum+=temp[i]-'0';
}
if(n%sum==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int c1=0,c2=0,c3=0,c4=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		if(s=="AC") c1++;
		else if(s=="WA")  c2++;
		else if(s=="TLE") c3++;
		else              c4++;
	}
	cout<<"AC"<<" x "<<c1<<endl;
	cout<<"WA"<<" x "<<c2<<endl;
	cout<<"TLE"<<" x "<<c3<<endl;
	cout<<"RE"<<" x "<<c4<<endl;
	return 0;
}

Measured memory_bytes: 3552
'''ika tako  色は1～からの番号で表すとする。
適当な頂点①から、順に辺で繋がった頂点を探索し、辺の色を、
まだ使われてない最小の色で確定していけば、条件を満たすように作れる。
①--- 1 ---②--- 2 ---⑤
 |           `-- 3 ---⑥
 |--- 2 ---③--- 1 ---⑦
 |           `-- 3 ---⑧
 `--- 3 ---④--- 1 ---⑨
             `-- 2 ---⑩
木の場合は、根から順に確定する限り、相手先の頂点の他の辺が必ず
未確定である（後でその頂点の処理時に何とでも調整できる）ので、
この方法が使える。
'''
import sys
 
n = int(input())#頂点数
links = [set() for _ in range(n)]#この入力はABC166Cでも使う
for i, line in enumerate(sys.stdin):
    a, b = map(int, line.split())
    a -= 1#0-indexへ、abc165Cも同様
    b -= 1
    links[a].add((i, b))
    #リストlinksの中身のa番目のセットにindexと共に連結先を追加add
    links[b].add((i, a))

ans = [-1] * (n - 1)#初期値は存在しえない数値、頂点-1個で足りる
k = max(map(len, links))#リストlinksの長さの最大(セットの要素数の最大)
q = [(0, -1)]
fixed = set()
 
while q:
    v, c = q.pop()#頂点vと色cをキューから取り出す
    color = 1
    if c == color:#取り出した色が使っている色なら、新しい色を使う
        color += 1
    for i, u in links[v]:#リストlinksからindexと連結先を取り出す
        if ans[i] != -1:#色が決まっていたら何もしない
            continue
        ans[i] = color#色を決めて、ansに入れる
        q.append((u, color))#キューに連結先と使った色を入れる
        color += 1#色を新しい色にしておく
        if c == color:
        #これがないとサンプルはOKだが、他はダメ。
        #複数の連結先がある場合がダメか？
            color += 1
print(k)
print('\n'.join(map(str, ans)))

Measured memory_bytes: 57148
#include <iostream>

using namespace std;

int main()
{
    while (true)
    {
        int N;
        cin>>N;
        if (N==0)
            break;
        int k[100000];
        for (int i=0; i<N; i++)
            cin>>k[i];

        bool ok = false;
        int ans = 1;
        for (int i=0; i<N; i++)
        {
            if (k[i]>=1)
                ans++;
            if (k[i]>=2)
                ok = true;
        }
        if (ok)
            cout<<ans<<endl;
        else
            cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll H, W, N;
int sr, sc;
string S, T;

bool count(char a, char b, int d, int s) {
  int res = s;
  REP(i, N) {
    if(S[i] == a) res++;
    if(res >= s + d) return true;
    if(T[i] == b && res > 0) res--;
  }

  return false;
}

int main(){
  cin >> H >> W >> N;
  cin >> sr >> sc;
  cin >> S;
  cin >> T;

  bool ans = count('L', 'R', sc, W - sc) || count('R', 'L', W - sc + 1, sc - 1) 
  || count('U', 'D', sr, H - sr) || count('D', 'U', H - sr + 1, sr - 1);

  if(ans) cout << "NO" << endl;
  else cout << "YES" << endl; 

  return 0;
}



Measured memory_bytes: 776
#include <stdio.h>
using namespace std;

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((W >= x+r) && (H >= y+r) && (x-r >= 0) && (y-r >= 0)){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int d;

int main()
{
    _FastIO;
    cin >> d;
    string ans = "Christmas";
    int k = 25 - d;
    for(int i = 0; i < k; i++){
        ans += " Eve";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;
  int t[109];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t[i];
    sum+=t[i];
  }
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int p,x;
    cin>>p>>x;
    p--;
    cout<<sum-t[p]+x<<endl;
  }
  return(0);
}


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

typedef long long ll;
#define re(n) cin >> n
#define all(a) a.begin(),a.end()
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define te(t) ll t; re(t); while(t--)

int main(){
	int arr[82]={0};
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			arr[i*j] = 1;
		}
	}
	ll x;
	re(x);
	if(arr[x]&&x<=81) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

    int i_inputDigitNum;
    int i_inputJudgeCountNum;
    char c_existFlag = 1;

    scanf("%d%d", &i_inputDigitNum, &i_inputJudgeCountNum);

    int displayNum[i_inputDigitNum];

    for (int index = 0; index < i_inputDigitNum; index++)
    {
        displayNum[index] = 10;
    }

    int i_judgeNumDigit;
    int i_judgeNumber;
    for (int count = 0; count < i_inputJudgeCountNum; count++)
    {
        scanf("%d%d", &i_judgeNumDigit, &i_judgeNumber);
        if (i_inputDigitNum != 1 && i_judgeNumDigit == 1 && i_judgeNumber == 0)
        {
            c_existFlag = 0;
            break;
        }
        if (displayNum[i_judgeNumDigit - 1] == 10 || displayNum[i_judgeNumDigit - 1] == i_judgeNumber)
        {
            displayNum[i_judgeNumDigit - 1] = i_judgeNumber;
        }
        else
        {
            c_existFlag = 0;
        }
    }

    for (int index = 0; index < i_inputDigitNum; index++)
    {
        if (displayNum[index] == 10 && index == 0 && i_inputDigitNum != 1)
        {
            displayNum[index] = 1;
        }
        else if (displayNum[index] == 10)
        {
            displayNum[index] = 0;
        }
    }

    if (c_existFlag == 1)
    {
        for (int index = 0; index < i_inputDigitNum; index++)
        {
            printf("%d", displayNum[index]);
        }
    }
    else
    {
        printf("-1");
    }

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, cn;

int main()
{
	scanf("%d", &n);
	if(n == (n & -n)) {
		printf("No\n");
		return 0;
	}
	
	printf("Yes\n");
	
	cn = n - (n + 1) % 4;
	rep1(i, cn) printf("%d %d\n", i, i == cn ? n + 1 : i + 1);
	rep1(i, cn - 1) printf("%d %d\n", n + i, n + i + 1);
	
	if(n - cn == 1) {
		int cur = n & -n;
		printf("%d %d\n", cn + 1, cur + 1);
		printf("%d %d\n", n + cn + 1, (n ^ cur));
	} else if(n - cn == 2) {
		printf("%d %d\n", cn + 1, cn + 2);
		printf("%d %d\n", cn + 2, 1);
		printf("%d %d\n", n + cn + 1, n + cn + 2);
		printf("%d %d\n", n + cn + 1, 1);
	} else if(n - cn == 3) {
		printf("%d %d\n", cn + 1, cn + 2);
		printf("%d %d\n", cn + 2, 1);
		printf("%d %d\n", n + cn + 1, n + cn + 2);
		printf("%d %d\n", n + cn + 1, 1);
		printf("%d %d\n", cn + 3, cn + 2);
		printf("%d %d\n", n + cn + 3, 2);
	}
	return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{

    int N;
    int M;

    scanf("%d %d", &N, &M);

    if(N < 1 || N > 100000 || M < N || M > 1000000000) {
        exit(0);
    }

    int syou = M / N;

    for(int i = syou;i > 0;i--) {
        if(M % i == 0) {
            printf("%d\n", i);
            break;
        } 
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x,y,c,d;
    cin>>x>>y>>c>>d;
    if (x+y>c+d)
        cout<<"Left";
    else if (x+y<c+d)
        cout<<"Right";
    else
        cout<<"Balanced";
    return 0;
}


Measured memory_bytes: 256
n = input()
a = list(map(int,input().split()))

def iseven(i,num_list):
  count = 0
  for num in num_list:
    if num % 2 != 0:
      return False
  return True

num_divided = 0

while iseven(n,a) :
  a = list(map(lambda x: x / 2, a ))
  num_divided += 1

print(num_divided)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll n;
ll a[224514];
P b[224514];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)b[i].first = a[i];
	rep(i, n)b[i].second = i;
	sort(b, b + n);
	ll memo = b[n - 1].second;
	rep(i, n) {
		if (i == memo)cout << b[n - 2].first << endl;
		else cout << b[n - 1].first << endl;
	}
	ggr
}


Measured memory_bytes: 6656
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const int maxn = 100000+5;
const LL mod = 1000000007;
struct Node {
    int l,r;
    int sum;
    int c;
}t[maxn<<2];
struct Seg {
    int l,r;
}s[maxn+(maxn<<1)];
vector<int>g[maxn];
void build(int l,int r,int rt) {
    t[rt].l=l;
    t[rt].r=r;
    t[rt].sum=0;
    t[rt].c=0;
    if (l==r) {
        return ;
    }
    int mid = (l+r)>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    return ;
}
void pushdown(int &rt) {
    if (!t[rt].c) {
        return ;
    }
    int len = t[rt].r-t[rt].l+1;
    t[rt<<1].sum+=t[rt].c*( len - (len>>1) );
    t[rt<<1|1].sum+=t[rt].c*( len>>1 );
    t[rt<<1].c+=t[rt].c;
    t[rt<<1|1].c+=t[rt].c;
    t[rt].c=0;
    return ;
}
void update(int l,int r,int rt,int val) {
    if (l<=t[rt].l&&t[rt].r<=r) {
        t[rt].sum+=val*(t[rt].r-t[rt].l+1);
        t[rt].c+=val;
        return ;
    }
    pushdown(rt);
    int mid = (t[rt].l+t[rt].r)>>1;
    if (l<=mid) {
        update(l,r,rt<<1,val);
    }
    if (r>mid) {
        update(l,r,rt<<1|1,val);
    }
    t[rt].sum=t[rt<<1].sum+t[rt<<1|1].sum;
    return ;
}
int query(int rt,int where) {
    if (t[rt].l==t[rt].r) {
        return t[rt].sum;
    }
    pushdown(rt);
    int mid = (t[rt].l+t[rt].r)>>1;
    if (where<=mid) {
        return query(rt<<1,where);
    }
    if (where>mid) {
        return query(rt<<1|1,where);
    }
}
int main() {
    
    int n,m;
    scanf("%d%d",&n,&m);
    build(1,m,1);
    for (int i=1;i<=n;++i) {
        scanf("%d%d",&s[i].l,&s[i].r);
        int len = s[i].r-s[i].l+1;
        g[len].push_back(i);
    }
    for (int i=1;i<=m;++i) {
        int ans=0;
        n-=g[i-1].size();
        for (int j=0;j<g[i-1].size();++j) {
            int &pos=g[i-1][j];
            update(s[pos].l,s[pos].r,1,1);
        }
        for (int j=i;j<=m;j+=i) {
            ans+=query(1,j);
        }
        printf("%d\n",ans+n);
    }
    return 0;
}

Measured memory_bytes: 14208
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int m = ni();

		long h[] = new long[n];

		for (int i = 0; i < n; i++) {
			h[i] = nl();
		}

		boolean yoi[] = new boolean[n];
		for (int a = 0; a < n; a++) {
			yoi[a] = true;
		}

		for (int i = 0; i < m; i++) {

			int a1 = ni() - 1;
			int b1 = ni() - 1;

			if (h[a1] < h[b1]) {
				yoi[a1] = false;
				//yoi[b1] = true;
			} else if (h[a1] > h[b1]) {
				//yoi[a1] = true;
				yoi[b1] = false;
			} else {
				yoi[a1] = false;
				yoi[b1] = false;
			}

		}

		int count = 0;
		for (boolean flg : yoi) {
			if (flg) {
				count++;
			}
		}

		out(count);

	}

	public static int count(String search, String text) {
		int nsearch = search.length();
		int ntext = text.length();
		int count = 0;

		for (int i = 0; i <= ntext - nsearch + 1; i++) {
			for (int j = i + nsearch - 1; j < ntext; j++) {
				if (search.equals(text.substring(i, j + 1))) {
					count++;
				}
			}
		}

		return count;
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

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

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

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


Measured memory_bytes: 60468
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,m,x[8],c=0;
    bool e[9][9];
    cin>>n>>m;
    for(int i=0;i<9;i++)for(int j=0;j<9;j++)e[i][j]=false;
    for(int i=0;i<n;i++)x[i]=i+1;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        e[a][b]=e[b][a]=true;
    }
    do{
        /*
        for(int i=0;i<n;i++){
            cout<<x[i];
            if(i<n-1)cout<<" ";
            else cout<<endl;
        }
        */
        bool f=true;
        for(int i=0;i<n-1&&f;i++){
            f=e[x[i]][x[i+1]];
        }
        if(f)c++;
    }while(next_permutation(x+1,x+n));
    
    cout<<c<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		var b=sc.Ia;
		var qu=new Queue<int>();
		long ans=0;
		for(int i = 0;i<n;i++) {
			if(b[i]>a[i]&&b[i]>b[(i+1)%n]&&b[i]>b[(i-1+n)%n]){qu.Enqueue(i);}
		}
		while(qu.Count>0){
			var e=qu.Dequeue();
			int p=(b[e]-a[e])/(b[(e-1+n)%n]+b[(e+1)%n]);
			b[e]-=p*(b[(e-1+n)%n]+b[(e+1)%n]);
			ans+=p;
			int d=(e+1)%n;
			if(b[d]>a[d]&&b[d]>b[(d+1)%n]&&b[d]>b[(d-1+n)%n]){qu.Enqueue(d);}
			d=(e-1+n)%n;
			if(b[d]>a[d]&&b[d]>b[(d+1)%n]&&b[d]>b[(d-1+n)%n]){qu.Enqueue(d);}
		}
		for(int i = 0;i<n;i++) {
			if(a[i]!=b[i]){ans=-1;break;}
		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 45416
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int N;
int Q;
int S;
long long Sum;
int main()
{
  scanf("%d", &N);
  for(int i=0; i<N; i++)
  {
      scanf("%d", &S);
      if(S<Q)
      {
        Sum+=Q-S;
      }
      else
      {
      	Q=S;
	  }    
  }
  printf("%lld", Sum);
  return 0;
}

Measured memory_bytes: 3744
H, W = map(int, input().split())

data = [list(map(int, input().split())) for _ in range(H)]

way = []
for h in range(H):
    for w in range(W):
        if h % 2 == 0:
            if data[h][w] % 2 == 1:
                if w < W-1:
                    way.append((h+1, w+1, h+1, w+2))
                    data[h][w+1] += 1
                elif h+1 < H:
                    way.append((h+1, w+1, h+2, w+1))
                    data[h+1][w] += 1
        else:
            w = W - 1 - w
            if data[h][w] % 2 == 1:
                if w > 0:
                    way.append((h+1, w+1, h+1, w))
                    data[h][w-1] += 1
                elif h+1 < H:
                    way.append((h+1, w+1, h+2, w+1))
                    data[h+1][w] += 1

print(len(way))
for a, b, c, d in way:
    print(a, b, c, d)




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

const int LIMIT = (int)1e4;

vector<int> dp(LIMIT + 1, -LIMIT);
int numbers[] = { 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int> > a(m);
	for (int i = 0; i < m; i++) {
		int tmp; cin >> tmp;
		a[i] = make_pair(tmp, numbers[tmp - 1]);
	}
	sort(a.rbegin(), a.rend());

	dp[0] = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			int tmp = a[j].second;
			if (i < tmp) continue;
			if (dp[i - tmp] < 0) continue;
			dp[i] = max(dp[i], dp[i - tmp] + 1);
		}
	}
	int digit = dp[n];
	for (int i = 0; i < digit; i++) {
		for (int j = 0; j < m; j++) {
			if (n < a[j].second) continue;
			if (dp[n - a[j].second] == dp[n] - 1) {
				cout << a[j].first;
				n -= a[j].second;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
count = [0]*n
for _ in range(k):
    d = int(input())
    a = map(int,input().split())
    for i in a:
        count[i-1]+=1
        
ans = 0
for i in count:
    if i == 0:
        ans += 1
    
print(ans)

Measured memory_bytes: 9216
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N; cin >> N;

    stack<ll > F; 
    queue<ll > F2;  
    queue<ll > B; 
    stack<ll > B2;

    bool f = true;
    //ll n; cin >> n; B.push(n);
    for(ll i = 0; i < N; i++){
        ll n; cin >> n;
        if(f == true){
            B.push(n);
            B2.push(n);
            f = false;
        }else{
            F.push(n);
            F2.push(n);
            f = true;
        }
    }

    if(N % 2 == 0){
        while(!F.empty()){
            cout << F.top() << " ";
            F.pop();
        }
        while(!B.empty()){
            cout << B.front() << " ";
            B.pop();
        } 
    }else{
        while(!B2.empty()){
            cout << B2.top() << " ";
            B2.pop();
        }
        while(!F2.empty()){
            cout << F2.front() << " ";
            F2.pop();
        }         
    }
   

}

Measured memory_bytes: 5504
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n, a[100010];
signed main() {
	int cnt = 0;
	bool f = false;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (a[i] < 0)cnt++;
		if (!a[i])f = true;
	}
	if (f) {
		int ans = 0;
		rep(i, n)ans += abs(a[i]);
		cout << ans << endl;
	}
	else {
		if (cnt % 2 == 0) {
			int ans = 0;
			rep(i, n)ans += abs(a[i]);
			cout << ans << endl;
		}
		else {
			rep(i, n)a[i] = abs(a[i]);
			sort(a, a + n);
			int ans = 0;
			rep(i, n)ans += a[i];
			ans -= a[0] * 2;
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int n,dp[1009][10009];
pair <pair<int,int>,int> v[1009];
int f(int i,int c){
	if(i==n)return 0;
	if(dp[i][c]!=-1)
		return dp[i][c];
	dp[i][c]=f(i+1,c);
	if(v[i].f.f<=c)
		dp[i][c]=max(dp[i][c],v[i].s+f(i+1,min(c-v[i].f.f,v[i].f.s)));
	return dp[i][c];
}
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> v[i].f.f >> v[i].f.s >> v[i].s;
		v[i].f.f+=v[i].f.s;
	}
	sort(v,v+n);
	reverse(v,v+n);
	for(int i=0;i<n;i++)
		v[i].f.f-=v[i].f.s;
	memset(dp,-1,sizeof(long long)*1009*10009);
	int m=0;
	for(int i=0;i<n;i++)
		m=max(v[i].s+f(i+1,v[i].f.s),m);
	cout << m << endl;
}


Measured memory_bytes: 79232
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    token = lines[0].split()
    a = int(token[0])

    s = lines[1]

    return (a, s)


def solve(a, s):

    result = s
    if a < 3200:
        result = 'red'

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;

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

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

main(){
  string in;
  while(getline(cin,in) && in != "."){
    stack<char> S;
    bool fg=true;
    rep(i,in.size()){
      if (in[i] == '(')S.push(in[i]);
      if (in[i] == ')'){
	if (S.empty() || S.top() != '('){fg=false;break;}
	S.pop();
      }
      if (in[i] == '[')S.push(in[i]);
      if (in[i] == ']'){
	if (S.empty() || S.top() != '['){fg=false;break;}
	S.pop();
      }
    }
    if (S.empty() && fg)cout <<"yes" << endl;
    else  cout <<"no" << endl;
  }
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
ll n;
int main(){
    scanf("%d",&n);
    cout<<((n)*1ll*(n+1))/2<<endl;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def min(a,b)
    return a>b ? b : a
end

def max(a,b)
    return a>b ? a : b
end
W,H,N=get_i
y0=0
x0=0
ym=H
xm=W
N.times do
    x,y,a=get_i
    case a
    when 1 then
        x0=max(x,x0)
    when 2 then
        xm=min(x,xm)
    when 3 then
        y0=max(y,y0)
    when 4 then
        ym=min(y,ym)
    end
end
ans=(ym-y0)*(xm-x0)
if ym-y0<=0 or xm-x0<=0
    puts 0
else
    puts ans
end

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

const int D = 365, T = 26;

vector<int> c(T);
vector<vector<int>> s(D, vector<int>(T));
vector<vector<int>> pena(T, vector<int>(D + 2));

class Timer {
private:
    chrono::high_resolution_clock::time_point start;
public:
    Timer() {
        reset();
    }
    void reset() {
        start = chrono::high_resolution_clock::now();
    }
    chrono::milliseconds::rep elapsed() {
        auto end = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(end - start).count();
    }
} timer;

auto current = timer.elapsed();

struct State {
    vector<int> ct;
    vector<vector<int>> h;
    State() : ct(D), h(T) {
        for(int t = 0; t < T; ++t) {
            h[t].push_back(-1);
            h[t].push_back(D);
        }
    }
    void add(int d, int i) {
        auto it = lower_bound(h[i].begin(), h[i].end(), d);
        h[i].insert(it, d);
        ct[d] = i;
    }
    void rmv(int d) {
        h[ct[d]].erase(remove(h[ct[d]].begin(), h[ct[d]].end(), d), h[ct[d]].end());
    }
    int calc_each(int i) {
        int res = 0;
        for(auto &d : h[i]) {
            if(d == -1 || d == D) continue;
            res += s[d][i];
        }
        for(int d = 0; d < h[i].size() - 1; ++d) {
            res -= pena[i][h[i][d + 1] - h[i][d]];
        }
        return res;
    }
    int calc() {
        int res = 0;
        for(int t = 0; t < T; ++t) res += calc_each(t);
        return res;
    }
    int calc_diff(int d, int bf, int af) {
        int res = s[d][af] - s[d][bf];
        {
            auto it = lower_bound(h[bf].begin(), h[bf].end(), d);
            int r = *next(it) - d, l = d - *prev(it);
            res -= pena[bf][l + r] - pena[bf][r] - pena[bf][l];
        }
        {
            auto it = lower_bound(h[af].begin(), h[af].end(), d);
            int r = *it - d, l = d - *prev(it);
            res += pena[af][l + r] - pena[af][r] - pena[af][l];
        }
        return res;
    }
    void output() {
        for(int i = 0; i < D; ++i) cout << ct[i] + 1 << '\n';
    }
    void update() {
        int d = rand() % D, bf = ct[d], af = rand() % T;
        if(bf == af) return;
        if(calc_diff(d, bf, af) > 0) {
            rmv(d);
            add(d, af);
        }
    }
    void exe() {
        update();
    }
};

State state;

void input() {
    int _; cin >> _;
    for(int i = 0; i < T; ++i) cin >> c[i];
    for(int i = 0; i < D; ++i) {
        for(int j = 0; j < T; ++j) cin >> s[i][j];
    }
}

void init() {
    for(int i = 0; i < D; ++i) {
        state.ct[i] = max_element(s[i].begin(), s[i].end()) - s[i].begin();
        state.add(i, state.ct[i]);
    }
    for(int t = 0; t < T; ++t) {
        for(int i = 2; i <= D + 1; ++i) {
            pena[t][i] = pena[t][i - 1] + c[t] * (i - 1);
        }
    }
}

int main() {
    input();
    init();
    cerr << state.calc() << '\n';
    while(current < 1900) {
        current = timer.elapsed();
        state.exe();
    }
    state.output();
    cerr << state.calc() << '\n';
    return 0;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] d = new int[N];
        for (int i = 0; i < N; i++) {
            d[i] = sc.nextInt();
        }
        sc.close();

        System.out.println(HeightLimit(N, K, d));
    }
    public static int HeightLimit(int N, int K, int[] d) {
        if (N <= 0) {
            return 0;
        }
        if (d[N-1] >= K) {
            return 1 + HeightLimit(N-1, K, d);
        }
        return HeightLimit(N-1, K, d);
    }
}


Measured memory_bytes: 52944
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));


int main(){
    string s;
    cin >> s;
    int N;
    cin >> N;
    vector<string> A;
    for(int i = 0; i < N; i++){
        string query;
        cin >> query;
        if(query == "print"){
            int a, b;
            cin >> a >> b;
            A.push_back(s.substr(a, b - a + 1));
        }else if(query == "reverse"){
            int a, b;
            cin >> a >> b;
            string t = s.substr(a, b - a + 1);
            reverse(all(t));
            s.replace(a, b - a + 1, t);
        }else{
            int a, b;
            cin >> a >> b;
            string p;
            cin >> p;
            s.replace(a, b - a + 1, p);
        }
    }
    for(string t : A) cout << t << endl;
}


Measured memory_bytes: 3228