akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv, std.algorithm;

void main() {
	int N = readln().chomp().to!(int);
	int [] t = readln().chomp().split().to!(int[]);
	int [] v = readln().chomp().split().to!(int[]);
	v ~= 0;

	long [210][2] dp;
	foreach(int i; 0..210) dp[0][i] = dp[1][i] = 0;
	dp[0][0] = 1;
	foreach(int i; 0..N) {t[i] *= 2; v[i] *= 2;}
	foreach(int i; 1..N) {
		t[i] += t[i-1];
	}
	int s = t[N-1];
	int k = 0;
	foreach(int i; 1..(s+1)) {
		while(t[k] < i) k++;
		foreach(int j; 0..210) dp[i&1][j] = 0;

		int vv = v[k];
		if(t[k] == i) vv = min(vv, v[k+1]);
		foreach(int j; 0..(vv+1)) {
			if(dp[1^i&1][j] != 0)
				dp[i&1][j] = max(dp[i&1][j], dp[1^i&1][j] + j*2);

			if(dp[1^i&1][j+1] != 0)
				dp[i&1][j] = max(dp[i&1][j], dp[1^i&1][j+1] + j*2+1);

			if(j-1>=0 && dp[1^i&1][j-1] != 0)
				dp[i&1][j] = max(dp[i&1][j], dp[1^i&1][j-1] + j*2-1);
		}
	}
	writefln("%f", (dp[s&1][0]-1) / 8.0);
}



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

using namespace std;

int N;
char sir[200009];

bool ok (int K)
{
    int df = 0;
    for (int i=N - K + 2; i<=K; i++)
        df += (sir[i] != sir[i - 1]);
    return (df == 0);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s", sir + 1), N = strlen (sir + 1);
int p = 1, u = N, mij, ras = -1;
while (p <= u)
{
    mij = (p + u) >> 1;
    if (ok (mij)) ras = mij, p = mij + 1;
    else u = mij - 1;
}
printf ("%d\n", ras);
return 0;
}


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

ans = [0] * n
a.reverse()
for i in range(n):
  if i % 2 == 0:
    ans[i//2] = a[i]
  else:
    ans[(n - 1) - (i//2)] = a[i]

print(*ans)
  

Measured memory_bytes: 26176
#include<iostream>
#include<cstdio>
using namespace std;
int t1[100500],t2[100500],a[100500],b[100500];
int min(int a,int b){
	return a<b?a:b;
}
int main(){
	int i,j,k,m,n,m1=-1,m2=-1,z1=0,z2=0,m3=-1,m4=-1,z3=0,z4=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i+=2){
		t1[a[i]]++;
		if(t1[a[i]]>=z1){
			if(a[i]!=m1) z2=z1,m2=m1;
			z1=t1[a[i]];m1=a[i];
		}
		else if(t1[a[i]]>z2){
			z2=t1[a[i]];m2=a[i];
		}
	}
	for(i=2;i<=n;i+=2){
		t2[a[i]]++;
		if(t2[a[i]]>=z3){
			if(a[i]!=m3) z4=z3,m4=m3;
			z3=t2[a[i]];m3=a[i];
		}
		else if(t2[a[i]]>z4){
			z4=t2[a[i]];m4=a[i];
		}
	}
//	cout<<m1<<" "<<m2<<" "<<m3<<" "<<m4<<" "<<z1<<" "<<z2<<" "<<z3<<" "<<z4<<endl;
	if(m1!=m3){
		printf("%d\n",n-z1-z3);
	}
	else{
		printf("%d\n",min(n-z2-z3,n-z1-z4));
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  int A, B, ans;
  cin >> A >> B;
  
  for (int i = A; i <= B; i++) {
    string strNum = to_string(i);
    rep(j, strNum.size()/2) {
      if(strNum[j] == strNum[strNum.size()-1-j]) {
        if (j == strNum.size()/2-1) ans++;
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double N;
ll M;
string s;
vector<ll > input1;  
vector<vector <ll > > input2;

int main(){
    
    int n = 0;
    cin >> n;
    vector<pair <int, int > > result;
    int s, t; 
    for(int i = 0; i < n; i++){
        cin >> s >> t;
        result.push_back(make_pair(t, s));
    }

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

    int temp = result[0].first;
    int number = result[0].second;
    for(int i = 0; i < n; i++){
        if(temp == result[i].first){
            number = result[i].second;
        }else{
            break;
        }
    }

    cout << number <<  " " << result[0].first << endl;



} 


Measured memory_bytes: 3164
from collections import deque

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

c = [[10**9 for _ in range(W)] for _ in range(H)]
que = deque()

for i in range(H):
  for j in range(W):
    if maze[i][j] == "#":
      c[i][j] = 0
      que.append([i, j])

dxy = [[-1, 0], [1, 0], [0, -1], [0, 1]]      
      
while len(que) != 0:
  p = que.popleft()
  for i in dxy:
    nx = p[0] + i[0]
    ny = p[1] + i[1]
    if 0 <= nx < H and 0 <= ny < W and c[nx][ny] == 10**9 and maze[nx][ny] ==".":
      maze[nx][ny] = "#"
      c[nx][ny] = c[p[0]][p[1]] + 1
      que.append([nx, ny])
max = 0
for i in range(H):
  for j in range(W):
    if max < c[i][j]:
      max = c[i][j]
print(max)

Measured memory_bytes: 177628
import java.util.Scanner;

class Main{
  static void trace(int[] a){
    int i;
    for(i = 0; i < a.length - 1; i++)
      System.out.print(a[i] + " ");
    System.out.println(a[i]);
  }

  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int a[] = new int[n];
    for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt();

    int count = 0;
    for(int i = 0; i < a.length; i++){
      int m = i;
      for(int j = i; j < a.length; j++){
        if(a[j] < a[m])
          m = j;
        }
      if(m != i){
        int tmp = a[i];
        a[i] = a[m];
        a[m] = tmp;
        count++;
      }
    }

    trace(a);
    System.out.println(count);

  }
}

Measured memory_bytes: 26416
#include<iostream>
#include<cmath>
#include<utility>
#include<vector>
#include<map>
   
using namespace std;
   
typedef pair<double,double> PBB;
typedef vector<PBB > VPBB;
typedef multimap<double,int> MDI;
typedef MDI::iterator MDII;
   
#define PUSH push_back
#define MDIVT MDI::value_type
#define PI 3.14159265359
#define INF 10000000000
#define NMAX 100
   
   
int main(){
   
    int n;
    int main,st;
    int num;
    double x,y;
	double sita;
    char gav;
	double bef;
    VPBB pin;
    MDI point;
    MDII ite;
 
    while(1){
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>x>>gav>>y;
			pin.PUSH(PBB(x,y));
		}
 
		main=0;
		for(int i=1;i<n;i++){
			if(pin[main].second<pin[i].second) main=i;
			else if(pin[main].second==pin[i].second&&pin[main].first<pin[i].first) main=i;
		}
		st=main;
		num=0;
		bef=-1*PI;
		while(1){
			///cout<<num<<"\\\\"<<main<<endl;
			for(int i=0;i<n;i++){
				if(pin[i].second!=pin[main].second) sita=atan2(pin[i].second-pin[main].second,pin[i].first-pin[main].first);
				else sita=-1*PI;
				if(i!=main&&sita>bef){
					///cout<<sita<<"---"<<i<<endl;
					point.insert(MDIVT(sita,i));
				}
			}
			ite=point.begin();
			bef=(*ite).first;
			main=(*ite).second;
			point.clear();
			num++;
			if(main==st) break;
		}
		cout<<n-num<<endl;
		pin.clear();
	}
}

Measured memory_bytes: 1308
using System;
using System.Collections.Generic;
using System.Linq;

namespace P0018_SortingFiveNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            string readLine = Console.ReadLine(); 
                        
            var sp = readLine.Split(' ').ToList<string>();

            var spl = new List<long>();

            foreach (var l in sp) 
            {
                spl.Add(long.Parse(l));
            }


            spl.Sort();
            spl.Reverse();

            var sp2 = new List<string>();

            foreach (var l in spl)
            {
                sp2.Add(l.ToString());
            }

            Console.WriteLine(string.Join(" ",sp2.ToArray()));

        }
    }
}

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

int main() {
 int h1,m1,h2,m2,k;
 cin>>h1>>m1>>h2>>m2>>k;
 int h=h2-h1;
 int m=m2-m1;
 int total=(h*60)+m;
 int left=total-k;
 cout<<left;

}


Measured memory_bytes: 3624
from bisect import bisect_left as lower_bound
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

def main():
    N = I()
    XL = [None] * N
    ans = 0

    for i in range(N):
        X, L_ = MI()
        XL[i] = (X, L_, i)

    arr = [None] * N
    for i in range(N):
        arr[i] = (XL[i][0] - XL[i][1], XL[i][0] + XL[i][1])

    arr = sorted(arr, key=lambda a: a[1])
    maxv = -(10 ** 9)
    cur = maxv
    for i in range(N):
        if cur <= arr[i][0]:
            cur = arr[i][1]
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37068
n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)

ansa=[0]*8
ansb=0
for i in range(n):
  if a[i]<400:
    ansa[0]=1
  elif a[i]<800:
    ansa[1]=1
  elif a[i]<1200:
    ansa[2]=1
  elif a[i]<1600:
    ansa[3]=1
  elif a[i]<2000:
    ansa[4]=1
  elif a[i]<2400:
    ansa[5]=1
  elif a[i]<2800:
    ansa[6]=1
  elif a[i]<3200:
    ansa[7]=1
  else:
    ansb+=1
    
if sum(ansa)==0:
  print(1,ansb)
else:  
  print(sum(ansa),sum(ansa)+ansb)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using AnsType = long long int;
const AnsType MOD = 1000000007;

const int MAXN = 100010;
AnsType fact[MAXN+10], finv[MAXN+10];

AnsType mod_pow(AnsType x, AnsType k) {
    AnsType res = 1;
    for(; k>0; k>>=1) {
        if(k & 1) (res *= x) %= MOD;
        (x *= x) %= MOD;
    }
    return x;
}

bool is_leaf[MAXN];
AnsType dp[MAXN], N, K;
vector<int> G[MAXN];

void init_fact() {
    fact[0] = 1;
    for(int i=1; i<MAXN; i++) fact[i] = (fact[i-1] * i) % MOD;
    finv[MAXN-1] = mod_pow(fact[MAXN-1], MOD-2);
    for(int i=MAXN-1; i>0; i--) {
        finv[i-1] = (finv[i] * i) % MOD;
    }
}

void solve(int cur, int par=-1, int depth=1) {
    int m = max(0LL, K - min(depth, 2));
    is_leaf[cur] = true;
    for(auto to : G[cur]) {
        if(to == par) continue;
        is_leaf[cur] = false;
        dp[to] = m--;
        solve(to, cur, depth + 1);
    }
}

int main() {
    cin >> N >> K;
    for(int i=0; i<N-1; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    dp[0] = K;
    solve(0);

    AnsType ans = 1;
    for(int i=0; i<N; i++) {
        (ans *= dp[i]) %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define debug(...) 42
const double PI = std::atan(1.0)*4;
template <typename T> struct Point {
  using TCoord = T;

  Point() : Point(0, 0) {}
  Point(const T& x, const T& y) : x(x), y(y) {}

  Point<T>& operator+=(const Point<T>& rhs) { *this = this->operator+(rhs); return *this; }
  Point<T>& operator-=(const Point<T>& rhs) { *this = this->operator-(rhs); return *this; }

  bool operator<(const Point<T> &rhs) const {
    return (this->x < rhs.x || (this->x == rhs.x && this->y < rhs.y));
  }
  bool operator==(const Point<T> &rhs) const {
    return this->x == rhs.x && this->y == rhs.y;
  }

  Point<T> operator-(const Point<T> &rhs) const { return {x - rhs.x, y - rhs.y}; }
  Point<T> operator+(const Point<T> &rhs) const { return {x + rhs.x, y + rhs.y}; }
  Point<T> DotProduct(const Point<T> &rhs) const { return {x * rhs.x + y * rhs.y}; }
  Point<T> Rotate(double angle) {
    return {x * cos(angle) - y * sin(angle), x * sin(angle) + y * cos(angle)};
  }
  double Distance(const Point<T> &rhs) {
    return sqrt((x - rhs.x) * (x - rhs.x) + (y - rhs.y) * (y - rhs.y));
  }
  double PolarAngle() const {
    double alpha = atan2(y, x);
    if (alpha < 0) alpha += 2 * PI;
    return alpha;
  }

  T x, y;
};

using P = Point<double>;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  auto p1 = P(0, a).Rotate(-2 * PI * (h / 12 + m / 60 / 12));
  auto p2 = P(0, b).Rotate(-2 * PI * m / 60);
  debug(p1.x, p1.y);
  debug(p2.x, p2.y);
  cout << fixed << setprecision(10) << p1.Distance(p2);
  return 0;
}

Measured memory_bytes: 4112
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

def main():
    n, a, b = map(int, input().split())
    if not (n + a - 1) // a <= b <= n - a + 1:
        print(-1)
        exit()
    ans = []
    ans.append(list(range(1, a + 1)))
    # print(ans)
    b -= 1
    st = a + 1
    while b:
        if b == 1:
            ans.append(list(range(st, n + 1)))
            break
        elif n - st + 1 - a >= b - 1:
            ans.append(list(range(st, st + a)))
            st += a
            b -= 1
        else:
            ans.append([st])
            st += 1
            b -= 1
    x = []
    for ak in ans[::-1]:
        x += ak
    print(*x)

main()


Measured memory_bytes: 40188
#include "bits/stdc++.h"
using namespace std;
#define LL long long
 
int main()
{
  string s;
  cin>>s;
  set<string>st;
  for(int i=0;i<s.size();i+=2){
      string ss=s.substr(i,2);
      st.insert(ss);
  }
  
  string f;
  for(auto x:st) f=x;
  if(st.size()==1 and f=="hi") cout<<"Yes"<<"\n";
  else cout<<"No"<<"\n";
    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 PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	char x, y;
	cin >> x >> y;
	if (x > y)
		cout << '>' << endl;
	else if (x < y)
		cout << '<' << endl;
	else
		cout << '=' << endl;
} 

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
typedef pair<int, pair<int, int> > PP;

bool comp(const PP& a, const PP& b){ return a.first > b.first;}

int main(){
  int n, m, a, h, p, q;
  while(scanf("%d%d%d", &n, &m, &a) && n+m+a){
    vector<PP> line(m);
    rep(i, m){
      scanf("%d%d%d", &h, &p, &q);
      line[i] = make_pair(h, make_pair(p, q));
    }

    sort(line.begin(), line.end(), comp);
    int res = a;
    //    rep(i, m) printf("%d %d %d\n", line[i].first, line[i].second.first, line[i].second.second);
    rep(i, m){
      if(line[i].second.first == res) res = line[i].second.second;
      else if(line[i].second.second == res) res = line[i].second.first;
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1204
import math
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
x = LI()
sort_x = sorted(x)
left = sort_x[math.floor(n/2-0.1)]
right= sort_x[math.floor(n/2+0.1)]
for num in x:
    if num < (left+right)/2:
        print(right)
    else:
        print(left)


Measured memory_bytes: 25220
v,e=map(int,raw_input().split())
dis=[[float("inf")]*v for _ in xrange(v)]
for i in xrange(e):
    s,t,d=map(int,raw_input().split())
    dis[s][t]=d
dp=[[float('inf')]*(v) for _ in xrange(1<<v)]
dp[1][0]=0
for i in xrange(1<<v):
    for j in xrange(v):
        if dp[i][j]==float('inf'):continue
        for k in xrange(v):
            if (i>>k)%2==1:continue
            nexti=i|1<<k
            nextdis=dp[i][j]+dis[j][k]
            dp[nexti][k]=min(dp[nexti][k],nextdis)
ans=float('inf')
for i in xrange(v):
    if dp[(1<<v)-1][i]==float('inf'):continue
    ans=min(ans,dp[(1<<v)-1][i]+dis[i][0])
if ans==float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 16328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <array>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    ll Ai, Bi;
    priority_queue<array<ll,3>> C;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> Ai >> Bi;
        C.push(array<ll,3>{Ai+Bi,Ai,Bi});
    }
    ll sum = 0;
    for(int i=0;i<N;i++){
        if(i%2==0) sum += C.top()[1];
        else       sum -= C.top()[2];
        C.pop();
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

ll dp[4200][4200];
int main() {
    ll n; cin >> n;
    vll x1(n), x2(n), y1(n), y2(n);
    vll wx, wy, vx, vy;

    rep(i, n) {
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        wx.push_back(x1[i]);
        wx.push_back(x2[i]);
        wy.push_back(y1[i]);
        wy.push_back(y2[i]);
    }
    sort(wx.begin(), wx.end());
    sort(wy.begin(), wy.end());

    rep(i, wx.size()) {
        if(i == 0 || wx[i] != wx[i-1]) vx.push_back(wx[i]);
        if(i == 0 || wy[i] != wy[i-1]) vy.push_back(wy[i]);
    }

    rep(i, n) {
        ll pos1 = lower_bound(vx.begin(), vx.end(), x1[i]) - vx.begin();
        ll pos3 = lower_bound(vx.begin(), vx.end(), x2[i]) - vx.begin();
        ll pos2 = lower_bound(vy.begin(), vy.end(), y1[i]) - vy.begin();
        ll pos4 = lower_bound(vy.begin(), vy.end(), y2[i]) - vy.begin();
        dp[pos1][pos2]++, dp[pos1][pos4]--, dp[pos3][pos2]--, dp[pos3][pos4]++;
    }

    for(ll i = 0; i < 4100; i++) {
        for(ll j = 1; j < 4100; j++) dp[i][j] += dp[i][j-1];
    }
    for(ll i = 1; i < 4100; i++) {
        for(ll j = 0; j < 4100; j++) dp[i][j] += dp[i-1][j];
    }

    ll ans = 0;
    rep(i, vx.size()) rep(j, vy.size()) {
        if(dp[i][j] >= 1) ans += (vx[i+1] - vx[i]) * (vy[j+1] - vy[j]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 137800
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define fs first
#define sc second
#define mpr make_pair
#define iter iterator
#define all(X) X.begin(),X.end()
#define sau(X) sort(all(X)),X.resize(unique(all(X))-X.begin())
#define exist(X,ele) binary_search(all(X),ele)
#define y0 I_love_Ryougi_Shiki_0
#define y1 I_love_Ryougi_Shiki_1
 
template<typename T1,typename T2>
ostream& operator << (ostream& out,const pair<T1,T2>& X)
{
	out<<"{"<<X.fs<<","<<X.sc<<"}";
	return out;
}
 
template<typename T>
ostream& operator << (ostream& out,const vector<T>& X)
{
	for(auto i:X) out<<i<<" ";
	return out;
}
 
inline void cmin(int& x,int y)
{
	x=min(x,y);
}
 
inline void cmax(int& x,int y)
{
	x=max(x,y);
}
 
const int inf=5000000000000000ll;
 
int N,M,V,P;
vector<int> a;
 
bool chk(int id)
{
//	cout<<"Checking "<<id<<endl;
	if(a[id]+M<a[N-P]) return false;
	int nv=V-(P-1)-id-1; // cout<<"  nv="<<nv<<endl;
	if(nv<=0) return true;
	// 0..id-1 | id(+M) | ? | N-P+1..N-1
	int canv=0;
	for(int i=id+1;i<=N-P;i++)
	{
//		cout<<"  i="<<i<<" Canv+="<<min(M,a[id]+M-a[i])<<endl;
		canv+=a[id]+M-a[i];
	}
	return (canv>=nv*M);
}
 
main()
{
	ios::sync_with_stdio(false);
	
	cin>>N>>M>>V>>P;
	a.resize(N);
	for(int i=0;i<N;i++)
	{
		cin>>a[i];
	}
	sort(all(a)); // cout<<a<<endl;
	int L=0,R=N-1,mid;
	while(R-L>10)
	{
		mid=(L+R)/2;
		if(chk(mid)) R=mid;
		else L=mid;
	}
	for(int i=L;i<=R;i++)
	{
		if(chk(i))
		{
			cout<<N-i<<endl;
			return 0;
		}
	}
	cout<<"0"<<endl;
	return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 1152
# 入力
N, W = map(int, input().split())

weight_value = []

for i in range(N):
    value, weight = map(int, input().split())
    weight_value.append([value, weight])
 
# dpの初期値（i + 1に入れていくので、ひとつ多く準備する）
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]

# 動的計画法で最大値を求める
# 選ぶ個数のループ
for i in range(N):
    value = weight_value[i][0]
    weight = weight_value[i][1]
    
    # 各重さのループ
    for j in range(W + 1):
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        
        next_weight = j + weight
        next_value = dp[i][j] + value
        
        if (next_weight <= W and next_value > dp[i+1][next_weight]):
            dp[i+1][next_weight] = next_value

            
# 結果出力
print(dp[N][W])


Measured memory_bytes: 25976
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define All(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr long long MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    unsigned long long N;cin >> N;
    unsigned long long A[N],keta[60] = {};
    REP(i,N){
        cin >> A[i];
        REP(j,60LL){
            if(bitset<60>(A[i])[j] == 1){
                keta[j]++;
            }
        }
    }
    unsigned long long ans = 0;
    REP(i,60LL){
        unsigned long long a = (1LL << i);a %= MOD;
        unsigned long long b = keta[i] * (N - keta[i]);b %= MOD;
        ans += (a*b)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
/*
ID: cs14bte1
TASK: holstein
LANG: C++11
 */
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include<climits>
#include<map>
#include<set>
#include<utility>
#include<iterator>
#include<cstring>
#include<cstdio>
#include<unordered_map>
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define ff first
#define ss second
//#define scd static_cast<double>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int, int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using pill=pair<int,ll>;
using vvi=vector<vi>;

ll gcd(ll a, ll b)
{	
	ll t;
	while((t=a%b)!=0) {
		a=b;
		b=t;
	}
	return b;
}

ll fast_exp(ll base, ll n, ll m)
{
	if(n==0)	return 1;
	ll t=fast_exp(base,n/2,m);
	if(n%2==0)	return (t*t)%m;
	else	return (((t*t)%m)*base)%m;
}

bool is_set(int i, ll mask)
{
	return (mask>>i)&1;
}

int count_bits(ll mask)
{
	int ans=0;
	for(int i=0;i<64;++i)
		if (is_set(i,mask)) ++ans;
	return ans;	
}

int first_bit(ll mask)
{	
	int i=0;
	while(i<64) 
		if(is_set(i++, mask)) return i-1;
	return -1;
}
int const N=100000;
ll a[3*N];

bool foo(int  i, int j)
{
    return a[i] < a[j];
}

bool bar(int i, int j)
{
    return a[i] > a[j];
}

int main()
{
	ios::sync_with_stdio(false);
    int n;cin>>n;
    priority_queue<int,vi,bool(*)(int, int)> q1(bar);
    priority_queue<int,vi,bool(*)(int, int)> q2(foo);
//    set<int, bool(*)(int,int)> s(foo);
    bool avail[3*n];
    memset(avail, false, sizeof avail);
    ll s1=0, s2=0;
    for (int i=0; i<3*n; ++i)  {
        cin>>a[i];
        if (i<n) {
            q1.push(i), s1+=a[i];
        }
        else {
            if (q2.size() < n)
                q2.push(i), s2+=a[i];
            else if (a[i] < a[q2.top()])
                s2 -= a[q2.top()], s2 += a[i], avail[q2.top()]=true, q2.pop(), q2.push(i);
            else avail[i]=true;//, q3.push(a[i]);
        }
    }
    vi v;
    for (int i=n; i<3*n; ++i)
        if (avail[i]) v.pb(i);
    sort(v.begin(), v.end(), foo);
    int p=0;
    ll ans=s1-s2;
    for (int i=n; i<2*n; ++i) {
        //<<i<<endl;
        if (a[i]>a[q1.top()]) {
            s1 -= a[q1.top()];
            s1 += a[i];
            q1.pop();
            q1.push(i);
        }
        //<<"l1"<<endl;
        if (!avail[i]) {
            s2 -= a[i];
            while (p<v.size() and !avail[v[p]]) p++;
            s2 += a[v[p]];
            avail[v[p]]=false;
        }
        //<<"l2"<<endl;
        avail[i]=false;
        ans = max(ans, s1-s2);
        //<<"done"<<"\n";
    }
    cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 4472
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define for1(i, a, b) for(i = a; i <= b; ++i)
#define for0(i, a, b) for(i = a; i < b; ++i)
#define forw1(i, a, b) for(i = a; i >= b; --i)
#define forw0(i, a, b) for(i = a - 1; i >= b; --i)
#define fora(v, a) for(auto v : a)
#define bp __builtin_popcount
#define bpll __builtin_popcountll

using namespace std;
using cd = complex<double>;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<cd> vcd;
typedef vector<ii> vii;
typedef vector<vector<int> > vvi;

const int modd1 = 1e9 + 7, modd2 = 998244353, maxn = 1e5 + 10, K = 26, inf = 1e9, infll = 1e18;
const double pi = acos(-1);
int n, m, k;
int nhan[maxn], chia[maxn], pr[3010], s, ans;
map<int, int> mpp;

void solve(){
	int i, j, l, r;
	cin >> n;
	for1(i, 1, n){
		cin >> s;
		for(j = 2; j * j * j <= s; ++j){
			while(s % (j * j * j) == 0){
				s /= (j * j * j);
			}
		}
		mpp[s]++; //cout << s << ' ';
		chia[i] = s; int t = 1; 
		for(j = 2; j * j * j <= s; ++j){
			if(s % j == 0){
				t *= j;
				if(s % (j * j) != 0){
					t *= j;
				}
				while(s % j == 0){
					s /= j;
				}
			}
		}
		int tmp = sqrt(s);
		if(tmp * tmp == s){
			t *= tmp;
		}
		else{
			t *= s * s;
		}
		nhan[i] = t;
	}
	if(mpp[1]){
		ans++; mpp[1] = 0;
	}
//	for1(i, 1, n){
//		cout << a[i] << ' ' << b[i] << '\n';
//	}
	for1(i, 1, n){
		ans += max(mpp[chia[i]], mpp[nhan[i]]);
		mpp[chia[i]] = 0; mpp[nhan[i]] = 0;
	}
	cout << ans;
}

signed main() {
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}


Measured memory_bytes: 17764
import sys
input = sys.stdin.readline
Max = 2000
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())

h,w = m()

aa = [[] for i in range(h)]
aaa = []
ma = 0
for i in range(h):
    k = list(input())
    for j in range(w):
        if k[j] == "#":
            aa[i].append(0)
            aaa.append([i,j])
        else:
            aa[i].append(Max)
kk = []
while True:
    if len(aaa) == 0:
        break
    for i in range(len(aaa)):
        c,v = aaa[i]
        if not c == 0:
            if aa[c-1][v] > aa[c][v]+1:
                aa[c-1][v] = aa[c][v]+1
                kk.append([c-1,v])
                ma = max(ma,aa[c-1][v])
        if not c == h-1:
            if aa[c+1][v] > aa[c][v]+1:
                aa[c+1][v] = aa[c][v]+1
                kk.append([c+1,v])
                ma = max(ma,aa[c+1][v])
        if not v == 0:
            if aa[c][v-1] > aa[c][v]+1:
                aa[c][v-1] = aa[c][v]+1
                kk.append([c,v-1])
                ma = max(ma,aa[c][v-1])
        if not v == w-1:
            if aa[c][v+1] > aa[c][v]+1:
                aa[c][v+1] = aa[c][v]+1
                kk.append([c,v+1])
                ma = max(ma,aa[c][v+1])
    aaa = kk
    kk = []
print(ma)
        


Measured memory_bytes: 144256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n;cin>>n;
    int a,b;cin>>a>>b;
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];
    int c1=0,c2=0,c3=0;
    for(int i=0;i<n;i++){
        if(p[i]<=a) c1++;
        else if(a<p[i]&&p[i]<=b) c2++;
        else c3++;
    }
    cout<<min(min(c1,c2),c3)<<endl;
    return 0;
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n);
    for(int i=0; i<n;i++){
        cin  >> h.at(i);
    }
    sort(h.begin(),h.end());
    ll ans=0;
    for(int i=0; i<n-k; i++){
        ans+=h.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
/*input
ABC
*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<long,long>
#define vi          vector<long long>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mod         998244353
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repi(i,a,b) for(ll i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define fIO         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define tr(it, a)   for(auto it = a.begin(); it != a.end(); it++)
#define clr(x)      memset(x, 0, sizeof(x))
#define debug(x)      cerr << #x << "=" << x << endl
#define debug2(x, y)  cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define TIME        cerr << "\nTime elapsed: "<<1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; 
//#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update>;

ll sub(ll a, ll b){return (a-b+hell)%hell;}
ll add(ll a, ll b){return (a+b)%hell;}
ll mul(ll a, ll b){return (a*b)%hell;}
/*vector<ll>adj[100005];
bool vis[100005];
ll siz,edges;
void dfs(ll i)
{
    vis[i]=1;
    //siz++;
    for(ll j=0;j<adj[i].size();j++)
    {        
        edges++;
        if(!vis[adj[i][j]])
            dfs(adj[i][j]);
    }
}
ll mpow(ll base, ll exp) {
  base %= hell;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % hell;
    base = ((ll)base * base) % hell;
    exp >>= 1;
  }
  return result;
}*/
int main()
{
fIO;
ll n,sum=0,t=1,m,ans;

//cin >> t;
while(t--){
  string s;
  cin>>s;
  if(s=="ABC")cout<<"ARC";
  else cout<<"ABC";
    













}
TIME;
    
}

Measured memory_bytes: 3844
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
int main(){
  int W,a,b;
  scanf("%d %d %d",&W,&a,&b);
  if(a<=b+W&&b<=a+W) printf("0\n");
  else if(a+W<b) printf("%d\n",b-(a+W));
  else if(b+W<a) printf("%d\n",a-(b+W));
  return 0;
}


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

using namespace std;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  string in;
  cin >> in;
  int a = 0, b = 0;
  for(int i = 0; i < in.size(); ++i){
    if(in[i] == 'C')  a = 1;
    if(in[i] == 'F')  b += a;
  }

  if(a*b > 0) cout << "Yes\n";
  else  cout << "No\n";


  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <vector>
#include <time.h>

using namespace std;

constexpr int D = 365;
constexpr int LIMIT = 1950;

int score(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& t) {
	int S = 0;

	vector<int> last(26, 0);
	for (size_t i = 0; i < t.size(); i++) {
		S += s[i][t[i]-1];

		last[t[i] - 1] = i+1;
		for (size_t j = 0; j < 26; j++) {
			S -= c[j] * (i+1 - last[j]);
		}
	}

	return S;
}

int score_alpha(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& t, const int& k) {
	int S = 0;

	vector<int> last(26, 0);
	for (size_t i = 0; i < t.size(); i++) {
		S += s[i][t[i] - 1];

		last[t[i] - 1] = i + 1;
		for (size_t j = 0; j < 26; j++) {
			S -= c[j] * (i + 1 - last[j]);
		}
	}

	for (size_t i = t.size(); i < min(int(t.size() + k), D); i++) {
		for (size_t j = 0; j < 26; j++) {
			S -= c[j] * (i + 1 - last[j]);
		}
	}
	return S;
}

vector<int> greedy(const vector<int>& c, const vector<vector<int>>& s, const int& k) {
	vector<int> t;
	t.reserve(D);

	for (size_t i = 0; i < D; i++) {
		int mscore = INT32_MIN, idx = 1;
		
		for (size_t j = 0; j < 26; j++) {
			t.push_back(j+1);
			int dscore = score(c, s, t);
			dscore = score_alpha(c, s, t, k);

			if (dscore > mscore) {
				mscore = dscore;
				idx = j+1;
			}
			t.pop_back();
		}

		t.push_back(idx);
	}

	return t;
}

vector<int> local(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& init) {
	vector<int> t(init);
	int mscore = score(c, s, t);

	while ((int)clock() < LIMIT) {	
		int ri = rand() % D;
		int rc = rand() % 26;

		vector<int> nt(t);
		nt[ri] = rc + 1;
		int nscore = score(c, s, nt);

		if (mscore < nscore) {
			mscore = nscore;
			copy(nt.begin(), nt.end(), t.begin());
		}
	}
	return t;
}

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

	int ig;
	cin >> ig;

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	
	for (int i = 0; i < 26; i++) {
		cin >> c[i];
		//c[i] = rand() % 100;
	}

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];
			//s[i][j] = rand() % 20000;
		}
	}

	vector<int> bt = greedy(c, s, 0);
	int sc = score(c, s, bt);

	for (int i = 1; i < 10; i++) {
		auto t = greedy(c, s, i);
		auto tsc = score(c, s, t);
		if (sc < tsc) {
			sc = tsc;
			bt = t;
		}
	}
	
	bt = local(c, s, bt);

	for (size_t i = 0; i < D; i++) cout << bt[i] << endl;
	
	return 0;
}

Measured memory_bytes: 3740
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = float("inf")

MOD = 1000000007
class Combination(object):
    def __init__(self, N):
        self.fac = [0] * (N + 1)
        self.inv = [0] * (N + 1)
        self.finv = [0] * (N + 1)
        self.fac[0] = 1
        self.finv[0] = 1
        if N > 0:
            self.fac[1] = 1
            self.inv[1] = 1
            self.finv[1] = 1
 
        # 前計算
        for i in range(2, N + 1):
            self.fac[i] = self.fac[i - 1] * i % MOD
            self.inv[i] = self.inv[MOD % i] * (MOD - (MOD // i)) % MOD
            self.finv[i] = self.finv[i - 1] * self.inv[i] % MOD
 
    def com(self, N, k):
        return (self.fac[N] * self.finv[k] * self.finv[N - k]) % MOD


# 処理内容
def main():
    S = int(input())
    Com = Combination(S)
    
    ans = 0
    i = 1
    S -= 3
    while S >= 0:
        ans += Com.com(S+i-1, i-1)
        ans %= MOD
        S -= 3
        i += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 72832
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	string s;
 	cin>>s;
 	deque<char>q;
 	ll par=0;
 	for(char x:s)
 	{
 		q.push_back(x);
 	}
 	ll Q;
 	cin>>Q;
 	while(Q--)
 	{
 		ll t;
 		cin>>t;
 		if(t==1)
 		{
 			par++;
 			par%=2;
 		}
 		else
 		{
 			ll f;
 			cin>>f;
 			char c;
 			cin>>c;
 			if(f==1)
 			{
 				if(par==0)
 				{
 					q.push_front(c);
 				}
 				else
 				{
 					q.push_back(c);
 				}
 			}
 			else
 			{
 				if(par==0)
 				{
 					q.push_back(c);
 				}
 				else
 				{
 					q.push_front(c);
 				}
 			}
 		}	
 	}
 	vector<char>v;
	for(char x:q)
	{
		v.push_back(x);
	}
	if(par==0)
	{
		for(char x:v)
		{
			cout<<x;
		}cout<<endl;
	}
	else
	{
		reverse(v.begin(),v.end());
		for(char x:v)
		{
			cout<<x;
		}cout<<endl;	
	}
    return 0;
}

Measured memory_bytes: 1364
n = int(input())
res = 0
for a in range(1, n + 1)[::2]:
  i = 1
  s = set()
  while i * i <= a:
    if a%i == 0:
      s.add(i)
      s.add(a//i)
    i += 1
  if len(s) == 8:
    res += 1
print(res)

Measured memory_bytes: 3060
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include <vector>

int main() {

  int N;
  int V;
  int C;

  std::vector<int> v1;
  std::vector<int> v2;

  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> V;
    v1.push_back(V);
  }

  for (int p = 0; p < N; p++) {
    std::cin >> C;
    v2.push_back(C);
  }

  std::vector<int> v3;
  for (int j = 0; j < N; j++) {
    v3.push_back(v1[j] - v2[j]);
  }

  std::sort(v3.begin(), v3.end(), std::greater<int>());

  if (N == 1) {
    std::cout << 0 << std::endl;
    return 0;
  }

  std::vector<int> v4;
  int tmp = 0;
  for (int y = 0; y < N; y++) {
    tmp += v3[y];
    v4.push_back(tmp);
  }
  if(v4[0]<0){
    std::cout << 0 << std::endl;
    return 0;
  }   
  std::sort(v4.begin(), v4.end(), std::greater<int>());
  std::cout << v4[0] << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------

void _main() {
	int K, S;
	cin >> K >> S;
	int counter = 0;
	rep(x, 0, K + 1) {
		rep(y, 0, K + 1) {
			int z = S - x - y;
			//マイナスやｋ以上は入ってはならない
			if (0 <= z and z <= K) {
				counter++;
			}
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int negativeNumCnt = 0;
        long absMin = Long.MAX_VALUE;
        long absSum = 0;
        boolean hasZero = false;
        for (int i = 0; i < N; i++) {
            if (A[i] == 0) {
                hasZero = true;
            }
            if (A[i] < 0) {
                negativeNumCnt++;
            }
            long abs = Math.abs(A[i]);
            absSum += abs;
            if (abs < absMin) {
                absMin = abs;
            }
        }

        if (negativeNumCnt %2 == 0 || hasZero == true) {
            System.out.println(absSum);
        }
        else {
            long max = absSum - absMin * 2;
            System.out.println(max);
        }
    }
}

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

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

long long INF = 1e18;
const int mod = 1e9 + 7;

using namespace std;

#define ll long long
#define MAX_V 1000
#define MAX_E 2000

struct edge{
    int from, to, cost;
};
edge es[MAX_E];
ll d[MAX_V+1];
int V, E;

bool bellman_ford(int s, int t){
    REP(i, V+1) d[i] = INF;
    d[s] = 0;
    REP(i, 2*V){
        REP(j, E){
            edge e = es[j];
            if(d[e.from]!=INF && d[e.to]>d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i>=V-1 && e.to==t) return true;
            }
        }
    }
    return false;
}

int main(){
  scanf("%d%d",&V,&E);
  REP(i,E){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    es[i].from = a;
    es[i].to = b;
    es[i].cost = -c;
  }

  if(bellman_ford(1,V)) printf("inf\n");
  else printf("%lld\n",-d[V]);

  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] X = new int[M];
		for (int i = 0; i < M; i++)
			X[i] = sc.nextInt();
		Arrays.sort(X);
		if (N >= M) {
			System.out.println(0);
			return;
		}
		Integer[] T = new Integer[M - 1];
		for (int i = 1; i < M; i++)
			T[i - 1] = X[i] - X[i - 1];
		Arrays.sort(T, Collections.reverseOrder());
		int t = 0;
		for (int i = 0; i < N - 1; i++)
			t += T[i];
		System.out.println((X[M - 1] - X[0]) - t);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 25712
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>

using namespace std;

typedef long long ll;

int main(void){
    ll n;
    cin >> n;
    vector<ll> p(n);
    for(ll i = 0; i < n; i++){
        cin >> p[i];
    }
    ll ans = 0;
    for(ll i = 1; i < n - 1; i++){
        if((p[i - 1] < p[i] && p[i + 1] > p[i]) || (p[i - 1] > p[i] && p[i]  > p[i + 1])){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	ll := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&ll[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(ll)))
	cnt := 0
	for i := 0; i < K; i++ {
		cnt += ll[i]
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<math.h>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;

int main() {
	string s;
	cin >> s;
	s.erase(s.size() - 8);
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
/*
 * @Author: Kaizyn
 * @Date: 2020-03-22 19:58:40
 * @LastEditTime: 2020-03-22 20:06:53
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 1;
const int MOD = 1e9+7;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> pii;

inline void solve()
{
    int l;
    cin >> l;
    printf("%.7f\n", pow(l/3.0, 3));
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }

class BinaryIndexedTree
{
// 0-indexed
public:
    vector<int> data;
    BinaryIndexedTree(int N):data(N+1,-1){}
    void update(int i,int x){
        for(i++;i<data.size();i+=i&-i) chmax(data[i],x);
    }
    int query(int i){
        int res=-1;
        for(i++;i>0;i-=i&-i) chmax(res,data[i]);
        return res;
    }
};

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

    int N; cin>>N;
    vector<int> h(N),a(N);
    for(int i=0;i<N;i++) cin>>h[i];
    for(int i=0;i<N;i++) cin>>a[i];
    vector<pair<int,int>> v(N);
    for(int i=0;i<N;i++){
        v[i]={h[i],i};
    }
    sort(v.begin(),v.end());

    vector<int> dp(N);
    BinaryIndexedTree bit(N);
    for(auto p:v){
        int i=p.second;
        dp[i]=a[i];
        chmax(dp[i],bit.query(i-1)+a[i]);
        bit.update(i,dp[i]);
    }
    // for(int i=0;i<N;i++) cout<<dp[i]<<' '; cout<<endl;
    cout<<*max_element(dp.begin(),dp.end())<<endl;
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <bitset>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> pv(m);
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		cin >> a >> b;
		int ix = 0;
		for (int j = 0; j < b; ++j) {
			int c;
			cin >> c;
			ix |= 1 << (c-1);
		}
		pv[i] = { a, ix };
	}

	vector<long long> dp(1 << n, INT_MAX);
	dp[0] = 0;
	for (int i = 0; i < dp.size(); ++i)
	{
		for (int j = 0; j < m; ++j) 
		{
			int ix = i | pv[j].second;
			long long co = dp[i] + pv[j].first;
			dp[ix] = min(dp[ix], co);
		}
	}
	if (dp.back() == INT_MAX) {
		cout << -1 << endl;
	}
	else {
		cout << dp.back() << endl;
	}

	return 0;
}

Measured memory_bytes: 256