akhauriyash/Code-Regression huggingface dataset:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
m = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500*a + 100*b + 50*c == X:
                m+=1
print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 < m2 || (m1 == 12 && m2 == 1))
    cout << 1 << '\n';
  else
    cout << 0 << '\n';
  return 0;
}


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

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

vi e[120000], cnt(120000), p(120000), cc(120000);
int d[120000][2];
vb vis(120000);
const int mod = 1e9 + 7;

void f(int& x){
    if (x >= mod)
        x %= mod;
}

void init(){
    for (int i = 0; i < 120000; ++i)
        vis[i] = 0;
}

void dfs(int x){
    vis[x] = 1;

    for (auto& i : e[x]){
        if (!vis[i]){
            p[i] = x;
            ++cc[x];
            dfs(i);
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int n;
    cin >> n;

    for (int i = 0; i < n - 1; ++i){
        int u, v;
        cin >> u >> v;

        e[u].push_back(v);
        e[v].push_back(u);
    }

    dfs(1);
    init();

    queue<int> q;
    for (int i = 1; i <= n; ++i){
        if (!cc[i]){
            q.push(i);
            vis[i] = 1;
        }
        d[i][0] = d[i][1] = 1;
    }

    while (!q.empty()){
        int c = q.front();
        q.pop();

        for (auto& i : e[c]){
            if (i == p[c]){
                d[i][0] *= (d[c][0] + d[c][1]);
                f(d[i][0]);
                d[i][1] *= d[c][0];
                f(d[i][1]);
                ++cnt[i];

                if (cc[i] == cnt[i]){
                    q.push(i);
                    vis[i] = 1;
                }
            }
        }
    }

    int sol = d[1][0] + d[1][1];
    f(sol);
    cout << sol << '\n';
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;




int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int w, h, x, y;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> w >> h >> x >> y;

    int ans = 0;
    if(2 * x == w && 2 * y == h) {
        ans = 1;
    }

    cout << fixed << setprecision(20) << 0.5 * h * w << " ";
    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii; 
const int maxn = 1000 + 10;
int n, m;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {-1, 0, 1, 0};
queue<pii> Q;
char s[maxn][maxn];
int vis[maxn][maxn], ans;
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
		{
			vis[i][j] = -1;
			if(s[i][j] == '#')
			{ 
				vis[i][j] = 0; 
				Q.push(mp(i, j));
			}
		}
	while(!Q.empty())
	{
		pii x = Q.front(); Q.pop();
		ans = max(ans, vis[x.first][x.second]);
		for(int i = 0; i < 4; ++i)
			if(vis[x.first + dx[i]][x.second + dy[i]] == -1)
			{
				vis[x.first + dx[i]][x.second + dy[i]] = ans + 1;
				Q.push(mp(x.first + dx[i], x.second + dy[i]));
			}
	}
	printf("%d\n", ans);
	return 0;
}
	


Measured memory_bytes: 13456
n = int(input())
p = list(map(int,input().split()))

max = 0
pre = -1
cur = 0
hop = 0
for i in range(n):
    cur = p[i]

    if cur <= pre:
        hop += 1
        if hop > max:
            max = hop
    else:
        hop = 0
    pre = cur

print(max)

Measured memory_bytes: 14252
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long n, m, x;
    scan(n, m, x);
    auto 参考書の値段とアルゴリズム = new long[][](n);
    // writeln(tmp);
    foreach (i; 0 .. n)
    {
        参考書の値段とアルゴリズム[i] = aryread();
    }

    long func(long state)
    {
        auto アルゴリズムの合計 = new long[](m);
        long 合計金額;
        foreach (i; 0 .. n)
        {
            if ((state & (1 << i)) != 0)
            {
                合計金額 += 参考書の値段とアルゴリズム[i][0];
                foreach (j; 1 .. m + 1)
                {
                    アルゴリズムの合計[j - 1] += 参考書の値段とアルゴリズム[i][j];
                }
            }
        }
        foreach (k; 0 .. m)
        {
            if (アルゴリズムの合計[k] >= x)
            {
                continue;
            }
            else
            {
                return long.max;
            }
        }
        return 合計金額;
    }

    long ans = long.max;
    foreach (state; 0 .. 1 << n)
    {
        ans = min(func(state), ans);
    }
    if (ans == long.max)
    {
        writeln(-1);
        return;
    }
    writeln(ans);

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3920
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int plen;
  while(cin >> plen, plen) {
    int cnum, width, cspace;
    cin >> cnum >> width >> cspace;
    vector<string> res(plen);
    string str;
    int cnt = 0;
    cin.ignore();
    while(getline(cin,str), str!="?") {
      int pos = 0;
      while(pos == 0 && str.size() == 0 || pos < str.size()) {
        if (cnt >= plen) {
          res[cnt%plen] += string(cspace, '.');
        }
        string tmp = str.substr(pos, width);
        res[cnt%plen] += tmp + string(width-tmp.size(), '.');
        cnt++;
        pos += width;
        if (cnt >= plen * cnum) {
          REP(i,plen) {
            cout << res[i] << endl;
          }
          cout << "#" << endl;
          res = vector<string>(plen);
          cnt = 0;
        }
      }
    }
    if (cnt) {
      while(cnt < plen * cnum) {
        if (cnt >= plen) {
          res[cnt%plen] += string(cspace, '.');
        }
        res[cnt%plen] += string(width, '.');
        cnt++;
      }
      REP(i,plen)
        cout << res[i] << endl;
      cout << "#" << endl;
    }
    cout << "?" << endl;
  }
}

Measured memory_bytes: 0
N = int(input())
d = {}

for i in range(N):
	S, P = [x for x in input().split()]
	P = int(P)
	
	if S in d.keys():
		d[S].append([P, i])
	else:
		d[S] = [[P, i]]

keys = sorted(list(d.keys()))

for key in keys:
	values = sorted(d[key])
	values.reverse()
	for val in values:
		print(val[1]+1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    stack<char> st;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='('||st.empty())
        {
            st.push(s[i]);
        }
        else if(s[i]==')'&&st.top()=='(')
        {
            st.pop();
        }
        else
        {
            st.push(s[i]);
        }
        
    }
    int cback=0,cfront=0;
    while(st.empty()!=1)
    {
        if(st.top()==')')
        {
            cback++;st.pop();
        }
        else if(st.top()='(')
        {
            cfront++;st.pop();
        }
    }
    for(int t=0;t<cback;t++)
    cout<<'(';
    cout<<s;
    for(int k=0;k<cfront;k++)
    cout<<')';
    cout<<endl;
    return 0;
}

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

int main(){
    int K;cin>>K;
    string s="ACL";
    rep(i,K){
        cout<<s;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  vector<string> s(3);
  vector<int> a(3,0);
  rep(i,3) cin >> s[i];
  int u=0;
  while(true){
      if (a[u]==s[u].size()) break;
      a[u]++;
      u=s[u][a[u]-1]-'a';
  }
  char ans='A'+u;
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h1 = sc.nextInt();
        int m1 = sc.nextInt();
        int h2 = sc.nextInt();
        int m2 = sc.nextInt();
        int k = sc.nextInt();
        int ans = 0;
        if(m1 < m2){
            ans += m2 - m1 + (h2-h1)*60 -k;
        }else{
            ans += m2 + (60-m1) + (h2-h1-1)*60 -k;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
using i64 = long long;

struct S {
    int x, w, i;
    S(int x, int w, int i) : x(x), w(w), i(i) {}
};

int main() {
    i64 n, l, t;
    std::cin >> n >> l >> t;
    std::vector<S> vs;
    i64 cnt[] { 0, 0, 0 };
    for (int i = 0; i < n; i++) {
        int x, w;
        std::cin >> x >> w;
        vs.emplace_back(x, w, i);
        cnt[w]++;
    }

    const auto f = vs.front();
    i64 bump = t / l * 2 * (f.w == 1 ? cnt[2] : cnt[1]),
        rem = t % l;
    for (int i = 1; i < n; i++) {
        if (f.w == vs[i].w) continue;
        auto dist = f.w == 1 ? vs[i].x - f.x : f.x + l - vs[i].x;
        if (dist < rem * 2 || (f.w == 2 && dist == rem * 2)) bump++;
        if (dist + l < rem * 2 || (f.w == 2 && dist + l == rem * 2)) bump++;
    }

    auto s = f.w == 1 ? bump % n : (n - bump % n) % n;
    std::vector<int> pos;
    for (const auto &e : vs) {
        if (e.w == 1) pos.push_back((e.x + rem) % l);
        else pos.push_back((e.x - rem + l) % l);
    }
    int sp = pos.front();
    std::sort(pos.begin(), pos.end());

    auto m = std::lower_bound(pos.begin(), pos.end(), sp) - pos.begin();
    std::vector<int> ret(n);
    for (int j = 0; j < n; j++) {
        ret[vs[(j + s) % n].i] = pos[(j + m) % n];
    }

    for (auto e : ret) std::cout << e << std::endl;

    return 0;
}


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main()
{
    int h,w;
    int bh,bw;
    cin >> h >> w;
    cin >> bh >> bw;
    h = h - bh;
    w = w - bw;
    if(h == 0 || h < 0)
    {
        h = 1;
    }

    cout << h*w << endl;
}

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

int N, M;
int H[114514];

int ec[114514];
int* es[114514];

void ae(int f, int t) {
	es[f] = realloc(es[f], sizeof(*es[f]) * (ec[f] + 1));
	if (es[f] == NULL) exit(2);
	es[f][ec[f]++] = t;
}

int main(void) {
	int i, j;
	int count = 0;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &H[i]) != 1) return 1;
	}
	for (i = 0; i < M; i++) {
		int A, B;
		if (scanf("%d%d", &A, &B) != 2) return 1;
		ae(A, B);
		ae(B, A);
	}
	for (i = 1; i <= N; i++) {
		int yes = 1;
		for (j = 0; j < ec[i]; j++) {
			if (H[i] <= H[es[i][j]]) yes = 0;
		}
		if (yes) count++;
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 6012
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a[]=new int[8];
		int b[]=new int[4];
		for(int i=0;i<4;i++){
			int se =stdIn.nextInt();
			int mai=stdIn.nextInt();
			switch(se){
			case 1:
				a[i]=mai*6000;
			break;
			case 2:
				a[i]=mai*4000;
			break;
			case 3:
				a[i]=mai*3000;
			break;
			case 4:
				a[i]=mai*2000;
			break;
			}
		}for(int i=0;i<4;i++){
			System.out.println(a[i]);
		}
	}
}

Measured memory_bytes: 17180
#include <bits/stdc++.h>
 
#define ll long long
#define Add_Speed ios_base::sync_with_stdio(0);cin.tie(0);
#define ins insert
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define sz size()
#define s second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define inf (int)1e9
#define gcd(a, b) __gcd(a, b)
#define int ll
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

const int maxn = (int)1e5 + 17;
const int maxm = (int)15e2 + 7;
const int minn = (int)1e4 + 7;
const int mod = (int)1e9 + 7;
const long double PI = acos(-1);
const int P = (int)1e5 + 7;

int n, k, a[maxn], dp[maxn];

main () {
 
    Add_Speed

    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    memset(dp, mod, sizeof(dp));
    dp[1] = 0;
    for(int i = 2; i <= n; i++){
        for(int j = max(1ll, i - k); j < i; j++){
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
        }
    }
    cout << dp[n];
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int t;
		cin>>t;
		n-=t;
	}
	if(n<0)
	{
		cout<<"-1";
		return 0;
	}
	cout<<n;
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(void)
{
	int W,H,x,y,r;
	
	cin >> W >> H >> x >> y >> r;

	if(x-r<0 || x+r>W || y-r<0 || y+r>H){
		cout << "No\n";
	}else{
		cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 1128
#include<set>
#include<cstdio>
#include<algorithm>
using namespace std;

#define MAXN 200000
int N;
struct node{
    int val,ID;
}A[MAXN+5];

bool cmp(node x,node y){
    return x.val<y.val;
}

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        A[i].ID=i;
        scanf("%d",&A[i].val);
    }
    sort(A+1,A+N+1,cmp);
    set<int> index;
    index.insert(0),index.insert(N+1);
    long long Ans=0;
    for(int i=1;i<=N;i++){
        set<int>::iterator Left,Right;
        Left=Right=index.upper_bound(A[i].ID),Left--;
        Ans+=1ll*(A[i].ID-*Left)*(*Right-A[i].ID)*A[i].val;
        index.insert(A[i].ID);
    }
    printf("%lld",Ans);
}


Measured memory_bytes: 11136
// I love
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

const int N = 55;

vector<int> adj[N];

int ans = 0;

int id[N], ch[N], cnt = 0;

void dfs(int i, int p) {
  id[i] = ch[i] = ++cnt;
  for (auto &j : adj[i]) {
    if (j == p) continue;
    if (id[j]) ch[i] = min(ch[i], id[j]);
    else {
      dfs(j, i);
      ch[i] = min(ch[i], ch[j]);
      if (id[i] < ch[j]) ans++;
    }
  }
}

void MAIN() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3660
# https://atcoder.jp/contests/abc136/submissions/6708242

def solve():
    n, k = map(int, input().split())
    a = tuple(sorted(map(int, input().split()), reverse=True))

    sum_a = sum(a)
    e = set()
    divisor = 1
    while divisor * divisor <= sum_a:
        if sum_a % divisor == 0:
            e.add(divisor)
            e.add(sum_a // divisor)
        divisor += 1

    e = sorted(e, reverse=True)
    # 約数降順

    for cand in e:
        r = tuple(sorted(x % cand for x in a if x % cand != 0))

        accm = [0]
        t = 0
        for x in r:
            t += x
            accm.append(t)

        accp = [0]
        t = 0
        for x in r:
            t += cand - x
            accp.append(t)

        m = len(r)
        for i in range(m + 1):
            if (accm[i] == (accp[m] - accp[i])) and (accm[i] <= k):
                return cand
    return -1


print(solve())

# 操作で総和は不変


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


string S;


bool solve()
{
    int n = S.size();
    int i, j;
    for (i = 0, j = n-1; i < j; i++, j--)
        if (S[i] != S[j]) return false;
    for (i = 0, j = (n-1)/2-1; i < j; i++, j--)
        if (S[i] != S[j]) return false;
    for (i = (n+3)/2-1, j = n-1; i < j; i++, j--)
        if (S[i] != S[j]) return false;
    return true;
}


int main()
{
    cin >> S;
    if (solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ERemOfSumIsNum {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N, K;
        cin >> N >> K;
        vector<int> A(N);
        REP(i, N) {
            cin >> A[i];
            A[i]--;
        }

        vector<int> sum(N + 1);
        REP(i, N) sum[i + 1] = (A[i] + sum[i]) % K;

        map<int, int> mp;
        int res = 0;
        FOR(i, 0, N) {
            res += mp[sum[i]];
            mp[sum[i]]++;
            if (i - (K - 1) >= 0) {
                mp[sum[i - (K - 1)]]--;
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ERemOfSumIsNum solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 15872
A,B = map(int,input().split())
def operate(i):
    if i == 1:
        i += 13
    return i
A = operate(A)
B = operate(B)
ans = ["Alice","Bob","Draw"]
if A > B:
    ans_index = 0
elif A < B:
    ans_index = 1
elif A == B:
    ans_index = 2
print(ans[ans_index])

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
ll n,k,x[100005],ans=10000000000000,r=-1;
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<n;i++){
        if(x[i]>=0){
            r=i;
            break;
        }
    }
    if(r==-1){
        cout<<-x[n-k]<<endl;
    }else{
        for(int i=0;i<k-1;i++){
            if(r+i>=n||r-(k-i)+1<0)continue;
                int u=r+i,v=r-(k-i)+1;
                ans=min(ans,x[u]-x[v]+min(x[u],-x[v]));
        }
        if(r-k>=0)ans=min(ans,-x[r-k]);
        if(r+k-1<n)ans=min(ans,x[r+k-1]);
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  int x=abs(h*60+m-m*12);
  x=min((720-x)%720,(x+720)%720);
  double f=cos((double)x*pi/360);
  decimal(12);
  out(sqrt(a*a+b*b-2*f*a*b));
  //out(x);
}

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


Measured memory_bytes: 4184
n=int(input())
p=list(map(int,input().split()))
ans = 0
for i in range(n-2):
    if(p[i]>p[i+1] and p[i+1]>p[i+2]):
        ans += 1
    if(p[i]<p[i+1] and p[i+1]<p[i+2]):
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;
vector<int> v[101010],art;
vector <pint> bridge;
int n,m,low[101010],ord[101010];

void addedge(int x,int y){
    v[x].push_back(y);
    v[y].push_back(x);
}

void dfs(int& count,int from,int x){
    ord[x]=count++;
    low[x]=ord[x];
    bool isart=false;
    int cnt=0;
    for(auto to:v[x]){
        if(to==from)continue;
        if(ord[to]==-1){
            cnt++;
            dfs(count,x,to);
            if(ord[x]<low[to])bridge.push_back({min(x,to),max(to,x)});
            if(from!=-1&&ord[x]<=low[to])isart=true;
            low[x]=min(low[x],low[to]);
        }
        else low[x]=min(low[x],ord[to]);
    }
    if(from==-1&&cnt>1)isart=true;
    if(isart)art.push_back(x);
}

void dfs(){
    rep(i,n)ord[i]=-1;
    int count=0;
    dfs(count,-1,0);
}
int main(){
    cin>>n>>m;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        addedge(x, y);
    }
    dfs();
    sort(art.begin(),art.end());
    for(auto x:art)cout<<x<<endl;
   return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

int h, w;
vector<string> s;
int mp[110][110];

bool inside(int y, int x)
{
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        string ss;
        cin >> ss;
        s.push_back(ss);
    }
    m0(mp);
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            mp[i][j] = 1e9 + 7;
        }
    }
    if (s[0][0] == '.')
    {
        mp[0][0] = 0;
    }
    else
    {
        for (int i = 0; i < h; i++)
        {
            if (s[i][0] == '#')
            {
                mp[i][0] = 1;
            }
            else
                break;
        }
        for (int i = 0; i < w; i++)
        {
            if (s[0][i] == '#')
            {
                mp[0][i] = 1;
            }
            else
                break;
        }
    }

    for (int ww = 0; ww < w; ww++)
    {
        for (int hh = 0; hh < h; hh++)
        {
            int nexth = hh + 1;
            if (inside(nexth, ww))
            {
                if (s[hh][ww] == '.' && s[nexth][ww] == '#')
                {
                    mp[nexth][ww] = min(mp[nexth][ww], mp[hh][ww] + 1);
                }
                else
                {
                    mp[nexth][ww] = min(mp[nexth][ww], mp[hh][ww]);
                }
            }
            int nextw = ww + 1;
            if (inside(hh, nextw))
            {
                if (s[hh][ww] == '.' && s[hh][nextw] == '#')
                {
                    mp[hh][nextw] = min(mp[hh][nextw], mp[hh][ww] + 1);
                }
                else
                {
                    mp[hh][nextw] = min(mp[hh][nextw], mp[hh][ww]);
                }
            }
        }
    }
    cout << mp[h - 1][w - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int max(int a ,int b)
{
  if(a>b)
    return a;
  else
    return b;
}

int main()
{
    string s1, s2;
    getline(cin,s1);
    getline(cin,s2);

  	int m = s1.length(), n = s2.length();
  	int L[m+1][n+1];

	for(int i = 0 ; i <= m ; i++)
    {
      for(int j = 0 ; j <= n ; j++)
      {
        if(i == 0 || j == 0)
          L[i][j] = 0 ;
        else if(s1[i-1] == s2[j-1])
          L[i][j] = L[i-1][j-1] + 1;
        else
          L[i][j] = max(L[i-1][j] , L[i][j-1]);
      }
    }
 // cout<<L[m][n]<<endl;
  int index = L[m][n];
  char lcs[index+1];
  lcs[index] = '\0';

   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      if (s1[i-1] == s2[j-1])
      {
          lcs[index-1] = s1[i-1];
          i--; j--; index--;
      }

      else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
   }
   cout<<lcs;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

class doll{
public:

	doll(int a, int b){
		h = a;
		r = b;
	}

	int h;
	int r;

	bool operator<(doll arg){
		if(h < arg.h && r < arg.r){
			return true;
		}else{
			return false;
		}
	}
};

int main(void){
	int n;
	while(cin >> n && n){
		vector<doll> a,b,c;
		int h,r,ret;
		for(int i=0;i<n;i++){
			cin >> h >> r;
			a.push_back(doll(h,r));
		}
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> h >> r;
			b.push_back(doll(h,r));
		}
		vector<doll>::iterator it,jt;
		bool isused[b.size()];
		memset(isused,false,sizeof(isused));
		ret = a.size();
		for(it=a.begin();it!=a.end();++it){
			jt = it;
			++jt;
			for(int pos=0;(unsigned int)pos<b.size();pos++){
				if(isused[pos]) continue;
				if(jt == a.end()){
					if(*it < b[pos]){
						isused[pos] = true;
						ret++;
					}
				}else{
					if(*it < b[pos] && b[pos] < *jt){
						isused[pos] = true;
						ret++;
					}
				}
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
static long gcd (long a, long b){
    a = abs(a); b = abs(b);
    return (b==0) ? a : gcd(b, a%b);
  }
int main() {
    long long int ar[201][201], i, j;
    
    for(i=1;i<=200;i++)
    {
        for(j=1;j<=200;j++)
        {
            ar[i][j]=gcd(i,j);
            // cout<<ar[i][j]<<" ";
        }
    }
    
    long long int n,k, sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                int q=ar[j][k];
                sum+=ar[i][q];
            }
        }
    }
    cout<<sum<<endl;
    
	return 0;
}

Measured memory_bytes: 3952
#include <stdio.h>
#include <stdlib.h>

void bubbleSort(int *,int);
void swap(int*,int*);

int main(){
  int i,n,a,*tmp;

  scanf("%d",&n);

  tmp = (int*)malloc(n*sizeof(int));

  for(i=0;i<n;i++){
    scanf("%d",&tmp[i]);
  }

  bubbleSort(tmp,n);
  
  free(tmp);
  return 0;
  
}

void bubbleSort(int *x,int n){
  int i,j,count=0;
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(x[j] < x[j -1]){
	swap(&x[j],&x[j-1]);
	count++;
	  }
    }
    printf("%d ",x[i]);
  }
  printf("%d\n",x[n-1]);
  printf("%d\n",count);
}

void  swap(int *x, int *y)
{
    int  work;   

    work = *x;   
    *x = *y;     
    *y = work;  
}

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

using namespace std;

#define ll long long
//#define mx 0
#define mn 1e9
#define vec(dt) vector<dt>
#define pr(x, y) pair<x,y>
#define loop(x, n) for(ll x = 0; x < n; x++)
#define in_arr(n) loop(i,n){cin>>a[i];}
#define out_arr(n) loop(i,n){cout<<a[i];}

inline void boost() {
    cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
}

//const int N = 2 * 1e5 + 5;

int main() {
    boost();
    ll n;
    cin>>n;
    string s;
    map<string,int> mp;
    vector<string> v;
    for (ll i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    ll maxx = 0;
    for (auto i = mp.begin();i!=mp.end();i++)
    {
        if (i->second > maxx)
        {
            v.clear();
            maxx = i->second;
            v.push_back(i->first);

        }
        else if (i->second==maxx)
        {
            v.push_back(i->first);
        }
    }
    sort(v.begin(),v.end());
    for (ll i=0;i<v.size();i++)
    {
       cout<<v[i]<<"\n";
    }

}



Measured memory_bytes: 25584
#include <stdio.h>

#define MAX 2000

int m_search(int,int);

int n, array[MAX];

int main(){

  int i, j, q, anser;
  int m_array[MAX];

  scanf("%d", &n);

  for( i=0; i<n; i++){
    scanf("%d", &array[i]);
  }

  scanf("%d", &q);

  for( i=0; i<q; i++){
    scanf("%d", &m_array[i]);
  }

  for( i=0; i<q; i++){
    anser = m_search(0,m_array[i]);

    if( anser == 0 )printf("yes\n");
    else printf("no\n");

  }

  return 0;
}

int m_search(int i, int m){
  int re;

  if( m == 0 ) return 0;

  if( i >= n ) return 1;

  re = m_search(i+1,m);
  if( re == 0 ) return re;

  re = m_search(i+1,m-array[i]);

  return re;
}



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

ll dp[111][101000]={};

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

    ll n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll mod = 1e9+7;
    
    for(int i=0;i<=a[0];i++) dp[1][i] = 1;
    for(int i=2;i<=n;i++){
        for(int j=0;j<=k;j++){
            dp[i][j] += dp[i-1][j];
            if(j) dp[i][j] += dp[i][j-1];
            if(j-a[i-1]>0) dp[i][j] +=mod - dp[i-1][j-a[i-1]-1];
            dp[i][j]%=mod;
        }
    }
    cout << dp[n][k] << endl;
    

    
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    int a = INF, b = -1;
    rep(i, n) {
        int x;
        cin >> x;
        minch(a, x);
        maxch(b, x);
    }
    cout << b - a << endl;
    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> as(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> as[i];
    }
    vector<int> balls(n+1, 0);
    for (int i = n; i >= 1; --i) {
        int current_count = 0;
        for (int j = 2*i; j <= n; j += i) {
            current_count += balls[j];
        }
        current_count %= 2;
        balls[i] = (current_count + as[i]) % 2;
    }
    vector<int> used_balls;
    for (int i = 1; i <= n; ++i) {
        if (balls[i]) {
            used_balls.push_back(i);
        }
    }
    cout << used_balls.size() << endl;
    for (int ball : used_balls) {
        cout << ball << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3192
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)

ans = A.inject(0) {|r,i| r + B[i-1] }
A.each_cons(2) {|i,j| ans += C[i-1] if i + 1 == j }
puts ans


Measured memory_bytes: 3836
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define swap(a,b) do{ll w=a;a=b;b=w;}while(0)
#define swapd(a,b) do{double w=a;a=b;b=w}while(0)
#define in(a) scanf("%lld", &(a))
#define ind(a) scanf("%lf", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a));
//def   puts(a) printf("%s\n", a) 文字はこっち
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll X, Y;
    in(X); in(Y);
    if(X%Y==0) puts("-1");
    else put(X);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート 1,2....9
}


Measured memory_bytes: 128
#include<stdio.h>
int max(int a, int b) {return a>b? a : b;}
int main()
{
    int n, x, t;
    
    t = 0;
    scanf ("%d%d%d", &n, &x, &t);
    
    if (x >= n) //return t;
    {printf("%d", t);return 0;}
    int cnt = 1;
    cnt = (n / x);
    if (n - n/x*x > 0)
    cnt++;//, printf("n = %d\tn/x*x = %d\n", n, n/x*x);
    printf("%d", t * cnt);
}


Measured memory_bytes: 1696
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    int t;
    cin >> t;
    t--;
    a[i] = t;
  }
  vector<bool> used(n);
  int it = 0;
  int ans = 0;
  while(true){
    if(it == 1) {
      cout << ans << endl;
      return 0;
    }
    if(used[it]){
      cout << -1 << endl;
      return 0;
    }
    used[it] = true;
    it = a[it];
    ans++;
  }
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int fib(int n);

int main() {
  int n;

  //入力
  cin >> n;

  //出力
  cout << fib(n) << endl;

  return 0;
}

int fib(int n){
  int dp[1000];
  dp[0] = 1;
  dp[1] = 1;

  for(int i = 2; i <= n; i++){
    dp[i] = dp[i-1] + dp[i-2];
  }
  return dp[n];
}



Measured memory_bytes: 3120
a, b = map(int,input().split())
v = []
for _ in range(b):
    aa,bb = map(int, input().split())
    v.append([aa-1, bb-1])
res = 0
for i in range(b):
    visited = [False] * a
    curv = []
    for j in range(a):
        curv.append([])
    for j in range(b):
        if i == j:
            continue
        else:
            x, y = v[j]
            curv[x].append(y)
            curv[y].append(x)
    import collections
    q = collections.deque([])
    q.append(0)

    while len(q) > 0:
        curnode = q.pop()
        if visited[curnode] is True:
            continue

        visited[curnode] = True
        for j in range(len(curv[curnode])):
            nextnode = curv[curnode][j]
            if visited[nextnode] is False:
                q.append(nextnode)

    isbridge = False
    for j in range(a):
        if visited[j] is False:
            isbridge = True
    if isbridge:
        res += 1

print(res)


Measured memory_bytes: 40688
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;


int main()
{
	int N; cin >> N;
	vec d(N);
	for (int i = 0; i < N; ++i) { cin >> d[i]; }

	sort(d.begin(), d.end());

	cout << d[N / 2] - d[N / 2 - 1] << endl;

	return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;



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

	int n,m;cin>>n>>m;

	if(abs(n-m) >=2){
		writeln(0);
		return 0;
	}


	ll a =1;
	ll b =1;

	for(int i=1; i<=n; i++){
		 a *=i;

		 a %= 1000000007;
	}
	for(int i=1; i<=m; i++){
		 b *=i;

		 b %= 1000000007;
	}
	if(n==m){
	writeln((2*a*b)%1000000007);
	}else {
		writeln((a*b)%1000000007);
	}
}


Measured memory_bytes: 256
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

//DEBUG_OUT("----\n");

struct RecInfo
{
    int s;
    int t;
    int c;
    bool operator<( const RecInfo &right ) const {
        return (s == right.s) ? (t < right.t) : (s < right.s);
    }
};
void func(void)
{
    int N, C;
    cin >> N >> C;
    vector<RecInfo> recInfo(N);

    for(int i=0; i<N; i++){
        int s, t, c;
        cin >> s >> t >> c;
        recInfo[i].s = s;
        recInfo[i].t = t;
        recInfo[i].c = c;
    }

    sort(recInfo.begin(), recInfo.end());
    
    int recMachineCnt = 0;
    while(recInfo.size() != 0){
        RecInfo prevRec;
        prevRec.s = -1;
        prevRec.t = -1;
        prevRec.c = -1;
        vector<int> delList;
        for(int i=0; i<recInfo.size(); i++){
            if(prevRec.c == recInfo[i].c){
                if(prevRec.t <= recInfo[i].s){
                    delList.push_back(i);
                    prevRec = recInfo[i];
                }
            }else{
                if(prevRec.t < recInfo[i].s){
                    delList.push_back(i);
                    prevRec = recInfo[i];
                }
            }
        }
        for(int d=delList.size()-1; d>=0; d--){
            recInfo.erase(recInfo.begin() + delList[d]);
        }
        recMachineCnt++;
    }

    cout << recMachineCnt << endl;
}


Measured memory_bytes: 2044
/* Read input from STDIN. Print your output to STDOUT*/
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll gcd(ll a, ll b){
    if(a < b) swap(a,b);
   if(b == 0) return a;
   return gcd(b, a%b);
}



ll calc(string s){
    if(s.size() == 1){
        ll c = s[0]-'0';
        return c/2;
    }
    ll val = 0;
    ll ans = 4LL;
    if(s.size() > 2){
      ll prod = 10LL*(pow(10LL, s.size()-2)-1LL)/9LL;
      ans *= prod;
    }
    for(int i = 0; i < s.size()-1; i++){
        ll c = s[i] - '0';
        c = 9LL-c;
        c /= 2LL;
        ll prod = 10LL*(pow(10LL, i)-1LL)/9LL;
        val -= c*prod;
    }
    ll c = s[s.size()-1] - '0';
    c /= 2LL;
    ll prod = 10LL*(pow(10LL, s.size()-1)-1LL)/9LL;
    val += c*prod;
    cout << ans << " " << val << endl;
    if(c > 1) ans += val;
    return ans;
}

int main()
{
   ll n;
   cin >> n;
   if(n%2){
       cout << 0;
       return 0;
   }

   n /= 2LL;
   ll ans = 0;
   ll cur = 5LL;
   while(1){
       if(n/cur == 0) break;
       ans += n/cur;
       cur *= 5LL;
   }
   cout << ans;


}


Measured memory_bytes: 256
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[1][0])
c = int(arr_data[2][0])
d = int(arr_data[3][0])



print((a if a<b else b) + (c if c<d else d))


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

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define SORT(v) sort(v.begin(), v.end())
typedef long long ll;

int main()
{
    int n, cnt = 1;
    cin >> n;
    vector<string> s(n);
    REP(i, n)
    cin >> s.at(i);
    SORT(s);
    FOR(i, 1, n)
    {
        if (s.at(i) != s.at(i - 1))
            cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 9600
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>x;i--)
typedef long long ll;
using namespace std;
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if (a+b>c+d){
        cout<<"Left"<<endl;
    }
    else if(a+b==c+d){
        cout<<"Balanced"<<endl;
    }
    else{
        cout<<"Right"<<endl;
    }
}


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(N), a(100001, 0), b(M, 0), c(M, 0);
    /*
    a[i]: iが何枚あるか
    b[i % M]: i % Mが何枚あるか.
    c[i % M]: iのペアの数
    */
    rep(i, N) {
        cin >> X[i];
        a[X[i]]++;
        b[X[i] % M]++;
    }
    rep(i, 100001) {
        c[i % M] += a[i] / 2;
    }
    /*
    rep(i, M) {
        cout << b[i] << " " << c[i] << endl;
    }
    */
    int ans = b[0] / 2;
    rep(i, M / 2) {
        if (i * 2 + 2 == M) {
            ans += b[i + 1] / 2;
        } else {
            int d = min(b[i + 1], b[M - i - 1]);
            ans += d;
            ans += min(c[i + 1], (b[i + 1] - d) / 2);
            ans += min(c[M - i - 1], (b[M - i - 1] - d) / 2);
        }
    }
    cout << ans << endl;
}

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

signed main()
{
    int h, w, k, cnt, ans=0;
    char c[6][7];

    cin >> h >> w >> k;
    for(int i=0; i<h ;i++ ){
        cin >> c[i];
    }

    for(int i=0 ;i<(1<<h) ;i++ ){
        for(int j=0 ;j<(1<<w) ;j++ ){
            cnt = 0;
            for(int x=0 ;x<h ;x++ ){
                for(int y=0 ;y<w ;y++ ){
                    if(i&(1<<x) && j&(1<<y)){
                        if(c[x][y] == '#'){
                            cnt ++;
                        }
                    }
                }
            }
            if(cnt == k){
                ans ++;
            }
        }
    }

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

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

struct edge{int to,cap,rev;};

const int MAX_V = 5010;
const int F_INF = 123456789;
vector<edge> G[MAX_V];
int level[MAX_V], iter[MAX_V];

void add_edge(int from, int to, int cap){
    // printf(" %d -> %d\n", from,to);
    G[from].pb({to,cap,(int)G[to].size()});
    G[to].pb({from,0,(int)G[from].size()-1});
}

void dinic_bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

int dinic_dfs(int v, int t, int f){
    if(v==t) return f;
    for(int &i=iter[v]; i<(int)G[v].size(); ++i){
        edge &e = G[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            int d = dinic_dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    while(1){
        dinic_bfs(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=dinic_dfs(s,t,F_INF))>0) flow += f;
    }
}

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

    vector<int> group(n+1,-1);
    group[0] = 0;
    rep(i,n)
    {
        int id = i+1;
        group[id] = !group[p[i]];
    }

    int A = 0;
    rep(i,n+1) A += !group[i];

    // printf(" A= %d\n", A);
    // rep(i,n+1) printf(" group[%d] = %d\n", i,group[i]);

    int S = n+1, T = n+2;
    add_edge(S,0,1);

    int ans = 0;
    rep(i,n)
    {
        int id = i+1;
        if(group[id]==0)
        {
            add_edge(S,id,1);
            add_edge(id,p[i],1);
        }
        else
        {
            add_edge(p[i],id,1);
            add_edge(id,T,1);
        }
        ans += max_flow(S,T);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3664