akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdlib>

using namespace std;

int main(){
	int N;
	cin >> N;

	int oturi = N % 1000;
	if(oturi == 0){
		cout << 0 << "\n";
	}
	else{
		cout << 1000 - oturi << "\n";
	}
}


Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;

int main(void){
    int n;
    cin >> n;
    bool judge = true;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a%2==0 && (a%3!=0&&a%5!=0)){
            judge = false;
            break;
        }
    }
    if(judge) cout << "APPROVED\n";
    else cout << "DENIED\n";
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include<algorithm>
using namespace std;
int main(){
	int n, k,p[1010],a=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> p[i];
	sort(p, p + n);
	for (int i = 0; i < k; i++)
		a += p[i];
	cout << a;
}

Measured memory_bytes: 3600
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
def main():
    N = I()
    A = LI()
    for a in A:
        if a % 2 == 0:
            if a % 3 != 0 and a % 5 !=0:
                print('DENIED')
                exit()
    print('APPROVED')

if __name__ == "__main__":
    main()


Measured memory_bytes: 74644
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    while (true){
        int H, W;
        cin >> H >> W;
        if (H == 0){
            break;
        }
        for (int i = 0; i < H; i++){
            for (int i = 0; i < W; i++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3228
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	inputs := scanNums()
	//x := inputs[0]
	//y := inputs[1]
	//z := inputs[2]
	k := inputs[3]
	alist := scanNums()
	blist := scanNums()
	clist := scanNums()

	ans := calc(alist, blist, clist, k)
	for _, a := range ans {
		fmt.Println(a)
	}

}

func calc(alist []int, blist []int, clist []int, k int) []int {
	ab := make([]int, 1000000)
	abc := make([]int, 1000000)

	for _, a := range alist {
		for _, b := range blist {
			ab = append(ab, a+b)
		}
	}

	sort.Sort(sort.Reverse(sort.IntSlice(ab)))

	for _, c := range clist {
		for _, a := range ab[0:k] {
			abc = append(abc, c+a)
		}
	}

	sort.Sort(sort.Reverse(sort.IntSlice(abc)))

	return abc[0:k]
}

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

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

func scanNums() (nums []int) {
	s := nextString()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextString()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}


Measured memory_bytes: 173440
#include <cstdio>
using namespace std;
int N, Q, l, r, sum[100000]; char S[100000];
int main() {
  scanf("%d %d %s", &N, &Q, &S);
  for(int i = 1; i < N; ++i) {
    sum[i] = sum[i-1]+(S[i-1]=='A'&&S[i]=='C');
  }
  for(int i = 0; i < Q; ++i) {
    scanf("%d %d", &l, &r);
    printf("%d\n", sum[r-1]-sum[l-1]);
  }
}

Measured memory_bytes: 1280
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String st;
	    while((st=sc.readLine())!=null){
		int[][] map = new int[12][12];
		for(int i=0; i<8; i++)
		    if(st.charAt(i)=='1')
			map[1][i+1] = 1;		
		for(int j=1; j<8; j++){
		    st=sc.readLine();
		    for(int i=0; i<8; i++)
			if(st.charAt(i)=='1')
			    map[j+1][i+1] = 1;
		}
		int sj=0, si=0;
		back:
		for(int j=1; j<=8; j++)
		    for(int i=1; i<=8; i++)
			if(map[j][i]==1){
			    sj = j; si = i;
			    break back;
			}
		char e;
		
		if(map[sj+3][si] == 1)
		    e = 'B';
		else if(map[sj][si+3] == 1)
		    e = 'C';
		else if(map[sj+2][si-1] == 1)
		    e = 'D';
		else if(map[sj+2][si+1] == 1)
		    e = 'F';
		else
		    if(map[sj+1][si] == 0)
			e = 'E';
		    else if(map[sj+1][si+1] == 0)
			e = 'G';
		    else
			e = 'A';
		System.out.println(e);
		st = sc.readLine();
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 10000
n=int(input())
h=list(map(int,input().split()))
if n==1:
    print(h[0])
elif n==2:
    print(max(h))
else:
    h.append(0)
    h.insert(0,0)
    
    ans=0
    f=[0 for i in range(n+2)]
    
    for i in range(10010):
        a=1
        x=[]
        for j in range(n+2):
            if h[j]<=f[j]:
                x.append(j)
        m=len(x)
        if m==n+2:
            break
        a=m-1
        for j in range(m-1):
            if x[j]+1==x[j+1]:
                a-=1
        ans+=a
        for j in range(n+2):
            f[j]+=1
        
    print(ans)
            
            
            
            
        
    
        
        
        
          


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

const int maxn = 1e5 + 5;

int a[maxn];
int n;

bool find(int key){
	int l = 1,r = n+1;;
	while(l < r){
		int mid = (l+r)>>1;
		if(a[mid] == key)return true;
		else if(a[mid] > key)r = mid;	
		else l = mid+1;
	}
	return false;
}

int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n; i++){
		scanf("%d",&a[i]);
	}
	int m;
	int ans = 0;
	scanf("%d",&m);
	for(int i = 1;i <= m; i++){
		int x;
		scanf("%d",&x);
		if(find(x))ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define FOREACH(it,c) for(__typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
#define TIMES(i,n) for(int i = 0; i < (n); ++i)

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

    int N;
    while(cin >> N) {
        vector<int> phrases(394, 0);
        int maxlen = 0;
        TIMES(i, N) {
            int S, L, P;
            cin >> S >> L >> P;
            for(int l = S; l <= L; ++l) {
                phrases[l] = max(phrases[l], P);
            }
            maxlen = max(maxlen, L);
        }
        int M;
        cin >> M;
        vector<int> WS(M);
        TIMES(i, M) {
            cin >> WS[i];
        }
        vector<int> ans;
        FOREACH(it, WS) {
            const int W = *it;
            vector<int> dp(W+1, 0);
            TIMES(pos, W) {
                TIMES(len, maxlen+1) {
                    const int next = pos+len;
                    if(next > W) break;
                    dp[next] = max(dp[next], dp[pos]+phrases[len]);
                }
            }
            if(dp[W] == 0) {
                ans.clear();
                ans.push_back(-1);
                break;
            } else {
                ans.push_back(dp[W]);
            }
        }
        FOREACH(it, ans) {
            cout << *it << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    int b = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= m; i++) {
        for(int j = 0; j < n - 1; j++) {
            if((a[j] % i) > (a[j + 1] % i)) {
                b = a[j];
                a[j] = a[j + 1];
                a[j + 1] = b;
            }
        }
    }
    for(int i = 0; i < n; i++) {
        cout << a[i] << endl;
    }
    return 0;
}


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

char S[10] = {0};

int main()
{
    scanf("%s",S);
    if(S[0] == S[1] && S[1] == S[2])printf("Yes\n");
    else if(S[1] == S[2] && S[2] == S[3])printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<int> x(n), y(n), h(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	int ma = 100;
	for (int cy = 0; cy <= ma; cy++) {
		for (int cx = 0; cx <= ma; cx++) {
			int needH = -1;
			for (int i = 0; i < n; i++) {
				if (h[i] > 0) {
					int tmp = h[i] + abs(cy - y[i]) + abs(cx - x[i]);

					if (needH == -1) {
						needH = tmp;
						continue;
					}

					if (needH != tmp) {
						needH = -2;
						break;
					}
				}
			}

			if (needH == -2) {
				continue;
			}

			for (int i = 0; i < n; i++) {
				if (h[i] == 0) {
					int dist = abs(cy - y[i]) + abs(cx - x[i]);
					if (needH > dist) {
						needH = -2;
						break;
					}
				}
			}

			if (needH == -2) {
				continue;
			}
			cout << cx << " " <<  cy << " " << needH << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define forn(i,n) for(int i = 0; i< n;++i)
ll MOD = 1e9 + 7;
ll INF = 1e17 + 9;

void update(vector<ll>& st,int root,int s, int e, int i, ll val){
	int mid = (s+e)/2;
	if( s < e ){
		if (i >= s &&  i <= mid){
			update(st,2*root+1,s,mid,i,val);
		}
		else{
			update(st,2*root+2,mid+1,e,i,val);
		}
		st[root] = max(st[2*root+1],st[2*root+2]);
	}
	else{
		st[root] = val;
	}
}
			
ll query(vector<ll>& st,int root, int s, int e, int i, int j){//i ,j are query paarmenter, s&ee are tree param
	if(i > e or j < s){ return -INF;}
	if(i == s && j == e){
		return st[root];
	}
	int mid = (s+e)/2;
	if(j <= mid){  //i-j lies on left side
		return query(st,2*root+1,s,mid,i,j);
	}
	else if(s > mid){ //i-j lies on right side
		return query(st,2*root+2,mid+1,e,i,j);
	}
	else{
		return max(query(st,2*root+1,s,mid,i,mid),query(st,2*root+2,mid+1,e,mid+1,j));
	}
}
	


int main() {
	int n;
	cin >> n;
	vector<ll> height(n,0);
	vector<ll> beauty(n,0);
	forn(i,n) cin >> height[i];
	forn(i,n) cin >> beauty[i];
	int max_size = 4e5 + 3;
	vector<ll> st(4e6 + 3,0);  //segment tree of heights
	
	//dp[i] = arr[i] intialize
	//dp[i] -> max sum of beauty of remaing flowers if including ith flower
	//dp[n-1]-> res
	vector<ll> dp(n,0);
	forn(i,n) dp[i] = beauty[i];
	
	for(int i = 0; i < n; ++i){
		//ll maxx = 0;
		ll maxx = query(st,0,0,max_size-1,1,height[i]-1);
		dp[i] = max(dp[i],beauty[i] + maxx);
		update(st,0,0,max_size-1,height[i],dp[i]);
	}
	ll res = 0;
	for(ll x : dp){
		res = max(res,x);
	}
	cout << res << endl;
}


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

char s[100001],s2[100001];

int main(){
	int len,i;
    gets(s);
	len=strlen(s);
	for(i=0;i<len;i++)
	{
		if(len-i-1>=0)
		{
			if(s[i]=='b') s2[len-i-1]='d';
		    if(s[i]=='d') s2[len-i-1]='b';
		    if(s[i]=='p') s2[len-i-1]='q';
		    if(s[i]=='q') s2[len-i-1]='p';
		}
		
	}
	for(i=0;i<len;i++)
	{
		if(s[i]!=s2[i]) 
		{
			cout<<"No"<<endl;
			return 0;
		}
		
	}
	cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;
const int MOD = 998244353;

struct E {
  int a, b, c;
};

int main(void) {
  int L;
  scanf("%d", &L);
  L--;
  int n = 2;
  for(; L > (1<<n)-1;) {
    ++n;
  }
  vector<E> es;
  for(int i = 1; n-i >= 1; ++i) {
    es.push_back((E){n-i, n-i+1, 0});
    es.push_back((E){n-i, n-i+1, 1<<(i-1)});
  }
  if(L > 1) {
    for(int i = n-2; i >= 0; --i) {
      if(L & (1 << i)) {
        int mask = (1 << (i+1))-1;
        int c = L & ~mask;
        es.push_back((E){1, n-i, c});
      }
    }
    es.push_back((E){1, n, L});
  }
  printf("%d %d\n", n, (int)es.size());
  REP(i, es.size()) {
    printf("%d %d %d\n", es[i].a, es[i].b, es[i].c);
  }
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};

int main(){
  double r; cin>>r;
  double pi = 3.141592;
  printf("%.2f", 2*pi*r);
  return 0;
}


Measured memory_bytes: 3780
#include<cstdio>
using namespace std;

char right[12] = "yhnujmikolp";

bool check(char c) { // right : T
  for (int i = 0; i < 11; i++) if (right[i] == c) return true;
  return false;
}

int main() {
  char s[50];
  while (1) {
    scanf("%s", s);
    if (s[0] == '#') break;
    int counter = 0;
    bool now = check(s[0]);
    for (int i = 1; s[i] != 0; i++) {
      if (now != check(s[i])) {
        now = check(s[i]);
        counter++;
      }
    }
    printf("%d\n", counter);
  }
}



Measured memory_bytes: 2676
using System;

namespace _01
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long sum1 = n*(n + 1) / 2;
            long sum2 = 0;
            for(long i = 1; i <= n; ++i)
            {
                if(i%3==0 || i % 5 == 0)
                {
                    sum2 = sum2 + i;
                }
            }
            Console.WriteLine(sum1 - sum2);
        }
    }
}


Measured memory_bytes: 27448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;



int main() {
	int A, B, C, D, E;
	int tmp,div,ans=0,buf=0;
	rep(i, 5) {
		cin >> tmp;
		if (tmp%10!=0)
		{
			div = tmp / 10 * 10 + 10;
			buf = max(buf, div - tmp);
			ans += div;
			
		}
		else {
			div = tmp;
			ans += div;
		}
	}
	cout << ans - buf << endl;
}

Measured memory_bytes: 3596
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

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 <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

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

  int H, W;
  cin >> H >> W;
  vector<vector<int>> grid(H + 1, vector<int>(W + 1, 0));
  REP(h, H) {
    REP(w, W) { cin >> grid[h][w]; }
  }
  REP(h, H) {
    REP(w, W) {
      int b;
      cin >> b;
      grid[h][w] = abs(grid[h][w] - b);
    }
  }
  constexpr int MAX = 6401;
  vector<vector<vector<bool>>> dp(
      H + 1, vector<vector<bool>>(W + 1, vector<bool>(MAX, false)));
  dp[0][0][grid[0][0]] = true;
  REP(h, H) {
    REP(w, W) {
      REP(i, MAX) {
        if (dp[h][w][i]) {
          if (i + grid[h][w + 1] < MAX) {
            dp[h][w + 1][i + grid[h][w + 1]] = true;
          }
          dp[h][w + 1][abs(i - grid[h][w + 1])] = true;
          if (i + grid[h + 1][w] < MAX) {
            dp[h + 1][w][i + grid[h + 1][w]] = true;
          }
          dp[h + 1][w][abs(i - grid[h + 1][w])] = true;
        }
      }
    }
  }
  REP(i, MAX) {
    if (dp[H - 1][W - 1][i]) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 6016
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    res = K
    step = [-1 for _ in range(N)]
    que = queue.Queue()
    que.put(0)
    step[0] = 0
    while not que.empty():
        nc = que.get()
        nn = A[nc]
        nn -= 1
        res -= 1
        if step[nn] == -1:
            step[nn] = step[nc] + 1
            if res == 0:
                return print(nn + 1)
            que.put(nn)
        else:
            start = nn
            closer = [nn]
            while True:
                nn = A[nn] - 1
                if nn != start:
                    closer.append(nn)
                else:
                    break
            ans = res % len(closer)
            print(closer[ans] + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103624
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int a, b, c, d;
	cin >> a >> b;
	if (a <= b) {
		cout << a << endl;
	}
	else {
		cout << a - 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

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

int main(){
	DRII(h,w);
	REP(i,h)RS(s[i]);
	REP(i,h){
		REP(j,w){
			if(s[i][j]=='.')continue;
			int nn=0;
			REP(d,4){
				int ny=i+dy[d],nx=j+dx[d];
				if(ny<0||ny>=h||nx<0||nx>=w)continue;
				nn+=s[ny][nx]=='#';
			}
			if((i==0&&j==0)||(i==h-1&&j==w-1)){
				if(nn>=2){puts("Impossible");return 0;}
			}
			else{
				if(nn>2){puts("Impossible");return 0;}
			}
		}
	}
	int y=0,x=0;
	REP(i,h+w-2){
		int ny=y+1,nx=x;
		if(ny>=0&&ny<h&&nx>=0&&nx<w){
			if(s[ny][nx]=='#'){
				y++;continue;
			}
		}
		ny=y,nx=x+1;
		if(ny>=0&&ny<h&&nx>=0&&nx<w){
			if(s[ny][nx]=='#'){
				x++;continue;
			}
		}
		puts("Impossible");return 0;
	}
	puts("Possible");
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

flag = 1
cnt = 0

for _ in range(n-1):
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                cnt += 1
print(" ".join(map(str, a)))
print(cnt)


Measured memory_bytes: 5600
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
const ll MOD = (pow(10, 9) + 7);

int main() {
	ll N; cin >> N;

	ll ans = 1;
	for (int i = 1; i <= N; i++) {
		ans *= i;
		ans %= MOD;
	}
	cout << ans << endl;
}

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

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

    char oneDigit = s[s.size()-1];
    if(oneDigit == '2' || oneDigit == '4' || oneDigit == '5' || oneDigit == '7' || oneDigit == '9'){
        cout << "hon";
    }else if(oneDigit == '0' || oneDigit == '1' || oneDigit == '6' || oneDigit == '8'){
        cout << "pon";
    }else{
        cout << "bon";
    }
    return 0;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        for(int i = x - k + 1; i < x + k; i++, System.out.print(" ")) {
            System.out.print(i);
        }
        System.out.println();

    } 
}

Measured memory_bytes: 21972
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, m; cin>>n>>m;
    vector<int> cnt(n, 1);
    vector<int> red(n, false);
    red[0] = true;
    for(int i=0; i<m; i++){
        int x, y; cin>>x>>y;
        x--, y--;
        if(red[x]){
            red[y] = true;
            cnt[x]--, cnt[y]++;
            if(cnt[x] == 0) red[x] = false;
        }
        else{
            cnt[x]--, cnt[y]++;
        }
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        ans += red[i];
    }

    cout << ans << endl;
}

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

int main() {
  char atDeer, topDeer; cin >> atDeer >> topDeer;
  if (atDeer == 'H') {
    cout << topDeer;
  } else {
    if (topDeer == 'H') {
      cout << 'D';
    } else {
      cout << 'H';
    }
  }
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define vl vector<ll>
#define pll pair<ll,ll>
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i= 0;i < a;i++)
#define rep1(i,a) for(ll i= 1;i < a;i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define pb push_back
#define sz(v) v.size()
#define all(a) a.begin(), a.end()
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1e6+5
#define MOD 1000000007
#define el "\n"
const ll INF = 2e9+5;
  
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll isPrime(ll n){if(n<=3) return 1;if(n%2==0||n%3==0) return 0;
for(ll j=5;j*j<=n;j+=6){if(n%j == 0||n%(j+2) == 0) return 0;}return 1;}
 
using namespace std;
void solve(){
   ll n;
   cin>>n;
   vector<ld> p(n);
   rep(i,n)cin>>p[i];
   vector<vector<double>> dp(n+1,vector<double>(n+1,0.0));
   dp[0][0] = 1.0;
   // dp[0][1] = 1-p[0];
   // dp[1][0] = p[0];
   ll i=1,j=1;
   for(ll i=1;i<=n;i++){
      for(ll j=0;j<=i;j++){
         if(j==0) dp[i][j] = dp[i-1][j]*(1.0-p[i-1]);
         else dp[i][j] = dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1.0-p[i-1]);
      }
   }
   ld ans=0;
   for(ll i=n;i>n/2;i--){
      ans += dp[n][i];
   }
   cout<<fixed<<setprecision(10)<<ans;
}
 
int main() {
   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r" , stdin);
      freopen("output.txt", "w" , stdout);
   #endif
   ios::sync_with_stdio(0); 
   cin.tie(0); cout.tie(0);   
   ll t;
   // cin>>t;
   t = 1;
   ll tc=0;
   while(tc++<t){
      // cout<<"Case #"<<tc<<": ";
      solve();
   }
   cerr<<"Time taken : "<<(double)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}


Measured memory_bytes: 73724
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int lim=1000000;
int a,b,c,t1,t2,t3,i,j,k,n,m,w;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	for (i=1;i<=lim;i++){
		if (a%2||b%2||c%2) break;
		t1=b/2+c/2;t2=a/2+c/2;t3=a/2+b/2;
		a=t1;b=t2;c=t3;
	}
	if (i>lim) puts("-1");else printf("%d\n",i-1);
	return 0;
}

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

int main() {
	long long n,x;cin>>n>>x;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	vector<vector<long long>> v(n,vector<long long>(n,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			v[i][j]=a[(i+j)%n];
//			cout<<v[i][j]<<' ';
		}
//		cout<<endl;
	}

	for(int i=0;i<n;i++){
		for(int j=1;j<n;j++){
			if(v[i][j]>v[i][j-1]){
				v[i][j]=v[i][j-1];
			}
		}
	}
	long long ans=0;
	for(int i=0;i<n;i++){
		long long anst=0;
		for(int j=0;j<n;j++){
			if(i<j){
				anst+=v[j-i][i];
			}else{
				anst+=v[(j-i+n)%n][i];
			}
		}
		anst+=i*x;
		if(ans==0)ans=anst;
		if(ans>anst)ans=anst;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 31616
#include <iostream>

using namespace std;

int main() {
  int X;
  int Y;
  cin >> X >> Y;
  for (int i = 0; i <= X; ++i) {
    if (i * 2 + (X - i) * 4 == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3632
/*
 * atcoder/abc099_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int MAX_N = 100100;
const int MAX_M = 100;
const ll INF = 100000000000000000;
int N, M;
vector<ll> A;
ll dp[MAX_N][MAX_M];

void solve() {
  cin >> N;
  A.push_back(1);
  ll a = 6;
  while (a <= N) {
    A.push_back(a);
    a *= 6;
  }
  a = 9;
  while (a <= N) {
    A.push_back(a);
    a *= 9;
  }
  M = A.size();
  loop(n,0,N+1) loop(m,0,M+1) dp[n][m] = INF;
  loop(n,0,N+1) {
    loop(m,0,M) {
      if (n==0) { dp[0][m] = 0; continue; }
      if (m==0) { dp[n][0] = n; continue; }
      chmin(dp[n][m], dp[n][m-1]);
      if (n-A[m]>=0) chmin(dp[n][m], 1 + dp[n-A[m]][m]);
    }
  }
  cout << dp[N][M-1] << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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

int main(void) {
  string weather[3] = {"Sunny", "Cloudy", "Rainy"};
  string today;

  cin >> today;

  for (int i = 0; i < 3; i++) 
    if (weather[i] == today)
      cout << weather[(i+1)%3];

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp36 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int A = st[0];
            int B = st[1];
            int C = st[2];

            if (A + B >= C) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}


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

int mod = 1000000007;

int main()
{
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for (int x = 0; x <= K; x++)
    {
        for (int y = 0; y <= K; y++)
        {
            int z = S - x - y;
            if (0 <= z && z <= K)
                ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

void solve() {
    cini(n);
    cinai(a,n);
    int ans=0;
    for(int i=0; i<n; i++) {
        if((i+1)%2 && a[i]%2)
            ans++;
    }
    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3608
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int max=0,a[200010],i,k,n;
  scanf("%d %d\n",&k,&n);
  for(i=0;i<n;i++){
    scanf("%d ",&a[i]);
  }
  a[n]=a[0]+k;
  for(i=0;i<n;i++){
    if(max<a[i+1]-a[i]){
      max=a[i+1]-a[i];
    }
  }
  printf("%d\n",k-max);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

vector<int> adj[100005];
int mx = 0;
map<pair<int, int>, int> m;

vector<int> color(100005, 0);

void dfs(int node, int parent, int col) {
	int cnt = 1;
	for(auto it: adj[node]) {
		if(it != parent) {
			if(cnt == col) {
				++cnt;
			}
			mx = max(mx, col);
			// cout << m[{node, it}] << "\n";
			int x = m[{node, it}];
			color[x] = cnt;
			dfs(it, node, cnt);
			++cnt;
		}
	}
}

int main() {
	IOS;

	int n;
	cin >> n;
	for(int i = 0; i < n-1; ++i) {
		int a, b;
		cin >> a >> b;
		m[{a, b}] = i+1;
		m[{b, a}] = i+1;
		adj[a].push_back(b);
		adj[b].push_back(a);
		mx = max(mx, (int)adj[a].size());
		mx = max(mx, (int)adj[b].size());
	}

	dfs(1, 1, 0);
	cout << mx << "\n";
	for(int i = 1; i <= n-1; ++i) {
		cout << color[i] << "\n";
	}
    return 0;
}

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

const int MAX_N = 1001; //要素の個数を1001と固定
int f[MAX_N + 1] = {2, 3};//最初に2,

int par[MAX_N];  //ノードの親を格納
int rank[MAX_N]; //木の高さ

/*フィボナッチ数列を計算して、配列fに順に入れる*/
void fib_init(){
  for(int i = 2; i < MAX_N+1; i++){
    f[i] = (f[i-1] + f[i-2]) % MAX_N;
  }
}

//init
void init(int n){
  for(int i = 0; i < n; i++){
    par[i] = i;
    rank[i];
  }
}

/*xのルートが何かを見つける*/
int find(int x){
  if(par[x] == x){ 
    //自分がルート
    return x;
  }else{
    //自分の親がいるなら、その親について再帰的に探す
    return par[x] = find(par[x]);
  }
}

/*集合を連結させる*/
void unite(int x, int y){
  x = find(x);
  y = find(y);
  //xとyのルートが同じ、つまり既に連結しているなら何もしない
  if(x == y) return;

  if(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

// x & y is same subset?
bool same(int x, int y){
  return find(x) == find(y);
}

/*------------------------------------------*/
int main()
{
  fib_init(); //init of "fib"

  int v, d; // v == num of nodes 
            //d is ?

  /*
  //チェック
  for(int i = 0;i < MAX_N; i++)
    {
      cout << f[i] << " ";
    }

  cout << endl;
  */





  while(cin >> v >> d){
    init(v); // init of "node"
    int memo[MAX_N+1] = {0};

    //if...  |f(i) - f(j)| < d  then... i & j is same subset.
    for(int i = 0; i < v; i++){
      for(int j = i + 1; j < v; j++){
	if(abs(f[i] - f[j]) < d){
	  unite(i, j); // if all pair nodes is upper state ok , unite() do! 
	}
      }
    }
    
    // count num of subset
    int ans = 0;
    for(int i = 0; i < v; i++){
      int root = find(i);
      if(memo[root] == 0)
	{
	  memo[root] = 1;
	  ans++;
	}
    }
    //output
    cout << ans << endl;
  }


}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	string s;
	cin >> s;
	int ans = 0;
	for (auto x : s)
		ans += (x - '0');
	if (ans % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

//!

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  if (x == y)
    cout << "a == b" << endl;
  else if (x > y)
    cout << "a > b" << endl;
  else
    cout << "a < b" << endl;
  return 0;
}

Measured memory_bytes: 3044
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8[:],i8)", cache=True)
def binary_search(a, key):
    """Meguru type binary search"""
    ng = -1
    ok = len(a)

    def is_ok(a, key, idx):
        if key <= a[idx]:
            return True
        else:
            return False

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(a, key, mid):
            ok = mid
        else:
            ng = mid

    return ok


@nb.njit("i8[:](i8,i8[:],i8[:],i8[:])", cache=True)
def solve(Q, S, T, X):
    ans = np.zeros(shape=Q, dtype=np.int64)
    for q, x in enumerate(X):
        min_dist = 10 ** 11
        # x --> s --> t
        i = binary_search(S, x)
        if 0 < i:
            l_s = S[i - 1]
            dist_s = abs(x - l_s)
            j = binary_search(T, l_s)
            l_t, r_t = T[j - 1], T[j]
            dist_t = min(abs(l_s - l_t), abs(r_t - l_s)) if 0 < j else abs(r_t - l_s)
            min_dist = min(min_dist, dist_s + dist_t)
        r_s = S[i]
        dist_s = abs(r_s - x)
        j = binary_search(T, r_s)
        l_t, r_t = T[j - 1], T[j]
        dist_t = min(abs(r_s - l_t), abs(r_t - r_s)) if 0 < j else abs(r_t - r_s)
        min_dist = min(min_dist, dist_s + dist_t)

        # x --> t --> s
        i = binary_search(T, x)
        if 0 < i:
            l_t = T[i - 1]
            dist_t = abs(l_t - x)
            j = binary_search(S, l_t)
            l_s, r_s = S[j - 1], S[j]
            dist_s = min(abs(l_t - l_s), abs(r_s - l_t)) if 0 < j else abs(r_s - l_t)
            min_dist = min(min_dist, dist_s + dist_t)
        r_t = T[i]
        dist_t = abs(r_t - x)
        j = binary_search(S, r_t)
        l_s, r_s = S[j - 1], S[j]
        dist_s = min(abs(r_t - l_s), abs(r_s - r_t)) if 0 < j else abs(r_s - r_t)
        min_dist = min(min_dist, dist_s + dist_t)

        ans[q] = min_dist
    return ans


def main():
    A, B, Q = map(int, input().split())
    S = np.zeros(shape=A, dtype=np.int64)
    T = np.zeros(shape=B, dtype=np.int64)
    X = np.zeros(shape=Q, dtype=np.int64)
    for i in range(A):
        S[i] = int(input())
    for i in range(B):
        T[i] = int(input())
    for i in range(Q):
        X[i] = int(input())

    ans = solve(Q, S, T, X)
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 118436
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main() {
	int n, x;
	while (1) {
		cin >> n;
		if (n == 0) break;
		vi d(n);
		rep(i, 0, n) {
			cin >> d[i];
		}
		cin >> x;
		int cnt = 0, l = 0, r = n - 1;
		while (l<=r) {
			cnt++;
			int mid = (l + r) / 2;
			if (d[mid] > x) {
				r = mid - 1;
			}
			else if (d[mid] < x) {
				l = mid + 1;
			}
			else if(d[mid]==x){
				break;
			}
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1192
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

K,S = mint()
ans = 0
for X in range(K+1):
    for Y in range(K+1):
        if S-X-Y in range(K+1):
            ans += 1
print(ans)            

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

int main(){
    int a,b,c,x,ans=0;
    cin >> a >> b >> c >> x;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(x==500*i+100*j+50*k)ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n;
    cin >> n;
    int a[n],b[n];
    
    inrep(n,a);
    inrep(n,b);

    int c[n];
    rep(i,0,n)c[i] = a[i]-b[i];

    ll ans = 0;
    rep(i,0,n)if(c[i] > 0)ans+= c[i];

    P(ans);
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAKS 1000000000000000LL

using namespace std;

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



int main()
{
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(a<=0 && b>=0)
        cout<<"Zero";
    else if(a<0 && (-a-max(-b,0))%2==0)
        cout<<"Negative";
    else cout<<"Positive";
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [None] * N

def solve(idx):
    if dp[idx] is not None:
        return dp[idx]

    if idx == N - 1:
        dp[idx] = 0
    elif idx == N - 2:
        dp[idx] = abs(h[idx] - h[idx + 1])
    else:
        temp = 10**10
        for k in range(1, K + 1):
            if idx + k == N:
                break
            if dp[idx + k] is None:
                temp = min(temp, solve(idx + k) + abs(h[idx] - h[idx + k]))
            else:
                temp = min(temp, dp[idx + k] + abs(h[idx] - h[idx + k]))
        dp[idx] = temp
    return dp[idx]

print(solve(0))

Measured memory_bytes: 217012