akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define f first
#define s second

const int maxn = 1010;

typedef pair<int,pi> pp;

int h,w;
int A[maxn][maxn];
int startx, starty;
int endx, endy;

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

bool invalid(int x, int y) {
	if (x < 1 or x > h) return true;
	if (y < 1 or y > w) return true;
	if (A[x][y] or visited[x][y]) return true;
	
	return false;
}

int32_t main() {
	cin >> h >> w;
	cin >> startx >> starty;
	cin >> endx >> endy;
	for (int i =1;i<=h;i++) {
		for (int j =1;j<=w;j++) {
			char x; cin >> x;
			if (x == '#') A[i][j] = 1;
		}
	}
	
	deque <pp> dq;
	dq.push_back(pp(0,pi(startx,starty)));
	
	while (!dq.empty()) {
		pp cur = dq.front(); dq.pop_front();
		int d = cur.f; int x = cur.s.f; int y = cur.s.s;
		
		if (visited[x][y]) continue;
		visited[x][y] = 1;
		//cout << d << " " << x << " " << y << "\n";
		
		if (x == endx and y == endy) {
			cout << d;
			return 0;
		}
		
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i]; int ny = y + dy[i];
			if (invalid(nx,ny)) continue;
			dq.push_front(pp(d, pi(nx,ny)));
		}
		
		for (int incx = -2; incx <= 2; incx++) {
			for (int incy = -2; incy <= 2; incy++) {
				int nx = x + incx; int ny = y + incy;
				if (invalid(nx,ny)) continue;
				//visited[nx][ny] = 1;
				//cout << "PUSH: " << nx << " " << ny << "\n";
				dq.push_back(pp(d+1, pi(nx,ny)));
			}
		}
		
	}
	
	cout << -1;
	
}





Measured memory_bytes: 13752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    bool yymm = 0;
    bool mmyy = 0;
    dump(S[2]-'0')
    if(S[0] - '0' > 1) mmyy = 0;
    else if(S[0] - '0' == 0) {
        if(S[1] - '0' == 0) mmyy = 0;
        else mmyy = 1;
    }
    else {
        if(S[1] - '0' >= 3) mmyy = 0;
        else mmyy = 1;
    }

    if(S[2] - '0' > 1) yymm = 0;
    else if(S[2] - '0' == 0) {
        if(S[3] - '0' == 0) yymm = 0;
        else yymm = 1;
    }
    else  {
        if(S[3] - '0' >= 3) yymm = 0;
        else yymm = 1;
    }
    dump(yymm)


    if(yymm == 1 && mmyy == 1) cout << "AMBIGUOUS" << endl;
    else if(yymm == 0 && mmyy ==1) cout << "MMYY" << endl;
    else if(yymm == 1 && mmyy == 0) cout << "YYMM" << endl;
    else cout << "NA" << endl;




}

Measured memory_bytes: 256
N=int(input())
c=input()
S=[0 for i in range(N+1)]
for i in range(N):
    if c[i]=="R":
        S[i+1]=S[i]+1
    else:
        S[i+1]=S[i]
ans=N
for i in range(N+1):
    ans=min(ans,max(i-S[i],S[N]-S[i]))
print(ans)

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

int main() {
  int cnt=0;
  string S;
  cin >> S;
  for(int i=0;i<3;i++){
    if(S.at(i)=='o'){
      cnt++;
    }
  }
  cout << 700+cnt*100 << endl;
}

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

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3 = x2-(y2-y1);
  int y3 = y2+(x2-x1);
  int x4 = x1-(y2-y1);
  int y4 = y1+(x2-x1);
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
package main

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

var (
	BufferSize = 20
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	a := scanInt(sc)
	b := scanInt(sc)
	t := scanInt(sc)

	var tmp int
	for i := 1; i <= 20; i++ {
		if i*a <= t {
			tmp = i
		} else {
			break
		}
	}
	fmt.Println(tmp * b)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    string s, t, u;
    lint a, b;
    cin >> s >> t >> a >> b >> u;
    
    map<string, lint> mp;
    mp[s] = a;
    mp[t] = b;
    mp[u]--;

    cout << mp[s] << " " << mp[t] << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N,M;
	int A[1001];	//?????¨
	int B[1001];	//??????
	int C[1001]={0};	//?\¨??°
	cin >> N >> M;
	for(int i=0;i<N;i++)
		cin >> A[i];
	for(int i=0;i<M;i++)
		cin >> B[i];
	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			if(B[i] >= A[j]){
				C[j]++;
				break;
			}
		}
	}
	int max_h=0,max_no1;
	for(int i=0;i<N;i++){
		if(max_h < C[i]){
			max_h = C[i];
			max_no1 = i + 1;
		}
	}
	cout << max_no1 << endl;
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
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; }

const long long INF = 1LL << 60;

long long a[100100][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2]

long long dp[100100][3]; // dp[i+1][j]:i日目までの活動履歴のうち最終日にjの活動をした場合の幸福度の最大値

int main(){
  int n; cin >> n;
  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }

  // d[0][0,1,2]の初期条件は勝手に０になってるからOK
  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < 3; j++) {
      for (size_t k = 0; k < 3; k++) {
        if (j == k) continue;
        chmax(dp[i+1][k], dp[i][j] + a[i][k]); //添え字注意。a[i][k←]を行ったからdp[i+1][k←]
      }
    }
  }
  long long ans = 0;
  for (size_t j = 0; j < 3; j++) chmax(ans, dp[n][j]);
  std::cout << ans << '\n';
}


Measured memory_bytes: 4992
object Main extends App {
  import scala.io.StdIn.readLine
  import scala.io.StdIn.readInt
  
  	var n = readInt
  	val pros = readLine.split(" ").map(_.toLong).toList.sorted
  
  if(n % 2 == 0){
    //リストは0から始まることに注意
    n =(n / 2).toInt
  	println( (pros(n - 1) until pros(n)).length )
  }
  else println("aaa")
  //奇数の長さのリストがあるか確認してみる
}


Measured memory_bytes: 68380
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

#define INF 2000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int32 n, h;
	std::cin >> n >> h;
	std::vector<uint32> a(n), b(n);
	rep(i, 0, n)
		std::cin >> a[i] >> b[i];
	uint32 ans = INF;
	std::sort(ALL(a));
	uint32 c = 0;
	std::sort(ALL(b),std::greater<uint32>());
	rep(i, 0, n) {
		if (b[i] > a[n - 1]) {
			h -= b[i];
			++c;
			if (h <= 0) break;
		}
		else {
			break;
		}
	}
	if (h <= 0) std::cout << c << "\n";
	else {
		c += ((h - 1) / a[n - 1]) + 1;
		std::cout << c << "\n";
	}
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
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;
}

class UnionFind {
  public:
    // 親の番号を格納する。親の場合 -1 になる
    vector<int> Parent;

    // 宣言されたとき Parent の値はすべて -1 にする
    UnionFind(int N) { Parent = vector<int>(N, -1); }

    // 与えられた値 x がどの親であるか調べる
    int root(int x) {
        // x が親だったとき
        if (Parent[x] < 0)
            return x;
        // 辺の縮約をいっしょにおこなう
        return Parent[x] = root(Parent[x]);
    }

    // 木の全体の数を返す
    int size(int x) {
        // マイナスがついているのは root
        // 以下の数をマイナスの値で管理しているから
        return -Parent[root(x)];
    }

    // 2つの引数を同じ親にする
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);

        // 同じ親の場合くっつけない
        if (x == y)
            return false;

        // x のほうが必ず大きな size にしたい
        if (size(x) < size(y))
            swap(x, y);
        Parent[x] += Parent[y];
        Parent[y] = x;
        return true;
    }
};

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

    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);

    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    int ans = 0;

    REP(i, M) {
        auto uni = UnionFind(N);
        // グラフ構築
        REP(j, M) {
            if (i == j) {
                continue;
            }
            uni.merge(a[j], b[j]);
        }

        if (uni.size(0) < N) {
            ans++;
        }
    }

    std::cout << ans << '\n';

    return 0;
}

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

int main(){
    int N, tmp, ans=0;
    cin >> N;
    map<int, int> mp;
    for(int i=0; i<N; i++){
	cin >> tmp;
	mp[tmp]++;
    }
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
	if(itr->first > itr->second)
	    ans += itr->second;
	else if(itr->first < itr->second)
	    ans += itr->second-itr->first;
    }
    cout << ans << endl;
}



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

int main(){
  int N, A, B;

  cin >> N >> A >> B;
  int d = B - A;
  if((d % 2) == 0){
    cout << "Alice" << endl;
  }else{
    cout << "Borys" << endl;
  }
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b > 0)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}

int find(string s,int md)
{
    int res = 0;
    
    for(auto x : s)
    {
        res*=2;
        res=(res+(x-'0'));
        res%=md;
    }
    
    return res;
}

const int N = 2e5 + 10;
int dp[N];

void pre()
{
    dp[0] = 0;
   
    for(int i=1;i<N;i++)
    {
        int v = __builtin_popcount(i);
        dp[i] = 1 + dp[i%v];
    }
}

void solve()
{
   int n;
    cin >> n;
    
   string s;
    cin >> s;
    
   int md1 = 0;
   f(i,n) md1+=(s[i] == '1');
   
   if(md1 == 0)
   {
        f(i,n) cout << 1 << '\n';
        return;
   }
   else if(md1 == 1)
   {
       f(i,n) if(s[i] == '1') cout << 0 << '\n';
       else if(i == n-1) cout << 2 << '\n';
       else if(s[n-1] == 1) cout << 2 << '\n';
       else cout << 1 << '\n';
           
       return;
   }
   
   md1++;
   int md2 = md1-2;
    
   int x1 = find(s,md1);
   int x2 = find(s,md2);
    
   f(i,n)
   {
      if(s[i] == '0')
      {
          int mod = md1;
          
          int val = x1;
          
          val=(val+mod_pow(2,n-i-1,mod))%mod;
          
          cout << dp[val] +1<< '\n';
      }
      else
      {
          int mod = md2;
          
          int val = x2;
          
          val=(val-mod_pow(2,n-i-1,mod))%mod;
          if(val < 0) val+=mod;
          
          cout << dp[val] +1<< '\n';
      }
   }
    
}

signed main()
{
    pre();
    
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 5480
#include<bits/stdc++.h>
//#include<stdint-gcc.h>

using namespace std;

map<int,int> mp;

bool sortcol(const vector<int>& v1, const vector<int>& v2 )
{
    return v1[1] < v2[1];
}

int main()
{
    int test=1;
    //cin>>test;
    while(test--)
    {
        int n,k,val;
        cin>>n>>k;
        set<int> ss;
        for(int i=0;i<n;++i)
        {
            cin>>val;
            ss.insert(val);
        }
        set<int>::iterator it;
        bool dp[k+1]; //current state of dp is true if player who will play next wins.

        for(int i=0;i<=k;++i)
            dp[i]=false;
        for(int i=1;i<=k;++i)
        {
            for(it=ss.begin();it!=ss.end();++it)
            {
                if((i-*(it))>=0)
                {
                    if(!dp[i - *(it)])
                    {
                        dp[i]=true;
                        break;
                    }
                }
            }
        }
        if(dp[k])
            cout<<"First";
        else
            cout<<"Second";

    }

    return 0;
}



Measured memory_bytes: 384
using System;

class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) Console.WriteLine("Possible");
    else Console.WriteLine("Impossible");
  }
}

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

int main(){
    int N; cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        cin >> d[i];
    }
    int sum = 0;

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            sum += d[i]*d[j];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9+7
    zero = [0] * 61
    one = [0] * 61
    for i in range(n):
        for j in range(61):
            if a[i]>>j  & 1:
                one[j] += 1
            else:
                zero[j] += 1
    ans = 0
    for i in range(60):
        ans += ((one[i]*zero[i]) * pow(2, i, mod)) % mod
        ans %= mod
    print(ans)
resolve()

Measured memory_bytes: 122936
N = int(input())
Xi = list(map(int,input().split()))
tairyoku = 10000000
for p in range(1,100+1,1):
  tmp = 0
  for x in Xi:tmp = tmp + (p-x)*(p-x)
  if tmp < tairyoku:
    tairyoku = tmp
print(tairyoku)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int yakusu(int s){
    int cnt = 0;
    int w = 1;
    while(w <= sqrt(s)){
        if(s % w == 0){
            cnt++;
            if(w*w != s) cnt++;
        }
        w++;
    }
    return cnt;
}
int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n-1; i++){
        int j = n-i;
        // iを因数分解
        ans += yakusu(i);
    }
    cout << ans << endl;
return 0;
}

Measured memory_bytes: 3672
#include<cstdio>
using namespace std;
void qsort(int left,int right,int *p){
    int i,j,t,temp;
    temp = p[(left+right)/2];
    i = left;
    j = right;
    while(i<=j){
        while(p[i]<temp)
            i++;
        while(p[j]>temp)
            j--;
        if(i<=j)
        {
            t = p[i],p[i]=p[j],p[j]=t;
            i++,j--;
        }
    }
    if(left<j)
        qsort(left,j,p);
    if(i<right)
        qsort(i,right,p);
}
int main(){
    int a[3];
    for(int i=0;i<3;i++)
        scanf("%d",&a[i]);
    qsort(0,2,a);
    for(int i=0;i<3;i++){
        if(i==2)
            printf("%d\n",a[i]);
        else
            printf("%d ",a[i]);
    }

    return 0;
}


Measured memory_bytes: 2704
N, K = [int(i) for i in input().split(' ')]
h = [int(hi) for hi in input().split(' ')]

dp = [float('inf')] * N
dp[0] = 0

for i in range(N - 1):
    for k in range(i + 1, min(i + K + 1, N)):
        dp[k] = min(dp[k], dp[i] + abs(h[i] - h[k]))

print(dp[-1])


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

typedef long long ll;

const int MAX_K = 100000;
ll K, A[MAX_K];

int main() {
  cin >> K;
  for (int i=0; i<K; i++) {
    scanf("%lld", &A[K-i-1]);
  }

  ll min = 2, max = 2;
  for (int i=0; i<K; i++) {
    max = A[i]*(max/A[i])+A[i]-1;
    min = A[i]*((min-1)/A[i])+A[i];

    // cout << min << " " << max << endl;
    if (max < min) {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << min << " " << max << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<fstream>

int main(){
	std::string b;

	std::cin >> b;

	if(b=="A") std::cout << 'T' << std::endl;
	if(b=="T") std::cout << 'A' << std::endl;
	if(b=="C") std::cout << 'G' << std::endl;
	if(b=="G") std::cout << 'C' << std::endl;

	return 0;
}


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

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

  long long int ans = 0;
  for(int i=55; i>=-1; i--){
    if(i != -1 && !(k & (1LL << i))) continue;

    long long int tmp = 0;
    for(int j=55; j>=0; j--){
      long long int q = (1LL << j);
      long long int cnt = 0;
      for(int l=0; l<n; l++){
        if((a[l]&q) == q) cnt++;
      }

      if (j > i) {
        if(k & q) tmp += q * (n-cnt);
        else tmp += q * cnt;
      }else if(j == i) {
        tmp += q * cnt;
      }else{
        tmp += q * max(cnt, n-cnt);
      }

    }
    ans = max(ans, tmp);

  }
  cout << ans << endl;

  return 0;
}


//


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define gc getchar()
#define N 100010
#define lint long long
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
lint x[N],v[N],s1[N],s2[N],s3[N],s4[N],pre1[N],pre2[N],suf3[N],suf4[N],ans;
int main()
{
	int n=inn();lint c;scanf("%lld",&c);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&v[i]);
	for(int i=1;i<=n;i++) s1[i]=s1[i-1]+v[i],s2[i]=s1[i];
	for(int i=1;i<=n;i++) s1[i]-=x[i],s2[i]-=2*x[i];
	for(int i=n;i>=1;i--) s3[i]=s3[i+1]+v[i],s4[i]=s3[i];
	for(int i=n;i>=1;i--) s3[i]-=c-x[i],s4[i]-=2*(c-x[i]);
	for(int i=1;i<=n;i++) pre1[i]=max(pre1[i-1],s1[i]),pre2[i]=max(pre2[i-1],s2[i]);
	for(int i=n;i>=1;i--) suf3[i]=max(suf3[i+1],s3[i]),suf4[i]=max(suf4[i+1],s4[i]);
	for(int i=0;i<=n;i++) ans=max(ans,pre2[i]+suf3[i+1]),ans=max(ans,pre1[i]+suf4[i+1]);
	return !printf("%lld\n",ans);
}

Measured memory_bytes: 8064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
	int a,b;
	int v1,v2;
	int t;
	cin>>a>>v1>>b>>v2>>t;
	if(v1<=v2){
			cout<<"NO";
			return 0;
	}
	b=fabs(b-a)-(v1-v2)*t;
	if(b<=0)
	cout<<"YES";
	else 
	cout<<"NO";
}

Measured memory_bytes: 3128
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	string s,t; cin>>s>>t;
	int ans = 0;
	rep(i,s.size()){
		if(s[i] != t[i])++ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3912
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int S[N],n,u[N][N],l[N][N],r[N][N];
char A[N][N];
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;i++)scanf("%s",A[i]+1);
	for (register int i=0;i<=n;i++)
		for (register int j=0;j<=n;j++)u[i][j]=A[i][j]>='0'&&A[i][j]<='9'?min(i,min(u[i-1][j],u[i][j-1])):1<<30;
	long long ans=0;
	for (register int x=1;x<=n;x++){
		for (register int i=x;i;i--){
			for (register int j=1;j<=n;j++)S[j]=S[j-1]+(u[x][j]<=i?A[x][j]-'0':0);
			for (register int j=n+1;j;j--){
				if (A[i][j]>='0'&&A[i][j]<='9'){
					if (i<x){
						l[i][j]=min(l[i][j+1],l[i+1][j]);
						r[i][j]=max(r[i][j+1],r[i+1][j]);
					}
					else l[i][j]=j,r[i][j]=max(j,r[i][j+1]);
				}
				else l[i][j]=1e9,r[i][j]=-1;
				if (l[i][j]<=r[i][j])ans+=(A[i][j]-'0')*(S[r[i][j]]-S[l[i][j]-1]-(i==x?A[i][j]-'0':0));
			}
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 15360
#include <iostream>
using namespace std;
int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; ++i)
    {
        int sum = 0;
        int num = i;
        while(num)
        {
            int digit = num % 10;
            sum += digit;
            num = num / 10;
        }
        if (sum >= A && sum <= B) ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define N 100010
#define mod 1000000007
//#define int ll
#define inf mod
string s;
void work(){
	repeat(i,0,s.length()){
		if(s[i]=='Z')s[i]='A';
		else s[i]++;
	}
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	cin>>s;
	repeat(i,0,n)work();
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
def reverse_polish_notation(x):
    operands = ["+", "-", "*"]
    number_stack = []
    for i in x:
        if i in operands:
            num2 = number_stack.pop()
            num1 = number_stack.pop()
            ans = eval("{}{}{}".format(num1, i, num2))
            number_stack.append(ans)
        else:
            number_stack.append(i)
    return ans
            
if __name__ == "__main__":
    x = input().split()
    print(reverse_polish_notation(x))


Measured memory_bytes: 5564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    string ans = "";
    rep(i,n) {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define df 0
long int c,d;
long int gcd(long int a,long int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
long int lcm(long int a,long int b){
  return a/gcd(a,b)*b;
}
long int f(long int n){
  return n-n/c-n/d+n/lcm(c,d);
}

int main(){
  long int a,b;
  scanf("%ld%ld%ld%ld",&a,&b,&c,&d);

  printf("%ld",f(b)-f(a-1));
}


Measured memory_bytes: 128
package main

import (
  "bufio"
  "fmt"
  "strings"
  "os"
  "strconv"
  "container/list"
)

func or(a []bool) bool {
  for i:=0; i<len(a); i++ {
    if a[i] {
      return true
    }
  }
  return false
}

func main()  {
  sc := bufio.NewScanner(os.Stdin)
  sc.Scan()
  NM := strings.Split(sc.Text(), " ")
  N, _ := strconv.Atoi(NM[0])
  M, _ := strconv.Atoi(NM[1])
  G := make([][]int, N)

  init := 0
  for i:=0; i<M; i++ {
    sc.Scan()
    AB := strings.Split(sc.Text(), " ")
    A, _ := strconv.Atoi(AB[0])
    B, _ := strconv.Atoi(AB[1])
    G[A-1] = append(G[A-1], B-1)
    G[B-1] = append(G[B-1], A-1)
    init = A-1
  }
  reach := make([]bool, N)
  pn := 0
  s := init
  e := init
  reach[init] = true
  pn += 1
  result := list.New()
  result.PushBack(init+1)
  for{
    c := 0
    for j:=0; j<len(G[e]); j++ {
      if reach[G[e][j]] {
        continue
      }
      reach[G[e][j]] = true
      result.PushFront(G[e][j]+1)
      e = G[e][j]
      pn += 1
      c += 1
      break
    }
    if c == 0 {
      break
    }
  }

  for {
    c := 0
    for j:=0; j<len(G[s]); j++ {
      if reach[G[s][j]] {
        continue
      }
      reach[G[s][j]] = true
      result.PushBack(G[s][j]+1)
      s = G[s][j]
      pn += 1
      c += 1
      break
    }
    if c == 0 {
      break
    }
  }

  fmt.Println(pn)
  for e := result.Front(); e != nil; e = e.Next() {
    fmt.Print(e.Value)
	  fmt.Print(" ")
  }
  fmt.Println("")
}


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

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	string S;
	getchar();
	getline(cin, S);
	if(N%2==1) {
		cout << "No" << endl;
	}
	else {
		bool f = true;
		for(int i=0;i<N/2;++i) {
			if(S[i] != S[i+N/2]){
				f = false;
				break;
			}
		}
		cout << (f ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){


    string S;
    
    cin >> S;

    if(S=="SUN") cout << 7 << endl;
    else if(S=="MON") cout << 6 << endl;
    else if(S=="TUE") cout << 5 << endl;
    else if(S=="WED") cout << 4 << endl;
    else if(S=="THU") cout << 3 << endl;
    else if(S=="FRI") cout << 2 << endl;
    else if(S=="SAT") cout << 1 << endl;
    

}

Measured memory_bytes: 3616
program sample
    implicit none
  
    integer(8) :: i,j,m,n,t
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n,t
    allocate(x(n))
    read(*,*)x
    m=0
    do i=2,n
        m=m+min(x(i)-x(i-1),t)
    end do
    m=m+t


    write(*,*) m
  
    stop
end program sample
  



Measured memory_bytes: 4560
#include<iostream>
#include<queue>

using namespace std;

int w,h;
int map[100][100];

void delIsland(int y,int x){

  queue<pair<int,int> > que;
  que.push(make_pair(y,x));


  int next[8][2] = {{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
  while(!que.empty()){
    pair<int,int> now  = que.front();
    que.pop();

    if(now.first<0 || now.first>=h || now.second<0 || now.second>=w || map[now.first][now.second]!=1){
      continue;
    }else{
      map[now.first][now.second] = 0;
    }


    for(int i=0;i<8;i++){
      int ny = now.first + next[i][0];
      int nx = now.second + next[i][1];
      que.push(make_pair(ny,nx));
    }
  }
}

int main(){
  cin>>w>>h;
  while(w!=0 && h!=0){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
       cin>>map[i][j];
     }
   }

   int ans = 0;
   for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
     if(map[i][j] == 1){
       ans++;
       delIsland(i,j);
     }
   }
 }

 cout<<ans<<endl;
 cin>>w>>h;
}

return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
typedef long double ld;
#define int ll
#define maxn 200001

int A[maxn],N,Q;


int32_t main(){
	fast;
	cin>>N;
	int xo = 0;
	
	FOR(i,1,N){
		cin>>A[i]; xo ^= A[i];
	}
	
	FOR(i,1,N) cout<<(xo ^ A[i])<<' ';
	
}


Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
const int M=3e5+5,mod=1e9+7;
int mmp[8][2]={3,1,5,2,2,2,4,7,3,3,6,1,5,5,3,1},dp[M][8],len,i,j;
char ch[M];
void in(){scanf("%s",ch);}
void ac()
{
	len=strlen(ch);dp[len][1]=dp[len][2]=1;
	for(i=len-1;i>=0;--i)for(j=0;j<8;++j)
	{
		if(ch[i]!='0')dp[i][j]+=dp[i+1][mmp[j][1]];
		if(ch[i]!='1')dp[i][j]+=dp[i+1][mmp[j][0]];
		dp[i][j]%=mod;
	}
	printf("%d",dp[0][0]);
}
int main(){in();ac();}

Measured memory_bytes: 9856
from heapq import heappush, heappop


p_que = []
while True:
    line = input().split()
    if line[0] == 'end':
        break
    elif line[0] == 'insert':
        val = int(line[1])
        heappush(p_que, -val)
    elif line[0] == 'extract':
        print(-1 * heappop(p_que))
    else:
        raise ValueError('想定外の事態')



Measured memory_bytes: 45308
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define int long long int
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int32_t main(){
	FIO
	int a,b,c,k,ans=0;
	cin>>a>>b>>c>>k;
	if(a<=k){ans+=a;k-=a;}
	else{ans+=k;k=0;}
	if(k==0){cout<<ans;return 0;}
	if(b<=k){k-=b;}
	else{k=0;}
	if(k==0){cout<<ans;return 0;}
	if(c<=k){ans+=-1*c;k-=c;}
	else{ans+=-1*k;k=0;}
	if(k==0){cout<<ans;return 0;}
	
	return 0;
}

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

int main() {
	// your code goes here
	int a,b,num;
	cin>>a>>b;
	for(int i=0;i<=a;i++){
		num=a-i;
		if(i*2+num*4==b){
			cout<<"Yes"<<endl;
			return 0;
			break;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3628
if __name__ == '__main__':
	S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
	K = int(input())
	print(S[K-1])

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,ans=0;
	cin >> n;
	map<string,ll> m;
	rep(i,n){
		string s;
		cin >> s;
		sort(all(s));
		ans+=m[s];
		m[s]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         998244353
#define mode        1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

const int N = 1e5+5;
ll n;
ll a[N],b[N];

void solve()
{
       cin>>n;
       rep(i,1,n+1) cin>>a[i]>>b[i];
       ll x[n+1];
       memset(x,0,sizeof x);
       ll inc=0;
       for(ll i=n; i>0; i--)
       {
              a[i]+=inc;
              ll k=a[i]/b[i];
              if(a[i]%b[i]) k++;
              ll dif=(k)*b[i]-a[i];
              x[i]=dif;
              inc+=dif;
       }
       ll ans=0;
       rep(i,1,n+1) ans+=x[i];
       cout<<ans;
}



int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


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

void solve(long long N) {
  ll minVal = 1e12;
  for (ll i = 1; i < sqrt(N) + 1; i++) {
      if (N%i != 0) continue;
      minVal = min(minVal, N/i+i);
  }
  cout << minVal - 2 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include <cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
#include <bits/stdc++.h>
using namespace std;

int main()
{ 
    int x;
    cin >> x;
    
    int bin = (2000.0 - 400.0) / 8.0;
    
    int y = (x - 400) / bin;
    
    cout << 8-y << endl;
}


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

typedef struct Node {
    int key;
    struct Node *prev;
    struct Node *next;
} Node;

Node *nil = NULL;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->prev = nil;
    nil->next = nil;
}

void insertNodeByKey(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    x->prev = nil;
    nil->next = x;
}

Node *searchNodeByKey(int key) {
    // printf(">> searchNodeByKey %d\n", key);
    Node *cur = nil->next;
    while (cur != nil) {
        if (cur->key == key)
            break;
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *x) {
    // printf(">> deleteNode %d\n", x->key);
    if (x == nil)
        return;
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
}

void deleteNodeByKey(int key) { deleteNode(searchNodeByKey(key)); }

void deleteFirst() { deleteNode(nil->next); }

void deleteLast() { deleteNode(nil->prev); }

void printList() {
    Node *cur = nil->next;
    while (1) {
        if (cur == nil)
            break;
        printf("%d", cur->key);
        if (cur->next != nil) {
            printf(" ");
        } else {
            printf("\n");
        }
        cur = cur->next;
    }
}

void deinit() {
    Node *cur = nil->next;
    while (cur != nil) {
        deleteNode(cur);
        cur = cur->next;
    }
    free(nil);
}

int main(int argc, char **argv) {
    int n = 0;
    char cmd[128] = {0};
    int key = 0;
    scanf("%d", &n);
    init();
    while (n > 0) {
        n--;
        scanf("%s %d", cmd, &key);
        // printf("cmd=%s key=%d\n", cmd, key);
        if (cmd[0] == 'i') {
            insertNodeByKey(key);
        } else if (cmd[6] == '\0') {
            deleteNodeByKey(key);
        } else if (cmd[6] == 'L') {
            deleteLast();
        } else {
            deleteFirst();
        }
        // printList();
    }
    printList();
    deinit();
    return 0;
}


Measured memory_bytes: 33016
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] B = new int[N];
		for(int i = 0; i < N - 1; i++) {
			B[i] = sc.nextInt();
		}
		B[N - 1] = Integer.MAX_VALUE;
		sc.close();
		int sum = B[0];
		// System.out.println("--------");
		// System.out.print(sum);
		for(int i = 0; i < N - 1; i++) {
			// System.out.print(">");
			sum += Math.min(B[i], B[i + 1]);
			// System.out.print(sum);
		}
		// System.out.println("\n--------");
		System.out.println(sum);
	}
}


Measured memory_bytes: 23636
def count(n,b,k)
  q,r=n.divmod b
  q*[b-k,0].max+[r-k+1,0].max
end

n,k=gets.split.map(&:to_i)
if k==0
  puts n*n
  exit
end
ans=0
1.upto(n){|b|ans+=count(n,b,k)}
puts ans

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 187
using namespace std;

inline void cmin(int &x, const int &y) {
    if (y < x) x = y;
}

inline void cmax(int &x, const int &y) {
    if (x < y) x = y;
}

int n, m, f[N][N][N][18], a[N][N];
char s[N][N];

bool check = 0;

inline int get(int i, int l, int r, int k) {
    int L = l, R = r - 1, res = l, ret;
    while (L <= R) {
        int mid = (L + R) >> 1;
        if (f[i][l][mid][k] >= f[i][mid + 1][r][k])
            L = (res = mid) + 1;
        else R = mid - 1;
    }
    ret = min(f[i][l][res][k], f[i][res + 1][r][k]);
    if (res + 1 < r) ++res;
    cmax(ret, min(f[i][l][res][k], f[i][res + 1][r][k]));
    if (check) cout << "  # " << ret  << endl;
    return ret;
}

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        scanf("%s", s[i] + 1);
        for (int j = 1; j <= m; ++j)
            a[i][j] = s[i][j] == '.', a[i][j] += a[i][j - 1];
    }

    for (int i = n; i >= 1; --i)
        for (int len = 1; len <= m; ++len)
            for (int l = 1, r = len; r <= m; ++l, ++r) {
                int &tmp = f[i][l][r][0];
                if (a[i][r] - a[i][l - 1] == 0 || a[i][r] - a[i][l - 1] == r - l + 1)
                    while (i + tmp <= n && (a[i + tmp][r] - a[i + tmp][l - 1] == a[i][r] - a[i][l - 1]))
                        ++tmp;
                //cout << i << " " << l << " " << r<< " " << 0 << " " << tmp << endl;
                for (int k = 1; k <= 16; ++k) {
                    f[i][l][r][k] = f[i][l][r][k - 1];
                    if (i + f[i][l][r][k - 1] <= n)
                        cmax(f[i][l][r][k], f[i][l][r][k - 1] + f[i + f[i][l][r][k - 1]][l][r][k - 1]);
                    //if (i == 1 && l == 1 && r == 2 && k == 1)
                    //    check = 1, cout << " ## " << f[2][l][r][k - 1] << endl;
                    if (l < r) cmax(f[i][l][r][k], get(i, l, r, k - 1));
                    //check = 0;
                    //cout << i << " " << l << " " << r << " " << k << " " << f[i][l][r][k] << endl;
                }
            }

    int ans = -1;
    for (int i = 0; i <= 16; ++i)
        if (f[1][1][m][i] >= n) {
            ans = i; break; 
        }

    if (ans == -1) cout << " :( ";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 457088
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = max(a, b); i != 0; i--) {
		if (a % i == 0 && b % i == 0)
			k--;
		if (k == 0) {
			cout << i;
			return 0;
		}
	}
}

Measured memory_bytes: 256
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N = rd.readInt()
    val A = IntArray(N)
    for (i in 0 until N) {
        A[i] = rd.readInt()
    }

    var ok = A[0]==0
    for (i in 1 until N) {
        if (A[i] <= A[i-1]+1 && A[i] <= i) continue
        ok = false
        break
    }
    if (!ok) {
        println(-1)
        return
    }


    var cnt = A[N-1].toLong()
    for (i in N-2 downTo 0) {
        if (A[i] == A[i+1]-1) continue
        else cnt += A[i]
    }

    val ans = cnt
    println(ans)
}


//val rd = debug.Reader("agc", "024", "c", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


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


using namespace std;


int N, M;
vector<int> H;


int main()
{
	cin >> N;
	cin >> M;
	
	H = vector<int>(N+1);
	auto yoi = vector<int>(N + 1, true);
	yoi[0] = false;

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

	for (int i = 1; i <= M; i++) {
		int a, b;
		cin >> a;
		cin >> b;

		if (H[a] <= H[b]) {
			yoi[a] = false;
		}

		if (H[b] <= H[a]) {
			yoi[b] = false;
		}
	}
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (yoi[i]) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, sum;
  cin >> N >> K;
  sum=1;

  for(int i=1;i<=N;i++){
    if(sum<K) sum*=2;
    else sum+=K;
  }

cout << sum << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    for(int i=1;i<n;i++){
        if(s.substr(i-1,2)=="AC"){
            cout <<"Yes"<<endl;
            return 0;
        }
    }
    cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 256