akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <cstdlib>
#define rep(i,o,u) for(int i = o;i < u; i++)
using namespace std;
struct node{
	int key;
	node *prev, *next;
};
node *nil;
void inti(){
	nil = (node *)malloc(sizeof(node));
	nil->next = nil;
	nil->prev = nil;
}
void insert(int key){
	node *x = (node *)malloc(sizeof(node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}
node* listSearch(int key){
	node *cur = nil->next;
	while(cur != nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}
void deleteNode(node *t){
	if(t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}
void deleteFirst(){
	deleteNode(nil->next);
}
void deleteLast(){
	deleteNode(nil->prev);
}
void deleteKey(int key){
	deleteNode(listSearch(key));
}
void printList(){
	node *x = nil->next;
	while(x != nil){
		cout << x->key;
		if(x != nil->prev)
			cout << " ";
		x = x->next;
	}
	cout << endl;
}
int main(){
	int n;
	inti();
	cin >> n;
	string a;int b;
	while(n--){
		cin >> a;
		if(a == "insert"){
			cin >> b;
			insert(b);
		}else if(a == "delete"){
			cin >> b;
			deleteKey(b);
		}else if(a == "deleteFirst"){
			deleteFirst();
		}else if(a == "deleteLast"){
			deleteLast();
		}
	}
	printList();
	return 0;
}

Measured memory_bytes: 34344
/*
O(VE)

build()をした後、1辺を追加するのはO(N^2)で済む

verify:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=ja
*/

#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using pii=pair<int,int>;
template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}

//辺 fromあり
template<typename T >
struct Edge {
  int from, to;
  T cost;

  Edge()=default;
  Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

};
constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;


template<typename T>
using Edges=vector<Edge<T>>;


template<typename T>
vector<T> BellmanFord(Edges<T> &g,int v,int s,T inf,T _inf,T zero){
    vector<T> dist(v,inf);
    dist[s]=zero;
    for(int i=0;i<v-1;i++){ //v-1回のループ 不閉路を気にしない場合はここだけ
        for(auto &e:g){
            if(dist[e.from]==inf) continue;
            chmin(dist[e.to],dist[e.from]+e.cost); //Tの足し算、比較
        }
    }
    //不閉路の有無だけを気にする場合はこれを利用
    //不閉路がある場合は空を返す
    for(auto &e:g){
        if(dist[e.from]==inf) continue;
        if(dist[e.from]+e.cost<dist[e.to]) return vector<T>();
    }
    return dist;
    
   /*
    //負の無限大になるところを調べる _infにする
    for(int i=0;i<v-1;i++){
        for(auto &e:g){
            if(dist[e.from]==inf) continue;
            if(dist[e.from]+e.cost<dist[e.to]) dist[e.to]=_inf; //_infを使用
        }
    }
    return dist;
    */
} 

inline pii operator+(const pii &a,const pii &b){
    return {a.first*b.first,a.second+b.second};
}


signed main(){
    int v,e,r;
    cin>>v>>e>>r;
    Edges<ll> g;
    for(int i=0;i<e;i++){
        int s,t,d;
        cin>>s>>t>>d;
        g.emplace_back(s,t,d);
    }
    auto V=BellmanFord<ll>(g,v,r,INF,-INF,0);
    if(V.size()==0) cout<<"NEGATIVE CYCLE"<<endl;
    else{
        for(auto ans:V){
            if(ans==INF) cout<<"INF"<<endl;
            else cout<<ans<<endl;
        }
    }
}


Measured memory_bytes: 3212
// B - Counting of Trees
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 998244353

int main(){
	int N; cin>>N;
	vector<int> C(N);
	int ans = 1;
	rp(i, 0, N){
		int d; scanf("%d",&d);
		if(i==0 ^ d==0) ans = 0;
		C[d]++;
	}
	rp(d, 2, N) rp(i, 0, C[d]) ans  = 1L*ans * C[d-1] % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

int main() {
	optimizar_io
	int x;
	cin >> x;
	cout << (x >= 30 ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	string t;
	t.push_back(s[5]);
	t.push_back(s[6]);
	int n=stoi(t);
	if(n<=4) cout<<"Heisei";
	else cout<<"TBD";
	
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<cassert>
#include<map>
#include<vector>
#include<cmath>
#include<complex>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define N 100
#define DEAD false
#define ARRIVE true
#define eps 1e-10

typedef complex<double> P;

double dot(P a,P b){
  return a.real()*b.real()+a.imag()*b.imag();
}

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

double distance_ls_p(P a,P b,P c,double r){
  if ( dot(b-a,c-a)<0)return r*2;
  else if ( dot(a-b,c-b)<0)return r*2;
  return abs(cross(b-a,c-a))/abs(b-a);
}


bool is_intersect_cl(P a,P b,P circle,double radius){
  bool flag1 = abs(a-circle)<=radius?1:0;
  bool flag2 = abs(b-circle)<=radius?1:0;
  
  if ( flag1 == true)return true;
  else if ( flag2 == true)return true;
  if (  distance_ls_p(a,b,circle,radius)<radius+eps)return true;
  return false;
}

class UFO{

public:
  P now;
  double r,v,theta,time;
  double vx,vy;
  bool flag;
  UFO(){};
  UFO(double tx,double ty,double tr,double tv,double R){
    flag = ARRIVE;
    now.real()=tx;
    now.imag()=ty;
    v=tv;
    r=tr;
    theta = arg(now);
    time = sqrt(tx*tx+ty*ty)-R;
    if (time < 0)flag=DEAD;
    else time/=v;
    vx=-cos(theta)*v;
    vy=-sin(theta)*v;    
  }

  void move(double t){    
    if (flag == DEAD){return;}
    now.real()+=vx;
    now.imag()+=vy;
    if ( time < t+eps){flag = DEAD;return ;}
  }

  bool crash_check(P a,P b){
    if ( flag == DEAD)return false;
    if ( is_intersect_cl(a,b,now,r)==true){
      flag = DEAD;
      return true;
    }
    return false;
  }
};


int solve(int n,UFO *data,double R){
  const double INF = 20000;
  int cnt=0;
  double time=1;
  while(true){
    double dist = 1000*1000;
    int minindex = -1;
    rep(i,n){
      data[i].move(time);
      if (data[i].flag == ARRIVE&& abs(data[i].now)<dist){
	dist=abs(data[i].now);
	minindex=i;
      }
    }
    if ( minindex == -1)break;
    
    P a,b,e;
    e = data[minindex].now/abs(data[minindex].now);
    a=e*R;
    b=e*INF;
    rep(i,n){
      if ( data[i].crash_check(a,b) == true)cnt++;
    }


    time+=1;
  }

  return n-cnt;
}

main(){
  double R;
  int n;
  while(cin>>R >> n && n){
    UFO data[n];
    rep(i,n){
      double x,y,r,v;
      cin>>x>>y>>r>>v;
      data[i]=UFO(x,y,r,v,R);
    }
    
    /*  

    for(double j=1;j<10;j+=1){
      cout <<j <<" seconds" << endl;
      rep(i,n){
	data[i].move(j);
	cout << data[i].flag <<" " <<data[i].time  << " " << data[i].now.real() <<" " << data[i].now.imag() << 
	  " " << abs(data[i].now) << " " << R << endl;

      }
      cout << "!!!"<<endl<<endl;
    }
*/
    cout << solve(n,data,R) << endl;

  }
}

Measured memory_bytes: 0
N = int(input())

if N == 1:
  print(1)

else:
  sum_ = N*(N+1)//2
  for i in range(2, N//2+1):
    n = N // i
    sum_ += i*(n*(n+1)//2)

  sum_ += (N//2+1 + N) * (N - (N//2+1) + 1) // 2

  print(sum_)

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


int main() {
  int a,b;
  cin >> a >> b;
  if(a <= 2*b){
    cout << 0 << endl;
  }
  else {
    cout << a - 2*b << endl;
  }
  
  return 0;
}

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

using namespace std;
int main(void){
    int N;
    cin >> N;
    
    std::vector<int> V(N);
    for(int i=0;i<N;i++) cin >> V[i];

    std::vector<int> C(N);
    for(int i=0;i<N;i++) cin >> C[i];
    int sum = 0;
    for(int i=0;i<N;i++){
        if(C[i]<V[i]) sum+=V[i]-C[i];
    }
    
 
    
    
    cout << sum;

    return 0;
    
}


Measured memory_bytes: 3564
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((maze)),(maze).begin(),TL<char>)
# define UPPER(s)    transform(ALL((maze)),(maze).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n;
double a[101010];
LL b[101010];
double ansa, ansb;
double minl = HINF;
int main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	sort(a, a + n);
	ansa = a[n - 1];
	REP(i, n-1) {
		if (minl > abs(ansa/2 - a[i])) {
			minl = abs(ansa/2 - a[i]);
			ansb = a[i];
		}
	}
	cout << (int)ansa << " " << (int)ansb << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
using namespace std;
int main(void)
{
	long long int i,n,m,j;
	scanf("%lld %lld",&n,&m);
	i = m -2*n;
	if(i < 0)
	{
		printf("%lld",m/2);
		return 0;
	}
	else
	{
		i /=4;
	printf("%lld",n+i);
}return 0;
}

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

int main() {
  int64_t X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<int64_t> as(A);
  for (int i = 0; i < A; i++) {
    cin >> as[i];
  }
  sort(as.begin(), as.end(), std::greater<int64_t>());

  vector<int64_t> bs(B);
  for (int i = 0; i < B; i++) {
    cin >> bs[i];
  }
  sort(bs.begin(), bs.end(), std::greater<int64_t>());

  vector<int64_t> cs(C);
  for (int i = 0; i < C; i++) {
    cin >> cs[i];
  }
  sort(cs.begin(), cs.end(), std::greater<int64_t>());

  vector<int64_t> xy;
  for (int64_t i = 0; i < X; i++) {
    xy.push_back(as[i]);
  }
  for (int64_t i = 0; i < Y; i++) {
    xy.push_back(bs[i]);
  }
  sort(xy.begin(), xy.end());

  for (int64_t i = 0; i < X + Y && i < C && xy[i] < cs[i]; i++) {
    xy[i] = cs[i];
  }

  int64_t sum = 0;
  for (int64_t i = 0; i < X + Y; i++) {
    sum += xy[i];
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 4724
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	
	static int n, r;
	static int[] p, c;
	
	static int[] cut(int[] cards, int pp, int cc)
	{
		int[] ret = new int[n];
		
		int i;
		for(i = 0;i < cc;i++) ret[i] = cards[i + pp - 1];
		for(i = 0;i < pp-1;i++) ret[i+cc] = cards[i];
		for(i = pp+cc-1;i < n;i++) ret[i] = cards[i];
		
		return ret;
		
	}
	
	static void start()
	{
		int[] cards = new int[n];
		for(int i=0;i < n;i++)
		{
			cards[i] = n-i;
		}
		
		for(int i=0;i < r;i++)
		{
			cards = cut(cards, p[i], c[i]);
		}
		
		System.out.println(cards[0]);
	}
	
	public static void main(String[] args)
	{
		
		
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			n = sca.nextInt();
			r = sca.nextInt();
			if(n == 0) break;
			
			p = new int[r];
			c = new int[r];
			for(int i=0;i < r;i++)
			{
				p[i] = sca.nextInt();
				c[i] = sca.nextInt();
			}
			
			start();
		}
	}
}

Measured memory_bytes: 28324
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    long long s;
    std::cin >> s;

    if (s == 1e18) {
        std::cout << "0 0 1000000000 0 0 1000000000" << std::endl;
        return 0;
    }

    std::cout << "0 0 1000000000 1 " << ((long long)1000000000 - s % (long long)1000000000) << " " << s / (long long)1000000000 + (long long)1 << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    int N,X;
    cin >> N >> X;
    vector<int> L(N);
    for(int i=0;i<N;i++) cin >> L.at(i);
    int count=1;
    int sum=0;
    for(int i=0;i<N;i++){
        sum+=L.at(i);
        if(sum>X) break;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
int a[10],b[5],x=0;
using namespace std;
void SOU(int i,int s)
{
    if(i==3)
    {
        if(s+a[4]==7) {b[3]=1;x=1;}
        else if(s-a[4]==7) {b[3]=0;x=1;}
        return;
    }
    if(x==0){
    b[i]=1;
    SOU(i+1,s+a[i+1]);}
    if(x==0){
    b[i]=0;
    SOU(i+1,s-a[i+1]);}
}

int main()
{
    int i,n;
    char c[5];
    scanf("%d",&n);
    a[4]=n%10;n/=10;
    a[3]=n%10;n/=10;
    a[2]=n%10;n/=10;
    a[1]=n;
    SOU(1,a[1]);
    for(i=1;i<=3;i++)
        if(b[i]==1) c[i]='+';
        else c[i]='-';
    for(i=1;i<=3;i++)
    {
        printf("%d",a[i]);
        printf("%c",c[i]);
    }
    printf("%d=7\n",a[4]);
    return 0;
}


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

using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;

    int res = n%(max(h,w)) == 0 ? n/max(h,w) : n/max(h,w)+1;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 764
(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
(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)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil

(defun enum-divisors (n)
  (declare (optimize (speed 3))
           ((integer 1 #.most-positive-fixnum) n))
  (if (= n 1)
      (list 1)
      (let* ((root (isqrt n))
             (res (list 1)))
        (labels ((%enum (i former latter)
                   (declare ((integer 1 #.most-positive-fixnum) i))
                   (if (< root i)
                       (setf (cdr former) latter)
                       (multiple-value-bind (quot rem) (floor n i)
                         (if (zerop rem)
                             (progn
                               (setf (cdr former) (list i))
                               (setf latter (cons quot latter))
                               (%enum (1+ i) (cdr former) latter))
                             (%enum (1+ i) former latter)))))
                 (%enum-for-square (i former latter)
                   (declare ((integer 1 #.most-positive-fixnum) i))
                   (if (= root i)
                       (setf (cdr former) (cons i latter))
                       (multiple-value-bind (quot rem) (floor n i)
                         (if (zerop rem)
                             (progn
                               (setf (cdr former) (list i))
                               (setf latter (cons quot latter))
                               (%enum-for-square (1+ i) (cdr former) latter))
                             (%enum-for-square (1+ i) former latter))))))
          (if (= (* root root) n)
              (%enum-for-square 2 res (list n))
              (%enum 2 res (list n)))
          res))))

(defun main ()
  (let* ((n (read))
         (m (read))
         (max (floor m n))
         (divs (enum-divisors m)))
    (println
     (loop for d in divs
           while (<= d max)
           maximize d))))

#-swank(main)


Measured memory_bytes: 18660
#include <bits/stdc++.h>
#define INF 1e9+7
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

vector<int> v;

int cnt;
void merge(int left,int right) {
    int mid = (left+right)/2;
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> l(n1+1,INF),r(n2+1,INF);
    REP(i,n1) l[i] = v[left+i];
    REP(i,n2) r[i] = v[mid+i];
    int i = 0, j = 0;
    FOR(k,left,right) {
        cnt++;
        if (l[i] <= r[j]) v[k] = l[i++];
        else v[k] = r[j++];
    }
}
void merge_sort(int left, int right) {
    if((left+1) >= right) return;
    int mid = (right-left)/2 + left;
    merge_sort(left,mid);
    merge_sort(mid,right);
    merge(left,right);
}

void solve() {
    cnt = 0;
    int n;
    cin >> n;
    v.resize(n);
    REP(i,n) cin >> v[i];
    merge_sort(0,n);
    REP(i,n) {
        if (i != 0) cout << " ";
        cout << v[i];
    }
    cout << endl;
    cout << cnt << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 6844
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[110][110];
int deg[110][110];
int main(){
	int a;
	long long b;
	while(scanf("%d%lld",&a,&b),a){
		b--;
		if(a%2||(1LL<<(a/2))<=b){
			printf("No\n\n");
			continue;
		}
		for(int i=0;i<110;i++)for(int j=0;j<110;j++)
			str[i][j]=deg[i][j]=0;
		for(int i=0;i<a/2;i++){
			if(b&(1LL<<(a/2-1-i))){
				str[0][i*2]=str[0][i*2+1]='E';
			}else{
				str[0][i*2]=str[0][i*2+1]='.';
			}
		}
		for(int i=0;i<a;i++){
			if(i&&str[0][i]==str[0][i-1])deg[0][i]++;
			if(i<a-1&&str[0][i]==str[0][i+1])deg[0][i]++;
		}
		for(int i=1;i<a;i++){
			for(int j=0;j<a;j++){
				if(deg[i-1][j]<2){str[i][j]=str[i-1][j];deg[i][j]++;}
				else if(str[i-1][j]=='E')str[i][j]='.';
				else str[i][j]='E';
			}
			for(int j=0;j<a;j++){
				if(j&&str[i][j]==str[i][j-1])deg[i][j]++;
				if(j<a-1&&str[i][j]==str[i][j+1])deg[i][j]++;
			}
		}
		for(int i=0;i<a;i++)printf("%s\n",str[i]);
		printf("\n");
	}
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a[12];
	int n;
	cin>>a;
	n=strlen(a);
	long long r=0;
	for(int i=0;i<1<<(n-1);i++)
	{
		long long m=0,s=0;
		m=0;
		s=0;
		for(int j=0;j<n;j++)
		{
			m*=10LL;
			m+=a[j]-'0';
			if(j<n-1&&(i>>j&1))
			{
				s+=m;
				m=0;
			}
		}
		s+=m;
		r+=s;
	}
	cout<<r<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main (int argc, char** argv) {
     int N;

     cin >> N;

     int a[N + 1];
     for (int i = 1; i < (N + 1); i++) {
	  cin >> a[i];
     }

     int pair = 0;
     for (int i = 1; i < (N + 1); i++) {
	  if ((i) == a[a[i]]) {
	       pair++;
	       a[a[i]] = 0;
	  }
     }

     cout << pair << endl;

     return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int a,b,c,m;
    scanf("%d%d%d",&a,&b,&c);
    m=a;
    if(m<b) m=b;
    if(m<c) m=c;
    printf("%d\n",a+b+c-m);
    return 0;
}


Measured memory_bytes: 128
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int k, int[] h) {
    h.sort();
    int ans = int.max;
    for (int i = k - 1; i < h.length; i++) {
        ans = min(ans, h[i] - h[i - k + 1]);
    }
    return ans;
}

void main() {
    auto nk = readints;
    int n = nk[0], k = nk[1];
    int[] h;
    for (int i = 0; i < n; i++) h ~= readint;
    writeln(calc(k, h));
}


Measured memory_bytes: 3708
// Think twice, Code once
// 1SAC
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
/*============================ DEBUGGING =============================*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
/*============================= DEFINES ==============================*/
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
/*============================== TYPEDEFS ============================*/
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;
/*============================ START FROM HERE =======================*/
 
int main(){
	FIO
	
	string s,t;cin >> s >> t;
	t+=s;
	cout << t;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

const int m = 2019;

int main()
{

    

    for (int i = 0; i < 3000; i++)
    {
        int x, y;
        cin >> x >> y;
        if (x == 0 && y == 0)
        {
            break;
        }
        if (x <= y)
        {
            cout << x << " " << y << endl;
        }
        else
        {
            cout << y << " " << x << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 2988
<?php
  $n = trim(fgets(STDIN));
  $a = explode(" ", trim(fgets(STDIN)));
  $count = 0; $two=0;
  for($i=0; $i<$n; $i++){
      if($a[$i]%4 == 0){
          $count++;
          continue;
      }else if($a[$i]%2 == 0){
          $two++;
      }
  }
  if($two > 0) $two--;
  if($n-$two == 1){
      echo "Yes";
      exit;
  }
  echo $count >= (int)(($n-$two)/2) ? "Yes" : "No";

Measured memory_bytes: 12792
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll k;
    cin>>k;
    vl as(k);
    cin>>as;
    reverse(rng(as));

    ll cur = -1;
    ll l = 2, u = 2;
    rep(i, k) {
        l = ((l + as[i] - 1) / as[i]) * as[i];
        u = u / as[i] * as[i] + as[i] - 1;
        if (l > u) {
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<l<<" "<<u<<endl;
}

Measured memory_bytes: 1024
open Str

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f
                                                 
let () =
  let n = read_int () in
  let xs = read_list int_of_string in
  let sxs = List.sort compare xs in
  let d = List.nth sxs (n-1) - List.hd sxs in
  string_of_int d |> print_endline
                                       


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
int parent(int i);
int left(int i);
int right(int i);

int main(){
  int H,i;
  int A[MAX];

  scanf("%d",&H);

  for(i=1; i<=H; i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=H; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1){
      printf("parent key = %d, ",A[parent(i)]);
	     }
     if(left(i) <= H){
	 printf("left key = %d, ",A[left(i)]);
		 }
     if(right(i)<= H){
	      printf("right key = %d, ",A[right(i)]);
	    }
	  printf("\n");
       }
      return 0;
    }



int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}



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

long L, A, B, M;

struct Matrix {
    using T = unsigned long;
    vector<vector<T> > data, tmp;
    Matrix(int h,int w) : data(h, vector<T>(w)) {}

    // get mat info
    inline T& at(int i,int j) { return data[i][j]; }
    inline const T& at(int i,int j) const { return data[i][j]; }
    inline int height() const { return (int)data.size(); }
    inline int width() const { return (int)data[0].size(); }
    //

    static Matrix identity(int n) {
        Matrix E(n, n);
        for(int i = 0; i < n; ++i) E.at(i,i) = 1;
        return E;
    }

    Matrix &operator*(const Matrix &m) {
        int H =   height(); int W =   width();
        int h = m.height(); int w = m.width();
        // assert(W == h);

        tmp.assign(H, vector<T>(w));
        for(int i = 0; i < H; ++i){
            for(int j = 0; j < w; ++j){
                T x = 0;
                for(int k = 0; k < h; ++k){
                    (x += data[i][k] % M * m.at(k, j) % M) %= M;
                }
                tmp[i][j] = x;
            }
        }
        data.swap(tmp);
        return *this;
    }
};

Matrix pow(Matrix &mat, long power) {
    Matrix product = Matrix::identity(mat.height());
    while(power) {
        if(power & 1) product = product * mat;
        mat = mat * mat;
        power >>= 1;
    }
    return product;
}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> L >> A >> B >> M;
    // si = A + B * i (i:0~L-1)

    // 前提1：ばかでかい数のあまりは上位桁からとる。
    // 3 7 11 15 19 なら
    // ((((3 % M * 10 + 7) % M) * 10^2 + 11) % M) * 10^2 + 15 ...

    // 前提2：構築途中の整数をx, 次に下位にくっつける数字をsとすると、 x' = x*10^(sの桁数) + s
    // sの桁数が一定の場合、これはあふぃん変換になる。なので行列累乗で高速化できる。
    // 桁数は最大18なので、桁数ごとに行列累乗しても間に合う。

    // 前提3：桁ごとの行列演算に必要なのは、その桁の初項と項数
    // にぶたんでその桁の最小値をとるindexと、次の桁の最小値をとるindexをみつければよい。

    long x = 0;
    long now = 1;
    for(int i = 0; i < 18; ++i, now *= 10) {
        // 今の桁で最小値を出すindexをにぶたん
        long l = -1, r = L;
        while(abs(r - l) > 1) {
            long mid = (r + l) / 2;
            if(A + B * mid >= now) r = mid;
            else l = mid;
        }
        long idx = r;

        // 次の桁で最小値を出すindexをにぶたん
        l = -1, r = L;
        while(abs(r - l) > 1) {
            long mid = (r + l) / 2;
            if(A + B * mid >= now*10) r = mid;
            else l = mid;
        }
        long nidx = r;

        long first = A + B * idx;

        if(nidx - idx == 0) continue;
        // x' = (10^d 1 0) x
        // s' = (0    1 B) s
        // 1  = (0    0 1) 1
        // こう？
      
        // 行列演算
        Matrix mat(3, 3);
        mat.at(0, 0) = now * 10 % M;
        mat.at(0, 1) = 1;
        mat.at(1, 1) = 1;
        mat.at(1, 2) = B % M;
        mat.at(2, 2) = 1;
        mat = pow(mat, nidx - idx);

        Matrix target(3, 1);
        target.at(0, 0) = x;
        target.at(1, 0) = first % M;
        target.at(2, 0) = 1;

        target = mat * target;
        x = target.at(0, 0);
    }
    
    cout << x << endl;
    return 0;
}

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

int main(){
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    int n; cin >> n;
    
    for(int k=0;k<n;k++){
        int b; cin >> b;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(a[i][j] == b){
                    a[i][j] = 0;
                }
            }
        }
    }
    //横ビンゴチェック
    for(int i=0;i<3;i++){
        int check = 0;
        for(int j=0;j<3;j++){
            check += a[i][j];
        }
        if(check==0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    //縦ビンゴチェック
    for(int j=0;j<3;j++){
        int check = 0;
        for(int i=0;i<3;i++){
            check += a[i][j];
        }
        if(check==0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    //斜めビンゴチェック
    int Check = 0;
    for(int i=0;i<3;i++){
        Check += a[i][i];
    }
        if(Check == 0){
            cout <<"Yes" << endl;
            return 0;
        }
    //斜めビンゴチェック
    if(a[0][2]+a[1][1]+a[2][0] == 0){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mx=1e9+7;
int a[100010];
int cnt[100010];
int main(){
	memset(cnt,0,sizeof(cnt));
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	if(n%2!=0){
		if(cnt[0]!=1){
			cout<<0<<endl;
			return 0;
		}
		for(int i=0;i<n;i++){
			if(a[i]!=0&&cnt[a[i]]!=2){
				cout<<0<<endl;
				return 0;
			}
		}
	}
	else if(n%2==0){
		if(cnt[0]!=0){
			cout<<0<<endl;
			return 0;
		}
		for(int i=0;i<n;i++){
			if(a[i]!=0&&cnt[a[i]]!=2){
				cout<<0<<endl;
				return 0;
			}
		}
	}
	int ans=1;
	if(n%2==0){
		for(int i=1;i<=n/2;i++){
			ans=ans*2;
			ans=ans%mx;
		}
	}
	else if(n%2!=0){
		for(int i=1;i<=n/2;i++){
			ans=ans*2;
			ans=ans%mx;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main(){
int n,i,j,k,l,q,w,e,r=0,u,y;
string s,c;
cin>>n>>s;
q=s.size();
for(u=0;u<n;u++){
	cin>>c;
	k=c.size();
	y=0;
	for(i=0;i<k&&y!=1;i++){
		for(j=1;i+j*(q-1)<k&&y!=1;j++){
			l=i;
			e=0;
			for(w=0;w<q;w++){
				if(s[w]!=c[l])e=1;
				l+=j;
			}
			if(e==0)y=1;
		}
		if(y==1)r++;
	}
}
cout<<r<<endl;
return 0;
}






















	

Measured memory_bytes: 3168
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]
r=[]
for i in ab:
  x1,y1=i[0],i[1]
  temp=[]
  for j in cd:
    x2,y2=j[0],j[1]
    temp.append(abs(x1-x2)+abs(y1-y2))
  r.append(temp.index(min(temp))+1)
print(*r,sep='\n')

Measured memory_bytes: 9244
a,b,x = map(int,input().split())
import math
# 0025~
# xがa*a*bの半分仮想で内科で場合分け.片側が常に限界まで水があるので
# 右へ右へと傾けていくことを考えている
maxL = a*a*b
# 半分より大きい場合．すなわち左側の水線がどんどん落ちていく場合，
rest = maxL -x
if rest <= maxL / 2:
    # 半分の容量に対してどれだけ減ったかを調べる
    dropped = (rest / (maxL/2)) * b
    # 傾けた角度は，dropped, a, の辺を持った直角三角形の角度tan-1(dropped/a)となる.
    theta = math.atan(dropped/a) / math.pi * 180.0
    print(abs(theta))
    exit()

# 半分より小さい場合，すなわち水線が底面の左から落ちていく場合
# 作られる削ってくる三角形
#rest = (maxL/2)-x
#dropped = rest /(maxL/2)
# ああ逆でいいのか
h = a * (x/(maxL/2))
theta2 = math.atan(h/b)/math.pi * 180.0
theta1 = math.atan(b/a)/math.pi * 180.0
# 更に傾けた角度は，(180-theta1) - theta2
print(theta1 + (90-theta1)-theta2)







Measured memory_bytes: 3188
n,k = (int(x) for x in input().split())
a = list(map(int, input().split()))
max_digit = 50
dp = [[-1,-1] for _ in range(max_digit + 10)]
dp[0][0] = 0

for i in range(max_digit):
  mask = 1<<(max_digit - i - 1)
  num = 0
  for j in range(n):
    if(mask&a[j]):
      num += 1
  cost0 = num*mask
  cost1 = (n-num)*mask
  if(dp[i][1] != -1):
    dp[i+1][1] = max(dp[i+1][1], (dp[i][1] + max(cost0, cost1)))
  if(dp[i][0] != -1):
    if(mask&k):
      dp[i+1][1] = max(dp[i+1][1], dp[i][0] + cost0)
      dp[i+1][0] = max(dp[i+1][0], dp[i][0] + cost1)
    else: 
      dp[i+1][0] = max(dp[i+1][0], dp[i][0] + cost0)

print(max(dp[max_digit]))
  
  


Measured memory_bytes: 14700
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let r: isize = iterator.next().unwrap().parse().unwrap();
    let g: isize = iterator.next().unwrap().parse().unwrap();
    let b: isize = iterator.next().unwrap().parse().unwrap();
    let n: isize = iterator.next().unwrap().parse().unwrap();

    let mut ans = 0;
    for i in 0..(n / r + 1) {
        for j in 0..(n / g + 1) {
            let k1 = (n - i * r - j * g) / b;
            let k2 = (n - i * r - j * g) % b;
            if k1 >= 0 && k2 == 0 {
                ans += 1;
            }
        }
    }

    return ans.to_string();
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int f(int n) {
	return n % 2 ? 3*n+1 : n/2;
}

int main(int argc, char const *argv[]) {
	int s; cin >> s;
	vector<int> a(100000, 0);
	vector<bool> b(100000, false);
	a[0] = s;
	b[s] = true;
	REP(i, 1, 1000000) {
		a[i] = f(a[i-1]);
		if (b[a[i]]) {cout << i + 1 << endl; return 0;}
		b[a[i]] = true;
	}
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int k, n;
	string s;
	cin >> n;
	cin >> s;
	cin >> k;

	for (int i = 0; i < n; i++) {
		if (s[i] != s[k-1]) {
			s[i] = '*';
		}
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())

if (A+B)/2 >= C and X >= Y:
  print(Y*2*C+A*(X-Y) if A*(X-Y)<2*C*(X-Y) else X*2*C)
elif (A+B)/2 >= C and Y >= X:
  print(X*2*C+B*(Y-X) if B*(Y-X)<2*C*(Y-X) else Y*2*C)
else:
  print(A*X+B*Y) 

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll unsigned long long
//#define mod 1000000007
#define NCONS 100001

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int N; cin >> N;
	int cur = 2;
	while (cur <= N)
	{
		cur *= 2;
	}
	cout << cur / 2;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  maxi = max(p[i-1],p[i],p[i+1])
  mini = min(p[i-1],p[i],p[i+1])
  if p[i] != maxi and p[i] != mini:
    ans += 1
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

unsigned GetDigit(unsigned num){
    return to_string(num).length();
}

int main() {
	string s, t; cin >> s >> t;
	int n = s.size();
	bool a = true;
	rep(i, n) {
		if (s[i] != t[i]) a = false;
	}
	bool b = true;
	int m = t.size();
	if (m != n + 1) b = false;

	if (a && b) puts("Yes");
	else puts("No");

	return 0;
}


Measured memory_bytes: 3632
import sys
import time
from collections import deque

start = time.time()

input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
player_in_this_game = set()
rn = range(n)
for _ in r5000:
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    if m in player_in_this_game:
      #自分が既に試合が組まれている
      continue

    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      teki_idx = teki - 1
      if teki_idx in player_in_this_game:
        #相手が既に試合に組まれている
        continue

      if a[teki_idx][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki_idx].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki_idx) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1
  player_in_this_game.clear()
  elapsed_time = time.time() - start
  if elapsed_time > 1:
    print(n*(n-1)//2)
    exit()


Measured memory_bytes: 36092
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0

for dq in range(min(n+1, k+1)):
    for rdq in range(dq+1):
        ldq = dq-rdq
        jwl = v[n-rdq:]+v[:ldq]
        jwl.sort()

        val = sum(jwl)
        for i in range(min(k-dq, len(jwl))):
            if jwl[i] < 0:
                val -= jwl[i]
            else:
                break

        ans = max(ans, val)

print(ans)


Measured memory_bytes: 3064
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();
        int count = 0;
        int[] a = new int[3];
        for(int i = 0; i < 1000; i++){
            a[0] = i/100;
            a[1] = (i - a[0] * 100)/10;
            a[2] = i%10;
            int index = 0;
            for(int j = 0; j < n; j++){
                if(a[index] == (s.charAt(j)-'0')){index++;}
                if(index == 3){count++;break;}
            }
        }
        System.out.println(count);
    }
}



Measured memory_bytes: 23636
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e5+10;
int a[N],b[N];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	scanf("%d%d",&a[i],&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	long long ans=0;
	if(n%2)
	{
		ans=b[n/2+1]-a[n/2+1]+1;
	}
	else
	ans=b[n/2]+b[n/2+1]-a[n/2]-a[n/2+1]+1;
	printf("%lld\n",ans);
}

Measured memory_bytes: 4788
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

void solve(){
	string s;
	ll q;
	cin>>s>>q;
	deque<char> dq;
	for(auto i:s)	dq.push_back(i);
	bool f=0;
	while(q--){
		ll t;
		cin>>t;
		if(t==1){
			f = f^1;
		}
		else{
			ll f1;	
			char c;
			cin>>f1>>c;
			f1--;
			f1 = f1 ^ f;
			if(f1){
				dq.push_back(c);
			}
			else{
				dq.push_front(c);
			}
		}
	}
	if(f){
		reverse(dq.begin(), dq.end());
	}
	for(auto i:dq)	cout<<i;cout<<endl;
	return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll no;
	// cin>>no;
	no = 1;
	while(no--){
		solve();
	}
    return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int h,a,b,c;
int main()
{
	scanf("%d%d",&h,&a);
	for(int i=1; i<=a; i++)
	{
		scanf("%d",&b);
		c+=b;
	}
	if(c>=h)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <utility>
using namespace std;

#define INF 1000000000

int main(void)
{
    int n;
    scanf("%d", &n);

    int r[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &r[i]);
    }

    int minv = r[0];
    int diff = -INF;
    for (int i = 1; i < n; i++)
    {
        diff = max(diff, r[i] - minv);
        minv = min(minv, r[i]);
    }

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

    return 0;
}



Measured memory_bytes: 4012
#include <stdio.h>

int main(void) {
	int a, v, b, w, t;
	int dis = 0;

	scanf("%d", &a);
	scanf("%d", &v);
	scanf("%d", &b);
	scanf("%d", &w);
	scanf("%d", &t);

	dis = abs(b - a);

	double tmp = (double)dis / (v - w);

	if (tmp <= t && tmp >= 0) {
		puts("YES");
	}
	else {
		puts("NO");
	}

	return 0;
}

Measured memory_bytes: 2092
import sys

L, R = map(int, sys.stdin.readline().split())
mod = 2019

mod_L = L%2019
mod_R = R%2019

for i in range(L + 1, R + 1):
    if i % mod == 0:
        print(0)
        sys.exit()

if R - L >= 2019:
    temp_i = mod_L
    temp_j = 2018
else:
    temp_i = mod_L
    temp_j = mod_R

min_mod = 2019
for i in range(mod_L, mod_R):
    for j in range(i + 1, mod_R + 1):
        if ((i*j)%mod) < min_mod:
            min_mod = (i*j)%mod
print(min_mod)

Measured memory_bytes: 3064
# import sys
# input = sys.stdin.readline

# import numpy as np
# from itertools import permutations
# from itertools import combinations
# from itertools import combinations_with_replacement
# import queue
# import heapq

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))



def main():
    S = input()
    T = input()

    ok = True
    for i, s in enumerate(S):
        if s != T[i]:
            ok = False

    if ok:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9036
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <fstream>
#include <bitset>
#include <array>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define erep(i, n) for (int i = 0; i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

const int INF = -1;

typedef long long ll;
typedef pair<int, int> pii;

ll dp[31];
int N;

void solve() {
    dp[1] = 1;
    dp[2] = 2;
    dp[3] = 4;
    for (int i = 4; i <= 30; ++i) dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
}

int main() {
    clr(dp, -1);
    solve();
    while (cin >> N, N) {
        cout << (dp[N]/10)/365+bool(dp[N]%3650) << endl;
    }
    return 0;
}

Measured memory_bytes: 3052
h,w=map(int,input().split())
cnt=0
ans=[]
a=[list(map(int,input().split())) for _ in [0]*h]
for i in range(h):
    for j in range(w-1):
        if a[i][j]%2:
            a[i][j+1]+=1
            cnt+=1
            ans.append((i+1,j+1,i+1,j+2))
for i in range(h-1):
    if a[i][w-1]%2:
        a[i+1][w-1]+=1
        ans.append([i+1,w,i+2,w])
        cnt+=1
print(cnt)
for i in ans:
    print(*i)

Measured memory_bytes: 74332
unittest
{
	assert( [ "1 2 2 2 1", "2 4", "5 1", "3" ].solve == 12 );
	assert( [ "2 2 2 2 2", "8 6", "9 1", "2 1" ].solve == 25 );
	assert( [ "2 2 4 4 4", "11 12 13 14", "21 22 23 24", "1 2 3 4" ].solve == 74 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto x = 0L;
	auto y = 0L;
	auto a = 0L;
	auto b = 0L;
	auto c = 0L;
	input.front.formattedRead!"%s %s %s %s %s"( x, y, a, b, c );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	input.popFront;
	auto qs = input.front.split.to!( long[] );
	input.popFront;
	auto rs = input.front.split.to!( long[] );
	
	ps.sort;
	qs.sort;
	rs.sort;
	ps = ps[ $ - x .. $ ];
	qs = qs[ $ - y .. $ ];
	
	// 赤か緑のリンゴのうち、美味しくないほうから無色のリンゴに交換
	auto ans = ps.sum + qs.sum;
	ps ~= long.max;
	qs ~= long.max;
	foreach_reverse( r; rs )
	{
		if( ps.front < qs.front )
		{
			if( r < ps.front ) break;
			ans += r - ps.front;
			ps.popFront;
		}
		else
		{
			if( r < qs.front ) break;
			ans += r - qs.front;
			qs.popFront;
		}
	}
	return ans;
}


Measured memory_bytes: 15256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] arr = new int[n];
        int[] dis = new int[n];
        arr[0] = sc.nextInt();
        for (int i = 1; i < n; i++) {
            arr[i] = sc.nextInt();
            dis[i - 1] = arr[i] - arr[i - 1];
        }
        dis[n - 1] = arr[0] - arr[n - 1] + k;
        Arrays.sort(dis);
        System.out.println(k - dis[n - 1]);
    }
}

Measured memory_bytes: 87632