akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )

int main() {
    std::string alpha = "abcdefghijklmnopqrstuvwxyz";
    std::string s;
    cin >> s;
    if (s.size() == 26) {
        char minz = 'z';
        for (int ss = 26; ss > 0; ss--) {
            s = s.substr(0, ss);
            std::string tmp = s;
            int i = (int)s.size() - 1;
            for (; i > 0; i--) {
                std::sort(tmp.begin() + i, tmp.end());
                for (int z = i; z <= (int)s.size()-1; z++) {
                    if (tmp[z] > s[i-1]) {
                        for (int k = 0; k < i-1; k++) {
                            std::cout << s[k];
                        }
                        std::cout << tmp[z] << std::endl;
                        return 0;
                    }
                }
            }
        }
        std::cout << -1 << std::endl;
    } else {
        std::string tmp = s;
        std::sort(tmp.begin(), tmp.end());
        int i = 0;
        for(; i < 26; i++) {
            if (tmp[i] != alpha[i]) {
                break;
            }
        }
        std::cout << s + alpha[i] << std::endl;
    }
}

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

using namespace std;
typedef long long ll;

void prime_sieve(vector<bool>& p){
    fill(p.begin(), p.end(), true);
    p.at(0) = false;
    p.at(1) = false;
    for(int i = 2; i < p.size(); i++){
        if(!p.at(i)){ continue; }
        for(int j = 2; i * j < p.size(); ++j){
            p.at(i * j) = false;
        }
    }
}

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

    vector<bool> p(55556);
    prime_sieve(p);

    for(int i = 2; i < p.size() && n > 0; ++i){
        if(p.at(i) && i % 5 == 1){
            cout << i;
            n--;
            if(n > 0){
                cout << ' ';
            }else{
                cout << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
N = input().rstrip()
A = list(map(int,input().split()))

#a = X[0]
#b = X[1]
#c = X[2]

res = 0
for ai in A :
  if ai % 2 ==0 :
    if (ai % 3 != 0) and (ai % 5 != 0):
      res += 1
      break

if res == 0 :
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main()
{
	int x=0, y=0, z=0;
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		int a;
		scanf("%d", &a);
		if(a%4==0){
			x++;
		}else if(a%2==0){
			y++;
		}else{
			z++;
		}
	}
	if(y==0){
		if(x>=z-1){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		if(z<=x){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

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

    int count_red  =0;
    int count_blue =0;

    for(int i=0; i<s.length; i++){
      if(s[i].equals("0")){
        count_red += 1;
      }else if(s[i].equals("1")){
        count_blue += 1;
      }
    }

    int ans = Math.min(count_red,count_blue)*2;

    System.out.println(ans);
  }
}

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

int main(){
int n,m;
  cin>>n;
  vector<string> s(n);
  vector<int> c(n,1);
  for(int i=0;i<n;i++){
    cin>>s.at(i);
  }
  cin>>m;
  vector<string> t(m);
  for(int i=0;i<m;i++){
    cin>>t.at(i);
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n&&j!=i;j++){
      if(s.at(i)==s.at(j)){
        c.at(i)++;
      }
    }
    for(int k=0;k<m;k++){
      if(s.at(i)==t.at(k)){
        c.at(i)--;
      }
    }
  }
  int max=0;
  for(int i=0;i<n;i++){
    if(max<c.at(i)){
      max=c.at(i);
    }
  }
  if(max>0){
  cout<<max;
  }else{
    cout<<0;
  }
}


Measured memory_bytes: 256
class Enumerator:
    def __init__(self, N: int, MOD: int) -> None:
        self.fact = [1, 1]
        self.finv = [1, 1]
        self.invs = [0, 1]
        for i in range(2, N + 1):
            self.fact.append(self.fact[i - 1] * i % MOD)
            self.invs.append(-self.invs[MOD % i] * (MOD // i) % MOD)
            self.finv.append(self.finv[-1] * self.invs[-1] % MOD)
        self._MOD = MOD
        self._N = N

    def choose(self, n: int, k: int) -> int:
        if p := self.permutate(n, k):
            return p * self.finv[k] % self._MOD
        else:
            return 0

    def permutate(self, n: int, k: int) -> int:
        if n < k or n < 0 or k < 0:
            return 0
        assert n <= self._N and k <= self._N
        return self.fact[n] * self.finv[n - k] % self._MOD

    def choose_with_duplicates(self, n: int, k: int) -> int:
        return self.choose(n + k - 1, n)


S = int(input())
MOD = 1_000_000_007
e = Enumerator(S, MOD)
ans = 0
q = S // 3
for i in range(1, q + 1):
    rem = S - 3 * i
    ans += e.choose_with_duplicates(rem, i)
    ans %= MOD
print(ans)


Measured memory_bytes: 9352
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int N;
	cin >> N;
	vector<int>a(N);
	REP(i,N)cin >> a[i];
	map<int,int>mp;
	REP(i,N){
		a[i] -= i;
		mp[a[i]]++;
	}
	int ans = 0;
	REP(i,N){
		--mp[a[i]];
		ans += mp[- i * 2 - a[i]];
	}
	out(ans);
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n, k;
vl a;
/******* define variable end *******/
int solve() {
	cin >> n >> k;
	a.resize(n);
	REP(i, n){
		cin >> a[i];
	}
	vl tables(n);
	vl tmp(n);
	REP(i, n){
		tmp[i] = a[i];
	}
	REP(i, k){
		vl zero(n);
		REP(j, n){
			tables[j] = 0;
		}
		REP(j, n){
			if(tmp[j] == 0) zero[j]++;
			tables[max((ll)0, j-tmp[j])]++;
			if(j+tmp[j]+1 < n) tables[j+tmp[j]+1]--;
		}
		REP(j, n){
			if(j > 0){
				tables[j] += tables[j-1];
			}
		}
		bool flag = true;
		REP(j, n){
			flag = flag && (tmp[j] == tables[j]);
		}
		if(flag){
			break;
		}
		tmp = tables;
	}
	REP(i, n){
		cout << tables[i] << " ";
	}
	cout << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        if (a > b)
            swap(a, b);
        if (b > c)
            swap(b, c);
        if (a * a + b * b == c * c)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


Measured memory_bytes: 3004
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

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

  ll a[3000000],len[3000000];
  len[0]=0;
  rep(i,0,n){
    cin>>a[i];
    len[i+1]=a[i]+len[i];
  }

  ll tmp=len[n];
  rep(i,1,n){
    if(tmp>abs(len[n]-2*len[i])){
      tmp=abs(len[n]-2*len[i]);
    }
  }

  cout<<tmp<<endl;
}

Measured memory_bytes: 7936
import re

def delete(s):
  if len(s) < 3: return s
  if s == 'mew': return ''
  res = re.finditer('mew', s, re.MULTILINE)
  for m in res:
    if m.start() == 0: continue
    if m.end() == len(s): continue
    ss = s[:m.start()]+s[m.end():]
    return delete(ss)
  return s

s = raw_input()
ss = delete(s)
if len(ss) == 0: print "Cat"
else: print "Rabbit"

Measured memory_bytes: 6792
from collections import Counter as c
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
XY.sort(key=lambda xy: (xy[0], xy[1]))
if N == 1 or N == 2:
    print(1)
    exit()

inclination = []
for i in range(0, N-1):
    for j in range(i+1, N):
        inclination.append((XY[j][0] - XY[i][0], XY[j][1] - XY[i][1]))

print(N - sorted(list(c(inclination).items()), key=lambda x: x[1])[-1][1])


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin >> s;
	map<char,int> ct;
	for (const char & ch : s)
		ct[ch]++;
	int ret=0;
	for (const auto & it : ct)
		if (it.second==2)
		ret++;
	cout << (ret==2?"Yes":"No") << "\n";	
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

class SWAG(object):
    def __init__(self,dot):
        self.__front=[]
        self.__back=[]
        self.__dot=dot

    def __bool__(self):
        return True if(self.__front or self.__back) else False

    def __len__(self):
        return len(self.__front)+len(self.__back)

    def append(self,x):
        back=self.__back
        if(not back): back.append((x,x))
        else: back.append((x,self.__dot(back[-1][1],x)))

    def popleft(self):
        assert(self)
        front=self.__front; back=self.__back
        if(not front):
            front.append((back[-1][0],back[-1][0]))
            back.pop()
            while(back):
                front.append((back[-1][0],self.__dot(back[-1][0],front[-1][1])))
                back.pop()
        front.pop()

    def sum(self):
        assert(self)
        front=self.__front; back=self.__back
        if(not front): return back[-1][1]
        elif(not back): return front[-1][1]
        else: return self.__dot(front[-1][1],back[-1][1])

def resolve():
    n,m=map(int,input().split())
    S=list(map(int,input()))
    swag=SWAG(min)
    dp=[INF]*(n+1)
    dp[n]=0
    for i in range(n-1,-1,-1):
        if(i+1+m<=n): swag.popleft()
        swag.append(dp[i+1])
        if(S[i]==1): continue
        dp[i]=swag.sum()+1

    if(dp[0]==INF):
        print(-1)
        return

    ans=[]
    now=0
    next=0
    while(now!=n):
        next+=1
        if(dp[next]!=INF and dp[now]!=dp[next]):
            ans.append(next-now)
            now=next
    print(*ans)
resolve()

Measured memory_bytes: 65884
from collections import defaultdict
s=input().strip()
t=input().strip()
def gg(cc, c, l, d):
    if d[c][-1] <= cc:
        return d[c][1], l+1
    ll = d[c]
    mx, mn = len(ll)-1, 0
    x = (mx + mn)//2
    while True:
#        print(x,cc,mx,mn,ll)
        if ll[x] <= cc and cc < ll[x+1]:
            return ll[x+1], l
        if cc < ll[x]:
            mx = x
            x = (mx+mn)//2
        else:
            mn = x
            x = (mx+mn)//2

def main():
    ss=set(s)
    tt=set(t)
    if len(tt - ss) != 0: 
        return -1
    d = dict()
    for i, c in enumerate(s):
        if c not in d:
            d[c] = [0]
        d[c].append(i+1)
    cc, l = 0, 0
    for c in t:
#        print(c)
        cc, l = gg(cc, c, l, d)
    return l*len(s) + cc

if __name__ == '__main__':
    print(main())



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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

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

const ll inf = 1LL<<60;

int main()
{
  string s,t; cin>>s>>t;
  ll n = s.size();

  vector<int> ms(26, -1);
  vector<int> mt(26, -1);

  bool flg = true;
  rep(i, n) {
    int ns = s[i] - 'a';
    int nt = t[i] - 'a';
    if (ms[ns] < 0) ms[ns] = nt;
    if (mt[nt] < 0) mt[nt] = ns;
    if (ms[ns] != nt) flg = false;
    if (mt[nt] != ns) flg = false;
  }
  if (flg) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3904
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

int main() {
    string s;
    stack<string> st;
    while (cin >> s) {
        if (s == "+") {
            int x = stoi(st.top());
            st.pop();
            int y = stoi(st.top());
            st.pop();
            st.push(to_string(x + y));
        } else if (s == "*") {
            int x = stoi(st.top());
            st.pop();
            int y = stoi(st.top());
            st.pop();
            st.push(to_string(x * y));
        } else if (s == "-") {
            int x = stoi(st.top());
            st.pop();
            int y = stoi(st.top());
            st.pop();
            st.push(to_string(y - x));
        } else {
            st.push(s);
        }
    }
    cout << st.top() << endl;

    return 0;
}



Measured memory_bytes: 3272
#include<stdio.h>
#include<string.h>

int main(void){
  int n;
  scanf("%d",&n);

  int d[n+1][2];


  int max = 0 , count = 0;
  for(int i = 0;i < n;i ++){
    scanf("%d %d",&d[i][0],&d[i][1]);
    if(d[i][0] == d[i][1]){
      count ++;
    }
    else if(d[i][0] != d[i][1] || i == n-1){
      if(max < count){
        max = count;
      }
      count = 0;
    }
  }

  if(max < count){
    max = count;
  }

  if(max >= 3){
    printf("Yes\n");
  }

  else{
    printf("No\n");
  }


  return 0;
}

Measured memory_bytes: 1596
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

pair<pair<string, int>, int>pp[110];

int main()
{
    int n;
    string s;
    int p;

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> s >> p;
        pp[i].first.first = s;
        pp[i].first.second = -p;
        pp[i].second = i;
    }
    sort(pp, pp+n);
    for (int i = 0; i < n; i++){
        cout << pp[i].second + 1 << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);

int main () {
  int n = in();
  int ans = 0;
  
  for (int i = 1; i <= n; ++i) {
    auto f = [&](int x) {
      int res = 0;
      while (x != 0) {
        x /= 10;
        res++;
      }
      return res;
    };
    if (f(i)%2 != 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/* Hello darkness my old friend, I've come to visit you again! */

#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;

int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int ans=0;
    int i;
    FOR(i,0,n)
    {
        int x;
        cin>>x;
        while(x)
        {
            if(x%2==0)
                ans++;
            else break;
            x/=2;
        }
    }
    cout<<ans;
    return 0;
}

/* This is the end, beautiful friend! */


Measured memory_bytes: 256
n = int(input())
matrix = []
for i in range(n):
    matrix.append([int(i) for i in input().split()])

can = True
t = 0
pos = [0, 0]
for row in matrix:
    t_diff = row[0] - t
    max_step = abs(row[1] - pos[0]) + abs(row[2] - pos[1])
    if max_step > t_diff:
        can = False
        break
    elif max_step % 2 != t_diff % 2:
        can = False
        break
    else:
        t = row[0]
        pos = row[1:3]

if can:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 21156
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,i;
  cin >> n >> i;
  cout << n - i + 1 << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int X,Y;
  cin>>X>>Y;

  int ANS = 0;
  int x = min(2*X,Y);
  x /=2;
  X -= x; Y -= 2*x;
  ANS += x;
  if(Y >= 0)
  {
    int y = Y/4;
    ANS += y;
  }

  cout<<ANS<<endl;

  
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define timesave ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const lli M = 1e6 + 5;
const lli MOD = 998244353;
lli cnt[M], A[M];

lli Big_Mod(lli base, lli power)
{
    if(power == 0) return 1;
    if(power == 1) return base;

    lli val = Big_Mod(base, power/2) % MOD;

    val = (val * val) % MOD;

    if(power%2) val = (val * base) % MOD;

    return val;
}

void solve(int t_case)
{
    lli n;
    cin >> n;

    lli arr[n+5];
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
        cnt[arr[i]]++;
    }

    lli d = Big_Mod(2, MOD-2) % MOD;
 
    for(lli i = 1; i <= 1000000; i++){
        lli pref_sum = 0;

        for(lli j = i; j <= 1000000; j += i){
            A[i] += (pref_sum * ((cnt[j] * j)%MOD))%MOD;
            A[i] %= MOD;
            A[i] += (((((cnt[j] * (cnt[j]-1))%MOD) * ((j * j)%MOD))%MOD) * d);
            A[i] %= MOD;
            pref_sum += (cnt[j] * j)%MOD;
            pref_sum %= MOD;
        }
    }

    lli sum = 0;

    for(lli i = 1000000; i >= 1; i--){
        for(lli j = i+i; j <= 1000000; j += i){
            A[i] -= A[j];
            if(A[i] < 0) A[i] = (A[i]+MOD) % MOD;
        }
       
        sum += (A[i] * Big_Mod(i, MOD-2)) % MOD;
        sum %= MOD;
    }

    cout << sum << "\n";
}
 
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    timesave;

    int tc = 1, t_case = 1;
    //cin >> tc;
    while(tc--) solve(t_case++);
 
    return 0;
}


Measured memory_bytes: 20776
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  int N,K;
  cin>>N>>K;
  int o=0;
  if(K==0)cout<<N*N<<endl;
  else{
    int ans=0;
    ans+=(N-K+1)*(N-K);
    ans/=2;
    for(int b=K+1;b<=N;b++){
      ans+=max((N/b-1)*(b-K),o);
      ans+=max((N%b)-K+1,o);
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let ans = if S.len() < 26 {
        format!(
            "{}{}",
            S.iter().map(|&c| c).collect::<String>(),
            (0..26)
                .map(|i| ('a' as u8 + i) as char)
                .find(|c| !S.contains(c))
                .unwrap()
        )
    } else if let Some(i) = (0..25).rev().find(|&i| S[i] < S[i + 1]) {
        format!(
            "{}{}",
            S[..i].iter().map(|&c| c).collect::<String>(),
            S.iter().rev().find(|&&c| S[i] < c).unwrap()
        )
    } else { "-1".to_string() };

    println!("{}", ans);
}

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

int main() {
    int n, k, q, ai;
    cin >> n >> k >> q;
    long long a[n];
    for(int i = 0; i < n; ++i) a[i] = k;
    for(int i = 0; i < q; ++i) {
        cin >> ai;
        a[ai-1]++;
    }
    for(int i = 0; i < n; ++i) {
        if(a[i] - q > 0) {
            cout << "Yes" << '\n';
        } else {
            cout << "No" << '\n';
        }
    }
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 100;
int n, ans = 0x7fffffff, w[MAXN + 5];

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) read(w[i]);
	for (int s1, s2, i = 1; i < n; ++i) {
		s1 = s2 = 0;
		for (int j = 1; j <= n; ++j)
			if (j <= i) s1 += w[j];
			else s2 += w[j];
		ans = min(ans, abs(s1 - s2));
	}
	write(ans);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


// a,bの最小公倍数
ll lcm(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll gcd(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}
// MOD
ll modadd(ll a, ll b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(ll a, ll b){return a%MOD*b%MOD%MOD;}
ll modexp(ll a, ll n){if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(ll n){return modexp(n%MOD,MOD-2);}
ll modfact(ll n){ll res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(ll n, ll r){ll numer=1;ll denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}


int main(){


    int a, b;
    cin >> a >> b;

    if (a < 2 * b) cout << 0 << endl;
    else cout << a - 2*b << endl;



}



//              g++ -std=c++1z


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T>
struct SegmentTree {
    SegmentTree(int n) : n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<T>(m + n + n % 2);
    }
    T &operator[](int i) {
        return t[m + i];
    }
    const T &root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    void update(int i, const T &o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    T query(int l, int r) {
        T o0, o1;
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (l & 1) o0 = o0 * t[l++];
            if (r & 1) o1 = t[--r] * o1;
        }
        return o0 * o1;
    }
    vector<T> t;
    int n, m;
};
struct Max {
    constexpr Max() : v(0) {}
    Max(int v) : v(v) {}
    Max operator*(const Max &o) const {
        return max(v, o.v);
    }
    int v;
};

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

    int n, k;
    cin >> n >> k;

    int m = 300001;
    SegmentTree<Max> st(m);

    int r = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        int t = st.query(max(a - k, 0), min(a + k + 1, m)).v + 1;
        st.update(a, Max(t));
        r = max(r, t);
    }

    cout << r << endl;

    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

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


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

long long int r[4005];
long long int g[4005];
long long int b[4005];

int main(){
    int N;
    int i,j;
    string S;
    cin >> N;
    cin >> S;
    long long int count=0;
    long long int ans=0;
    if(S[N-1]=='B')b[N-1]=1;
    if(S[N-1]=='G')g[N-1]=1;
    if(S[N-1]=='R')r[N-1]=1;
    for(i=1;i<N;i++){
        if(S[N-1-i]=='B')b[N-1-i]=b[N-i]+1;
        else b[N-1-i]=b[N-i];
        if(S[N-1-i]=='G')g[N-1-i]=g[N-i]+1;
        else g[N-1-i]=g[N-i];
        if(S[N-1-i]=='R')r[N-1-i]=r[N-i]+1;
        else r[N-1-i]=r[N-i];
    }
    for(i=0;i<N-2;i++){
        for(j=i+1;j<N-1;j++){
            if(S[j]!=S[i]){
            if(S[i]!='R'&&S[j]!='R') ans += r[j];
            if(S[i]!='G'&&S[j]!='G') ans += g[j];
            if(S[i]!='B'&&S[j]!='B') ans += b[j];
            if(2*j-i<N)if(S[2*j-i]!=S[i] && S[2*j-i]!=S[j])count++;
        }}
    }
cout << ans-count << endl;
}

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

int main() {
	int N, p, maxItem = 0, sum = 0;
	cin >> N;
	for (int i = 0;i < N;++ i) {
		cin >> p;
		sum += p;
		maxItem = max(maxItem, p);
	}
	cout << sum - (maxItem >> 1);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

全部足してから考えると、最大の品物1個の半分の値段を引き算する問題になるよ！
*/

Measured memory_bytes: 256
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]*n
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
  if i <= k:
    dp[i] = abs(h[0] - h[i])
  else:
    dp[i] = min(dp[i-j] + abs(h[i-j]-h[i])
    for j in range(1, k+1))
print(dp[-1])


Measured memory_bytes: 53216
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
//using namespace atcoder;

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	map<int, int> ANum, BNum;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ANum[A[i]]++;
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
		BNum[B[i]]++;
	}
	for (int i = 0; i <= N; i++) {
		if (ANum.find(i) == ANum.end() || BNum.find(i) == BNum.end()) continue;
		if (ANum[i] + BNum[i] > N) {
			cout << "No" << endl;
			return 0;
		}
	}
	int j = 0, bef = -1;
	for (int i = 0; i < N; i++) {
		if (bef != A[i]) j = 0;
		if (A[i] == B[i]) {
			while (j < N) {
				if (A[j] != A[i] && B[j] != A[i]) {
					swap(B[i], B[j]);
					break;
				}
				j++;
			}
		}
		bef = A[i];
	}
	cout << "Yes" << endl;
	for (int b : B) cout << b << " ";
	cout << endl;
}


Measured memory_bytes: 23420
#include <bits/stdc++.h>
using namespace std;
int k, s, cnt;
int main()
{
    scanf("%d %d", &k, &s);
    for (int i = 0; i <= s; i++)
        for (int j = 0; j <= s - i; j++)
            if (i <= k && j <= k && s - i - j <= k)
                cnt++;
    return printf("%d\n", cnt), 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
int mod=1e9+7;
const int maxv=1e5+10;

int dp[maxv][4];

signed main(){
	string s;cin>>s;
	dp[0][0]=1;
	int n=s.size();
	string abc="ABCX";
	rep(i,n){
	rep(j,4){
		char c=s[i];
		if(c=='?'){(dp[i+1][j]+=3*dp[i][j])%=mod;
				  if(j<3) (dp[i+1][j+1]+=dp[i][j])%=mod;
                  }else{
		
				(dp[i+1][j]+=dp[i][j])%=mod;
				if(c==abc[j])(dp[i+1][j+1]+=dp[i][j])%=mod;
            }
		
	
		
	}}
	cout<<dp[n][3]<<endl;
}




Measured memory_bytes: 3584
import numpy as np

# N: 会社員の人数
# 自分より番号が小さい人が直属の上司
N = int(input())
# A_i は社員番号iの直属の上司の社員番号
A = list(map(int, input().split()))

ans = np.zeros(N)

for i in range(N-1):
    ans[A[i]-1] += 1

for i in range(len(ans)):
    ans_str = int(ans[i])
    print(ans_str)


Measured memory_bytes: 50820
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = (ll)1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int n;
int a[1000];

int main(){
  while (cin >> n, n){
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    int mn = inf;
    rep(i, n - 1) chmin(mn, a[i + 1] - a[i]);
    cout << mn << endl;
  }
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll h,w;
  cin>>h>>w;
  vvc t(h,vc(w));
  ll k=0;
  rep(i,h){
    rep(j,w){
      cin>>t[i][j];
      if(t[i][j]=='.') k++;
    }
  }
  vvll a(h,vll(w,INF));
  queue<pll> p;
  p.pu(pll(0,0));
  a[0][0]=0;
  while(p.size()){
    pll pp=p.front();
    p.pop();
    if(pp.F==h-1&&pp.S==w-1) break;
    rep(i,4){
      ll nx=dx[i]+pp.F;
      ll ny=dy[i]+pp.S;
      if(nx>=0&&nx<h&&ny>=0&&ny<w&&t[nx][ny]!='#'&&a[nx][ny]==INF){
        a[nx][ny]=a[pp.F][pp.S]+1;
        p.pu(pll(nx,ny));
      }
    }
  }
  if(a[h-1][w-1]==INF)COUT(-1);
  else{
    COUT(k-a[h-1][w-1]-1);
  }
}
    

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

int main(){
  string A,B,C;cin >> A >> B >> C;
  cout << char('A'+int(A[0]-'a'));
  cout << char('A'+int(B[0]-'a'));
  cout << char('A'+int(C[0]-'a'));
  cout << endl;
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

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

    int n, h, w;
    cin >> n >> h >> w;

    cout << (n - h + 1) * (n - w + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n,ans;
        long num;
        n = input.nextInt();
        ans = 0;
        for (int i = 0; i < n; i++){
            num = input.nextLong();
            if (isPrime(num)){
                ans += 1;
            }
        }
        System.out.println(ans);
    }
    public static boolean isPrime(long n){
        for (int i = 2; i*i <= n; i++){
            if (n%i == 0){
                return false;
            }
        }
        return n != 1;
    }
}


Measured memory_bytes: 43636
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool flag = false;
  for(int i = 0; i < s.size()-1; i++) if(s.substr(i, 2) == "AC") flag = true;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i],a[i]--;
    vi b(n,-1);
    int t=0,c=0;
    while(b[t]==-1){
        b[t]=c++;
        t=a[t];
    }
    int nc=b[t];
    int cy=c-b[t];
    // cout<<nc<<sp<<cy<<endl;
    if(k>nc)k=(k-nc)%cy+nc;
    t=0;
    rep(i,k){
        t=a[t];
    }
    cout<<t+1<<endl;
}

Measured memory_bytes: 6356
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 100000;
    int N, K, A[MAX_N];
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
    }
    cout << 1 + ceil(N - K, K - 1) << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main(void)
{
	int len,i,flg;
	char s[101];
	scanf("%s",s);
	len=strlen(s);
	flg=0;
	for(i=0;i<len;i++){
		if(i==0||i%2==0){
			if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
				flg=1;
				break;
			}
		}
		if(i%2!=0){
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
				flg=1;
				break;
			}
		}
	}
	if(flg==1){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}

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

int main(){
    int a,b,c; cin >> a >> b >> c;
    if((a == b || b == c || c == a) && !(a == b & b== c)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
using namespace std;

int R, C, K;
int f[3010][3010][4];
int g[3010][3010];

int dfs(int r, int c, int k) {
    if (r < 1 or r > R or c < 1 or c > C or k < 0) return 0;
    int& res = f[r][c][k];
    if (~res) return res;
    res = 0;
    int grc = g[r][c];

    res = dfs(r, c + 1, k);
    if (grc) {
        if (k >= 1) {
            res = max(res, max(dfs(r + 1, c, 3), dfs(r, c + 1, k - 1)) + grc);
        } else {
            res = max(res, dfs(r + 1, c, 3));
        }
    } else {
        res = max(res, dfs(r + 1, c, 3));
    }

    return res;
}

signed main() {
    fastio;
    cin >> R >> C >> K;
    memset(f, -1, sizeof f);
    memset(g, 0, sizeof g);
    rep(k, K) {
        int r, c;
        cin >> r >> c;
        cin >> g[r][c];
    }

    int res = dfs(1, 1, 3);
    cout << res << endl;
}

Measured memory_bytes: 357472
#include <stdio.h>

int main(void){

    int n ,ans = 1;
    int height[20];

    scanf("%d" ,&n);

    for( int i = 0; i < n; i++)
    {
        scanf("%d" ,&height[i]);
    }

    int min = height[0];

    for( int i = 1; i < n; i++) {

        if (min <= height[i]) {

            ans ++;
            min = height[i];
                
        }    
    }
    
    printf("%d\n" ,ans);

    return 0;
    
}

Measured memory_bytes: 128
s = int(input())

def make_col(n):
    if n%2==0: return n//2
    else: return 3*n+1

lis = [s]
now = s
for i in range(1000000):
    next = make_col(now)
    if next in lis:
        print(i+2)
        break
    else:
        lis.append(int(next))
        now = next

Measured memory_bytes: 38384
mod = 10**9 + 7
N = int(input())
S = input()
al = [0]*26
ans = pow(2,N)-1
cnt = 1
for s in S:
    al[ord(s)-97] += 1
for e in al:
    if e >= 2:
        ans -= pow(2,N-e)*(pow(2,e)-(e+1))*cnt
        ans %= mod
        N -= e
        cnt *= (e+1)
ans %= mod
print(ans)

Measured memory_bytes: 3188
function Main(input) {
  const array = input.split('\n').map(e => e.split(''));
  if (array[0][0] === array[1][2] && array[0][1] === array[1][1] && array[0][2] === array[1][0]) {
    console.log('YES');
  } else {
    console.log('NO')
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
#define PI (acos(-1))
typedef long double ld;
typedef long long ll;

int main() {
  while(1) {
    ld n;
    cin >> n;
    
    if (n == 0) break;
    ld s[(int)n], sum=0;
    rep(i, n){
      cin >> s[i];
      sum += s[i];
    }

    ld m = sum / n;
    ld a, asum=0;
    rep (i, n) {
      asum += powl(s[i] - m, 2);
    }
    a = powl(asum / n, 0.5);

    cout << fixed;
    cout << a << endl;
  }
  return 0;
}



Measured memory_bytes: 3472
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    intmax_t N, A, B, C, D;
    char S[200000 + 1];
    intmax_t ans = 0;

    scanf("%jd%jd%jd%jd%jd", &N, &A, &B, &C, &D);
    scanf("%s", S);

    A--;
    B--;
    C--;
    D--;

    // #が並んでいると飛び越えれない
    for (int i = A; i < (D - 1); i++) {
        if (S[i] == '#' && S[i + 1] == '#') {
            puts("No");
            return 0;
        }
    }

    // C < Dだと、ふぬけくんを先にゴールさせとけばいい
    if (C < D) {
        puts("Yes");
        return 0;
    }

    // C > Dだと、すぬけくんがふぬけくんを飛び越えられればいい
    for (int i = B; i <= D; i++) {
        if (S[i] == '#') continue;
        if (S[i - 1] == '.' && S[i + 1] == '.') {
            puts("Yes");
            return 0;
        }
    }

    puts("No");
    return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll a,b,c,k; cin >> a>>b>>c>>k;
    ll res = 0;
    res+=min(a,k);
    k-=min(a,k);
    k-=min(b,k);
    if(k>0)res-=min(k,c);
    out(res);
}


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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;
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;
}

const ll INF = 1LL << 60;
const int MAX_N = 100003;
ll dp[MAX_N];

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];

  rep(i,MAX_N) dp[i] = INF;

  dp[0] = 0;
  for (int i=1; i<n; ++i) {
    dp[i] = min(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
    if (i > 1) {
      dp[i] = min(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 4408