akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; ++i) cin >> h.at(i);
  
  int mx = 0;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    if(mx > h.at(i)) continue;
    ans++;
    mx = max(mx, h.at(i));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
r1,c1,r2,c2=map(int,input().split())

mod = 10**9+7
MAX_N = 3*10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def comb(n,k,mod):
    if n<k:return 0
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans=0
ans+=comb(c1+r1,r1,mod)
ans%=mod
ans-=comb(c1+r2+1,r2+1,mod)
ans%=mod
ans-=comb(c2+r1+1,r1,mod)
ans%=mod
ans+=comb(c2+r2+2,r2+1,mod)
ans%=mod

print(ans)


Measured memory_bytes: 246460
import Data.List
import qualified Data.IntMap.Lazy as IM
 
main = do
  getLine
  as <- map read . words <$> getLine
  print . h . sortBy (flip compare) $ f IM.empty as
 
f im [] = j $ IM.toList im
f im (y:ys) = f (IM.insertWith (const succ) y 1 im) ys
 
h (x:y:_) = x * y
h _ = 0
 
j [] = []
j ((k, v):xs)
  | v >= 4 = [k, k] ++ j xs
  | v >= 2 = k : j xs
  | otherwise = j xs

Measured memory_bytes: 52604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin>>N;
  vi P(N);
  rep(i,N) cin>>P.at(i);
  int minimum=N+1;
  int counter=0;
  rep(i,N) {
    if(minimum>P.at(i)) {
      counter++;
      minimum=P.at(i);
    }
  }
  cout<<counter<<endl;
}

Measured memory_bytes: 1024
n=int(input())
d=[]
for _ in range(n):
  l=list(map(int,input().split()))
  d.append(l)
a=[1,2]
d.append(a)
d.append(a)
flg=0  
for i in range(n):
  if d[i][0]==d[i][1]:
    if d[i+1][0]==d[i+1][1]:
      if d[i+2][0]==d[i+2][1]:
        print("Yes")
        flg=1
        break
if flg==0:
  print("No")

Measured memory_bytes: 9216
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toInt)
    val a2 = aList.filter { it % 2 == 0 && it % 4 != 0 }.count()
    val a4 = aList.filter { it % 4 == 0 }.count()
    println(
            if (n / 2 <= a4) "Yes"
            else if (a2 == n) "Yes"
            else if (n - (a4 * 2) <= a2) "Yes"
            else "No"
    )
}

Measured memory_bytes: 53804
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(Solve( Console.ReadLine()));
    }

    static string Solve(params string[] args)
    {
        var arr = args[0].Split(' ').Select(s => int.Parse(s)).ToArray();
        var N = arr[0];
        var A = arr[1];
        var B = arr[2];

        var cnt = 0;
        for (int i = 1; i <= N; i++)
        {
            var sum = i.ToString().ToArray().Select(n => int.Parse(n.ToString())).Sum();
            if (sum >= A && sum <= B)
            {
                cnt += i;
            }
        }

        return cnt.ToString();
    }
}

Measured memory_bytes: 15444
n = int(input())
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
b = ''
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = a[X_dumy%n-1]+out
        if a[X_dumy%n-1] == 'z':
          X_dumy -= 26
        X_dumy = X_dumy//n
    return out

z = Base_10_to_n(n, 26)
print(z)

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

using namespace std;
using ll = long long; 


template<class T>
class SegTree{
    int n;                       //葉の数
    vector<T> data;              //格納するデータ
    T def;                       //単位元
    function<T(T, T)> operation; //区間クエリで使う処理
    function<T(T, T)> update;    //点更新で使う処理

    //区間[a, b)の総和
    T _query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l)return def;
        if(a <= l && r <= b)return data[k];
        T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
        T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }


  public:
    
    //_n : 要素数, _def : 単位元, _operation : クエリ関数, _update : 更新関数
    SegTree(int _n, T _def, function<T(T,T)> _operation, function<T(T,T)> _update) : def(_def), operation(_operation), update(_update){
            n = 1;
            while(n < _n)n *= 2;
            data = vector<T> (2 * n - 1, def);
    }

    //[a, b)の区間クエリを実行
    T query(int a, int b){
        return _query(a, b, 0, 0, n);
    }

    void change(int i, T x){
        i += n - 1;
        data[i] = update(data[i], x);
        while(i  > 0){
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    T operator[] (int i){
        return data[i + n - 1];
    }

};

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    SegTree<int> tree(n, 0, [](int a, int b){return __gcd(a,b);}, [](int a, int b){return b;});

    for(int i = 0; i < n; i++){
        tree.change(i, a[i]);
    }

    int nax = 0;
    for(int i = 0; i < n; i++){
        tree.change(i, 0);
        nax = max(tree.query(0, n), nax);
        tree.change(i,a[i]);
    }
    cout << nax << endl;

}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	double a, b, x;
	cin >> a >> b >> x;
	
	long double PI = 4.0 * atan(1.0);
	long double ans = 0.0;
	
	if( x >= a * a * b / 2.0 ) ans = atan(2 * (a * a * b - x) / (a * a * a));	
	else ans = PI / 2.0 - atan(2 * x / (a * b * b));
	
	cout << fixed << setprecision(10);
	cout << ans  * 180.0 / PI << endl;

	return 0;
}


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

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

    int m;
    cin >> m;

    int h[m];
    for(int i=0;i<m;i++){
      h[i] = 0;
    }

    for(int i=0;i<m;i++){
      cin >> h[i];
    }

    // シャッフルの処理
    for(int i=0;i<m;i++){
      n.insert(n.size(), n.substr(0,h[i]));
      n.erase(0, h[i]);
    }
    if(n != "-"){
      cout << n << endl;
    }
  } while(n != "-");
}



Measured memory_bytes: 3148
#include<stdio.h>
int main(){
	int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&r,&f);
		if(m==-1 && r==-1 && f==-1)		break;
		
		if(m==-1 || r==-1){
		printf("F\n");

		}else if(m+r>=80){
			printf("A\n");

		}else if(m+r>=65 && m+r<80){
			printf("B\n");

		}else if(m+r>=50 && m+r<65){
			printf("C\n");

		}else if(m+r>=30 && m+r<50){
			if(f>=50)	printf("C\n");
			else 		printf("D\n");

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

		}
	}
	return 0;
}


Measured memory_bytes: 2044
#include<iostream>

using namespace std;
int main()
{	
	int a[100];
	int N,m,cnt=0;
	cin>>N;
	for (int i = 0; i < N; ++i)
	{
		cin>>a[i];
	}
	int i=0,j,flag=1;
	while(flag)
	{
		flag=0;
		
		for ( j = N-1; j >=i+1; --j)
		{
			if (a[j-1]>a[j])
			{
				m=a[j-1];
				a[j-1]=a[j];
				a[j]=m;
				++cnt;
				flag=1;

			}
		}

	}
	for (int i = 0; i < N; ++i)
	{
		if (i==N-1)
		{
			cout<<a[i]<<endl;
		}
		else cout<<a[i]<<" ";
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>
long long n, x, a, b, c, ans;
int main() {
	scanf("%lld%lld", &n, &x);
	ans = n;
	if (x < n - x) {
		a = n - x;
		b = x;
	}
	else {
		a = x;
		b = n - x;
	}
	while (true) {
		if (a % b == 0) {
			ans += (2 * a / b - 1) * b;
			break;
		}
		else {
			ans += 2 * (a / b) * b;
			c = a % b;
			a = b;
			b = c;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,d,x,a[101],t;
	scanf("%d %d %d",&n,&d,&x);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<n;i++)
	{
		x++;
		int j=1;
		t=a[i];
		while(a[i]<=d)
		{
			a[i]=t*j+1;
			//printf("-----a[i]=%d,i=%d\n",a[i],i) ;
			j++;
			if(a[i]<=d)
				x++;
		}
	}
	printf("%d",x);
	return 0;
}

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

int main() {
  int A,B;
  cin >> A >>B;

  if (A < 6) {
    cout << 0 << endl;
  }
  else if (5 < A && A < 13 ){
    cout << B/2 << endl;
  }
  else if(A >= 13) {
    cout << B << endl;
  }
}

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


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

	int len = S.length();
	int cnt = 0;
	for (int i = 0; i < len / 2; i++) {
		if (S[i] != S[len - i - 1]) {
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

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

using namespace std;

int main() {
    unsigned int n, x;
    cin >> n >> x;

    int pos = 0;
    int ans = 1;
    for (int i = 0; i < n; ++i) {
        int l;
        cin >> l;
        pos += l;
        if (pos <= x) ans++;
    }

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

Measured memory_bytes: 256
// at_abc145c.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int MAXN = 9;
pair<int, int>arr[MAXN];
int main()
{
    int n;cin >> n;
    vector<int>v;
    double dist = 0;
    double fact = 1;
    for (int i = 0;i < n;i++) {
        fact *= (i + 1);
        v.push_back(i);
        cin >> arr[i].first >> arr[i].second;
    }
    do {
        double temp = 0;
        for (int i = 0;i < n-1;i++) {
            //temp += sqrt((arr[v[i]].first - v[i + 1].first) * (arr[i].first - arr[i + 1].first) + (arr[i].second - arr[i + 1].second) * (arr[i].second - arr[i + 1].second));
            dist += sqrt((arr[v[i]].first - arr[v[i + 1]].first) * (arr[v[i]].first - arr[v[i + 1]].first) + (arr[v[i]].second - arr[v[i + 1]].second) * (arr[v[i]].second - arr[v[i + 1]].second));
        }
       /* for (auto x : v) {
            cout << x << " ";
        }
        cout << temp << "\n";*/
    } while (next_permutation(v.begin(), v.end()));
    dist /= fact;
    printf("%.7f", dist);
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s, t;
  cin >> s >> t;
  int n = s.size();
  map<char, char> sm, tm;
  for(char C = 'a'; C <= 'z'; ++C) {sm[C] = -1; tm[C] = -1;}
  rep(i, n) {
    if(sm[s[i]] < 0) sm[s[i]] = t[i];
    if(tm[t[i]] < 0) tm[t[i]] = s[i];
    
    if(sm[s[i]] != t[i] || tm[t[i]] != s[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes"<< endl;
  return 0;
}


Measured memory_bytes: 776
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int N, A, B;
   cin >> N >> A >> B;
   cout << min(A, B) << " " << max(0, A + B - N) << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    vector<int> v(100001,0);
    int n;
    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        x++;
        v[x-1]++;
        v[x]++;
        v[x+1]++;
    }
    
    int ans=0;
    rep(i,0,100001){
        ans=max(ans,v[i]);
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
main(){
  int kingaku,kouka,k500,k100,k50,k10,k5;  
  while(1){
   scanf("%d",&kingaku);

  kouka=0;

   if(kingaku==0) break;

   kingaku=1000-kingaku;

   k500=kingaku/500;
   kouka+=k500;
   kingaku-=k500*500;  

   k100=kingaku/100;
   kouka+=k100;
   kingaku-=k100*100;
 
   k50=kingaku/50;
   kouka+=k50;
   kingaku-=k50*50;
  
   k10=kingaku/10;
   kouka+=k10;
   kingaku-=k10*10;

   k5=kingaku/5;
   kouka+=k5;
   kingaku-=k5*5;

   kouka+=kingaku;
  
 printf("%d\n",kouka);
  }
return 0; 
}

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

using namespace std;

#define int long long
#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 REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

string S;
ll N;

signed main() {
    cin >> S;
    N = S.length();
    ll ans = LINF;
    REP(i, N - 1) {
        if(S[i] != S[i + 1]) ans = min(ans, max(i + 1, N - i - 1));
    }
    if(ans == LINF) ans = N;
    cout << ans << "\n";
}

Measured memory_bytes: 512
#include <stdio.h>
 
int main()
{
	int i,j=0,N;
	scanf("%d",&N); 
	
	for(i=0;i<2;i++){
		if(N%10==9)j++;
	  N=N/10;}
	  
	  if(j!=0) printf("Yes");
	  else printf("No");
	return 0;
}
 


Measured memory_bytes: 1700
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
bool cmp (int a, int b) {
	return a > b;
}
int a[100005];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort (a + 1, a + 1 + n, cmp);
	int ans = 0;
	bool b = 0;
	for (int i = 1; i <= n + 1; i++) {
		if (a[i] == i){
			ans = i;
			break;
		}
		if (a[i] < i) {
			ans = i - 1;
			b = 1;
			break;
		}
	}
	bool sum = 0;
	if (!b) {
		sum = 1;
		for (int i = ans + 1; ; i++) {
			if (ans != a[i]) break;
			sum = !sum;
		}
		//cout <<"ssssssssss";
	}
	else {
		sum = (a[ans] - ans + 1) % 2;
		if (ans == a[ans + 1] && sum == 1) {
			sum = 1;
			for (int i = ans + 1; ; i++) {
				if (ans != a[i]) break;
					sum = !sum;
			}
		} 
	}
	cout << (sum ? "Second" : "First");
	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextLong()
    println(n * (n - 1) / 2)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 31392
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int R=sc.nextInt();
String ans="";
if(R<1200){ans="ABC";}else if(R<2800){ans="ARC";}else{ans="AGC";}
System.out.println(ans);
}}

Measured memory_bytes: 21716
import java.util.*;

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

    if (a < b && b < c) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
    sc.close();
  }
}


Measured memory_bytes: 26212
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}

LL n, a, b;
vector<LL> h, test;
//priority_queue<pair<LL, int> > q;
LL total;
LL t;

bool valid(LL tot) {
  vector<LL> empty;
  swap(test, empty);

  LL bdamage = b * tot;
//  printf("bdamage: %lld\n", bdamage);
  for (auto hh : h) {
    if (hh > bdamage) {
      test.PB(hh - bdamage);
    }
  }


  LL req = 0;
  for (auto tt : test) {
    req += (tt + (a - b - 1)) / (a - b);
  }

  return req <= tot;
}


int main() {
  GLL(n);
  GLL(a);
  GLL(b);

  total = 0;
  h.resize(n);
  FORN(i, n) {
    GLL(h[i]);
    total += h[i];
  }

  LL lo = 1, hi = 1000000010, guess = 0;
  while (lo <= hi) {
    LL mid = (lo + hi) / 2;
    if (valid(mid)) {
      hi = mid - 1;
      guess = mid;
    }
    else {
      lo = mid + 1;
    }
  }

  printf("%lld\n", guess);

  return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main ()
{
    int line;
    map<string,int>mymap;
    cin>>line;
    string x;
    while(line--)
    {
        cin>>x;
        mymap[x]++;
    }
    x="AC";
    cout<<"AC x "<<mymap[x]<<endl;
    x="WA";
    cout<<"WA x "<<mymap[x]<<endl;
    x="TLE";
    cout<<"TLE x "<<mymap[x]<<endl;
    x="RE";
    cout<<"RE x "<<mymap[x]<<endl;
    return 0;
}



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

int main(){
    ll A,V;
    cin >> A >> V;
    ll B,W;
    cin >> B >> W;
    ll T;
    cin >> T;
    if (W >= V){
        cout << "NO" << endl;
    }
    else{
        ll ans = (V - W) * T;
        if (max(A - B,B - A) <= ans){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int n,k;
int dp[100001];
int solve(int s){
  if(dp[s]+1)
    return dp[s];
  int ans=INT_MAX;
  for(int i=1;i<=k;i++){
    if(s+i>n-1)
      break;
    ans=min(ans,abs(a[s+i]-a[s])+solve(s+i));
  }
  return dp[s]=ans;
}
int main(){

  cin>>n>>k;
  for(int i=0;i<n;i++)
    cin>>a[i];
  memset(dp,-1,sizeof(dp));
  dp[n-1]=0;
  cout<<solve(0);

}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int arr[100005]={0};
int dp[100005]={0};
int k;
bool is_completed[100005]={0};
int dynamic(int a)
{
    if(a<2)
        return dp[a];
    else if(is_completed[a]==true)
        return dp[a];
    else
    {
        is_completed[a]=true;
        vector<int>v;
        for(int i=1;i<=k;i++)
        {
            if(a-i<0)
                break;
            v.push_back(dynamic(a-i)+abs(arr[a]-arr[a-i]));
        }
        dp[a]=*min_element(v.begin(),v.end());
        return dp[a];
    }
}
int main()
{
    int n;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    is_completed[0]=is_completed[1]=true;
    cout<<dynamic(n-1);
}


Measured memory_bytes: 10496
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def main():
    n,a,b,c,d = inpm()
    if (c+d)+(n-1)*(c-d) <= 1 and a-(n-1)*d <= b and b <= a+(n-1)*d:
        print('YES')
        return
    for i in range(n):
        left = a - (n-1)*d + i*( (n-1)*(d-c) + (c+d)+(n-1)*(c-d) )
        right = left + (n-1)*(d-c)
        if left <= b and b <= right:
            print('YES')
            return
    print('NO')

if __name__ == "__main__":
    main()

Measured memory_bytes: 41068
import collections
N=int(input())
A=list(map(int,input().split()))
if N%2==1:
    if 0 not in A:
        print(0)
    else:
        A.remove(0)
        Bc=dict(collections.Counter(A))
        for i in Bc.keys():
            if Bc[i]!=2:
                print(0)
                break
        else:
            print((2**(len(A)//2))%(10**9+7))
else:
    Bc=dict(collections.Counter(A))
    for i in Bc.keys():
        if Bc[i]!=2:
            print(0)
            break
    else:
        print((2**(len(A)//2))%(10**9+7))            

Measured memory_bytes: 16352
(N, K) = [int(n) for n in input().split()]
A = [int(n)-1 for n in input().split()]
v = [-1 for _ in range(N)]

D = [0]
v[0] = 0

cur = A[0]
i = 1

while v[cur] == -1:
    D.append(cur)
    v[cur] = i
    if i == K:
        print(cur+1)
        exit()

    i += 1
    cur = A[cur]

K -= v[cur]
K %= (i - v[cur])

print(D[v[cur] + K]+1)



Measured memory_bytes: 32208
use std::cmp::max;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        t: usize,
        a: [i32; n]
    }

    let mut mxs = vec![0; n];
    mxs[n - 1] = a[n - 1];
    for i in (0..n - 1).rev() {
        mxs[i] = max(a[i], mxs[i + 1]);
    }
    let mut idx_map: HashMap<i32, Vec<i32>> = HashMap::new();
    let mut diff_mx = 0;

    for i in 0..n - 1 {
        let diff = mxs[i + 1] - a[i];
        diff_mx = max(diff_mx, diff);
        if idx_map.contains_key(&diff) {
            idx_map.get_mut(&diff).unwrap().push(diff);
        } else {
            idx_map.insert(diff, vec![diff]);
        }
    }
    println!("{}", idx_map[&diff_mx].len());
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


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

int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  if(a+b<2*c){
    cout << a*x+b*y << endl;
  }
  else if(a>2*c&&x>y){
    cout << 2*c*x << endl;
  }
  else if(b>2*c&&x<y){
    cout << 2*c*y << endl;
  }
  else if(x>y){
    cout << 2*c*y+a*(x-y) << endl;
  }
  else{
    cout << 2*c*x+b*(y-x) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define pii pair<int,int>
#define ll long long
#define s second
#define f first
 
int n,a[105];
float m,s;
 
int main(){
  cin >> n >> m;
  for(int i=0;i<n;++i){
    cin >> a[i];
    s+=a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  int x=m;
  if(a[x-1]>=(float)(s/(4*m))){cout << "Yes";}
  else{cout << "No";}
  return 0;
}

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

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

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

    vector<int> x(n);
    for(int i = 0;i < n;i ++){
        cin >> x.at(i);
    }

    int ans = 0;
    for(int i = 0;i < n-1;i ++){
        if((x.at(i+1) - x.at(i)) * a < b){
            ans += (x.at(i+1) - x.at(i)) * a;
        }else{
            ans += b;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

using P=pair<int,int>;
void solve(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<string>s(h);
  int ans=numeric_limits<int>::max();
  rep(i,h)cin>>s[i];
  rep(bit,1<<(h-1)){
    int cnt=0;
    int pre=0;
    bool bad=false;
    vector<P>v;
    rep(i,h-1){
      if(bit&(1<<i)){
        ++cnt;
        v.eb(pre,i+1);//[pre,i+1)
        pre=i+1;
      }
    }
    v.eb(pre,h);//番兵を忘れない
    vector<int>sum(cnt+5);
    int j=0;
    int prej=j;
    while(j<w){
      rep(a,v.size()){
        REP(i,v[a].first,v[a].second){
          sum[a]+=s[i][j]=='1';
        }
      }
      bool ng=false;
      rep(a,v.size()){
        if(sum[a]>k)ng=true;
      }
      if(ng){
        ++cnt;
        if(prej==j){
          bad=true;
          break;
        }prej=j;
        rep(a,v.size())sum[a]=0;
      }
      else ++j;
    }
    if(bad)continue;
    chmin(ans,cnt);
  }
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

//同じコードでそんなにばらつくんですか

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	int H[100001];
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;

const int N = (1 << 18) + 10;
const int K = (1 << 9);

vector<pair<int, int>> prepare(vector<pair<int, int>> srt) {
	stable_sort(all(srt));
	vector<pair<int, int>> res;
	for (auto e : srt) {
		if (res.empty() || res.back().y < e.y) {
			res.push_back(e);
		}
	}
	return res;
}

vector<pair<int, int>> solve(vector<int> v, vector<int> w) {
	int n = (int)v.size();
	vector<pair<int, int>> srt = {{0, 0}};
	for (int i = 0; i < n; ++i) {
		int wcur = w[i];
		int vcur = v[i];
		for (int j = 0; j < (1 << i); ++j) {
			srt.emplace_back(srt[j].x + wcur, srt[j].y + vcur);
		}
	}
	/*
	for (int m = 0; m < (1 << n); ++m) {
		int ws = 0;
		int vs = 0;
		for (int i = 0; i < n; ++i) {
			if ((m >> i) & 1LL) {
				ws += w[i];
				vs += v[i];
			}
		}
		srt[ptr++] = {ws, vs};
	}
	*/
	return prepare(srt);
}

int n;
int q;
int val[N];
int wei[N];

vector<pair<int, int>> pre[K + 1];

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> val[i] >> wei[i];
	}
	pre[1] = {{0, 0}, {wei[1], val[1]}};
	for (int v = 2; v <= n && v <= K; ++v) {
		for (auto e : pre[v / 2]) {
			pre[v].push_back(e);
			pre[v].emplace_back(e.x + wei[v], e.y + val[v]);
		}
		pre[v] = prepare(pre[v]);
	}
	cin >> q;
	while (q--) {
		vector<int> v;
		vector<int> w;
		int i;
		int lim;
		cin >> i >> lim;
		for (; i > K; i /= 2) {
			v.push_back(val[i]);
			w.push_back(wei[i]);
		}
		vector<pair<int, int>> a = solve(v, w);
		vector<pair<int, int>> b = pre[i];
		/*
		vector<int> vt;
		vector<int> wt;
		for (i = 0; i < (int)v.size() / 2; ++i) {
			vt.push_back(v[i]);
			wt.push_back(w[i]);
		}
		vector<pair<int, int>> a = solve(vt, wt);
		vt.clear();
		wt.clear();
		for (i = (int)v.size() / 2; i < (int)v.size(); ++i) {
			vt.push_back(v[i]);
			wt.push_back(w[i]);
		}
		*/
		int j = (int)b.size() - 1;
		int ans = 0;
		for (i = 0; i < (int)a.size(); ++i) {
			while (j >= 0 && a[i].x + b[j].x > lim) {
				--j;
			}
			if (j >= 0) {
				ans = max(ans, a[i].y + b[j].y);
			}
		}
		cout << ans << "\n";
	}

    return 0;
}


Measured memory_bytes: 6928
import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int e = sc.nextInt();
            if(e==0) break;
            
            int m = Integer.MAX_VALUE;
            for(int i=0; i*i*i<=e; i++){
                int z = i*i*i;
                for(int j=0; j*j+z<=e; j++){
                    int y = j*j;
                    int k = e-z-y;
                    m = Math.min(m,i+j+k);
                }
            }
            System.out.println(m);
        }
    }

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

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()
 
 
 
int main()
{
    long long sum = 0;
    int k;
    cin >> k;
    for(int i =1; i<= k; i++)
    {
        for(int j = 1; j <= k; j++)
        {
            for(int n = 1; n <= k; n++)
            {
                sum+= __gcd(i,__gcd(j,n));
            }
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys


def cnt(n: int):
    i = 1
    ans = 0
    while i * i < n:
        if n % i == 0:
            ans += 1
        i += 1
    ans *= 2
    if i * i == n:
        ans += 1
    return ans


def solve(N: int):
    print(sum(1 for i in range(1, N + 1, 2) if cnt(i) == 8))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N=int(input())
h=list(map(int, input().split()))

cnt = 0
while 1:
  if max(h)==0: break

  i = 0
  while i<N:
    if h[i]==0:
      i+=1
    else:
      cnt += 1
      while i<N and h[i]>0:
        h[i] -= 1
        i += 1
print(cnt)


Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>

using namespace std;

long long n;
long long ans , ans2;
void work () {
	long long i , t;
	scanf ( "%lld" , &n );
	for ( i = 1 ; i * i < n ; i++ ) {
		if ( n % i == 0 ) {
			t = n / i;
			if ( t != 1 && n / (t-1) == n % (t-1) ) ans += t - 1;
			//printf ( "%lld\n" , t - 1 );
		}
	}
	/*for ( i = 1 ; i <= n ; i++ ) {
		if ( n / i == n % i ) {
			printf( "%lld\n" , i );
			ans2 += i;
		}
	}*/
	printf ( "%lld\n" , ans );
	//printf ( "%lld\n" , ans2 );
}
int main () {
	work ();
	return 0;
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


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

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


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    i64 n, k;
    cin >> n >> k;

    auto f = [&](i64 val){
        i64 sum = val;
        for(int i = 0; i < n - 1 && val; ++i){
            val /= 2;
            sum += val;
        }
        return sum <= k;
    };

    i64 ok = (k + n - 1) / n, ng = k + 1;
    for(int i = 0; i < 100; ++i){
        i64 mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
}




Measured memory_bytes: 3180
import java.util.Scanner;

public class Main {

    public static long dpSol(int a[][],int n,int w,long dp[][]){
       // System.out.println(n+" n "+w+"  w "+dp[n][w]);
        if(n==0){
            return 0;
        }
        if(w==0){
            return 0;
        }
        if(dp[n][w]!=-1){
            return dp[n][w];
        }

        long ans1=-1;
        if(w>=a[n][1]){
            ans1 = dpSol(a,n-1,w-a[n][1],dp)+a[n][2];
        }
        long ans2 = dpSol(a,n-1,w,dp);
       // System.out.println(ans2+" ans 2 ");

        dp[n][w]=Math.max(ans1,ans2);
        //System.out.println(dp[n][w]);
        return dp[n][w];
    }
    public static int recSol(int a[][],int n,int w){
        if(n==0){
            return 0;
        }
        if(w==0){
            return 0;
        }
        int ans1=-1;
        if(w>=a[n][1]) {
             ans1 = recSol(a, n - 1, w - a[n][1]) + a[n][2];
        }
        int ans2 = recSol(a,n-1,w);
        //System.out.println(n+" "+Math.max(ans1,ans2));
        return Math.max(ans1,ans2);
    }
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int a[][] = new int[n+1][3];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=2;j++){
                a[i][j] = sc.nextInt();
            }
        }
        long dp[][]= new long[n+1][w+1];
        for(int i=0;i<=n;i++){
            for(int j=0;j<=w;j++){
                dp[i][j] = -1;
            }
        }
        System.out.println(dpSol(a,n,w,dp));

    }
}


Measured memory_bytes: 126676
s=input()
l=len(s)
odd=s[::2]
even=s[1::2]
o0=odd.count("0")
o1=odd.count("1")
e0=even.count("0")
e1=even.count("1")
if o0+e1>o1+e0:
    print(o1+e0)
else:
    print(o0+e1)

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

int main()
{
 ll n,k;
 cin>>n>>k;
 int arr[n];
 for(int i=0;i<n;i++)cin>>arr[i];
 int dp[(int)1e6]={0};
 for(int i=0;i<(int)1e6;i++)
 {
     for(int x=0;x<n;x++)
      {
          if(i>=arr[x]&&dp[i-arr[x]]==0)dp[i]=1;
      }
 }

 if(dp[k]==1)cout<<"First"<<endl;
 else cout<<"Second"<<endl;
}
  

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

int main() {
    int n, m; cin >> n >> m;
    
    vector<int> f(n + 1, 0);

    for(int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        f[a] ^= 1, f[b] ^= 1;
    }
    
    int cnt = 0;

    for(int i = 1; i <= n; ++i) {
        cnt += f[i];
    }
    
    if(cnt <= 0) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
bool search();
int ans[100009];
int n;
string s;

int main(){
  cin>>n>>s;
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      memset(ans,0,sizeof(ans));
      ans[0]=i;
      ans[1]=j;

      if(search()){
	for(int k=0;k<n;k++){
	  if(ans[k]==0){
	    cout<<'S';
	  }
	  else{
	    cout<<'W';
	  }
	}
	cout<<endl;
	return(0);
      }
    }
  }

  cout<<-1<<endl;
  return(0);
}

bool search(){
  for(int i=2;i<n;i++){
    if(ans[i-1]==0){
      if(s[i-1]=='o'){
	ans[i]=ans[i-2];
      }
      else{
	ans[i]=!ans[i-2];
      }
    }
    else{
      if(s[i-1]=='o'){
	ans[i]=!ans[i-2];
      }
      else{
	ans[i]=ans[i-2];
      }
    }
  }

  int cnt=0;
  if(ans[0]==0){
    if(s[0]=='o'&&ans[n-1]==ans[1])cnt++;
    else if(s[0]=='x'&&ans[n-1]!=ans[1])cnt++;
  }
  else{
    if(s[0]=='o'&&ans[n-1]!=ans[1])cnt++;
    else if(s[0]=='x'&&ans[n-1]==ans[1])cnt++;
  }
  if(ans[n-1]==0){
    if(s[n-1]=='o'&&ans[n-2]==ans[0])cnt++;
    else if(s[n-1]=='x'&&ans[n-2]!=ans[0])cnt++;
  }
  else{
    if(s[n-1]=='o'&&ans[n-2]!=ans[0])cnt++;
    else if(s[n-1]=='x'&&ans[n-2]==ans[0])cnt++;
  }

  if(cnt==2)return true;
  else return false;
}


Measured memory_bytes: 896
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, A;
    cin >> X >> A;
    if (X < A) cout << 0 << endl;
    else cout << 10 << endl;

    return 0;
}


Measured memory_bytes: 3652
import functools
from fractions import gcd
n,k = map(int,input().split())
li = list(map(int,input().split()))
g = functools.reduce(gcd,li)
if k > max(li):
    print("IMPOSSIBLE")
elif g == 1:
    print("POSSIBLE")
else:
    if k % g == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Measured memory_bytes: 16304
#include<stdio.h>
long long int n, a[1010][2];
long long int c, d,min,e,f,k,t;

int main(){
    int i;
    scanf("%lld",&n);
    scanf("%lld %lld",&c,&d);
    for(i=1;i<n;i++){
        scanf("%lld %lld",&e,&f);
        if((c/e)>(d/f)){
            t=e*(c/e);
            k=f*(c/e);
        }else{
            t=e*(d/f);
            k=f*(d/f);
        }
        while(t<c||k<d){
            t=t+e;
            k=k+f;
        }
        c=t;
        d=k;
    }
    printf("%lld\n",c+d);
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
std::vector<std::string> split(const std::string &str, const char delemiter) {std::vector<std::string> res;std::stringstream ss(str);std::string buffer; while( std::getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;}
int msb(int x) {return x?31-__builtin_clz(x):-1;}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    ll A,B,C,K; cin >> A >> B >> C >> K;
    for(int i = 0; i <= K; ++i) {
        for(int j = 0; i+j <= K; ++j) {
            for(int k=0; i+j+k <= K; ++k) {
                ll S=A,T=B,U=C;
                for(int l = 0; l < i; ++l) S *= 2;
                for(int l = 0; l < j; ++l) T *= 2;
                for(int l = 0; l < k; ++l) U *= 2;
                corner(S<T && T<U,"Yes");
            }
        }
    }    
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> C(3, vector<int>(3));
  rep(i, 3) rep(j, 3) cin >> C[i][j];
  bool ok = true;
  rep(i, 2) rep(j, 2) {
    ok &= (C[i+1][j+1]-C[i][j+1] == C[i+1][0]-C[i][0]);
  }
  rep(j, 2) rep(i, 2) {
    ok &= (C[i+1][j+1]-C[i+1][j] == C[0][j+1]-C[0][j]);
  }
  cout << (ok ? "Yes" : "No") << endk;
  return 0;
}


Measured memory_bytes: 3536