akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<string.h>
#include<map>

using namespace std;

#define ll long long 


int main(){

    ll n,w;

    cin>>n>>w;

    ll weight[n+1],value[n+1];   
    ll valsum = 0; 

    for(int i=1;i<=n;i++){
        cin>>weight[i]>>value[i];
        valsum+=value[i];
    }

    ll dp[n+1][valsum+1];

    for(int i=0;i<=n;i++) dp[i][0] = 0;
    for(int i=1;i<=valsum;i++) dp[0][i] = 1e9+1;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=valsum;j++){
            dp[i][j] = dp[i-1][j];
            if(value[i]<=j) dp[i][j] = min(dp[i][j],weight[i] + dp[i-1][j-value[i]]); 
        }
    }

    /*for(int i=0;i<=n;i++){
        for(int j=0;j<=valsum;j++) cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    ll ans = 0;
    for(int i=0;i<=valsum;i++) { if(dp[n][i]<=w)  ans = i;} 
    cout<<ans;
    return 0;
}

Measured memory_bytes: 82360
n, a, b = map(int, input().split())

def findsum(n):
    sum = 0
    while n>0:
        sum += n%10
        n //= 10
    return sum

mylist = [i for i in range(n+1) if a<=findsum(i) and findsum(i)<=b]
print(sum(mylist))

Measured memory_bytes: 3396
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;



int main(){
    int pp[4][3][10];
    
    //初期化
    rep(i,4){
        rep(j,3){
            rep(k,10) pp[i][j][k] = 0;
        }
    }
    
    int n;
    cin >> n;
    
    //人数計算
    rep(i,n){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        
        pp[a-1][b-1][c-1] += d;
    }
    
    //表示
    rep(i,3){
        rep(j,3){
            rep(k,10){
                cout <<" " << pp[i][j][k];
            }
            cout << endl;
        }
        rep(i,20) cout << "#";
        cout << endl;
    }
    
    rep(i,3){
        rep(j,10){
            cout <<" " << pp[3][i][j];
        }
        cout << endl;
    }
    
}






Measured memory_bytes: 3128
import std.stdio;
import std.array;
import std.range;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
	while(true)
	{
		int N = readln().chomp().to!int(), A = 0, B = 0;

		if(N == 0) break;
		
		foreach(_; 0..N)
		{
			auto line = readln().split.map!("a.to!int");
			int a = line[0], b = line[1];

			if(a > b) A += a + b;
			if(a < b) B += a + b;
			if(a == b) A += a, B += b;
		}

		writefln("%d %d", A, B);
	}
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

long long dp[3100][3100];

int main()
{
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int w = 1; w <= N; w++) {
    for (int i = 0; i + w <= N; i++) {
      int j = i + w;
      if ((N - w) % 2 == 0)
        dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
      else
        dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
    }
  }

  cout << dp[0][N] << endl;
  return 0;
}

Measured memory_bytes: 73984
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let lVl = parseInt(input[0][0], 10);
	let lEl = parseInt(input[0][1], 10);
	dp = []; //global
    graph = []; // global
    for (let i = 0; i < lVl; i++){
        graph.push([]);
        for  (let j = 0; j < lVl; j++){
            graph[i][j] = Infinity;
        }
        graph[i][i] = 0;
    }
    for (let i = 0; i < lEl; i++){
        graph[parseInt(input[i + 1][0], 10)][parseInt(input[i + 1][1], 10)] = parseInt(input[i + 1][2], 10);
    }
    for (let i = 0; i < Math.pow(2, lVl); i++){
        dp.push([]);
        for (let j = 0; j < lVl; j++) {
            dp[i][j] = -1;
        }
    }
	dp[0][0] = 0; //start from node0
	dp[1][0] = 0;
	
	for (let i = 1; i < lVl; i++) bitDP(Math.pow(2, lVl) - 1, i);
	let ans = Infinity;
	for (let i = 1; i < lVl; i++){
		ans = Math.min(dp[dp.length - 1][i] + graph[i][0], ans);
	}
	if (ans === Infinity) ans = -1;
	console.log(ans);
}

function bitDP(S, v){
	if (S === 0) return (v === 0) ? 0: Infinity;
	if ((S & (1 << v)) === 0) return Infinity; //S does not include v
	if (dp[S][v] !== -1) return dp[S][v]; //initial value?
	let ret = Infinity;
	for (let i = 0; i <= Math.log2(S); i++){
		if (((S ^ (1 << v)) & (1 << i)) === 0) continue;
		ret = Math.min(ret, bitDP((S ^ (1 << v)), i) + graph[i][v]);
	}
	return dp[S][v] = ret;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 58700
#include <bits/stdc++.h>
using namespace std;
int s[11];
 int ss[11];
int main()
{
int n,m;
 int sum;sum=0;cin>>n>>m;
 int x;
 int a;
 for(int i=1;i<=m;i++)
 {
     cin>>a;
     s[a]=1;
 }
 for(int i=1;i<=100000;i++)
    if(i>=n)
 {
     int a;a=i;
     int k;k=0;
     while(a)
     {
         if(s[a%10])k=1;
         a=a/10;
     }
     if(k==0){cout<<i;break;}

 }
}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  (n : _) <- map (toInteger . unsafeSignedDecimal) . T.words <$> T.getLine :: IO [Integer]
  as <- map (toInteger . unsafeSignedDecimal) . T.words <$> T.getLine :: IO [Integer]
  let
    c = foldl lcm 1 as :: Integer
    sum' :: [Int] -> Int
    sum' = foldl step 0
      where
        modulus' = fromInteger modulus :: Int
        step x y = (x + y) `mod` modulus'
  print . sum' . map (fromInteger . (`mod` modulus) . (c `div`)) $ as

modulus = 10 ^ 9 + 7 :: Integer

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 4476
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;

int main(){
	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && n==0) break;
		bool* joseph = new bool[n+1];
		fill((bool*)joseph,(bool*)joseph+n+1,true);

		joseph[0]=false;

		int idx = 1;
		int c = 0;
		int total=0;
		while(1){
			if(n-total==1) break;
			if(joseph[idx%(n+1)]) c++;
			if(c == m){
				joseph[idx%(n+1)] = false;
				total++;
				c = 0;
			}
			idx++;
		}
		cout << find(joseph,joseph+n+1,true) - joseph << endl;
	}
}

Measured memory_bytes: 0
M, D = map(int, input().split())
count = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        d1 = d // 10
        d2 = d % 10
        if d1 >= 2 and d2 >= 2 and d1 * d2 == m:
            count += 1
print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N, X[1009];
vector<int> G[1009];

int dp(vector<int> nums, int k){
    if(k==0) return 0;
    set<int> now; now.insert(0);
    for(auto x:nums){
        if(x==0) continue;
        set<int> nxt;
        for(auto y:now){
            nxt.insert(y);
            if(x+y>k) continue;
            nxt.insert(x+y);
        }
        swap(now,nxt);
    }
    int mx=0;
    for(auto x:now) if(mx<x) mx=x;
    return mx;
}

pii dfs(int u){
    vector<int> nums;
    int sm=0,bg=0;
    for(int v:G[u]){
        pii p = dfs(v);
        if(p.first==-1) return {-1,-1};
        sm+=p.first;
        bg+=p.second;
        nums.push_back(p.second-p.first);
    }
    if(bg<=X[u]) return {sm,X[u]};
    if(sm>X[u]) return {-1,-1};
    int n=dp(nums,X[u]-sm);
    sm+=n; bg-=n;
    return {min(bg,X[u]),max(bg,X[u])};
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    for(int v=2;v<=N;v++){
        int u; cin>>u;
        G[u].push_back(v);
    }
    
    rep1(i,N){
        cin>>X[i];
    }
    
    pii ans = dfs(1);
    if(ans.first!=-1){
        cout1("POSSIBLE");
    }else{
        cout1("IMPOSSIBLE");
    }
}

Measured memory_bytes: 640
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
N = int(input())
T = [int(input()) for i in range(N)]
print(lcm_list(T))


Measured memory_bytes: 67908
#include<bits/stdc++.h>
using namespace std;
char a[50][50];
int c,d,b[55][55];
int main(){
    cin>>c>>d;
    for(int i=0;i<c;i++)
    cin>>a[i];
    for(int i=0;i<c;i++)
    for(int j=0;j<d;j++)
    if(a[i][j]=='#')
    b[i][j]++,b[i][j+1]++,b[i][j+2]++,
    b[i+1][j]++,b[i+1][j+1]++,b[i+1][j+2]++,
    b[i+2][j]++,b[i+2][j+1]++,b[i+2][j+2]++;
    for(int i=0;i<c;i++){
        for(int j=0;j<d;j++)if(a[i][j]=='#') cout<<'#';else cout<<b[i+1][j+1];cout<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll=long long;
using namespace std;
const ll mod=1e9+7;
int main(){
    ll n,k,ans=0;
    cin>>n>>k;
    rep(i,k,n+2)ans=(ans+i*(n-i+1)+1)%mod;
    cout<<ans;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int x=1,C[200001];
    string s,t;
    cin>>s>>t;
    ll S=s.size(),T=t.size();
    vector<int> A[26];
    rep(i,S) A[s[i]-'a'].push_back(i);
    rep(i,T) C[i]=t[i]-'a';
    rep(i,T) if(A[C[i]].size()==0) x=0;
    if(x==0) cout<<-1;
    else{
        rep(i,26) sort(A[i].begin(),A[i].end());
        ll a,b,ans;
        rep(i,T){
            if(i==0) a=A[C[i]][0],ans=a+1;
            else{
                if(A[C[i]][A[C[i]].size()-1]>a) b=*upper_bound(A[C[i]].begin(),A[C[i]].end(),a),ans+=b-a,a=b;
                else b=*A[C[i]].begin(),ans+=b+S-a,a=b;
            }
        }
        cout<<ans;
    }
}

Measured memory_bytes: 1468
# E - Bomber

from collections import Counter

h, w, m = map(int, input().split())
hw = [tuple(map(int, input().split())) for i in range(m)]

ys, xs = zip(*hw)
ymax, = Counter(ys).most_common(1)
xmax, = Counter(xs).most_common(1)

bombed = max(ymax[1], xmax[1])

if bombed < m:
    if ymax[1] > xmax[1]:
        hw2 = [(a, b) for a, b in hw if a != ymax[0]]
        _, xs = zip(*hw2)
        xmax, = Counter(xs).most_common(1)
        bombed += xmax[1]
    else:
        hw2 = [(a, b) for a, b in hw if b != xmax[0]]
        ys, _ = zip(*hw2)
        ymax, = Counter(ys).most_common(1)
        bombed += ymax[1]

print(bombed)


Measured memory_bytes: 243056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<pair<int, int>, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    string s;
    cin >> s;

    bool fwin = (s.length() & 1) ^ (s.front() == s.back());
    cout << (fwin ? "First" : "Second") << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<memory>
#include<vector>
#include<algorithm>
#include<set>

template<typename T> // なお正数であること
std::uint64_t factrization(T target, std::vector<T> &output)
{
        const auto sq_target = static_cast<T>(sqrt(target)); // 切り捨て
        auto tmp = target;

        std::uint64_t ctr = 0;

        for(auto i = decltype(sq_target)(2); i <= sq_target+2; i++)
        {
                bool flag = false;
                while(tmp % i == 0)
                {
                        tmp /= i;
                        flag = true;
                }

                if(flag)
                {
                        // std::cout << "prime: " <<i << std::endl;
                        output.push_back(i);
                        ctr++;
                }
        }
        if(tmp != 1)
        {
                // std::cout << "prime: " << tmp << std::endl;
                output.push_back(tmp);
                ctr++;
        }

        return ctr;
}

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

        std::uint64_t a,b;
        std::cin >> a;
        std::cin >> b;

        const std::uint64_t sq_a = sqrt(a);
        const std::uint64_t sq_b = sqrt(b);

        std::vector<std::uint64_t> a_primes;
        std::vector<std::uint64_t> b_primes;

        a_primes.push_back(1);
        b_primes.push_back(1);

        auto a_ctr = factrization(a, a_primes);
        auto b_ctr = factrization(b, b_primes);

        // std::cout << "primes" << std::endl;
#if 0
        for(auto i : a_primes)
        {
                std::cout << i << std::endl;
        }
#endif

        std::vector<std::uint64_t> result;
        std::set_intersection(a_primes.begin(), a_primes.end(), b_primes.begin(), b_primes.end(), std::inserter(result, result.end()));

        // コーナーケース
        if(a != b)
        {
                if(a % b == 0)
                {
                        result.push_back(b);
                }
                if(b % a == 0)
                {
                        result.push_back(a);
                }
        }

        std::sort(result.begin(), result.end());
        result.erase(std::unique(result.begin(), result.end()), result.end());


#if 0
        std::cout << "anses" << std::endl;
        for(auto i : result)
        {
                std::cout << i << std::endl;
        }
#endif

        std::cout << result.size() << std::endl;
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
const double PI=3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }







int main() {


  cout<<fixed<<setprecision(10);

  ll n,w; cin>>n>>w;

  vvint dp(n+1, vint(w+1, -1));
  dp[0][0] = 0;

  rep(i,n){
    ll a,b; cin>>a>>b;

    rep(j, w){
      if(dp[i][j] < 0) continue;
      chmax(dp[i+1][j], dp[i][j]); // 選ばない
      if(j + a > w) continue;
      chmax(dp[i+1][j+a], dp[i][j] + b);
    }
  }

  cout<<*max_element(ALL(dp[n]))<<endl;

}

//


Measured memory_bytes: 80256
n,m=map(int,input().split())

ship=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    ship[a].append(b)

flag=False
for i in ship[1]:
    if n in ship[i]: flag=True; break

if flag: print("POSSIBLE")
else: print("IMPOSSIBLE")

Measured memory_bytes: 29068
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	int64 ans = nn / 2;
	if(nn % 2 == 0)
	{
		ans--;
	}
	cout << ans << endl;
	return 0;
}

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

const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int,int>> key;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j,b) {
      int c;
      cin >> c;
      --c;
      s |= 1<<c;
    }
    key.emplace_back(s,a);
  }

  vector<int> dp(1<<n, INF);
  dp[0] = 0;
  rep(s,1<<n) {
    rep(i,m) {
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      dp[t] = min(dp[t], cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n,m;
    cin >> n >> m;
    dsu d(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        d.merge(a,b);
    }
    vector<int> s(n);
    int cnt = 0;
    rep(i,n) {
        int l = d.leader(i);
        if(s[l] == 0) {
            s[l]++;
            cnt++;
        }
    }
    cout << cnt - 1 << endl;
    return 0;
}


Measured memory_bytes: 4080
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#define FOR(n)			for(int i = 0; i < n; ++i)
using namespace std;

int main() {
	int n;
	vector<pair<int, int>> v;

	cin >> n;
	v.resize(n);
	FOR(n) {
		cin >> v[i].first;
		v[i].second = i+1;
	}
	sort(v.begin(), v.end());

	FOR(n) {
		cout << v[i].second << " " << flush;
	}
	cout << endl;
	return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  
  for(int i=0;i<s.size();i++){
    string u="";
    for(int j=0;j<s.size();j++){
      u+=s.at((i+j+1)%s.size());
    }
    if(u==t){
      cout << "Yes" << endl;
      break;
    }
    else if(i==s.size()-1){
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
import time
import random
import collections
import bisect  

start = time.time()

def insert(list, n): 
    bisect.insort(list, n)  
    return list

def read_input():
  D = int(input())
  c = list(map(int, input().split()))
  s = [list(map(int, input().split())) for _ in range(D)]
  return D, c, s
D, c, s = read_input()

tests = [int(input()) - 1 for _ in range(D)]
M = int(input())
d = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]

#c = np.array(c)
#s = np.array(s)
#tests = np.argmax(s, axis=1)

def get_dates_for_tests(tests):
  dates_for_tests = [list([-1]) for _ in range(26)]
  for i, t in enumerate(tests):
    dates_for_tests[t].append(i)
  for t in range(26):
    dates_for_tests[t].append(D)
  return dates_for_tests

dates_for_tests = get_dates_for_tests(tests)

def get_score(tests):
  dates_for_tests = get_dates_for_tests(tests)
  score = 0
  d = [0]*26 #np.zeros(26, dtype=np.int64)
  for selected, S in zip(tests, s):
    d = [x+1 for x in d]#d += 1
    d[selected] = 0
    score += S[selected]
    for ct, dt in zip(c,d):
      score -= ct*dt# - (c * d).sum()
  return score

def score_diff(date, test):
  #print(date, test)
  before = tests[date]
  if test == before:
    return 0, None, None
  pos_diff = s[date][test] - s[date][before]
  new_index = bisect.bisect_left(dates_for_tests[test], date, 1)
  new_diff = c[test] * (dates_for_tests[test][new_index] - date) * (date - dates_for_tests[test][new_index-1])

  old_index = bisect.bisect_left(dates_for_tests[before], date, 1)
  #print(c[test], dates_for_tests[test])
  #print(c[before], dates_for_tests[before])
  old_diff = c[before] * (dates_for_tests[before][old_index+1] - date) * (date - dates_for_tests[before][old_index-1])
  
  total_diff = pos_diff + new_diff - old_diff
  #print(test, total_diff, pos_diff, new_diff, -old_diff)
  return total_diff, new_index, old_index

current_score = get_score(tests)
#print(d)
for date, test in d:
  total_diff, new_index, old_index= score_diff(date, test)
  current_score += total_diff
  del dates_for_tests[tests[date]][old_index]
  insert(dates_for_tests[test], date)
  tests[date] = test
  
  print(current_score)

Measured memory_bytes: 102604
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    int cnt=0;
    for(int i=0;i<n-1;i++){
        if(a.at(i)==a.at(i+1)) continue;
        else cnt++;
    }
    cout << cnt+1 << endl;
}

Measured memory_bytes: 384
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_A&lang=jp
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

bool dfs(vector<vector<int>> &A, vector<bool> &U, vector<bool> &S, int c)
{
        if (U[c])
                return true;
        if (S[c])
                return false;
        U[c] = true;
        bool cyc = false;
        for (auto a: A[c]) {
                if (dfs(A, U, S, a)) {
                        cyc = true;
                        break;
                }
        }
        U[c] = false;
        if (!cyc)
                S[c] = true;
        return cyc;
}

int main(int argc, char **argv)
{
        int V, E;
        cin >> V >> E;
        vector<vector<int>> A(V);
        for (int i = 0; i < E; i++) {
                int s, t;
                cin >> s >> t;
                A[s].push_back(t);
        }
        vector<bool> U(V), S(V);
        for (int i = 0; i < V; i++) {
                if (S[i])
                        continue;
                if (dfs(A, U, S, i)) {
                        cout << 1 << endl;
                        return 0;
                }
        }
        cout << 0 << endl;
        return 0;
}

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

int main ()
{
   int N,a,b;
   cin >> N;
   a = N%10;
   b = N/10;
   if(a == 9 || b == 9)
   {
       cout << "Yes" << endl;
   }
   else
    cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    string st; cin >> st;
    if (st[0] == '7' || st[1] == '7' || st[2] == '7') {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 3624
module Main where

import           Data.List
import           Control.Monad

main :: IO ()
main = do
    [h, w] <- (map read . words) <$> getLine :: IO [Int]
    list   <- map (map read . words) <$> (replicateM h) getLine :: IO [[Int]]
    let res1    = (map goRight . enumerate2d) list
    let list2   = (map snd) res1
    let result1 = (concatMap fst) res1
    let res2    = (goRight . map last) list2
    let result2 = fst res2
    let result  = concat [result1, result2]

    putStr
        $ (unlines . (((show . length) result) :) . map
              (unwords . (\((a, b), (c, d)) -> (map show) [a, b, c, d]))
          )
              result

    return ()
goRight
    :: [((Int, Int), Int)] -> ([((Int, Int), (Int, Int))], [((Int, Int), Int)])
goRight list@[_         ] = ([], list)
goRight (     a : b : xs) = if even (snd a)
    then let res = goRight (b : xs) in mapSnd (a :) res
    else
        let res = goRight (mapSnd (+ 1) b : xs)
        in  ((fst a, fst b) : (fst res), mapSnd (subtract 1) a : (snd res))

enumerate :: [a] -> [(Int, a)]
enumerate = zip [1 ..]

enumerate2d :: [[a]] -> [[((Int, Int), a)]]
enumerate2d list =
    (map (\(y, a) -> (map (\(x, b) -> ((y, x), b)) . enumerate) a) . enumerate)
        list

mapTuple f1 f2 (a, b) = (f1 a, f2 b)

mapFst f = mapTuple f id
mapSnd f = mapTuple id f


Measured memory_bytes: 78460
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A,B;
  int ans;
  cin>>A>>B;
  if(A+B>=A-B)
   ans=A+B;
  else
   ans=A-B;
  if(ans>=A*B)
    cout<<ans<<endl;
  else
    cout<<A*B<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <cmath>
typedef long long LL;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main(){
  LL N;
  cin>>N;
  vector<LL> A(N+1);
  vector<LL> B(N);
  vector<LL> beatable(N);
  rep(i,N+1){
    cin >> A[i];
  }
  rep(i,N){
    cin >> B[i];
  }
  
  for(LL n=N;n>0;n--){
    beatable[n-1]=min(B[n-1],A[n]+A[n-1]);
    if(B[n-1]-A[n] > 0){
      A[n-1] -= B[n-1]-A[n];
      A[n-1] = max((LL)0,A[n-1]);
    }
  }
  
  sort(beatable.rbegin(),beatable.rend());
  LL res=0;
  rep(i,N){
    res += beatable[i];
  }
  cout << res;
  
  return 0;
}

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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int gcd(int m,int n){
  if(m == 0 || n == 0) return 0;

  while(m != n){
    if(m > n) m -= n;
    else n -= m;
  }
  return m;
}

main(){
  int a,b,c; cin >> a >> b >> c;
  if(c % gcd(a,b) == 0) cout << "YES";
  else cout << "NO";
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int holiday(int** task,int** dp,int i,int d,int n)
{
  if(i==n)
    return 0;
  int j,max=0;
  for(j=0;j<3;j++)
  {
    if(j==d)
      continue;
    if(dp[i][j]==-1)
      dp[i][j]=holiday(task,dp,i+1,j,n)+task[i][j];
    if(dp[i][j]>max)
      max=dp[i][j];
  }
  return max;
}
int main(void)
{
  int n;
  cin>>n;
  int** task=new int*[n];
  int** dp=new int*[n];
  int i,j;
  for(i=0;i<n;i++)
  {
    task[i]=new int[3];
    dp[i]=new int[3];
    for(j=0;j<3;j++)
    {
      cin>>task[i][j];
      dp[i][j]=-1;
    }
  }
  int happ=holiday(task,dp,0,-1,n);
  cout<<happ;
  return 0;
}


Measured memory_bytes: 17408
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.19 00:48:48
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n,k;cin >> n >> k;
    typedef pair<int,int> T;
    priority_queue<T> pq1;
    priority_queue<T,vector<T>,greater<T>> pq2;
    for (int i = 0; i < n; i++) {
        int t,d;cin >> t >> d;
        t--;
        pq1.push(make_pair(d,t));
    }
    ll sum = 0;
    ll kind_cnt = 0;
    vector<bool> kind(n,false);
    for (int i = 0; i < k; i++) {
        auto p = pq1.top(); pq1.pop();
        sum += p.first;
        if (!kind[p.second]) {
            kind[p.second] = true;
            kind_cnt++;
        }
        else {
            pq2.push(p);
        }
    }
    ll ans = kind_cnt * kind_cnt + sum;
    while(!pq2.empty()) {
        auto p = pq2.top(); pq2.pop();
        sum -= p.first;
        while(!pq1.empty() && kind[pq1.top().second]) {
            pq1.pop();
        }
        if (pq1.empty()) break;
        p = pq1.top(); pq1.pop();
        kind[p.second] = true;
        kind_cnt++;
        sum += p.first;
        ans = max(ans,kind_cnt * kind_cnt + sum);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;

const int N = 1e5 + 10, INF = 0x3f3f3f3f , MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}

map<ll,ll> m;

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    init();
    int n; cin>>n;
    ll res = 0;
    m[0] = 1;
    ll pre = 0;
    for (int i = 0; i < n; i++) {
        ll x; cin>>x;
        pre += x;
        res += m[pre];
        m[pre]++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 12800
function Main(input) {
  var inputs = input.split(" ");
  var h1 = parseInt(inputs[0], 10);
  var m1 = parseInt(inputs[1], 10);
  var h2 = parseInt(inputs[2], 10);
  var m2 = parseInt(inputs[3], 10);
  var k = parseInt(inputs[4], 10);
  
  var minute1 = h1 * 60 + m1;
  var minute2 = h2 * 60 + m2;
  
  var difference = minute2 - minute1;
  console.log(difference - k);
}  
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29640
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>

using namespace std;

//ユークリッドの互除法
int gcd(int A, int B){
    int temp = 0;
    if(B > A){
        temp = A;
        A = B;
        B = temp;
    }
    if(A % B == 0){
        return B;
    }else{
        return gcd(B , A % B);
    }
}

//int moreGcd

int main(){

    int N = 0;
    cin >> N;

    vector<int> A(N, 0);

    int temp = 0;

    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    std::sort(A.begin(),A.end());

    if(N == 2){
        cout << gcd(A[0], A[1]);
    }else{
        for(int i = N - 1; i > 0; i--){
            //cout << i - 1;
            if(i == N - 1){
                temp = gcd(A[i], A[i - 1]);
            }else{
                temp = gcd(A[i - 1], temp);
            }
            //std::cout << temp << std::endl;
        }
        cout << temp;
    }

}

Measured memory_bytes: 640
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.20 03:02:29
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

constexpr int MOD = 1e9 + 7;
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((MOD+x)%MOD) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= MOD;
        }
        this->x = z;
    }
    mint& operator+=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint& operator/=(const mint &a) {
        long long n = MOD - 2;
        mint u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};
int main() {
    int n,m;cin >> n >> m;
    vector<int> s(n),t(m);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int j = 0; j < m; j++) {
        cin >> t[j];
    }
    
    vector<vector<mint>> dp(n+1,vector<mint>(m+1,0));
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 1;
    }
    for (int i = 0; i <= m; i++) {
        dp[0][i] = 1;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] += dp[i][j];
            }
        }
    }
    //cout << dp << endl;
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 34616
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll n,m,k;
char a[6][6];
bool check(ll r,ll c)
{
  ll cont=0;
  for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
    {
      if(r&(1<<i) || c&(1<<j))
        continue;
      else
        if(a[i][j]=='#')
          cont++;
    }
  if(cont==k)
    return true;
  else
    return false;
}
int main()
{
  
  cin>>n>>m>>k;
  for(ll i=0;i<n;i++)
  {
    for(ll j=0;j<m;j++)
    {
      cin>>a[i][j];
    }
  }
  ll ans=0;
  for(ll i=0;i<(1<<n);i++)
  {
    for(ll j=0;j<(1<<m);j++)
    {
      if(check(i,j))
        ans++;
    }
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur!=nil && key!=cur->key){
    cur =cur->next;
  }
  if(cur == nil) return NULL;
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if( t == nil) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t;
  t = listSearch(key);
  if(t != NULL){
  deleteNode(t);
  }
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i=0;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  while(1){
    i++;
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
    if(i==n)break;
  }

  printList();
  return 0;
}

Measured memory_bytes: 31660
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i32,
    m: i32,
  }

  puts!("{}\n", n * (n-1) / 2 + m * (m-1) / 2);
}


Measured memory_bytes: 4352
lect = 0
dia = 0
while True:
    try:
        a, b, c = map(int, raw_input().split(","))
        if a == b:
            dia += 1
        elif c**2 - a**2 - b**2 == 0:
            lect += 1
    except:
        break

print lect
print dia

Measured memory_bytes: 4204
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector <pair <int, pair <int, int> > > yp(M);
  for (int i = 0; i < M; i++) {
	  int p, y;
	  cin >> p >> y;
	  yp[i] = make_pair(y, make_pair(p, i + 1));
	}
  sort(yp.begin(), yp.end());
  vector <int> city(N + 1, 0);
  vector <long long> id(M + 1);
  for (int i = 0; i < M; i++) {
	  int p, c;
	  p = yp[i].second.first;
	  c = yp[i].second.second;
	  city[p]++;
	  id[c] = (long long) p * (long long) 1000000 + city[p];
	}
  for (int i = 1; i <= M; i++) {
	  cout << setfill('0') << right << setw(12) << id[i] << endl;
	}
  return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(void){
    long long N;
    cin >> N;
    vector<long long> a(N);
    vector<long long> resi(N);
    long long sum = 0;
    for(long long i = 0;i < N;i++){
        resi[i] = 0;
    }
    for(long long i = 0;i < N;i++){
        cin >> a[i];
        sum += a[i];
    }
    long long ans = 10000000000;
    long long sunuke = 0;
    long long arai = 0;
    for(long long i = 0;i < N; i++){
        sunuke += a[i];
        arai = sum - sunuke;
        if(i < N - 1){
            ans = min(ans,abs(sunuke - arai));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>
 
#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
void runtime(){cout<<fixed<<setprecision(5)<<1.0*clock()/CLOCKS_PER_SEC<<endl;}

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <class T>void read(vector<T> &a,int n){T x; a.clear();for(int i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}


const double PI=acos(-1.0);

double a,b,h,m;

double c(double a,double b,double ang)
{
    return sqrt(a*a+b*b-2*a*b*cos(ang));
}

int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
    
    cin>>a>>b>>h>>m;
    
    double ang1=2*PI/12*h+2*PI/(12*60)*m;
    double ang2=2*PI/60*m;
    
    cout<<fixed<<setprecision(10)<<c(a,b,abs(ang1-ang2))<<'\n';
}


Measured memory_bytes: 3672
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a, b;
  cin >> a >> b;
  ll k;
  cin >> k;
  for(ll i=0;i<k;i++){
    if(a%2==1)a-=1;
    b += a/2;
    a/=2;
    i++;
    if(i==k)break;
    if(b%2==1)b-=1;
    a += b/2;
    b/=2;
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 3492
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 1e5 + 5 ;
const int mod = 1e9 + 5 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif


void solve()
{
	int n,m;
	cin >> n >> m ;
	mycout << n << " " << m << endl ;
	int a[n], b[n] ;
	pii val[n] ;
	rep(i,n){
		cin >> a[i] >> b[i] ;
		val[i] = {a[i],i} ;
		mycout << val[i].ff << " "  << val[i].ss << endl ;
	}
	sort(val,val+n) ;
	reverse(val,val+n) ;
	stack<int> st ;
	rep(i,n){
		st.push(val[i].ss) ;
	}
	int curr = m, ans = 0 ;
	while(st.size() && curr > 0){
		//cout << st.top() << " " ;
		int tmp = min(curr,b[st.top()]) ;
		ans += tmp*a[st.top()] ;
		st.pop();
		curr -= tmp ;
	}
	cout << ans ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
   // cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define INF 1152921504606846976
i64 N;
i64 A, B, C;
i64 L[8];

i64 dfs(i64 i, i64 a, i64 b, i64 c) {
    if (i == N) {
        if (a == 0 || b == 0 || c == 0) return INF;
        else return abs(A - a) + abs(B - b) + abs(C -c);
    }

    i64 res = INF;
    auto cost = [](i64 a) {
        return (a == 0) ? 0 : 10;
    };
    chmin(res, dfs(i + 1, a, b, c));
    chmin(res, dfs(i + 1, a + L[i], b, c) + cost(a));
    chmin(res, dfs(i + 1, a, b + L[i], c) + cost(b));
    chmin(res, dfs(i + 1, a, b, c + L[i]) + cost(c));
    return res;
}

int main() {
    cin >> N;
    cin >> A >> B >> C;
    REP(i, N) cin >> L[i];

    cout << dfs(0, 0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256