akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
 
int cmp( const void *a, const void *b ){
    return *(int *)b - *(int *)a;
}
 
int main(){
 
    int N, K;
    scanf("%d%d", &N, &K);
 
    int i;
    int H[N];
    for( i = 0; i < N; i++ ){
        scanf("%d", &H[i]);
    }
 
    qsort( H, N, sizeof(H[0]), cmp);
 
    long long int ans=0;
    for( i = K; i < N; i++ ){
        ans += H[i];
    }
 
    printf("%lld\n", ans);
 
    return 0;
} 

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<map>
#include<stack>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// Recieve edge(=(int,int)) as an adj list.
vector<vector<int>> getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);

	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
// 	putv(graph[i]);
	return graph;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
using namespace std;

int main(){
	int N;
	string S;
	cin >> N >> S;
	int x = 0;
	int max = 0;
	rep(i,N)
		if(S[i] == 'I'){
			x++;
			if(x > max) max = x;
		}
		else x--;
	cout << max << endl;

}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 2e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int r, g, b; cin >> r >> g >> b;
    int num = 100 * r + 10 * g + b;
    if(num % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    bool yy = false,mm = false;
    if(s[0] == '0' && s[1] != '0' || s[0] == '1' && s[1] == '0' || s[0] == '1' && s[1] == '1' || s[0] == '1' && s[1] == '2'){
        mm = true;
    }
    if(s[2] == '0' && s[3] != '0' || s[2] == '1' && s[3] == '0' || s[2] == '1' && s[3] == '1' || s[2] == '1' && s[3] == '2'){
        yy = true;
    }
    if(yy && mm) cout << "AMBIGUOUS" << endl;
    else if(!yy && mm) cout << "MMYY" <<endl;
    else if(yy && !mm) cout << "YYMM" << endl;
    else cout << "NA" << endl;
    
    return 0;
}

Measured memory_bytes: 3728
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a, b;
        a = int.Parse(str[0]);
        b = int.Parse(str[1]);
        if (a + b >= 10)
            Console.WriteLine("error");
        else
            Console.WriteLine(a + b);
    }
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define endl "\n"
#define len(x) x.size()
#define gcd(a, b) __gcd(a, b)
#define ste(v) v.begin(), v.end()
#define stea(arr, n) arr, arr+n


void solve(){
    // Solve here
    ll a, b, c, d;
    cin>>a>>b>>c>>d;

    ll ans1 = a*c;
    ll ans2 = a*d;
    ll ans3 = b*c;
    ll ans4 = b*d;

    cout<<max(ans1, max(ans2, max(ans3, ans4)));
}

int32_t main() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
{-# LANGUAGE BangPatterns #-}
import Data.Int
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

solve :: Int -> Int -> V.Vector (Int,Int) -> V.Vector Int64
solve n m edges = V.create $ do
  -- m 番目の島から順番に島同士が「繋がっていく」と考える

  -- j = assocs ! i : i 番目の島の親が j
  -- assocs <- VM.new n
  -- forM_ [0..n-1] $ \i -> VM.write assocs i i
  assocs <- V.thaw $ V.enumFromN 0 n

  -- numberOfElements ! i : i番目の島と同じ連結成分に属する島の個数
  numberOfElements <- VM.replicate n 1

  rank <- VM.replicate n (0 :: Int)

  let getRoot !i xs = do
        !j <- VM.read assocs i
        if i == j
          then forM_ xs (\l -> VM.write assocs l i) >> return i
          else getRoot j (i:xs)

      -- i 番目の島と j 番目の島を繋いで、新たに繋がった組み合わせの個数を返す
      unify !i !j = do
        !i' <- getRoot i []
        !j' <- getRoot j []
        if i' == j'
          then return 0
          else do
          !ri <- VM.read rank i'
          !rj <- VM.read rank j'
          !k <- case compare ri rj of
                  EQ -> do VM.write rank i' (ri + 1)
                           return i'
                  LT -> return j'
                  GT -> return i'
          VM.write assocs i' k
          VM.write assocs j' k
          !n1 <- VM.read numberOfElements i'
          !n2 <- VM.read numberOfElements j'
          VM.write numberOfElements k (n1 + n2)
          return $! n1 * n2
  result <- VM.new m
  VM.write result (m-1) $ fromIntegral n * (fromIntegral n - 1) `quot` 2
  forM_ [m-1,m-2..1] $ \i -> do
    let (a,b) = edges V.! i
    convenience <- unify a b
    prevInconveniences <- VM.read result i
    VM.write result (i-1) (prevInconveniences - convenience)
  return result

readIntPair :: IO (Int, Int)
readIntPair = do
  [a,b] <- BS.words <$> BS.getLine
  case (BS.readInt a, BS.readInt b) of
    (Just (a', _), Just (b', _)) -> return (a',b')

main = do
  (n,m) <- readIntPair
  -- [n,m] <- map (read . BS.unpack) . BS.words <$> BS.getLine -- 2 <= n <= 10^5, 1 <= m <= 10^5
  edges <- V.replicateM m $ do
    (a,b) <- readIntPair
    -- [a,b] <- map (read . BS.unpack) . BS.words <$> BS.getLine
    return (a-1, b-1)
  -- maxIncovenience < n * (n - 1) / 2 < 10^10 (2^32 < 10^10)
  let result = solve n m edges
  V.forM_ result print


Measured memory_bytes: 6908
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define ll long long 
#define sum(a,b) a=a+b


int main() {
ll a,b,c,k;
scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
  if (k % 2 == 0) printf("%lld\n",a-b);
  else printf("%lld\n",b-a);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N;
int pT, pX, pY, T, X, Y;
bool ans = true;
int main(void) {
	cin >> N;
	for (int n = 0; n < N; ++n) {
		cin >> T >> X >> Y;
		int dt = T - pT;
		int dx = abs(X - pX);
		int dy = abs(Y - pY);
		bool no = (dt < (dx + dy)) || ((dt % 2) ^ ((dx + dy) % 2));
		if (no) {
			ans = false;
			break;
		}
		pT = T;
		pX = X;
		pY = Y;
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {

  int a,b;
  cin>>a>>b;

  int d=a/b;
  int r=a%b;
  double f=(1.0*a)/b;

  cout<<d<<" "<<r<<" ";
  printf("%.5lf\n" ,f);

  return 0;
}

Measured memory_bytes: 1240
import java.util.*;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		
		int area =(int)( 0.5f * (a + b) * h);
		
		System.out.println(area);
	}
}

Measured memory_bytes: 20820
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
    	new A().doIt();
    }
    class A{
    	void doIt(){
    		int a[] = new int[3];
    		for(int i = 0;i < 3;i++){
    			a[i] = sc.nextInt();
    		}
    		Arrays.sort(a);
    		if(a[0] == 5 && a[1] == 5 && a[2] == 7){
    			System.out.println("YES");
    		}else{
    			System.out.println("NO");
    		}
    	}
    }
}

Measured memory_bytes: 8788
s = str(input())
o1 = s[::2].count('1')
e1 = s[1::2].count('0')
x = len(s)-(o1+e1) 
o2 = s[::2].count('0')
e2 = s[1::2].count('1')
y = len(s)-(o2+e2)
print(min(x,y))

Measured memory_bytes: 9148
/*
				C++
				encoding: UTF-8
				Last Modified: 19/Oct/2019 07:42:13 PM

				✪ H4WK3yE乡
				Mohd. Farhan Tahir
				Indian Institute Of Information Technology (IIIT), Gwalior
*/

#include <bits/stdc++.h>
#ifdef LOCAL_PROJECT
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		 int                    long long
#define		 ve                     vector
#define		 pb                     push_back
#define		 endl                   "\n"
#define		 ff                     first
#define		 ss                     second
#define		 pii                    pair<int, int>
#define		 len(v)                 (int)v.size()
#define		 all(v)                 v.begin(), v.end()
#define		 reset(a, b)            memset(a, b, sizeof(a));
#define		 fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		 dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on

const int N = 305;
int n, m, l;
int vis[N];
int dist[N][N], c[N][N];
int s, t;

void init () {
	fr (i, 0, N) {
		vis[i] = 0;
		fr (j, 0, N) {
			dist[i][j] = 1e18;
			if (i == j) {
				dist[i][j] = 0;
			}
		}
	}
}

void floyd () {
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (dist[i][j] > dist[i][k] + dist[k][j]) {
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}

	fr (i, 1, n + 1) {
		fr (j, 1, n + 1) {
			if (dist[i][j] <= l) {
				c[i][j] = 1;
			} else {
				c[i][j] = 1e18;
			}
		}
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (c[i][k] < 1e18 and c[k][j] < 1e18) {
					c[i][j] = min (c[i][j], c[i][k] + c[k][j]);
				}
			}
		}
	}
}


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	cin >> n >> m >> l;
	init ();
	fr (i, 0, m) {
		int u, v, c;
		cin >> u >> v >> c;
		dist[u][v] = c;
		dist[v][u] = c;
	}

	floyd ();

	int tc;
	cin >> tc;
	while (tc--) {
		cin >> s >> t;
		if (c[s][t] == 1e18) {
			pr (-1);
			continue;
		}
		pr (c[s][t] - 1);
	}
	return 0;
}


Measured memory_bytes: 2048
var input = function()
{

  return require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
};

var out = function(x)
{
  console.log(x);
  return x;
}

var drawRect = function(H,W)
{
  var rect = "";
  for (var i = 0; i < H; i++)
  {
    rect = rect+drawLine(W);
  }
  out(rect);
  return rect;
}

var drawLine = function(W)
{
  var line = "";
  for(i=0;i<W;i++)
  {
    line = line+'#';
  }
  line = line+'\n';
  return line;
}

var calc = function(x)
{
for (var i = 0; i < x.length; i++) {
  var HW = x[i].split(' ').map(Number);
  if(HW[0]==0 && HW[1] ==0)return;
  drawRect(HW[0],HW[1]);
}
return x;
};

calc(input());

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

int N;
string S;


bool check(int a,int b,int c){
	int now = 0;
	int arr[3] = {a,b,c};
	for(int i = 0; i < N; i++){
		if(now == 3){
			return true;
		}
		if(S[i] == (char)('0'+ arr[now])){
			now++;
		}
	}
	return now == 3;
}

int main(){
	cin >> N >> S;
	int ans = 0;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			for(int k = 0; k < 10; k++){
				if(check(i,j,k)){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from heapq import *

readline = sys.stdin.readline
N, M = map(int, readline().split())
days = [[] for _ in range(M)]
for _ in range(N):
    a, b = map(int, readline().split())
    if a <= M:
        days[a-1].append(b)
ans = 0
hq = []
heapify(hq)
for day in days:
    for pay in day:
        heappush(hq, -pay)
    if hq:
        ans += -heappop(hq)
print(ans)


Measured memory_bytes: 18412
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 1e6 + 100;
int a[MAXN], n, sol;

int main()
{
	int k;
	scanf("%d",&k);

	int ost = 0;

	for (int i = 1; i<= 2000000;i++)
	{
		int new_ost = ost * 10 + 7;
		new_ost %= k;

		if (new_ost == 0){
			printf("%d\n",i);
			return 0;
		}
		ost = new_ost;
	}

	printf("%d\n",-1);

	return 0;
}

Measured memory_bytes: 3824
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a == 1 || b == 1) {
        if(a == 2 || b == 2) {
            cout << 3;
        } else {
            cout << 2;
        }
        
    } else {
        cout << 1;
    }

    return 0;
}


Measured memory_bytes: 256
# Problem - Count ABC

# input
N = int(input())
S = list(input())

# initialization
abc_count = 0

# abc count
for i in range(1, N-1):
    if S[i]=='B' and S[i-1]=='A' and S[i+1]=='C':
        abc_count += 1

# output
print(abc_count)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back

using namespace std;

//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        lli n,k=1000,s=0;
        cin>>n;
        vector<lli> a(n);
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        bool l=0;
        for(i=0;i<n-1;i++)
        {
            if(l==0)
            {
                if(a[i+1]>a[i])
                {
                    s=(k/a[i]);
                    k-=(s*a[i]);
                    l=1;
                }
            }
            else
            {
                if(a[i+1]<a[i])
                {
                    k+=(s*a[i]);
                    s=0;
                    l=0;
                }
            }
        }
        k+=(s*a[n-1]);
        cout<<k<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
#include<math.h>
#define ll long long 

ll dp[100010];

ll min(ll a, ll b)
{
        return (a>b)?b:a;
}

int main()
{
        ll n, k, i, j;
        scanf("%lld %lld", &n, &k);
        ll a[n+1];
        for(i = 0; i < n; i++)
        {
                scanf("%lld", a+1+i);
        }
        ll cost, mini= (ll) 1e10;

        dp[0]= dp[1] = 0;
        dp[2] = abs(a[2]-a[1]);

        for(i = 3; i <= n; i++)
        {
                mini = (ll) 1e10;
                for(j = 1; j <= k; j++)
                {
                        if(i-j >= 1)
                                mini = min(mini, dp[i-j] + abs(a[i]-a[i-j]));
                }
                dp[i] = mini;
        }
        printf("%lld\n", dp[n]);
        return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    vector<int> t(n);
    vector<int> x(n);
    vector<int> y(n);

    for (int i = 0; i < n; ++i) {
        cin >> t[i] >> x[i] >> y[i];
    }

    bool ans = true;

    if (t[0] != x[0] + y[0]) {
        ans = false;
    }

    for (int i = 1; i < n; ++i) {
        if ((t[i] - t[i-1]) < (abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]))) {
            ans = false;
            break;
        }

        if((t[i] - t[i-1]) - (abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])) % 2 == 1) {
            ans = false;
            break;
        }
    }

    if (ans) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
    long long n, l, r, ans = 0; 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        ans += r-l+1;
    }

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

Measured memory_bytes: 3576
from collections import deque
n,m=map(int,input().split())
G=[[] for i in range(n+1)]# 隣接リスト

for i in range(m):# 隣接リストを格納
    a,b=map(int,input().split())
    templ=G[a]
    templ.append(b)
    G[a]=templ
    templ=G[b]
    templ.append(a)
    G[b]=templ


dist=[-1 for i in range(n+1)]
prev=[-1 for i in range(n+1)]
q=deque([1])
dist[1]=0

while len(q)!=0:
    v=q.popleft()
    for nv in G[v]:
        if dist[nv]!=-1:
            continue
        dist[nv]=dist[v]+1
        prev[nv]=v
        q.append(nv)
print('Yes')
for i in range(2,n+1):
    print(prev[i])



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

int main(){
    int N;
    cin >> N;
    
    int l[N], r[N];
    int ans = 0;
    
    for(int i = 0; i < N; i++){
        cin >> l[i] >> r[i];
        ans += r[i] - l[i] + 1;
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<iostream>

#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
using namespace std;

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 pair<int, int> pii;



int main() {
	
	int k,x;
	

	cin >> k>>x;
	
	

	for (int i = 1; i <= 2 * k - 1; i++) {
		cout << x - k+i << endl;
	}
	
	



	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(n);i++)
#define PI 3.1415926535897932384626433832795028841971693993
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    long double a,b,h,m;
    cin>>a>>b>>h>>m;
    long double ang=2*PI*(h/12.0+m/12.0/60.0-m/60.0);
    long double ans=(a*a+b*b)-(2*a*b*cosl(ang));
    ans=sqrtl(ans);
    printf("%20.20Lf",ans);
}

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

struct sushi{
    int t;
    int d;
};

int compare(const void *e1, const void *e2){
    struct sushi *s1 = (struct sushi *)e1;
    struct sushi *s2 = (struct sushi *)e2;
    return s2->d - s1->d;
}

bool new_neta(int a, int t[]){
    if(t[a] == 0){
        t[a] = 1;
        return true;
    }
    return false;
}


int main() {
    int N, K;
    cin >> N >> K;
    sushi S[N];
    for(int n = 0; n < N; n++){
        cin >> S[n].t >> S[n].d;
    }

    int t[N + 1];
    for(int n = 0; n < N + 1; n++) {
        t[n] = 0;
    }    
    
    qsort(S, N, sizeof(struct sushi), compare);

    int neta[K];
    //おいしさの高い順で満足度を計算
    long bp = 0;
    long x = 0;
    for(int n = 0; n < K; n++){
        if(new_neta(S[n].t, t)){
            neta[n] = 1;
            x++;
        } else{
            neta[n] = 0;
        }
        bp += S[n].d;
    }
    long point = bp + x * x;

    //ネタの数を増やしていく
    int px = K;
    for(int n = K; n < N; n++){
        if(x == K)
            break;
        if(new_neta(S[n].t, t)){
            while(true){
                if(neta[--px] == 0)
                    break;
            }
            
            bp += S[n].d - S[px].d;
            ++x;
            long newpoint = bp + x*x;
            if(newpoint > point)
                point = newpoint;
        }
    }
    cout << point << endl;
}

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
//1 41  41 
int main() {
    int n;
    cin >> n;
    int one = 0, two = 0, four = 0;
    rep(i,n) {
        int a;
        cin >> a;
        if(a%4==0) four++;
        else if(a%2==0) two++;
        else one++;
    }
    if(!one) cout << "Yes" << endl;
    else {
        four -= one-1;
        if(two) four--;
        if(four >= 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const 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 ALL(v) (v).begin(), (v).end()

ll ans = IINF;

void rec(ll x2, ll x1, ll y2, ll y1, ll cnt){
    if(cnt > ans)return;
    if(x2+x1 >= y2*2+y1){
        ans = min(ans, cnt);
        return;
    }
    ll x = x2+x1;
    rec(y2-max(0LL,x-y1+1)/2,max(0LL,y1-x)+max(0LL,x-y1)%2,x2,x1,cnt+1); // 体力1を優先的に倒す
    rec(max(0LL,y2-x),y1+min(x,y2)-max(0LL,x-y2),x2,x1,cnt+1);  // 体力2を優先的に倒す
}

int main() {
    ll n, m;
    cin >> n >> m;
    rec(n,0,m,0,0);
    cout << ans << endl;
    return 0;
}



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

#define rep(i, u) for (int i = 0; i < u; i++)

using ll = long long;
using ull = unsigned long long;

int main() {
  int n, x;
  while (true) {
    cin >> n >> x;
    if (n == 0 && x == 0) break;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x) ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3056
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let dfs vs n =
  let d = Array.make n (-1) in
  let rec doit i j =
    d.(i) <- j;
    List.iter (fun v -> if d.(v) = (-1) then doit v j) vs.(i) in
  Array.iteri (fun i e -> if e = (-1) then doit i i) d;
  d

let () =
  let read_ints () = read_line () |> split_on_char ' ' |>  List.map int_of_string in
  let (n, m) = match read_ints () with
    | [n; m] -> (n, m)
    | _ -> assert false in
  let vs = Array.make n [] in
  for _ = 0 to m - 1 do
    match read_ints () with
    | [s; t] ->
      vs.(s) <- t :: vs.(s);
      vs.(t) <- s :: vs.(t);
    | _ -> assert false
  done;
  let d = dfs vs n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    match read_ints () with
    | [s; t] -> Printf.printf (if d.(s) = d.(t) then "yes\n" else "no\n")
    | _ -> assert false
  done

Measured memory_bytes: 19136
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 303, M = 998244353;

int dp[N][N][N];

void add(int &a, int b) {
	a += b;
	if(a >= M) a -= M;
}

signed main()
{
	IO_OP;
	
	string s;
	int k;
	cin >> s >> k;
	k = min(k, (int)s.size());
	vi v;
	int cnt = 0;
	for(char c:s) {
		if(c == '0') {
			v.PB(cnt);
			cnt = 0;
		} else {
			cnt++;
		}
	}
	v.PB(cnt);
	for(int i = 0; i < v.size(); i++) {
		for(int j = 0; j <= k; j++) {
			for(int l = 0; l + j <= k; l++) {
				if(i == 0) {
					if(j == 0) dp[i][j][l] = 1;
				} else {
					// take
					for(int take = 0; take <= v[i] && take <= j; take++) {
						add(dp[i][j][l], dp[i-1][j-take][l + take]);
					}					
					// put
					for(int put = 1; put <= l; put++) {
						add(dp[i][j][l], dp[i-1][j][l - put]);
					}
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0; i <= k; i++)
		add(ans, dp[v.size() - 1][i][0]);
	cout << ans << endl;
}





Measured memory_bytes: 57280
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll d;cin>>d;
    vector<ll>c(26);
    rep(i,26)cin>>c[i];
    vector<vector<ll> >s(d,vector<ll>(26));
    rep(i,d){
        rep(j,26)cin>>s[i][j];
    }
    vector<ll>last(26);
    vector<ll>v(d);
    ll ans=0;
    vector<ll>q(d);
    rep(i,d){
        cin>>q[i];
        q[i]--;
    }
    rep(i,d){
        ll t=q[i];
        ans+=s[i][t];
        last[t]=i+1;
        rep(j,26){
            ans-=c[j]*(i-last[j]+1);
        }
        v[i]=ans;
    }
    ll m;cin>>m;
    while(m){
        m--;
        ll a,b;cin>>a>>b;
        a--;b--;
        ll cnt=0;
        vector<ll>la(26);
        rep(i,d){
            ll t=q[i];
            if(a==i)t=b;
            cnt+=s[i][t];
            la[t]=i+1;
            rep(j,26){
                cnt-=c[j]*(i-la[j]+1);
            }
        }
        q[a]=b;
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int A,B,C,D,E,F; cin >>A >>B >>C >>D >>E >>F;
  // 水は100A or 100B
  // 砂糖はC or D
  // 水100g に E g 溶ける
  // 砂糖は溶け残らせてはいけない
  // 水と砂糖の合計が F を超えてはいけない
  // 最大の濃度となる水と砂糖の質量を求めよ

  // 全探索する
  pair<int,int> res = {100*A, 0}; // 水、砂糖
  // ありうる水の量はこんな感じ
  for (int a=0; a<=(F / (100*A)); a++){
    for (int b=0; b<=(F / (100*B)); b++){
      int water = a * 100 * A + b * 100 * B;
      if (water > F) continue;
      if (water == 0) continue;
      int sugarmax = min(F-water, water/100*E);
      for (int c=0; c<=sugarmax/C; c++){
        for (int d=0; d<=sugarmax/D; d++){
          int sugar = c*C + d*D;
          if (sugar > sugarmax) continue;
          if (sugar == 0) continue;
          // (水、砂糖) = (water, sugar)
          // 暫定首位は(res.first, res.second)なのでこれと比較する
          // 砂糖 / 水 の値が大きい方を採用する
          // 但しdoubleで計算
          double buf = (double)sugar / (double)water;
          double bur = (double)res.second / (double)res.first;
          if (buf > bur){
            res = {water, sugar};
          }
        }
      }
    }
  }
  // 水、佐藤 から 砂糖水、砂糖 に変換してから
  res.first = res.first + res.second;
  cout <<res.first <<" " <<res.second <<endl;
}


Measured memory_bytes: 256
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
    double d, t, s;

    cin >> d >> t >> s;

    if (d / s <= t) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  int n; cin >> n;
  int a[n]; rep(i, n) cin >> a[i];
  int ans = 0;
  for(int i = 0; i < n; i++){
    int selectMin = i;
    for(int j = i+1; j<n; j++){
      if(a[j] < a[selectMin]) selectMin = j;
    }
    swap(a[selectMin], a[i]);
    if(selectMin != i) ans++;
  }
  rep(i, n-1) cout << a[i] << " ";
  cout << a[n-1] << "\n"; 
  cout << ans << "\n";
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std; 

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

    v_ll x(n); 
    irep(i, n) {
        cin >> x[i];
    }

    ll dp[n+1][n+1][n*a+100];

    irep(i, n+1) {
        irep(j, n+1) {
            lrep2(k, 0, n*a) {
                dp[i][j][k] = 0;
            }
        }
    }
    dp[0][0][0] = 1;

    irep(i, n) {
        irep(j, n) {
            lrep2(k, 0, n*a) {
                dp[i+1][j+1][k+x[i]] += dp[i][j][k];
                dp[i+1][j][k] += dp[i][j][k];
            }
        }
    }
    #if 0
    irep(i, n+1) {
        irep(j, n) {
            irep2(k, 0, n*a) {
                printf("dp[%d,%d,%d],%lu\n", i, j, k ,dp[i][j][k]);
            }
        }
    }
    #endif
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
            ans += dp[n][i][i*a];
    }
    cout << ans << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 53120
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	double a,b,x,y;
	cin >> a >> b >> x >> y;
	cout << fixed << setprecision(20) << sqrt((x - a) * (x - a) + (y - b) * (y - b)) << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    string ans = "APPROVED";
    for(auto& e : a){
        cin >> e;
        if(e % 2 == 0 && (e % 3 != 0 && e % 5 != 0)){
            ans = "DENIED";
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	for( int i = 0; i < n; ++i ) {
		double xa, ya, ra, xb, yb, rb;
		cin >> xa >> ya >> ra >> xb >> yb >> rb;

		double x = xa - xb;
		double y = ya - yb;
		double d = sqrt( x*x + y*y );

		int result = 0;
		if( d <= ra+rb ) {
			result = 1;

			if( d+ra < rb ) { result = -2; }
			if( d+rb < ra ) { result = 2; }
		}

		cout << result << endl;
	}
}



Measured memory_bytes: 3232
require 'date'
if ARGV[0]=="LOCAL_DEV"
  define_method("debug") do |var|
    p var
  end
else
  define_method("debug") do |var|
  end
end

N,K=STDIN.gets.strip.split.map(&:to_i)
D=STDIN.gets.strip.split.map(&:to_i)
n=N
while true
  s=n.to_s
  ok=true
  D.each do |d|
    if s.index(d.to_s)
      ok=false
      break
    end
  end
  if ok
    puts n
    exit
  end
  n+=1
end


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    ll a, b; cin >> a >> b;
    if((a + b) % 2 == 0) cout << (a + b) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;


    return 0;
}


Measured memory_bytes: 3616
# include <bits/stdc++.h>
# include <math.h>
// # define INF 1e9 + 1
using namespace std;

int main(){

  long double A, B, H, M;
  cin >> A >> B >> H >> M;
  long double ang1, ang2;

  ang1 = H * 30 + M / 60 * 30;
  ang2 = M / 60 * 360;

  long double x1, y1, x2, y2;
  x1 = B * cos(ang1/180 * M_PI);
  y1 = B * sin(ang1/180 * M_PI);
  x2 = A * cos(ang2/180 * M_PI);
  y2 = A * sin(ang2/180 * M_PI);

  long double d;
  d = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
  cout << std::setprecision (15) << d << endl;

}


Measured memory_bytes: 4104
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		int tank = Integer.parseInt(st.nextToken());
		ArrayList<Pair>[] g = new ArrayList[n];
		for(int i = 0; i < n; i++) g[i] = new ArrayList<Pair>();
		for(int i = 0; i < m; i++) {
			st = new StringTokenizer(br.readLine());
			int u = Integer.parseInt(st.nextToken())-1;
			int v = Integer.parseInt(st.nextToken())-1;
			int w = Integer.parseInt(st.nextToken());;
			if(w > tank) continue;
			g[u].add(new Pair(v, w));
			g[v].add(new Pair(u, w));
		}
		Pair[][] dist = new Pair[n][n];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				dist[i][j] = new Pair(n+1, 0);
			}
		}
		for(int s = 0; s < n; s++) {
			LinkedList<Pair2> q = new LinkedList<>();
			q.add(new Pair2(s, new Pair(0, tank)));
			dist[s][s] = new Pair(0, tank);
			while(!q.isEmpty()) {
				Pair2 p = q.pollFirst();
				int u = p.k;
				for(Pair pv: g[u]) {
					int ts = p.w.k;
					int curr = p.w.w;
					if(pv.w > curr) {
						ts++; curr = tank - pv.w;
					}
					else {
						curr -= pv.w;
					}
					Pair up = new Pair(ts, curr);
					if(dist[s][pv.k].compareTo(up) > 0) {
						dist[s][pv.k] = up;
						q.add(new Pair2(pv.k, up));
					}
				}
			}
		}
		st = new StringTokenizer(br.readLine());
		int qers = Integer.parseInt(st.nextToken());
		for(int qi = 0; qi < qers; qi++) {
			st = new StringTokenizer(br.readLine());
			int s = Integer.parseInt(st.nextToken())-1;
			int t = Integer.parseInt(st.nextToken())-1;
			if(dist[s][t].k > n) {
				bw.write("-1");
				bw.write("\n");
			}
			else {
				bw.write(""+dist[s][t].k);
				bw.write("\n");
			}
		}
		bw.flush();
		
	}
	static class Pair implements Comparable<Pair>{
		int k, w;
		public Pair(int k, int w) {
			this.k = k; this.w = w;
		}
		@Override
		public int compareTo(Pair p) {
			if(k == p.k) return p.w - w;
			else return k - p.k;
		}
		public String toString() {
			return k+"/"+w;
		}
		
	}
	static class Pair2 implements Comparable<Pair2>{
		int k; Pair w;
		public Pair2(int k, Pair w) {
			this.k = k; this.w = w;
		}
		@Override
		public int compareTo(Pair2 p) {
			return w.compareTo(p.w);
		}
		public String toString() {
			return k+"-("+w.toString()+")";
		}
	}
}


Measured memory_bytes: 347012
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;


namespace AtCoder
{
    class AC
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;


        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();
            int N = int.Parse(Console.ReadLine());
            int H = int.Parse(Console.ReadLine());
            int W = int.Parse(Console.ReadLine());
            Console.WriteLine((N - H + 1) * (N - W + 1));
            //Console.Out.Flush();
        }
       
    }
   public class Scanner
        {
            public int[] SplitReader()
            {
                int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
                return array;
            }
            public long[] SplitReaderL()
            {
                long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
                return array;
            }
        }

   public static class Tool
        {
            static public void Initialize<T>(ref T[] array, T initialvalue)
            {
                for (var i = 0; i < array.Length; i++)
                {
                    array[i] = initialvalue;
                }
            }
            static public long ModuloP(long value, long mod)
            {
                long r = value % mod;

                if (r * mod < 0)
                {
                    r += mod;
                }
                return r;
            }

        }

   struct Pair<T> : IComparable<Pair<T>> where T : IComparable<T>
        {
            public T variable;
            public int index;

            public Pair(T val, int i)
            {
                variable = val;
                index = i;
            }

            public int CompareTo(Pair<T> otherPair)
            {
                return variable.CompareTo(otherPair.variable);
            }

            public int CompareIndex(Pair<T> otherPair)
            {
                return index.CompareTo(otherPair.index);
            }
        }
    


}






Measured memory_bytes: 11092
#include <iostream>

using namespace std;

template<typename T>
class Dice {

private:
   void Init() {
      upId = 0;
      frontId = 1;
      rightId = 2;
   }

public:
   Dice() :
      number{1, 2, 3, 4, 5, 6}
   {
      Init();
   }
   Dice(T (&n)[6]) :
      number{n[0], n[1], n[2], n[3], n[4], n[5]}
   {
      Init();
   }
   virtual ~Dice() {;}

   enum Direction {
      north,
      south,
      east,
      west
   };

   void Roll(Direction direction) {
      switch (direction) {
      case north: {
         int tmp = upId;
         upId = frontId;
         frontId = 5 - tmp;
         break;
      }
      case south: {
         int tmp = frontId;
         frontId = upId;
         upId = 5 - tmp;
         break;
      }
      case east: {
         int tmp = rightId;
         rightId = upId;
         upId = 5 - tmp;
         break;
      }
      case west: {
         int tmp = upId;
         upId = rightId;
         rightId = 5 - tmp;
         break;
      }
      }
   }

   T Print() {
      return number[upId];
   }   

   T Search(T up, T front) {
      int downId = 5 - upId;
      int backId = 5 - frontId;
      int leftId = 5 - rightId;
      
      if (number[frontId] == up) {
         Roll(north);
      } else if (number[rightId] == up) {
         Roll(west);
      } else if (number[downId] == up) {
         Roll(north);
         Roll(north);
      } else if (number[backId] == up) {
         Roll(south);
      } else if (number[leftId] == up) {
         Roll(east);
      }

      downId = 5 - upId;
      backId = 5 - frontId;
      leftId = 5 - rightId;

      if (number[frontId] == front) {
         return number[rightId];
      } else if (number[rightId] == front) {
         return number[backId];
      } else if (number[backId] == front) {
         return number[leftId];
      } else if (number[leftId] == front) {
         return number[frontId];
      }
      return 0;
   }

private:
   T number[6];
   int upId;
   int frontId;
   int rightId;

};

int SearchDice(Dice<int>& dice, int up, int front) {
   if (dice.Print() != up) {
      for (int i = 0; i < 3; ++i) {
         dice.Roll(Dice<int>::north);
         if (dice.Print() == up) {
            break;
         }
      }
      if (dice.Print() != up) {
         dice.Roll(Dice<int>::east);
         if (dice.Print() != up) {
            dice.Roll(Dice<int>::west);
            dice.Roll(Dice<int>::west);
         }
      }
   }
   dice.Roll(Dice<int>::north);
   if (dice.Print() != up) {
      for (int i = 0; i < 3; ++i) {
         dice.Roll(Dice<int>::east);
         if (dice.Print() == up) {
            break;
         }
      }
   }
   dice.Roll(Dice<int>::east);
   return dice.Print();
}

int main() {

   int number[6]{};
   for (int i = 0; i < 6; ++i) {
      cin >> number[i];
   }

   int n{};
   cin >> n;
   while (n--) {
      int up{}, front{};
      cin >> up >> front;
      
      Dice<int> dice(number);
      cout << dice.Search(up, front) << endl;;
   }

   return 0;

}

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

int main() {
    int K, S;
    cin >> K >> S;
    int cnt = 0;

    rep(X, K + 1) {
        rep(Y, K + 1) {
            int Z = S - X - Y;
            if (Z <= K && 0 <= Z) cnt++; 
        }
    }

    cout << cnt << endl;
}

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

#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define repback(i, n, k) for (int i=int(n); i >= (int)(k); --i)

typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n);
	rep(i, n + 1) cin >> a[i];
	rep(i, n) cin >> b[i];
	//Aそれぞれが10^9までなので
	//sum はintに収まらない
	ll ans = 0;
	rep(i, n) {

		//左を全力で倒す
		int left = min(a[i], b[i]);
		ans += left;
		a[i] -= left;
		b[i] -= left;

		//残った戦力で右を全力で倒す
		int right = min(a[i + 1], b[i]);
		ans += right;
		a[i + 1] -= right;
		b[i] -= right;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

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

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", texto);
 
////////////////////////// Solution starts below. //////////////////////////////

/// OBJETIVO:

/// Achar o maior caminho entre dois vertices num DAG usando programação dinâmica

const int N = 1e5+5;
vector<vector<int>> adj(N, vector<int>());
int dist[N], degree[N];

template<typename T> void max_self(T&a, T b){
	a = max(a, b);
}

int main(){

	int n, m;
	scanf("%d %d", &n, &m);
	int x, y;
	for(int i = 0; i < m; i++){
		scanf("%d %d", &x, &y);
		adj[x].pb(y);
		degree[y]++;
	}

	queue<int> to_process;
	for(int i = 1; i <= n; i++){
		if(!degree[i]) to_process.push(i);
	}

	while(!to_process.empty()){
		int v = to_process.front();
		to_process.pop();
		for(int u : adj[v]){
			max_self(dist[u], dist[v]+1);
			degree[u]--;
			if(!degree[u]) to_process.push(u);
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		max_self(ans, dist[i]);
	}
	printf("%d\n", ans);
	
	return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int max1 = -1;
  int max2 = -1;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    a[i] = tmp;
    int tmpMax1 = max1;
    max1 = max(tmp, max1);
    if (tmp == max1) {
      max2 = max(tmpMax1, max2);
    } else {
      max2 = max(tmp, max2);
    }
  }

  rep(i, n) {
    int v = max1;
    if (a[i] == max1) {
      v = max2;
    }
    cout << v << endl;
  }
  return 0;
}


Measured memory_bytes: 2432
#!/usr/bin/env python3
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    x = 0
    a = list(map(int, input().split()))
    for i in range(m):
        x += a[i] * b[i]
    ans += x + c > 0
print(ans)


Measured memory_bytes: 3060