akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

int main() {
	int n, m;
	cin >> n >> m;

	vector<int> a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];

	set< vector<int> > st;

	int ans = 0,s = 0, t = 1;
	while(s != b.size()) {
		vector<int> v(t - s);
		REP(j, s, t) {
			v[j-s] = b[j];
		}

		bool flag = false;
		int id = 0;
		rep(j, n) {
			if(a[j] == v[id]) {
				id++;
				if(id == v.size()) {
					flag = true;
					break;
				}
			}
		}

		if(flag) {
			t++;
			ans = max(ans, (int)v.size());
		} else {
			s++;
			if(s == t) t++;
		}

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

int dp[210100][2];
signed main() {
	
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	string s;
	cin>>s;

	bool flag=false;
	int cnt=0,cnt1=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='#')
		{
			dp[i+1][0]=min(dp[i][0],dp[i][1]);
			dp[i+1][1]=dp[i][1]+1;
		}else{
			dp[i+1][0]=min(dp[i][0],dp[i][1])+1;
			dp[i+1][1]=dp[i][1];
		}	
	}
	cout<<min(dp[n][0],dp[n][1])<<endl;
	return  0;

}


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

struct node{
  int key;
  struct node *pa;
  struct node *le;
  struct node *ri;
};
typedef struct node* TREE;
TREE root;

void insert(int);
int find(int);
void print();
void inorder(TREE);
void preorder(TREE);
TREE successor(TREE);
TREE minimum(TREE);
void delete(int);

int main(){
  int i,m,num;
  char com[7];

  scanf("%d",&m);
  if(m>500000) exit(2);
  root = NULL;
  for(i=0;i<m;i++){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d",&num);
      insert(num);
    }
    else if(com[0] == 'p')print();
    else if(com[0] == 'f'){
      scanf("%d",&num);
      if(find(num) == 1) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] == 'd'){
      scanf("%d",&num);
      delete(num);
    }
  }
  
  return 0;
}

void insert(int key){
  TREE node_root=root,newnode,p,oya=NULL;

  newnode = (TREE)malloc(sizeof(struct node));
  newnode->le = newnode->ri = NULL;
  newnode->key = key;
  p=node_root;
  while(p!=NULL){
    oya=p;
    if(p->key > key) p=p->le;
    else p=p->ri;
  }
  newnode->pa = oya;
  if(oya == NULL){
    root = newnode;
  }else{
    if(oya->key > newnode->key) oya->le = newnode;
    else oya->ri = newnode;
  }
}

void print(){
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}

void inorder(TREE out){
  if(out == NULL) return;
  inorder(out->le);
  printf(" %d",out->key);
  inorder(out->ri);
}

void preorder(TREE out){
  if(out == NULL) return;
  printf(" %d",out->key);
  preorder(out->le);
  preorder(out->ri);
}

int find(int key){
  TREE node_root=root,p;

  p=root;
  while(p!=NULL){
    if(p->key == key) return 1;
    if(p->key > key) p=p->le;
    else p=p->ri;
  }
  return 0;
}

void delete(int key){
  TREE p,delch,ne,delnode;
  int i=0;
  
  p=root;
  while(p!=NULL){
    if(p->key > key)p=p->le;
    else if(p->key < key)p=p->ri;
    else{
      if(p->le == NULL || p->ri == NULL){
	delnode = p;
      }else{
	delnode = successor(p);
      }
      if(delnode->le != NULL){
	delch = delnode->le;
      }else{
	delch = delnode->ri;
      }
      if(delch != NULL){
	delch->pa = delnode->pa;
      }
      if(delnode->pa == NULL){
	root = delch;
      }else{
	if(delnode == delnode->pa->le){
	  delnode->pa->le = delch;
	}else{
	  delnode->pa->ri = delch;
	}
      }
      if(delnode != p){
	p->key = delnode->key;
      }
      break;
    }
  }
  free(delnode);
}

TREE successor(TREE x){
  if(x->ri != NULL) return minimum(x->ri);
  TREE y=x->pa;
  while(y != NULL && x == y->ri){
    x=y;
    y=y->pa;
  }
  return y;
}

TREE minimum(TREE x){
  while(x->le != NULL) x=x->le;
  return x;
}



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

using namespace std;
typedef map<const long long, long long> lll;

long long n, k, a[200005], psfront[200005], pslast[200005], summ, cnt, targ;
lll lis;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		a[i] = (a[i] - 1 + k) % k;
	}
	psfront[0] = 0;
	for (int i=1; i<=n; i++) {
		psfront[i] = (psfront[i - 1] + a[i - 1]) % k;
//		cout << "Front of " << i << " is " << psfront[i] << endl;
	}
	pslast[0] = 0;
	lis[0] = 1;
	for (int i=1; i<n; i++) {
		pslast[i] = (pslast[i - 1] + a[n - i]) % k;
//		cout << "Last of " << i << " is " << pslast[i] << endl;
		lis[pslast[i]]++;
	}
	for (int i=0; i<=n-k; i++) lis[pslast[i]]--;
	summ = psfront[n];
	for (int i=0; i<n; i++) {
		targ = (summ - psfront[i] + k) % k;
		cnt += lis[targ];
//		cout << "Cumulative count = " << cnt << endl;
		lis[pslast[n - 1 - i]]--;
		if (n - k - i >= 0) lis[pslast[n - k - i]]++;
	}
	cout << cnt << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> res(N);
  for(int i = 0; i < N; i++) {
    cin >> res.at(i);
  }
  
  int ac_cnt = 0, wa_cnt = 0, tle_cnt = 0, re_cnt = 0;
  
  for(int i = 0; i < N; i++) {
    string jud;
    jud = res.at(i);
    if(jud == "AC") ac_cnt++;
    else if(jud == "WA") wa_cnt++;
    else if(jud == "TLE") tle_cnt++;
    else if(jud == "RE") re_cnt++;
  }
  
  cout << "AC x " << ac_cnt << endl;
  cout << "WA x " << wa_cnt << endl;
  cout << "TLE x " << tle_cnt << endl;
  cout << "RE x " << re_cnt << endl;
}

Measured memory_bytes: 6380
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(1000001);
  rep(i,0,N) {
    i64 a;
    cin >> a;
    A[a]++;
  }
  i64 ans = 0;
  rep(x,0,A.size()) {
    if(A[x] == 0) continue;
    if(A[x] == 1) ans++;
    for(i64 i = x + x; i < A.size(); i += x) {
      A[i] = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 11176
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Not Found
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

bool used[26];

/* subroutines */

/* main */

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

  for (int i = 0; i < s.size(); i++) used[s[i] - 'a'] = true;

  int k = -1;
  for (int i = 0; k < 0 && i < 26; i++)
    if (! used[i]) k = i;

  if (k < 0) puts("None");
  else printf("%c\n", 'a' + k);
  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N]={0};
    int B[N-1];
    for(int i=0;i<N-1;i++) cin >> B[i];

    for(int i=0;i<N-1;i++){
        A[B[i]-1]++;
    }

    for(int i=0;i<N;i++){
        cout << A[i] << endl;
    }
   
}

Measured memory_bytes: 5188
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;

void main() {
    while (true) {
        string s = read!string;
        if (s == null) break;

        auto ab = s.split.to!(int[]);
        int sum = ab[0] + ab[1];
        writeln(sum.to!(string).length);
    }
}



Measured memory_bytes: 2464
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 200010;


int main() {
	int N;
	int p[MAX];
	int table[MAX];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		table[p[i] - 1] = i;
	}

	int cnt = 1;
	int cntMAX = 1;

	for (int i = 1; i < N; i++) {
		if (table[i - 1] < table[i]) {
			cnt++;
		}
		else {
			cntMAX = max(cnt, cntMAX);
			cnt = 1;
		}
	}
	cntMAX = max(cnt, cntMAX);

	cout << N - cntMAX << endl;

	return 0;
}

Measured memory_bytes: 1792
n, k = map(int, input().split())
a_set = set()
for _ in range(k):
    input()
    a = set(map(int, input().split()))
    a_set = a_set | a

n_set = set()
for i in range(1,n+1):
    n_set.add(i)

ans = n_set - a_set

print(len(ans))


Measured memory_bytes: 9188
AB = split(readline())
A = parse(Int,AB[1])
B = parse(Int,AB[2])

function judge(x,y)
    if x == 1
        x = 14
    end
    if y == 1
        y = 14
    end
    if x > y
        println("Alice")
    elseif x < y
        println("Bob")
    else
        println("Draw")
    end
end

judge(A,B)

Measured memory_bytes: 108636
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  ll y = stoll(s.substr(0, 4));
  ll m = stoll(s.substr(5, 2));
  if ((y == 2019 && m <= 4) || (y < 2019)) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int n, k;
    cin >> n >> k;
    vector<double> a(n);
    for(auto &x: a) {
        double t; cin >> t;
        x = (t+1)/2;
    }
    double ans = 0;
    for(int i = 0; i < k; ++i) {
        ans += a[i];
    }
    double tmp = ans;
    for(int i = k; i < n; ++i) {
        tmp -= a[i-k];
        tmp += a[i];
        ans = max(ans, tmp);
    }
    cout << ans;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> rate(8, 0);
	int in;
	int over = 0;//3200以上をカウント
	int cnt = 0;
	bool check = false;//制約範囲内の入力があるかのチェック
	for(int i = 0; i < n; i++){
		if(n > 100)break;
		cin >> in;
		if(in < 1 || in > 4800) continue;
		else {
			check = true;
			if(in >= 3200) over++;//3200以上をカウント
			else rate[in / 400]++;//表埋め
		}
	}

	for(int i = 0; i < 8; i++)if(rate[i] > 0)cnt++;//表の人数が正のものをカウント

	if(!check) cout << "input error" << endl;
	else cout << max(1, cnt) << ' ' << cnt + over << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int digit = String.valueOf(N).length();
		int ans = 0;
		switch(digit) {
		case 1:
			ans = N;
			break;
		case 2:
			ans = 9;
			break;
		case 3:
			ans = N - 90;
			break;
		case 4:
			ans = 909;
			break;
		case 5:
			ans = N - 9090;
			break;
		case 6:
			ans = 90909;
			break;
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 22612
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int r=sc.nextInt();
    int c=sc.nextInt();
    int[][] a=new int[r+1][c+1];
    int sum=0;
    for(int i=0;i<r;i++){
      for(int j=0;j<c;j++){
        a[i][j]=sc.nextInt();
        a[i][c]+=a[i][j];
        a[r][j]+=a[i][j];
        sum+=a[i][j];
      }
    }
    a[r][c]=sum;
    for(int i=0;i<r+1;i++){
      for(int j=0;j<c;j++){
        System.out.print(a[i][j]+" ");
      }
      System.out.println(a[i][c]);
    }
  }
}




Measured memory_bytes: 45400
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut x: u32 = read();
    let a: u32 = read();
    let b: u32 = read();

    x -= a;
    while x >= b {
        x -= b;
    }

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


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef pair<int, int> P;
typedef long long LL;

static const int INF = INT_MAX;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    string s,t; cin >> s >> t;
    int siz_s = (int)s.size();
    int siz_t = (int)t.size();
    
    vector<string> v;
    for(int i=0;i<siz_s-siz_t+1;i++){
        int cnt = 0;
        for(int j=0;j<siz_t;j++){
            if(s[i+j] == '?'){
                cnt++;
                continue;
            }
            else if(s[i+j] == t[j]) cnt++;
        }

        if(cnt == siz_t){
            string key = s;
            for(int k=0;k<siz_t;k++) key[i+k] = t[k];
            for(int k=0;k<siz_s;k++){
                if(key[k] == '?') key[k] = 'a';
            }
            v.push_back(key);
        }
    }

    if((int)v.size() < 1){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }else{
        sort(v.begin(),v.end());
        cout << v[0] << endl;
        return 0;
    }
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;
use std::collections::BTreeSet;

fn main() {
    input! {
        n: usize
    }

    let mut mat = Vec::new();

    for _ in 0..n {
        input! {
            a: usize,
            x: [(Usize1,usize); a]
        }
        mat.push(x);
    }

    let ans = {
        let mut ans = 0;
        for b in 0..2u32.pow(n as u32) {
            let mut flag = true;
            let shojiki = (0..n).filter(|i| (b >> i) & 1 == 1).collect::<BTreeSet<usize>>();
            for &i in shojiki.iter() {
                if !flag {
                    break;
                }
                for &(j,whi) in &mat[i] {
                    if (shojiki.contains(&j) && whi == 0) || (!shojiki.contains(&j) && whi == 1) {
                        flag = false;
                        break;
                    }
                }
            }
            if flag && ans < shojiki.len() {
                ans = shojiki.len();
            }
        }
        ans
    };


    println!("{}",ans)
}

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

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    vector<vector<int>> res(H, vector<int>(W));
    int next_h = 0, next_w = 0;
    for (int a = 0; a < N; a++) {
        int n = A[a], cnt = 0;
        int h = next_h;
        for (int i = h; i < H && cnt < n; i++) {
            int w = next_w;
            if (i % 2 == 0) {
                for (int j = w; j < W && cnt < n; j++) {
                    res[i][j] = a + 1;
                    cnt++;
                    if (j == W - 1 && i <= H - 1) {
                        next_h = i + 1; next_w = j;
                    } else {
                        next_h = i; next_w = j + 1;
                    }
                }
            } else {
                for (int j = w; j >= 0 && cnt < n; j--) {
                    res[i][j] = a + 1;
                    cnt++;
                    if (j == 0 && i <= H - 1) {
                        next_h = i + 1; next_w = j;
                    } else {
                        next_h = i; next_w = j - 1;
                    }
                }
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

int n;

int pow(int a, int p) {
    int ans = 1;
    while (p > 0) {
        ans *= a;
        p--;
    }
    return ans;
}

int cost(int a, int p) {
    int tmp = p;
    while (tmp < a) {
        tmp *= p;
    }

    int cost = 0;
    for (; tmp > 1; tmp /= p) {
        if (a >= tmp) {
            cost += a / tmp;
            a -= tmp * (a / tmp);
        }
        //cout << tmp << ", "<< a << ": " << cost << endl;
    }
    return cost;
}

int main(){
  //cout << cost(91, 9) << endl;
    cin >> n;
    int ans = n;
    for (int k = 0; k <= n; k+=6) {
        int c = cost(k, 6);
        c += cost(n - k, 9);
        //cout << k << ", " << cost(k, 6) << " " << n - k << ", " <<  cost(n - k, 9) << " ... " << (n - k) % 9  <<endl;
        c += (n - k) % 9;
        ans = min(c, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <map>
#include <string>

int main()
{	
	std::map<std::string, long long int> M;
	
	int q; std::string sq;
	getline(std::cin, sq); q = std::stoi(sq);
	for (int i=0; i<q; i++) {
		std::string key;
		int op;
		long long int x;
		
		std::string buf;
		getline(std::cin, buf);
		op = buf[0] - '0';
		int sp_pos = buf.find(' ', 2);
		if (sp_pos != std::string::npos) {
			key = buf.substr(2, sp_pos-2);
			x = std::stoll(buf.substr(sp_pos+1));
		} else {
			key = buf.substr(2);
		}
		if (op==0) {
			M[key] = x;
		} else {
			if (M.find(key) != M.end()) std::cout << M[key] << std::endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 25916
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int a, b;
	cin >> a >> b;

	if (a <= 0 && b >= 0 || a == 0 || b == 0) cout << "Zero" << endl;
	else {
		if (a > 0) cout << "Positive" << endl;
		else {
			if ((b - a) % 2 == 1) cout << "Positive" << endl;
			else cout << "Negative" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
path = [[] for _ in range(n)]
pp = set()
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if (a, b) in pp:
        continue
    else:
        pp.add((a, b))
        path[a].append(b)
    if (b, a) in pp:
        continue
    else:
        pp.add((b, a))
        path[b].append(a)
# print(path)
ans = 0
for i in range(n):
    ok = True
    for j in path[i]:
        if h[i] <= h[j]:
            ok = False
    if ok:
        ans += 1

print(ans)


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

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    cout << (n-1)/max(h,w)+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)    cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
//----------------------------------------------------------------
ll gcd(ll a, ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}

int main(void) {
  ll k;
  cin >> k;

  ll ans=0;
  rep(a,k){
    rep(b,k){
      rep(c,k){
        ans+=gcd((a+1),gcd(b+1,c+1));
      }
    }
  }

  prt(ans);
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.14159265359
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-------------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	string ar[n+1];
	map<string,ll> mp;
	ll mx=0;	
	for(i=1;i<=n;i++){
		cin>>ar[i];
		mp[ar[i]]++;
		if(mp[ar[i]]>mx){
			mx=mp[ar[i]];
		}
	}

	for(auto it:mp){
		if(it.sc==mx)
			cout<<it.fs<<endl;
	}
	return 0;
}

Measured memory_bytes: 25472
import numpy as np

# 初期値を入力

N, T = map(int, input().split())

Cost = np.zeros((N, 2))
for i in range(N):
    Cost[i, 0], Cost[i, 1] = map(int, input().split())


# メインプログラム

Cost_Best = 100000

for i in range(N):

    if Cost[i,1] <= T:
        if Cost[i,0] < Cost_Best:
            Cost_Best = Cost[i,0]

if Cost_Best == 100000:
    print( "TLE" )
else:
    print(int(Cost_Best))


Measured memory_bytes: 12496
from collections import Counter
N,K=map(int,input().split())
m=[]
for i in range(1,N+1):
    m.append(i%K)
Cnt=Counter(m)
cnt=0
for a in range(K):
    r=(K-a)%K
    if((2*r)%K==0):
        cnt+=Cnt[r]**2*Cnt[a]
print(cnt)

Measured memory_bytes: 16620
#include<bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 +7;
constexpr int MAXNe6 = 1e6 + 7;
#pragma region 
inline long long read()
{
	char c = getchar();long long flag = 1, ans = 0;
	while(c < '0' || c > '9'){if(c == '-')flag = -1; c = getchar();}
	while(c >= '0' && c <= '9'){ans = ans * 10 + c - '0'; c = getchar();}
	return (ans * flag);
}
#pragma endregion
// C'est la vie
long long dp[10007];
int main() {
    int h = read(), n = read();
    vector<pair<int, int> > ve;
    memset(dp, 0x3f3f3f3f, sizeof(dp));
    ve.emplace_back(make_pair(0, 0));
    for(int i = 1; i <= n; ++ i) {
        int u = read(), v = read();
        ve.emplace_back(make_pair(u, v));
    }
    dp[0] = 0;
    for(int i = 1; i <= n; ++ i) {
        for(int j = 0; j <= h; ++ j) {
            dp[j] = min(dp[j], dp[((j - ve[i].first <= 0) ? 0 : j - ve[i].first)] + ve[i].second);
        }
    }
    cout << dp[h];
    #ifndef ONLINE_JUDGE
    system("pause");
    #endif
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

bool f(int x){
    vector<int> a(10);
    while(x){
        a[x % 10]++;
        x /= 10;
    }
    for(int i = 3; i <= 7; i+=2){
        if(a[i] == 0) return false;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    queue<ll> q;
    q.push(0);
    ll num = 0, ans = 0;
    while(true){
        num = q.front(); q.pop();
        for(int i = 3; i <= 7; i+=2){
            ll next = num * 10 + i;
            if (next > n){
                cout << ans << endl;
                return 0;
            }
            if (f(next)) ans++;
            q.push(next);
        }
    }
}

Measured memory_bytes: 3756
# 1文字ずつ格納
a = [str(i) for i in input()] 
max=0
ans=0


for i in range(len(a)):

    if a[i] == "A" or a[i] == "C" or a[i] == "G" or a[i] == "T":
        max=max+1
    else:
        if(ans <= max):
            ans=max
            max=0
        
        
if(ans <= max):
    ans=max

if ans >= 11:
    ans=10
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int k;
  cin >> k;
  if(k%2==0) {
    cout << k/2 * k/2 << endl;
  } 
  else {
    cout << k/2 * (k/2 + 1) << endl;
  } 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}
    int32_t main()
    {
        std::ios::sync_with_stdio(false);
        char c;
        cin>>c;
        if(c>='A' && c<='Z')
            cout<<'A'<<endl;
        else
            cout<<'a'<<endl;
        return 0;
    }


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

using namespace std;

int main(void) {
    int n, k;
    scanf("%d %d", &n, &k);
    if (2*k-1 <= n) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

signed main(){
  int n;string s;cin>>n>>s;
  int cnt = 0, cnt2 = 0, ba = 0;
  rep(i,n){
    if(s[i] == ')'){
      if(ba > 0)ba--;
      else cnt++;
    }else{
      ba++;
    }
  }
  string a = string(max(0LL, cnt),'('), b = string(max(0LL, ba),')');
  cout << a << s << b << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

n = 1
order = [n]
order_set = set([n])

for i in range(1, K + 1):
    n = A[n - 1]
    if n in order_set:
        Li = order.index(n)
        Ri = len(order)
        idx = Li + (K - Li) % (Ri - Li)
        print(order[idx])
        exit()
    else:
        order.append(n)
        order_set.add(n)
        continue
print(n)


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  char prev='9';
  int ret=0;
  for(int i=0; i<n; i++){
    if(prev!=s[i]){
      ret++;
      prev=s[i];
    }
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
int bits(int x) {
    int ret = 0;
    while (x) {
        ret += x & 1;
        x >>= 1;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vvi a(n, vi(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }
    vvl dp(n + 1, vl(1 << n, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= 1 << n; ++j) {
            if (__builtin_popcount(j) != i)
                continue;
            for (int k = 0; k < n; ++k) {
                if (a[i][k] == 1 && !(j & 1 << k)) {
                    dp[i + 1][j | 1 << k] += dp[i][j];
                    dp[i + 1][j | 1 << k] %= MOD;
                }
            }
        }
    }
    cout << dp[n][(1 << (n)) - 1] << "\n";
    return 0;
}

Measured memory_bytes: 377216
def assert_(L, nm):
    for i in range(len(L) // 2):
        i *= 2
        if L[i] == L[i + 1] == nm:
            nm += 2
            continue
        print(0)
        exit()
    pass


mod = int(1e9) + 7

n = int(input())
A = [int(x) for x in input().split()]
A.sort()

if n % 2 == 0:
    if A[0] != 1 or A[1] != 1:
        print(0)
        exit()
    assert_(A[2:], 3)
else:
    if A[0] != 0:
        print(0)
        exit()
    assert_(A[1:], 2)

ans = 1
num_power = (n - 1) // 2 if n % 2 == 1 else n // 2
for _ in range(num_power):
    ans *= 2
    ans %= mod
print(ans)


Measured memory_bytes: 13880
import sys,heapq
input = sys.stdin.buffer.readline

sys.setrecursionlimit(10**7)


n,m = map(int,input().split())
edge = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

#True:訪問済み False:未訪問
flag = [False]*n

def dfs(now):
    if flag[now]:
        return 0
    
    flag[now] = True

    size = 0
    for nxt in edge[now]:
        if not flag[nxt]:
            size += dfs(nxt)

    return size + 1

res = 0

for i in range(n):
    if flag[i]:
        continue
    res = max(res,dfs(i))

print(res)


Measured memory_bytes: 716100
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>

int main()
{
    int i, n, x, d[100+1] = {[0]0}, l[100+1] = {[0]0};
    scanf("%d %d", &n, &x);
    for (i = 1; i <= n; i++)
    {
        scanf("%d", &l[i]);
        d[i] = d[i-1] + l[i-1];
        if (d[i] == x)
            break;
        else if(d[i] > x)
        {
            i--;
            break;
        }
    }
    printf("%d", i);
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ll ans = 700;
  string s;
  cin >> s;
REP(i,3){
  if (s[i] == 'o') ans += 100;
}
cout << ans << endl;
return 0;
}


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

int main(){
  char c;
  cin >> c;
  if (c == 'a'||c == 'i'||c == 'u'||c == 'e'||c == 'o')cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        List<String> values = IO.readLineAsList();
        char x = values.get(0).charAt(0);
        char y = values.get(1).charAt(0);
        if( x - y < 0 ) {
            IO.writeLine("<");

        } else if ( x == y ) {
            IO.writeLine("=");

        } else {
            IO.writeLine(">");
        }
    }

    @SuppressWarnings("unused")
    public static class IO {

        private static BufferedReader br;

        private static BufferedReader br() {
            if( br == null ) {
                br = new BufferedReader( new InputStreamReader(new BufferedInputStream(System.in), StandardCharsets.UTF_8) );
            }
            return br;
        }

        public static String readLine() {
            try {
                return br().readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public static int readLineAsInt() {
            return Integer.parseInt(readLine());
        }

        public static List<String> readLineAsList() {
            return Arrays.asList( readLine().split(" "));
        }

        public static List<Integer> readLineAsIntList() {
            return readLineAsList().stream()
                    .map( Integer::parseInt )
                    .collect(Collectors.toList());
        }

        public static void writeLine(String line) {
            System.out.println( line );
        }

        public static void writeLine(List<Integer> values) {
            StringJoiner j = new StringJoiner(" ");
            values.forEach(i -> j.add(String.valueOf(i)) );
            writeLine(j.toString());
        }

        public static void writeLines(List<String> lines) {
            lines.forEach(System.out::println);
        }
    }
}


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

void fnInput(int& rnSelSiz, vector<int>& rvnHeight)
{
  int nHeightSiz;
  cin >> nHeightSiz >> rnSelSiz;
  rvnHeight.resize(nHeightSiz);

  for (int& rnHeight : rvnHeight)
    cin >> rnHeight;

  sort (begin(rvnHeight), end(rvnHeight));
}

int fnMinDiffHeight(int nSelSiz, const vector<int>& cnrvnHeight)
{
  int nMinDiffHeight = INT_MAX;

  for (int i = 0; i < cnrvnHeight.size() - (nSelSiz - 1); i++)
    nMinDiffHeight = min(nMinDiffHeight, cnrvnHeight[i + (nSelSiz - 1)] - cnrvnHeight[i]);  
  
  return nMinDiffHeight;
}
 
int main()
{
  int nSelSiz;
  vector<int> vnHeight;

  fnInput(nSelSiz, vnHeight);
  cout << fnMinDiffHeight(nSelSiz, vnHeight) << endl;

  return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	cin.ignore();
	while(n-->0){
		int a[8];
		for(int i=0;i<8;i++) scanf("%1d",&a[i]);
		sort(a,a+8);
		int max = 0;
		int min = 0;
		for(int i=0;i<8;i++){
			int t = a[i];
			if(t!=0) for(int j=0;j<i;j++) t *= 10;
			max += t;
			t = a[7-i];
			if(t!=0) for(int j=0;j<i;j++) t *= 10;
			min += t;
		}
		cout << max-min << endl;
	}
}

Measured memory_bytes: 1260
#include <cstdio>
#include <cmath>
#include <climits>
using namespace std;

long long INF = LONG_LONG_MAX / 3;
const int N = (int) 1e5 + 5;

int n;
long long c;
long long x[N], v[N];
long long dp[N][2];
// 0: clockwise
// 1: counter - clockwise

void maximize(long long &a, long long b) {
	if (a < b) a = b;
}

void minimize(long long &a, long long b) {
	if (a > b) a = b;
}

int main() {
	scanf("%d %lld", &n, &c);
	for (int i = 1; i <= n; i++) scanf("%lld %lld", &x[i], &v[i]);
	long long ans = -INF;
	long long temp = 0;
	for (int i = 1; i <= n; i++) {
		temp += v[i];
		temp -= (x[i] - x[i - 1]);
		maximize(ans, temp);
	}
	temp = 0;
	x[n + 1] = c;
	for (int i = n; i >= 1; i--) {
		temp += v[i];
		temp -= (x[i + 1] - x[i]);
		maximize(ans, temp);
	}
	temp = 0;
	dp[n + 1][1] = -INF;
	for (int i = n; i >= 1; i--) {
		temp += v[i];
		temp -= (x[i + 1] - x[i]);
		maximize(dp[i][1], dp[i + 1][1]);
		maximize(dp[i][1], temp);
	}
	temp = 0;
	dp[0][0] = -INF;
	for (int i = 1; i <= n; i++) {
		temp += v[i];
		temp -= (x[i] - x[i - 1]);
		maximize(dp[i][0], dp[i - 1][0]);
		maximize(dp[i][0], temp);
	}
	for (int i = 1; i <= n; i++) maximize(ans, dp[i][0] + dp[i + 1][1] - x[i]);
	for (int i = n; i >= 1; i--) maximize(ans, dp[i][1] + dp[i - 1][0] - (c - x[i]));
	maximize(ans, 0);
	printf("%lld", ans);
	return 0;
}

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

using namespace std;

int main () {
	int n;
	cin >> n;

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

	sort(begin(v), end(v), greater<int>());

	int prev = INT_MAX;
	int ans = 0;
	for (int x : v) {
		if (x < prev) {
			prev = x;
			++ans;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N=int(input())
C=[0]*N
S=[0]*N
F=[0]*N
for i in range(N-1):
  C[i],S[i],F[i]=map(int,input().split())

ans=[]
for s in range(N-1):
  time=0
  for i in range(s,N-1):
    if i==s:
      time=S[i]+C[i]
    else:
      time=S[i]+C[i] if time<=S[i] else time+(F[i]-time%F[i])%F[i]+C[i]
  ans.append(time)

for i in ans:
  print(i)
print(0)

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long a[n+1];
  for(int i = 0; i < n; i++)cin >> a[i];
  int Max = 0;
  a[n]= 1000000001;
  for(int i = 0; i < n; i++){
    int count = 1;
    while(a[i]>=a[i+1]){
      Max = max(Max, count);
      count++;
      i++;
    }
  }
  cout << Max << endl;
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define r0 return 0;

int main()
{
   fastio
   int n;
   string s;
   cin>>n>>s;
   int x=s.size();
   if(x<=n)
   cout<<s<<"\n";
   else
   {
   	cout<<s.substr(0,n)<<"..."<<"\n";
   }
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}




int main(){  
  int h,w,k;
  cin >> h >> w >> k ;
  int len[h][w];
  char cake[h][w];
  rep(i,h){
    rep(j,w){
      len[i][j]=0;
    }
  }
 
  rep(i,h){
    rep(j,w){
      cin>>cake[i][j];
    }
  }
  int sum=0;
  rep(i,h){
    rep(j,w){
      if(cake[i][j]=='#'){
        sum++;
        len[i][j]=sum;
      }
    }
  }
  rep(i,h){
    rep(j,w-1){
      if(len[i][j+1]==0)len[i][j+1]=len[i][j];      
    }
  } 
  rep(i,h){
    rep(j,w-1){
      if(len[i][w-j-2]==0)len[i][w-j-2]=len[i][w-j-1];      
    }
  } 
  
  vector<int>a;
  rep(i,h){  
    bool zero=true;
    rep(j,w){
      if(len[i][j]) zero=false;
    }
    if(zero)a.push_back(i);
  }
  if(a.size()){
    rep(i,a.size()){
      rep(j,w){
        if(a[i]!=0)len[a[i]][j]=len[a[i]-1][j];
      }
    }
  }
  vector<int>b;
  rep(i,h){  
    bool non=true;
    rep(j,w){
      if(len[i][j]) non=false;
    }
    if(non)b.push_back(i);
  }
  if(b.size()){
    for(int i=b.size()-1;b[0]<=i;i--){
      rep(j,w){
        if(b[i]!=h-1)len[b[i]][j]=len[b[i]+1][j];
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout << len[i][j]<<" " ;
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int t1=0,t2=0,t4=0;
	for(int i=0;i<n;i++)
	{
		int b;
		cin>>b;
		if(b%4==0)
		{
			a[i]=4;
			t4++;
		}
		else if(b%2==0)
		{
			a[i]=2;
			t2++;
		}
		else
		{
			a[i]=1;
			t1++;
		}
	}
	if(t4>=t1||(t2==0&&t4+1>=t1))
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 640