akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int A, B, C;
int X;
int solve(){
int ans = 0;
for(int i = 0; i <= A; ++i){
for(int j = 0; j <= B; ++j){
for(int k = 0; k <= C; ++k){
int tmp = i * 500 + j * 100 + k * 50;
if(tmp == X) ans++;
}
}
}
return ans;
}

int main(){
scanf("%d%d%d%d", &A, &B, &C, &X);
int ans = solve();
printf("%d\n", ans);
return 0;
}


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

using namespace std;

#define lint long long
#define P pair<int, int>

int main(){
    int r, D, x;
    cin >> r >> D >> x;

    for(int i = 0; i < 10; ++i){
        x = x * r - D;
        cout << x << endl;
    }
}



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

int64_t f(int64_t x){
  if(x == 1){
    return 1;
  }else{
    return 1 + 2 * f(x/2);
  }
}

int main() {
  int64_t H;
  cin >> H;
  cout << f(H) << endl;
}

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

for i in range(N):
    A[i] = (A[i],i+1)

A.sort()

B = [A[i][1] for i in range(N)]

print(*B)

Measured memory_bytes: 87516
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int n=s.size();
    rep(i,n){
        if(s[i]=='?'){
            s[i]='D';
        }
    }
    rep(i,n) cout<<s[i];
}

Measured memory_bytes: 3744
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    
    char A[64];
    for (int i=0; i < H * W; ++i) cin >> A[i];
    
    int sharp = 0;
    for (int i=0; i < H * W; ++i) {
        if (A[i] == '#') ++sharp;
    }
    
    if (sharp == H + W -1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

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

#define ll long long
#define mod 1000000007
#define mx 100005

int a[mx+10];
char ch[mx+10];
int n,k;

void solve(int ii)
{
    scanf("%d%d",&k,&n);

    if(k*500>=n)printf("Yes\n");
    else printf("No\n");



   return;
}

int main()
{
    int t=1;

    for(int i=1;i<=t;i++)solve(i);

    return 0;
}


Measured memory_bytes: 256
import bisect
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()

    mx = [-1, -1]
    for i in range(N):
        idx = bisect.bisect_left(A,A[i]/2)
        if idx == 0:
            mx = [max(A[i],A[idx]), min(A[i],A[idx])]
            continue

        if abs(A[i]/2 - A[idx]) < abs(A[i]/2 - A[idx-1]):
            mx = [max(A[i],A[idx]), min(A[i],A[idx])]
        else:
            mx = [max(A[i],A[idx-1]), min(A[i],A[idx-1])]
    
    print(*mx)
    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 62704
#include<stdio.h>
#include<math.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    double start1,start2,end1,end2;
    if(12.5*a<10*b){
        start1=12.5*a;
        start2=10.0*b;
        end1=12.5*(a+1);
        end2=10.0*(b+1);
    }else{
        start2=12.5*a;
        start1=10.0*b;
        end2=12.5*(a+1);
        end1=10.0*(b+1);
    }
    if(start2<end1)printf("%d\n",(int)ceil(start2));
    else printf("-1\n");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	int count, n, i, j, sum;
	scanf("%d",&n);
	while(n){
		count = 0;
		for(i = 1;i < n;i++){
			sum = 0;
			for(j = i;j < n && sum < n;j++)
				sum += j;
			if(sum == n)
				count++;
		}
		printf("%d\n",count);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()

int main(){
    int T, P, R;
    while(cin >> T >> P >> R, T|P|R){
        vector<vector<int> > pen(T, vector<int>(P));
        vector<tuple<int, int, int> > info(T);
        rep(i, T)get<2>(info[i]) = i+1;
        while(R--){
            int tID, pID, tim; string mes;
            cin >> tID >> pID >> tim >> mes;
            tID--; pID--;
            if(mes[0] == 'W')pen[tID][pID]++;
            else{
                get<0>(info[tID])--;
                get<1>(info[tID]) += pen[tID][pID] * 1200 + tim;
            }
        }
        sort(all(info));
        rep(i, T){
            int corr, pena, id; tie(corr, pena, id) = info[i];
            cout << id << ' ' << -corr << ' ' << pena << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
int n,k;
vector<ll> a;
ll dp[110][100010];
ll mod = 1000000007;

int main(){
 cin >> n >> k;
 a.resize(n);
 for(int i = 0; i < n; ++i) cin >> a[i];
 for(int i = 0; i <= n; ++i) dp[i][0] = 1;
  
 for(int i = 1; i <= n; ++i){
   for(int j = 1; j <= k; ++j){
     dp[i][j] = (dp[i - 1][j] + dp[i][j - 1])%mod;
     if(j - a[i - 1] - 1 >= 0){
       dp[i][j] = (dp[i][j] + mod - dp[i - 1][j - a[i - 1] - 1])%mod;
     }
   }
 }
 cout << dp[n][k] << endl;
 return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const int MOD = 1000000007;

char dir[4] = {'L', 'R', 'U', 'D'};
char rev[4] = {'R', 'L', 'D', 'U'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

int H, W, N;
string S, T;

bool check(int sr, int sc, int k) {
    for(int i = 0;i < N;i++) {
        if(S[i] == dir[k]) {
            sr += dy[k], sc += dx[k];
            if(sr > H || sc > W || sr <= 0 || sc <= 0) {
                return true;
            }
        }
        if(T[i] == rev[k]) {
            sr -= dy[k], sc -= dx[k];
            if(sr > H || sc > W || sr <= 0 || sc <= 0) {
                sr += dy[k], sc += dx[k];
            }
        }
    }
    return false;
}

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

    int sr, sc;
    cin >> H >> W >> N;
    cin >> sr >> sc;
    cin >> S >> T;

    bool ans = true;

    for(int i = 0;i < 4;i++) {
        if(check(sr, sc, i)) {
            ans = false;
            break;
        }
    }

    cout << (ans ? "YES" : "NO") << endl;

    return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int a, b, c;
  cin >> a >> b >> c;
  set<int> s;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  if (s.size() == 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;

int main(){
    int N,i,p;
    int *A,*B;
    long long int K,count=0,t,r;
    cin >> N >> K;
    A = new int[N]; 
    B = new int[N];
    for(i=0;i<N;i++) cin >> A[i];
    for(i=0;i<N;i++) B[i]=0;
    p=1;    //いる町
    while(count < K){
        if(B[p-1] != 0){
            r = count - B[p-1];
            break;
        }
        B[p-1] = count;
        p=A[p-1];
        count++;
    }
    t = (K - count) % r;
    while(t > 0){
        p=A[p-1];
        t--;
    }
    cout << p;
}

Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int A,B,C;
	cin>>A>>B>>C;
	
	if(A+B+C<=21)cout<<"win"<<endl;
	else cout<<"bust"<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		
		int n;
		int x;
		int[][] sig  = {
				{0, 1, 1, 1, 1, 1, 1},
				{0, 0, 0, 0, 1, 1, 0},
				{1, 0, 1, 1, 0, 1, 1},
				{1, 0, 0, 1, 1, 1, 1},
				{1, 1, 0, 0, 1, 1, 0},
				{1, 1, 0, 1, 1, 0, 1},
				{1, 1, 1, 1, 1, 0, 1},
				{0, 1, 0, 0, 1, 1, 1},
				{1, 1, 1, 1, 1, 1, 1},
				{1, 1, 0, 1, 1, 1, 1}
		};
		
		int[] ans;
		
		while(true){
			n = scan.nextInt();
			
			if(n == -1)break;
			
			ans = new int[7];
			
			for(int i = 0; i < n; i++){
				x = scan.nextInt();
				for(int j = 0; j < 7; j++){
					if(ans[j] != sig[x][j])ans[j] = 1;
					else ans[j] = 0;
					System.out.print(ans[j]);
					ans[j] = sig[x][j];
				}
				System.out.println();
			}
		}
	}
}

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

char s[10];

int main()
{
	scanf("%s", &s);

	if (s[0] == 'Y') 
	{
		if (s[1] == 'A') 
		{
			if (s[2] == 'K') 
			{
				if (s[3] == 'I') 
				{
					printf("Yes\n");
				}
				else {
					printf("No\n");
				}
			}
			else {
				printf("No\n");
			}
		}
		else {
			printf("No\n");
		}
	}

	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <math.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a + b < 10)
    {
        cout << a + b << endl;
    }
    else
    {
        
        cout << "error" << endl;
    }

    return 0;    
}



Measured memory_bytes: 256
n,m = list(map(int,input().split()))
l_list = [list(map(int,input().split())) for i in range(m)] 
p = list(map(int,input().split()))
output = 0

for i in range(2 ** n):
  lights = []
  for j in range(n+1):
    if ((i >> j) & 1):
      lights.append(j+1)
      
  for k, l in enumerate(l_list):
    if len(set(l[1:]) & set(lights)) % 2 != p[k]:
      break
  else:
    output += 1
print(output)

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

int main()
{
    char hitachi[10]={};
    cin>>hitachi;

    int i,hoge,ans=0;
    for(i=0;i<10;i+=2)
    {
        if(hitachi[i]=='h'&&hitachi[i+1]=='i') ans++;
		else if(hitachi[i]=='\0'&&hitachi[i+1]=='\0')
        {
        	break;
        }
        else
        {
      	    ans++;
            break;
        }
        
    }

    if(ans==i/2)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b, c; cin >> a >> b >> c;
  cout << max(c - a + b, 0) << '\n';
}

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

int rec(int a[], int n, int **mem, int k, int ch)
{
  if(k<0)
    return ch;
  if(k==0)
    return !ch;
  if(mem[k][ch]!=-1)
    return mem[k][ch];
  int ans=!ch;
  for(int i=0;i<n;i++)
  {
    int an=rec(a,n,mem,k-a[i],!ch);
    if(ch==0&&an==0)
    {
      ans=0;
      break;
    }
    else if(ch==1&&an==1)
    {
      ans=1;
      break;
    }
  }
  mem[k][ch]=ans;
  return ans;
}

int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int **mem=new int*[k+1];
  for(int i=0;i<=k;i++)
  {
  	mem[i]=new int[2];
    mem[i][0]=-1;
    mem[i][1]=-1;
  }
  if(rec(a,n,mem,k,0))
	cout<<"Second";
  else
	cout<<"First";

  
}

Measured memory_bytes: 13568
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  int ans[N];
  REP(i,N)ans[i]=0;
  REP(i,M){
    int a,b;
    cin>>a>>b;
    a--;b--;
    ans[a]++;
    ans[b]++;
  }
  REP(i,N)cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
char str[110];
map<int,int> m[128];
int sz[128];
bool ok=true;
int cur;
int expr(){
	if('0'<=str[cur]&&str[cur]<='9'){
		int ret=0;
		while('0'<=str[cur]&&str[cur]<='9'){
			ret*=10;ret+=str[cur]-'0';cur++;
		}
		return ret;
	}
	char t=str[cur];
	cur+=2;
	int val=expr();
	cur++;
	if(!~val||sz[t]<=val||!m[t].count(val))return -1;
	return m[t][val];
}

int main(){
	while(1){
		bool last=true;
		int ret=0;
		int now=1;
		for(int i=0;i<128;i++)m[i].clear();
		for(int i=0;i<128;i++)sz[i]=-1;
		ok=true;
		while(1){
			scanf("%s",str);
			if(str[0]=='.')break;
			if(!ok)continue;
			last=false;
			bool eq=false;
			for(int i=0;str[i];i++)if(str[i]=='=')eq=true;
			if(!eq){
				int num=0;
				int at=2;
				while('0'<=str[at]&&str[at]<='9'){
					num*=10;num+=str[at]-'0';at++;
				}
				sz[str[0]]=num;
			}else{
				cur=2;
				int left=expr();
				cur+=2;
				int right=expr();
				if(left>=sz[str[0]])ok=false;
				if(!~right)ok=false;
				if(~left&&~right)m[str[0]][left]=right;
			}
			if(!ret&&!ok)ret=now;
			now++;
		}
		if(last)break;
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1056
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;
public class Main{
    static int n;
    static double[] prob;
    static double[][] memo;
    public static void main(String[] args) throws IOException {
        scanner sc = new scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        n = sc.nextInt();

        prob = new double[n];
        for (int i = 0; i < n; i++)
            prob[i] = sc.nextDouble();

        memo = new double[n][n+1];

        for (int i = 0; i < n; i++)
            Arrays.fill(memo[i],-1);





         out.println(dp(0,0));
        out.flush();

    }

    static double dp(int i,int heads){
        if (i == n)
            return heads > n/2?1:0;

        if (memo[i][heads] != -1) return memo[i][heads];

        return memo[i][heads] = prob[i]*dp(i+1,heads+1) + (1-prob[i])*dp(i+1,heads);
    }

}
class scanner{
    StringTokenizer st;
    BufferedReader br;
    public scanner(InputStream s){
        br = new BufferedReader(new InputStreamReader(s));
    }
    public scanner (String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s));}

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
        return  Long.parseLong(next());
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public boolean ready() throws IOException {
        return br.ready();
    }
}

Measured memory_bytes: 131536
from collections import deque

h, w = map(int, input().split())
a = [input() for _ in range(h)]
b = ['#' * (w + 1)] * 2
b[1: - 1] = [['#', '#'] for _ in range(h)]
r = 0
for i in range(1, h + 1):
  for j in range(1, w + 1):
    if a[i - 1][j - 1] == '.':
      for x, y in zip(a, b[1:]):
        y[1: -1] = x
      q = deque()
      b[i][j] = 0
      q.append((i, j))
      while(q):
        i, j = q.popleft()
        r = max(r, b[i][j])
        d = 0
        for i1 in range(i - 1, i + 2):
          for j1 in range(j - d, j + 2, 2):                
            if b[i1][j1] == '.':
              b[i1][j1] = b[i][j] + 1
              q.append((i1, j1))
          d ^= 1
print(r)


Measured memory_bytes: 3316
#include<stdio.h>
int main(void){
        int i,j,n,f=0;
        scanf("%d",&n);
        for(i=1;i<=9;i++){
                for(j=1;j<=9;j++){
                if(i*j==n){f=1;break;}
                }
        }
        if(f==1)printf("Yes");
        else printf("No");
 }

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}

const i32 mod = 1000000007;

i32 mod_pow (i32 r, i32 n) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n & 1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

i32 inv (i32 a) {
  return mod_pow (a, mod - 2);
}

i32 *fact = NULL;
i32 *iFact = NULL;
void init_fact (const i32 n) {
  fact = (i32 *) calloc (n + 1, sizeof (i32));
  fact[0] = 1;
  for (i32 i = 1; i <= n; ++i) {
    fact[i] = (i64) i * fact[i - 1] % mod;
  }
  iFact = (i32 *) calloc (n + 1, sizeof (i32));
  iFact[n] = inv (fact[n]);
  for (i32 i = n - 1; i >= 0; --i) {
    iFact[i] = (i64) (i + 1) * iFact[i + 1] % mod;
  }
}

i32 comb (i32 n, i32 k) {
  if (!(0 <= k && k <= n)) return 0;
  return (i64) fact[n] * iFact[k] % mod * iFact[n - k] % mod;
}

void run (void) {
  i32 b, w;
  scanf ("%" SCNi32 "%" SCNi32, &b, &w);
  init_fact (b + w);
  const i32 q = inv (2);
  const i64 buf = (i64) mod * mod;
  i64 ans = q;
  for (i32 i = 1, qq = (i64) q * q % mod; i <= b + w; ++i, qq = (i64) qq * q % mod) {
    print_int (ans);
    putchar ('\n');
    if (i >= b) {
      ans = (ans + buf - (i64) comb (i - 1, b - 1) * qq) % mod;
    }
    if (i >= w) {
      ans = (ans + (i64) comb (i - 1, w - 1) * qq) % mod;
    }
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    if (K > (N - 1) * (N - 2) / 2) cout << -1 << endl;
    else {
        cout << N * (N - 1) / 2 - K << endl;
        for (int i = 1; i < N; i++)
            cout << 1 << " " << i + 1 << endl;
        int cnt = 0, limit = (N - 1) * (N - 2) / 2 - K;
        for (int i = 1; i < N && cnt < limit; i++)
            for (int j = i + 1; j < N && cnt < limit; j++, cnt++)
                cout << i + 1 << " " << j + 1 << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int i,n,s[2000],p[2000],q[2000],r[2000],c[2000],p2,q2,r2,c2,flg;
	scanf("%d",&n);
	while(n!=0){
	    flg=0;
	    for(i=0;i<n;i++){
		    scanf("%d %d %d %d",&s[i],&p[i],&q[i],&r[i]);
			c[i]=p[i]*4+q[i]*9+r[i]*4;
		}
		scanf("%d %d %d %d",&p2,&q2,&r2,&c2);
		for(i=0;i<n;i++){
		    if(p[i]<=p2&&q[i]<=q2&&r[i]<=r2&&c[i]<=c2){
			    printf("%d\n",s[i]);
				flg=1;
			}
		}
		if(flg==0) printf("NA\n");
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 2664
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N;
string S;
int b, w;

int main(){
	cin >> N >> S;
	for (int i = 0; i < N; i++){
		if (S[i] == '.'){
			w++;
		}
	}

	int MIN = w;
	for (int i = 0; i < N; i++){
		if (S[i] == '.')w--;
		if (S[i] == '#')b++;
		if (MIN > (w + b)){
			MIN = (w + b);
		}
	}

	cout << MIN << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;

  int a, b, c, d;
  a = s[0] - '0';
  b = s[1] - '0';
  c = s[2] - '0';
  d = s[3] - '0';
  for (int ops = 0; ops < 8; ops++) {
    int sum = a;
    char op1, op2, op3;
    if (ops & 1) {
      sum += b;
      op1 = '+';
    } else {
      sum -= b;
      op1 = '-';
    }
    if (ops & 2) {
      sum += c;
      op2 = '+';
    } else {
      sum -= c;
      op2 = '-';
    }
    if (ops & 4) {
      sum += d;
      op3 = '+';
    } else {
      sum -= d;
      op3 = '-';
    }
    if (sum != 7)
      continue;

    cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
    break;
  }
}


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

using namespace std;

#define INF 1000000000;

int main()
{
  int n;
  int dp[100010] = {0};

  cin >> n;

  for(int i = 1;i < 100010;i++)
    dp[i] = INF;

  for(int i = 0;i < 100000;i++){
    int si = 6,ni = 9;
    dp[i+1] = min(dp[i+1],dp[i]+1);
    
    for(int j = 1;j < 10;j++){
      if(i+si > n) break;
      dp[i+si] = min(dp[i+si],dp[i]+1);
      si *= 6;
    }

    for(int j = 1;j < 10;j++){
      if(i+ni > n) break;
      dp[i+ni] = min(dp[i+ni],dp[i]+1);
      ni *= 9;
    }
  }

  cout << dp[n] << endl;
  
  return 0;

  
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(void)
{
    int a, b, c;
    char op;

    cin >> a >> op >> b;

    while (op != '?')
    {
        switch (op)
        {
            case '+':
                c = a + b;
                break;
            case '-':
                c = a - b;
                break;
            case '*':
                c = a * b;
                break;
            case '/':
                c = a / b;
                break;
            default:
                break;
        }
        cout << c << endl;
        cin >> a >> op >> b;
    }
}


Measured memory_bytes: 3104
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    high = 0
    ans = 0
    for a in A:
        if high > a:
            ans += high - a
        elif high < a:
            high = a
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 94392
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        String input = new Scanner(System.in).nextLine();
        String[] inputs = input.split("\\s+");
        List<String> sorted = Arrays.stream(inputs).sorted().collect(Collectors.toList());
        System.out.println(sorted.get(0) + " " + sorted.get(1) + " " + sorted.get(2));
    }
}


Measured memory_bytes: 31876
#include <cmath>
#include <cstdio>
const int MAXN = 10;
int X[MAXN][MAXN];
int D, N;

int main() {
    scanf(" %d%d", &N, &D);
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
            scanf("%d", &X[i][j]);
        }
    }
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            int dd = 0;
            for (int k = 0; k < D; ++k) {
                int dk = (X[i][k] - X[j][k]);
                dd += dk * dk;
            }
            int ds = sqrt(dd);
            if (ds * ds == dd) {
                ++cnt;
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 128
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    p = sieve_of_eratosthenes(n+1)
    ansdict = defaultdict(int)
    for i in range(1,n+1):
        for j in p:
            subans = 0
            while i % j == 0:
                ansdict[j] += 1
                i //= j
    ans = 1
    for i in ansdict.values():
        ans *= i+1
        ans %= Mod

    print(ans)
if __name__ == "__main__":
    main() 
    
#endline===============================================
    

Measured memory_bytes: 21896
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define INF 1000000007
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define CLR(a) memset((a), 0, sizeof(a))

using ll = long long;
using ull = unsigned long long;
using namespace std;

ll gcd(ll a, ll b){
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

bool cmp_second(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}




int main(void){

    ll n;
    cin >> n;

    ll a[n];
    ll max = 0;
    ll maxi = 0;
    ll next = 0;
    FOR(i,0,n){
        cin >> a[i];
        if(a[max]<=a[i]){
            max = i;
            next = maxi;
            maxi = a[i];
        }else if(a[i]>next){
            next = a[i];
        }
    }
    FOR(i,0,n){
        if(a[i]!=maxi)cout << maxi << endl;
        else cout << next << endl;
    }

    return 0;
}


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

int main() {

	int n; cin >> n;
	map<string, int> mp;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		mp[s]++;
	}
	int maxCount = 0;
	for (auto u : mp) {
		maxCount = max(maxCount, u.second);
	}
	for (auto u : mp) {
		if (maxCount == u.second) {
			cout << u.first << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 19220
EPS = 1e-9
def dfs(pos, s, t)
  return true if t == $n
  (1..$n).each do |i|
    unless $used[i]
      return false if $dist[i][$n+1] < s + $dist[pos][i] + EPS
    end
  end
  (1..$n).each do |i|
    unless $used[i]
      $used[i] = true
      return true if dfs(i, s + $dist[pos][i], t + 1)
      $used[i] = false
    end
  end
  false
end
 
while l = gets
  $n, x0, y0, x1, y1 = l.split.map(&:to_i)
  break if $n == 0
  ps = $n.times.map { gets.split.map(&:to_i) }
  $ps = [[x0, y0], *ps, [x1, y1]]
  $dist = $ps.map { |x0, y0| $ps.map { |x1, y1| Math.sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2) } }
  $used = [false] * ($n + 1)
  puts dfs(0, 0, 0) ? 'YES' : 'NO'
end

Measured memory_bytes: 8868
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> ii;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lp(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define F          first
#define S          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "Yes\n";
string no = "No\n" ;
const double EPS = 1e-6;
const int inf = 1<<20;
const ll M  = 1e9+7 ;
//const int N = 100100;
//////////////////////    Hi    ^_^  hack me if you can :P


int main()
{
    int n , l , r , ans ;
    cin >> n;
    ff(i,1,n) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}


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

//型定義
typedef long long ll;

//定数
const int INF = 1e+9;
const int MOD = 1e+9 + 7;

//REPマクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP2(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define REPD2(i, a, b) for (ll i = a; i > (ll)(b); i--)

//vectorの扱い
#define ALL(x) (x).begin(), (x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size())      //size
#define MAX(x) *max_element(ALL(x))   //最大値
#define MIN(x) *min_element(ALL(x))   //最小値

//グローバル変数

//ライブラリ挿入

int main()
{
  string s;
  cin >> s;
  int N;
  N = s.size();
  int cnt = 0;
  int ans = 0;
  REP(i, N)
  {
    if (s[i] == 'g')
    {
      if (cnt > 0)
      {
        ans++;
        cnt--;
      }
      else
      {
        cnt++;
      }
    }
    else
    {
      if (cnt > 0)
      {
        cnt--;
      }
      else
      {
        ans--;
        cnt++;
      }
    }
  }
  cout << ans << endl;
}


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

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  for(int i = 0; i < D; ++i) t[i] = i%26;
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  
  // hill climbing
  int lm = 0;
  int sc[26];
  for(;;) {
    if((xor64()>>25)&1) {
      int d = xor64()%D;
      int pi = t[d];
      last[pi].erase(d);
      for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
      int mi = std::max_element(sc, sc+26) - sc;
      t[d] = mi;
      last[mi].insert(d);
      if(mi != pi) lm = 0; else ++lm;
    } else {
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-16 || d2 < d1-16 || t[d1] == t[d2]) {
        d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
        ++lm;
      }
    }
    if(lm >= 1000) break;
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


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

int binarySearch(int A[], int n, int key){
	int mid ,left = 0, right = n;
	while(left < right){
		mid = (left + right) / 2;
		if(A[mid] == key) return 1;
		else if(key < A[mid]) right = mid;
		else left = mid + 1;
	}
	return 0;
}


int main(){
	int n, s[100100], q, key, count = 0;
	int i, j, k;
	
	cin>>n;
	
	for(i = 0; i < n; i++) scanf("%d", &s[i]);
	
	cin>>q;
	
	for(i = 0; i < q; i++){
		 scanf("%d",&key);
		 if(binarySearch(s, n, key)) count++;
	}
	
	cout<<count<<endl;	
	
	return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct SegmentTree {
    struct Node {
        Node operator*(const Node& o) const {
            return { min(v, o.v) };
        }
        int v;
    };

    SegmentTree(int n) : e({ (1U << 31) - 1 }), n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<Node>(m + n + n % 2, e);
    }
    Node& operator[](int i) {
        return t[m + i];
    }
    const Node& root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) {
            t[i] = t[i * 2] * t[i * 2 + 1];
        }
    }
    void update(int i, const Node& o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    Node query(int l, int r) {
        Node o[2] = { e, e };
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (r & 1) o[1] = t[--r] * o[1];
            if (l & 1) o[0] = o[0] * t[l++];
        }
        return o[0] * o[1];
    }
    vector<Node> t;
    const Node e;
    int n, m;
};

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

    int n, q;
    cin >> n >> q;

    SegmentTree st(n);
    for (int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;

        if (c == 0) {
            st.update(x, { y });
        } else {
            y++;
            cout << st.query(x, y).v << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 3936
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N, K = MAP()
a = LIST()

dp = [0]*(K+1)

for i in range(1, K+1):
	for x in a:
		if i - x >= 0 and dp[i-x] == 0:
			dp[i] = 1

if dp[K]:
    print("First")
else:
    print("Second")


Measured memory_bytes: 62824
A, B = map(int, input().split())

minA = int(A//0.08+1)
maxA = int((A+1)//0.08)
minB = int(B//0.1+1)
maxB = int((B+1)//0.1)

if minA <= minB <= maxA :
    print(minB)
elif minB <= minA <= maxB:
    print(minA)
else:
    print("-1")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  long long a,b,n;
  cin >> a >> b >> n;
  long long ans = 0;
  if(b-1 <= n) {
    ans = max(ans,a*(b-1)/b);
  }
  if(b+1 <= n) {
    ans = max(ans,a/b);
  }
  ans = max(ans,a*n/b - a*(n/b));
  if(b == 1) ans = 0;
  cout << ans << endl;
  return 0;
}


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

int main() {
        long long q, h, s, d;
        scanf("%lld%lld%lld%lld", &q, &h, &s, &d);
        long long n;
        scanf("%lld", &n);
        long long one = min({4 * q, 2 * h, s});
        long long ans;
        if (one * 2 <= d) ans = one * n;
        else ans = (n / 2) * d + (n % 2) * one;
        printf("%lld\n", ans);
        return 0;
}



Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

h, w,n = map(int, input().split())
r,c = map(int, input().split())
s = input() #sys.stdin.readlineは最後が改行
t = input() #sys.stdin.readlineは最後が改行

# toR
x=c
for i in range(n):
    if s[i] == 'R' : x+=1
    if x == w+1:
        print('NO')
        exit()
    if t[i] == 'L' and x>1 : x-=1

# toL
x=c
for i in range(n):
    if s[i] == 'L' : x-=1
    if x == 0:
        print('NO')
        exit()
    if t[i] == 'R' and x<w: x+=1

# toU
y=r
for i in range(n):
    if s[i] == 'U' : y-=1
    if y == 0:
        print('NO')
        exit()
    if t[i] == 'D' and y<h: y+=1

# toD
y=r
for i in range(n):
    if s[i] == 'D' : y+=1
    if y == h+1:
        print('NO')
        exit()
    if t[i] == 'U' and y>1: y-=1

print('YES')


Measured memory_bytes: 43248
r1,c1,r2,c2=map(int,input().split())
MOD=10**9+7
idx=r2+c2+3
perm=[1]*(idx+1)
for i in range(1,idx+1):
    perm[i]=perm[i-1]*i
    perm[i]%=MOD
def inv_mod(a):
  return pow(a,MOD-2,MOD)

def comb(n,m,p=10**9+7):
    if n < m : return 0
    if n < 0 or m < 0:return 0
    m = min(m, n-m)
    top = bot = 1
    for i in range(m):
        top = top*(n-i) % p
        bot = bot*(i+1) % p
    bot = pow(bot, p-2, p)
    return top*bot % p
def g(i,j):
    return comb(i+j+2,i+1,MOD)
def s(n,m):
    return comb(n+m+2, m+1, MOD)
res=g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)
res%=MOD

ans = s(r2,c2) - s(r2, c1-1) - s(r1-1, c2) + s(r1-1, c1-1)
ans %= MOD
print(res)

Measured memory_bytes: 55788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll h[2000], w[2000], hsum[2000], wsum[2000];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        ll H, W;
        cin >> H >> W;
        if(H == 0) break;
        map<ll, ll> mp;
        for(int i = 1; i <= H; i++) {
            cin >> h[i];
            hsum[i] = hsum[i-1] + h[i];
        }
        for(int i = 1; i <= W; i++) {
            cin >> w[i];
            wsum[i] = wsum[i-1] + w[i];
        }
        for(int i = 0; i <= H; i++) {
            for(int j = i + 1; j <= H; j++) {
                mp[hsum[j] - hsum[i]]++;
            }
        }
        ll ans = 0;
        for(int i = 0; i <= W; i++) {
            for(int j = i + 1; j <= W; j++) {
                ans += mp[wsum[j] - wsum[i]];
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    double a,b,h,m,angle,ans;
    cin>>a>>b>>h>>m;
    angle=abs(((11*m)-(60*h))/2);
    if(angle>180)
        angle=360-angle;
    //cout<<angle<<nl;
    angle=(PI*angle)/180;
    ans=sq(a)+sq(b)-(2*a*b*cos(angle));
    cout<<fixed<<setprecision(20)<<sqrt(ans)<<nl;
    return 0;
}


Measured memory_bytes: 4216
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()
A = LIST()
B = LIST()

# データの持ち方を座標から区間長にして累積和
A2 = []
for i in range(N-1):
    A2.append(A[i+1] - A[i])
B2 = []
for i in range(M-1):
    B2.append(B[i+1] - B[i])
A2 = [0] + list(accumulate(A2))
B2 = [0] + list(accumulate(B2))

# 縦横独立に、累積和の全区間総和を取る
lsm = rsm = 0
for i in range(N):
    lsm += A2[i] * (N-i-1)
    rsm += A2[i] * i
    lsm %= MOD
    rsm %= MOD
h = rsm - lsm
lsm = rsm = 0
for i in range(M):
    lsm += B2[i] * (M-i-1)
    rsm += B2[i] * i
    lsm %= MOD
    rsm %= MOD
w = rsm - lsm

ans = h * w % MOD
print(ans)


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

long long n,a[200005],r=100000000000000000,pr[200005],p1,p2,p3;

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

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        pr[i]=pr[i-1]+a[i];
    }

    for(long long i=2;i<=n-2;i++)
    {
        p1=upper_bound(pr,pr+n+1,pr[i]/2)-pr;
        p3=upper_bound(pr,pr+n+1,pr[i]+(pr[n]-pr[i])/2)-pr;
        for(int j1=p1-1;j1<=p1;j1++)
            for(int j3=p3-1;j3<=p3;j3++)
            {
                if(j1==0||i<=j1||i>=j3||j3==n)
                    continue;
                else
                    r=min(r,max(pr[j1],max(pr[i]-pr[j1],max(pr[j3]-pr[i],pr[n]-pr[j3])))-min(pr[j1],min(pr[i]-pr[j1],min(pr[j3]-pr[i],pr[n]-pr[j3]))));
            }
    }

    cout<<r<<endl;

    return 0;
}


Measured memory_bytes: 6736
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(5*1e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int from, to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/

int n, a[505], b[505 * 505];
//x番目について、y番目の数字
int x, lo[505], up[505];
P p[505];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		p[i] = { a[i] - 1,i + 1 };
		b[a[i] - 1] = i + 1;
		lo[i + 1] = i;
		up[i + 1] = n - i - 1;
	}
	sort(p, p + n);
	rep(i, n) {
		while (lo[p[i].second]) {
			if (b[x]) {
				if (lo[b[x]]) {
					cout << "No" << endl;
					endre;
				}
				x++;
				continue;
			}
			b[x] = p[i].second;
			x++;
			lo[p[i].second]--;
		}
	}
	x = n * n - 1;
	for (int i = n - 1; i >= 0; i--) {
		while (up[p[i].second]) {
			if (b[x]) {
				if (up[b[x]]) {
					cout << "No" << endl;
					endre;
				}
				x--;
				continue;
			}
			b[x] = p[i].second;
			x--;
			up[p[i].second]--;
		}
	}
	cout << "Yes" << endl;
	rep(i, n*n) {
		cout << b[i] << " ";
	}
	cout << endl;
	endre;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b,int m) {
    if (b==0) return 1;
    ll c = power(a,b>>1,m);
    c = (c*c)%m;
    if (b&1) return (c*a)%m;
    return c;
}
ll powerwithoutmod(ll a,ll b) {
    if (b==0) return 1;
    ll c = powerwithoutmod(a,b>>1);
    c = (c*c);
    if (b&1) return (c*a);
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int Q = 301;
const int logN = 16;

vector<pi> v;
int dig_count(int a) {
    if (!a) return 1;
    int ret = 0;
    while (a>0) {
        ret++;
        a/=10;
    }
    return ret;
}
string int_to_str(int a) {
    if (!a) return "0";
    string ret = "";
    while (a>0) {
        ret += ('0'+(a%10));
        a/=10;
    }
    reverse(all(ret));
    return ret;
}
bool check(int num, int len) {
    if (dig_count(num) != len) return false;
    string s = int_to_str(num);
    for (auto it:v) {
        if (s[it.first] != ('0'+it.second)) {
            return false;
        }
    }
    return true;
}
void solve() {
    int n,m,s,c;
    cin>>n>>m;
    REP(i,1,m) {
        cin>>s>>c;
        v.pb({s-1,c});
    }
    REP(i,0,999) {
        if (check(i,n)) {
            cout<<i;
            return;
        }
    }
    cout<<-1;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 256