akhauriyash/Code-Regression huggingface dataset:
N, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(1, N):
  total = A[i-1] + A[i]
  if total <= x: continue
  if A[i-1] > x:
    A[i-1] = x
    A[i] = 0
  else:
    A[i] -= total - x
  ans += total - x
    
print(ans)

Measured memory_bytes: 14540
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
    }
    let mut ans = 0;

    for i in 1..n +1 {
        let mut ii = i;
        let mut cnt = 0;
        while ii > 0 {
            cnt += 1;
            ii /= 10;
        }
        if cnt & 1 == 1 {
            ans += 1;
        }
    }

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


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

int main()
{
	int N; cin >> N;
	while(N--)
	{
		double x1,x2,x3,x4,y1,y2,y3,y4;
		cin >> x1 >> y1 >> x2 >> y2;
		cin >> x3 >> y3 >> x4 >> y4;

		x2 -= x1; y2 -= y1;
		x4 -= x3; y4 -= y3;


		cout << ( fabs(x2*y4-x4*y2)<1e-10 ? "YES" : "NO") << endl;

	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){

  int q;
  map <string,int> a;

  cin>>q;

  for(int i=0;i<q;i++){

    int n;
    string s;
    cin>>n>>s;

    if(n) cout<<a[s]<<endl;
    else{
      int x;
      cin>>x;
      a[s]=x;
    }

  }

  return 0;

}



Measured memory_bytes: 27812
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int N;
	vector <int> A;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int temp;
		cin >> temp;
		A.push_back(temp);
	}
	sort(A.begin(), A.end());

	vector <int> B;
	B.push_back(A[0]);
	A.erase(A.begin());
	int cnt = 1;
	while (true) {
		if (cnt == N)break;
		B.insert(B.begin(), A.back());
		A.pop_back();
		cnt++;
		if (cnt == N)break;

		B.push_back(A.back());
		A.pop_back();
		cnt++;
		if (cnt == N)break;

		B.insert(B.begin(), A.front());
		A.erase(A.begin());
		cnt++;
		if (cnt == N)break;

		B.push_back(A.front());
		A.erase(A.begin());
		cnt++;
		if (cnt == N)break;
	}
	
	long long out1 = 0;
	long long out2 = 0;
	long long out3 = 0;
	for (int i = 0; i < N - 1; i++) {
		out1 = out1 + abs(B[i] - B[i + 1]);
	}
	out2 = out1 - abs(B[0] - B[1]) + abs(B[0] - B[N - 1]);
	out3 = out1 - abs(B[N-2] - B[N-1]) + abs(B[0] - B[N - 1]);
	cout << max(out3,max(out1,out2));
	return 0;
}

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

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

int main(void){
  while(true){
    int w, h;
    cin >> w >> h;
    if(w == 0 && h == 0){ break; }

    vector<vector<vector<bool> > > canGo(h + 2, vector<vector<bool> >(w + 2, vector<bool>(4, true)));
    for(int i = 0; i < h + 2; i++)
      for(int j = 0; j < w + 2; j++)
        for(int k = 0; k < 4; k++)
          if(i + dx[k] <= 0 || i + dx[k] > h || j + dy[k] <= 0 || j + dy[k] > w)
            canGo[i][j][k] = false;

    int input;
    for(int i = 0; i < 2 * h - 1; i++){
      if(i % 2 == 0){
        for(int j = 1; j <= w - 1; j++){
          cin >> input;
          if(input == 1){
            canGo[i / 2 + 1][j][3] = false;
            canGo[i / 2 + 1][j + 1][1] = false; 
          }
        } 
      }
      else{
        for(int j = 1; j <= w; j++){
          cin >> input;
          if(input == 1){
            canGo[i / 2 + 1][j][2] = false;
            canGo[i / 2 + 2][j][0] = false; 
          }
        }
      }
    }

    queue<pair<int, pair<int, int> > > wait;
    wait.push(make_pair(0, make_pair(1, 1)));
    for(int i = 0; i < 4; i++)
      canGo[1 + dx[i]][1 + dy[i]][(i + 2) % 4] = false;

    int ans = -1;
    while(!wait.empty()){
      int cost = wait.front().first;
      int x = wait.front().second.first;
      int y = wait.front().second.second;
      wait.pop();
      if(x == h && y == w){
        ans = cost;
        break;
      }

      for(int i = 0; i < 4; i++){
        if(canGo[x][y][i]){
          int nextX = x + dx[i];
          int nextY = y + dy[i];
          wait.push(make_pair(cost + 1, make_pair(nextX, nextY)));
          for(int j = 0; j < 4; j++)
            canGo[nextX + dx[j]][nextY + dy[j]][(j + 2) % 4] = false;
        }
      }
    }

    cout << ans + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if (h == 0 && w == 0)
				break;
			for (int i = 1; i <= h; i++) {
				for (int j = 1; j <= w; j++) {
					if (i == 1 || i == h) {
						System.out.print("#");
					} else {
						if (j == 1 || j == w) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}

					}
				}
				System.out.printf("\n");
			}
			System.out.printf("\n");
		}
	}

}



Measured memory_bytes: 37264
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]

ans = 0

for i in range(N) :
    calc = C
    for j in range(M) :
        a,b = A[i][j],B[j]
        calc += a*b
    if calc > 0 :
        ans += 1
print(ans)


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

void trace(int A[], int n)
{
    for (int i = 0; i < n; i++)
    {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}


int main()
{
    int maxN = 1000;
    int A[maxN];

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

    //bubble sort
    int swp = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = N-1; j >= i+1; j--)
        {
            if (A[j] < A[j-1])
            {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                swp++;
            }
        }
    }
    
    trace(A,N);
    cout << swp << endl;
  
    return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
const int N = 100050;
using namespace std;
int gi(){
  char ch=getchar(); int x=0,q=0;
  while(ch<'0' || ch>'9') (ch=='-'?q=1:0),ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
char s[N];
int a[N],b[N];
int main(){
  int n;
  scanf("%s",s+1);
  n=strlen(s+1);
  for (int i=1; i<=n; ++i)
    a[i]=a[i-1]+(s[i]=='A'?1:2);
  scanf("%s",s+1);
  n=strlen(s+1);
  for (int i=1; i<=n; ++i)
    b[i]=b[i-1]+(s[i]=='A'?1:2);
  int q=gi(),l1,r1,l2,r2;
  for (int i=1; i<=q; ++i){
    l1=gi(),r1=gi(),l2=gi(),r2=gi();
    if ((a[r1]-a[l1-1])%3==(b[r2]-b[l2-1])%3)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}


Measured memory_bytes: 1408
import sys


def main():
    input = sys.stdin.buffer.readline
    N, M = map(int, input().split())
    skip = (N // 2) // 2 + 1 if N % 2 == 0 else None
    count = 0
    left, right = 0, N + 1
    while count < M:
        left += 1
        if left == skip:
            continue
        right -= 1
        print(left, right)
        count += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 69308
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    int N,M,n;
    ll ans=0;
    cin>>N>>M;
    cout<<(1900*M+100*(N-M))*pow(2,M)<<endl;
}


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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};
using namespace std;

void solve(){
//   map<long ,long >mp;
  string s1,s2;
  cin>>s1>>s2;
  int a,b;
  cin>>a>>b;
  string res;
  cin>>res;
  if(res==s1){
     cout<<(a-1)<<" "<<b;
     
     
     }
 else if(res==s2){
    cout<<(a)<<" "<<(b-1);
 }
      
}
int main(){
//   #ifndef ONLINE_JUDGE
//      freopen("in.txt", "r", stdin);
//      freopen("out.txt", "w", stdout);
//   #endif  
    std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,a,b;cin>>n>>a>>b;
    if(a*b<n||a+b>n+1){
        cout<<-1<<endl;
        return 0;
    }
    vector<ll>ans(0);
    ll re=n-b;
    ll now=n;
    rep(i,b){
        ll mi=min(a-1,re);
        rep(j,mi+1){
            ans.pb(now-mi+j);
        }
        re-=mi;
        now-=mi+1;
    }
    rep(i,n){
        cout<<ans[i]<<' ';
    }
    cout<<endl;
}

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

struct KnuthMorrisPratt {
    string ptn;
    vector<int> fail;   // longest prefix suffix matching of [0, i)
    KnuthMorrisPratt(const string &ptn) : ptn(ptn) {
        int m = ptn.size();
        fail.assign(m + 1, -1);
        for (int i = 0, j = -1; i < m; i++) {
            while (j >= 0 && ptn[i] != ptn[j]) j = fail[j];
            fail[i + 1] = ++j;
        }
    }
    // the period of ptn[0:i]
    int period(int i) { return i - fail[i]; }
    // the index i such that S[i:] has the exact prefix p
    vector<int> match(const string &s) {
        int m = ptn.size(), n = s.size();
        vector<int> res;
        for (int i = 0, k = 0; i < n; i++) {
            while (k >= 0 && s[i] != ptn[k]) k = fail[k];
            if (++k == m) res.emplace_back(i - m + 1);
        }
        return res;
    }
};

int main() {
    string T, P;
    cin >> T >> P;
    for (int i: KnuthMorrisPratt(P).match(T)) cout << i << endl;
    return 0;
}


Measured memory_bytes: 8404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>



int main() {
	int n;

	std::cin >> n;

	std::vector<int> v(n);

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	int count = 0;
	for (size_t i = 1; i < n - 1; i++)
	{
		if ((v[i - 1] < v[i] && v[i] < v[i + 1]) || (v[i + 1] < v[i] && v[i] < v[i - 1])) {
			count++;
		}
	}
	
	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    ll S; cin >> S;

    ll ub = 1e9 + 10, lb = 0;
    while(ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        if(mid * mid >= S) ub = mid;
        else lb = mid;
    }

    ll x1 = ub, y2 = ub;
    ll rem = x1 * y2 - S;
    ll x2 = rem, y1 = 1;
    ll x3 = 0, y3 = 0;
    printf("%lld %lld %lld %lld %lld %lld\n", x1, y1, x2, y2, x3, y3);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  int res = 0;
  int ans = 1;
  for (int i = 1; i <= N; ++i) {
    int cnt{}, k{i};
    while (k && k % 2 == 0) {
      k /= 2;
      ++cnt;
    }
    if (chmax(res, cnt)) {
      ans = i;
    }
  }
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++)
    {
        if((i * 2 + (x - i) * 4 == y) || (i * 4 + (x - i) * 2 == y))
            {
                cout << "Yes";
                return 0;
            }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 3584
object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    def adjustRow(row: Seq[Int]): Seq[Int] = row.scanLeft(0){ (a, carry) => (a + carry) % 2 }.drop(1).dropRight(1)

    val Array(h, w) = readLineInts
    val a = Array.fill(h)(readLineInts)
    val moveResults: Seq[(Seq[Int], Int)] = a.map { row =>
      val moves = adjustRow(row)
      (moves, row.last + moves.lastOption.getOrElse(0))
    }
    val rowMoves = moveResults.map(_._1)
    val column = moveResults.map(_._2)
    val columnMoves = adjustRow(column)

    val rowWiseMoves = {
      for((rowMove, rowIndex) <- rowMoves.zipWithIndex;
          (moveFlag, columnIndex) <- rowMove.zipWithIndex;
          move <- Some((rowIndex + 1, columnIndex + 1, rowIndex + 1, columnIndex + 2)) if moveFlag == 1) yield move
    }
    val columnWiseMoves = {
      for ((moveFlag, rowIndex) <- columnMoves.zipWithIndex;
            move <- Some((rowIndex + 1, w, rowIndex + 2, w)) if moveFlag == 1) yield move
    }
    val moves = rowWiseMoves ++ columnWiseMoves

    println(moves.length)
    for ((a, b, c, d) <- moves) println(s"$a $b $c $d")
  }
}


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

int main(void) {
  int N, n, a, b, c;
  cin >> N;

  n = N;
  c = n % 10;
  n /= 10;
  b = n % 10;
  n /= 10;
  a = n % 10;

  if (a == b && a == c) {
    cout << N << endl;
  } else if (a >= b && a >= c) {
    cout << 100 * a + 10 * a + a << endl;
  } else {
    cout << 100 * (a + 1) + 10 * (a + 1) + a + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;

int main(){
  int n;
  int count=0;
  cout << fixed << setprecision(1);
  while(1){
    cin >> n;
    if(n==0)return 0;
    int x[n],y[n];
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i];
    }
    double ans=0;
    int l;
    for(int i=0;i<n;i++){
      l=(i+1)%n;
      ans+=(x[i]*y[l]-x[l]*y[i])/2.0;
    }
    ans=fabs(ans);
    count++;
   
    cout << count << " " << ans << endl;
  }
    
}

Measured memory_bytes: 3176
using System;

    public class Program
    {
        public static void Main(string[] args)
        {
            string[] input=Console.ReadLine().Split(' ');
            int n=int.Parse(input[0]);
            int m=int.Parse(input[1]);
            int mm=0,nn=0;
            for (int i=0;i<n;i++)
            {
                string[] input2=Console.ReadLine().Split(' ');
                for (int j=0;j<m;j++)
                {
                    if (input2[j]=="snuke")
                    {
                        mm=i;
                        nn=j;
                    }
                }
            }
            Console.Write((char)('A'+nn));
            Console.WriteLine(mm+1);
        }
    }


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

const int N = 3e5 + 5, djq = 1e9 + 7;

int n, f[N][3][3], ans;
char s[N];

inline void add(int &a, const int &b) {if ((a += b) >= djq) a -= djq;}

int main()
{
	scanf("%s", s + 1); n = strlen(s + 1);
	f[0][0][0] = 1;
	for (int i = 0; i < n; i++)
		for (int a = 0; a < 3; a++) for (int b = 0; b < 3; b++)
		{
			if (s[i + 1] != '1') add(f[i + 1][a][b == 2 ? 1 : b + 1], f[i][a][b]);
			if (s[i + 1] != '0')
			{
				if (b) add(f[i + 1][a][b - 1], f[i][a][b]);
				else add(f[i + 1][a == 2 ? 2 : a + 1][b], f[i][a][b]);
			}
		}
	for (int a = 0; a < 3; a++) for (int b = 0; b <= a; b++)
		add(ans, f[n][a][b]);
	return std::cout << ans << std::endl, 0;
}

Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int num = stdIn.nextInt();
        if (num % 10 == num / 100)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 21716
import time
def gcd1(x,y):
    d = x % y
    while d != 0:
        x,y = y,d
        d = x % y
    return y

def gcd(x,y):
    if x == 1 or y == 1:
        return 1
    if x < y:
        x,y = y,x
    return gcd1(x,y)

def gcd3(a,b,c):
    d = gcd(a,b)
    return gcd(d,c)

K = int(input())
t1 = time.time()
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd3(a,b,c)
t2 = time.time()
print(ans)
#

Measured memory_bytes: 70804
#include <iostream>

using namespace std;

int
main()
{
  int n;
  cin >> n;
 
  long int *a;
  a = (long int*)malloc( n * sizeof( long int ));
  if ( NULL == a ) return -1;
  for ( int i = 0 ; i < n ; ++i ) {
    cin >> a[i];
    if ( a[i] == 0 ) { cout << 0 << endl; return 0; }
  }
  
  long int ans[2] = { 0, 1 };
  for ( int i = 0 ; i < n ; ++i ) {
    long int a_lower = a[i] & 0xFFFFFFFF;
    long int a_upper = ( a[i] >> 32 ) & 0xFFFFFFFF;
    
    long int ll = ans[1] * a_lower;
    long int lu = ans[1] * a_upper;
    long int ul = ans[0] * a_lower;
    long int uu = ans[0] * a_upper;

    if ( 1 <= uu ) { cout << -1 << endl; return 0; }
    long int ans_lower = ll & 0xFFFFFFFF;
    long int ans_upper = lu + ul + (( ll >> 32 ) & 0xFFFFFFFF );
    if ( 0xFFFFFFFF < ans_upper ) { cout << -1 << endl; return 0; }
    long int _ans = ( ans_upper << 32 ) + ans_lower;
    if ( 1000000000000000000 < _ans ) { cout << -1 << endl; return 0; }
    
    ans[1] = ans_lower;
    ans[0] = ans_upper;
  }
  
  long int _ans = ( ans[0] << 32 ) + ans[1];
  cout << _ans << endl;
}

Measured memory_bytes: 4420
#include<stdio.h>
int main(void){
	long int N=0,b,r,ans,x,y;
	if(scanf("%ld %ld %ld",&N,&b,&r)==3){
		x=N/(b+r);
		y=N%(b+r);
		if(y>=b){
			ans=x*b+b;
		}else if(y<b){
			ans=x*b+y;
		}
		printf("%ld",ans);
	}else{
		printf("error");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<cstring>
#include<string>
#include<map>
#include<cmath>
#include<vector>
using namespace std;

const int INF = 0x3f3f3f3f;
const int maxn = 300000+10;
int n,m,a[20],b[20],st,ed;
int d[maxn];
int c[20],cnt,ans;

void dfs(int x,int now){
    if(x==n){
        cnt=0;
        memset(c,0,sizeof(c));
        for(int i=n-1;i>=0;i--){
            int x=((now&(1<<i))>>i),y=((now&(1<<(i+1)))>>(i+1));
            if(i==n-1||x==y) c[cnt]++;
            else  cnt++,c[cnt]=1;
        }
        if(cnt==m-1){
            bool flag=true;
            for(int i=0;i<=cnt;i++)
                if(c[i]!=b[i]) flag=false;
            if(flag) ans=min(ans,d[now|(1<<n)]);
        }
        return;
    }
    dfs(x+1,now);
    dfs(x+1,now|(1<<x));
}

void spfa(){
    queue<int> q;
    bool inq[maxn];
    for(int i=0;i<=ed;i++) d[i]=INF,inq[i]=0;
    d[st]=0,q.push(st);
    while(!q.empty()){
        int u=q.front(); q.pop(); inq[u]=0;
        for(int i=0;i<n-1;i++){
            int a=(((1<<i)&u)>>i),b=(((1<<(i+1))&u)>>(i+1));
            if(a!=b){
                int v=u^(1<<i)^(1<<(i+1));
                if(d[v]>d[u]+1){
                    d[v]=d[u]+1;
                    if(!inq[v]){
                        q.push(v);
                        inq[v]=1;
                    }
                }
            }
        }
    }
}

int main(){
    //freopen("a.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) scanf("%d",&a[n-1-i]);
    for(int i=0;i<m;i++) scanf("%d",&b[i]);
    a[n]=1;
    st=ed=0;
    //printf("%d\n",(1<<17));
    for(int i=0;i<=n;i++){
        if(a[i]) st|=(1<<i);
        ed|=(1<<i);
    }
    spfa();
    ans=INF;
    dfs(0,0);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1544
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int H,W;
  cin >> H >> W;
vector<string> a(H);
rep(i,H){
cin >> a.at(i);
}


  rep(i,W+2){
    cout << "#";
  }
  cout << endl;
  rep(i,H){
    cout << "#" << a.at(i) << "#" << endl;
  }
  rep(i,W+2){
    cout << "#";
  }

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    /*
    int a, b , c, d;
    cin >> a >> b >> c >> d ;
    //*/

    //*
    vector<int> vec(5);
    //cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    for(int i = 0; i < 5; i++){
        cin >> vec.at(i);
    }
    int l;
    cin >> l ;
    
    int cnt = 0;
    for(int i = 0; i < 5; i++){
        for(int j = 0; j < 5; j++){
            if(abs(vec.at(i) - vec.at(j)) > l){
                cnt++;
            }
        }
    }
    
    //sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( cnt == 0 ){
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    //*/
    
    //cout << a << endl;

    return 0; 
}


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

#define pb push_back
#define ss second
#define ff first
#define N 100005
#define ll long long
#define mid(a,b) (a+b)/2
#define pii pair<ll,ll>

using namespace std;

ll mod = 1e9+7;
ll n,k;
ll fc[N],inv[N],a[N],sum;

ll big(ll a,ll b){
	if(b == 0) return 1;
	ll x = big(a,b / 2);
	if(b % 2) return (((x * x) % mod) * a) % mod;
	return (x * x) % mod;
}

ll norm(ll x){
	if(x < 0) x += mod;
	else if(x >= mod) x -= mod;
	
	return x;
}

ll C(ll n,ll k){
	return (((fc[n] * inv[n - k]) % mod) * inv[k]) % mod;
}

int main()
{
	scanf("%lld%lld",&n,&k);
	fc[0] = 1;
	for(int i = 1;i <= n;i++)
		fc[i] = (fc[i - 1] * i) % mod;
	inv[n] = big(fc[n],mod - 2);
	for(int i = n - 1;i >= 0;i--)
		inv[i] = (inv[i + 1] * (i + 1)) % mod;
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	sort(a + 1,a + n + 1);
	
	for(int i = n;i >= k;i--){
		sum += ((a[i] * C(i - 1,k - 1)) % mod);
		sum %= mod;
	}
	for(int i = 1;i <= n - k + 1;i++){
		sum -= ((a[i] * C(n - i,k - 1)) % mod);
		sum = norm(sum);
	}
	printf("%lld",sum);
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;
    vector<int> X;
    X.resize(M);
    for (int i = 0; i < M; i++)
    {
        cin >> X[i];
    }

    if (N >= M)
    {
        cout << 0 << endl;
        return 0;
    }
    

    sort(X.begin(), X.end());

    vector<int> d;
    d.resize(M - 1);
    for (int i = 0; i < M - 1; i++)
    {
        d[i] = X[i + 1] - X[i];
    }
    
    sort(d.begin(), d.end());

    int sum = accumulate(d.begin(), d.end() - (N - 1), 0);

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  int N,ans=0;
  string S;
  cin >> N >> S;
  for(int i=0;i<1000;++i){
    string s = to_string(i);
    while(s.size()<3){
      s.insert(0,"0");
    }
    int j=0,tmp=0;
    while(j<N){
      if(S[j] == s[tmp]){
        tmp++;
      }
      j++;
    }
    if(tmp==3) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // maxA + 1 )

Measured memory_bytes: 7804
#include <stdio.h>
#define N 10

int main(void){
	double a, sum; int i;
	
	while(~scanf("%lf",&a)){
		sum=0, i=1;
		
		while(i<=N){
			sum+=a;
			
			if(i%2==0) a/=3;
			else a*=2;
			i++;
		}
		
		printf("%lf\n",sum);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i, j;
	long long int a[2003], b[2003], c[2003];
	for (i = 0; i < m; i++)
	{
		scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
		a[i]--;
		b[i]--;
	}
	long long int d[1003];
	for (i = 0; i < n; i++)
		d[i] = -10000000000000000;
	d[0] = 0;
	for (j = 0; j < n; j++)
		for (i = 0; i < m; i++)
			if (d[b[i]] < d[a[i]] + c[i])
				d[b[i]] = d[a[i]] + c[i];
	long long int ans = d[n - 1];
	for (i = 0; i < m; i++)
		if (d[b[i]] < d[a[i]] + c[i])
			d[b[i]] = d[a[i]] + c[i];
	if (ans < d[n - 1])
		printf("inf\n");
	else
		printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    H = tuple(map(int, input().split()))
    AB = [tuple(map(int, input().split())) for _ in [0] * M]

    good = [1] * N
    for a, b in AB:
        if H[a-1] < H[b-1]:
            good[a-1] = 0
        elif H[b-1] < H[a-1]:
            good[b-1] = 0
        else:
            good[a-1], good[b-1] = 0, 0
    print(good.count(1))


main()


Measured memory_bytes: 27332
package main

import (
	"fmt"
)

func main() {
	x := 0
	var S string
	fmt.Scanf("%s", &S)
	for i := 0; i < 4; i++ {
		if []rune(S)[i] == '+' {
			x++
		} else {
			x--
		}
	}
	fmt.Printf("%d\n", x)
	return
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

if N == 1:
  print(1)
  exit()

import math
def prime(x):
  p = {}
  cnt = 2
  Flag = True
  while Flag:
    last = math.ceil(x ** 0.5) 
    if cnt > last:
      break
    for i in range(cnt, last + 1):
      if x % i == 0:
        x //= i
        p[i] = 1
        cnt = i + 2
        while x % i == 0:
          x //= i
          p[i] += 1
        cnt = i + 1
        break
      if i == last:
        Flag = False
  if x != 1:
    p[x] = 1
  return p

def listgcd(L):
  p = prime(L[0])
  for i in range(1, len(L)):
    q = prime(L[i])
    for n in q:
      if n in p:
        p[n] = max(p[n], q[n])
      else:
        p[n] = q[n]
  return p

def listgcdmod(L, MOD):
  p = listgcd(L)
  t = 1
  for n in p:
    t = t * pow(n, p[n]) % MOD
  return t

class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invL(s, a, n):
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L

t = listgcdmod(A, MOD)
inv = Inv(MOD)
ans = 0
for i in range(N):
  ans = (ans + t * inv.invx(A[i])) % MOD
print(ans)


Measured memory_bytes: 51932
#include <bits/stdc++.h>
#define maxn 4086 
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;

inline ll read(){
	ll x = 0, f = 1;char ch = getchar();
	while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
	return x * f;
}
int t, n;
ll ans;
int main(){
	int i, j, x, mx;
	n = read();
	ans = 1;
	if(n <= 1){puts("0");return 0;}
	for(i = 1;i <= n;i++) ans = ans * 10 % mod;
	ll now = 1;
	for(i = 1;i <= n;i++) now = now * 9 % mod;
	ans = (ans - now + mod) % mod;
	ans = (ans - now + mod) % mod;
	now = 1;
	for(i = 1;i <= n;i++) now = now * 8 % mod;
	ans = (ans + now + mod) % mod;
	cout<<ans;
}

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

using namespace std;

int const S = 444444;
int const N = 123456;
int const C = 333;

vector<int> s[N];
int len[N], id[N], wh[N], ls[N], lcp[N];
int flcp[S / C + 1][S / C + 1];
int p[42], where[42];
int fr;
int link[26][S];
vector<int> all[S];
int insub[S], term[S];


int newnode() {
  for (int i = 0; i < 26; i++) link[i][fr] = -1;
  return fr++;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int c = getchar();
    while (c <= 32) c = getchar();
    while (c > 32) {
      s[i].push_back(c - 'a');
      c = getchar();
    }
    len[i] = (int) s[i].size();
  }
  for (int i = 0; i < n; i++) id[i] = i;
  std::sort(id, id + n, [](int i, int j) {
    return s[i] < s[j];
  });
  int cn = 0;
  for (int it = 0; it < n; it++) {
    int i = id[it];
    if (len[i] > C) {
      wh[i] = cn;
      ls[cn++] = i;
    }
  }
  for (int i = 0; i + 1 < cn; i++) {
    int j = 0;
    while (j < len[ls[i]] && j < len[ls[i + 1]] && s[ls[i]][j] == s[ls[i + 1]][j]) ++j;
    lcp[i] = j;
  }
  for (int i = 0; i < cn; i++) {
    int mn = 1 << 30;
    for (int j = i + 1; j < cn; j++) {
      mn = std::min(mn, lcp[j - 1]);
      flcp[i][j] = flcp[j][i] = mn;
    }
  }
  fr = 0;
  newnode();
  for (int i = 0; i < n; i++) {
    int v = 0;
    for (int j = 0; j < len[i]; j++) {
      int letter = s[i][j];
      if (link[letter][v] < 0) {
        link[letter][v] = newnode();
      }
      v = link[letter][v];
      if (len[i] > C) {
        all[v].push_back(i);
      }
      insub[v]++;
    }
    term[v] = i + 1;
  }
  int q;
  scanf("%d", &q);
  for (int cq = 0; cq < q; cq++) {
    int k;
    scanf("%d", &k);
    int c = getchar();
    while (c <= 32) c = getchar();
    for (int j = 0; j < 26; j++) {
      p[j] = c - 'a';
      where[c - 'a'] = j;
      c = getchar();
    }
    k--;
    int v = 0;
    int depth = 0;
    int ans = 0;
    while (depth <= C && depth < len[k]) {
      if (term[v] > 0) {
        ++ans;
      }
      for (int i = 0; i < 26; i++) {
        if (p[i] == s[k][depth]) {
          break;
        }
        int to = link[p[i]][v];
        if (to < 0) continue;
        ans += insub[to];
      }
      v = link[s[k][depth]][v];
      depth++;
    }
    if (len[k] > C) {
      auto comp = [](int i, int j) {
        if (i == j) return false;
        int lc = flcp[wh[i]][wh[j]];
        return lc == len[i] || (lc != len[j] && where[s[i][lc]] < where[s[j][lc]]);
      };
      for (int i : all[v]) {
        // printf("%d, ", i);
        if (comp(i, k)) {
          ++ans;
        }
      }
      puts("");
    }
    printf("%d\n", ans + 1);
  }
}

Measured memory_bytes: 77440
// inputに入力データ全体が入る
function Main(input) {

  var inp = input.split('\n');
  var N = parseInt(inp[0]);
  var tmp = '';
  var i = [];
  var x = [];
  var y = [];
  i.push(0);
  x.push(0);
  y.push(0);
  for (idx = 1; idx <= N; idx++) {
    tmp = inp[idx].split(' ');
    i.push(parseInt(tmp[0]));
    x.push(parseInt(tmp[1]));
    y.push(parseInt(tmp[2]));
  }

  for (var j = 1; j <= N; j++) {
    // 到達可能な距離のチェック
    if (Math.abs(x[j] - x[0]) + Math.abs(y[j] - y[0]) > i[j]){
      console.log('%s', 'No');
      return;
  };

    // 到達可能な距離だがありえない値のチェック
    if (i[j] % 2 === 0) {
      if ((x[j] + y[j]) % 2 === 1) {
        console.log('%s', 'No');
        return;
      }
    } else {
      if ((x[j] + y[j]) % 2 === 0) {
        console.log('%s', 'No');
        return;
      }
    }
  }

  console.log('%s', 'Yes');

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29940
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a;
  a={0,1,2,1,3,1,3,1,1,3,1,3,1};
  int x,y;
  cin >> x >> y;
  if(a.at(x)==a.at(y)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define fi first 
#define se second 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);
#define mem(a,v) memset(a,v,sizeof(a))
const ll INF=1e18;
const int mod=1e9+7;
const int iinf=1e9+10;
const int xd[4]={1,0,-1,0},yd[4]={0,1,0,-1};
const int mxN=1e2;
bool v[mxN+1]{};
int main()
{
    faster
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=n/i;
        if(n%i==0)
            ans--;
    }
    cout<<ans;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
int main()
{
	int a;
	std::cin >> a;
	std::vector<int> v;
	for (auto i = 0;i < a;++i)
	{
		int b;
		std::cin >> b;
		v.push_back(b);
	}
	while (--a)
	{
		std::cout << v[a]<<" ";
	}
	std::cout << v[a] <<std::endl;
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <stdio.h>

int main() {
    int x,a;
    std::cin >> x;
    std::cin >> a;
    
    if (x<a){
        std::cout << 0 << std::endl;
    }else{
        std::cout << 10 << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  vector<int> x(n); REP(i,n) cin >> x[i];

  vector<int> sorted = x;
  sort(sorted.begin(), sorted.end(), greater<int>());

  int b = n/2-1;
  REP(i,n) {
    if (x[i] >= sorted[b]) COUT(sorted[b+1]);
    else COUT(sorted[b]);
  }
  return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include <math.h>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
	ll n;
	cin >> n;
	ll ans = 2 * n;
	rep2(i, 1,  sqrt(n)+100) {
		if (n%i == 0) ans = min(ans, i + n / i);
	}
	cout << ans - 2 << endl;
}

Measured memory_bytes: 384
#include<iostream>

#define INFINITY 1000000001

using namespace std;


int merge(int*, int left, int mid, int right);
int mergeSort(int*, int left, int right);

int main() {
	int n;
	cin >> n;
	int* a = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int count = mergeSort(a, 0, n);
	for (int i = 0;i < n-1;i++) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;
	cout << count << endl;
}

int merge(int* a, int left, int mid, int right) {
	int count = 0;
	int* l, * r;
	l = new int[mid - left+1];
	r = new int[right - mid+1];
	for (int i = 0;i < mid - left;i++) {
		l[i] = a[i + left];
	}
	for (int i = 0;i < right - mid;i++) {
		r[i] = a[mid + i];
	}
	l[mid - left] = r[right - mid] = INFINITY;
	int j = 0,k = 0;
	for (int i = 0;i < right - left;i++) {
		if (l[j] <= r[k]) {
			a[left + i] = l[j];
			j++;
		}
		else {
			a[left + i] = r[k];
			k++;
		}
		count++;
	}
	return count;
}

int mergeSort(int* a, int left, int right) {
	if (right-left<=1)return 0;
	int count = 0;
	int mid = (left + right) / 2;
	count+=mergeSort(a, left, mid);
	count+=mergeSort(a, mid, right);
	count+=merge(a, left, mid, right);
	return count;
}


Measured memory_bytes: 65824
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  REP(i, N) {
    cin >> A[i];
  }
  vector<int64_t> x(N);
  REP(i, N) {
    if (i == 0) {
      int sign = 1;
      int64_t sum = 0;
      REP(j, N) {
        sum += sign * A[j];
        sign *= -1;
      }
      x[0] = sum / 2;
    } else {
      x[i] = A[i-1] - x[i-1];
    }
  }
  REP(i, N) {
    cout << x[i]*2 << endl;
  }
  return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n,k;
      cin>>n>>k;
      vector<int>arr(n+1,0);
      for(int i=1;i<=n;i++)cin>>arr[i];
      for(int i=1;i<=n;i++)arr[i]+=arr[i-1];
      map<int,int>data;
      int ans=0;
      for(int i=0;i<=n;i++){
            if(i-k>=0)data[((arr[i-k]-i)%k+k)%k]--;
            ans+=data[((arr[i]-i)%k+k)%k];
            data[((arr[i]-i)%k+k)%k]++;
      }
      cout<<ans;
}



Measured memory_bytes: 14336
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func small(N, X, M int) {
	a := X
	ans := X
	for i := 2; i <= N; i++ {
		a *= a
		a %= M
		ans += a
	}
	out(ans)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, X, M := getInt(), getInt(), getInt()

	if N < 1000000000 {
		small(N, X, M)
		return
	}
	m := make([]int, M)
	b := make([]int, 0)

	last := -1
	a := X % M
	b = append(b, a)
	tot := a
	m[a]++
	for i := 1; i <= N; i++ {
		a *= a
		a %= M
		if m[a] != 0 {
			last = a
			break
		}
		if a == 0 {
			out(tot)
			return
		}
		tot += a
		m[a]++
		b = append(b, a)
	}
	// out(b, last, tot)
	if last == -1 {
		out(tot)
		return
	}
	start := 0
	ans := 0
	for i := 0; i < len(b); i++ {
		if b[i] == last {
			start = i
			break
		}
		ans += b[i]
		tot -= b[i]
	}
	N -= start
	loop := len(b) - start
	// out(N, loop, tot)
	n := N / loop
	ans += n * tot
	rest := N % loop
	for i := 0; i < rest; i++ {
		ans += b[start+i]
	}
	// out(n*loop + rest)
	out(ans)
}


Measured memory_bytes: 4940
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        mut a: i64,
        mut b: i64,
        mut k: i64,
    }
    if a >= k {
        a -= k;
    } else {
        k -= a;
        a = 0;
        b -= k;
        b = std::cmp::max(0, b);
    }
    println!("{} {}", a, b);
}


Measured memory_bytes: 4352
a, b, c = (int(x) for x in input().split())

if a > b :
    tmp = a
    a = b
    b = tmp
    
if b > c :
    tmp = b
    b = c
    c =tmp
    
if a > b :
    tmp = a
    a = b
    b = tmp
    
print(a, b, c)


Measured memory_bytes: 5600
//@HelloElwin20190819
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int main() {
	
	int a;
	char s[100];

	scanf("%d %s", &a, s);

	if (a < 3200) printf("red");
	else printf("%s", s);

	return 0;
}

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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 1000007, inf = 0x3f3f3f3f;

int a[N];
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	int x = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		x ^= a[i];
	}

	for(int i = 0; i < n; i++) {
		cout << (a[i]^x) << ' ';
	}
	cout << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<int, int>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int N, u, v;
vector<vector<int>> edges;

vector<lpair> bfs(int start) {
	vector<lpair> ret(N, lpair(inf<int>, inf<int>));
	ret[start - 1] = lpair(0, start);
	queue<int> que;
	que.push(start);
	while (que.size()) {
		int now = que.front();
		que.pop();

		for (auto &edge: edges[now]) {
			if (ret[edge - 1].first > ret[now - 1].first + 1) {
				ret[edge - 1] = lpair(ret[now - 1].first + 1, edge);
				que.push(edge);
			}
		}
	}

	return ret;
}

int bfs2(int start, vector<int> &bad) {
	int ret = 0;

	vector<lpair> dis(N, lpair(inf<int>, inf<int>));
	dis[start - 1] = lpair(0, start);
	queue<int> que;
	que.push(start);
	while (que.size()) {
		int now = que.front();
		que.pop();
		ret = dis[now - 1].first;
		if (bad[now - 1] == 2) continue;

		for (auto &edge: edges[now]) {
			if (bad[edge - 1] == 1) continue;
			if (dis[edge - 1].first > dis[now - 1].first + 1) {
				dis[edge - 1] = lpair(dis[now - 1].first + 1, edge);
				que.push(edge);
			}
		}
	}

	return ret;
}

int main() {
	cin >> N >> u >> v;
	edges.resize(N + 1);
	int to, from;
	for (int i = 0; i < N - 1; ++i) {
		cin >> to >> from;
		edges[to].push_back(from);
		edges[from].push_back(to);
	}

	auto tkhs = bfs(u);
	auto aok = bfs(v);

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		if (tkhs[i].first <= aok[i].first) {
			ans = max(ans, aok[i].first);
		}
	}

	cout << ans - 1 << endl;

	return 0;
}


/*

高橋：青木に追いつかれない範囲で遠くまで移動する
青木：高橋に向かうだけ

*/

Measured memory_bytes: 7424