akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

// all_of
// partial_sum, adjacent_difference

#if _DEBUG
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#endif

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif
string s;
string t;
int cnt;
int main() {
	cin >> s;
	t = s;
	reverse(t.begin(), t.end());
	int i = 0, j = 0;
	while (i < s.size() || j < t.size()) {
		if (s[i] != t[j]) {
			if (s[i] == 'x') {
				++i; ++cnt;
			} else if(t[j] == 'x'){
				++j; ++cnt;
			} else {
				cout << -1 << endl;
				return 0;
			}
		} else {
			++i; ++j;
		}
	}
	cout << cnt / 2 << endl;

	return 0;
}






Measured memory_bytes: 512
#include <iostream>

using namespace std;

int p, q, a, n, ans;

void func(int numer, int demon, int pre, int mlt, int count)
{
	if (p * demon == q * numer) {
		ans++;
		return;
	}

	if (n == count) return;
	if (q * numer > p * demon) return;

	for (int i = pre; mlt * i < a + 1; i++) func(numer * i + demon, demon * i, i, mlt * i, count + 1);
}

int main()
{
	while (cin >> p >> q >> a >> n) {
		if (!p && !q && !a && !n) break;
		ans = 0;
		func(0, 1, 1, 1, 0);
		cout << ans << endl;
	}
}


Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N, M;
int dp[100001];
vector<vector<int> > G;

int solve(int v){
	if(dp[v] != -1) return dp[v];
	int res = 0;
	for(int i=0; i<G[v].size(); i++){
		res = max(res, solve(G[v][i])+1);
	}

	return dp[v] = res;
}

int main(void){
	cin >> N >> M;
	G.assign(N, vector<int>());
	for(int i=0; i<M; i++){
		int x, y; cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
	}

	fill(dp, dp+100001, -1);

	int ans = 0;
	for(int i=0; i<N; i++){
		ans = max(ans, solve(i));
	}

	cout << ans << endl;
}

Measured memory_bytes: 8192
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
N, K = map(int, input().split())
L = list(map(int, input().split()))
#N = int(input())
#S = str(input())

L.sort(reverse=True)

sum = 0
for i in range(K) :
  sum += L[i]
  
print (sum)


Measured memory_bytes: 38256
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

ll mind(int x,vector<int> &v){
  int ok = v.size()-1,ng = -1;
  while(ok - ng > 1){
    int next = (ok+ng)/2;
    if(v[next] > x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}

ll maxd(int x,vector<int> &v){
  int ok = 0,ng = v.size();
  while(ng - ok > 1){
    int next = (ok+ng)/2;
    if(v[next] < x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}


int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i,N)cin >> L[i];
  sort(L.begin(),L.end());
  int ans = 0;
  for(int i = 0;i <= N-3;i++){
    for(int j = i+1;j <= N-2;j++){
      int a,b;
      a = mind(L[j]-L[i],L);
      b = maxd(L[i]+L[j],L);
      if(a <= j)a = j+1;
      ans += b - a +1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
N = gets.chomp!.to_i
a_s = []
N.times do
  a_s.append(gets.chomp!.to_i)
end

# pp "***********************************#{N}"
count = 1
_next = a_s[0]
(1...N).each do |i_1|
  #   puts "count:#{count}, next:#{_next}"
  if _next == 2
    puts count
    exit
  end
  _next = a_s[_next - 1]
  count += 1
end
puts -1



Measured memory_bytes: 15440
#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 rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvb vector<vb>
#define vvd vector<vd>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pb push_back
#define sz(s) (int)(s.size())


int main(){
  double r; cin >> r;
  cout << fixed << setprecision(10) << 2.0*r*3.1415936535 << endl;
}


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

int main() {
  int n, m, k;

  cin >> n >> m >> k;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      int x = i * m;
      int y = j * n;
      x = x > 0 && y > 0 ? x - (j * i) : x;
      y = y > 0 && x > 0 ? y - (i * j) : y;
      if (x + y == k) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int D; cin >> D;
	
	if (D == 25) {
		cout << "Christmas" << endl;	
	}else if (D == 24) {
		cout << "Christmas Eve" << endl;	
	}else if (D == 23) {
		cout << "Christmas Eve Eve" << endl;	
	}else if (D == 22) {
		cout << "Christmas Eve Eve Eve" << endl;	
	}
	return 0;
}


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

int main(){

  int n;
  string daseki;
  cin >> n;

  for(int i=0;i<n;i++){

    int a[5] = {0},count = 0,out = 0;

    while(1){
      if(out == 3) break;

      cin >> daseki;

      if(daseki == "HIT"){
	if(a[3] == 1){
	  count++;
	  a[3] = 0;
	}
	if(a[2] == 1){
	  a[3] = 1;
	  a[2] = 0;
	}
	if(a[1] == 1){
	  a[2] = 1;
	  a[1] = 0;
	}
	a[1] = 1;
      }

      if(daseki == "HOMERUN"){
	count++;
	for(int j=1;j<=3;j++){
	  if(a[j] == 1){
	    count++;
	    a[j] = 0;
	  }
	}
      }

      if(daseki == "OUT") out++;
    }

    cout << count << endl;

  }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)

int main() {
	int n,in,k,ans=0;
	vi v;
	cin >> n >> k;
	rep(i, n) {
		cin >> in;
		v.pb(in);
	}
	int l = 1,r=20000*n;
	int p = r;
	while (1) {
		bool s = true;
		p = (l + r) / 2;
		int c = 1, tmp = 0;
		rep(j,n) {
			tmp += v[j];
			if (tmp > p) {
				c++;
				tmp = v[j];
				if (tmp > p)s = false;
			}
		}
		if (c <= k&& s) {
			ans = p;
			if ((l + r) / 2 == r)break;
			r = p;
		}
		else {
			if ((l + r) / 2 == l)break;
			l = p;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int MAXN=210;
vector<int> g[MAXN]; // [0,n)->[0,m)
int mat[MAXN];bool vis[MAXN];
int match(int x){
	if(vis[x])return 0;
	vis[x]=true;
	for(int y:g[x])if(mat[y]<0||match(mat[y])){mat[y]=x;return 1;}
	return 0;
}
vector<pair<int,int> > max_matching(int n){
	vector<pair<int,int> > r;
	memset(mat,-1,sizeof(mat));
	fore(i,0,n)memset(vis,false,sizeof(vis)),match(i);
	fore(i,0,n)if(mat[i]>=0)r.pb({mat[i],i});
	return r;
}

int main(){FIN;
	int n; cin>>n;
	vector<ii> a(n),b(n);
	fore(i,0,n) cin>>a[i].fst>>a[i].snd;
	fore(i,0,n) cin>>b[i].fst>>b[i].snd;
	fore(i,0,n) fore(j,0,n) if(a[i].fst<b[j].fst&&a[i].snd<b[j].snd) g[i].pb(j);
	cout<<SZ(max_matching(n))<<"\n";
}

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

void solve(){
  int n; cin >> n;
  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      if(n == i * j){
        cout <<  "Yes\n";
        return;
      }
    }
  }
  cout << "No\n";
  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, D; cin >> N >> D;
vector< vector<int> > X(N, vector<int>(D));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < D; ++j) {
cin >> X[i][j];
}
}
int ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = i+1; j < N; ++j) {
int norm = 0;
for (int k = 0; k < D; ++k) {
int diff = abs(X[i][k] - X[j][k]);
norm += diff * diff;
}
// check whether norm = k for some k
bool flag = false;
for (int k = 0; k <= norm; ++k) {
if (k * k == norm) {
flag = true;
}
}
if (flag) ++ans;
}
}
cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding utf-8 -*-
n=int(input())
s=list(str(input()))
ans=0
h=[0]
for i in range(n):
    if  s[i]=="I":
        ans+=1
        h.append(ans)
    elif s[i]=="D":
        ans-=1
        h.append(ans)
print(max(h))


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  int a,b,c,k;
  int mt;
  vector<int> m;

  cin >> a >>b>>c>>k;

  int max3 = (a>b) ? max(a,c) : max(b,c);
  // for (auto l : m) {
  // }

  int x2 = max3 * (pow(2,k));

  cout<<x2+ a+b+c-max3<<endl;
  
  // int minn = *min_element(p.begin(), p.end());
  // cout << minn << endl;
}


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

using namespace std;

int main()
{
    int n,d,ara[25][25],cnt=0;

    cin>>n>>d;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>ara[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int sum=0;
            for(int k=0;k<d;k++){
                sum+=(abs(ara[i][k]-ara[j][k]))*(abs(ara[i][k]-ara[j][k]));

            }
            int ans = sqrt(sum);
            if(ans*ans==sum) cnt++;
        }

    }
    cout << cnt <<endl;

    return 0;
}


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

using namespace std;

int main()
{
   string str;
   int n;

   cin >> n;
   cin.ignore();

   for(int i = 0; i < n; ++i){

      getline( cin, str);

      while( string::npos != str.find( "Hoshino"))
      {
         int pnt = str.find( "Hoshino" );

         str.replace( pnt, 7, "Hoshina");
      }

      cout << str << endl;
   }
}

Measured memory_bytes: 1208
/*
  	丹阳市第三中学 蒋帅
*/

#include <bits/stdc++.h>
#define R(n) long long (n) = read()
#define w(n) write(n)
#define W(n) write(n), putchar('\n')
using namespace std;

inline long long read()
{
	int a = 0;
	char c = getchar();
	int	f = 1;
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) {a = a * 10 + c - '0'; c = getchar();}
	return a * f;
}

inline long long write(long long x)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}

int main()
{
	R(n);
	R(a);
	R(b);
	if (n > 1 && b >= a || n == 1 && a == b)
        cout << (n - 2) * (b - a) + 1 << endl;
	else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 256
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var h = int.Parse(line[2]);
        var m = int.Parse(line[3]);
        var ans = getAns(a, b, h, m);
        Console.WriteLine(ans);
    }
    static double getAns(int a, int b, int h, int m)
    {
        var aa = conv(getA(h, m));
        var ax = a * Cos(aa);
        var ay = a * Sin(aa);
        var bb = conv(getB(m));
        var bx = b * Cos(bb);
        var by = b * Sin(bb);
        var ans = Sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
        return ans;
    }
    static double getA(int h, int m) => 360d - 30d * h - m / 2d;
    static double getB(int m) => 360d - 6d * m;
    static double conv(double p) => PI * p / 180d;
}



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

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

    if (n == m)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N;
map<string, bool> mp;

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

    cin >> N;
    string bef;
    cin >> bef; mp[bef] = true;
    rep(i, N - 1) {
        string s;
        cin >> s;
        if(s[0] == bef[(int)bef.size() - 1] && !mp[s]) {
            bef = s;
            mp[s] = true;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const double inf = 1e9;
const int mod = 1e5;
const int MAX = 5005;

struct status {int y, x, len;};

int main() {
    int h, w, K; cin >> h >> w >> K;
    vector<string> field_s(h);
    rep(i,h) cin >> field_s[i];
    vvint field_ori(h,vint(w));
    rep(i,h)rep(j,w) field_ori[i][j] = field_s[i][j] - '0';
    // rep(a,h) {
    //     rep(b,w) cout << field[a][b] << " ";
    //     cout << endl;
    // }
    int ans = 0;
    rep(i,h)rep(j,w) {
        // if (i != 3 || j != 2) continue;
        int sum = 0;
        vvint field = field_ori;
        field[i][j] = 0;
        deque<int> q;
        rep(a,h) if (field[a][j] != 0) q.push_back(field[a][j]);
        while (q.size() < h) q.push_front(0);
        rep(a,h) {
            int x = q.front(); q.pop_front();
            field[a][j] = x;
        }
        // rep(a,h) {
        //     rep(b,w) cout << field[a][b] << " ";
        //     cout << endl;
        // }
        // cout << endl;
        int now = 0;
        while (true) {
            bool update = false;
            rep(k,h) {
                int index = 0;
                int ct = 1;
                rep(l,w) {
                    if (field[k][l] == field[k][l+1] && l != w-1) ct++;
                    else {
                        if (ct >= K) {
                            // cout << ct << index << endl;
                            if (field[k][index] != 0) update = true;
                            sum += field[k][index]*ct*pow(2,now);
                            for (int m = index; m < index+ct; m++) field[k][m] = 0;
                        }
                        index = l+1;
                        ct = 1;
                    }
                }
            }
            // rep(i,h) {
            //     rep(j,w) cout << field[i][j] << " ";
            //     cout << endl;
            // }
            // cout << endl;
            if (!update) {ans = max(ans,sum); break;}
            deque<int> q;
            rep(l,w) {
                rep(k,h) if (field[k][l] != 0) q.push_back(field[k][l]);
                while (q.size() < h) q.push_front(0);
                rep(k,h) {
                    int x = q.front(); q.pop_front();
                    field[k][l] = x;
                }
            }
            now++;
            // rep(i,h) {
            //     rep(j,w) cout << field[i][j] << " ";
            //     cout << endl;
            // }
            // cout << endl;
            // cout << sum << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
    int n; cin>>n;
    int a[3] ={};
    a[0] = (n % 10); n /= 10;// 1桁目を取り出す
    a[1] = (n % 10); n /= 10;// 2桁目を取り出す
    a[2] = (n % 10); n /= 10;// 3桁目を取り出す

    for(int i=0;i<3;i++){
        if(a[i]==1)
            a[i] = 9;
        else if(a[i]==9)
            a[i] = 1;
    }

    int ans = a[2]*100 + a[1]*10 + a[0];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
 
int main(){
    int n, x[100], y[100];
     
    scanf(" %d", &n);
    for(int i=0; i<n; ++i)
        scanf(" %d", &x[i]); 
    for(int i=0; i<n; ++i)
        scanf(" %d", &y[i]); 
         
    for(int p=1; p<=3; ++p){
        double d=0;
        for(int i=0; i<n; ++i)
            d += pow( fabs(x[i]-y[i]), p);
         
        printf("%lf\n", pow(d,1.0/p));
    }       
     
    double max=0;   
    for(int i=0; i<n; ++i)
        if(max < fabs(x[i]-y[i])) max = fabs(x[i]-y[i]);
     
    printf("%lf\n", max);   
     
    return 0;
}


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

int main(){
	int a,b,sum;
	char op;
	for( ; ; ){
	cin >> a >> op >> b;
	if(op=='+'){
		sum=a+b;
		cout << sum << endl;
	}else if(op=='-'){
		sum=a-b;
		cout << sum << endl;
	}else if(op=='*'){
		sum=a*b;
		cout << sum << endl;
	}else if(op=='/'){
		sum=a/b;
		cout << sum << endl;
	}else{
		break;
	}
	}
	return 0;
}



Measured memory_bytes: 3112
import sys
fin = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush


def initialize(adj, s):
    MAX_NUM = float('inf')
    parent = {s: None}
    d = {vertex: MAX_NUM for vertex in adj.keys()}
    d[s] = 0
    return d, parent


# Dijkstra can work using a minheap which does not have decrease_key.
# and also we do not have to implement Vertex class.
# Instead, we can use (distance, vertex).
# in this case, the time it takes is O(ElgE).
# E is at most O(V^2), thus O(ElgE) = O(ElgV).
def dijkstra_simple(adj, w, s):
    d, parent = initialize(adj, s)
    priority_queue = []
    heappush(priority_queue, (d[s], s))
    while priority_queue:
        distance, source = heappop(priority_queue) 
        for neighbor in adj[source]:
            new_distance = distance + w[(source, neighbor)]
            if new_distance < d[neighbor]:
                d[neighbor] = new_distance
                parent[neighbor] = source
                heappush(priority_queue, (new_distance, neighbor))
    return d


n, m, s, t = map(int, fin().split())
adj = defaultdict(list)
yen_weights = dict()
snuuk_weights = dict()
for _ in range(m):
    u, v, a, b = map(int, fin().split())
    for v1, v2 in [(u, v), (v, u)]:
        adj[v1].append(v2)
        yen_weights[(v1, v2)] = a
        snuuk_weights[(v1, v2)] = b

d_yen = dijkstra_simple(adj, yen_weights, s)
d_snuuk = dijkstra_simple(adj, snuuk_weights, t)
min_cost = float('inf')
min_cost_after_each_year_reversed = []
for vertex in range(n, 0, -1):
    min_cost = min(min_cost, d_yen[vertex] + d_snuuk[vertex])
    min_cost_after_each_year_reversed.append(min_cost)

initial_money = 10**15
for cost in reversed(min_cost_after_each_year_reversed):
    print(initial_money - cost)



Measured memory_bytes: 121236
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
    fastio;
    int t;
    cin >> t;
    int ca=0,ct=0,cw=0,cr=0;
    while(t--){
        string s;
        cin >> s;
        if(s=="AC"){ca++;}
        else if(s=="TLE"){ct++;}
        else if(s=="WA"){cw++;}
        else if(s=="RE"){cr++;}
    }
    cout << "AC x " <<ca<<"\n";
    cout << "WA x " <<cw<<"\n";
    cout << "TLE x " <<ct<<"\n";
    cout << "RE x " <<cr<<"\n";
    return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j,n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
	return 0;
}


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

main() {
    string S; cin >> S;
    map<char,int>m;
    m[S[0]]++;m[S[1]]++;m[S[2]]++;
    if(m['a']==1&&m['b']==1&&m['c']==1)
    cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori


def main():
    kazu = [0]
    for i in range(1, 14):
        kazu.append(26 ** i + kazu[i - 1])
    #    print(kazu)
    n = int(input())

    def hante(a):
        b = 0
        for i in range(len(kazu)):
            if a <= kazu[i]:
                b = i
                break
        return b

    keta = hante(n)
    ans = []
    i = keta - 1
    n -= kazu[keta - 1]+1
    ans.append(n%26)
    n//=26
    while i > 0:
        temp = n % 26
        ans.append(temp)
        n//=26

        i -= 1
    ko = list("abcdefghijklmnopqrstuvwxyz")
    ans2 = []
    for i in ans:
        ans2.append(ko[i])
    ans2.reverse()
    print("".join(ans2))


if __name__ == "__main__":

    main()

Measured memory_bytes: 72772
// A - Shrinking
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

lli x;
bool cmp(lli a, lli b)
{
  return abs(a - x) < abs(b - x);
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, h, n, w, ans = INF, count = 0, tmp = 0;
  string s, t;
  vector<pair<char, vlli>> pr;
  cin >> t;
  lli len = t.size();
  set<char> g;
  rep(i, 0, len)
  {
    g.insert(t[i]);
  }
  if (g.size() <= 1)
  {
    std::cout << 0 << endl;
    return 0;
  }

  for (auto c = 'a'; c <= 'z'; c++)
  {
    rep(i, 0, len)
    {
      rep(j, 0, len)
      {
        if (i != j && t[j] != c)
        {
          count++;
        }
        else
        {
          count = 0;
        }
        tmp = max(tmp, count);
        // std::cout << "tmp: " << tmp << endl;
      }
      count = 0;
    }
    ans = min(ans, tmp);
    tmp = 0;
  }
  std::cout << ans << endl;
}

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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

    int n;
    cin>>n;

    vector<int> A(n+4,0), cost(n+4,0);

    for(int i=1;i<=n;++i)   cin>>A[i];

    cost[0] = 1200000000;
    cost[1] = 0;
    cost[2] = abs(A[2]-A[1]);

    for(int i=2;i<=n;++i){
        cost[i] = min(cost[i-2] + abs(A[i] - A[i-2]), cost[i-1] + abs(A[i] - A[i-1]));
    }

    cout<<cost[n]<<"\n";

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[1001],t[1001];
	int a,b,i,j,cnt=0,max=0;
	scanf("%s %s",s,t);
	a=strlen(s);
	b=strlen(t);
	for(i=0;i<=a-b;i++){
		for(j=0;j<b;j++){
			if(s[i+j]==t[j]){
				cnt++;
			}
		}
		// printf("cnt=%d\n",cnt);
		if(max<=cnt){
			max=cnt;
			// printf("max=%d\n",max);
		}
		cnt=0;
	}
	printf("%d\n",b-max);
	return 0;
}

Measured memory_bytes: 1736
//   PIGMEISTER™   //

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

#define ll long long
#define ld long double
#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 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 PI (ld)3.141592653589793238
#define MAX 100005

int main()
{
    jaldi;
    
    ll h, w, k;
    cin >> h >> w >> k;
    string mat[h];
    sidha (i, 0, h) cin >> mat[i];
    
    ll ans = 0;
    sidha (i, 0, (1ll<<(h+w))) {
        ll count = 0;
        sidha (j, 0, h) {
            if (i&(1ll<<j)) continue;
            sidha (l, 0, w) {
                if (i&(1ll<<(h+l))) continue;
                if (mat[j][l] == '#') count++;
            }
        }
        if (count == k) ans++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  int m,d,i,j;
  scanf("%d%d",&m,&d);
  int count=0;
  for(i=1;i<=m;++i){//months
    for(j=1;j<=d;++j){//day
      int i10,i1;
      i10=j/10;
      i1=j%10;
      if(i10 >= 2 && i1 >= 2 && i10 * i1 == i){
        count++;
      }
    }
  }
  printf("%d",count);
  return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	int n = N/2*2;

	vector<Pi> dats;
	for (int i = 1; i <= n; i++) {
		for (int j = i+1; j <= N; j++) {
			if (j != n-i+1) dats.emplace_back(i, j);
		}
	}
	cout << dats.size() << endl;
	for (auto &dat : dats) {
		cout << dat.first << " " << dat.second << endl;
	}
}

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


Measured memory_bytes: 3772
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect

class Solver():

    R = 'R'
    G = 'G'
    B = 'B'

    def __init__(self, n, s):
        self.n = n
        self.s = s
        self.rgb = self.make_rgb()
        self.large = self.calc_large()
        #print('self.large') # debug
        #print(self.large) # debug
        self.trident = 0

    def make_rgb(self):
        rgb = {
                self.R: [],
                self.G: [],
                self.B: [],
                }
        for i, c in enumerate(self.s):
            rgb[c].append(i)
        return rgb

    def calc_large(self):
        r = self.rgb[self.R]
        g = self.rgb[self.G]
        b = self.rgb[self.B]
        l = [
                (self.R, len(r)),
                (self.G, len(g)),
                (self.B, len(b)),
                ]
        l = sorted(l, key=lambda tpl: tpl[1])
        #print('l') # debug
        #print(l) # debug
        return l[-1][0]

    def get_smalls(self):
        if self.large == self.R:
            return self.rgb[self.G], self.rgb[self.B]
        if self.large == self.G:
            return self.rgb[self.R], self.rgb[self.B]
        if self.large == self.B:
            return self.rgb[self.G], self.rgb[self.R]

    def run(self):
        s1, s2 = self.get_smalls()
        for i1 in s1:
            for i2 in s2:
                self.check_3way(i1, i2)
        return self.calc_ans()

    def check_3way(self, i1, i2):
        if not i1 < i2:
            i1, i2 = i2, i1
        d = i2 - i1
        self.hit_then_count(i1 - d)
        self.hit_then_count(i1 + d / 2)
        self.hit_then_count(i2 + d)

    def hit_then_count(self, key):
        if int(key) != key:
            return
        if not (0 <= key < len(self.s)):
            return
        key = int(key)
        if self.s[key] == self.large:
            self.trident += 1

    def calc_ans(self):
        r = len(self.rgb[self.R])
        g = len(self.rgb[self.G])
        b = len(self.rgb[self.B])
        return r * g * b - self.trident




if __name__ == '__main__':
    n = int(input())
    s = input()
    ans = Solver(n, s).run()
    #print('ans') # debug
    print(ans)

    #print('\33[32m' + 'end' + '\033[0m') # debug


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

int s[1000], d[1000], y[1000], a, b, n, m, h, k;
pair<int, int>p[100000];
int main() {
	while (scanf("%d%d%d%d", &n, &m, &h, &k), n) {
		rep(i, n)scanf("%d", &s[i]);
		rep(i, m)scanf("%d%d", &a, &b), p[i] = { b,a };
		sort(p, p + m); iota(d, d + n, 0);
		rep(i, m) {
			swap(d[p[i].t - 1], d[p[i].t]);
			p[i] = { d[p[i].t - 1],d[p[i].t] };
			if (p[i].f > p[i].t)swap(p[i].f, p[i].t);
		}
		rep(i, n)y[d[i]] = s[i];
		int M = accumulate(y, y + k, 0); int S = M;
		rep(i, m)if (p[i].f < k&&p[i].t >= k)M = min(M, S + y[p[i].t] - y[p[i].f]);
		printf("%d\n", M);
	}
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    vi A(n), B(n);
    rep(i, n) cin >> A[i] >> B[i];

    vi C(m), D(m);
    rep(i, m){
        cin >> C[i] >> D[i];
    }

    rep(i, n){
        int a = A[i], b = B[i];

        int res = -1;
        int mindist = inf;
        rep(j, m){
            int c = C[j], d = D[j];
            int dist = abs(c - a) + abs(d - b);
            if(chmin(mindist, dist)){
                res = j + 1;
            }
        }
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 256
program round_one

 implicit none
 integer :: a,b,ans
 
 read*,a,b

 if((a==1 .and. b==2) .or. (a==2 .and. b==1)) ans=3
 if((a==2 .and. b==3) .or. (a==3 .and. b==2)) ans=1
 if((a==1 .and. b==3) .or. (a==3 .and. b==1)) ans=2

 print*,ans

end program round_one

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    int count = 0;
    for(int i = A; i <= B; i++){
        int work = i;
        int k[10];
        int j = 0;
        while(work != 0){
            k[j] = work % 10;
            work /= 10;
            j++;
        }
        if(k[0] == k[4] && k[1] == k[3]) count++;

    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define go(i, a, n) for (ll i = a; i < (ll)n; i++)
#define gor(i, a, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define gos(i, a, n, step) for (ll i = a; i < (ll)n; i += step)
#define show(a) cout << a << '\n'
#define show2(a, b) cout << a << " " << b << '\n'
#define show3(a, b, c) cout << a << " " << b << " " << c << '\n'
#define show4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << '\n'
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define mem(a, k) memset(a, k, sizeof(a))
#define answer(z, k) cout << "Case #" << z << ": " << k << endl;
#define ans(z) cout << "Case #" << z << ": "
auto t1 = chrono::high_resolution_clock::now();

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // ll t;
    // cin >> t;
    // while (t--)
    // {
    // }
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    show(max({a * c, a * d, b * c, b * d}));
    auto t2 = chrono::high_resolution_clock::now();
    auto duration = chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();
    clog << "Time taken = " << duration * 1.0 / 1000 << " seconds" << endl;
    return 0;
}


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

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

int MOD = 1e9 + 7;
int INF = 1e9;
// ll INF = 1e18;

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n, m, h, w, a[505][505];

int solve(){
	cin >> n >> m >> h >> w;
	ll sum = 0;
	int k = 1000000000 / (h * w);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++){
		if(i % h == h-1 && j % w == w-1)
			a[i][j] = -k * (h * w - 1) - 1;
		else
			a[i][j] = k;
		sum += a[i][j];
	}
	if(sum <= 0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
		for(int i=0;i<n;i++) for(int j=0;j<m;j++) cout << a[i][j] << " \n"[j==m-1];
	}

	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	// int t; cin >> t; while(t--)
	solve();
	// cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}


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

public class Yado
{
    public int d { get; set; }
    public int p { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var wk = new List<Yado>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            for (int i = 0; i < n; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                var d = int.Parse(line2[0]);
                var p = int.Parse(line2[1]);
                wk.Add(new Yado { d = d, p = p });
            }
            var yados = wk.OrderByDescending(x => x.p).ToList();
            var nexti = -1;
            for (int i = 0; i < n; i++)
                if (m - yados[i].d > 0) m -= yados[i].d;
                else { nexti = i + 1; break; }
            var ret = 0;
            if (nexti != -1)
            {
                for (int i = nexti; i < n; i++)
                    ret += yados[i].d * yados[i].p;
                ret += (yados[nexti - 1].d - m) * yados[nexti - 1].p;
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 11132
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

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

    vector<int>a(n, 0);
    vector<int>ct(8, 0);
    REP(i, n) cin >> a[i];

    int redct = 0;
    REP(i, n){
        if (a[i] >= 3200){
            redct++;
            continue;
        }
        ct[a[i] / 400]++;
    }

    int minct = 0;

    REP(i, 8){
        if (ct[i] > 0) minct++;
    }
    cout << max(minct, 1) << " " << min(minct + redct, n) << endl;
}

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;

int main() {
  int n; cin>>n;
  vector<int> a(n),b(n);
  rep(i, n) cin>>a[i];
  rep(i, n) cin>>b[i];

  vector<int> x(n);
  rep(i, n) x[i]=i+1;

  int anum,bnum,k=1;
  rep(i, n) k*=(i+1);
  rep(i, k) {
    bool afrag=true;
    bool bfrag=true;
    for (auto p : x) {
      if (x!=a) afrag=false;
      if (x!=b) bfrag=false;
    }
    next_permutation(x.begin(), x.end());
    if (afrag) anum=i;
    if (bfrag) bnum=i;
  }
  cout<<abs(anum-bnum)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, c, n;
    int ans = 0;
    cin >> a >> b;
    if(a < 10 && b < 10)cout << a*b << endl;
    else cout << -1 << endl; 
    return 0;
}

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

int main()
{
    int A, B, max;
    cin >> A >> B;
    max = A + B;
    if (A - B > max)
    {
        max = A - B;
    }
    if (A * B > max)
    {
        max = A * B;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
// Problem : D - Line++
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e9 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n, x, y;
vi graph[maxN];
int ans[maxN], dist[maxN];

void BFS(int start) {
	queue<int> Q;
	RI(i, n) {
		dist[i] = inf;
	}
	dist[start] = 0;
	Q.push(start);
	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		if (u > start)
			ans[dist[u]]++;
		for (auto v: graph[u]) {
			if (dist[v] == inf) {
				dist[v] = dist[u] + 1;
				//ans[dist[u]]
				Q.push(v);
			}
		}
	}
	// cout << start << "\n";
	// RI(i, n) cout << dist[i] << " ";
	// cout << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> x >> y;
	graph[x].pb(y);
	graph[x].pb(y);
	RI(i, n - 1) {
		graph[i].pb(i + 1);
		graph[i + 1].pb(i);
	}
	RI(i, n) {
		BFS(i);
	}
	RI(i, n - 1) {
		cout << ans[i] << endl;
	}
	return 0;
}
 


Measured memory_bytes: 27520
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();
        int h = sc.nextInt();
        int m = sc.nextInt();

        double kakudo = Math.toRadians(Math.abs((h * 30 + m * 0.5) - (m * 6)));
        double ans = Math.sqrt(Math.pow(a,2) + Math.pow(b,2) - 2 * a * b * Math.cos(kakudo));

        System.out.println(ans);
    }
}


Measured memory_bytes: 36112