akhauriyash/Code-Regression huggingface dataset:
// B.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int p = a[i] == b[i], q = b[i] == c[i], r = c[i] == a[i];
		if (p & q & r) {
			;
		} else if (p || q || r) {
			++ans;
		} else {
			ans += 2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int i,x,y;
	string s;
	cin >> s;
	x=s.size();
	y=0;
	for(i=0;i<s.size();i++){
		if(s[i]=='A' && i<x){
			x=i;
		}
		if(s[i]=='Z' && i>y){
			y=i;
		}
	}
	cout << y-x+1 << endl;
	return 0;
}


Measured memory_bytes: 640
A = []
for i in range(3):
  temp = list(map(int,input().split()))
  A.append(temp)

if A[0][0]+A[1][1] == A[0][1]+A[1][0] and \
A[0][1]+A[1][2] == A[0][2]+A[1][1] and \
A[1][0]+A[2][1] == A[1][1]+A[2][0] and \
A[1][1]+A[2][2] == A[1][2]+A[2][1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <set>

#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

//priority_queue<int, vector<int>, greater<int>> min_heap;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//   return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
int a[100001];
int main() { // E 
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	rep(i, n) {
		int x; cin >> x;
		a[x] = i;
	}

	for (int i = 1; i <= n; i++) {
		cout << a[i] + 1 << ' ';
	}



}

Measured memory_bytes: 1280
while True:
    (n,m) = map(int,input().split())
    if n == 0 and m == 0:
        break
    iss = list(map(int, input().split()))
    best = max([ (iss[i] + iss[j] if not ( i == j) and iss[i] + iss[j] <= m else -1) for i in range(0,n) for j in range(0,n) ])
    if(best < 0):
        print("NONE")
    else:
        print(best)


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pa;

#define fst first
#define snd second
#define pb push_back

const int maxn=300005,maxm=1006;
const double pi=acos(-1.0);
//const ll mod=1000000007;
const ll mod=998244353;
const double eps=1e-8;

int n,k;
int a[maxn];
int b[maxn];

bool fl=0;

void cal()
{
    if(fl) return;
    int i,j;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
        int mi=max(0,i-a[i]);
        int ma=min(n,i+a[i]+1);
        b[mi]++;b[ma]--;
    }
    a[0]=b[0];
    for(i=1;i<n;i++)
    {
        a[i]=a[i-1]+b[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]!=n) break;
    }
    if(i>=n) fl=1;
}

int main()
{
	int i,j;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++) scanf("%d",a+i);
	for(int ca=1;ca<=k;ca++)
    {
        cal();
    }
    for(i=0;i<n;i++) printf("%d%c",a[i],i==n-1?'\n':' ');
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N; cin >> N;
  if(N==1){
    cout<<"Hello World"<<endl;
  }
  else{
    int a, b; cin >> a >> b;
    cout<<a+b<<endl;
  }

    return 0;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl; 
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
inline int in() { int x; cin>>x; return x; }
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}

//}}}

// -------------------- Spliters ------------------------
const int maxn = 200050;

int a[maxn];

int n;
bool judge(int x) {
	int last = -1;
	int nearest = 9999999;
	int zo = 0;
	int mid = n / 2;
	rep(i, 0, n) {
		int cur = x <= a[i] ? 1 : 0;
		if(cur == last) {
			if(nearest > abs(i - mid)) {
				nearest = abs(i - mid);
				zo = cur;
			}
		}
		last = cur;
	}
	last = -1;
	for(int i = n - 1; i >= 0; i--) {
		int cur = x <= a[i] ? 1 : 0;
		if(cur == last) {
			if(nearest > abs(i - mid)) {
				nearest = abs(i - mid);
				zo = cur;
			}
		}
		last = cur;
	}
	if(nearest == 9999999) {
		return a[0] >= x;
	}
	return zo == 1;
}

int main() {
	ios::sync_with_stdio(0);
	cin>>n;
	n = 2 * n - 1;
	rep(i, 0, n) cin>>a[i];
	if(n == 1) {
		cout<<1<<endl;
		return 0;
	}
	int l = 2, r = n - 1;
	int ans = -1;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(judge(mid)) {
			l = mid + 1;
			ans = mid;
		} else {
			r = mid - 1;
		}
	}
	for(int i = l - 1; i <= r + 1; i++) {
		if(judge(i)) ans = max(ans, i);
	}
	cout<<ans<<endl;
	return 0;
}
// --USE C++11
// *-USE O2


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

int main()
{
    int n, d;
    cin >> n >> d;

    vector<vector<int>> x(n, vector<int>(d));
    rep(i, n)
    {
        rep(j, d) cin >> x[i][j];
    }

    int ans = 0;
    rep(i, n) rep(j, i)
    {
        int sq = 0;
        rep(k, d)
        {
            int s = x[i][k] - x[j][k];
            sq += s * s;
        }
        int s = sqrt(sq) + 0.5;
        if (s * s == sq)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    long long answer = 0;
    for (int i = 0; i < v.size() - 2; ++i) {
        for (int j = i + 1; j < v.size() - 1; ++j) {
            if (v[i] + v[j] > v.back()) {
                answer += v.size() - j - 1;
            } else {
                for (int k = j + 1; k < v.size(); ++k) {
                    if (v[k] >= v[i] + v[j]) break;
                    ++answer;
                }
            }
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
#include<iostream>
//#include<ctype.h>
using namespace std;
#define ll long
int main(){
	int N,X,Li,sum=0,ctr=1;
	cin>>N>>X;
	for(int i=0;i<N;i++){
		cin>>Li;
		sum+=Li;
		if(sum<=X){
			ctr++;
		}
	}
	cout<<ctr;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i, d)
    {
        cin >> p[i] >> c[i];
    }
    reverse(p.begin(), p.end());
    reverse(c.begin(), c.end());
    int sft = (int)pow(2, d - 1);
    int ans = 1000;
    rep(bit, 1 << d)
    {
        int score = 0, cnt = 0;
        rep(i, d)
        {
            if (bit & (sft >> i))
            {
                rep(j, p[i])
                {
                    score += (d - i) * 100;
                    cnt++;
                    if (score >= g)
                    {
                        ans = min(ans, cnt);
                        break;
                    }
                    if (j == p[i] - 1)
                    {
                        score += c[i];
                        if (score >= g)
                        {
                            ans = min(ans, cnt);
                            break;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4120
import numpy as np

n, k = map(int, input().split())
h = np.array(list(map(int, input().split())))

cost = np.zeros(n)


for i in range(1,n):
    left = max(0,i-k)
    cost[i] = (cost[left:i]+abs(h[i]-h[left:i])).min()
     

print(int(cost[-1]))

Measured memory_bytes: 22724
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
13
'''

def solve(n):
	n -= 1
	return n*(n+1) // 2

N = int(stdin.readline())
ans = solve(N)
print(ans)



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

int main() {
  long long n;
  cin >> n;
  long long p[200010];
  for (long long i = 0; i < n; i++) {
    cin >> p[i];
  }
  long long ans = 0;
  long long tmp = 1e9;
  for (long long i = 0; i < n; i++) {
    if (p[i] > tmp) {
      continue;
    }
    tmp = min(p[i], tmp);
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define MAX 10000
#define NIL -1

int left[MAX], right[MAX], parent[MAX];
int n, H[MAX], D[MAX];
int getDepth(int u){
  int d = 0;
  while(parent[u] != NIL){
    u = parent[u];
    d++;
  }
  return d;
}
void setDepth(int u, int p){
  D[u] = p;
  if(right[u] != NIL){
    setDepth(right[u], p+1);
  }
  if(left[u] != NIL){
    setDepth(left[u], p+1);
  }
}

int seTHeight(int u){
  int h1 = 0;
  int h2 = 0;
  if( right[u] != NIL ){
    h1 = seTHeight(right[u]) + 1;
  }
  if( left[u] != NIL ){
    h2 = seTHeight(left[u]) + 1;
  }
  return H[u] =(h1 > h2 ? h1 : h2);
}
int seTSibling(int u){
  if(parent[u] == NIL )      return NIL;
  if(left[parent[u]] != u && left[parent[u]] != NIL )     return left[parent[u]];
  if(right[parent[u]] != u && right[parent[u]] != NIL)    return right[parent[u]];
  return NIL;
}

void printChildren(int u){
  int c;
  int deg = 0;

  printf("node %d: ", u);
  printf("parent = %d, ", parent[u]);
  printf("sibling = %d, ", seTSibling(u));
  if(left[u] != NIL ) deg++;
  if(right[u] != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);
  if(parent[u] == NIL) printf("root\n");
  else if(left[u] == NIL && right[u] == NIL ) printf("leaf\n");
  else printf("internal node\n");
}

int main(){
  int i, d, ro, v, le;
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++)  parent[i] = left[i] = right[i] = NIL;

  for( i = 0 ; i < n ; i++){
    scanf("%d", &v);
    scanf("%d", &le);
    scanf("%d", &d);
    left[v] = le;
    right[v] = d;
    if(le != NIL ) parent[le] = v;
    if(d != NIL ) parent[d] = v;
  }
  for( i = 0 ; i < n ; i++){
    if( parent[i] == NIL ) ro = i;
  }
  setDepth(ro, 0);
  seTHeight(ro);
  for( i = 0 ; i < n ; i++) printChildren(i);
  return 0;
}



Measured memory_bytes: 2104
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
fact_l=[1]*(N+10)
mod = 10**9+7
for i in range(2,N+1):
  fact_l[i]=(fact_l[i-1]*i)%mod
  
fact_inv_l = [1]*(N+10)
for i in range(2,N+1):
  fact_inv_l[i]=pow(fact_l[i],mod-2,mod)
ans = 0
for i in range(1,N-K+2):
  b = N-i
  c = K-1
  ans -= A[i-1]*fact_l[b]%mod*fact_inv_l[b-c]%mod*fact_inv_l[c]%mod
  ans += A[-i]*fact_l[b]%mod*fact_inv_l[b-c]%mod*fact_inv_l[c]%mod
    
print(ans%mod)

Measured memory_bytes: 14840
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

def check_a(a_num, b_num):
    res = False
    if a_num < b_num:
        res = True
    return res

def check_c(c_num, b_num):
    res = False
    if b_num < c_num:
        res = True
    return res

ans = 0
cnt_a = 0
cnt_c = 0
for bi in range(len(b)):
    left = 0
    right = len(a)-1
    if check_a(a[0], b[bi]) is False:
        cnt_a = 0
    elif check_a(a[-1], b[bi]) is True:
        cnt_a = len(a)
    else:
        while right-left > 1:
            mid = (left + right) // 2
            if check_a(a[mid], b[bi]):
                left = mid
            else:
                right = mid
        cnt_a = left + 1

    left = 0
    right = len(c) - 1
    if check_c(c[0], b[bi]) is True:
        cnt_c = len(c)
    elif check_c(c[-1], b[bi]) is False:
        cnt_c = 0
    else:
        while right - left > 1:
            mid = (left + right) // 2
            if check_c(c[mid], b[bi]):
                right = mid
            else:
                left = mid
        cnt_c = len(c) - right
    ans += cnt_a * cnt_c
print(ans)



Measured memory_bytes: 24140
h,w=gets.split.map(&:to_i)
field=readlines
field[-1] << '.'
field << '.' * (w+1)

0.upto(h-1) do |j|
  0.upto(w-1) do |i|
    next if field[j][i] == '.'
    
    ok = [
      field[j-1][i],
      field[j+1][i],
      field[j][i-1],
      field[j][i+1],
    ].any? {|b| b == '#'}

    unless ok
      puts 'No'
      exit 0
    end
  end
end

puts 'Yes'

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

int main() {
  int x, y;

  while(true) {
    cin >> x >> y;

    if(!x && !y) {
      break;
    }

    for (int i = 0; i < x; ++i) {
      for (int j = 0; j < y; ++j) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#define int long long int
#define cons 1000000007 
using namespace std;
 
 
signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
 
    int k, x, i;
    cin>>k>>x;
    for(i=max(x-k+1, (int)-100000);i<=min((int)100000, x+k-1);i++){
        cout<<i<<" ";
    }
    cout<<endl;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
//typedef pair<int,int> P;

using namespace std;


const int INF=INT_MAX/3;
const int V_MAX=10000,E_MAX=10000;

int V,E;
map<int,int> d;

int card[8]={0,1,2,3,4,5,6,7};

void decode(int x){

  for(int i=0;i<8;i++){
    card[7-i]=x%10;
    x=int(x/10);
  }
}

int encode(){

  int x=0;
  int y=1;
  
  for(int i=0;i<8;i++){
    x += card[7-i]*y;
    y *= 10;
  }
  return x;
}

void swap_v(int i,int j){
  int t=card[i];
  card[i]=card[j];
  card[j]=t;
}



int solve(){

  queue<int> qu;
  int dx[4]={-4,4,-1,1};

  int res=0;
  
  map<int,int>::iterator itr;
  int current=encode();

  d[current]=0;
  qu.push(current);
  
  while(!qu.empty()){

    current=qu.front();
    qu.pop();
    decode(current);

    //cout<<"card:";
    //for(int i=0;i<8;i++) cout<<card[i]<<" ";
    //cout<<"\n";
    
    int zero=0;
    for(int i=0;i<8;i++){
      if(card[i]==0){
	zero=i; break;
      }
    }
    
    for(int i=0;i<4;i++){
      int x=zero+dx[i];
      if(zero==3 && x==4) continue;
      if(zero==4 && x==3) continue;
      if(0<=x && x<=7){
	
	swap_v(zero, x);
	int s=encode();
	//cout<<s<<endl;
	//for(int i=0;i<8;i++) cout<<card[i]<<" ";
	
	map<int,int>::iterator itr=d.find(s);
	if(itr==d.end() || d[current]+1<d[s]){
	  d[s]=d[current]+1;
	  qu.push(s);
	  //cout<<"push:"<<s;
	}
	swap_v(zero,x);
      }
    }
    res++;
  }
  
  return res;
}

int main(){

  solve();
  bool end=false;
  
  while(1){
    
    for(int i=0;i<8;i++){
      cin>>card[i];
      if(cin.eof()) end=true;
    }
    if(end) break;
    int x = encode();
    cout<<d[x]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;



void solve() {
	int n, m;
	cin >> n >> m;
	string s(n, '0');
	for(int i = 0	;i < m; ++i) {
		int idx, v;
		cin >> idx >> v;
		--idx;	
		if((s[idx] != '0' && s[idx] != v + '0') || (n != 1 && idx == 0 && v == 0)) {
			cout << -1 << endl;
			return; 
			}
			s[idx] = v + '0';
		}
		if(n > 1 && s[0] == '0') s[0] = 1 + '0';
		cout << s << endl;
}			


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	int t;
	solve();
	return 0;
}
 
 
 


Measured memory_bytes: 3600
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int a,b;
    int temp=1;
    int count = 0;
    cin >> a >> b;
    while(temp<b){
        temp+=(a-1);
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<int,int>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;

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

   vvi dp(s.size()+1,vector<int>(t.size()+1, 0));

   /* s= abcde t = aabbc
      1 2 3 4 5
    1 1 1 1 1 1
    2 1 1 2 2 2
    3 1 1 2 2 3
    4 1 1 2 2 3
    5 1 1 2 2 3
   */
   /* s= axyb t = abyxb
      a x y b
    a 1 1 1 1 
    b 1 1 1 2 
    y 1 1 2 2 
    x 1 2 2 2 
    b 1 2 2 3 
   */
   string ans = "";
   vector<P> index(min(s.size()+1,t.size()) + 1, P(-1,-1));

   for(int i = 0; i < s.size();i++)
   {
      for(int j = 0; j < t.size(); j++)
      {
         if(s[i] == t[j]) 
         {
            dp[i+1][j+1] = dp[i][j]+ 1;
            if(index[dp[i+1][j+1]].first == -1) index[dp[i+1][j+1]] = P(i,j);
            else
            {
               int before = max(index[dp[i+1][j+1]].first, index[dp[i+1][j+1]].second);
               int now = max(i,j);
               if(now < before) index[dp[i+1][j+1]] = P(i,j);
            }
         }
         else dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
      }
   }
   
   // rep(i,s.size()+1)
   // {
   //    rep(j,t.size()+1)
   //    {
   //       cout << dp[i][j] << " ";
   //    }
   //    cout << endl;
   // }

    // 復元
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
    cout << res << endl;

   // rep(i, index.size())
   // {

   //    if(index[i+1].first == -1) break;
   //    ans += s[index[i+1].first];
   // }

   // cout << ans << endl;;
}


Measured memory_bytes: 35584
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

const int MOD = 1000000007;

ll factorial(int n)
{
    ll res = 1;
    rep(num, 1, n+1)
    {
        res *= num;
        res %= MOD;
    }
    return res;
}

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

    int num_line = 0;
    ll cnt = factorial(n);
    for (auto c: s)
    {
        if (c == 'W')
        {
            if (num_line & 1)
                ++num_line;
            else
            {
                cnt *= num_line;
                cnt %= MOD;
                --num_line;
            }
        }
        else
        {
            if (num_line & 1)
            {
                cnt *= num_line;
                cnt %= MOD;
                --num_line;
            }
            else
                ++num_line;
        }
    }

    // check validity
    if (num_line > 0)
    {
        cout << 0 << endl;
        return 0;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;
    if (U == S) {
        cout << A -1 << " " << B << endl;
    } else {
        cout << A << " " << B-1 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
using ll = long long int;

ll factorial(ll n) {
    if (n == 0) {
        return 0;
    }
    if (n == 1) {
        return 1;
    } else {
        return n * factorial(n-1);
    }
}

map<ll, ll> sosuu (ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i*i <= n; i++)
    {
        if (n % i == 0) {
            while (n % i == 0) {
                res[i]++;
                n /= i;
            }
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

ll combination(const ll n, const ll k) {    
    map<ll, ll> n_fact;
    // n!
    for (size_t i = 1; i <= n; i++)
    {
        map<ll, ll> mp = sosuu(i);
        for (auto &&e : mp)
        {
            n_fact[e.first] += e.second;
        }
    }
    // (n-1)!
    for (size_t i = 1; i <= (n-k); i++)
    {
        map<ll, ll> mp = sosuu(i);
        for (auto &&e : mp)
        {
            n_fact[e.first] -= e.second;
        }
    }
    // k!
    for (size_t i = 1; i <= k; i++)
    {
        map<ll, ll> mp = sosuu(i);
        for (auto &&e : mp)
        {
            n_fact[e.first] -= e.second;
        }
    }
    
    ll ans = 1;
    for (auto &&e : n_fact)
    {
        ans *= pow(e.first, e.second);
    }
    return ans;
}

int main()
{
    ll n, p;
    cin >> n >> p;
    ll even = 0, odd = 0;

    for (size_t i = 0; i < n; i++)
    {
        ll ai;
        cin >> ai;
        if (ai % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }

    // ll all = (1LL<<n);
    // ll even_to_even = (1LL<<even);
    // ll odd_to_even = 1;
    // for (size_t i = 1; i <= odd; i++)
    // {
    //     if (i % 2 == 0) {
    //         odd_to_even += combination(odd, i);
    //     }
    // }
    // ll even_count = even_to_even * odd_to_even;
    // ll odd_count = all - even_count;


    if (p == 0) {
        cout << ((odd == 0) ? (1LL<<n) : (1LL<<(n-1))) << endl;
    } else {
        cout << ((odd == 0) ? 0 : (1LL<<(n-1))) << endl;
    }

}

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

int main(){
	LL n, h, w, fz;
	cin >> n;
	for(h = 3500; h; -- h)
		for(w = 3500; w; -- w){
			if((h + w) * n >= 4 * h * w)
				break;
			fz = 4 * h * w - n * w - n * h;
			if(((n * h * w) % fz) == 0){
				cout << h << ' ' << w << ' ' << n * h * w / fz << endl;
				return 0;
			}
		}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+2);
    a[0] = 0;
    a[n+1] = 0;
    int sum = 0;
    for ( int i = 1; i < n + 1; ++i ) {
        cin >> a[i];
        sum += abs(a[i] - a[i-1]);
        if ( i == n ) {
            sum += abs(0-a[i]);
        }
    }
//    cout << sum << endl;
    int ans = 0;
    for ( int i = 1; i < n + 1; ++i ) {
        ans = sum + abs( a[i+1] - a[i-1] ) - abs( a[i] - a[i-1] ) - abs(a[i+1] - a[i] );
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<>();
    for (int i = 1; i * i <= M; i++) {
      if (M % i == 0) {
        list.add(i);
        list.add(M / i);
      }
    }
    int ans = -1;
    for (int i = 0; i < list.size(); i++) {
      int value = list.get(i);
      if (ans < value && value <= M / N) {
        ans = value;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N;
  cin >> N;
  cout << N*N*N << endl;
  return 0;
}


Measured memory_bytes: 256
//ProblemC

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

//ProblemC
#define MAXN 105

class Solve {
private:
	int n;
	using XY = pair<int,int>;
	int a[MAXN], b[MAXN], c[MAXN], d[MAXN];

	int line[MAXN][MAXN]{};
	int next[MAXN]{}, used[MAXN]{};

	bool found(int x)
	{
		for (int i = 1; i <= n; i++)
		{
			if (line[x][i] && !used[i])
			{
				used[i] = 1;
				if (next[i] == 0 || found(next[i]))
				{
					next[i] = x;
					return 1;
				}
			}
		}
		return 0;
	}

	void solve() {
		cin >> n;
		for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
		for (int i = 1; i <= n; i++) cin >> c[i] >> d[i];

		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++) {
				if (a[i] < c[j] && b[i] < d[j]) {
					line[i][j] = 1;
				}
			}

		int sum = 0;
		for (int i = 1; i <= n; i++)
		{
			memset(used, 0, sizeof(used));
			if (found(i)) sum++;
		}
		cout << sum << endl;
	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> N;
  Vec(Ed,pint,N-1,pint(0,0));
  rep(i,0,N-1){
    cin >> A >> B;
    if(A>B)swap(A,B);
    Ed[i]=pint(A,B);
  }
  Sort(Ed);
  rep(i,0,N)sum+=(N-i)*(N-i+1)/2;
  rep(i,0,N-1)sum-=Ed[i].first*(N-Ed[i].second+1);
  Out(sum);
}
    


Measured memory_bytes: 6364
def solve():
    from sys import stdin
    f_i = stdin
    
    from heapq import heappush, heappop
    while True:
        n, m = map(int, f_i.readline().split())
        if n == 0:
            break
        
        adj = [[] for i in range(n)]
        for i in range(m):
            a, b, c = map(int, f_i.readline().split())
            a -= 1
            b -= 1
            adj[a].append((b, c))
            adj[b].append((a, c))
        
        # Dijkstra's algorithm
        fare = [[100000] * 3 for i in range(n)]
        fare[0][2] = 0
        hq = [(0, 0, 2)] # (fare, pos, remaining ticket)
        n -= 1
        while hq:
            f1, u, rt = heappop(hq)
            
            if rt != 1 and u == n:
                print(f1)
                break
            
            for v, f2 in adj[u]:
                if rt == 0:
                    f3 = f1 + f2
                    if f3 < fare[v][0]:
                        fare[v][0] = f3
                        heappush(hq, (f3, v, 0))
                elif rt == 1:
                    if f1 < fare[v][0]:
                        fare[v][0] = f1
                        heappush(hq, (f1, v, 0))
                else:
                    f3 = f1 + f2
                    if f3 < fare[v][2]: # not using ticket
                        fare[v][2] = f3
                        heappush(hq, (f3, v, 2))
                    if f1 < fare[v][1]: # using ticket
                        fare[v][1] = f1
                        heappush(hq, (f1, v, 1))

solve()


Measured memory_bytes: 5672
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

inline int nextCombination(int comb) {
	int x = comb & -comb, y = comb + x;
	return (((comb & ~y) / x) >> 1) | y;
}

bool solve(int n, int m, int x) {
	if (m == n - 2)
		return x == m;
	if (m == n - 1)
		return x == n;
	if (m <= n / 2 - 1)
		return x <= m;
	return (m - n / 2) * 2 + 2 - n % 2 <= x && x <= m;
}

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<int> a(N);
		for (int i = 0; i < N; ++ i)
			scanf("%d", &a[i]);
		int L = *min_element(a.begin(), a.end());
		int R = *max_element(a.begin(), a.end());
		bool ans;
		if (L == R) {
			ans = R * 2 <= N || R + 1 == N;
		} else if (L + 1 == R) {
			int x = count(a.begin(), a.end(), L);
			ans = solve(N, L, x);
		} else {
			ans = false;
		}
		puts(ans ? "Yes" : "No");
	}
	return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  cout << (double)((n+1)/2)/n << endl;
  return 0;
}


Measured memory_bytes: 892
import java.io.*;
import java.util.*;
import java.math.*;
 
class Main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st, st2;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
    public static int INF = 0x3f3f3f3f;
    public static int MOD = 1000000007;
    public static long LINF = 0x3f3f3f3f3f3f3f3fL;

    public static void main(String[] args) throws Exception {
        st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        boolean[] won = new boolean[N];
        st = new StringTokenizer(br.readLine());
        int R = Integer.parseInt(st.nextToken());
        int S = Integer.parseInt(st.nextToken());
        int P = Integer.parseInt(st.nextToken());

        long ans = 0;

        char[] A = br.readLine().toCharArray();
        for (int i = 0; i < N; i++) {
            if (i < K || A[i] != A[i-K] || !won[i-K]) {
                won[i] = true;
                if (A[i] == 'r') {
                    ans += P;
                } else if (A[i] == 's') {
                    ans += R;
                } else {
                    ans += S;
                }
            }
        }

        pw.println(ans);

        pw.close();
        br.close();
    }
}

class Pair implements Comparable<Pair>{
    public int a, b;

    Pair(int _a, int _b){
        a = _a;
        b = _b;
    }
 
    public String toString(){
        return a + " " + b;
    }

    public int compareTo(Pair p){
        if (b != p.b) return b < p.b ? -1 : 1;
        if (a != p.a) return a < p.a ? -1 : 1;
        return 0;
    }
}

Measured memory_bytes: 26452
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long ans = 0;
    long yo = 100;
    for(long i = 1; i < Long.MAX_VALUE; i++) {
      yo = (yo + (yo / 100));
      if(yo >= x) {
        ans = i;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35596
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[200001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=200000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}

//vector< vector <lld > > v(100001);
lld p1=1000000007,p2=998244353;
lld l,r,mid,ans;
lld n,m,i,j,k;
lld x,y,n1,a,b,n2,h,z,c;
queue<lld> q;
lld d,p=1000000000;

void solve()
{
    cin>>n;
    vector<lld > v,w(n);
    for(i=0;i<n;i++)
    {
        cin>>l;
        v.pb(l);
    }   
    w[1]= abs(v[1]-v[0]);
    //cout<<w[1];
    for(i=2;i<n;i++)
    {
        w[i] = min(w[i-2]+abs(v[i]-v[i-2]) , w[i-1] + abs(v[i]-v[i-1])); 
    }
    cout<<w[n-1];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
    //getfac(p2);
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
            solve();
        cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
//素数判定
bool is_prime(long long n){
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i,n){
        cin >> p[i];
    }
    rep(i,n){
        cin >> q[i];
    }
    map<vector<int>, int> ord;
    int iter = 1;
    vector<int> v(n);
    rep(i,n){
        v[i] = i + 1;
    }
    do{
        ord[v] = iter++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(ord[p] - ord[q]) << endl;
    return 0;
}

Measured memory_bytes: 8640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine();
        //String line = sc.nextLine();
        check(num);
    }

    public static void check(String num) {
        //int cnt = Integer.parseInt(num);
        String[] strs = num.split(" ");
        int[] nums = new int[strs.length];
        for(int i=0; i<strs.length; i++) {
            nums[i] = Integer.parseInt(strs[i]);
        }
        System.out.println(Math.min(nums[0]*nums[1], nums[2]));
    }
}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mmod 1000000007
#define pi acos(-1)
struct st
{
    int value,in;
};
bool cmp(st i, st j)
{
    return i.value<j.value;
}
int main()
{
    faster;
    ll a,b;
    cin>>a>>b;
    ll maxi=max(a,b);
    if (a==b)
        cout<<a*2<<endl;
    else
        cout<<maxi*2-1<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int a[101];
ll dp[100003][101];
int n,k;
int main(){
	cin>>n>>k;
	FOR(i,0,n) cin>>a[i];
	dp[0][0]=1;
	FOR(i,0,n){
		FOR(j,0,k+1){
			(dp[j][i+1]+=dp[j][i])%=MOD;
			if(j+a[i]<k+2) (dp[j+a[i]+1][i+1]+=(MOD-dp[j][i]))%=MOD;
		}
		FOR(j,0,k+1){
			(dp[j+1][i+1]+=dp[j][i+1])%=MOD;
		}
	}
	co(dp[k][n]);
}


Measured memory_bytes: 79104
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
  int L, R, d, ld, rd, ans;
  scanf("%d%d%d", &L, &R, &d);
  ld = L / d;
  rd = R / d;
  if (L % d == 0)
  {
    ans = rd - ld + 1;
  }
  else
  {
    ans = rd - ld;
  }

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 1676
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;

    vector<long long> v(n);
    for (int i=0; i<n; i++){
        cin >> v.at(i);
        if(v.at(i) == 0){
            cout << 0 << endl;
            return 0;
        }
    }
  
    long long ans=1;
    for (int i=0; i<n; i++){
        if(v.at(i)>1000000000000000000/ans){
            cout << -1 << endl;
            return 0;
        }
        ans *= v.at(i);
    }
    cout << ans << endl;
    return 0;
    }

Measured memory_bytes: 4012
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] arr = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            total += arr[i];
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            int x = total % (4 * m) == 0 ?  total / (4 * m) : total / (4 * m) + 1;
            if (arr[i] >= x) {
                count++;
            }
        }
//        debug(count);

        System.out.println(count >= m ? "Yes" : "No");

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

using namespace std;
using ll = long long;

template <typename T>
void clr(T& a, T& b, T& c) {
	while (!a.empty()) { a.pop(); }
	while (!b.empty()) { b.pop(); }
	while (!c.empty()) { c.pop(); }
}

int main() {
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	vector<int> l(N);
	for (int i = 0; i < N; ++i) { cin >> l[i]; }

	int res = 1e8;
	queue<int> a;
	queue<int> b;
	queue<int> c;
	int sz = pow(4, N);
	for (int i = 0; i < sz; ++i) {
		int t = i;
		for (int j = 0; j < N; ++j) {
			int idx = t % 4;
			t /= 4;
			if (idx == 0) { a.push(l[j]); }
			if (idx == 1) { b.push(l[j]); }
			if (idx == 2) { c.push(l[j]); }
		}

		int tmp = 0;
		if (a.empty()) {
			clr(a, b, c);
			continue;
		}
		tmp += (10 * (a.size() - 1));
		if (b.empty()) {
			clr(a, b, c);
			continue;
		}
		tmp += (10 * (b.size() - 1));
		if (c.empty()) {
			clr(a, b, c);
			continue;
		}
		tmp += (10 * (c.size() - 1));

		int suma = 0;
		while (!a.empty()) {
			suma += a.front();
			a.pop();
		}
		int sumb = 0;
		while (!b.empty()) {
			sumb += b.front();
			b.pop();
		}
		int sumc = 0;
		while (!c.empty()) {
			sumc += c.front();
			c.pop();
		}

		tmp += (abs(suma - A) + abs(sumb - B) + abs(sumc - C));
		res = min(res, tmp);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256