akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	LL a[4],b[4],c[4][4],i,j,k;
	bool found=false,f;
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++)
			cin>>c[i][j];
	}
	for(a[1]=0;a[1]<=100&&!found;a[1]++){
		for(a[2]=0;a[2]<=100&&!found;a[2]++){
			for(a[3]=0;a[3]<=100&&!found;a[3]++){
				b[1]=c[1][1]-a[1];
				b[2]=c[1][2]-a[1];
				b[3]=c[1][3]-a[1];
				f=true;
				for(i=1;i<=3&&f;i++){
					for(j=1;j<=3&&f;j++){
						if(b[j]!=c[i][j]-a[i]){
							f=false;
							break;
						}
					}
				}
				if(f)found=true;

			}
		}
	}
	if(found)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;
typedef long long ll;

ll opt[3010][3010];

int main() {
	int n; scanf("%d", &n);
	vector<int> a(n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
	for (int i = n - 1; i >= 0; --i) {
		opt[i][i] = a[i];
		for (int j = i + 1; j < n; ++j) {
			opt[i][j] = max(a[i] - opt[i+1][j], a[j] - opt[i][j-1]);
		}
	}
	printf("%lld\n", opt[0][n-1]);
	return 0;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//BST(Binary Search Tree):二分探索木

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *NIL, *root;

void insert(int key) {
    Node *x, *y, *z;
    
    // initialize
    z = new Node;  // 新しい要素のメモリ確保
    z->key = key;
    z->left = NIL;
    z->right = NIL;
    y = NIL;
    x = root;

    // rootから適切な位置まで二分木をたどる
    while (x != NIL) {
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }

    // 新しい要素を配置する場所を決定
    z->parent = y;  
    if (y == NIL) root = z;  // もともと木が存在しなかった場合
    else if (z->key < y->key) y->left = z;
    else y->right = z;    
}

// 先行順巡回
void preorder(Node* node) {
    if (node == NIL) return;
    cout << " " << node->key;
    if (node->left != NIL) preorder(node->left);
    if (node->right != NIL) preorder(node->right); 
}

// 中間順巡回
void inorder(Node* node) {
    if (node == NIL) return;
    if (node->left != NIL) inorder(node->left);
    cout << " " << node->key;
    if (node->right != NIL) inorder(node->right);
}

void print() {
    inorder(root);
    cout << endl;
    preorder(root);
    cout << endl;
}

//AOJ Binary Search Tree I

int main() {
    int i, m, key;
    string command;

    cin >> m;
    for (i = 0; i < m; i++) {
        cin >> command;
        if (command == "insert") {
            cin >> key;
            insert(key);
        }
        else print();
    }

    return 0;
}


Measured memory_bytes: 26504
# -*- coding: utf-8 -*-
"""
Created on Thu Jun  4 19:55:07 2020

@author: NEC-PCuser
"""

def binary_search(b, a):
    low = 0
    high = len(b) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = b[mid]
        if guess == a:
            return b[mid]
        elif guess > a:
            high = mid - 1
        else:
            low = mid + 1
    abs_low = a * 4
    if len(b) > low: 
        abs_low = abs(b[low] - a)
    abs_high = abs(b[high] - a)
    return b[high] if abs_low > abs_high else b[low]
    
            


if __name__ == "__main__":
    n = int(input())
    
    a = list(map(int, input().split()))
    
    a.sort()
    
    b = a[0:len(a)-1]
    c = binary_search(b, a[len(a)-1] / 2)
    print(str(a[len(a)-1]) + " " + str(c))

Measured memory_bytes: 14052
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
//using namespace __gnu_pbds;
//using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
int n;
ll a[310];
void MAIN() {
	cin>>n;
	rep(i,n)cin>>a[i];
	ll S=a[0]+a[1],X=0;
	rng(i,2,n-1)X^=a[i];
	ll D=(S-X)/2;
	if(S<X||(S-X)%2||(X&D)||(D>a[0])) {
		cout<<"-1";
		return;
	}
	ll R=0;
	for(int i=40;i>=0;i--) {
		if(D>>i&1)R|=1ll<<i;
		else if(X>>i&1) {
			if((R|(1ll<<i)|D)<=a[0])R|=1ll<<i;
		}
	}
	if(!R)cout<<"-1";
	else cout<<a[0]-R;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3668
import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
 
 
def main():
    h, w = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1
    s2 = [list(input()) for i in range(h)]
    s2[Ch][Cw] = 0
    d = deque()
    d.append([Ch, Cw])
    while d:
        nowh, noww = d.popleft()
        if [nowh,noww]==[Dh,Dw]:
            print(s2[nowh][noww])
            exit()
        for i, j in [[0, 1], [1, 0], [0, -1], [-1, 0]]:
            if ((0 <= nowh+i < h) and (0 <= noww+j < w)):
                if s2[nowh+i][noww+j] == '.':
                    s2[nowh+i][noww+j] = s2[nowh][noww]
                    d.appendleft([nowh+i, noww+j])
                elif s2[nowh+i][noww+j] != '#':
                    if s2[nowh+i][noww+j] > s2[nowh][noww]:
                        s2[nowh+i][noww+j] = s2[nowh][noww]
                        d.appendleft([nowh+i, noww+j])
        for i in [-2,-1,0,1,2]:
            for j in [-2,-1,0,1,2]:
                if ((0 <= nowh+i < h) and (0 <= noww+j < w)):
                    if s2[nowh+i][noww+j] == '.':
                        s2[nowh+i][noww+j] = s2[nowh][noww]+1
                        d.append([nowh+i, noww+j])
                    elif s2[nowh+i][noww+j] != '#':
                        if s2[nowh+i][noww+j] > s2[nowh][noww]+1:
                            s2[nowh+i][noww+j] = s2[nowh][noww]+1
                            d.append([nowh+i, noww+j])
    print(-1)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 171580
//package atCoder;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int numberOfGate = sc.nextInt();
		int LLimit = sc.nextInt();
		int RLimit = sc.nextInt();

		for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		}
		sc.close();

		System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0);
	}
}


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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

class UnionFind
{
    std::vector<int> data;

  public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(int x)
    {
        return -data[root(x)];
    }
};

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

    int n,m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
    }

    int res = 0;
    for(int i = 0; i < n; i++){
        if(uf.find(i,p[i])) res++;
    }
    cout << res << endl;
}

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

int main(){
	int a,b;
	int c;
	cin >> a >> b;
	c=a+b;
	if(c % 2 == 0){
		cout << (a + b) /2 << endl;
	}
	else{
		cout << (a + b) / 2 + 1 << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;

int h, w, n;

bool outrange(int y, int x) {
	return (x <= 0 || x >= w-1 || y <= 0 || y >= h-1);
}


int main() {
	int i, j, k; 
	cin >> h >> w >> n;
	map <p_ii, int> square;
	set<p_ii> check;

	for (i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		for (j = -1; j <= 1; j++) {
			for (k = -1; k <= 1; k++) {
				if (outrange(a + j, b + k))continue;
				if (check.count({ a + j, b + k }) == 0) {
					check.insert({ a + j,b + k });
					square[{a + j, b + k}] = 0;
				}
				square[{a + j, b + k}]++;
			}
	    }
	}

	map<int, ll> ans;
	for (i = 0; i < 10; i++)ans[i] = 0;

	for (auto itr = check.begin(); itr != check.end(); itr++) {
		ans[square[*itr]]++;
	}

	ans[0] = (ll)(h - 2)*(w - 2);
	for (i = 1; i < 10; i++) {
		ans[0] -= ans[i];
	}

	for (i = 0; i < 10; i++) {
		cout << ans[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 100352
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, r, i, j, k, p, c, tmp;
    int[] a;

    for(;;){
      n = sc.nextInt(); r = sc.nextInt();
      if(n == 0 && r == 0)break;
      a = new int[n];
      for(i = 0;i < n;i++)a[i] = n - i;

      for(i = 0;i < r;i++){
        p = sc.nextInt(); c = sc.nextInt(); p--;
        for(j = 0;j < c;j++){
          tmp = a[p + j];
          for(k = 0;k < p;k++)a[p + j - k] = a[p + j - 1 - k];
          a[j] = tmp;
        }
      }
      out.println(a[0]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 26696
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
typedef unsigned long long ull;
const ull INF = 1e18;
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int lst[n];
    rep(i,0,n){
        cin>>lst[i];
    }
    sort(lst,lst+n);
    int ans=0;
    rep(i,0,k){
        ans+=lst[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
const int INF = 1000000000;
const long INF64 = 9223372036854775807;
const int MOD = 1000000007;

long ggd(long a, long b) {//最小公倍数，最大公約数
	if(a<b)swap(a,b);
	if (b == 0) {
		return a;			
	}
	return ggd(b, a % b);
}

long lcm(long number1,long number2){
	return ggd(number1,number2) * number2;	
}

int main(){
	int n;
	std::cin >> n;
	vector<int>a(n);
	rep(i,n)std::cin >> a[i];
	int ans=ggd(a[0],a[1]);
	rep(i,n-2){
		ans=ggd(ans,a[i+2]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        String s = scanner.next();
        for (int i = 0; i < 8; i++) {
            if (s.startsWith("keyence".substring(0, i)) && s.endsWith("keyence".substring(i))) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 23636
<?php

class Solver
{
    private $number_of_elements;
    private $values = array();

    public function __construct()
    {
        $lines = array();
        while (1) {
            if (!$line = fgets(STDIN)) {
                break;
            }
            $line = trim($line);
            $lines[] = $line;
        }

        $this->number_of_elements = $lines[0];
        $this->values = explode(' ', $lines[1]);
    }

    public function solveAnswer()
    {
        $BubbleSortedArray = $this->BubbleSort();
        echo implode(' ', $BubbleSortedArray) . PHP_EOL;
        echo $this->isStable($this->values, $BubbleSortedArray) ? "Stable" . PHP_EOL : "Not stable" . PHP_EOL;

        $SelectionSortedArray = $this->SelectionSort();
        echo implode(' ', $SelectionSortedArray) . PHP_EOL;
        echo $this->isStable($this->values, $SelectionSortedArray) ? "Stable" . PHP_EOL : "Not stable" . PHP_EOL;
    }

    public function BubbleSort()
    {
        $tmp_array = $this->values;
        $flag = 1;
        while ($flag) {
            $flag = 0;
            for ($i = $this->number_of_elements - 1; $i > 0 ; $i--) {
                if (substr($tmp_array[$i], -1) < substr($tmp_array[$i - 1], -1)) {
                    list($tmp_array[$i], $tmp_array[$i - 1]) = [$tmp_array[$i - 1], $tmp_array[$i]];
                    $flag = 1;
                }
            }
        }
        return $tmp_array;
    }
    
    public function SelectionSort()
    {
        $tmp_array = $this->values;
        for ($i = 0; $i < $this->number_of_elements; $i++) {
            $minj = $i;
            for ($j = $i; $j < $this->number_of_elements; $j++) {
                if (substr($tmp_array[$j], -1) < substr($tmp_array[$minj], -1)) {
                    $minj = $j;
                }
            }
            if ($minj!=$i) {
                list($tmp_array[$i], $tmp_array[$minj]) = [$tmp_array[$minj], $tmp_array[$i]];
            }

        }
        return $tmp_array;
    }
    
    public function isStable($in, $out)
    {
        for ($i = 0; $i < $this->number_of_elements; $i++) {
            for ($j = $i + 1; $j < $this->number_of_elements; $j++) {
                for ($a = 0; $a < $this->number_of_elements; $a++) {
                   for ($b = $a + 1; $b < $this->number_of_elements; $b++) {
                        if (substr($in[$i], -1) == substr($in[$j], -1) && $in[$i]==$out[$b] && $in[$j] == $out[$a]) {
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }
}

$solver = new Solver;
$solver->solveAnswer();


Measured memory_bytes: 9476
package main

import "fmt"

func main(){
  A := [7]string{"SUN","MON","TUE","WED","THU","FRI","SAT"}
  
  var S string
  fmt.Scan(&S)
  
  var D int
  
  for i := 0;i<7;i++{
    if A[i] == S{
      D = i
     	break 
    }
  }
  fmt.Print(7-D)
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

template <typename T>
class SegTree
{
    using F = function<T(const T&, const T&)>;

public:
    SegTree(const int n_, const T unity_, const F opr_, const F upd_ = [](int a, int b) {return b;}) : 
        n(1 << __lg(2*n_-1)), data(2*n-1, unity_), unity(unity_), opr(opr_), upd(upd_) {}
    
    T query(int a, int b) { return _query(a, b, 0, 0, n); }

    // k番目の値をxで更新
    void update(int k, T x) {
        k += n - 1; // 葉の節点に変換
        data[k] = upd(data[k], x);
        // 各節点を更新
        while (k > 0) {
            k = (k - 1) / 2;
            data[k] = opr(data[2*k+1], data[2*k+2]);
        }
    }

    T operator[](size_t i) {
        return data[i + n - 1];
    }

private:

    int n;          // 要素数
    vector<T> data; // データを格納する配列
    T unity;        // 単位元
    F opr;          // クエリ処理の関数
    F upd;          // 点更新の関数

    // [a, b)の区間クエリ
    T _query(int a, int b, int k, int l, int r) {
        // [a, b)と[l, r)が交差しないとき
        if (r <= a || b <= l) return unity;

        // [l, r)が[a, b)に完全に含まれているとき
        if (a <= l && r <= b) {
            return data[k];
        } else {
            // そうでなければ、子ノードのoprを返す
            T v1 = _query(a, b, 2*k+1, l, (l+r)/2);
            T v2 = _query(a, b, 2*k+2, (l+r)/2, r);
            return opr(v1, v2);
        }
    }
};

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

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

    SegTree<int> st(
        n, 0, 
        [] (int a, int b) { return a | b; },
        [] (int a, int b) { return b; }
    );

    for (int i = 0; i < n; i++) {
        st.update(i, 1 << (s[i] - 'a'));
    }

    int q; cin >> q;
    while (q--) {
        int k; cin >> k;
        if (k == 1) {
            int i; cin >> i; i--;
            char c; cin >> c;
            st.update(i, 1 << (c - 'a'));
        } else {
            int l, r; cin >> l >> r; l--;
            int ans = __builtin_popcount(st.query(l, r));
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5020
import java.util.*;
class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while(true)
        {
            //?????°
            int n = sc.nextInt();
            //??????????????°
            int r = sc.nextInt();
            if(n==0 && r==0)
            {
                break;
            }
            int card[] = new int[n];
            //?????????
            for(int i=0; i<n; i++)
            {
                card[i]=n-i;
            }
            for(int i=0; i<r; i++)
            {
                int p=sc.nextInt();
                int c=sc.nextInt();
                //??????????????????????????£?????????
                int tcard[] = new int[n];
                for(int j=0; j<n; j++)
                {
                    tcard[j]=card[j];
                }
                //??\?????????
                for(int j=0; j<c; j++)
                {
                    card[j]=tcard[p-1+j];
                }
                for(int j=c; j<p-1+c; j++)
                {
                    card[j]=tcard[j-c];
                }
            }
            System.out.println(card[0]);
        }

        sc.close();
    }
}

Measured memory_bytes: 37180
(let [n (read-line) xs (map read-string (clojure.string/split (read-line) #" "))]
  (loop [m 1000000 p 100]
    (if (< p 1) (println (int m))
      (recur (min m (reduce #'+ (map #(Math/pow (- % p) 2) xs))) (dec p)))))


Measured memory_bytes: 68184
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int n;
int a;
int vis[1000011]={0};
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		vis[a+1]++;
		vis[a]++;
		vis[a+2]++;
	}
	int maxx=0;
	for(int i=0;i<=100005;i++){
	    maxx=max(maxx,vis[i]);
	}
	cout<<maxx;
}

Measured memory_bytes: 640
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define MOD 1000000007
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const ll P=1000000007LL;
const double PI=acos(-1.0);
template<typename T> inline T gcd(T&a,T&b){return b==0?a:gcd(b,a%b);}
template<typename T> inline T lcm(T&a,T&b){return a/gcd(a,b)*b;}
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int n;
string s1,s2;
int main(){
    read(n);
    cin>>s1>>s2;
    ll ans=0;
    for (int i=0;i<s1.length();){
        if (s1[i]==s2[i]){
            if (i==0){
                ans=3;
            }
            else{
                if (s1[i-1]==s2[i-1]) ans=(ans*2)%P;
            }
            i++;
        }
        else{
            if (i==0){
                ans=6;
            }
            else{
                if (s1[i-1]==s2[i-1]) ans=(ans*2)%P;
                else ans=(ans*3)%P;
            }
            i+=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        let _ = io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line()
            .split_whitespace()
            .map(|s| s.to_string())
            .collect()
    }

    pub struct Reader {
        buf: VecDeque<String>,
    }

    #[allow(dead_code)]
    impl Reader {
        pub fn new() -> Reader {
            Reader { buf: VecDeque::new() }
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T
        where
            T: FromStr,
            T::Err: Debug,
        {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn next_n<T>(&mut self, n: usize) -> Vec<T>
        where
            T: FromStr,
            T::Err: Debug,
        {
            let mut vec: Vec<T> = Vec::with_capacity(n);

            for _ in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}

fn main() {
    let mut reader = reader::Reader::new();

    let n: usize = reader.next();

    let rev: bool = n % 2 != 0;

    use std::collections::VecDeque;
    let mut deq: VecDeque<i32> = VecDeque::new();

    for i in 0..n {
        if i % 2 == 0 {
            deq.push_back(reader.next());
        } else {
            deq.push_front(reader.next());
        }
    }

    if rev {
        for i in (0..n).rev() {
            print!("{}{}", deq[i], if i == 0 { "\n" } else { " " });
        }
    } else {
        for i in 0..n {
            print!("{}{}", deq[i], if i == n - 1 { "\n" } else { " " });
        }        
    }

}

Measured memory_bytes: 16120
N,M = map(int,input().split())
pool = []
for i in range(M):
    i_1,i_2 = map(int,input().split())
    pool.append([i_1,i_2])
min_val = max([int(pool[i][0]) for i in range(M)])
max_val = min([int(pool[i][1]) for i in range(M)])
if min_val > max_val:
    print(0)
else:
    print(max_val-min_val+1)
    

Measured memory_bytes: 20468
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;


vector<string>road;
int ix[] = { 0,1,1,1,0,-1,-1,-1 };
int iy[] = { -1,-1,0,1,1,1,0,-1 };
void dfs(int y, int x, int h, int w) {
	road[y][x] = '0';
	rep(i, 8) {
		int dx = x + ix[i], dy = y + iy[i];
		if (dx < 0 || w <= dx || dy < 0 || h <= dy || road[dy][dx] == '0')continue;
		dfs(dy, dx, h, w);
	}
}

int main() {
	while (1) {
		int h, w, cnt = 0;
		string k;
		cin >> w >> h;
		if (h == 0 || w == 0)break;
		road.resize(h);
		road.assign(h, "");
		rep(i, h)rep(j, w) {
			cin >> k;
			road[i] += k;
		}
		rep(i, h)rep(j, w) {
			if (road[i][j] == '0')continue;
			dfs(i, j, h, w);
			cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}




Measured memory_bytes: 3348
#include <iostream>
#include <fstream>

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define ll long long int
#define REP(i, n) for(int i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;


class CID {
public:
    ll N, M;
    ll P[100000], Y[100000];
    vector<ll> yd[100001];

    void solve(std::istream& in, std::ostream& out) {
        in >> N >> M;
        REP(i, M) {
            in >> P[i] >> Y[i];
            yd[P[i]].push_back(Y[i]);
        }
        REP(i, N) sort(ALL(yd[i + 1]));
        REP(i, M) {
            Dump(P[i], out);
            Dump(lower_bound(ALL(yd[P[i]]), Y[i]) - yd[P[i]].begin() + 1, out);
            out << endl;
        }
    }

    void Dump(ll x, std::ostream& out) {
        out << setfill('0') << right << setw(6) << x;
    }
};


int main() {
    CID solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 8576
#include<stdio.h>
#define N 2000001

void CountingSort(int *,int *,int ,int);
int C[N];
int B[N];
int main(){
  int A[N];
  
int i,n,k=0;
  scanf("%d",&n);
for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  if(k<A[i])
    k=A[i];}
CountingSort(A,B,n,k);
  for(i=1;i<n;i++)
    printf("%d ",B[i]);
  printf("%d\n",B[n]);
  return 0;
}




void CountingSort(int *A ,int *B,int n ,int k){
  int i,j;
  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){

  C[i]=C[i]+C[i-1];
  }
 for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;}
 

 }










Measured memory_bytes: 18224
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */

#define MAXN (200000)
#define MOD (1000000007)

char s[MAXN+1];

uint64_t dp[2][MAXN+1];

int main(void)
{
    int n;
    scanf("%d",&n);
    scanf("%s", s);
    n*=2;

    bool isR;
    isR = false;
    int l = 1;
    uint64_t c;
    c = 1;
    if(s[0]=='W')
    {
        printf("0\n");
        return 0;
    }
    for(int i=1;i<n;i++)
    {
        if(s[i-1]==s[i])
        {
            isR = !isR;
        }
        if(!isR)
        {
            l++;
        }else
        {
            if(l<=0)
            {
                printf("0\n");
                return 0;               
            }
            c *= l;
            c %= MOD;
            l--;
        }
    }

    if(l!=0)
    {
        printf("0\n");
        return 0;               
    }   

    uint64_t ans;
    ans = 1;
    for(int i=2;i<=(n/2);i++) 
    {
        ans *= i;
        ans %= MOD;
    }
    ans *= c;
    ans %= MOD;

    printf("%ld\n",ans);

    return 0;
}





Measured memory_bytes: 384
import numpy as np


def solve(string):
    n, m, c, *ba = map(int, string.split())
    b = np.asarray(ba[:m])
    a = np.asarray(ba[m:])
    a.resize((n, m))
    return str(sum(np.dot(b, a.T) > -c))


if __name__ == '__main__':
    n, m, o = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, o) + '\n'.join([input() for _ in range(n + 1)])))


Measured memory_bytes: 20004
# coding: utf-8
# Your code here!
n,k=map(float,input().split(" "))
ans1=0
ans=0
n=int(n)
for i in range(1,n+1):
    c=0
    ans1=0
    while(i<k):
        i*=2
        c+=1
    ans1+=2**c
    ans+=1/ans1
   # print(c)
print(ans*(1/n))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "random"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=310;

int n,m=1,l;
ii f[N][N];
vector<ii> ad[N];

main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);

    fasty;
    cin>>n;
    vector<char> a;
    forinc(i,1,n){
        char ch; cin>>ch; a.pb(ch);
    }
    forinc(i,1,n-1){
        m+=a[i]!=a[i-1];
    }
    cout<<m<<"\n";


    return 0;

    n=in,m=in,l=in;
    forinc(i,1,m){
        int u=in,v=in,c=in;
        if(c>l) continue;
        ad[u].pb({v,c});
        ad[v].pb({u,c});
    }

    forinc(i,1,n)
        forinc(j,1,n)
            f[i][j]=i==j?ii(0,-l):ii(n+1,0);
    forinc(i,1,n){
        using w=tuple<int,int,int>;
        priority_queue<w,vector<w>,greater<w>> q;
        q.push(mt(0,-l,i));
        int c,g,u;
        while(q.size()){
            tie(c,g,u)=q.top(); q.pop();
            //cout<<f[i][u].fi<<" "<<f[i][u].se<<"\n";
            if(f[i][u]<ii(c,g)) continue;
            //cerr<<c<<" "<<g<<" "<<u<<"\n";
            forv(v,ad[u]){
                int C,G;
                if(-g>=v.se) C=c,G=-g-v.se;
                else C=c+1,G=l-v.se;
                if(f[i][v.fi] > ii(C,-G)){
                    f[i][v.fi]=ii(C,-G);
                    q.push(mt(C,-G,v.fi));
                }
            }
        }
        //cout<<f[5][2].fi;
        ///return 0;
        //return 0;
    }

    forinc(i,1,in){
        int u=in,v=in;
        cout<<(f[u][v].fi>n?-1:f[u][v].fi)<<"\n";
    }
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int count = 0;
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        DateTime d = new DateTime(2000, a[0], a[1]);
        for (int i = 1; i <= 12; i++)
        {
            if (new DateTime(2000, i, i) <= d) count++;
        }
        Console.WriteLine(count);
    }
}

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

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<long long> L(N+1);
    L[0] = 2;
    L[1] = 1;
    for (int i = 2; i <= N; i++)
    {
        L[i] = L[i-1] + L[i-2];
    }
    
    cout << L[N] << endl;
}

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

Measured memory_bytes: 3596
#include <iostream>
#include <string>

using namespace std;

int abs(int num){
  if(num >= 0){
    return num;
  }else{
    return -num;
  }
}

int main(){
  string S;
  cin >> S;
  int sum=0;
  for(int i=0;i<2;i++){
    sum += abs(S[i+1] - S[i]);
  }

  if(sum > 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;

}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

const int MAX_N = 1 << 16;
int dp[5][MAX_N];

int main()
{
  dp[0][0] = 1;
  for (int i = 0; i * i < MAX_N; i++){
    int x = i * i;
    for (int j = 1; j <= 4; j++){
      for (int k = 0; k < MAX_N - x; k++){
        if (!dp[j - 1][k]) continue;
        dp[j][k + x] += dp[j - 1][k];
      }
    }
  }
  while (int n = in()){
    printf("%d\n", dp[4][n]);
  }
  return 0;
}

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

int main()
{
	string S;
	cin >> S;
	char part[] = {'A', 'C', 'G', 'T'};
	int ans = 0;
	int cnt = 0;
	for(int i = 0; i < S.length(); i++){
		bool mat = false;
		for(int j = 0; j < 4; j++){
			if(S[i] == part[j]){
				mat = true;
			}
		}
		if(mat){
			cnt++;
		}
		else{
			 ans = max(cnt, ans);
			 cnt = 0;
		}
	}
	ans = max(cnt, ans);
	cout << ans << 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++)
using ll = long long;

int main(){
  int n; cin >>n;
  vector<int> a(n);
  ll cnt = 0;
  rep(i,n){
    cin >>a[i];
    if(i!=0){
      while(a[i]<a[i-1]){
        cnt++;
        a[i]++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 4028
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] a = sc.next().split("");
		String[] b = sc.next().split("");
		if(a.length > b.length) {
			System.out.println("GREATER");
			return;
		}
		if(a.length < b.length) {
			System.out.println("LESS");
			return;
		}
		for(int i =0;i < a.length;i++) {
			if(Integer.valueOf(a[i]) >Integer.valueOf(b[i])) {
				System.out.println("GREATER");
				return;
			}

			if(Integer.valueOf(a[i]) <Integer.valueOf(b[i])) {
				System.out.println("LESS");
				return;
			}
		}
		System.out.println("EQUAL");
	}
}

Measured memory_bytes: 23636
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int m1 = sc.NextInt();
        int d1 = sc.NextInt();
        int m2 = sc.NextInt();
        int d2 = sc.NextInt();
        if (m1 != m2)
        {
            Console.WriteLine("1");
        }
        else
        {
            Console.WriteLine("0");
        }
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 11092
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    println!("{}", (a - 1) * (b - 1));
}



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

int main() {
  string s;
  cin >> s;
  
  int ans=0;
  vector<char> data={'A','C','G','T'};
  
  for(int i=0;i<s.size();i++){
    for(int j=1;i+j<=s.size();j++){
      string ss=s.substr(i,j);
      for(int k=0;k<ss.size();k++){
        for(char d:data){
          if(ss.at(k)!=data.at(0)&&ss.at(k)!=data.at(1)&&ss.at(k)!=data.at(2)&&ss.at(k)!=data.at(3)){
            goto SKIP;
          }
        }
      }
      if(ss.size()>ans){
        ans=ss.size();
      }
      SKIP:;
    }
  }
  
  cout << ans;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll X;

int main(){
    cin>>X;
    
    ll ans=0;

    ans+=X/500*1000;
    X%=500;
    ans+=X/5*5;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n, m;
    scan(n, m);
    auto ng = new bool[](n + 1);
    iota(m).map!(i => readln.chomp.to!int).each!(ai => ng[ai] = 1);

    auto f = new long[](n + 1);
    f[0] = 1;
    if (!ng[1]) f[1] = 1;

    foreach (i ; 2 .. n + 1) {
        if (ng[i]) continue;
        f[i] = (f[i - 1] + f[i - 2]) % mod;
    }

    debug {
        writeln(f);
    }

    writeln(f[$-1]);
}














void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 3964
#include <iostream>
using namespace std;
int main(){
    int n, k;
    int x[105];
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += min(x[i]*2, (k - x[i])*2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
k = int(input())

cnt = 0
step = 1
base = 1
tail = ""
now = 0
def f(x):
    s = list(str(x))
    return sum([int(i) for i in s])
while 1:
    now += step
    if now > step*f(now):
        now -= step
        step *= 10
    else:
        cnt += 1
        print(now)
        if cnt == k:
            exit(0)
     


Measured memory_bytes: 3188
n=int(input())
h=list(map(int,input().split()))
ans=0
tmp=h[0]
tt=0
for i in range(n-1):
    if h[i+1]<=tmp:
        tmp=h[i+1]
        tt+=1
        if tt>ans:
            ans=tt
    else:
        tmp=h[i+1]
        tt=0
print(ans)

Measured memory_bytes: 85104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1193&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int H;

ll check(vector<int>& vec){
    ll ret = 0;
    
    for(int i = 0; i < 3;i++){
        ll t = vec[i];
        ll cnt = 1;
        for(int j = i+1; j < 5;j++){
            if(vec[j] != t) break;
            cnt++;
        }
        if(cnt >= 3){
            for(int j = i; j < i+cnt;j++){
                vec[j] = 0;
            }
            ret += t*cnt;
            return ret;
        }
    }
    return ret;
}
ll solve(){
    ll res = 0;
    vector<vector<int>> Stone(H,vector<int>(5,0));
    for(int i = H-1; i >= 0; i--){
        for(int j = 0; j < 5;j++){
            cin >> Stone[i][j];
        }
    }
    while(true){
        ll t = res;
        for(int i = H-1; i >= 0; i--){
            res += check(Stone[i]);
        }
        if(t == res) break;
        while(true){
            bool update = false;
            for(int i = 0; i < H-1;i++){
                for(int j = 0; j < 5;j++){
                    if(Stone[i][j] == 0 && Stone[i+1][j] != 0){
                        update = true;
                        swap(Stone[i][j],Stone[i+1][j]);
                    }
                }
            }
            if(!update) break;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> H,H){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int maxn = 100000 + 20;

bool prime[maxn];

bool isprime(int n)
{
    int t = sqrt(n);
    for(int i = 2; i <= t; i++)
    {
        if(n % i == 0)
        {
            return false;
        }
    }
    return true;
}

int presum[maxn];

void init()
{
    memset(prime, true, sizeof(prime));
    prime[0] = false;
    prime[1] = false;
    for(int i = 2; i < maxn; i++)
    {
        if(!prime[i])
        {
            continue;
        }
        if(isprime(i))
        {
            for(int j = 2; j * i < maxn; j++)
            {
                prime[j * i] = false;
            }
        }
        else
        {
            prime[i] = false;
        }
    }
    for(int i = 1; i < maxn; i++)
    {
        presum[i] = presum[i-1] + (prime[i] && prime[(i+1)/2]);
    }
}

int getsum(int l, int r)
{
    return presum[r] - presum[l - 1];
}

int main()
{
    init();
    int T;
    cin >> T;
    while(T--)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        cout << getsum(l, r) << endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
const int INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1000*1000*1000+7;
lli bpow(lli a, lli b) {
	if(b == 0) return 1;
	if(b == 1) return a % MOD;
	lli r = bpow(a, b >> 1);
	r = (r * r) % MOD;
	return (r * (((b&1)?a:1) % MOD)) % MOD;
}
lli multInverse(lli a) {
	return bpow(a, MOD - 2);
}
lli modMult(lli a, lli b) {
	return (a * b) % MOD;
}
lli modSub(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli modAdd(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	set<int> aa;
	for(int i = 1; i <= n; i++) {
		int inp;
		cin >> inp;
		aa.insert(inp);
	}
	cout << (aa.size() == n ? "YES" : "NO") << "\n";
	return 0;
}

Measured memory_bytes: 9600
n,x=map(int,input().split())
a=[int(i) for i in input().split()]
ans=0
for i in range(1,n):
    if a[i-1]+a[i]<=x:
        continue
    else:
        tmp=a[i-1]+a[i]-x
        ans+=tmp
        if tmp<=a[i]:
            a[i]-=tmp
        else:
            a[i]=0
            a[i-1]-=tmp-a[i]
print(ans)



Measured memory_bytes: 14252