akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int N;
    cin >> N;

    int lim = 1123456;
    vector<bool> neri(lim, false);
    map<int, int> tapi;
    vector<int> A(N);

    REP(i, N) {
        cin >> A[i];
        neri[A[i]] = true;
        tapi[A[i]]++;
    }

    for (int i = 1; i < lim; ++i) {
        if (neri[i]) {
            for (int j = i * 2; j < lim; j += i) {
                neri[j] = false;
            }
        }
    }

    int ans = 0;
    for (int i = 1; i < lim; ++i) {
        if (neri[i] && tapi[i] == 1) {
            ans++;
        }
    }
    cout << ans << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 13068
//==================== default starts ====================//
#include <bits/stdc++.h>
 
using namespace std;
 
#define fread(x)        freopen(x,"r",stdin)
#define fwrite(x)       freopen (x,"w",stdout)
 
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define MEMSET(a,x)     memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))
 
#define white           1
#define grey            2
#define black           3
 
#define ll              long long
#define pb              push_back
#define pf              push_front
#define INF             9e18
#define PI              acos(-1.0)
#define pii             pair<int,int>
#define pll             pair<ll, ll>
 
#define all(v)          v.begin(), v.end()
 
#define fastread        ios_base::sync_with_stdio(0);cin.tie(nullptr);
int on(int N,int pos){return N=N | (1<<pos);}
int off(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
//==================== default ends ====================//
int arr[] = {111,222,333,444,555,666,777,888,999};
int find_num(int n){
	int mid = 9/2, start = 0, ed = 9;
	while(ed-start > 1){
		mid=(start+ed)>>1;
		if(arr[mid] > n){
			ed = mid;
		}else if(arr[mid] < n){
			start = mid;
		}else{
			return arr[mid];
		}
	}
	if(arr[start]==n)return arr[start];
	else return arr[start+1];
}
int main(){
	fastread
	int n;
	cin>>n;
	if(n<=111){
		cout<<"111";
		return 0;
	}
	cout<<find_num(n)<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   int f, a, k;
   scanf("%d %d", &f, &a);
   k=-32767;
   if(k < f+a)
        k=f+a;
   if(k < f-a)
        k=f-a;
   if(k < f*a)
        k=f*a;

    printf("%d\n", k);
}


Measured memory_bytes: 128
n,k=map(int, input().split())
a=(n-1)*(n-2)//2
from itertools import permutations, combinations,combinations_with_replacement,product
moto=list(range(2,n+1))
ku=list(combinations(moto,2))

if k>a:
    print(-1)
else:
    print(n-1+a-k)
    for j in range(n-1):
        print(1,j+2)
    for j in range(a-k):
        print(*ku[j])

Measured memory_bytes: 3992
#include<iostream>
#include<vector>
using namespace std;
const int N=25;
const int mod=1e9+7;
int com[N][N];
long long dp[(1<<21)];
int main(){
	int n,i,j,k;
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			cin>>com[i][j];
		}
	}
	dp[0]=1;
	for(i=0;i<(1<<n);i++){
		k=__builtin_popcount(i);
		for(j=0;j<n;j++){
			if(((1<<j)&i)){
				if(com[j+1][k]){
					//cout<<i<<" "<<((1<<j)^i)<<endl;
					dp[i]+=dp[((1<<j)^i)];
					if(dp[i]>=mod){
						dp[i]-=mod;
					}
				}
			}
		}
		//cout<<dp[i]<<" "<<k<<endl;
	}
	cout<<dp[(1<<n)-1];
}


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

rs = []
for i in range(m):
    a,s = map(str,input().split())
    r = [int(a),s]
    rs.append(r)


c = 0
d = 0
acs = [0] * n 
was = [0] * n
for i in range(m):
    if rs[i][1] == 'AC':
        acs[rs[i][0] - 1]  += 1
    elif (rs[i][1] == 'WA') & (acs[rs[i][0] - 1] == 0):
        was[rs[i][0] - 1] += 1

for i in range(n):
    if acs[i] != 0:
        c += 1
        d += was[i]

print(("{} {}").format(c,d))


Measured memory_bytes: 23520
import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  int N = cin.nextInt();
	  List<int[]> all[] = new List[N];
	  for( int i = 0; i < N; ++i ) {
		  all[i] = new ArrayList<int[]>();
	  }
	  for( int i = 0; i < N - 1; ++i ) {
		  int v = cin.nextInt() - 1;
		  int u = cin.nextInt() - 1;
		  int d = cin.nextInt() & 1;
		  all[u].add(new int[] { v, d });
		  all[v].add(new int[] { u, d });
	  }
	  int ans[] = new int[N];
	  boolean vis[] = new boolean[N];
	  int queue[] = new int[N];
	  int q = 0;
	  queue[q++] = 0;
	  vis[0] = true;
	  for( int i = 0; i < q; ++i ) {
		  int cur = queue[i];
		  for( int edge[] : all[cur] ) {
			  // parent;
			  if( vis[ edge[0] ] ) { continue; }
			  vis[ edge[0] ] = true;
			  ans[ edge[0] ] = ans[cur] ^ edge[1];
			  queue[q++] = edge[0];
		  }
	  }
	  for( int i = 0; i < N; ++i ) {
		  System.out.println(ans[i]);
	  }
  }

}


Measured memory_bytes: 109124
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    VVI rec(h);
    rep(i, h){
        rec[i].resize(w, 1);
    }
    rep(i, n){
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1){
            rep(i, x){
                rep(j, h){
                    rec[j][i] = 0;
                }
            }
        }else if(a == 2){
            for(int i = x ; i < w ; i++){
                rep(j, h){
                    rec[j][i] = 0;
                }
            }
        }else if(a == 3){
            rep(i, w){
                rep(j, y){
                    rec[j][i] = 0;
                }
            }
        }else{
            rep(i, w){
                for(int j = y ; j < h ; j++){
                    rec[j][i] = 0;
                }
            }
        }
    }
    int ans = 0;
    rep(i, w){
        rep(j, h){
            ans += rec[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;

	scanf("%d%d", &a, &b);

	if (1 <= a && a <= 9) //Aが1以上9以下のとき
	{
		if (1 <= b && b <= 9) //Bが1以上9以下のとき（条件と一致）
		{
			printf("%d\n", a * b);
		}
		else //Aのみ一致
		{
			printf("-1\n");
		}
	}
	else //A Bどちらも一致しない
	{
		printf("-1\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>

int a[4] = {6000, 4000, 3000, 2000};

int main(){
	for(int i = 0; i < 4; i++){
		int t, n; scanf("%d%d", &t, &n);
		t--;
		printf("%d\n", a[t]*n);
	}
}

Measured memory_bytes: 1028
import sys, math, collections, heapq, itertools

F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N, M = map(int, line_input())
    A = [int(a) for a in line_input()]
    change = [None] * M
    for i in range(M):
        b, c = map(int, line_input())
        change[i] = [c, b]
    A.sort()
    change.sort(reverse = True)

    sum = 0
    index = 0
    for c, b in change:
        bleft = b
        while bleft > 0:
            if c > A[index]:
                sum += c
                index += 1
                bleft -= 1
                if index == N: break
            else: break
        if index == N: break
    if index < N:
        for i in range(index, N):
            sum += A[i]
    print(sum)

    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 24272
# -*- coding: utf-8 -*-
 
import sys
import math

n = int(input())

s = []

for i in range(3):
    s.append(input())

num = 0
for i in range(n):
    if s[0][i] == s[1][i] == s[2][i]:
        num = num
    elif s[0][i] == s[1][i]:
        num += 1
    elif s[0][i] == s[2][i]:
        num += 1
    elif s[1][i] == s[2][i]:
        num += 1
    else:
        num += 2


print(num)

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

typedef long long int lli;

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;

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

    int count=1;
    int m = 1;
    for(int i=1;i<n;i++)
    {
        if(arr[i]<=arr[i-1])
        {
            count++;
            if(count>m)
                m=count;
        }
        else
            count=1;
    }

    cout<<m-1;
}

Measured memory_bytes: 640
H, W = map(int, input().split())
S = ['.' * (W + 2)]
for i in range(H):
    s = '.' + input() + '.'
    S.append(s)
S.append('.' * (W + 2))

ans = []

for h in range(1, H + 1):
    t = ''
    cnt = 0
    for w in range(1, W + 1):
        if S[h - 1][w] == '#':
            cnt += 1
        if S[h + 1][w] == '#':
            cnt += 1
        if S[h][w - 1] == '#':
            cnt += 1
        if S[h][w + 1] == '#':
            cnt += 1
        if S[h - 1][w - 1] == '#':
            cnt += 1
        if S[h + 1][w + 1] == '#':
            cnt += 1
        if S[h + 1][w - 1] == '#':
            cnt += 1
        if S[h - 1][w + 1] == '#':
            cnt += 1

        if S[h][w] == '#':
            t += '#'
        else:
            t += str(cnt)
        cnt = 0
    ans.append(t)

for i in ans:
    print(i)


Measured memory_bytes: 9112
n = input()
nlen = len(n)

if nlen > 5:
  n5 = 90000
  n3 = 900
  n1 = 9
elif nlen == 5:
  n5 = int(n[-5:]) - 9999
  n3 = 900
  n1 = 9
elif nlen >3:
  n5 = 0
  n3 = 900
  n1 = 9
elif nlen == 3:
  n5 = 0
  n3 = int(n[-3:]) - 99
  n1 = 9
elif nlen > 1:
  n5 = 0
  n3 = 0
  n1 = 9
else:
  n5 = 0
  n3 = 0
  n1 = int(n[-1:])

print(n1 + n3 + n5)

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

int main()
{
  char yc[5], mc[3], dc[3];
  int yi, mi, di;
  scanf("%4s/%2s/%2s",yc,mc,dc);
  yi =  atoi(yc);
  mi =   atoi(mc);
  di =   atoi(dc);
  if(yi == 2019 && mi <= 4 && di <= 30)
      printf("Heisei");
  else if(yi < 2019)
      printf("Heisei");
  else
      printf("TBD");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>
// #include "utiltime.hpp"

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef complex<double> cdouble;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define readfile(filename) ifstream in(filename); cin.rdbuf(in.rdbuf());
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(double x) { ll m = (ll)sqrt(x); return m + (m * m <= (ll)(x) ? 0 : -1); }
ll ceilsqrt(double x) { ll m = (ll)sqrt(x); return m + ((ll)x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }

/*******************************************************/

void failed() {
	cout << -1 << endl;
	exit(0);
}

int main() {
	ll n, m; cin >> n >> m;
	string s, t; cin >> s >> t;
	if (n < m) {
		swap(n, m);
		swap(s, t);
	}
	ll p = n / m;
	ll q = n % m;
	ll g = gcd(n, m);
	Loop(i, g) {
		if (s[i * n / g] != t[i * m / g]) {
			failed();
		}
	}
	cout << n * m / g << endl;
}

Measured memory_bytes: 512
n = gets.to_i
a = []
n.times do
  a << gets.to_i
end
a.sort!
ans = 0
if n.odd?
  m = a.slice!(n/2-1,3)
  n -= 3
  ans += [-2*m[0]+m[1]+m[2],-m[0]-m[1]+2*m[2]].max
else
  ans += - a.delete_at(n/2-1)
  ans +=  a.delete_at(n/2-1)
  n -= 2
end
ans += -2 * a[0,n/2].inject(:+) + 2*a[n/2,n/2].inject(:+) if !a.empty?
p ans


Measured memory_bytes: 4016
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    string T;
    cin >> T;
    for(auto e: T) {
        if(e == '?') {
            cout << 'D';
        } else {
            cout << e;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N;
  cin >> N;
  cout << (N - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, TD):
    TD.sort(key=lambda x: x[1], reverse=True)

    c = Counter()
    base = 0
    rc = []
    for i in range(K):
        t, k = TD[i]
        c[t] += 1
        base += k
        if c[t] > 1:
            rc.append((t, k))

    mi = i
    ans = base + len(c)**2
    while True:
        if len(rc) == 0:
            break
        rt, rk = rc.pop()
        for i in range(mi+1, len(TD)):
            if TD[i][0] not in c:
                c[TD[i][0]] += 1
                c[rt] -= 1
                base -= rk
                base += TD[i][1]
                mi = i
                ans = max(ans, base + len(c)**2)
                break

        else:
            break
    return ans


def main():
    # N = read_int()
    N, K = read_int_n()
    TD = [read_int_n() for _ in range(N)]
    print(slv(N, K, TD))


if __name__ == '__main__':
    main()


Measured memory_bytes: 35296
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
using namespace std;

int getH(int t){
  return t/100;
}

int getT(int t){
  return t-t/100*100;
}

int gettime(int t){
  return getH(t)*60+getT(t);
}

int main(){
  int n,start,end,i,j,k,l,m,ins,ine;

  while(1){
    cin>> n >> start >> end;
    if(n == 0 && start == 0 && end == 0)break;
    int time[100000];
    start = gettime(start);
    end = gettime(end);
    assert(end-start >= 0);
    for(i=0;i<100000;i++)time[i] = 0;
    for(i=0;i<n;i++){
      cin >> m;
      for(j=0;j<m;j++){
	cin >> ins >> ine;  
	ins = gettime(ins);
	ine = gettime(ine);
	for(int k=ins;k<ine;k++)time[k]++;
      }
    }
    int ans = 0,cnt=0;
  
    for(i=start;i<=end+1;i++){
      if(time[i] == n || i == end){
	ans = max(ans,cnt);
	cnt = 0;
	continue;
      }
      cnt++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1548
import collections
N = int(input())
answer = 0
flag = collections.defaultdict(int)

for i in range(N):
  a = int(input())
  flag[a] = (flag[a]+1)%2

list = list(flag.values())

for i in range(len(list)):
  if list[i] == 1:
    answer+=1

print(answer)

Measured memory_bytes: 15460
from functools import reduce

n,a,b = map(int,input().split())
MOD = 1000000007

# nCr の計算
def F(n,r):
    # 分子 n*(n-1)*(n-2)*...(n-r+1)
    numerator = reduce(lambda x,y: x * y % MOD, range(n,n-r,-1))
    # 分母 r!(rの階乗)
    denominator = reduce(lambda x,y: x * y % MOD, range(1,r+1))
    return numerator * pow(denominator, MOD - 2, MOD) % MOD

# 繰り返し二乗法
ans = pow(2,n,MOD)-1
ans -=F(n,a)
ans -=F(n,b)
ans %= MOD

print(ans)

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

int main(void){
	int i,j,x,y;
	int log[128];
	bool flg;

	while(cin>>x>>y){
		flg = false;
		for(i=0;;i++){
			if(i)cout << x/y;
			x = x - y * (x / y);
			if(x == 0) break;
			for(j=i-1;j>=0;j--){
				if(x == log[j]){
					flg = true;
					break;
				}
			}
			if(flg){
				break;
			}
			log[i] = x;
			x *= 10;
		}
		cout<<endl;
		if(flg){
			int k;
			for(k=0;k<j;k++){
				cout<<' ';
			}
			for(;k<i;k++){
				cout<<'^';
			}
			cout<<endl;
		}
	}

  return 0;
}

Measured memory_bytes: 0
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().solver();
	}
	void solver(){
		Scanner sc=new Scanner(System.in);
		int V=sc.nextInt();
		int E=sc.nextInt();
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] e=new ArrayList[V];
		for(int i=0;i<V;i++){
			e[i]=new ArrayList<Integer>();
		}
		for(int i=0;i<E;i++){
			int s=sc.nextInt();
			int t=sc.nextInt();
			e[s].add(t);
		}
		ArrayDeque<Integer> ans=topological_sort(e,0);
		while(!ans.isEmpty()){
			System.out.println(ans.poll());
		}
		sc.close();
	}
	
	ArrayDeque<Integer> topological_sort(ArrayList<Integer>[] edges,int s){
		ord=new ArrayDeque<Integer>();
		visit=new boolean[edges.length];
		for(int i=0;i<edges.length;i++){
			if(!visit[i]){
				dfs(edges,i);
			}
		}
		return ord;
	}
	boolean[] visit;//true:?¨??????????false:?¨????????????????
	ArrayDeque<Integer> ord;
	void dfs(ArrayList<Integer>[] edges,int i){
		visit[i]=true;
		for(int j:edges[i]){
			if(!visit[j]){
				dfs(edges,j);
			}
		}
		ord.addFirst(i);
	}
}

Measured memory_bytes: 70640
#include <cctype>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  string s;
  getline(cin, s);

  rep(i, s.size()) {
    char c = s.at(i);
    if (islower(c))
      c = toupper(c);
    else if (isupper(c))
      c = tolower(c);
    cout << c;
  }
  cout << endl;
}


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

int64_t modpow(int64_t x, int64_t n) {
    const int MOD = 998244353;
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int64_t n,m,k;
  cin>>n>>m>>k;
  const int MOD = 998244353;

  int64_t m_1[k+1];
  int64_t start = n-1-k;
  m_1[0] = modpow(m-1, start);
  for(int i=1; i<=k; i++) {
    m_1[i] = (m_1[i-1]*(m-1))%MOD;
  }

  int64_t ans = 0;
  int64_t comb = 1;
  for(int i=0; i<=k; i++) {
    int64_t add = (comb*m_1[k-i])%MOD;
    ans += add;
    ans = ans%MOD;
    comb = (comb*(n-1-i))%MOD;
    int64_t div = modpow((i+1), MOD-2);
    comb = (comb*div)%MOD;
  }

  ans = (ans*m)%MOD;

  cout<<ans<<endl;


  return 0;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  int ansl=1,ansr=n;
  for (int i=0; i<m; i++) {
    int l,r;
    cin>>l>>r;
    if (l>ansl) ansl=l;
    if (r<ansr) ansr=r;
  }
  int ans=max(0,ansr-ansl+1);
  cout<<ans<<endl;
  return 0;
}

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

int mn = 1000000;
signed main(){
  
  int a[6];
  cin >> a[0] >> a[1] >> a[2];
  a[3] = a[0];
  a[4] = a[1];
  //sort(a,a+2);
  for(int i = 0;i<3;i++){
    mn = min(a[i]+a[i+1],mn);
  }
  cout << mn << endl;
  return 0;
}
    
  


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    rep(i,x) cin >> a[i];
    rep(i,y) cin >> b[i];
    rep(i,z) cin >> c[i];
    vector<ll> ab;
    rep(i, x) {
        rep(j, y) ab.push_back(a[i]+b[j]);
    }
    sort(ALL(ab), greater<ll>());
    sort(ALL(c), greater<ll>());
    
    vector<ll> abc;
    rep(i, min(k, x*y)) {
        rep(j, min(k, z)) {
            abc.push_back(ab[i]+c[j]);
        }
    }
    sort(ALL(abc), greater<ll>());
    rep(i, k) cout << abc[i] << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        ret %= MOD;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count))%MOD;
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



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

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int calc_price(int w)
{
    int cost = 1150;
    if (w <= 10) return cost;
    if (w <= 20) return cost + (w - 10) * 125;
    cost += 1250;
    if (w <= 30) return cost + (w - 20) * 140;
    cost += 1400;
    return cost + (w - 30) * 160;
}

int main()
{
    int w;
    while (w = in(), ~w){
        printf("%d\n", 4280 - calc_price(w));
    }
    return (0);
}

Measured memory_bytes: 1188
#include<iostream>
#include<iomanip>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 500;
int H, W, d;

char getColor(int x, int y) {
	x = (x + W) / d;
	y = (y + H) / d;
	if (y & 1) {
		if (x & 1)return 'R';
		else return 'G';
	}
	else {
		if (x & 1)return 'B';
		else return 'Y';
	}
}

int main() {
	cin >> H >> W >> d;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int y = i + j;
			int x = i - j;
			cout << getColor(x, y);
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int min(int a,int b){
  if(a > b)
    return b;
  else
    return a;
}

int main(){
  int i,j,k;
  int N;
  scanf("%d",&N);
  int A[N][26];
  for(i=0;i<N;i++){
    for(j=0;j<26;j++){
      A[i][j]=0;
    }
  }
  int tmp;
  char S[N][50];
  for(i=0;i<N;i++){
    scanf("%s",S[i]);
    for(j=0;j<strlen(S[i]);j++){
      
      A[i][S[i][j]-'a']++;
    }
  }
 /* for(i=0;i<26;i++)
    printf("%d\n",A[0][i]);*/
  
  int min;
  for(i=0;i<26;i++){
    min=100;
    for(j=0;j<N;j++){
      if(A[j][i] < min)
        min=A[j][i];
    }
    for(j=0;j<min;j++)
      printf("%c",i+97);
  }
  puts("");
  return 0;
}
    

Measured memory_bytes: 128
def main():
    n,d=map(int,input().split())
    ans=0
    for _ in range(n):
        x,y=map(int,input().split())
        z=(x**2+y**2)**0.5
        if z <= d: ans+=1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9564
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(){
	//printf("%s",str);
	char a[105];
    char b[105];
	char c[105];
	for(int i=0;i<105;i++){
	 a[i]='0';	
	}
	fgets(a,1000,stdin);
	for(int i=0;i<105;i++){
	 b[i]='0';	
	}
	fgets(b,1000,stdin);
	
	for(int i=0;i<105;i++){
	 c[i]='0';	
	}
	fgets(c,1000,stdin);
	

	int acard=0;
	int bcard=0;
	int ccard=0;
	
	int turn=1;
	
	int fin=0;
	
	while(fin==0){
		if(turn==1){
	if(a[acard]=='0')fin=1;	
	if(a[acard]=='a')turn=1;	
	if(a[acard]=='b')turn=2;	
	if(a[acard]=='c')turn=3;	

	acard++;
	}
		if(turn==2){
	if(b[bcard]=='0')fin=1;	
	if(b[bcard]=='a')turn=1;	
	if(b[bcard]=='b')turn=2;	
	if(b[bcard]=='c')turn=3;	
	bcard++;
	}
		if(turn==3){
	if(c[ccard]=='0')fin=1;	
	if(c[ccard]=='a')turn=1;	
	if(c[ccard]=='b')turn=2;	
	if(c[ccard]=='c')turn=3;	
	ccard++;
	}	
	}
	
	if(turn==1)printf("A\n");
	if(turn==2)printf("B\n");
	if(turn==3)printf("C\n");

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, k, cur;
vector<pair<int,int> > v;
signed main(){
	cin >> n >> k;
	cur = (n - 1)*(n - 2)/2;
	if(k > cur){
		cout << -1;
		return 0;
	}
	for(int i = 1 ; i < n ; i ++)
		v.push_back({i, n});
	for(int i = 1 ; i < n - 1 ; i ++)
		for(int j = i + 1 ; j < n ; j ++){
			if(cur-- > k) v.push_back({i, j});
			else break;
		}
	cout << v.size() << endl;
	for(pair<int,int> p: v)
		cout << p.first << " " << p.second << endl;
}

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

int main(){
    int N, K;
    string S;
    cin >> N >> K >> S;

    if(S.at(K-1) == 'A'){
        S.at(K-1) = 'a';
    }
    else if(S.at(K-1) == 'B'){
        S.at(K-1) = 'b';
    }
    else if(S.at(K-1) == 'C'){
        S.at(K-1) = 'c';
    }

    cout << S << endl;
}


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

ll n, k;
vector<ll> v;

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		ll a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	ll ans=10000000000;
	k--;
	for(int i=0;i+k<n;i++){
		ans=min(ans,v[i+k]-v[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#ifndef INT_MAX
#  define INT_MAX std::numeric_limits<int>().max()
#endif
#ifndef INT_MIN
#  define INT_MIN std::numeric_limits<int>().min()
#endif
#define LL_MAX std::numeric_limits<ll>().max()
#define LL_MIN std::numeric_limits<ll>().min()
#define INF LL_MAX

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())

ll N;

multiset<ll> head;
multiset<ll, greater<ll> > back;
vector<ll> middle;

ll head_sum[100010];    // 境界線の位置が i だったときの head の総和
ll back_sum[100010];    // 境界線の位置が i だったときの back の総和

int main()
{
    cin >> N;

    ll head_sum_tmp = 0;
    ll back_sum_tmp = 0;
    REP(i, N) {
        ll a;
        cin >> a;
        head.insert(a);
        head_sum_tmp += a;
    }
    head_sum[0] = head_sum_tmp;
    REP(i, N) {
        ll a;
        cin >> a;
        middle.push_back(a);
    }
    REP(i, N) {
        ll a;
        cin >> a;
        back.insert(a);
        back_sum_tmp += a;
    }
    back_sum[N] = back_sum_tmp;

#if 1
    multiset<ll> head_tmp = head;
    multiset<ll, greater<ll> > back_tmp = back;
    for(ll i = 1; i <= N; ++i) {
        head_tmp.insert(middle[i-1]);
        head_sum[i] = head_sum[i-1] + middle[i-1] - *head_tmp.begin();
        head_tmp.erase(head_tmp.begin());

        back_tmp.insert(middle[N-i]);
        back_sum[N-i] = back_sum[N-i+1] + middle[N-i] - *back_tmp.begin();
        back_tmp.erase(back_tmp.begin());
    }
    ll ans = head_sum_tmp - back_sum_tmp;
    for(ll i = 0; i <= N; ++i) {
        ans = max(ans, head_sum[i] - back_sum[i]);
    }
    printf("%lld\n", ans);
#else
    ll ans = LL_MIN;
    for(ll i = 0; i <= middle.size(); ++i) {
        multiset<ll> head_tmp = head;
        multiset<ll, greater<ll> > back_tmp = back;
        for(ll j = 0; j < middle.size(); ++j) {
            if(j < i) {
                // head の入れ替え
                head_tmp.insert(middle[j]);
                head_tmp.erase(head_tmp.begin());
            } else {
                // back の入れ替え
                back_tmp.insert(middle[j]);
                back_tmp.erase(back_tmp.begin());
            }
        }
        ll head_sum = 0;
        ll back_sum = 0;
        auto head_it = head_tmp.begin();
        auto back_it = back_tmp.begin();
        REP(j, head_tmp.size()) {
            head_it++;
        }
        REP(j, back_tmp.size()) {
            back_it++;
        }
        head_it = head_tmp.begin();
        back_it = back_tmp.begin();
        REP(j, N) {
            head_sum += *head_it;
            back_sum += *back_it;
            head_it++;
            back_it++;
        }
        ans = max(ans, head_sum - back_sum);
    }
    printf("%lld\n", ans);
#endif
    return 0;
}


Measured memory_bytes: 21368
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string.h>
#define endl "\n"
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    int i, j, k;
    vector < vector <int> > v(m);
    int size, conn;
    for(i = 0; i < m; i ++)
    {
    	cin >> size;
    	for(j = 0; j < size; j ++)
    	{
    		cin >> conn;
    		v[i].push_back(conn);
    	}
    }

    vector <int> p(m);
    for(i = 0; i < m; i ++)
    	cin >> p[i];

    int row = 1 << n;
    int col = n;
    int comb[row][col];

    memset(comb, 0, sizeof(comb));

    for(i = 0; i < (1 << n); i ++)
    {
        int val = i;
    	int index = n - 1;
    	while(val > 0)
    	{
    		int rem = val % 2;
    		comb[i][index] = rem;
    		val = val / 2;
    		index --;
    	}
    }

    int finalAns = 0;
    for(i = 0; i < (1 << n); i ++)
    {
    	int ans = 0;
    	for(j = 0; j < m; j ++)
    	{
    		int count = 0;
    		for(int sw: v[j])
    		{
    			if(comb[i][sw - 1] == 1)
    				count ++;
    		}
    		// cout << "count " << count << endl;
    		if(count % 2 == p[j])
    			ans ++;
    	}

    	// cout << "ans " << ans << endl;
    	if(ans == m)
    		finalAns ++;
    }
    cout << finalAns << endl;
}

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

typedef long long ll;

const int Maxm = (1 << 16) + 5;
const int mod = 1000000007;
const int Maxn = 16;

int fac[Maxm];
int inv[Maxm];
int n, m;
int a[Maxn];
int dp[Maxn + 1][1 << Maxn];
int comp[1 << Maxn];
int res;

int Inv(int a)
{
	int p = mod - 2;
	int res = 1;
	while (p) {
		if (p & 1) res = ll(res) * a % mod;
		p >>= 1; a = ll(a) * a % mod;
	}
	return res;
}

int C(int n, int k)
{
	if (n < 0 || k < 0 || k > n) return 0;
	return ll(fac[n]) * inv[k] % mod * inv[n - k] % mod;
}

int main()
{
	fac[0] = inv[0] = 1;
	for (int i = 1; i < Maxm; i++) {
		fac[i] = ll(i) * fac[i - 1] % mod;
		inv[i] = Inv(fac[i]);
	}
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
		scanf("%d", &a[i]);
	dp[m][0] = 1;
	for (int i = m; i > 0; i--)
		for (int j = 0; j < 1 << n; j++) if (dp[i][j] != 0) {
			dp[i - 1][j] = (dp[i - 1][j] + dp[i][j]) % mod;
			int lft = (1 << n) - a[i - 1] + 1 - j;
			for (int l = 0; l < n; l++) 
				if (!(j & 1 << l) && (1 << l) <= lft) {
					int ways = ll(C(lft - 1, (1 << l) - 1)) * fac[1 << l] % mod * 2 % mod;
					dp[i - 1][j | 1 << l] = (dp[i - 1][j | 1 << l] + ll(ways) * dp[i][j]) % mod;
				}
		}
	comp[0] = 1;
	for (int i = 1; i < 1 << n; i++) {
		int j = 0;
		while (!(i & 1 << j)) j++;
		comp[i] = ll(comp[i ^ 1 << j]) * 2 % mod * fac[1 << j] % mod * C(i, (1 << j)) % mod;
	}
	for (int j = 0; j < 1 << n; j++) {
		int ways = ll(dp[0][j]) * comp[((1 << n) - 1) ^ j] % mod;
		if (__builtin_popcount(j) % 2) res = (res - ways + mod) % mod;
		else res = (res + ways) % mod;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 4864
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		boolean j = true;

		String s = sc.next();

		for(int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if(i % 2 == 0){
				if(c != 'R' && c != 'U' && c != 'D') {
					j = false;
					break;
				}
			} else {
				if(c != 'L' && c != 'U' && c != 'D') {
					j = false;
					break;
				}
			}
		}

		System.out.println(j ? "Yes" : "No");
	}
}

Measured memory_bytes: 35376
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

//for(int i = 0; i < size; i++)
//    cout << a[i] << " ";

int main(){

    fast_io;

    int t;

    cin >> t;

    if(t % 1000 == 0){
        cout << 0 << '\n';
    }
    else{
        cout << 1000 - t % 1000 << '\n';
    }

    return 0;
}


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

int main(){
    int N, T, A;
    cin >> N;
    cin >> T >> A;

    double app_temp = 1000; 
    int point;
    for(int i=1; i<=N; i++){
        long x;
        cin >> x;
        if(abs(A-T+x*0.006) < app_temp){
            app_temp = abs(A-T+x*0.006);
            point = i;
        }
    }

    cout << point;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	c := make(map[byte][]bool)
	suits := []byte{'S', 'H', 'C', 'D'}
	for _, s := range suits {
		c[s] = make([]bool, 13)
	}

	for i := 0; i < n; i++ {
		var s string
		var x int
		fmt.Scan(&s, &x)
		c[s[0]][x-1] = true
	}
	for _, s := range suits {
		for i := 0; i < 13; i++ {
			if !c[s][i] {
				fmt.Println(string(s), i+1)
			}
		}
	}
}



Measured memory_bytes: 1168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
    string s; cin >> s;
    ll n = s.size();

    ll cnt = 0,b = 0;
    rep(i,n) {
        if(s[i] == 'B') {
            cnt += n - i - 1;
            b++;
        }
    }

    cout << cnt - b * (b - 1) / 2 << endl;
}


Measured memory_bytes: 640
import sys
S = input()
S = S[::-1]
while S:
    if S[:3]=="res":
        if S[:6]=="resare":
            S = S[6:]
#             print(S)
        else:
            print("NO")
            sys.exit()

    elif S[:3]=="esa":
        if S[:5]=="esare":
            S = S[5:]
#             print(S)
        else:
            print("NO")
            sys.exit()
    
    elif S[:3]=="rem":
        if S[:7]=="remaerd":
            S = S[7:]
#             print(S)
        else:
            print("NO")
            sys.exit()
        
    elif S[:3]=="mae":
        if S[:5]=="maerd":
            S = S[5:]
#             print(S)
        else:
            print("NO")
            sys.exit()
            
    else:
        print("NO")
        sys.exit()
else:
    print("YES")

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
//#define ls x<<1
//#define rs x<<1|1
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
const ull hashp=131;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=11092019;
const int maxn=1e5+100;

void solve(){
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double l=30.0*h+30.0*m/60.0,r=6.0*m;
	double ai=fabs(l-r);
	if(ai>180.0)ai=360.0-ai;
	ai=ai/180.0*pi;
	double ans=sqrt(a*a+b*b-2.0*a*b*cos(ai));
	printf("%.20f",ans);
}
int main(){
    //IOS;
    //freopen("D:\\data.txt","r",stdin);
    //freopen("D:\\out.txt","w",stdout);
    solve();

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;                                             ;;
	;;         ;;            ;;;;;;;;;       ;;    ;;
	;;        ;; ;;        ;;                ;;    ;;
	;;       ;;   ;;       ;;                ;;    ;;
	;;      ;;;;;;;;;      ;;                ;;    ;;
	;;     ;;       ;;     ;;                      ;;
    ;;    ;;         ;;      ;;;;;;;;;       ;;    ;;
    ;;                                             ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const ll INF = 1LL<<60;

int main(){
    ll n;
    vector<ll> a(5);
    cin >> n;
    rep(i,5) cin >> a[i];
    int minI = 0;
    ll minNum = INF;
    rep(i,5) {
        if (chmin(minNum, a[i])) minI = i;
    }


    ll ans = 0;
    rep(i,5){
        if (minI == i){
            ans += n / a[i];
            if (n % a[i]  != 0){
                ans++;
            }
        }else{
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100;
int a[N];
int main(){
	LL n=0,num=1000,num1=0;scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);a[n]=0;
	for(int i=0;i<n;i++){
		if(a[i]<a[i+1])num1+=num/a[i],num%=a[i];
		else num+=num1*a[i],num1=0;
	}
	printf("%lld",num);
	return 0;
}

Measured memory_bytes: 3780
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

const ll p = (1e+9) + 7;

ll add(ll a, ll b) {
	return (a + b) % p;
}

ll sub(ll a, ll b) {
	return (a + p - b) % p;
}

ll mul(ll a, ll b) {
	return ((a%p)*(b%p)) % p;
}

ll power(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	else if (b == 1) {
		return a % p;
	}
	else if (b % 2 == 0) {
		ll c = power(a, b / 2);
		return (c*c) % p;
	}
	else {
		ll c = power(a, b / 2);
		return (((c*c) % p)*a) % p;
	}
}

ll divi(ll a, ll b) {
	return mul(a, power(b, p - 2));
}

int main() {
	ll H, W, A, B, g[200000], inv_g[200000];
	cin >> H >> W >> A >> B;

	REP(i, H + W - 1) {
		if (i == 0) {
			g[i] = 1;
		}
		else {
			g[i] = mul(i, g[i - 1]);
		}
		inv_g[i] = divi(1, g[i]);
	}
	
	ll ans = 0;
	REP(i, H - A) {
		ll s = mul(mul(g[B + i - 1], inv_g[i]), inv_g[B - 1]);
		ll t = mul(mul(g[H + W - 2 - B - i], inv_g[W - B - 1]), inv_g[H - i - 1]);
		ans = add(ans, mul(s, t));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
char in[30];
int UF[300];
int w[300];
pair<int,int> FIND(int a){
	if(UF[a]<0)return make_pair(a,0);
	pair<int,int>ret=FIND(UF[a]);
	ret.second+=w[a];
	return ret;
}
bool ok=true;
void UNION(int a,int b,int c){
	pair<int,int>A=FIND(a);
	pair<int,int>B=FIND(b);
	int d=A.first;
	int e=B.first;
	int f=A.second+c-B.second;
	if(d==e){
		if(B.second-c!=A.second)ok=false;
		return;
	}
	UF[d]+=UF[d];
	UF[e]=d;
	w[e]=f;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		map<string,int>m;
		int sz=0;ok=true;
		for(int i=0;i<300;i++){
			UF[i]=-1;w[i]=0;
		}
		for(int i=0;i<a;i++){
			scanf("%s%s",in,in);
			string A=in;
			int C=0;
			scanf("%s%s",in,in);
			if(in[1]==0)C=0;
			else{
				sscanf(in,"%d^%d",&C,&C);
			}
			scanf("%s",in);
			string B=in;
			int p,q;
			if(!m.count(A)){
				p=sz;
				m[A]=sz++;
			}else p=m[A];
			if(!m.count(B)){
				q=sz;
				m[B]=sz++;
			}else q=m[B];
			UNION(p,q,C);
		//	if(!ok)printf("%d\n",i);
		}
		if(ok)printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 1092
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL;

LL OneL;
LL TwoL;
LL Ans = 0;

int main()
{
	LL Q, H, S, D, N;
	cin >> Q >> H >> S >> D;
	cin >> N;
	OneL = min(Q * 4, min(H * 2, S));
	TwoL = min(Q * 8, min(H * 4, min(S * 2, D)));
	if (N % 2 == 0)
	{
		Ans = (N / 2) * TwoL;
	}
	else
	{
		Ans = (N / 2) * TwoL + OneL;
	}
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
  public static void main (String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int ans = 0;
    for(int i = 0; i < n-1; i++)
    {
      int[] xx = new int[26];
      int[] yy = new int[26];
      
      for(int j = 0; j <= i; j++)
      {
        xx[s.charAt(j) - 'a']++;
      }
      for(int k = i+1; k < n; k++)
      {
        yy[s.charAt(k) - 'a']++;
      }
      int tmp = 0;
      for(int l = 0; l < 26; l++)
      {
        if(xx[l] > 0 && yy[l] > 0) tmp++;
      }
      ans = Math.max(ans, tmp);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23508
import sys
from io import StringIO
import unittest

def resolve():
    n = input()

    if '7' in n:
        print('Yes')
    else:
        print('No')


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """117"""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """123"""
        output = """No"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """777"""
        output = """Yes"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 70988
cx, cy, r = map(int, input().split())
q = int(input())

for _ in range(q):
  x1,y1,x2,y2 = map(int,input().split())
  dx, dy = x2 - x1, y2 - y1
  px, py = cx - x1, cy - y1
  s2 = dx **2 + dy **2
  dot = dx*px + dy*py
  crs = dx * py - dy * px
  t1 = (dot + (s2 * r ** 2 - crs ** 2) **0.5)/s2
  t2 = (dot -(s2 * r ** 2 -crs ** 2) ** 0.5)/s2
  if (dx < 0 or (dx == 0 and dy < 0 )) ^ (t1 > t2):
    t1,t2 = t2,t1
  print(x1+dx*t1, y1+dy*t1,x1+dx*t2,y1+dy*t2)



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

int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<int> > vec(10, vector<int>(10));
    rep(i,10){
        rep(j,10){
            cin >> vec[i][j];
        }
    }
    rep(k,10){
        rep(i,10){
            rep(j,10){
                vec[i][j] = min(vec[i][j], vec[i][k] + vec[k][j]);
            }
        }
    }
    vector<vector<int> > wall(H, vector<int> (W));
    rep(i,H){
        rep(j,W){
            cin >> wall[i][j];
        }
    }
    int ans = 0;
    rep(i,H){
        rep(j,W){
            if (wall[i][j] != -1){
                ans += vec[wall[i][j]][1];
            }
        }
    }
    cout << ans << endl;    
}



Measured memory_bytes: 3768