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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

ll modpow(ll n, ll k){
	ll res = 1;
	REP(i, k){
		res *= n;
		res %=mod;
	}
	return res;
}

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

    ll n;
    cin >> n;
    ll dp[120][4][4][4];
    ll A = 0, G = 1, C = 2, T = 3;
    REP(i, 120)REP(j, 4)REP(k, 4)REP(l, 4) dp[i][j][k][l] = 0;
    
    REP(j, 4)REP(k, 4)REP(l, 4){
    	dp[3][j][k][l] = 1;
    }
    dp[3][A][G][C] = 0;
    dp[3][G][A][C] = 0;
    dp[3][A][C][G] = 0;
 
    REP(i, n){
    	if(i<=2) continue;
    	dump(i)
    	REP(j, 4)REP(k, 4)REP(l, 4)REP(m, 4){
    		if(k == A && l == G && m == C) continue;
    		if(k == G && l == A && m == C) continue;
    		if(k == A && l == C && m == G) continue;
    		if(j == A && l == G && m == C) continue;
    		if(j == A && k == G && m == C) continue;
    		dp[i+1][k][l][m] += dp[i][j][k][l];
    		dp[i+1][k][l][m] %= mod;
    	}
    }
    ll res = 0;
    REP(j, 4)REP(k, 4)REP(l, 4){
    	dump(dp[n][j][k][l])
    	res += dp[n][j][k][l];
    	res %= mod;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
N, L = map(int, input().split())
a = sum(L + i for i in range(N))
min_ = None
for i in range(N):
    b = sum(L + j for j in range(N) if i != j)
    if min_ is None or abs(a - b) < abs(a - min_):
        min_ = b
print(min_)

Measured memory_bytes: 38896
# AGC002B - Box and Ball
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    X = tuple(tuple(map(int, input().split())) for _ in range(M))
    R = [0] * (N + 1)  # red ball may be in box i
    R[1] = 1
    C = [1] * (N + 1)  # number of balls in box i (count)
    for x, y in X:
        R[y] = 1 if R[x] or R[y] else 0
        C[x] -= 1
        C[y] += 1
        R[x] = 0 if C[x] == 0 else R[x]
    ans = sum(R[1:])
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 18848
#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 unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    int p[10];
    cin>> n;
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
   sort(p,p+n);
   p[n-1]=0.5*p[n-1];
   int sum=0;
   for(int i =0;i<n;i++){
       sum+=p[i];

   }
   cout<<sum<<endl;
   

    return 0;
}

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

struct UnionFind {
  vector<int> par;
    
  UnionFind(int n) : par(n, -1) { }
  void init(int n) { par.assign(n, -1); }
    
  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
    
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
    
  bool merge(int x, int y) {
    x=root(x);
    y=root(y);
    if (x==y) return false;
    if (par[x]>par[y]) swap(x, y);
    par[x]+=par[y];
    par[y]=x;
    return true;
  }
    
  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  int N,M,K; cin>>N>>M>>K;
  UnionFind uf(N);
  vector<int> A(N);
  rep(i, M) {
    int x,y; cin>>x>>y;
    x--; y--;
    uf.merge(x, y);
    A[x]++, A[y]++;
  }
  rep(i, K) {
    int x,y; cin>>x>>y;
    x--; y--;
    if (uf.issame(x, y)) A[x]++, A[y]++;
  }
  rep(i, N) {
    if (i) cout<<" ";
    cout<<uf.size(i)-A[i]-1;
  }
  cout<<endl;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll n;cin >>n;
   ll c=n;
   ll sum=0;
   while(c>0){
       sum+=c%10;
       c/=10;
   }
   if(n%sum==0){
       puts("Yes");
   }
   else puts("No");
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int stoneCount[n];
	int playerCount[n];
	for(int i = 0; i < n; i++){
		cin >> stoneCount[i] >> playerCount[i];
	}
	for(int i = 0; i < n; i++){
		int win = stoneCount[i]%playerCount[i];
		if(win == 0){
			win = playerCount[i];
		}
		cout << win <<'\n';
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
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; }

int main(){
    ll n;cin>>n;
    vector<ll> d(n);rep(i,n)cin>>d[i];
    ll m;cin>>m;
    vector<ll> t(m);rep(i,m)cin>>t[i];
    multiset<ll> x;
    rep(i,n){
        x.insert(d[i]);
    }
    rep(i,m){
        if(x.count(t[i])){
            x.erase(x.find(t[i]));
        }
        else {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;


}

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

int main()
{
  ll N;
  cin >> N;
  string s = to_string(N);
  ll S = 0;
  for (ll i = 0; i < s.length(); i++)
  {
    S += s[i] - '0';
  }
  if (N % S == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3692
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <cstring>
#include <ctime>
#include <vector>
#define inf 1e9
#define ll long long
#define For(i,j,k) for(ll i=j;i<=k;i++)
#define Dow(i,j,k) for(ll i=k;i>=j;i--)
using namespace std;
inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }
inline void write(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10);   putchar(x%10+'0');  }
inline void writeln(ll x){write(x);puts("");}
int a,b,c;
int main()
{
	a=read();b=read();c=read();
	int ans=min(min(a+b,b+c),a+c);
	writeln(ans);
}  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>

using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll mod = 1e9+7;
    ll n,k; cin>>n>>k;
    int a[n];
    rep(i,n)cin>>a[i];
    ll ans = 0;
    rep(i,n){
        ll cnt1 = 0, cnt2 = 0;
        rep(j,i){
            if(a[j]>a[i])cnt1++;
        }
        rep(j,n){
            if(a[j]>a[i])cnt2++;
        }
        ans += cnt1*k +(k*(k-1)/2)%mod*cnt2%mod;
        ans %= mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
    Cout("Yes");
  else
    Cout("No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    long X;
    cin >> X;
    /*if(X/100 != X/105) cout << 1 << endl; 
    else if(X<100)cout << 0 << endl;
    else cout << 0 << endl;*/
    bool ans = false;
    for(int i=1;i<10000;i++){
        if(100*i <= X && 105*i >= X) ans = true; 
    }
    if(ans) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 888
function main(input) {
    var inputArray = input.split(' ');
    var a = parseInt(inputArray[0]);
    var b = parseInt(inputArray[1]);

    if (a > 8 || b > 8){
        console.log(':(');
    } else {
        console.log('Yay!');
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
//It will be AC.I'm sure.
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ba=0;
	cin>>n;
	for(int t=111;t<=n*111;t++)
	{
		if(t/100<=n&&(t/10)%10<=n&&(t/10)%10>0&&t%10<=n&&t%10>0)
		{
			ba++;
			//cout<<t<<" ";
		}
	}
	cout<<ba;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
	ll n, m;
	cin >> n >> m;
	if(n == m && n == 1) cout << 1 << endl;
	else if(n == 1 || m == 1) cout << max<ll>(0, max(n, m) - 2) << endl;
	else cout << n * m - (2 * n + 2 * m - 4) << endl;
	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<long long> cnt(100001, 0);
  for (int i = 0; i < N; i++) cnt.at(A.at(i))++;
  long long S = 0;
  for (int i = 0; i < N; i++) S += A.at(i);

  int Q; cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; i++) cin >> B.at(i) >> C.at(i);
  for (int i = 0; i < Q; i++) {
    long long b = B.at(i);
    long long c = C.at(i);
    S -= b * cnt.at(b);
    S += c * cnt.at(b);
    cnt.at(c) += cnt.at(b);
    cnt.at(b) = 0;
    cout << S << endl;
  }
}

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n, k;
        cin >> n >> k;

        set<long> s;
        while (k--) {
            long d;
            cin >> d;

            while (d--) {
                long x;
                cin >> x;
                s.insert(x);
            }
        }
        long ans = n - s.size();
        printf("%lld\n", ans);
    }
}


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

using namespace std;

#define INF 1e9 + 5

typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0;i<n;i++)
		cin >> v[i];
		
	vector<int> dp(n + 1,INF);	
	dp[0] = 0;
	for(int i = 0;i<n - 1;i++){
		dp[i + 1] = min(dp[i] + abs(v[i] - v[i + 1]), dp[i + 1]);
		dp[i + 2] = min(dp[i] + abs(v[i] - v[i + 2]), dp[i + 2]);
	}
	cout << dp[n - 1] << "\n";
}

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

int main(){
	string n;
	cin>>n;
	int a[n.length()];
	int p[n.length()];
	int sum=0;
	for(int i=0;i<n.length();++i){
		a[i]=n.at(i);
		p[i]=a[i]-'0';
		sum+=p[i];
	} 
	if (sum%9==0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 5264
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#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 = 1e12;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int e;
	while(cin >> e, e){
		int MIN = INF;
		rep(i, 0, 101){
			rep(j, 0, 1001){
				int x = e - i * i * i - j * j;
				if(x < 0) break;
				chmin(MIN, i + j + x);
			}
		}
		cout << MIN << endl;
	}
}


Measured memory_bytes: 3032
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
typedef long long ll;
using namespace std;

ll pow10(int x){
  ll r = 1;
  while(x--) r *= 10;
  return r;
}

int main(){
  ll n;
  while(scanf("%lld", &n) && n){
    int f = ((n > 0)? 1 : -1);
    n *= f;
    ll res = 0;
    for(int i = 0; n; n /= 10, i++){
      int m = n % 10;
      if((f == 1 && i % 2 == 0) || (f == -1 && i % 2)){
	res += m * pow10(i);
      }else if(m){
	res += (10 - m) * pow10(i);
	n += 10;
      }
    }
    printf("%lld\n", res);
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

string s, t;
int main(){
    while (cin >> s >> t) {
        bool ok = false;
        for (int i = 0; i < s.size(); i++) {
            string ss = s.substr(1) + s[0];
            if (ss == t) ok = true;
            s = ss; 
        }
        if (ok) puts("Yes");
        else puts ("No");
    }
}

Measured memory_bytes: 3596
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator<(const Puzzle &p)const{
    for(int i=0;i<N2;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};

static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};

bool isTarget(Puzzle p){
  for(int i=0;i<N2;i++)
  if(p.f[i]!=(i+1))return false;
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle>Q;
  map<Puzzle,bool>V;
  Puzzle u,v;
  s.path = "";
  Q.push(s);
  V[s]=true;

  while(!Q.empty()){
    u=Q.front();Q.pop();
    if(isTarget(u))return u.path;
    int sx =u.space/N;
    int sy =u.space%N;
    for(int r=0;r<4;r++){
      int tx =sx+dx[r];
      int ty =sy+dy[r];
      if(tx<0||ty<0||tx>=N||ty>=N)continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
        V[v]=true;
        v.path+=dir[r];
        Q.push(v);
      }
    }
  }

  return "unsolvable";
}

int main(){
  Puzzle in;

  for(int i=0;i<N2;i++){
    cin >> in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans =bfs(in);
  cout << ans.size() << endl;

  return 0;
}



Measured memory_bytes: 30616
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define KAISU 150

int inD;
int c[27] = {0};
int s[366][27] = {0};
int t[366] = {0};
int last[366] = {0};
long long int man = 0;

long long int cal_manzoku(void);
void input_A(void);
void input_t(void);
long long int exec_query(int &d, int &q);
void print_t(void);

int main(){

    srand((unsigned) time(NULL));

    input_A();
    // input_t();
    for(auto i=1; i<=inD; ++i){
        t[i] = rand() % 26 + 1;
    }
    man = cal_manzoku();
    // printf("%lld\n", man);

    for(auto i=0; i<KAISU; ++i){
        int rand_day = rand()%365 + 1;
        int rand_t = rand()%26 + 1;
        int t_pre = t[rand_day];
        long long man_pre = man;

        t[rand_day] = rand_t;
        man = cal_manzoku();
        if(man_pre > man){
            t[rand_day] = t_pre;
        }

    }
    print_t();

    // int m;
    // scanf("%d", &m);
    // for(int i=1; i<=m; ++i){
    //     int d,q;
    //     scanf("%d %d", &d, &q);
    //     man = exec_query(d, q);
    //     print_t();
    //     printf("%lld\n", man);
    // }

}

void print_t(void){
    for(int i=1; i<=inD; ++i){
        printf("%d\n", t[i]);
    }
    // printf("\n");
}

void input_A(){
    scanf("%d", &inD);
    for(int i=1; i<=26; ++i){
        scanf("%d", &c[i]);
    }
    
    // // Test
    // for(int i=1; i<=26; ++i){
    //     printf("%d ", c[i]);
    // }
    // printf("\n\n");

    for(int i=1; i<=inD; ++i){
        for(int j=1; j<=26; ++j){
            scanf("%d", &s[i][j]);
        }
    }
    // // Test
    // for(int i=1; i<=inD; ++i){
    //     for(int j=1; j<=26; ++j){
    //         printf("%d ", s[i][j]);
    //     }
    //     printf("\n");
    // }
    // printf("\n\n");

    return;
}

void input_t(){

    // 問題B入力
    for(int i=1; i<=inD; ++i){
        scanf("%d", &t[i]);
    }

    // // Test
    // for(int i=1; i<=inD; ++i){
    //     printf("%d ", t[i]);
    // }
    // printf("\n\n");
}

long long int cal_manzoku(){

    long long int manzoku=0;

    for(int day=1; day<=inD; ++day){
        long long int down = 0;
        last[t[day]] = day;
        for(int i=1; i<=26; ++i){
            down += c[i]*(day - last[i]);
            // printf("down %d %lld %d %d\n", day, down, c[i], last[i]);
        }

        manzoku = manzoku + s[day][t[day]] - down;
        // printf("manzoku %d %d %lld %d %lld\n", day, t[day], manzoku, s[day][t[day]], down);
        // printf("last %d %d\n", t[day], last[t[day]]);

        // printf("%lld\n", manzoku);
    }

    return(manzoku);

}

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

#define MOD (1000 * 1000 * 1000 + 7)
typedef long long ll;
typedef long double ld;

#define maxn 55
#define maxs 2555
ll dp[maxn][maxn][maxs];

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

    vector<int> num(n);
    for(int i = 0; i < n; ++i)
        cin >> num[i];

    dp[0][0][0] = 1;
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            for(int k = 0; k < maxs; ++k) {
                if(dp[i][j][k] == 0)
                    continue;
                dp[i + 1][j + 1][k + num[i]] += dp[i][j][k];
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }

    ll sum = 0;
    for(int i = 1; i <= n; ++i)
          sum += dp[n][i][a * i];

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 55552
import java.util.*;

public class Main{
    static Scanner sc = new Scanner(System.in);
    static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int[] b = new int[n];
        int bmax = 0;
        for(int i=0; i<n; i++){
            int t = Integer.parseInt(sc.next());
            a[i] = t;
        }
        Arrays.sort(a);
        reverse(a);
        
        
        //にぶたん
        int ub = a[0];
        int lb = 1;
        for(int i=0; i<60; i++){
            int mid = (ub+lb)/2;
            int sum = 0;
            for(int j=0; j<n; j++){
                int m = (a[j]+mid-1)/mid-1;
                sum += m;
                //System.out.println(m);
            }
            //System.out.println(sum + " : " + mid);
            if(sum > k){
                lb = mid;
            }else{
                ub = mid;
            }
        }
        
        System.out.println(ub);
        
    }
    
    public static void reverse(int[] x){
        for(int i=0; i<x.length/2; i++){
            int tmp = x[i];
            x[i] = x[x.length-1-i];
            x[x.length-1-i] = tmp;
        }
    }
}


Measured memory_bytes: 61600
#include <iostream>
using namespace std;
int N,T,A,M,Q,i,j,k,l;
int H[9999999];
int S[9999999];
int P[9999999];

int main(){
    cin >> N >> T >> A;
    for (i=0; i<N; i++) cin >> H[i];
    for (j=0; j<N; j++) S[j]=1000*T-6*H[j];
    for (k=0; k<N; k++){
         if (S[k]>1000*A) {P[k]=S[k]-1000*A;}
        else {P[k]=1000*A-S[k];}
    }
    M=P[0];
    Q=0;
    for(l=1;l<N;l++){
		if(M>P[l]) {
                                M=P[l];
                                Q=l;
                 }
    }
    cout << Q+1 << endl;
}

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

int findSumOfDigits(int n){
  int sum = 0;
  while (n > 0){
    sum += n % 10;
    n /= 10;
  }
  
  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i){
    int sum = findSumOfDigits(i);
    if (sum >= A && sum <= B){
      total += i;
    }
  }
  
  cout << total << endl;
}
  




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

int main() {
  
  int N, fx, N1, cp, a = 100000000;
  cin >> N;
  N1 = N;
  for (int i = 0; i < 9; i++) {
    cp = N;
    cp /= a;
    fx += cp;
    N -= cp * a;
    a /= 10;
  }
  if (N1 % fx == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long a = scan.nextLong();
    double b = scan.nextDouble();
    if ((a == 0) || (b==0)){
      System.out.println("0");
      return;
    }
    String t = b+"";
    long t2 = 0;
    long t3 = 0;

    long t1 = Integer.parseInt(String.valueOf(t.charAt(0)));
    if (t.length()>=3){
      t2 = Integer.parseInt(String.valueOf(t.charAt(2)));
    }
    if (t.length()>=4){
      t3 = Integer.parseInt(String.valueOf(t.charAt(3)));
    }
    long c = (a*t1*100)+(a*t2*10)+(a*t3);
    String g = c+"";
    if (g.length()<=2){
      System.out.println("0");
      return;
    }

    for (int i=0;i<g.length()-2;i++){
      System.out.print(g.charAt(i));
    }
    System.out.println("");
  }
}


Measured memory_bytes: 39836
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[1])

c = sum([i for i,j in ab])
abmax = max([j for i,j in ab])

ab.reverse()
ans = "Yes"
x = c + 0
for i,j in ab:
    if not x <= j:
        ans = "No"
        break
    x -= i

print(ans)

Measured memory_bytes: 103164
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

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

	int n, a, b;
	cin >> n >> a >> b;
	int alr = (n / (a + b)) * a;
	n %= (a + b);
	cout << alr + min(n, a) << endl;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    p = [0] + list(map(int, readline().split()))

    cnt = 0
    for i in range(N + 1):
        if p[i] != i:
            cnt += 1

    if cnt <= 2:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61792
#include<bits/stdc++.h>
using namespace std;
 void solve(){
  int n,k;
  cin>>n>>k;int a[n];
  for (int i = 0; i < n; ++i)
  {
      cin>>a[i];
  }
  sort(a,a+n);int s=0;
  for (int i = 0; i < k; ++i)
  {
      s+=a[i];
  }
  cout <<s<<endl;
}
int main()
{
     solve();
     return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  int i;
  int ni;
  for(i=0;i<n;i++){
    cin>>a.at(i);
  }
  int v;
  if(n%2==1){
    ni=(n-1)/2;
    b.at(ni)=a.at(0);
    v=1;
    for(i=1;i<=ni;i++){
      b.at(ni+i)=a.at(v);
      b.at(ni-i)=a.at(v+1);
      v+=2;
    }
  }else{
    ni=n/2;
    b.at(ni)=a.at(0);
    v=1;
    for(i=1;i<ni;i++){
      b.at(ni-i)=a.at(v);
      b.at(ni+i)=a.at(v+1);
      v+=2;
    }
    b.at(0)=a.at(n-1);
  }
  cout<<b.at(0);
  if(n!=1){
  for(i=1;i<n;i++){
    cout<<" "<<b.at(i);
  }
  }
}


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

int main(){    
  long long n;
  cin >> n;
  vector<long long>l(n+1,0);
  l.at(0) = 2;
  l.at(1) = 1;
  for(int i=2;i<n+1;i++){
    l.at(i) = l.at(i)+l.at(i-1)+l.at(i-2);
  }
  cout << l.at(n) << endl;
}


Measured memory_bytes: 256
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}




signed main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    for(int i = 0; i < h; ++i)
        cin >> c[i];
    int ans = 0;
    for(int i = 0; i < (1 << h); ++i){
        for(int j = 0; j < (1 << w); ++j){
            vector<string> cp = c;
            int cnt = 0;
            for(int ii = 0; ii < h; ++ii){
                for(int jj = 0; jj < w; ++jj){
                    if((i & (1 << ii)) || (j & (1 << jj)))
                        cp[ii][jj] = '?';
                    if(cp[ii][jj] == '#')
                        ++cnt;
                }
            }
            ans += (cnt == k);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n+1];

        int count = 0;
        
        for(int i = 1; i <= n; i++){
            p[i] = sc.nextInt();
        }
        
        for(int i = 2; i<n; i++){
            if(p[i] < p[i-1] && p[i] > p[i+1]){
                count++;
            }
            if(p[i] > p[i-1] && p[i] < p[i+1]){
                count++;
            }
        }
        
        System.out.println(count);

    }

}


Measured memory_bytes: 21844
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


#隣接リスト 1-order
def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    X, Y, A, B, C = NMI()
    P = NLI()
    Q = NLI()
    R = NLI()
    reds = [[1, p] for p in P]
    greens = [[2, q] for q in Q]
    skels = [[0, r] for r in R]
    apples = reds + greens + skels
    apples.sort(key=lambda x: x[1], reverse=True)

    colors = [0, 0, 0]
    limits = [10**9, X, Y]
    ans = 0
    for color, a in apples:
        if sum(colors) >= X + Y:
            break

        if colors[color] <= limits[color] - 1:
            colors[color] += 1
            ans += a
            continue

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 54476
N=int(input())
l=list(map(int, input().split()))
s=0
for i in range(N):
  for j in range(N):
    for k in range(N):
      if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i] and l[i]<l[j]+l[k] and l[j]<l[i]+l[k] and l[k]<l[i]+l[j]:
        s+=1
print(int(s/6))


Measured memory_bytes: 9132
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if (a>b){
        printf("a > b\n");
    }
    else if (a<b){
        printf("a < b\n");
    }
    else{
        printf("a == b\n");
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<tuple<string, int, int>> t(n);
  rep(i, n) {
    string s;
    int a;
    cin >> s >> a;
    t[i] = make_tuple(s, -a, i);
  }

  sort(all(t));
  rep(i, n) {
    int a;
    tie(ignore, ignore, a) = t[i];
    cout << a+1 << endl;
  }
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,ll> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

typedef pair<ll,int> edge;

struct S {
	int a,b;ll c;
	S(int x,int y,ll z):a(x),b(y),c(z) {}
};

int n,m,s,t;
vector<P> g[100000];
vector<S> LIST;
ll d[2][100000],dp[2][100000];
const int MOD=1e9+7;

void dijkstra(int type,int start) {
	priority_queue<edge,vector<edge>,greater<edge> > pq;
	REP(i,n) d[type][i]=LINF;
	dp[type][start]=1;
	d[type][start]=0;
	pq.push(P(0,start));
	while(!pq.empty()) {
		edge p=pq.top();pq.pop();
		int v=p.se;
		if(d[type][v]<p.fi) continue;
		for(auto e:g[v]) {
			if(d[type][e.fi]<d[type][v]+e.se) continue;
			if(d[type][e.fi]==d[type][v]+e.se) (dp[type][e.fi]+=dp[type][v])%=MOD;
			else {
				dp[type][e.fi]=dp[type][v];
				d[type][e.fi]=d[type][v]+e.se;
				pq.push(edge(d[type][e.fi],e.fi));
			}
		}
	}
}

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

	cin>>n>>m>>s>>t;
	s--,t--;
	REP(i,m) {
		int v,u;ll D;cin>>v>>u>>D;
		v--,u--;
		g[u].pb(P(v,D));g[v].pb(P(u,D));
		LIST.pb(S(u,v,D));
	}

	dijkstra(0,s);
	dijkstra(1,t);

	ll dif=0;

	REP(i,m) {
		int u=LIST[i].a,v=LIST[i].b;ll D=LIST[i].c;
		if(d[0][u]>d[0][v]) swap(u,v);
		if(d[0][u]+D!=d[0][v]) continue;
		if(d[0][u]*2<d[0][t]&&d[0][v]*2>d[0][t]&&d[0][u]+d[1][v]+D==d[0][t]) {
			ll num=(dp[0][u]*dp[1][v])%MOD;
			(dif+=num*num)%=MOD;
		}
	}
	REP(i,n) {
		if(d[0][i]+d[1][i]==d[0][t]&&d[0][i]==d[1][i]) {
			ll num=(dp[0][i]*dp[1][i])%MOD;
			(dif+=num*num)%=MOD;
		}
	}
	cout<<(dp[0][t]*dp[1][s]-dif+MOD)%MOD<<endl;

	//REP(i,n) cout<<dp[0][i]<<' '<<dp[1][i]<<endl;

	return 0;
}


Measured memory_bytes: 22088
#include <iostream>
#include <cmath>
#include <iomanip>

int main() {
  static const double pi = 3.141592653589793;
  double a, b, c;
  std::cin >> a >> b >> c;
  double radian = pi / 180;
  std::cout << std::fixed;
  double s = 0.5 * a * b * std::sin(c * radian);
  std::cout << std::setprecision(8) << s << "\n";
  std::cout << std::setprecision(8) << std::sqrt(a * a + b * b - 2 * a * b * std::cos(c * radian)) + a + b << "\n";
  std::cout << std::setprecision(8) << s * 2 / a << "\n";
}


Measured memory_bytes: 3424
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>

using namespace std;

long long N;
int main() {
	cin >> N;
	int a[100000];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int x = 0;
	for (int i = 0; i < N; i++) {
		x = a[x]-1;
		if (x == 1) {
			cout << i + 1;
			return 0;
		}
	}
	cout << "-1";
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	  double r=0,a=0,b=0;
	  cin>>r;
	  a=r*r;
	  b=r*2;
	  cout<<fixed<<a*M_PI<<" "<<fixed<<b*M_PI<<endl;
	  
	  return 0;
	  }	 

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

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

  ll N; cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) ans += i;
  }
  cout << ans << '\n';
  return 0;
}

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

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

  while(1){
    int n;
    cin >> n;
    if(n== 0) break;
    int l=0,r=0,wh=0,ans=0;;

    rep(i,n){
      string s;
      cin >> s;
      if(s == "lu") l = 1;
      else if(s == "ld") l = 0;
      else if(s == "ru") r = 1;
      else if(s == "rd") r = 0;

      if(wh == 0 && l == 1 && r == 1){
	ans++; wh = 1;
		 } 
      else if(wh == 1 && l == 0 && r == 0){
	ans++; wh = 0;
      }
    }
    cout << ans << endl; 
  }
    return 0;
  }

Measured memory_bytes: 1212
//   PIGMEISTER™   //

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

#define ll long long
#define ull unsigned long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define modinv(x) powah(x,mod-2)
#define ncr(n,r) (((fact[n]*modinv(fact[n-r]))%mod*modinv(fact[r]))%mod)
#define factorial fact.pb(1);sidha(i,1,MAX)fact.pb((fact[i-1]*i)%mod)
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod (ll)1000000007
//#define mod (ll)998244353
#define MAX 100005

int main()
{
    jaldi;
    
    ll r;
    cin >> r;
    long double pi = 3.1415926535;
    cout << (long double)2*pi*r;
    
    return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <stdio.h>
using namespace std;
int pr[1000003];
int main() {
 int i,j,n,p,m,f,e,g;
 for (i=2;i<1000000;i++) if (pr[i]==0) { pr[i]=2; for (j=i*2;j<1000000;j+=i) pr[j]=1;}
 for (i=2,j=0;i<1000000;i++) { j+=pr[i]>1; pr[i]=j; }
 while(cin >> n) {
	 if (n==0) break;
	 g=0;
	 for (;n>0;n--) {
      cin >> p >> m;
	  f=p-m<0 ? 0 : p-m;
	  e=p+m>999999 ? 999999 : p+m;
	  j=pr[e]-pr[f-1];
	  if (j==0) g--;  else g+=j-1;
	 }
	 cout << g << endl;
 }
 return 0;
 }

Measured memory_bytes: 5064
from collections import deque
class csr:
    def __init__(self,N,edges):
        self.start = [0]*(N+1)
        self.elist = [0]*len(edges)
        for e in edges:
            self.start[e[0]+1] += 1
        for i in range(1,N+1):
            self.start[i] += self.start[i-1] 
        counter = self.start[:]
        for e in edges:
            self.elist[counter[e[0]]] = e[1]
            counter[e[0]] += 1

class scc_graph:
    def __init__(self,N):
        self.N = N
        self.edges = []
    
    def add_edge(self,v,w):
        self.edges.append((v,w))

    def scc_ids(self):
        g = csr(self.N,self.edges)
        now_ord = group_num = 0
        visited = deque()
        low = [0]*self.N
        order = [-1]*self.N
        ids = [0]*self.N
        parent = [-1]*self.N
        for i in range(self.N):
            if order[i] == -1:
                stack = deque()
                stack.append(i)
                stack.append(i)
                while stack:
                    v = stack.pop()
                    if order[v] == -1:
                        low[v] = order[v] = now_ord
                        now_ord += 1
                        visited.append(v)
                        for i in range(g.start[v],g.start[v+1]):
                            to = g.elist[i]
                            if order[to] == -1:
                                stack.append(to)
                                stack.append(to)
                                parent[to] = v
                            else:
                                low[v] = min(low[v],order[to])
                    else:
                        if low[v] == order[v]:
                            while True:
                                u = visited.pop()
                                order[u] = self.N
                                ids[u] = group_num
                                if u == v:
                                    break
                            group_num += 1
                        if parent[v] != -1:
                            low[parent[v]] = min(low[parent[v]],low[v])
        for i,x in enumerate(ids):
            ids[i] = group_num-1-x

        return group_num,ids
    
    def scc(self):
        group_num,ids = self.scc_ids()
        groups = [[] for _ in range(group_num)]
        for i,x in enumerate(ids):
            groups[x].append(i)
        return groups
    
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N,M = map(int,readline().split())
ab = list(map(int,read().split()))
sg = scc_graph(N)

it = iter(ab)
for a,b in zip(it,it):
    sg.add_edge(a,b)

scc = sg.scc()
print(len(scc))
for group in scc:
    print(*([len(group)] + group))

Measured memory_bytes: 213660
#include<iostream>
using namespace std;
int  main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
	cout<<"a < b"<<endl;
	}
	else if(a>b){
	cout<<"a > b"<<endl;
	}
	else{
	cout<<"a == b"<<endl;
	}
return 0;
}

Measured memory_bytes: 3032
n = int(input())
w = list(map(int, input().split()))
m = 1000
for i in range(n):
    x = 0
    y = 0
    for j in range(i):
        x += w[j]
    for j in range(i, n):
        y += w[j]
    z = x - y
    if z < 0:
        z = -z
    if z < m:
        m = z
print(m)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> c(n);
  for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    c[i]=make_pair(a,b);
  }
  sort(c.begin(),c.end());
  cout << c[n-1].first+c[n-1].second << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }
        sc.close();

        if(a[0] != 0){
            System.out.println(-1);
            return;
        }
        for(int i=0; i<n-1; i++){
            if(a[i+1]-1 > a[i]){
                System.out.println(-1);
                return;
            }
        }

        long ans = 0;

        for(int i=1; i<n-1; i++){
            if(a[i] >= a[i+1]){
                ans += a[i];
            }
        }
        ans += a[n-1];

        System.out.println(ans);
    }
}

Measured memory_bytes: 86588
N, K = map(int, input().split())
X_list = list(map(int, input().split()))
INF = 10 ** 18
ans = INF
import bisect

zero_index = bisect.bisect_left(X_list, 0)
candidate_list = []
ans = INF
for i in range(K + 1):
    head = zero_index - i
    tail = head + K - 1
    if head < 0 or tail > N - 1: continue
    if i == 0:
        ans = min(ans, abs(X_list[tail]))
    elif i == K:
        ans = min(ans, abs(X_list[head]))
    else:
        head_abs = abs(X_list[head])
        tail_abs = abs(X_list[tail])
        ans = min(ans, head_abs + tail_abs + min(head_abs, tail_abs))
print(ans)


Measured memory_bytes: 20112
// review
#include <iostream>
#include <iomanip>

using namespace std;

double w, h, x, y;

void solve() {
  bool multiple = (w == 2 * x && h == 2 * y);

  cout << setprecision(10) << (w * h / 2.0) << " " << (multiple ? "1" : "0") << endl;
}

int main() {
  cin >> w >> h >> x >> y;
  solve();
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, s; cin >> n >> m >> s;
    using edge = array<int, 3>;
    vector<vector<edge>> e(n);
    vector<int> c(n), d(n);
    for (int i = 0; i < m; i++) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        u--, v--;
        e[u].push_back({v, a, b});
        e[v].push_back({u, a, b});
    }
    for (int i = 0; i < n; i++) cin >> c[i] >> d[i];
    const int A = n * 50;
    const long long inf = 1e18;
    long long cost[n][A+1];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= A; j++) {
            cost[i][j] = inf;
        }
    }
    s = min(A, s);
    cost[0][s] = 0;
    set<tuple<long long, int, int>> st;
    st.emplace(cost[0][s], 0, s);
    while (!st.empty()) {
        auto [x, i, ai] = *st.begin();
        st.erase(st.begin());
        if (cost[i][ai] != x) continue;
        if (cost[i][min(A, ai+c[i])] > x + d[i]) {
            cost[i][min(A, ai+c[i])] = x + d[i];
            st.emplace(x+d[i], i, min(A, ai+c[i]));
        }
        for (auto &[j, a, b]: e[i]) {
            if (ai < a) continue;
            if (cost[j][ai-a] > x + b) {
                cost[j][ai-a] = x + b;
                st.emplace(x+b, j, ai-a);
            }
        }
    }
    for (int i = 1; i < n; i++) {
        long long ans = inf;
        for (int a = 0; a <= A; a++) {
            ans = min(ans, cost[i][a]);
        }
        cout << ans << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 9220
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    int sum = 0;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    int ave = sum / n;
    int ave_p1 = -1;
    if ( sum % n != 0 ) {
        ave_p1 = ave + 1;
    }
    int ans = 1e8;
    rep(ri, 2) {
        int ave_sel = ( ri == 0 ) ? ave : ave_p1;
        int tmp_ans = 0;
        rep(i, n) {
            tmp_ans += ( a[i] - ave_sel ) * ( a[i] - ave_sel );
        }
        ans = min(ans, tmp_ans);
    }

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

Measured memory_bytes: 256
class MyBinaryNode
  attr_accessor :parent, :left, :right
  attr_reader :id, :v

  def initialize(id, v)
    @id = id
    @parent = nil
    @left = nil
    @right = nil
    @v = v
  end

  def to_s
    @v
  end
end

def pre_order(node)
  if node.nil?
    return 
  end
  print ' '
  print node.v
  pre_order(node.left)
  pre_order(node.right)
end

def in_order(node)
  if node.nil?
    return 
  end
  in_order(node.left)
  print ' '
  print node.v
  in_order(node.right)
end

# def post_order(nodes, id)
#   if id.nil?
#     return 
#   end
#   post_order(nodes, nodes[id].left)
#   post_order(nodes, nodes[id].right)
#   print ' '
#   print id
# end

def print_nodes(node)
  in_order(node)
  puts ""
  pre_order(node)
  puts ""
end

def insert(z, root)
  y = nil
  x = root
  while !x.nil? do
    y = x
    if z.v < x.v
      x = x.left
    else
      x = x.right
    end
  end
  
  z.parent = y

  if y.nil?
    # skip
  elsif z.v < y.v
    y.left = z
  else
    y.right = z
  end

end

def find(x, k)
  while !x.nil? && k != x.v do
    if k < x.v
      x = x.left
    else
      x = x.right
    end
  end

  x
end

n = gets.to_i
root = nil
i = 0
n.times do
  order, v = gets.split
  v = v.to_i
  case order
  when "insert"
    node = MyBinaryNode.new(i, v)
    insert(node, root)
    if i == 0
      root = node
    end
    i += 1
  when "print"
    print_nodes(root)
  when "find"
    if find(root, v)
      puts "yes"
    else
      puts "no"
    end
  end
end



Measured memory_bytes: 50000
using System;
using System.Linq;
using System.Collections.Generic;


namespace Test1 {

    class ClassMain {

        public static int cnt = 0;

        public static void countUp(char[,] map, int y, int x) {
            if (x < 0 || map.GetLength(1) <= x
                || y < 0 || map.GetLength(0) <= y) {
                    return;
            }
            if (map[y, x] != '.') { return; }
            cnt++;
            map[y, x] = 'X';
            countUp(map, y - 1, x);
            countUp(map, y, x-1);
            countUp(map, y + 1, x);
            countUp(map, y, x+1);            
        }

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int n = ints[0]; 
                //int n = int.Parse(line);                
                if(n==0){break;}
                int y = ints[1];

                cnt = 0;
                char[,] map = new char[y, n];
                int startX = -1, startY = -1;
                for (int i = 0; i < y; i++) {
                    string str = Console.ReadLine();
                    for (int j = 0; j < n; j++) {
                        map[i, j] = str[j];
                        if (str[j] == '@') {
                            startX = j; startY = i;
                        }
                    }
                }
                //stored.

                map[startY, startX] = '.';
                countUp(map, startY, startX);
                Console.WriteLine(cnt);

            }   
        }   
    }
}

Measured memory_bytes: 6108
#include <iostream>
#include <string>
using namespace std;
int a, b;
string st;
bool w = true;
int main() {
	cin >> a >> b;
	cin >> st;
	for (int i = 0; i < a; i++) {
		if (int(st[i]) > 57 || int(st[i]) < 48) {
			w = false;
		}
	}
	if (st[a] != '-')
		w = false;
	for (int i = a + 1; i < a + b; i++) {
		if (int(st[i]) > 57 || int(st[i]) < 48)
			w = false;
	}
	if (w)
		cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
P = [None] * N
A = [0] * N
for i in range(N):
    x, y, A[i] = map(int, input().split())
    P[i] = (x, y)

left = max({P[i][0] for i in range(N) if A[i] == 1} | {0})
right = min({P[i][0] for i in range(N) if A[i] == 2} | {W})
bottom = max({P[i][1] for i in range(N) if A[i] == 3} | {0})
top = min({P[i][1] for i in range(N) if A[i] == 4} | {H})
if right <= left or top <= bottom:
    print(0)
else:
    print((right - left) * (top - bottom))


Measured memory_bytes: 3064