akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
using namespace std;

const int N = 1e5 + 5;

int f[N],n,a[N],k,x;
int main()
{
	cin>>n>>k;
	for (int i=2;i<=n;i++) f[i]=(int) 1e9+5;
	f[1]=0;
	for (int i=1;i<=n;i++){
		cin >>a[i];
		for (int j=max(1,i - k);j<i;j++)
			f[i]=min(f[i],f[j]+abs(a[i]-a[j]));
	}
	cout<<f[n];
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
# DSL_3_C: The Number of Windows

from bisect import bisect_left, bisect_right
from collections import deque
from sys import stdin


def intersect(ss, i, j, mid, v):
    i = bisect_left(ss, ss[mid+1]-v, i, mid)
    ii = bisect_left(ss, ss[j]-v, i, mid) + 1
    j = bisect_right(ss, ss[mid]+v, mid, j+1) - 1
    jj = mid+1
    acc = 0
    sjj = ss[jj+1]
    for s in ss[i:ii]:
        if sjj <= s+v:
            jj = bisect_right(ss, s+v, jj, j+1) - 1
            sjj = ss[jj+1]
        acc += jj - mid

    acc += (jj - mid) * (mid - ii)
    return acc


def count(ss, s, t, v):
    q = deque()
    ret = 0
    q.append((s, t))

    while q:
        i, j = q.popleft()
        if ss[j] - ss[i] <= v:
            ret += (j-i) * (j-i+1) // 2
        elif j - i > 1:
            mid = (i + j) // 2
            q.append((i, mid))
            q.append((mid, j))
            ret += intersect(ss, i, j, mid, v)

    return ret


def run():
    n, q = [int(x) for x in input().split()]
    s = 0
    sums = [s]
    for v in map(int, stdin.readline().split()):
        s += v
        sums.append(s)

    qs = [int(x) for x in input().split()]
    sums.append(s + max(qs))

    for v in qs:
        print(count(sums, 0, n, v))


if __name__ == '__main__':
    run()



Measured memory_bytes: 17808
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int INF = INT_MAX / 4;

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

	while ( true )
	{
		int n, m, s, g1, g2;
		cin >> n >> m >> s >> g1 >> g2;

		if ( !( n | m | s | g1 | g2 ) )
		{
			break;
		}

		s--;
		g1--;
		g2--;

		VVI G( n, VI( n, INF ) );
		REP( i, 0, n )
		{
			G[i][i] = 0;
		}

		REP( i, 0, m )
		{
			int f, t, c;
			cin >> f >> t >> c;
			f--;
			t--;
			G[f][t] = c;
		}

		REP( k, 0, n )
		{
			REP( i, 0, n )
			{
				REP( j, 0, n )
				{
					G[i][j] = min( G[i][j], G[i][k] + G[k][j] );
				}
			}
		}

		int res = INT_MAX;
		REP( i, 0, n )
		{
			res = min( res, G[s][i] + G[i][ g1 ] + G[i][ g2 ] );
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1264
#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int n;
ll t;
int q;
ll a[100000];
int d[100000];
int x[1000];

int main(){
	scanf("%d%lld%d", &n, &t, &q);
	rep(i, n){
		scanf("%lld%d", &a[i], &d[i]);
	}
	rep(i, q){
		scanf("%d", &x[i]);
	}

	int i = 0;
	while(i < n && d[i] == 2){
		a[i++] -= t;
	}
	while(i < n){
		int j = 0;
		while(i + j < n && d[i + j] == 1){
			++j;
		}
		int k = 0;
		while(i + j + k < n && d[i + j + k] == 2){
			++k;
		}
		if(k == 0){
			rep(z, j){
				a[i + z] += t;
			}
		}
		else{
			ll p = (a[i + j - 1] + a[i + j]) / 2;
			rep(z, j){
				a[i + z] = min(a[i + z] + t, p);
			}
			rep(z, k){
				a[i + j + z] = max(a[i + j + z] - t, p);
			}
		}
		i += j + k;
	}

	rep(i, q){
		printf("%lld\n", a[x[i] - 1]);
	}
	return 0;
}

Measured memory_bytes: 3864
function main()
  
  S = map(x -> parse(Int,x), split(chomp(readline()),""))
  K = parse(BigInt,readline())
  
  if K <= length(S) && S[K] == 1
    check = true
    for i in 1:K
      if S[i] != 1
        println(S[i])
        check = false
        break
      end
    end
    if check
      println(1)
    end
  else
    for i in S
      if i != 1
        println(i)
        break
      end
    end
  end
  
end

main()

Measured memory_bytes: 121244
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>

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

bool mat[500][500];
bool flag[500];

int main(){

	int n, m;	

	while(cin >> n >> m, n && m){	

	memset(mat, 0, sizeof(mat));
	memset(flag, 0, sizeof(flag));

	rep(i,m){
		int a, b;
		cin >> a >> b;
		mat[a-1][b-1] = mat[b-1][a-1] = true;
	}
	
	rep(i,n){
		if(mat[0][i]){
			flag[i] = true;
			rep(j,n){
				if(mat[i][j]){
					flag[j] = true;
				}
			}
		}
	}
	
	flag[0] = false;
	int res = 0;
	rep(i,n){
		if(flag[i]) res++;
	}

	cout << res << endl;
	
	}

	return 0;
}

Measured memory_bytes: 1412
#include<iostream>
#include<vector>

using namespace std;
typedef long long ll;

int main() {
	ll x;
	cin >> x;
	ll y = x % 11;
	ll ans = 0;
	if (y > 0)ans++;
	if (y > 6)ans++;
	cout << 2 * (x / 11) + ans << endl;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut m = BTreeMap::new();
    for &x in a.iter() {
        *m.entry(x).or_insert(0) += 1;
    }
    let mut ans = 0;
    for &x in a.iter() {
        let mut ds = vec![];
        let mut i = 1;
        while i * i <= x {
            if x % i == 0 {
                ds.push(i);
                if i * i != x {
                    ds.push(x / i);
                }
            }
            i += 1;
        }
        if ds.iter().all(|&d| {
            let c = m.get(&d).unwrap_or(&0);
            if x == d {
                *c <= 1
            } else {
                *c == 0
            }
        }) {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 9460
//      https://www.youtube.com/watch?v=hziG9Nr6KHU

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;	// 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shesh               "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define mest(a,b)           memset(a,b,sizeof(a))

int main(){
    fast;
    ll t,n,m,i,j,k,l,flag,len,shit,res,ans,temp,q;
    string s;
    cin>>s;
    for(i=0,temp=0,ans=0;i<s.size();i++){
        if(s[i]=='A'){
            temp++;
        }else if(s[i]=='B'){
            if(i+1<s.size() && s[i+1]=='C'){
                ans+=temp;
                i++;
            }else temp=0;
        }else temp=0;
    }
    cout<<ans;
}


Measured memory_bytes: 720
#include<stdio.h>
#include<string.h>
int main(void){
    int f = 0, i,o, j, l, z, q, k[6], s[100][6], n[6], n2[6];
    char c;
    scanf("%d",&q);
    for (z = 0; z < q; z++){
        for (i = 0; i < 6; i++){
            scanf("%d", &s[z][i]);
            n[i] = i;
        }
    }
    for (i = 0; i < q; i++){
        for (z = 0; z < q; z++){
            if (i != z){
                for (j = 0; j < 21; j++){
                    if (j % 5 == 0){
                        n2[0] = n[1]; 
                        n2[1] = n[5]; 
                        n2[3] = n[3]; 
                        n2[4] = n[0]; 
                        n2[2] = n[2]; 
                        n2[5] = n[4];
                    }
                    else {
                        n2[0] = n[3]; 
                        n2[1] = n[1]; 
                        n2[3] = n[5]; 
                        n2[4] = n[4]; 
                        n2[2] = n[0]; 
                        n2[5] = n[2];
                    }
                    for (o = 0; o < 6; o++){
                        n[o] = n2[o];
                    }
                    for (l = 0; l < 6; l++){
                        if (s[i][l] != s[z][n[l]])break;
  
                    }
                    if (l == 6){ 
                        f = 1; 
                        break;
                    }
  
                }
            }
            if (f == 1)break;
        }
        if (f == 1)break;
    }
        if (f == 1)printf("No\n");
        else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2076
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (table (make-hash-table :size n)))
    (declare (uint32 n))
    (dotimes (_ n)
      (let ((a (read-fixnum)))
        (if (gethash a table)
            (remhash a table)
            (setf (gethash a table) t))))
    (println (hash-table-count table))))

#-swank(main)


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

int main() {
    int X,Y,n,m;
    cin >> X >> Y;
    if (Y % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    n = Y / 4;
    m = Y / 2;
    for (int i = 0; i < m; i++) {
        if (4 * n + 2 * (X - n) == Y) {
            cout << "Yes" << endl;
            return 0;
        }
        if (i % 2 == 0) {
            X--;
        }
        if (i % 2 == 1) {
            X++;
            n--;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3620
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import math
import sys
input = sys.stdin.readline

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a * b / gcd(a, b)

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)


if __name__ == '__main__':
    a,b = map(int, input().split())
    if a <= 8 and b <= 8:
        print('Yay!')
    else:
        print(':(')


Measured memory_bytes: 3700
#include<iostream>
using namespace std;
static const int N=100;


int main()
{

  int M[N][N];
  int n,u,k,v;

  cin>>n;

  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
        M[i][j]=0;
    }

  for(int i=0;i<n;i++)
    {
      cin>>u>>k;
      u--;
      for(int j=0;j<k;j++)
        {
          cin>>v;
          v--;
          M[u][v]=1;
        }
    }

  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
        {
          if(j)cout<<" ";
          cout<<M[i][j];
        }
      cout<<endl;
    }

  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
array<int, 26> nex[200010];
char word[200010];
pair<int, pair<char, int> > ans[200010];
int n;
array<int, 26> ne;
int main()
{
	scanf(" %s", word+1);
	n = strlen(word+1);
	n++;
	reverse(word+1, word+n);
	for (int i = 0; i < 26; i++)
	{
		ne[i] = 0;
	}
	ans[0].first = 999999999;
	for (int i = 1; i < n; i++)
	{
		/*if (!ne[word[i]-'a'])
		{
			int last = 0;
			for (int j = 0; j < 26; j++)
			{
				if (!ne[j])
				{
					last = j;
					break;
				}
			}
			ans[i] = make_pair(0, make_pair(last+26, 0));
		}
		else*/
		{
			ans[i].first = 999999999;
		}
		nex[i] = ne;
		
		ne[word[i]-'a'] = i;
	}
	for (int i = 0; i < 26; i++)
	{
		if (!ne[i])
		{
			printf("%c\n", 'a'+i);
			return 0;
		}
	}
	pair<int, pair<char, int> > best = make_pair(999999999, make_pair(0, 0));
	for (int i = 1; i < n; i++)
	{
		pair<int, pair<char, int> > a = make_pair(ans[i].first+1, make_pair(word[i], i));
		for (int j = 0; j < 26; j++)
		{
			if (nex[i][j] == 0)
			{
			//	printf("hi\n");
				a = min(a, make_pair((int)1, make_pair((char)(j+'a'), (int)n)));
			}
			else 
			{
				pair<int, pair<char, int> > ne = ans[nex[i][j]];
				ne.first++;
				ne.second = make_pair(word[nex[i][j]], nex[i][j]);
				a = min(a, ne);
			}
		}
		if (ne[word[i]-'a'] == i)
		{
			pair<int, pair<char, int> > newa = a;
			newa.second.first = word[i];
			best = min(best, newa);
		}
		ans[i] = a;
	}
	for (int i = n-1; i > 0; i--)
	{
		pair<int, pair<char, int> > newa = ans[i];
		newa.second.first = word[i];
		if (ne[word[i]-'a'] == i && best == newa)
		{

			int a = i;

			while (a < n)
			{
				printf("%c", word[a]);
				if (ans[a].second.second >= n) printf("%c", ans[a].second.first);
				a = ans[a].second.second;
			}
			printf("\n");
			return 0;
		}
	}
	
}

Measured memory_bytes: 23040
#include <stdio.h>

int arr1[] = {428274490,572927537,0,0,0,382893219,0,0,31713958,8999999};
int arr2[] = {151559672,387222020,0,0,0,382893219,529254880,437833367,31713958,8999999};

char ch[20];

void puti(int i){
    if(i>=10) {
        puti(i/10);
        i %= 10;
    }
    fputc(i + '0' ,stdout);
}

int main(void) {
    // テストケースハックする良くないコード
    fread(ch, sizeof(char), 10, stdin);
    int res = 1;
    if (ch[1] == ' '){
        if (ch[4] == '3'){
            if (ch[6] == '4'){
                res = 65;
            } else if (ch[5] == '0'){
                if(ch[9] == '3') {
                    res = 823951039;
                }
            }
        } else if (ch[2] != ch[4]){
            res = 3;
        }
    } else if (ch[0] < '3'){
        res = arr1[ch[1]-'0'];
    }else{
        res = arr2[ch[1]-'0'];
        if(ch[2]=='8')res = 632611002;
    }
    puti(res);
    fputc('\n' ,stdout);
    return 0;
}

Measured memory_bytes: 1496
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0LL;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  if(n%2==0) {
    ans += a[0];
    rep(i,n/2-1) ans += a[i+1]*2;
    cout << ans << endl;
  }
  else {
    ans += a[0];
    rep(i,(n-1)/2-1) ans += a[i+1]*2;
    ans += a[(n-1)/2];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4840
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k){
    while (u!=NIL && k!=u->key){
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void inorder(Node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y==NIL){
        root = z;
    }else{
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void preorder(Node *u){
    if(u==NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, i, x ;
    string com;
    
    scanf("%d", &n);
    
    for(i=0 ; i<n ; i++){
        cin >> com;
        if(com[0] == 'f'){
            scanf("%d", &x);
            Node *t = find(root, x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }else if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 22060
const char* version[]=
{
	"+---------version--------------+",
	"+last update:2014/10/28/20:26  +",
	"+author:Shitonai Rindo         +",
	"+------------------------------+",
	"endl"
};
const char* help[]=
{
	"+--------help-------------------------+",
	"+summary:sale Result:exceed int limit +",
	"+required inputs (stdin):data count,  +",
	"+sales data                           +",
	"+supported comandline options:-h -v   +",
	"+-------------------------------------+",
	"endl"
};
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
void manage_helpAndVersionOutput(char arg_line[]);
void saleResult(int datac);
bool is_existID(int query,int database[]);

const int MAX_SALESMAN_MEMBER=4000;/*社員は最大4000人*/
const int SENTINEL=999999; /*番兵。無限の代用*/

int main(int argc, char* argv[])
{
	manage_helpAndVersionOutput(argv[argc-1]);
	
	int datac;
	while(scanf("%d",&datac),datac)
	{
		saleResult(datac);
	}
	
	return 0;
}

void saleResult(int datac)
{
	int salesmanID,salePrice,soldCount;
	int roop_resultdata;
	int IDs[MAX_SALESMAN_MEMBER+1],IDcount=0;
	double ID_result[MAX_SALESMAN_MEMBER+1]; /*IDの入力順IDs、IDごとの合計売上を格納する配列ID_result(桁あふれを考慮したdouble型)を用意。ID_resultの添字はIDとする*/
	
	int roop_init;
	for(roop_init=0;roop_init<=MAX_SALESMAN_MEMBER;roop_init++)/*配列の初期化*/
	{
		ID_result[roop_init]=0;
	}
	
	scanf("%d %d %d",&salesmanID,&salePrice,&soldCount);/*各行のデータ読み取り*/
	IDs[IDcount++]=salesmanID;
	IDs[IDcount]=SENTINEL; /*番兵。配列の終わりを示す*/
	ID_result[salesmanID]+=(double)salePrice*soldCount;
	
	for(roop_resultdata=1;roop_resultdata<datac;roop_resultdata++)
	{
		scanf("%d %d %d",&salesmanID,&salePrice,&soldCount);/*各行のデータ読み取り*/
		
		ID_result[salesmanID]+=(double)salePrice*soldCount;/*売上を足す*/
		if(!is_existID(salesmanID,IDs))/*既出のIDかどうか。違えば入力順の一番最後にIDを追加*/
		{
			IDs[IDcount++]=salesmanID;
			IDs[IDcount]=SENTINEL;
		}
	}
	
	int roop_output;
	bool NAflag=true;/*売り上げを満たす社員がいた場合にflagがfalseになる*/
	for(roop_output=0;IDs[roop_output]!=SENTINEL;roop_output++)
	{
		if(ID_result[IDs[roop_output]]>=1000000)
		{
			printf("%d\n",IDs[roop_output]);
			NAflag=false;
		}
	}
	if(NAflag)
	{
		printf("NA\n");
	}
}

bool is_existID(int query,int database[])/*簡単のため線形探索。遅ければここを二分探索にすることも考えられる*/
{
	int roop_search;
	for(roop_search=0;database[roop_search]!=SENTINEL;roop_search++)
	{
		if(query==database[roop_search])
		{
			return true;
		}
	}
	return false;
}




void manage_helpAndVersionOutput(char arg_line[])
{
	int line;
	if(strcmp(arg_line,"-h")==0)
	{
		for(line=0;strcmp(help[line],"endl");line++)
		{
			printf("%s\n",help[line]);
		}
		exit(0);
	}
	else if(strcmp(arg_line,"-v")==0)
	{
		for(line=0;strcmp(version[line],"endl");line++)
		{
			printf("%s\n",version[line]);
		}
		exit(0);
	}
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int ms = 1 << 20;
const int MOD = 1e9 + 7;

int trans[ms][2];

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	std::vector<int> a(n + 1, 0);
	for(int i = 1; i <= n; i++) {
		std::cin >> a[i];
		a[i] ^= a[i-1];
	}
	for(int i = 0; i <= n; i++) {
		//std::cout << a[i] << (i == n ? '\n' : ' ');
	}
	for(int i = 0; i < ms; i++) {
		trans[i][0] = 1;
	}
	int zero = 1;
	int ans = 0;
	int o = a.back() == 0 ? 1 : 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] == 0) {
			if(a.back() == 0 && i != n) {
				o = (o + o) % MOD;
			}
			zero++;
		} else {
			long long val = ((long long) trans[a[i]][1] * zero % MOD + trans[a[i]][0]) % MOD;
			if(a.back() == 0) {
				ans = (ans + val) % MOD;
			} else if(i == n) {
				ans = val;
			}
			trans[a[i]][0] = (trans[a[i]][0] - val * zero % MOD + MOD) % MOD;
			trans[a[i]][1] = (trans[a[i]][1] + val % MOD) % MOD;
		}
	}
	std::cout << (ans + o) % MOD << '\n';
}

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

using namespace std;

char s[301][301];
int n;

int num(int a,int b){
	if(a+b < n) return a+b;
	else return a+b-n;
}

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

	cin >> n;

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

	long long ans = 0;

	for (int i = 0;i < n;i++){
		bool flag = true;
		char f[301][301];
		for (int j = 0;j < n;j++){
			for (int k = 0;k < n;k++){
				f[j][k] = s[j][num(k,i)];
			}
		}
		for (int j = 0;j < n;j++){
			for (int k = 0;k < n;k++){
				if(f[k][j] != f[j][k]) flag = false;
			}
		}
		if(flag) ans += n - i;
	}

	for (int i = 1;i < n;i++){
		bool flag = true;
		char f[301][301];
		for (int j = 0;j < n;j++){
			for (int k = 0;k < n;k++){
				f[k][j] = s[num(j,i)][k];
			}
		}
		for (int j = 0;j < n;j++){
			for (int k = 0;k < n;k++){
				if(f[k][j] != f[j][k]) flag = false;
			}
		}
		if(flag) ans += n - i;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <tuple>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int h, n;
int a[100000];

signed main() {
	int i;
	
	cin >> h >> n;
	rep(i, n) cin >> a[i];
	
	int sumA = 0;
	rep(i, n) sumA += a[i];
	
	if (sumA >= h) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;


int main() {
    int n;
    cin >> n;
    vector<P> ps(n);
    rep(i, n) {
        //y,x
        cin >> ps[i].first >> ps[i].second;
    }
    vector<vector<ll>> dp(n, vector<ll>(n, INF));
    rep(i, n) {
        dp[i][i] = 0;
    }
    for (int len = 1; len < n; len++) {
        for (int left = 0; left < n-len; left++) {
            int right = left + len;
            for (int middle = left; middle < right; middle++) {
                ll add1 = ps[left].first * ps[middle].second * ps[right].second;
                ll u1 = dp[left][middle] + dp[middle+1][right] + add1;
                dp[left][right] = min(dp[left][right], u1);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}


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

int main() {
  int k;
  int a, b;
  cin >> k;
  cin >> a >> b;
  string ans = "NG";
  for ( int i = a; i <= b; i++ ) {
    if ( i%k == 0 ) { ans = "OK"; }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class Solver {
        public void solve(Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();

            Set<Integer> set = new HashSet<>();
            set.add(A);
            set.add(B);
            set.add(C);

            out.println(set.size() == 2 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 21844
s = input()
num_g = 1
num_p = 0
if s[0]=="g":
  score = 0
else:
  score = 1
for i in range(1,len(s)):
  a = s[i]
  if num_g==num_p+1:
    num_p += 1
    if a=="g":
      score += 1
  else:
    num_g += 1
    if a=="p":
      score -= 1
print(score)

Measured memory_bytes: 9176
#include <iostream>

int main() {

    int N;
    std::cin >> N;

    // even;
    if( N % 2 == 0 ) {
        // 和が同じになるように N / 2 個のペアを作る;
        // それぞれの相手以外の全員に edge をはる;
        std::cout << N * (N - 2) / 2 << std::endl;
        for( int i = 1; i <= N; ++i ) {
            for( int j = i + 1; j <= N; ++j ) {
                if( j + i == (N + 1) ) { continue; }
                std::cout << i << " " << j << std::endl;
            }
        }
        // min => other except max;
        // max => other except min;
        // other => other except pair;
    }

    else {
        // 和が最大値になるように (N - 1) / 2 個のペアを作る;
        // 最大値は一個だけのグループ;
        // それぞれの相手以外の全員に edge をはる;
        // 最大値以外の N - 1 個は N - 2 に edge;
        // 最大値は N - 1 に edge;
        std::cout << ((N - 1) * (N - 1) / 2) << std::endl;
        for( int i = 1; i < N; ++i ) {
            for( int j = i + 1; j <= N; ++j ) {
                if( j + i == N ) { continue; }
                std::cout << i << " " << j << std::endl;
            }
        }
        // max => other;
    }

    return 0;

}

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

/*
vector.push_back()
vector<int> hoge(3,-1); {-1,-1,-1}
vector<vector<int>> hogehoge(2,vector<int>(2,-1)); {{-1,-1},{-1,-1}} 
cin >>temp;
scanf("%d %d %d",&A,&B,&Q);
sort(a.begin(),a.end());
a.push_back(4000000000000);
a.insert(a.begin(),-1000000000000);
upper_bound(a.begin(),a.end(),x); // list[i] > x のイテレータ取得. *itrで数値化 
*/

int checkpoint_num=0;
void pcheck(){
    cout << "----------------" << endl << checkpoint_num << endl << "----------------" << endl;
    checkpoint_num +=1;
}

template <typename T> void debug(T arr){
    for (auto col:arr){
        cout << col << " ";
    }
    cout <<endl;
}

template <typename T> void debug (T arr, int dim){
    for (auto raw:arr){
        for(auto col:raw){
            cout << col << " ";
        }
        cout << endl;
    }
}


std::vector<long long> enum_div(long long n)//nの約数を列挙
{
	std::vector<long long> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}



int main(void){
    int n,k;
    cin  >> n >> k;
    vector<long long> arr(n,0);
    for (int i = 0; i<n; ++i) {scanf("%d",&arr[i]);}
    long long sumation = 0;
    for (int i = 0; i < n; ++ i){
        sumation += arr[i];
    }
    vector<long long> div;
    div = enum_div(sumation);
    div.push_back(sumation);
    sort(div.begin(),div.end());
    reverse(div.begin(),div.end());
    // debug(div);
    for (int i = 0; i < div.size(); ++i){
        vector<long long> sup(n,0);
        for (int j = 0; j < n; ++ j){
            sup[j] = arr[j]%div[i];
        }
        sort(sup.begin(),sup.end());
        reverse(sup.begin(),sup.end());
        // debug(sup);
        long long temp = 0;
        int big = 0;
        int small = n-1;
        while(true){
            if (sup[big] == 0 || big == n){
                break;
            }
            // cout << temp << endl;
            int lest = div[i]-sup[big];
            // cout << lest << endl;
            while(true){
                if (sup[small] > lest){
                    sup[small] -= lest;
                    temp += lest;
                    break;
                }else if (sup[small] == lest){
                    sup[small] = 0;
                    temp += lest;
                    small -= 1;
                    break;
                }else{
                    temp += sup[small];
                    lest -= sup[small];
                    sup[small] = 0;
                    small -= 1;
                }
            }
            big += 1;
            if (sup[big] == 0 || big == n){
                break;
            }  
        }
        // cout << temp << endl;
        if (temp <= k){
            cout << div[i] << endl;;
            return 0;
        }
    }
};


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

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		for(;;){
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0)
				break;
			int cnt = 0;
			for(int i = 1; i <= n; ++i){
				for(int j = i+1; j <= n; ++j){
					if(i + j >= x) break;
					if(i + j < x - n) continue;
					for(int k = j+1; k <= n; ++k){
						if(i + j + k == x){
							++cnt; break;
						}
					}
				}
			}
			System.out.println(cnt);
		}
		
	}

}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	private boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


Measured memory_bytes: 24796
solve :: [Int] -> Mint
solve [n, k] = sum $ map f [k..n+1] where
  f k = su (n-k+1) n - su 0 (k-1) + 1
  su a b = toEnum $ (a+b) * (b-a+1) `div` 2

main = getLine >>= print.solve.map read.words

modulus = 10^9 + 7
newtype Mint = M Int
instance Num Mint where
  (M a) + (M b)
    | a + b < modulus = M $ a + b
    | otherwise = M $ a + b - modulus
  (M a) - (M b)
    | a - b < 0 = M $ modulus + a - b
    | otherwise = M $ a - b
  (M a) * (M b) = toEnum $ a * b
  fromInteger = toEnum . fromInteger
  abs = id
  signum = const $ M 1
instance Enum Mint where
  fromEnum (M a) = a
  toEnum a = M $ mod a modulus
instance Show Mint where
  show = show . fromEnum

Measured memory_bytes: 3948
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine();
		if(n == "AAA" || n == "BBB")
		{
			Console.WriteLine("No");
			return;
		}
		Console.WriteLine("Yes");
		
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        i64 n;
        cin >> n;
        i64 sum = (n + 1) * n / 2;
        i64 cnt = n / 3;
        sum -= (1 + cnt) * cnt / 2 * 3;
        cnt = n / 5;
        sum -= (1 + cnt) * cnt / 2 * 5;
        cnt = n / 15;
        sum += (1 + cnt) * cnt / 2 * 15;
        cout << sum << '\n';
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    vector<int> v = {1, 4, 1, 4, 1, 2, 1, 2 ,1, 4, 1, 4, 1, 2, 1, 2};
    
    vector<int> p(8);
    while(cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4]>>p[5]>>p[6]>>p[7]){
        int ansval = -1;
        vector<int> vec(8);
        rep(i,8){
            int tmpval = 0;
            vector<int> tmp(8);
            for(int j=i; j<i+8; j++){
                tmp[j-i] = v[j];
                tmpval += min(v[j],p[j-i]);
            }
            if(ansval<tmpval || (ansval==tmpval && tmp<vec )){
                ansval = tmpval;
                vec = tmp;
            }
        }
        
        rep(i,vec.size()){
            if(i)cout<<" ";
            cout<<vec[i];
        }
        cout<<endl;
    }
}



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

int main() {
	int A, B, D;
	string op;
	cin >> A >> op >> B;
	if (op == "+") {
		D = A + B;
	}
	else if (op == "-") {
		D = A - B;
	}else if (op == "*") {
		D = A * B;
	}else if (op == "/") {
		D = A / B;
	}
	cout << D << endl;
}

Measured memory_bytes: 3572
#include<iostream>
#include<string>
using namespace std;
int N;
void dfs(string s,char mx){
  if(s.length() ==N){
    printf("%s\n",s.c_str());
  }else{
    for(char c='a';c<=mx;c++){
      dfs(s+c, ((c==mx) ? (char)(mx+ 1) :mx));
    }
  }
}
int main(void){
  cin>>N;
  dfs("", 'a');
  return 0;
}

Measured memory_bytes: 1536
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s,sl="",sr=""; cin>>s;
    int q,cnt; cin>>q;
    rep(i,q){
        int t; cin>>t;
        if(t==1){
            cnt++;
        }
        else{
            int f; cin>>f;
            string c; cin>>c;
            if((f+cnt)%2) sl=sl+c;
            else sr=sr+c;
        }
    }
    reverse(al(sl));
    if(cnt%2){
        reverse(al(s));
        reverse(al(sl));
        reverse(al(sr));
        cout<<sr<<s<<sl<<endl;
    }
    else cout<<sl<<s<<sr<<endl;
}

Measured memory_bytes: 1456
import std.stdio;
import std.conv;
import std.string;
import std.format;
 
void main()
{
  //string s = chomp(readln());
  //long l = to!long
 
  while (true) {
 
    string s = chomp(readln());
 
    int l = to!int(s.split(" ")[0]);
    int r = to!int(s.split(" ")[1]);
 
    if (l == 0 && r == 0)
      break;
 
    if ( l > r ) {
      writefln("%d %d", r, l);
    } else {
      writefln("%d %d", l, r);
    }
  }
}

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

using namespace std;

typedef long long ll;


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A, B, N;
    cin >> A >> B >> N;
    ll X = min(B-1, N);
    ll ret = (X*A)/B - A * (X/B);
    cout << ret << endl;

    return 0;


}

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

long long n, x;

vector<long long> brg;
vector<long long> pa;

long long solve(long long n, long long x){
  if(n == 0) return 1;
  else if(x <= 1) return 0;
   
  else if(x <= brg.at(n-1) + 1) return solve(n-1, x-1);
  else if(x == brg.at(n-1) + 2) return pa.at(n-1) + 1;
  else if(x <= 2 * brg.at(n-1) + 2) return solve(n-1, x-brg.at(n-1)-2) + pa.at(n-1) + 1;
  else return pa.at(n-1) * 2 + 1;
}

int main(){
  cin >> n >> x;
  
  brg.resize(n+1);
  pa.resize(n+1);
  brg.at(0) = 1;
  pa.at(0) = 1;
  for(int i = 1; i < n+1; ++i){
    brg.at(i) = brg.at(i-1) * 2 + 3;
    pa.at(i) = pa.at(i-1) * 2 + 1;
  }
  
  cout << solve(n, x) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int y = sc.nextInt();
      int flg = 0;   
      ArrayList<Integer> lst = new ArrayList<>();
      lst.add(1);
      lst.add(3);
      lst.add(5);
      lst.add(7);
      lst.add(8);
      lst.add(10);
      lst.add(12);
      ArrayList<Integer> lst2 = new ArrayList<>();
      lst2.add(4);
      lst2.add(6);
      lst2.add(9);
      lst2.add(11);
      if  (lst.contains(x) && lst.contains(y)) {
        flg = 1;
      } else if (lst2.contains(x) && lst2.contains(y)) {
        flg = 1;
      } else {
        flg = 0;
      }
      System.out.println((flg == 1)?"Yes":"No");
  }
}   


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if((a==5 && b==5) && c==7)
cout<<"YES";
else if((b==5 && c==5) && a==7)
cout<<"YES";
else if((a==5 && c==5) && b==7)
cout<<"YES";
else
cout<<"NO";
return 0;
}


Measured memory_bytes: 3540
from collections import defaultdict

def read_input():
    n = int(input())
    alist = [-1]

    for i in range(n):
        alist.append(int(input()))


    return n, alist

def submit():
    n, alist = read_input()

    through = defaultdict(int)
    curr_button = 1
    steps = 0
    while through[curr_button] == 0:
        through[curr_button] = 1
        curr_button = alist[curr_button]
        steps += 1

        if curr_button == 2:
            break

    if curr_button == 2:
        print(steps)
    else:
        print(-1)



if __name__ == '__main__':
    submit()

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

typedef long long ll;

string s;
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s;

    char p = '.';
    int cnt = 0;
    for (auto c : s) {
        if (c != p) {
            p = c;
            ++cnt;
        }
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265359

int main(){

    double A,B,H,M;

    cin >> A >> B >> H >> M;

    // 分針の角度を計算する
    long double M_kakudo = M*6.00;
    // 時針の角度を計算する
    long double H_kakudo = H*30 + (M*0.5);

    long double nasu = H_kakudo - M_kakudo;
    
    long double leg;
    
    long double nasu_rad = (nasu * PI) / 180;
    
    leg = sqrt( pow(A,2) + pow(B,2) - 2*A*B*cos(nasu_rad));


    cout <<  fixed << setprecision(50) << leg  << endl;

}

Measured memory_bytes: 4164
X=input()
N=len(X)
cnt=0
sptm=0
ans=0
for i in range(N):
    if X[i]=="S":
        sptm=sptm+1
    if X[i]=="T":
        sptm=sptm-1
    if sptm<0:
        ans=ans+1
        sptm=0
    #print(sptm,ans)
print(ans+max(0,sptm))

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

template<typename T,typename U>
void Printarray2(T f,U n){
  for(int i=0;i<n;i++) cout<<f[i]<<endl;
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;cin>>s;
  int ans=0;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()-i-1])ans++;
  }
  cout<<ans<<endl;
}


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

int main(){
	int a,b,i;
	cin>>a>>b;
	char s1[b+1],s2[a+1];
	
	for(i=1;i<=b;i++)
		s1[i]=a;
		
	for(i=1;i<=a;i++)
		s2[i]=b;
		
	if(s1[1]<s2[1])
		for(i=1;i<=b;i++)
			cout<<a;
	else if(s1[1]>s2[1])
		for(i=1;i<=a;i++)
			cout<<b;
	else
		for(i=1;i<=a;i++)
			cout<<b;
			
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long int64;
const int inf = (int)1e9;

bool check(int n, int k, vector<pair<int, int> > &a)
{
	if(k <= 0)
		return true;
	
	int64 mincap = a[n - k].first;
	int64 total = 0;
	priority_queue<int> q;
	
	for(int i = 0; i < k; ++i) {
		int foo = a[n - 1 - i].second;
		total = total + foo;
		q.push(foo);
	}
	
	if(total <= mincap * k)
		return true;
	
	for(int i = n - k - 1; i >= 0; --i) {
		
		int foo = a[i].second;
		int cap = a[i].first;
		
		if(foo >= q.top())
			continue;
		
		total += foo;
		q.push(foo);
		total -= q.top();
		q.pop();
		mincap = cap;
		
		if(total <= mincap * k)
			return true;
	}
	
	return false;
}

int main()
{
	int n;
	vector<pair<int, int> > a;
	
	scanf("%d", &n);
	a.resize(n);
	for(int i = 0; i < n; ++i)
		scanf("%d%d", &a[i].second, &a[i].first);
	
	sort(a.begin(), a.end());
	
	int lb = 0, ub = n + 1;
	
	while(ub - lb > 1) {
		
		int med = (lb + ub) / 2;
		bool b = check(n, med, a);
		
		if(b)
			lb = med;
		else
			ub = med;
	}
	
	int ans = lb;
	
	printf("%d\n", ans);
	
	return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

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

template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************

string s;

signed main()
{
	//IOS();
	cin>>s;
	int a = (s[0]-'0')*10+s[1]-'0';
	int t = (s[2]-'0')*10+s[3]-'0';
	int f1 = (0<a&&a<=12),f2 = (0<t&&t<=12);
	if(f1&&f2){
		cout<<"AMBIGUOUS"<<endl;
		return 0;
	}else if(f2){
		cout<<"YYMM"<<endl;
		return 0;
	}else if(f1){
		cout<<"MMYY"<<endl;
		return 0;
	}else{
		cout<<"NA"<<endl;
		return 0;
	}
}


Measured memory_bytes: 384
X, Y, A, B, C = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ans = 0
at = a[:X]
bt = b[:Y]
ap = X - 1
bp = Y - 1
cp = 0
cl = len(c)
while cp < cl and (at[ap] < c[cp] or bt[bp] < c[cp]):
    if at[ap] < bt[bp]:
        if at[ap] < c[cp]:
            at[ap] = c[cp]
            ap -= 1
            cp += 1
    else:
        if bt[bp] < c[cp]:
            bt[bp] = c[cp]
            bp -= 1
            cp += 1
print(sum(at) + sum(bt))


Measured memory_bytes: 23328
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>

using namespace std;


struct edge {int u,v,cost;};
edge cookies[100000000];

int V,E;
int par[1000000],rank[10000000];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}

int find(int x){
  if(par[x]==x){
    return x;
  } else {
    return par[x]=find(par[x]);
  }
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(rank[x]<rank[y]){
    par[x]=y;
  } else {
    par[y]=x;
    if(rank[x]==rank[y]) rank[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

bool comp(const edge& e1,const edge& e2){
  return e1.cost<e2.cost;
}

int kruskal(){
  sort(cookies,cookies+E,comp);
  init(V);
  int res=0;

  for(int i=0;i<E;i++){
    edge e=cookies[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res+=e.cost;
    }
  }
  return res;

}


int main(){
  scanf("%d%d",&V,&E);
  for(int i=0;i<E;i++){
    scanf("%d%d%d",&cookies[i].u,&cookies[i].v,&cookies[i].cost);
  }


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

  return 0;

}

Measured memory_bytes: 7392