akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();

        long LCM = lcm(C, D);

        long C1 = A / C;
        if (A % C > 0) {
            C1++;
        }
        long C2 = B / C;

        long D1 = A / D;
        if (A % D > 0) {
            D1++;
        }
        long D2 = B / D;

        long LCM1 = A / LCM;
        if (A % LCM > 0) {
            LCM1++;
        }
        long LCM2 = B / LCM;

        System.out.println((B - A + 1) - ((C2-C1+1) + (D2-D1+1) - (LCM2-LCM1+1)));
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private static long gcd(long m, long n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  ll K;
  cin>>K;
  ll cnt = K/50;
  int amari = K%50;
  vector<ll> ans(50,49+cnt);
  for(int i(0);i<amari;i++){
    ans[i] += 50-amari+1;
  }
  for(int i(amari);i<50;i++){
    ans[i] -= amari;
  }
  cout << 50 << endl;
  for(int i(0);i<50;i++){
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}



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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define pb push_back

using namespace std;

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

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void solve() {

}

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n) cin >> vec[i];
  vector<int> ans = vec;
  sort(ALL(vec));
  if( vec == ans ) { puts("YES"); return 0; }

  rep(i,n) {
    REP(j,i+1,n) {
      vector<int> tmp = vec;
      swap(tmp[i],tmp[j]);
      if( tmp == ans ) { puts("YES"); return 0; }
    }
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 256
N = int(input())
s, t = map(str, input().split())
ss = []
tt = []
ss.append(s)
tt.append(t)

for i in range(N - 1):
    s_, t_ = map(str, input().split())
    ss.append(s_)
    tt.append(t_)
tt = [int(j) for j in tt]

X = str(input())

index = ss.index(X)
tt = tt[(index + 1):]
x = sum(tt)

print(x)


Measured memory_bytes: 3064
N = int(input())
*a, = map(int, input().split())

dp = [[0]*N for _ in range(N)]
size = [[0]*N for _ in range(N)]

for i in range(N):
    for j in range(i,N):
        size[i][j] = sum(a[i:j+1])

for i in range(N-2, -1, -1):
    for j in range(i+1, N):
        dp[i][j] = min([dp[i][k] + dp[k+1][j] + size[i][k] + size[k+1][j] for k in range(i, j)])

print(dp[0][N-1])

Measured memory_bytes: 77068
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    double x[100], y[100], z[100];
    cin >> n;
    REP(i, n) {
        cin >> y[i];
    }
    REP(i, n) {
        cin >> x[i];
    }
    REP(i,n) {
        z[i] = fabs(x[i] - y[i]);
    }
    double l1 = 0, l2 = 0, l3 = 0, linf = 0;
    REP(i, n) {
        l1 += z[i];
        l2 += pow(z[i], 2);
        l3 += pow(z[i], 3);
        if (z[i] > linf) {
            linf = z[i];
        }
    }
    printf("%lf\n%lf\n%lf\n%lf\n", l1, pow(l2, 0.5), pow(l3, 1/3.0), linf);
    return 0;
}


Measured memory_bytes: 3428
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  vector<int>tmp(n);
  map<int,int>m;
  rep(i,n){
    tmp[i] = v[i] - (i + 1);
  }
  sort(all(tmp));
  int med;
  if(n % 2 == 0){
    med = tmp[n / 2] + tmp[n / 2 - 1];
    med /= 2;
  }
  else med = tmp[n / 2];
  ll ans = 0;
  rep(i,n){
    ans += abs(v[i] - (med + (i + 1)));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for(int &i: h) cin >> i;

    vector<int> dp(n, INT_MAX);
    dp[0] = 0, dp[1] = abs(h[0] - h[1]);

    for(int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i - 2] -h[i]));
    }

    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  long double deg,ans;
  h=h%12;
  //cout<<a<<endl;
  deg = m/60.0-h/12.0-(m/12.0)/60.0;
  //cout<<deg<<endl;
  deg=deg*(2*PI);
  //cout<<deg<<endl;
  //cout<<"cosnan"<<cos(deg)<<endl;
  double c =b/a;
  //cout<<"c:"<<c<<endl;
  ans=a*a+b*b-2*a*b*cos(deg);
  //cout<<ans<<endl;
  //ans=ans*a*a;
  ans=sqrt(ans);
  //cout<<"ansnan"<<ans<<endl;
  //ans=sqrt(ans);
  //printf("%.10lf\n",ans);
  cout << fixed << setprecision(20);
  cout<<ans<<endl;
}

Measured memory_bytes: 4188
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
/*
int main()
{
	int n, a, b, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		int m = max(a, max(b, c));
		int l = min(a, b);
		int n = min(b, c);
		if (l == n) {
			n = min(a, c);
		}
		if (m*m == n*n + l*l) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
    return 0;
}

*/
int main() {
	priority_queue<int> pq;
	int n, a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a;
			pq.push(a);
		}	
		int a, b, c;
		a = pq.top(); pq.pop();
		b = pq.top(); pq.pop();
		c = pq.top(); pq.pop();
		cout << (a*a == b*b + c*c ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
n=int(input())
alis=list(map(int,input().split()))
xlis=dict()
for i in set(alis):
    xlis[i-1]=0
    xlis[i+1]=0
    xlis[i]=0
for i in alis:
    xlis[i-1]+=1
    xlis[i+1]+=1
    xlis[i]+=1
print(max(xlis.values()))

Measured memory_bytes: 21108
#include <stdio.h>
#include <math.h>

typedef struct{
  double x;
  double y;
} Point;

void koch(int n,Point a, Point b){
  if(n==0) return;
  Point s,t,u;

  s.x=(2*a.x+b.x)/3;
  s.y=(2*a.y+b.y)/3;
  t.x=(a.x+2*b.x)/3;
  t.y=(a.y+2*b.y)/3;
  u.x=(t.x-s.x)/2-(t.y-s.y)*(sqrt(3)/2)+s.x;
  u.y=(t.x-s.x)*(sqrt(3)/2)+(t.y-s.y)/2+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main(){
  Point a,b;
  int n;
  scanf("%d", &n);
  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        String s=scan.next();
        boolean c=false,f=false;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='C')
                c=true;
            if(s.charAt(i)=='F'&&c)
                f=true;
        }
        if(c &&f)
            System.out.println("Yes");
        else
            System.out.println("No");


    }
}


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

int main(void) {
	std::vector<int> times;
	for (int i = 0; i < 3; i++) {
		int temp;
		std::cin >> temp;
		times.push_back(temp);
	}
	std::sort(times.begin(), times.end());
	std::cout << (times[0] + times[1]);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    int answer = 0;
    if(k > a + b){
      answer = a - (k - a - b);
    } else {
      answer = Math.min(a,k);
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 35852
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		String K = sc.nextLine();

		int lastK = Integer.parseInt(K.substring(K.length()-1, K.length()));

		int ans;
		if(lastK%2==0) {
			ans = A-B;
		} else {
			ans = B-A;
		}
		System.out.println(ans);
	}
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
bitset<55555> bi;
vector<int> pri;
void criba()
{
	bi.set();
	fore(i, 2, 55555)
	{
		if(bi[i])
		{
			forg(j, i + i, 55555, i)
				bi[j] = 0;
			if(i % 10 == 1)
				pri.pb(i);
		}
	}
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	criba();
	int n;
	cin>>n;
	fore(i, 0, n)
	{
		if(i > 0) cout<<' ';
		cout<<pri[i];
	}
	cout<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

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

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

    int a;
    for (int i = 1; i < N; i++)
    {
        for (int i = 1; i < N; i++)
        {
            if (p[i] < p[i - 1])
            {
                a = p[i];
                p[i] = p[i - 1];
                p[i - 1] = a;
            }
        }
    }

    int answer = 0;

    for (int i = 0; i < K; i++)
    {
        answer += p[i];
    }

    cout << answer << endl;
}

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

namespace Student
{
    class Program
    {
         static void Main(string[] args)
        {
            Test4();
        }
                private static void Test4()
        {
            string str=Console.ReadLine();
            Console.WriteLine("{0}{1}{2}",str[0],str.Length-2,str[str.Length-1]);
            Console.ReadKey();
        }
    }
}

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

typedef pair<int,int>   ii;

map<ii,int> S[20][20];
vector<ll>  F[20][20];

ll  a[20];

ll  dp(int l,int r,int xl,int xr)   {
    if (l + 1 == r)
        return  0;

    int j = -1;

    if (S[l][r].count(ii(xl,xr)))
        j = S[l][r][ii(xl,xr)];

    if (j >= 0) return  F[l][r][j];

    S[l][r][ii(xl,xr)] = F[l][r].size();
    F[l][r].pb(1e18);

    ll &res = F[l][r].back();

    for(int i = l + 1 ; i < r ; ++i)    {
        ll  nxt = a[i] * (xl + xr);
        nxt += dp(l,i,xl,xl + xr);
        nxt += dp(i,r,xl + xr,xr);

        if (res > nxt)
            res = nxt;
    }
    return  res;
}

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

    int n;  cin >> n;

    for(int i = 1 ; i <= n ; ++i)
        cin >> a[i];

    cout << dp(1,n,1,1) + a[1] + a[n] << endl;
    //cerr << f.size() << "\n";
}

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

int main() {
    int x, N;
    cin >> x >> N;
    set <int> A;
    for (int i=0; i<N; i++){
        int n;
        cin >> n;
        A.insert(n);
    }
    int a, b;
    for (int i=x;; i++){
        if (!A.count(i)){
            a=i;
            break;
        }
    }
    for (int i=x;;i--){
        if (!A.count(i)){
            b=i;
            break;
        }
    }
    int y=abs(x-a);
    int z=abs(x-b);
    if (y>=z){
        cout << b << endl;
    }
    else cout << a << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 200000;
const int INF = 1e9 + 5;

#define v first
#define pos second

int a[MAXN+5], b[MAXN+5], N;
PII diff[MAXN+5];
LL pre[MAXN+5];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	LL ans = 0;
	int minv = INF;;
	bool eq = true;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
		if (a[i] != b[i]) eq = false;
		if (a[i] > b[i]) minv = min(b[i], minv);
		ans += a[i];
	}
	
	if (eq) {
		cout << "0\n";
		return 0; 
	}
	
	ans -= minv;
	cout << ans << "\n";
	
	/**** Note MAXN ****/
}


Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string str;
  cin >> str;
  int q,i;
  cin >> q;
  string s1,s2;
  int a,b;
  for(i=0;i<q;i++){
    //cout << str << endl;
    cin >> s1 >> a >> b;
    if(s1=="print"){
      cout << str.substr(a,b-a+1) << endl;
    }else if(s1=="reverse"){
      string s3=str.substr(a,b-a+1);
      reverse(s3.begin(),s3.end());
      str=str.substr(0,a)+s3+str.substr(b+1,str.size()-a-1);
    }else{
      cin >> s2;
      str=str.substr(0,a)+s2+str.substr(b+1,str.size()-a-1);
    }
  }
}



Measured memory_bytes: 3216
n,m = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i)
cnt = 0
sum = as.inject(:+)
as.each do |a|
	if 4*m*a >= sum
		cnt += 1
	end
end

puts cnt >= m ? "Yes" : "No"

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll bit[100010], num;
ll n, a[200010], b[200010], pt;
priority_queue<ll> ct;
priority_queue<P> tl;

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
		tl.push(P(b[i], a[i]));
		pt += a[i];
	}
	bool jd = true;
	for (int i = 0; i < n; i++)
	{
		if (tl.size() == 0)
		{
			break;
		}
		while (tl.top().first >= pt)
		{
			ct.push(tl.top().second);
			tl.pop();
			if (tl.size() == 0)
			{
				break;
			}
		}
		if (ct.size() == 0)
		{
			jd = false;
			break;
		}
		else
		{
			pt -= ct.top();
			ct.pop();
		}
	}
	if (jd)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	int www;
	cin >> www;
}


Measured memory_bytes: 10732
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll h, w;std::cin >> h >> w;
  vector<string> s(h);
  re(i, h) std::cin >> s[i];
  vvl ans = vv(2*h, 2*w, 0, ll);
  re(i, h){
    re(j, w) if(s[i][j]=='*') ans[i*2][j*2] = ans[i*2][j*2+1] = 1;
    re(j, w) if(s[i][j]=='*') ans[i*2+1][j*2] = ans[i*2+1][j*2+1] = 1;
  }
  re(i, 2*h){
    re(j, w) std::cout << (ans[i][j*2]==1?'*':'.');
    std::cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int sizes;
vector <int> adj[200001];
bool visited[200001]={0};
void dfs(int v)
{
    if(visited[v]==0)
    {
     visited[v]=1;
     for(int i=0;i<(adj[v].size());i++)
        if(visited[adj[v][i]]==0)
        {
         dfs(adj[v][i]);
         visited[adj[v][i]]=1;
        }
        sizes++;
    }
    return;
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t;
   t=1;
   while(t--)
   {
        int n,m;
        cin>>n>>m;
        for(int i=0;i<m;i++)
        {
            int a,b;
            cin>>a>>b;
            a--;b--;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        int mx=0;                          //to count the size of maximum members
        for(int i=0;i<n;i++)
        {
            if(visited[i]==0)
            {
                sizes=0;
                dfs(i);
                mx=max(mx,sizes);
            }
        }
        cout<<mx;
   }
}


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

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

    int n;cin>>n;
    int x,t;cin>>x>>t;

    int ans=(n-1)/x+1;

    ans*=t;

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
const ll INFLL = (ll) 1e18 + 1;
ll A[111], B[111];
ll C[111], D[111];
vector<l_l> edge1[55];
vector<l_l> edge2[55 * 2500];

vector<ll> dijkstra(ll s){
    priority_queue<l_l, vector<l_l>, greater<l_l>> pq;
    vector<ll> dist(55*2500, INFLL);
    dist[s] = 0;
    pq.push({dist[s], s});
    while(!pq.empty()){
        auto tmp = pq.top();
        pq.pop();
        ll from = tmp.second;
        ll d = tmp.first;
        //if(dist[from] < d)continue;
        for(auto p: edge2[from]){
            ll to = p.first;
            ll d = p.second;
            if(dist[to] > dist[from] + d){
                dist[to] = dist[from] + d;
                pq.push(l_l(dist[to], to));
            }
        }
    }
    return dist;
}
ll f(ll v, ll s){
    return v*2500 + s;
}
int main(){
    ll n, m ,s, u, v;
    cin >> n >> m >> s;
    for(ll i = 0;i < m;i++){
        cin >> u >> v >> A[i] >> B[i];
        u--;v--;
        edge1[u].emplace_back(v, i);
        edge1[v].emplace_back(u, i);
    }
    for (int i = 0; i < n; ++i) {
        cin >> C[i] >> D[i];
    }
    for(ll i = 0;i < n;i++){
        for(ll j = 0;j <= 2499;j++){
            ll to = min(j + C[i], 2499ll);
            edge2[f(i,j)].emplace_back(f(i,to), D[i]);
            for(auto e: edge1[i]){
                ll to2 = e.first;
                ll edge_idx = e.second;
                if(j - A[edge_idx] < 0)continue;
                edge2[f(i,j)].emplace_back(f(to2, j-A[edge_idx]), B[edge_idx]);
            }
        }
    }
    s = min(s, 2499LL);
    auto dist = dijkstra(f(0,s));
    for(ll i = 1;i < n;i++){
        ll ans = INFLL;
        for(ll j = 0;j < 2500;j++){
            ans = min(ans, dist[f(i, j)]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 24092
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    unsigned n,k,s,t,a;
    cin>>n>>k>>s>>t;
    vector<unsigned> A,c;
    fr(i,n){
        cin>>a;
        if((a&s)==s and (a|t)==t) A.push_back(a);
    }
    n=A.size();
    chmin(k,n);
    c.resize(n);
    unsigned l{};
    for(unsigned i{};i<18u;++i){
        if((s>>i)&1u) continue;
        if((t>>i)&1u){
            fr(j,n) c[j]^=((A[j]>>i)&1u)<<l;
            ++l;
        }
    }
    ll comb[51][51]={};
    fr(i,n+1){
        comb[i][0]=comb[i][i]=1;
        Fr(j,i-1) comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
    }
    vector<ll> K(n+1);
    Fr(i,n) Fr(j,k) K[i]+=comb[i][j];
    ll ans{};
    fr(b,1u<<l){
        ll tmp{};
        map<ll,int> mp;
        fr(i,n) ++mp[c[i]&b];
        for(auto[key,val]:mp) tmp+=K[val];
        if(__builtin_popcount(b)&1u) ans-=tmp;
        else ans+=tmp;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 3684
#include <iostream>
using namespace std;
int main()
{
  int n;
  int a[101] = {};
  for (int i = 0; i < 3; i++)
  {
    cin >> n;
    a[n]++;
  }
  int ans = 0;
  for (int i = 1; i <= 100; i++)
  {
    if (0 < a[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls ch[x][0]
#define rs ch[x][1]
#define ll long long
using namespace std;

inline ll read(){
	ll num=0,neg=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')neg=-1;c=getchar();}
	while(isdigit(c)){num=(num<<3)+(num<<1)+c-'0';c=getchar();}
	return num*neg;
}

int main(){
	printf("%d\n",read()^1) ;
	return 0;
}


Measured memory_bytes: 3760
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e4 + 3;

int n, dp[N];
bool vis[N];
pair<PII, int> a[N];

bool cmp(pair<PII, int> x, pair<PII, int> y) {
  return x.ST.ND-y.ST.ST > y.ST.ND-x.ST.ST;
}

signed main() {
  init_ios();
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i].ST.ST >> a[i].ST.ND >> a[i].ND;
  sort(a+1, a+n+1, cmp);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j+a[i].ST.ST < N; ++j)
      if (vis[j+a[i].ST.ST]) {
        dp[min(j, a[i].ST.ND)] = max(dp[min(j, a[i].ST.ND)], a[i].ND+dp[j+a[i].ST.ST]);
        vis[min(j, a[i].ST.ND)] = true;
      }
    vis[a[i].ST.ND] = true;
    dp[a[i].ST.ND] = max(dp[a[i].ST.ND], a[i].ND);
  }
  int res = 0;
  for (int i = 0; i < N; ++i)
    res = max(res, dp[i]);
  cout<<res<<"\n";
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int f[300];
int main()
{
    int n,i,x,minn=0,maxx=0;
    cin>>n;
    int v[n+1];
    char c[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    for(i=1;i<=n;i++)
    {
        if(v[i]>=1 && v[i]<=399)
            f['g']++;
        if(v[i]>=400 && v[i]<=799)
            f['r']++;
        if(v[i]>=800 && v[i]<=1199)
            f['e']++;
        if(v[i]>=1200 && v[i]<=1599)
            f['c']++;
        if(v[i]>=1600 && v[i]<=1999)
            f['b']++;
        if(v[i]>=2000 && v[i]<=2399)
            f['y']++;
        if(v[i]>=2400 && v[i]<=2799)
            f['o']++;
        if(v[i]>=2800 && v[i]<=3199)
            f['d']++;
        if(v[i]>=3200)
            f['a']++;
    }

    for(i=97;i<=122;i++)
    {
        if((i=='g' || i=='r' || i=='e' || i=='c' || i=='b' || i=='y' || i=='o' || i=='d') && f[i]!=0)
            minn++,maxx++;
        if(i=='a' && f[i]!=0)
            maxx+=f[i];
    }
    if(minn==0) minn=1;
    cout<<minn<<" "<<maxx;
    return 0;
}


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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


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

    ll k, s;
    cin >> k >> s;

    ll c = 0;
    rep(i, k+1){
        rep(j, k+1){
            ll t = s - i - j;
            if(0 <= t && t <= k){
                c++;
            }
        }
    }
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <set>
#include <string>

using namespace std;

int main(void)
{
    int n;
    cin >> n;
    
    set<string> s;
    string temp;
    for(int i = 0; i < n; i ++)
    {
        cin >> temp;
        s.insert(temp);
    }

    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 19256
using namespace std;

//#define fileio

#ifndef fileio
#include <iostream>
#endif
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>

typedef long long ll;

#ifdef fileio
ifstream cin;
ofstream cout;
#endif





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifdef fileio
    cin.open("Text.txt");
    cout.open("Output.txt");
    #endif

    ll n, x, t;
    cin >> n >> x >> t;
    cout << t * (1 + ((n - 1) / x)) << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/29  Problem: 071_arc_b / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL W, H;

LL ans = 0LL;

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

	cin >> W >> H;
	VL x(W);
	FOR(i, 0, W) {
		cin >> x[i];
	}
	VL y(H);
	FOR(i, 0, H) {
		cin >> y[i];
	}

	LL xsum = 0, bef;
	FOR(i, 1, W) {
		(xsum += bef) %= MOD;
		(xsum += (x[i] - x[i - 1])*i % MOD) %= MOD;
		(bef += (x[i] - x[i - 1])*i % MOD) %= MOD;
	}
	bef = 0;
	LL ysum = 0;
	FOR(i, 1, H) {
		(ysum += bef) %= MOD;
		(ysum += (y[i] - y[i - 1])*i % MOD) %= MOD;
		(bef += (y[i] - y[i - 1])*i % MOD) %= MOD;
	}
	ans = (xsum*ysum) % MOD;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size();
const int INF=INT_MAX;
struct edge{ll from,to,length;};
int main(){
  ll l;cin>>l;
  ll copy=l,r=0,n,m;
  while(copy>1){
    copy/=2;r++;
  }
  ll _copy=l;
  l-=pow(2,r);
  n=r+1;m=2*r;
  ll t=r;
  vll tt(0);
  while(l>0){
    if(l>=pow(2,t-1)){
      l-=pow(2,t-1);
      tt.push_back(t);
    }
    t--;
  }
  m+=tt.size();
  vector<edge> g(m);
  rep(i,0,r){
    g[i*2].from=i+1;g[i*2].to=i+2;g[i*2].length=0;
    g[i*2+1].from=i+1;g[i*2+1].to=i+2;g[i*2+1].length=pow(2,i);
  }
  rep(i,0,tt.size()){
    g[2*r+i].from=tt[i];g[2*r+i].to=n;g[2*r+i].length=_copy-pow(2,tt[i]-1);
    _copy-=pow(2,tt[i]-1);
  }
  cout<<n<<" "<<m<<endl;
  rep(i,0,m){
    cout<<g[i].from<<" "<<g[i].to<<" "<<g[i].length<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll M; cin >> M;
  ll d, c;
  ll ans = 0;
  vector<ll> cntd(10, 0);
  rep(i,M){
    cin >> d >> c;
    cntd[d] += c;
  }
  ans += cntd[0]; cntd[0]=0;
  bool flag = true;
  while(flag){
    vector<ll> cnt_(10,0);
    rep(i,10) ans += cntd[i]/2;
    cnt_[2] += cntd[1]/2; cnt_[1] += cntd[1]%2;
    cnt_[4] += cntd[2]/2; cnt_[2] += cntd[2]%2;
    cnt_[6] += cntd[3]/2; cnt_[3] += cntd[3]%2;
    cnt_[8] += cntd[4]/2; cnt_[4] += cntd[4]%2;
    cnt_[1] += cntd[5]/2; cnt_[0] += cntd[5]/2; cnt_[5] += cntd[5]%2;
    cnt_[1] += cntd[6]/2; cnt_[2] += cntd[6]/2; cnt_[6] += cntd[6]%2;
    cnt_[1] += cntd[7]/2; cnt_[4] += cntd[7]/2; cnt_[7] += cntd[7]%2;
    cnt_[1] += cntd[8]/2; cnt_[6] += cntd[8]/2; cnt_[8] += cntd[8]%2;
    cnt_[1] += cntd[9]/2; cnt_[8] += cntd[9]/2; cnt_[9] += cntd[9]%2;
    ans += cnt_[0]; cnt_[0]=0;
    ans += 10*(cnt_[1]/10); cnt_[1] = cnt_[1]/10+cnt_[1]%10;
    cntd = cnt_;
    rep(i,10){
      if(cntd[i] >= 2) break;
      if(i==9) flag = false;
    }
  }
  bool flag2 = true;
  vector<ll> cntt_ = cntd;
  while(flag2){
    rep(x,10){
      rep(y,10){
        if(cntt_[x]>0 && cntt_[y]>0){
          if(x==y && cntt_[x]==1) continue;
          if(x+y>=10) cntt_[1]++;
          cntt_[(x+y)%10]++;
          cntt_[x]--; cntt_[y]--;
          ans++;
        }
      }
    }
    ll s=0;
    rep(i,10) s+=cntt_[i];
    if(s<=1) flag2 = false;
  }
  cout << ans << endl;
  return 0;
}


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

int A[3], B[3], C[4] = { 1, 2, 3, 4 };
bool used[5][5];

int main() {
	for (int i = 0; i < 3; i++) {
		cin >> A[i] >> B[i];
		used[A[i]][B[i]] = true;
		used[B[i]][A[i]] = true;
	}
	do {
		bool flag = true;
		for (int i = 0; i < 3; i++) {
			if (used[C[i]][C[i + 1]] == false) flag = false;
		}
		if (flag == true) {
			cout << "YES" << endl;
			return 0;
		}
	} while (next_permutation(C, C + 4));

	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main() {
    long long int N,M,A,r=0;
    cin >> N >> M;
    priority_queue<int> que;
    for(int i=0; i<N; ++i) {
        cin >> A;
        que.push(A);
    }
    for(int i=0; i<M; ++i) {
        que.push(que.top()/2);
        que.pop();
    }
    while(!que.empty()) {
        r += que.top();
        que.pop();
    }
    cout << r;
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;




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

    string ans;
    while (N != 0){
        ll r = N % 2;
        if (r < 0) r = 1;

        N = (N - r) / (-2);

        ans += (char)('0' + r);
    }

    reverse(ans.begin(), ans.end());
    if (ans == "") ans = "0";

    cout << ans << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,sum;
  sum=1;
  cin >> N >> K;
  for(int i=0;i<N;i++){
  	if(sum>=K){
      sum+=K;
    }else{
      sum+=sum;
    }
  }
  cout << sum << endl;
}

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

bool cmp(const int &a,const int &b){
	return a>b;
}	
int main()
{
int a,b,c;
cin>>a>>b>>c;
vector<int> vec;
for(int i=1;i<=min(a,b);++i)
	if(a%i==0&&b%i==0)vec.push_back(i);
sort(vec.begin(),vec.end(),cmp);
cout<<vec[c-1]<<endl;

return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll X;
  cin >> X;

  ll happy = 0;

  while (X >= 500) {
    X -= 500;
    happy += 1000;
  }
  while (X >= 5) {
    X -= 5;
    happy += 5;
  }

  cout << happy << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   string s;
   cin>>s;
   
   ll cnt = 1;
   char c = s[0];
   
   for(ll i=1;i<n;i++)
   {
       if(c!=s[i])
       {
           cnt++;
           c = s[i];
           continue;
       }
   }
   
   cout<<cnt;
   
   return 0;
}

Measured memory_bytes: 512
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveD();
	}

	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a - b == b - c) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	private void solveB() {
		Scanner sc = new Scanner(System.in);
		String o = sc.nextLine();
		String e = sc.nextLine();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < e.length(); i++) {
			sb.append(o.charAt(i));
			sb.append(e.charAt(i));
		}
		if (o.length() != e.length()) {
			sb.append(o.charAt(o.length() - 1));
		}
		System.out.println(sb.toString());
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		int[] min = new int[26];
		for (int i = 0; i < 26; i++) {
			min[i] = 51;
		}
		for (int i = 0; i < n; i++) {
			int[] tmp = new int[26];
			String buffer = sc.nextLine();
			for (int j = 0; j < buffer.length(); j++) {
				char asc = buffer.charAt(j);
				tmp[(asc - 'a')]++;
			}
			for (int j = 0; j < 26; j++) {
				if (min[j] > tmp[j]) {
					min[j] = tmp[j];
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for (char c = 'a'; c <= 'z'; c++) {
			for (int i = 0; i < min[c - 'a']; i++) {
				sb.append(c);
			}
		}
		System.out.println(sb.toString());
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		BigInteger MOD = BigInteger.valueOf(1000000007);
		int n = sc.nextInt();
		int m = sc.nextInt();
		//BigInteger prev = null;
		BigInteger sum_x = BigInteger.ZERO;
		/*
		for (int i = 0; i < n; i++) {
			BigInteger tmp = BigInteger.valueOf(sc.nextInt());
			if (prev != null) {
				sum_x = sum_x.add(tmp.subtract(prev).multiply(BigInteger.valueOf(i * (n - i))).remainder(MOD));
			}
			prev = tmp;
		}
		*/
		for (int i = 0; i < n; i++) {
			sum_x = sum_x.add(BigInteger.valueOf(sc.nextInt()).multiply(BigInteger.valueOf(2 * i - n + 1)));
		}
		//prev = null;
		BigInteger sum_y = BigInteger.ZERO;
		/*
		for (int i = 0; i < m; i++) {
			BigInteger tmp = BigInteger.valueOf(sc.nextInt());
			if (prev != null) {
				sum_y = sum_y.add(tmp.subtract(prev).multiply(BigInteger.valueOf(i * (m - i))).remainder(MOD));
			}
			prev = tmp;
		}
		*/
		for (int i = 0; i < m; i++) {
			sum_y = sum_y.add(BigInteger.valueOf(sc.nextInt()).multiply(BigInteger.valueOf(2 * i - m + 1)));
		}
		sum_x = sum_x.remainder(MOD);
		sum_y = sum_y.remainder(MOD);
		BigInteger ans = sum_x.multiply(sum_y).remainder(MOD);
		System.out.println(ans);
	}
}

Measured memory_bytes: 91892
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int K, S;
  cin >> K >> S;
  int count = 0;
  for(int i=0;i<K+1;i++)
  {
    for(int j=0;j<K+1;j++)
    {
              if(i+j>=S-K&&i+j<=S)
        {
          count++;
        }
    }
  }
  cout << count << endl;
  return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    int c=1;
    for(int i=0;i<n;i++)
        if(a[i]==c)c++;
    c--;
    if(c==0)n=-1;
    else n=n-c;
    cout << n;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(5e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

ll n, W, v[105], w[105], dp[105][105][500], ans = 0;

int main() {
    cin >> n >> W;
    REP(i,n){
        cin >> w[i] >> v[i];
    }
    REP(i,n){
        REP(j,i+1){
            REP(k,j*3+1){
                dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
                ll c = w[i] - w[0];
                if(w[0]*(j+1)+k+c <= W) dp[i+1][j+1][k+c] = max(dp[i+1][j+1][k+c], dp[i][j][k] + v[i]);
            }
        }
    }
    REP(i,n+1){
        REP(j,500){
            ans = max(ans, dp[n][i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 41216
#include<stdio.h>
int solve(int,int);
int n,A[2000];
int main(){
  int q,mi[2000],i,x,m;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&mi[i]);
  }
  for(i=0; i<q; i++){
    if(solve(0,mi[i]))printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}
int solve(int i,int m){
  int result;
  if(m==0)return 1;
  if(i>=n)return 0;
  result = solve(i+1,m) || solve(i+1,m-A[i]);
  return result;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            long mod = 1000003L;
            long[] fact = new long[(int) mod];
            fact[0] = 1;
            for (int i = 1; i < fact.length; i++) {
                fact[i] = (i * fact[i - 1]) % mod;
            }
            int Q = in.nextInt();
            long[] x = new long[Q];
            long[] d = new long[Q];
            long[] n = new long[Q];
            for (int i = 0; i < Q; i++) {
                x[i] = in.nextInt();
                d[i] = in.nextInt();
                n[i] = in.nextInt();
            }
            for (int i = 0; i < Q; i++) {
                if (d[i] == 0) {
                    long res = modPow(x[i], n[i], mod);
                    System.out.println(res);
                    continue;
                }
                long invD = modInverseByFermatsLittleTheorem(d[i], mod);
                long a = (x[i] * invD) % mod;
                long b = a + n[i] - 1;
                if (0 < a && b < mod) {
                    long dPowN = modPow(d[i], n[i], mod);
                    long fact1 = fact[(int) b];
                    long fact2 = fact[(int) a - 1];
                    long mm = (fact1 * modInverseByFermatsLittleTheorem(fact2, mod)) % mod;
                    System.out.println((dPowN * mm) % mod);
                } else {
                    System.out.println(0);
                }
            }
        }
    }

    public static long modInverseByFermatsLittleTheorem(long x, long modulo) {
        return modPow(x, modulo - 2, modulo);
    }

    public static final long modPow(long x, long n, long modulo) {
        long res = 1L;
        while (n > 0) {
            if ((n & 1L) != 0) {
                res = res * x % modulo;
            }
            x = x * x % modulo;
            n >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 106184
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p,s=[-1]*-~n,[-1]*-~n
for i,(a,b)in enumerate(t):
  x,y=r(a),r(b)
  if(x!=y)*m>i:
    if x>y:x,y=y,x
    p[x]+=p[y]
    p[y]=x
  if(x!=y)*i<m:
    s[a]-=1
    s[b]-=1
for i in range(n+1):s[i]-=p[r(i)]
print(*s[1:])

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


typedef long long ll;

ll ans;
ll N,K;

void solve(ll n, ll now){
  if(now < N){
    solve(n*2, now+1);
    solve(n+K, now+1);
  } else { 
    if(n < ans){
      ans = n;
    }
  }
}

int main(){
  cin >> N;
  cin >> K; 
  ans = 10000000000000;
  solve(1, 0);
  cout << ans << endl;
  
}

Measured memory_bytes: 256
//  ©   ___MRX___

#include <bits/stdc++.h>
    using namespace std;

#define ll long long int

int main()
{
    int n, i;
    bool checker = false;

    cin >> n;

    for(i = 1; i < 10; i++) {
        if(n / i < 10 && n % i == 0) {
            checker = true;
            break;
        }
    }
    checker ? cout << "Yes" <<'\n' : cout << "No" << '\n';

    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

void calc_inverse_matrix(double mat[2][2], double inv_mat[2][2])
{
    double det = mat[0][0]*mat[1][1] - mat[0][1]*mat[1][0];

    inv_mat[0][0] = mat[1][1]/det;
    inv_mat[0][1] = -mat[0][1]/det;
    inv_mat[1][0] = -mat[1][0]/det;
    inv_mat[1][1] = mat[0][0]/det;
}

int read_inputline(double mat[2][2], double vec[2])
{
    return scanf("%lf %lf %lf %lf %lf %lf", 
                         &mat[0][0], &mat[0][1], &vec[0],
                         &mat[1][0], &mat[1][1], &vec[1]);
}

void calc_ans(double mat[2][2], double vec[2], double ans[2])
{
    static double inv_mat[2][2];

    calc_inverse_matrix(mat, inv_mat);

    ans[0] = inv_mat[0][0]*vec[0] + inv_mat[0][1]*vec[1];
    ans[1] = inv_mat[1][0]*vec[0] + inv_mat[1][1]*vec[1];
}

int main(){
    double mat[2][2], vec[2], inv_mat[2][2], ans[2];

    while(read_inputline(mat, vec)!=EOF){
        calc_ans(mat, vec, ans);
        printf("%.3f %.3f\n", ans[0], ans[1]);
    }

    return 0;
}

Measured memory_bytes: 652
#include <cstdio>
using namespace std;

int main()
{
while(true) {
int n;
scanf("%d", &n);
if(n == 0)
break;
int change = 1000 - n;
int ans = 0;
for(int digit = 1; digit < 1000; digit *= 10) {
int cur = change / digit % 10;
ans += (cur / 5) + (cur % 5);
}
printf("%d\n", ans);
}
return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n,k;
  cin>>n>>k;
  vector<int> H;
  rep(i,n){
    int h;
    cin>>h;
    H.push_back(h);
  }
  sort(H.begin(),H.end());
  int MinCost=H[n-1];
  rep(i,n-k+1){
    int cost=H[i+k-1]-H[i];
    MinCost=min(MinCost,cost);
  }
  cout<<MinCost<<endl;
  return 0;
}


Measured memory_bytes: 892
#include <cstdio>
using namespace std;

const int N = 1e6 + 7;
int was[N];

bool good(int x)
{
	for (int i = 1; i * i <= x; ++i)
		if (x % i == 0)
		{
			int ni = x / i;
			if ((i != x && was[i]) || (ni != x && was[ni]))
				return false;
		}
	return true;
}

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

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

	int res = 0;
	for (int i = 1; i < N; ++i)
		if (was[i] == 1)
			if (good(i))
				++res;
	printf("%d", res);

	return 0;
}


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl x(n);
  rep(i, n) cin >> x[i];
  vl sx = x;
  sort(all(sx));
  rep(i, n) cout << (x[i] > sx[n / 2 - 1] ? sx[n / 2 - 1] : sx[n / 2]) << '\n';
}

Measured memory_bytes: 6376
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####

from collections import defaultdict as ddic

def solve(N):
    ans = []
    while True:
        N -= 1
        r = (N) % 26
        N //= 26
        ans.append(chr(r + ord('a')))

        if N == 0: break
    return "".join(ans[::-1])
print solve(rri())


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

using namespace std;

int x;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> x;
    cout << (x >= 30 ? "Yes" : "No") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3608