akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
template<class T> using vv=vector< vector<T> >;
typedef deque<int> di;
typedef deque< deque<int> > ddi;


int main() {
    int n,q;
    queue<int> Qi;
    queue<string> Qs;
    cin >> n >> q;
    rep(i,n) {
        string s; 
        int t;
        cin >> s >> t;
        Qi.push(t); 
        Qs.push(s);
    }
    int t = 0;       
    while(!Qi.empty ()) {
        int q1 = Qi.front();
        Qi.pop();
        string q2 = Qs.front();
        Qs.pop();
        if(q1 > q) {
           q1 -= q; 
           t += q;
           Qi.push(q1);
           Qs.push(q2);
        } else {
            t += q1;
            cout << q2 << " " << t << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 5692
fun main(args : Array<String>){
    val (n,c) = readLine()!!.split(' ').map(String::toInt)
    val d = mutableListOf<List<Int>>()
    for(i in 0 until c){
        val tmp = readLine()!!.split(' ').map(String::toInt)
        d.add(tmp)
    }
    val mp = mutableListOf<List<Int>>()
    for(i in 0 until n){
        val tmp = readLine()!!.split(' ').map(String::toInt)
        mp.add(tmp)
    }

    val seica = Array(3,{IntArray(55,{0})})

    for(i in 0 until n){
        for(j in 0 until n){
            seica[(i+j)%3][mp[i][j]-1]++
        }
    }

    var ans = 1000000000

    for(i in 0 until c){
        for(j in 0 until c){
            for(k in 0 until c){
                if(i == j || j == k || k == i)continue
                var tmp = 0
                for(x in 0 until c){
                    tmp += seica[0][x] * d[x][i]
                    tmp += seica[1][x] * d[x][j]
                    tmp += seica[2][x] * d[x][k]
                }
                ans = Math.min(ans,tmp)
            }
        }
    }

    println(ans)

}

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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
        fastio;
        string s[]={"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};
        string t;
        cin>>t;
        for(int i=0;i<7;i++)
        {
            if(t==s[i])
            {
                cout<<7-i<<endl;
                break;
            }
        }

    }

Measured memory_bytes: 3612
#include<stdio.h>
int main()
{
	int n,x;
	scanf("%d %d",&n,&x);
	int i;
	int a[100005];
	for(i=0;i<n;i++)
	    scanf("%d",&a[i]);
	double ans=0;
	for(i=0;i<n;i++)
	    if(a[i]>x)
	    {
	    	ans+=a[i]-x;
	    	a[i]=x;
	    }
	for(i=0;i<n-1;i++)
	    if(a[i]+a[i+1]>x)
	    {
	    	ans+=a[i]+a[i+1]-x;
	    	a[i+1]=x-a[i];
	    }
	printf("%.0lf\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int no[10];
    rep(i, 10){
        no[i] = 0;
    }
    //printArray(no, 10);
    no[a]++;
    no[b]++;
    no[c]++;
    no[d]++;
    //printArray(no, 10);
    //cout << "debug" << endl;
    if(no[1]){
        if(no[7]){
            if(no[9]){
                if(no[4]){
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

vector<string> SORT(vector<string> S){
  string v;
  for(int i=1;i<S.size();i++){
    int j=i-1;
    v=S.at(i);
    while(j>=0 && v<S.at(j)){
      S.at(j+1)=S.at(j);
      j--;
    }
    S.at(j+1)=v;
  }
  return S;
}

int main() {
  int n,l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s.at(i);
  }
  s = SORT(s);
  for(int i=0;i<n;i++){
    cout << s.at(i);
  }
  cout << endl;
}

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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(int64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

// 最小公倍数lcm=m*n/gcd
uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// nCm
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

signed main() {
  long double a,b;
  uint64_t h,m;
  string s;
  cin >> a >> b >> h >> m;
  
  long double angleH, angleM;
  angleH = ((long double)h)*2.0*M_PIl/12.0;
  angleM = ((long double)m)*2.0*M_PIl/60.0;
  angleH += angleM/12.0;
  
  cout << std::setprecision(15) << (long double)sqrtl( (a*cosl(angleH)-b*cosl(angleM))*(a*cosl(angleH)-b*cosl(angleM)) 
               + (a*sinl(angleH)-b*sinl(angleM))*(a*sinl(angleH)-b*sinl(angleM)) ) << endl;
  return 0;
}

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

#define io ios::sync_with_stdio(false)
#define pb push_back
#define pqueue priority_queue
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define sz(x) (int)(x).size()
#define dbg(x) cout<<#x<<" --- "<<x<<endl
#define mst(x,a) memset(x,a,sizeof(x))
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const int inf=0x7fffffff;
int n;

int main(){
	io;
	cin>>n;
	n%=1000;
	n=1000-n;
	n%=1000;
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int H, N, S = 0, a;
	cin >> H >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a;
		S += a;
	}

	if (S >= H) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n;
    cin>>n;
    if(n%1000==0)
    cout<<0;
    else
    cout<<1000-n%1000;}
    
    
    
    

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

int main(){
        int r,g,b;
        cin >> r >> g >> b;
        if ((100*r + 10*g + b )%4 == 0) {
                cout << "YES" << endl;
        }else{
                cout << "NO" << endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    int l = s.length();
    for (int i = 0; i < l; i++) {
        if (s[i] == '?') {
            if (i == 0) {
                if (s[i + 1] == 'D')
                    s[i] = 'P';
                else
                    s[i] = 'D';
            }
            else if (i == l - 1)
                s[i] = 'D';
            else {
                if (s[i - 1] == 'P' || s[i + 1] == 'P')
                    s[i] = 'D';
                else if (s[i - 1] == 'D' && s[i + 1] == 'D')
                    s[i] = 'P';
                else
                    s[i] = 'P';
            }
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    
    vector<long long> v;
    for (long long i = 0;i < s.size();i++){
        v.push_back(s[i]-'0');
    }
    long long ans = 0;
    for (long long i = 0;i < (1<<(v.size()-1));i++){
        stack<long long> S;
        S.push(v[0]);
        for (long long j = 0;j < v.size();j++){
            if ((i>>j)%2==0 && j != v.size()-1){
                S.push(v[j+1]);
            }
            else {
                long long p = 1;
                while(S.size()!=0){
                    long long t = S.top();
                    S.pop();
                    ans += t*p;
                    p *= 10;
                }
                S.push(v[j+1]);
            }
        }
    }
    cout << ans << endl;
}


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

#define ll long long
#define endl "\n"

int main(void)
{
    int a,b;
    cin >> a >> b;
    int val, counter = 1, i, sum = 0;
    for(i = 0; i < a; i++)
    {
        cin >> val;
        sum += val;
        if(sum <= b)
            counter++;
    }
    cout << counter << endl;

    return 0;
}


Measured memory_bytes: 256
//Be Name Khoda
//man az biganegan  hargez  nanalam
//ke harche kard ba man ashena kard
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); }
#define MKP make_pair
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
#define GEI(x) scanf("%d",&x)
#define GEL(x) scanf("%lld",&x)
#define ALL(x) x.begin(),x.end()
const ll M=2e5+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

ll n;
vll g[2][M];
ll par[2][M];
ll root[2];
ll nt;
ll ans[M];
vll h[M];
ll col[M];

ll dfs(ll x)
{
    for (ll y:h[x])
    {
        if (col[y]) continue;
        col[y]=col[x]*-1;
        dfs(y);
    }    
}


ll dfst(ll x)
{
    ll gh=-1;
    for (ll yy:g[nt][x])
    {
        ll y=dfst(yy);
        if (gh==-1) gh=y;
        else
        {
            h[gh].PB(y);
            h[y].PB(gh);
            gh=-1;
        }
    }
    if (gh==-1) return x;
    return gh;
}



int main()
{
    GEL(n);
    For(i,0,n)
    {
        GEL(par[nt][i]);
        if (par[nt][i]==-1) 
        {
            root[nt]=i;
            continue;
        }
        par[nt][i]--;
        g[nt][par[nt][i]].PB(i);
    }    
    nt=1;
    For(i,0,n)
    {
        GEL(par[nt][i]);
        if (par[nt][i]==-1) 
        {
            root[nt]=i;
            continue;
        }
        par[nt][i]--;
        g[nt][par[nt][i]].PB(i);
    }
    For(i,0,n)
    {
        if (SZ(g[0][i])%2!=SZ(g[1][i])%2)
            RET("IMPOSSIBLE");
        
        ans[i]=1-SZ(g[0][i])%2;        
    }
    nt=0;
    dfst(root[nt]);
    nt=1;
    dfst(root[nt]);    
    For(i,0,n)
    {
        if (col[i]) continue;
        col[i]=1;
        dfs(i);
    }
    cout << "POSSIBLE\n";
    For(i,0,n) cout << col[i]*ans[i] << ' ';
}

Measured memory_bytes: 28160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<tuple<string,int,int>> mp(n);
    rep(i,n){
        string s; int a; cin >> s >> a;
        mp[i] = make_tuple(s,a*-1,i+1);
    }
    //rep(i,n)cout << get<0>(mp[i])<<" "<<get<1>(mp[i]) <<" " <<get<2>(mp[i]) <<endl;

    sort(all(mp));
    rep(i,n) cout << get<2>(mp[i]) << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, A = map(int, input().split())
tmp = input()
ary = [int(a) for a in tmp.split()]

maximum = max(ary)


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


g = None
for a in ary:
    if g is None:
        g = a
        continue
    g = gcd(g, a)

if A % g == 0 and A <= maximum:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 15320
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
for i,I in enumerate(h):
    if i !=0:
        j=0 if i<k else i-k
        dp[i]=min(abs(I-p)+q for p,q in zip(h[j:i],dp[j:i]))
print(dp[n-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

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

void Main() {
    i64 K, A, B;
    cin >> K >> A >> B;
    i64 ans = 0;
    i64 bis = 1;
    if (A + 1 >= B || K < A - 1) {
        cout << 1 + K << endl;
        return;
    }
    K -= A - 1;
    bis = A;
    bis += K / 2 * (B - A);
    if (K % 2 == 1) {
        K--;
        bis++;
    }
    cout << bis << endl;


}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

ll dp[1000010];
int main(){
    int n;
    cin >> n;
    ll m,k;
    cin >> m >> k;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    sort(a.rbegin(),a.rend());
    bool flag = 1;
    ll sm = 0;
    
    for(int i=0;i<n;i++){
        if(flag){
            if(sm + a[i]<=m){
                sm += a[i];
            }else{
                flag = 0;
                dp[a[i]]++;
                dp[m-sm]--;
            }
        }else{
            dp[a[i]]++;
            dp[0]--;
        }
    }
    ll cnt = 0;
    ll res = 0;
    for(ll i=1000001;i>=0;i--){
        cnt += dp[i];
        if(cnt==0)continue;
        if(k>0){
            if(k>cnt){
                k-=cnt;
            }else{
                res += (cnt-k)*i;
                k = 0;
            }
        }else{
            res += cnt*i;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 11468
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

int main() {
    ios_base::sync_with_stdio(0);
    ll a,b,x;
    cin>>x;
    ll n=100;
    for(ll i=1;;++i) {
        ll p = n/100;
        n += p;
        if(n>=x) {
            cout<<i<<endl;
            return 0;
        }
    }   
    return 0;
}

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

using namespace std;

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

typedef long long ll;

const int MAX_N=2e4;

int N,M,K;
int A[MAX_N];

ll dp[MAX_N+1];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>N>>M>>K;
	REP(i,N){
		cin>>A[i];
	}
	dp[0]=0;
	FOR(i,1,N+1){
		dp[i]=K+dp[i-1];
		int ma=A[i-1],mi=A[i-1];
		FOR(j,2,min(M,i)+1){
			ma=max(ma,A[i-j]);
			mi=min(mi,A[i-j]);
			dp[i]=min(dp[i],K+(ll)j*(ma-mi)+dp[i-j]);
		}
	}
	cout<<dp[N]<<endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define MEM(a,b) memset(a,b,sizeof(a));
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int deg[MAXN], color[MAXN], isValid[MAXN], visited[MAXN];
vi v[MAXN], g[MAXN];

int weight[MAXN], node, wt;

void dfs(int p, int len, int flag) {
    visited[p] = flag;
    if(len + weight[p] > wt) {
        wt = len;
        node = p;
    }
    for(auto i: g[p]) {
        if(visited[i] == flag) continue;
        dfs(i, len+weight[p], flag);
    }
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int rn = uniform_int_distribution<int>(0, MAXN)(rng);

    int n;
    char c;
    cin>>n;
    REP(i,n-1) {
        int x,y;
        cin>>x>>y;
        x--, y--;
        v[x].PB(y); v[y].PB(x);
        deg[x]++; deg[y]++;
    }
    int count = 0;
    REP(i,n) {
        cin>>c;
        if(c == 'W') color[i] = 0, count++;
        else color[i] = 1;
    }
    
    if(count == 0) {
        cout<<"0"; return 0;
    } else if(count == 1) {
        cout<<"1"; return 0;
    }

    queue<int> q;
    REP(i,n) if(deg[i] == 1 && color[i] == 1) q.push(i);
    MEM(isValid, 1);
    while(!q.empty()) {
        int p = q.front();
        isValid[p] = 0;
        q.pop();
        for(auto i: v[p]) {
            if(deg[i] <= 1 || !isValid[i]) continue;
            deg[i] -= 1;
            if(deg[i] == 1 && color[i] == 1) q.push(i);
        }
    }

    int edges = 0, bv = 0, st = -1;
    REP(i,n) {
        if(!isValid[i]) continue;
        st = i;
        for(auto j: v[i]) if(isValid[j]) g[i].PB(j);
        edges += g[i].size();
        if((color[i] == 1 && g[i].size()%2 == 1) || (color[i] == 0 && g[i].size()%2 == 0)) weight[i] = 2, bv += 1;
        else weight[i] = 0;
    }

    wt = -1;
    dfs(st,0,1);
    wt = -1, st = node;
    dfs(st,0,2);

    int res = edges + bv - wt;
    cout<<res;

    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int dfs(int maxim, int left, int sum){
  int res = 0;
  if(left == 0 and sum == 0) return 1;
  for(int i=1; i<maxim; i++){
    if(sum < i) break;
    res += dfs(i, left-1, sum-i);
  }
  return res;
}

int main(){
  int n, k, s;
  while(cin >> n >> k >> s and n + k + s){
    int maxim = n+1;
    cout << dfs(maxim, k, s) << endl;
  }
  return 0;
}

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

int n;
string mark;
int index_x;
int num;
int cards[4][13];

int main() {
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> mark >> num;
    if(mark == "S"){
      index_x = 0;
    }else if(mark == "H"){
      index_x = 1;
    }else if(mark == "C"){
      index_x = 2;
    }else{
      index_x = 3;
    }
    cards[index_x][num-1] = 1;
  }

  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 13; j++){
      if(cards[i][j] != 1){
        if(i == 0){
          cout << "S ";
        }else if(i == 1){
          cout << "H ";
        }else if(i == 2){
          cout << "C ";
        }else{
          cout << "D ";
        }
        cout << j+1 << endl;
      }
    }
  }
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int a;cin>>a;
    string s;cin>>s;
    if(a>=3200)cout<<s;
    else cout<<"red"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }



int collatz(int n){
    int a=n;
    if(a%2 == 0)a/=2;
    else a = a*3+1;
    return a;
}

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

    if(X==7 || X==5 || X==3)cout <<"YES" << endl;
    else cout << "NO" << endl;




}



Measured memory_bytes: 3612
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
    ll H, W, A, B;
    cin >> H >> W >> A >> B;

    rep(i, H) {
        if (i < B) {
            rep(k, A) { cout << 0; }
            rep(k, W - A) { cout << 1; }
            cout << endl;
        } else {
            rep(k, A) { cout << 1; }
            rep(k, W - A) { cout << 0; }
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int P = 1e9 + 7;
const int inv3 = (P + 1) / 3;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int inv[MAXN];
int main() {
	int ans = 0, n;
	read(n), inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = (P - 1ll * (P / i) * inv[P % i] % P) % P;
	for (int i = 1, mul = inv3; i <= n; i++, mul = 1ll * mul * inv3 % P)
		ans = (ans + 1ll * inv[n] * inv[n - i + 1] % P * mul) % P;
	writeln(ans);
	return 0;
}

Measured memory_bytes: 4096
n,l = map(int,input().split())
ls = [x + l - 1 for x in range(1,n+1)]
c = 10000000000;check = 1
for i in range(len(ls)):
    if c > abs(ls[i]):
        c = abs(ls[i])
        if ls[i] < 0:check = -1
        else:check = 1
print(sum(ls) - c*check)

Measured memory_bytes: 3060
n,m=map(int,input().split())
ac_cnt = set()
wa_cnt = 0
penalty = [0]*n
for i in range(m):
    p,s = input().split()
    num = int(p) - 1
    if num not in ac_cnt:
        if s == "AC":
            ac_cnt.add(num)
            wa_cnt += penalty[num]
        else:
            penalty[num] += 1
print(len(set(ac_cnt)),wa_cnt)

Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
using namespace std;

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,pair<int,int>>> da(m);
    vector<int> p(m),y(m);
    for rip(i,m){
        cin >> da[i].first >> da[i].second.first;
        da[i].second.second=i;
    }
    sort(da.begin(),da.end());
    vector<pair<int,int>> ans(m);
    int co=1;
    ans[da[0].second.second]=make_pair(da[0].first,1);
    for (int i=1;i<m;i++){
        if(da[i].first==da[i-1].first){
            co++;
        }
        else{
            co=1;
        }
        ans[da[i].second.second]=make_pair(da[i].first,co);
    }
    for rip(i,m){
        printf("%06d%06d\n",ans[i].first,ans[i].second);
    }
}

Measured memory_bytes: 4224
#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
	LL n,s=0;
	cin>>n;
	for(LL i=1;i<=n;i++)
	{
		if(i%3!=0&&i%5!=0)
		s+=i;
	}
	cout<<s;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<set>
using namespace std;

#define MAX 100000

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev){
    //ノード　current を訪問した直後の処理
    prenum[current] = lowest[current] = timer;
    timer++;

    visited[current] = true;

    int next;

    for(int i=0; i<G[current].size(); i++){
        next = G[current][i];
        if(!visited[next]){
            //ノード　current から next へ訪問する直前の処理
            parent[next] = current;

            dfs(next, current);

            //ノード　next の探索が終了した直後の処理
            lowest[current] = min(lowest[current], lowest[next]);
        }else if(next != prev){
            // エッジ　current --> next がback-edge の場合
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }
    // ノード current の探索が終了した直後の処理
}

void apt_points(){
    for(int i=0; i<N; i++) visited[i] = false;
    timer = 1;
    //lowest　の計算
    dfs(0,-1);

    set<int> ap;
    int np = 0;
    for(int i=1; i<N; i++){
        int p = parent[i];
        if(p==0) np++;
        else if(prenum[p] <= lowest[i]) ap.insert(p);
    }
    if(np > 1) ap.insert(0);
//    for(auto x: ap)
//        cout << x << endl;
    for( set<int>::iterator it = ap.begin(); it != ap.end(); it++)
        cout << *it << endl;
}

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

    for(int i=0; i<m; i++){
        int s, t;
        cin >> s >> t;
        //無向グラフ
        G[s].push_back(t);
        G[t].push_back(s);
    }
    apt_points();

    return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d,e=0;
  cin>>a>>b>>c>>d;
  for(int i=0;i*a<=d;++i)
    for(int j=0;j*b+i*a<=d;++j)
    	e+=(d-i*a-j*b)%c==0;
  cout<<e;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
ll n,m;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  std::vector<P> v(m);
  rep(i,m) cin>>v[i].fi>>v[i].se;
  std::vector<ll> num(n,0),red(n,0);
  rep(i,n) num[i] = 1;
  red[0] = 1;
  rep(i,m){
    v[i].fi--;
    v[i].se--;
    if(red[v[i].fi]) red[v[i].se] = true;
    num[v[i].fi] = num[v[i].fi] - 1;
    num[v[i].se] = num[v[i].se] + 1;
    if(num[v[i].fi] == 0) red[v[i].fi] = false;
  }
  ll cnt = 0;
  rep(i,n) if(red[i]  == true) cnt++;
  cout<<cnt<<endl;

}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define FD(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define pii pair<int,int>
#define reset(x,y) memset(x, y,sizeof(x))
#define MIN(x,y) if (x > (y)) x = (y)
#define MAX(x,y) if (x < (y)) x = (y)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define EL putchar('\n');
#define mod 1000000007
#define oo 1000006
int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
void write(int x)
{
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
string s;
int n[100005],d,f[10004][100][3];
void ReadInPut()
{
    cin>>s>>d;
    F(i,0,s.size()-1)n[i+1]=int(s[i]-48);
}
int tinh(int i,int j,int ok)
{
    //cout<<i<<" "<<j<<" "<<ok<<'\n';
    if(i==s.size()+1)return j==0&&ok<2;
    if(f[i][j][ok]!=-1)return f[i][j][ok];
    f[i][j][ok]=0;
    if(i>1&&j==0)f[i][j][ok]++;
    F(z,0,9)
    {
        if(i==1&&z==0)continue;
        if(ok==1||(ok==0&&z==n[i])||(ok==2))f[i][j][ok]=(f[i][j][ok]+tinh(i+1,(j+z)%d,ok))%mod;
        if(ok==0&&z<n[i])f[i][j][ok]=(f[i][j][ok]+tinh(i+1,(j+z)%d,1))%mod;
        if(ok==0&&z>n[i])f[i][j][ok]=(f[i][j][ok]+tinh(i+1,(j+z)%d,2))%mod;
    }
    return f[i][j][ok];
}
void Solve()
{
    reset(f,-1);
    cout<<tinh(1,0,0);
}
main()
{
//    freopen("t.INP","r",stdin);
  //  freopen(".OUT","w",stdout);
    int sotest=1;
    //cin>>sotest;
    for(int i=1;i<=sotest;i++)
    {
        ReadInPut();
        Solve();
    }
}


Measured memory_bytes: 13184
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class AtCoder
{
    int Bisect(long[] array, long value)
    {
        int ret = -1;
        for(int start = 0, end = array.Length - 1, mid = (start + end) / 2; start <= end; mid = (start + end) / 2)
        {
            if(array[mid] == value)
                return mid;
            else if(array[mid] > value)
            {
                start = mid + 1;
            }
            else
            {
                end = mid - 1;
                ret = mid;
            }
        }
        return ret;
    }
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        int a = int.Parse(inputs[0]);
        int b = int.Parse(inputs[1]);
        int c = int.Parse(inputs[2]);
        int k = int.Parse(inputs[3]);
        long[] cakeA = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[] cakeB = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[] cakeC = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();
        long[] AaddB =
            cakeA
            .SelectMany(x => cakeB.Select(y => x + y).ToArray())
            .OrderByDescending(x => x)
            .ToArray();
        long bef = long.MaxValue; 
        for(int i = 0; i < k;)
        {
            int count = 1;
            long max = 0;
            int index = 0;
            foreach (long num in cakeC)
            {
                long searchValue = bef - num - 1;
                index = Bisect(AaddB, searchValue);
                if (index < 0)
                    continue;
                long sum = AaddB[index] + num;
                //Console.WriteLine($"{searchValue} {AaddB[index]} {sum}");
                if(max <= sum)
                {
                    int temp = 1;
                    for (int j = index - 1; j >= 0 && AaddB[j] == AaddB[index]; j--)
                        temp++;
                    for (int j = index + 1; j < AaddB.Length && AaddB[j] == AaddB[index]; j++)
                        temp++;
                    if (max == sum)
                    {
                        count += temp;
                    }
                    else
                    {
                        count = temp;
                    }
                    max = sum;
                }                
            }
            foreach(int j in Enumerable.Range(0, Math.Min(count, k - i)))
            {
                Console.WriteLine(max);
            }
            i += count;
            bef = max;
        }
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

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

int main() {
	// your code goes here
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int k=0;
	while(a>0 && c>0){
		if(k%2==0){
			c-=b;
			k++;
		}
		else{
			a-=d;
			k++;
		}
	}
	if(a<=0)
		cout<<"No";
		else
		cout<<"Yes";
	
	return 0;
}

Measured memory_bytes: 3632
//https://atcoder.jp/contests/dp/tasks/dp_a
#include<bits/stdc++.h>
using namespace std;


int main(){
    int n;
    cin>>n;
    std::vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    std::vector<int> dp(n,0);
    dp[1] = abs(a[1] - a[0]);
    for(int i=2;i<n;i++){
        dp[i] = min((dp[i-1]+abs(a[i] - a[i-1])),(dp[i-2]+abs(a[i] - a[i-2])));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


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

const int N = 100005;

int n, head[N], tot;
struct edge { int to, nxt; } e[N << 1];
void link(int x, int y) {
	e[++tot] = (edge) { y, head[x] }, head[x] = tot;
	e[++tot] = (edge) { x, head[y] }, head[y] = tot;
}

int dfs(int x, int f = 0) {
	int ret = 0;
	for (int i = head[x]; i; i = e[i].nxt)
		if (e[i].to != f) ret ^= dfs(e[i].to, x) + 1;
	return ret;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, x, y; i < n; ++i)	
		std::cin >> x >> y, link(x, y);
	std::cout << (dfs(1) ? "Alice" : "Bob") << '\n';
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
typedef long long ll;
const int N=100000;
int n,k,x;
string s;
//vector<int>v;
ll dp[110][N+10];
int main(){

	scanf("%d%d",&n,&k);
	for(int i =0;i<=100;i++){
		for(int j=0;j<=N;j++)
			dp[i][j]=1000000000000000l;
	}
	dp[0][0]=0;
	ll v,w;
	for(int i =1;i<=n;i++){
		cin >> w>> v;
		for(int j=N;j>=0;j--){
			dp[i][j]=dp[i-1][j];
			if(j>=v){
				dp[i][j]=min(dp[i][j],w+dp[i-1][j-v]);
			}
		}
	}
	for(int i =N;i>=0;i--){
		if(dp[n][i]<=k){
			printf("%d\n",i );
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 80128
N = int(input())
t_prev, x_prev, y_prev = 0,0,0

flag = True
for _ in range(N):
    t,x,y = map(int,input().split())
    k = abs(x-x_prev) + abs(y-y_prev)
    t_diff = t-t_prev
    
    if k > t_diff:
        flag = False
        break
    else:
        if (t_diff - k)%2 != 0:
            flag = False
            break
    t_prev, x_prev, y_prev = t,x,y

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int n;
	cin>>n;
	cout<<(100000-n)%1000;
	re 0;
}


Measured memory_bytes: 3604
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

class UFT
  attr_accessor:node,:rank
  def initialize(n)
    @node=array(n,1,0)
    @rank=array(n,1,0)
    n.times do|i|
      @node[i]=i
    end
  end

  def find(x)
    return x if @node[x]==x
    return @node[x]=find(@node[x])
  end

  def unite(x,y)
    x=find(x)
    y=find(y)
    if @rank[x]<@rank[y]
      @node[x]=y
    else
      @node[y]=x
      @rank[x]+=1 if @rank[x]==@rank[y]
    end
  end

  def same?(x,y)
    return find(x)==find(y)
  end
end

n,m=get_i
p=get_i
corres=array(n,1,-1)
n.times do|i|
  corres[p[i]-1]=i
end
uft=UFT.new(n)
m.times do
  x,y=get_i
  uft.unite(x-1,y-1)  
end
ans=0
n.times do|i|
  if p[i]==i+1
    ans+=1
  elsif uft.same?(i,p[i]-1)
   ans+=1 
  end
end
puts ans

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

// 26進数に変換する関数
vector<int> change(long n) {
    vector<int> a;
  while(1) {
  if(n < 26) {
    a.push_back(n);
    break; }
  else {
    a.push_back(n % 26);
    n = n / 26; }
  }
  return a;
}

int main() {
  long n;
  cin >> n;
  vector<int> a = change(n); // nを26進数に変換 #26進数を逆順で表記
  string alp, name;
  alp = "abcdefghijklmnopqrstuvwxy";
  
  for(long i = 0; i < a.size()-1; i++) {
    if(a.at(i) != 0) name.push_back(alp.at(a.at(i)-1));
    else {
      name.push_back('z');
      for(long j = 1; i+j < a.size(); j++) {
        if(a.at(i+j) != 0) {
          a.at(i+j) -= 1;
          break; }
        else a.at(i+j) = 25; }
    }
  }
  if(a.at(a.size()-1) != 0) name.push_back(alp.at(a.at(a.size()-1)-1));
  
  reverse(name.begin(), name.end());
  cout << name << endl;
}

Measured memory_bytes: 3628
# ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)
# readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
# gets.split.map(&:to_i)

# n,a,b = gets.split.map(&:to_i)

# sum = 0
# n.times do |i|
#   num = (i+1).to_s.split("").map { |s| s.to_i }.inject(:+)
#   if a <= num && num <= b
#     sum += i+1
#   end
# end

# puts sum


n,a,b = gets.split.map(&:to_i)

sum = 0
1.upto(n) do |i|
  val = i.to_s.split("").map(&:to_i).inject(:+)
  sum += i if a <= val && b >= val
end

puts sum 

Measured memory_bytes: 14416
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,sum=0;;
	string s;
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			sum++;
			i+=2;
		}
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
char* myfgets(char *buf,int n,FILE *fp){ //accepts LF/CRLF
	char *ret=fgets(buf,n,fp);
	if(!ret)return NULL;
	if(strlen(buf)&&buf[strlen(buf)-1]=='\n')buf[strlen(buf)-1]=0;
	if(strlen(buf)&&buf[strlen(buf)-1]=='\r')buf[strlen(buf)-1]=0;
	return ret;
}

char Q[99999];
char *q[9];
char L[99999];
int ind[9];
int n;
dfs(depth){
	int cur_ind=0;
	if(!myfgets(L,sizeof(L),stdin)){puts("no such property");exit(0);}
	if(depth){
		for(;L[cur_ind]==' ';cur_ind++);
		if(ind[depth-1]>=cur_ind){puts("no such property");exit(0);}
	}
	char *name=strtok(L+cur_ind,":"),*value=name+strlen(name)+1;
	if(!strcmp(name,q[depth])){
		if(depth==n-1){
			if(*value)
				printf("string \"%s\"\n",value+1),exit(0);
			else
				puts("object"),exit(0);
		}
		ind[depth]=cur_ind;
		dfs(depth+1);
	}
	dfs(depth);
}

main(depth){
	myfgets(Q,sizeof(Q),stdin);
	q[0]=strtok(Q+1,".");
	for(n=1;;n++)if(!(q[n]=strtok(NULL,".")))break;
	dfs(0);
}

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

int main() {
  
  long long a, b, r, x, tmp;
 
  cin >> a;
  cin >> b;
 
  x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  /* 最小公倍数を出力 */
  cout <<  x/b << endl;
 
  return 0;

}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define M 1000000007
#define M 998244353
const int inf=4e18;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int x,y,a,b,c;cin>>x>>y>>a>>b>>c;
	int red[a+1],green[b+1],cless[c+1],i,j;
	for(i=1;i<=a;i++)
		cin>>red[i];
	for(i=1;i<=b;i++)
		cin>>green[i];
	for(i=1;i<=c;i++)
		cin>>cless[i];
	sort(red+1,red+a+1,greater<int> ());
	sort(green+1,green+b+1,greater<int> ());
	sort(cless+1,cless+c+1,greater<int> ());
	int pc[c+1];pc[0]=0;
	for(i=1;i<=c;i++)
		pc[i]=pc[i-1]+cless[i];
	int opt[x+y+1];opt[0]=0;
	i=1;j=1;
	while(i<=x||j<=y)
	{
		if(i>x)
		{
			opt[i+j-1]=opt[i+j-2]+green[j],j++;
			continue;
		}
		if(j>y)
		{
			opt[i+j-1]=opt[i+j-2]+red[i],i++;
			continue;
		}
		if(red[i]>green[j])
			opt[i+j-1]=opt[i+j-2]+red[i],i++;
		else
			opt[i+j-1]=opt[i+j-2]+green[j],j++;
	}
	int o=0;
	for(i=0;i<=min(x+y,c);i++)
		o=max(o,pc[i]+opt[x+y-i]);
	cout<<o<<endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(10) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define pint pair<lli,lli>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> S;
  DV(dp,lli,S.size(),13,0);//dp[i][j]:=上位i+1桁を決定した時、mod13がjになる組み合わせの数
  N=S.size();
  if(S[0]!='?')dp[0][S[0]-'0']=1;
  else rep(i,0,10)dp[0][i]=1;
  rep(i,0,N-1){
    if(S[i+1]!='?')rep(j,0,13){
      dp[i+1][(j*10%13+(S[i+1]-'0'))%13]+=dp[i][j];
      dp[i+1][(j*10%13+(S[i+1]-'0'))%13]%=mod;
    }else{
      rep(j,0,13)rep(k,0,10){
        dp[i+1][(j*10%13+k)%13]+=dp[i][j];
        dp[i+1][(j*10%13+k)%13]%=mod;
      }
    }
  }
  Out(dp[N-1][5]);
}

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

int main(void) {
    int n;
    cin >> n;
    string r;
    cin >> r;
    string a;
    int count = 0;
    for(int i =0; i < n/2; i++) {
        a = a + r[i];
    }
  if(r == (a + a)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256