akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

const int MOD = 1e9+7;
int dp[10005][105][2];
bool mark[10005][105][2];
int n, d;
char s[10005];

void add(int &a, int b) {
    a += b;
    if(a >= MOD) a-= MOD;
}

int f(int i, int j, bool lim) {
    if(i == n) return j == 0;
    if(mark[i][j][lim]) return dp[i][j][lim];
    mark[i][j][lim] = true;
    int ret = 0;
    int up = lim ? s[i] - '0' : 9;    
    for(int k = 0; k <= up; k++) {
        int newJ = (j+k)%d;
        add(ret, f(i+1, newJ, lim&(k==up)));
    }

    return dp[i][j][lim] = ret;
}

int main() {
    ll k;
	scanf(" %s %d", s, &d);
    n = strlen(s);
  	int ans = f(0,0,1) - 1;
  	if(ans < 0) ans += MOD;
    printf("%d\n", ans);
	
    return 0;
}

Measured memory_bytes: 11520
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<list>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

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

	int N; cin >> N;
	print(N*N*N);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 1000 + 10;

int n;

long long C[maxn], S[maxn], F[maxn];

long long cal(int i)
{
    if(i == n)
    {
        return 0;
    }
    long long cur = 0;
    while(i < n)
    {
        cur += (cur >= S[i] ? (cur % F[i] == 0 ? 0 : F[i] - cur % F[i]) : S[i] - cur) + C[i];
        i++;
    }
    return cur;
}

int main()
{
    cin >> n;
    for(int i = 1; i < n; i++)
    {
        scanf("%lld%lld%lld", &C[i], &S[i], &F[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        cout << cal(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(int,input().split()))

import math
lcm = 1
for i in range(n):
    b = a[i]//2
    lcm = lcm*b //math.gcd(lcm,b)
if any(2*lcm//i % 2 == 0 for i in a):
    print(0)
else:
    print((m-lcm)//(2*lcm) + 1)

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

int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 0; i <= n; ++i)
        for(int j = 0; i + j <= n; ++j) {
            int k = n - i - j;
            if(i * 10000 + j * 5000 + k * 1000 == m) return !printf("%d %d %d\n", i, j, k);
        }

    puts("-1 -1 -1");
}

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

using namespace std;

int main(void)
{
    int H, W, K;
    cin >> H >> W >> K;

    vector<string> S;
    for (int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        S.push_back(s);
    }

    int num = 1;
    int no = 0;
    int numf =1;
  int numold=1;
    for (int i = 0; i < H; i++)
    {
        bool check = false;
        for (int j = 0; j < W; j++)
        {
            if (S[i].at(j) == '#')
            {
                check = true;
                break;
            }
        }
      //cout<<numf<<"a"<<numold<<endl;

        if (check)
        {
            for (int p = 0; p <= no; p++)
            {
                num = numf;

                bool first = true;

                for (int j = 0; j < W; j++)
                {
                    if (S[i].at(j) == '#')
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            num++;
                        }
                    }

                    cout << num;

                    if (j != (W - 1))
                    {
                        cout << ' ';
                    }
                }
                cout << endl;
            }
            no = 0;
            num++;
          
          numold = numf;
          numf = num;
        }
        else
        {
            no++;
            if(i==H-1){

            for (int p = 0; p < no; p++)
            {
                bool first = true;
                num = numold;

                for (int j = 0; j < W; j++)
                {
                    if (S[i-no].at(j) == '#')
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            num++;
                        }
                    }

                    cout << num;

                    if (j != (W - 1))
                    {
                        cout << ' ';
                    }
                }
                cout << endl;
            }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    string s; cin >> s;
    int a,z;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'A') {a=i;break;}
    }
    for(int i=0;i<s.size();i++){
        if(s[s.size()-i] == 'Z') {z=s.size()-i;break;}
    }
    cout << z-a+1 << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main()
{
    ll h, w;
    cin >> h >> w;
 
    ll ans = h * w / 2 + h * w % 2;
    cout << (h == 1 || w == 1 ? 1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
#define rep(i,s,n) for(ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(),a.end()
#define mod 1000000007
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/

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


/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,a,b,ans=0,x=0,y=0,z=0;
    cin>>n>>a>>b;
    vector<ll>p(n);
    rep(i,0,n){
        cin>>p[i];
    }
    rep(i,0,n){
        if(p[i]<=a){
            x++;
        }
        else if(p[i]>=a+1&&p[i]<=b){
            y++;
        }
        else{
            z++;
        }
    }
    cout<<min({x,y,z})<<endl; 

    
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int sum = 0;
    int num = 0;
    int digit = 0;
    int total = 0;

    int val[3];

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

    for(int i=0; i<=val[0]; i++){ 
        num = i;
        sum = 0;

        while(1){
            // printf("check number : %d\n", num);
            
            digit = num%10;
            if(digit > 0){
                sum = sum + digit;
            }

            // printf("   digit : %d\n",digit);

            num = num/10;

            // printf("   sum : %d\n", sum);

            if(num == 0){
                break;
            }

        }

        if(val[1]<=sum && sum<=val[2]){
            total = total + i;
            // printf("total : %d\n",total);
            // printf("sum : %d\n",sum);
        }
    }


    printf("%d\n",total);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>
#include<iomanip>

using namespace std;

int main()
{
	int n;
	vector<double> t, v;
	double ans = 0, input, count = 0.0, min, p_min;

	cin >> n;

	t.push_back(0);
	for (int i = 0; i < n; i++) {
		cin >> input;
		count += input;
		t.push_back(count);
	}
	
	for (int i = 0; i < n; i++) {
		cin >> input;
		v.push_back(input);
	}

	for (double time = 0; time <= t[n]; time += 0.5) {
		min = 100;
		for (int i = 0; i < n; i++) {
			if (time >= t[i] && time < t[i+1]) {
				if (min > v[i])min = v[i];
			}
			else if(time < t[i]){
				if (min > v[i] + (t[i] - time)) min = v[i] + (t[i] - time);
			}
			else {
				if (min > v[i] + (time - t[i+1])) min = v[i] + (time - t[i+1]);
			}
		}
		if (min > time) min = time;
		if (min > t[n]-time) min = t[n] - time;
		
		if (time != 0) {
			ans += (min + p_min)*0.5 / 2.0;
		}
		p_min = min;
	}
	cout << fixed;
	cout << setprecision(3) << ans;

	char qq;
	cin >> qq;
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(n);

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

    sort(l.begin(), l.end(), greater<int>());

    int sum = 0;
    for(int i=0; i<k; i++){
        sum += l.at(i);
    }

    cout << sum << 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;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin >> k;
    int n = 50;
    vector<ll> ans(n);
    rep(i,n) ans[i] = n - 1 + k / n;
    rep(i,k%n){
        ans[i] += n;
        rep(j,n){
            if(i == j) continue;
            ans[j]--;
        }
    }
    cout << n << endl;
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass
{
	static void Main(string[] args)
	{
		Answer();
	}
	public static void Answer()
	{
      var rate = int.Parse(Console.ReadLine());
      if (rate < 1200)
      {
        Console.WriteLine("ABC");
        return;
      }
      else
      {
        Console.WriteLine("ARC");
        return;
      }		
	}
}


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

int chmin(int a,int b){
  if(b < a){
    return b;
  }
  else{
    return a;
  }
}

int main() {
  int n,k;
  cin >> n >> k;
  vector<int>data(n);
  vector<long>dp(n,1000000000);
  dp[0] = 0;
  for(int i = 0;i < n;i++){
    cin >> data[i];
  }
  dp[1] = abs(data[1]-data[0]);
  for(int i = 2;i < n;i++){
    int t = k;
    if(i <= k){
      t = i;
    }
    vector<int>jmp(t);
    for(int j = 0;j < t;j++){
      jmp[j] = abs(data[i]-data[i-j-1]);
      dp[i] = chmin(dp[i],dp[i-j-1]+jmp[j]);
    }
  }
  cout << dp[n-1] << endl;
}


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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */

signed main() 
{
  string a,b,c;
  cin >> a >> b >> c;
  cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << endl;
  return 0;
}



Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		HashMap<Long, Integer> map = new HashMap<>();
		for (long i = 2; i <= Math.sqrt(n); i++) {
		    while (n % i == 0) {
		        if (map.containsKey(i)) {
		            map.put(i, map.get(i) + 1);
		        } else {
		            map.put(i, 1);
		        }
		        n /= i;
		    }
		}
		if (n != 1) {
		    if (map.containsKey(n)) {
		        map.put(n, map.get(n) + 1);
		    } else {
		        map.put(n, 1);
		    }
		}
		int count = 0;
		for (int x : map.values()) {
		    int y = x;
		    for (int i = 1; y > 0; i++) {
		        if (y >= i) {
		            count++;
		            y -= i;
		        } else {
		            break;
		        }
		    }
		}
	    System.out.println(count);
	}
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int sum = 0;
  sum += min(a, k);
  k -= min(a, k);
  k = max(k - b, 0LL);
  sum -= min(c, k);
  cout << sum << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const ll CFMOD = 998244353;
const double PI  = 3.14159265358;
const double EPS = 1e-8;
 
#define INT_MX 2147483647
#define INF (((int)1e9) + 7)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define PB push_back
#define PF push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,n,m) for(int i=(n);i<(m);i++)
#define vec vector
#define __ <<' '<<
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void solve(){
    int n;
    
    cin >> n;
    vec<pii> v(n);
    
    rep(i,n){
        cin >> v[i].F >> v[i].S;
        v[i].F += v[i].S;
    }
    
    sort(ALL(v));
    int k = -INF, ans = 0;
    
    rep(i,n){
        if(k <= v[i].F - v[i].S*2){
            k = v[i].F;
            ans++;
        }
        
    }
    cout << ans << '\n';
    
}


 
int main(){
    IOS
    int t = 1;
    
    while(t--){
        solve();
    }
}


Measured memory_bytes: 1024
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

while True:
    h, w = map(int, input().split())
    if h + w == 0:
        exit(0)

    for i in range(h):
        for j in range(w):
            print("#", end="")
        print()
    print()


Measured memory_bytes: 8296
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    cout << (A+B+C>=22 ? "bust" : "win") << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = input().split(" ")
N, M = int(N), int(M)
H = [int(h) for h in input().split(" ")]
A = []
B = []
TF = [True] * N
for i in range(M):
    a, b = input().split(" ")
    a, b = int(a), int(b)
    if H[a-1] > H[b-1]:
        if TF[b-1]:
            TF[b-1] = False
    elif H[b-1] > H[a-1]:
        if TF[a-1]:
            TF[a-1] = False
    else:
        TF[b-1] = False
        TF[a-1] = False
            
print(sum(TF))

Measured memory_bytes: 80332
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>

#define ll long long

using namespace std;

int main(){
    long long n,a;
    cin>>n>>a;
    vector<vector<ll> > dp(n+1, vector<ll>(50*50+1,0));
    vector<int> x(n);
    for(int i=0; i<n; i++){
	cin>>x[i]; 
	for(int k=i; k>=1; k--){
	for(int j=0; j<=50*50; j++){
		if(dp[k][j]){
		    dp[k+1][j+x[i]] += dp[k][j];
		}
	    }
	}
	dp[1][x[i]]++;
    }
    ll res=dp[1][a];
    for(int i=2; i<=n; i++){
	res+=dp[i][a*i];
    }
    cout<<res;

}

Measured memory_bytes: 1280
list1 = [int(a) for a in input().split()]
m_a = list1[0] #a
m_b = list1[1] #b
m_c = list1[2] #c
m_d = list1[3] #d

if abs(m_a - m_c) <= m_d:
    print("Yes")
elif abs(m_b - m_c) <= m_d and abs(m_b - m_a) <= m_d:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
	int N;
	int i;
	int L[110] ;
	scanf("%d",&N);
	for(i=0;i<=N-1;i++){
		scanf("%d",&L[i]);
	};
	int max = 0;
	for(i=0;i<=N-1;i++){
		if(L[i] > max)	max = L[i];
	};
	int sum = 0;
	for(i=0;i<=N-1;i++){
		sum += L[i];
	};
	if(sum - 2 * max > 0)
		printf("Yes");
	else printf("No");
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

int maximum (int a, int b, int c) {

    int max_num = a;
    max_num = max(max_num, b);
    max_num = max(max_num, c);

    return max_num;
}

int main() {

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

    int max_num = maximum(a, b, c);
    int diff = (max_num - a) + (max_num - b) + (max_num - c);
    
    while (diff % 2 != 0) {
        diff += 3;
    }
    cout << diff / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = [int(x) for x in input().split()]
s_coords = [[int(_) for _ in input().split()] for i in range(n)]
c_coords = [[int(_) for _ in input().split()] for j in range(m)]

for i in s_coords:
    for j in range(1, m+1):
        man_dist = abs(c_coords[j - 1][0] - i[0]) + abs(c_coords[j - 1][1] - i[1])
        if j == 1:
            min_dist = man_dist
            destn_index = 1
        if min_dist > man_dist:
            min_dist = man_dist
            destn_index = j
    print(destn_index)



Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	pfs := primeFactor(n)
	cnt := 0
	for _, v := range pfs {
		s := 0
		for i := v; s < i; i -= s{
			cnt++
			s++
		}
	}
	fmt.Println(cnt)
}

// 素因数分解
func primeFactor(n int) map[int]int {
	ret := make(map[int]int)
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			n /= i
			ret[i]++
		}
	}
	if n > 1 {
		ret[n]++
	}
	return ret
}


Measured memory_bytes: 1856
N, M =map(int,input().split())
H_n =list(map(int,input().split()))

weak=[]
for i in range(M):
    An,Bn =map(int,input().split())
    if H_n[An-1] < H_n[Bn-1]:
        weak.append(An)
    elif H_n[An-1] == H_n[Bn-1]:
        weak.append(An)
        weak.append(Bn)
    else:
        weak.append(Bn)

print(N -len(set(weak)))



Measured memory_bytes: 20096
#include <stdio.h>

int main(void)
{
	int i;
	int qty;
	char str[21];
	
	for(i=0;i<21;i++)
	{
		str[i] = 'm';
	}
	
	//gets(str);
	fgets(str,21,stdin);
	
	for(i=0;i<21;i++)
	{
		if(str[i] == '\0')
		{
			qty = i;
		}
	}
	
	for(i=(qty-1);i>=0;i--)
	{
		printf("%c",str[i]);
	}
	
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	char a, b;	cin >> a >> b;
  	int ai = a - '0', bi = b - '0';
  	string abs, bas;
  	rep(i,bi) abs.push_back(a);
  	rep(i,ai) bas.push_back(b);
	if(abs >= bas) cout << bas << endl;
  	else cout << abs << endl;
}


Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    a,b,c,d=map(int, input().split())
    if a+b>c+d:
        print("Left")
    elif a+b==c+d:
        print("Balanced")
    else:
        print("Right")

main()

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	s := nextInt()
	w := nextInt()
	if w >= s {
		fmt.Println("unsafe")
	} else {
		fmt.Println("safe")
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

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

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 1760
#include <iostream>

using namespace std;

int main(void) {
    int input;
    cin >> input;

    int h = 0;
    int m = 0;
    int s = 0;
    while (input > 0) {
        if (input >= (60 * 60)) {
            h++;
            input -= (60 * 60);
        } else if (input >= 60) {
            m++;
            input -= 60;
        } else {
            s = input;
            input -= input;
        }
    }
    
    cout << h << ':' << m << ':' << s << endl;

    return 0;
}

Measured memory_bytes: 3092
def main():
    from math import gcd
    K = int(input())

    ans = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            for c in range(1, K + 1):
                ans += gcd(gcd(a, b), c)

    print(ans)


if __name__ == '__main__':
    main()


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	cout << "ABC" << N << endl;

	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
        ($($t:ty),*) => {
            $(
                impl InputValue for $t {
                    fn parse(s: &str) -> $t { s.parse().unwrap() }
                }
            )*
    	}
    }
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
    	($($t:ident),*) => {
    		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
    			fn parse(s: &str) -> ($($t),*) {
    				let mut tokens = s.split_whitespace();
    				let t = ($($t::parse(tokens.next().unwrap())),*);
    				t
    			}
    		}
    	}
    }
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

const INF: usize = 10000000;

fn main() {
    let s: String = read();
    let s: Vec<u8> = s.into_bytes();

    let mut map = HashMap::new();
    let mut flg = 0;
    let mut pl = 0;
    map.insert(flg, pl);
    pl += 1;

    let n = s.len();
    for i in 0..n {
        let idx = (s[i] - 'a' as u8) as usize;
        flg ^= 1<<idx;
        if !map.contains_key(&flg) {
            map.insert(flg, pl);
            pl += 1;
        }
    }

    let mut dp = vec![INF; n+100];
    let mut last = 0;
    dp[0] = 0;
    flg = 0;
    for i in 0..n {
        let idx = (s[i] - 'a' as u8) as usize;
        flg ^= 1<<idx;

        let mut best = INF;
        for l in 0..26 {
            let bf = flg ^ (1<<l);
            if map.contains_key(&bf) {
                let &bi = map.get(&bf).unwrap();
                best = min(best, dp[bi]);
            }
        }
        let &fi = map.get(&flg).unwrap();
        dp[fi] = min(dp[fi], best + 1);
        last = dp[fi];
    }
    if flg == 0 {
        last = 1;
    }

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

Measured memory_bytes: 17172
#include<bits/stdc++.h>
 
using namespace std;
 
using int64 = long long;
const int64 INF = 1000000000000001LL;
 
int H, W;
string S[50];
int64 dp[55][55];
int64 dp2[55][55][55][55];
 
int64 rec2(int sy, int sx, int gy, int gx)
{
  return (dp2[sy][sx][gy][gx]);
}
 
int64 rec(int sy, int sx)
{
  if(sy >= H && sx >= W) return (-INF);
  if(~dp[sy][sx]) return (dp[sy][sx]);
  int64 ret = rec2(sy, sx, H - 1, W - 1);
  for(int i = sy; i < H; i++) {
    for(int j = sx; j < W; j++) {
      if((isdigit(S[i][j]))) {
        if(i + 2 < H && S[i + 1][j] == '+') {
          auto x = rec2(sy, sx, i, j);
          auto y = rec(i + 2, j);
          if(x >= 0 && y >= 0) ret = max(ret, x + y);
        }
 
        if(j + 2 < W && S[i][j + 1] == '+') {
          auto x = rec2(sy, sx, i, j);
          auto y = rec(i, j + 2);
          if(x >= 0 && y >= 0) ret = max(ret, x + y);
        }
 
        if((i + 1 < H && S[i + 1][j] == '+') &&
           (j + 1 < W && S[i][j + 1] == '+')) {
          if(i + 1 < H && j + 1 < W) {
            auto x = rec2(sy, sx, i, j);
            auto y = rec(i + 1, j + 1);
            if(x >= 0 && y >= 0) ret = max(ret, x + y);
          }
        }
      }
    }
  }
  return (dp[sy][sx] = min(INF, ret));
}
 
int main()
{
  memset(dp, -1, sizeof(dp));
  fill_n(***dp2, 55 * 55 * 55 * 55, -INF);
 
  cin >> H >> W;
  for(int i = 0; i < H; i++) cin >> S[i];
 
 
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(isdigit(S[i][j])) {
        dp2[i][j][i][j] = S[i][j] - '0';
        for(int m = i; m < H; m++) {
          for(int n = j; n < W; n++) {
            if(isdigit(S[m][n])) {
              if(dp2[i][j][m][n] >= 0) {
                if(m + 2 < H && S[m + 1][n] == '*') {
                  dp2[i][j][m + 2][n] = max(dp2[i][j][m + 2][n], dp2[i][j][m][n] * (int64) (S[m + 2][n] - '0'));
                  dp2[i][j][m + 2][n] = min(INF, dp2[i][j][m + 2][n]);
                }
                if(n + 2 < W && S[m][n + 1] == '*') {
                  dp2[i][j][m][n + 2] = max(dp2[i][j][m][n + 2], dp2[i][j][m][n] * (int64) (S[m][n + 2] - '0'));
                  dp2[i][j][m][n + 2] = min(INF, dp2[i][j][m][n + 2]);
                }
                if((n + 1 < W && S[m][n + 1] == '*') || (m + 1 < H && S[m + 1][n] == '*')) {
                  if(n + 1 < W && m + 1 < H) {
                    dp2[i][j][m + 1][n + 1] = max(dp2[i][j][m + 1][n + 1], dp2[i][j][m][n] * (int64) (S[m + 1][n + 1] - '0'));
                    dp2[i][j][m + 1][n + 1] = min(INF, dp2[i][j][m + 1][n + 1]);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
 
  auto p = rec(0, 0);
  if(p >= INF)
    cout << -1 << endl;
  else
    cout << p << endl;
}

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




int main(){
    int x;cin >> x;
    for (int i = 0; i < 10; i++) {
        int t = 8 - i;
        if(400 + i * 200 <= x && x < 400 + (i + 1) * 200){
            cout << t << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3684
h,w = map(int,input().split())

ls = [[x for x in input()] for _ in range(h)]

for i in range(h):
    ls[i].append(".")
    ls[i].insert(0,".")
a = ["." for _ in range(w+2)]
ls.append(a)
ls.insert(0,a)

ans = [['#' for _ in range(w)] for _ in range(h)]

for j in range(1,h+1):
    for k in range(1,w+1):
        if ls[j][k] == ".":
            c = [ls[j-1][k-1],ls[j-1][k],ls[j-1][k+1],ls[j][k-1],ls[j][k+1],ls[j+1][k-1],ls[j+1][k],ls[j+1][k+1]]
            ans[j-1][k-1] = str(c.count("#"))

for l in ans:
    print("".join(l))   

Measured memory_bytes: 39792
import * as fs from 'fs'

function main(n: number, xn: number[]) {
    xn = xn.sort();

    for (let i: number = 0; i < xn.length-1; i++) {
        if (xn[i] === xn[i+1]) {
            console.log('NO');
            return;
        }
    }
    console.log('YES');
}

const input: string[] = fs.readFileSync("/dev/stdin", "utf8").split("\n");
const args1: number = parseInt(input[0]);
const args2: number[] = input[1].split(' ').map(n => parseInt(n));
main(args1, args2);


Measured memory_bytes: 34460
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n, x;
  cin >> n >> x;
  if(x == 1 || x == 2 * n - 1){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for(int i = 1; i <= 2 * n - 1; i++){
    int index = i - (n - x);
    if(index <= 0)index += 2 * n - 1;
    if(index >= 2 * n)index -= 2 * n - 1;
    cout << index << endl;
  }
	return 0;
}


Measured memory_bytes: 1536
#include<cstdio>
#include<cmath>

using namespace std;


const int CCW_COUNTER_CLOCKWISE = 1;
const int CCW_CLOCKWISE = -1;
const int CCW_ONLINE_BACK = 2;
const int CCW_ONLINE_FRONT = -2;
const int CCW_ON_SEGMENT = 0;


const double EPS = 1e-10;
inline bool equals(double x, double y) {
  return fabs(x-y) < EPS;
}


struct Point {
  Point(int _x, int _y) : x(_x), y(_y) {}

  double x, y;

  Point operator+(const Point& other) const {
    return Point(x+other.x, y+other.y);
  }

  Point operator-(const Point& other) const {
    return Point(x-other.x, y-other.y);
  }

  Point operator*(double k) const {
    return Point(x*k, y*k);
  }
};


typedef Point Vector;


struct Segment {
  Segment(Point _p1, Point _p2) : p1(_p1), p2(_p2) {}
  Point p1, p2;
};


typedef Segment Line;


double norm(Vector v) {
  return v.x*v.x + v.y*v.y;
}

double abs(Vector v) {
  return sqrt(norm(v));
}

double dot(Vector a, Vector b) {
  return a.x*b.x + a.y*b.y;
}

double cross(Vector a, Vector b) {
  return a.x*b.y - a.y*b.x;
}

int ccw(Point p0, Point p1, Point p2) {
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if (cross(a, b) > EPS) return CCW_COUNTER_CLOCKWISE;
  if (cross(a, b) < -EPS) return CCW_CLOCKWISE;
  if (dot(a, b) < -EPS) return CCW_ONLINE_BACK;
  if (norm(a) < norm(b)) return CCW_ONLINE_FRONT;
  return CCW_ON_SEGMENT;
}

bool intersect(Point p0, Point p1, Point p2, Point p3) {
  return ccw(p0, p1, p2) * ccw(p0, p1, p3) <= 0 &&
         ccw(p2, p3, p0) * ccw(p2, p3, p1) <= 0;
}

double getDistanceLP(Line line, Point p) {
  Point p1 = line.p1, p2 = line.p2;
  return fabs(cross(p2-p1, p-p1) / abs(p2-p1));
}

double getDistanceSP(Segment s, Point p) {
  if (dot(s.p2-s.p1, p-s.p1) < -EPS) return abs(p-s.p1);
  if (dot(s.p1-s.p2, p-s.p2) < -EPS) return abs(p-s.p2);
  return getDistanceLP(s, p);
}

double getDistanceSS(Segment s1, Segment s2) {
  if (intersect(s1.p1, s1.p2, s2.p1, s2.p2)) return 0.0; 
  return fmin(fmin(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
              fmin(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}


void solve(int n) {
  for (int i = 0; i < n; ++i) {
    int x0, y0, x1, y1, x2, y2, x3, y3;
    scanf("%d %d %d %d %d %d %d %d", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);
    Point p0(x0, y0), p1(x1, y1), p2(x2, y2), p3(x3, y3);
    Segment s1(p0, p1), s2(p2, p3);
    printf("%.10lf\n", getDistanceSS(s1, s2));
  }
}

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

  solve(n);
  return 0;
}



Measured memory_bytes: 2820
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
ll inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


const int MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

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

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

    int n, k;
    cin >> n >> k;
    ll a[100100];

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

    ll res = 0;

    sort(a, a+n);
    for (int i = 0; i < n; i++)
    {
        res = (res + (a[i] * COM(i, k-1))%MOD)%MOD;
    }
    for (int i = 0; i < n; i++)
    {
        res = (res - (a[i] * COM(n-i-1, k-1))%MOD + MOD)%MOD;
    }
    cout << res << "\n";
}

Measured memory_bytes: 13056
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 inf = 1000000000000;
    int n;
    std::cin >> n;
    i64 sxl = inf, sxr = -inf, syd = inf, syu = -inf,
        posmxl = inf, posmxr = -inf, posmyd = inf, posmyu = -inf,
        negmxl = inf, negmxr = -inf, negmyd = inf, negmyu = -inf;

    for (int i = 0; i < n; i++) {
        i64 x, y; char dir;
        std::cin >> x >> y >> dir;
        if (dir == 'U') {
            sxl = std::min(sxl, x);
            sxr = std::max(sxr, x);
            posmyd = std::min(posmyd, y);
            posmyu = std::max(posmyu, y);
        } else if (dir == 'D') {
            sxl = std::min(sxl, x);
            sxr = std::max(sxr, x);
            negmyd = std::min(negmyd, y);
            negmyu = std::max(negmyu, y);
        } else if (dir == 'R') {
            syd = std::min(syd, y);
            syu = std::max(syu, y);
            posmxl = std::min(posmxl, x);
            posmxr = std::max(posmxr, x);
        } else {
            syd = std::min(syd, y);
            syu = std::max(syu, y);
            negmxl = std::min(negmxl, x);
            negmxr = std::max(negmxr, x);
        }
    }

    std::vector<double> cand { 0 };
    // negmxr - t == sxr
    cand.push_back(negmxr - sxr);
    cand.push_back(negmyu - syu);
    // posmxr + t == sxr
    cand.push_back(sxr - posmxr);
    cand.push_back(syu - posmyu);
    // negmxl - t == sxl
    cand.push_back(negmxl - sxl);
    cand.push_back(negmyd - syd);
    // posmxl + t == sxl
    cand.push_back(sxl - posmxl);
    cand.push_back(syd - posmyd);

    // negmxr - t == posmxr + t
    cand.push_back((negmxr - posmxr) / 2.0);
    cand.push_back((negmyu - posmyu) / 2.0);
    //negmxl - t == posmxl + t
    cand.push_back((negmxl - posmxl) / 2.0);
    cand.push_back((negmyd - posmyd) / 2.0);

    std::sort(cand.begin(), cand.end());
    auto it = std::lower_bound(cand.begin(), cand.end(), 0.0);

    auto dx = [&](double t) {
        double ub = std::max({ (double)sxr, posmxr + t, negmxr - t }),
            lb = std::min({ (double)sxl, posmxl + t, negmxl - t });
        return ub - lb;
    };
    auto dy = [&](double t) {
        double ub = std::max({ (double)syu, posmyu + t, negmyu - t }),
            lb = std::min({ (double)syd, posmyd + t, negmyd - t });
        return ub - lb;
    };
    auto f = [&](double t) {
        return dx(t) * dy(t);
    };

    auto ret = std::numeric_limits<double>::max();
    while (it != cand.end()) {
        ret = std::min(ret, f(*it++));
    }

    std::cout << std::fixed << std::setprecision(10);
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
function main()
  n = parse(readline())
  if n < 105
    print(0)
  elseif n < 135
    print(1)
  elseif n < 165
    print(2)
  elseif n < 189
    print(3)
  elseif n < 195
    print(4)
  else
    print(5)
  end
end

main()

Measured memory_bytes: 108284
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

int main() {
	ll N, M; cin >> N >> M;
	cout << C(N) + C(M) << endl;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
c, a = [], []
for i in range(n):
  tmp = [int(j) for j in input().split()]
  c.append(tmp[0])
  a.append(tmp[1:])

INF = 10 ** 9
ans = INF

for s in range(0, 1 << n):
  smart = [0] * m
  cost_sum = 0

  for i in range(n):
    if (s >> i) % 2 == 0:
      continue
    cost_sum += c[i]

    for j in range(m):
      smart[j] += a[i][j]

    ok = True
    for j in range(m):
      if smart[j] < x:
        ok = False
    if ok:
      ans = min(ans, cost_sum)

if ans == INF:
  ans = -1
print(ans)
        


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X);
    vector<ll> B(Y);
    vector<ll> C(Z);
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];
    priority_queue<ll> queue;
    rep(x, X) {
        rep(y, Y) {
            queue.push(A[x] + B[y]);
        }
    }
    vector<ll> target;
    ll tmp = min(K, X*Y);
    while (target.size() != tmp) {
        ll q = queue.top();
        queue.pop();
        target.push_back(q);
    }
    priority_queue<ll> ans;
    rep(i, tmp) {
        ll t = target[i];
        rep(z, Z) {
            ans.push(C[z] + t);
        }
    }

    int cnt = 0;
    while (cnt != K) {
        cout << ans.top() << endl;
        ans.pop();
        cnt++;
    }
}

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


Measured memory_bytes: 43400
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def root(par, x):
    if par[x] == x:
        return x
    else:
        return root(par, par[x])


def unite(rank, par, x, y):
    x = root(par, x)
    y = root(par, y)

    if x == y:
        par[x] = y

    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1


def main():
    N, M = map(int, readline().split())
    p = list(map(int, readline().split()))
    m = map(int, read().split())
    XY = list(zip(m, m))

    par = list(range(N))
    rank = [0] * N

    for x, y in XY:
        x -= 1
        y -= 1
        unite(rank, par, x, y)

    d_p = defaultdict(list)
    d_index = defaultdict(list)
    for i in range(N):
        par[i] = root(par, i)
        d_index[par[i]].append(p[i])
        d_p[par[i]].append(i+1)

    cnt = 0
    for i in set(par):
        cnt += len(list(set(d_index[i]) & set(d_p[i])))

    print(cnt)


main()


Measured memory_bytes: 69828
n = int(input())
s = input()
sol = 0


for i in range(n // 2):
    
    if s[i - 1] == s[i - 1 + (n // 2)]:
        sol = sol + 1
 
if sol == n // 2:
    if n != 1 and n % 2 == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 2940