akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

class Combination {
private:
    int64_t mod; // 元, 素数でないとNG
    int64_t max_size; // 最大値, 10^7まで
    vector<int64_t> factorial; // 階乗
    vector<int64_t> inverse; // 逆元
    vector<int64_t> inverse_factorial; // 逆元の階乗

    void init() {
        // 値は1で初期化する
        factorial.assign(max_size, 1);
        inverse.assign(max_size, 1);
        inverse_factorial.assign(max_size, 1);
        for (auto i = 2; i < max_size; i++) {
            factorial[i] = factorial[i - 1] * i % mod;
            inverse[i] = mod - inverse[mod % i] * (mod / i) % mod; // 拡張Euclidの互除法の変形版
            // inverse[i] = modinv(i); // Fermatの小定理
            inverse_factorial[i] = inverse_factorial[i - 1] * inverse[i] % mod;
            // cout << i << " " << factorial[i] << " " << inverse[i] << " " << inverse_factorial[i] << endl;
        }
    };
public:;
    Combination(int64_t mod, int64_t max_size) {
        this->mod = mod;
        assert(max_size < 1e7);
        this->max_size = max_size + 1;
        // テーブル生成
        init();
    };
    virtual ~Combination(){};

    int64_t modpow(int64_t a, int64_t n) {
        int64_t ret = 1;
        while(n > 0) {
            if(n & 1) ret = ret * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return ret;
    };
    int64_t modinv(int64_t a) { return modpow(a, mod - 2); };
    int64_t combination(int64_t n, int64_t k) {
        if (n < k) return 0;
        if (n < 0 or k < 0) return 0;
        // cout << factorial[n] << " " << inverse_factorial[k] << " " << inverse_factorial[n - k] << endl;
        return factorial[n] * (inverse_factorial[k] * inverse_factorial[n - k] % mod) % mod;
    };
};

int main(){
    int x, y;
    cin >> x >> y;

    int a = x / 2, b = (x - a * 2);
    while(y != a + b * 2) {
        a--; b+=2;
        // cout << a << " " << b << " " << a * 2 + b << " " << a + b * 2 << endl;
        if(a < 0 or b > y / 2) {
            cout << 0 << endl;
            return 0;
        }
    }

    int64_t mod = 1e9+7, n = a + b;
    Combination c(mod, n);

    cout << c.combination(n, a) % mod << endl;
    return 0;
}

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

int main() {
  string g;
  int y, m, d;
  while (true) {
    cin >> g >> y >> m >> d;
    if (g == "#") break;

    if (31 <= y) {
      if (y == 31) {
        if (m >= 5 && d >= 1) {
          cout << "? " << y - 30 << " " << m << " " << d;
        } else {
          cout << g << " " << y << " " << m << " " << d;
        }
      } else {
        cout << "? " << y - 30 << " " << m << " " << d;
      }
    } else {
      cout << g << " " << y << " " << m << " " << d;
    }

    cout << "\n";
  }

  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 100010;
int n , m , arr[N] , v , p;

bool check(int mid){
	int val = arr[mid] + m;
	if(arr[n - p] > val)
		return false;
	long long all = 0;
	for(int i = 0 ;i < n - p + 1;i++){
		all += min(m , max(0 , val - arr[i]));
	}
	all /= m;
	if(all >= v - (p - 1))
		return true;
	return false;
}

int main(){
	scanf("%d%d%d%d",&n,&m,&v,&p);
	for(int i = 0 ;i < n;i++){
		scanf("%d",&arr[i]);
	}
	sort(arr,arr+n);
	int low = 0 , high = n - 1 , res = n , mid;
	while(high >= low){
		mid = (low + high) / 2;
		if(check(mid))
			res = mid , high = mid - 1;
		else
			low = mid + 1;
	}
	cout << n - res << endl;
	return 0;
}


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

int main() {
    double a, b;
    cin >> a >> b;

    if (a > b)
        cout << "GREATER" << endl;
    else if (a < b)
        cout << "LESS" << endl;
    else
        cout << "EQUAL" << 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)
const int INF=1e9+7;

int main() {
	int N,C,rr=INF;
	cin >> N >> C;
	vector<vector<int>> D(C, vector<int>(C)), c(N, vector<int>(N)), sc;
	vector<map<int,int>> m(3, map<int,int>());

	rep(i,C)
		rep(j,C)
			cin >> D.at(i).at(j);
	rep(i,N)
		rep(j,N)
			cin >> c.at(i).at(j);

	rep(i,C-2)
		for(int j=i+1; j<C-1; ++j)
			for(int k=j+1; k<C; ++k) {
				vector<int> tc = {i, j, k};
				do {
					sc.push_back(tc);
				} while(next_permutation(tc.begin(), tc.end()));
			}

	rep(i,N)
		rep(j,N)
			if(m.at((i+j+2)%3).count(c.at(i).at(j)))
				++m.at((i+j+2)%3).at(c.at(i).at(j));
			else
				m.at((i+j+2)%3)[c.at(i).at(j)] = 1;

	rep(i,sc.size()) {
		int r = 0;
		rep(j,3)
			for(auto p : m.at(j))
				r += D.at(p.first-1).at(sc.at(i).at(j))*p.second;
		rr = min(rr, r);
	}

	cout << rr << endl;
}

Measured memory_bytes: 2616
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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 (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int A, P;
  cin >> A >> P;
  P += A * 3;
  int ans = P / 2;
  cout << ans << endl;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int64_t N;
    cin >> N;
    vector<int64_t> arr(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }

    int start = 0;
    int64_t prev = INT_MAX; 
    int64_t ans = INT_MIN;
    for (int j = 0; j < N; j++) {
        int64_t curval = arr[j];
        int64_t curpos = j;
        if (prev < curval) {
            ans = max(curpos - 1 - start, ans);
            start = curpos;
        }
        prev = curval;
    }
    ans = max(N - 1 - start, ans);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
using Graph = vector<vector<int>>;

int main() {
	ll n, ans = 0, a[100000], b[100000];
	cin >> n;
	rep(i, n) cin >> a[i] >> b[i];
	for (int i = n - 1; i >= 0; i--) {
		ans += (b[i] - (a[i] + ans)% b[i]) % b[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1920
h, w = map(int, input().split())
field = [input() for _ in [0] * h]
HR = list(range(h))
WR = list(range(w))
WR2 = list(range(w - 2, -1, -1))

# horizontal dp, vertical dp
hor = [[[-1] * h for _ in WR] for _ in HR]  # hor[top][left][bottom] = right
ver = [[[-1] * w for _ in WR] for _ in HR]  # ver[top][left][right] = bottom

for i in HR:
    hi = hor[i]
    fi = field[i]
    curr = hi[-1][i] = w - 1
    curc = fi[-1]
    for j in WR2:
        if fi[j] != curc:
            curr = hi[j][i] = j
            curc = fi[j]
        else:
            hi[j][i] = curr

for i in HR:
    hi = hor[i]
    vi = ver[i]
    fi = field[i]
    for j in WR:
        hij = hi[j]
        vij = vi[j]
        fij = fi[j]
        curr = hij[i]
        for k in range(i + 1, h):
            if field[k][j] != fij:
                break
            curr = hij[k] = min(curr, hor[k][j][k])
        curr = j
        for k in range(h - 1, i - 1, -1):
            if hij[k] == -1:
                continue
            nxtr = hij[k] + 1
            dr = nxtr - curr
            if dr > 0:
                vij[curr:nxtr] = [k] * dr
                curr = nxtr

ans = 0
while True:
    if hor[0][0][-1] == w - 1:
        break
    for i in HR:
        hi = hor[i]
        vi = ver[i]
        for j in WR:
            hij = hi[j]
            vij = vi[j]

            # print(ans + 1, i, j, 'first')
            # print(hor[i][j])
            # print(ver[i][j])

            # Update hor using hor, ver using ver
            for k in range(i, h):
                h_ijk = hij[k]
                if h_ijk == -1:
                    break
                if h_ijk == w - 1:
                    continue
                hij[k] = max(h_ijk, hi[h_ijk + 1][k])
            for k in range(j, w):
                v_ijk = vij[k]
                if v_ijk == -1:
                    break
                if v_ijk == h - 1:
                    continue
                vij[k] = max(v_ijk, ver[v_ijk + 1][j][k])

            # print(ans + 1, i, j, 'before')
            # print(hor[i][j])
            # print(ver[i][j])

            # Update hor using ver, ver using hor
            curr = j
            for k in range(h - 1, i - 1, -1):
                h_ijk = hij[k]
                if h_ijk == -1:
                    continue
                while curr <= h_ijk:
                    vij[curr] = max(vij[curr], k)
                    curr += 1
            curb = i
            for k in range(w - 1, j - 1, -1):
                v_ijk = vij[k]
                if v_ijk == -1:
                    continue
                while curb <= v_ijk:
                    hij[curb] = max(hij[curb], k)
                    curb += 1

            # print(ans + 1, i, j, 'after')
            # print(hor[i][j])
            # print(ver[i][j])
    ans += 1

print(ans)


Measured memory_bytes: 154636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//�]���؂�グ�� =>  (a + b - 1) / b 

signed main(){
	char c; cin>>c;
  c++;
  cout<<c<<endl;
	
	return 0;
}

Measured memory_bytes: 3560
#include <stdio.h>

int n[1000], m[1000];
int score[1000]={0};

int main(void)
{
  int N, M, i, j, res, max;

  scanf("%d%d", &N, &M);

  for(i = 0; i < N; i++) scanf("%d", &n[i]);
  for(i = 0; i < M; i++) scanf("%d", &m[i]);

  for(i = 0; i < M; i++){
    for(j = 0; j < N; j++){
      if(n[j] <= m[i]){
	score[j]++;
	  break;
      }
    }
  }
  max = score[0];
  for(i = 0; i < M; i++){
    if(max < score[i]){
      max = score[i];
      res = i;
    }
  }
    printf("%d\n", res+1);
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
struct node {
  int key;
  node *lp,*rp;
 
  node(){}
  node(int z):key(z),lp(NULL),rp(NULL){}
 
} *root;
 
void insert(node* z){
  node *x=root,*y=NULL;
 
  while(x){
    y = x;
    x = (z->key < x->key) ? x->lp : x->rp;
  }
 
  if(!y)root = z;
  else (z->key < y->key ? y->lp : y->rp) = z;
}
 
bool find(node *t, int v){
  if(!t)return false;
  if(t->key == v)return true;
  return find((v < t->key)?t->lp:t->rp,v);
}
 
vector<int> preorder, inorder;
 
int dfs(node *t = root){
  preorder.push_back(t->key);
  if(t->lp)dfs(t->lp);
  inorder.push_back(t->key);
  if(t->rp)dfs(t->rp);
}
 
int main(void) {
 
  root = NULL;
 
  int n,v;
  string s;
  cin >> n;
 
  for(int i=0,m=0;i<n;i++){
    cin >> s;
    if(s=="insert"){
      cin >> v;
      insert(new node(v));
      m++;
    } else if(s=="find"){
      cin >> v;
      cout << (find(root,v)?"yes":"no") << endl;
    } else {
      dfs();
      for(int j=0;j<m;j++)cout << " " << inorder[j];
      cout << endl;
      for(int j=0;j<m;j++)cout << " " << preorder[j];
      cout << endl;
 
      preorder.clear();
      inorder.clear();
    }
  }
 
  return 0;
}


Measured memory_bytes: 18716
import java.util.Scanner;

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

	int x,a;
	x = sc.nextInt();
	a = sc.nextInt();

	if(x < a){
	    System.out.println(0);
	}else{
	    System.out.println(10);
	}
    }
}
	


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

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

int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    vector<string> v;
    rep(i,n){
      string s;
      cin>>s;
      v.push_back(s);
    }
    int cnt=0;
    rep(i,n-1){
      if((v[i]=="lu"&&v[i+1]=="ru")||(v[i]=="ru"&&v[i+1]=="lu")
         ||(v[i]=="ld"&&v[i+1]=="rd")||(v[i]=="rd"&&v[i+1]=="ld")){cnt++; i++;}
    }
    cout<<cnt<<endl;
  }
  return 0;
}

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

int h, w;
string a[1001];

int main () {
	cin >> h >> w;
	for (int i = 0; i < h; i++){
		cin >> a[i];
	}
	for (int i = 0; i < w+2; i++){
		cout << "#";
	}
	for (int i = 0; i < h; i++){
		cout << endl << "#" << a[i] << "#";
	}
	cout << endl;
	for (int i = 0; i < w+2; i++){
		cout << "#";
	}
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n,x;
    scanf("%d%d",&n,&x);
    if (x<=(500*n))
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}

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

int main(){
		int n,l; //2<=n<=200 -100<=l<=100
		cin >> n >> l;

		//aji l+i-1

		int aji[200];
		

		for (int i = 0; i < n; i++){
			aji[i] = l + (i+1) - 1;
			//cout << aji[i] << endl;
		}

		int taberu = 0;

		for (int i = 1; i < n; i++){
			if (abs(aji[i-1])>abs(aji[i])){
				taberu = i;
			}
		}

		//cout << taberu << endl;

		int wa = 0;
		for (int i = 0; i < n; i++){
			if (i == taberu){
			}
			else{
				wa += aji[i];
			}
		}

		cout << wa << endl;
			

		//system("pause");

		return 0;
	}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string.h>

using namespace std;

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

int main() {

	int H, W;
	char w[123][123];

	scanf("%d %d", &H, &W);

	REP(i, H) scanf("%s", w[i]);

	int r[123][123];
	memset(r, 0xFF, sizeof(r));

	REP(i, H) {
		REP(j, W) {
			if (j != 0 && r[i][j - 1] != -1) r[i][j] = r[i][j - 1] + 1;
			if (w[i][j] == 'c') r[i][j] = 0;
		}
	}


	REP(i, H) {
		REP(j, W) {
			printf("%d", r[i][j]);
			if (j != W - 1) printf(" ");
		}
		printf("\n");
	}

	return 0;
}

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

int main(){
	int n;
	int card[2][210];
	cin >> n;
	for(int i=0;i<2*n;i++){
		card[0][i] = i+1;
	}
	int m;
	cin >> m;
	for(int i=0;i<m;i++){
		int a; cin >> a;
		if(a == 0){
			int k = 0;
			for(int j=0;j<n;j++,k+=2){
				card[(i+1)%2][k] = card[i%2][j];
				card[(i+1)%2][k+1] = card[i%2][j+n];
			}
		}
		else {
			int k = 0;
			for(int j=a;j<2*n;j++,k++){
				card[(i+1)%2][k] = card[i%2][j];
			}
			for(int j=0;j<a;j++,k++){
				card[(i+1)%2][k] = card[i%2][j];
			}
		}
	}
	for(int i=0;i<2*n;i++){
		cout << card[m%2][i] << endl;
	}
}

Measured memory_bytes: 1160
'''     ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     '''


# [temp1.py] => [29-07-2020 @ 10:25:10] 
# Author & Template by : Udit "luctivud" Gupta
# https://www.linkedin.com/in/udit-gupta-1b7863135/


import math;   from collections import *
import sys;    from functools import reduce
import time;   from itertools import groupby

# sys.setrecursionlimit(10**6)

def input()         : return sys.stdin.readline()
def get_ints()      : return map(int, input().strip().split())
def get_list()      : return list(get_ints())
def get_string()    : return list(input().strip().split())
def printxsp(*args) : return print(*args, end="")
def printsp(*args)  : return print(*args, end=" ")


DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)] 
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1),\
              (+1, +1), (+1, +0), (+1, -1), (+0, +1)]


CAPS_ALPHABETS = {chr(i+ord('A')) : i for i in range(26)}
SMOL_ALPHABETS = {chr(i+ord('a')) : i for i in range(26)}
INF = float('inf')


# Custom input output is now piped through terminal commands.
# for _test_ in range(int(input())): 
n, d = get_ints()
d = d * d
ans = 0
for _  in range(n):
	a, b = get_ints()
	if (a**2) + (b**2) <= d:
		ans += 1
print(ans)



# print("Time Elapsed: {}".format(float(S34p-S34t)))


Measured memory_bytes: 9588
import copy

H, W, K = map(int, input().split())
squares = [list(input()) for _ in range(H)]
result = 0

def check_squares(H_mask, W_mask, squares):
    for i, x in enumerate(f'{H_mask:0{H}b}'):
        if int(x):
            squares[i] = ['R'] * W
    
    for i_1, x in enumerate(f'{W_mask:0{W}b}'):
        if int(x):
            for i_2 in range(H):
                squares[i_2][i_1] = 'R'
                
    return sum([x.count('#') for x in squares])


for H_mask in range((1 << H)):
    for W_mask in range((1 << W)):
        #print(f'{H_mask:0{H}b} {W_mask:0{W}b}')
        #print(check_squares(H_mask, W_mask, copy.deepcopy(squares)))
        c = check_squares(H_mask, W_mask, copy.deepcopy(squares))
        if c == K:
            result += 1
            
print(result)

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

int main(){
    typedef pair<int, int> P;
    int n, k;
    cin >> n >> k;
    vector<P> vertex(n);
    vector<int> vertex_x(n);
    vector<int> vertex_y(n);
    int x, y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        vertex[i] = {x, y};
        vertex_x[i] = x;
        vertex_y[i] = y;
    }
    sort(vertex_x.begin(), vertex_x.end());
    sort(vertex_y.begin(), vertex_y.end());

    long long ans = 4'000'000'000'000'000'000;
    long long x1, x2, y1, y2;

    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            for (int s = 0; s < n; s++){
                for (int t = s + 1; t < n; t++){
                    x1 = vertex_x[i];
                    x2 = vertex_x[j];
                    y1 = vertex_y[s];
                    y2 = vertex_y[t];
                    int tmp = 0;
                    for (int z = 0; z < n; z++){
                        if (x1 <= vertex[z].first && vertex[z].first <= x2 && y1 <= vertex[z].second && vertex[z].second <= y2) tmp++;
                    }
                    if (tmp >= k) ans = min((long long)ans, (long long)((x2 - x1) * (y2 - y1)));
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
	string a;
	cin>>a;
	for(int i=0;i<a.length();++i){
		if(i%2==0){
			cout<<a[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 512
/*  ex3_4: 81
    Jun_JPN */

#include <stdio.h>

int main(void){

    int num, i, j;
    int judge = 0;

    scanf("%d", &num);

    while(1){
        for(i=1; i<10; i++){    // numが「九九」の結果にあるか判定する
            for(j=1; j<10; j++){
                if (num == i*j){
                    judge = 1;  // numが「九九」の結果にある場合，judgeに1が代入される
                }
            }
        }
        if (judge){ // judgeが1（True）ならばYesを出力
            printf("Yes\n");
            break;
        }else{
            printf("No\n");
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 128
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}

	const int N=1e6+10;
	//------------------FIXED------------------
	int a[N];
	void main()
	{
		map<int,int> ct;int n=qread();fo(i,1,n) ct[a[i]=qread()]++;
		int mx=0;fo(i,1,n) chmax(mx,ct[a[i]]+ct[a[i]-1]+ct[a[i]+1]);write(mx);
 	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

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

int main()
{
	string a, b, c;
	
	cin >> a >> b >> c;

	string ans = "";
	ans += 'A';
	ans += b[0];
	ans += 'C';
		
	cout << ans << endl;
	return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    llint k;
    cin >> k;

    llint n;
    n = s.size();

    vector<vector<llint>> dp0(n+1, vector<llint>(k+2, 0));
    vector<vector<llint>> dp1(n+1, vector<llint>(k+2, 0));

    llint num;
    dp0.at(0).at(0) = 1;
    for(llint in=0;in<n;in++) {
        for(llint ik=0;ik<k+1;ik++) {
            num = s.at(in)-'0';
            if(num>0) {
                dp0.at(in+1).at(ik+1) += dp0.at(in).at(ik);
            }
            else {
                dp0.at(in+1).at(ik) += dp0.at(in).at(ik);
            }
            if(num>0) {
                dp1.at(in+1).at(ik+1) += dp0.at(in).at(ik)*(num-1);
                dp1.at(in+1).at(ik) += dp0.at(in).at(ik);
            }
            dp1.at(in+1).at(ik+1) += dp1.at(in).at(ik)*9;
            dp1.at(in+1).at(ik) += dp1.at(in).at(ik);
        }
    }

    cout << dp0.at(n).at(k)+dp1.at(n).at(k) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
long long a[404], d[404][404];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) for (int j = 1; j + i <= n; j++) {
        d[j][j + i] = 1e18;
        for (int k = j; k < j + i; k++)
            d[j][j + i] = min(d[j][j + i],
                              d[j][k] + d[k + 1][j + i]);
        for (int k = j; k <= j + i; k++) d[j][j + i] += a[k];
    }
    cout << d[1][n] << '\n';
}


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

int main()
{
    int k, n, temp;
    cin >> k >>n;
    unordered_map<int, int> map;
    for(int i=0; i<n; i++) {
        cin >> temp;
        map[temp] = 1;
    }
    while(1) {
        temp = k++;
        while(temp>0) {
            if(map[temp%10] == 1)
                break;
            temp/=10;
        }
        if(temp == 0)
            break;
    }
    cout << k-1;
    return 0;
}


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

using namespace std;

typedef long long LL;

const int N = (1e6) + 6, mod = 0;
int mark[N];
vector<int> adj[N];

int main() {
	int n, m;
	cin >> n >> m;
	for (int j = 0; j < m; ++j) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector<int> a, b;
	a.push_back(0);
	mark[0] = 1;
	int cur = 0;
	while (true) {
		int flag = 1;
		for (int u : adj[cur]) if (!mark[u]) {
			mark[u] = 1;
			a.push_back(u);
			cur = u;
			flag = 0;
			break;
		}
		if (flag) break;
	}
	cur = 0;
	while (true) {
		int flag = 1;
		for (int u : adj[cur]) if (!mark[u]) {
			mark[u] = 1;
			b.push_back(u);
			cur = u;
			flag = 0;
			break;
		}
		if (flag) break;
	}
	reverse(b.begin(), b.end());
	for (int x : a) b.push_back(x);
	cout << (int)b.size() << endl;
	for (int x : b) cout << x + 1 << ' ';
	cout << endl;
    return 0;
}


Measured memory_bytes: 29432
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL a,b,c;
  cin>>a>>b>>c;
  LL ceat = min(c,a+b+1);
  cout<<b+ceat<<endl;



  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int solution(string A[], int pos)
{
	if(A[pos].size()==0)
	{
		return pos;
	}
	else
	{
		string e=A[pos];
		char inv=e[0];
		string nuev=e.substr(1,e.size());
		A[pos]=nuev;
		if(inv=='a')
		{
			return solution(A,0);
		}
		if(inv=='b')
		{
			return solution(A,1);
		}
		if(inv=='c')
		{
			return solution(A,2);
		}
	}
}
void solution2(string A[], int pos)
{
	int r=solution(A,pos);
	if(r==0)
	{
		cout<<"A"<<endl;
	}
	if(r==1)
	{
		cout<<"B"<<endl;
	}
	if(r==2){
		cout<<"C"<<endl;
	}
}
main()
{
	string a,b,c;
	string A[3];
	for(int i=0; i<3; i++)
	{
		cin>>A[i];
	}
	solution2(A,0);
}

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

int main() {
  int a,b;cin>>a>>b;
  ll ans=a/(ll)gcd(a,b)*b;
  cout<<ans<<endl;
}

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 100 + 17;

int n, a[MAXN], k, ans;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++)
		if (k >= a[i])
			k -= a[i], ans++;
		else
			k = 0;
	cout << ans - (k > 0) << endl;
	return 0;
}


Measured memory_bytes: 256
S=list(input())
Sf=S[0]+S[1]
Ss=S[2]+S[3]
Sf=int(Sf)
Ss=int(Ss)

if Sf>=13 or Sf==0:
  if 1<=Ss and Ss<=12:
    print("YYMM")
  else:
    print("NA")
    
elif 1<=Sf and Sf<=12:
  if Ss>=13 or Ss==0:
    print("MMYY")
  elif 1<=Ss and Ss<=12:
    print("AMBIGUOUS")
  else:
    print("NA")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
using namespace std;
char str[1000000];
int main() {
  int ans, k, len, J, O, I;
  int a;
  //string str;
  
  while(scanf("%s", str) != EOF) {
    len = strlen(str);
    J=0, O=0, I=0;
    ans=0, k=0;
    //cout << len << endl;
    for(int i = 0 ; i < len ; i++) {
      if(str[i] != 'J') continue;

      if(str[i] == 'J') {
	if(str[i] != '#') a = i;
	while(str[a] == 'J') {
	  str[a] = '#';
	  a++;
	  J++;
	}
	if(str[a] == 'O') {
	  while(str[a] == 'O') {
	    a++;
	    O++;
	  }
	  if(str[a] == 'I') {
	    while(str[a] == 'I') {
	      a++;
	      I++;
	    }
	  }
	}
      }
      //printf("J = %d, O = %d, I = %d\n", J, O, I);
      if(O <= J && O <= I) k = min(J, min(O, I));
      //if(J == O && O == I /*|| J <= O && O >= I*/) k = min(J, min(O, I));
      //else J = 0; O = 0; I = 0;
      ans = max(k, ans);
      J = 0; O = 0; I = 0;
        
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
/*
Submitted With (^^) by -> Hossam ^_^
_____________________
|     ___     ___     |
|    (^_^)   (^_^)    |
|   /( | )\_/( | )\   |
|_____|_|_____|_|_____|
*/

#include <bits/stdc++.h>

using namespace std;

inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};

#define X first
#define Y second
#define endl '\n'
#define ll long long
#define inf (0x7fffffffffffffff)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << (x) << "\n";
#define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;

const int mod = (int)1e9 + 7;
// const int mod = 998244353;
const int MX = (int)5e5 + 10;

int main()
{    
    
    prep();
    
    int n;
    cin >> n;

    map<string, bool> mp;
    string s[n];
    for(int i = 0; i < n; ++i){
        cin >> s[i];
        if(i > 0 && (s[i][0] != s[i - 1].back() || mp[s[i]]))
            return puts("No"), 0;
        mp[s[i]] = true;
    }

    cout << "Yes" << endl;

    // ZXC
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {
	static HashMap<String,Boolean> map;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String in = sc.nextLine();
			String[] a = in.split(" ");
			int n = Integer.parseInt(a[0]);
			int m = Integer.parseInt(a[1]);
			int[] C = new int[n];
			int[] V = new int[n];
			int[] D = new int[n];
			int[] L = new int[n];
			for(int i = 0; i < n; i++) {
				in = sc.nextLine();
				in = sc.nextLine();
				a = in.split(" ");
				C[i] = Integer.parseInt(a[0]);
				V[i] = Integer.parseInt(a[1]);
				D[i] = Integer.parseInt(a[2]);
				L[i] = Integer.parseInt(a[3]);
			}
			int MAX = 0;
			int[][] dp = new int[n+1][m+1];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j <= m; j++) {
					for(int k = 0; ; k++) {
						if(j + C[i] * k > m) break;
						dp[i+1][j + C[i] * k] = Math.max(dp[i+1][j + C[i] * k], dp[i][j] + V[i] * k);
					}
				}
			}
			for(int i = 0; i <= m; i++) {
				MAX = Math.max(dp[n][i], MAX);
			}
			dp = new int[n+1][m+1];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j <= m; j++) {
					for(int k = 0; ; k++) {
						if(j + C[i] * k > m) break;
						dp[i+1][j + C[i] * k] = Math.max(dp[i+1][j + C[i] * k], dp[i][j] + D[i] * k);
					}
				}
			}
			for(int i = 0; i <= m; i++) {
				MAX = Math.max(dp[n][i], MAX);
			}
			dp = new int[n+1][m+1];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j <= m; j++) {
					for(int k = 0; ; k++) {
						if(j + C[i] * k > m) break;
						dp[i+1][j + C[i] * k] = Math.max(dp[i+1][j + C[i] * k], dp[i][j] + L[i] * k);
					}
				}
			}
			for(int i = 0; i <= m; i++) {
				MAX = Math.max(dp[n][i], MAX);
			}
			System.out.println(MAX);
			
			
			
			
		}
		
	}
 }

Measured memory_bytes: 183752
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n;cin >> n;
    int h[n];
    rep(i,n)cin >> h[i];
    reverse(h,h+n);
    int now = 0;
    int cnt = 0;
    int ans = 0;
    rep(i,n){
        if(now <= h[i]){
            cnt++;
            now = h[i];
        }
        else {
            ans = max(ans,cnt);
            cnt = 1;
            now = h[i];
        }
    }
    ans = max(ans,cnt);
    cout << ans-1<< endl;

    return 0;
}

Measured memory_bytes: 1024
N, K = [int(_) for _ in input().split()]
V = [int(_) for _ in input().split()]

max_log = []

for total_take in range(min(N, K) + 1):
    for left_take in range(total_take + 1):
        right_take = total_take - left_take
        taken_set = V[:left_take] + (V[-right_take:] if right_take != 0 else [])
        taken_set.sort(reverse=True)


        if taken_set == []:
            continue
        else:
            removal = min(K - total_take, len(taken_set))
            for _ in range(removal):
                if taken_set[-1] < 0:
                    taken_set.pop()
                    if taken_set == []:break
                else:
                    break

        max_log.append(sum(taken_set))

print(max(max_log))


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  while(true){
    int n;
    cin>>n;
    if(!n)break;
    vi sp(n+1);
    REP(i,n+1)cin>>sp[i];
    int res;
    REP(x,n+1){
      set<int> diff;
      REP(i,n){
        if(i+1 == x){
          if(i<n-1)diff.insert(sp[i+2]-sp[i]);
        }else if(i == x){
          continue;
        }else{
          diff.insert(sp[i+1]-sp[i]);
        }
      }
      if(diff.size() == 1){
        res = sp[x];
        break;
      }
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const double INF=(1e20);
const int maxn=(1e5)+10;
int n; char s[10];
int id[300],a[maxn];
int x[maxn],y[maxn];
double xmx,xmn,ymx,ymn;
int fx[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
double solve(double mid) {
	xmx=ymx=-INF; xmn=ymn=INF;
	double A,B;
	for (int i=1;i<=n;i++) {
		A=x[i],B=y[i];
		if (a[i]==0) A+=mid;
		else if (a[i]==1) A-=mid;
		else if (a[i]==2) B+=mid;
		else B-=mid;
		xmx=max(xmx,A);
		xmn=min(xmn,A);
		ymx=max(ymx,B);
		ymn=min(ymn,B);
	//	printf("%.2lf %.2lf\n",A,B);
	}
	return (xmx-xmn)*(ymx-ymn);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	id['R']=0; id['L']=1;
	id['U']=2; id['D']=3;
	for (int i=1;i<=n;i++) {
		read(x[i]),read(y[i]);
		scanf("%s",s+1);
		a[i]=id[s[1]];
	}
	double l=0,r=(1e10),m1,m2,len;
	for (int i=1;i<=1000;i++) {
		len=(r-l)/3;
		m1=l+len; m2=l+2*len;
		if (solve(m1)<solve(m2)) r=m2;
		else l=m1;
	}
	printf("%.11lf\n",solve(l));
	return 0;
}

Measured memory_bytes: 1408
<?php
list($n, $a, $b, $c, $d) = ints();
$a--;
$b--;
$c--;
$d--;
list($s) = strs();
$maxwa = $cntwa = $maxwb = $cntwb = $maxr = $cntr = 0;
for ($i = 0; $i < $n; ++$i) {
    // Aが通る範囲の連続する岩の最大数
    // 1以下でないとたどり着けない
    if ($i > $a && $i < $c) {
        if ($s[$i] === '#') $cntwa++;
        else $cntwa = 0;
    }
    $maxwa = max($maxwa, $cntwa);

    // Bが通る範囲の連続する岩の最大数
    // 1以下でないとたどり着けない
    if ($i > $b && $i < $d) {
        if ($s[$i] === '#') $cntwb++;
        else $cntwb = 0;
    }
    $maxwb = max($maxwb, $cntwb);

    // Bが通る範囲に左右一つずつ足した範囲の連続する何もないマスの最大数
    // C>Bの場合にこれが3以上ないとAがBを追い越すことが出来ない
    if ($i >= $b - 1 && $i <= $d + 1) {
        if ($s[$i] === '.') $cntr++;
        else $cntr = 0;
    }
    $maxr = max($maxr, $cntr);
}
if ($c > $d) echo max($maxwa, $maxwb) <= 1 && $maxr >= 3 ? 'Yes' : 'No';
else echo max($maxwa, $maxwb) <= 1 ? 'Yes' : 'No';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

int main() {
  int A , B ;
  cin >> A >> B ;
  
  if(A%2==0 && B%2!=0 || A%2!=0 && B%2==0){
    cout << "IMPOSSIBLE" << endl;
  }
  
  else cout << (A+B)/2 << endl;
  
}


Measured memory_bytes: 256
/* code by AbhiTaker
         ____
        /    \
       /  __  \              _______      __       _   _    _____    _____
      /  /  \  \            |__   __|    /  \     | | / /  |  ___|  |  _  \
     /  /____\  \     ___      | |      / /\ \    | |/ /   | |__    | |_)  )
    /  /______\  \   |___|     | |     / /__\ \   |   /    |  __|   |    _/
   /  /        \  \            | |    / /----\ \  | |\ \   | |___   | |\ \
  /__/          \__\           |_|   /_/      \_\ |_| \_\  |_____|  |_| \_\
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1000016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000
ll dp[N],val[N];

int main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
   ll n;
   cin>>n;
   for(ll i=1; i<=n; i++) {
        cin>>val[i];
        if(i==2)
            dp[i] = abs(val[i] - val[i-1]);
        else if(i>2)
            dp[i] = min(dp[i-1] + abs(val[i]-val[i-1]), dp[i-2] + abs(val[i]-val[i-2]));
   }

   cout<<dp[n]<<"\n";
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	int N;
	cin>>N;
	map<int,int> mp;
	for(int i=0; i<N; i++){
		int a;
		cin>>a;
		if(mp.count(a))mp[a]++;
		else mp[a]=1;
		
	}
	for(auto itr=mp.begin(); itr!=mp.end(); itr++){
		if(itr->second>1){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
}
		
		
		
		
		
		
		
		
	

Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

LL gcd(LL x, LL y){
  LL sm, la, work;
  if(x<y) {
    la = y;
    sm = x;
  }
  else{
    la = x;
    sm = y;
  }

  while(1){
    work= la%sm;
    if(work==0)break;
    la=sm;
    sm=work;
  }
  return sm;
}

LL lcm(LL a, LL b){
  return a/gcd(a, b)*b; //順序変えるとオーバーフローする
}

int main(){
  LL a, b, c, d;
  cin>>a>>b>>c>>d;
  --a;
  LL e=lcm(c, d);
  LL ans=b/c-a/c+b/d-a/d-(b/e-a/e);
  ans=b-a-ans;
  ECHO(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  int n;
  cin >> n;
  int a[200005];
  rep(i, n)
  {
    cin >> a[i];
  }

  if (a[0] != 0)
  {
    cout << -1 << endl;
    return 0;
  }

  ll ans = 0;
  int tmp = 0; // a[0]
  repi(i, 1, n)
  {
    if (tmp + 2 <= a[i])
    {
      cout << -1 << endl;
      return 0;
    }

    if (tmp + 1 == a[i])
    {
      ans++;
    }
    else
    {
      ans += a[i];
    }
    tmp = a[i];
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int v[100100];
//初期化(n頂点バラバラ)
void init(int n){
	rep(i,n) v[i]=i;
}
//頂点aが属するrootを求める
int root(int a){
	if(v[a]==a) return a; //aはroot
	return (v[a]=root(v[a])); //aの親のroot
}
//頂点aとbが同一グループか?
bool is_same_set(int a,int b){
	return root(a)==root(b);
}
//頂点aとbを同一グループにまとめる
void unite(int a,int b){
	v[root(a)]=root(b);
}
int main(){
	int n; cin>>n;
	init(n);
    int m; cin>>m;
    int p[n]; rep(i,n) cin>>p[i];
    while(m--){
        int x,y; cin>>x>>y;
        unite(x,y);
    }
    int cnt=0;
    rep(i,n){
        if(is_same_set(i+1,p[i])) cnt++;
    }
    cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5;
int st[10*MAXN];
int flag;
int insert(int root,int l,int r,int ql,int qr){
	if(l>qr || r<ql)return st[root];
	if(l==r ){
		if(st[root]==1){
			flag=0;
			
		}
		else {
		st[root]=1;
		flag=1;
		}
		return 1;
	}
	int m=l+(r-l)/2;
	int rt=(root<<1)+1;
	int lf=root<<1;
	if(!st[rt]){
		int val=insert(rt,m+1,r,ql,qr);
		st[root]=min(st[lf],val);
		if(flag)
	return st[root];
	}
	if(!st[lf]){
		int val=insert(lf,l,m,ql,qr);
		st[root]=min(st[rt],val);
		if(flag)
		return st[root];
	}
	flag=0;
	return st[root];
	
}
int main(){
	int n,m;cin>>n>>m;
	vector<pair<int,int>> arrmv;
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		arrmv.push_back(make_pair(b,a));
	}
	sort(arrmv.begin(),arrmv.end(),greater<pair<int,int>>());
	int ans=0;
	memset(st,0,sizeof(st));
	for(int i=0;i<n;i++){
		int l=m- (arrmv[i].second-1);
		if(l<=0)continue;
		flag=0;
		 insert(1,1,m,1,l);
		if(flag)ans+=arrmv[i].first;
		else continue;
	}
	
	cout<<ans<<endl;
	return 0;
}//test

Measured memory_bytes: 5108
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &a) {
    register T x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
    a = x * flag;
}

template <class T>
inline void write(T x) {
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, a, b) for (int i = (a); i <= (b); i++) 
#define Rep(i, a, b) for (int i = (a); i >= (b); i--) 
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)

#define int long long
const int maxn = 501000;
const int Mod = 1e9 + 7;
int n, k;
int prime[maxn], tot, vis[maxn], phi[maxn];
int S[maxn];
void Get_phi(int n) {
	phi[1] = 1;
	For(i, 2, n) {
		if (vis[i] == 0) {
			prime[++tot] = i;
			phi[i] = i - 1;
		}
		For (j, 1, tot) {
			int v = i * prime[j];
			if (v > n) break;
			vis[v] = 1;
			if (i % prime[j] == 0) {
				phi[v] = phi[i] * prime[j];
				break;
			}
			phi[v] = phi[i] * (prime[j] - 1);
		}
	}
	For (i, 1, n) {
		S[i] = (S[i - 1] + phi[i]) % Mod;
	}
}
int Pow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = 1ll * ans * x % Mod;
		x = 1ll * x * x % Mod;
		y >>= 1;
	}
	return ans;
}
signed main() {
	int ans = 0;
	cin >> n >> k;
	Get_phi(k);
	for (int l = 1, r = 0; l <= k; l = r + 1) {
		r = min(k, k / (k / l));
		ans = (ans + 1ll * (S[r] - S[l - 1] + Mod) % Mod * Pow(k / l, n) % Mod) % Mod;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 6060
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    
}


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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,W = [int(i) for i in readline().split()]
wv = [[int(i) for i in readline().split()] for j in range(n)]

w0 = wv[0][0]

d = [[] for i in range(4)]
for w,v in wv:
    d[w-w0].append(v)

from itertools import accumulate
ac = [None]*4
for i in range(4):
    d[i].sort(reverse=True)
    ac[i] = list(accumulate([0]+d[i]))

#print(d)
#print(ac)

ans = 0
di = len(ac[0])
dj = len(ac[1]) 
dk = len(ac[2]) 
dl = len(ac[3])

ac3 = ac[3]
for i in range(di):
    for j in range(min(n+1-i,dj)):
        for k in range(min(n+1-i-j,dk)):
            Wres = i*w0 + j*(w0+1) + k*(w0+2)
            if Wres > W: continue

            res = ac[0][i] + ac[1][j] + ac[2][k]
            idx = (W-Wres)//(w0+3)
            res += ac3[min(dl-1,idx)]
            if ans < res:
                ans = res

print(ans)            










Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int R;
int G;
int B;
int main(){
  rd(R);
  rd(G);
  rd(B);
  if((10*G+B)%4){
    wt_L("NO");
    wt_L('\n');
  }
  else{
    wt_L("YES");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int R,G,B;
// {
//   rd(R,G,B);
//   wt( if[(10G+B)%4, "NO", "YES"] );
// }


Measured memory_bytes: 256