akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

int D;
int c[32];
int s[512][32];
int ans[512];

void inp(){
    cin>>D;
    for(int i=1;i<=26;i++){
        cin>>c[i];
    }
    for(int i=1;i<=D;i++){
        for(int j=1;j<=26;j++){
            cin>>s[i][j];
        }
    }
}

void ans_inp(){
    for(int i=1;i<=D;i++){
        cin>>ans[i];
    }
}

void man_disp(){
    int l[32]={0};
    int man=0;
    for(int i=1;i<=D;i++){
        int n=ans[i];
        l[n]=i;
        man+=s[i][n];
        for(int j=1;j<=26;j++){
            man-=c[j]*(i-l[j]);
        }
        cout<<man<<endl;
    }
}

signed main(){
    inp();
    ans_inp();
    man_disp();
    return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int main(){
    ll n;
    cin >> n;
    vector<ll> h(n+1,0);
    ll ans = 0;
    for (ll i = 1; i < n + 1; i++) cin >> h[i];
    for (ll i = 0; i < n;i++){
        ans += max(0LL, h[i + 1] - h[i]);
    }
    cout << ans << endl;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
    cout << fixed;
  double n; cin>>n;
  cout<<((n/3)*(n/3)*(n/3))<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((abs(a-b)<=d && abs(b-c)<=d)||abs(c-a)<=d) cout << "Yes" << "\n";
    else cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 200001
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int n,a[1000],b[1000],t[10001],s;

int solve(){
    int ans=0;

    bool V[1000];
    rep(i,n){
        b[i]=a[i];
        V[i]=false;
    }
    sort(b,b+n);
    rep(i,n) t[b[i]]=i;
    rep(i,n){
        if(V[i]) continue;
        int cur=i;
        int S=0;
        int m=1000000;
        int an=0;
        while(1){
            V[cur]=true;
            an++;
            int v=a[cur];
            m=min(m,v);
            S+=v;
            cur=t[v];
            if(V[cur]) break;
        }
        ans+=min(S+(an-2)*m,m+S+(an+1)*s);
    }
    return ans;
}

int main() {
    cin>>n;
    s=100000;
    rep(i,n){
        cin>>a[i];
        s=min(s,a[i]);
    }
    int ans=solve();
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    // redcoder
    string S;
    cin >> S;
    int ans = 0;
    int n = S.length();
    for(int i = 0; i < n/2; i++) {
        if(S[i] != S[n-1-i]){
            ans++;
        }
    }

    cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    int M = 1 << N;
    
    vector<int> A(M);
    for (int i = 0; i < M; i++) cin >> A[i];
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    vector<bool> use(M, false);
    use[0] = true;
    
    bool check = true;
    for (int K = 0; K < N; K++) {
        vector<bool> par = use;
        int u = 1;
        int p = 0;
        int cnt = 0;
        while (cnt < (1 << K)) {
            while (!par[p])p++;
            while (use[u] || A[u] >= A[p]) {
                u++;
                if (u == M) {
                    check = false;
                    break;
                }
            }
            if (!check) break;
            use[u] = true;
            p++;
            cnt++;
        }
        if (!check) break;
    }
    cout << (check ? "Yes" : "No") << endl;
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

struct UFweight
{
    int i;
    vector<int> par;
    vector<int> size;
    vector<int> rank;
    vector<ll> diff_weight;
    UFweight(int n, ll sum_unity = 0){
        par.resize(n);  rank.resize(n); size.resize(n); diff_weight.resize(n);
        for(i = 0;i < n;++i){
            par.at(i) = i;
            rank.at(i) = 0;
            size.at(i) = 1;
            diff_weight.at(i) = sum_unity;
        }
    }
    
    int root(int x){
        if(par.at(x) == x){
            return x;
        }else{
            int r = root(par.at(x));
            diff_weight.at(x) += diff_weight.at(par.at(x));
            return par.at(x) = r;
        }
    }

    ll weight(int x){
        root(x);
        return diff_weight.at(x);
    }

    ll get_diff(int x, int y){
        return weight(y) - weight(x);
    }
    
    // weight(y) - weight(x) = wとなるようにmerge
    bool merge(int x, int y, ll w){
        w += weight(x); w -= weight(y);
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            ll weight_diff = get_diff(rx, ry);
            if(weight_diff == w) return true;
            else return false;
        }

        if(rank.at(rx) < rank.at(ry)){
            swap(rx,ry);
            w *= -1;
        }
        if(rank.at(rx) == rank.at(ry)) ++rank.at(rx);
        par.at(ry) = rx;
        diff_weight.at(ry) = w;
        size.at(rx) += size.at(ry);

        return true;
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size.at(root(x));
    }
};

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    UFweight ufw(n);
    for(i = 0;i < m;++i){
        ll l,r,d;
        cin >> l >> r >> d;
        --l;    --r;
        bool flag = ufw.merge(l,r,d);
        if(!flag){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define MOD 1000000007

typedef long long ll;
ll dp[11451419];

int main(){
  int n, m;
  cin>> n >> m; 
  vector <int> a(n);
  vector<bool> ok(n+1, true);
  for(int i=0; i<m; i++) {
    cin>> a[i];
    ok[a[i]]=false;
  }
  dp[0]=1;
  for(int i=1; i<=n; i++){
    if(ok[i]){
	if(i==1)dp[i]=1;
	else{
	  dp[i] = (dp[i-1]+dp[i-2])%MOD;
	}
    }
  } 
  cout<< dp[n] << endl;
}


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

int main()
{
    long long int n, k;
    cin >> n >> k;

    if (k == 0)
    {
        cout << n*n << endl;
        return 0;
    }

    long long int count = 0;
    for (long long int b=k+1; b <= n; ++b)
    {
        long long int temp = n/b*(b-k);
        if (temp > 0)
        {
            count += temp;
        }

        temp = n%b-(k-1);
        if (temp > 0)
        {
            count += temp;
        }
    }
    cout << count << endl;

    return 0;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'

ll man,cost[1005],key[1005],dp[1005][9005];
ll n,m,a,b,c;
	
ll on(ll p, ll pos)
{
	ll ans = (1<<pos);
	p = (p|ans);
	return p;
}

ll func_dp(ll indx, ll val)
{
	if(indx > m)
	{
		if(val==man)
		{
			return 0;
		}
		else return 1e9;
	}
	
	if(dp[indx][val] != -1) return dp[indx][val];
	
	ll a1 = func_dp(indx+1,val|key[indx]) + cost[indx];
	ll a2 = func_dp(indx+1,val);
	
	return dp[indx][val] = min(a1,a2);
}

int main()
{	
	cin >> n >> m;
	
	man = (1 << n) - 1; 
	
	for(int i = 1; i <= m; i++)
	{
		cin >> a >> b;
		cost[i] = a;
		ll bit = 0;
		for(int j = 1; j <= b; j++)
		{
			cin >> c;
			bit = on(bit,c-1);
		}
		key[i] = bit;
	}
	
	memset(dp,-1,sizeof(dp));
	
	ll ans = func_dp(1,0);
	
	if(ans >= 1e9) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 71040
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int tmp=2*b;
	if(tmp>a)
	cout<<0<<endl;
	else
	{
		a-=tmp;
		cout<<a<<endl;
	}
	return 0;
}

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

using namespace std;

int c[10][10];

int main(void) {
    int n;
    cin >> n;
    
    for(int i = 1; i <= n; i++) {
        if(i % 10 == 0) continue;

        int y = i;
        while(y >= 10) {
            y /= 10;
        }

        c[y][i % 10]++;
    }

    long long ans = 0;
    for(int j = 1; j <= 9; j++) {
        for(int i = 1; i <= 9; i++) {
            ans += c[i][j] * c[j][i];
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, X, A, B);
  if (B <= A) {
    print("delicious");
  } else if ((B - A) <= X) {
    print("safe");
  } else {
    print("dangerous");
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int n;
  while(cin >> n){
    vector<LLI> A(n); cin >> A;
    LLI sum = accumulate(ALL(A),0LL);

    vector<LLI> ans(n);
    vector<LLI> diff(n);
    
    REP(i,n){
      diff[i] = A[(i+1)%n] - A[i];
    }

    int j = 0;
    REP(i,n){
      ans[(j+2)%n] = ans[j] + 2*diff[j];
      
      (j += 2) %= n;
    }

    LLI d = (sum-accumulate(ALL(ans),0LL))/n;

    REP(i,n) ans[i] += d;

    join(cout, ALL(ans));
  }
  
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

int main() {
    int A, B;
    cin >> A >> B;

    if (A + B >= 10) {
        cout << "error" << endl;
    } else {
        cout << A + B << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s = int(input())
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3*n + 1
flag = [0 for i in range(1000001)]
flag[s] = 1
a = [s]

for i in range(1000000):
    a.append(f(a[i]))
    if flag[a[i+1]] == 1:
        break
    else:
        flag[a[i+1]] = 1
print(len(a))

Measured memory_bytes: 10904
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))


for p in range(1, 4):
    D = 0
    for i in range(n):
        D += abs((x[i] - y[i]))**p
    ans = math.pow(D, 1/p)
    print(f"{ans:.6f}")

l = []
for i in range(n):
    l.append(abs((x[i] - y[i])))
print(max(l))



Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
int ans;
char a[1000001];
signed main()
{
	cin>>a+1;
	int n=strlen(a+1);
	for(int i=1;i<=n/2;i++)
		if(a[i]!=a[n-i+1])
			ans++;
	printf("%d",ans);
	return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n+1);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  vector<int> dp(n,INT_MAX);
  dp[0]=0;
  for(int i=0;i<n;i++){
      for(int j=1;j<=k;j++){
          if((i+j)<n) dp[i+j]= min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));
      }
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 3900
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int x[100010];
int disx[100010];


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


int main() {

    int N, X;
    cin >> N >> X;
    rep(i, N)cin >> x[i];

    x[N] = X;

    sort(x, x + N + 1);
    rep(i, N)disx[i] = x[i + 1] - x[i];

    sort(x, x + N);

    int ans = INF;
    int ma;
    rep(i, N) {
        ma = gcd(disx[i], disx[i + 1]);
        ans = min(ans, ma);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	char c;
	cin>>c;
	if(c>='a'&&c<='z')
    {
        cout<<'a'<<endl;
    }
    else
    {
        cout<<'A'<<endl;
    }
	return 0;
}


Measured memory_bytes: 3612
sx, sy, tx, ty = list(map(int, input().split()))
forth1 = 'U' * (ty - sy) + 'R' * (tx - sx)
back1 = 'D' * (ty - sy) + 'L' * (tx - sx)
forth2 = 'L' + 'U' * (ty - sy + 1) + 'R' * (tx - sx + 1) + 'D'
back2 = 'R' + 'D' * (ty - sy + 1) + 'L' * (tx - sx + 1) + 'U'
print(forth1 + back1 + forth2 + back2)

Measured memory_bytes: 3060
#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
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

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

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 1000000007;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

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

    vector<int> T(N+1),TT(N+1);

    for (int i = 1; i <= N; ++i) {
        cin >> T[i];
    }

    for (int j = 1; j <= N; ++j) {
        TT[j] = T[j];
    }

    int M;
    cin >> M;

    vector<int> P(M+1), X(M+1);

    for (int i = 1; i <= M; ++i) {
        cin >> P[i] >> X[i];
    }

    vector<pair<int, int> > p(M+1);

    for (int i = 1; i <= M; ++i) {
        p[i] = make_pair(P[i], X[i]);
    }

    for (int i = 1; i <= M; ++i) {
        TT[p[i].first] = p[i].second;
        int S = 0;
        for (int j = 1; j <= N; ++j) {
            S+=TT[j];
        }
        cout << S << endl;
        for (int j = 1; j <= N; ++j) {
            TT[j] = T[j];
        }
    }

}

Measured memory_bytes: 384
using System;

class AOJ{
  static void Main(string[] args)
  {
    string s = Console.ReadLine();
    string ans = "";

    int[] x = Array.ConvertAll(s.Split(' '), int.Parse);

    Array.Sort(x);

    for (int i = 0; i < 5; i++){
      ans += (x[4-i]);
      if (i != 4) ans += " ";
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 9304
#include<iostream>
#include<cstdio>
#define M 1000001
using namespace std;

int main(){
    int H, W;
    while(true){
        cin >> H >> W;
        if (W == 0 && H == 0) break;
        for(int i = 0; i < H; i ++){
            for(int j = 0; j < W; j ++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	int a, b; cin >> a >> b;
	int d = 0;
	if (b < 10) {
		 d = a * 10 + b;
	}
	else if (b < 100) {
		 d = a * 100 + b;
	}
	else {
		 d = a * 1000 + b;
	}
	for (int i = 1; pow(i, 2) <= d; i++) {
		if (d == pow(i, 2)) {
			cout << "Yes" << endl;
		}
		else if(pow(i+1,2)>d){
			cout << "No" << endl;
		}
	}
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define str string
#define s_vec(data,name,vertical,horizontal) vector<vector<(data)>> (name)((vertical),vector<(data)>((horizontal)));




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

    vector<int> a(n);

    int num;
    rep(i,n){
        cin>>num;
        a.at(num-1) = (i+1);
    }
    rep(i,n){
        cout<<a.at(i)<<" ";
    }

    


}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int d[100005];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>d[i];
  }

  sort(d+1,d+n+1);
  
  int ans=d[n/2+1]-d[n/2];
  
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 640
n = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

for i in range(n - 1):
    if A[i] == A[i + 1] - 1:
        ans += C[A[i] - 1]

print(ans)


Measured memory_bytes: 3060
//<--sbhmsh-->//

#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
#define lli long long int
#define endl '\n'
#define deb cout<<"sab_badhiya"<<endl;
// const long long INF = 1000 * 1000 * 1000 * 1ll * 1000 * 1000 * 1000;
const long INF = 1000 * 1000 * 1000;
const long long int mod = 1000000007;
int dp[100005]={0};
map<int, int>ans, mp;
int main() {
  FASTIO
  int n, k, m;
  cin>>n>>k;
  int a[n+1];
  for(int i=0;i<n;i++) {
    cin>>a[i];
    dp[i] = 1e9;
    m = i-k;
    m = max(0, m);
    dp[0] = 0;
    for(int j=i-1;j>=m;j--){
      dp[i] = min(dp[i], abs(a[i]-a[j]) + dp[j]);
    }
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI pair<int,int>
#define ff first
#define ss second
#define MOD 1000000007


int divisors(int n)
{
	int cnt=0,ans=1;
	while(n%2==0)
	{
		n/=2;
		cnt++;
	}
	if(cnt)
		ans++;
	for(int i=3;i<=sqrt(n);i++)
	{
		cnt=0;
		while(n%i==0)
		{
			n/=i;
			cnt++;
		}
		if(cnt)
			ans++;
	}
	if(n>2)
		ans++;
	return ans;
}

int32_t main()
{
    boost;
   /* #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
	*/
    int a,b;
    cin>>a>>b;
    int g=__gcd(a,b);
    int ans=divisors(g);
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long N,M,K;
main()
{
	cin>>N>>M>>K;
	long A=1,B=1,C=1;
	for(int i=1;i<=N*M-2;i++)A=A*i%mod;
	for(int i=1;i<=N*M-K;i++)B=B*i%mod;
	for(int i=1;i<=K-2;i++)C=C*i%mod;
	cout<<A*power(B*C%mod,mod-2)%mod*((mod+1)/2)%mod*(N*N%mod*M%mod*(M+1)%mod*(M-1)%mod+M*M%mod*N%mod*(N+1)%mod*(N-1)%mod)%mod*power(3,mod-2)%mod<<endl;
}

Measured memory_bytes: 256
#-*- coding:utf-8 -*-
S = list(map(int, list(input())))

# 0 start, 1 start
count = [0, 0]

# from 0 
for i, s in enumerate(S):
    if i % 2 == 0: # even
        if s != 0:
            count[0] += 1        
    elif i % 2 == 1: # odd
        if s != 1:
            count[0] += 1

# from 1
for i, s in enumerate(S):
    if i % 2 == 0: # even
        if s != 1:
            count[1] += 1        
    elif i % 2 == 1: # odd
        if s != 0:
            count[1] += 1

print(min(count))

Measured memory_bytes: 4652
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}
 
const double PI=3.14159265358979323846;



ll kaijo[2000010];
void init() {
	kaijo[0] = 1;
	for (ll i = 1;i < 2000010;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}
 
ll inv(ll x,ll power) {
	ll res = 1;
	ll k = power;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}
 
ll Comb(ll n, ll k) {
	if (n < 0 || k < 0 || (n - k) < 0)return 0;
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd,N-2)) % N) % N;
}

int main(void){
    init();
    ll K;
    string S;
    cin>>K>>S;
    ll n = S.length();
    ll ans = 0;
    for(ll i=0;i<=K;i++){
        ll now = inv(26LL,K-i);
        now = (now*inv(25LL,i))%N;
        now = (now*Comb(i+n-1,n-1))%N;
        ans = (ans+now)%N;
        ans = (ans+N)%N;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 20904
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();


    if(A<= 9 && B <= 9){
      System.out.println(A*B);
    }else{
      System.out.println(-1);
    }
  }

}


Measured memory_bytes: 23636
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = a; i >= (b); --i)
#define repdl(i, a, b) for(ll i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void writef(T ...tail) { write(tail...); cout << flush; }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.size()) {
    rep(i, 0, sz(v) - 1)
      out << v[i] << " ";
    out << v.back();
  }
  return out;
}
#endif
using namespace std;

ll n, k;
ll p[5005], bs[5005];
ll c[5005], sum[5005];

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  read(n, k);
  rep(i, 1, n + 1) read(p[i]);
  rep(i, 1, n + 1) read(c[i]);

  rep(i, 1, n + 1) {
    if (!bs[i]) {
      vector<int> elem;
      elem.push_back(i);
      ll s = c[elem.back()];
      while (p[elem.back()] != elem.front()) {
        s += c[p[elem.back()]];
        elem.push_back(p[elem.back()]);
      }
      for (int e : elem) bs[e] = sz(elem), sum[e] = s;
    }
  }

  ll ans = -0x3f3f3f3f3f3f3f3fll;
  repl(i, 1, n + 1) {
    {
      ll v = 0;
      ll gg = max(k / bs[i] - 1, 0ll);
      v += 1ll * gg * sum[i];
      ll g = k % bs[i], pos = i;
      repl(j, 0, k - gg * bs[i]) {
        v += c[p[pos]];
        chmax(ans, v);
        pos = p[pos];
      }
    }

    {
      int pos = i;
      ll v = 0;
      rep(j, 0, min(k, n)) {
        v += c[p[pos]];
        pos = p[pos];
        chmax(ans, v);
      }
    }
  }
  write(ans);
}



Measured memory_bytes: 3864
#include "iostream"
#include "algorithm"
#include "vector"
#include "map"
#define K 1000000000000000000

typedef long long llint;

using namespace std;

llint a, b, c;
llint k;
llint x, y;

int main() {
    cin >> a >> b >> c >> k;

    // int x = 1;
    // x = x << k;
    // cout << x << endl;
    if (k % 2 == 0) {
        cout << a - b << endl;
    } else {
        cout << b - a << endl;
    }
}


Measured memory_bytes: 256
/**
 *	@file: C.cpp
 *	@author: Huy Le
 *	@created: 07/11/2020 18:52:28
**/


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int ts;
int n;

void solve() {
	map<ll,int> mp;
	cin >> n;
	for(int i = 1; i < n; ++i) {
		if( pow(i,2) > n)
			break;
		for(int j = 1; j < n; ++j) {
			if(pow(i,2)+pow(j,2) + i*j > n)
				break;
			for(int k = 1; k < n; ++k) {
				ll tmp = pow(i,2) + pow(j,2) + pow(k,2) + i*j + i*k + j*k;
				if(tmp <= n)
					mp[tmp]++;
				else
					break;
			}
		}
	}
	for(int i = 1; i <= n; ++i) {
		if(mp.find(i) != mp.end())
			cout << mp[i] << '\n';
		else
			cout << 0 << '\n';
	}
}

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

	//cin >> ts;
	//while(ts--) 
		solve();
}


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

struct Benri {Benri() {std::cin.tie(0); ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);}} benri;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007




int main() {
    string s; cin >> s;
    int a = (s[5] - '0') * 10 + s[6] - '0';
    cout << (a <= 4 ? "Heisei" : "TBD") << endl;
}





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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/08  Problem: ABC 094 B / Link: http://abc094.contest.atcoder.jp/tasks/abc094_b  ----- */


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

	LL N, M, X; cin >> N >> M >> X;
	vector<LL> a(N + 1);
	for (int i = 0; i < M; ++i) {
		int pos; cin >> pos;
		a[pos]++;
	}
	LL ans = LINF;
	{
		LL sub = 0;
		FOR(i, 0, X) {
			sub += a[i];
		}
		ans = min(ans, sub);
	}
	{
		LL sub = 0;
		FOR(i, X + 1, N + 1) {
			sub += a[i];
		}
		ans = min(ans, sub);
	}


	cout << (ans) << "\n";

	return 0;
}


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

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> p(n);
    vector<pair<string, int> > si_vec;
    vector<vector<pair<int, int> > > ivec;
    for (int i = 0; i < n; ++i) {
        cin >> s[i] >> p[i];
        si_vec.emplace_back(make_pair(s[i], i));
    }
    sort(s.begin(), s.end());
    s.erase(std::unique(s.begin(), s.end()), s.end());
    ivec.resize(s.size());
    for (int i = 0; i < n; ++i) {
        string si = si_vec[i].first;
        int iter = si_vec[i].second;
        auto itr = std::find(s.begin(), s.end(), si);
        size_t index = std::distance(s.begin(), itr );
        ivec[index].emplace_back(make_pair(p[iter], iter));
    }
    for (int i = 0; i < ivec.size(); ++i) {
        sort(ivec[i].rbegin(), ivec[i].rend());
    }
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < ivec[i].size(); ++j) {
            cout << ivec[i][j].second + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
a=[]
for i in range(h):
	a.extend(list(input()))

from collections import Counter
a=Counter(a)
a=[i%4 for i in a.values()]
l=(h*(w%2)+w*(h%2)-(h*w)%2)
if sum(a)<=l:
	a=[i%2 for i in a]
if (h*w)%2==sum(a):
	print('Yes')
else:
	print('No')

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
  
	if(a < b && b < c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3100
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Lining Up
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

typedef long long ll;
const ll MOD = 1000000007LL;

/* typedef */

/* global variables */

int cs[MAX_N];

/* subroutines */

ll powmod(ll a, int b) {
  ll pm = 1;
  while (b > 0) {
    if (b & 1) pm = (pm * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return pm;
}

/* main */

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int ai;
    cin >> ai;
    if ((n - 1 - ai) & 1) {
      puts("0");
      return 0;
    }

    // |i - (n - 1 - i)| = ai
    // |2i - (n - 1)| = ai
    // -> 2i - (n - 1) = +-ai -> 2i = (n - 1 +-ai) -> i = (n - 1 +-ai) / 2
    int i0 = (n - 1 - ai) / 2, i1 = (n - 1 + ai) / 2;
    cs[i0]++, cs[i1]++;
    //printf("ai=%d, i0=%d, i1=%d\n", ai, i0, i1);
  }

  for (int i = 0; i < n; i++)
    if (cs[i] != 2) {
      puts("0");
      return 0;
    }

  ll ans = powmod(2LL, n / 2);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int n; cin >> n;
  string ans;

  if(n == 0) ans = "0";
  while (n != 0) {
    if(n%2 == 0) ans = "0" + ans;
    else{
      n--;
      ans = "1" + ans;
    }
    n /= -2;
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    for (int i = 0; i < 2000; i++) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            cout << i << endl;
            return 0;
        }
    }

    cout << "-1" << endl;
}

Measured memory_bytes: 256
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
OutV = lambda x: print(*x, sep='\n')
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N = iIn()
A = iInLH()
Q = iIn()
BC = iInLD(Q)

ssum = sum(A)
lst = [0]*100000
for i in range(N):
    lst[A[i]-1] += 1

for i in range(Q):
    n_b = lst[BC[i][0]-1]
    ssum = ssum - BC[i][0] * n_b + BC[i][1] * n_b
    print(ssum)
    lst[BC[i][0]-1] = 0
    lst[BC[i][1]-1] += n_b
    

Measured memory_bytes: 94824
N,M=map(int,input().split())
ks=[list(map(int,input().split())) for _ in range(M)]
p=list(map(int,input().split()))
bit=[]
ans=0
for i in range(2**N):
    bit+=[list(bin(i)[2:].zfill(N))]
for b in bit:
    for i in range(M):
        on=0
        for j in range(ks[i][0]):
            if b[ks[i][j+1]-1]=="1":
                on+=1
        if on%2!=p[i]:
            break
    else:
        ans+=1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define maxn 200086
using namespace std;

int n;
int x[maxn], y[maxn], d[maxn];
char s[10];
vector<pair<int, int> > v[maxn], V;
int a[maxn * 2];

inline void rotate(){
	for(int i = 1;i <= n;i++){
		int tmp = x[i];
		x[i] = y[i], y[i] = 200000 - tmp;
		d[i] = (d[i] + 1) % 4;
	}
}


int main(){
	scanf("%d", &n);
	for(int i = 1;i <= n;i++){
		scanf("%d%d%s", &x[i], &y[i], s);
		switch(s[0]){
			case 'U':
				d[i] = 0;
				break;
			case 'R':
				d[i] = 1;
				break;
			case 'D':
				d[i] = 2;
				break;
			case 'L':
				d[i] = 3;
				break;			
		}
	}
	int ans = maxn * 10;
	for(int t = 1;t <= 4;t++){
		//for(int i = 1;i <= n;i++) printf("%d %d %d--\n", x[i], y[i], d[i]);
		for(int i = 0;i < maxn;i++) v[i].clear();
		for(int i = 1;i <= n;i++){
			if(d[i] == 1) v[y[i]].push_back({x[i], 0});
			if(d[i] == 3) v[y[i]].push_back({x[i], 1});
		} 
		for(int i = 0;i < maxn;i++){
			if(v[i].size() <= 1) continue;
			sort(v[i].begin(), v[i].end());
			int k = -1;
			for(int j = 0;j < v[i].size();j++){
				if(j > 0 && v[i][j].first == v[i][j - 1].first) ans = 0;
				if(v[i][j].second == 0) k = v[i][j].first;
				else if(k != -1) ans = min(ans, (v[i][j].first - k) * 5);
			}
		}
		memset(a, -1, sizeof(a));
		V.clear();
		for(int i = 1;i <= n;i++){
			if(d[i] == 0) V.push_back({y[i], -i});
			if(d[i] == 1) V.push_back({y[i], i});
		}
		sort(V.begin(), V.end());
		for(int i = 0;i < V.size();i++){
			if(V[i].second < 0){
				int j = -V[i].second;
				a[x[j] + y[j]] = max(a[x[j] + y[j]], y[j]);
			}else{
				int j = V[i].second;
				if(a[x[j] + y[j]] != -1) ans = min(ans, (y[j] - a[x[j] + y[j]]) * 10);
			}
		}
		rotate();
	} 
	if(ans == maxn * 10) printf("SAFE");
	else printf("%d", ans);
}

Measured memory_bytes: 20176
#include <stdio.h>
#define P printf
int main(void){int h,w,i,j;for(;;){scanf("%d %d",&h,&w);if(h+w==0)return 0;for(i=h;i>0;--i){for(j=w;j>0;--j)P((i==h)|(i==1)|(j==w)|(j==1)?"#":".");P("\n");}P("\n");}}

Measured memory_bytes: 588
N,x = map(int,input().split())
A = list(map(int,input().split()))
A_org = sum(A)
if A[0]>x:
	A[0]=x
for i in range(N-1):
	if A[i]+A[i+1]>x:
		A[i+1] = x-A[i]

print(A_org-sum(A))


Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<P>V(N);
	rep(i, N) {
		cin >> V[i].second >> V[i].first;
	}
	sort(V);
	vector<int>S(N);
	S[0] = V[0].second;
	for (int i = 1; i < N; i++) {
		S[i] = S[i - 1] + V[i].second;
	}
	vector<int>B(N);
	rep(i, N) {
		B[i] = V[i].first - S[i];
	}
	rep(i, N) {
		if (B[i] < 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


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

int main()
{
	string s,t;
	cin>>s>>t;
	
	int m=s.length();
	int n=t.length();
	
	int dp[m+1][n+1];
	
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(s[i-1]==t[j-1])	dp[i][j]=dp[i-1][j-1]+1;
			else if(dp[i-1][j]>=dp[i][j-1])	dp[i][j]=dp[i-1][j];
			else
				dp[i][j]=dp[i][j-1];
		}
	}
	
	int i=m;
	int j=n;
	string str="";
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			str=str+s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j]>=dp[i][j-1])
		{
			i--;
		}
		else
		{
			j--;
		}
	}
	reverse(str.begin(),str.end());
	cout<<str;
	return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
  ll k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
}

Measured memory_bytes: 3604
# -*- coding: utf-8 -*-

import sys

def sum_intergers(n, k=4, last=True):
    clip_9 = lambda x: x if x < 10 else 9

    if k > 1:
        c = sum_intergers(n, k=k-1, last=False)
    else:
        return [(s,) for s in range(clip_9(n)+1)]

    ret = []
    for cc in c:
        sum_cc = sum(cc) # memorize
        for s in range(clip_9(n-sum_cc)+1):
            if not last or s+sum_cc==n:
                r = [p for p in cc]
                r.append(s)
                ret.append(tuple(r))
    return ret


def main():
    ns = [int(n) for n in sys.stdin]
    for n in ns:
        c = len(sum_intergers(n, k=4))
        print(c)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=1000;

ll N,K;

ll d_sum(ll n){
  ll res=0;
  while(n>0){
    res+=n%10;
    n/=10;
  }
  return res;
}

double sn(ll n){
  return (double)(n)/d_sum(n);
}

int main(){
  cin>>K;
  ll b=1;
  vector<ll> candidate;
  for(ll i=0;i<15;i++){
    for(ll j=1;j<999;j++){
      candidate.emplace_back(b*(j+1)-1);
    }
    b*=10;
  }
  sort(candidate.begin(), candidate.end());
  candidate.erase(unique(candidate.begin(), candidate.end()), candidate.end());
  for(ll i=0;i<candidate.size();i++){
    for(ll j=i+1;j<candidate.size();j++){
      if(sn(candidate[i])>sn(candidate[j])){
        candidate.erase(candidate.begin()+i);
        i--;
        break;
      }
    }
  }

  for(ll i=0;i<K;i++){
    cout<<candidate[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
#![allow(non_snake_case)]

use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    let mut ws = buf.split_whitespace();
    let w: i32 = ws.next().unwrap().parse().unwrap();
    let h: i32 = ws.next().unwrap().parse().unwrap();
    let x: i32 = ws.next().unwrap().parse().unwrap();
    let y: i32 = ws.next().unwrap().parse().unwrap();
    let r: i32 = ws.next().unwrap().parse().unwrap();

    let mut is_contain = true;
    if x - r < 0 {
        is_contain = false;
    } else if x + r > w {
        is_contain = false;
    } else if y - r < 0 {
        is_contain = false;
    } else if y + r > h {
        is_contain = false;
    }

    if is_contain {
        println!("Yes");
    } else {
        println!("No");
    }

}



Measured memory_bytes: 5024
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &x:a)cin >> x;

    vector<ll> ball(n+1,0);
    for(int i=0;i<n;i++){
        int now=a[i];
        ball[now]++;
    }

    vector<ll> conbination(n+1,-1);
    conbination[0]=0;
    ll sum=0;
    for(int i=1;i<n+1;i++){
        ll now=ball[i];
        if(now==0)continue;
        if(conbination[now]==-1)conbination[now]=(now*(now-1))/2;
        sum+=conbination[now];
    }

    for(int i=0;i<n;i++){
        ll now=a[i];
        ll b=ball[now];
        if(conbination[b-1]!=-1){
            cout << sum-conbination[b]+conbination[b-1] << endl;
            continue;
        }
        conbination[b-1]=(b-1)*(b-2)/2;
        cout << sum-conbination[b]+conbination[b-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 7140
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n, k;
    cin >> n >> k;
    vi cnt(n, 0);

    while(k--)
    {
        int d; cin >> d;
        while(d--)
        {
            int a; cin >> a;
            cnt[--a]++;
        }
    }

    cout << count(ALL(cnt), 0) << endl;
    
    return 0;
}

Measured memory_bytes: 3636