akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdlib.h>

using namespace std;

int main()
{
	int n,w;
	cin >> n >> w;
	vector <pair <int, int> > all(n);
	for (int i = 0; i < n; i++)
	{
		cin >> all[i].second >> all[i].first;
	}
	//sort(all.begin(), all.end());
	vector < long long > dp(1000 * n + 1, 1e18 + 5);
	dp[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = n * 1000 - all[i].first; j >= 0; --j)
		{
			dp[j + all[i].first] = min(dp[j + all[i].first], dp[j] + all[i].second);
			//cout << dp[i][j] << " ";
		}
	}
	long long ans = 0;
	for (int i = 0; i <= n * 1000; i++)
	{
		if (dp[i] <= w)
			ans = max(ans, (long long) i);
	}
	cout << ans;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace ABC153
{
    class C
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int K = input[1];
            int[] H = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();

            //Console.WriteLine(string.Join(",", H));

            long res = 0;
            for (int i = K; i < N; i++)
            {
                res += H[i];
            }

            Console.WriteLine(res);

        }
    }
}


Measured memory_bytes: 38400
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int x,y,h,w;
	cin>>h>>w;
	int count[h+2][w+2]={};
	char c[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>c[i][j];
			if(c[i][j]=='#'){
				for(y=0;y<3;++y){
					for(x=0;x<3;++x){
						count[i+y][j+x]++;
					}
				}
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(c[i][j]=='#'){
				cout<<c[i][j];
			}else{
				cout<<count[i+1][j+1];
			}
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef double ll;
int main()
{
	int n;cin>>n;
	int a1=0,a2=0,a3=0;
	ll dp[n+1][n+1][n+1];
	for (int i = 0; i < n; ++i)
	{
		ll x;cin>>x;
		if(x==1)a1++;
		if(x==2)a2++;
		if(x==3)a3++;
	}
	dp[0][0][0]=0;
	for (int i = 1; i <= n; ++i)
	{
		dp[i][0][0]=(dp[i-1][0][0]+1)+(ll)((ll)(n-i)/i);
	}
	for (int j = 1; j <= n; ++j){
		for (int i = 0; i < n; ++i){
			if(i>0)dp[i][j][0]=(n-i-j+(dp[i-1][j][0]+1)*(i)+(dp[i+1][j-1][0]+1)*(j))/((ll)(i+j));
			else dp[i][j][0]=(n-j+(dp[i+1][j-1][0]+1)*(j))/((ll)j);
		}
	}
	for (int k = 1; k <= n; ++k){
		for (int j = 0; j < n; ++j){
			for (int i = 0; i < n; ++i){
				if(i>0 && j>0)dp[i][j][k]=(n-i-j-k+(dp[i-1][j][k]+1)*(i)+(dp[i+1][j-1][k]+1)*(j)+(dp[i][j+1][k-1]+1)*(k))/((ll)(i+k+j));
				else if(i>0)dp[i][j][k]=(n-i-k+(dp[i-1][j][k]+1)*(i)+(dp[i][j+1][k-1]+1)*(k))/((ll)(i+k));
				else if(j>0)dp[i][j][k]=(n-j-k+(dp[i+1][j-1][k]+1)*(j)+(dp[i][j+1][k-1]+1)*(k))/((ll)(k+j));
				else dp[i][j][k]=(n-k+(dp[i][j+1][k-1]+1)*(k))/((ll)(k));
			}
		}
	}
	printf("%0.15lf\n",dp[a1][a2][a3]);
}











Measured memory_bytes: 212736
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define vi   vector<int>
#define vvi  vector<vi >
#define vvvi vector<vvi >
#define pii  pair<int,int>
#define INF  (int)1e9
#define MOD  (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	vi b(n),c(n);
	
	REP(i,n) cin>>a[i];
	
	b[0]=-1;
	for(int i=1;i<n;++i){
		b[i]=max(b[i-1],a[i-1]);
	}
	
	c[n-1]=-1;
	for(int i=n-2;i>=0;--i){
		c[i]=max(c[i+1],a[i+1]);
	}
	
	REP(i,n){
		cout<<max(b[i],c[i])<<endl;
	}
}

Measured memory_bytes: 3968
def main():
    N = int(input())
    rate = 380000
    jpy = 0
    bit = 0
    for _ in range(N):
        x, u = input().split()
        if u=='JPY':
            jpy += float(x)
        else:
            bit += float(x)
    print(jpy + bit*rate)
main()

Measured memory_bytes: 38384
package main

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

func main() {
	r := readInt()

	fmt.Println(r * r)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S; cin >> S;
  if (S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  for (char c : S) {
    if (c == 'A' || c == 'C') continue;
    if (isupper(c)) {
      cout << "WA" << endl;
      return 0;
    }
  }

  int cnt = 0;
  for (int i = 2; i < S.size() - 1; ++i) {
    if (S[i] == 'C') ++cnt;
  }

  if (cnt == 1) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 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...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N, M, K, Q;

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

    cin >> N >> K;
    vector<ll> a(N);
    REP(i, N) cin >> a.at(i);

    ll ans = 1e18;
    REP(bit, 1 << N) {
        if (__builtin_popcount(bit) == K) {
            ll now = 0;
            ll sum = 0;
            REP(i, N) {
                int mask = 1 << i;
                if (bit & mask) {
                    if (now < a[i]) {
                        now = a[i];
                    } else {
                        now = now + 1;
                        sum += now - a[i];
                    }
                } else {
                    now = max(now, a[i]);
                }
            }
            chmin(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int N, A, B;
  string S;
  cin >> N >> A >> B >> S;
  int pass = 0;
  int abroad = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'c') cout << "No" << endl;
    else {
      if (pass < A+B) {
        if (S[i] == 'b' && abroad < B) {
          cout << "Yes" << endl;
          pass++;
          abroad++;
        }
        else if (S[i] == 'a') {
          cout << "Yes" << endl;
          pass++;
        }
        else cout << "No" << endl;
      }
      else cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 896
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
double pie=3.14159265358979;
long long mod=1000000007;
//
int main(){
	int n;
	int a[100];
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i%2==0){
			if(a[i]%2==1){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

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

const double pi = 3.14159265358979323846;

// #define fio() cin.tie(0); ios::sync_with_stdio(false);
// template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
// template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define TG0 get< 0 >
#define TG1 get< 1 >
#define TG2 get< 2 >
#define F first
#define S second
#define VL vector< ll >

// to_string(123)
// atoi("123"); atoi(s.c_str());
// "abc".size()
// s.find('+') == string::npos
// 1e18

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

  ll K, N;
  cin >> K >> N;

  ll A[N * 2];
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll m = LLONG_MAX;
  for (ll i = 0; i < N; i++) {
    // cout << i << " " << A[(i + N - 1) % N] + K << " " << A[i] << endl;
    if (i == 0) {
      m = min(m, A[N - 1] - A[i]);
    } else {
      m = min(m, A[(i + N - 1) % N] - A[i] + K);
    }
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std; 
typedef long long int ll; 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int>h(n);
    for(auto &x : h)
    cin>>x;
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0; i<n; i++)
        for(auto j : {i+1,i+2})
            if(j<n)
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
    cout<<dp[n-1];        
    return 0;
}

Measured memory_bytes: 1024
u[],t;main(c){char*x,*y,*z;for(;t=scanf("%s%s%s",x=u,y=u+14,z=u+28)-1;puts(y))for(c=*y++;c-*z&&putchar(c),*z;)c=c==*z?++z,*x++:*y++;}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}
int disum(int n){
	int sum=0;

	while(n){

		sum+=n%10;
		n/=10;





	}
	return sum;




}
int main() {
    int i,n,m,k,c=0,sum=0;
    c_p_c();
    // cout<<"the defufe";
    // cin>>n;
    // int temp = sqrt(n);
    // cout<<temp*temp<<endl;
    cin>>n;

    // watch(disum(n));

    if(n%disum(n)==0) cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3536
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int min(int x, int y)
{
    if (x<=y) return x;
    else return y;
}

int main()
{
    int n, m, x, a[100];
    scanf("%d%d%d", &n, &m, &x);
    int i;
    for (i=0; i<m; i++)
    {
        scanf("%d", &a[i]);
    }
    int left = 0, right = 0;
    for (i=0; i<m; i++)
    {
        if (a[i] < x) left ++;
        else right ++;
    }
    printf("%d\n", min(left, right));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

template <std::uint_fast64_t mod>
class ModInt {
    using u64 = std::uint_fast64_t;

   public:
    u64 x;
    ModInt(const ll x = 0) : x(x < 0 ? (mod - (-x % mod)) % mod : x % mod) {}

    ModInt operator+(const ModInt r) { return ModInt(*this) += r; }
    ModInt operator*(const ModInt r) { return ModInt(*this) *= r; }
    ModInt operator-(const ModInt r) { return ModInt(*this) -= r; }
    ModInt operator/(const ModInt r) { return ModInt(*this) /= r; }
    ModInt operator-() { return ModInt(mod - x); }

    ModInt &operator+=(const ModInt r) {
        x += r.x;
        if (x >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt r) {
        if (x < r.x) x += mod;
        x -= r.x;
        return *this;
    }
    ModInt &operator*=(const ModInt r) {
        x *= r.x;
        if (x >= mod) x %= mod;
        return *this;
    }
    ModInt &operator/=(ModInt r) {
        if (!(x % r.x)) {
            x /= r.x;
            return *this;
        }
        u64 p = mod - 2;
        while (p > 0) {
            if (p & 1) *this *= r;
            r *= r;
            p >>= 1;
        }
        return *this;
    }
    ModInt &operator++(int) { return (*this) += 1; }
    ModInt &operator++() { return (*this) += 1; }
    ModInt &operator--(int) { return (*this) -= 1; }
    ModInt &operator--() { return (*this) -= 1; }

    bool operator<(const ModInt r) { return x < r.x; }
    bool operator>(const ModInt r) { return x > r.x; }
    bool operator<=(const ModInt r) { return x <= r.x; }
    bool operator>=(const ModInt r) { return x >= r.x; }
    bool operator==(const ModInt r) { return x == r.x; }
    bool operator!=(const ModInt r) { return x != r.x; }

    ModInt inv() { return (ModInt)1 / (*this); }
    int get_mod() { return mod; }

    friend std::istream &operator>>(std::istream &in, ModInt &m) {
        ll a;
        in >> a;
        if (a < 0) a = mod - (-a % mod);
        if (a >= mod) a %= mod;
        m.x = a;
        return in;
    }
    friend std::ostream &operator<<(std::ostream &out, const ModInt &m) {
        out << m.x;
        return out;
    }
};
constexpr std::uint_fast64_t mod = 2019;
using mint = ModInt<mod>;

template <typename T, typename U>
T pow(T x, U n, T e = 1) {
    T res = e;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    s += "0";
    reverse(s.begin(), s.end());
    vector<mint> v(s.size(), 0);
    map<int, ll> mp;
    mp[0] = 1;
    for (int i = 1; i < s.size(); i++) {
        v[i] = v[i - 1] + pow<mint, int>(10, i) * (s[i] - '0');
        mp[v[i].x]++;
    }
    ll ans = 0;
    for (int i = 0; i < 2019; i++) ans += mp[i] * (mp[i] - 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5172
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int N;
	cin >> N;
	int currentX = 0;
	int currentY = 0;
	int currentT = 0;
	string result = "Yes";
	for (auto i = 0; i < N; ++i)
	{
		int t, x, y;
		cin >> t >> x >> y;
		auto time = t - currentT;

		auto diff = abs(currentX - x) + abs(currentY - y);
		if (time < diff || (time - diff) % 2 != 0)
		{
			result = "No";
		}

		currentX = x;
		currentY = y;
		currentT = t;
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define pb push_back
#define mpr make_pair
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD
    
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<pair<ll,ll>>v;
    int i=0;
    while(i<s.size())
    {
        int flag=0;
        int cnt=0;
        while(s[i]=='0')
        {
            i++;
            flag=1;
            cnt++;
        
        }
        if(flag==1)
        v.pb({i-cnt,i-1});
        if(flag==0)
        i++;
    }
    v.pb({s.size(),s.size()});
    ll ans=0;
    if(v.size()>k)
    ans=v[k].fr;
    ll co=0;
    ll prev=v[1].se;
    for(int i=k;i<v.size()-1;i++)
    {
        ans=max(ans,v[i+1].fr-1-v[i-k].se);
    }
    if(v.size()<=k)
    cout<<s.size()<<endl;
    else
    cout<<ans<<endl;
}






Measured memory_bytes: 1528
#include<bits/stdc++.h>
#define ll long long
#define ni 500000004
#define N 3010
#define mo 1000000007
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
ll n,a[N],dp[N][N],q,x,y,ansn;
ll po(ll x,ll y){ll z=1;while (y){if (y%2)z=x*z%mo;x=x*x%mo;y/=2;}return z;}
int main(){
	read(n);read(q);
	for (int i=1;i<=n;i++) read(a[i]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)dp[i][j]=(a[i]>a[j]);
	for (int i=1;i<=q;i++){
		read(x);read(y);
		dp[x][y]=dp[y][x]=(dp[x][y]+dp[y][x])*ni%mo;
		for (int j=1;j<=n;j++)
			if (j!=x&&j!=y)dp[j][x]=dp[j][y]=(dp[j][x]+dp[j][y])*ni%mo,dp[x][j]=dp[y][j]=(dp[x][j]+dp[y][j])*ni%mo;
	}
	ll z=po(2,q);
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++)ansn=(ansn+dp[i][j]*z)%mo;
	cout<<ansn<<endl;
	return 0;
}

Measured memory_bytes: 70784
f :: Int -> Int
f n
  |n > 1000 = 2001 - n
  |otherwise = n + 1

getRange :: Int -> [Int]
getRange n
  |n > 2000 = [(n - 2000)..2000]
  |otherwise = [0..n]

solve :: Int -> Int
solve n = sum [(f x) * (f (n - x)) | x <- getRange n]

main = do
  input <- getContents
  mapM_ print $ map solve (map (\n -> read n :: Int) (lines input))

Measured memory_bytes: 4356
# coding: utf-8
a = []

timeloss =[]
for i in range(5):
    a.append(int(input()))
    timeloss.append((10-a[i]) % 10)

count = 0
for i in range(4):
    if timeloss[i + 1]>timeloss[count]:
        count = i + 1
t = sum(a) + sum(timeloss) - timeloss[count]
print(t)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>

int main() {
    double r, x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    r = sqrt(pow(x2 - x1,2) + pow(y2 - y1,2));
    printf("%lf\n",r);

    return 0;
}

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

typedef long long int ll;

#define endl '\n'

ll n;
ll arr[405];
ll dp[405][405];

ll solve(ll i,ll j)
{
    //cout<<i<<" "<<j<<endl;
    if(i>j){
        return 0;
    }
    if(i==j){
        return 0;
    }

    if(i+1==j){
        return arr[i]+arr[j];
    }

    if(dp[i][j]==-1)
    {
        ll val = 1e18;
        ll z = 0;
        for(ll k=i;k<j;k++){
            z+=arr[k];
            val = min(val,solve(i,k)+solve(k+1,j));
            //cout<<k<<" "<<val<<endl;
        }
        z+=arr[j];
        dp[i][j] = val+z;
    }
    //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    return dp[i][j];

}

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

    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }

    cout<<solve(0,n-1)<<endl;




}


Measured memory_bytes: 1536
<?php
fscanf(STDIN, "%d %d", $n, $k);
$inputs = explode(' ', trim(fgets(STDIN)));

$count = 0;
if (count($inputs) > $k) {
    rsort($inputs);
    $tmp = array_slice($inputs, $k);
    #var_dump([$inputs, $tmp, $k]);
    $sum = array_sum($tmp);
    $count = $sum;
}

echo $count;


Measured memory_bytes: 29240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			System.out.println(Math.min(n * a, b));
		}
	}
}


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

//#define int long long

using namespace std;

int d[101][101];
char a[101][101];

int main () {
	int n, m;
	cin >> n >> m;
	int kol = 0;
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			cin >> a[i][j];
			if (a[i][j] == '#') kol ++;
		}
	}
	if (kol != n + m - 1) {	cout << "Impossible"; return 0;}
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			if (a[i + 1][j] == '#' && a[i][j + 1] == '#') {	cout << "Impossible"; return 0;}
		}
	}
	cout << "Possible";
    return 0;           		
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define MOD (LL)1000000007
#define pi acos(-1.0)
#define ULL unsigned long long
#define mem_1(str) memset(str,-1,sizeof(str))
#define mem0(str) memset(str,0,sizeof(str))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define INF 999999999
using namespace std;
string s;
LL num[200000][30];
LL jie[200000]; 
LL q_mod(LL x, LL n, LL m)
{
    LL res = 1;
    while (n > 0)
	{
        if  (n & 1)   
            res = (res * x) % m;
        x = (x * x) % m;
        n >>= 1;     
    }
    return res;
}
int main()
{ios::sync_with_stdio(false);
	 cin.tie(NULL); 
	 cout.tie(NULL);
	 
	jie[0]=1;
	for(int i=1;i<100005;i++)
    {
        jie[i]=(i*jie[i-1])%MOD;
    }
    LL x,y;
    cin>>x>>y;
   if(abs(x-y)>=2)
   {
   	    cout<<"0"<<endl;
   }
   else if(x==y)
   {
   	    LL ans=(jie[x]*jie[y]*2)%MOD;
   	    cout<<ans<<endl;
   }
   else
   {
   	  LL ans=(jie[x]*jie[y])%MOD;
   	    cout<<ans<<endl;
   }
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
using namespace std;

int main(){
    int n, k, a, i;
    int ans;
    cin >> n >> k;
    int v[n];
    for(i = 0; i < n; i++){
        cin >> a;
        v[i] = a;
    }
    
    if((n-1) % (k-1) == 0){
        ans = (n-1) / (k-1);
    }else{
        ans = (n-1) / (k-1) + 1;
    }
    
    cout << ans << endl;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//* Mod int
const int mod = 1000000007;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
typedef vector<vm> vvm;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  VLL a(n);
  rep(i,n){
    cin >> a[i];
  }

  mint ans = 1;
  
  multiset<int> num = {0,0,0};
  rep(i,n){
    if(num.find(a[i]) == num.end()){
      cout << 0 << endl;
      return 0;
    }
    ans *= num.count(a[i]);
    //cout << num.count(a[i]) << endl;
    
    num.erase(num.lower_bound(a[i]));
    num.insert(a[i]+1);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

using UnweightedGraph = vector<vector<int>>;

template <typename G>
struct Strongly_Connected_Components
{
    const G &g;

    UnweightedGraph g1, g2;
    vector<int> comp, order, used;

    Strongly_Connected_Components(G &g) : g(g), g1(g.size()), g2(g.size()), comp(g.size(), -1), used(g.size())
    {
        for (int i = 0; i < g.size(); i++)
        {
            for (auto &e : g[i])
            {
                g1[i].emplace_back((int)e);
                g2[(int)e].emplace_back(i);
            }
        }
    }
    int operator[](int k)
    {
        return comp[k];
    }

    void dfs(int idx)
    {
        if (used[idx])
            return;
        used[idx] = true;
        for (int &to : g1[idx])
            dfs(to);
        order.push_back(idx);
    }

    void rdfs(int idx, int cnt)
    {
        if (comp[idx] != -1)
            return;
        comp[idx] = cnt;
        for (int to : g2[idx])
            rdfs(to, cnt);
    }

    void build(UnweightedGraph &t)
    {
        for (int i = 0; i < g1.size(); i++)
        {
            dfs(i);
        }
        reverse(begin(order), end(order));

        int ptr = 0;
        for (int i : order)
        {
            if (comp[i] == -1)
            {
                rdfs(i, ptr);
                ptr++;
            }
        }

        t.resize(ptr);

        for (int i = 0; i < g.size(); i++)
        {
            for (auto &to : g[i])
            {
                int x = comp[i], y = comp[to];
                if (x == y)
                    continue;

                t[x].push_back(y);
            }
        }
    }
};

int main()
{
    int V, E, Q;
    scanf("%d %d", &V, &E);
    UnweightedGraph g(V), buff;
    for (int i = 0; i < E; i++)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        g[a].emplace_back(b);
    }
    Strongly_Connected_Components<UnweightedGraph> scc(g);
    scc.build(buff);
    scanf("%d", &Q);
    while (Q--)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        puts(scc[a] == scc[b] ? "1" : "0");
    }
}


Measured memory_bytes: 5088
public class Main {
	public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();

		int[] V = new int[N];

		for (int i=0; i < N; i++) {
			V[i] = sc.nextInt();
		}

		int result = 0;
		int tmp = 0;
		for (int i=0; i < N; i++) {
			tmp = V[i] - sc.nextInt();
			if (tmp > 0) {
				result += tmp;
			}
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>

#define INF 100000000

using namespace std;

int main()
{
    string s;
    cin >> s;
    if(s[5] == '0'&&s[6] <= '4')
    {
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def solve():
  n, x, d = nm()
  ans = 0
  if d == 0:
    print(1 if x == 0 else n+1)
    return
  if d < 0:
    d = -d
    x = -x
  g = dict()
  g[0] = [(0, 0)]
  for i in range(1, n+1):
    c, y = divmod(x * i, d)
    # print((c, y))
    f = (c + i*(i-1)//2, c + n*i - i*(i+1)//2)
    if y not in g:
      g[y] = list()
    g[y].append(f)
  for y in g:
    f = sorted(g[y])
    # print(f)
    cx, cy = f[0]
    for nx, ny in f:
      if nx <= cy:
        cx = min(nx, cx)
        cy = max(ny, cy)
      else:
        ans += cy - cx + 1
        cx, cy = nx, ny
    ans += cy - cx + 1
  print(ans)
  return

solve()


Measured memory_bytes: 72260
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    int N,A,B;
    cin >> N >> A >> B;
    int tmp,digit;
    int total = 0;
    for (int i=1; i<N+1; ++i)
    {
        tmp = i;
        digit = 0;
        while(tmp>0){
            digit += tmp%10;
            tmp = tmp/10;
            // cout << digit << tmp << "\n";
        }
        if (digit >= A && digit <= B)
        {
            total += i;
        }
    }

    cout << total << endl;
    return 0;
}

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

int dx[] = {1 , -1 , 0 ,  0};
int dy[] = {0 ,  0 , 1 , -1};
#define ll long long
#define vi vector <int>
#define pi pair< int , int >
#define pl pair< ll , ll >
#define pii pair< pi , int >
#define fr first
#define sc second
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define PI acos(-1)
#define eps 1e-6
#define OO   INT_MAX
#define infin LLONG_MAX
#define mod 1000000007
#define SPEED_UP ios_base::sync_with_stdio(false); cin.tie(NULL);
#define SZ(x) ((int)(sizeof(x)))
#define sz(v) (int)v.size()
#define all(t) t.begin(),t.end()
#define frei freopen("in.in","r",stdin)
#define freo freopen("out.out","w",stdout)
#define SET(x,y)    x|=(1<<y)
#define CLEAR(x,y)  x&= ~(1<<y)
#define TOGGLE(x,y) x^=(1<<y)
#define READ(x,y)   ((bool)((ll)(x&(1<<y)) != 0))
#define I(x) scanf("%d",&x)
#define I2(x,y) scanf("%d%d",&x,&y)
#define I3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define I4(x,y,z,r) scanf("%d%d%d%d",&x,&y,&z,&r)
#define L(x) scanf("%I64d",&x)
#define L2(x,y) scanf("%I64d%I64d",&x,&y)
#define L3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define L4(x,y,z,r) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&r);
#define D4(x,y,z,r) scanf("%lf%lf%lf%lf",&x,&y,&z,&r);
#define MAX (int)1e5+100
int n,k,a[MAX][3];
ll dp[MAX][4];
ll get(int i = 0,int state = 3)
{
    if(i > n)return -1e15;
    if(i == n)return 0;
    if(dp[i][state] + 1)return dp[i][state];
    ll ret = -1e15;
    if(state != 0)ret = max(ret,get(i+1,0) + a[i][0]);
    if(state != 1)ret = max(ret,get(i+1,1) + a[i][1]);
    if(state != 2)ret = max(ret,get(i+1,2) + a[i][2]);
    return dp[i][state] = ret;
}
int main()
{
    memset(dp,-1,SZ(dp));
    scanf("%d",&n);
    FOR(i,0,n)scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
    printf("%I64d\n",get());
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	for(int i=1;i<s.size();i++)
	{
		if(s[i]==s[i-1])
		{
			cout<<"no"<<endl;
			return 0;
		}
	}
	cout<<"yes"<<endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<double> a(n);
  rep(i, n) cin >> a.at(i);
  double sum = 0;
  rep(i, n) sum+= 1/a.at(i);
  cout << setprecision(10) << 1/sum << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int []arr=new int[n];
		for(int i=0; i<n; i++) {
			arr[i]=scn.nextInt();
		}
		Arrays.sort(arr);
		int count=0;
		for(int i=0;i<n;i++) {
			for(int j=n-1;j>i+1;j--) {
				int idx=binarySearch(i+1,j-1,arr,i,j);
				if(idx!=-1) {
					count+=j-idx;
				}
				//System.out.println(j+" idx   "+idx);
			}
			//System.out.println(count);
		}
		System.out.println(count);
		
	}
	public static int binarySearch(int i, int j, int []arr, int left , int right) {
		if(i==j ) {
			//System.out.println(i+" "+j+" "+left+" "+right);
			if(arr[left]+arr[i]>arr[right]) {
				//System.out.println("ppp");
				return i;

			}
			else {
				return -1;
			}
		}
		//System.out.println(i+" "+j+" "+left+" "+right);
		int mid=(i+j)/2,x=0;
		if(arr[left]+arr[mid]>arr[right]) {
			if(i>mid-1)
				return mid;
			return ((x=binarySearch(i,mid-1,arr,left,right))==-1)?mid:x;
		}else {
			return binarySearch(mid+1,j,arr,left,right);
		}
	}
}


Measured memory_bytes: 28000
n=int(input())
a=[]
b=[]
for i in range(1,n+1):
    if i%2==1:
        for j in range(1,i+1):
            if i%j==0:
                a.append(j)
        if len(a)==8:
            b.append(i)
            a.clear()
        else:
            a.clear()
print(len(b))

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	char s;
	cin >> s;
	if (isupper(s)) {
		cout << "A" << endl;
	} else {
		cout << "a" << endl;
	}
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    vector<ll> v(3,0);
    string s;cin>>s;

    rep(i,siz(s)){
        v.at(s[i]-'a')++;
    }
    sort(all(v));

    if(v[2]-1<=v[1] && v[2]-1<=v[0]){
        puts("YES");
    }else{
        puts("NO");
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int h, w; cin >> h >> w;
	REP(i, h)
	{
		string s; cin >> s;
		cout << s << endl << s << endl;
	}
	return 0;
}

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

int main() {
    int m, M, k;
    cin >> m >> M >> k;
    
    for(int i = m; i <= min(M, m+k-1); i++) cout << i << endl;
    for(int i = max(M-k+1, m+k); i <= M; i++) cout << i << endl;

  	return 0;
}


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

const int INF = (int)(1 << 30);

enum OP
{
  ADD,
  DEL,
};

ostream& operator<<(ostream& os, const tuple<int, int, OP>& tpl){
  int t, x;
  OP op;
  tie(t, x, op) = tpl;
  os << t << " " << op << " " << x;
  return os;
}

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  vector<int> S(N), T(N), X(N);
  vector<int> D(Q);
  for(int i = 0; i < N; i++){
    cin >> S[i] >> T[i] >> X[i];
  }
  for(int i = 0; i < Q; i++){
    cin >> D[i];
  }

  // vector<tuple<int, OP, int>> ev(N*2+Q);
  vector<tuple<int, int, OP>> ev;
  for(int i = 0; i < N; i++){
    ev.push_back(make_tuple(S[i] - X[i], X[i], ADD));
    ev.push_back(make_tuple(T[i] - X[i], X[i], DEL));
  }
  for(int i = 0; i < Q; i++){
    ev.push_back(make_tuple(D[i], INF, ADD));
  }

  sort(ev.begin(), ev.end());
  
#ifdef EBUG
  for(int i = 0; i < (int)ev.size(); i++){
        cout << ev[i] << endl;
  }
#endif

  int idx = 0;
  set<int> que = {INF};
  vector<int> ans(Q);
  for(int i = 0; i < (int)ev.size(); i++){
    const auto& e = ev[i];
    int t, x;
    OP op;
    tie(t, x, op) = e;

    if(x == INF){
      ans[idx] = *que.begin();
      if(ans[idx] == INF) ans[idx] = -1;
      idx++;
    }else{
      if(que.count(x)) que.erase(x);
      else que.insert(x);
      // if(op == ADD) que.insert(x);
      // else que.erase(x);
    }
  }
  for(const auto& a: ans){
    cout << a << endl;
  }
}


Measured memory_bytes: 23016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int a[100010];
int main(void){
	int n; cin >> n;
	rep(i, n){
		cin >> a[i];
	}
	int ki = 0, gu = 0;
	rep(i, n){
		if(a[i] % 2 == 0){
			gu++;
		}else{
			ki++;
		}
	}
	if(gu % 2 == 0 && ki % 2 == 0){
		printf("YES\n");
	}else if(gu % 2 == 0 && ki % 2 == 1){
		printf("NO\n");
	}else if(gu % 2 == 1 && ki % 2 == 0){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 640
import sys, collections, bisect, itertools, heapq, math, copy
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = LI()
    A = LI()
    Q = I()
    BC = [LI() for _ in range(Q)]

    cnt = collections.Counter(A)
    S = sum([k*v for k, v in cnt.items()])

    for i in BC:
        B = i[0]
        C = i[1]
        if B in cnt:
            B_num = cnt[B]
            if C in cnt.keys():
                cnt[C] += B_num
            else:
                cnt[C] = B_num
            S += (C - B) * B_num
            cnt.pop(B)
        print(S)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 36316
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

typedef long long i64;
int A[15], N;

int main() {
  scanf("%d", &N);
  i64 odd = 1, even = 0;
  
  for (int i = 1, X; i <= N; ++i) {
    scanf("%d", &X);
    even = even * 3;
    if (X & 1) {
      even += odd * 2;
      odd = odd;
    } else {
      even += odd;
      odd = odd * 2;
    }
  }

  printf("%lld\n", even);
  
  return 0;
}


Measured memory_bytes: 128
use proconio::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize, K: usize,
    }
    let mut v = vec![0; N];
    for _ in 0..K {
        input! {
            d: usize,
            A: [usize; d],
        }
        for i in A.iter() {
            v[i - 1] = 1;
        }
    }
    let ans = v.iter().filter(|&&x| x == 0).count();
    println!("{}", ans);
}


Measured memory_bytes: 2180
read N
read W

sum=$(echo $W | tr ' ' '\n' | awk '{sum+=$1} END {print sum}')

acc=0
ans=1000000

for i in $(seq 1 $N)
do
    acc=$(($acc+$(echo $W | cut -d ' ' -f $i)))
    rest=$(($sum-$acc))
    if [ $acc -gt $rest ]; then
        V=$(($acc-$rest))
    else
        V=$(($rest-$acc))
    fi
    if [ $V -lt $ans ]; then
        ans=$V
    fi
done

echo $ans

Measured memory_bytes: 1036
n=gets.to_i
l=[]
n.times do
  l << []
end
(n-1).times do
  a,b=gets.split.map(&:to_i)
  l[a-1] << b-1
  l[b-1] << a-1
end
c=gets.split.map(&:to_i).sort.reverse
s=[0]
v=[nil]*n
v[0]=c[0]
i=1
while s!=[]
  z=[]
  s.each do |ss|
    l[ss].each do |lss|
      if !v[lss]
        v[lss]=c[i]
        i+=1
        z << lss
      end
    end
  end
  s=z.dup
end
puts c[1,n-1].sum
puts v.join(" ")


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

    double prob = 1.0/N * (N - min(N, K-1));
    for(int i=1; i<=min(N, K-1); i++) {
        auto n = ceil(log2(K/i));
        prob += 1.0/N * pow(1.0/2, n);
    }
    printf("%.16f\n", prob);
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll H,W,N; cin>>H>>W>>N;
  vector<ll> a(N); rep(i,N) cin>>a[i];
  
  vector<vector<ll>> vec(H,vector<ll>(W));
  ll i=0;
  rep(j,N){
    rep(k,a[j]){
      ll h=i/(2*W)*2,w=i%(2*W); if(w>=W) {w=(2*W-1)-w; h++;}
      vec[h][w]=j+1;
      i++;
    }
  }
  
  rep(i,H){
    rep(j,W){
      if(j!=0) cout<<" ";
      cout<<vec[i][j];
    }
    cout<<'\n';
  }
  
  return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>

int main(int argc, char const *argv[])
{
  int n,a;
  scanf("%d", &n);
  scanf("%d", &a);

  while(n >= 500){
    n -= 500;
  }
  if(n <= a)	puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 128