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

const long long INF = 1LL << 60;

int main() {
  long long n,cnt1=0,cnt2=0;
  long long a,b,sum1=0,sum2=0;
  cin >> n;
  
  //a_1が正のとき
  
  
  for(int i=0;i<n;i++){
    cin >> a;
    b = a;

      if(i%2 == 0){
    	  if(sum1+a<=0 ){
    		  cnt1 += 1-sum1-a ;
          sum1 = 1;
      	}
        else
        {
          sum1 += a;
        }
        
          
        
    }
    if(i%2 == 1){
    	if(sum1+a>=0 ){
    		cnt1 += sum1 + a+1 ;
        sum1 = -1;
        }
        else
        {
          sum1 += a;
        }
        
    }
  

    //b_1が負のとき
  
      if(i%2 == 1){
    	  if(sum2+b<=0 ){
    		  cnt2 += 1-sum2-b ;
          sum2 = 1;
      	}
        else
        {
          sum2 += b;
        }

    }
    if(i%2 == 0){
    	if(sum2+b>=0 ){
    		cnt2 += sum2 + b +1 ;
        sum2 = -1;
        }
        else
        {
          sum2 += b;
        }
        
    }
  }
 
  cout << min(cnt1,cnt2)  << endl;
  
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i=0;i<n;i++)

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

	int n, x;
	cin >> n >> x;
    vi a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;

    sort(a.begin(), a.end());

    int last = -1;
    
    rep(i, n){
        if(a[i] <= x){
            x -= a[i];
            ans++;
        }else{
            last = i;
            break;
        }
    }

    if(x>0 && last == -1){
        ans--;
    }



    

    cout << ans << endl;
    return 0;
	
}


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

const int M = 3e5 + 10;
const int MB = 60;
const int MD = 1e9 + 7;
int n;
int b[MB];

int main () {
    while (scanf("%d", &n) == 1) {
        memset(b, 0, sizeof(b));
        for (int i = 0; i < n; i++) { 
            long long a;
            scanf("%lld", &a);
            for (int ib = 0; ib < MB; ib++)
                if (a >> ib & 1) b[ib]++;
        }

        long long res = 0, b2 = 1;
        for (int ib = 0; ib < MB; ib++) {
            long long n1 = b[ib], n0 = n - b[ib];
            res = (res + (1ll * n1 * n0) % MD * b2) % MD;
            b2 = (b2 * 2) % MD;
        }
        printf("%lld\n", res);
    } 
    return 0;    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    cout << 1 - n;
    return 0;
}

Measured memory_bytes: 3688
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=5e5+5;
int fa[N],n,m;
inline int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	scanf("%d%d",&n,&m);
	fp(i,1,n+m)fa[i]=i;
	for(R int i=1,k,x;i<=n;++i){
		scanf("%d",&k);
		while(k--)scanf("%d",&x),fa[find(i)]=find(x+n);
	}
	fp(i,1,n)if(find(i)!=find(1))return puts("NO"),0;
	puts("YES");
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 1010

int W, H, N;

signed main()
{
    cin >> W >> H >> N;
    int l = 0, r = W, u = H, d = 0;
    REP(i, N) {
        int x, y, a;
        cin >> x >> y >> a;
        switch(a) {
            case 1:
                l = max(l, x);
                break;
            case 2:
                r = min(r, x);
                break;
            case 3:
                d = max(d, y);
                break;
            case 4:
                u = min(u, y);
                break;
        }
    }
    if(l >= r || d >= u) {
        printf("0\n");
        return 0;
    }
    printf("%lld\n", (r - l) * (u - d));
    return 0;
}


Measured memory_bytes: 256
module Main where

import           Data.Char                    (isLower)
import           Text.ParserCombinators.ReadP (ReadP, char, eof, many1,
                                               readP_to_S, satisfy)

main :: IO ()
-- interact を使うと一部失敗する
-- main = interact $ show . f
main = print . f =<< getLine

f :: String -> Result
f s = if not . null . readP_to_S parser $ s then AC else WA

parser :: ReadP ()
parser = char 'A' *> many1 lowerChar *> char 'C' *> many1 lowerChar *> eof

lowerChar :: ReadP Char
lowerChar = satisfy isLower

data Result
  = AC
  | WA
  deriving (Show, Eq)

tests :: [Bool]
tests =
  [ test1
  , test2
  , test3
  , test4
  , test5
  ]

test1, test2, test3, test4, test5 :: Bool
test1 = f "AtCoder" == AC
test2 = f "ACoder" == WA
test3 = f "AcycliC" == WA
test4 = f "AtCoCo" == WA
test5 = f "Atcoder" == WA


Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

struct Restaurant {
    int id;
    std::string location;
    int rating;
};

bool compare(const Restaurant& lhs, const Restaurant& rhs) {
    if (lhs.location != rhs.location) {
        return lhs.location < rhs.location;
    } else {
        return lhs.rating > rhs.rating;
    }
}

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

    std::vector<Restaurant> restaurants;
    for (int i = 0; i < N; i += 1) {
        std::string S;
        int P;
        std::cin >> S;
        std::cin >> P;

        restaurants.push_back({i + 1, S, P});
    }
    std::sort(restaurants.begin(), restaurants.end(), compare);

    for (int i = 0; i < N; i += 1) {
        std::cout << restaurants[i].id << std::endl;
    }

    return 0;
}


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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(a + b + c < 22) cout << "win" << endl;
	else cout << "bust" << endl;
	return 0;
}



Measured memory_bytes: 256
N  = int(input())
if N == 0:
    print(0)
else:
    ans = ""
    while N != 0:
        if N%2 == 1:
            ans += "1"
            N -= 1
        else:
            ans += "0"
        N //= -2
    print(ans[::-1])
    # tmp = [1*(i==0) for i in ans][::-1]
    # print("".join(map(str, tmp)))


Measured memory_bytes: 9100
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	ll h, w; cin >> h >> w;
	ll res = 1e18;
	//横３つパターン
	if (h % 3 == 0)res = 0;
	else res = min(res, w);
	//縦３つパターン
	if (w % 3 == 0)res = 0;
	else res = min(res, h);
	//横２×縦１パターン
	for (ll i = 1; i < w; ++i)
	{
		res = min(res, max((abs((h / 2)*(w - i) - h * i)), abs(((h + 1) / 2)*(w - i) - h * i)));
	}
	//横１×縦２パターン
	for (ll i = 1; i < h; ++i)
	{
		res = min(res, max(abs((w / 2)*(h - i) - w * i), abs(((w + 1) / 2)*(h - i) - w * i)));
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    if(N%2 == 0){
        int M = N * (N-1) / 2 - N/2;
        cout << M << endl;
        FOR(i,1,N+1){
            FOR(j,i+1,N+1){
                if(i+j != N+1){
                    cout << i << " " << j << endl;
                }
            }
        }
    }else{
        int M = N * (N-1) / 2 - N/2;
        cout << M << endl;
        FOR(i,1,N+1){
            FOR(j,i+1,N+1){
                if(i+j != N){
                    cout << i << " " << j << endl;
                }
            }
        }
    }

}


Measured memory_bytes: 256
sd = input()
t = input()
li_answer = list()
c_loop = len(sd) - len(t) + 1

for i in range(c_loop):
    if all((w_sd == "?" or w_sd == w_t) for w_sd, w_t in zip(sd[i:i + len(t) + 1], t)):
        s_tmp = str(sd[0:i] + t + sd[i + len(t):]).replace("?", "a")
        li_answer.append(s_tmp)

if li_answer:
    print(sorted(li_answer)[0])
else:
    print("UNRESTORABLE")


                                            

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a,b;
    scanf("%c %c",&a,&b);
    if(a>b)
        cout<<">"<<endl;
    else if(b>a)
        cout<<"<"<<endl;
    else
        cout<<"="<<endl;
    return 0;
}


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

using namespace std;
const int INF = 1001001001;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    
    vector<int> difference;
    for(int i = 0; i < N - 1; ++i){
        difference.push_back(A[i + 1] - A[i]);
    }
    
    int cnt = 0;
    bool flag;
    int index = 0;
    while(index < difference.size()){
        if(difference[index] == 0){
            index++;
        }
        else{
            if(difference[index] > 0){
                flag = true;
                index++;
            }
            else{
                flag = false;
                index++;
            }
            break;
        }
    }
    
    while(index < difference.size()){
        if(flag){
            if(difference[index] < 0){
                cnt++;
                flag = false;
                index++;
                
                while(index < difference.size()){
                    if(difference[index] == 0){
                        index++;
                    }
                    else{
                        if(difference[index] > 0){
                            flag = true;
                            index++;
                        }
                        else{
                            flag = false;
                            index++;
                        }
                        break;
                    }
                }
                if(index == difference.size())      break;
            }
            else{
                index++;
            }
        }
        else{
            if(difference[index] > 0){
                cnt++;
                flag = true;
                index++;

                while(index < difference.size()){
                    if(difference[index] == 0){
                        index++;
                    }
                    else{
                        if(difference[index] > 0){
                            flag = true;
                            index++;
                        }
                        else{
                            flag = false;
                            index++;
                        }
                        break;
                    }
                }
                if(index == difference.size())      break;
            }
            else{
                index++;
            }
        }
    }
    cnt++;
    
    cout << cnt << endl;
}

Measured memory_bytes: 1276
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b&a>c)
	{
		if(b>c)
		cout<<c<<" "<<b<<" "<<a<<endl;
		else
		cout<<b<<" "<<c<<" "<<a<<endl;
	}
	else {
		if(b>c&b>a){
			if(a>c)
			cout<<c<<" "<<a<<" "<<b<<endl;
			else
			cout<<a<<" "<<c<<" "<<b<<endl;
		}
	else {
		if(c>b&c>a){
			if(b>a)
			cout<<a<<" "<<b<<" "<<c<<endl;
			else
			cout<<b<<" "<<a<<" "<<c<<endl;
		}
	}
	}

	return 0;
}


Measured memory_bytes: 3096
from itertools import permutations
N = int(input())
P, Q = tuple(map(int, input().split())), tuple(map(int, input().split()))
a, b = 0, 0
for i, perm in enumerate(permutations(range(1, N + 1), N)):
    if perm == P:
        a = i + 1
    if perm == Q:
        b = i + 1
    if all((a, b)):
        print(abs(a - b))
        break

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#include<stdio.h>
#include<string>

typedef struct fox{ int val; fox *left, *right; } fox_n;

fox_n* init()
{
    fox_n* root = new fox_n;
    root->val = -2000000001;
    root->left = NULL;
    root->right = NULL;
    return root;
}

void insert(fox_n* root, int key)
{
    static bool first = true;
    static bool add_leaf = true;  // true:left, false:right.
    if(first){ first = false; root->val = key; return; }  // initialize.
    fox_n* canis;
    fox_n* water = root;  // water from root to leaf.
    do{
        canis = water;
        if(key < canis->val){  // canis chases water.
            water = canis->left;
            add_leaf = true;
        }else{
            water = canis->right;
            add_leaf = false;
        }
    }while(water != NULL);

    fox_n* leaf = new fox_n;  // add new leaf.
    leaf->val = key;
    leaf->left = NULL;
    leaf->right = NULL;
    if(add_leaf){ canis->left = leaf; }else{ canis->right = leaf; }
    return;
}

bool find(fox_n* root, int key)
{
    fox_n* fox = root;
    int val;
    do{
        val = fox->val;
        if(key < val){ fox = fox->left; }
        else if(val < key){ fox = fox->right; }
        else{ return true; }
    }while(fox);
    return false;
}

void inorder(fox_n* root)
{
    if(!root) return;
    inorder(root->left);
    printf(" %d", root->val);
    inorder(root->right);
    return;
}

void preorder(fox_n* root)
{
    if(!root) return;
    printf(" %d", root->val);
    preorder(root->left);
    preorder(root->right);
    return;
}

int main()
{
    fox_n* root = init();
    int i, n, key; char cmd[6];
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%s", cmd);
        if(cmd[0] == 'i'){ scanf("%d", &key); insert(root, key); }
        else if(cmd[0] == 'f'){ scanf("%d", &key); (find(root, key) ? printf("yes\n") : printf("no\n")); }
        else{ inorder(root); printf("\n"); preorder(root); printf("\n"); }
    }
    return 0;
}

Measured memory_bytes: 13704
#include<cstdio>
#include<vector>
#include<set>
#include<map>
const int MaxN=100010;
int N,D,x[MaxN],y[MaxN]; 
std::map<int,std::vector<int> >L[2];
std::map<int,std::set<int> >V[2];
long long ans;
void dfs(int x,int y);
int lb(int t,int v,int x){
	std::vector<int>&vec=L[t][v];
	int l=-1,r=vec.size(),mid;
	while(r-l>1)vec[mid=l+r>>1]<x?l=mid:r=mid;
	return r;
}
void trans(int t,int v,int l,int r){
	ans+=lb(t,v,r)-lb(t,v,l);
	std::set<int>::iterator it;
	while((it=V[t][v].lower_bound(l))!=V[t][v].end()&&*it<r){
		int x=*it,y=t?x+v:v-x;
		dfs(x,y);
	}
}
void dfs(int x,int y){
	V[0][x+y].erase(x);
	V[1][y-x].erase(x);
	trans(0,x+y-D,x-D,x);
	trans(0,x+y+D,x+1,x+D+1);
	trans(1,y-x+D,x-D+1,x+1);
	trans(1,y-x-D,x,x+D);
}
int diff(int a,int b){return a>b?a-b:b-a;}
int main(){
	int a,b;
	scanf("%d%d%d",&N,&a,&b);
	for(int i=1;i<=N;i++){
		scanf("%d%d",x+i,y+i);
		V[0][x[i]+y[i]].insert(x[i]);
		V[1][y[i]-x[i]].insert(x[i]);
	}
	for(int t=0;t<2;t++){
		std::map<int,std::set<int> >::iterator it;
		std::set<int>::iterator it2;
		for(it=V[t].begin();it!=V[t].end();it++){
			std::vector<int>v;
			for(it2=it->second.begin();it2!=it->second.end();it2++)
				v.push_back(*it2);
			L[t][it->first]=v;
		}
	}
	D=diff(x[a],x[b])+diff(y[a],y[b]);
	dfs(x[a],y[a]);
	printf("%lld\n",ans/2);
}

Measured memory_bytes: 88832
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int N, T;
    cin >> N >> T;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    vector<vector<int>> dp1(N+1, vector<int>(T+1, 0));
    vector<vector<int>> dp2(N+2, vector<int>(T+1, 0));

    for(int i = 0; i < N; i++){
        for(int t = 0; t < T; t++){
            int u = min(t + A[i], T);
            dp1[i+1][t] = max(dp1[i+1][t], dp1[i][t]); 
            dp1[i+1][u] = max(dp1[i][u], dp1[i][t] + B[i]);
        }
    }

    for(int i = N; i > 0; i--){
        for(int t = 0; t < T; t++){
            int u = min(t + A[i-1], T);
            dp2[i][t] = max(dp2[i][t], dp2[i+1][t]); 
            dp2[i][u] = max(dp2[i][u], dp2[i+1][t] + B[i-1]);
        }
    }

    int ans = 0;
    for(int i = 1; i <= N; i++){
        for(int t = 0; t < T; t++){
            ans = max(ans, dp1[i-1][t] + dp2[i+1][T-t-1] + B[i-1]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e2 + 10;
const int INF = 0x3f3f3f3f;
int n, m;
struct edge { int to, cost; };
typedef pair<int, int> P;
vector<edge> g[N], new_g[N]; 
int d[N]; 
int vis[N];
int dp[N][N];
int dist[N][N];


void dijkstra(int from) {
    priority_queue<P, vector<P>, greater<P> > que; // 优先队列优化，优先找花费最少的点。
    fill(d, d + N, INF);
    d[from] = 0; // 出发点
    que.push(P(0, from));
    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < new_g[v].size(); i++) {
            edge e = new_g[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        if(d[i] == INF) d[i] = 0;
        dp[from][i] = d[i]-1;
    }
    dp[from][from] = 0;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int l;
    cin >> n >> m >> l;
    memset(dist, 0x3f, sizeof dist);
    for(int i = 0, a, b, c; i < m; i++) {
        cin >> a >> b >> c;
        dist[a][b] = c;
        dist[b][a] = c;
        dist[a][a] = 0;
        dist[b][b] = 0;
    }
    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(dist[i][j] < INF && dist[i][j] <= l) {
                new_g[i].push_back(edge{j, 1});
                // printf("%d - %d\n", i, j);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        dijkstra(i);
    }
    int q;
    cin >> q;
    while(q--) {
        int s, t;
        cin >> s >> t;
        cout << dp[s][t] << '\n';
    }
    return 0;
}

Measured memory_bytes: 2432
N = int(input())
H_i = list(map(int, input().split()))

splits = []
ans = 0

for i in range(N - 1):
    if H_i[i] < H_i[i + 1]:
        splits.append(i)

for i in range(len(splits) - 1):
    if splits[i + 1] - splits[i] > ans:
        ans = splits[i + 1] - splits[i]

if splits:
    if splits[0] + 1 > ans:
        ans = splits[0] + 1

    if N - splits[-1] - 1 > ans:
        ans = N - splits[-1] - 1
else:
    ans = N
    
ans -= 1

print(ans)

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

int main(){
  int N; cin >> N;
  vector<int> L(N);
  for (int i=0; i<N; i++){
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  long long ans = 0;
  for (int i=0; i<N-1; i++){
    for (int j=i+1; j<N; j++){
      int num = lower_bound(L.begin(), L.end(), L[i]+L[j]) - upper_bound(L.begin(), L.end(), abs(L[i]-L[j]));
      if (2*L[i]>L[j]) num--;
      if (2*L[j]>L[i]) num--;
      if (num > 0 ) ans += num;
    }
  }
  cout << ans/3 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
typedef vector<int > vi;
int n;
vector<vector<int > >adjlist;
vi sz;
vi stree;
void dfs(int u,int p){
	int maxstree=0;
	for(auto v: adjlist[u]){
		if(v==p)continue;
		dfs(v,u);

	}
	for(auto v: adjlist[u]){
		if(v==p)continue;
		maxstree = max(maxstree,stree[v]);
		stree[u]+=stree[v];
	}
	sz[u] = max(maxstree,n-stree[u]-1);
	//cout<<u+1<<' '<<maxstree<<' '<<sz[u]<<'\n';
	stree[u]+=1;
}
int main(){
	int n;
	cin>>n;
	cout<<abs(n-1);
}


Measured memory_bytes: 3620
import sys, math
from functools import lru_cache
from collections import defaultdict
from itertools import accumulate
import bisect
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    A = list(mi())
    B = list(mi())
    if sum(A) < sum(B):
        print(-1)
        return

    short = []
    excess = []
    for i in range(N):
        if A[i] < B[i]:
            short.append(B[i]-A[i])
        if A[i] > B[i]:
            excess.append(A[i]-B[i])
    
    if not short:
        print(0)
        return

    excess.sort(reverse=True)
    acc = list(accumulate(excess))

    k = bisect.bisect_right(acc, sum(short))

    print(len(short)+k+1)




if __name__ == '__main__':
    main()


Measured memory_bytes: 24800
n = gets.chomp.to_i
arr = n.times.map{gets.chomp.split(" ").map(&:to_i)}

count = 0
arr.each do |(d1, d2)|
  if d1 == d2
    count += 1
  else
    count = 0
  end
  if count == 3
    puts "Yes"
    exit 0
  end
end

puts "No"

Measured memory_bytes: 14268
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		pr.println((x - a) % b);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <map>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        map<int,int> mp;
        int N;
        cin >> N;
        int tmp;
        rep(i,N){
                cin >> tmp;
                mp[tmp]++;
                mp[tmp+1]++;
                mp[tmp-1]++;
        }
        int max_num = 0;
        for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
                max_num = max(max_num, itr->second);
        }
        cout << max_num << endl;
        return 0;
}


Measured memory_bytes: 4736
#include <iostream>

using namespace std;

void insertionSort(int A[], int N) {
// N個の要素を含む0-オリジンの配列A
    int i, j, v, l;
    for (i = 1; N > i; i++) {   //for i が 1 から N-1 まで
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j + 1] = v;
        cout << A[0];
        for(l =1; l < N; l++){
            cout << " " << A[l];
        }
        cout << endl;
    }
}

int main() {
    int A[110];
    int i, l, N, t, f, flg=1;
    
    cin >> N;
    for(i =0; i < N; i++){
        cin >> A[i];
    }
    cout << A[0];
    for(i =1; i < N; i++){
        cout << " " << A[i];
    }
    cout << endl;
    insertionSort(A, N);
/*
    for(i =0; i < N; i++){
        cout << A[i] << " ";
    }
    cout << endl;
*/
    return 0;
}



Measured memory_bytes: 3060
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())

    l = [[1 if i=="#" else 0 for i in input()] for _ in range(H)]
    q = deque([(0, (Ch-1, Cw-1))])
    INF = 10**12
    costs = [[INF]*W for _ in range(H)]
    costs[Ch-1][Cw-1] = 0

    while q:
        cost, pos = q.popleft()
        h, w = pos
        for dh in range(-2, 3):
            for dw in range(-2, 3):
                if dh==0 and dw==0:
                    continue
                hh, ww = h+dh, w+dw
                if not (0<=hh<H and 0<=ww<W):
                    continue
                if l[hh][ww]:
                    continue
                
                if ((abs(dh)==1 and dw==0) or (dh==0 and abs(dw)==1)) and costs[hh][ww] > costs[h][w]:
                    costs[hh][ww] = costs[h][w]
                    q.appendleft((cost, (hh, ww)))
                elif costs[hh][ww] > costs[h][w]+1:
                    costs[hh][ww] = costs[h][w]+1
                    q.append((cost+1, (hh, ww)))

    ans = costs[Dh-1][Dw-1]
    print(ans if ans!=INF else -1)


solve()


Measured memory_bytes: 122512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lld", &i);
    sort(v.begin(),v.end());
    ll ng = -INF<ll>, ok = INF<ll>;
    while(ok-ng > 1){
        ll mid = ng+(ok-ng)/2;
        ll cnt = 0;
        for (int i = 0; i < n; ++i) {
            if(v[i] > 0){
                ll ok2 = -1, ng2 = n;
                while(ng2 - ok2 > 1){
                    ll mid2 = (ok2+ng2)/2;
                    (v[i]*v[mid2] <= mid ? ok2 : ng2) = mid2;
                }
                cnt += ok2+1;
            }else if(v[i] == 0){
                cnt += (mid >= 0 ? n : 0);
            }else {
                ll ok2 = n, ng2 = -1;
                while(ok2 - ng2 > 1){
                    ll mid2 = (ok2+ng2)/2;
                    (v[i]*v[mid2] <= mid ? ok2 : ng2) = mid2;
                }
                cnt += n-ok2;
            }
            cnt -= v[i]*v[i] <= mid;
        }
        (cnt/2 < k ? ng : ok) = mid;
    }
    cout << ok << "\n";
    return 0;
}

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

int main() {
    int num;
    while (cin >> num, num) {
        vector<int> a(num);
        cin >> a[0];
        for (int i = 1; i < num; i++) {
            cin >> a[i];
            a[i] = max(a[i - 1] + a[i], a[i]);
        }
        cout << *max_element(a.begin(), a.end()) << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [ri() for _ in range(N)]
even_cnt = sum([1 for x in A if x % 2 == 0])
odd_cnt = N - even_cnt
print('first' if odd_cnt else 'second')


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int n = 0, l, m=0;
	string s;
	cin >> l >> s;
	for(char x: s){
		n += (x=='I'? 1:-1);
		m = max(m, n);
	}
	cout << m << "\n";

}


Measured memory_bytes: 256
W, H, N = [int(_) for _ in input().split()]
maxX = W
minX = 0
maxY = H
minY = 0
for _ in range(N):
    X, Y, A = [int(_) for _ in input().split()]
    if A == 1:
        minX = max(minX, X)
    elif A == 2:
        maxX = min(maxX, X)
    elif A == 3:
        minY = max(minY, Y)
    else:
        maxY = min(maxY, Y)
if maxX > minX and maxY > minY:
    print((maxX - minX) * (maxY - minY))
else:
    print(0)


Measured memory_bytes: 3064
flip = 0
front = ""
back = ""

S = input()
Q = int(input())
for _ in range(Q):
    q = input().split()
    if len(q) == 1:
        flip ^= 1
        continue
    _, f, c = q
    if not flip:
        if f == "1":
            front = c + front
        else:
            back += c
    else:
        if f == "1":
            back += c
        else:
            front = c + front

ans = front + S + back
if flip:
    ans = ans[::-1]

print(ans)

Measured memory_bytes: 4560
#include<cstdio>
#include<cstdlib>
#include<cstring>

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

Node *nil;

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

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

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while ( 1 ) {
		if ( cur == nil ) break;
		if ( isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

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(listSearch(key));
}

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

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++ ) {
		scanf("%s%d", com, &key);
		if ( com[0] == 'i' ) { insert(key); np++; size++; }
		else if ( com[0] == 'd' ) {
			if ( strlen(com) > 6 ) {
				if ( com[6] == 'F' ) deleteFirst();
				else if ( com[6] == 'L' ) deleteLast();
			} else {
				deleteKey(key); nd++;
			}
			size--;
		}
	}

	printList();

	return 0;
}


Measured memory_bytes: 33984
#include <iostream>
#include<algorithm>
#include<string>
#include <stdio.h>
#include <stdbool.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define cerear(v) memset(v,0,sizeof(v))
#define FOR(i,a,b)      for(int i = (a) ; i < int(b) ;i++)
#define REVFOR(i,a,b)   for(int i = (a) ; i >= int(b) ;i--)
#define FORSW(i,a,b,sw) for(int i = a ; i < b && sw;i++)
#define QUE puts("0_0")
#define pu insert
#define run auto
#define ll long long
///////////////===========================/////////////////

int main(){
string str1;
string str2;
cin>>str1;
cin>>str2;
if(str2.size()==str1.size()+1){
	bool sw=true;
	for(int i=0;i<str1.size()&&sw;i++){
		if(str1[i]!=str2[i])sw=false;
	}
	if(sw){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}
else{
	cout<<"No";
}
    return 0;

}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f;
	string s;
	cin>>s;ll sum=0;i=0;
	while(i<s.length()){
	    sum+=s[i]-'0';sum%=9;i++;}
	if(sum==0)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
const int maxn=1e5+10;
int a[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	char c='1';
	char b;
	int num=0;
	for(int i=1;i<=n;i++){
		scanf(" %c",&b);
		if(b!=c){
			c=b;
			num++;
		}
	}
	printf("%d\n",num);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int n,T; cin >> n >> T;
  vi a(n),b(n);
  rep(i,n) cin >> a[i] >> b[i];

  vvi dp1(n+1,vi(T+1,0));
  vvi dp2(n+1,vi(T+1,0));
  rep(i,n) rep(t,T+1) {
    dp1[i+1][t] = dp1[i][t];
    if(t >= a[i]) chmax(dp1[i+1][t], dp1[i][t-a[i]] + b[i]);
  }
  for(int i = n-1; i >= 0; i--) rep(t,T+1) {
    //cout << i << " " << t << endl;
    //cout << dp2[i][t] << endl;
    dp2[i][t] = dp2[i+1][t];
    if(t >= a[i]) chmax(dp2[i][t], dp2[i+1][t-a[i]] + b[i]);
  }


  int ans = 0;
  rep(i,n) rep(t,T) chmax(ans, dp1[i][t] + dp2[i+1][T-1-t] + b[i]);
  cout << ans << endl;
}

Measured memory_bytes: 70912
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <map>

constexpr size_t di[]={size_t(-1), 0, 1, 0};
constexpr size_t dj[]={0, size_t(-1), 0, 1};

void dfs(std::vector<std::vector<intmax_t>>& g, size_t i, size_t j) {
  assert(g[i][j] != -1);
  intmax_t c = g[i][j];
  g[i][j] = -1;

  size_t m = g.size();
  for (size_t k=0; k<4; ++k) {
    size_t ni = i+di[k];
    size_t nj = j+dj[k];
    if (!(ni < m && nj < m)) continue;
    if (g[ni][nj] != c) continue;
    dfs(g, ni, nj);
  }
}

int comps(std::vector<std::vector<intmax_t>> g) {
  size_t m = g.size();
  int res = 0;
  for (size_t i=0; i<m; ++i)
    for (size_t j=0; j<m; ++j)
      if (g[i][j] > -1) {
        dfs(g, i, j);
        ++res;
      }

  return res;
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);

  if (n == 0) return 1;

  std::vector<int> L(n), T(n), R(n), B(n);
  std::map<int, int> X, Y;
  for (size_t i=0; i<n; ++i) {
    scanf("%d %d %d %d", &L[i], &T[i], &R[i], &B[i]);
    X.emplace(L[i], 0);
    X.emplace(R[i], 0);
    Y.emplace(B[i], 0);
    Y.emplace(T[i], 0);
  }

  {
    int x = 0;
    for (auto& p: X) p.second = ++x;
  }
  {
    int y = 0;
    for (auto& p: Y) p.second = ++y;
  }

  size_t m = 2*(n+1);
  std::vector<std::vector<intmax_t>> g(m, std::vector<intmax_t>(m));
  for (size_t i=0; i<n; ++i) {
    int l = X[L[i]];
    int t = Y[T[i]];
    int r = X[R[i]];
    int b = Y[B[i]];
    intmax_t mask = intmax_t(1) << i;

    for (int x=l; x<r; ++x)
      for (int y=b; y<t; ++y)
        g[x][y] |= mask;
  }

  printf("%d\n", comps(g));
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 3548
#include <iostream>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>

#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;



int main() {
	int a;
	string s;
	cin >> a>>s;
	if (3200 <= a)cout << s;
	else cout << "red" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int x, y;
  cin >> x >> y;
  int ans1 = 0, ans2 = 0;
  if (x == 3) {
    ans1 = 100000;
  } else if (x == 2) {
    ans1 = 200000;
  } else if (x == 1) {
    ans1 = 300000;
  }
  if (y == 3) {
    ans2 = 100000;
  } else if (y == 2) {
    ans2 = 200000;
  } else if (y == 1) {
    ans2 = 300000;
  }
  int ans = ans1 + ans2;
  if (x == 1 && y == 1) {
    ans += 400000;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
	int n;
	int debt;
	float Interest;
	int i;
	
	debt = 100000;

	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		Interest = 0;
		Interest = debt * 0.05;
		
		debt += Interest;
		
		if (debt % 1000 != 0){
			debt += (1000-(debt % 1000));
		}
	}
	
	printf("%d\n", debt);
	
	return (0);
}

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

int main() {
  int n;
  cin>>n;
  vector<ll> A(110);
  for(int i=1; i<=n; i++){
    int a;
    cin>>a;
    A.at(i)=a;
  }
  int max_d=0;
  for(int i=1; i<=n; i++){
    for(int j=i+1; j<=n; j++){
      int now_d=0;
      now_d=abs(A.at(i)-A.at(j));
      max_d=max(max_d,now_d);
    }
  }
  cout<<max_d<<endl;
}

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

using namespace std;

typedef long long LL;
typedef pair<int,int> pi;
typedef vector<int> vi;
#define ST first
#define ND second
#define PB push_back
#define DET(a,b,c) (LL(b.x-a.x)*LL((c.y-a.y))-LL((c.x-a.x))*LL((b.y-a.y)))

const int MAXN = 3010;
const LL INF = (LL)1000*1000*1000*1000*1000*1000;
int n,a[MAXN];
LL dp[MAXN][MAXN];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1; i<=n;i++) {
        cin>>a[i];
        if(n%2==0) {
            dp[i][i] = -a[i];
        }else {
            dp[i][i] = a[i];
        }
    }
    for(int len = 2; len<=n; len++) {
        for(int i=1; i<=n;i++) {
            int j = i+len-1;
            if(j>n) {
                continue;
            }
            if((n-len)%2==1) {
                dp[i][j] = min(dp[i+1][j]-a[i],dp[i][j-1]-a[j]);
            } else {
                dp[i][j] = max(dp[i+1][j]+a[i],dp[i][j-1]+a[j]);
            }
        }
    }
    cout<<dp[1][n];
}


Measured memory_bytes: 70016
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
vector<int>gg;
int k;
int dp[100001];
int solve(int x)
{
  if(x>=gg.size())return INF;
  if(x==gg.size()-1)return 0;
  if(dp[x]!= -1)return dp[x];
  int ans = INF;
  for (int i = 1; i <= k; ++i)
  {
    ans = min(ans,abs(gg[x+i]-gg[x])+solve(x+i));
  }
  return dp[x]=ans;
}
int main()
{
  // flash;
  int x;
  cin>>x>>k;
  memset(dp,-1,sizeof dp);
  for (int i = 0; i < x; ++i)
  {
    int j;cin>>j;gg.pb(j);
  }
  cout<<solve(0);
  return 0;
}

Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
 
int main() {
  int n,m;
  while(cin >> n && n) {
    int h[n];
    for(int i=0; i<n; i++) cin >> h[i];
    cin >> m;
    vector<P> a,b;
    string name,t;
    for(int i=0; i<m; i++) {
      P c;
      cin >> name >> c.first >> t >> c.second;
      if(t=="All") a.push_back(c);
      else b.push_back(c);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int da[100001],db[100001];
    fill(da,da+100001,1<<29);
    fill(db,db+100001,1<<29);
    da[0]=db[0]=0;
    for(int i=0; i<a.size(); i++) {
      for(int j=0; j<100001; j++) da[min(100000,j+a[i].second)]=min(da[min(100000,j+a[i].second)],da[j]+a[i].first);
    }
    for(int i=0; i<b.size(); i++) {
      for(int j=0; j<100001; j++) db[min(100000,j+b[i].second)]=min(db[min(100000,j+b[i].second)],db[j]+b[i].first);
    }
    for(int i=99999; i>=0; i--) {
      da[i]=min(da[i],da[i+1]);
      db[i]=min(db[i],db[i+1]);
    }
    int ans=1<<29;
    for(int i=0; i<=100000; i++) {
      int d=da[i];
      if(d==1<<29) continue;
      bool f=1;
      for(int j=0; j<n; j++) {
        int x=max(0,h[j]-i);
	if(db[x]>=1<<29) f=0;
        d+=db[x];
      }
      if(f) ans=min(ans,d);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2000
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
//QAQ

//   ^--^
//  (*-_-)
//   --~-	
//  / ":"\
// /  ":"\

int main()
{
	//freopen("tt.txt","r",stdin);
	int x,y;
	cin>>x>>y;
	if(x%y)
	{
		cout<<x;
	}
	else
	cout<<-1;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100005

typedef struct pro{
  char name[10];
  int time;
}PROCESS;

void enqueue(PROCESS );
PROCESS dequeue();


PROCESS QUEUE[N];

int head = 0,tail;

int main()
{
  int num,q,cnt,t = 0,j = 0;
  scanf("%d%d",&num,&q);
  for(int i = 0; i < num; i++){
    scanf("%s%d",QUEUE[i].name,&QUEUE[i].time);
  }
  tail = num;
  while(cnt != num){
    if(QUEUE[head].time > q){
      QUEUE[head].time -= q;
      t+=q;
      enqueue(dequeue());
    }
    else {
      t += QUEUE[head].time;
      printf("%s %d\n",QUEUE[head].name,t);
      dequeue();
      cnt++;
    }
  }
  return 0;
}

void enqueue(PROCESS x){
  QUEUE[tail] = x;
  tail = (tail+1)%N;
}

PROCESS dequeue(){
  PROCESS tmp;
  tmp = QUEUE[head];
  head = (head+1)%N;
  return tmp;
}



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

int main() {
	int N, ans = 0;
	cin >> N;
	vector<string> s(N);
	for (string& i : s) cin >> i;
	for (string& i : s) {
		for (int j = 0; j < i.size() - 1; ++j) {
			if (i[j] == 'A' && i[j + 1] == 'B') ++ans;
		}
	}
	int A = 0, B = 0, AB = 0;
	for (string& i : s) {
		if (i[0] == 'B' && i[i.size() - 1] == 'A') ++AB;
		else if (i[0] == 'B') ++B;
		else if (i[i.size() - 1] == 'A') ++A;
	}
	if (AB > 0) {
		ans += AB - 1;
		if (A > 0) {
			++ans;
			--A;
		}
		if (B > 0) {
			++ans;
			--B;
		}
	}
	ans += min(A, B);
	cout << ans;
}

Measured memory_bytes: 768
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	int W,a,b;
	cin>>W>>a>>b;
	int dis1=b-(a+W),dis2=a-(b+W);
	
	cout<<(dis1>0?dis1:(dis2>0?dis2:0))<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int i,j,n;
        cin>>n;
        double p[n+1];
        for(i=1;i<=n;i++)
        {
            cin>>p[i];
        }
        double v[n+1][n+1];
        memset(v,0.0,sizeof v);
        v[0][0]=1;
        double ans=0;
        for(i=1;i<=n;i++)
        {
            for(j=0;j<=i;j++)
            {
                if (j==0) v[i][j] = v[i-1][j]*(1-p[i]);
                else v[i][j] = v[i-1][j]*(1-p[i]) + v[i-1][j-1]*p[i];
            }
        }
        for(i=(n+1)/2;i<=n;i++)
        {
            ans+=v[n][i];
        }
        cout<<fixed<<setprecision(9)<<ans<<"\n";
    
    
    return 0;
}

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

int main() {
    //input
    string a,b,c;
    cin >> a >> b >> c;
    if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0)){
        cout << "YES";
    }else{
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, m, sum=0, out=0;
  cin >> n>> m;
  int A[n];

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

  for(int i=0; i<n;i++)
  {
    if((float)A[i]>=((float)sum/(4*m))) out++;
  }

  if(out>=m) cout << "Yes" <<endl;
  else cout << "No" <<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
const int MAXX=200010;
long long a[MAXX];
long long sum[MAXX];
int n;
long long ans=0x3f3f3f3f;
long long minnn1=0x3f3f3f3f;
long long maxxx1=0;
long long minnn2=0x3f3f3f3f;
long long maxxx2=0;
inline void solve(int L,int R,int v){
	int l=L;
	int r=R;
	if(l>r)return ;
    while(l+1<r){
    	int mid=(l+r)>>1;
        if(sum[mid]-sum[L-1]>(sum[R]-sum[mid]))r=mid;
        else l=mid;
    }
    if(v==1){
    if(abs(sum[l]-sum[L-1]-(sum[R]-sum[l]))<abs(sum[r]-sum[L-1]-(sum[R]-sum[r]))){
      minnn1=min(sum[l]-sum[L-1],sum[R]-sum[l]);
      maxxx1=max(sum[l]-sum[L-1],sum[R]-sum[l]);
    }
    else {
    	minnn1=min(sum[r]-sum[L-1],sum[R]-sum[r]);
    	maxxx1=max(sum[r]-sum[L-1],sum[R]-sum[r]);
      }
    }
    else {
    	if(abs(sum[l]-sum[L-1]-(sum[R]-sum[l]))<abs(sum[r]-sum[L-1]-(sum[R]-sum[r]))){
      minnn2=min(sum[l]-sum[L-1],sum[R]-sum[l]);
      maxxx2=max(sum[l]-sum[L-1],sum[R]-sum[l]);
    }
    else {
    	minnn2=min(sum[r]-sum[L-1],sum[R]-sum[r]);
    	maxxx2=max(sum[r]-sum[L-1],sum[R]-sum[r]);
      }
    }
}
int main(){
   scanf("%d",&n);
   for(int i=1;i<=n;++i){
   	cin>>a[i];
    sum[i]=sum[i-1]+a[i];
    }
    for(int i=1;i<=n;++i){
    	if(i<2||n-i<2)continue;
    	minnn1=0x3f3f3f3f;
    	maxxx1=0;
    	minnn2=0x3f3f3f3f;
    	maxxx2=0;
    	solve(1,i,1);
    	solve(i+1,n,0);
    	ans=min(max(maxxx1,max(maxxx2,max(minnn1,minnn2)))-min(maxxx2,(min(maxxx1,min(minnn1,minnn2)))),ans);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3328