akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int a,b;

int main()
{
    cin>>a>>b;
    if(a+b>=10)printf("error");
    else printf("%d",a+b);
    return 0;
}


Measured memory_bytes: 256
import math
from fractions import gcd


class Work():

    def __init__(self, a, b):
        self.a = a
        self.b = b

    def __lt__(self, other):
        return self.b < other.b

    def __eq__(self, other):
        return self.b == other.b

    def __repr__(self):
        return "Work(%d, %d)" % (self.a, self.b)


def read():
    N = int(input().strip())
    works = []
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        works.append(Work(a, b))
    return N, works


def solve(N, works):
    works = sorted(works)
    t = 0
    for work in works:
        t += work.a
        if t > work.b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 108756
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int n , m ;
	cin >> n >> m; 
	cout << (n*(n-1)+m*(m-1))/2 << endl;
	
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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

bool is_leap( int y )
{
	if ( y % 4 == 0 )
	{
		if ( y % 100 == 0 )
		{
			if ( y % 400 == 0 )
			{
				return true;
			}
		}
		else
		{
			return true;
		}
	}
	return false;
}

int main( void )
{
	bool f = false;
	int a, b;
	while ( cin >> a >> b && a && b )
	{
		if ( f ) cout << endl;
		else f = true;

		bool exist = false;
		for ( int i = max(0,a); i <= min(3000,b); i++ )
		{
			if ( is_leap( i ) )
			{
				cout << i << endl;
				exist = true;
			}
		}

		if ( exist == false )
			cout << "NA" << endl;

	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  ll a,b,c;
  cin>>a>>b;
  c=b-a-1;
  cout<<c*(c+1)/2-a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define fi first
#define se second
#define pb push_back
#define read(type, ...)type __VA_ARGS__; macro_scan(__VA_ARGS__);

using namespace std;

template<typename T> void macro_scan(T& t){cin>>t;};
template<typename F, typename ...R>void macro_scan(F& f , R& ...r){
  cin>>f;macro_scan(r...);
}

void deb(){
    cerr<<endl;
}
template<typename T , typename... t>
void deb(T a , t...b){
    cerr<<a<<" ";
    deb(b...);
}
template<typename T>
void dev(vector<T>v){
    int c = 0;
    for(auto i : v){
        cerr<<i<<" ";
        c++;
    }
    cerr<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //int t; cin>>t;for(;t--;)done();
     read(int , n);
     vector<int>v(n);
     for(int& i : v)cin>>i;
     if(is_sorted(all(v))){
         return cout<<"YES\n" , 0;
     }
     for(int i = 0 ; i < n; ++i){
         for(int j = i + 1 ; j < n; ++j){
             swap(v[i] , v[j]);
             if(is_sorted(all(v))){
                 return cout<<"YES\n" , 0;
             }else{
                 swap(v[i], v[j]);
             }
         }
     }
     cout<<"NO\n";
}




Measured memory_bytes: 256
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(Int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(Int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);

const string YES = "Yes";
const string NO = "No";
void yn(bool ok){
  cout << (ok ? YES : NO) << endl;
}

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
  vi ans(N), cnta(N+1, -1);
  rep(i, N) {
    chmax(cnta[A[i]], i);
  }
  Int shi = 0;
  rep(i, N){
    if(cnta[B[i]] == -1) continue;
    chmax(shi, cnta[B[i]] - i + 1);
  }
  rep(i, N) ans[(i + shi) % N] = B[i];
  dump(shi);
  bool res = true;
  rep(i, N) res &= (ans[i] != A[i]);
  yn(res);
  if(res) rep(i, N) cout << ans[i] << (i == N-1 ? "\n" : " ");
}

int main(){
  // std::cout << std::fixed << std::setprecision(15);
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

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


Measured memory_bytes: 9620
use v5.18;
use warnings;
use Data::Dumper;
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

sub print_map {
  my $map = shift;
  for my $row (@$map) {
    say join '', @$row;
  }
}

my ($h, $w) = splited_read_line;
my $map = [ map { [ split //, read_line ] } 0 .. $h - 1 ];

my $blank_row = '.' x $w;
my @row_compressioned = grep { join('', @$_) ne $blank_row } @$map;

my $blank_column = '.' x @row_compressioned;
my @remain_columns = grep {
  my $x = $_;
  my $column = join '', map { $row_compressioned[$_][$x] } 0 .. $#row_compressioned;
  $column ne $blank_column;
} 0 .. $w - 1;
my @column_compressioned = map {
  my $y = $_;
  my @row = map {
    my $x = $_;
    $row_compressioned[$y][$x];
  } @remain_columns;
  \@row;
} 0 .. $#row_compressioned;

print_map(\@column_compressioned);


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

void solve() {
	double D , T , S ;
	cin >> D >> T >> S ;
	double Tm = D / S ;
	if (Tm <= T)
		cout << "Yes" ;
	else
		cout << "No" ;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin) ;
#endif
	int T = 1 ;
	while (T--) {
		solve() ;
		//cout << "\n" ;
	}
}

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

#define ll long long
#define ii pair<int,int>

using namespace std;


int main(){
	int n, m;
	cin >> n >> m;
	vector<bool>can(n,false);
	vector<int>cnt(n,0);
	int sum[2];
	sum[0] = sum[1] = 0;
	for(int i = 0;i < m;i++){
		int num;
		string v;
		cin >> num >> v;
		num--;
		if(can[num])continue;
		if(v[0] == 'W'){
			cnt[num]++;
		}
		else{
			can[num] =  true;
			sum[0]++;
			sum[1]+= cnt[num];
		}
	}
	cout << sum[0] <<' ' << sum[1] << endl;
}


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

int n, ans;
long long k;
vector<pair<int,int> > v;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 0, a, b; i < n; i++) cin >> a >> b, v.emplace_back(a, b);
	sort(v.begin(), v.end());
	long long sum = 0;
	for(auto p: v) {
		sum += p.second;
		if(sum >= k) {
			ans = p.first;
			break;
		}
	}
	cout << ans;
}


Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] chars = s.toCharArray();
		int count = 0;
		for(char c : chars) {
			int i = Integer.parseInt(String.valueOf(c));
			if(i == 1) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
import sys
readline = sys.stdin.readline
NIL = None
class Tree:
    def __init__(self, key = None):
        self.key = key
        self.p = NIL
        self.left = NIL
        self.right = NIL
n = int(input())
tree = {"root":NIL}
def insert(T, z):
    y = NIL
    x = T["root"]
    while x != NIL:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.p = y
    if y == NIL:
        T["root"] = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
def preorder_tree_walk(T):
    print(f" {T.key}", end="")
    if T.left != NIL:
        preorder_tree_walk(T.left)
    if T.right != NIL:
        preorder_tree_walk(T.right)
def inorder_tree_walk(T):
    if T.left != NIL:
        inorder_tree_walk(T.left)
    print(f" {T.key}", end="")
    if T.right != NIL:
        inorder_tree_walk(T.right)
for _ in range(n):
    ss = readline()
    if ss[0] == "i":
        s, v = ss.split()
        insert(tree, Tree(int(v)))
    else:
        inorder_tree_walk(tree["root"])
        print()
        preorder_tree_walk(tree["root"])
        print()



Measured memory_bytes: 105028
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    double ans=0;
    long long n,k; cin>>n>>k;
    for(long long i=1;i<=n;i++){
        long long tmp=i;
        double tmpans=1.0;
        while(tmp<k){
            tmpans/=2.0;
            tmp*=2;
        }
        ans+=tmpans/(double)n;
    }
    printf("%.15f\n",ans);
    return 0;
}


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

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
 string s,t;
 cin >> s >> t;
 if(s==t.substr(0,s.size())){
   cout << "Yes" << endl;
 }else{
   cout << "No" << endl;
 }
 return 0;
}


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

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
#define PB push_back
#define mkp make_pair
#define mins(a,b) a=min(a,b)

typedef long long ll;
typedef vector<int> vint;

map<ll, int> ma;
set<ll> se;



ll pow1[10];
ll pow2[10];

void rev(ll &a,int l,int r){
	while(l<r){
		ll b = a%pow2[l]/pow1[l]*pow1[l];
		ll c = a%pow2[r]/pow1[r]*pow1[r];
		a+=-b-c+b*pow1[r-l]+c/pow1[r-l];
		l++;
		r--;
	}
}

vector<int> w;


int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i], v[i]--;
	w.assign(n, 0);
	rep(i, n) w[i] = i;
	if(v == w) {
		cout << 0 << endl;
		return 0;
	}
	pow1[0] = 1;
	pow2[0] = 10;
	rep(i,9){
		pow1[i+1] = pow1[i]*10;
		pow2[i+1] = pow2[i]*10;
	}
	int ans = n - 1;
	queue<ll> q[2];
	ll vv=0,ww=0;
	rep(i,n){
		vv=vv*10+v[i];
		ww=ww*10+w[i];
	}
	q[0].push(vv);
	int m = (v.size()-1)/2;
	ma[vv] = 0;
	rep(o,m){
		queue<ll>& now = q[o%2];
		queue<ll>& next = q[1-o%2];
		while(now.size()){
			auto top = now.front();
			now.pop();
			rep(i,n){
				rep(j,i){
					rev(top,j,i);
					if(ma.count(top)==0){
						ma[top] = o+1;
						next.push(top);
					}
					rev(top,j,i);
				}
			}
		}
	}
	while(q[0].size()) q[0].pop();
	while(q[1].size()) q[1].pop();
	set<ll> used;
	q[0].push(ww);
	rep(o,m){
		queue<ll>& now = q[o%2];
		queue<ll>& next = q[1-o%2];
		while(now.size()){
			auto top = now.front();
			now.pop();
			rep(i,n){
				rep(j,i){
					rev(top,j,i);
					if(ma.count(top)){
						mins(ans,ma[top]+o+1);
					}
					else if(used.find(top)!=used.end()){

					}
					else{
						next.push(top);
						used.insert(top);
					}
					rev(top,j,i);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 32720
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, it) for(auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define endl "\n"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

const int mxn = 1e7 + 1;
ll f[mxn];

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

	ll i, n, ans = 0, j;
	cin >> n;
	for(i = 1; i <= n; i++)
	{
		for(j = 0; j <= n; j += i)
			f[j]++;
	}
	rep(i, 1, n + 1)
		ans += (i * f[i]);
	cout << ans << endl;
}

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

typedef long long ll;
ll g(ll p) {return p > 0 ? p : -p;}
ll a, b, ans;
int main()
{
	cin >> a >> b;
	if (g(a) <= g(b)) {
		ans = g(b) - g(a);
		if (a < 0) ans++;
		if (b < 0) ans++;
	} else {
		ans = g(a) - g(b);
		if (a > 0) ans++;
		if (b > 0) ans++;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 256
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {

	string S =Console.ReadLine();
      char[] s={S[0],S[1],S[2],S[3]};
      Array.Sort(s);
      if(s[0]==s[1] && s[0]!=s[2] && s[2]==s[3])
      {
        Console.WriteLine("Yes");
      }else{
        Console.WriteLine("No");
      }

      
    }
    
  }

}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
 
#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
using ll = long long;
 
int main() {
    int N;
    ll count = 0;
    int j = 1;
    IN(N);
    vector<string> s(N);
    REP(i, N) {
        IN(s[i]);
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    REP(i, N - 1) {
        if(s[i] == s[i + 1]) {
            count += j;
            j++;
        }
        else j = 1;
    }
    OUT(count);
}

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

int main() {
    int r, c, value;
    cin >> r >> c;
    int answer[r + 1][c + 1];

    for (int h = 0; h <= r; h++) {
        for (int i = 0; i <= c; i++) {
            answer[h][i] = 0;
        }
    }

    for (int h = 0; h < r; h++) {
        for (int i = 0; i < c; i++) {
            cin >> value;
            answer[h][i] = value;
            answer[h][c] += value;
            answer[r][i] += value;
            answer[r][c] += value;
        }
    }

    for (int h = 0; h <= r; h++) {
        for (int i = 0; i <=  c; i++) {
            cout << answer[h][i];
            if (i != c) {
                cout << " ";
            } else {
                cout << endl;
            }
        }
    }

    return 0;
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int sum = a + b, cnt = 0, b_r = 1;
    for (int i = 0; i < n; i++) {
        if (s.at(i) == 'c') {
            cout << "No" << endl;
        } else {
            if (cnt < sum) {
                if (s.at(i) == 'a') {
                    cout << "Yes" << endl;
                    cnt++;
                } else if (s.at(i) == 'b' && b_r <= b) {
                    cout << "Yes" << endl;
                    cnt++;
                    b_r++;
                } else {
                    cout << "No" << endl;
                }
            } else {
                cout << "No" << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3764
S = gets.chomp

a = Array.new(2019, 0); a[0] = 1
m, d = 0, 1
S.reverse.chars.map(&:to_i).each do |n|
  m = (m + n*d) % 2019
  d = d*10 % 2019
  a[m] += 1
end
puts a.inject(0){|s, v| s + v*(v - 1)/2}

Measured memory_bytes: 26580
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

string s;
int n, K, keta;

bool comp(string& a, string& b)
{
    if(len(a) < len(b)){
        return true;
    }else if(len(a) > len(b)){
        return false;
    }else{
        return a < b;
    }
}

bool possible(string& t)
{
    string nw;
    int cnt = 0;
    rep(i,n){
        nw.pb(s[i]);
        if(comp(t, nw)){
            nw.clear();
            cnt++;
            nw.pb(s[i]);
            if(comp(t, nw)){
                return false;
            }
        }
    }
    return (cnt <= K);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> K;
    cin >> s;
    n = len(s);
    keta = (n+K) / (K+1);
    if(K == 0){
        cout << s << "\n";
        return 0;
    }
    if(K == 1){
        string x = s.substr(0,keta), y = s.substr(n-keta,keta);
        if(comp(x, y)){
            cout << y << "\n";
        }else{
            cout << x << "\n";
        }
        return 0;
    }
    vs ss;
    rep(i,n-keta+1){
        ss.pb(s.substr(i,keta));
    }
    sort(all(ss),comp);
    int l = -1, r = n-keta;
    while(r-l>1){
        int mid = (l+r)/2;
        if(possible(ss[mid])){
            r = mid;
        }else{
            l = mid;
        }
    }
    cout << ss[r] << "\n";
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	int claim[15][15];
	
	rep(i,N){
		rep(j,N){
			claim[i][j] = -1;
		}
	}
	
	rep(i,N){
		int a;
		cin >> a;
		rep(j,a){
			int x,y;
			cin >> x >> y;
			x--;
			claim[i][x] = y;
		}
	}
	
	int ans = 0;
	
	rep(bit, 1<<N) {
		vector<int> d(N);
		rep(i, N) {
			if (bit & (1 << i)) {
				d[i] = 1;
			}
		}
		bool ok = true;
		rep(j, N) {
			if (d[j] == 1) {
				rep(k, N) {
					if (claim[j][k] == -1) continue;
					if (claim[j][k] != d[k]) ok = false;
				}
			}
		}
		if (ok) {
			int temp = 0;
			rep(i, N) {
				if (d[i] == 1) {
					temp++;
				}
			}
			ans = max(ans, temp);
		}
	}
	
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define N 500000
void merge(int A[N],int left,int mid,int right);
void mergeSort(int A[N],int left,int right);
int count=0;
int main (){
  int i,n;
  int A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    if(i<n-1) printf("%d ",A[i]);
    else printf("%d\n",A[i]);
  }
  printf("%d\n",count);
  return 0;
}

void merge(int A[N],int left,int mid,int right){
  int L[N],R[N];
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  for(i = 0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1] =1000000000;
  R[n2] =1000000000;
  i = 0;
  j = 0;
  for(k = left;k<right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
    }
    count++;
  }
}
void mergeSort(int A[N],int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A,left, mid);
    mergeSort(A,mid, right);
    merge(A,left, mid, right);
  }
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int an = 0;
  int bn = 0;
  int cn = 0;
  for (auto c : s) {
    if (c == 'a') {
      an++;
    } else if (c == 'b') {
      bn++;
    } else if (c == 'c') {
      cn++;
    }
  }
  if (an == 1 && bn == 1 && cn == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()
#define fst first
#define sec	second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef pair<long,long> P;

const int mod = 1e9 + 7;


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

	int n;
	cin >> n;
	vi b(n);
	rep(i, n-1){
		cin >> b[i];
	}

	vi a(n);
	rep(i, n-1){
		a[i] = b[i];
		a[i+1] = b[i];
		if(i > 0){
			if(b[i-1] < b[i]){
				a[i] = b[i-1];
			}else{
				a[i] = b[i];
			}
		}
	}

	ll ans = 0;
	rep(i, n){
		ans += a[i];
	}

	cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#DAG判定
#n=頂点数 e=隣接リスト
#負の閉路検出
#n=頂点数 e=[[a,b,c],[]...](a~bの距離がc)
def find_negative_loop(n,e):
  d=n*[10**20];d[0]=0
  for h in range(n):
    for i,j,k in e:
      if d[j]>d[i]+k:
        d[j]=d[i]+k
        if h==n-1:return True
  return False

#DAG判定
#n=頂点数 e=隣接リスト
#flag=0...DAG判定　flag=1...トポロジカルソート
from collections import deque
def find_loop(n,e,flag):
  x=[0]*n
  d=deque()
  t=[]
  c=0
  for i in range(n):
    for j in e[i]:x[j]+=1
  for i in range(n):
    if x[i]==0:
      d.append(i)
      t.append(i)
      c+=1
  while d:
    i=d.popleft()
    for j in e[i]:
      x[j]-=1
      if x[j]==0:
        d.append(j)
        t.append(j)
        c+=1
  if flag==0:return c==n
  else:return t

#ベルマンフォード(d[i]=頂点sから頂点iの最短距離)
#単一始点最短経路(負の辺対応)
#s=始点 n=頂点数 e=[[a,b,c],[]...](a~bの距離がc)
def bellman_ford(s,n,e):
	inf=10**20;d=[inf]*n;d[s]=0
	while 1:
		f=True
		for i,j,k in e:
			if d[i]!=inf and d[j]>d[i]+k:d[j]=d[i]+k;f=False
		if f:break
	return d

n,m,p=map(int,input().split())
ef=[[]for _ in range(n)]
ee=[[]for _ in range(n)]
e=[]
for _ in range(m):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  c-=p
  ef[a].append(b)
  ee[b].append(a)
  e.append([a,b,c])
eff=[0]*n
eff[0]=1
Q=[0]
visited={0}
while Q:
  P=[]
  for i in Q:
    for j in ef[i]:
      if j in visited:continue
      visited.add(j)
      eff[j]=1
      P.append(j)
  Q=P
eef=[0]*n
eef[n-1]=1
Q=[n-1]
visited={n-1}
while Q:
  P=[]
  for i in Q:
    for j in ee[i]:
      if j in visited:continue
      visited.add(j)
      eef[j]=1
      P.append(j)
  Q=P
edge=[]
for a,b,c in e:
  if eff[a]==1 and eef[a]==1 and eff[b]==1 and eef[b]==1:
    edge.append([a,b,-c])
if find_negative_loop(n,edge):print(-1);exit()
print(max(-bellman_ford(0,n,edge)[n-1],0))

Measured memory_bytes: 59992
h,w,k=map(int,input().split())
a=["x" for _ in range(h)]
c=1
if k==0:
  a=[1 for _ in range(w)]
  for i in range(h):
    print(*a)
  import sys
  sys.exit()

for i in range(h):
  s=input()
  sh=[]
  nc=0
  if s=="."*w:continue
  
  for j in range(w):
    if s[j]=="#" and nc>0:c+=1
    elif s[j]=="#": nc+=1
    sh.append(str(c))
  a[i]=sh[:]
  c+=1
  
if a[0]=="x":
  l=1
  while a[l]=="x":
    l+=1
  a[0]=a[l]
  
while "x" in a:
  for i in range(h):
    if a[i]=="x":
      l=i-1
      while a[l]=="x":
        l-=1
      a[i]=a[l]
      
for m in a:
  print(*m)

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll e;
  while(cin >> e && e){
    ll m = inf;
    for(int i = 0; i <= 100; ++ i){
      for(int j = 0; int(e - i * i * i - j * j) >= 0; ++ j){
        ll x = e - i * i * i - j * j ;
        if(x >= 0 && x <= 1000000){
          m = min(m,i+j+x);
        }
      }
    }
    cout << m << endl;
  }
  return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
long long n,k,ans,cur;
int main()
{
	cin>>n>>k;
	cur=n/k;
	ans=cur*cur*cur;
	if (k%2==0)
	{
		cur=n/k;
		if (cur*k+k/2<=n) cur++;
		ans+=cur*cur*cur;
	}
	cout<<ans<<endl;
	return 0;
}

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

int len[100005];
int ans[100005];

int main()
{
	for (int i = 0; i < 100005; ++i)
	{
		ans[i] = 0;
	}
	string S;
	cin >> S;
	int cnt = 0;
	int index = 0;
	bool flag = true; //true -> R  false -> L
	for (int i = 0; i < S.size(); ++i)
	{
		if ((flag)&&(S[i] == 'L'))
		{
			len[index] = cnt;
			index++;
			cnt = 1;
			flag = false;
		}
		else if ((!flag)&&(S[i] == 'R'))
		{
			len[index] = cnt;
			index++;
			cnt = 1;
			flag = true;
		}
		else
		{
			cnt++;
		}
	}

	len[index] = cnt;
	index++;
	cnt = 1;
	flag = true;

	/*
	for (int i = 0; i < index; ++i)
	{
		cout << len[i] << " ";
	}

	cout << endl;
	*/

	int temp = 0;

	for (int i = 0; i < index; i += 2)
	{
		if (len[i] % 2 == 0)
		{
			ans[temp + len[i] - 1] = (len[i] + len[i+1]) / 2;
			ans[temp + len[i]] = (len[i] + len[i+1] + 1) / 2;
			temp += len[i] + len[i+1];
		}
		else
		{
			ans[temp + len[i]] = (len[i] + len[i+1]) / 2;
			ans[temp + len[i] - 1] = (len[i] + len[i+1] + 1) / 2;
			temp += len[i] + len[i+1];
		}
	}

	for (int i = 0; i < S.size(); ++i)
	{
		if (i != 0)
		{
			cout << " ";
		}

		cout << ans[i];
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 1472
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int N;
vector<int> a;

int main(void){
	cin >> N;
	for(int i = 1; i <= 3 * N; i++){
		int input;
		cin >> input;
		a.push_back(input);
	}
	sort(a.begin(), a.end());
	ll ans = 0;
	for(int i = 1; i <= N; i++){
		ans += a[a.size() - 2 * i];
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int n,m;
    double temp=0;
    bool rta;
    cin >> n >> m;
    double a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        temp+=a[i];
    }
    temp/=(4*m);
    for(int i=0;i<m;i++){
        rta=false;
        for(int j=0;j<n;j++){
            if(a[j]>=temp){
                a[j]=0;
                rta=true;
                break;
            }
        }
    }
    if(rta) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner in  = new Scanner(System.in);
    public static void main(String[] args){
        int x = in.nextInt(), a = in.nextInt(), b = in.nextInt();
        if(a >= b){
            System.out.println("delicious");
        }else{
            if(b - a >= x + 1){
                System.out.println("dangerous");
            }else{
                System.out.println("safe");
            }
        }
    }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void)
{
    int n, d;
    cin >>n >>d;

    int req = ceil((double)n / (1+2*d));

    printf("%d\n", req);

    return 0;
}

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

int searchMinimumSum(ll sum[]) {
	if (sum[0] <= sum[1] && sum[0] <= sum[2]) {
		return 0;
	} else if (sum[1] <= sum[0] && sum[1] <= sum[2]) {
		return 1;
	}
	return 2;
}

int main(int argc, char const* argv[])
{
	ll N, ans = -1, counter = 0;
	cin >> N;
	ll A[N], sum[3] = {0}, knife[3] = {0, 1, 2};
	for (int i=0; i<N; i++) {
		cin >> A[i];
		if (i==0) {
			sum[0] = A[0];
		} else if (i==1) {
			sum[1] = A[1];
		} else {
			sum[2] += A[i];
		}
	}
	while (counter < N + 3) {
		int minID = searchMinimumSum(sum);
		if (ans < sum[minID]) {
			ans = sum[minID];
		}
		sum[minID] += A[knife[(minID+1)%3]];
		sum[(minID+1)%3] -= A[knife[(minID+1)%3]];
		knife[(minID+1)%3]++;
		if (knife[(minID+1)%3] == N) {
			knife[(minID+1)%3] = 0;
	 	}
		if (minID == 2) {
			counter++;
		}

	}
	cout << ans << "\n";

	return 0;
}


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

const ll INF = 1001001001;

struct edge {
  int from;
  int to;
  ll cost;
  edge(int a, int b, ll c) : from(a), to(b), cost(c){};
};

vector<int> to[2505];
vector<int> rto[2505];
bool reachableFrom[2505];
bool reachableTo[2505];
bool reachableFromTo[2505];

void dfs(int v) {
    if(reachableFrom[v]) return;
    reachableFrom[v] = true;
    for(auto u: to[v]) dfs(u);
}

void rdfs(int v) {
    if(reachableTo[v]) return;
    reachableTo[v] = true;
    for(auto u: rto[v]) rdfs(u);
}

int main() {
  int n, m, p;
  cin >> n >> m >> p;
  vector<edge> G;

  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    --a; --b;
    c -= p;
    c = -c;
    edge e(a, b, c);
    G.push_back(e);
    to[a].push_back(b);
    rto[b].push_back(a);
  }

  dfs(0);
  rdfs(n-1);
  rep(i, n) reachableFromTo[i] = reachableFrom[i]&reachableTo[i];

  vector<ll> dist(n, INF);
  dist[0] = 0;
  bool neg_loop = false;

  // 頂点数-1　回ループして更新する。
  // 頂点数 回目のループで更新があった場合、正の閉路が存在する。
  for(int i = 0; i < n; ++i) {
    for(auto &e: G) {
      if(!reachableFromTo[e.to]) continue;
      if(!reachableFromTo[e.from]) continue;
      if(dist[e.to] > dist[e.from] + e.cost) {
        dist[e.to] = dist[e.from]+ e.cost;
        if(i == n-1) {
          neg_loop = true;
          break;
        }
      }
    }
  }
  ll ans = -dist[n-1];
  ans = max(ans, 0LL);
  if(!neg_loop) cout << ans << endl;
  else cout << "-1" << endl;
  return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int d[300005] = {};
int main(){
	ios_base::sync_with_stdio(false);
	string S;

	cin >> S;
	S = "a" + S;
	int N = S.length();

	vector<int> to(30,-1);
	vector<int> edge[300005];
	rrep(i,N){
		edge[i] = to;
		to[ S[i] - 'a' ] = i;
	}

	string ans;
	queue<pair<int,string>> que;
	que.emplace();
	while( !que.empty() ){
		int i = que.front().X;
		string s = que.front().Y;
		que.pop();
		rep(k,26) if( ans.empty() ){
			string ns = s + (char)('a' + k);
			if( edge[i][k] < 0 ) ans = ns;
			else{
				int ni = edge[i][k];
				if( d[ni] ) continue;
				d[ni] = s.length();
				que.emplace(ni, ns);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

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

    int res = 0;
    int left = 0, right = (int)S.size() - 1;
    while (left < right) {
        if (S[left++] != S[right--]) res++;
    }

    cout << res << endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    string S; cin >> S;
    cout << (S[0]==S[1]&&S[1]==S[2] ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
struct st{
	ll x,y,z;
}x[N];
ll n,m,i,j,k,ans;
inline bool cmp(st a,st b){return a.x*i+a.y*j+a.z*k>b.x*i+b.y*j+b.z*k;}
int main()
{
	cin>>n>>m;
	for(i=0;i<n;i++)cin>>x[i].x>>x[i].y>>x[i].z;
	for(i=-1;i<=1;i+=2)
	{
		for(j=-1;j<=1;j+=2)
		{
			for(k=-1;k<=1;k+=2)
			{
				sort(x,x+n,cmp);
				ll suma=0,sumb=0,sumc=0,sum;
				for(int l=0;l<m;l++)
				{
					suma+=x[l].x;
					sumb+=x[l].y;
					sumc+=x[l].z;
				}
				sum=suma*i+sumb*j+sumc*k;
				ans=max(ans,sum);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
string = input()

s = []
total = 0
s2 = []
for i in range(len(string)):
    if string[i] == '\\':
        s.append(i)
    elif string[i] == '/' and len(s) > 0:
        j = s.pop() # j: 対応する '\' の位置
        area = i - j # 面積
        total += area
        while len(s2) > 0 and s2[-1][0] > j: # s2[-1][0] == s2.pop()[0]
            area += s2[-1][1]
            s2.pop()
        s2.append([j, area]) # j: 水たまりの左端 / tmp: その水たまりの面積

ans = []
for i in range(len(s2)):
    ans.append(str(s2[i][1]))

print(total)
if len(ans) == 0:
    print(len(ans))
else:
    print(len(ans), end = ' ')
    print(' '.join(ans))


Measured memory_bytes: 6160
import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {
    //Solution by Sathvik Kuthuru
    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {
        int a, b, c, d;
        long[][] memo;
        static final long MOD = 998244353;


        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            a = scan.nextInt();
            b = scan.nextInt();
            c = scan.nextInt();
            d = scan.nextInt();
            memo = new long[c + 1][d + 1];
            for(int i = 0; i <= c; i++) Arrays.fill(memo[i], -1);
            out.println(rec(a, b));
        }

        long rec(int row, int col) {
            if(row == c && col == d) return 1;
            if(row > c || col > d) return 0;
            if(memo[row][col] != -1) return memo[row][col];
            return memo[row][col] =(((col * rec(row + 1, col)) % MOD + (row * rec(row, col + 1)) % MOD - (row * col * rec(row + 1, col + 1)) % MOD
            + MOD)) % MOD;
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 105520
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,x,y) for(int i=x;i<y;i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n;
    string s;
    cin>>n>>s;
    int ans=0,cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
            cnt++;
            ans=max(ans,cnt);
        }
        else cnt--;
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 3624
N = int(input())
A = list(map(int,input().split()))
B = [A[0]]
for i in range(1,N):
    B.append(B[-1]+A[i])
#plus_case
plus_ans = 0
c = 0
for i in range(N):
    current_value = B[i]+c
    if i%2 == 0:
        if current_value <= 0:
            plus_ans += abs(current_value-1)
            c -= current_value-1
    else:
        if current_value >= 0:
            plus_ans += abs(current_value+1)
            c -= current_value+1
#minus_case
minus_ans = 0
c = 0
for i in range(N):
    current_value = B[i]+c
    if i%2 == 0:
        if current_value >= 0:
            minus_ans += abs(current_value+1)
            c -= current_value+1
    else:
        if current_value <= 0:
            minus_ans += abs(current_value-1)
            c -= current_value-1
print(min(plus_ans,minus_ans))

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

typedef struct node{
    int key;
    struct node *prev, *next;
}Node;

  Node *nil;

void init(){ // ???????????????
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

//??\???????????????????????¢??°

void insert(int key){  
    Node *x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* Search(int key){
    Node* x = nil->next;
    while(x != nil && x->key != key){
        x = x->next;
    }
    return x;
}

void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(Search(key));
}

void print(){  //???????????????
    Node* x = nil->next;
    int i = 0;
    while(1){
        if(x == nil) break;
        if(i++ > 0) printf(" ");
        printf("%d", x->key);
        x = x->next;
    }
    printf("\n");
}

int main(void){
    int n,key,i,size = 0;
    char com[20];
    scanf("%d",&n);
    init();
    for(i=0;i<n;i++){
        scanf("%s %d", com, &key);
        if(com[0] == 'i'){	//insert?????????????????´???
            insert(key);
        }else if(com[0] == 'd'){	//delete?????????????????´??? ???????????????????????§?????\
        	if(strlen(com)>6){
        		if(strlen(com)>10){	//???????????????10????????\???->deleteFirst
        		deleteFirst();
        		}else if(strlen(com)>9){
        		deleteLast();
        		}
        }else{
            deleteKey(key);
        }
        }
    }
    print();
    return 0;
}

Measured memory_bytes: 32992
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[100005];
long long s;
long long x[100005];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		if(i==n) continue;
		if(i&1) s+=2*a[i];
		else s-=2*a[i];
	}
	s+=2*a[n];
	x[1]=s/2;
	for(int i=2;i<=n;i++){
		x[i]=2*a[i-1]-x[i-1];
	}
	for(int i=1;i<=n;i++) printf("%lld ",x[i]);
	
	return 0;
}

Measured memory_bytes: 2816