akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

int n;
int a[MAXN];
bool tp[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	char ts[5];
	tp[1] = true;
	lpi ( i, 1, n ){
		if ( i > 1 ){
			scanf ( "%s", ts );
			tp[i] = ts[0] == '+';
		}
		scanf ( "%d", &a[i] );
	}
}

void work ()
{
	// main work
	
	LL sum = 0, ans = 0, sn = 0;
	lpi ( i, 1, n ) sum += a[i], ans += tp[i] ? a[i] : -a[i], sn += tp[i] ? 0 : a[i];
	
	LL cur = 0;
	lpd ( i, n, 1 ){
		cur += a[i];
		if ( !tp[i] ){
			sn -= a[i];
//			cerr << i << " " << sum << " " << cur << " " << ans << endl;
			ans = qmax ( ans, sum - ( cur + sn ) * 2 );
			cur = 0;
		}
	}
	
	cout << ans << endl;
}

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

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

Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

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

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

    lint n;
    cin >> n;

    cout << n * (n - 1LL) / 2LL << endl; 

    return 0;
}

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

const int maxn = 2e5 + 10;

int n, k, l, par1[maxn], par2[maxn];

void init() {
	for (int i = 0; i < n; i++) {
		par1[i] = i;
		par2[i] = i;
	}
}

int find(int x, int *par) {
	return x == par[x] ? x : par[x] = find(par[x], par);
}

void unite(int x, int y, int *par) {
	x = find(x, par);
	y = find(y, par);
	if (x != y) {
		par[x] = y;
	}
}

int main() {

	scanf("%d%d%d", &n, &k, &l);
	init();
	for (int i = 0; i < k; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		unite(x, y, par1);
	}
	for (int i = 0; i < l; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		unite(x, y, par2);
	}
	map<pair<int, int>, int> mp;
	for (int i = 1; i <= n; i++) {
		find(i, par1);
		find(i, par2);
	}
	for (int i = 1; i <= n; i++) {
		mp[make_pair(par1[i], par2[i])]++;
	}

	for (int i = 1; i <= n; i++) {
		cout << mp[make_pair(par1[i], par2[i])] << " ";
	}

	return 0;
}

Measured memory_bytes: 13568
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(x) x.begin(), x.end()
#define ASORT(x) sort(x.begin(), x.end());
#define DSORT(x) sort(x.rbegin(), x.rend());
#define OUT(x) cout<<x<<endl;

#define VINT vector<int>;
#define I(x) int x; cin>>x;
#define VI(v,n) vector<int> v; v.resize(n); REP(i,n) cin>>v[i];
#define VLINT vector<long long>
#define LI(x) long long x; cin>>x;
#define VLI(v,n) vector<lint> v; v.resize(n); REP(i,n) cin>>v[i];
#define VDOUBLE vector<double>
#define D(x) double x; cin>>x;
#define VD(v,n) vector<double> v; v.resize(n); REP(i,n) cin>>v[i];
#define VSTRING vector<string>
#define STR(x) string x; cin>>x;
#define VSTR(v,n) vector<string> v; v.resize(n); REP(i,n) cin>>v[i];

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

bool eval(vector<int> vint)
{
	int N = vint.size();
	int s = N - 1;
	
	DSORT(vint);
	if (N % 2 == 1) vint.push_back(0);

	REP(i, N)
	{
		int a = vint[i];
		int b = vint[++i];
		if (a != s || b != s || a != b) return false;
		s -= 2;
	}

	return true;
}

long long pow(int a, int b, int mod)
{
	int ret = 1;
	REP(i, b)
	{
		ret = ret * a % mod;
	}
	return ret;
}

int main()
{
	I(N);
	VI(A, N);
	
	if (eval(A)) OUT(pow(2, N/2, 1000000007)) else OUT(0)

	cin.get();
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M, X;
int C[12], A[12][12];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> X;
	rep(i, 0, N) {
		cin >> C[i];
		rep(j, 0, M) cin >> A[i][j];
	}

	int ans = inf;
	rep(msk, 0, 1 << N) {
		int cst = 0;
		vector<int> rikai(M, 0);

		rep(i, 0, N) if (msk & (1 << i)) {
			cst += C[i];
			rep(j, 0, M) rikai[j] += A[i][j];
		}

		bool ok = true;
		rep(i, 0, M) if (rikai[i] < X) ok = false;
		if (ok) chmin(ans, cst);
	}

	if (ans == inf) ans = -1;
	cout << ans << endl;
}







Measured memory_bytes: 3660
#include<stdio.h>
#include<math.h>
int exmax(int, int);
int exmin(int, int);
int main() {
	int a, i, xA, minv,maxv;
	maxv = -1*(int)pow(10, 9);
	scanf("%d%d", &a,&minv);
	for (i = 1; i < a ; i++) {
		scanf("%d", &xA);
		maxv = exmax(maxv, xA - minv);
		minv = exmin(minv, xA);
		if (i == a-1)
		{
			printf("%d", maxv);
		}
	}
	printf("\n");
	return 0;
}
int exmax(int x, int y) {
	if (x > y)
	{
		return x;
	}
	else
	{
		return y;
	}
}
int exmin(int x, int y) {
	if (x > y)
	{
		return y;
	}
	else {
		return x;
	}
	
}


Measured memory_bytes: 2108
#include<stdio.h>
int main()
{
	int a,b,c,d,i=0,j=0;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while(a>0)
	{
		a-=d;
		i++;
	}
	while(c>0)
	{
		c-=b;
		j++;
	}
	if(i<j)
	{
		printf("No");
	}
	else
	printf("Yes");
	return 0;
}

Measured memory_bytes: 1696
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,a,ak,h;
	cin>>n>>k>>a;
	h=a;
	for(int i=2;i<=n;i++)
	{
	    cin>>ak;
		a=__gcd(a,ak);
		h=max(ak,h);
	}
	if(k%a==0&&k<=h)
	{
	    cout<<"POSSIBLE"<<endl;
	}
	else
	{
	    cout<<"IMPOSSIBLE"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    string S;
    int result=0;
    cin >> S;
    VI N(S.size());
    transform(S.begin(), S.end(), N.begin(), [](char ch) { return ch - '0';});
    int next;
    if(N[0]==1){next=0;}else{next=1;}
    REP(i,S.size()-1){
        if(N[i+1]!=next){
            N[i+1==next];
            result++;
        }
        if(next==1){next=0;}else{next=1;}
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std ;
#define ll  long long 
#define dl long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second


int main ()
{
	
    ll n,m=0;
    cin >> n ;
    ll k = 1000;
    if (n%k==0)
    	cout<<0<<endl;
    else
    {
    	 ll i = 1;
    	 while (m<n)
    	 {
    	 	m = i*k;
    	 	i++;
    	
    	 }
    	 cout<<m-n<<endl;

    }

	return 0;

}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int n,m;
    cin >> n >> m;
    string a[n],b[m];
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    bool next = false;
    rep(i,n-m+1){
        rep(j,n-m+1){
            next = false;
            rep(v,m){
                rep(u,m){
                    if(a[i+v][j+u] != b[v][u]) next = true;
                    if(next) break;
                }
                if(next) break;
            }
            if(!next){
                cout << "Yes" << endl;
                return 0;
            }

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

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 3e5 + 5;


void debug_out() {
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    FAST
    int n;
    cin >> n;
    set<string> s;
    while (n--)
    {
        string h;
        cin>>h;
        s.insert(h);
    }
    cout<<s.size()<<endl;

        return 0;
}

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

typedef pair<int, int> II;
typedef vector< II > VII;
typedef vector<int> VI;

#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ll long long
#define fr(i,n) for(i=0;i<n;i++)

ll a[100010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,cnt=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        cnt+=abs(a[i]-a[i-1]);
    }
    cnt+=abs(a[i]-a[i-1]);
    for(i=1;i<=n;i++)
    {
        cout<<cnt-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
    }
    return 0;
}


Measured memory_bytes: 2048
n = int(input())
ans = -1
k = list(map(int, input().split()))
now = 1
while now:
    for i in range(n):
        if k[i] % 2 == 0 and k[i] != 0:
            k[i] = k[i] / 2
        else:
            now = 0
            break
    ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N;
vector<ll> num;
ll ans = 0;
ll before = 0;
bool operation(vector<ll>& A) {
  ll sum = 0;
  for (ll i = 0; i < N; ++i) {
    num.at(i) = A.at(i) / N;
    sum += num.at(i);
  }
  for (ll i = 0; i < N; ++i) {
    ans += A.at(i) / N;
    A.at(i) %= N;
    A.at(i) += (sum - num.at(i));
  }
  if (sum == 0) {
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  vector<ll> A(N);
  num = vector<ll>(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  bool check = false;
  while (!check) {
    check = operation(A);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <vector>
#include <string>
#include <cstring>
#include <cassert>
#include <complex>
#include <ctime>
#include <numeric>
using namespace std;

#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(unique(all(x)) - (x).begin())
#define ld long double
#define int long long

void SOLVE1() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector <int> A(a), B(b), C(c);
	for (int i = 0; i < a; i++) cin >> A[i];
	for (int i = 0; i < b; i++) cin >> B[i];
	for (int i = 0; i < c; i++) cin >> C[i];
	sort(rall(A));
	sort(rall(B));
	sort(all(C));
	vector <int> prefa(a);
	vector <int> prefb(b);
	for (int i = 0; i < a; i++) {
		prefa[i] = A[i];
		if (i) prefa[i] += prefa[i - 1];
	}
	for (int i = 0; i < b; i++) {
		prefb[i] = B[i];
		if (i) prefb[i] += prefb[i - 1];
	}
	int pos = C.size() - 1;
	int i = x - 1;
	int j = y - 1;
	int ans = 0;
	while (i >= 0 || j >= 0) {
		if (i >= 0 && j >= 0) {
			if (pos >= 0 && (C[pos] > A[i] || C[pos] > B[j])) {
				if (C[pos] > A[i] && C[pos] > B[j]) {
					if (A[i] == B[j]) {
						int t1 = i ? prefa[i - 1] : 0;
						int t2 = j ? prefb[j - 1] : 0;
						int tt1 = t1 + C[pos] + t2 + B[j];
						int tt2 = t1 + A[i] + t2 + C[pos];
						if (tt1 > tt2) {
							ans += C[pos--];
							i--;
						}
						else {
							ans += C[pos--];
							j--;
						}
					}
					else if (A[i] > B[j]) {
						ans += C[pos--];
						j--;
					}
					else if (A[i] < B[j]) {
						ans += C[pos--];
						i--;
					}
				}
				else if (C[pos] > A[i]) {
					ans += C[pos--];
					i--;
				}
				else if (C[pos] > B[j]) {
					ans += C[pos--];
					j--;
				}
			}
			else ans += A[i--] + B[j--];
		}
		else if (i >= 0) {
			if (pos >= 0 && C[pos] > A[i]) {
				ans += C[pos--];
				i--;
			}
			else ans += A[i--];
		}
		else if (j >= 0) {
			if (pos >= 0 && C[pos] > B[j]) {
				ans += C[pos--];
				j--;
			}
			else ans += B[j--];
		}
	}
	cout << ans << '\n';
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed;
	cout.precision(10);
	int Q = 1;
	//cin >> Q;
	while (Q--) {
		SOLVE1();
	}

	return 0;
}

Measured memory_bytes: 4224
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

struct Edge {
    int u, v, cost;
    Edge() {}
    Edge(int a, int b, int c) : u(a), v(b), cost(c) {}
};

signed main() {
    int L; cin >> L;

    int N = 0, K = 1;
    while(K <= L) N++, K *= 2;

    vector<Edge> edges;
    for(int i=0; i<N-1; i++) {
        edges.push_back(Edge(i+1, i+2, 0));
        edges.push_back(Edge(i+1, i+2, 1LL << i));
    }

    for(int i=N-2; i>=0; i--) {
        if(L - (1LL << i) >= (1LL << (N-1))) {
            edges.push_back(Edge(i+1, N, L - (1LL << i)));
            L -= (1LL << i);
        }
    }

    int M = edges.size();
    printf("%lld %lld\n", N, M);
    for(int i=0; i<M; i++) {
        printf("%lld %lld %lld\n", edges[i].u, edges[i].v, edges[i].cost);
    }
    return 0;
}

Measured memory_bytes: 256
import time
from random import randint
import copy
d = int(input())
c = list(map(int,input().split()))
starttime = time.time()
timelimit = 1.8
ans = []
fin = [1]*d
pen = [0]*26
sattemp = 0
sat = 0
sl = [list(map(int,input().split())) for i in range(d)]
for i in range(d):
    s = sl[i]
    sp = sum(pen)
    temp = -(10**9)
    for j in range(26):
        if s[j]-(sp-pen[j]) > temp:
            temp = s[j]-(sp-pen[j])
            tempans = j+1
    ans += [tempans]
    sat += s[tempans-1]-sp+pen[tempans-1]
    for j in range(26):
        pen[j] += c[j]
        pen[tempans-1] = 0
fin = ans
ans = []
pen = [0]*26
while time.time() - starttime <= timelimit:
    ans = fin.copy()
    d1 = randint(0,d-1)
    d2 = randint(d1,min(d-1,d1+15))
    if randint(0,1):
        ans[d1],ans[d2] = ans[d2],ans[d1]
        # print(1)
    else:
        ans[d1] = randint(1,26)
        # print(0)
    pen = [0]*26
    sattemp = 0
    for i in range(d):
        # print(i,fin,fin[i])
        s = sl[i]
        sp = sum(pen)
        tempans = ans[i]
        sattemp += s[tempans-1]-sp+pen[tempans-1]
        for j in range(26):
            pen[j] += c[j]
            pen[tempans-1] = 0
        # print(sattemp)
    if sattemp > sat:
        fin = ans
        sat = sattemp
for i in fin:
    print(i)

Measured memory_bytes: 89608
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

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

const ll INF = (ll)9e18;
int N, K;
vector<int> X, Y;
vector<pi> P;

int cnt_point(int xl, int xr, int yu, int yd) {
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		if ((P[i].first >= X[xl] && P[i].first <= X[xr])
			&& (P[i].second >= Y[yd] && P[i].second <= Y[yu]))
			++cnt;
		if (cnt >= K)
			break;
	}
	return cnt;
}

ll solve(void) {
	ll min_s = INF;
	for (int xl = 0; xl <= N - 2; ++xl) {
		for (int xr = xl + 1; xr <= N - 1; ++xr) {
			for (int yd = 0; yd <= N - 2; ++yd) {
				for (int yu = yd + 1; yu <= N - 1; ++yu) {
					int cnt = cnt_point(xl, xr, yu, yd);
					if (cnt >= K) {
						ll s = (ll)(X[xr] - X[xl]) * (Y[yu] - Y[yd]);
						min_s = min(s, min_s);
					}
				}
			}
		}
	}
	return min_s;
}

int main(void) {
	cin >> N >> K;
	X.resize(N);
	Y.resize(N);
	P.resize(N);
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		X[i] = x;
		Y[i] = y;
		P[i] = make_pair(x, y);
	}

	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	ll ans = solve();

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args){
		int[] array = new int[1 << 15];
		int[] prime = new int[1 << 15];
		
		int cnt = 0;
		
		array[1] = array[0] = 1;
		for(int i = 2; i < array.length; i++){
			if(array[i] == 0){
				// array[i] = 1;
				prime[cnt++] = i;
				for(int j = i * 2; j < array.length; j += i){
					array[j] = 1;
				}
			}
		}

		int n, ans;
		Scanner sc = new Scanner(System.in);
		while((n = sc.nextInt()) != 0){
			ans = 0;
			for(int i = 0; i < cnt && prime[i] + prime[i] <= n; i++){
				/*
				for(int j = i; j < cnt; j++){
					if(prime[i] + prime[j] == n){
						ans++;
					}
				}
				*/
				if(array[n-prime[i]] == 0)
					ans++;
			}
			
			System.out.println(ans);
		
		}
	}
}

Measured memory_bytes: 17876
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

/*int cal(int m,int l){

}*/
int main() {
   string s; cin >> s;
   int n = s.length();
   string s1 = s.substr(0,(n-1)/2 );
   string s2 = s.substr((n+3)/2 - 1, (n-1)/2);

   bool flag = true;

    for (int i = 0; i < s1.size(); ++i) {
        if(s1[i] != s1[s1.size() - (i + 1)])flag = false;
    }
    for (int i = 0; i < s2.size(); ++i) {
        if(s2[i] != s1[s2.size() - (i + 1)])flag = false;
    }

    if(flag)print("Yes");
    else print("No");
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();

		if ( N % 2 != 0 ) {
			System.out.println("No");
		} else {
			boolean ans = true;
			for ( int i = 0 ; i < N / 2 ; i++ ) {
				if ( S.charAt(i) != S.charAt(i + N / 2) ) {
					ans = false;
					break;
				}
			}
			System.out.println(ans ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	string s;cin>>s;
  if(s=="SAT") cout<<'1'<<endl;
  if(s=="FRI") cout<<'2'<<endl;
  if(s=="THU") cout<<'3'<<endl;
  if(s=="WED") cout<<'4'<<endl;
  if(s=="TUE") cout<<'5'<<endl;
  if(s=="MON") cout<<'6'<<endl;
  if(s=="SUN") cout<<'7'<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int now,n,k;

int main(){
  int ans=999999999;
  cin >> n;
  vector<int> a(n),csum(n+1,0);
  REP(i,n) cin>>a[i];
  REP(i,n) csum[i+1]=csum[i]+a[i];
  
  REP(i,n-1) ans=min(ans,abs(csum[n]-csum[i+1]-csum[i+1]));
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 int main(void){
   int a,b,c;
   cin >> a >> b >> c;
   int score =0;
   for (int day=1; ; day++){
       score+=a;
       if(day %7==0){
           score +=b;
           
       }
       if(score >=c){
           cout << (day) << endl;
           break;
       }
   }
 }


Measured memory_bytes: 3104
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn gcd(n: usize, m: usize) -> usize {
    match (n, m) {
        (n, 0) => n,
        (n, m) => gcd(m, n%m),
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let K: usize = sc.get();
    let mut ans = 0;
    for a in 1..=K {
        for b in 1..=K {
            for c in 1..=K {
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    println!("{}", ans);
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	int n;
	while (cin >> n, n) {
		string now; cin >> now;
		int ans = 0;
		rep(i, n - 1) {
			string next; cin >> next;
			if (now == "lu" && next == "ru") ans++;
			else if (now == "ru" && next == "lu") ans++;
			else if (now == "ld" && next == "rd") ans++;
			else if (now == "rd" && next == "ld") ans++;
			now = next;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll k;
int p[5005];
ll c[5005];
ll loop[5005],len[5005];
int dep[5005];
ll ans=-1LL<<35;
vector<ll> vi;

void dfs(int v,int d){
	if(dep[v]==-1){
		dep[v]=d;
		vi.push_back(c[v]);
		dfs(p[v],d+1);
	}else{
		ll sum=0;
		for(int i=0;i<min((int)k,dep[v]);i++){
			sum+=vi[i+1];
		}
		/*
		for(int i=0;i<vi.size();i++){
			printf("%lld ",vi[i]);
		}
		printf("\n");
		*/
		if(dep[v]>0)ans=max(ans,sum);
		if(k<=dep[v])return;
		ll rest=k-dep[v];
		ll su2=0;
		ll len=vi.size()-dep[v];
		for(int i=dep[v];i<vi.size();i++){
			su2+=vi[i];
		}
		//printf("%lld\n",su2);
		if(su2>0LL){
			if(rest>=len*2LL){
				ll cnt=(rest-len)/len;
				sum+=su2*cnt;
				rest-=cnt*len;
				ans=max(ans,sum);
			}
		}
		int pos=dep[v];
		for(int i=0;i<min(len*2,rest);i++){
			pos++;
			if(pos==vi.size()){
				pos=dep[v];
			}
			sum+=vi[pos];
			ans=max(ans,sum);
			//printf("%lld ",sum);
		}
		//printf("\n");
	}
}

int main(void){
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		p[i]--;
	}
	for(int i=0;i<n;i++){
		scanf("%lld",&c[i]);
	}
	for(int i=0;i<n;i++){
		memset(dep,-1,sizeof(dep));
		vi.clear();
		dfs(i,0);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3968
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())

if B1>A1:
  A1,A2,B1,B2=B1,B2,A1,A2
  
if A1*T1+A2*T2>B1*T1+B2*T2:
  print(0)
  exit()
if A1*T1+A2*T2==B1*T1+B2*T2:
  print("infinity")
  exit()

x=(T1*A1-T1*B1)//((B1-A1)*T1+(B2-A2)*T2)+1
ans=2*x-1
if (T1*A1-T1*B1)%((B1-A1)*T1+(B2-A2)*T2)==0:
  ans-=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, K;
  cin >> N >> M ;
  K = 2*M ;
  int L[M], R[M], A[K];
  
  for(int i=0; i<K; i++){
	cin >> A[i];
  }
  for(int i=0; i<M; i++){
    L[i] = A[2*i];
  }
    for(int i=0; i<M; i++){
    R[i] = A[2*i+1];
  }
  
  sort(L, L+M);
  sort(R, R+M);

  if(R[0]>=L[M-1])
  cout << -L[M-1] + R[0] +1 << endl;
  else
    cout << 0 << endl;
    
}

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

const int mod = 1000000007;
signed main(void)
{
	map<char, int> mp;
	long long ans;
	int n;
	string s;

	cin >> n >> s;
	rep(i, n)
	{
		mp[s[i]]++;
	}
	ans = 1;
	for(auto p : mp)
	{
		auto v = p.second;
		ans *= (v + 1);
		ans %= mod;
	}
	cout << ans - 1 << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 6666;
int n,m;
int f(int x, int y){
	x--;y--;
	rep(i,0,30)if((x>>i&1)!=(y>>i&1))return i+1;
}
int main() {
	read(n);
	rep(i,1,n-1){
		rep(j,i+1,n)printf("%d ",f(i,j));
		puts("");
	}
	return 0;
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val vs = readLine()!!.split(" ").map { it.toInt() }
    val cs = readLine()!!.split(" ").map { it.toInt() }

    var ans = 0
    for (i in 0 until n) {
        if (vs[i] - cs[i] > 0) {
            ans += vs[i] - cs[i]
        }
    }
    println(ans)
}

Measured memory_bytes: 37748
#include <stdio.h>
#include <ctype.h>


int main(int argc, const char * argv[]) {
    char c;
    while(1){
        scanf("%c",&c);
        if(islower(c)){
            c = toupper(c);
        }else if(isupper(c)){
            c = tolower(c);
        }else if(c == '\n'){
            printf("\n");
            break;
        }
        printf("%c",c);
        
    }
    return 0;
}

Measured memory_bytes: 524
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll n, a[5];
    cin >> n;
    for(int i = 0; i < 5; i++)  cin >> a[i];

    ll ans = (n+a[0]-1)/a[0];
    for(int i = 1; i < 5; i++){
        if(a[i] > a[i-1]){
            ans++;
        }else{
            ans = max(ans+1, i + (n+a[i]-1)/a[i]);
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    ll n, a, place[200005], ans=0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a;
        place[a] = i;
    }

    set<ll> s;
    s.insert(0);
    s.insert(n+1);

    for (ll i = 1; i <= n; i++) {
        auto x = s.upper_bound(place[i]);
        auto y = x--;
        ans += i * (*x - place[i]) * (place[i] - *y);
        s.insert(place[i]);
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
const int N=305;
double dp[N][N][N];
int n,a,b,c,x;
double dfs(int A,int B,int C)
{
	if(!A&&!B&&!C)return 0;
	if(dp[A][B][C]!=0.00)return dp[A][B][C];
	double sum=1;
	if(A)
	{
		sum+=(double)A*dfs(A-1,B,C)/(double)n;
	}
	if(B)
	{
		sum+=(double)B*dfs(A+1,B-1,C)/(double)n;
	}
	if(C)
	{
		sum+=(double)C*dfs(A,B+1,C-1)/(double)n;
	}
	sum+=sum/(double)(A+B+C)*(double)(n-A-B-C);
	return dp[A][B][C]=sum;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;if(x==1)a++;else if(x==2)b++;else c++;
	}
	double ans=dfs(a,b,c);
	printf("%.13f\n",ans);
	return 0;
}

Measured memory_bytes: 219392
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    REP (i, 0, N) cin >> v[i];
    vector<double> pos(N, 0.0);
    REP (i, 1, N) {
        REP (j, 0, i) {
            double x = sqrt((v[i] + v[j]) * (v[i] + v[j]) - (v[i] - v[j]) * (v[i] - v[j]));
            pos[i] = max(pos[i], pos[j] + x);
        }
    }
    const double inf = 1e+15;
    double m = inf, M = -inf;
    REP (i, 0, N) {
        m = min(m, pos[i] - v[i]);
        M = max(M, pos[i] + v[i]);
    }
    cout << fixed << setprecision(10) << M - m << endl;
    return 0;
}


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

#define int long long
#define ll long long
#define pb push_back

main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double pi = 3.14159265359;
    double fi = (double(60) - m) / double(60) * 360;
    double se = (double(12) - h - m / double(60)) / double(12) * 360;
    double k = abs(se - fi);
    if (k > 180) k = 360 - k;
    cout << fixed << setprecision(10) << sqrt(a * a + b * b - 2 * a * b * cos(k / 180 * pi));
}


Measured memory_bytes: 4160
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,k;
    cin >> n >> k;
    if(k <= (n + 1) / 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
N, = map(int, raw_input().split())
t = 0
nt = []
for i in range(N):
  s, = map(int, raw_input().split())
  t += s
  if s%10>0:
    nt.append(s)
if t%10==0:
  if nt:
    t -= min(nt)
print t if t%10>0 else 0

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

typedef pair<int, pair<int, int>> IntTriple;
IntTriple make_itriple(int i, int j, int k){ return make_pair(i, make_pair(j, k)); }
int get1st(IntTriple t){ return t.first; }
int get2nd(IntTriple t){ return t.second.first; }
int get3rd(IntTriple t){ return t.second.second; }

int main()
{
  int x, y, z, n;
  cin >> x >> y >> z >> n;

  long long a[x];
  for (int i = 0; i < x; i++){
    cin >> a[i];
  }

  long long b[y];
  for (int i = 0; i < y; i++){
    cin >> b[i];
  }

  long long c[z];
  for (int i = 0; i < z; i++){
    cin >> c[i];
  }

  sort(a, a+x, greater<long long>()); // new item for me: sort and greater<T>()
  sort(b, b+y, greater<long long>());
  sort(c, c+z, greater<long long>());

  set<IntTriple> s;
  priority_queue<pair<long long, IntTriple>> q;

  q.push(make_pair(a[0]+b[0]+c[0], make_itriple(0, 0, 0)));
  s.insert(make_itriple(0, 0, 0));

  for (int ct = 0; ct < n; ct++){
    long long score = q.top().first;
    IntTriple t = q.top().second;
    q.pop();

    cout << score << endl;

    int i = get1st(t);
    int j = get2nd(t);
    int k = get3rd(t);

    // CAUTION : I shot my foot by forgetting the range check of "i < x-1" etc.
    if ((i < x-1) && s.find(make_itriple(i+1, j, k)) == s.end()){
      q.push(make_pair(a[i+1]+b[j]+c[k], make_itriple(i+1, j, k)));
      s.insert(make_itriple(i+1, j, k));
    }

    if ((j < y-1) && s.find(make_itriple(i, j+1, k)) == s.end()){
      q.push(make_pair(a[i]+b[j+1]+c[k], make_itriple(i, j+1, k)));
      s.insert(make_itriple(i, j+1, k));
    }

    if ((k < z-1) && s.find(make_itriple(i, j, k+1)) == s.end()){
      q.push(make_pair(a[i]+b[j]+c[k+1], make_itriple(i, j, k+1)));
      s.insert(make_itriple(i, j, k+1));
    }
  }
}


Measured memory_bytes: 896
def quick_sort(seq, left, right):
  if left >= right - 1 and seq[left] <= seq[right]:
    return 0
  mid = (left + right)//2
  pivot = seq[mid]
  L = left
  R = right
  while True:
    if seq[L] >= pivot and seq[R] <= pivot:
      seq[L], seq[R] = seq[R], seq[L]
      L += 1
      R -= 1
    elif seq[L] >= pivot:
      R -= 1
    elif seq[R] <= pivot:
      L += 1
    else:
      L += 1
      R -= 1
    if L >= R:
      break
  '''if L == R:
    if seq[L] >= mid:
      R -= 1'''
  quick_sort(seq,left,R)
  quick_sort(seq,L,right)
  return seq

N = int(input())
vec = list(map(int,input().split()))
quick_sort(vec,0,N-1)
ans = vec[0]
for i in range(N-1):
  ans = (ans + vec[i+1])/2
print(ans)




Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<limits>

// 隣接リスト
using weight_graph = std::vector<std::vector<std::pair<size_t, size_t>>>;

int main(){
    
    size_t vertex, edge, root;
    std::cin >> vertex >> edge >> root;

    weight_graph graph(vertex);

    for(size_t i = 0; i < edge; i++){
        size_t s, t, w;
        std::cin >> s >> t >> w;
        graph.at(s).emplace_back(t, w);
    }

    std::vector<size_t> cost(vertex, std::numeric_limits<size_t>::max()); // 添字までのコスト
    std::vector<bool> seen(vertex, false); // 添字に訪れたかどうか
    std::priority_queue<std::pair<size_t, size_t>, // first: 重み, second: 頂点番号
                        std::vector<std::pair<size_t, size_t>>, 
                        std::greater<std::pair<size_t, size_t>>> candidate;

    cost.at(root) = 0; // rootへのコストは0
    candidate.emplace(0, root); // rootを候補へ

    while(!candidate.empty()){ // ダイクストラ
        auto node = candidate.top(); candidate.pop();
        auto v = node.second;

        if(seen.at(v)) continue;
        seen.at(v) = true;

        if(cost.at(v) < node.first) continue; // 小手先の最適化
                                              // (訪れる頂点への最短経路コストが辺の重みより小さい場合最短経路に含まれることはない)

        for(size_t i = 0; i < graph.at(v).size(); i++){
            if(cost.at(v) + graph.at(v).at(i).second < cost.at(graph.at(v).at(i).first)){
                cost.at(graph.at(v).at(i).first) = cost.at(v) + graph.at(v).at(i).second;
                candidate.emplace(cost.at(graph.at(v).at(i).first), graph.at(v).at(i).first);
            }
        }
    }

    for(const auto& e : cost){
        if(e == std::numeric_limits<size_t>::max()){
            std::cout << "INF" << std::endl;
        }else{
            std::cout << e << std::endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 19372
#include<bits/stdc++.h>
#define li long long int
using namespace std;
int main(){
    li n;
    cin>>n;
    if(n>=400&&n<600)
    cout<<8<<endl;
    if(n>=600&&n<800)
    cout<<7<<endl;
    if(n>=800&&n<1000)
    cout<<6<<endl;
    if(n>=1000&&n<1200)
    cout<<5<<endl;
    if(n>=1200&&n<1400)
    cout<<4<<endl;
    if(n>=1400&&n<1600)
    cout<<3<<endl;
    if(n>=1600&&n<1800)
    cout<<2<<endl;
    if(n>=1800&&n<2000)
    cout<<1<<endl;
    
}

Measured memory_bytes: 3564
k = int(input())
lundex = [1,2,3,4,5,6,7,8,9]
count = 9
for i in lundex:
    for j in range(0,10):
        new = str(i)+str(j)
        l = len(new)
        if abs(int(new[l-2])-int(new[l-1]))<=1:
            lundex.append(int(new))
            count += 1
        if count >= k:
            break
    if count >= k:
        break
print(lundex[k-1])

Measured memory_bytes: 7060
#include <iostream>

int main(){
    long N;

    std::cin >> N;

    long count = 0;
  
    long aN = 0;
  
    if ( N % 2 == 0 ) aN = N/2;
    else aN = N/2 + 1;
  
    count = N - aN;
  
    for ( long A = 1; A < aN; A++ ) {
        for ( long B = 1; B < N; B++){
            if (N <= A*B) break;
            count++;
        }
    } 

    std::cout << count;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int H = Integer.parseInt(scan.next());
	int W = Integer.parseInt(scan.next());

	StringBuilder str = new StringBuilder();
	for (int i = 0; i < W+2; i++) {
	    str.append("#");
	}
	str.append("\n");
	for (int i = 0; i < H; i++) {
	    str.append("#");
	    str.append(scan.next());
	    str.append("#\n");
	}
	for (int i = 0; i < W+2; i++) {
	    str.append("#");
	}
	System.out.println(str.toString());
	scan.close();
    }
}


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

#define ll long long



using namespace std;

ll s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    ll xa = 0;
    ll ya = 0;
    ll xc = 1;
    ll xb = 1000000000;
    ll yb = (1000000000 - s % 1000000000) % 1000000000;
    ll yc = (s + 1000000000 - 1) / 1000000000;
    cout << xa << " " << ya << " " << xb << " " << yb << " " << xc << " " << yc << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> PII;
int a,b;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a

int MAXX(vector<int> v,int k){
int max=0;
REP(i,k){
if(v[i]>=max){max=v[i];}
}
return max;
}

int main(){
  int n,a,max,mmax=0,cnt=0;
  cin>>n;
  vector<int> v(n);
  REP(i,n)cin>>v[i];
max=MAXX(v,n);
  REP(i,n){
  if(max>v[i]&&v[i]>=mmax){
    mmax=v[i];
  }
  }
  REP(i,n){if(max==v[i])cnt++;}
  if(cnt==1){
    REP(i,n){
  if(v[i]==max){cout<<mmax<<endl;}
  
      else cout<<max<<endl;
   
      }
  }
  else {
  REP(i,n){
  cout<<max<<endl;
  }
  }
  
return 0;
}

Measured memory_bytes: 2416
#include <bits/stdc++.h>
#define ll  long long
#define ld  long double
#define endl "\n"
#define ull  unsigned long long
#define pb push_back
#define all(v) ((v).begin()),((v).end())
#define vi   vector<ll>
#define INF 1000000000
#define M ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
	M
	ll n; cin>>n;
	ll dp[100005][3]={},a[100005],b[100005],c[100005];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			if(i==0){
				if(j==0) dp[i][j]=a[i];
				else if(j==1) dp[i][j]=b[i];
				else dp[i][j]=c[i];
			}
			else{
				for(int k=0;k<3;k++){
					if(j==k) continue;
					if(j==0) dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i]);
					else if(j==1) dp[i][j]=max(dp[i][j],dp[i-1][k]+b[i]);
					else dp[i][j]=max(dp[i][j],dp[i-1][k]+c[i]);
				}
			}
		}
	}
	ll ans=0;
	ans=max(ans,dp[n-1][0]);
	ans=max(ans,dp[n-1][1]);
	ans=max(ans,dp[n-1][2]);
	cout<<ans<<endl;
	return 0;
}


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

#define mod 1'000'000'007
typedef long long ll;

template<typename T>
void deb(initializer_list<T> l)
{
	for (auto &e : l)
		cout << e << ' ';
	cout << endl;
}

void solve()
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	int min1 = h1 * 60 + m1;
	int min2 = h2 * 60 + m2;
	min2 -= k;
	cout << min2 - min1 << '\n';
}

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

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}


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

void fnInput(vector<string>& rvsGrid)
{
  int nHigh, nWide;
  cin >> nHigh >> nWide;

  rvsGrid.resize(nHigh);
  for (int ny = 0; ny < nHigh; ny++)
    cin >> rvsGrid[ny];
}

int fnRepaint(int ny, int nx, const vector<string>& cnrvsGrid)
{
  if (   ny >= 0  && ny < cnrvsGrid.size()
      && nx >= 0  && nx < cnrvsGrid[ny].size())
    if (cnrvsGrid[ny][nx] == '#')
      return 1;
    else;

  return 0;
}

int fnGridRepaint(const vector<string>& cnrvsGrid)
{
  const vector<int> cnvnDy = {-1,  0,  1,  0};
  const vector<int> cnvnDx = { 0, -1,  0,  1};

  for (int ny = 0; ny < cnrvsGrid.size(); ny++)
  {
    for (int nx = 0; nx < cnrvsGrid[ny].size(); nx++)
    {
      if (cnrvsGrid[ny][nx] == '#')
      {
        bool bRslt = false;
        for (int i = 0; i < cnvnDy.size(); i++)
        {
          if (fnRepaint(ny + cnvnDy[i], nx + cnvnDx[i], cnrvsGrid))
            bRslt = true;
        }
        if (!bRslt)  return 0;
      }
    }
  }
  return 1;
}

int main()
{
  vector<string> vsGrid;

  fnInput(vsGrid);
  if (fnGridRepaint(vsGrid))  cout << "Yes" << endl;
  else                        cout << "No"  << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n;cin>>n;
    string s;cin>>s;
    vector<ll> cnt(26,0);
    for(int i=0;i<n;i++){
        cnt[(int)(s[i]-'a')]++;
    }
    ll ans=1;
    for(int i=0;i<26;i++){
        if(cnt[i]>0) ans=ans*(cnt[i]+1)%MOD;
    }
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 512