akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
    int a;
    int b;
    int c;
    int d;
    cin >> a >> b >> c >> d;
    int atob = b - a;
    if (atob < 0){
        atob *= (-1);
    }
    int btoc = c - b;
    if (btoc < 0){
        btoc *= (-1);
    }
    int atoc = c - a;
    if (atoc < 0){
        atoc *= (-1);
    }
    if (d >= atob && d >= btoc){
        cout << "Yes" << endl;
    }else if (d >= atoc){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){

	string S;
	cin >> S;
	int ans = INT_MAX;
	for(int i=0; i<S.size()-2; i++){
		int num = (S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0')*1;
		ans = min(ans, abs(753-num));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vi a(n), p(n), q(n);
    rep(i, n){
        cin >> p[i];
        a[i] = i+1;
    }
    rep(i, n) cin >> q[i];
    int cur_p, cur_q;
    int order = 1;
    do{
        bool pf = true;
        bool qf = true;
        for(int i=0; i<n; i++){
            if(a[i] != p[i]) pf = false;
            if(a[i] != q[i]) qf = false;
        }
        if(pf) cur_p = order;
        if(qf) cur_q = order;
        order++;
    }while(next_permutation(all(a)));

    cout << abs(cur_p - cur_q) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = 1e18;
	if((b-a)%2 == 0) ans = (b - a) / 2;
	else{
		ll ans1 = a + ((b-a) - 1) / 2;
		ll ans2 = (n-b+1) + (n - (a+(n-b+1))) / 2;
		ans = min(ans1, ans2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
A, B, K = map(int, input().split())

if(A > B):
    start = B
else:
    start = A

cnt = 0
for i in range(start,0,-1):
    if(0 == A % i == B % i):
        cnt = cnt + 1
    if(K == cnt):
        print(i)
        break


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}


int main() {
    int H, W; cin >> H >> W;
    int N; cin >> N;
    vector<int> a(N); REP(i, N) cin >> a[i];

    int h = 0;
    int w = 0;
    bool flag = true;
    vector<deque<ll>> ans(H);

    for(int i = 0; i < N; ++i) {
        for(int k = 0; k < a[i]; ++k) {
            if(flag) ans[h].push_back(i + 1);
            if(!flag) ans[h].push_front(i + 1);

            if(ans[h].size() == W) {
                h++;
                flag = !flag;
            }
        }
    }

    REP(i, H) {
        REP(k, W) {
            cout << ans[i][k] << " ";
        }
        cout << endl;
    }
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

}

Node treeMaximum(Node x){

}

Node treeSearch(Node u, int k){
if(u==NIL||k==u -> key) return u;
if(k<u->key) return treeSearch(u->left,k);
else return treeSearch(u->right,k); 
}

Node treeSuccessor(Node x){

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  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 inorder(Node u){
  if ( u == NIL ) return;
   inorder(u->left);
   printf(" %d", u->key);
   inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if( t != NIL )
       printf("yes\n");
      else
       printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20440
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    slen = len(s)-1
    for bit in range(1 << slen): # 中に入るもの
        sum_ = int(s[0])
        ans = s[0]
        for i in range(3):
            if bit & (1 << i):#フラグが立ってたら足す
                sum_ += int(s[i+1])
                ans += "+" + s[i+1]
            else:
                sum_ -= int(s[i+1])
                ans += "-" + s[i+1]
        if sum_ == 7:
            print(ans + "=7")
            exit()
if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include "bits/stdc++.h"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long int;

ll mpow(ll a, ll n, ll mod)
{
	ll r = 1;
	while (n) {
		if (n&1) r = r*a%mod;
		a = a*a%mod;
		n >>= 1;
	}
	return r;
}

const int N = 2e5 + 5;

int seg_v[4*N+5], seg_h[4*N+5];

void upd(int seg[], int node, int L, int R, int pos, int val)
{
	if (L+1 == R) {
		seg[node] = val;
		return;
	}
	int mid = (L+R)/2;
	if (pos < mid) upd(seg, node<<1, L, mid, pos, val);
	else upd(seg, node<<1|1, mid, R, pos, val);
	seg[node] = max(seg[node<<1], seg[node<<1|1]);
}

int qu(int seg[], int node, int L, int R, int val)
{
	if (L+1 == R) {
		return L;
	}
	int mid = (L+R)/2;
	if (seg[node<<1] >= val) return qu(seg, node<<1, L, mid, val);
	else return qu(seg, node<<1|1, mid, R, val);
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int n, q; cin >> n >> q;
	ll black = 1LL*(n-2)*(n-2);
	upd(seg_v, 1, 1, n+1, n, n);
	upd(seg_h, 1, 1, n+1, n, n);
	while (q--) {
		int type, x; cin >> type >> x;
		if (type == 1) { // Vertical line
			int pos = qu(seg_h, 1, 1, n+1, x);
			black -= pos-2;
			upd(seg_v, 1, 1, n+1, x, pos-1);
		}
		else {
			int pos = qu(seg_v, 1, 1, n+1, x);
			black -= pos-2;
			upd(seg_h, 1, 1, n+1, x, pos-1);
		}
	}
	cout << black << '\n';
}

Measured memory_bytes: 7756
import java.util.Scanner;

//Aizu Buried Treasure
public class Main{

	int INF = 1<<29;
	int w, h, f, m, o;
	int[][] a;
	int[][][] dp, mem;
	
	int get(int H, int S, int p, int rest){
		if(rest<=1||p<0||w<=p)return INF;
		if(mem[S][p][rest]!=INF)return mem[S][p][rest];
		int res = INF;
		if(p-1>=0){
			int np = p-1, ns = S|(1<<np), nr = rest-1, c = 0;
			if(((S>>np)&1)==0){
				if(a[H][np]>0)nr = Math.min(m, nr+a[H][np]);
				else c+=-a[H][np];
			}
			res = Math.min(res, c+get(H, ns, np, nr));
		}
		if(p+1<w){
			int np = p+1, ns = S|(1<<np), nr = rest-1, c = 0;
			if(((S>>np)&1)==0){
				if(a[H][np]>0)nr = Math.min(m, nr+a[H][np]);
				else c+=-a[H][np];
			}
			res = Math.min(res, c+get(H, ns, np, nr));
		}
		int np = p, ns = 1<<p, nr = rest-1, c = 0;
		if(a[H+1][np]>0)nr = Math.min(m, nr+a[H+1][np]);
		else c+=-a[H+1][np];
		res = Math.min(res, c+dp[ns][p][nr]);
		return mem[S][p][rest] = res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int INF = 1<<29;
		for(;;){
			w = sc.nextInt(); h = sc.nextInt();
			if((w|h)==0)break;
			f = sc.nextInt(); m = sc.nextInt(); o = sc.nextInt();
			a = new int[h][w];
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)a[i][j]=sc.nextInt();
			dp = new int[1<<w][w][m+1];
			for(int i=0;i<1<<w;i++)for(int j=0;j<w;j++)for(int k=0;k<=m;k++)dp[i][j][k]=k==0?INF:0;
			for(int H=h-2;H>=0;H--){
				mem = new int[1<<w][w][m+1];
				for(int i=0;i<1<<w;i++)for(int j=0;j<w;j++)for(int k=0;k<=m;k++)mem[i][j][k]=INF;
				for(int j=0;j<w;j++)for(int k=0;k<=m;k++)get(H, 1<<j, j, k);
				dp = mem;
			}
			int res = INF;
			for(int j=0;j<w;j++)if(o-1>0){
				if(a[0][j]>0)res = Math.min(res, dp[1<<j][j][Math.min(m, o-1+a[0][j])]);
				else res = Math.min(res, -a[0][j]+dp[1<<j][j][o-1]);
			}
			System.out.println(f<res?"NA":res);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define forn(i,a,n) for(int i=(int)a;i<(int)(n);i++)
#define rep(i,n) forn(i,0,n)
#define itn int
#define nit itn
#define nti nit
#define tin nti
#define tni tin
using namespace std;
int n,k;
set<int>d;
bool right(int n,set<int>s)
{
	while(n>0)
	{
		if(s.count(n%10)==1)
		{
			return false;
		}
		n/=10;
	}return true; 
}
int main()
{
	cin>>n>>k;
	for(int i=0;i<k;i++)
	{
		int a;
		cin>>a;
		d.insert(a);
	}
	for(int i=n;i<INT_MAX;i++)
	{
		int k=i;
		if(right(k,d)==true)
		{
			cout<<i<<"\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n, k;
   cin >> n >> k;
   vector<int> h(n);
   rep(i, 0, n) cin >> h[i];
   vector<int> dp(n, 2e9);
   dp[0] = 0;
   rep(i, 0, n) {
      rep(j, 1, k + 1) {
         if (i + j < n)
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
      }
   }
   cout << dp[n - 1] << endl;
   return 0;
}

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

int main(){
    string S;
    cin >> S;
    for (char c='a'; c<='z'; c++){
        bool found=false;
        for (int i=0; i<S.length(); i++){
            if(c==S.at(i)){
                found=true;
            }
        }
        if (!found){
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 512
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
  
int a[92][92] = {0};
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int dfs(int x, int y) {
    a[x][y] = 0;
    int max_ret = 1;

    for(int dir = 0; dir < 4; dir++){
      if(a[x + dx[dir]][y + dy[dir]]){
	max_ret = max(max_ret, dfs(x + dx[dir], y + dy[dir]) + 1);
      }
    }
    
    a[x][y] = 1;
    return max_ret;
}
  
int main(){
    while(true) {
      int m, n;
      
      cin >> m >> n;
      if ( m == 0 ) break;
      for ( int i = 0; i < n+2; i++ ) {
	for ( int j = 0; j < m+2; j++ ) {
	  if ( i == 0 || i == n+1 || j == 0 || j == m+1 ) {
	    a[j][i]=0;
	  }else {
	    cin >> a[j][i];
	  }
	}
      }
      
      int max_value = 0;
      
      for(int i = 1; i < n+1; i++ ) {
	for(int j = 1; j < m+1; j++ ) {
	  if(a[j][i]){
	    max_value = max(max_value, dfs(j, i));
	  }
	}
      }
      
      cout << max_value << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
def main():

    num_houseki, num_sousa = map(int, input().split())
    data = list(map(int, input().split()))

    ans = 0

    for left in range(min(num_houseki, num_sousa) + 1):
        for righ in range(min(num_sousa- left, num_houseki - left) + 1):
            data_left = data[:left]
            data_righ = data[num_houseki - righ:]
            data_now = data_left + data_righ
            data_now.sort()
            nokori = num_sousa - len(data_now)

            while nokori > 0:
                if len(data_now) == 0:
                    break
                if data_now[0] < 0:
                    data_now.pop(0)
                    nokori -= 1
                else:
                    break

            kari = sum(data_now)
            if kari > ans:
                ans = kari

    print(ans)





if __name__ == '__main__':
    main()


Measured memory_bytes: 42092
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  for (int i = 0; i < n; ++i) {
    if (b > 0) {
      for (int j = 0; j < m; ++j) {
        cout << 0 + (int)(j < a);
      }
      cout << '\n';
      for (int j = 0; j < m; ++j) {
        cout << 1 - (int)(j < a);
      }
      cout << '\n';
      ++i; --b;
    } else {
      for (int j = 0; j < m; ++j) {
        cout << 0 + (int)(j < a);
      }
      cout << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 1280
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
#import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
#from collections import defaultdict
# from collections import Counter
#from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	x=int(input())
	ans=0
	
	if x>=2000:
		ans=1
	else:
		a=x//100
		b=x-a*100
		if 5*a>=b:
			ans=1
	
	print(ans)
	
	
	
	
	
	
if __name__ == "__main__":
		main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
char ch[11][1010];
int bel[11],tot,sum[11];
int nxt(int x){
    memset(sum,0,sizeof(sum));
    int p=x;
    while(x<=m){
        bool pd=1;
        for(int i=1;i<=n;i++){
            sum[bel[i]]+=ch[i][x]-'0';
            if(sum[bel[i]]>k) pd=0;
        }
        if(!pd) break;
        x++;
    }
    if(p==x) return -1;
    return x;
}
int main(){
    int minn=2e9;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++) scanf(" %c",&ch[i][j]);
    }
    for(int i=(1<<(n-1))-1;i>=0;i--){
        bel[1]=tot=1;
        for(int j=2;j<=n;j++){
            if(i&(1<<(j-2))) bel[j]=bel[j-1];
            else bel[j]=++tot;
        }
        int x=1,ans=0;
        while(x!=-1&&x<=m) x=nxt(x),ans++;
        if(x!=-1) minn=min(minn,ans+tot-2);
    }
    printf("%d\n",minn);
    return 0;
}


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

static const size_t n_max = 100000;
static int A[n_max];

int main() {
  size_t n;
  scanf("%zu", &n);
  for (size_t i = 0; i < n; i++)
    scanf("%d", A + i);
  size_t i = 0;
  for (size_t j = 0; j < n; j++)
    if (A[j] <= A[n-1])
      std::swap(A[i++], A[j]);
  i--;
  for (size_t j = 0; j < n - 1; j++)
    if (i == j)
      printf("[%d] ", A[j]);
    else
      printf("%d ", A[j]);
  if (i == n-1)
    printf("[%d]\n", A[n-1]);
  else
    printf("%d\n", A[n-1]);
  return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <map>
#include <unordered_map>
#include <tuple>

using namespace std;

#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define umap unordered_map
#define uset unordered_set
#define cina(s, n, a) for(int quer = s; quer < n; quer++) cin >> a[quer]
#define couta(s, n, a) for(int quer = s; quer < n; quer++) cout << a[quer] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES\n" : "NO\n")
#define mod(a, b) (abs(b) + (a % abs(b))) % abs(b)
#define setp(x) fixed << setprecision(x)
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;

void solve(){
    int n;
    cin >> n;
    int cnt = 0, evens = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x % 4 == 0) cnt++;
        else if(x % 2 == 0) evens++;
    }
    int x = n - (2 * cnt);
    if(x <= 0 || x == 1 || (x <= evens)) cout << "Yes";
    else cout << "No";
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
const ll MOD = 1000000007;
vector<ll> p(100010,0);
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
void Main(){
    ll n;cin>>n;
    ll k;cin>>k;
    for(ll i = k;i > 0; i--){
        p[i] = modpow(k/i,n,MOD);
        for(ll j = 2; j * i <= k; j++){
            p[i] -= p[i*j];
            p[i] = (p[i]+MOD)%MOD;
        }
        ans += i * p[i] % MOD;
        ans %= MOD;
    }
    cout << (ans+MOD)%MOD << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> G(N);
    ll a, b;
    rep(i,M){
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<ll> que;
    que.push(0);
    vector<ll> memo(N,-1);
    memo[0] = -2;
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(auto& u:G[v]){
            if(memo[u] != -1) continue;
            memo[u] = v;
            que.push(u);
        }
    }
    cout << "Yes" << endl;
    REP(i,1,N){
        cout << memo[i] + 1 << endl;
    }
}

Measured memory_bytes: 13028
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

typedef pair<LL, LL> PP;

string S;
int main() {
	char c = 'a';
	int cnt = -1;
	cin >> S;
	REP(i, 0, S.size()) {
		if (c != S[i]) {
			c = S[i];
			++cnt;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
int a,b,c;
int main()
{
	scanf(" %d %d %d",&a,&b,&c);
	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=b))printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h> 
int main(int argc, char *argv[])
{
	int i;
	char a[6];
	while(scanf("%s",&a) != EOF)
	{
		for( i = 0; i < strlen(a) - 1; i++ )
		{
			if(a[i] == 'A'){
				if(a[i+1] == 'C')break; 
			}
		}
		if(i == (strlen(a) - 1))printf("No\n");
		else printf("Yes");
	}
	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N; cin >> N;
	ll ans = 0;
	F0R(i, N-1) {
		ll a, b; cin >> a >> b; if (a > b) swap(a, b);
		ans -= a * (N-b+1);		
	}
	F0R(i, N) ans += (i+1) * (N-i);
	print(ans);
}

Measured memory_bytes: 3544
f=lambda:map(int,input().split())
n,m,k=f()

# Union_Find
p=[-1]*n
def root(x):
  while p[x]>=0: x=p[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x==y: return
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return -p[root(x)]

l=[-1]*n
for _ in range(m):
  a,b=f()
  unite(a-1,b-1)
  l[a-1]-=1
  l[b-1]-=1
for i in range(n):
  l[i]+=size(i)
for _ in range(k):
  c,d=f()
  if same(c-1,d-1):
    l[c-1]-=1
    l[d-1]-=1
print(*l)

Measured memory_bytes: 15720
observatories, roads = gets.split.map(&:to_i)
heights = gets.split.map(&:to_i)

ary = Array.new(observatories) { true }

roads.times do |i|
  a, b = gets.split.map(&:to_i)
  
  ary[a - 1] = false if heights[a - 1] <= heights[b - 1]
  ary[b - 1] = false if heights[b - 1] <= heights[a - 1]
end

puts ary.filter{|el| el }.length

Measured memory_bytes: 22360
#include <iostream>
using namespace std;
bool check(char);
int main(void){
    int n = 0;
    string str;
    cin >> str;
    int tmpN = 0;
    for(int i = 0;i < str.length();i++){
        if(check(str[i])){
            tmpN++;
        }else{
            if(n < tmpN) n = tmpN;
            tmpN = 0;
        }
    }
    if(n < tmpN) n = tmpN;
    cout << n << endl;
    return 0;
}
bool check(char c){
    if(c == 'A' || c == 'T' || c == 'G' || c == 'C'){
        return true;
    }
    return false;
}


Measured memory_bytes: 256
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#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 rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

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

typedef string str;
typedef long double db;
typedef long long ll;
typedef pair<int, int> pll;
typedef vector<int> vll;
typedef vector<pll> vpll;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

int n;
int a[N], b[N], c[N];
int dp[N][4];

int32_t main() {
  FAST_IO;
  cin >> n;
  rep(i, n)
    cin >> a[i] >> b[i] >> c[i];
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  loop(i, 1, n) {
    dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
    dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
  }
  cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << '\n';
  rtn 0;
}


Measured memory_bytes: 5760
import java.util.Scanner;

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

		int xp1 = sc.nextInt();
		int yp1 = sc.nextInt();
		int xp2 = sc.nextInt();
		int yp2 = sc.nextInt();

		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			int xp0 = sc.nextInt();
			int yp0 = sc.nextInt();

			int ax = xp2 - xp1;
			int ay = yp2 - yp1;
			int bx = xp0 - xp1;
			int by = yp0 - yp1;
			double dot = Geom.dot(ax, ay, bx, by);
			int a2 = Geom.sumofsquare(ax, ay);
			double x = dot / a2 * ax + xp1;
			double y = dot / a2 * ay + yp1;
			
			System.out.printf("%.9f %.9f\n", x, y);
		}

		sc.close();
	}
	
	@SuppressWarnings("unused")
	private static class Geom {
		static int dot(int xa, int ya, int xb, int yb) {
			return xa * xb + ya * yb;
		}

		static int cross(int xa, int ya, int xb, int yb) {
			return xa * yb - xb * ya;
		}
		
		static int sumofsquare(int xa, int ya) {
			return xa * xa + ya * ya;
		}
	}
}

Measured memory_bytes: 33336
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)

int main(){
  int a,b;cin>>a>>b;
  REP(i,2000){
    if(((i*8)/100==a)&&(i*10)/100==b){
      cout<<i;
      return 0;
    }
  }
  cout<<"-1";
}

Measured memory_bytes: 256
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    pa = [abs(a) for a in A]

    count = 0
    for i in range(N):
        if A[i] < 0:
            count += 1

    if count % 2 == 0:
        ans = sum(pa)
    else:
        ans = sum(pa) - (min(pa) * 2)

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  set<string> s;
  string last;
  bool ok = true;
  rep(i, n) {
    string w;
    cin >> w;
    if(i == 0) {
      last = w;
      s.insert(w);
      continue;
    }
    if(last.back() != w[0]) ok = false;
    if(s.count(w)) ok = false;
    last = w;
    s.insert(w);
  }
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <queue>
#include <map>

using namespace std;
typedef pair<int, int> info;
typedef pair<string, info> data;

bool isInside( int index ){
  return ( 0 <= index && index < 8 );
}

int main(){

  map<string, bool> check_list;
  map<string, int> answer_list;
  char num;

  queue<data> que;
  que.push(data("01234567", info(0, 0)));
  answer_list["01234567"] = 0;

  while( !que.empty() ){
    data d = que.front(); que.pop();
    if( check_list[d.first] ) continue;

    string s = d.first;
    int index = d.second.first;
    int count = d.second.second;

    answer_list[s] = count;
    check_list[s] = true;

    if( index != 3 && isInside( index+1 ) ){
      string ns = s;
      ns[index] = ns[index+1];
      ns[index+1] = '0';
      que.push(data(ns, info(index+1, count+1)));
    }
    if( isInside( index+4 ) ){
      string ns = s;
      ns[index] = ns[index+4];
      ns[index+4] = '0';
      que.push(data(ns, info(index+4, count+1)));
    }
    if( index != 4 && isInside( index-1 ) ){
      string ns = s;
      ns[index] = ns[index-1];
      ns[index-1] = '0';
      que.push(data(ns, info(index-1, count+1)));
    }
    if( isInside( index-4 ) ){
      string ns = s;
      ns[index] = ns[index-4];
      ns[index-4] = '0';
      que.push(data(ns, info(index-4, count+1)));
    }
  }

  while(true){
    string goal = "";
    for(int i = 0; i < 8; i++){
      cin >> num;
      if(cin.eof()) return 0;
      goal += num;
    }
    cout << answer_list[goal] << endl;
  }

  return 0;
}

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

using namespace std;
using ll = long long;

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.length() <= k){
        cout << s << endl;
    }else{
        cout << s.substr(0,k) << "..." << endl;
    }
}

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

int n, a, b, c, d;

int main(){
  
  cin>>n>>a>>b>>c>>d;
  
  int v1 = n/a*b;
  if(n%a) v1+=b;
  
  int v2 = n/c*d;
  if(n%c) v2+=d;

  cout<<min(v1, v2)<<endl;
  
  return 0;
}



Measured memory_bytes: 3076
# include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b&&a != 0 && b != 0) {
		bool block[20][20];
		for (int i = 0; i <20; i++) {
			for (int j = 0; j <20; j++) {
				block[j][i] = false;
			}
		}
		int dp[20][20];
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			int c, d;
			cin >> c >> d;
			block[d][c] = true;
		}
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {
				if (block[j][i] == true) {
					dp[j][i] = 0;
				}
				else if (j == 1 && i == 1) {
					dp[j][i] = 1;
				}
				else if (j == 1) {
					if (dp[j][i - 1] != 0) {
						dp[j][i] = 1;
					}
					else {
						dp[j][i] = 0;
					}
				}
				else if (i == 1) {
					if (dp[j - 1][i] != 0) {
						dp[j][i] = 1;
					}
					else {
						dp[j][i] = 0;
					}
				}
				else {
					dp[j][i] = dp[j - 1][i] + dp[j][i - 1];
				}
			}
		}
		cout << dp[b][a] << endl;
	}
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
int main() {
string words;
  cin>>words;
  for(int i=0;i<words.size();i++){
if(words.at(i)=='P'){
 cout<<"P"; 
}
    else{
      cout<<"D";
  }
}
  cout<<endl;
}

Measured memory_bytes: 3748
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    int K; cin >> K;
    int rec[60], ans[60];
    int div = K / 50, md = K % 50;
    rep(i,0,50) rec[i] = div + (i < md);

    rep(i,0,50) {
        int S = 0;
        rep(j,0,50) {
            if(i != j) S += rec[j];
        }
        ans[i] = 50 * (rec[i] + 1) - S - 1;
    }
    cout << 50 << endl;
    rep(i,0,50) cout << (i ? " " : "") << ans[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> ods;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

ll dp[401][401];
ll cost[401][401];

void solve(ll t)
{
    // cout<<"Case #"<<t<<":\n";
    ll n;
    cin>>n;
    repf(i,0,n) repf(j,0,n) dp[i][j]=1e18;
    repf(i,0,n) repf(j,0,n) cost[i][j]=1e18;
    ll a[n];
    repf(i,0,n) cin>>a[i];
    repf(i,0,n) dp[i][i]=a[i],cost[i][i]=0;
    repf(l,2,n+1)
    {
        repf(i,0,n-l+1)
        {
            ll j=i+l-1;
            repf(k,i,j)
            {
                if(dp[i][j]>=dp[i][k]+dp[k+1][j])
                {
                    dp[i][j]=dp[i][k]+dp[k+1][j];
                    ll val=dp[i][j];
                    if(k-i+1>1) val+=cost[i][k];
                    if(j-k>1) val+=cost[k+1][j];
                    cost[i][j]=min(cost[i][j],val);
                    // if(i==0 && j==2) cout<<"vv "<<cost[i][j]<<" "<<cost[i][k]<<" "<<cost[k+1][j]<<" "<<k<<endl;  
                }
            }
        }
    }
    // cout<<cost[0][1]<<" "<<cost[2][2]<<endl;
    // cout<<dp[0][2]<<" "<<cost[0][2]<<endl;
    cout<<cost[0][n-1]<<endl;
}

int main()
{
    IOS;
    ll t;
    // cin>>t;
    t=1;
    ll tt=1;
    while(t--)
    {
        solve(tt);
        tt++;
    }
}     

Measured memory_bytes: 2816
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  if (S.substr(0, 4) == "YAKI") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
const int mod=(int)1e09+7;
 
int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(long long *)a-*(long long *)b;
}
 
int main(void){
	int a=in(),b=in();
	if(a%3==0||b%3==0||(a+b)%3==0){
		puts("Possible");
	}
	else{
		puts("Impossible");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int h[110],lb[110],rb[110],in[110];
ll dp[110][110];
int n;
vector<int> lsh;
inline ll quickpow(ll base,int ind)
{
	ll ans=1;
	while(ind>0)
	{
		if(ind&1)ans=ans*base%MOD;
		ind>>=1;
		base=base*base%MOD;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&h[i]);
		lsh.push_back(h[i]);
	}
	lsh.push_back(1);
	sort(lsh.begin(),lsh.end());
	lsh.erase(unique(lsh.begin(),lsh.end()),lsh.end());
	int m=lsh.size();
	for(int i=0;i<m;i++)
	{
		rb[i]=lsh[i];
		if(i)lb[i]=rb[i-1]+1;
		else lb[i]=1;
	}
	lb[m]=rb[m-1]+1;
	rb[m]=inf;
	for(int i=0;i<n;i++)
	{
		in[i]=lower_bound(lsh.begin(),lsh.end(),h[i])-lsh.begin();
//		cout<<i<<" "<<in[i]<<endl;
	}
//	system("pause");
	for(int i=1;i<=in[0]+1;i++)
	{
		int lowest=lb[i],higest=min(rb[i],h[0]);
//		cout<<"l "<<lowest<<" "<<higest<<endl;
		if(lowest<=higest)
			dp[0][i]=2ll*(quickpow(2,h[0]-lowest+1)-quickpow(2,h[0]-higest)+MOD)%MOD;
		else dp[0][i]=2;
//		cout<<i<<" "<<dp[0][i]<<endl;
	}
//	system("pause");
	for(int i=0;i+1<n;i++)
	{
		if(h[i]>=h[i+1])
		{
			for(int j=1;j<=in[i]+1;j++)
			{
				if(j<=in[i+1])
				{
					dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
				}
				else
				{
					dp[i+1][in[i+1]+1]=(dp[i+1][in[i+1]+1]+dp[i][j]*2ll)%MOD;
				}
			}
		}
		else
		{
			int ind=h[i+1]-h[i];
			for(int j=1;j<=in[i];j++)
			{
				dp[i+1][j]=(dp[i+1][j]+dp[i][j]*quickpow(2,ind)%MOD)%MOD;
			}
			for(int j=in[i]+1;j<=in[i+1]+1;j++)
			{
				int lowest=lb[j],higest=min(h[i+1],rb[j]);
	//			cout<<j<<" "<<lowest<<" "<<higest<<" "<<lb[j]<<" "<<rb[j]<<" "<<h[i+1]<<" "<<in[i+1]<<endl;
				if(lowest<=higest)
				{
					dp[i+1][j]=(dp[i+1][j]+
					dp[i][in[i]+1]*2ll%MOD*(quickpow(2,h[i+1]-lowest+1)-quickpow(2,h[i+1]-higest)+MOD)%MOD)%MOD;
				}
				else
				{
					dp[i+1][j]=(dp[i+1][j]+dp[i][in[i]+1]*2ll)%MOD;
				}
			}
		}
		
	//	for(int j=1;j<=in[i+1]+1;j++)
	//		cout<<j<<" "<<dp[i+1][j]<<endl;
	//	system("pause");
	}
	ll ans=0;
	for(int i=1;i<=in[n-1]+1;i++)
		ans=(ans+dp[n-1][i])%MOD;
	printf("%lld\n",ans);
	return 0;
}

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

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
    vector<int> W, K;
    rep(i, 10){
        W.push_back(-in());
    }
    rep(i, 10){
        K.push_back(-in());
    }
    sort(W.begin(), W.end());
    sort(K.begin(), K.end());
    printf("%d %d\n", -(W[0] + W[1] + W[2]), -(K[0] + K[1] + K[2]));
    return (0);
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    string s;
    int a, n, tmp, ans=777, i;
    cin >> s;
    n=s.size();
    for(i=0;i<=n-3;i++){
        tmp=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        if(ans>abs(tmp-753))ans=abs(tmp-753);
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    b = [int(input()) for _ in range(N)]

    for bb in b:
        for i in range(3):
            for j in range(3):
                if bb == A[i][j]:
                    A[i][j] = 0

    for i in range(3):
        if A[i][0] == 0 and A[i][1] == 0 and A[i][2] == 0:
            print('Yes')
            exit()

    for i in range(3):
        if A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0:
            print('Yes')
            exit()

    if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
        print('Yes')
        exit()
    if A[2][0] == 0 and A[1][1] == 0 and A[0][2] == 0:
        print('Yes')
        exit()

    print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>
#include <iterator>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int INF = 1e9 + 5;

int main() {
	ll a = 0, b = 0, c = 0, k = 0;
	cin >> a >> b >> c >> k;
	if(k % 2 != 0){
		cout << b-a << endl;
	}
	else{
		cout << a - b << endl;
	}



	

    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N = 2e6 + 50, P = 998244353;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int ans, n, m, fac[N], inv[N]; 

int C(int n, int m) {
	if (n < 0 || m > n) return 0;
	return mul(fac[n], mul(inv[m], inv[n - m]));
}
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	cin >> n >> m;
	fac[0] = 1; lop(i, 1, N) fac[i] = mul(fac[i - 1], i); 
	inv[1] = 1; lop(i, 2, N) inv[i] = mul(P - P / i, inv[P % i]); 
	inv[0] = 1; lop(i, 1, N) inv[i] = mul(inv[i - 1], inv[i]);
	rep(o, 0, min(n, m)) {
		int t = 3 * m - o;
		if (t % 2) continue;
		int ill = add(mul(o,C(t/2+n-1-m,n-1)),mul(n-o,C(t/2+n-1-m-1,n-1)));
		ans=add(ans,mul(C(n,o),sub(C(t/2+n-1,n-1),ill)));
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vint A(N); cin >> A;
	if (A[0] != 0) { cout << -1 << endl; return; }

	ll num = 0;
	for (int i = 1; i < N; i++) {
		if (A[i] > A[i-1]+1) { cout << -1 << endl; return; }
		if (A[i] > A[i-1]) num++;
		else num += A[i];
	}
	cout << num << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3908
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    cin>>N;
    if(N%2 == 0){
        cout<<N/2 -1 <<endl;
    }else{
        cout<<N/2 << endl;
    }
}

Measured memory_bytes: 256