akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
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;}

template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

int isprime(int x){
    if(x<2)return 0;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0){
            return 0;
        }
    }
    return 1;
}
long long INF = 1LL<<60;
int main(){
    int q;
    cin>>q;
    vector<int> l(q),r(q);
    int maxr=0;
    rep(i,q){
        cin>>l[i]>>r[i];
        chmax(maxr,r[i]);
        }
    vector<int> sum_prime(maxr+3,0);
    for(int i=0;i<=maxr+1;i++){
    //s_{i+1}=s_{i}+islikenum(i+1);
    sum_prime[i+1]=sum_prime[i]+(i%2&&isprime(i)&&isprime((i+1)/2));
    }
    rep(i,q){
        cout<<sum_prime[r[i]+1]-sum_prime[l[i]]<<endl;
    }
    return 0;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100010];
int main(void){
	int n,m,v,p;
	scanf("%d%d%d%d",&n,&m,&v,&p);
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int l=0,r=n-p+1;
	while(l<r-1){
		int md=(l+r)>>1;
		ll tot=1ll*m*(v-p+1);
		int t=a[md]+m;
		for (int i=1;i<=n-p+1;++i){
			if (a[i]>=t) break;
			tot-=min(t-a[i],m);
		}
		bool f=1;
		if (tot>0) f=0;
		if (a[n-p+1]>t) f=0;
		if (f){
			r=md;
		}
		else{
			l=md;
		}
	}
	printf("%d",n-l);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const ll maxn = 1000005;
const double pi = acos(-1.0);

char s[10];

int main()
{
    int vis[30];
    memset(vis,0,sizeof(vis));
    for(int i = 0; i < 4; i ++)
    {
        cin >> s[i];
        vis[s[i] - 65] ++;
    }
    int num = 0;
    for(int i = 0; i < 26; i ++)
    {
        if(vis[i] != 0)
            num ++;
    }
    if(num == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int n;
    scanf("%d",&n);
    n = 24 - n;
    printf("%d\n",n+24);
    return 0;
}

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

void solve(){
	
}

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

#ifndef ONLINE_JUDGE
	//for getting input from input1.txt
	freopen("input1.txt", "r", stdin);
	//for getting output from output1.txt
	freopen("output1.txt", "w", stdout);
#endif

	ll x;
	cin>>x;
	if(x>=30) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define nl '\n'
#define vec vector<ll>
#define pr pair<ll,ll>
#define vecp vector< pr >
#define pq priority_queue<ll>
#define pqp priority_queue<pr>
#define ff first
#define ss second
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define PI 3.14159265
 const ll MOD=1000000007;
 ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=low+((high-low)/2);
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
vec sieve;
void Sieve(int N) {
    const ll maxn = N+1;
    sieve.resize(maxn);
    f(i,0,maxn) sieve[i] = i;
    sieve[1] = -1;
    sieve[0] = -1;
    f(i, 2, maxn) if (i == sieve[i]) for (ll j = 2 * i ; j < maxn ; j += i) if (sieve[j] == j) sieve[j] = i;
}
ll dp[100001];
ll func(ll n,ll k,ll *a)
{
	dp[1]=0;
	for(ll i=2;i<=n;i++)
	{
		for(ll j=i-1;j>=1 && (i-j)<=k;j--)
		{
			dp[i]=min(dp[i],(abs(a[i]-a[j])+dp[j]));
		}
	}
	return dp[n];
}
int main()
{
ll n,k;
cin>>n>>k;
ll a[n+1];
f(i,1,n+1)
cin>>a[i];
f(i,0,n+1)
dp[i]=10000000000000000;
ll ans=func(n,k,a);
cout<<ans<<nl;
return 0;
}



Measured memory_bytes: 5100
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim().split(' ');
  var a = Number(inputs[0]);
  var b = Number(inputs[1]);
console.log(a*b,(a+b)*2);
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15392
#include <iostream>

using namespace std;

long long GCD(long long a,long long b)
{
    long long  gcd;
    if(b==0)
        gcd=a;
    else
        gcd=GCD(b,a%b);
    return gcd;
    
}
long long LCM(long long a,long long b)
{
    return a*b/GCD(a, b);
}


int main() {
    
    long long a,b;
    while(cin>>a>>b)
    {
        cout<<GCD(a,b)<<" "<<LCM(a, b)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
vector<ll> a, b, c;
ll x, y, z, k;

int main(){
    cin >> x >> y >> z >> k;
    a.resize(x); b.resize(y);c.resize(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());
    auto solve=[&](ll q){
        int cnt = 0;
        rep(i, x){
            rep(j, y){
                rep(w, z){
                    if(a[i]+b[j]+c[w]<q) break;
                    cnt++;
                    if(cnt==k) return true;
                }
            }
        }
        return false;
    };
    ll ng = a[0]+b[0]+c[0]+1, ok=-1;
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        if(solve(mid))ok=mid;
        else ng=mid;
    }
    
    vector<ll> ans;
    rep(i,x)rep(j,y)rep(w,z){
        if(a[i]+b[j]+c[w]<ok) break;
        ans.push_back(a[i]+b[j]+c[w]);
    }
    sort(ans.rbegin(), ans.rend());
    rep(i, k)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 133472
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
      ll n,sum = 0;
      cin >> n;
      vector < ll > v;

      for (int i=0 ; i<n;i++){

            ll a;
            cin >> a;
            v.push_back(a);

            sum^=a;
      }
      for (int i = 0 ; i<n;i++){
            cout << (sum^v[i]) << " ";
      }
      cout << endl;

      return 0;
}


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

    long long X;
    cin >> X;
    long long ans = 0;
    
    if(X/500 > 0){
        ans += (X/500) * 1000;
        X = X % 500;
    }
    if(X/5 > 0){
        ans += (X/5) * 5;
        X = X % 5;       
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define end(x) prev(x.end());
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }

typedef long long ll;
typedef pair<int, int> pii;

const int mod = 1e9+7;
const int N = 2e5+5;

void solve(){
	string s;
	cin>>s;
	ll ans=0;
	for(ll mask=0;mask<(1<<(sz(s)-1));mask++){
		ll res=s[0]-'0';
		for(ll j=sz(s)-2,i=1;j>=0;i++,--j){
			if(mask&(1<<j)){
				ans+=res;
				res=(ll)(s[i]-'0');
			}
			else res=res*10+(ll)(s[i]-'0');
		}
		ans+=res;
	}
	cout<<ans;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <algorithm>
#include<math.h>
#include<cstdlib>
#include<cstring>
using namespace std;

 int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int aa,bb,cc;
	if(a >= max(b,c)){aa = min(b,c);bb = max(b,c);cc = a;}
	if(a <max(b,c) && a > min(b,c)){aa= min(b,c);bb = a;cc =max(b,c);}
	if(a <=min(b,c)){ aa = a;bb=min(b,c);cc=max(b,c);}
	a=aa;b=bb;c=cc;
	if (a==b&&b==c)
{   printf("1\n");
    return 0;
}
    if(a==b)
{   printf("2\n");
    return 0;
}
    if(b==c)
{   printf("2\n");
    return 0;
}
    if(a!=b&&b!=c)
{   printf("3\n");
    return 0;
}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a) 
int main(){
  int a,b;
  cin>>a>>b;
  int ans=-1;
  rep(i,2000){
    if((i*8)/100==a&&(i*10)/100==b){
      ans =i;
      break;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    for(int i = 0; i < D; ++i) {
        cin >> p[i] >> c[i];
    }
    int ans = 1e9;
    for(int S = 0; S < (1 << D); ++S) {
        int tot = 0;
        int tans = 0;
        vector<int> remain;
        for(int i = 0; i < D; ++i) {
            if(S & (1 << i)) {
                tot += 100 * (i + 1) * p[i] + c[i];
                tans += p[i];
            } else {
                for(int j = 0; j < p[i]; ++j) remain.push_back(100 * (i + 1));
            }
        }
        sort(rbegin(remain), rend(remain));
        for(auto x : remain) {
            if(tot >= G) break;
            tot += x;
            tans += 1;
        }
        ans = min(ans, tans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, i, j;
    j=0;
    cin >> a >> b >> c;
    for(i=a;i<=b;i++){
        if(c%i==0) j++;
    }
    cout << j << endl;
    return 0;
}


Measured memory_bytes: 3092
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(D)]

last=[0]*26


for d in range(1,D+1):
    ans=[]
    for choice in range(1,27):
        ans_tmp=0
        ans_tmp+=s[d-1][choice-1]
        for i in range(26):
            if i+1==choice:
                continue
            ans_tmp-=c[i]*(d-last[i])*(D-d)//36
        ans.append((ans_tmp,choice))
    _,case=max(ans)
    last[case-1]=d
    print(case)



Measured memory_bytes: 9256
#include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
     
    using namespace std;
    string s,s1;
    int main(){
        cin>>s>>s1;
        bool prime=true;
        int slen=s.length();
        int sslen=s1.length();
        for(int i=0,j=sslen-1;i<slen&&j>=0;i++,j--){
            if(s[i]!=s1[j])
                {
                    prime=false;
                    break;
                }
        }
        if(prime)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#define sp system("pause");
using namespace std;
int main(){
	int a,b,c;
	int k;
	cin>>a>>b>>c>>k;
	for(int i=1;i<=k;i++)
	{
		if(max(a,max(b,c))==a)
			a*=2;
		else if(max(a,max(b,c))==b)
			b*=2;
		else if(max(a,max(b,c))==c)
			c*=2;
	}
	cout<<a+b+c;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h, n) = readIntegerList()
    val abArray = Array(n) {
        val (a, b) = readIntegerList()
        Pair(a, b)
    }

    val dp = Array(h + 1 + abArray.maxBy { it.first }!!.first) { Int.MAX_VALUE / 3 }
    dp[0] = 0
    for (i in 1 until dp.size) {
        for (ab in abArray) {
            if (i - ab.first >= 0) {
                dp[i] = Math.min(dp[i], dp[i - ab.first] + ab.second)
            }
        }

    }
    val ans = dp.drop(h).min()!!
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 77044
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int n; string s; cin >> n >> s;
    int x = 0, mmax = 0;
    rep(i, s.size()) {
        if (s[i] == 'I') {
            x++;
            chmax(mmax, x);
        } else {
            x--;
            chmax(mmax, x);
        }
    }
    cout << mmax << endl;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())
k = Y // 1000
flag = 0
for a in range(N + 1):
    if (k - a) % 5 == 0:
        c = (k - a) // 5 - (N - a)
        b = N - a - c
        if b >= 0 and c >= 0:
            print("{0} {1} {2}".format(c, b, a))
            flag = 1
            break
if flag == 0:
    print("-1 -1 -1")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/


int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    set<int> s;
    rep(i, 0, N) {
        int x; cin >> x;

        if (s.count(x)) s.erase(x);
        else s.insert(x);
    }
    cout << s.size() << endl;
}


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

int c[100003];

int main() {

    int n;
    cin >> n;

    rep(i, n) {
        int a, b;
        cin >> a >> b;
        c[a]++;
        c[b+1]--;
    }

    int ans=0, t=1;
    rep(i, 100003) {
        t += c[i];
        if (i <= t) {
            ans = i;
        }
    }

    cout << ans-1 << endl;
}

Measured memory_bytes: 3484
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<20;


string s[12];
int h,w;
bool used[12];
int order[12];

bool check(){
    bool cc[12];
    memset(cc,false,sizeof(cc));
    string t[h];
    for (int i = 0; i < h; i++) {
        if(i%2) t[i/2]=s[order[i]];
        else t[h-i/2-1]=s[order[i]];
    }
    for (int i = 0; i < w; i++) {
        if(cc[i]) continue;
        string a="";
        for (int j = 0; j < h; j++) {
            a.pb(t[j][i]);
        }
        for (int j = i+1; j < w; j++) {
            if(cc[j]) continue;
            string b="";
            for (int k = 0; k < h; k++) {
                b.pb(t[k][j]);
            }
            reverse(ALL(b));
            if(a==b){
                cc[i]=true;
                cc[j]=true;
                break;
            }
        }
    }
    int cnt=0;
    for (int i = 0; i < w; i++) {
        cnt+=(!cc[i]);
    }
    return cnt<=1;
}

bool dfs(int m,int k){
    if(m==h){
        return check();
    }
    if(m==h-1&&h%2){
        for (int i = 0; i < h; i++) {
            if(used[i]) continue;
            used[i]=1;
            order[m]=i;
            if(dfs(m+1,k)) return true;
            used[i]=0;
        }
        return false;
    }
    for (int i = k+1; i < h; i++) {
        if(used[i]) continue;
        used[i]=1;
        order[m]=i;
        if(m%2){
            if(dfs(m+1,k)) return true;
        }
        else{
            if(dfs(m+1,i)) return true;
        }
        used[i]=0;
    }
    return false;
}

int main(){
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    if(dfs(0,-1)) puts("YES");
    else puts("NO");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

void solve() {
    int n, a, b, c;
    std::cin >> n >> a >> b >> c;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;
    std::sort(xs.rbegin(), xs.rend());

    int ans = c / a;
    for (auto x : xs) {
        c += x;
        a += b;
        ans = std::max(ans, c / a);
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
#define  fi first
#define  se second 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1e9+9;


int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b)cout<<c<<endl;
    if(b==c)cout<<a<<endl;
    if(c==a)cout<<b<<endl;
    
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()

int main() {
	int n;
	cin >> n;
	vector<int> d(51);
	FOR(i, 1, n) {
		cin >> d[i];
	}
	int sum=0;
	FOR(i, 1, n-1) {
		FOR(j, i+1, n) {
			sum += d[i] * d[j];
		}
	}
	pv(sum)
	return(0);
}

Measured memory_bytes: 256
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, mw = na()
wv = [na() for i in range(n)]
w = [wv[i][0] for i in range(n)]
v = [wv[i][1] for i in range(n)]
dp = [(mw + 1) * [0] for i in range(n + 1)]

for i in range(n):
    for j in range(mw + 1):
        if j < w[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])

print(dp[n][mw])

Measured memory_bytes: 120236
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

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

    ll A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    ll tmp, tmp1, tmp2, s = 0, w = A * 100, cap;
    double tmp3, density = 0.0;
    for (ll i = 0; i <= 30; i++)
    {
        for (ll j = 0; j <= 30; j++)
        {
            tmp = A * 100 * i + B * 100 * j;
            if (tmp <= F and tmp != 0)
            {
                ll extra = 0;
                cap = (E * tmp) / 100;
                tmp1 = cap / C;
                tmp2 = cap / D;

                for (ll k = 0; k <= tmp1; k++)
                {
                    for (ll l = 0; l <= tmp2; l++)
                    {
                        extra = C * k + D * l;
                        tmp3 = extra / (extra + tmp + .0);
                        if ((extra + tmp) > F or extra > cap)
                            break;
                        if (tmp3 >= density)
                        {
                            density = tmp3;
                            s = extra;
                            w = tmp;
                        }
                    }
                }
            }
        }
    }
    cout << s + w << " " << s << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    while(true) {
      int H = in.nextInt();
      int W = in.nextInt();

      if (H == 0 && W == 0) break;

      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if ((i + j) % 2 == 0) {
            System.out.print("#");
          }
          else {
            System.out.print(".");
          }
        }
        System.out.println();
      }
      System.out.println();
    }
  }
}

Measured memory_bytes: 34932
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
const int INF = 1001001001;

int main()
{
    int a,b,k;
    in a>>b>>k;
    if(b-a>=2*k)
    {
        for(int i=a;i<a+k;i++)
        {
            cout<<i<<endl;
        }
        for(int i=b-k+1;i<b+1;i++)
        {
            cout<<i<<endl;
        }
    }
    else for(int i=a;i<b+1;i++)cout<<i<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(s.size() <= n){
		cout << s << endl;
	}
	else {
		rep(i,n){
			cout << s[i];
		}
		cout << "..." << endl;
	}

	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

const int limit = 200010;
ll a[limit];

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

	rep(i,n) cin >> a[i];

	rep(i,1,n) a[i]+=a[i-1];

	map<ll,ll> cnt;
	cnt[0]++;
	rep(i,n) cnt[a[i]]++;

	ll ans = 0LL;

	for(auto &it:cnt){
		const ll add = 1LL * it.second * (it.second - 1) / 2LL;
		ans+= add;
	}

	cout << ans << endl;

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mm 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define siz(x) (int)x.size()
#define inf 1e18

#define show(x) cout<<#x<<" "<<x<<'\n'
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

int main()
{
    iosbase;
    ll n,w,i,sum=0;
    cin>>n>>w;
    
    vector<ll> wei(n+1),val(n+1),dp(100005,inf);
    
    for(i=1;i<=n;i++)
    {
        cin>>wei[i]>>val[i];
        sum+=val[i];
    }
    dp[0]=0;
    for(i=1;i<=n;i++)
    {
        for(ll j=sum;j>=val[i];j--)
        {
            dp[j]=min(dp[j],dp[j-val[i]]+wei[i]);
        }
    }
    ll ans=0;
    for(i=0;i<=sum;i++)
    {
        if(dp[i]<=w) ans=i;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long int lli;
int main() {
	// your code goes here
	lli n,i,ans=0;
	cin>>n;
	for(i=1;i<=n;i++){
	    if(i%3!=0 && i%5!=0){
	        ans+=i;
	    }
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3636
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = sum(A)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    if c not in C.keys():
        C[c] = 0
    if b in C.keys():
        ans += (c-b)*C[b]
        C[c] += C[b]
        C[b] = 0
    print(ans)
    

Measured memory_bytes: 21396
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int v[N];
int dp[N];
int n, k;
int calc(int idx) {
	if (idx >= n - 1)
		return 0;
	int &ret = dp[idx];
	if (ret != -1)
		return ret;
	ret = 1e9;
	for (int i = 1; i <= k; ++i)
		if (idx + i < n)
			ret = min(ret, calc(idx + i) + abs(v[idx] - v[idx + i]));
	return ret;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	memset(dp, -1, sizeof(dp));
	cout << calc(0) << endl;
	return 0;
}

Measured memory_bytes: 5760
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
		ArrayList<Integer> A = new ArrayList<>();
        ArrayList<Integer> F = new ArrayList<>();
        for(int i=0;i<N;i++){
          A.add(sc.nextInt());
        }
        for(int i=0;i<N;i++){
          F.add(sc.nextInt());
        }
        Collections.sort(A,Comparator.reverseOrder());
        Collections.sort(F);
      
        //二分探索
        //初期化
        long min = -1;
		long max = (long)Math.pow(10, 12);
        
        
        while(max-min>1){
          long binary = min + (max-min)/2;
          //条件判定
          boolean b;
          long sum = 0;
          for(int i=0;i<N;i++){
            if(A.get(i)>binary/F.get(i)){
              sum += A.get(i)-binary/F.get(i);
            }
          }
          b = sum <= K;
          //幅の更新
          if(b){
            max = binary;
          }
          else{
            min = binary;
          }
		  //
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 115508
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <map>

#define rep(i,n) for(int i=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;

int main(void)
{
    ll N;
    cin >> N;
    ll ret = 0;
    for(int A=1; A<=N; ++A) {
        for(int B=1; B<=N; ++B) {
            if(A*B >= N)
                break;
            ret++;
        }
    }
    cout << ret << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    rep (i, n) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            } 
        }
    }
    cout << "APPROVED" << endl;
    
    return 0;
}



Measured memory_bytes: 256
public class Main {

  private static void solve() {

    String[] w = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    String s = next();

    for (int i = 0; i < 7; i++) {
      if (w[i].equals(s)) {
        for (int j = 1; j <= 7; j++) {
          if (w[(i + j) % 7].equals("SUN")) {
            System.out.println(j);
            return;
          }
        }
      }
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int n, q, x, y, t, rmq[1 << 18];
bool com;

void update(int x, int y) {
	int z = t / 2 + x;
	rmq[z] = y;
	while (z) {
		z /= 2;
		rmq[z] = min(rmq[z * 2], rmq[z * 2 + 1]);
	}
}

int find(int x, int y, int z, int l, int r) {
//	cout << x << sp << y << sp << z << sp << l << sp << r << endl;
	if (x <= l&&r <= y)
		return rmq[z];
	else if (r < x || y < l)
		return intmax;
	else
		return min(find(x, y, z * 2, l, (l + r) / 2), find(x, y, z * 2 + 1, (l + r) / 2 + 1, r));
}

int main(){
	cin >> n >> q;
	for (int i = 1; i != 19; ++i) {
		if ((1 << i) / n >= 2) {
			t = (1 << i);
			break;
		}
	}
	fill(rmq, rmq + t, intmax);
	for (int i = 0; i != q; ++i) {
		cin >> com >> x >> y;
		if (com)
			cout << find(x, y, 1, 0, t / 2 - 1) << endl;
		else
			update(x, y);
	}
	return 0;
}



Measured memory_bytes: 4092
d, g = map(int,input().split())
p = []
c = []
for i in range(d):
    problems, bonus = map(int,input().split())
    p.append(problems)
    c.append(bonus)

solve_lis = []
for i in range(2**d):
    solve = 0
    point = 0
    way = True
    for j in range(d-1, -1, -1):
        if ((i >> j) & 1):
            solve += p[j]
            point += p[j] * 100 * (j + 1) + c[j]
        elif way == True:
            index = j
            way = False
    for k in range(p[index]):
        if k > 0:
            solve += 1
            point += 100 * (index + 1)
        if point >= g:
             solve_lis.append(solve)
    
print(min(solve_lis))

Measured memory_bytes: 7040
#import sys
#import numpy as np
from scipy.sparse import csr_matrix, coo_matrix
from scipy.sparse.csgraph import dijkstra, bellman_ford

#sys.setrecursionlimit(10000)

N, M = [int(i) for i in input().split()]

rows = []
cols = []
weights = []

for _ in range(M):
    # u v 間のコスト
    u, v, a = [int(i) for i in input().split()]
    rows.append(u-1)
    cols.append(v-1)
    weights.append(-a)

#graph = coo_matrix((weights, (rows, cols)), shape=(N, N)).tocsr()
graph = coo_matrix((weights, (cols, rows)), shape=(N, N)).tocsr() #N→1
try:
    d1 = bellman_ford(graph, indices = [N-1], directed=True, unweighted=False)
    print(-int(d1[0][0]))
except:
    print("inf")

Measured memory_bytes: 13964
#include <iostream>
#include <string>
#include <string.h>
#include <cstdio>
#include <cctype>
using namespace std;
int main(){

    int n, ans1=0, ans2=0; cin >> n;
    string s, t; 
    for(int i =0; i<n; i++){
        cin >> s >> t;
        if(s==t){
            ans1 += 1;
            ans2 += 1;
        } else if (s>t) {
            ans1 += 3;
        } else {
            ans2 += 3;
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}//約数求める


ll kaijou(int n) {
	ll temp = 1;
	for (int i = 2; i <= n; i++) {
		temp *= i;
		temp %= MOD;
	}
	return temp;
}



int main() {
	int n;
	cin >> n;
	vector<ll> num(n);
	for (int i = 0; i < n; i++) {
		cin >> num[i];
	}
	sort(num.begin(), num.end());
	int *flag = new int[n];
	ll pair = 0;
	for (int i = 0; i < n; i++)flag[i] = 0;
	for (int i = n - 1; i >= 0; i--) {
		ll temp;
		if (flag[i] == 0) {
			flag[i] = 1;
			for (int j = 0; j < 1000000000; j++) {
				temp = ((ll)pow(2, j) - num[i]);
				if (temp>0) {
					break;
				}
			}
			int min = -1;
			int max = i;
			for (int j = 0; j < i; j++) {
				
				int mid = (min + max) / 2;
				if (num[mid] == temp) {
					if (flag[mid] == 0) {
						flag[mid] = 1;
						pair++;
						break;
					}
					bool now = false;
					for (int k = 1; k < n; k++) {
						if (num[mid + k] != temp)break;
						if (flag[mid + k] == 0) {
							flag[mid+k] = 1;
							pair++;
							now = true;
							break;
						}
					}
					if (now == false) {
						for (int k = mid-1; k >= 0 ; k--) {
							if (num[k] != temp)break;
							if (flag[k] == 0) {
								flag[k] = 1;
								pair++;
								break;
							}
						}
					}
					break;
				}
				if (num[mid] < temp) {
					min = mid;
				}
				else {
					max = mid;
				}
				if (max - min == 1)break;
			}
		}
		

	}
	cout << pair;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define FIO "race"
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define lb(x) ((x)&(-(x)))
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 200010
using namespace std;
typedef long long ll;
struct edge{int a,b,c;bool operator <(const edge& t)const{return c>t.c;};}e[N];
int n,cnt,fa[N],siz[N],v[N],G[N][2];
ll ans[N];
inline int find(int x){while(x^fa[x])x=fa[x]=fa[fa[x]];return x;}
inline void dfs(int x,ll t){
	if(x<=n){ans[x]=t;return;}
	dfs(G[x][0],t+1ll*v[x]*siz[G[x][1]]),dfs(G[x][1],t+1ll*v[x]*siz[G[x][0]]);
}
int main(){
	cin>>n,cnt=n;
	for(int i=1;i<=n;i++)fa[i]=i,siz[i]=1;
	for(int i=1;i<n;i++)scanf("%d%d%d",&e[i].a,&e[i].b,&e[i].c);
	sort(e+1,e+n);
	for(int i=1;i<n;i++){
		int x=find(e[i].a),y=find(e[i].b);
		cnt++,fa[cnt]=cnt,v[cnt]=e[i].c,siz[cnt]=siz[x]+siz[y],fa[x]=fa[y]=cnt;
		G[cnt][0]=x,G[cnt][1]=y;
	}
	dfs(cnt,0);
	for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 7936
M, D = list(map(int, input().split()))
ans = 0
for i in range(1,M+1):
    if D >= 22:
        for j in range(22,D+1):
            k = list(str(j))
            if i == int(k[0])*int(k[1]):
                if int(k[0]) >= 2 and int(k[1]) >= 2:
                    ans += 1

print(ans)

Measured memory_bytes: 3060
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] w = new String[n];
        for (int i = 0 ; i < n ; i++) {
            w[i] = sc.next();
        }
        boolean s = true;
        for (int i = 0 ; i < n - 1; i++) {
            String a = w[i].substring(w[i].length() - 1, w[i].length());
            String b = w[i + 1].substring(0, 1);
            if (!a.equals(b)) {
                s = false;
            }
         }

        Set<String> set = new HashSet<>();
        for (int i = 0 ; i < n ; i++ ) {
            set.add(w[i]);
        }
        if (set.size() != n ) {
            s = false;
        }

        if (s) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}

Measured memory_bytes: 23252
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    print(N*800-(N//15)*200)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define lli long long int

int main() {
    int k,x;
    cin>>k>>x;
    int l = -1000000, r= 1000000;
    int l1 = max(l, x-k+1);
    int r1 = min(r, x+k-1);
    //cout<<l1<<" "<<r1<<"\n";
    for(int i=l1;i<=r1;i++){
        cout<<i<<" ";
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
#define MAX 200

int main(){
  int k;
  ll N,x[MAX],y[MAX],h[MAX],H,temph,ans;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i]>>h[i];
  }
  int count=0;
  while(true){
    if(h[count]!=0){
      swap(x[0],x[count]);
      swap(y[0],y[count]);
      swap(h[0],h[count]);
      break;
    }else count++;
  }
  
  for(int tempx=0;tempx<=100;tempx++){
    for(int tempy=0;tempy<=100;tempy++){
      H=h[0]+abs(x[0]-tempx)+abs(y[0]-tempy);
      for(k=1;k<N;k++){
        temph=H-abs(x[k]-tempx)-abs(y[k]-tempy);
        if(h[k]==0 && temph>0) break;
        if(h[k]>0 && h[k]!=temph) break;
      }
      if(k==N){
        cout<<tempx<<" "<<tempy<<" "<<H<<endl;
        return 0;
      }

    }
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long long,long long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	vector<int>h(n);
	rep(i, n)cin >> h[i];
	sort(h.begin(), h.end());
	int ans = h[k - 1] - h[0];
	for (int i = 1; i + k - 1 < n; i++) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
   int n;
   cin >> n;
   int *p;
   p = new int[n];
   for (int i=0; i<n; i++) {
      cin >> p[i];
   }
   int x_id, x_val;
   int y_id, y_val;
   int num = 0;
   for (int i=0; i<n; i++) {
      if (p[i] != (i+1)) {
         if (num == 0) {
            x_id = (i+1);
            x_val = p[i];
         } else if (num == 1) {
            y_id = (i+1);
            y_val = p[i];
         }
         num++;
      }
   }
   if (num == 0) {
      cout << "YES" << endl;
      return 0;
   }
   if (num == 2) {
      if ((x_id == y_val) && (y_id == x_val)) {
         cout << "YES" << endl;
      }else{
         cout << "NO" << endl;
      }
   } else {
      cout << "NO" << endl;
      return 0;
   }
}


Measured memory_bytes: 256