akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#define DEBUG 0
typedef long long LL;

struct Node {
  int index = -1;
  int num_inflow;
  std::vector<int> outflow;
  LL cost = 0;
};

int main() {
  int N, M; std::cin >> N >> M;
  std::vector<Node> nodes(N);
  for (int i = 0; i < M; ++i) {
    int x, y; std::cin >> x >> y;
    --x; --y;

    nodes[y].num_inflow++;
    nodes[x].outflow.push_back(y);
  }

#if DEBUG
  for (const auto& n : nodes) {
    std::cout << n.num_inflow << ", {";
    for (int m : n.outflow) {
      std::cout << m << ", ";
    }
    std::cout << "}" << std::endl;
  }
#endif

  // Topological sort.
  std::queue<int> que;
  std::vector<int> node_indices;
  for (int i = 0; i < N; ++i) {
    if (nodes[i].num_inflow == 0) {
      que.push(i);
    }
  }

  while(!que.empty()) {
    int index = que.front();
    que.pop();
    node_indices.push_back(index);
    const auto& n = nodes[index];

    for (int i : n.outflow) {
      --nodes[i].num_inflow;
      if (nodes[i].num_inflow == 0) que.push(i);
    }
  }

  for (int i : node_indices) {
    const auto& n = nodes[i];
    for (int i : n.outflow) {
      nodes[i].cost = std::max(nodes[i].cost, n.cost + 1);
    }
  }

  LL max_cost = 0;
  for (const auto& n : nodes) {
    max_cost = std::max(max_cost, n.cost);
#if DEBUG
    std::cout << n.cost << std::endl;
#endif
  }
  std::cout << max_cost << std::endl;
}


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

int n, A[50];

int solve(int i, int m) {
  if (m == 0) return 1;
  if (i >= n) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main() {
  int q, M, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &M);
    if (solve(0, M))
      printf("yes\n");
    else
      printf("no\n");
  }

  return 0;
}


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

int main()
{
	int N;
	cin >> N;
	int A,B;
	cin >> A >> B;
	int P, P_1 = 0, P_2 = 0, P_3 =0;
	for(int i=0; i<N; i++){
		cin >> P;
		
		if (P <= A) {
			P_1 += 1;
		}else if(A+1 <= P && P <= B){
			P_2 += 1;
		}else if(B+1 <= P){
			P_3 += 1;
		}
		
	}
	cout << min(P_1,min(P_2,P_3)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  string s;cin >> s;
  int len = s.length();
  int mi = 1000;
  rep(i,len-2){
    int a = s[i]-'0';int b = s[i+1]-'0';
    int c = s[i+2]-'0';
    int tmp  = a*100+b*10+c;
    mi = min(abs(753-tmp), mi);

  }

  cout << mi << endl;
  return 0;
}

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

int main(){
  int N,M,a,b;
  cin >> N >> M;
  vector<int> town(N);
  for(int i=0;i<M;i++){
    cin >> a >> b;
    town.at(a-1)++;
    town.at(b-1)++;
  }
  for(int i=0;i<N;i++)
    cout << town.at(i) << endl;
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> ws(h);
    for (auto &s : ws) cin >> s;
    vector<vector<int>> f(h, vector<int>(w, 0));
    rep(r, 0, h) rep(c, 0, w) if (ws[r][c] == '#') {
        rep(i, -1, 2) rep(j, -1, 2) {
            int u = r + i, v = c + j;
            if (u < 0 || u >= h || v < 0 || v >= w) continue;
            ++f[u][v];
        }
    }
    rep(r, 0, h) {
        rep(c, 0, w) if (ws[r][c] == '#') cout << '#';
        else cout << char('0' + f[r][c]);
        cout << '\n';
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.min

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

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

fun solve() {
    val (h, w) = readIntegerList()
    val aList = Array(h) { br.readLine()!! }
    out.println("#".repeat(w + 2))
    for (r in aList) {
        out.print("#")
        out.print(r)
        out.println("#")
    }
    out.println("#".repeat(w + 2))
}

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


Measured memory_bytes: 36424
//============================================================================
// Name        : Hello5.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;//<key,value>


int main() {
int n,m;
cin>>n>>m;
if(n==m)
	cout<<"Yes"<<endl;
else{
	cout<<"No"<<endl;
}
return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int main(){
  int n,m;cin>>n>>m;
  pair<int,int> d[100000];
  rep(i,m){
    int a,b;cin>>a>>b;
    d[i] = make_pair(a,b);
  }
  sort(d,d+m);
  int ans = 0;
  int pre_tail = 0;
  rep(i,m){
    if(d[i].first >= pre_tail){
      ans++;
      pre_tail = d[i].second;
    }else if(d[i].second < pre_tail)pre_tail = d[i].second;
  }
  cout << ans << endl;
}



Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int aa = sc.nextInt();
		int bb = sc.nextInt();
		int cc = sc.nextInt();
		int dd = sc.nextInt();
		int ee = sc.nextInt();
		int ff = sc.nextInt();
		int maxSugar = 0;
		int maxWater = 0;
		double max = -1;
		for (int a = 0; 100 * a * aa <= ff; a++) {
		    for (int b = 0; 100 * (a * aa + b * bb) <= ff; b++) {
		        for (int c = 0; 100 * (a * aa + b * bb) + c * cc <= ff && (a * aa + b * bb) * ee >= c * cc; c++) {
		            for (int d = 0; 100 * (a * aa + b * bb) + c * cc + d * dd <= ff && (a * aa + b * bb) * ee >= c * cc + d * dd; d++) {
		                int sugar = c * cc + d * dd;
		                int water = 100 * (a * aa + b * bb);
		                if (max < (double)sugar / (sugar + water)) {
		                    max = (double)sugar / (sugar + water);
		                    maxSugar = sugar;
		                    maxWater = water;
		                }
		            }
		        }
		    }
		}
        System.out.println((maxSugar + maxWater) + " " + maxSugar);
	}
}


Measured memory_bytes: 21844
s=input()
n=0
ans=0
while n<2**(len(s)-1):
    p=0
    for i in range(len(s)-1):
        if n&(1<<i):
            ans+=int(s[p:i+1])
            p=i+1
    if p<len(s):
        ans+=int(s[p:])
    n+=1
print(ans)



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

int	main() {
	int	size;
  	cin >> size;
  	vector<int> nums(size);
  	for (int i=0;i<size;i++) cin >> nums.at(i);
  
  	//sort
  	sort(nums.begin(), nums.end());
      
    // check if same
    int	flg;
    flg = 0;
    for (int i=0;i<size-1;i++) {
    	if (nums.at(i) == nums.at(i+1)) {
          flg = 1;
        }
    }

    
    if (flg==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.buffer.readline

n,t = map(int,readline().split())

dp = [0]*(t+1)

AB = [list(map(int,readline().split())) for i in range(n)]
AB.sort(reverse=True)
for i in range(n):
    a,b = AB[i]
    for j in range(t):
        if j+a > t:
            dp[j] = max(dp[j],b)
        else:
            dp[j] = max(dp[j],dp[j+a]+b)

print(dp[0])

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

const int MOD = 1e9+7;

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

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

  vector< vector<int> > dp(n+1,vector<int> (k+1,0));
  //i番目までにj個の飴を配る場合の数
  dp[0][0] = 1;
  for(int i = 0; i < n; i++){
    vector<int> b(k+2,0); //累積和
    for(int j = 0; j <= k; j++){
      b[j+1] += b[j] + dp[i][j];
      b[j+1] %= MOD;
    }

    for(int j = 0; j <= k; j++){
      dp[i+1][j] += b[j+1] - b[max(0LL,j - a[i])] + MOD;
      dp[i+1][j] %= MOD;
    }
  }
  cout << dp[n][k] << endl;

  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

bool used[51][51][51][51];
int roomL[51][51], roomR[51][51];

inline int s_to_i(char c) {
  switch (c) {
  case '#':
    return -1;
  case '.':
    return 0;
  case 'L':
  case 'R':
    return 1;
  case '%':
    return 2;
  }
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    int R, C;
    cin >> C >> R;
    if (R == 0 && C == 0) break;
    REP(i, R) {
      string rowL, rowR;
      cin >> rowL >> rowR;
      REP(j, C) {
	roomL[i][j] = s_to_i(rowL[j]);
	roomR[i][j] = s_to_i(rowR[j]);
      }
    }	  

    int slr = 0, slc = 0, elr = 0, elc = 0, srr = 0, src = 0, err = 0, erc = 0;
    REP(r, R) REP(c, C) {
      if (roomL[r][c] == 1) slr = r, slc = c;
      else if (roomL[r][c] == 2) elr = r, elc = c;
      if (roomR[r][c] == 1) srr = r, src = c;
      else if (roomR[r][c] == 2) err = r, erc = c;
    }
    //cout << slr << ' ' << slc << ' ' << elr << ' ' << elc << ' ' << srr << ' ' << src << ' ' << err << ' ' << erc << endl;
    REP(i, R) REP(j, C) REP(k, R) REP(l, C) used[i][j][k][l] = false;
    
    queue<P> que;
    que.push(P(slr * C + slc, srr * C + src));

    bool flag = false;
    while (!que.empty()) {
      P p = que.front(); que.pop();
      int lr = p.first / C, lc = p.first % C, rr = p.second / C, rc = p.second % C;
      //cout << lr << ' ' << lc << ' ' << rr << ' ' << rc << endl;
      if (lr == elr && lc == elc && rr == err && rc == erc) {
	flag = true;
	break;
      } else if (used[lr][lc][rr][rc] || (lr == elr && lc == elc) || (rr == err && rc == erc)) {
	continue;
      }

      used[lr][lc][rr][rc] = true;
      REP(i, 4) {
	int nlr = lr + dr[i], nlc = lc + dc[i], nrr = rr + dr[(i+2*(i&1))%4], nrc = rc + dc[(i+2*(i&1))%4];
	if (nlr < 0 || nlr >= R || nlc < 0 || nlc >= C || roomL[nlr][nlc] == -1) nlr = lr, nlc = lc;
	if (nrr < 0 || nrr >= R || nrc < 0 || nrc >= C || roomR[nrr][nrc] == -1) nrr = rr, nrc = rc;
	if (!used[nlr][nlc][nrr][nrc]) que.push(P(nlr * C + nlc, nrr * C + nrc));
      }
    }
    cout << (flag ? "Yes" : "No") << endl;    
  }
  return 0;
}

Measured memory_bytes: 10316
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s;
    int i = 0, j = 0, x = 0, a = 0, b = 0, y = 0;
    cin >> s;
    for(i = 1; i < s.size(); i++)
    {
        if(s[i] == s[0])
        {

            a = i;
            while(x < i)
            {
                if(s[a] != s[x])
                {
                    b = 1;
                }
                a++;
                x++;
            }
            if(b == 0 && i * 2 != s.size())
            {
                y = i;
            }
        }
        x = 0;
        b = 0;
    }

        cout << y * 2;



return 0;
}

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

struct VAL{
    int v0, v1;
}finf;
VAL operator + (const VAL &a,int b){
    if (b&1) return {a.v1+b,a.v0+b};
    else return {a.v0+b,a.v1+b};
}
VAL Max(const VAL &a,const VAL &b){
    return (VAL){max(a.v0,b.v0),max(a.v1,b.v1)};
}
struct TR{
    int lc, rc; VAL v;
}tr[10001000], nil; int cntr;

void U(int x){
    tr[x].v=Max(tr[tr[x].lc].v,tr[tr[x].rc].v);
}
void add(int &x,int y,int l,int r,int p,VAL v){
    x=++cntr; tr[x]=tr[y];
    if (l==r){
        tr[x].v=v;
        return;
    }
    int mid=l+r>>1;
    if (p<=mid) add(tr[x].lc,tr[y].lc,l,mid,p,v);
    else add(tr[x].rc,tr[y].rc,mid+1,r,p,v);
    U(x);
}
VAL que(int x,int l,int r,int p){
   if (r<=p) return finf;
   if (l>p) return tr[x].v;
   int mid=l+r>>1;
   return Max(que(tr[x].lc,l,mid,p),que(tr[x].rc,mid+1,r,p)); 
}
VAL query(int x,int l,int r,int p){
    return Max(que(x,l,r,p),(VAL){0,(int)-1e9-1});
}

int n, a[202000], fl[202000], rt[202000], suf[202000];

bool chk(int i,int mx1,int mx2,int c1,int c2){
    int aim=c1+suf[i]-c2;
    if (aim<0) return 0;
    return (aim&1? query(rt[i],1,n,mx2).v1: query(rt[i],1,n,mx2).v0) >= aim;
}
bool check(int i,int mx1,int mx2,int c1,int c2){
    return chk(i,mx1,mx2,c1,c2)||chk(i,mx2,mx1,c2,c1);
}

int main(){
    finf.v0=-1e9, finf.v1=-1e9-1; tr[0].v=nil.v=finf;
    cin>>n; int mx=0;
    for (int i=1;i<=n;++i){
        cin>>a[i];
        if (a[i]>mx) mx=a[i], fl[i]=1;
    }
    for (int i=n;i>=1;--i){
        add(rt[i],rt[i+1],1,n,a[i],query(rt[i+1],1,n,a[i])+fl[i]+1);
        suf[i]=suf[i+1]+fl[i];
    }
    vector<int>ans;
    int las1=0, las2=0, c1=0, c2=0, nex1, nex2;
    for (int i=1;i<=n;++i){
        nex1=max(las1,a[i]), nex2=las2;
        if (check(i+1,nex1,nex2,c1+(nex1>las1),c2+(nex2>las2))){
            ans.push_back(0);
            c1+=nex1>las1; c2+=nex2>las2;
            las1=nex1; las2=nex2;
            continue;
        }
        nex1=las1, nex2=max(las2,a[i]);
        if (check(i+1,nex1,nex2,c1+(nex1>las1),c2+(nex2>las2))){
            ans.push_back(1);
            c1+=nex1>las1; c2+=nex2>las2;
            las1=nex1; las2=nex2;
            continue;
        }
        puts("-1"); exit(0);
    }
    for (auto o:ans) cout<<o; puts("");
}

Measured memory_bytes: 64888
#include<bits/stdc++.h> 
using namespace std;
const int N=3e5+5;
int n,s[N];
long long ans;
void in(){
    int i;
    cin>>n;
    for(i=1;i<=2*n;++i) cin>>s[i];
    sort(s+1,s+2*n+1);}
void wo(){
    int i;
    for(i=1;i<=2*n;++i) ans+=1LL*(i-1)*s[i];
    printf("%.12lf\n",1.0*ans/(2*n-1));}
int main(){
    in();
    wo();
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using p  = pair<int, int>;
using vec_int = vector<int>;
using vec_str = vector<string>;
#define INF (1<<29)
ll ans = 0;

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}

void debug_input(vec_str& argv)
{
    // デバッグ用引数読み込み
    ifstream file("./input.txt");
    string str;
    while( getline(file, str) ) {
        argv.push_back(str);
    }
}

void debug_split_string(const string& str, vec_str& v)
{
    stringstream ss{str};
    string buf;
    while (getline(ss, buf, ' ')) {
        v.push_back(buf);
    }
}

void debug_split_int(const string& str, vec_int& v)
{
    stringstream ss{str};
    string buf;
    while (getline(ss, buf, ' ')) {
        istringstream ss(buf);
        int temp;
        ss >> temp;
        v.push_back(temp);
    }
}

int main()
{
    int A, B, C, D = 0;
	cin >> A >> B >> C >> D;

    while(1) {
        C -= B;
        if( C <= 0 ) {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if( A <= 0 ) {
            cout << "No" << endl;
            break;
        }
    }
        

    
    
    return 0;
}

Measured memory_bytes: 3640
#include <stdlib.h>
#include <stdio.h>

int maior(int a, int b){

	if (a > b)
		return a;
	else 
		return b;
}

int main(){

	int A, B, C, K, M;

	scanf("%d %d %d", &A, &B, &C);
	scanf("%d", &K);

	M = maior(maior(A, B), C);
	
	if (M == A){
		for (int i = 0; i < K; i++)
			M *= 2;
		printf("%d\n",B+C+M );
	}
	else if (M == B){
		for (int i = 0; i < K; i++)
			M *= 2;
		printf("%d\n",A+C+M );

	}
	else{
		for (int i = 0; i < K; i++)
			M *= 2;
		printf("%d\n",A+B+M );

	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(b-c>=0)cout<<"delicious"<<endl;
	else if(b-c <0 && c-b<= a)cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
			return 0;
}

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

flag = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    if a==b:continue
    if h[a] > h[b]:
        flag[b] = -1
    elif h[a] == h[b]:
        flag[a] = -1
        flag[b] = -1
    else:
        flag[a] = -1
        
cnt = 0
for i in range(n):
    if flag[i] != -1:
        cnt += 1
print(cnt)

Measured memory_bytes: 20088
N ,M = map(int, input().split())
A_list = [int(i) * (-1) for i in input().split()]


import heapq

heapq.heapify(A_list)
for i in range(M):
    x = heapq.heappop(A_list)
    heapq.heappush(A_list, (-1)*(-x//2))

print(-sum(A_list))

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

int a[205];
int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=(n<<1);i++){
		scanf("%d",&a[i]);	
	}
	sort(a+1,a+1+n*2);
	for(int i=1;i<=n;i++){
		ans+=a[i*2-1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n;

int w[100][100];

int WHITE = 0;
int GRAY = 1;
int BLACK = 2;

int INFTY = 10000;

int color[100];
int d[100];
int p[100];

int prim() {
  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    d[i] = INFTY;
  }

  d[0] = 0;
  p[0] = -1;
  int u;

  int sum = 0;

  while(1) {
    int mincost = INFTY;
    for (int i = 0; i < n; i++) {
      if (color[i] != BLACK && d[i] < mincost) {
        mincost = d[i];
        u = i;
      }
    }

    if (mincost == INFTY) {
      break;
    }

    sum += mincost;

    color[u] = BLACK;
    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && w[u][v] != INFTY) {
        if(w[u][v] < d[v]) {
          d[v] = w[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }

  return sum;
}

int main() {
  cin >> n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> w[i][j];
      if(w[i][j] == -1) {
        w[i][j] = INFTY;
      }
    }
  }

  cout << prim() << endl;
}



Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include <iomanip>
#include <cmath>
#include <math.h>
#include <algorithm> 
#include <bits/stdc++.h>
#include<map>
using namespace std;
int main()
{
        vector<long int>::iterator it;
         // std::vector<long int>::iterator upper; 
 //long long long int l,r,m,i,t,a,b,n;
long long int n,t{0},l,i,d,k,x,sum{0},a,y,j,r,b,z,m{0},cnto{0},cnte{0};//diff{0};
string s,s1,s3;
long long int ans{0};
// cin>>t;
// while(t>0)
{
    vector<int>a(5);
    for(i=0;i<5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            cout<<i+1;
            break;
        }
    }
t--;
}
return 0;
}


Measured memory_bytes: 3600
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

tab = [[] for _ in range(10 ** 5)]
for Ai, Bi in AB:
    tab[Ai - 1].append(Bi)

import heapq
import bisect

# from end
ans = 0
q = []
for d_left in range(1, M + 1):
    for item in tab[d_left - 1]:
        heapq.heappush(q, -item) # pos -> neg
    if len(q) > 0: 
        ans_tmp = -(heapq.heappop(q)) # neg -> pos
        ans += ans_tmp

print(ans)

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

int main(){
    int N;
    cin>>N;
    string ans="No";
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N)ans="Yes";
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

int main (int argc, char* argv[]) {
	string s;
	cin >> s;
	int num_one = 0;
	for (auto c : s) {
		if (c == '1') {
			num_one++;
		}
	}
	cout << min((int)s.size() - num_one, num_one) * 2 << endl;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int w;
	cin >> w;
	REP(i, s.size()) {
		if (i%w == 0)cout << s[i];
	}
	cout << endl;

}

Measured memory_bytes: 256
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$m = (int)$input[1];

$ms = [];
for ($i=0; $i < $m; $i++) { 
	$input = (int)trim(fgets(STDIN));
	$ms[$input] = true;
}

if ($n === 1) {
	if (isset($ms[1])) {
		echo 0;
	}else{
		echo 1;
	}
	exit();
}

$dp = [];
$dp[0] = 1;
if (isset($ms[1])) {
	$dp[1] = 0;
	if (isset($ms[2])) {
		echo 0;
		exit();
	}else{
		$dp[2] = 1;
	}
}else{
	$dp[1] = 1;
	if (isset($ms[2])) {
		$dp[2] = 0;
	}else{
		$dp[2] = 2;
	}
}

for ($i=3; $i <= $n; $i++) { 
	if (isset($ms[$i])) {
		$dp[$i] = 0;
		continue;
	}else{
		$dp[$i] = ($dp[$i-2] + $dp[$i-1]) % 1000000007;
	}
}

echo $dp[$n];

Measured memory_bytes: 14840
import math
N,D = map(int,input().split())
cnt = 0
data = []
for i in range(N):
  list_youso = list(map(int,input().split()))
  data.append(list_youso)
for i in range(N):
  for k in range(i+1,N):
    distance = 0
    for j in range(D):
      distance += abs(data[i][j]-data[k][j])**2
    if int(math.sqrt(distance))*int(math.sqrt(distance)) == distance:
      cnt += 1
print(cnt)

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
int dp1[1<<13];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    int a[1010],b[1010];
    int pos[1010];
    cin >>N>>M;
    for(int i=0;i<M;i++){
	cin >>a[i]>>b[i];
	pos[i]=0;
	for(int j=0;j<b[i];j++){
	    int c;
	    cin >>c;
	    c--;
	    pos[i]|=(1<<c);
	}
    }
    for(int i=0;i<(1<<N);i++) dp1[i]=inf;
    dp1[0]=0;
    for(int i=0;i<M;i++){
	for(int j=0;j<(1<<N);j++){
	    if(dp1[j]!=inf){
		dp1[j|pos[i]]=min(dp1[j|pos[i]],dp1[j]+a[i]);
	    }
	}
    }
    if(dp1[(1<<N)-1]!=inf) cout <<dp1[(1<<N)-1]<<'\n';
    else cout <<"-1\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int candy;
	int n;
	
	while (scanf("%d", &candy) != EOF){
		
		n = candy % 39;
		
		if (n == 0){
			printf("3C39\n");
		}
		else if ((n >= 1) && (n <= 9)){
			printf("3C0%d\n", n);
		}
		else {
			printf("3C%d\n", n);
		}
	}
	return (0);
}

Measured memory_bytes: 608
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX_N 2000000
//配列は必ずMAX+Nより大きくとること!!!!!(配列外参照)
int prime[MAX_N+100];
void eratos(){
    for(int i=0;i<MAX_N;i++)prime[i]=1;
    prime[0]=prime[1]=0;
    for(int i=2;i*i<=MAX_N;i++)if(prime[i]){
        for(int j=i*2;j<=MAX_N;j+=i)prime[j]=0;
    }
    return;
}
int main(){
    eratos();
    int x;
    cin >> x;
    for(int i=x;i<2000000;i++){
      if(prime[i]){
        cout << i << endl;
        return 0;
      }
    }
    return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct point point;
typedef struct connection con;

typedef struct connection{
	point *conPoint;
	long long distance;
	con *nextCon;
}con;

typedef struct point{
	con *connection;
	int color;
	long long count;
}point;

void cal(point *num,con *connection){

	// if(connection->conPoint->count == -1){
	// 	connection->conPoint->count = num->count + connection->distance;
	// 	cal(connection->conPoint,connection->conPoint->connection);
	// }

	// if(connection->nextCon == NULL){
	// 	return;
	// }	
	// cal(num,connection->nextCon);



	while (connection != NULL) {
		if(connection->conPoint->count == -1){
			connection->conPoint->count = num->count + connection->distance;
			cal(connection->conPoint,connection->conPoint->connection);
		}
		connection = connection->nextCon;
	}	
}

void insert(point *p,int tempD,int tempP,int tempP2){
	con *connection = malloc(sizeof(con));
	connection->distance = tempD;
	connection->nextCon = p[tempP - 1].connection;
	p[tempP - 1].connection = connection;
	connection->conPoint = &p[tempP2 - 1];
}

int main(int argc, char **argv){
	int n = 0;
	int i = 0;
	int tempP = 0;
	int tempP2 = 0;
	int tempD = 0;
	scanf("%d",&n);
	point *node = malloc(sizeof(point) * n);

	for(i = 0;i < n;i++){
		node[i].color = 0;
		node[i].connection = NULL;
		node[i].count = -1;
	}

	for(i = 0;i < n-1;i++){
		scanf("%d%d%d",&tempP,&tempP2,&tempD);
		insert(node,tempD,tempP,tempP2);
		insert(node,tempD,tempP2,tempP);
	}

	
	node[0].count = 0;
	cal(&node[0],node[0].connection);
	
	
	
	for(i = 1;i < n;i++){
		if(node[i].count % 2 == 1){
			node[i].color = 1;
		}
	}
	

	for(i = 0;i < n;i++){
		printf("%d\n",node[i].color);
	}
}



Measured memory_bytes: 9856
a = int(input())
n3 = a//3
n5 = a//5
n15 = a//15
ans = a*(a+1)//2 - 3*n3*(n3+1)//2 - 5*n5*(n5+1)//2 + 15*n15*(n15+1)//2
print(ans)

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

int main() {
  long long int A, B, K;
  cin >> A >> B >> K;
  if (K <= A) {
    cout << A - K << " " << B << endl;
  }
  else if (K <= A + B) {
    cout << 0 << " " << A + B - K << endl;
  }
  else {
    cout << 0 << " " << 0 << endl;
  }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

struct Trie{
	struct TrieNode{
		int num, next[2];
		TrieNode(){
			num = 0;
			for(int i = 0; i < 2; i++) next[i] = -1;
		}
	};
	vector<TrieNode> vec;
	Trie(){
		init();
	}
	void init(){
		vec.clear();
		vec.push_back(TrieNode());
	}
	int seek(string &s)
	{
		int p = 0;
		for(int i = 0; i < s.size(); i++){
			int c = s[i]-'0';
			if(vec[p].next[c] == -1){
				vec.push_back(TrieNode());
				vec[p].next[c] = (int)vec.size()-1;
			}
			p = vec[p].next[c];
		}
		return p;
	}
	void insert(string &s, int x = 1)
	{
		int p = seek(s);
		vec[p].num += x;
	}
	void erase(string &s, int x = 1)
	{
		int p = seek(s);
		vec[p].num = max(0, vec[p].num - x);
	}
	int count(string &s)
	{
		int p = seek(s);
		return vec[p].num;
	}
};

llint n, L;
string s[100005];
Trie trie;
vector<llint> vec;

void dfs(int v, int d)
{
	if(trie.vec[v].next[0] == -1 && trie.vec[v].next[1] == -1) return;
	for(int i = 0; i < 2; i++){
		if(trie.vec[v].next[i] == -1) vec.push_back(L-d-1);
		else dfs(trie.vec[v].next[i], d+1);
	}
}

llint get(llint x)
{
	x++;
	llint ret = 1;
	while(x%2==0) x/=2, ret*=2;
	return ret;
}

int main(void)
{
	cin >> n >> L;
	for(int i = 1; i <= n; i++){
		cin >> s[i];
		trie.insert(s[i]);
	}
	dfs(0, 0);
	
	llint ans = 0;
	for(int i = 0; i < vec.size(); i++) ans ^= get(vec[i]);
	if(ans == 0) cout << "Bob" << endl;
	else cout << "Alice" << endl;
	
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n;

int main(){
    cin >> n;
    cout << n / 3 << endl;
}


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



int main(){
    int n;
    int ans=1;
    cin >> n;
    for(int i=1;i*i<=n;i++){
        ans=max(ans,i*i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int N, A[21], B[21], C[21];

int main() {
  std::cin >> N;
  for (int i = 1; i <= N; ++i)
    std::cin >> A[i];
  for (int i = 1; i <= N; ++i)
    std::cin >> B[i];
  for (int i = 2; i <= N; ++i)
    std::cin >> C[i];

  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans += B[A[i]];
    //std::cout << i << ": " << A[i] << ": " << B[A[i]] << "\n";
    if (i > 0 and A[i] == A[i-1] + 1) {
      ans += C[A[i]];
      //std::cout << A[i] << " " << A[i-1] << "\n";
    }
  }
  std::cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T inv[N+1];
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i = 0; i < N; i++)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i = N-1; i >= 0; i--)
            ifact[i] = (ifact[i+1]*(i+1))%M;
        inv[0] = 0;
        for (int i = 0; i < N; i++)
            inv[i+1] = (fact[i]*ifact[i+1])%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ModFact<100000, ll, MOD> fact;

ll N;

int main() {
    ll N, ans = 0, prev, now;
    N = getint();
    prev = getint();
    ll a = 0;
    REP(i, N-1) {
        now = getint();
        // cin >> now;
        a = (a + fact.inv[i+1]) % MOD;
        ans += a * (now - prev) % MOD;
        prev = now;
    }
    printf("%lld\n", ((ans%MOD)*fact.fact[N-1])%MOD);
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    string s;
    cin >> s;
    int count = 0;

    int s_len = s.length();
    if(s_len % 2 == 0) {
        int s_center = s_len / 2 - 1;
        int i = s_center;
        int j = s_center + 1;
        while(i >= 0) {
            if(s[i] != s[j]) {
                count++;
            }
            i--;
            j++;
        }
    } else {
        int s_center = s_len / 2;
        int i = s_center - 1;
        int j = s_center + 1;
        while(i >= 0) {
            if(s[i] != s[j]) {
                count++;
            }
            i--;
            j++;
        }

    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;  
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;

ll fpow(ll a, ll n) 
{
	ll ans = 1;
	while (n) 
	{
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

void solve() 
{
	int n;
	ll k;
	cin >> n >> k;
	ll arr[n];
	For(i,0,n) cin >> arr[i];
	ll low = 1, high = *max_element(arr, arr+n);
	ll ans = high;
	while (low <= high)			
	{
		ll mid = (low+high) >> 1;
		ll curr = 0;
		For(i,0,n) 
		{
			curr += arr[i]/mid;
			if (arr[i]%mid == 0) --curr;
		}
		// trace(mid,curr);
		if (curr <= k)
		{
			ans = mid;
			high = mid-1;
		}
		else low = mid+1;
	}
	cout << ans << endl;
}

int main() 
{
	fast_io();
	int t = 1;
	// cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 5188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define Pr pair<ll,ll>
#define mp make_pair
#define ll long long
using namespace std;
const int N=2*(1e5)+10;
namespace Fast{/*{{{*/
	const int LEN=10000000;
	char inp[LEN];
	int inpos,outpos;
	void init(){
		fread(inp,1,LEN,stdin);
		inpos=0; outpos=0;
	}
	char GetChar(){return inp[inpos++];}
	int read(){
		int ret=0; char ch=GetChar();
		while (ch<'0'||ch>'9') ch=GetChar();
		while ('0'<=ch&&ch<='9') ret=ret*10+ch-'0',ch=GetChar();
		return ret;
	}
}/*}}}*/
int h[N],ch[N][2],dis[N][2];
ll rec[N];
vector<Pr> f[N];
int n,tot;
ll sum,Mx;
bool cmp1(Pr x,Pr y){return x.first<y.first;}
bool cmp2(Pr x,Pr y){return x.second<y.second;}
void merge(int x){
	int lch=ch[x][0],rch=ch[x][1];
	if (f[lch].size()>f[rch].size()) swap(lch,rch);
	int lsz=f[lch].size(),rsz=f[rch].size();

	sort(f[lch].begin(),f[lch].end(),cmp2);
	sort(f[rch].begin(),f[rch].end(),cmp1);
	rec[0]=f[rch][0].second;
	for (int i=1;i<rsz;++i) rec[i]=min(rec[i-1],f[rch][i].second);
	for (int i=0,j=rsz-1;i<lsz;++i){
		while (j>=0&&f[lch][i].second+f[rch][j].first>Mx) --j;
		if (j>=0) f[x].push_back(mp(f[lch][i].first,rec[j]));
	}

	sort(f[lch].begin(),f[lch].end(),cmp1);
	sort(f[rch].begin(),f[rch].end(),cmp2);
	rec[0]=f[rch][0].first;
	for (int i=1;i<rsz;++i) rec[i]=min(rec[i-1],f[rch][i].first);
	for (int i=0,j=rsz-1;i<lsz;++i){
		while (j>=0&&f[rch][j].second+f[lch][i].first>Mx) --j;
		if (j>=0) f[x].push_back(mp(rec[j],f[lch][i].second));
	}
}
void dfs(int x){
	int u,sz;
	f[x].clear();
	if (ch[x][0]==0&&ch[x][1]==0){
		f[x].push_back(mp(0,0));
		return;
	}
	dfs(ch[x][0]);
	dfs(ch[x][1]);
	sz=f[ch[x][0]].size();
	for (int i=0;i<sz;++i) 
		f[ch[x][0]][i].first+=dis[x][0],f[ch[x][0]][i].second+=dis[x][0];
	sz=f[ch[x][1]].size();
	for (int i=0;i<sz;++i) 
		f[ch[x][1]][i].first+=dis[x][1],f[ch[x][1]][i].second+=dis[x][1];
	merge(x);
}
bool check(ll x){
	Mx=x;
	dfs(1);
	return f[1].size()>0;
}
void solve(){
	ll l=0,r=sum,mid,ans=0;
	while (l<=r){
		mid=l+r>>1;
		if (check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",ans);
}

int main(){
#ifndef ONLINE_JUDGE
	//freopen("a.in","r",stdin);
#endif
	int x,y;
	Fast::init();
	n=Fast::read();
	memset(h,-1,sizeof(h));
	tot=0; sum=0;
	for (int i=1;i<n;++i){
		x=Fast::read(); y=Fast::read();
		if (ch[x][0]) ch[x][1]=i+1,dis[x][1]=y;
		else ch[x][0]=i+1,dis[x][0]=y;
		sum+=y;
	}
	solve();
}

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

using namespace std;

using ll = long long;

int main(){
    string s; cin >> s;
    ll n = s.length();
    ll left[n + 24] = {0};
    ll right[n + 24] = {0};
    for(ll i = 0; i < n; ++i){
        if(s[i] == '<'){
            left[i + 1] = left[i] + 1; 
        }else left[i + 1] = 0;
    }
    for(ll i = n; i >= 1; --i){
        if(s[i] == '>'){
            right[i] = right[i + 1] + 1; 
        }else right[i] = 0;
    }
    ll sum = 0;
    if(s[0] == '<'){
        left[0] = 0;
    }
    else if(s[0] == '>'){
        left[0] = max(left[1], right[1]) + 1;
    }
    if(s[n - 1] == '<'){
        right[n] = max(left[n - 1], right[n - 1]) + 1;
    }
    else if(s[n - 1] == '>'){
        right[n] = 0; 
    }
    for(ll i = 0; i < n + 3; ++i){
        sum += max(left[i], right[i]);
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 11632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
 
#define rep(i,n) for(ll i=0;i<(n;i++)
typedef long long ll;
using namespace std;
 int main() {
   string S;
   cin >> S;
   if(S == "ABC") {
     cout << "ARC" << endl;
   }
   else{
     cout << "ABC" <<endl;
   }
 }

Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        L_Deque solver = new L_Deque();
        solver.solve(1, in, out);
        out.close();
    }

    static class L_Deque {
        Long[][] dp;
        int[] a;

        long go(int i, int j) {
            if (i == j)
                return a[i];
            if (dp[i][j] != null)
                return dp[i][j];
            long res = Math.max(a[i] - go(i + 1, j), a[j] - go(i, j - 1));
            dp[i][j] = res;
            return res;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();

            a = in.na(n);
            dp = new Long[n][n];
            long ans = go(0, n - 1);
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public int[] na(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = ni();
            return a;
        }

    }
}



Measured memory_bytes: 226836
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

char c[14][14];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

int belong[14][14];
int ok[10000];
int gx,gy;

int ans = 0;
int ccc = 0;
void dfs(int x,int y,int C,int px,int py){
  if( c[y][x] == '#' || c[y][x] == '*') return;
  if( C + abs(x-gx) + abs(y-gy) >= ans ) return;
  if( c[y][x] == 'G'){
    ans = C;
    return;
  }
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( px == tx && ty == py ) continue;
    if( c[ty][tx] == '*' ) return;
  }
  char cur = c[y][x];
  c[y][x] = '*';
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( c[ty][tx] == 'X' ){
      int b = belong[ty][tx];
      if( ok[b] > 0 ){
	ok[b]--;
	dfs(tx,ty,C+1,x,y);
	ok[b]++;
      }
    }else{
      dfs(tx,ty,C+1,x,y);
    }
  }
  c[y][x] = cur;
  return;
}
void grouping(int x,int y,int k){
  if( c[y][x] != 'X') return;
  if( belong[y][x] != -1 ) return;
  belong[y][x] = k;
  ccc++;
  for(int i = 0 ; i < 4 ; i++)
    grouping(x+dx[i],y+dy[i],k);
}

int main(){
  ios_base::sync_with_stdio(false);
  int W,H;
  while(cin >> W >> H && W){
    rep(i,14)rep(j,14) belong[i][j] = -1;
    rep(i,14)rep(j,14) 
      c[i][j] = '#';
    int sx , sy;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cin >> c[i+1][j+1];
	if(c[i+1][j+1] == 'S'){
	  c[i+1][j+1] = '.';
	  sx = j+1 , sy = i+1;
	}else if(c[i+1][j+1] == 'G' ){
	  gx = j+1 , gy = i+1;
	}
      }
    }
    int k = 0;
    for(int i = 1 ; i <= H ; i++){
      for(int j = 1 ; j <= W ; j++){
	if( c[i][j] == 'X' && belong[i][j] == -1){
	  ccc = 0;
	  grouping(j,i,k);
	    ok[k] = ccc / 2;
	    k++;
	}
      }
    }
    ans = 1e7;
    dfs(sx,sy,0,-1,-1);
    cout << ans << endl;
    
  }
}

Measured memory_bytes: 1200
#include<cstdio>
#include<algorithm>
int a[200000], b[200000];
int main() {
	int n, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	std::sort(b, b + n);
	for (i = 0; i < n; i++) {
		if (a[i] <= b[n / 2 - 1]) printf("%d\n", b[n / 2]);
		else printf("%d\n", b[n / 2 - 1]);
	}
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

// d[u][v]は辺e = (u, v)のコスト（存在しない場合はINF、ただしd[i][i] =
// 0とする。） Vは頂点数
void warshall_floyd(vector<vector<ll>> &d, ll V) {
    for(ll k = 0; k < V; k++) {
        for(ll i = 0; i < V; i++) {
            for(ll j = 0; j < V; j++) {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, l, q;
    cin >> n >> m >> l;
    // ワーシャルフロイドで全点間の最短距離を求める
    vector<vector<ll>> d1(n, vector<ll>(n, LLINF));
    for(ll i = 0; i < n; i++) {
        d1[i][i] = 0;
    }
    for(ll i = 0; i < m; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        d1[a][b] = c;
        d1[b][a] = c;
    }
    warshall_floyd(d1, n);
    // 次に、2頂点間の最短距離がL以下のもの同士にコスト1の辺を張る
    vector<vector<ll>> d2(n, vector<ll>(n, LLINF));
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j < n; j++) {
            if(i == j) {
                d2[i][j] = 0;
            } else if(d1[i][j] <= l && d1[j][i] <= l) {
                d2[i][j] = d2[j][i] = 1;
            }
        }
    }
    warshall_floyd(d2, n);
    cin >> q;
    while(q--) {
        ll s, t;
        cin >> s >> t;
        s--;
        t--;
        cout << (d2[s][t] == LLINF ? -1 : d2[s][t] - 1) << endl;
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, l, a=IINF, ans = 0, b = 0;
    cin >> n >> l;
    for(int i=0;i<n;i++){
        ans += l+i;
        if(a > abs(l+i)){
            a = abs(l+i);
            b = l+i;
        }
    }
    cout << ans - b << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)

#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long ll;
const int N = 1e5+1 , M = 5e5+1, OO = 0x3f3f3f3f,MOD = 1e9+7;
int arr[4]={-1,-1,-1,-1};
int main()
{
  int n,m;
  bool f=1;
  scanf("%d%d",&n,&m);  
  while(m--)
  {
    int x,y;
    scanf("%d%d",&x,&y);
    if(!~arr[x] || arr[x]==y) arr[x]=y;
    else f=0;
  }
  if(!f || (!arr[1] && n>1)) puts("-1");
  else
  {
    
    if(!~arr[1])
    {
      if(n>1) printf("1");
      else printf("0"); 
    }
    else printf("%d",arr[1]);

    for(int i=2;i<=n;++i)
    {
      if(!~arr[i]) printf("0");
      else printf("%d",arr[i]);
    }
    puts("");

    
    
  }
  #ifdef _LOCAL_DEFINE  
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 256