akhauriyash/Code-Regression huggingface dataset:
module deque_mod
    use,intrinsic :: iso_fortran_env
    implicit none
    type deque
        integer(int32),pointer:: v(:)
        integer(int32):: l,r
        integer(int32):: lmax, rmax
    end type
    private
    public:: deque
    public:: init_deque
    public:: append, appendleft
    public:: pop, popleft
    public:: right, left
    public:: remaining_elements
    public:: remain

contains
    subroutine init_deque(dq)
        ! 初期化
        type(deque):: dq
        dq%r=0; dq%rmax=1
        dq%l=1; dq%lmax=-1
        allocate(dq%v(dq%lmax:dq%rmax))
    end subroutine


    subroutine append(dq,num)
        ! 右端に挿入
        type(deque):: dq
        integer(int32):: num
        if (dq%r+1 > dq%rmax) call add_(dq)
        dq%r=dq%r+1
        dq%v(dq%r) = num
    end subroutine

    subroutine appendleft(dq,num)
        ! 左端に挿入
        type(deque):: dq
        integer(int32):: num
        if (dq%l-1 < dq%lmax) call add_(dq)
        dq%l=dq%l-1
        dq%v(dq%l) = num
    end subroutine

    subroutine add_(dq)
        ! arrayの延長
        type(deque):: dq
        integer(int32):: l
        integer(int32),pointer:: tmp(:)
        l = size(dq%v)
        allocate(tmp(l))
        tmp(:) = dq%v(:)
        deallocate(dq%v)
        allocate(dq%v(4*dq%lmax:4*dq%rmax))
        dq%v(dq%lmax:dq%rmax) = tmp(:)
        dq%lmax = 4*dq%lmax
        dq%rmax = 4*dq%rmax
    end subroutine


    function pop(dq) result(ret)
        ! 右端から取り出し
        type(deque):: dq
        integer(int32):: ret
        ret = dq%v(dq%r)
        dq%r=dq%r-1
    end function

    function popleft(dq) result(ret)
        ! 左端から取り出し
        type(deque):: dq
        integer(int32):: ret
        ret = dq%v(dq%l)
        dq%l=dq%l+1
    end function


    function right(dq) result(ret)
        ! 右端を確認
        type(deque):: dq
        integer(int32):: ret
        ret = dq%v(dq%r)
    end function

    function left(dq) result(ret)
        ! 左端を確認
        type(deque):: dq
        integer(int32):: ret
        ret = dq%v(dq%l)
    end function

    function remaining_elements(dq) result(ret)
        ! 残りの要素数
        type(deque):: dq
        integer(int32):: ret 
        ret = dq%r - dq%l + 1
    end function

    function remain(dq) result(ret)
        ! 要素が残っているかどうか
        type(deque):: dq
        logical:: ret
        ret = remaining_elements(dq) > 0
    end function
end module


program name
    use,intrinsic :: iso_fortran_env
    use deque_mod
    implicit none
    integer(int32):: n,i
    integer(int32), allocatable:: a(:), ans(:)
    type(deque):: b

    call init_deque(b)
    read*, n
    allocate(a(n),ans(n))
    read*, a(:)

    do i=1,n
        if (mod(i,2) == 1) then
            call append(b,a(i))
        else
            call appendleft(b,a(i))
        end if
    end do

    if (mod(n,2) /= 0) then
        do i=1,n
            ans(i) = pop(b)
        end do
    else
        do i=1,n
            ans(i) = popleft(b)
        end do
    end if

    print'(100000(i0,1x))', ans(:)




end program name

Measured memory_bytes: 7288
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

long long factorial(long long a){
	if(a == 0) return 1;
	return a*factorial(a-1);
}

int main(){	
	

	int n;
	cin>>n;
	string s;
	map<string,int> m;
	long long res = 0;
	for(int i =0;i<n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		if(m.find(s) == m.end()){
			m[s] = 1;
		}
		else{
			m[s]++;
		}
	}
	for(auto it= m.begin();it!=m.end();it++){
		res+=(  ((it->second)*1LL*( (it->second) - 1))/2    );
	}
	cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
#define f first
#define s second
const int MAX=1000*100+5;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	set<int>A;
	rep(i,0,3)
	{
		int a;cin>>a;
		A.insert(a);
		}
		if(A.size()==2){
			cout<<"Yes\n";
		}else cout<<"No\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x,2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vd = vector<long double>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
const int MOD = 1e9 + 7;
vector<long long> fact, fact_inv, inv;
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}
const ll mod = 1000000007;
int main() {
  init_nCk(2000);
  ll first,n,s,ans=0,t;
  cin >> first;
  n=first/3;
  REP(i,1,n+1){//i個に分ける
    s=first;
    s-=2*i;
    ans+=nCk(s-1,i-1);
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define nl '\n'
#define ff first
#define ss second
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */
     
     
     
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0); srand(time(0));
     
  string s; cin >> s;
  size_t k; cin >> k;
  size_t n = s.length();
  set<string> S;
  for(size_t len = 1; len <= min(n, k); len++) {
    for(size_t i=0; i+len <= n; i++) {
      S.emplace(s.substr(i, len));
      while( S.size() > k ) S.erase(--S.end());
    }
  }
  cout << *S.rbegin() << nl;

  return 0;
}
     
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


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

using namespace std;
#define ll long long int

ll dp[2020];
int main()
{
    ll a,b,n;
    cin >> a >> b >> n;
    if(n>=b)
    n = min(b,n)-1;
    ll ans = (a*n)/b;
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
int main(){
    int a=0,n;
    char s[100];
    scanf("%d %s",&n,s);
    if(n%2==1){
        printf("No\n");
        return 0;
    }
    for(int i=0;i<n/2;i++){
        if(strncmp(&s[i],&s[i+n/2],1)==0){
            a++;
        }
    }
    if(a==n/2){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(z) (z).begin(),(z).end() 
#define MOD 1000000007
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll isprime(ll n)
{
	for(int i=2;i<n;i++)
		if(n%i==0)
		return 0;
		
	return 1;	
}
int main()
{ 
    FAST;
	long double n,d;
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(32);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve(){
    ll n, x;
    cin >> n;
    ll ans = 0;
    for(ll i = 1 ; i <= n ; i++){
        cin >> x;
        if(x&1 && i&1)
            ans++;
    }
    cout << ans << nl;
}

int main(){
    boost;
    // cal(3);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


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

// template {{{
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define sort_by(x, y) sort(all(x), [&](const auto& a, const auto& b) { return y; })

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;

using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;

template<typename T> void ckmin(T& a, const T& b) { a = min(a, b); }
template<typename T> void ckmax(T& a, const T& b) { a = max(a, b); }

int m = 1000000007;
int cntSeq(int sumSoFar, vector<int>& dp)
{
    if(sumSoFar == 0)
    {
        return 1;
    }
    if(dp[sumSoFar] == -1)
    {
        int sum1 = 0;
        for(int i=3; sumSoFar - i >=0; i++)
        {
            sum1 = (sum1%m + cntSeq(sumSoFar-i, dp)%m)%m;
        }
        dp[sumSoFar] = sum1;
    }
    return dp[sumSoFar];
}
void solve()
{
    int n;
    cin>>n;
    vector<int>dp(n+5, -1);
    cout<<cntSeq(n, dp)<<endl;
}
int main() {
    
      solve();

    return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string S; cin >> S;
    int ans = 0;
    for(int i = 2; i < S.length()-1; i += 2)
    {
        int m = (S.length() - i) / 2;
        string s1 = S.substr(0, m);
        string s2 = S.substr(m, m);
        if(s1 == s2) ans = max(ans, (int)S.length()-i);
    }
    cout << ans << endl;
}

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

    return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10**9+7
c = pow(2,n,mod)
def nCr(n, r, mod):
	r = min(r, n-r)
	numer = denom = 1
	for i in range(1, r+1):
		numer = numer * (n+1-i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod-2, mod) % mod
c -= 1
aa = nCr(n,a,mod)
bb = nCr(n,b,mod)
c -= (aa+bb)
print (c%mod)


Measured memory_bytes: 38512
def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: x[1])
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


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

using namespace std;

int main()
{
	int N, *A, maxD;

	cin >> N;

	A = new int[N];

	maxD = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		for (int j = 0; j < i; j++)
		{
			maxD = max(abs(A[i] - A[j]), maxD);	
		}	
	}

	cout << maxD << endl;

	delete A;

	return 0; 
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  for (int &v : a) cin >> v;
  for (int &v : b) cin >> v;
  
  int ans = (*min_element(a.begin(), a.end()))+(*min_element(b.begin(), b.end()));
  while (M--) {
   int x, y, c;
    cin >> x >> y >> c;
    --x, --y;
    ans = min(ans, a[x]+b[y]-c);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=1e2+10;

int N,A[maxm],B[maxm];

int main(){
	register int i,j,k;
	register bool Find;
	scanf("%d",&N);
	for(i=1;i<=N;i++) scanf("%d",&A[i]);
	for(i=N;i;i--){
		Find=true;
		for(j=i;j;j--){
			if(A[j]==j){
				B[i]=j;
				for(k=j;k<i;k++) A[k]=A[k+1];
				Find=false;
				break;
			}
		}
		if(Find){
			printf("-1");
			return 0;
		}
	}
	for(i=1;i<=N;i++) printf("%d\n",B[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    string s;
    cin >> s;
    int ans;
    if(s == "SUN") ans = 7;
    if(s == "MON") ans = 6;
    if(s == "TUE") ans = 5;
    if(s == "WED") ans = 4;
    if(s == "THU") ans = 3;
    if(s == "FRI") ans = 2;
    if(s == "SAT") ans = 1;

    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    string S, T;
    bool flag;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++) {
        flag = true;
        for (int j = 0; j < S.size(); j++) {
            // cout << S[(i + j) % S.size()] << endl;
            // cout << T[j] << endl;
            if (S[(i + j) % S.size()] != T[j]) {
                flag = false;
            }
        }
        if (flag) {
            Yes;
            return 0;
        }
    }
    No;
}


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

using namespace std;

#define MAX_N 305

int n;
double dn, dp[MAX_N][MAX_N][MAX_N];
bool v[MAX_N][MAX_N][MAX_N];

double f_imp(int, int, int);

double f(int a, int b, int c)
{
	if (a < 0 || b < 0 || c < 0)
		return 0;
	if (!v[a][b][c])
	{
		v[a][b][c] = true;
		dp[a][b][c] = f_imp(a, b, c);
	}
	return dp[a][b][c];
}

double f_imp(int a, int b, int c)
{
	if (a + b + c == 0)
		return 0;
		
	return (((n - a - b - c)/dn) + (a/dn)*(1 + f(a - 1, b, c)) + (b/dn)*(1 + f(a + 1, b - 1, c)) + (c/dn)*(1 + f(a, b + 1, c - 1)))/((a + b + c)/dn);
}

int main()
{
	scanf("%d", &n);
	dn = n;
	int a[3];
	a[0] = 0;
	a[1] = 0;
	a[2] = 0;
	for (int i = 0; i < n; i++)
	{
		int t;
		scanf("%d", &t);
		t--;
		a[t]++;
	}
	printf("%.11lf\n", f(a[0], a[1], a[2]));
}


Measured memory_bytes: 246016
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = 998244353;
const ll INF = 1LL << 61;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N>>A>>B;
    if(A*B < N || A+B > N+1){
        cout<<-1<<endl;
        return 0;
    }
    vec ans(N);
    rep(i,N) ans[i] = N - i;
    //reverse(ans.begin(), ans.begin() + 2);
    for(ll i = N; i >= 0; i -= A){
        ll left = max({0LL, i - A, --B});
        reverse(ans.begin() + left, ans.begin() + i);
    }
    rep(i,N) cout<<ans[i]<<(i == N - 1 ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 4480
#include<stdio.h>
#include<stdlib.h>

#define N_MAX 100000
#define M_MAX 100000
#define Q_MAX 100000

typedef struct tag_edge_t
{
	int from, to;
	struct tag_edge_t *next;
}edge_t;

typedef struct
{
	int id, c, x, d, y;
	edge_t *edge;
}node_t;

typedef struct
{
	int v, d, c, x;
}cmd_t;


#define QUE_SIZE Q_MAX*10

node_t node[N_MAX+1];
edge_t edge[M_MAX*2];
cmd_t cmd[Q_MAX];
cmd_t que[QUE_SIZE];
int que_start, que_end;
int g_count;

void que_init(void)
{
	que_start=que_end=0;
}

int que_push(cmd_t cmd)
{
	que[(que_end++)%QUE_SIZE]=cmd;
	if(que_end>=que_start+QUE_SIZE)
	{
		printf("que_start=%d\n", que_start);
		printf("que_end=%d\n", que_end);
		exit(1);
	}
	return 1;
}


int que_pop(cmd_t *cmd)
{
	if(que_end<=que_start) return 0;

	*cmd=que[(que_start++)%QUE_SIZE];
	if(que_start>=QUE_SIZE)
	{
		que_start-=QUE_SIZE;
		que_end-=QUE_SIZE;
	}
	return 1;
}


void paint(cmd_t cmd)
{
	edge_t *edge;
	cmd_t cmd2;

	que_init();
	que_push(cmd);
	while(que_pop(&cmd))
	{
		if(node[cmd.v].x==cmd.x) continue;
		if(node[cmd.v].x<0) g_count++;

		if(node[cmd.v].x<cmd.x)
		{
			node[cmd.v].c=cmd.c;
			node[cmd.v].x=cmd.x;
			node[cmd.v].d=cmd.d;
		}
		else
		{
			if(node[cmd.v].d>=cmd.d) continue;
		}

		if(cmd.d<1) continue;

		cmd2=cmd;
		cmd2.d--;
		edge=node[cmd.v].edge;
		for(;edge;edge=edge->next)
		{
			if(node[edge->to].x==cmd.x) continue;
			if(node[edge->to].y==cmd.x) continue;
			cmd2.v=edge->to;
			node[edge->to].y=cmd.x;
			que_push(cmd2);
		}
	}
//	printf("\n");
}


int cmp(const void *pa, const void *pb)
{
	const cmd_t *a, *b;
	a=pa;
	b=pb;
	if(a->d>b->d) return -1;
	return a->d<b->d;
}


int cmp2(const void *pa, const void *pb)
{
	const cmd_t *a, *b;
	a=pa;
	b=pb;
	if(a->d<b->d) return -1;
	return a->d>b->d;
}


int main(void)
{
	int N, M, Q;
	int a, b;
	int i;

	while(scanf("%d%d", &N, &M)==2)
	{
		for(i=1;i<=N;i++)
		{
			node[i].id=i;
			node[i].c=0;
			node[i].edge=NULL;
			node[i].x=-1;
			node[i].y=-1;
		}
		for(i=0;i<M;i++)
		{
			scanf("%d%d", &a, &b);
			edge[i*2  ].next=node[a].edge;
			edge[i*2  ].from=a;
			edge[i*2  ].to=b;
			node[a].edge=&edge[i*2  ];
			edge[i*2+1].next=node[b].edge;
			edge[i*2+1].from=b;
			edge[i*2+1].to=a;
			node[b].edge=&edge[i*2+1];
		}
		scanf("%d", &Q);
		for(i=0;i<Q;i++)
		{
			scanf("%d%d%d", &cmd[i].v, &cmd[i].d, &cmd[i].c);
			cmd[i].x=i;
		}
//		qsort(cmd, Q, sizeof(cmd_t), cmp2);
//		for(i=0;i<Q;i++) printf("cmd %d,%d,%d,%d\n", cmd[i].v, cmd[i].d, cmd[i].c, cmd[i].x);
		g_count=0;
		for(i=Q-1;i>=0;i--)
		{
			paint(cmd[i]);
			if(g_count>=N) break;
		}
		for(i=1;i<=N;i++) printf("%d\n", node[i].c);
	}

	return 0;
}


Measured memory_bytes: 23936
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    vector<ll> b(n);
    rep(i,n) cin >> b[i];
    #define SZ(x) (int)x.size()
    vector<ll> ans;
    auto remove = [&](auto index){
        auto itr = b.begin();
        itr += index;
        b.erase(itr);
        return ;
    };
    bool ok = true;
    while(SZ(b)){
        bool temp = false;
        for(int i = SZ(b) - 1; 0 <= i; i--){
            if(b[i] == i+1){
                ans.emplace_back(i+1);
                remove(i);
                temp = true;
                break;
            }
        }
        ok &= temp;
        if(!temp)break;
    }

    reverse(all(ans));
    if(ok){
        for(auto i : ans)cout << i << "\n";
    }
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2010;
string A, B;
int L[maxN], R[maxN];
int n;

int main() {
	cin >> A >> B; 
	n = B.size();
	bool fun = 0;
	for (auto c : B) fun |= c-'0';
	if (not fun) return cout << (A == B)-1 << endl, 0;
	int fst = n, lst = -1; 
	for (int i = 0; i < n; ++i) {
		if (B[i] == '1') {
			fst = min(fst, i);
			lst = max(lst, i);
		}
	}
	for (int i = 0; i < n; ++i) L[i] = R[i] = n;
	int d = lst-n;
	for (int i = 0; i < n; ++i) {
		if (B[i] == '1') d = i;
		L[i] = min(i==0?n:L[i-1]+1, i - d);
	}
	d = n+fst;
	for (int i = n-1; i >= 0; --i) {
		if (B[i] == '1') d = i;
		R[i] = min(i==n-1?n:R[i+1]+1, d-i);
	}
	int ans = 3*n;
	for (int r = -n+1; r < n; ++r) {
		int cnt = 0, lans = abs(r);
		vector<pair<int, int>> p;
		for (int i = 0; i < n; ++i) {
			if (A[i] != B[(i+r+n)%n]) {
				cnt += 1;
				p.push_back({R[i], L[i]});
			}
		}
		if (not p.empty()) lans = 1e9;
		typedef pair<int, int> ii;
		sort(begin(p), end(p), [](ii a, ii b) {
			return a.first > b.first or a.first == b.first
			and a.second < b.second;
		});
		//cout << "**************" << endl;
		//cout << r << " " << cnt << endl;
		//for (auto e : p) cout << e.first << " " << e.second << endl;
		int mn = -1e9;
		for (auto& e : p) {
			e.second = max(e.second, mn);
			mn = e.second;
		}
		reverse(begin(p), end(p));
		p.push_back({0, 0});
		int lastx = 0;
		for (auto& e: p) {
			if (r >= 0)
				lans = min(lans, 2*(max(r, lastx) + e.second) - r);
			else
				lans = min(lans, 2*(lastx + max(e.second, -r)) + r);			
			lastx = e.first;
		}		 
		ans = min(ans, lans + cnt);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int digitSum(int N){
  int a=0;
  while(N>0){
    a = a+ N%10;
    N = N/10;
  }
  return a;
}
int main(){
  int N;
  cin>>N;
  int a,b;
  a=1;
  b=N-a;

  int c;
  int res=N;
  N=N/2 + 1;
  FOR(i,0,N){
    c=digitSum(a)+digitSum(b);
    if(res>=c) res=c;
    a++;
    b--;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    int s, w; cin>>s>>w;
    if(w>=s){
        cout<<"unsafe";
    }
    else
        cout<<"safe";
}

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    solve();
    return 0;
}





Measured memory_bytes: 3652
def match(y, x):
    ret = True
    for i in range(M):
        for j in range(M):
            if A[y + i][x + j] != B[i][j]:
                ret = False
    return ret


N, M = map(int, input().split())

A = []

for i in range(N):
    A.append(list(input()))

B = []

for i in range(M):
    B.append(list(input()))

flg = False

for i in range(N - M + 1):
    for j in range(N - M + 1):
        if match(i, j):
            flg = True

print("Yes" if flg else "No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> t(n), a(n);
    rep(i, 0, n) cin >> t[i];
    rep(i, 0, n) cin >> a[i];
    vector<bool> f(n), g(n);
    f[0] = true;
    rep(i, 1, n){
        if(t[i] != t[i - 1]) f[i] = true;
    } 
    g[n - 1] = true;
    repr(i, n - 2, 0){
        if(a[i] != a[i + 1]) g[i] = true;
    }
    int ans = 1;
    rep(i, 0, n){
        if(f[i]){
            if(t[i] > a[i]) ans = 0;
        }else if(g[i]){
            if(t[i] < a[i]) ans = 0;
        }else{
            ans = (ans * min(t[i], a[i])) % mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
#include <stdio.h>

int main(void)
{int a,b,c,d,an,nn;
	
	while(scanf("%d",&nn) != EOF){
		
	an =0;
	
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if(a + b + c + d == nn){
							an++;
						}
					}
				}
			}
		}

	

		printf("%d\n",an);
	}


	return 0;
}

Measured memory_bytes: 596
n = int(input())
t = list(map(int,input().split()))
sum_t = sum(t)
m = int(input())
s = [ input() for _ in range(m)]
p = [0]*m
x = [0]*m
for i in range(m):
  p[i],x[i] = map(int,s[i].split())
  print(sum_t - t[p[i]-1] + x[i])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll ch[100010];
ll a[3];
int main() {
	ll ans=1;
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	for(ll i=0;i<n;i++){
		ll now=ch[i];
		bool ch=true;
		ll sum=0;
		for(ll j=0;j<3;j++){
			if(now==a[j]&&ch==true){
				a[j]++;
				sum++;
				ch=false;
				continue;
			}
			else if(now==a[j]){
				sum++;
			}
		}
		ans*=sum;
		ans%=inf;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1024
// 2020-08-23 22:46:59
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

using T = tuple<int, int, int>;
const int inf = 1e9;
void answer() {
  int h, w;
  cin >> h >> w;
  int Ch, Cw, Dh, Dw;
  cin >> Ch >> Cw >> Dh >> Dw;
  Ch--;
  Cw--;
  Dh--;
  Dw--;
  vector<string> maze(h);
  rep(i, h) {
    string s;
    cin >> s;
    maze[i] = s;
  }
  deque<T> que;
  vector<vector<int> > D(h, vector<int>(w, inf));
  que.emplace_front(0, Ch, Cw);
  while(!que.empty()) {
    auto [cd, cy, cx] = que.front(); que.pop_front();
    if(D[cy][cx] < cd) continue;
    chmin(D[cy][cx], cd);
    REPC(dy, -2, 2) REPC(dx, -2, 2) {
      if(dy == 0 && dx == 0) continue;
      int ny = cy + dy, nx = cx + dx;
      if(ny < 0 || h <= ny || nx < 0 || w <= nx || maze[ny][nx] == '#') continue;
      if(abs(ny - cy) + abs(nx - cx) == 1) {
        int nd = cd;
        if(chmin(D[ny][nx], nd)) {
          que.emplace_front(nd, ny, nx);
        }
      } else {
        int nd = cd + 1;
        if(chmin(D[ny][nx], nd)) {
          que.emplace_back(nd, ny, nx);
        }
      }
    }
  }
  int ans = D[Dh][Dw];
  if(ans == inf) ans = -1;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 8624
N = int(input())
A = {}
for i in range(N):
  A[i+1] = int(input())
B = [-1 for i in range(N+1)]
B[1] = 0
i = 1
while 1:
  j = A[i]
  if j == 2:
    print(B[i] + 1)
    break
  elif B[j] != -1:
    print(-1)
    break
  else:
    B[j] = B[i] + 1
    i = j

Measured memory_bytes: 89672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> a[10];
    for (int i = 0; i < N; i++) {
        int t = S[i] - '0';
        a[t].push_back(i);
    }
    int ans = 0;
    for (int i = 0; i < 10; i++) {
        if (a[i].size() == 0) continue;
        for (int j = 0; j < 10; j++) {
            if (a[j].size() == 0) continue;
            for (int k = 0; k < 10; k++) {
                if (a[k].size() == 0) continue;
                for (int l = 0; l < a[j].size(); l++) {
                    if (a[i][0] < a[j][l] && a[j][l] < a[k][a[k].size() - 1]) {
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

void chmin(int& x, int y) {
    if (x > y) x = y;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int v, e; cin >> v >> e;

    vector<vector<pair<int, int>>> g(v);
    REP(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        g[s].eb(t, d);
    }

    vector<vi> dp(1 << v, vi(v, inf));
    dp[0][0] = 0;

    REP(i, 1 << v) {
        REP(from, v) {
            if (dp[i][from] == inf) continue;

            for(auto &p: g[from]) {
                int to = p.fi;
                if(i >> to & 1) continue;
                chmin(dp[i | 1 << to][to], dp[i][from] + p.se);
            }
        }
    }

    if (dp[(1 << v) - 1][0] == inf) dp[(1 << v) - 1][0] = -1;
    print(dp[(1 << v) - 1][0]);
}


Measured memory_bytes: 6236
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <string>
using namespace std;
int main(void)
{
    string s;
    int w; 
    cin >> s >> w;
    char c;
    int p=0;
    while(p < s.size()){
        cout << s[p];
        p += w;
    }
    return 0;
}

Measured memory_bytes: 256
//Jacker0031
        //packages
        #if __has_include("C:/Sublime Text 3/debug.h")
            #include "C:/Sublime Text 3/debug.h"
        #else
            #include <bits/stdc++.h>
            using namespace std;
            #define d(...) 11
            #define cerr if(0) cerr
        #endif
        #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

            
        #define ll long long 
        #define ld long double
            
        #define all(a)      (a).begin(),(a).end()
        #define sz(x)       (int)x.size()
            
        #define ff first
        #define ss second
        #define mp make_pair
                 
        #define pb push_back
        #define endl "\n" 
                 
        #define loop(i,l,r) for(ll i=l;i<r;i++)
        #define rf(i,r,l) for(ll i=r;i>=l;i--)    
         
        #define bp __builtin_popcountll
        #define inf LLONG_MAX
            
        const int N=2e5+5; 
        const int M=1e9+7;
        ////////////

        //NOW CODE BEGIN.
        //DHARMSINH DESAI UNIVERSITY.
        #include <ext/pb_ds/assoc_container.hpp> 
        #include <ext/pb_ds/tree_policy.hpp> 
        using namespace __gnu_pbds; 
        #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

        #define ar array
        int main()
        {
            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
            #ifdef Jenish
            freopen("C:/Sublime Text 3/in.txt","r",stdin);
            freopen("C:/Sublime Text 3/out.txt","w",stdout);
            #endif
           string a;
           cin>>a;
           ll sum=0;
           for(auto i:a)
           {
            sum+=(i-'0');
           }
           if(sum%9==0)
           {
            cout<<"Yes";
           }
           else
           {
            cout<<"No";
           }



        }       

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

int now[30];

int main()
{
	int w,n;
	scanf("%d%d",&w,&n);
	for(int i = 0; i < w; i++)
	{
		now[i] = i + 1;
	}
	for(int i = 0; i < n; i++)
	{
		int a,b;
		scanf("%d,%d",&a,&b);
		int w = now[a - 1];
		now[a - 1] = now[b - 1];
		now[b - 1] = w;
	}
	for(int i = 0; i < w; i++)
	{
		printf("%d\n",now[i]);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  ll ans = 0;
  ll p;
  rep(i,1,1000000){
    p = n/i;
    if(p<=1000000){
      break;
    }
    ll a = n/(p-1);
    ll b = n%(p-1);
    if(a==b){
      ans+=p-1;
    }
  }
  rep(i,1,p){
    ll a = n/i;
    ll b = n%i;
    if(a==b)ans+=i;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  
  int N=0;
  cin >> N;
  
  if(N<30) {
    
    cout << "No" << endl;
    
  } else {
    
    cout << "Yes" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>

using std::cin;
using std::cout;
using std::endl;

// Range Minimum, Range Update
template<class T>
struct lazy_segment_tree{
  std::vector<T> data,lazy;
  T identity1,identity2;
  int n;
  lazy_segment_tree(){}
  lazy_segment_tree(int sz,T ide1,T ide2):identity1(ide1),identity2(ide2){
    n = 1;
    while(n<sz)n<<=1;
    data.resize(2*n-1,identity1);
    lazy.resize(2*n-1,identity2);
  }
  void eval(int k){
    if(lazy[k]==identity2)return;
    if(k<n-1){
      lazy[2*k+1] = lazy[k];
      lazy[2*k+2] = lazy[k];
    }
    data[k] = lazy[k];
    lazy[k] = identity2;
  }
  void update_impl(int a,int b,T x,int k,int l,int r){
    eval(k);
    if(a<=l&&r<=b){
      lazy[k] = x;
      eval(k);
    }
    else if(a<r&&l<b){
      update_impl(a,b,x,2*k+1,l,(l+r)/2);
      update_impl(a,b,x,2*k+2,(l+r)/2,r);
      data[k] = std::min(data[2*k+1],data[2*k+2]);
    }
  }
  T query_impl(int a,int b,int k,int l,int r){
    eval(k);
    if(r<=a||b<=l){
      return identity1;
    }
    if(a<=l&&r<=b){
      return data[k];
    }
    else{
      T vl = query_impl(a,b,2*k+1,l,(l+r)/2);
      T vr = query_impl(a,b,2*k+2,(l+r)/2,r);
      return std::min(vl,vr);
    }
  }
  void update(int a,int b,T x){
    update_impl(a,b,x,0,0,n);
  }
  T query(int a,int b){
    return query_impl(a,b,0,0,n);
  }
  T operator[](int i){
    return query_impl(i,i+1,0,0,n);
  }
};

signed main(){
  int n,q;
  cin>>n>>q;
  constexpr int64_t INF = (1LL<<31)-1;
  lazy_segment_tree<int64_t> data(n,INF,-1);
  while(q--){
    int c;cin>>c;
    if(c==0){
      int s,t,x;cin>>s>>t>>x;
      data.update(s,t+1,x);
    }else{
      int s,t;cin>>s>>t;
      cout<< data.query(s,t+1) <<endl;
    }
  }
}


Measured memory_bytes: 7068
S=input()
if S=='MON':
    print(6)
elif S=='TUE':
    print(5)
elif S=='WED':
    print(4)
elif S=='THU':
    print(3)
elif S=='FRI':
    print(2)
elif S=='SAT':
    print(1)
else:
    print(7)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

vector<vector<int>> memo(101, vector<int>(10001, -1));

// index番目以降の商品で重さがweight以下になる中で、最大の価値を求める
int CalcMaxValue(int index, int weight, vector<int>& v, vector<int>& w) {
  if(index == v.size()){
    return 0;
  }
  if(weight < w[index]){
    if(memo[index+1][weight] == -1) memo[index+1][weight] = CalcMaxValue(index+1, weight, v, w);
    return memo[index+1][weight];
  }
  int not_choice, choice;
  if(memo[index+1][weight] == -1){
    memo[index+1][weight] = CalcMaxValue(index+1, weight, v, w);
  }
  not_choice = memo[index+1][weight];

  if(memo[index+1][weight-w[index]] == -1){
    memo[index+1][weight-w[index]] = CalcMaxValue(index+1, weight-w[index], v, w);
  }
  choice = memo[index+1][weight-w[index]] + v[index];

  return max(not_choice, choice);
}

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> v(N);
  vector<int> w(N);

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

  cout << CalcMaxValue(0, W, v, w) << endl;
  return 0;
}



Measured memory_bytes: 6684
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans=0;
int k,n;
//string s;
int vk[111],sk[111];
vector<int> v,s;
signed main(){
	
	cin>>n;
	rep(i,n){
		int a;
		cin>>a;
		vk[i]=a;
		v.push_back(a);
	}
	rep(i,n){
		int a;
		cin>>a;
		sk[i]=a;
		s.push_back(a);
	}
	sort(v.begin(),v.end());
	sort(s.begin(),s.end());
	int ans2,cnt=0;
	do{
		cnt++;
		int f=1,f2=1;
		rep(i,n){
			if(vk[i]!=v[i])f=0;
			if(sk[i]!=s[i])f2=0;
		}
		if(f)ans=cnt;
		if(f2)ans2=cnt;
	}while(next_permutation(v.begin(),v.end())&&next_permutation(s.begin(),s.end()));
	cout<<abs(ans-ans2)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int X,Y,Z;
  cin>>X>>Y>>Z;
  cout<<(X-Z)/(Z+Y);
return 0;}

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

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

    long long result = 0;
    result += 1000 * (int)(x / 500);
    int amari = x % 500;

    result += (int)(amari / 5) * 5;

    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<climits>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>

using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	if(a<=8 && b<=8)
		cout<<"Yay!";
	else
		cout<<":(";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c;
    k=a;
    a=b;
    b=k;
    k=a;
    a=c;
    c=k;
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}


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

#define N (1<<18)
#define ll long long
#define ld long double
#define M 1000000007
#define INF 0x5ADFACE5
#define LINF 0x51DEEFFEC7C0DECALL
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second

using namespace std;

int main() {
    ll a, b, c;
    cin>>a>>b>>c;
    int ans = 0;
    while ((~a & 1) && (~b & 1) && (~c & 1) && ans < 100) {
    	ans++;
    	ll x = a / 2, y = b / 2, z = c / 2;
    	a = y + z;
    	b = x + z;
    	c = x + y;
    }
    if (ans == 100) ans = -1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include <bitset>
#include <functional>
#include <cmath>

#define INF 1000000000
using namespace std;

const int MAX = 2000010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

//テーブルの前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        //そのまま計算すると負の値になるのでMODを足す
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//二分累乗法
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    long long k;
    string s;
    cin >> k >> s;

    COMinit();
    long long ans = 0;
    for(long long x = 0; x <= k; x++){
        ans += ((modpow(25, k-x, MOD) * modpow(26, x, MOD))%MOD * COM(k+s.size()-x-1, s.size()-1))%MOD;
        ans %= MOD;
    }
    
    cout << ans << endl;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define EPS (1e-9)
#define INF (1e9 + 1)
#define PI (acos(-1))

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

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

ll A, B, N, sum = 0;

int X;

int main() {
	cin >> X;
	if (X == 3 || X == 5 || X == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256