akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len;
    cin >> len;
    vector<int> arr(len);
    map<int, long long> freq;
    for(int i = 0; i < len; i++) {
        cin >> arr[i];
        freq[arr[i]] += 1;
    }
    long long all = 0;
    set<int> s;
    for(int i = 0; i < len; i++) {
        if(!s.count(arr[i])) {
            s.insert(arr[i]);
            all += (freq[arr[i]] * (freq[arr[i]] - 1)) / 2;
        }
    }
    for(int i = 0; i < len; i++) {
        cout << all - ((freq[arr[i]] * (freq[arr[i]] - 1)) / 2) + ((freq[arr[i]] - 1) * (freq[arr[i]] - 2)) / 2 << " ";
    }
}

Measured memory_bytes: 17984
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

map<ll, ll> m;
int main() {
	ll n; cin >> n;
	repe(i, 1, n) {
		ll a; cin >> a;
		m[a] = i;
	}

	for (map<ll, ll>::iterator it = m.begin(); it != m.end(); it++) {
		if (it != m.begin()) {
			cout << " " << it->second;
		}
		else {
			cout << it->second;
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 7040
n = int(input())
l = list(map(int, input().split()))
a = [0] + l + [0]
s = 0
x = 0
for i in range(n + 2):
    s += abs(x - a[i])
    x = a[i]

for i in range(1, n + 1):
    t = s + abs(a[i + 1] - a[i - 1])
    t = t - abs(a[i] - a[i - 1])
    t = t - abs(a[i + 1] - a[i])
    print(t)


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

int main(){
	int length_string, index_cursor=0, num_ABC=0;
	string input_string;
	
	cin >> length_string >> input_string;
	
	while(index_cursor<length_string-2){
		if(input_string.substr(index_cursor,1)=="A"){
			if(input_string.substr(index_cursor+1,1)=="B"){
				if(input_string.substr(index_cursor+2,1)=="C"){
					num_ABC++;
					index_cursor+=3;
				}else{
					index_cursor+=2;
				}
			}else{
				index_cursor++;
			}
		}else{
			index_cursor++;
		}
	}
	
	cout << num_ABC << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}
ll dpc[10000][10000];
ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else {return dpc[n][r]=combination(n - 1, r - 1)  + combination(n - 1, r);}}


ll nCr(ll n, ll r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}

bool chsK(string s) {
	int n = s.length();
	if (n % 2 == 0) {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i-1])return false;
		}
	}
	else {
		for (int i = 0;i <= n / 2;i++) {
			if (s[i] != s[n - i-1])return false;
		}
	}
	return true;
}

int main() {

	int k;
	int n;
	cin >>k>> n;

	vector<int>a(n);
	vector<int>b(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		if (i == n - 1)b[0] = a[0] - a[n - 1] + k;
		else b[i] = a[i + 1] - a[i];
	}
	sort(b.begin(), b.end());
	cout << k - b[n - 1] << endl;
	return 0;
}

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

int a,b,c,d,e;

int main() {
	cin>>a>>b>>c;
	int ki=0,ka=0;
	for(int i=0;i<b;i++) {
		cin>>d;
		if(d<c)ki++;
		else ka++;
	}
	cout<<min(ki,ka)<<"\n";
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int left = 0; int right = n-1;
    while(left < n-1){
        if(a[left] == left+1){
            int tmp = a[left];
            a[left] = a[left+1];
            a[left+1] = tmp;
            ans++;
        }
        if(a[right] == right+1){
            int tmp = a[right];
            a[right] = a[right-1];
            a[right-1] = tmp;
            ans++;
        }
        left++; right--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>

using namespace std;

#define ll long long

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

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

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

#define For(i, n) for(int i = 0; i < n; i++)

template<typename T> void input(T *data, int n){
	For(i, n){
		cin >> data[i];
	}
}

template<typename T> void input(vector<T> &vec, int n){
	T temp;
	For(i, n){
		cin >> temp;
		vec.push_back(temp);
	}
}

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

struct Vec{
	int x, y;
	Vec():
	x(0), y(0){}
	Vec(int _x, int _y):
	x(_x), y(_y){}
};

template<typename T> void print(T *x, int n){
	For(i, n){
		cout << x[i] << " ";
	}
	cout << endl;
}

template<typename T> void print(vector<T> &x){
	For(i, (int)x.size()){
		cout << x[i] << " ";
	}
	cout << endl;
}

int gcd(int n, int m){
	if(n % m == 0){
		return m;
	}
	else{
		return gcd(m, n % m);
	}
}

unsigned ll func(unsigned ll n, unsigned ll i){

	n++;
	if(n >> i == 0){
		return 0;
	}
	unsigned ll num_one = (n / (2 << i)) * (1 << i);

	if((n % (2 << i)) != 0 && (n % (2 << i)) - (1 << i) > 0){
		num_one += (n % (2 << i)) - (1 << i);
	}

	return num_one;

}

int main(){

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

	if(a * c > b){
		out(b / a);
	}
	else{
		out(c);
	}

	return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int a[N];
int b[N];
int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
        b[a[i]]++;
    }
    bool flag=true;
    if(n&1){
        if(b[0]!=1) flag=false;
        for(int i=2;i<=n-1;i+=2){
            if(b[i]!=2) flag=false;
        }
    }else{
        for(int i=1;i<=n-1;i+=2)
            if(b[i]!=2) flag=false;
    }
    ll res=1;
    for(int i=1;i<=n/2;i++)
        res=(res%mod)*2%mod;
    if(!flag) cout<<0<<endl;
    else cout<<res<<endl;
    return 0;
}

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

#ifdef LOCAL_PC
	#define debug(args...) { cout.flush(); fflush(stdout); fprintf(stderr, args); }
#else
	#define debug(args...) ; /*  */
#endif
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class Ty> Ty rnd(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }

template<class num> inline void rd(num &x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar()))
		x = (x << 3) + (x << 1) + c - '0';
	if (neg) x = -x;
} template <class T, class... Args> inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int main() {
	//ios::sync_with_stdio(false); cin.tie(NULL);
	ll a, b, c, k; rd(a, b, c, k);
	
	auto go = [](ll& k, ll a) {
		ll q = min(k, a);
		k -= q;
		return q;
	};

	ll x1 = go(k, a);
	ll x2 = go(k, b);
	ll x3 = go(k, c);

	cout << x1 - x3 << '\n';

}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    /** 週利 */
    private static final double INTEREST_WEEK = 0.05;

    /** 繰り上げ単位 */
    private static final int ROUND_UP_UNIT = 1000;

    /** 元金 */
    private static final int PRINCIPAL = 100000;

    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(System.in));
        int intInputWeek = Integer.parseInt(bufferedReader.readLine());

        // 借金計算
        double totalDebt = calcDebt(PRINCIPAL, intInputWeek);
        System.out.println((int) totalDebt);
    }

    /**
     * 借金計算メソッド（週利0.05%）
     * @param debt 現在の借金
     * @param week 現在の残り週
     * @return 借金額
     */
    private static double calcDebt(double debt, int week) {
        if (week == 0) {
            return debt;
        }
        debt *= 1 + INTEREST_WEEK;

        // 1000円未満は切り上げる
        double debtPlus = debt / ROUND_UP_UNIT - (int) (debt / ROUND_UP_UNIT);
        if (debtPlus > 0)
            debt = debt + ROUND_UP_UNIT - debtPlus * ROUND_UP_UNIT;

        return calcDebt(debt, --week);
    }

}

Measured memory_bytes: 15012
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 10000

void countSort(short *,short *,int);
 
int main(){

  unsigned short *A, *B;
  int i,n;
 
  scanf("%d",&n);
   
  A = malloc(sizeof(int) * n + 1);
  B = malloc(sizeof(int) * n + 1);
 
  for(i = 1;i <= n;i ++)scanf("%hd",&A[i]);
   
  countSort(A,B,n);
 
  for(i = 1;i < n;i ++)
    {
    printf("%hd ",B[i]);
    }
  
  printf("%hd\n",B[n]);
  
  free(A);
  free(B);
  
  return 0;
}
     
void countSort(short *A,short *B,int n){

  int i,j;
  int C[MAX+1];
 
  for(i = 0;i <= MAX;i ++)
    {
      C[i] = 0;
    }
  
  for(j = 1;j <= n;j ++)
    {
      C[A[j]]++;
    }
  
  for(i = 1;i <= MAX;i ++)
    {
	C[i] = C[i] + C[i-1];
    }
  
  for(j = n;j >= 1;j --)
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }
}

   
  

Measured memory_bytes: 11176
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int ans[202020];
void no()
{
	printf("No\n");
	exit(0);
}
int zzz[202020];
int ai[202020];
int dd[202020];
void check(int num, string s)
{
	fill(zzz, zzz + num * 2, -1);
	for (int i = 0; i < num * 2; i++)
	{
		if (zzz[ans[i]] == -1)zzz[ans[i]] = i;
		else ai[i] = zzz[ans[i]], ai[zzz[ans[i]]] = i;
	}
	int now = 0;
	for (;;)
	{
		if (now == num * 2)break;
		now = ai[now];
		dd[now] = 1;
		now++;
	}
	for (int i = 1; i < s.size() - 1; i++)if ((s[i] == '0') != (dd[i - 1] == 0))abort();
}
typedef pair<int, int>pii;
int main()
{
	int num;
	scanf("%d", &num);
	string s;
	cin >> s;
	s = "1" + s + "1";
	vector<int>v;
	for (int i = 0; i < num * 2; i++)if (s[i] == '1'&&s[i + 1] == '1')v.push_back(i);
	if (v.size() % 2 == 1)no();
	if (v.size() % 4 == 0)
	{
		int pt = 0;
		for (int i = 0; i < v.size() / 2; i++)ans[v[i]] = ans[v[i + v.size() / 2]] = pt++;
		vector<int>a, b, c;
		for (int i = 0; i < num * 2; i++)
		{
			if (s[i] == '1'&&s[i + 1] == '0')a.push_back(i);
			if (s[i] == '0'&&s[i + 1] == '1')b.push_back(i);
			if (s[i] == '0'&&s[i + 1] == '0')c.push_back(i);
		}
		for (int i = 0; i < a.size(); i++)ans[a[i]] = ans[b[i]] = pt++;
		for (int i = 0; i < c.size() / 2; i++)ans[c[i * 2]] = ans[c[i * 2 + 1]] = pt++;
		check(num, s);
		printf("Yes\n");
		for (int i = 0; i < num * 2; i++)printf("%d ", ans[i] + 1);
		printf("\n");
	}
	else
	{
		int pt = 0;
		for (int i = 0; i < v.size() / 2; i++)ans[v[i]] = ans[v[i + v.size() / 2]] = pt++;
		vector<int>a, b, c;
		for (int i = 0; i < num * 2; i++)
		{
			if (s[i] == '1'&&s[i + 1] == '0')a.push_back(i);
			if (s[i] == '0'&&s[i + 1] == '1')b.push_back(i);
			if (s[i] == '0'&&s[i + 1] == '0')c.push_back(i);
		}
		for (int i = 0; i < a.size(); i++)ans[a[i]] = ans[b[i]] = pt++;
		for (int i = 0; i < c.size() / 2; i++)ans[c[i * 2]] = ans[c[i * 2 + 1]] = pt++;



		int now = 0, mode = -1;
		int lb = s.size() - 1, ub = s.size() - 1;
		for (int i = 0; i < s.size(); i++)
		{
			if (s[i] == '1')now++;
			else
			{
				if (mode == -1)mode = 0;
				else if (now % 2 == 0 && now > 0)
				{
					lb = i - now, ub = i;
					break;
				}
				now = 0;
			}
		}
		if (ub == s.size() - 1)
		{
			now = 0, mode = -1;
			vector<pii>zz;
			for (int i = 0; i <= num * 4; i++)
			{
				if (s[i % (num * 2)] == '1')now++;
				else
				{
					if (mode == -1)mode = 0;
					else if (now > 2)
					{
						zz.push_back(make_pair(i - now, i));
					}
					now = 0;
				}
			}
			if (zz.size() <= 2)no();
			swap(ans[zz[0].second - 2], ans[zz[1].first%(num*2)]);
			lb = zz[1].first, ub = zz[1].second % (num * 2);
		}
		int t;
		for (int i = 0; i < num * 2; i++)if (ub - 1 != i&&ans[ub - 1] == ans[i])t = i;
		swap(ans[lb - 1], ans[t]);
		check(num, s);
		printf("Yes\n");
		for (int i = 0; i < num * 2; i++)printf("%d ", ans[i] + 1);
		printf("\n");
	}
}

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

#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007

int main(){
	fast;
	ll x,k,d,ans;
	cin>>x>>k>>d;
	x=abs(x);
	ll minR,minL,stepI;
	stepI=x/d;
	
	if(x%d==0)
	{
		ll step=x/d;
		ll rem=k-step;
		if(rem>0)
		{
			if(!(rem%2))
			{
				cout<<0;
				return 0;
			}
			else
			{
				cout<<d;
				return 0;
			}
		}	
		else
		{
			cout<<x - k*d;
			return 0;
		}
	}
	if(stepI<k)
	{
		minR=x - stepI*d;
		minL=minR-d;
		ll rem=k - stepI;
		if(rem%2)
			ans=minL;
		else
			ans=minR;
	}
	else
	{
		minR=x - k*d;
		ans=minR;
	}
	cout<<abs(ans);
	return 0;
}



Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <stdio.h>
using namespace std;
using ll =long long;

ll gcd(ll a, ll b){
  if (b==0) return a;
  else gcd(b,a%b);
}

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


int main (void) {
  int N;
  cin >> N;
  ll T[N];
  ll ans=0;
  for (int i=0; i<N; i++) {
    cin >> T[i];
    if (i==0){
      ans=T[i];
      continue;
    }
    else{
      ans=lcm(ans,T[i]);
    }
  }
  cout << ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; string S; cin>>N>>S;
	// cout<<S<<"\n";//

	long long ans = 0;

	rp(i,0,1000){
		char c1 = i/100 +'0';
		char c2 = (i/10)%10 +'0';
		char c3 = i%10 +'0';
		// cout<<c1<<""<<c2<<""<<c3<<"\n";

		int ix = 0;
		while(ix<N && S[ix]!=c1){
			ix++;
		}
		if(ix==N) continue;

		ix++;
		while(ix<N && S[ix]!=c2){
			ix++;
		}
		if(ix==N) continue;

		ix++;
		while(ix<N && S[ix]!=c3){
			ix++;
		}
		if(ix==N) continue;
		ans++;
	}

	cout<< ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int 	long long int
#define pii 	pair<int,int>
#define vi 		vector<int>
#define vii		vector<pii>
#define mii 	map<int,int>
#define pb 		push_back
#define mp 		make_pair
#define ff 		first
#define ss 		second
#define MOD 	1000000007

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

	int N,W,i;
	cin>>N>>W;
	int maxVal=N*1000;
	int w[N],v[N];
	for(i=0;i<N;i++)
	{
		cin>>w[i]>>v[i];
	}

	int dp[N][maxVal+1]; //sum of min possible weights for exact value 'v'
	for(int val=0;val<=maxVal;val++)
		dp[0][val]=INT_MAX;

	dp[0][v[0]]=w[0];
	dp[0][0]=0;
	for(i=1;i<N;i++)
	{
		for(int val=0;val<=maxVal;val++)
		{
			dp[i][val]=dp[i-1][val];
			if(val-v[i]>=0)
				dp[i][val]=min(dp[i][val],w[i]+dp[i-1][val-v[i]]);
		}
	}

	int ans=INT_MIN;
	for(int val=0;val<=maxVal;val++)
	{
		if(dp[N-1][val]<=W)
			ans=(val);
	}

	cout<<ans;
    return 0;
}

Measured memory_bytes: 78336
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
using namespace std;

constexpr int intMax = (1 << 30) - 1 + (1 << 30);
constexpr int intHalf = intMax / 2; // > 10^9

int main()
{
	int n, w;
	cin >> n >> w;
	vector<array<int, 2>> wvls(n);
	for (auto& wv : wvls)cin >> wv[0] >> wv[1];
	vector<vector<unsigned long long>> dp_max(n + 1, vector<unsigned long long>(w + 1, 0ULL));
	
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= w; ++j) {
			dp_max[i][j] = max(
				j - wvls[i - 1][0] >= 0 ? dp_max[i - 1][j - wvls[i - 1][0]] + wvls[i - 1][1] : 0, // choose (if able)
				dp_max[i - 1][j]); // don't choose
		}
	}

	cout << dp_max[n][w] << endl;
	return 0;
}

Measured memory_bytes: 80256
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
		int N = input[0];
		int K = input[1];
		List<int> H = new List<int>();
        for(var i = 0; i < N; i++)
		{
			int h = int.Parse(Console.ReadLine());
			H.Add(h);
		}

		List<int> dif = new List<int>();
		H.Sort();

        for(var i = 0; i < N; i++)
		{
			if (i + K - 1 > H.Count - 1) { break; }
			dif.Add(H[i + K - 1] - H[i]);
		}
		dif.Sort();
		Console.WriteLine(dif[0]);
	}
}


Measured memory_bytes: 18780
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;
#define sq(x) ((x)*(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
	int n, k;
	while(cin >> n >> k, n|k){
		queue<int> q;
		int sum = 0;
		int ans = -1e10;
		rep(i, n){
			int a;
			cin >> a;
			sum += a;
			q.push(a);
			if(q.size() >= k){
				ans = max(ans, sum);
				sum -= q.front();
				q.pop();
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1348
#include <stdio.h>
#include <string.h>

#define M 1010579 /* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M;/* your task */; }
int h2(int key){ return 1 + key % (M - 1);/* your task */; }

int find(char str[]){

  /* your task */
  int key, i = 0;
  key = getKey(str);
  while(H[(h1(key)+i*h2(key))%M][0] != '\0'){
    if(strcmp(H[(h1(key)+i*h2(key))%M],str) == 0) return 1;
    else if(strcmp(H[(h1(key)+i*h2(key))%M],str) != 0) i++; }
  return 0;
}

int insert(char str[]){

  /* your task */
  int key, i = 0;
  
  key = getKey(str);
  while(1){
    if(H[(h1(key)+i*h2(key))%M][0] == '\0'){
      strcpy(H[(h1(key)+i*h2(key))%M],str);
      return 0; }
    else if(strcmp(H[(h1(key)+i*h2(key))%M],str) == 0) return 0;
    else i++; }
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }

  return 0;
}



Measured memory_bytes: 15604
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
result = 0
for i in range(n):
    if b[i] <= a[i]:
        result += b[i]
    else:
        result += a[i]
        if (b[i]-a[i]) <= a[i+1]:
            result += b[i] - a[i]
            a[i+1] -= b[i] - a[i]
        else:
            result += a[i+1]
            a[i+1] = 0
print(result)

Measured memory_bytes: 18476
n = int(input())
s = input()
result = []
w_list = []
e_list = []
w_1 = 0
e_1 = 0
for i in range(n):
  if s[i] == "W":
    w_1 += 1
    w_list.append(w_1)
    e_list.append(e_1)
  if s[i] == "E":
    e_1 += 1
    w_list.append(w_1)
    e_list.append(e_1)
  
for i in range(n):
  if i == 0:
    ans = e_list[-1] - e_list[0]
    result.append(ans)
  if i == n-1:
    ans = w_list[n-2]
    result.append(ans)
  else:
    ans_e = w_list[i-1]
    ans_w = e_list[-1] - e_list[i]
    result.append(ans_e + ans_w)
    
print(min(result))
    

Measured memory_bytes: 29860
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		List<AB> ab = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			ab.add(new AB(s.nextInt(), s.nextInt()));
		}

		ab.sort((obja, objb) -> obja.b - objb.b);
		System.out.println((calc(ab) ? "Yes" : "No"));
	}

	public static boolean calc(List<AB> rests) {
		int time = 0;
		for (AB e : rests) {
			time += e.a;
			if (time > e.b) {
				return false;
			}
		}
		return true;
	}

	static class AB {
		final private int a;
		final private int b;

		public AB(int ina, int inb) {
			this.a = ina;
			this.b = inb;
		}
	}
}


Measured memory_bytes: 99180
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for(;;){
			//入力
			int e = Integer.parseInt(br.readLine());
			if(e==0) break;
			
			//mの値を探す
			double m=e;
			for(int z=0; ; z++){
				double z3 = Math.pow(z, 3);
				if(z3 > e)break;
				for(int y=0; ; y++){
					double x = e -(z3 +Math.pow(y, 2));
					if(x<0) break;
					double l = x+y+z;
					if(m>l) m = l;
				}
			}
			System.out.println((int)m);
		}
		
		br.close();
	}

}



Measured memory_bytes: 28728
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, ans = 1;
    string S;
    cin >> N >> S;
    vector<int64_t> A(26);
    for (int i = 0; i < N; i++) {
        A.at(S.at(i) - 'a')++;
    }

    for (int i = 0; i < 26; i++) {
        ans = ans * (A.at(i) + 1) % 1000000007;
    }
    cout << ans - 1 << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int ans = -50, t = 1e5;
    for(int i = 0; i < 3; i++){
        int a;
        cin >> a;
        t = min(t, a);
    }
    ans += t;
    t = 1e5;
    for(int i = 0; i < 2; i++){
        int a;
        cin >> a;
        t = min(t, a);
    }
    ans += t;
    cout << ans << endl;
}



Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int a[114514];
int gcdd[114514];
signed main(){
	ic(n) 
	rep(0,i,n)cin>>a[i];
	if(n==1){
		c(abs(0+a[0]))
		return 0;
	}	
	gcdd[0]=gcd(a[0],a[1]);
	rep(1,i,n-1)gcdd[i]=gcd(gcdd[i-1],a[i+1]);
	c(abs(0+gcdd[n-2]))
}	
	


Measured memory_bytes: 1024
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bits (testBit)
import Data.List (transpose, mapAccumL)

main :: IO ()
main = do
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    fromIntToBools :: Int -> [Bool]
    fromIntToBools = flip map is . testBit
      where
        is = [39, 38..0] :: [Int]
    k' = fromIntToBools k :: [Bool]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    as' = transpose . map fromIntToBools $ as :: [[Bool]]
    maxF = snd . mapAccumL step (Just k') . map count $ as' :: [Int]
      where
        step :: Maybe [Bool] -> (Int, Int) -> (Maybe [Bool], Int)
        step (Just (False : bs')) (ct, _)              = (Just bs', ct)
        step (Just (_ : bs'))     (ct, cf) | ct < cf   = (Just bs', cf)
                                           | otherwise = (Nothing, ct)
        step Nothing              (ct, cf)             = (Nothing, max ct cf)
  print . fromDigitsToInt $ maxF

fromDigitsToInt :: [Int] -> Int
fromDigitsToInt = foldl step 0
  where
    step :: Int -> Int -> Int
    step ds d = 2 * ds + d
{-# INLINE fromDigitsToInt #-}

count :: [Bool] -> (Int, Int)
count = foldl step (0, 0)
  where
    step (ct, cf) b | b         = (succ ct, cf)
                    | otherwise = (ct, succ cf)
{-# INLINE count #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 44412
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define m0(x) memset(x,0,sizeof(x))
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

map<ll, ll> primeFactors(ll n)
{
    map<ll, ll> ret;
    while (n % 2 == 0)
    {
        if( ret.find(2) != ret.end() ) {
            ret[2]++;
        }
        else
        {
            ret[2] = 1;
        }
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            if( ret.find(i) != ret.end() ) {
            ret[i]++;
        }
        else
        {
            ret[i] = 1;
        }
            n = n / i;
        }
    }
    if (n > 2)
        {
            if( ret.find(n) != ret.end() ) {
            ret[n]++;
        }
        else
        {
            ret[n] = 1;
        }
        }
    return ret;
}

void print_map(map<char, int> mp){
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        std::cout << "key = " << itr->first           // キーを表示
                        << ", val = " << itr->second << "\n";    // 値を表示
    }
}

// Returns nCr % p
ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N;
    string A, B, C;
    cin >> N >> A >> B >> C;
    ll count = 0;
    rep(i, N)
    {
        map<char, int> mp;
        mp[A[i]]++;
        mp[B[i]]++;
        mp[C[i]]++;
        ll max = 0;
        for (auto itr = mp.begin(); itr != mp.end(); ++itr)
        {
            if (itr->second > max) {
                max = itr->second;
            }
        }
        count += 3 - max;
    }
    cout << count << endl;
    return 0;
}



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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

int main(int argc, char const *argv[])
{
    int N, K; cin >> N >> K;
    vector <int> x;
    REP(i,N) {
        int tmp; cin >> tmp;
        x.push_back(tmp);
    }
    int res = INT_MAX;
    REP(i , N - (K - 1)) {
        int xl = x[i];
        int xr = x[i + (K - 1)];
        if (xl < 0) {
            if (xr <= 0){
                res = min(res, -xl);
            } 
            else {
                int time = min(-2*xl + xr, -xl + 2*xr);
                res = min(res, time);
            }
        }
        else {
            res = min(res, xr);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 892
#coding: utf-8
inf = 100000000
n = int(input())

List = [0] + [list(map(int,input().split())) for i in range(n)]
d = [inf for i in range(n+1)]
color = ["white" for i in range(n+1)]

s = 1
Q = [s]
d[s] = 0
color[s] = "gray"

while Q != []:
    q = Q.pop(0)
    k = List[q][1]
    for i in List[q][2:2+k]:
        if color[i] == "white":
            Q.append(i)
        d[i] = min(d[q] + 1, d[i])
    color[q] = "gray"


for i, dis in enumerate(d[1:], 1):
    if dis == inf:
        dis = -1
    print(i, dis)



Measured memory_bytes: 6000
#include <stdio.h>

int main (int argc, char* argv[])
{
  int n, i;
  long int capital=100000;
  
  scanf("%d", &n);
  for (i=0; i<n; i++) {
    capital *= 1.05;
    if (0 < capital % 1000) {
      capital = capital / 1000 + 1;
      capital *= 1000;
    }
  }

  printf("%ld\n", capital);
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;
int n,q;
int a[1000];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	cin>>q;
	for(int i=0;i<q;i++)
	{
		int c,b,e;cin>>c>>b>>e;
		if(c)
		{
			cout<<accumulate(a+b,a+e,int(-2e9),[](int a,int b){return max(a,b);})<<endl;
		}
		else
		{
			cout<<accumulate(a+b,a+e,int(2e9),[](int a,int b){return min(a,b);})<<endl;
		}
	}
}


Measured memory_bytes: 3096
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

//方針
//超えるまでたす、あとは微調整でok

ll X;
/*
ll dfs(ll n, ll i){
    if(n==0) return i-1;
    if(n<0) return 999999999;
    if(i>X) return 999999999;
    ll ret = 999999999;
    ret = min(ret, min(dfs(n-i, i+1), dfs(n, i+1)));
    return ret;
}
*/
ll llabs(ll a){
    return (a>0 ? a:-1*a);
}

int main(){
    cin>>X;
    X=llabs(X);
    ll i = 0;
    ll sum = 0;
    while(sum<X){
        i++;
        sum+=i;
    }
    sum-=i;
    i--;
    ll ans = 0;
    if(sum==X) ans = i;
    else if(i==X) ans = i;
    else ans = i+1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  bool result =
    (0 <= x - r) && (x + r <= W) &&
    (0 <= y - r) && (y + r <= H);

  cout << (result ? "Yes" : "No") << endl;
} 



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

const int N = 3e5+1 , M = 5e3+5;

int n , m , a[N] , ok[N] , t , b[N] , sol;

int main()
{
    cin>>n;
    for(int i = 1;i<=n;i++)
    {
        cin>>b[i];
    }
    m = n;
    for(int i = m;i>0;i--)
    {
        t = b[i];
        int acc = 0;
        for(int j = i;j<=m;j+=i)
            acc+=a[j];
        if(acc%2!=t%2)
        {
            if(a[i])sol--;
            else sol++;
            a[i]^=1;

        }
    }
    cout<<sol<<"\n";
    for(int i = 1;i<=n;i++)
        if(a[i])cout<<i<<" ";
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    constexpr auto M = 3500;

    int64_t n;
    cin >> n;

    for (int64_t m0 = 1; m0 <= M; ++m0) {
        for (int64_t m1 = 1; m1 <= M; ++m1) {
            // m2 = 1/(4/N - 1/m0 - 1/m1) = N m0 m1 / (4 m0 m1 - N m1 - N m0)
            auto p = 4 * m0 * m1 - n * m1 - n * m0;
            if (p <= 0) {
                continue;
            }
            auto d = n * m0 * m1;
            auto m2 = d / p;
            if (m2 * p == d) {
                cout << m0 << " " << m1 << " " << m2 << endl;
                return 0;
            }
        }
    }
}

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

using namespace std;

int main(void)
{
  string N;
  cin >> N;

  if (N[0] == '7' || N[1] == '7' || N[2] == '7') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> A(N),B(N);
    
    for(int i=0;i<N;i++){
        cin>>A[i];
        A[i]--;
    }
    
    for(int i=0;i<N;i++){
        cin>>B[i];
        B[i]--;
    }
    
    int now=0,a=-1,b=-1;
    
    vector<int> id(N);
    iota(all(id),0);
    
    do{
        if(id==A) a=now;
        if(id==B) b=now;
        
        now++;
        
    }while(next_permutation(all(id)));
    
    cout<<abs(a-b)<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
const ll N=2000005;
ll fac[N],facinv[N];
ll bpow(ll a,ll b){
	ll res=1;
	while(b!=0){
		if(b%2) res= (res*a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return res;
}
ll p25[N];
void pre(){
	fac[0]=1;
	for(ll i=1;i<N;i++){
		fac[i] = (fac[i-1]*i)%mod;
	}
	for(ll i=0;i<N;i++){
		facinv[i] = bpow(fac[i],mod-2);
	}
	p25[0]=1;
	for(ll i=1;i<N;i++) {
		p25[i] = (p25[i-1]*25)%mod;
	}
}
ll  nCr(ll a,ll b){
	ll res = (facinv[b]*facinv[a-b])%mod;
	res = (res*fac[a])%mod;
	return res;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	pre();
	ll k;
	cin>>k;
	string s;
	cin>>s;
	ll n=s.size();
	ll ans=0;
	for(ll i=n;i<=n+k;i++){
		ans = (ans + (p25[n+k-i]*nCr(n+k,i))%mod)%mod;
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 51128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    // 頂点数と辺数
    int N, M;
    cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty())
    {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v])
        {
            if (dist[nv] != -1)
                continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = v + 1;
            que.push(nv);
        }
    }
    cout << "Yes" << endl;
    FOR(i, 1, N)
    {
        if (dist[i] == -1)
        {
            cout << "No" << endl;
        }
        else
        {
            cout << dist[i] << endl;
        }
    }
}

Measured memory_bytes: 10120
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

int find(int v, vector<int>& p){
    if(p[v] == -1){
        return v;
    }
    p[v] = find(p[v], p);
    return p[v];
}

void unite(int u, int v, vector<int>& p){
    int u_root = find(u, p);
    int v_root = find(v, p);

    if(u_root == v_root){
        return;
    }
    p[u_root] = v_root;
}

signed main(){
    int n, m;
    cin >> n >> m;

    vector<int> p(n+1);
    rep(i, n) cin >> p[i+1];

    vector<int> x(m), y(m);
    rep(i, m){
        cin >> x[i] >> y[i];
    }

    vector<int> parent(n+1, -1);

    rep(i, m){
        unite(x[i], y[i], parent);
    }

    int ans = 0;
    for(int i = 1; i <= n; i++){
        int a = find(i, parent);
        int b = find(p[i], parent);
        if(a == b){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    for (int i=0;i<n;i++)
    scanf("%d",&a[i]);
    ll val=0,rem=0,sum1=1000;
    int i=0;
    while (i<(n-1))
    {
        if (a[i]<a[i+1])
        {
            val=sum1/a[i];
            rem=sum1%a[i];
            sum1=(val*a[i+1])+rem;
        }
        i++;
    }
    printf("%lld\n",sum1);
    return 0;
}

Measured memory_bytes: 3824
#include <stdio.h>

int main(int argc, char *argv[])
{
  int isec, h, m, s;

  scanf("%d", &isec);
  h = isec/3600;
  m = isec%3600/60;
  s = isec%60;
  printf("%d:%d:%d\n", h, m, s);

  return 0;
}



Measured memory_bytes: 1848
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    long double a,b,c;
    cin >> a >> b >> c;
    long double tmp = c - (a+b);
    long double left = tmp * 1.0f;
    long double right = 2 * sqrt(a*b);

    if(left > right) cout << "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
#include <set>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 100000;
ll n, k;
ll x[MAX_N];

int main(){
  cin >> n >> k;
  REP(i, n) cin >> x[i];

  ll ans = INFi;
  REP(i, n - k + 1) {
    if (x[i] * x[i + k - 1] > 0) {
      ans = min(ans, max(abs(x[i]), abs(x[i + k - 1])));
    } else {
      ans = min(ans, min(abs(x[i]), abs(x[i + k - 1])) * 2 + max(abs(x[i]), abs(x[i + k - 1])));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h> 
using namespace std; 
#define int long long int
  
// Function to return the probability when 
// number of heads is greater than the number of tails 
double Probability(double p[], int n) 
{ 
    // Declaring the DP table 
    double dp[n + 1][n + 1]; 
    memset(dp, 0.0, sizeof(dp)); 
  
    // Base case 
    dp[0][0] = 1.0; 
  
    // Iterating for every coin 
    for (int i = 1; i <= n; i += 1) { 
  
        // j represents the numbers of heads 
        for (int j = 0; j <= i; j += 1) { 
  
            // If number of heads is equal to zero 
            // there there is only one possiblity 
            if (j == 0) 
                dp[i][j] = dp[i - 1][j] 
                           * (1.0 - p[i]); 
            else
                dp[i][j] = dp[i - 1][j] 
                               * (1.0 - p[i]) 
                           + dp[i - 1][j - 1] * p[i]; 
        } 
    } 
  
    double ans = 0.0; 
  
    // When the number of heads is greater than (n+1)/2 
    // it means that heads are greater than tails as 
    // no of tails + no of heads is equal to n for 
    // any permuation of heads and tails 
    for (int i = (n + 1) / 2; i <= n; i += 1) 
        ans += dp[n][i]; 
  
    return ans; 
} 

int32_t main(){
    int n;
    cin>>n;
    double p[n+1];

    for (int i = 1; i <=n; ++i)
    {
        cin>>p[i];
    }
    cout<<fixed<<setprecision(10)<<Probability(p,n);

}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while(true) {
        c -= b;
        if(c <= 0) {
            cout << "Yes" << endl;
            break;
        }

        a -= d;
        if(a <= 0) {
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    x = II()
    fh = x // 500
    x = x - fh * 500
    five = x // 5
    print(1000 * fh + 5 * five)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FS first
#define SC second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for (auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for (auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int N, M; cin >> N >> M;
   map<int,int> cnt;

   REP(i, N) {
      int K; cin >> K;
      set<int> s;
      REP(j, K) {
         int a; cin >> a;
         cnt[a]++;
      }
   }

   int ans = 0;
   EACH(i, cnt) {
      if (i->second == N) {
         ans++;
      }
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256