akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          string s = Input.ScanStr();
          
          int left=300000, right=0;
          for(int i=0;i<s.Length;i++){
            if(s[i]=='A') left = Math.Min(i,left);
            if(s[i]=='Z') right = Math.Max(i,right);
          }
            
          Console.WriteLine(right - left + 1);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11616
#include<iostream>
using namespace std;
int main(){
	int N;
	bool num[10];
	for(int i=0;i<4;i++){cin>>N;num[N]=true;}
	if(num[1]&&num[9]&&num[7]&&num[4])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

const ll INF = 999999;

int W, H, N;
queue<pair<ll, ll> > que; // ??§?¨? ???????????¢
vector<string> vs;
ll d[1010][1010];
ll st, gl, goal[10];

ll Z(int y, int x){
    return 1010 * y + x;
}

int main(){
    cin >> H >> W >> N;
    vs.resize(H);
    FOR(i,0,H) cin >> vs[i];
    FOR(y,0,H){
        FOR(x,0,W){
            if(vs[y][x]=='S') st = Z(y,x);
            if(vs[y][x]>='1' && vs[y][x]<='9') goal[vs[y][x]-'0'] = Z(y,x);
        }
    }

    // ?????????

    int vx[4] = {0,1,0,-1};
    int vy[4] = {-1,0,1,0};

    int n = 1;
    int ans = 0;
    while(n<=N){
        st = n==1?st:goal[n-1];
        gl = goal[n];

        FOR(i,0,H) FOR(j,0,W) d[i][j] = INF;
        while(!que.empty()) que.pop();
        que.push(make_pair(st, 0));
        d[st/1010][st%1010] = 0;
        while(!que.empty()){
            int nowy = que.front().first / 1010;
            int nowx = que.front().first % 1010;
            int nowd = que.front().second;
            que.pop();
            if(d[nowy][nowx] < nowd) continue;
            FOR(i,0,4){
                int nexty = nowy + vy[i];
                int nextx = nowx + vx[i];
                if(nexty < 0 || nexty >= H || nextx < 0 || nextx >= W) continue;
                if(vs[nexty][nextx]=='X') continue;
                int nextd = nowd + 1;

                if(d[nexty][nextx] > nextd){
                    d[nexty][nextx] = nextd;
                    que.push(make_pair(Z(nexty,nextx), nextd));
                }
            }
        }

        ans += d[gl/1010][gl%1010];
        n++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11716
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#define	MOD  1000000007;
#define PI = 3.14159265358979323846;
using namespace std;

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

	if ((N[0] == N[1] && N[1] == N[2]) ||
		(N[1] == N[2] && N[2] == N[3]))

	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
using pii = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  vector<pii> v;
  rep(i, 0, M) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    v.push_back(pii(a[i], b[i]));
  }
  sort(all(v), [](pii x, pii y) { return x.second < y.second; });

  int x = -1;
  int ans = 0;
  rep(i, 0, M) {

    if (x < v[i].first) {
      ans++;
      x = v[i].second - 1;
    }
  }
  cout << ans << endl;

  return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h, n;
	cin >>h >>n;
	VI a(n), b(n);
	rep(i, n) cin >>a[i] >>b[i];
	
	VI dp(h+10, MD);
	dp[0] = 0;
	rep(i, n) rep(j, h){
		int nj = min(j+a[i], h);
		dp[nj] = min(dp[nj], dp[j] + b[i]);
	}
	cout << dp[h] <<"\n";
	return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a,b;
    cin>>a>>b;
    if((a+b)%2==1) cout<<"IMPOSSIBLE"<<endl;
    else cout<<(a+b)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v, w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
ll e10 = 1e10 + 10;
double EPS = 1e-10;

int main() {
	int N, T; cin >> N >> T;
	vector<ll> a(N);
	rep(i, N) cin >> a[i];
	ll ans1, ans2;
	{
		ll mi = INT_MAX, d = INT_MIN, cnt;
		rep(i, N) {
			ll x = a[i];
			mi = min(mi, x);
			if (x - mi > d) {
				d = x - mi;
				cnt = 1;
			}
			else if (x - mi == d) cnt++;
		}
		ans1 = cnt;
	}
	{
		ll ma = INT_MIN, d = INT_MIN, cnt;
		for (int i = N - 1; i >= 0; i--) {
			ll x = a[i];
			ma = max(ma, x);
			if (ma - x > d) {
				d = ma - x;
				cnt = 1;
			}
			else if (ma - x == d) cnt++;
		}
		ans2 = cnt;
	}
	cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApp8
{   
    class Program
    {
        public static void Main(string[] args) {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int f = 0;
            for (int d = a; d<= b; d++)
            { int e = c % d;    
                if (e == 0)
                    f++;
            }
            Console.WriteLine(f);
        }
    }
}

Measured memory_bytes: 9236
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL);
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007

ll dp[105][(int)1e5+5];
pair<ll,ll> arr[105];

ll func(ll idx, ll wt)
{
    if(wt==0 || idx==-1)
        return 0;
    if(dp[idx][wt]!=-1)
        return dp[idx][wt];
    if(wt<arr[idx].first)
        return func(idx-1,wt);
    return dp[idx][wt]=max(func(idx-1,wt),arr[idx].second+func(idx-1,wt-arr[idx].first));    
}

int main()
{
    fast;
    ll n,wt,x,y;
    cin>>n>>wt;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        arr[i]=pii(x,y);
    }
    memset(dp,-1,sizeof(dp));
    cout<<func(n-1,wt);
    return 0;
}

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

bool is_op(char c){
    return c=='+' || c=='-' || c=='*' || c=='/';
}

int operate(int &e1,int &e2,char &op){
    if(op == '+') return e1+e2;
    if(op == '-') return e1-e2;
    if(op == '*') return e1*e2;
    if(op == '/') return e1/e2;
    assert(false);
}

set<int> calc(vector<set<int>> Es, vector<char> &ops, vector<int> &perm){
    int n = perm.size();
    if(n == 0){
        return Es[0];
    }
    vector<bool> done(n);
    rep(i,n){
        int p = perm[i];
        set<int> E;
        char op = ops[p];
        for(int e1 : Es[p]){
            for(int e2 : Es[p+1]){
                if(op == '/' && e2 == 0) continue;
                E.insert(operate(e1,e2,op));
            }
        }
        done[p] = true;
        Es[p] = E;
        Es[p+1] = E;
        int l = p-1, r = p+1;
        while(l>=0 && done[l]){
            Es[l] = E;
            l--;
        }
        while(r<n && done[r]){
            Es[r+1] = E;
            r++;
        }
        if(i == n-1){
            return E;
        }
    }
    return Es[0];
}

set<int> all_check(vector<set<int>> &Es, vector<char> &ops){
    int n = ops.size();
    vector<int> perm(n);
    rep(i,n){
        perm[i] = i;
    }

    set<int> res;
    do{
        set<int> tmp = calc(Es,ops,perm);
        for(int t : tmp){
            res.insert(t);
        }
    }while(next_permutation(all(perm)));
    return res;
}


set<int> eval(string &s, int &i){
    vector<set<int>> Es;
    vector<char> ops;
    while(1){
        if(isdigit(s[i])){
            set<int> res;
            int num = 0;
            while(isdigit(s[i])){
                num = num*10 + s[i]-'0';
                i++;
            }
            res.insert(num);
            Es.push_back(res);
        }else if(s[i] == '('){
            i++; // (
            Es.push_back(eval(s,i));
            i++; // )
        }

        if(i == (int)s.size()) break;
        if(is_op(s[i])){
            ops.push_back(s[i]);
            i++;
        }else{
            break;
        }
    }
    return all_check(Es,ops);

}

int main(){
    string s;
    while(cin>>s, s!="#"){
        int index = 0;
        cout<<eval(s, index).size()<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int a,b; cin>>a>>b;
  string s; cin>>s;

  rep(i,a+b+1){
    if(i==a) continue;
    if(s[i]<'0'||s[i]>'9') return cout<<"No"<<endl,0;
  }
  cerr << s[a] << endl;
  if(s[a]!='-') return cout<<"No"<<endl,0;
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int t[100005] , x[100005] , y[100005];
int main(){
	dhoom;
	int x , a , b;
	cin >> x >> a >> b;
	x = x - a;
	x = x % b;
	cout << max(0 , x) << endl;
	return 0;
}


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

bool linear_search(vector<int> s, int n, int key){
   s[n] = key;
   int i = 0;
   while(s[i] != key) i++;
   
   return i != n;

}

int main(){
  int n, q;
  cin >> n;
  vector<int> s(n + 1);
  
  for (int i = 0; i < n; i++){
    cin >> s[i];
  }

  cin >> q;
  vector<int> t(q);
  for (int i = 0; i < q; i++){
    cin >> t[i];
  }

  int count = 0;
  for (int j = 0; j < q; j++){
    if(linear_search(s, n, t[j])) count++;
  }

  cout << count << endl;

  return 0;
}


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

int main(){
  int K,X;
  cin >>K>>X;
  for (int i=X-K+1;i<X+K;i++){
    if(i==X-K+1){}
    else{cout<<" ";}
    cout <<i;
  }

  return 0;
}

   
    
  

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

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c;
    d = a+b+c;
    if(d>=22)
    {
        cout<<"bust"<<endl;
    }
    else
    {
        cout<<"win"<<endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;

void solve(long N, vector<long> A) {
  ll ans = 0;
  unordered_map<long, long> i_pl;
  unordered_map<long, long> i_mi;
  rep(i, N) {
    i_pl[i+A[i]]++;
    i_mi[i-A[i]]++;
  }
  for(auto& pair : i_pl) {
    long x = pair.first;
    if (!i_mi[x])
      continue;
    ans += i_pl[x] * i_mi[x];
  }
    
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  long N;
  cin >> N;

  vector<long> A(N);
  rep(i, N)
    cin >> A[i];

  solve(N, move(A));

  return 0;
}


Measured memory_bytes: 27972
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

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

int main(){
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int ans;
    rep(i,1e9+1){
        if((i*(i-1)/2)<x&&x<=(i*(i+1))/2){
            ans=i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n, m, a, b;
bool onetoi[200001], iton[200001];

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		cin >> a >> b;
		if(a == 1) onetoi[b] = true;
		else if(b == n) iton[a] = true;
	}
	for(int i = 2; i < 200001; ++i){
		if(onetoi[i] && iton[i]){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 640
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F0(i,n) for (int i = 0; i < n; i++)
#define F1(i,n) for (int i = 1; i <= n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans;
int a[100005], b[100005];
set<int> V;
map<int, vector<int> > M;

void dfs(int i) {
	V.insert(i);
	for (int j : M[i]) {
		if (!V.count(j)) dfs(j);
	}
}

int main() {
	//freopen("x.in", "r", stdin);

	cin >> n;
	int x = 0;
	F0(i, n) {
		cin >> a[i];
		x ^= a[i];
	}
	F0(i, n) {
		cin >> b[i];
		if (a[i] != b[i]) {
			M[a[i]].push_back(b[i]);
			M[b[i]].push_back(a[i]);
			ans++;
		}
	}

	multiset<int> S;
	S.insert(x);
	F0(i, n) S.insert(a[i]);

	F0(i, n) if (!S.count(b[i])) {
		cout << -1 << endl;
		exit(0);
	}
	else {
		S.erase(S.find(b[i]));
	}

	F0(i, n) if (a[i] != b[i] && !V.count(a[i])) {
		ans++;
		dfs(a[i]);
	}

	if (M.count(x)) ans--;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 24448
#include<iostream>
#include<queue>
#include<string>
using namespace std;

int main(){
  priority_queue<int> q;
  string cmd;
  while(cin>>cmd && cmd!= "end"){
    if(cmd == "insert"){
      int k;
      cin >> k;
      q.push(k);
    }else if(cmd == "extract"){
      int k = q.top();
      q.pop();
      cout << k << endl;
    }
  }
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, d, x;
  cin >> n >> d >> x;

  int p[d][n];
  for ( int i = 0; i < d; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      cin >> p[i][j];      
    }
  }

  for ( int i = 0; i < d-1; i++ ) {
    vector<int> dp(100001);
    iota(dp.begin(), dp.end(), 0);
    for ( int j = 0; j < n; j++ ) {
      for ( int k = 0; k <= x; k++ ) {
	if ( k-p[i][j] < 0 ) continue;
	dp[k] = max(dp[k], dp[k-p[i][j]]+p[i+1][j]);	
      }      
    }

    for ( int k = 0; k <= x; k++ ) {
      x = max(x, dp[k]);      
    }
  }

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



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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  if(a-b>=0)
  	cout << "delicious" << endl;
  else if(a+x-b>=0)
  	cout << "safe" << endl;
  else
  	cout << "dangerous" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main(){

	int v[2001] = {};
	rep(i, 1001){
		rep(j, 1001){
			v[i+j]++;
		}
	}

	int vv[4001] = {};
	rep(i, 2001){
		rep(j, 2001){
			vv[i+j] += v[i]*v[j];
		}
	}

	int n;
	while(cin >> n){
		cout << vv[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 

int solve(){
	int h, w;
	cin>> h>> w;
	char a[h][w];
	int dp[h][w];
	rep(i, 0, h)
		rep(j, 0, w)
			cin>> a[i][j];
	dp[0][0] = (a[0][0] == '#');
	rep(i, 0, h){
		rep(j, 0, w){
			if(i == 0  and  j == 0)
				continue;
			dp[i][j] = 1000001;
			if(i > 0)
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + (a[i][j] == '#'  and  a[i - 1][j] == '.'));
			if(j > 0)
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + (a[i][j] == '#'  and  a[i][j - 1] == '.'));
		}
	}
	cout<< dp[h - 1][w - 1];
	return 0;
}
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int h,w,a,b; cin>>h>>w>>a>>b;

	rep(i, b ) cout<<string(a,'0')+string(w-a,'1')<<endl;
	rep(i,h-b) cout<<string(a,'1')+string(w-a,'0')<<endl;

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int n, m;
int w[100020];
int v[100020];
vector<int> a[100020];
int bestvalue;
int bestindex;
long long ans;
void dfs(int x) {
	v[x] = 1;
	if (bestvalue > w[x]) {
		bestvalue = w[x];
		bestindex = x;
	}
	for (int i: a[x]) {
		if (!v[i]) {
			dfs(i);
		}
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (!v[i]) {
			bestvalue = 2e9;
			bestindex = -1;
			dfs(i);
			cnt++;
			ans += bestvalue;
			w[bestindex] = 2e9;
		}
	}
	sort(w, w + n);
	if (cnt == 1) {
		printf("0\n");
		exit(0);
	}
	for (int i = 0; i < cnt - 2; i++) {
		if (w[i] == 2e9) {
			printf("Impossible\n");
			exit(0);
		}
		ans += w[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6528
A = [
    list(map(int, input().split())),
    list(map(int, input().split())),
    list(map(int, input().split()))
]
N = int(input())
B = list()
for i in range(N):
    B.append(int(input()))
hantei_1 =False
hantei_2 =False
hantei_3 =False
hantei_4 =False
hantei_5 =False
hantei_6 =False
hantei_7 =False
hantei_8 =False
if A[0][0] in B and A[0][1] in B and A[0][2] in B:
    hantei_1 = True
if A[1][0] in B and A[1][1] in B and A[1][2] in B:
    hantei_2 = True
if A[2][0] in B and A[2][1] in B and A[2][2] in B:
    hantei_3 = True
if A[0][0] in B and A[1][0] in B and A[2][0] in B:
    hantei_4 = True
if A[0][1] in B and A[1][1] in B and A[2][1] in B:
    hantei_5 = True
if A[0][2] in B and A[1][2] in B and A[2][2] in B:
    hantei_6 = True
if A[0][0] in B and A[1][1] in B and A[2][2] in B:
    hantei_7 = True
if A[0][2] in B and A[1][1] in B and A[2][0] in B:
    hantei_8 = True
if hantei_1 or hantei_2 or hantei_3 or hantei_4 or hantei_5 or hantei_6 or hantei_7 or hantei_8:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>



using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	if (a * n > b)
		cout << b;
	else
		cout << a*n;

}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l,i;
    cin>>n>>l;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n);
    for(i=0;i<n;i++){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

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

    int c4 = 0,c2 = 0, c = 0;

    for (int i = 0; i < N; ++i) {
        int cur;
        cin >> cur;
        if (cur % 4 == 0) c4++;
        else if (cur % 2 == 0) c2++;
        else c++;
    }
    if (c4 + 1 == c && c2 == 0) {
        cout << "Yes" << endl;
    } else if (c4 < c) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }



    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,m,a,b,mi,max=0,i;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    if(max<a){
      max=a;
      mi=i;
    }
    hin(b);
  }
  for(i=0;i<n&&m>0;i++){
    b=N[hout()];
    if(b<max)break;
    m-=b;
  }//printf("%d %d\n",m,i);
  if(m>0)i+=(m-1)/max+1;
  printf("%d\n",i);
  return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define inf 1e18+9
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define umap unordered_map<ll,ll>
#define lpq priority_queue<ll,vector<ll>,greater<ll>>
ll globe=0;
ll powe(ll n,ll r){if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);}

bool pali(string &a){
    ll i=0,j=a.size()-1;
    while(i<=j){
        if(a[i]!=a[j])
            return false;
        i++;
        j--;
    }
    return true;
}

int32_t main(){
 
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
 
	ll t=1;
	//cin>>t;
	while(t--){
	    string s;
	    cin>>s;
	    ll k=(s.size()-1)/2;
	    string a=s.substr(0,k);
	    k=(s.size()+1)/2;
	    string b=s.substr(k);
	    if(pali(s)&&pali(a)&&pali(b))
	        cout<<"Yes\n";
	    else
	        cout<<"No\n";
	}
 
	return 0;
 
}
//BitMasking->setBit: n|(1<<i); unsetBit: n&!(1<<i); checkBit: n&(1<<i);
//ll idx=upper_bound(v.begin(),v.end(),val)-v.begin();
//v.erase(unique(v.begin(),v.end()),v.end());
//ll cnt=count(v.begin(),v.end(),val);
//bool f=find(v.begin(),v.end(),val);

Measured memory_bytes: 256
import sys
r=sys.stdin.readline
I=float('inf')
for e in iter(r,'0 0\n'):
 n,k=map(int,e.split())
 F=[[I]*-~n for _ in[0]*-~n]
 for i in range(1,n+1):F[i][i]=0
 for _ in[0]*k:
  f=r();g=map(int,f[2:].split())
  if'0'==f[0]:a,b=g;A=F[a][b];print([A,-1][A==I])
  else:
   c,d,e=g
   if e<F[c][d]:
    for i in range(2,n+1):
     for j in range(1,i):
      F[i][j]=F[j][i]=min(F[i][j],F[i][c]+e+F[d][j],F[i][d]+e+F[c][j])


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

ll P = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vi a(n), b(m);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];
  ll ans = 1;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  vector<bool> aused(n), bused(m);
  for (int i = 0; i < n - 1; i++)
    if (a[i + 1] == a[i]) {
      cout << 0 << endl;
      return 0;
    }
  for (int i = 0; i < m - 1; i++)
    if (b[i + 1] == b[i]) {
      cout << 0 << endl;
      return 0;
    }
  map<ll, bool> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (a[i] == b[j]) {
        mp[a[i]] = true;
        aused[i] = true;
        bused[j] = true;
      }
  }
  vi asum(n + 1), bsum(m + 1);
  for (int i = 0; i < n; i++) {
    asum[i + 1] = asum[i] + aused[i];
  }
  for (int i = 0; i < m; i++) {
    bsum[i + 1] = bsum[i] + bused[i];
  }
  int oks = 0;
  for (int i = n * m; i > 0; i--) {
    if (mp[i]) {
      oks++;
      continue;
    }
    auto ait = lower_bound(a.begin(), a.end(), i);
    ll ac = n - (ait - a.begin());
    bool f = false;
    if (ait != a.end() && *ait == i) {
      ac = 1;
      f = true;
    }
    auto bi = lower_bound(b.begin(), b.end(), i);
    ll bc = m - (bi - b.begin());
    if (bi != b.end() && *bi == i) {
      bc = 1;
      f = true;
    }
    if (f) {
      ans *= ac * bc;
      ans %= P;
    } else {
      ans *= ac * bc - oks;
      ans %= P;
    }
    oks++;
  }

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


Measured memory_bytes: 62720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

int main(){
	ll n;
	cin >> n;
	vector<ll> A(n);
	FOR(i,0,n) cin >> A[i];
	ll sum = 0;
	FOR(i,0,n) sum+=A[i];
	ll mid=0,s=0;
	FOR(i,0,n){
		s += A[i];
		if(abs(sum-s*2)<abs(sum-mid*2)){
			mid = s;
		}
	}
	cout << abs(sum-mid*2) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<vector<int> >adj;
int parent[100005][20];
void dfs(int ver,int pr)
{
  parent[ver][0]=pr;
  for(auto i:adj[ver])
  {
    dfs(i,ver);
  }
}

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(0);   

  #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout);
      }
  #endif  

  int n;
  cin>>n;
  adj.resize(n+2);
  int x[n+1];
  set<pair<int,int> >s;
  for(int i=1;i<=n;i++)
  {
    cin>>x[i];
    s.insert({x[i],i});
  }
  int len;
  cin>>len;
  for(int i=1;i<=n;i++)
  {
    auto j=s.lower_bound({x[i]+len+1,-1});
    j--;
    if(j->second==i)
    {
      adj[n+1].push_back(i);
      // cout<<n+1<<" "<<i<<"\n";
    }
    else
    {
      adj[j->second].push_back(i);
      // cout<<j->second<<" "<<i<<"\n";
    }    
  }
  dfs(n+1,n+1);
  for(int i=1;i<=19;i++)
    for(int j=1;j<=n+1;j++)
      parent[j][i]=parent[parent[j][i-1]][i-1];

  int q;
  cin>>q;
  int l,r;
  while (q--)
  {
    cin>>l>>r;
    if(l>r)
      swap(l,r);
    if(l==r)
    {
      continue;
      cout<<0<<"\n";
    }
    int ans=1;
    for(int i=19;i>=0;i--)
    {
      if(parent[l][i]<r)
      {
        ans+=(1<<i);
        l=parent[l][i];
      }
    }
    cout<<ans<<"\n";
  }
  

}

Measured memory_bytes: 32128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		 Scanner sc = new Scanner(System.in);
	     int X = sc.nextInt();
	     
	     if(X >= 30) {
	    	 System.out.println("Yes");
	     }else {
	    	 System.out.println("No");
	     }
	}

}


Measured memory_bytes: 35624
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		boolean[] able1 = new boolean[n + 1];
		boolean[] ableN = new boolean[n + 1];
		for (int i = 0; i < m; i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			if (a > b) {
				int tem = a;
				a = b;
				b = tem;
			}
			if (a == 1)
				able1[b] = true;
			if (b == n)
				ableN[a] = true;
		}
		for (int i = 1; i <= n; i++) {
			if (able1[i] && ableN[i]) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
	}
}

Measured memory_bytes: 65452
#include<bits/stdc++.h>
using namespace std;
int mem[100005][5];

int dp(int arr[][5],int n,int i,int j)
{
    if(i==n)
        return 0;
    if(mem[i][j]!=-1)
        return mem[i][j];
    if(j==1)
    {

        mem[i][1]=max((dp(arr,n,i+1,2)+arr[i+1][2]),  (dp(arr,n,i+1,3)+arr[i+1][3]));
        return mem[i][1];
    }
    else if(j==2)
    {

        mem[i][2]=max((dp(arr,n,i+1,1)+arr[i+1][1]),  (dp(arr,n,i+1,3)+arr[i+1][3]));
        return mem[i][2];
    }
    else
    {

        mem[i][j]=max((dp(arr,n,i+1,1)+arr[i+1][1]),  (dp(arr,n,i+1,2)+arr[i+1][2]));
        return mem[i][3];
    }




}

int main()
{
    int n,i,j,x,y,z;
    cin>>n;
    int arr[n+3][5];
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=3; j++)
        {
            cin>>arr[i][j];

        }
    }
    memset(mem,-1,sizeof(mem));
    x=dp(arr,n,1,2)+arr[1][2];
    memset(mem,-1,sizeof(mem));
    y=dp(arr,n,1,3)+arr[1][3];
    memset(mem,-1,sizeof(mem));
    z=dp(arr,n,1,1)+arr[1][1];
    cout<<max( x,  max(y,z) )<<endl;


    return 0;
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            Console.WriteLine(input.Substring(0, input.LastIndexOf('F')));
#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


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

int main(){
    long long n,k;
    cin>>n>>k;
    
    long long m=n/k;
    long long ans1=n-k*m;
    long long ans2=k*(m+1)-n;
    
    cout<<min(ans1,ans2)<<endl;
    return 0;
}

Measured memory_bytes: 256
def sgn(a, b):
    return int(a*b/abs(a*b))

class Dice:
    def __init__(self, numbers):
        self.numbers_dict = {1:numbers[0], 2:numbers[1], 3:numbers[2], -3:numbers[3], -2:numbers[4], -1:numbers[5]}
        self.numbers_ver_dict = {numbers[0]:1, numbers[1]:2,numbers[2]:3,numbers[3]:-3, numbers[4]:-2,numbers[5]:-1}

    # a:top, b:front
    def show_right(self, a, b):
        var_a = self.numbers_ver_dict[a]
        var_b = self.numbers_ver_dict[b]
        if abs(var_a) == 1:
            if abs(var_b) == 2:
                return self.numbers_dict[sgn(var_a,var_b)*3]
            else:
                return self.numbers_dict[-sgn(var_a,var_b)*2]
        elif abs(var_a) == 2:
            if abs(var_b) == 1:
                return self.numbers_dict[-sgn(var_a, var_b)*3]
            else:
                return self.numbers_dict[sgn(var_a,var_b)]
        else:
            if abs(var_b) == 1:
                return self.numbers_dict[sgn(var_a, var_b)*2]
            else:
                return self.numbers_dict[-sgn(var_a,var_b)]

    def exam_equal(self, dice):
        for key in dice.numbers_ver_dict:
            if key not in self.numbers_ver_dict:
                return False
        exam_tuple = ((examin_list[0], examin_list[1]), (examin_list[0], examin_list[2]), (examin_list[0], examin_list[4]),
        (examin_list[0], examin_list[3]), (examin_list[1], examin_list[5]))
        for num in exam_tuple:
            if dice1.show_right(num[0], num[1]) != dice.show_right(num[0], num[1]):
                return False
        return True


if __name__ == '__main__':
    n = int(input())
    examin_list = list(map(int, input().split()))
    dice1 = Dice(examin_list)
    dice = []
    for i in range(n-1):
        dice.append(Dice(list(map(int, input().split()))))
    diff_flag = False
    for d in dice:
        if dice1.exam_equal(d):
            print('No')
            diff_flag = True
            break
    if not diff_flag:
        print('Yes')



Measured memory_bytes: 5620
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const ll longinf=1LL<<60;
const int mod=1000000007;    
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

ll pow(ll n,int k){
  if(k<0)k+=mod-1;
  ll ret=1;
  while(k>0){
    if(k&1)ret=ret*n %mod;
    n=n*n %mod;
    k>>=1;
    }
  return ret;
  }

int main(){
  ll n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  ll fact[n+1];
  fact[0]=1;
  rep(i,n)fact[i+1]=(i+1)*fact[i]%mod;
  ll dp[1001][1001];
  rep(i,n+1){
    dp[a-1][i]=0;
    }
  dp[a-1][0]=fact[n];
  REP(i,a,b+1){
    rep(j,n+1){
      dp[i][j]=dp[i-1][j];
      if(i*c<=j){
        int m=min(d-c+1,1+(j-i*c)/i);
        rep(k,m){
          ll res=dp[i-1][j-i*(c+k)]*pow(fact[i],-c-k)%mod;
          dp[i][j]+=res*pow(fact[c+k],-1)%mod;
          }
        dp[i][j]%=mod;
        }
      }
    }
  cout<<dp[b][n]<<endl;
  return 0;
  }   

Measured memory_bytes: 8064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
char a[110],b[110],c[110];
ll alen,blen,clen;
ll acnt=0,bcnt=0,ccnt=0;
void turn_a();
void turn_b();
void turn_c();
ll cnt=0;
void turn_a(){
 //pr(cnt);puts("turn_a");cnt++;
 //pr(alen);
 alen-=1;
 if(alen<=0){puts("A");return;}
 else{
 acnt++;
 if(a[acnt-1]=='a')turn_a();
 else if(a[acnt-1]=='b')turn_b();
 else if(a[acnt-1]=='c')turn_c();
 }
}
void turn_b(){
 //pr(cnt);puts("turn_b");cnt++;
// pr(blen);
 blen-=1;
 if(blen<=0){puts("B");return;}
 else{
 bcnt++;
 if(b[bcnt-1]=='a')turn_a();
 else if(b[bcnt-1]=='b')turn_b();
 else if(b[bcnt-1]=='c')turn_c();
 }
}
void turn_c(){
 //pr(cnt);puts("turn_c");cnt++;
 clen-=1;//pr(clen);
 if(clen<=0){puts("C");return;}
 else{
 ccnt++;
 //pr(clen);
 if(c[ccnt-1]=='b')turn_b();
 else if(c[ccnt-1]=='c')turn_c();
 else if(c[ccnt-1]=='a')turn_a();
 }
}
int main(){
 sc(a);sc(b);sc(c);
 alen=strlen(a)+1;blen=strlen(b)+1;clen=strlen(c)+1;
 turn_a();

return 0;}

Measured memory_bytes: 3552
#include <stdio.h>

int main(){
  char flg = 0;
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++){
    char x;
    scanf("%c", &x);
    if ( x == 'Y') flg = 1;
  }
  if (flg)
  printf("Four\n");
  else printf("Three\n");
  return 0;
}


Measured memory_bytes: 128
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();
   
   if (n >= 2 || m >=2 ){
     int a = n*(n-1)/2;
     int b = m*(m-1)/2;
     
      System.out.println(a+b);
   }
   else {
     System.out.println(0);
   }
 }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvpi vector<vpi>
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define For(i,n) for(int i=0;i<n;i++)
#define Forn(i,a,n) for(int i=a;i<n;i++)
#define pie =3.14159265358979323846264338327950;
const int mod= 1e9+7;

const int mx= 405;
int dp[mx][mx];

int sum(int l,int r, vector<int> &ar){
	int ans=0;
	for(int i=l;i<=r;i++){
		ans+=ar[i];
	}
	return ans;
}

void solve(){
	fio;
	int n;
	cin>>n;
	vector<int> ar(n);
	For(i,n) cin>>ar[i];
	for(int l=n-1;l>=0;l--){
		for(int r=l;r<n;r++){
			if(r==l){
				dp[l][r]=0;
			}
			else{
				dp[l][r]=1e18;
				int s= sum(l,r,ar);
				for(int i=l;i<=r-1;i++){
					dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+s);
				}
			}
		}
	}
	cout<<dp[0][n-1]<<endl;
}

int32_t main(){
	fio;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){ 
		//cout<<"Case #"<<i<<":\n";
		solve();
	}
	return 0;
}


Measured memory_bytes: 4880
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K=MI()
    N%=K
    ans = min(abs(N-K), N)
    print(ans)
if __name__ == '__main__':
    main()

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

using ll=long long;
using namespace std;

int main(){
    int n;
    cin>>n;
    
    bool flag=true;
    int i=1;
    while(flag){
        if(pow(2,i)>n){
            i--;
            flag=false;
            continue;
        }
        i++;
    }
    
    cout<<pow(2,i)<<endl;
    return 0;
}


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

int main() {
    // freopen("input.txt", "r", stdin);
    int n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        int a, b; cin>> a >> b;
        if(a == b) {
            v[i] = 1;
        } else { 
            v[i] = 0;
        }
    }
    int cnt =0 ;
    for (int i = 0; i < n; i++ ){
        if(v[i]) {
            cnt++;
        } else {
            cnt = 0;
        }
        if (cnt  == 3) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 3628
a, b, c, x = 4.times.map { gets.to_i }

ans = 0
(0..a).each do |i|
  (0..b).each do |j|
    sum = 500 * i + 100 * j
    rest = x - sum
    ans += 1 if rest >= 0 && rest <= c * 50
  end
end

puts ans

Measured memory_bytes: 1788
#include<stdio.h>

int main(void)
{
	int n, i, pm, pe, pj;

	while (1)
	{
		scanf("%d", &n);
		if (n == 0)break;
		for (i = 0;i < n;i++)
		{
			scanf("%d %d %d", &pm, &pe, &pj);
			if (pm == 100 || pe == 100 || pj == 100)
			{
				printf("A\n");
			}
			else if ((pm + pe) / 2 >= 90)
			{
				printf("A\n");
			}
			else if ((pm + pe + pj) / 3 >= 80)
			{
				printf("A\n");
			}
			else if ((pm + pe + pj) / 3 >= 70)
			{
				printf("B\n");
			}
			else if ((pm + pe + pj) / 3 >= 50)
			{
				if (pm >= 80 || pe >= 80)
				{
					printf("B\n");
				}
				else
				{
					printf("C\n");
				}
			}
			else
			{
				printf("C\n");
			}
		}

	}
	return 0;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
  int n;
  int ac =0;
  int wa =0;
  int tle =0;
  int re =0;
  cin >> n;
  string s;
  rep(i,n){
    cin >> s;
    if(s=="AC"){
      ac++;
    }else if(s=="WA"){
      wa++;
    }else if(s=="TLE"){
      tle++;
    }else if(s=="RE"){
      re++;
    }
  }
  cout << "AC x " << ac  << endl;
  cout << "WA x " << wa  << endl;
  cout << "TLE x " << tle  << endl;
  cout << "RE x " << re  << endl;
  return 0;
}


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

int main() {
  int N;
  vector <double> vec(N);
  cin >> N;
  for (int i=0;i<N;i++){
    cin >> vec[i] ;
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  vector <double> two(N);
  two[0]=2;
  for (int i=1;i<N-1;i++){
    two[i]=2*two[i-1];
  }
    two[N-1]=two[N-2];
  double sum=0;
  for (int i=0; i<N;i++){
    sum+=vec[i]/two[i];
  }
  cout  << sum << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#define ll long long
#define fup(i,a,b) for(int i=a;i<=b;++i)

void Main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll s;
    if(n>1&&m>1)s=m+m+n+n-4;
    else if(m==1&&n==1)s=0;
    else s=2;
    printf("%lld",n*m-s);
}
int main()
{
Main();
return 0;
}

Measured memory_bytes: 504