akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define drep(i,n) for (int i = n-1; i >= 0; --i)
#define pb push_back
#define sz(x) int(x.size())
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
using namespace std;
inline int in() { int x; scanf("%d", &x); return x;}
typedef vector<int> vi;
typedef vector<vi> vvi;

struct Lowlink {
  int n, k;
  vvi to, st, br;
  vi ord, low;
  Lowlink(int n=0):n(n),to(n),st(n),br(n),ord(n,-1),low(n){}
  void add(int a, int b) {
    to[a].pb(b); st[a].pb(0);
    to[b].pb(a); st[b].pb(0);
  }
  void dfs(int v, int p=-1) {
    ord[v] = low[v] = k++;
    rep(i,sz(to[v])) {
      int u = to[v][i];
      if (u == p) continue;
      if (ord[u] == -1) {
        st[v][i] = 1;
        dfs(u,v);
        mins(low[v],low[u]);
      } else {
        st[v][i] = -1;
        mins(low[v],ord[u]);
      }
    }
  }
  int init() {
    k = 0;
    dfs(0);
    int res = 0;
    rep(i,n)rep(j,sz(to[i])) {
      int v = i, u = to[i][j];
      if (ord[v] > ord[u]) swap(v,u);
      if (ord[u] == low[u]) res++;
      br[i].pb(ord[u] == low[u]);
    }
    return res/2;
  }
};

int n, m;
vvi to;
vi used, vs;

int rv;
bool cfs(vvi& to, int v) {
  if (used[v]) {
    if (used[v] == 2) return false;
    rv = v;
    return true;
  }
  used[v] = 1;
  for (int u : to[v]) {
    if (cfs(to,u)) {
      if (rv != -1) vs.pb(v);
      if (rv == v) rv = -1;
      return true;
    }
  }
  used[v] = 2;
  return false;
}
bool findCycle(vvi& to) {
  used = vi(n);
  rv = -1;
  rep(i,n) if (!used[i]) {
    if (cfs(to,i)) return true;
  }
  return false;
}
bool solve1(int u, int v) {
  // printf("%d %d\n", v, u);
  vvi t(n);
  rep(i,n) for (int j : to[i]) {
    if (i == v && j == u) continue;
    t[i].pb(j);
    // printf("edge %d %d\n", i, j);
  }
  if (findCycle(t)) return false;
  // printf("%d %d\n", v, u);
  Lowlink g(n);
  rep(i,n) for (int j : to[i]) {
    if (i == v && j == u) continue;
    g.add(i,j);
  }
  return g.init() >= 2;
}
bool solve2(Lowlink& g, int ei, int ej) {
  Lowlink t(n);
  rep(i,n)rep(j,sz(g.to[i])) {
    if (ei == i && ej == j) continue;
    int u = g.to[i][j];
    if (!g.st[i][j]) continue;
    if (g.st[i][j] == -1 && i < u) continue;
    t.add(i,u);
  }
  return t.init() >= 2;
}

int main() {
  n = in(); m = in();
  to = vvi(n);
  rep(i,m) {
    int a = in(), b = in();
    --a; --b;
    to[a].pb(b);
  }
  if (findCycle(to)) {
    int s = sz(vs);
    rep(i,s) {
      if (solve1(vs[i],vs[(i+1)%s])) {
        puts("YES");
        return 0;
      }
    }
  } else if (m >= n) {
    Lowlink g(n);
    rep(i,n) for (int u : to[i]) g.add(i,u);
    if (g.init() >= 2) {
      puts("YES");
      return 0;
    }
    rep(i,n) rep(j,sz(g.to[i])) {
      if (g.st[i][j] != 1 || g.br[i][j]) continue;
      if (solve2(g,i,j)) {
        puts("YES");
        return 0;
      }
    }
  }
  puts("NO");
  return 0;
}

Measured memory_bytes: 3496
import Control.Monad
import Control.Applicative
solve :: [[Double]] -> [Double]
solve [_,vecX,vecY] =
    [
        chebyshev 1.0 vecX vecY,
        chebyshev 2.0 vecX vecY,
        chebyshev 3.0 vecX vecY,
        maximum $ zipWith (\x y -> abs(x-y)) vecX vecY
    ] 
    where
    chebyshev :: Double -> [Double] -> [Double] -> Double
    chebyshev n vx vy =
        (sum $ zipWith (\x y -> abs(x-y)**n) vx vy) ** (1.0/n)

main =
    mapM_ (putStrLn . show) =<< solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Double]]
    takeInputs = take 3 . map (map read . words)

Measured memory_bytes: 4432
import java.util.Scanner;

public class Main {


      public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            int d = sc.nextInt();
            int t = sc.nextInt();
            int s = sc.nextInt();

            String  ans = "Yes";
            if (!(t * s >=d)){
                  ans = "No";
            }
            System.out.println(ans);
            

      }


}


Measured memory_bytes: 35636
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b; cin >> a >> b;
	if(a + b == 15){
		cout << "+" << endl;
	}
	else if(a * b == 15){
		cout << "*" << endl;
	}
	else cout << "x" << endl;
	
	return 0;
}

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

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> void drop(T x){cout<<x<<endl;exit(0);};

int check(string s){

  int n=s.size();

  for(int i=0;i<n;i++){
    for(int j=i+2;j<n;j++){
      if(s[i]!='B') continue;
      if(s[j]!='B') continue;
      int lose=1;
      for(int k=i+1;k<j;k++)
        if(s[k]!='W') lose=0;
      if(lose) return -1;
    }
  }

  int res=0;
  for(int i=0;i<n;i++){
    for(int j=i+2;j<n;j++){
      if(s[i]!='W') continue;
      if(s[j]!='W') continue;
      int win=1;
      for(int k=i+1;k<j;k++)
        if(s[k]!='B') win=0;
      if(win) chmax(res,j-i-1);
    }
  }
  //cout<<s<<":"<<res<<endl;
  return res;
}

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

  int n;
  string s;
  cin>>n>>s;

  int ans=0;

  for(int i=0;i<n;i++){
    if(s[i]!='.') continue;
    string t=s;
    t[i]='W';
    chmax(ans,check(t));
  }

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



Measured memory_bytes: 3212
import sys


def resolve(in_):
    x = int(in_.read())
    for a in range(-118, 119 + 1):
        for b in range(-118, 119 + 1):
            if x == a ** 5 - b ** 5:
                return a, b
    raise ValueError()


def main():
    answer = resolve(sys.stdin.buffer)
    print('{} {}'.format(*answer))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec));
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	int n;
	cin>>n;
	int cnt=0;
	pair<int,int>p[n];
	rep(i,n) {
		cin>>p[i].first>>p[i].second;
	}
	reverse(p,p+n);
	rep(i,n) {
		if((p[i].first+cnt)%p[i].second==0) continue;
		cnt+=p[i].second-(p[i].first+cnt)%p[i].second;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 1792
function main(input) {
  const inputs = input.split('\n')
  const [N, K] = inputs[0].split(' ').map(Number)
  const su = Array.from(new Array(N + 1))
  for(let i = 1; i <= K * 2; i += 2) {
    const d = inputs[i]
    const Ai = inputs[i+1].split(' ')
    // console.log(d, Ai)
    Ai.forEach(e => {
      su[e] = true
    })
  }
  // console.log(su)
  console.log(
    su.slice(1).reduce((h, e) => {
      return e === undefined ? h + 1 : h
    }, 0)
  )
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 29336
#include <bits/stdc++.h>
typedef long long int ll;
//typedef unsigned long long int ull;
typedef long double ld;
 
#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353
#define vi vector<ll>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x, 0;
#define all(v) v.begin(),v.end()

#define naman                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

const ll INF=1e18;
const double PI=4*atan(1);

void solve(){
    ld a,b;
    cin >>a  >> b;
    cout << (ll)(a*b) << endl;

}

int32_t main(){
    naman
    ll i = 0,j = 0;
      
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
      
    //cout << fixed << setprecision(10);

    ll t;
    t=1;
    //cin >> t;
    ll cno=0;
    while (t--){
        solve();

    }

}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9 + 7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    int n, d;
    while(cin >> n >> d, n){
        vector<vector<int> > c(n);
        vector<int> sum(n, 0);
        for(int i=0;i<n;i++){
            int m;
            cin >> m;
            c[i].resize(m);
            for(int j=0;j<m;j++){
                cin >> c[i][j];
                sum[i] += c[i][j];
            }
        }
        bool update = true;
        while(update){
            update = false;
            int fst = 0, snd = 0, mi = IINF;
            for(int i=0;i<n;i++){
                if(sum[i] > fst){
                    snd = fst;
                    fst = sum[i];
                }
                else if(sum[i] > snd){
                    snd = sum[i];
                }
                mi = min(mi, sum[i]);
            }
            for(int i=0;i<n;i++){
                if(c[i].empty()) continue;
                if(sum[i] == fst){
                    if(snd - min(mi, sum[i]-c[i].back()) <= d){
                        sum[i] -= c[i].back();
                        c[i].pop_back();
                        update = true;
                        break;
                    }
                }
                else{
                    if(fst - min(mi, sum[i]-c[i].back()) <= d){
                        sum[i] -= c[i].back();
                        c[i].pop_back();
                        update = true;
                        break;
                    }
                }
            }
        }
        bool ok = true;
        for(int i=0;i<n;i++){
            ok &= c[i].empty();
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
    return 0;
}



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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll k,sum;
    cin>>k>>sum;
    ll ans=0;
    for(int x=0;x<=k;x++)
    {
        for(int y=0;y<=k;y++)
        {
            int z=sum-x-y;
            if(z>=0&&z<=k)
            {
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i = 0; i , (n); ++i)
using ll = long long;
using namespace std;
int sum(int n) {
    if (n == 0) {
        return 0;
    }

    int s = sum(n - 1);
    return s + n;
}
int main() {
    int N;
    string S;
    int A = 0, W = 0, T = 0, R = 0;
    cin >> N;
    for (int i = 0;i < N;i++) {
        cin >> S;
        if (S == "AC") {
            A++;
        }
        if (S == "WA") {
            W++;
        }
        if (S == "TLE") {
            T++;
        }
        if (S == "RE") {
            R++;
        }
    }
    cout << "AC x " << A << endl;
    cout << "WA x " << W << endl;
    cout << "TLE x " << T << endl;
    cout << "RE x " << R << endl;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,b=0;
    cin>>n;
    int t[n];
    for(int i=0;i<n;i++) {cin>>t[i]; b+=t[i];}
    cin>>m;
    int p[m],x[m];
    for(int i=0;i<m;i++) {cin>>p[i]>>x[i]; cout<<b-t[p[i]-1]+x[i]<<endl;}
  return 0;
}


Measured memory_bytes: 256
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]
 
def F(n):
    time = 0
    for i in range(n, N-1):
        c, s, f = CSF[i]
        if time <= s:
            time = s + c
        else:
            remainder = time % f
            time += (f-remainder)%f+c
    print(time)
for i in range(N-1):
    F(i)
print(0)

Measured memory_bytes: 3188
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1e9+7 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	ll ans = 0 ;
	while(n--){
		ll a ; cin >> a ;
		while(a%2==0){
			ans++ ;
			a /= 2 ;
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})



 int main(){

 ll n,k;
   cin>>n>>k;

   map<ll,ll>mp;

   for(int i=0;i<n;++i){
      int a,b;
      cin>>a>>b;
      mp[a] += b;
   }

   ll cnt=0;

   map<ll,ll>::iterator it;
   for(it=mp.begin();it!=mp.end();it++){
      cnt += it->second;
      if(cnt >=  k){
            cout<<it->first<<endl;
            return 0;
      }
   }

 return 0;
 }


Measured memory_bytes: 7436
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
            sum+=i;
    }
    cout<<sum;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	if(n%2==0){
		cout<<(n*(n-1))/2 - n/2<<endl;
		For(i,1,n+1){
			For(j,i+1,n+1){
				if(i+j==n+1) continue;
				else{
					cout<<i<<" "<<j<<endl;
				}
			}
		}
	}else{
		ll k = n-1;
		cout<<(n*(n-1))/2 - k/2<<endl;
		For(i,1,n+1){
			For(j,i+1,n+1){
				if(i!=n && j!=n && (i+j)==k+1) continue;
				else{
					cout<<i<<" "<<j<<endl;
				}
			}
		}
	}











	
}

Measured memory_bytes: 256
N,H=map(int,input().split())
ab=sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1],reverse=True)
ab_M=max([ab[i][0] for i in range(N)])
ab_m=min([ab[i][1] for i in range(N) if ab[i][0]==ab_M])
cnt=0
flag=0
for i in range(N):
    if ab[i][1]<=ab_M:
        break
    elif flag==0 and ab[i]==[ab_M,ab_m]:
        flag=1
    else:
        H-=ab[i][1]
        cnt+=1
        if H<=0:
            break
if H>0:
    if H<=ab_m:
        print(cnt+1)
    else:
        print(cnt+1+(H-ab_m+ab_M-1)//ab_M)
else:
    print(cnt)

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

using lint = long long;

lint comb(lint n, lint r) {
    lint res = 1;
    for (lint i = 0; i < r; i++) {
        res = res * (n - i) / (i + 1);
    }
    return res;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    map<lint, int> num;
    for (int i = 0; i < n; i++) {
        lint v;
        cin >> v;
        num[v]++;
    }

    int count = 0;
    lint sum = 0, ans = 0;
    double ave;
    for (auto i = num.rbegin(), e = num.rend(); i != e; i++) {
        lint val = i->first;
        int have = i->second;
        if (count == 0 and a <= have) {
            for (lint j = a; j <= min(b, have); j++) {
                ans += comb(have, j);
            }
            ave = val;
            break;
        } else {
            int take = min(have, a - count);
            count += take;
            sum += val * take;
            ave = double(sum) / double(count);
            if (count == a) {
                ans = comb(have, take);
                break;
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;


int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,k,n,m;
     ll t;
     string s;
     cin>>n>>k;
     map<ll,bool> m1;
     for(i=0;i<k;i++)
     {
         cin>>m;
        
         ll r;
         for(j=0;j<m;j++)
         { cin>>r;
           m1[r]=true;}
     }
     ll ans=0;
     for(i=1;i<=n;i++)
     {
         if(m1[i]==false)
             ans++;
     }
     cout<<ans;
}  


Measured memory_bytes: 3624
<?php
  list($h, $w, $x) = explode(" ", trim(fgets(STDIN)));

  $masu = [];
  for ($i=0; $i<$h; $i++) {
    list($masu[]) = explode(" ", trim(fgets(STDIN)));
  }

  $ans = 0;
  $wend=pow(2, $w);
  $hend=pow(2, $h); 
  for ($i=0; $i<$hend; $i++) {
    for ($j=0; $j<$wend; $j++) {
      $count = 0;
      for ($k=0; $k<$h; $k++) {
        for ($l=0; $l<$w; $l++) {
//          echo $i." ".$k." ".$j." ".$l." ".(($i >> $k) & 1)." ".(($j >> $l) & 1)." ".$masu[$k][$l].PHP_EOL;
          if(($i >> $k & 1) == 1 && ($j >> $l & 1) == 1){ 
	          if($masu[$k][$l] == '#'){
    	        $count++;
        	  }
          }
        }
      }
      
      if($count == $x){
//      echo $i." ".$j." ".$count." ".$x.PHP_EOL;
        $ans++;
      }
    }
  }
  echo $ans;

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

int n, ans, l, r;

int main(){
	scanf("%d", &n);
	ans = 0;
	while(n--){
		scanf("%d %d", &l, &r);
		ans = ans + r - l + 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <math.h>
#include <algorithm>
#include <functional>

using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)



signed main()
{
	vector<int> color(8,0),tmp;
	int n;
	int ultra = 0;
	int result = 0,result2 = 0;
	cin >> n;
	tmp.resize(n);
	REP(i, n) {
		cin >> tmp[i];
	}

	REP(i, n) {
		if(tmp[i] < 3200) color[tmp[i]/400] = 1;
		else ultra++;
	}

	REP(i, 8) {
		result += color[i];
	}
	result2 = result + ultra;
	if (result == 0) result = 1;
	cout << result <<  " " << result2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1000003;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=3000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll q,x,d,n;

int main(){
	Init();
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>x>>d>>n;
		if(d==0){
			cout<<Pow(x,n)<<endl;
			continue;
		}
		if(n>mod){
			cout<<0<<endl;
			continue;
		}
		ll t=Div(x,d)%mod;
		cout<<Div(F[t+n-1],(t?F[t-1]:1))*Pow(d,n)%mod<<endl;
	}
}

Measured memory_bytes: 24320
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int n, m, ans = INF;
vector<P> sc(5);
int main(){
    cin >> n >> m;
    rep(i, 0, m) cin >> sc[i].first >> sc[i].second;

    int start = pow(10, n-1); if(start < 10) start = 0;
    int end = pow(10, n);

    rep(i, start, end){
        int cnt = 0;
        string str = to_string(i);
        rep(i, 0, m){
            int f = sc[i].first, s = sc[i].second;
            f--;
            if(str[f]-'0' == s) cnt++;
        }
        if(cnt == m){
            ans = i;
            break;
        }
    }

    if(ans == INF) cout << -1 << el;
    else cout << ans << el;

    return 0;
}


Measured memory_bytes: 3528
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
 
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
 
    var ans = a - b;
    if(ans < 0) {
        ans = 0;
    }
	console.log('%d',ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
/***********************************************
 *                                             *
 *   author: raghav_0901 (Raghav Dalmia)       *
 *   updated on: 21-06-2020, 12:25:15 am IST   *
 *                                             *
\***********************************************/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

signed main( )
{

    char c;cin>>c;

    if(c>='a' && c<='z')
        cout<<"a\n";
    else
        cout<<"A\n";

    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
//#include <limits.h>
int INF = 1000000009;
int main(){
	int n,m,s,i,j;
	scanf("%d%d%d",&n,&m,&s);
	int e[2100][3],dist[2100],update=1;
	for(i=0;i<m;i++){
		for(j=0;j<3;j++){
			scanf("%d",&e[i][j]);
		}
	}
	for(i=0;i<n;i++){
		dist[i]=INF;
	}
	dist[s]=0;
	for(i=0;i<n-1;i++){
		update=0;
		for(j=0;j<m;j++){
			if(dist[e[j][0]]!=INF&&dist[e[j][1]]>dist[e[j][0]]+e[j][2]){
				dist[e[j][1]]=dist[e[j][0]]+e[j][2];
				update=1;
			}
		}
		if(update==0)break;
	}
	for(j=0;j<m;j++){
		if(dist[e[j][0]]!=INF&&dist[e[j][1]]>dist[e[j][0]]+e[j][2]){
			printf("NEGATIVE CYCLE\n");
			return 0;
		}
	}
	for(i=0;i<n;i++){
		//if(i>0)printf("\n");
		if(dist[i]==INF){
			printf("INF\n");
		}
		else{
			printf("%d\n",dist[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 632
n, w = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]

v_max = 100*(10**3) + 1
INF = 10**18

dp = [[INF]*(v_max) for i in range(n+1)]
dp[0][0] = 0

for i in range(n):
    weight, val = info[i]
    for j in range(v_max):
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        if j - val >= 0:
            dp[i+1][j] = min(dp[i][j-val] + weight, dp[i+1][j])

ans = 0
for i, num in enumerate(dp[n]):
    if num <= w:
        ans = i
print(ans)

Measured memory_bytes: 119916
import java.util.Scanner;
 
public class Main {
    long count = 0;
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        StringBuilder builder = new StringBuilder();
        int[] A = new int[n];
        int[] B = new int[n];
        int K = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            A[i] = scanner.nextInt();
            K = Math.max(K, A[i]);
        }
        CountingSort(A, B, K);
        builder.append(B[0]);
        for (int i = 1; i < n; i++) {
            builder.append(' ').append(B[i]);
        }
        System.out.println(builder);
    }
 
    private void CountingSort(int[] a, int[] b, int k) {
        int[] C = new int[k + 1];
        for (int i = 0; i < a.length; i++)
            C[a[i]]++;
 
        for (int i = 1; i <= k; i++)
            C[i] += C[i - 1];
 
        for (int i = a.length - 1; i >= 0; i--) {
            C[a[i]]--;
            b[C[a[i]]] = a[i];
 
        }
    }
}


Measured memory_bytes: 515116
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for(int i=0;i<n;++i) cin >> v[i];
  for(int i=0;i<n;++i) cin >> c[i];  

  for(int i=0;i< (1<<n);i++){
    int total = 0;
    for(int j=0;j<n;j++){
      if(1<<j & i) total += (v[j] -c[j]);  
    }
    ans = max(total,ans); 
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (sx, sy, tx, ty) = readInputLine().split(" ").map { it.toInt() }

    for (i in 1..ty - sy) {
        print('U')
    }
    for (i in 1..tx - sx) {
        print('R')
    }
    for (i in 1..ty - sy) {
        print('D')
    }
    for (i in 1..tx - sx) {
        print('L')
    }
    
    print('L')
    for (i in 0..ty - sy) {
        print('U')
    }
    for (i in 0..tx - sx) {
        print('R')
    }
    print('D')

    print('R')
    for (i in 0..ty - sy) {
        print('D')
    }
    for (i in 0..tx - sx) {
        print('L')
    }
    print('U')

    println()
}

fun readInputLine(): String {
    return readLine()!!
}



Measured memory_bytes: 42864
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200'005)
#define MOD (1000000000ll + 7ll)
#define OO (1050000000)
#define OOL (1100000000000000000)

//global


int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	string x;
	cin >> x;
	int ans = 0;
	stack<bool> s;
	rep(i,0,sz(x)){
		if(x[i] == 'T'){
			if(sz(s)){
				s.pop();
			}else{
				ans++;
			}
		}else{
			s.push(1);
		}
	}
	cout << ans+sz(s) << endl;
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> p[i];
  }
  int ans = accumulate(p.begin(), p.end(), 0) - *max_element(p.begin(), p.end()) / 2;
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3584
from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = deque()
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat.append((h, w, 0))
            s[w] = 1
        else:
            s[w] = 0
    dp[h] = s

while len(mat):
    h, w, cnt = mat.popleft()

    for t, h, w, cnt in ((h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)):
        if t and dp[h][w] == 0:
            mat.append((h, w, cnt+1))
            dp[h][w] = 1

print(cnt)


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

using namespace std;

typedef long long ll;

ll gcd(ll m, ll n){
	return n ? gcd(n, m%n) : m;
}

ll lcm(ll m, ll n){
	return m / gcd(m, n) * n;
}

string hexstr = "0123456789ABCDEF";

int main(){	
	int T;
	cin >> T;
	int abc = 0;
	while (T--){
		int N;
		cin >> N;
		vector<string> v(N);
		vector<int> gcds;
		for (int i = 0; i < N; ++i) cin >> v[i];

		ll total = 1;
		for (auto &s : v){
			int g = s.size() / 2;
			for (int i = 0; i < s.size(); i += 2){
				if (s[i] != '0' || s[i+1] != '0') g = gcd(g, i / 2);
			}
			total = lcm(total, s.size() / 2 / g);
			total = min(total, 1025ll);
			gcds.push_back(g);
		}

		if (total * 2 <= 2048){
			vector<int> ans(total);
			for (int j = 0; j < v.size(); ++j){
				string &s = v[j];
				int g = gcds[j];
				int mul = total / (s.size() / 2 / g);
				for (int i = 0; i < s.size(); i += 2){
					if (s[i] == '0' && s[i + 1] == '0') continue;
					int pos = i / 2 / g * mul;
					ans[pos] |= (s[i] - '0') * 16;
					ans[pos] |= (s[i + 1] - '0');
				}
			}
			for (auto &e : ans){
				int x = e / 16, y = e % 16;
				cout << hexstr[x] << hexstr[y];
			}
			cout << endl;
		}
		else{
			cout << "Too complex." << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    ll x, y;
    cin >> x >> y;
    int ans = 0;
    for (ll i = x; i <= y;)
    {
        i *= 2;
        ans++;

        /* code */
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = 'a'.ord
ans = ''
p = 0
while n > 0
  d = n % 26
  if d == 0
    ans << 'z'
    n = (n - 26) / 26
  else
    ans << (a + d - 1).chr
    n = (n - d) / 26
  end
end
puts ans.reverse


Measured memory_bytes: 14372
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n,p;cin>>n>>p;
    ll o=0,e=0;
    rep(i,n){
        int a;cin>>a;
        a%=2;
        if(a==0)e++;
        else o++;
    }
    
    ll res=1;
    rep(i,n)res*=2;
    if(o==0){
        if(p==0)cout<<res<<endl;
        else cout<<0<<endl;
        return 0;
    }
    cout<<res/2<<endl;
}

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

using namespace std;

bool IsOdd(int x)
{
  	int Cnt = 0;
  	while(x)	x /= 10, Cnt++;
  	return Cnt & 1;
}

int main()
{
	int n;	cin >> n;
  	
  	int Ans = 0;
  
  	for(int i = 1; i <= n; i++)	Ans += IsOdd(i);
  	
  	cout << Ans;
}

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

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

    map<string, int> m;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        m[s] += 1;
    }

    int maxCnt = 0;
    for (auto i = m.begin(); i != m.end(); ++i) {
        int cnt = i->second;
        maxCnt = max(maxCnt, cnt);
    }

    for (auto i = m.begin(); i != m.end(); ++i) {
        if (maxCnt == i->second) cout << i->first << endl;
    }

    return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m;
vector<i64> a;

template<class F>
i64 bisect(i64 l, i64 r, F f) { // (l, r]
  if (r - l <= 1) return r;
  i64 m = l + (r - l) / 2;
  return f(m) ? bisect(l, m, f) : bisect(m, r, f);
}

template<class F>
i64 bisect_left(i64 l, i64 r, F f) {
  return bisect(l, r, [=](i64 x) { return !f(x); }) - 1;
}

int main() {
    cin >> n >> m;
    read_n(a, n);
    sort(begin(a), end(a));
    vector<i64> s(n + 1);
    for (int i = 1; i <= n; ++i) {
        s[i] = s[i - 1] + a[i - 1];
    }

    i64 sum = 0, cnt = 0;
    i64 x = bisect_left(0, 1e6, [&](i64 x) {
        cnt = 0;
        sum = 0;
        for (int i = 0; i < n; ++i) {
            auto it = lower_bound(begin(a), end(a), x - a[i]);
            int j = end(a) - it;
            cnt += j;
            sum += j * a[i] + s[n] - s[it - begin(a)];
        } 
        // cerr << x << ' ' << cnt << ' ' << sum << endl;
        return cnt >= m;
    });

    i64 ans = sum - (cnt - m) * x;

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

Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(memo: &mut Vec<Vec<i32>>, x: usize, y: usize) -> i32 {
    if x <= 1 && y <= 1 {
        return 0;
    }
    if memo[x][y] != -1 {
        return memo[x][y];
    }
    let mut ret = 0;
    for i in 1..x / 2 + 1 {
        let nx = x - 2 * i;
        let ny = y + i;
        ret = std::cmp::max(ret, 1 ^ calc(memo, nx, ny));
    }
    for i in 1..y / 2 + 1 {
        let nx = x + i;
        let ny = y - 2 * i;
        ret = std::cmp::max(ret, 1 ^ calc(memo, nx, ny));
    }
    memo[x][y] = ret;
    ret
}

fn naive(x: usize, y: usize) -> i32 {
    let mut memo = vec![vec![-1; x + y + 1]; x + y + 1];
    calc(&mut memo, x, y)
}

fn main() {
    let x = read::<i64>();
    let y = read::<i64>();
    println!("{}", if (x - y).abs() <= 1 { "Brown" } else { "Alice" });
}


Measured memory_bytes: 4352
/**
	������������ Author : Avi J Patel ������������
	������������ University : DA-IICT ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 998244353
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
/*void calc()
{
	for(int i=0;i<2005;i++)
	{
		a[i][0]=1;
		a[i][i]=1;
		for(int j=1;j<i;j++)
		{
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%MOD;	
		}
	}
}*/
int main()
{
	int n,m;
	cin>>n>>m;
	if(n>m)
	swap(n,m);
	if((m-n)%2==0)
	{
		cout<<n+(m-n)/2;
	}
	else
	{
		cout<<"IMPOSSIBLE";
	}
}









Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 2019  # type: int

def solve(L: int, R: int):
    m = L // MOD
    r = L % MOD
    L -= MOD * (m + 1) # -2019 <= L <= -1
    R -= MOD * (m + 1)
    minmod = sys.maxsize
    upperbound = min(L + MOD, R + 1)
    for i in range(L, upperbound):
        for j in range(i + 1, upperbound):
            minmod = min(minmod, (i * j) % MOD)
    for i in range(L, upperbound):
        if i + MOD <= R:
            minmod = min(minmod, (i * i) % MOD)
    print(minmod)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(L, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
# reference: https://www.buildinsider.net/language/rubytips/0007

# 度からラジアンを求める
def radian(degree)
  degree * Math::PI / 180
end

# ラジアンから度を求める
def degree(radian)
  radian * 180 / Math::PI
end

a, b, h, m = gets.split.map(&:to_i)

h_degree = 30 * h + m / 2.0
m_degree = 6 * m

# Complex.polar(長さ, 偏角（ラジアン）)
# 実数部にx座標、虚数部にy座標
h_complex = Complex.polar(a, radian(h_degree))
m_complex = Complex.polar(b, radian(m_degree))
# 2点間の距離 |a - b|
puts (h_complex - m_complex).abs

# 角度（ラジアン）
# p h_complex.angle

# [x座標, y座標]
# p h_complex.rect

# 90度左回転
# p h_complex * Complex.polar(1.0, radian(90))

# 原点に対して対称
# p -h_complex

# x軸に対して対称（y座標の正負を反転）
# p h_complex.conj

# y軸に対して対称（x座標の正負を反転）
# p -h_complex.conj

# x座標3、y座標4から生成する場合
# c = Complex(3, 4)

# 原点からの距離
# p c.abs
#=> 5


Measured memory_bytes: 14744
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;

bool valid(lint a, lint b, lint c){
	if(a == b || a==c || b==c)return false;
	return a < (b+c) && b < (a+c) && c < (b+a);

}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n; cin>>n;
	vector<lint> l(n);
	for(auto &x:l)cin>>x;
	int cont = 0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			for(int k=j+1;k<n;k++)
				if(valid(l[i],l[j],l[k])){
					//cerr<<l[i]<<" "<<l[j]<<" "<<l[k]<<"\n";
					cont++;
				}
	cout<<cont<<"\n";
	return 0;	
}


Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <typeinfo>
using namespace std;

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

	double x[10];
	char u[10];

	for (int i = 0; i < N; i++) {
		cin >> x[i] >> u[i];
		cin.ignore(2);
	}
	
	for (int i = 0; i < N; i++) {
		if (u[i] == 'B')x[i] *= 380000.0;
	}
	double answer = 0;
	for (int i = 0; i < N; i++) {
		answer += x[i];
	}

	cout << fixed << setprecision(8) << answer << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
int n, x, y;
vector<int> a[MAXN], b[MAXN];
int depA[MAXN], depB[MAXN];
int fa[MAXN][21];
void dfsA(int x, int f) {
    depA[x] = depA[f] + 1;
    for (int i = 0; i < a[x].size(); i++) {
        int u = a[x][i];
        if (u == f) continue;
        dfsA(u, x);
    }
}
void dfsB(int x, int f) {
    depB[x] = depB[f] + 1;
    fa[x][0] = f;
    for (int i = 1; i < 20; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
    for (int i = 0; i < b[x].size(); i++) {
        int u = b[x][i];
        if (u == f) continue;
        dfsB(u, x);
    }
}
int lca(int u, int v) {
    if (depB[u] < depB[v]) swap(u, v);
    for (int i = 19; i >= 0; i--)
        if (depB[fa[u][i]] >= depB[v]) u = fa[u][i];
    if (u == v) return u;
    for (int i = 19; i >= 0; i--)
        if (fa[u][i] != fa[v][i]) {
            u = fa[u][i];
            v = fa[v][i];
        }
    return fa[u][0];
}
int ans;
void dfs(int x, int f) {
    if (depA[x] >= depB[x]) return;
    if (ans != -1) ans = max(ans, (depB[x] - 1) * 2);
    for (int i = 0; i < a[x].size(); i++) {
        int u = a[x][i];
        if (u == f) continue;
        if (depB[u] + depB[x] - 2 * depB[lca(u, x)] > 2) ans = -1;
        dfs(u, x);
    }
}
int main() {
    while (SF("%d%d%d", &n, &x, &y) != EOF) {
        int u, v;
        for (int i = 1; i < n; i++) {
            SF("%d%d", &u, &v);
            a[u].push_back(v);
            a[v].push_back(u);
        }
        for (int i = 1; i < n; i++) {
            SF("%d%d", &u, &v);
            b[u].push_back(v);
            b[v].push_back(u);
        }
        dfsA(x, 0);
        dfsB(y, 0);
        ans = 0;
        dfs(x, 0);
        PF("%d\n", ans);
        for (int i = 1; i <= n; i++) {
            a[i].clear();
            b[i].clear();
        }
    }
}

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

int main() {
  int n;

  cin >> n;

  vector<int> h(n), ans(n);

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

  ans[1] = abs(h[0] - h[1]);
  for (int i = 2; i < n; i++) {
    // ans[i] = 1e5;
    // for (int j = 1; j < 2 + 1; j++) {
    ans[i] = min(abs(h[i] - h[i - 2]) + ans[i - 2],
                 abs(h[i] - h[i - 1]) + ans[i - 1]);
    //}
  }

  cout << ans[n - 1];

  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> C(N), S(N), F(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }
  for (int i = 0; i < N; i++) {
    int time = 0;
    for (int j = i; j < N - 1; j++) {
      if (time < S[j])
        time = S[j];
      else if (time % F[j] != 0)
        time += F[j] - (time % F[j]);
      time += C[j];
    }
    cout << time << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
      int d; long long int g;
        cin >> d >> g;
        int p[d]; int c[d];
        for(int i=0;i<d;i++){
          cin >> p[i]>> c[i];
        }
        long long res=1<<29;
      for(int i=0;i<(1<<d);i++){//2^d回のループ(d桁の2進数全列挙)
        long long int sum=0;//得点
        long long int num=0;//解いた数
        for(int j=0;j<d;j++){//(j+1)*100点の問題を全部解く
            if(i&(1<<j)) sum+=c[j]+p[j]*100*(j+1),num+=p[j];
            //iのj+1桁目が1であれば全完予定にする
        }//全完問題を決めたら
        if(sum>=g) res=min(res,num);//全完だけでsumがgを超えてたらresを更新
        else{//sumがgを超えてないとき
          for(int j=d-1;j>=0;j--){//点数の高い問題から解いていく
            if(i&(1<<j)) continue;//全完する予定の問題は飛ばす
            for(int k=0;k<p[j];k++){//(j+1)*100点問題の数分だけ回す
              if(sum>=g) break;//sumがg以上なら抜ける
              sum+=100*(j+1);//sumに空きがあるなら1問ずつ加える
              num++;//解答数を1増やす
            }
          }
          res=min(res,num);//sumがgを超えたら解答数の更新
        }
      }
      cout <<res<<endl;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int main() {
	string s;
	cin >> s;
	vector<pair<char, int>> v;
	pair<char, int> p;
	if (s[0] == 'J')p = make_pair('J', 1);
	if (s[0] == 'O')p = make_pair('O', 1);
	if (s[0] == 'I')p = make_pair('I', 1);
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == s[i - 1])p.second++;
		else {
			v.emplace_back(p);
			p = make_pair(s[i], 1);
		}
	}
	v.emplace_back(p);
	int ans = 0;
	if (v.size() >= 3) {
		for (int i = 0; i < v.size() - 2; i++) {
			if (v[i].first == 'J'&&v[i + 1].first == 'O'&&v[i + 2].first == 'I') {
				if (v[i].second >= v[i + 1].second&&v[i + 1].second <= v[i + 2].second) {
					ans = max(ans, v[i + 1].second);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 12604
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
 
 
int main () {
    int K;
    string S;

    cin >> K >> S;

    if(S.size() <=K){
        cout << S << endl;
    }

    else{
        rep(i,K){
            cout << S[i];
        }
        cout << "..." << endl;
    }


}


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

int main(){
    int a,b,c;
    bool f = false;
    cin >> a >> b >> c;
    if(a+b+c == 17){
        if(a == 7 || b == 7 || c == 7){
            if(a == 5 || b == 5 || c == 5){
                f = true;
            }
        }
    }
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;    
}

Measured memory_bytes: 3616