akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fs = new FastScanner();
        int a = fs.nextInt();
        int b = fs.nextInt();
        int h = fs.nextInt();
        int m = fs.nextInt();
        double digh = 30*(h%12);

        digh += 0.5*m;
        double digm =6*m;
        double diff = digm-digh;
        System.out.println(Math.sqrt(a*a+b*b-2*a*b*Math.cos(diff*Math.PI/180)));

    }
    static class FastScanner{
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte(){
            if(ptr < buflen){
                return true;
            }else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen <= 0){
                    return false;
                }
            }
            return true;
        }

        private int readByte(){
            if(hasNextByte())return buffer[ptr++];
            else return -1;
        }

        private boolean isPrintableChar(int c){
            return 33<=c && c<=126;
        }

        public boolean hasNext(){
            while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
            return hasNextByte();
        }

        public String next(){
            if(!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)){
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong(){
            if(!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if(b == '-'){
                minus = true;
                b = readByte();
            }
            if(b < '0' || '9' < b){
                throw new NumberFormatException();
            }
            while(true){
                if('0' <= b && b<='9'){
                    n*=10;
                    n+=b-'0';
                }else if(b==-1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt(){
            long nl = nextLong();
            if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
            return (int)nl;
        }
        public double nextDouble(){return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 33236
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    n %= 1000;
    if(n == 0)cout << 0 << endl;
    else cout << 1000 - n << endl;
    
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);

        int n;
        cin >> n;
        int ans=0;
        int x=n/500;
        ans+=(1000*x);
        n=n-(500*x);
        int y=n/5;
        ans+=(5*y);
        cout << ans << '\n';

}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    string S;
    cin >> S;

    ll N = S.length();
    vector<ll> digit(N);
    vector<ll> dp1(N,INF);
    vector<ll> dp2(N,INF);

    REP(i,N){
        digit[i] = S[i] - 48;
        // cout << digit[i] << endl;
    }
    if(digit[0] <= 5){
        dp1[0] = digit[0];
    }
    else{
        dp1[0] = 11 - digit[0];
    }
    if(digit[0] <= 4){
        dp2[0] = digit[0] + 1;
    }
    else{
        dp2[0] = 10 - digit[0];
    }
    
    for(ll i=1; i<N; i++){
        dp1[i] = min(dp1[i-1]+digit[i], dp2[i-1] + 10 - digit[i]);
        dp2[i] = min(dp1[i-1]+digit[i]+1, dp2[i-1] + 9 - digit[i]);
    }
    cout << dp1[N-1] << endl;    
    return 0;
}

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

using namespace std;

struct Line{int h,p,q;};
int n,m,a;
vector<Line> V;

void solve(){

  for(int i = 0; i < V.size(); i++)
    for(int j = i+1; j < V.size(); j++)
      if(V[i].h < V[j].h) swap(V[i],V[j]);


  int pos = a;
  for(int i = 0; i < V.size(); i++){
    if(V[i].p == pos) pos = V[i].q;
    else if(V[i].q == pos) pos = V[i].p;
  }
  cout << pos << endl;
}
void init(){
  V.clear();
}

int main(){

  while(cin >> n >> m >> a && n+m+a){
    init();

    for(int i = 0; i < m; i++){
      Line l;
      cin >> l.h >> l.p >> l.q;
      V.push_back(l);
    }

    solve();
  }
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e6+10;
const int mod=1e9+7;
const int maxm=1e3+10;
using namespace std;
struct wzy
{
    int day,money;
}p[maxn];
bool cmp(wzy u,wzy v)
{
    return u.day<v.day;
}
int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>p[i].day>>p[i].money;
    sort(p,p+n,cmp); //tian:xiao->da
    
    priority_queue<int>que;
    int ans=0;
    int pos=0;
    for(int i=1;i<=m;i++)
    {
    	
        while(p[pos].day<=i&&pos<n)
        {
        	 que.push(p[pos++].money);
		}
           
        if(!que.empty())
            ans+=que.top(),que.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
// 287644PV
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(6)<<(x)
const long long mod = 1000000007;

void addSelf(long long&x, long long y)
{
    x+= y;
    if(x >= mod)
        x-=mod;
}
void subSelf(long long&x, long long y)
{
    x -= y;
    if(x < 0)
        x += mod;
}

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

long long power(long long base, long long expo)
{
    long long sol = 1;
    for (long long i = 0; i <expo ; ++i) {
        sol *= base;
    }
    return sol;
}

bool compare1(pair<long long,long long> i,pair<long long,long long> j) // 1 < i < n
{
    return i.second < j.second;
}

bool compare2(pair<long long,long long> i, pair<long long,long long> j) //n > n-i > 1
{
    return i.first > j.first;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> in(n);
    long long ssum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> in[i];
        ssum += in[i];
    }
    vector<long long> sol(n);
    sol[0] = ssum;
    for (int j = 1; j < n; j+=2) {
        sol[0] -= 2*in[j];
    }

    for (int i = 1; i < n; ++i) {
        sol[i] = 2*in[i-1] -sol[i-1];
    }

    for(int x: sol)
        cout << x << " ";


return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        if(x+r <= w && 0 <= x-r && y +r <= h && 0 <= y-r ){
            System.out.print("Yes");
        }else {
            System.out.print("No");
        }
        System.out.println();
    }
}


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

using namespace std;

typedef unsigned long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

string s;
ll l,r;

int z[430252*2];
void zalgo(string s){
  REP(i,s.size())z[i] = 0;
  // z algorithm
  // http://snuke.hatenablog.com/entry/2014/12/03/214243
  z[0] = s.size();
  {
    int i=1,j=0;
    while(i<s.size()){
      while(i+j<s.size() && s[j]==s[i+j]){
        j++;
      }
      z[i]=j;
      if(j==0){
        i++;
        continue;
      }
      int k=1;
      while(i+k<s.size() && k+z[k]<j){
        z[i+k] = z[k];
        k++;
      }
      i+=k;
      j-=k;
    }
  }
}

ll fibmemo[1252];
ll fib(int x){
  if(x==0)return 0;
  if(x==1)return 1;
  if(fibmemo[x]>0)return fibmemo[x];
  return fibmemo[x] = fib(x-1)+fib(x-2);
}

ll cnt[26];
ll ans[26];

void calc(string &X, string &Y, ll end){
  ll x = X.size();
  ll y = Y.size();
  if(end <= x+y){
    // greedy
    REP(i,end){
      if(i<x)cnt[X[i]-'a']++;
      else cnt[Y[i-x]-'a']++;
    }
    return;
  }
  ll xcnt = 1; int xi=1;
  ll ycnt = 0; int yi=0;
  while(x*xcnt <= end && y*ycnt <= end && x*xcnt+y*ycnt > 0 && x*xcnt+y*ycnt <= end){
    xcnt = fib(++xi);
    ycnt = fib(++yi);
  }
  xcnt = fib(--xi);
  ycnt = fib(--yi);
  REP(i,x)cnt[X[i]-'a']+=xcnt;
  REP(i,y)cnt[Y[i]-'a']+=ycnt;
  ll len = x*xcnt+y*ycnt;
  if(len==end)return;
  calc(X,Y,end-len);
}

string f(string s){
  zalgo(s);
  int n = s.size();
  int k = 0;
  REP(i,(n-1)/2){
    if(z[n-1-i]>=i+1)k=i+1;
  }
  string t = s.substr(0,n-k);
  return t+t;
}

int main(){
  cin>>s;
  int n = s.size();
  cin>>l>>r;
  s = f(s);
  int x1 = s.size();
  // first step
  s = f(s);
  int x2 = s.size();
  // second
  string t = f(s);
  int x3 = t.size();

  // if(x3-x2 == x2-x1){
  //   int width = x3-x2;
  //   {
  //     ll x = r;
  //     ll tms = x/width;
  //     ll y = x-tms*width;
  //     REP(i,width)ans[s[i]-'a'] += tms;
  //     REP(i,y)ans[s[i]-'a']++;
  //   }
  //   {
  //     ll x = l-1;
  //     ll tms = x/width;
  //     ll y = x-tms*width;
  //     REP(i,width)ans[s[i]-'a'] -= tms;
  //     REP(i,y)ans[s[i]-'a']--;
  //   }
  //   REP(i,26)printf("%llu%c",ans[i],i==25?'\n':' ');
  //   return 0;
  // }

  string X = s.substr(0,s.size()/2);
  string Y = t.substr(X.size(),t.size()/2-X.size());
  calc(X,Y,r);
  REP(i,26)ans[i]=cnt[i];
  REP(i,26)cnt[i]=0;
  calc(X,Y,l-1);
  REP(i,26)ans[i]-=cnt[i];
  REP(i,26)printf("%llu%c",ans[i],i==25?'\n':' ');
  return 0;
}


Measured memory_bytes: 4640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,W;
    cin>>n>>W;
    int w[n],v[n];
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
        sum=sum+v[i];
    }
    ll dp[n+1][sum+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=sum;j++)
        {
            if(j==0)
            {
                dp[i][j]=0;
            }
            if(i==0 && j!=0)
            {
                dp[i][j]=INT_MAX;
            }

        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=sum;j++)
        {
            if(v[i-1]<=j)
            {
                dp[i][j]=min(w[i-1]+dp[i-1][j-v[i-1]] , dp[i-1][j]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }

        }
    }
    ll ans=0;
    for(int i=0;i<=sum;i++)
    {
        if(dp[n][i]<=W)
        {
            ans=i;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 79104
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	VI v(n), c(n);
	rep(i, n)cin >> v[i];
	rep(i, n)cin >> c[i];
	int ans = 0;
	rep(i, n)ans += max(0, v[i] - c[i]);
	Cout(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n;cin >> n;
	int ans = 0;
	if(n < 10){
		ans += n;
		goto out;
	}
	ans += 9;
	if(n < 1000){
		ans += max(0,n-99);
		goto out;
	}
	ans += 900;
	ans += max(0,n-9999);
	if(n == 100000) ans--;

	out:
		cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main ()
{
	int c,x[6],sum;
	for(c=0; c<6; c++){
		scanf("%d",&x[c]);
	}
	
	if(x[0] <= x[1]){
		
		if(x[0] <= x[2]){
			if(x[0] <= x[3]){
				sum = x[1] + x[2] + x[3];
			}
			else{
				sum = x[0] + x[1] + x[2];
			}
		}
		
		else{
			if(x[2] <= x[3]){
				sum = x[0] + x[1] + x[3];
			}
			else{
				sum = x[0] + x[1] + x[2];
			}
		}
	}
	
	
	else{
		if(x[1] <= x[2]){
			
			if(x[1] <= x[3]){
				sum = x[0] + x[2] + x[3];
			}
			else{
				sum = x[0] + x[1] + x[2];
			}
		}
		
		else{
			if(x[2] <= x[3]){
				sum = x[0] + x[1] + x[3];
			}
			else{
				sum = x[0] + x[1] + x[2];
			}
		}
	}
	
	if(x[4] <= x[5]){
		sum = sum + x[5];
	}
	else{
		sum = sum + x[4];
	}
	
	printf("%d\n",sum);
	
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef vector <int> VI;
typedef map <int, VI> MIVI;

MIVI G;
const int gsize = 13;
const int size = 2010;
int T[gsize][size];
int TC[gsize];
int D[gsize][size];
int dp[size];

void init_table() {
    for ( int i = 0; i < gsize; ++ i ) TC[i] = 0;
    for ( int i = 0; i < size; ++ i ) {
        dp[i] = 0;
    }
}

int main() {
    int n, k;
    while ( cin >> n >> k ) {
        // input
        for ( int i = 0; i < gsize; ++ i ) {
            G[i].clear();
        }
        for ( int i = 0; i < n; ++ i ) {
            int c, g;
            cin >> c >> g;
            G[g].push_back( c );
        }
        for ( int i = 0; i < gsize; ++ i ) {
            sort( G[i].rbegin(), G[i].rend() );
        }
        // init
        init_table();
        for ( int i = 0; i < gsize; ++ i ) {
            for ( VI::iterator it_i = G[i].begin(); it_i != G[i].end(); ++ it_i ) {
                T[i][TC[i]++] = *it_i;
            }
        }
        // calc
        for ( int i = 0; i < gsize; ++ i ) {
            D[i][0] = 0;
            for ( int j = 1; j <= TC[i]; ++ j ) {
                D[i][j] = D[i][j-1] + T[i][j-1] + ( j - 1 ) * 2;
            }
        }
        for ( int i = 0; i < gsize; ++ i ) {
            for ( int j = k; j >= 0; -- j ) {
                // cout << i << ": " << j - TC[i] + 1 << ", " << j << endl;
                for ( int l = max( 0, j - TC[i] ); l < j; ++ l ) {
                    dp[j] = max( dp[j], dp[l] + D[i][j-l] );
                }
            }
        }
        // output
        cout << dp[k] << endl;
    }
    return 0;
}

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

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

    int n;
    cin >> n;
    
    long long cost = 0;
    REP(i, n){
        int a;
        cin >> a;
        cost += a - 1;
    }
    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 256
s=input()
a=int(s[:2])
b=int(s[2:])

if 1<= a <=12 and 1<= b <= 12:
    print("AMBIGUOUS")

elif 1<= b <= 12:
    print("YYMM")

elif 1 <= a <= 12:
    print("MMYY")

else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

const int MX = 2019;

int main()
{
    int l, r;
    cin >> l >> r;
    if (r - l >= MX-1) {
        cout << 0 << "\n";
        return 0;
    }
    l = l % 2019;
    r = r % 2019;
    if (r <= l) r += 2019;
    int ans = MX;
    repSE(i,l,r) repSE(j,i+1,r+1) {
        int tmp = (i*j)%2019;
        chmin(ans, tmp);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3608
using System;

public class SmallLargeEqual {
  static int Main(string[] args)
  {
    string inputData = Console.ReadLine();
    string[] dataArray = inputData.Split();
    int a = int.Parse(dataArray[0]);
    int b = int.Parse(dataArray[1]);

    if(a < b) {
      Console.WriteLine("a < b");
    } else if(a > b) {
      Console.WriteLine("a > b");
    } else {
      Console.WriteLine("a == b");
    }

    return 0;
  }
}


Measured memory_bytes: 8880
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC109 {
	class ABC109_A {
		static void Main(string[] args) {
			var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var A = input[0];
			var B = input[1];
			Console.WriteLine((0x01 & A & B) > 0 ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int n,m;
    cin>>n>>m;
    int a[20];
    memset(a,0,sizeof(a));
    int s,x;
    int j=m;
    while(m--)
    {
      cin>>s>>x;
      if((a[s]!=0 && a[s]!=x) || (n>=2 && s==1 && x==0))
      return cout<<-1<<"\n",0;
      else a[s]=x;  
    }
    if(n==1)return cout<<a[1],0;
    if(a[1]==0)a[1]=1;
    FOR(i,1,n)cout<<a[i];
  }
  return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

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

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = (int)1e9 + 7;

int add(int a, int b)
{
	return (a%N + b%N)%N;
}

long long ipow(long long base, int exp)
{
	if(exp == 0) return 1;
	long long ret = ipow(base, exp/2);
	ret = (ret * ret)%N;
	if(exp%2) return (ret * base)%N;
	else return ret;
}

int main()
{
	int h, w, k;
	cin >> h >> w >> k;
	int dp[h+1][w];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			for(int z = 0; z < (1 << (w-1)); z++)
			{
				bool check = true;
				for(int y=0;y<w-2;y++)
				{
					if(((z >> y) & 1) && ((z >> (y+1)) & 1))
					{
						check = false;
						break;
					}
				}
				if(check)
				{
					if(j > 0 && ((z >> (j-1)) & 1))
					{
						dp[i+1][j-1] = add(dp[i+1][j-1], dp[i][j]);
					}
					else if(j < w-1 && ((z >> j) & 1))
					{
						dp[i+1][j+1] = add(dp[i+1][j+1], dp[i][j]);
					}
					else
						dp[i+1][j] = add(dp[i+1][j], dp[i][j]);
				}
			}
		}
	}
	cout << dp[h][k-1] << "\n";
	return 0;
}

Measured memory_bytes: 256
def m():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    B = [a[i-1]-i for i in range(1, n+1)]
    B.sort()
    b = B[n//2]
    for i in range(n):
        ans += abs(B[i]-b)
    return ans

print(m())

Measured memory_bytes: 26832
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_A
# やるだけ
# 有向成分を読み込むたびにノード番号に対応する表に書き込んでいけばよい

N = int(input())
for _ in range(N):
    out_ls = [0]*N
    tmp = list(map(int, input().split()))
    # id = tmp[0]-1 #idは順番通り与えられるので実はこれもいらない
    if tmp[1] != 0:
        for adj in tmp[2:]:
            out_ls[adj-1] = 1

    print(*out_ls)



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, m;
pair<int,int> a[maxn]; //(days after, reward)


map<int,vector<int>> mp;

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

  int tot = 0;
  cin>>n>>m;
  for (int i=0; i<n; i++) {
    cin>>a[i].first>>a[i].second;
    mp[a[i].first].push_back(a[i].second);
  }
  priority_queue<int> pq;
  for (int i=1; i<=m; i++) {
    for (auto x: mp[i]) {
      pq.push(x);
    }
    if (!pq.empty()) {
      tot += pq.top(); pq.pop();
    }
  }

  cout<<tot<<endl;

  return 0;
}


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

int main(){
  int A, B, C, K;
  int num = 0;
  cin >> A >> B >> C >> K;
  
  while (B <= A){
    B *= 2;
    num++;
  }
  
  while (C <= B){
    C *= 2;
    num++;
  }
  
  if (num <= K){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };
 
 
int main() {
	string s;
	cin >> s;
	int x, y;
	cin >> x >> y;
	vector<int>X;
	vector<int>Y;
 
 
 
 
	bool fl = 0;
	int temp = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'T') {
			if (!fl) {
				X.push_back(temp);
			}
			else {
				Y.push_back(temp);
			}
			temp = 0;
			if (fl)fl = 0;
			else fl = 1;
		}else if(i == s.size()-1){
			temp++;
			if (!fl) {
				X.push_back(temp);
			}
			else {
				Y.push_back(temp);
			}
		}else {
			temp++;
		}
	}
 
 
	if (X.size() > 0 && Y.size() > 0) {
 
		vector< vector<int> >x_ok(X.size(), vector<int>(16200, 0));
		x_ok[0][8100 + X[0]]++;
 
		rep(i, 1, X.size()) {
			rep(j, 0, 16200) {
				if (x_ok[i - 1][j] > 0) {
					x_ok[i][j + X[i]]++;
					x_ok[i][j - X[i]]++;
				}
			}
		}
 
 
 
 
		vector< vector<int> >y_ok(Y.size(), vector<int>(16200, 0));
		y_ok[0][8100 + Y[0]]++;
		y_ok[0][8100 - Y[0]]++;
 
		rep(i, 1, Y.size()) {
			rep(j, 0, 16200) {
				if (y_ok[i - 1][j] > 0) {
					y_ok[i][j + Y[i]]++;
					y_ok[i][j - Y[i]]++;
				}
			}
		}
 
		if (x_ok[X.size() - 1][x + 8100] > 0 && y_ok[Y.size() - 1][y + 8100] > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else if (X.size() == 0 && Y.size() != 0) {
		if (x == 0 && (y == Y[0] || y == -Y[0])) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else if (X.size() != 0 && Y.size() == 0) {
		if (y == 0 && (x == X[0])) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (x == 0 && y == 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
 
 
	return 0;
}

Measured memory_bytes: 502784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const int MOD = 1000000007;
        private static List<long> ps = null;
        static void Solve()
        {
            string n = Console.ReadLine();
            int ans = 0;
            for(int i=0;i<n.Length;++i)
            {
                if(n[i] == '2')
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }


        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

const int MAX_N = 2e5;
const int MAX_P = 10000;

int N;
int P;
string S;
int u;
int s;
int num[MAX_P];
long long cnt;

int ksm(int p,long long y)
{
	long long x = 10LL;
	long long rt = 1LL;
	while ( y )
	{
		if ( y & 1 )
			rt = rt * x % p;
		x = x * x % p;
		y >>= 1;
	}
	return (int)rt;
}

int main()
{
	scanf("%d%d",&N,&P);
	cin >> S;
	if ( P == 2 || P == 5 )
	{
		for ( int i = N-1 ; i >= 0 ; i-- )
			if ( ( S[i] - 0x30 ) % P == 0 )
				cnt += (long long)(i+1);
	}
	else
	{
		num[0] = 1;
		long long ten = 1;
		for ( int i = N-1 ; i >= 0 ; i-- )
		{
			u = ( S[i] - 0x30 ) * (int)ten % P;
			s = ( s + u ) % P;
			cnt += (long long)num[s];
			num[s]++;
			ten *= 10LL;
			ten %= (long long)P;
		}
	}
	printf("%lld",cnt);
	printf("\n");
	return 0;
}

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

int main() {
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	ll dp[n+1];
	dp[0]=0,dp[1]=0,dp[2]=abs(a[1]-a[0]);
	for(ll i=3;i<=n;i++)
	{
	    ll min1 = 1e9;
	    for(ll j=i-1,cnt=0;j>=1;j--,cnt++)
	    {
	        if(cnt==k)
	            break;
	       min1=min(dp[j]+abs(a[i-1]-a[j-1]) , min1);
	    }
	    dp[i]=min1;
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll n;
  cin >> n;
  ll i,j,ans,ans1,ans2;
  for(i=1;i<=3500;i++){
    for(j=1;j<=3500;j++){
      if((4*i*j-n*j-n*i)<=0){
        continue;
      }
      if((n*i*j)%(4*i*j-n*j-n*i)==0){
        ans=(n*i*j)/(4*i*j-n*j-n*i);
        ans1=i,ans2=j;
        break;
      }
    }
  }
  printf("%lld %lld %lld\n",ans1,ans2,ans);
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  ll f = 0;
  ll t = 0;
  rep (i,n) {
    ll q;
    cin >> q;
    if (q%4 == 0) ++f;
    if (q%4 == 2) ++t;
  }
  n -= f*2;
  if (t == 0) --n;
  n -= t;
  if (n <= 0) cout << "Yes\n";
  else cout << "No\n";

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

using WG = map<int,map<int,double>>; // weighted graph
// verified with https://beta.atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_d
const double inf=1e20;
void dijkstra(int s, WG& g, vector<double>& dist) {
  vector<bool> visited(dist.size());
  fill(dist.begin(),dist.end(),inf);
  using P = pair<double,int>;
  priority_queue<P,vector<P>, greater<P>> pq;
  dist[s]=0;
  //visited[s]=true;
  pq.push(make_pair(0.0,s));
  while(!pq.empty()) {
    int v;
    double d;
    tie(d,v)=pq.top();
    pq.pop();
    if(visited[v]) continue;
    visited[v]=true;
    for(auto& uw : g[v]) {
      int u;
      double w;
      tie(u,w)=uw;
      if(visited[u]) continue;
      if(d+w<dist[u]) {
        dist[u]=d+w;
        pq.push(make_pair(dist[u],u));
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll xs,ys,xt,yt;
  cin>>xs>>ys>>xt>>yt;
  int n;
  cin>>n;
  vector<ll> x(n+2);
  vector<ll> y(n+2);
  vector<ll> r(n+2);
  x[0]=xs;
  y[0]=ys;
  r[0]=0;
  x[1]=xt;
  y[1]=yt;
  r[1]=0;
  rep(i,n)cin>>x[i+2]>>y[i+2]>>r[i+2];
  WG g;
  vector<double> dist(n+2);
  rep(i,n+2) {
    rep(j,n+2) {
      if(i==j)
        continue;
      ll dx=x[i]-x[j];
      ll dy=y[i]-y[j];
      g[i][j]=max(0.0,sqrt(dx*dx+dy*dy)-r[i]-r[j]);
    }
  }
  dijkstra(0,g,dist);
  cout << fixed;
  cout << dist[1] << endl;
  return 0;
}


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

int main(){
	string s;
	cin >> s;
	
	int ans1=0;
	for(int i=0;i<s.length();i++){
		if(i%2==0&&s[i]=='0')ans1++;
		if(i%2==1&&s[i]=='1')ans1++;
	}
	
	int ans2=0;
	for(int i=0;i<s.length();i++){
		if(i%2==0&&s[i]=='1')ans2++;
		if(i%2==1&&s[i]=='0')ans2++;
	}
	
	cout << min(ans1,ans2) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+20;
const int M=1<<20;
ll w,h;
int main()
{
	while(cin>>w>>h)
	{
		ll ans=2e15;
		ll S=w*h;
		for(ll i=1;i<h;i++)//ºáÇÐ 
		{
			ll a=i*w;
			
			//Ê£ÏÂ¾ù·Ö
			ll h1=h-i;
			//Êú¾ù·Ö
			ll b=h1*(w/2),c=h1*(w-w/2);
			if(a&&b&&c)
				ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
			//ºá¾ù·Ö
			b=w*(h1/2),c=w*(h1-h1/2);
			if(a&&b&&c)
				ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
		
		}
		
	
		for(int i=1;i<w;i++)
		{
			ll a=i*h;
			//
			ll w1=w-i;
			ll b=w1*(h/2),c=w1*(h-h/2);//ºá¾ù·Ö
			if(a&&b&&c)
				ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
			b=h*(w1/2),c=h*(w1-w1/2);
			if(a&&b&&c)
				ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
		} 
		cout<<ans<<endl;
	}
	return 0;
}

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

import numpy
import scipy
#import sys


S = input()

S = S.replace("eraser", "")
#print(S)
S = S.replace("erase", "")
#print(S)
S = S.replace("dreamer", "")
#print(S)
S = S.replace("dream", "")
#print(S)

if S == "":
    print("YES")
else:
    print("NO")

Measured memory_bytes: 12648
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
edges = [set() for _ in range(N+1)]
MOD = 10 ** 9 + 7
for _ in range(N-1):
    a, b = lr()
    edges[a].add(b)
    edges[b].add(a)

roots = [None] * (N+1)
roots[1] = 1
que = deque([1])
while que:
    q = que.popleft()
    for next in edges[q]:
        if roots[next] == None:
            roots[next] = q
            que.append(next)

def permutation(n, x):
    # nPx 順列　ex) permutaion(5, 2) = 20
    tmp = 1
    for i in range(n, n-x, -1):
        tmp = (tmp * i) % MOD
    return tmp

def dfs(x):
    global answer
    answer %= MOD
    if x == 1:
        answer *= permutation(K-1, len(edges[x]))
    else:
        answer *= permutation(K-2, len(edges[x])-1)
    for y in edges[x]:
        if y == roots[x]:
            continue
        dfs(y)

answer = K # 1にはK色塗れる
dfs(1)
print(answer%MOD)
# 50

Measured memory_bytes: 100888
#include <cstdio>

int main(){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if(a >= b){
        printf("delicious\n");
    }else if(b - a <= x){
        printf("safe\n");
    }else{
        printf("dangerous\n");
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S=sc.next();
		int tmp=0;
      	String ttt;
		for(int i=1;i<9;i++){
          	ttt = String.valueOf(i);;
			tmp+=i*(S.length() - S.replace(ttt,"").length());
		}
		if(tmp%9==0){
			System.out.println("Yes");
        }else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 43208
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();

		board = new char[h][w];
		dist = new int[h][w];
		visit = new boolean[h][w];

		int block = 0;
		for(int i = 0; i < h; i++){
			String str = sc.next();

			for(int j = 0; j < w; j++){
				board[i][j] = str.charAt(j);
				if(board[i][j] == '#'){
					block++;
				}
			}

//			Arrays.fill(dist[i], Integer.MAX_VALUE);
		}

		ArrayList<Point2D> queue = new ArrayList<Point2D>();

		visit[0][0] = true;
		dist[0][0] = 1;
		queue.add(new Point2D.Double(0, 0));

		int dx[] = {0,1,0,-1};
		int dy[] = {1,0,-1,0};
		while(!queue.isEmpty()){
			Point2D point = queue.remove(0);

			for(int i = 0; i < 4; i++){
				int tmpX = (int)point.getX() + dx[i];
				int tmpY = (int)point.getY() + dy[i];

				if(tmpX < 0 || tmpX >= w || tmpY < 0 || tmpY >= h || board[tmpY][tmpX] == '#'){
					continue;
				}

				if(!visit[tmpY][tmpX]){
					visit[tmpY][tmpX] = true;
					dist[tmpY][tmpX] = dist[(int)point.getY()][(int)point.getX()] + 1;
					queue.add(new Point2D.Double(tmpX, tmpY));
				}
			}
		}

//		for(int i = 0; i < h; i++){
//			for(int j = 0; j < w; j++){
//				System.out.print(dist[i][j] + " ");
//			}
//			System.out.println();
//		}

		System.out.println(dist[h - 1][w - 1] != 0 ? h*w - block - dist[h - 1][w - 1] : -1);

	}

	static char[][] board;
	static int[][] dist;
	static boolean[][] visit;

}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <bits/stdc++.h>


using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair


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

    int h, w;  cin>>h>>w;
    map<int, pii> seg;
    multiset<int> candi; // ai - i;
    for (int i=1; i<= w; ++i){
        seg[i] = {i, i+1};
        candi.insert(0);
    }
    for (int i = 0; i<h; ++i){
        int a, b; cin>>a>>b;
        auto left = seg.lower_bound(a);
        auto right = seg.lower_bound(b+2);
        if (left != right)
        {
            auto e = prev(right);
            pii in = {left->second.first, e->second.second};
            vi torm;
            for (auto it = left; it != (right); ++it) torm.push_back(it->first);
            for (int v : torm)
            {
                int c = v - seg[v].second+1;
                if (v <= w) candi.erase(candi.find(c));
                seg.erase(v);
                //
            }
            seg[b+1] = in;
            if (b+1 <= w) candi.insert(b - in.second + 2);
        }
        if (seg.begin()->first <= w) cout<<*candi.begin() + i + 1;
        else cout<<-1;
        cout<<'\n';
    }

}


Measured memory_bytes: 25464
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by kazuki on 2014/07/10.
 */
public class Main{
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args) {
        int tNum, hNum, tCalc, hCalc, calc;
        int[] t, h;
        int n = 0, m = 0;
        boolean flag;

        while (true) {
            tNum = s.nextInt();
            hNum = s.nextInt();

            if (tNum == 0 && hNum == 0) break;

            tCalc = 0;
            hCalc = 0;
            flag = false;
            t = new int[tNum];
            h = new int[hNum];

            for (int i = 0; i < tNum; i++) {
                t[i] = s.nextInt();
                tCalc += t[i];
            }
            for (int i = 0; i < hNum; i++) {
                h[i] = s.nextInt();
                hCalc += h[i];
            }

            Arrays.sort(t);
            Arrays.sort(h);

            calc = tCalc - hCalc;

            for (n = 0; n < tNum; n++) {
                for (m = 0; m < hNum; m++) {
                    if (calc == (t[n] - h[m])*2) {
                        flag = true;
                        break;
                    }
                }
                if (flag) break;
            }
            if (flag)
                System.out.println(t[n] + " " + h[m]);
            else
                System.out.println("-1");
        }

    }
}

Measured memory_bytes: 21044
//stringray

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

/*#ifndef __LOCAL__ 
#pragma comment(linker,"/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif*/ 

using namespace std;
using namespace __gnu_pbds;

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

typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<set<int>> vsi;

#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define F first
#define S second
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0)


const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T>
istream& operator >> (istream& is,vector<T>& vec){
  for(T &x:vec)is>>x;
  //for(int i=0;i<vec.size();++i)is>>x[i];
  return is;
}

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

ll mpow(ll a, ll b){
  ll ret=1;
  while(b>0){
    if(b&1)ret=(ret*a)%mod;
    (a=a*a)%=mod;
    b>>=1LL;
  }
  return ret;
}

//#define int int64_t
//int a[N+2];
void solve(){
  int r;cin>>r;
  cout<<3*r*r<<endl;
  
}
int32_t  main(){
  IOS;
  solve();
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

void run (void) {
  i64 n, x;
  scanf ("%" SCNi64 "%" SCNi64, &n, &x);
  i64 *len = (i64 *) calloc (n, sizeof (i64));
  i64 *p = (i64 *) calloc (n, sizeof (i64));
  len[0] = p[0] = 1;
  for (i32 i = 1; i < n; ++i) {
    len[i] = 2 * len[i - 1] + 3;
    p[i] = 2 * p[i - 1] + 1;
  }
  i64 ans = 0;
  for (i32 i = n; x > 0; --i) {
    x--;
    if (x < len[i - 1]) continue;
    x -= len[i - 1];
    ans += p[i - 1];
    if (x == 0) break;
    x--;
    ans++;
    if (x < len[i - 1]) continue;
    x -= len[i - 1];
    ans += p[i - 1];
    break;
  }
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 128