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

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;


    int H, W;

    void calc()
    {
        int N = cin.nextInt();

        long[] A = cin.ArrayLong(N);
        long ok = 0;
        long ng = (long)1e18;
        while(Math.Abs(ok-ng) > 1)
        {
            long mid = (ok + ng) / 2;
            if (check(A, mid)) ok = mid;
            else ng = mid;
        }
        long ans = ok;
        for (long i = ok - 1; i >= Math.Max(0, ok - 2 * N - 10000); i--)
        {
            if (!check(A, i)) ans = i - 1;
        }
        Console.WriteLine(ans);


    }

    bool check(long[] A, long num)
    {
        long cnt = 0;
        for (int i = 0; i < A.Length; i++)
        {
            cnt += (A[i] + num) / (A.Length + 1);
        }
        return num <= cnt;
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}




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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll h,cnt=0,x=1; cin>>h;
    while(h>0){
        x*=2;
        h /= 2;
        cnt += x;
    }
    cout<<cnt/2<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>

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

	bool isMatch= false;

	for(int i=0; i<s.size(); i++){
		if(s==t){
			isMatch= true;
			break;
		}

		char c= s.back();
		s.pop_back();

		s.insert(s.begin(),c);
	}

	if(isMatch)
		std::cout<< "Yes"<<std::endl;
	else
		std::cout<< "No"<<std::endl;

	return 0;
}

Measured memory_bytes: 256
// B - Counting Roads

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int N, M;
	cin >> N >> M;

	map<int, int> cnt;

	for (int i=1; i<=N; i++) {
		cnt[i] = 0;
	}

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

	for (auto itr = cnt.begin(); itr != cnt.end(); itr++) {
		cout << itr->second << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import math
t=[]
for _ in range(5):
  x=int(input())
  t.append(x)
tt=[]
for i in t:
  tt.append(math.ceil(i*0.1))
sa=[]
for i in range(5):
  sa.append(tt[i]*10-t[i])
print(sum(tt)*10-max(sa))

Measured memory_bytes: 3060
#include <stdio.h>

int a[1000000+10];
int main(){
	int x;
	scanf("%d",&x);
	int cnt=1;
	while(!a[x]){
		a[x]=cnt;
		x=x%2?3*x+1:x/2;
		cnt++;
	}
	printf("%d",cnt);
}

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

int main()
{
    int n;
    cin >> n;
    int ans = 100000;
    vector<long> a(n);
    for(int i=0;i<n;i++){cin >> a[i];}
    for(int j=0;j<n;j++){
        int tmp = 0;
        while(a[j]%2 == 0){
            a[j] = a[j]/2;
            tmp++;
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vll>;
using vb = vector<bool>;
 
const int INF = 2e9+5;
const ll LLINF = (1LL << 60) + 5;
 
/*
  filippos
  Contest : AtCoder DP contest
  Task : I - Coins
*/
 
int main(){
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

  int n; cin >> n;
  vector<double> v(n);
  for(double &d : v)
    cin >> d;

  const int OFFSET = n;
  vector<vector<double>> memo(n, vector<double>(2*n + 1, -1));

  function<double(int, int)> dp = [&](int i, int heads) {
    // base case, no more coins to toss
    if(i >= n) return (double)(heads > 0);
    // dp check
    auto &ans = memo[i][heads + OFFSET];
    if(ans != -1) return ans;
    // simple formula, kind of: consider both toss outcomes
    return ans = v[i] * dp(i + 1, heads + 1) + (1 - v[i]) * dp(i + 1, heads - 1);
  };

  cout << setprecision(10) << dp(0, 0);

  return cout << endl, 0;
}

Measured memory_bytes: 141184
#include <cstdio>
#include <algorithm>

using namespace std;

const int V_MAX = 15;
const int INF = 10000000;

int n, e;
int g[V_MAX][V_MAX];
int dp[1 << V_MAX][V_MAX];

int tsp(int visited, int v)
{
    if (dp[visited][v] != -1)
        return dp[visited][v];

    if (visited == (1 << n) - 1 && v == 0)
        return 0;

    int res = INF;
    for (int u = 0; u < n; ++u) {
        if (!(visited & (1 << u)) && g[v][u] != INF) {
            res = min(res, tsp(visited | (1 << u), u) + g[v][u]);
        }
    }
    return dp[visited][v] = res;
}

int main()
{
    scanf("%d %d", &n, &e);
    fill(&g[0][0], &g[n][0], INF);
    for (int i = 0; i < e; ++i) {
        int s, t, d;
        scanf("%d %d %d", &s, &t, &d);
        g[s][t] = d;
    }

    fill(&dp[0][0], &dp[1 << V_MAX][0], -1);
    int d = tsp(0, 0);
    if (d == INF)
        printf("-1\n");
    else
        printf("%d\n", d);

    return 0;
}

Measured memory_bytes: 2952
n = int(input())
a = [0] * 100
count = 0
for i in range(1, n + 1):
    x = i%10
    y = int(str(i)[0])
    a[10*y + x] += 1
for i in range(1, n + 1):
    x = i%10
    y = int(str(i)[0])
    count += a[10*x + y]
print(count)

Measured memory_bytes: 3064
import std.stdio;
import std.string;
import std.conv;
import std.math;

int main() {
    string buf = strip(readln());

    while ((buf = strip(readln())) != null) {
        writeln(is_right_triangle(buf));
    }

    return 0;
}

string is_right_triangle(string data_set) {
    string[] sides = split(data_set);
    int a = to!(uint)(sides[0]);
    int b = to!(uint)(sides[1]);
    int c = to!(uint)(sides[2]);
    int max = 0;
    int s1, s2;
    if (a > b) {
        if (a > c) {
            max = a;
            s1 = b;
            s2 = c;
        } else {
            max = c;
            s1 = a;
            s2 = b;
        }
    } else {
        if (b > c) {
            max = b;
            s1 = a;
            s2 = c;
        } else {
            max = c;
            s1 = b;
            s2 = a;
        }
    }
    if (a < b + c && b < a + c && c < a + b) {
        if (pow(max, 2) == pow(s1, 2) + pow(s2, 2)) {
            return "YES";
        }

    }
    return "NO";
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
const int MN = 105;
map<ll,vl> ew;
ll dp[MN][MN];
ll ch(ll n, ll k) {
	if(k > n || k < 0) {return 0;}
	if(k == 0 || n == 0) {return 1;}
	if(dp[n][k] != -1) {return dp[n][k];}
	return dp[n][k] = ch(n-1,k-1)+ch(n-1,k);
}
ll rmul(ll a, ll b) {
	if(a > 1e13/b) {
		return 1e13;
	}
	return a*b;
}
int main() {
	ll n;
	cin >> n;
	memset(dp,-1,sizeof(dp));
	for(int i=2;i<50;i++) {
		ll ok = (1LL<<(i-1))-1;
		ew[ok] = {i};
	}
	for(int i=1;i<=40;i++) {
		for(int j=1;j<=40;j++) {
			for(int k=1;k<=i;k++) {
				if(k+i > 40) {continue;}
				for(int l=1;l<=j;l++) {
					if(l+j > 40) {continue;}
					ll ct = 0;
					ct += ((1LL<<(i+k-1))-1);
					ct += ((1LL<<(j+l-1))-1);
					ll wa = 0,wb = 0;
					for(int a=1;a<=k;a++) {
						wa += ch(k,a)*ch(i,a);
					}
					for(int a=1;a<=l;a++) {
						wb += ch(l,a)*ch(j,a);
					}
					ct += rmul(wa,wb);
					ew[ct] = {i,j,k,l};
				}
			}
		}
	}
	for(int i=10;i<=20;i++) {
		for(int j=10;j<=20;j++) {
			for(int k=10;k<=20;k++) {
				for(int x=1;x<=10;x++) {
					for(int y=1;y<=10;y++) {
						for(int z=1;z<=10;z++) {
							ll ct = 0;
							ct += ((1LL<<(i+x-1))-1);
							ct += ((1LL<<(j+y-1))-1);
							ct += ((1LL<<(k+z-1))-1);
							ll rs = 1;
							ll wa = ch(x+i,x)-1;
							rs = rmul(rs,wa);wa = 0;
							wa = ch(y+j,y)-1;
							rs = rmul(rs,wa);wa = 0;
							wa = ch(z+k,z)-1;
							rs = rmul(rs,wa);
							ct += rs;
							ct += rmul(ch(x+i,x)-1,ch(y+j,y)-1);
							ct += rmul(ch(z+k,z)-1,ch(y+j,y)-1);
							ct += rmul(ch(x+i,x)-1,ch(z+k,z)-1);
							if(ct <= 1e12) {
							ew[ct] = {i,j,k,x,y,z};
							}
						}
					}
				}
			}
		}
	}
	ll C = 0;
	ll E = 1;
	vl res;
	while(n > 0) {
		auto it = ew.upper_bound(n);
		it--;
		vl val = (it->second);
		if(val.size() > 1) {
			int num = val.size()/2;
			for(int i=0;i<val.size();i++) {
				for(int j=0;j<val[i];j++) {
					res.push_back(E+(i%num));
				}
			}
			E += num;
		} else {
			for(int i=0;i<val.back();i++) {
				res.push_back(E);
			}
			E += 1;
		}
		n -= it->first;
	}
	cout << res.size() << '\n';
	for(int i=0;i<res.size();i++) {
		if(i > 0) {cout << " ";}
		cout << res[i];
	}
	cout << '\n';
}


Measured memory_bytes: 24104
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  n, a, b = map(int, readline().split())
  ans = n//(a+b) * a + min((n%(a+b)),a)
  print(ans)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int x;
cin >> x;
int temp;
temp = x/100;
int temp2;
temp2 = 5*temp;
if(x-(temp*100)<=temp2)fin(1);else fin(0);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
mt19937 _mt(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l,ll r){return uniform_int_distribution<ll>(l,r-1)(_mt);}
/*
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;
*/

vl fact, finv;
ll mdpow(ll x, ll k) { 
	ll res = 1;
	while (k != 0) {
		if (k & 1) res = res*x % MOD;
		x = x*x % MOD;
		k = k >> 1;
	}
	return res;
}
ll comb(ll n, ll k) {
	if (n == 0 && k == 0)return 1;
	if (n < k || n < 0)return 0;
	return fact[n] * finv[n - k] % MOD * finv[k] % MOD;
}

struct ferm{
	ferm(ll n){
		fact.resize(n);
		finv.resize(n);
		fact[0] = 1;
		finv[0] = 1;
		rep (i,n-1) {
			fact[i + 1] = (fact[i] * (i + 1)) % MOD;
			finv[i + 1] = mdpow(fact[i + 1], MOD-2);
		}
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	ll in=m;
	map<int,int> mp; 
	for(int i=2;i*i<=m;i++){
		while(in%i==0){
			in/=i;
			mp[i]++;
		}
	}
	if(in!=1)mp[in]++;
	ll ans=1;
	ferm(200002);
	for(auto x:mp){
		ans*=comb(n+x.sc-1,n-1);
		ans%=MOD;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3456
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var list = new List<Tuple<long, long>>();
        for (int i = 0; i < n; i++)
        {
            var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            list.Add(new Tuple<long, long>(line[0], line[1]));
        }
        list = list.OrderByDescending(f => f.Item1 + f.Item2).ToList();
        long tk = 0;
        long ao = 0;
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0) tk += list[i].Item1;
            else ao += list[i].Item2;
        }
        Console.WriteLine(tk - ao);
    }
}

Measured memory_bytes: 28092
#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,k;
    cin >> n >> k;
    int cc=0;
    vector <int> a(n+1,0),b(n+1,0),c(n+1,0),a2(n+1,0);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,k){
        cc=0;
        b=c;
        a2=c;
        rep(j,n){
            if((j-a[j])<0){
                ++b[0];
            }
            else{
                ++b[j-a[j]];
            }
            if((j+a[j])>n-1){
                --b[n];
            }
            else{
                --b[j+a[j]+1];
            }
        }

        rep(j,n){
            //cout << b[i] << endl;
            if(j==0){
                a2[0]=b[0];
            }
            else{
                a2[j]=a2[j-1]+b[j];
            }
            if(a2[j]!=n){
                cc=1;
            }
        }


        a=a2;
        if(cc==0){
            break;
        }
    }

    rep(i,n){
        cout << a[i] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 6344
using System.IO;
using System;

class Program
{
    static void Main()
    {
        string value = Console.ReadLine();
        string[] v = value.Split();
        int[] vi = new int[3];
        int swap;
        
        for(int x=0; x<3; x++)
        {
            vi[x] = int.Parse(v[x]);
        }
        
        for(int x=0; x<2;x++)
        {
            for(int y=x+1; y<3; y++)
            {
                if(vi[x] > vi[y])
                {
                    swap = vi[x];
                    vi[x] = vi[y];
                    vi[y] = swap;
                }
            }
        }
        Console.WriteLine("{0} {1} {2}", vi[0], vi[1], vi[2]);
    }
}


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> x(n, vector<int>(3));
    int a = -1;
    for (int i = 0; i < n; ++i) {
        cin >> x[i][0] >> x[i][1] >> x[i][2];
        if (x[i][2] > 0) {
            a = i;
        }
    }
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            int h = x[a][2] + abs(i - x[a][0]) + abs(j - x[a][1]);
            bool ok = true;
            for (int k = 0; k < n; ++k) {
                int hh = max(h - abs(i - x[k][0]) - abs(j - x[k][1]), 0);
                if (hh != x[k][2]) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << i << " " << j << " " << h << "\n";
                return 0;
            }
        }
    }
    return 0;
}


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

int main() {
    int n, l;
    cin >> n >> l;
    int current_taste, current_distance;
    int total_taste = 0;
    int total_distance = INT_MAX;
    int original_taste = 0;
    
    original_taste = (l + (l + n - 1)) * n / 2;
    
    for (int i = 0; i < n; i++) {
        current_taste = original_taste - (l + i);
        current_distance = abs(current_taste - original_taste);
        
        if (total_distance > current_distance) {
            total_distance = current_distance;
            total_taste = current_taste;
        }
    }
    
    cout << total_taste << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
fs = [None]*n
for i in range(n):
    l = list(map(int, input().split()))
    fs[i] = set([i for i in range(10) if l[i]])
p = [None]*n
for i in range(n):
    p[i] = list(map(int, input().split()))
ans = -float("inf")
for b in range(1<<10):
    if b==0:
        continue
    score = 0
    s = set()
    for i in range(10):
        if b>>i&1:
            s.add(i)
    for i in range(n):
        score += p[i][len(s&fs[i])]
    ans = max(ans, score)
print(ans)

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

int main(void){
    int h, w;
    char a[105];
    cin >> h >> w;
    for (int i = 1; i <= w + 2; i++) cout << "#";
    cout << endl;
    for (int i = 1; i <= h; i++) {
        cin >> a;
        cout << "#" << a << "#" << endl;
    }
    for (int i = 1; i <= w + 2; i++) cout << "#";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=1010;
LL gi() {
	LL w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int mod=1e9+7;
bool o[N][N];
inline int qpow(int x,LL y) {
	int ans=1;
	while (y) {
		if (y&1) ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}
struct M{ int a[2][2]; };
inline M operator * (const M &a,const M &b) {
	M ans={};
	for (int i=0;i<2;i++)
		for (int j=0;j<2;j++)
			for (int k=0;k<2;k++)
				ans.a[i][j]=(ans.a[i][j]+1LL*a.a[i][k]*b.a[k][j])%mod;
	return ans;
}
int main()
{
	int n=gi(),m=gi(),i,j,A=0,B=0,C=0;LL k=gi();
	char c;
	bool t1=false,t2=false;
	if (!m) return puts("1"),0;
	for (i=1;i<=n;i++)
		for (j=1;j<=m;A+=o[i][j++]=c=='#')
			while ((c=getchar())!='.'&&c!='#');
	for (i=1;i<=n;i++) if (o[i][1]&&o[i][m]) t1=true,C++;
	for (j=1;j<=m;j++) if (o[1][j]&&o[n][j]) t2=true,C++;
	if (t1&&t2) return puts("1"),0;
	if (!t1&&!t2) return printf("%d\n",qpow(A,k-1)),0;
	if (t1)
		for (i=1;i<=n;i++)
			for (j=1;j<m;j++)
				B+=o[i][j]&&o[i][j+1];
	else
		for (i=1;i<n;i++)
			for (j=1;j<=m;j++)
				B+=o[i][j]&&o[i+1][j];
	M ans={},trans={};
	ans.a[0][0]=ans.a[0][1]=1;
	trans.a[0][0]=A;
	trans.a[1][0]=mod-B;
	trans.a[1][1]=C;
	for (--k;k;k>>=1) {
		if (k&1) ans=ans*trans;
		trans=trans*trans;
	}
	printf("%d\n",ans.a[0][0]);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const long double pi = 3.14159265358979323846;



void solve() {
  ll n, k; cin >> n >> k;
  ll a[n];
  f0r(i, n) cin >> a[i];
  sort(a, a + n);
  ll s = 0;
  f0r(i, k) s += a[i];
  cout << s << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 3656
#B
N = int(input())
A = list(map(int, input().split()))

flag = False
for i in range(N):
    if A[i] % 2 == 0:
        if (A[i] % 3 == 0) or (A[i] % 5 == 0):
            flag = True
        else:
            flag = False
            break
    else:
        flag = True

if flag == True:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
#define PII pair<int, int>
using namespace std;
typedef long long LL;
//const int MOD = 1e9+7;
const auto INF  = 1e9;
const int N = 5e2+5;

LL a[N][N];

int main() {
    int N, M, n, m;
    scanf("%d%d%d%d", &N, &M, &n, &m);
    LL x, y;
    y = 1e9;
    if(n*m != 1)
        x = (y-1)/(n*m-1);
    else
        x = 1;
    for(int i=1; i*n <= N; i++) {
        for(int j=1; j*m <= M; j++) {
            a[i*n][j*m] = -y;
        }
    }
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=M; j++) {
            if(a[i][j] == 0) {
                a[i][j] = x;
            }
        }
    }
    bool flag = true;
    LL answer = 0;
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=M; j++) {
            answer += a[i][j];
        }
    }
    if(answer <= 0)
        flag = false;
    if(!flag)
        printf("No\n");
    else {
        printf("Yes\n");
        for(int i=1; i<=N; i++) {
            for(int j=1; j<=M; j++) {
                printf("%lld%c", a[i][j], j == M ? '\n' : ' ');
            }
        }
    }
}




Measured memory_bytes: 4864
#include <stdio.h>
#include <stdlib.h>
void quick_sort( int *a, int n)
{   int i, j, p, tmp;
    if (n < 2)  return;
    p = a[n / 2];   // Get the middle element as pivot ..
    for ( i = 0, j = n -1;; i++, j--) {
        while (a[i] < p)
            i++;
        while (p < a[j])
            j--;
        if ( i >= j)
            break;
        tmp = a[i]; a[i] = a[j]; a[j] = tmp;    //swap both ..
    }

    quick_sort( a, i);
    quick_sort( a + i, n - i);
}
int main()
{
    int N;
    int BOB=0,ALICE=0;
    int a[105];
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    scanf("%d",&a[i]);
    quick_sort(a,N);
        for(int i=N-1;i>=0;i-=2)
        ALICE+=a[i];
        for(int i=N-2;i>=0;i-=2)
        BOB+=a[i];
    printf("%d",(ALICE-BOB));

    return 0;
}


Measured memory_bytes: 128
using System;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var f = new string[s.Length];
            var idx = 0;
            for(var i = 0; i < s.Length; i++){
                if(s[i] == '0'){
                    f[idx] = "0";
                    idx++;
                }else if(s[i] == '1'){
                    f[idx] = "1";
                    idx++;
                }else{
                    if(idx - 1 >= 0){
                        idx--;
                    }else{
                        idx = 0;
                    }
                }
            }

            for(var i = 0; i < idx; i++){
                Console.Write(f[i]);                
            }
            Console.Write("\n");
        }
    }
}


Measured memory_bytes: 13140
N,Y=map(int,input().split())

maxA=Y//10000
ans=[]

for a in range(maxA+1):
  for b in range(N+1-a):
      if Y==10000*a+5000*b+1000*(N-a-b):
        ans.append(str(a)+" "+str(b)+" "+str(N-a-b))
    
if len(ans)!=0:
  print(ans[0])
else:
  print(str(-1)+" "+str(-1)+" "+str(-1))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <fstream>
#include <numeric>


using namespace std;

#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b

int N, K;
int d[100];
int A[100] = { 0 };

int main() {

    cin >> N >> K;

    int cnt = 0;
    for (int i = 0; i < K; i++) {
        cin >> d[i];
        for (int j = 0; j < d[i]; j++)
        {
            int tmp;
            cin >> tmp;
            A[tmp - 1] += 1;
        }

    }

    for (int i = 0; i < N; i++) {
        if (A[i] == 0) cnt++;
    }

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

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

using namespace std;

const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int MaxN = 1e5 + 15;

int dp[MaxN][2];
vector <int> v[MaxN];

void dfs(int x, int p = 0)
{
    dp[x][0] = 1;
    dp[x][1] = 1;

    for(int to : v[x])
        if(to != p)
        {
            dfs(to, x);

            dp[x][0] = (long long) dp[x][0] * (dp[to][0] + dp[to][1]) % MOD;
            dp[x][1] = (long long) dp[x][1] * dp[to][0] % MOD;
        }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);

    int n;
    cin >> n;

    for(int i = 1; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    dfs(1);

    cout << (dp[1][0] + dp[1][1]) % MOD << '\n';

    return 0;
}



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

using namespace std;

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

const int N = 100010;
const double eps = 1e-6;

int n;
int t[N];
PII point[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> t[i] >> x >> y;
        point[i] = {x, y};
    }

    for(int i = 1; i <= n; i++)
    {
        int d = abs(point[i].first - point[i - 1].first) + abs(point[i].second - point[i - 1].second);
        if(t[i] - t[i - 1] < d || d % 2 != (t[i] - t[i - 1]) % 2)
        {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


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

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

    rep(i,S.size()) {
        if((S.size()-(i+1))%2)
            continue;
        bool ok=1;
        rep(j,(S.size()-(i+1))/2)
            if(S.at(j) != S.at(j+(S.size()-(i+1))/2))
                ok = 0;
        if(ok) {
            r = S.size()-(i+1);
            break;
        }
    }

    cout << r << endl;
}

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

using namespace std;

#define ll long long
#define md 1000000007
#define loop(i,a,b) for(int i=a; i<b; i++)
#define lloop(i,a,b) for (long long i=a; i<b; i++)
#define loopr(i,a,b) for(int i = a; i>=b; i--)
#define iterate(it, v) for (auto it = v.begin(); it!= v.end(); it++)
#define mk make_pair
#define pb push_back

template <typename T>
void printArray(T *arr, int n){
    loop(i,0,n){
        cout << arr[i] << " ";
    } cout << endl;
}

template <typename T>
void printMatrix(T **arr, int m, int n){
    loop(i,0,m){
        loop(j,0,n) cout << arr[i][j] << " ";
    } cout << endl;
}

ll int getMinCost(int *arr, int n, int k) {
	ll dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);

    loop(i,2,n) {
        dp[i] = INT64_MAX;
        int temp = 0;
        while(temp < k && i-temp-1 >= 0) {
            dp[i] = min(dp[i], (ll)dp[i-1-temp] + (ll)abs(arr[i] - arr[i-1-temp]));
            temp++;
        }
    }

    return dp[n-1];
}

int main(){
    
	int n, k;
  	cin >> n >> k;
  	int arr[n];
  	loop(i,0,n) cin >> arr[i];
  
  	cout << getMinCost(arr, n, k) << endl;
    
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){

	int H,W;

	for(;;){
		cin >> H >> W;
		if(H == 0 && W == 0) break;

		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if((i%2 == 0 && j%2 == 1)||(i%2 == 1 && j%2 == 0))cout << ".";
				else cout << "#";
			}
			cout << endl;
		}

		cout << endl;

	}

	return 0;
}


Measured memory_bytes: 3104
function main (input) {
    var A = input.split('\n')[0];
    var B = input.split('\n')[1];
    var C = input.split('\n')[2];
    var X = input.split('\n')[3];
    var ptn = 0;
    var total;
    for (var a=0;a<=A;a++){
        for (var b=0;b<=B;b++){
            for (var c=0;c<=C;c++){
                total = 500*a + 100*b + 50*c;
                if (X == total){
                    ptn++;
                }
            }
        }
    }
    console.log(ptn);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11596
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main(){
  long long n,m,a;
  cin>>n>>m;
  vector<long long> S(n+1,1);
  vector<long long> DP(n+1,0);
  for(long long i=0;i<m;i++){cin>>a;S.at(a)=0;}

  DP.at(n) = 1;
  DP.at(n-1) = S.at(n-1) * DP.at(n);  
  for(long long i=n-2;i>=0;i--){
    DP.at(i)=S.at(i)*(DP.at(i+1)+DP.at(i+2))%MOD;
  }
  cout<<DP.at(0)<<endl;
  return 0;
}


Measured memory_bytes: 1792
/**
       **********    ************
	  Author : Avi J Patel
	  University : DA-IICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
}
int fact(int n) 
{ 
    // single line to find factorial 
    return (n==1 || n==0) ? 1: n * fact(n - 1);  
}
ll bioCo(ll n, ll k)  
{  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (ll i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);
		
    }  
  
    return res;  
}   
int main()
{
	FAST
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)
	{
		cout<<"bust";
	}
	else
	cout<<"win";
	return 0;
}















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

odd = 0  # 奇数
even = 0  # 偶数
for ai in A:
    if ai % 2 == 0:
        odd += 1
    else:
        even += 1

if even % 2 == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 14108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int h,n;
int a[100005];
int sum;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> h >> n;
	for(int i = 1;i <= n;i++) {
		cin >> a[i];
		sum += a[i];
	}
	if(sum >= h) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 640
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	int x,h;
	double ssr,sr;
	while(1){
		cin>>x;
		cin>>h;
		if(x==0&&h==0) break;
		sr=sqrt(h*h+(x*x)/4.0);
		ssr=sr*x*2+x*x;
		printf("%.8lf\n", ssr);
	}
}

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

int main(){
  int N,M; cin>>N>>M;
  vector<int> A(N);
  rep(i,N) cin>>A[i];
  sort(A.begin(),A.end());
  vector<pair<int,int>> V(M);
  rep(i,M){
    int B,C; cin>>B>>C;
    V[i]={C,B};
  }
  sort(V.rbegin(),V.rend());
  int l=0;
  for(auto p:V){
    int cnt=p.second;
    while(cnt--&&A[l]<p.first&&l<N){
      A[l++]=p.first;
    }
  }
  ll ans=0;
  for(int v:A) ans+=1LL*v;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x);
int main(){
    ll n, k, x, y;
    ll sum = 0ll;
    sc(n) sc(k)
    vector<P> v;
    for (int i = 0; i < n; i++){
        sc(x) sc(y)
        v.push_back(P(x, y));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++){
        sum += v[i].second;
        if (sum >= k){
            cout << v[i].first << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 2420
main :: IO ()
main = do
  n <- readLn
  a <- readLn
  putStrLn $ canPay' n a

canPay
  :: Int -> Int -> Bool
canPay n a = let r = n `rem` 500 in
  if r > a
    then False
    else True

canPay'
  :: Int -> Int -> String
canPay' n a
  | canPay n a = "Yes"
  | otherwise  = "No"


Measured memory_bytes: 508
<?php
fscanf(STDIN, "%d",$n);
$a=explode(" ", rtrim(fgets(STDIN)));
$ave=0;
for($i=0; $i <$n; $i++)
	$ave+=$a[$i];
$ave/=$n;

$temp1=0;
$temp2=0;
for ($i=0; $i < $n; $i++)
	$temp1+=pow($a[$i]-floor($ave), 2);

for ($i=0; $i < $n; $i++)
	$temp2+=pow($a[$i]-ceil($ave), 2);

printf("%d",min($temp1,$temp2));

Measured memory_bytes: 4604
#include <iostream>
using namespace std;
int main(void){

int H, W, i;
string a;

cin >> H >> W;


for(i = 0; i < W + 2; i++){
    cout << "#" ;
}
cout << endl;


for(i = 0; i < H; i++){
    
    cin >> a;
    
    cout << "#" << a << "#" << endl;
    
}

for(i = 0; i < W + 2; i++){
    cout << "#" ;
}
cout << endl;
    
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    vl v(n, -INF);
    rep(i,n) v[i] = i + a[i];
    sort(all(v));

    ll ans = 0;
    rep(i,n){
        if(i - a[i] > 0){
            ans += upper_bound(all(v), i - a[i]) - lower_bound(all(v), i - a[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

constexpr int MOD = 998244353;
using mint = Fp<MOD>;

int main() {
	int N, S;
	cin>>N>>S;
	vector<int> A(N);
	for(int i=0; i<N; i++) cin>>A[i];
	
	vector<vector<mint>> dp(N+1, vector<mint>(S+1,0));
	dp[0][0]=1;
	for(int i=0; i<N; i++){
		for(int j=0; j<=S; j++){
			dp[i+1][j]+=dp[i][j];
			if(j-A[i]==0){
				if(j!=S)dp[i+1][j]+=dp[i][j-A[i]] *(i+1);
				else	dp[i+1][j]+=dp[i][j-A[i]] *(i+1)*(N-i);
			}
			if(j-A[i]>0){
				if(j!=S) dp[i+1][j]+=dp[i][j-A[i]];
				else	 dp[i+1][j]+=dp[i][j-A[i]] *(N-i);
			}
		}
	}
	
	cout<<dp[N][S]<<endl;
	return 0;
}


Measured memory_bytes: 70784
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000


int main(){
  int *A,*B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = (int *)malloc(sizeof(int)*n+1);
  B = (int *)malloc(sizeof(int)*n+1);

  /* your code */
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
  }


  for(i=0;i<=VMAX;i++){
    C[i] = 0;
  }

  for(j=1;j<=n;j++){
    C[A[j]]++;
  }

  for(i=1;i<=VMAX;i++){
    C[i] = C[i] + C[i-1];
  }

  for(j=1;j<=n;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
 

  return 0;
}




Measured memory_bytes: 17452
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long i64;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

int N;
i64 S[MAXN];
i64 A, B;
i64 dp[MAXN];

int main()
{
	i64 last = 0, answer = 0;
	int ansptr = 0;

	S[0] = -1LL << 60 ;
	cin >> N >> A >> B ;

	if(A < B)
		swap(A, B);

	dp[0] = 1;
	for(int i = 1, j = 0; i <= N; i++)
	{
		cin >> S[i];
		if(i > 1 && S[i] - S[i-2] < B)
		{
			puts("0");
			return 0;
		}

		while(S[i] - S[j] >= A)
			last = (last + dp[j]) % MOD, j++;
		dp[i] = last;

		if(S[i] - S[i-1] < B)
			j = ansptr = i - 1, last = 0;
	}

	while(ansptr <= N)
		answer = (answer + dp[ansptr]) % MOD, ansptr++;

	cout << answer << endl ;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
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<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int a[1010],b[1010],c[1010][15];
vector<vector<int>>key(1010,vector<int>());
bool vis[1010];
vector<ll>dp(1<<12,INF);
signed main(){
   int n,m;
   cin>>n>>m;
   vector<int>v(n+1,0);
   vector<vector<int>>w(n);
    for (int i = 0; i < m; i++)
    {
        cin>>a[i]>>b[i];
        for (int j = 0; j < b[i]; j++)
        {
            cin>>c[i][j];
            c[i][j]--;
            key[i].push_back(c[i][j]);
        }
    }
    for (int bit = 0; bit < 1<<n; bit++)
    {
        dp[0]=0;
        for (int i = 0; i < m; i++)
        {
            int newbit=bit;
            for (int j = 0; j < key[i].size(); j++)
            {
                newbit|=(1<<key[i][j]);
            }
            chmin(dp[newbit],dp[bit]+a[i]);
        }    
    }    
    if(dp[(1<<n)-1]==INF) cout<<-1<<endl;
    else cout<<dp[(1<<n)-1]<<endl;
    return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	for i := 0; i < n; i++ {
		b[i] = nextInt()
	}

	for i := 0; i < n; i++ {
		c[i] = nextInt()
	}

	sort.Ints(a)
	sort.Ints(b)
	sort.Ints(c)

	count := 0
	for i := 0; i < n; i++ {
		aa := lowerBound(a, b[i])
		cc := n - upperBound(c, b[i])

		count += aa * cc
	}

	fmt.Println(count)
	// for i := 0; i < n; i++ {
	// 	for j := 0; j < n; j++ {
	// 		for k := 0; k < n; k++ {
	// 			if a[i] < b[j] && b[j] < c[k] {
	// 				count++
	// 			}
	// 		}
	// 	}
	// }

	// fmt.Println(count)

}

func lowerBound(t []int, k int) int {
	lb := -1
	ub := len(t)
	for ub-lb > 1 {
		mid := (lb + ub) / 2

		if t[mid] >= k {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

func upperBound(t []int, k int) int {
	lb := -1
	ub := len(t)
	for ub-lb > 1 {
		mid := (lb + ub) / 2

		if t[mid] <= k {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  for (int i = 0; i < n -1; i++){
    if(s[i] == s[i+1]){
      cout << "Bad\n";
      return 0;
    }
  }
  cout << "Good\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>
#include<time.h>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;


/*vectorの要素を全部確認するやつだよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。

int dy[] = { 0, 1, 0, -1 };
int dx[] = { 1, 0, -1, 0 };


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; i++) {
	for (int j = 0; j < w; j++) {

	}
}

*/

/*実行開始からの経過時間を表すよ。これで1900msまで動作を繰り返すよ。
while (clock() < 1900000) { ; }
*/

/*まだ使えないテクニックのメモだよ。
for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ
*/


int main() {

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

	int ans = 0;
	
	while (clock() < 1900000 && !(a % 2 == 1 || b % 2 == 1 || c % 2 == 1)) {
		ans++;
		int tmpa = a / 2, tmpb = b / 2, tmpc = c / 2;
		a = tmpb + tmpc;
		b = tmpa + tmpc;
		c = tmpa + tmpb;
	}

	if (ans < 1000) { cout << ans << endl; }
	else { cout << "-1" << endl; }




	return 0;
}

Measured memory_bytes: 256
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x,y)
a,b,c,d = map(int,input().split())
a -= 1
e = lcm(c,d)
print(b-a-b//c-b//d+b//e+a//c+a//d-a//e)

Measured memory_bytes: 5092