akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;

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

    vector<int> a(1000000);
    a[0] = s;
    for (int i = 1; i <= 1000000; i++)
    {
        if (a[i - 1] % 2 == 0)
        {
            a[i] = a[i - 1] / 2;
        }
        else
        {
            a[i] = 3 * a[i - 1] + 1;
        }
    }

    // for (int i = 0; i < 100; i++)
    // {
    //     cout << a[i] << " ";
    // }

    int i, j;
    bool found = false;
    int location = 0;
    for (i = 0; i < 1000000 - 1; i++)
    {
        for (j = i + 1; j < 1000000; j++)
        {
            if (a[i] == a[j])
                found = true;

            if (found == true)
            {
                location = j + 1;
                break;
            }
        }
        if (found == true)
        {
            break;
        }
    }
    cout << location << endl;
    return (0);
}

Measured memory_bytes: 4096
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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; }
template<typename T>
struct List {
	struct Node {
		T key;
		Node *prev, *next;
		Node() {}
		Node(T key, Node *prev, Node *next) :key(key), prev(prev), next(next) {}
	};
	Node *top;
	List() {
		top = (Node*)malloc(sizeof(Node));
		top->prev = top->next = top;
	}
	void printlist() {
		for (Node *a = top->next; a != top; a = a->next) {
			if (a != top->next)cout << ' ';
			cout << a->key;
		}
		cout << endl;
	}
	void insert(T x) {
		Node *i = new Node;
		i->prev = top;
		i->next = top->next;
		i->key = x;
		top->next->prev = i;
		top->next = i;
	}
	Node* findkey(T x) {
		Node *ret;
		for (ret = top->next; !(ret == top || ret->key == x); ret = ret->next);
		return ret;
	}
	void deletepointer(Node *f) {
		if (f == top)return;
		f->prev->next = f->next;
		f->next->prev = f->prev;
		delete f;
	}
	void deletex(T x) {
		deletepointer(findkey(x));
	}
	void deletefirst() {
		deletepointer(top->next);
	}
	void deletelast() {
		deletepointer(top->prev);
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	List<int>lis;
	int N; cin >> N;
	rep(i, 0, N) {
		string com; cin >> com;
		if (com == "insert") {
			int x; cin >> x;
			lis.insert(x);
		}
		else if (com == "delete") {
			int x; cin >> x;
			lis.deletex(x);
		}
		else if (com == "deleteFirst") {
			lis.deletefirst();
		}
		else lis.deletelast();
	}
	lis.printlist();
	return 0;
}

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

int main() {
  int N;
  int flag = 0;
  cin >> N;

  rep(i, N) {
    string P;
    cin >> P;
    if(P == "Y"){
      flag = 1;
    }
  }
  if(flag == 1){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    string s;
    cin >> s;

    int cnt = 0;
    int jp = 0;
    int other = 0;
    for (int i=0; i<N; i++){
        char si = s.at(i);
        if (si=='a'){
            if (cnt < A+B){
                jp++;
                cnt++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        else if (si=='b'){
            if(cnt < A+B and other+1 <= B){
                other++;
                cnt++;
                cout << "Yes" << endl;
            }
            else cout <<"No"<< endl;
        }
        else cout << "No" << endl;


    }
}

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

int main(){
  int a,b;
  cin >> a >> b;
  
  if(a >= 13){
    cout << b;
  }else if(a >= 6){
    cout << b/2;
  }else cout << "0";
  
  return 0;
}
    

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

const ll MAX = 1300000;
bool isPrime[MAX];
int d[MAX];
void calc(){
  FOR(i,0,MAX) d[i] = -1;
  d[0] = 0;
  d[1] = 0;
  for (ll i = 0; i < MAX; i++) isPrime[i] = true;
  int cnt = 0;
  for (ll i = 2; i < MAX + 1; i++){
    if(isPrime[i]){
      d[i-1] = cnt;
      d[i] = 0;
      cnt = 0;
      for (ll j = 2 * i; j < MAX; j += i) isPrime[j] = false;
    } else {
      cnt++;
    }
  }
  for(int i = MAX - 1; i >= 0; i--) {
    if(d[i] > 0 && d[i-1] == -1) d[i-1] = d[i];
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  calc();
  int n;
  while(cin >> n, n) cout << (d[n] == 0 ? 0 : (d[n] + 1)) << '\n';
  return 0;
}

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

int main(){
  int n;
  vector<pair<int, int>> l;
  
  cin >> n;
  for(int i=0; i<n; i++){
    int a, b;
    cin >> a >> b;
    l.push_back(make_pair(a, b));
  }
  
  sort(l.begin(), l.end(),
       [](auto p1, auto p2){return p1.first + p1.second > p2.first + p2.second;});
  
  long long ans = 0;
  for(int i=0; i<n/2; i++){
    ans += l[i*2].first - l[i*2+1].second;
  }
  if(n%2) ans += l[n-1].first;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(void)  {
  int i, j, n, a[100], flag, tmp, k = 0;

  scanf("%d", &n);
  for (i = 0; i < n; i++)  {
    scanf("%d", &a[i]);
  }
  flag = 1;
  while (flag)  {
    flag = 0;
    for (j = n - 1; j >= 1; j--)  {
      if (a[j] < a[j - 1])  {
        tmp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = tmp;
        flag = 1;
        k++;
      }
    }
  }

  for (i = 0; i < n - 1; i++)  {
    printf("%d ", a[i]);
  }

  printf("%d\n%d\n", a[n - 1], k);

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

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

int main() {
  int M;
  cin >> M;
  cout << (24+(24-M))  << endl;
  return 0;
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	LL R, C;
	cin >> R >> C;
	if (R == 1 && C == 1) {
		cout << 1 << endl;
	}
	else if (R == 1 || C == 1) {
		cout << R*C - 2 << endl;
	}
	else {
		cout << (R - 2)*(C - 2) << endl;
	}


	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Read();
            string str="";
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].ToString() == "A"|| s[i].ToString() == "C"||s[i].ToString() == "G"||s[i].ToString() == "T")
                {
                    str += "1";
                }
                else
                {
                    str += "0";
                }
            }

            if (str.Contains("1111111111"))
            {
                Console.WriteLine("10");
            }
            else if (str.Contains("111111111"))
            {
                Console.WriteLine("9");
            }
            else if (str.Contains("11111111"))
            {
                Console.WriteLine("8");
            }
            else if (str.Contains("1111111"))
            {
                Console.WriteLine("7");
            }
            else if (str.Contains("111111"))
            {
                Console.WriteLine("6");
            }
            else if (str.Contains("11111"))
            {
                Console.WriteLine("5");
            }
            else if (str.Contains("1111"))
            {
                Console.WriteLine("4");
            }
            else if (str.Contains("111"))
            {
                Console.WriteLine("3");
            }
            else if (str.Contains("11"))
            {
                Console.WriteLine("2");
            }
            else if (str.Contains("1"))
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine("0");
            }

        }


        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>

int main(){
  int a,b,c,box1;
  scanf("%d%d",&a,&b);
  
  if(a<=b){
    box1=a;
    a=b;
    b=box1;
  }
  while(1){
    c=a%b;
    if(c==0){
      printf("%d\n",b);
      break;
    }
    else{
      a=b;
      b=c;
    }
  }
  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1e5+5;
int head[N],opt;
struct info{
	int to,nxt,w;
}e[N<<1];
void add(int x,int y,int z){
	e[++opt]=(info){y,head[x],z};head[x]=opt;
}
int cnt[3],co[N],tot,ksg;
ll ans;
bool used[N],d;
void dfs(int u,int c){
	if(used[u]){
		if(co[u]!=c) d=0;
		return;
	}
	used[u]=1;co[u]=c;cnt[c]++;ksg++;
	for(int i=head[u];i;i=e[i].nxt){
		int k=e[i].to;
		tot++;
		dfs(k,(c+e[i].w+3)%3);
	}
}
int main(){
	int n=read(),m=read();
	For(i,1,m){
		int x=read(),y=read();
		add(x,y,1);add(y,x,-1);
	}
	For(i,1,n) if(!used[i]){
		ksg=tot=cnt[0]=cnt[1]=cnt[2]=0;d=1;
		dfs(i,0);
		if(d){
			int ssw=0;
			For(j,0,2) ssw+=(cnt[j]>0);
			if(ssw<=2) ans+=tot/2;
			else ans+=(ll)cnt[0]*cnt[1]+(ll)cnt[1]*cnt[2]+(ll)cnt[2]*cnt[0];
		}else ans+=(ll)ksg*ksg;
	}
	cout<<ans;
}

Measured memory_bytes: 9968
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	// スペース区切りの整数の入力
	int a = sc.nextInt();
	int b = sc.nextInt();
    System.out.println(Math.max(Math.max(a+b,a-b),a*b));
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define ll long long
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define INF 1000000000
#define M 1000000007ll
ll h,w,a,b,f[300005],inv[300005];
ll expo(ll a,ll b) {
	if (!b) return 1ll;
	ll x=expo(a,b/2ll);
	if (b%2ll) return (((x*x)%M)*a)%M;
	return (x*x)%M;
}
ll choose(int n,int k) {
	return (((f[n]*inv[n-k])%M)*inv[k])%M;
}
int main() {
	scanf("%lld%lld%lld%lld",&h,&w,&a,&b);
	ll n=(h+w-2);
	f[0]=inv[0]=1ll;
	for (int i=1;i<=n;i++) {
		f[i]=(f[i-1]*(ll)i)%M;
		inv[i]=expo(f[i],M-2ll);
	}
	ll ans=0ll;
	for (ll l=h-a-1+b;l<=n-a;l++) {
		ans+=choose(l,h-a-1)*choose(n-l-1,a-1);
		ans%=M;
	}
	printf("%lld\n", ans);
}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

ll dp[100500];
int n;
int a[100500];

ll f(int i){
	if(i == n - 1) return 0;
	if(i >= n) return inf;
	if(dp[i] != -1) return dp[i];
	if(i == n - 2) return dp[i] = abs(a[i] - a[i + 1]);
	return dp[i] = min(abs(a[i] - a[i + 1]) + f(i + 1), abs(a[i] - a[i + 2]) + f(i + 2));
}

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

	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	memset(dp, -1, sizeof dp);
	cout << f(0);
}

Measured memory_bytes: 2944
//#pragma GCC optimize(3)
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<utility>
#include<iterator>
#include<iomanip>
using namespace std;
#define lowbit(x) x&(-x)
typedef long long ll;
typedef long double lb;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const int maxn = 100005;
int a[maxn];
int read();
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i = 1 ;i<=n;i++)
    {
       cin>>a[i];
    } 
    bool f = true;
    for(int i = n;i>=1;i--)
    {
    	if(a[i] < a[i-1]-1)
    	{
    		f =false;
    		break;
    	}else
    	if(a[i]==a[i-1]-1)
    	{
    		a[i-1] -=1;
    	}
    }
    if(f)
    {
    	cout<<"Yes"<<endl;
    }else
    {
    	cout<<"No"<<endl;
    }
    return 0;
}
inline int read()
{
	int x = 0,w = 0;
	char ch = 0;
	while(!isdigit(ch)){
		w |= (ch == '-');
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x<<3)+(x<<1)+(ch^48);
		ch = getchar();
	}
	return w?-x:x;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
typedef    long long          ll;
typedef    vector<long long>    vi; 
typedef    vector<vi>         vvi; 
typedef    pair<long,long>      ii; 
#define    sz(a)              long((a).size()) 
#define    pb                 push_back 
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end() 
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define    present(c,x)       ((c).find(x) != (c).end()) 
#define    cpresent(c,x)      (find(all(c),x) != (c).end())  
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "
#define    ff           first
#define    ss           second


ll mod = 1e9+7;

int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,i;
    cin>>n;
    vi v(n);
    ll ans = 0;
    ll sum = 0;
    for(i=0;i<n;i++)
    {
      cin>>v[i];
      sum+=v[i];
      sum%=mod;
    }
    for(i=0;i<n;i++)
    {
      sum-=v[i];
      sum+=mod;
      sum%=mod;
      ans+=sum*v[i];
      ans%=mod;
    }

    cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 4780
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn sp(n: usize) -> u64 {
    300 + (n as u64)
}

fn main() {
    let mut sc = Scanner::new();
    let s = sc.cin::<String>().chars().map(|c| (c as u8) as u64).collect::<Vec<_>>();
    let k: usize = sc.cin();

    if s.len() == 1 {
        put!(k / 2);
        return;
    }

    let mut ans0 = 0;
    let mut ans1 = 0;
    let mut ans2 = 0;

    let mut last = 0;
    for i in 0..s.len() {
        if last == s[i] {
            last = sp(ans0);
            ans0 += 1;
        } else {
            last = s[i];
        }
    }
    for i in 0..s.len() {
        if last == s[i] {
            last = sp(ans1);
            ans1 += 1;
        } else {
            last = s[i];
        }
    }
    for i in 0..s.len() {
        if last == s[i] {
            last = sp(ans2);
            ans2 += 1;
        } else {
            last = s[i];
        }
    }
    let ans = ans0 + ans1 * (k / 2) + ans2 * ((k - 1) / 2);
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
const ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

int N, K;
ll h[100010];
ll dp[100010];

ll rec(int i)
{
  if (dp[i] < INF)
    return dp[i];
  if (i == 0)
    return 0;

  ll res = INF;
  repd(k, 1, K + 1)
  {
    if (i - k < 0)
      continue;
    chmin(res, rec(i - k) + abs(h[i] - h[i - k]));
  }

  return dp[i] = res;
}

int main()
{
  cin >> N >> K;
  rep(i, N) cin >> h[i];
  rep(i, N) dp[i] = INF;

  cout << rec(N - 1) << endl;
}

Measured memory_bytes: 6528
loop do
    require 'set'
    n = gets.to_i
    break if n == 0
    nodes = Set.new
    g = {}
    deg = Hash.new(0)
    n.times do
        s = gets.chomp
        u, v = s[0], s[-1]
        (g[u] ||= []) << v
        deg[u] += 1
        deg[v] -= 1
        nodes += [u, v]
    end
    queue = [g.keys[0]]
    reached = Set[*queue]
    until queue.empty?
        u = queue.shift
        (g[u] || []).each do |v|
            next if reached.include?(v)
            queue << v
            reached << v
        end
    end
    if reached.size < nodes.size
        puts 'NG'
    elsif deg.values.all?{|x| x == 0}
        puts 'OK'
    else
        puts 'NG'
    end
end



Measured memory_bytes: 8208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double a[500][500];
#define pi 3.142857143
int main() {
	int n , m;
	cin >>n >> m;
	int sum = 0;
	for(int i = 0 ; i < m ;i++){
		int x;
		cin >> x;
		sum += x;
	}
	if(n - sum >= 0)
	cout << max(0 , n - sum) << endl;
	else 
	cout << -1 << endl;
	return 0;
	
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	ll a[n+1];
	rep(i, 1, n){
		cin >> a[i];
	}
	
	ll cnt[70];
	ll ans = 0;
	memset(cnt, 0, sizeof(cnt));
	rep(i, 1, n){
		for(ll j = 0; j < 60; j++){
			ll flag = (1LL << j);
			flag %= MOD;
			if(a[i] & (1LL << j)){
				ll buf = (i-1-cnt[j]) * flag;
				buf %= MOD;
				ans += buf;
				ans %= MOD;
			}
			else{
				ll buf = cnt[j] * flag;
				buf %= MOD;
				ans += buf;
				ans %= MOD;
			}
			
			if(a[i] & (1LL << j)){
				cnt[j]++;
			}
		}
	}
	print(ans)
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const int INF = 10000000;

int main(){
    int n; cin >> n;
    vector<int> t(n+1), x(n+1), y(n+1);
    t[0] = x[0] = y[0] = 0;
    rep(i, n) cin >> t[i+1] >> x[i+1] >> y[i+1];

    bool ok = true;

    for(int i = 0; i < n; ++i){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if(dt < dist) ok = false;
        if(dt % 2 != dist % 2) ok = false;
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

bool parallel(double x1, double y1, double x2, double y2){
	double vec;
	vec = x1*y2 - x2*y1;
	if (vec < 0.0000000001 && vec > -0.0000000001) return true;
	return false;
}

int main(){
    int n;
    double x1, x2, x3, x4, y1, y2, y3, y4;
    cin >> n;
    REP(i, n) {
    	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
    	if (parallel(x1-x2, y1-y2, x3-x4, y3-y4)) cout << "YES" << endl;
    	else cout << "NO" << endl;
    }
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sortv(X) sort(X.begin() , X.end()) ; 
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int > 
#define ordered_set tree<pair <long long  ,long long >, null_type,less<pair <long long ,long long > >, rb_tree_tag,tree_order_statistics_node_update> 
  
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 5e5 + 10 ;
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}




int main(){
	string s , t ; 
	cin>>s>>t ; 
	int ans = t.size() ; 
	for (int i = 0 ; i <= s.size() - t.size() ; i++){
		int now = 0 ; 
		for (int j = 0 ; j < t.size() ; j++ ){
			if (s[i+j]!=t[j])
				now++ ; 
		}
		ans = min (ans , now) ; 
	}
	cout<<ans ; 
}


Measured memory_bytes: 3624
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    S = input()

    if (S[0] == 'A' and
            S[2:-1].count('C') == 1 and
            all([s.islower() for s in S if s not in ['A', 'C']])):
        print('AC')
    else:
        print('WA')


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
program main
   implicit none
   character(100000)s
   integer n,k
   integer ::i,ma=1,counter=0,j=1
   integer ::a(200000)=0,suma
   read(*,*)n,k
   read(*,*)s
   do i=1,n
      if(mod(j,2)==1)then
        if(s(i:i)=="1")then
          a(j)=a(j)+1
        else
          j=j+1
        endif
        cycle
      else
        if(s(i:i)=="0")then
          a(j)=a(j)+1
        else
          j=j+1
        endif
      endif
      cycle
   enddo
   a(2:j)=a(2:j)+1
   suma=sum(a)
   if(j/2<=k)then
	  write(*,*)suma
	  STOP
   endif
   do i=1,j,2
      if(ma<sum(a(i:i+2*k)))ma=sum(a(i:i+2*k))
   enddo
   write(*,*)ma
end program main


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

int main()
{
    int a,b,d;
    cin>>a>>b;
    if(a==1 && b==2 || a==2 && b==1)
    {
        d=3;
    }
    else if(a==2 && b==3 || a==3 && b==2 )
    {
        d=1;
    }
    else if(a==1 && b==3 || a==3 && b==1)
    {
        d=2;
    }
    cout<<d<<endl;
    return 0;
}


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

using ll = long long;
const ll MOD = 998244353;

int main() {
    int N;
    cin >> N;
    if (N % 2) {
        int M = N - 1 + (N - 1) / 2 * (N - 3);
        cout << M << endl;
        for (int i = 1; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i + j == N) continue;
                cout << i << " " << j << endl;
            }
            cout << i << " " << N << endl;
        }
    } else {
        int M = N / 2 * (N - 2);
        cout << M << endl;
        for (int i = 1; i < N; i++) {
            for (int j = i + 1; j <= N; j++) {
                if (i + j == N + 1) continue;
                cout << i << " " << j << endl;
            }
        }
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	ns := strings.Split(sc.Text(), " ")
	n, e := strconv.ParseFloat(ns[0]+ns[1], 32)
	if e != nil {
		return
	}

	res := false
	for i := 4; i < 317; i++ {
		fl := float64(i)
		if n/fl == fl {
			res = true
			break
		}
	}

	if res {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
a,b,c,d,e,f=map(int,input().split())

ans = 0
sub = [0,0]

for i in range(31):
    for g in range(31):
        water = 100*a*i+100*b*g
        if water<=f and water!=0:
            r1 = f-water
            r2 = e*water//100
            _min = min(r1,r2)
            repeat_c = _min//c
            max_sugar = 0
            for m in range(repeat_c+1):
                n=(_min-c*m)//d
                if n>=0:
                    max_sugar = max(max_sugar,c*m+d*n)
            if ans<=max_sugar/(max_sugar+water):
                ans = max_sugar/(max_sugar+water)
                sub[0]=max_sugar+water
                sub[1]=max_sugar
print(*sub)

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	if a < b {
		if b < c {
			if a < c {
				//a < b < c
				fmt.Print(a)
				fmt.Print(" ")
				fmt.Print(b)
				fmt.Print(" ")
				fmt.Println(c)
			} else {
				//a < c < b
				fmt.Print(a)
				fmt.Print(" ")
				fmt.Print(c)
				fmt.Print(" ")
				fmt.Println(b)
			}
		} else {
			//c < a < b
			fmt.Print(c)
			fmt.Print(" ")
			fmt.Print(a)
			fmt.Print(" ")
			fmt.Println(b)
		}
	} else if c < b {
		if a < c {
			//b < a < c
			fmt.Print(b)
			fmt.Print(" ")
			fmt.Print(a)
			fmt.Print(" ")
			fmt.Println(c)
		} else {
			//c < b < a
			fmt.Print(c)
			fmt.Print(" ")
			fmt.Print(b)
			fmt.Print(" ")
			fmt.Println(a)
		}
	} else {
		//b < c < a
		fmt.Print(b)
		fmt.Print(" ")
		fmt.Print(c)
		fmt.Print(" ")
		fmt.Println(a)
	}
}


Measured memory_bytes: 1160
import java.util.*;

public class Main {
	
	public static class MyPair implements Comparable<MyPair> {
		int cost;
		int supply;
		
		public MyPair(int cost, int supply) {
			this.cost = cost;
			this.supply = supply;
		}
		
		@Override
		public int compareTo(MyPair other) {
			return (this.cost - other.cost);
		}
	}
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		long totalCost = 0;
		
		MyPair[] costAndSupply = new MyPair[N];
		for (int i = 0; i < N; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			costAndSupply[i] = new MyPair(A, B);
		}
		Arrays.sort(costAndSupply);
		
		int ptr = 0;
		while (M > 0) {
			MyPair mp = costAndSupply[ptr];
			if (M >= mp.supply) {
				M -= mp.supply;
				totalCost += ((long)mp.supply)*mp.cost;
			} else {
				totalCost += ((long)M)*mp.cost;
				M = 0;
			}
			ptr++;
		}
		
    	System.out.println(totalCost);
    }
  
}


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

int main() {
	float A, B, T;
	cin >> A >> B >> T;
  	int ans = 0;
  	float S = A;
    while (S<T+0.5){
      ans += B;
      S += A;
    }
  	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
write = sys.stdout.write

err = 2 * (10**9) + 1

class Node:
    def __init__(self, k, l, r, p):
        self.key = k
        self.left = l
        self.right = r
        self.parent = p

n = int(input())
keys = list(map(int, readline().split()))

Heap = [Node(err, None, None, None) for i in range(n+1)]
for i in range(1, n+1):
    Heap[i].key = keys[i-1]
    if 2*i  < n+1:
        Heap[i].left = Heap[2*i]
    if 2*i + 1 < n+1:
        Heap[i].right = Heap[2*i + 1]
    if i > 1:
        Heap[i].parent = Heap[int(i/2)]

for i in range(1, n+1):
    write("node " + str(i) + ": key = " + str(Heap[i].key) + ", ")
    if Heap[i].parent is not None:
        write("parent key = " + str(Heap[i].parent.key) + ", ")
    if Heap[i].left is not None:
        write("left key = " + str(Heap[i].left.key) + ", ")
        if Heap[i].right is not None:
            write("right key = " + str(Heap[i].right.key) + ", ")
    write("\n")


Measured memory_bytes: 5668
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

get_numbers_2(0, _, []).
get_numbers_2(N1, N2, [X|Xs]) :- 
    get_numbers(N2, X), 
    N12 is N1 - 1, 
    get_numbers_2(N12, N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

get_i_to_x_rbtree0(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 0, T2, T).

get_i_to_x_rbtree1(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 1, T2, T).

get_i_to_x_rbtree(0, _, T, T).
get_i_to_x_rbtree(N, I, T2, T) :-
    get_number(X),
    rb_insert(T2, I, X, T3),    
    N2 is N - 1,
    I2 is I + 1,
    get_i_to_x_rbtree(N2, I2, T3, T).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)

    include(f, Xs, Ys) : filter f

    findall(使う変数のタプル, (hoge), hogeが通るタプルのリスト)
*/

cu(Xs, Zs) :- cu(Xs, 0, Zs).
cu([], C, [C]).
cu([X|Xs], C, [C|Zs]) :- C2 is C + X, cu(Xs, C2, Zs).

f(N, [X|Xs], M, [Y|Ys], K, C, Z) :-
    X + Y =< K, !,
    C2 is max(C, N + M),
    N2 is N + 1,
    f(N2, Xs, M, [Y|Ys], K, C2, Z).

f(N, [X|Xs], M, [Y|Ys], K, C, Z) :-
    X + Y > K, !,
    M2 is M - 1,
    f(N, [X|Xs], M2, Ys, K, C, Z).

f(_, [], _, _, _, C, C) :- !.
f(_, _, _, [], _, C, C) :- !.

main :-
    get_number(N, M, K),
    get_numbers(N, Xs),
    get_numbers(M, Ys),
    cu(Xs, Xs_cu),
    cu(Ys, Ys_cu),
    reverse(Ys_cu, Ys_cu_r),
    f(0, Xs_cu, M, Ys_cu_r, K, 0, Z),
    writeln(Z).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 49856
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
using namespace std;

int main(){
    long long x, p, q;
    cin >> x;
    p = x / 11;
    q = x % 11;
    if(q == 0) cout << 2 * p << endl;
    else if(q < 7) cout << 2 * p + 1 << endl;
    else cout << 2 * p + 2 << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 2010;
int N,Z,W;
int a[MC];

int main(){
	cin >> N >> Z >> W;
	repp(i,1,N+1) cin >> a[i];
	a[0] = a[N];
	cout << max(abs(W-a[N]),abs(a[N-1]-a[N])) << endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np


def solve():


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

    A = []
    B = []

    for _ in range(N):
        A_temp, B_temp = map(int, input().split())
        A.append(A_temp)
        B.append(B_temp)

    A = np.array(A, np.int)
    B = np.array(B, np.int)

    idx = np.argsort(A)
    A = A[idx]
    B = B[idx]

    dp = np.zeros((N, T), np.int)

    for i in range(N - 1):
        dp[i + 1, :A[i]] = dp[i, :A[i]]
        dp[i + 1, A[i]:] = np.maximum(dp[i, A[i]:], dp[i, :-A[i]] + B[i])

    print(np.max(dp[:, -1] + B))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 84532
N,*H=`dd`.split.map &:to_i;B=[0]*-~M=2**18;N.times{|i|j=k=H[i];r=0;1while(r<B[j]&&r=B[j];j-=j&-j)>0;1until(B[k]=[B[k],r+H[N+i]].max;k+=k&-k)>M};p B[M]

Measured memory_bytes: 55828
#include<iostream>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
char x[a][b];
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
cin >> x[i][j];
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
if(x[i][j]=='#' and x[i][j+1]!='#' and x[i][j-1]!='#' and x[i+1][j]!='#' and x[i-1][j]!='#'){
cout << "No";
return 0;
}
cout << "Yes";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == N - 1) {
      cout << "Three";
    }
  }
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;
    let hist = Array.make 1000001 0 in
    Array.iter (fun v -> hist.(v) <- hist.(v) + 1) a;
    let rec loop_i i acc =
        let rec loop_j v j acc =
            let check c =
                if hist.(c) = 0 then true else
                    if v <> c then false else
                        if hist.(c) = 1 then true else false
            in
            if j * j > v then acc else
                if v mod j <> 0 then loop_j v (j + 1) acc else
                if check j && check (v / j) then loop_j v (j + 1) acc else acc - 1
        in
        if i = n then acc else
            loop_i (i + 1) (loop_j a.(i) 1 acc)
    in
    loop_i 0 n |> Printf.printf "%d\n"
)

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

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

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int D = in.Int();
            int N = 26;
            int[] c = in.Int(N);
            int[][] s = new int[D][N];
            for (int i = 0; i < D; i++) {
                s[i] = in.Int(N);
            }

            int[] last = new int[N];
            for (int d = 0; d < D; d++) {
                int t = 0;
                int max = Integer.MIN_VALUE;
                for (int tt = 0; tt < N; tt++) {
                    int tmp = s[d][tt];
                    last[tt] = d + 1;
                    for (int i = 0; i < N; i++) {
                        if (tt != i) {
                            tmp -= c[i] * ((d + 1) - last[i]);
                        }
                    }
                    if (tmp > max) {
                        max = tmp;
                        t = tt;
                    }
                }
                out.println(t + 1);
            }
        }

    }

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

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

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

        public int Int() {
            return Integer.parseInt(next());
        }

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

    }
}



Measured memory_bytes: 34852
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N; ll C;
ll X[MAX_N], V[MAX_N];
ll L1[MAX_N], L2[MAX_N], R1[MAX_N], R2[MAX_N];

void solve() {
	cin >> N >> C;
	rep(i, 0, N) {
		cin >> X[i] >> V[i];
	}

	ll vs = 0, l1m = 0, l2m = 0;
	rep(i, 0, N) {
		vs += V[i];
		MAX(l1m, vs - X[i]);
		MAX(l2m, vs - 2 * X[i]);
		L1[i + 1] = l1m;
		L2[i + 1] = l2m;
	}
	// debug(vl(L1, L1 + N + 1));
	// debug(vl(L2, L2 + N + 1));
	vs = 0; ll r1m = 0, r2m = 0;
	rer(i, N, 0) {
		vs += V[i];
		MAX(r1m, vs - (C - X[i]));
		MAX(r2m, vs - 2 * (C - X[i]));
		R1[i] = r1m;
		R2[i] = r2m;
	}
	// debug(vl(R1, R1 + N + 1));
	// debug(vl(R2, R2 + N + 1));
	ll res = 0;
	rep(i, 0, N + 1) {
		MAX(res, L1[i] + R2[i]);
		MAX(res, L2[i] + R1[i]);
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int N;
const int MN = 100000;
ll a[MN*3];
ll l[MN*3+1];
ll r[MN*3+1];
ll inf = 1e16;
int main(){
	cin>>N;
	rep(i,3*N) cin>>a[i];
	rep(i,3*N+1) l[i] = -inf, r[i] = inf;

	{
		priority_queue<ll,vector<ll>,greater<ll> > que;
		ll sum = 0;
		rep(i,3*N){
			que.push(a[i]);
			sum += a[i];
			if(que.size()>N){
				ll v = que.top();
				que.pop();
				sum -= v;
			}
			if(que.size()==N) l[i+1] = sum;
		}
	}
	{
		priority_queue<ll> que;
		ll sum = 0;
		rep(j,3*N){
			int i = 3*N-1-j;
			que.push(a[i]);
			sum += a[i];
			if(que.size()>N){
				ll v = que.top();
				que.pop();
				sum -= v;
			}
			if(que.size()==N) r[j+1] = sum;
		}
	}
	ll ans = -inf;
	rep(a,3*N+1){
		int b = 3*N-a;
		chmax(ans,l[a]-r[b]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 9076
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int w,a,b;
    cin>>w>>a>>b;
    if(b+w<a)cout<<a-b-w<<endl;
    else if(a<=b+w&&b+w<=a+w)cout<<"0"<<endl;
    else if(a<=b&&b<=a+w)cout<<"0"<<endl;
    else if(a+w<b)cout<<b-a-w<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0
for p in range(1000):
  s = '{:03}'.format(p)
  i = 0
  for j in range(N):
    if i < 3 and S[j] == s[i]:
      i += 1
  if i == 3:
    ans += 1
print(ans)


Measured memory_bytes: 41692
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){  
  char A,B,C,D;
  cin >> A >> B >> C >> D;
  int a=A-'0';
  int b=B-'0';
  int c=C-'0';
  int d=D-'0';
  int ans=0;
  rep(i,8){
    int cur=a;
    if(i/4>0){cur += b;}else{cur-=b;}
    if(i%4/2>0){cur += c;}else{cur-=c;}
    if(i%2>0){cur += d;}else{cur-=d;}
    if(cur==7){ ans=i;}
  }
  cout << a;
  if(ans/4>0){cout << "+";}else{cout << "-";}
  cout << b;
  if(ans%4/2>0){cout << "+";}else{cout << "-";}
  cout << c;
  if(ans%2>0){cout << "+";}else{cout << "-";}
  cout << d;
  cout << "=7";
  return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    ld p = 0.0;
    for(int i=1;i<=n;i++){
        int a = i;
        ld pi = 1.0/(ld)n;
        while(a < k){
            pi *= 0.5;
            a *= 2;
        }
        p += pi;
    }
    printf("%.9Lf",p);
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int p[100010];
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
  int n, m;
  cin >> n >> m;
  rep(i,n) {cin >> p[i]; p[i]--;}
  int x, y;
  UnionFind uf(n);
  rep(i,m) {
    cin >> x >> y;
    x--; y--;
    uf.merge(x,y);
  }
  int ans = 0;
  rep(i,n) {
    if (uf.issame(i,p[i])) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5120