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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x,int y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(int x,int y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(int x,int y)
{
    return (x%mod *1LL* y%mod)%mod;
}

inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}


int main()
{
    ///freopen("output.txt","w",stdout);
    //freopen("input.txt","r",stdin);

    ///FastIO;

    int n;
    while(scn(n) == 1)
    {
        lli res = 0, Ag,Bg, As,Bs;
        Ag = Bg = As = Bs = 0;
        int cnt = 0 , mn = mod+3;

        for(int i=1; i<=n; i++)
        {
            int a,b;
            scn2(a,b);
            res += a;
            if(a == b) cnt++;
            if(a>b) mn = min(b,mn);
        }

        res -= mn;

        if(cnt == n) res = 0;

        cout<<res;
       // cout<<endl;
    }
    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;
const ll MOD=1000000007;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

string s;
ll ans;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> s;
    int l = s.size();
    rep(i, 0, 1 << (l-1)) {
        ll sum = 0LL;
        rep(j, 0, l) {
            sum *= 10;
            sum += s[j] - '0';
            if (i & (1 << j)) {
                ans += sum;
                sum = 0;
            }
        }
        ans += sum;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    string s;
    cin>>s;
    
    rep(i, s.length()){
        if(i%2==1 && s[i]=='R'){
            cout << "No" << endl;
            return 0;

        }else if(i%2==0 && s[i]=='L'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}


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

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

constexpr char color[4] = {'R', 'Y', 'G', 'B'};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    int d;
    cin >> d;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            const int x = (i + j) / d;
            const int y = (W - j + i - 1) / d;
            if (y % 2 == 0) {
                cout << color[x % 4];
            } else {
                cout << color[(x + 2) % 4];
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n, i, j;
	cin >> n;
	vi a(n);
	int M = -inf, m = inf;
	int Mi, mi;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > M) {
			M = a[i];
			Mi = i;
		}
		if (a[i] < m) {
			m = a[i];
			mi = i;
		}
	}
	if (M == m) {
		cout << 0 << endl;
		return 0;
	}
	int cnt = 0;
	bool sei;
	if (m > 0) {
		sei = true;
	}
	else if (M < 0) {
		sei = false;
	}
	else {
		if (abs(M) >= abs(m)) {
			for (i = 0; i < n; i++) {
				a[i] += M;
				cnt++;
			}
			sei = true;
		}
		else {
			for (i = 0; i < n; i++) {
				a[i] += m;
				cnt++;
			}
			sei = false;
		}
	}
	if (sei) {
		cout << 2 * n - 1<< endl;
		for (i = 0; i < n; i++) {
			cout << Mi + 1 << " " << i + 1 << endl;
		}
		for (i = 1; i <= n - 1; i++) {
			cout << i << " " << i + 1 << endl;
		}
		return 0;
	}
	else {
		cout << 2 * n - 1 << endl;
		for (i = 0; i < n; i++) {
			cout << mi + 1 << " " << i + 1 << endl;
		}
		for (i = n; i >= 2; i--) {
			cout << i << " " << i - 1 << endl;
		}
		return 0;
	}
}

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

int main(){
  int count = 0;
  string s,t;
  
  cin >> s >> t;
  
  for( int i = 0; i < 3; i++ ){
    if(s.at(i)==t.at(i)){
      count++;
    }
  }
  
  cout << count;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

A,B,C=get.sort{|x,y|y<=>x}
puts (A+B).to_i+C.to_i

Measured memory_bytes: 3836
from fractions import gcd
import sys
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [i // 2 for i in a]
def div2check(i):
    count = 0
    while i % 2 == 0:
        count += 1
        i //= 2
    return count
c = [div2check(i) for i in b]
if c.count(c[0]) != n:
    print(0)
    sys.exit()

lcm = b[0]
for i in b[1:]:
    lcm = lcm * i // gcd(lcm, i)
print((m // lcm + 1) // 2)

Measured memory_bytes: 16280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<complex.h>
#include<utility>
using namespace std;

typedef long long int ll;

int main(){


    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    int tmp = -1;
    int count = 0;
    for(int i = 0;i < n-1;i++){
        if(a[i] == a[i+1]){
            a[i+1]=tmp;
            count++;
            tmp--;
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
    ll n; cin >> n;
    V<double> x(n+1), y(n+1), r(n+1, 0);
    V<double> d(n+1, HIGHINF);
    priority_queue<P<double, ll>, V<P<double, ll> >, greater<P<double, ll> > > que;
    REP(i, n) {
        cin >> x[i] >> y[i] >> r[i];
        double tmpd = sqrt((x[i]-xs)*(x[i]-xs) + (y[i]-ys)*(y[i]-ys));
        d[i] = max(tmpd - r[i], 0.0);
        if (d[i] < 0) d[i] = 0;
        que.push(make_pair(d[i], i));
    }
    x[n] = xt; y[n] = yt;
    d[n] = sqrt((xt-xs)*(xt-xs) + (yt-ys)*(yt-ys));
    
    V<bool> visit(n+1);
    while (!que.empty()) {
        P<double, ll> q = que.top(); que.pop();
        if (visit[q.second]) continue;
        visit[q.second] = true;
        REP(i, n+1) {
            if (visit[i]) continue;
            ll u = q.second;
            if (sqrt((x[i]-x[u])*(x[i]-x[u]) + (y[i]-y[u])*(y[i]-y[u])) < r[i]+r[u]) {
                chmin(d[i], q.first);
                que.push(make_pair(d[i], i));
            } else {
                double tmpd = sqrt((x[i]-x[u])*(x[i]-x[u]) + (y[i]-y[u])*(y[i]-y[u])) - r[i] - r[u];
                if (d[i] > d[u]+tmpd) {
                    d[i] = d[u]+tmpd;
                    que.push(make_pair(d[i], i));
                }
            }
        }
    }
    cout << fixed << setprecision(12) << d[n] << endl;
    return 0;
}


Measured memory_bytes: 6260
#include <stdio.h>

int main(void){
    int N;
    scanf("%d", &N);
    int n = N % 10;
    char *ans;
    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
        ans = "hon";
    }else if(n == 0 || n == 1 || n == 6 || n == 8){
        ans = "pon";
    }else{ ans = "bon"; }
    printf("%s\n", ans);
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n;
	cin >> n;
	vector<ll>v(n);
	rep(i, n)cin >> v[i];
	vector<pair<ll, ll>>vE(pow(10, 6)), vO(pow(10, 6));
	rep(i, pow(10, 6)) {
		vE[i] = make_pair(0, i);
		vO[i] = make_pair(0, i);
	}
	rep(i, n) {
		if (i % 2 == 0)vE[v[i]].first++;
		else vO[v[i]].first++;
	}
	sort(all(vE));
	sort(all(vO));
	ll mvE = vE[vE.size() - 1].first;
	ll mvE2 = vE[vE.size() - 2].first;
	ll mvO = vO[vO.size() - 1].first;
	ll mvO2 = vO[vO.size() - 2].first;

	if (vE[vE.size() - 1].second != vO[vO.size() - 1].second)cout << n - mvE - mvO << endl;
	else cout << n - max(mvE + mvO2, mvO + mvE2) << endl;
}



Measured memory_bytes: 32256
# -*-coding: utf-8 -*-

#金額と個数の入力
sum,num = map(int,input().split())
#嫌いな数字の入力
dis = list(map(int,input().split()))

pay = sum
while True:
  flag = 0;
  str_pay = str(pay)
  for i in str_pay:
    if int(i) in dis:
      flag = 1
      break
  if flag == 0:
    break
  else:
    pay = pay + 1
print(pay)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int n, k, c=0, result;
    scanf("%d %d", &n , &k);
    up: result=n/k;
    if(result>0)
    {
        c++;
        n=result;
        goto up;
    }
    else if (result==0)
    {
        printf("%d", c+1);
        return 0;
    }
}


Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include<set>
#include<stdio.h>
#include <bitset>
#include<string.h>
#include <unordered_map>
#define ii int64_t
#define PI 3.14
#define lli long long int
#define li long int
#define deb(x) cout<<"\nhi"<<x<<"\n"
#define mod 1000000007
#define f(x,n) for(int x=0;x<n;++x)
#define ff(x,y,z) for(x=y;x<=z;++x)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// while(scanf("%d",&n)!=EOF)

using namespace std;
 
vector < vector <int> > v(100005);
int dp[100005];


int dhundhle(int i)
{
    //deb(1);
    if (v[i].empty())return 0;
    
    if(dp[i]>=0)return dp[i];
    
    int ans =-1;
    for(int j=0;j<v[i].size();j++)
    {
        ans=max(ans,dhundhle(v[i][j])+1);
        dp[i]=ans;
    }
    return ans;
    
}



int main()
 
{
    fio
    int n,m,i,j,x,y;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
    }
    //deb(2);
    memset(dp, -1, sizeof(dp));
    
    int ans=-1;
    for(i=1;i<=n;i++)
    {
        ans=max(ans,dhundhle(i));
    }
    cout<<ans;

}





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

namespace ConsoleApp15
{
    class Class398
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long axor = 0;
            for(int i = N-1; i >=0; i--)
            {
                axor = axor ^ a[i];
            }
            long[] ans = new long[N];
            for (int i = 0; i < N; i++)
            {
                
                ans[i] = axor^a[i];
            }
            Console.WriteLine(string.Join(" ",ans));
        }
    }
}


Measured memory_bytes: 68176
// be name khoda
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,r=0,ans=0;
    string s;
    cin >> n >> s;
    for (int i=0;i<n;i++)
        if (s[i]=='R') r++;

    for (int i=0;i<r;i++) {
        if (s[i]=='W') ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
using namespace std;
int n,m,c,a[20],b,cnt,ans;
int main(void){
    cin>>n>>m>>c;
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cnt=0;
        for(int j=0;j<m;j++){
            cin>>b;
            cnt+=b*a[j];
        }
        if(cnt+c>0)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> h(n+1);
    for (int i = 0; i < n; ++i) {
        cin >> h[i+1];
    }
    auto dp = make_v(n+1, x+1, INF<ll>);
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < i; ++j) {
            for (int k = 0; k+(i-j-1) <= x; ++k) {
                chmin(dp[i][k+(i-j-1)], dp[j][k] + abs(h[j]-h[i]));
            }
        }
    }
    ll ans = INF<ll>;
    for (int j = 0; j <= n; ++j) {
        for (int k = 0; k+(n-j) <= x; ++k) {
            chmin(ans, dp[j][k] + h[j]);
        }
    }
    cout << ans/2 << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int N,Y;
    cin >> N >> Y;
    int x,y,z;
    int i;
    bool f = true;
    int M = Y / 1000 - N;
    for(i = 0;M - 9*i >= 0; i++)
    {
        if((M - 9*i) % 4 == 0)
        {
            x = i;
            y = (M - 9*i) / 4;
            if(x + y <= N)
            {
                z = N - x - y;
                cout << x << " " << y << " " << z;
                f = false;
                break;
            }
        }
    }
    if(f)
    {
        cout << -1 << " " << -1 << " " << -1;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

int main(){
    int N;
    int l[400],u[400],p[400];
    scanf("%d",&N);
    rep(i,N)scanf("%d%d%d",&l[i],&u[i],&p[i]);

    int dp[400];fill_n(dp,400,-1);
    dp[0]=0;

    for(int i=0;i<N;i++){
        for(int j=0;j<=393;j++){
            for(int k=l[i];k<=u[i];k++){
                if(j-k<0||dp[j-k]==-1)continue;
                dp[j]=max(dp[j],dp[j-k]+p[i]);
            }
        }
    }
    int ans[400];
    int M;
    scanf("%d",&M);
    for(int i=0;i<M;i++){
        int w;
        scanf("%d",&w);
        if(dp[w]==-1){
            puts("-1");
            return 0;
        }
        ans[i]=dp[w];
    }

    for(int i=0;i<M;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 1196
n, m = map(int, input().split())
c = list(map(int, input().split()))
# dp[i][j] = i 番目までを使用して総和がj になる組み合わせ
INF = 5 * 10 ** 4
dp = [[INF] * (n + 1) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    for j in range(n + 1):
        if j >= c[i - 1]:
            dp[i][j] = min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            )
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[m][n])




Measured memory_bytes: 43780
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}


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

  ll v[n-1][3];

  REP(i, n-1){
    ll c, s, f;
    cin>>c>>s>>f;
    v[i][0] = c;
    v[i][1] = s;
    v[i][2] = f;
  }

  REP(i, n-1){
    ll start = v[i][1];
    start += v[i][0];
    FOR(j, i+1, n-2){
      //cout<<start<<" ";
      if(start-v[j][1]==0) start += v[j][0];
      else if(start-v[j][1]<0) start = v[j][1] + v[j][0];
      else {
        if((start-v[j][1])%v[j][2]==0) start += v[j][0];
        else start += (v[j][2]-((start-v[j][1])%v[j][2]) + v[j][0]);
      }
      //cout<<j<<":"<<start<<" ";
    }
    cout<<start<<endl;
  }
  cout<<"0"<<endl;
  return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
long int a,b,x;
 cin >> a >> b >> x;
 long int  aa, bb;
 aa = a /x;
 bb = b / x;
 if (a%x==0){
   aa--;
 }
 cout << bb - aa << endl;

}

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

int main() {
	char str[5];
	char s1, s2, s3, s4;
	int count = 0;
	cin >> str;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			if (str[i] == str[j]) {
				count++;
			}
		}
	}
	if (count == 8) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int x = scan.nextInt();
    int left = 0;
    int right = 0;
    int temp = 0;
    for(int i=0; i<m; i++){
      temp = scan.nextInt();
      if(temp < x)left++;
      else{
        right++;
      }
    }
    System.out.println(Math.min(left, right));

  }
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 200010, M = 1010;

int n;
int a[N], b[N];
LL m;

bool check(LL x)
{
	LL sum = 0;
	for (int i = 0; i < n; i ++ ) sum += max(0LL, (LL)a[i] - x / (LL)b[i]);
	return sum <= m;
}

int main()
{
	scanf("%d%lld", &n, &m);
	for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
	for (int i = 0; i < n; i ++ ) scanf("%d", &b[i]);
	sort(a, a + n);
	sort(b, b + n, greater<int>());
	
	LL l = 0, r = 1e12 + 10;
	while (l < r)
	{
		LL mid = l + r >> 1;
		if(check(mid)) r = mid;
		else l = mid + 1LL;
	}
	
	printf("%lld\n", r);
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define MOD 1000000007

#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)

using namespace std;

const int maxn=511;

ll dp[maxn][maxn],a[maxn*maxn],ans=0;
int n;
ll dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool vis[maxn][maxn];

ll nv(ll x,ll y)
{
	ll mn=1e18;
	
	for(int i=0;i<4;i++)
	{
		ll tx=x+dx[i],ty=y+dy[i];
		
		if(tx>=0&&tx<n&&ty>=0&&ty<n)
		{
			mn=min(mn,dp[tx][ty]);
		}
		
	}
	
	return mn+(vis[x][y]==0);
}

void ref(ll x,ll y)
{
	dp[x][y]--;
	
	for(int i=0;i<4;i++)
	{
		ll tx=x+dx[i],ty=y+dy[i];
		
		if(tx>=0&&tx<n&&ty>=0&&ty<n)
		{
			if(nv(tx,ty)<dp[tx][ty])
			{
				ref(tx,ty);
			}
		}
		
	}
	
	return;
}

int main(){
	
	fast;itt;now;
	
	cin>>n;
	
	for(int i=0;i<n*n;i++)
	{
		cin>>a[i];
		a[i]--;
	}
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			dp[i][j]=min(min(i,n-i-1),min(j,n-j-1))+1;
		}
	}
	
	for(int i=0;i<n*n;i++)
	{
		ll x=a[i]/n,y=a[i]%n;
		vis[x][y]=true;
		
		ref(x,y);
		ans+=dp[x][y];
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 23352
#include<bits/stdc++.h>
using namespace std;
long long a[100010],dp[100010];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		dp[i]=1<<31-1;
	}
	dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;i++)
		for(int c=1;c<=k;c++)
			if(i-c>0)dp[i]=min(dp[i-c]+abs(a[i]-a[i-c]),dp[i]);
	printf("%d",dp[n]);
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF (1e9+1)
#define N 100001
using namespace std;
typedef long long ll;
ll n,m,s[N],t[N],p[N],P[N];
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>s[i]>>t[i];
  for(int i=1;i<=m;i++) cin>>p[i];
  p[m+1]=P[m+1]=INF;
  sort(p,p+m+2);
  for(int i=1;i<m+2;i++)P[i]=p[i]-p[i-1];
  for(int i=2;i<m+1;i+=2)P[i]+=P[i-2],P[i+1]+=P[i-1];
   
  ll sum=0; 
  for(int i=0;i<n;i++){
    int idx2=upper_bound(p,p+m+2,s[i])-p,idx1=idx2-1;
    int idx4=upper_bound(p,p+m+2,t[i])-p,idx3=idx4-1;
 
    int f;
    if(idx2==idx4)sum+=abs(t[i]-s[i]);
    else if(s[i]<t[i]){
      sum+=p[idx2++]-s[i];
      f=idx2%2==idx3%2;
      sum+=P[idx3-f]-P[idx2-1]+f*(t[i]-p[idx3]);
    } 
    else{
      sum+=s[i]-p[idx1--];
      f=idx1%2==idx4%2;
      sum+=P[idx1]-P[idx4-!f]+f*(p[idx4]-t[i]);
    }
  }
  cout <<sum<<endl;
  return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int h,w;
    char c[52][52] = {{}};

    Scd2(h,w);
    Rep(i,h){
        Scs(c[i+1]+1);
    }

    bool ans = true;
    Repe(i,h+1,1){
        Repe(j,w+1,1){
            if( c[i][j] == '#' && c[i][j+1] != '#' && c[i][j-1] != '#' && c[i+1][j] != '#' && c[i-1][j] != '#' ){
                ans = false;
            }
       }
    }

    YesNo(ans);


    return 0;
}



Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n = int(input())
    S = {input() for _ in range(n)}
    print(len(S))
if __name__ == '__main__':
    main()

Measured memory_bytes: 31188
#include <stdio.h>

int main()
{
    int n, m, c;
    scanf("%d%d%d", &n, &m, &c);
    int a[m], b[m];
    int jud = 0;
    int k=0;
    int i;
    for(i = 0; i < m; i++){
        scanf("%d",&b[i]);
    }
    for(;n>0;n--){
        jud = c;
        for(i = 0; i < m; i++){
            scanf("%d",&a[i]);
            jud += a[i] * b[i];
        }
        if(jud > 0){
            k++;
        }
    }
    printf("%d\n",k);

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1345

?????????????????????????????????????????????????????????????????????????????????????????°???????????????
????????????????????£??\???????????????????????¢?????\?????????????????¨??????????¨±????????????
????°??????\???????????°??§?¨??????§??????????????°????????????????????????

  ???????????????????????????????´??????????????????£??????????????£?????¨?????????
??????????????????????????¬?????°????????????????????£?????????????????????
??????????????????????????¬?????°??????????????????????????????0???1????????§??£???????????±?????????
?????????????????????????????±????????§??????????????¨?????°???"011100"???????????¬?????°???????????????
"1 3 2"??§??????.??????????????¬?????°??????????????????????????????????????????????????????????????¨??????????????????????????????
0???????§???????1,?????????1???????§???????0?????????????????????????????????????????????????????????

??????????????±???????????§?????????????????????"100101"???????????¬?????°????????????"1 3 2"?????????????????????????????????????????°????????????,
????????????"100011" or "011100"?????????????????°?????????????????¨??????????????????"011100"????????????????°?????????¨???4????????????
???????????????????????°?????????????????¨??????????????????"100011"???????????????1????????????????????§?????????
?????????????????????????????????1??????

*/

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<int> b1(N), b2(N);
	vector<int> p1(M), p2(M);
	for (int i = 0; i < N;i++) cin >> b1[i];
	b2 = b1;
	for (int i = 0; i < M;i++) cin >> p1[i];
	p2 = p1;

	int ans1 = 0;
	int key = 0;
	int at = 0;
	for (int i = 0; i < N;i++) {
		if (b2[i] != key) {
			bool f = false;
			for (int j = i + 1; j < N;j++) {
				if (b2[j] == key) {
					ans1 += j - i;
					swap(b2[i], b2[j]);
					f = true;
					break;
				}
			}
			if (!f) {

				ans1 = (1 << 30);
			}
		}
		p2[at]--;
		if (p2[at] == 0) {
			at++;
			key = (key == 0 ? 1 : 0);
		}
	}
	b2 = b1;
	p2 = p1;
	int ans2 = 0;
	key = 1;
    at = 0;
	for (int i = 0; i < N;i++) {
		if (b2[i] != key) {
			bool f = false;
			for (int j = i + 1; j < N;j++) {
				if (b2[j] == key) {
					ans2 += j - i;
					swap(b2[i], b2[j]);
					f = true;
					break;
				}
			}
			if (!f) {
				ans2 = (1 << 30);
			}
		}
		p2[at]--;
		if (p2[at] == 0) {
			at++;
			key = (key == 0 ? 1 : 0);
		}
	}
	cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 3224
N, A, B, C = gets.split.map(&:to_i)
Ss = readlines.map(&:chomp)

def choice(x, y, s1)
  case
  when x == 0 && y == 0
    puts 'No'
    exit
  when x > y
    [x - 1, y + 1, false]
  when x == 1 && y == 1
    s1 ? [x + 1, y - 1, true] : [x - 1, y + 1, false]
  else
    [x + 1, y - 1, true]
  end
end

a, b, c = A, B, C
ans = []
(0 ... N).each do |i|
  case Ss[i]
  when 'AB'
    a, b, x = choice(a, b, (Ss[i + 1] || 'AB').include?('A'))
    ans << (x ? 'A' : 'B')
  when 'AC'
    a, c, x = choice(a, c, (Ss[i + 1] || 'AC').include?('A'))
    ans << (x ? 'A' : 'C')
  when 'BC'
    b, c, x = choice(b, c, (Ss[i + 1] || 'BC').include?('B'))
    ans << (x ? 'B' : 'C')
  end
end
puts 'Yes'
puts ans

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

using namespace std;

int main(){
    long long a, b_100;
    string b;

    cin >> a >> b;
    b_100 = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0')*1;

    cout << a*b_100/100 << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

string s;
map<char,int> ma;
bool f = true;

P dfs(int l,int r){
    if(!f) return mp(-1,-1);
    if(r - l <= 1) return mp(ma[s[l]],0);
    int cnt = 0;
    int idx = -1;
    for (int i = l; i < r; i++) {
        if(cnt == 1 && s[i] == '-'){
            idx = i;
            break;
        }
        else if(s[i] == '[') cnt++;
        else if(s[i] == ']') cnt--;
    }
    auto ll = dfs(l+1,idx), rr = dfs(idx+1,r-1); 
    if(ll.fs == ll.sc && rr.fs == rr.sc) f = false;
    else if(ll.fs == ll.sc) return mp(rr.fs,rr.sc+1);
    else if(rr.fs == rr.sc) return mp(ll.fs,ll.sc+1);
    else f = false;
    return mp(-1,-1);
}


int main(){
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        int a = s[i] - 'a';
        if(0<=a&&a<26){
            char ch;cin >> ch;
            int num;cin >> num;
            ma[ch] = num;
        }
    }
    auto r = dfs(0,s.length());
    if(f&&r.fs == r.sc) puts("Yes");
    else puts("No");
    return 0;
}



Measured memory_bytes: 3216
# 高橋くんが好きな整数の入力
K = gets.to_i

# 判定の計算を簡単にするため、Lを定義
if K % 7 == 0
  # Kが7の倍数ならLを9K/7と定義
  L = 9 * K / 7
else
  # そうでなければLを9Kと定義
  L = 9 * K
end

mod = 10 % L
# Lと10が互いに素でなければ
if L % 2 == 0 || L % 5 == 0
  # 数列にKの倍数は見つからない
  puts -1
elsif mod == 1
  puts 1
else
  for i in 2..9000000 do
    mod *= 10
    if mod % L == 1
      puts i
      break
    end
    mod %= L
  end
end

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

int main() {
  int N, answer = 0, number = 1;
  cin >> N;
  vector<int> a(N);
  vector<int> counter(N);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  for(int i = 0; i < N; i++) {
    number = a.at(number - 1);
    answer++;
    counter.at(number - 1)++;
    if(number == 2) {
      cout << answer << endl;
      break;
    }
    else if (counter.at(number -  1) == 2) {
      cout << "-1" << endl;
      break;
    }
  }
}

Measured memory_bytes: 4048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W	 = in.readLine();
		String last = W.split(" ")[0];

//		Scanner sc = new Scanner(System.in);
//		int N = sc.nextInt();

		if(last.equals("ABC")) {
			System.out.println("ARC");
		}else {
			System.out.println("ABC");
		}




	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}



}


Measured memory_bytes: 32596
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion

signed main() {
    int n;cin >> n;
    /*int sum=0,mult=1;
    rep(i, n) {
        int a;cin >> a;
        sum+=a;
        mult*=a;
    }
    cout << setprecision(10) << (double)(mult)/((mult*n)/sum) << endl;*/
    long double ans = 0;
    rep(i, n) {
        int a;cin >> a;
        ans+=1.0/a;
    }
    cout << setprecision(10) << 1.0/ans << endl;
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

//const int mod = 998244353;
const int mod=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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*(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;
  }
};

// 出力は.xで！！！！

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  combination C(2000100);
  mint ans=0;
  ans+=C(c+d+2,c+1)-1;
  ans-=C(a+d+1,d+1)-1;
  ans-=C(b+c+1,c+1)-1;
  ans+=C(a+b,a)-1;

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

Measured memory_bytes: 34372
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,ans = 0;
    cin>>n;
    vi a(n),b(n);
    rep(i,0,n){
        cin>>a[i]>>b[i];
    }
    sort(all(a));
    sort(all(b));
    if(n&1){
        int ans = b[n/2] - a[n/2] + 1;
        cout<<ans<<endl;return 0;
    }
    else{
        int medmin = a[n/2] + a[n/2-1];
        int medmax = b[n/2] + b[n/2-1];
        int ans = medmax - medmin + 1;
        cout<<ans<<endl;return 0;
    }
}

Measured memory_bytes: 6352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 10;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s, t;
	int n;
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++)
			cout << s[i] << t[i];
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,p[300000],dist[510][510];
bool b[510][510];
P pos[300010];
#define PP pair<int,P>
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n*n){
        cin>>p[i];
        p[i]--;
        pos[i]={i/n,i%n};
    }
    rep(i,n){
        rep(j,n){
            dist[i][j]=min({i,j,n-i-1,n-j-1});
        }
    }
    int ans=0;
    rep(i,n*n){
        int x=pos[p[i]].fi,y=pos[p[i]].se;
        ans+=dist[x][y];
        b[x][y]=true;
        queue<P>q;
        q.push({x,y});
        while(!q.empty()){
            P pp=q.front();
            q.pop();
            x=pp.fi,y=pp.se;
            if(b[x][y]==false){
                rep(k,4){
                    int X=x+dx[k],Y=y+dy[k];
                    if(0<=X&&X<n&&0<=Y&&Y<n){
                        if(dist[X][Y]>dist[x][y]+1){
                            dist[X][Y]=dist[x][y]+1;
                            q.push({X,Y});
                        }
                    }
                }
            }
            else{
                rep(k,4){
                    int X=x+dx[k],Y=y+dy[k];
                    if(0<=X&&X<n&&0<=Y&&Y<n){
                        if(dist[X][Y]>dist[x][y]){
                            dist[X][Y]=dist[x][y];
                            q.push({X,Y});
                        }
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11720
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(n: usize);

    for i in 1..n + 1 {
        let x = i * (i + 1) / 2;
        if x >= n {
            println!("{}", i);
            break;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 62;
constexpr double eps = (1e-9);

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

  string s;
  cin >> s;
  ll k;
  cin >> k;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a' && i != s.size() - 1) continue;
    if ('z' - s[i] + 1 <= k) {
      k -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
    if (i == s.size() - 1) {
      int tmp = s[i] - 'a' + k;
      tmp %= 26;
      s[i] = 'a' + tmp;
    }
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 3716