akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

int main() {
  ll n; cin >> n;
	if (n % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}

	ll d = 10, ans = 0;
	while (n / d != 0) {
		ans += n / d;
		d *= 5;
	}

	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
	
using namespace std;
 
#define int long long
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define LOCAL
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)
 
typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;
 
const int INF = LONG_LONG_MAX/2;
const int NINF = LONG_LONG_MIN/2;
const double PI = 3.141592653589793238;

int cnt[1000000];

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	
	vi a(n);
	for (int& x: a) cin >> x;
	
	int c = 0;
	for (int i = 0; i < n; i++) {
		if ((i+1)%2 == 1 && a[i]%2 == 1) {
			c++;
		}
	}
	
	cout << c << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined -std=c++17


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

using namespace std;
using pii=pair<int,int>;


char grid[1000][1000];
int h,w;

const int mod=1e9+7;

map < pii, int > dp;


int solve (int row,int col) {
      if (row<0||col<0) return 0;
      if (row==0&&col==1) return grid[row][col]!='#';
      if (row==1&&col==0) return grid[row][col]!='#';
      if (grid[row][col]=='#') return 0;
      if (!dp.count({row,col-1})) dp[{row,col-1}]=solve(row,col-1)%mod;
      if (!dp.count({row-1,col})) dp[{row-1,col}]=solve(row-1,col)%mod;
      return (dp[{row,col-1}]%mod+ dp[{row-1,col}]%mod)%mod;
}



int main(){
      cin>>h>>w;
      for (int i=0; i<h; i++)
            for (int j=0; j<w; j++)
                  cin>>grid[i][j];

      cout<<solve(h-1,w-1)<<endl;

      return 0;
}

Measured memory_bytes: 64000
using System;

class P
{
public static void Main()
{
            //????????????????????????
            string a = Console.ReadLine();

            //?????????????????????????????????
            var b = a.Split(' ');

            //?????°???????????????
            int W = Int32.Parse(b[0]);
            int H = Int32.Parse(b[1]);
            int x = Int32.Parse(b[2]);
            int y = Int32.Parse(b[3]);
            int r = Int32.Parse(b[4]);

            //?????¶??????
            if (r <= x & x <= W - r & r <= y & y <= H - r)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
}
}

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  vector<vector<int64_t>> dp(N+1,vector<int64_t>(2));
  dp[N][0]=0;
  dp[N][1]=1;

  for(int i=N-1;i>=0;--i){
    for(int j=0;j<2;++j){
      int64_t k=S[N-1-i]-'0';
      if(j==0){
        if(k==0) dp[i][j]=dp[i+1][0];
        else dp[i][j]=min(k+dp[i+1][0],(10-k)+dp[i+1][1]);
      }
      if(j==1){
        if(k==9) dp[i][j]=dp[i+1][1];
        else dp[i][j]=min(k+1+dp[i+1][0],(9-k)+dp[i+1][1]);
      }
      //cout<<dp[i][j]<<" "<<endl;
    }
  }
    
  cout<<dp[0][0]<<endl;
}

Measured memory_bytes: 55940
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    ll H;
    cin >> H;

    //resolve
    ll hp = H;
    ll atackCounter=0;
    cpp_int ans = 1;
    while(hp>1) {
        hp/=2;
        ans *= 2;
        atackCounter++;
    }

    //cpp_int ans = (1<<atackCounter)-1;

    // output
  ans *= 2;
    cout << ans-1 << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int a[n];
  for (int i = n - 1; i >= 0; i--) {
    cin >> a[i];
  }

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


Measured memory_bytes: 3096
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
	int H,W,h,w;
	
	cin >> H >> W >> h >> w;
	
	cout << (H-h)*(W-w) << endl;
	
	return 0;
}

Measured memory_bytes: 3648
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::{i32, i64, i128, u32, u64, u128, f64};
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::{input, marker::{Isize1, Usize1, Bytes, Chars}};

#[proconio::fastout]
fn main() {
    proconio::input!(
        s: String,
    );
    if s == "RRR".to_string() { println!("3"); }
    else if s.contains("RR") { println!("2"); }
    else if s.contains("R") { println!("1"); }
    else { println!("0"); }
}


Measured memory_bytes: 2140
# coding: utf-8
# Your code here!

list1 = list(map(int,input().split()))

#print(list1)
list2 = []

## bit全探索 
#list1 = ['A', 'B', 'C']
for i in range(list1[1]):
    list2.append(list(map(int,input().split())))

list3 = list(map(int,input().split()))
#print(list2)
#print(list3)
a = 0
# 全探索
for i in range(2**list1[0]):  # 空集合を除く場合はrange(1, 2**len(list1))
    for k in range(list1[1]):
        t = 0
        for j in range(list1[0]):
#            print(i,k,j,i >> j)
            if j+1 in list2[k][1:] and (i >> j) &1 == 1:
#                print(i,k,j)
                t += 1
#        print(t)
        if t%2 != list3[k]:
#            print("break",i,k,j)
            break
    else:
#        print(i)
        a += 1 
print(a)
    
    

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int M1 = in.nextInt();
		int D1 = in.nextInt();
		int M2 = in.nextInt();
		int D2 = in.nextInt();
		System.out.println(M1 + 1 == M2 ? 1 : 0);
		in.close();
	}
}

Measured memory_bytes: 22996
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[100001];
  int b[100001];
  int c[100001];
  a[0] = 0;
  b[0] = 0;
  c[0] = 0;
  for (int i = 1; i <= n; i++){
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
  }
  for (int i = 0; i < n; i++){
    int dt = a[i+1] - a[i];
    int dx = b[i+1] - b[i];
    int dy = c[i+1] - c[i];
    if (dt < abs(dx) + abs(dy) || abs(dt + dy + dx) % 2 == 1){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


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

typedef long long ll;

void solve(){
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	string s;
	cin >> s;
	const ll B = 62;
	vector<ll> what(62);
	for(int i = n-1; i >= 0; i--){
		ll cur = a[i];
		for(int j = B-1; j >= 0; j--){
			if(what[j] && (cur & (1ll << j))){
				cur ^= what[j];
			}
		}
		if(s[i] == '0'){
			for(int j = B-1; j >= 0; j--){
				if((cur & (1ll << j))){
					what[j] = cur;
					break;
				}
			}
		} else if(s[i] == '1'){
			if(cur != 0){
				cout << "1" << '\n';
				return;
			}
		}
	}
	cout << "0" << '\n';
	return;
}

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int T;
	cin >> T;
	while(T--) solve();
}


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

using namespace std;

int main() {
  int a, b;
  cin >> a;
  cin >> b;
  if((a+b) % 2 == 1) {
    cout << "IMPOSSIBLE" << '\n';
  }
  else {
    cout << (a+b)/2 << '\n';
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);

int main(){
    int n;cin>>n;
    vi a(n);
    rep(i,n){
        int x;cin>>x;
        a[i]=x;
    }
    if(a[0]!=0){
        cout<<-1<<endl;return 0;
    }
    reverse(been(a));
    int cur =a[0];
    ll ans =0;
    rep(i,n){
        if(a[i]+1<cur){
            cout<<-1<<endl;return 0;
        }
        else if(a[i]>=cur){
            cur=a[i];ans+=a[i];
        }
        else {
            cur=a[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4016
num = int(input())
room = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

while num > 0:
    list = input().split()
    b = int(list[0]) - 1
    f = int(list[1]) - 1
    r = int(list[2]) - 1
    v = int(list[3])
    room[b][f][r] += v 
    num -= 1

for i in range(4):
    for j in range(3):
        for k in range(10):
            print("", room[i][j][k], end ="")
        print()
    if i < 3:
        print("####################")


Measured memory_bytes: 5632
#include<iostream>
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;


#define mod                1000000000000000007
#define pi                 3.1415926535897932384626433832795
#define ll                 long long
#define pb                 push_back
#define pii                pair < int , int >
#define vecsort(v)         sort(v.begin(),v.end())
#define lcm(x,y)           (x/__gcd(x,y))*y
#define forn(i,n)          for(i = 0 ; i < n ; i++)
#define deb(x)             cout << #x << " " << x << endl;
#define vecsum(v)          accumulate(v.begin(), v.end(), 0)
#define T(t)               cout << "Case " << t <<": ";
#define fast_cin           ios_base::sync_with_stdio(false);cin.tie(NULL)



int main() {



    ll a , b , x;
    cin >> a >> b >> x;

    if( a % x == 0 ){
        cout << (b/x-a/x) + 1 << endl;
    }
    else{
        cout << (b/x - a/x) << endl;
    }


    return 0;
}


Measured memory_bytes: 3644
sx, sy, tx, ty = map(int, raw_input().split())
dx = tx-sx
dy = ty-sy
s = ""
s += "L" + "U"*(dy+1) + "R"*(dx+1) + "D"
s += "R" + "D"*(dy+1) + "L"*(dx+1) + "U"
s += "U"*dy + "R"*dx
s += "D"*dy + "L"*dx
print s

Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ff first
#define ss second
#define maxn 1000000007
#define PI 3.14159265358979323846
#define MAX 1000007 
using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    //cout<<fixed<<setprecision(20);
    string s;
    cin>>s;
    for (int i = 1; i < s.length(); ++i)
    {
        if(s[i]==s[i-1])
        {
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}

Measured memory_bytes: 256
h, w = gets.chomp.split.map(&:to_i)
s = []
h.times do |i|
  s[i] = gets.chomp.split("").map(&:to_s)
end
d = [[-1, 0], [1, 0], [0, -1], [0, 1]]


h.times do |i|
  w.times do |j|
    if s[i][j] == "#"
      result = false
      d.each do |dy, dx|
        next if i + dy < 0 || i + dy >  h - 1 || j + dx < 0 || j + dx > w - 1
        if s[i + dy][j + dx] == "#"
          result = true
          break
        end
      end
      unless result
        puts "No"
        exit
      end
    end
  end
end
puts "Yes"


Measured memory_bytes: 2044
package main

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

var sc *bufio.Scanner

func totalPoints(days int, acts [][]int) int {
	maxInt := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	points := make([][3]int, days+2)
	for j := 0; j < days; j++ {
		points[j+1] = [3]int{
			maxInt(points[j][1], points[j][2]) + acts[j][0],
			maxInt(points[j][0], points[j][2]) + acts[j][1],
			maxInt(points[j][0], points[j][1]) + acts[j][2],
		}
	}
	return maxInt(points[days][0], maxInt(points[days][1], points[days][2]))
}

func ScanInt() int {
	sc.Scan()
	res, _ := strconv.Atoi(sc.Text())
	return res
}

func ScanIntArray(size int) []int {
	res := make([]int, size)
	for i := 0; i < size; i++ {
		sc.Scan()
		res[i], _ = strconv.Atoi(sc.Text())
	}
	return res
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	days := ScanInt()
	activities := make([][]int, days)
	for i := 0; i < days; i++ {
		activities[i] = ScanIntArray(3)
	}
	fmt.Println(totalPoints(days, activities))
}


Measured memory_bytes: 9856
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
	ll x,y,a,b,c,s=0;
	cin>>x>>y>>a>>b>>c;
	vector<ll> v1,v2,v3;
	ll colorless=0,red=0,blue=0;
	forn(i,a){
		ll t;
		cin>>t;
		v1.pb(t);
	}
	forn(i,b){
		ll t;
		cin>>t;
		v2.pb(t);
	}
	forn(i,c){
		ll t;
		cin>>t;
		v3.pb(t);
	}
	sort(v1.begin(),v1.end(),greater<ll>());
	sort(v2.begin(),v2.end(),greater<ll>());
	sort(v3.begin(),v3.end(),greater<ll>());
	
	while((x+y)>colorless){
		ll t=0;
		if((x!=0)&&(y!=0)){
			if(v1[red]>v2[blue]) t=0;
			else t=1;
		}
		else if(x==0) t=1;
		else t=0;
		if(t==0){
			if(colorless==c){
				s+=v1[red];
				x--;
				red++;
				continue;
			}
			if(v1[red]>v3[colorless]){
				s+=v1[red];
				x--;
				red++;
			}
			else{
				s+=v3[colorless];
				colorless++;
			}
		}
		else{
			if(colorless==c){
				s+=v2[blue];
				y--;
				blue++;
				continue;
			}
			if(v2[blue]>v3[colorless]){
				s+=v2[blue];
				y--;
				blue++;
				continue;
			}
			else{
				s+=v3[colorless];
				colorless++;
			}
		}
	}
	cout<<s;
}

Measured memory_bytes: 3316
#include <stdio.h>
int main(){
  int i,j,n,maxv,minv;
  int input[200000];

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

  maxv = input[1]-input[0];
  minv = input[0];
  for(i=1;i<n;i++){
    if( maxv<input[i]-minv ) maxv = input[i]-minv;
    if( input[i]<minv ) minv = input[i];
  }

  printf("%d",maxv);
  printf("\n");
  return 0;
}

Measured memory_bytes: 1380
import math
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
sum = 0
for i in range(A+1):
	for j in range(B+1):
		for k in range(C+1):
			sum = 50 * k + 100 * j + 500 * i
			if(sum == X):
				cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <cmath>
using namespace std;

vector<long long> A, B;
int N, M, Q;

long long solve(long long x) {
	int pos1 = lower_bound(A.begin(), A.end(), x) - A.begin();
	int pos2 = lower_bound(B.begin(), B.end(), x) - B.begin();

	vector<long long>G1, G2;
	if (pos1 >= 1) G1.push_back(A[pos1 - 1]);
	if (pos1 < A.size()) G1.push_back(A[pos1]);

	if (pos2 >= 1) G2.push_back(B[pos2 - 1]);
	if (pos2 < B.size()) G2.push_back(B[pos2]);

	long long ans = (1LL << 60);
	for (int i = 0; i < G1.size(); i++) {
		for (int j = 0; j < G2.size(); j++) {
			ans = min(ans, abs(x - G1[i]) + abs(G1[i] - G2[j]));
			ans = min(ans, abs(x - G2[j]) + abs(G2[j] - G1[i]));
		}
	}
	return ans;
}

int main() {
	cin >> N >> M >> Q;
	for (int i = 0; i < N; i++) { long long c; cin >> c; A.push_back(c); }
	for (int i = 0; i < M; i++) { long long c; cin >> c; B.push_back(c); }
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	for (int i = 1; i <= Q; i++) {
		long long pl; cin >> pl;
		cout << solve(pl) << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
#define INF 1000000001;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  long long ans1 = 0;
  long long ans2 = 0;

  long long before = a[0];
  long long a1point = -100;

  for (int i = 1; i < n; i++) {
    long long after = a[i];
    if (before == after && ans1 == 0 && ans2 == 0) {
      ans1 = after;
      a1point = i;
    } else if (before == after && ans1 != 0 && ans2 == 0 && a1point != i-1) {
      ans2 = after;
    }
    before = after;
  }

  cout << ans1 * ans2 << endl;
  return 0;
}

Measured memory_bytes: 1024
N,M,K = map(int,input().split())
solved = False

for i in range(N+1):
    for j in range(M+1):
        
        if i*M+j*N-2*i*j == K:
            print('Yes')
            solved = True
            break
            
    if solved:
        break
        
else:
    print('No')

Measured memory_bytes: 3060
n, m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
B = [int(input()) for i in range(m)]
ans = []
for a in A:
    vec = 0
    for i in range(m):
        vec += a[i] * B[i]
    ans.append(vec)
print("\n".join(map(str, ans)))


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, sum;
  cin >> N >> K;
  sum = 1;
 
  for (int i = 0; i < N; i++){
    if (sum >= K){
      sum = sum + K;
    }
    else{
      sum = sum * 2;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = char;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

vector<string> solve(int h, int w, vector<string>& css){
    vector<string> dss;
    for(auto cs: css){
        dss.push_back(cs);
        dss.push_back(cs);
    }
    return dss;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w;
    cin >> h >> w;
    vector<string> css(h);
    for(int i = 0; i < h; i++){
        cin >> css[i];
    }

    const vector<string>& dss = solve(h, w, css);
    for(auto ds: dss){
        cout << ds << endl;
    }

    return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long

#define int8_t signed char
#define int16_t signed short
#define int32_t signed int
#define int64_t signed long long

using namespace std;

int main(int argc, char const* argv[])
{
    int N = 0;
    int M = 0;
    cin >> N >> M;

    vector<int> broken(N+1);
    REP(i,M) {
        int a;
        cin >> a;
        broken[a] = 1;
    }


    long long dp[N+1] = {};
    //REP(i, N) dp[i][j] = INT_MIN;

    dp[0] = 1;
    dp[1] = broken[1] ? 0:1;
    for (int i = 0; i <= N-2; i++) {

        dp[i+2] = (dp[i] + dp[i+1]) % 1000000007;
        if (broken[i+2]) {
            dp[i+2] = 0;
            continue;
        }        
    }

    cout << dp[N] << endl;

    return 0;
}




Measured memory_bytes: 1408
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from heapq import heappop, heapify, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
L = [LIST() for i in range(M)]

graph = defaultdict(list)

def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist


for a, b in L:
    graph[a-1].append((b-1, 1))
    graph[b-1].append((a-1, 1))

ans = 0
for a, b in L:
    E = deepcopy(graph)
    E[a-1].remove((b-1, 1))
    d = dijkstra(E, a-1)
    if d[b-1] == INF:
        ans += 1
print(ans)





Measured memory_bytes: 5588
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let _n: usize = input();
    let m: usize = input();
    let mut ab: Vec<(usize, usize)> = (0..m).map(|_| (input(), input())).collect();
    ab.sort_by_key(|&(_, b)| b);

    let mut prev = 0;
    let mut ans = 0;
    for &(a, b) in &ab {
        if prev < a {
            ans += 1;
            prev = b - 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
  int n,f;
  long long a,b,c;
  while(std::cin>>n,n){
		map<int,long long> m;
		vector<int> v;
		f=1;
    for(;n;n--){
      std::cin>>a>>b>>c;
      if(!m[a])v.push_back(a);
      m[a] += b*c;
    }
    
    for(int i=0;i<v.size();i++){
      if(m[v[i]]>=1000000){
				f=0;
				cout<<v[i]<<endl;}
    }
    if(f)cout<<"NA"<<endl;
  }
  return 0;
}

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

#define int long long
main(){
  int q,h,s,d,n; cin >> q >> h >> s >> d >> n;
  h = min(h, 2*q);
  s = min(s, 2*h);
  if(2*s <= d) cout << n * s << endl;
  else cout << (n/2)*d + (n%2)*s << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
//from CrAzYUnIoN
//I prefer being hacked to being FST
using namespace std;
//数组不要开小了
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1)a=14;
    if(b==1)b=14;
    if(a>b)cout<<"Alice"<<endl;
    if(a<b)cout<<"Bob"<<endl;
    if(a==b)cout<<"Draw"<<endl;
	return 0;
}


Measured memory_bytes: 256
#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 rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;

int K,X;
void input(){
    cin>>K>>X;
    for(int i=X-K+1; i<=X+K-1; i++)cout<<i<<" ";
}

void solve(){

}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include <string.h>
using namespace std;
typedef long long ll;
ll t=0,n,m;
ll y,z;
ll i,j,k;
ll a[1000005];
int main()
{
    ll h,x=0,j,ans=0,ma=0,k,d;

        scanf("%lld %lld %lld",&x,&k,&d);
        if(x<0)
            x=-x;
        if(abs(x-d)>x)
        {
            if(k%2==1)
            {
                ans=abs(x-d);
            }
            else
            {
                ans=x;
            }
        }
        else
        {
            if(k%2==1)
            {
                if(x/d<k)
                {
                    h=x/d;
                    if(h%2==1)
                    {
                        ans=x%d;
                    }
                    else
                    {
                        ans=min(abs(x%d-d),abs(x%d+d));
                    }
                }
                else
                {
                    ans=x-k*d;
                }
            }
            else
            {
                if(x/d<k)
                {
                    h=x/d;
                    if(h%2==0)
                    {
                        ans=x%d;
                    }
                    else
                    {
                        ans=min(abs(x%d-d),abs(x%d+d));
                    }
                }
                else
                {
                    ans=x-k*d;
                }
            }
        }
        printf("%lld\n",ans);



    return 0;
}


Measured memory_bytes: 3820
<?php
  declare(strict_types=1);

  fscanf(STDIN, "%i", $n);
  $xs = explode(" ", trim(fgets(STDIN)));

  $ys = [];
  for ($i = 0; $i < $n; ++$i)
  {
      for ($j = $n; $j > 0; $j -= 2)
      {
          $ys[$i++] = $xs[$j - 1];
      }

      for ($j = $n % 2; $j < $n; $j += 2)
      {
          $ys[$i++] = $xs[$j];
      }
  }

  echo implode(" ", $ys), PHP_EOL;


Measured memory_bytes: 33392
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
#define MP make_pair
#define PB push_back
#define F_d first
#define S_d second
#define LARGE 100000000
#define MOD 100000
#define LL long long

int M, N, K;
string grid[1009];
int jc[1009][1009] = {}, oc[1009][1009] = {}, ic[1009][1009] = {};


int main() {
	cin >> M >> N >> K;
	for (int i = 1; i <= M; i++) {
		cin >> grid[i];
		for (int j = 1; j <= N; j++) {
			if (grid[i][j-1] == 'J')jc[i][j]++;
			if (grid[i][j-1] == 'O')oc[i][j]++;
			if (grid[i][j-1] == 'I')ic[i][j]++;
			jc[i][j] += jc[i][j - 1] + jc[i - 1][j] - jc[i - 1][j - 1];
			oc[i][j] += oc[i][j - 1] + oc[i - 1][j] - oc[i - 1][j - 1];
			ic[i][j] += ic[i][j - 1] + ic[i - 1][j] - ic[i - 1][j - 1];
		}	
	}

	for (int i = 0; i < K; i++) {
		int i1, j1, i2, j2;
		cin >> i1 >> j1 >> i2 >> j2;
		int J, O, I;
		J = jc[i2][j2] - jc[i2][j1 - 1] - jc[i1 - 1][j2] + jc[i1 - 1][j1 - 1];
		O = oc[i2][j2] - oc[i2][j1 - 1] - oc[i1 - 1][j2] + oc[i1 - 1][j1 - 1];
		I = ic[i2][j2] - ic[i2][j1 - 1] - ic[i1 - 1][j2] + ic[i1 - 1][j1 - 1];
		cout << J << " " << O << " " << I << endl;
	}
	
	

	return 0;
}




Measured memory_bytes: 15732
#include <stdio.h>
int main(void){
    int a;
    scanf("%d", &a);
    if(a==22)
        printf("Christmas Eve Eve Eve\n");
    if(a==23)
        printf("Christmas Eve Eve\n");
    if(a==24)
        printf("Christmas Eve\n");
    if(a==25)
        printf("Christmas\n");
    return 0;
}

Measured memory_bytes: 128
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>

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

int main() {
    ll h, w;
    cin >> h >> w;
    vector<bool> v;
    v[0];
    vector<int> v2;
    v2[0];
    int a[h][w], b[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    ll max_diff = 2 * 80 * 160;
    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = false;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = true;
    dp[0][0][-b[0][0] + a[0][0] + mid] = true;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if (i + 1 <= h - 1) {
                    dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] |= dp[i][j][l];
                    dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] |= dp[i][j][l];
                }
                if (j + 1 <= w - 1) {
                    dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] |= dp[i][j][l];
                    dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] |= dp[i][j][l];
                }
            }
        }
    }
    ll ans = 1e18;
    rep(i, max_diff) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 160384
#include<iostream>
using namespace std;
int main(){
        int N, K;
        cin >> N >> K;
        int h[N];
        int j,i;
        j=0;
        for (i=0;i<N;i++) cin >> h[i];
        for (i=0;i<N;i++) if(h[i] >= K) j++;
        cout << j << endl;
        return 0;
}


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

using namespace std;

const int N = 1234567;

char a[N], b[N];

int main() {
  scanf("%s %s", a, b);
  int len_a = strlen(a);
  int len_b = strlen(b);
  for (int i = 0; i < min(len_a, len_b); i++) {
    printf("%c%c", a[i], b[i]);
  }
  if (len_a > len_b) printf("%c", a[len_a - 1]);
  puts("");
  return 0;
}             

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main(){
	int a, b, c, x, y;
	long long ans = 1e18;
	cin >> a >> b >> c >> x >> y;
	c <<= 1;
	for(int i = 0; i <= x; i++){
		long long cst = a * 1ll * i + c * 1ll * (x - i);
		// cerr << i << " " << cst << endl;
		int rem_b = max(0, y - (x - i));
		cst += rem_b * 1ll * min(c, b);
		// cerr << i << " " << cst << endl;
		ans = min(ans, cst);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int p[11],n,m,s,c;
int main()
{
	memset(p,-1,sizeof(p));
	cin>>n>>m;
	while(m--)
	{
		cin>>s>>c;
		if(p[s]!=c&&p[s]!=-1)
		{
			cout<<-1<<endl;
			return 0;
		}
		else p[s]=c;
	}
	if(n==1)
	{
		if(p[1]!=-1) cout<<p[1]<<endl;
		else cout<<0<<endl;
	}
	else
	{
		if(p[1]==0) cout<<-1<<endl;
		else
		{
			if(p[1]==-1) cout<<1;
			else cout<<p[1];
			for(int i=2;i<=n;i++)
			{
				if(p[i]==-1) cout<<0;
				else cout<<p[i];
			}
			cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define INF ((1ll<<60)-233)
#define sqr(x) ((x)*(x))
#define debug puts("wzpkking")
using namespace std;
int n,a[200005];
bool check(int mid){
	for (int i=0;i<n-1;i++){
		int s0=0,s1=0;
		if (a[n-i]>=mid&&a[n-i-1]>=mid) s1++;
		if (a[n-i]<mid&&a[n-i-1]<mid) s0++;
		if (a[n+i]>=mid&&a[n+i+1]>=mid) s1++;
		if (a[n+i]<mid&&a[n+i+1]<mid) s0++;
		if (s1) return 1;
		if (s0) return 0;
	}
	return a[1]>=mid;
}
int main(){
	scanf("%d",&n);
	For(i,1,2*n-1) scanf("%d",&a[i]);
	int l=2,r=2*n-1,ans=1;
	while (l<=r){
		int mid=(l+r)/2;
		if (check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d",ans);
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int a[n];
  int s = 0;
  for(int i = 0; i<n ;++i){
    cin >> a[i];
    s += a[i];
  }
  sort(a, &a[n]);
  if(a[n- m]>=((s + 4*m - 1)/(4*m))) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int64_t gcd(int64_t A, int64_t B){
  if(A%B==0LL){
    return B;
  }
  else{
    return gcd(B, A%B);
  }
}

int64_t lcm(int64_t A, int64_t B){
  return (A/gcd(A, B))*B;
}

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> T(N);
  for(int64_t i=0LL; i<N; i++){
    cin >> T.at(i);
  }
  int64_t Ans=T.at(0LL);
  for(int64_t i=0LL; i<N; i++){
    Ans=lcm(Ans, T.at(i));
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 5000000007

#n = int(input())
#b = int(input())
#n, m = [int(i) for i in input().split()]
#table = [[int(i)  for i in input().split()] for j in range(m)]
#table = [list(input()) for n in range(r)] #table[h][w]
#p = [int(i) for i in input().split()]
#s = [int(i) for i in range(n)]
#p = [int(input()) for i in range(m)]
s = input()

#list = list(s)
#dp = [MOD for _ in range(m)]
#dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
#dp = [[[0 for _ in range(11)] for _ in range(2)] for _ in range(11)]

#Combination = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

n = len(s)

temp = 0
max = 0

for i in range(n):
    if(s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T"):
        temp += 1
    else:
        temp = 0
    if (max < temp):
        max = temp


print(max)

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

int n,cnt;

int solve(){
    cnt=0;
    for (int i=1;i*i<=n;++i){
        if (i*i==n) ++cnt;
        for (int j=i;i*i+j*j<=n;++j){
            if (i*i+j*j==n) ++cnt;
            for (int k=j;i*i+j*j+k*k<=n;++k){
                if (i*i+j*j+k*k==n) ++cnt;
                for (int l=k;i*i+j*j+k*k+l*l<=n;++l){
                    if (i*i+j*j+k*k+l*l==n) ++cnt;
                }
            }
        }
    }
    return cnt;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n,n){
        cout << solve() << '\n';
    }
}


Measured memory_bytes: 3188
/*
   The area and the circumference of a circle
*/

#include <stdio.h>
#include <math.h> /* M_PI */
int main(void)
{
    double r;
    scanf("%lf", &r);
    printf("%5lf %5lf\n", r * r * M_PI, 2 * M_PI * r);
    return (0);
}




Measured memory_bytes: 2056
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,C;
    cin >> N >> C;
    vector<pair<ll,ll>> A(N);
    vector<pair<ll,ll>> calR(N);
    vector<ll> maxR(N);
    vector<pair<ll,ll>> calL(N);
    vector<ll> maxL(N);
    for (int i = 0; i < N; ++i) {
        ll tmpX,tmpV;
        cin >> tmpX >> tmpV;
        A[i] = make_pair(tmpX,tmpV);
    }
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += A[i].second;
        calR[i] = make_pair(sum - A[i].first,A[i].first);
        if(i == 0){
            maxR[i] = calR[i].first;
        }else{
            maxR[i] = max(maxR[i - 1],calR[i].first);
        }
    }

    sum = 0;
    for(int i = 0; i < N; i++){
        sum += A[N - i -1].second;
        calL[i] = make_pair(sum - (C - A[N - i - 1].first),(C - A[N - i - 1].first));
        if(i == 0){
            maxL[i] = calL[i].first;
        }else{
            maxL[i] = max(maxL[i - 1],calL[i].first);
        }
    }


    for (int i = 0; i < N; ++i) {
        //cout << calR[i].first << "," << calR[i].second << "---" << calL[i].first << "," << calL[i].second << endl;
        //cout << maxR[i]<< "---" << maxL[i] << endl;
    }

    ll result = 0;
    for (int li = 0; li < N; ++li) {
        result = max(result,calL[li].first);
        if(li == N - 1){
            continue;
        }
        result = max(result,calL[li].first - calL[li].second + maxR[N - li - 2]);
    }
    for (int ri = 0; ri < N; ++ri) {
        result = max(result,calR[ri].first);
        if(ri == N - 1){
            continue;
        }
        result = max(result,calR[ri].first - calR[ri].second + maxL[N - ri - 2]);
    }
    cout << result << endl;
}


Measured memory_bytes: 6528
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		int x;
		cin >> x;
		if(cin.fail()) break;

		int kyu=10-x/200;

		cout << kyu << "\n";
	}
	return 0;
}


Measured memory_bytes: 3648
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
    class Program
    {
        //メイン関数
        static void Main(string[] args)
        {
            int a = ReadI();
            string s = Read();

            if (a < 3200)
            {
                Write("red");
            }
            else Write(s);
        }

        //メインじゃない関数
        private static string Read() { return ReadLine(); }
        private static int ReadI() { return int.Parse(ReadLine()); }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef pair<int, int> PII;
typedef pair<int, bool> PIB;
typedef vector<int> VI;
typedef VI::iterator VII;
const int INF = 2e9;

int w, h, n, ans;
int mask_x1[1010], mask_y1[1010], mask_x2[1010], mask_y2[1010];
bool board[2010][2010];

VI mask_sorted_x, mask_sorted_y;

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

void bfs(PII start)
{
  queue<PII> Q;
  Q.push(start);
  board[start.first][start.second] = true;

  while(!Q.empty()){
    PII now = Q.front();
    Q.pop();
    for(int i = 0; i < 4; i++){
      PII next = make_pair(now.first + dx[i], now.second + dy[i]);
      if(0 <= next.first && next.first < mask_sorted_x.size() - 1 && 0 <= next.second && next.second < mask_sorted_y.size() - 1 && !board[next.first][next.second]){
	board[next.first][next.second] = true;
	Q.push(next);
      }
    }
  }
  return;
}

int main()
{
  while(true){
    scanf("%d%d", &w, &h);
    if(!w && !h)
      break;

    ans = 0;
    mask_sorted_x.clear();
    mask_sorted_y.clear();
    memset(board, false, sizeof board);

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
      scanf("%d%d%d%d", &mask_x1[i], &mask_y1[i], &mask_x2[i], &mask_y2[i]);
    
    for(int i = 0; i < n; i++){
      mask_sorted_x.PB(mask_x1[i]);
      mask_sorted_x.PB(mask_x2[i]);
      mask_sorted_y.PB(mask_y1[i]);
      mask_sorted_y.PB(mask_y2[i]);
    }
    
    mask_sorted_x.PB(0);
    mask_sorted_x.PB(w);
    mask_sorted_y.PB(0);
    mask_sorted_y.PB(h);
    
    sort(mask_sorted_x.begin(), mask_sorted_x.end());
    sort(mask_sorted_y.begin(), mask_sorted_y.end());
    
    mask_sorted_x.erase(unique(mask_sorted_x.begin(), mask_sorted_x.end()), mask_sorted_x.end());
    mask_sorted_y.erase(unique(mask_sorted_y.begin(), mask_sorted_y.end()), mask_sorted_y.end());

    for(int i = 0; i < n; i++){
      mask_x1[i] = lower_bound(mask_sorted_x.begin(), mask_sorted_x.end(), mask_x1[i]) - mask_sorted_x.begin();
      mask_x2[i] = lower_bound(mask_sorted_x.begin(), mask_sorted_x.end(), mask_x2[i]) - mask_sorted_x.begin();
      mask_y1[i] = lower_bound(mask_sorted_y.begin(), mask_sorted_y.end(), mask_y1[i]) - mask_sorted_y.begin();
      mask_y2[i] = lower_bound(mask_sorted_y.begin(), mask_sorted_y.end(), mask_y2[i]) - mask_sorted_y.begin();
    }

    for(int i = 0; i < n; i++)
      for(int j = mask_x1[i]; j < mask_x2[i]; j++)
	for(int k = mask_y1[i]; k < mask_y2[i]; k++)
	  board[j][k] = true;

    for(int i = 0; i < mask_sorted_x.size() - 1; i++)
      for(int j = 0; j < mask_sorted_y.size() - 1; j++)
	if(!board[i][j]){
	  bfs(MP(i, j));
	  ans++;
	}

    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 5184
MOD = 10**9 + 7
n = int(input())
s = input()
ans = 1
left = 0
for i in s:
    if i == "B":
        if left%2 == 1:
            ans *= left
            left -= 1
        else:
            left += 1
    else:
        if left%2 == 0:
            ans *= left
            left -= 1
        else:
            left += 1
    if left < 0:
        print(0)
        exit()
    ans %= MOD

if left > 0:
    print(0)
    exit()

for i in range(1,n+1):
    ans *= i
    ans %= MOD

print(ans)

Measured memory_bytes: 41708
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define pii(p)			pair<int,int> p
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

void solve() {
	int h, n, sum = 0;
	vi(a);
	cin >> h >> n;
	a.resize(n);
	FOR(n) {
		cin >> a[i];
		sum += a[i];
	}
	if (h <= sum)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int gcd(int a,int b){
	return a%b==0?b:gcd(b,a%b);
}
int a[100000];
int main(void)
{
	int n,k,t,i;
	scanf("%d%d",&n,&k);
	FOR(i,0,n) scanf("%d",&a[i]);
	t=a[0];
	FOR(i,1,n) t=gcd(t,a[i]);
	FOR(i,0,n){
		if(a[i]>=k&&(a[i]-k)%t==0){
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}
    
    


Measured memory_bytes: 512