akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	static boolean twoCol;
	static int size;
	public static void main(String[] args) {
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		ArrayList<Integer>[] adj = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			adj[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			adj[u].add(v);
			adj[v].add(u);
		}
		int[] col = new int[n];
		long numNonTwoCol = 0;
		long numTwoCol = 0;
		long numSizeOne = 0;
		ArrayList<Integer> sizes = new ArrayList<>();
		ArrayList<Boolean> twoC = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			if (col[i] == 0) {
				twoCol = true;
				size = 0;
				dfs(i, 1, col, adj);
				sizes.add(size);
				twoC.add(twoCol);
				if (size == 1) {
					numSizeOne++;
				}
				else if (twoCol) {
					numTwoCol++;
				}
				else {
					numNonTwoCol++;
				}
			}
		}
		long ans = 0;
		for (int i = 0; i < sizes.size(); i++) {
			int size = sizes.get(i);
			boolean tc = twoC.get(i);
			if(size == 1) {
				ans += n;
				continue;
			}
			if(tc) {
				ans += numNonTwoCol + numSizeOne * size + 2 * numTwoCol;
			} else {
				ans += numNonTwoCol + numSizeOne * size + numTwoCol;
			}
		}
		System.out.println(ans);

	}
	
	static void dfs(int v, int c, int[] col, ArrayList<Integer>[] adj) {
		col[v] = c;
		size++;
		for (int u : adj[v]) {
			if (col[u] == 0) {
				dfs(u, 3-c, col, adj);
			}
			else if (col[u] != 3-c) {
				twoCol = false;
			}
		}
	}

}


Measured memory_bytes: 129508
import sys
N = int(input())
An = []
mul = 1

An = list(map(int,input().split()))
if An.count(0) > 0:
    print("0")
    sys.exit()

for i in An:
    mul *= i
    if mul > 10**18:
        print("-1")
        sys.exit()

if mul <= 10**18:
    print(mul)
    

Measured memory_bytes: 21596
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>

using namespace std;

int main() {
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double h_angle = M_PI / 6 * h + (M_PI / 6) * (m / 60);
	double m_angle = M_PI / 30 * m;
	double c = sqrt(a * a + b * b - 2 * a * b * cos(h_angle - m_angle));
	std::cout << std::fixed << std::setprecision(10);
	cout << c << "\n";
	return 0;
}


Measured memory_bytes: 4192
// C - Sugar Water
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void solve(int w1,int w2, int s1, int s2, int solute, int volume){
	int WS = w1*100, S = 0;
	int wend = volume/100 + 1;
	double maxper = 0.0;
	rp(iw, 1, wend){
		rp(jw, 0, wend){
			int w = w1*iw + w2*jw;
			if(w >= wend) break;
			int send = volume - w*100 + 1;
			rp(is, 0, send){
				rp(js, 0, send){
					int s = s1*is + s2*js;
					if(s >= send) break;
					int ws = w * 100 + s;
					if(ws <= volume && s <= solute*w){
						double per = 100.0*s/ws;
						if(maxper < per){
							maxper = per;
							WS = ws;
							S = s;
						}
					}
				}
			}
		}
	}
	printf("%d %d\n",WS,S);
}

int main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	solve(a,b,c,d,e,f);
}

Measured memory_bytes: 256
S = list(input())
K = int(input())

L = len(S)

a = 1
B = []
for i in range(L-1):
    if S[i] == S[i+1]:
        a += 1
    else:
        B.append(a)
        a = 1
B.append(a)

ans = 0
if S[0] != S[-1]:
    for b in B:
        ans += b // 2
    ans *= K
elif len(B) == 1:
    ans = L*K//2
else:
    for i in range(1, len(B)-1):
        ans += B[i]//2
    ans *= K
    ans += (B[0]+B[-1])//2 * (K-1)
    ans += B[0] // 2
    ans += B[-1] // 2

print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int main(){
    int n,k,s;
    while(cin >> n >> k >> s){
        if(n == 0 && k == 0 && s == 0) break;
        int dp[30][30][200]={};
        for(int i=0; i<=n; i++) dp[i][0][0] = 1;

        for(int i=1;  i<=n; i++){
            for(int j=1; j<=k; j++){
                for(int l=0; l<=s; l++){
                    if(l < i) dp[i][j][l] = dp[i-1][j][l];
                    else dp[i][j][l] = dp[i-1][j][l] + dp[i-1][j-1][l-i];
                    //cout << dp[i][j][l];
                }
                //cout << endl;
            }
        }
        cout << dp[n][k][s] << endl;
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    string str;
    cin >> str;
    ll r=0, g=0, b=0;
    rep(i, n){
        if(str[i] == 'R') r++;
        else if(str[i] == 'B') g++;
        else b++;
    }
    ll res = r*g*b;
    for(int i=1; i<=(n-1)/2; i++){
        for(int j=0; j<n-i*2; j++){
            set<int> st;
            st.insert(str[j]);
            st.insert(str[j+i]);
            st.insert(str[j+i+i]);
            if(st.size() == 3) res--;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<ll> S(N + 1, 0);
    for (int i = 0; i < N; i++) S[i + 1] = S[i] + A[i];
    ll res = 1ll << 60;
    for (int i = 1; i < N - 2; i++) {
      ll lsum = S[i + 1], rsum = S[N] - lsum;
      int x = lower_bound(S.begin(), S.end(), lsum / 2) - S.begin();
      int y = lower_bound(S.begin(), S.end(), lsum + rsum / 2) - S.begin();
      for (int dx = -2; dx <= 2; dx++) {
        for (int dy = -2; dy <= 2; dy++) {
          int nx = x + dx, ny = y + dy;
          if (nx >= 0 && nx < i && i < ny && ny < N - 1) {
            ll p = S[nx + 1];
            ll q = S[i + 1] - p;
            ll r = S[ny + 1] - p - q;
            ll s = S[N] - p - q - r;
            res = min(res, max({p, q, r, s}) - min({p, q, r, s}));
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 3328
using System;

public class Program
{
	public static void Main()
	{
		string[] strs = { "dream", "dreamer", "erase", "eraser" };
		var S = Console.ReadLine();
		int i = S.Length;
		while (i > 0)
		{
			bool flg = false;
			foreach (var str in strs)
			{
				if (i >= str.Length)
				{
					if (S.Substring(i - str.Length, str.Length) == str)
					{
						i -= str.Length;
						flg = true;
					}
				}
			}
			if (!flg)
			{
				Console.WriteLine("NO");
				return;
			}
		}
		Console.WriteLine("YES");
	}
}

Measured memory_bytes: 4568
package main 

import "fmt"

func main() {
	var x [5]int

	for i := 0; i < 5; i++ {
		fmt.Scan(&x[i])
	}

	for i := 0; i < 5; i++ {
		if x[i] == 0 {
			fmt.Println(i + 1)
		}
	}
}

Measured memory_bytes: 1768
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N;

    scanf("%d", &N);

    int C[N], S[N], F[N];

    for(int i = 1; i < N; i++){
        scanf("%d%d%d", &C[i], &S[i], &F[i]);
    }

    for(int k = 1; k < N; k++){
        int t = 0;
        for(int i = k; i < N; i++){
            if(t < S[i]){
                t = S[i];
            }
            for(int j = 0; j < F[i]; j++){
                if((t + j) % F[i] == 0){
                    t += j;
                    break;
                }
            }
            t += C[i];
        }
        printf("%d\n", t);
    }

    printf("0\n");

    return 0;
}

Measured memory_bytes: 1724
#include<iostream>

using namespace std;

int main(void) {
	int n;
	int l[1001], r[1001];
	int total = 0;

	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> l[i] >> r[i];
	}

	for (int i = 1; i <= n; i++) {
		total += (r[i] - l[i] + 1);
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        char pic;       /*?¨????*/
        int i,j,c,n,m,picn,v[4][13]={}; /*n=??????????????£??????????????°,m=??????????????°???*/ /*??????v???????´? 0?????¨????????????,1?????¨?????????*/
        scanf("%d", &n);
        for(i=0; i<n; i++){
                scanf(" %c %d",&pic,&m);
                switch(pic){
                        case 'S':picn = 0; break;       /*????????????*/
                        case 'H':picn = 1; break;       /*?????????*/
                        case 'C':picn = 2; break;       /*?????????*/
                        case 'D':picn = 3; break;       /*?????????*/
                }
                v[picn][m-1] = 1; /*????????¨??????*/
        }

        for(i=0; i<4; i++)
                for(j=0; j<13; j++){
                        switch(i){
                                case 0:pic = 'S'; break;
                                case 1:pic = 'H'; break;
                                case 2:pic = 'C'; break;
                                case 3:pic = 'D'; break;
                        }
                        if(v[i][j] == 0)
                                printf("%c %d\n",pic,j+1);
                }
        return 0;

}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

ll calc(ll x){
    return x*(x+1)/2;
}
void solve(){
    string s;
    cin>>s;
    int n=s.size();
    vector<ll>v;
    ll ans=0;
    rep(i,n){
        ll cnt=1;
        if(s[i]=='>'){
            while(i<n-1&&s[i+1]=='>'){
                ++i;
                ++cnt;
            }
            v.pb(cnt);
        }
        else if(s[i]=='<'){
            while(i<n-1&&s[i+1]=='<'){
                ++i;
                ++cnt;
            }
            v.pb(cnt);
        }
    }
    for(int i=0;i<v.size();++i){
        ans+=calc(v[i]);
    }
    //<>の部分で小さい方を引く
    if(s.front()=='<'){
        for(int i=0;i<v.size()-1;i+=2){
            ans-=min(v[i],v[i+1]);
        }
    }
    else {
        for(int i=1;i<v.size()-1;i+=2){
            ans-=min(v[i],v[i+1]);
        }
    }
    cout<<ans<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

using namespace std;

int main(){

        stack<int> s;
        string op;
        int ans;

        while(cin >> op){

                if(op == "+"){
                        ans = s.top();
                        s.pop();
                        ans += s.top();
                        s.pop();
                        s.push(ans);
                }
                else if(op == "-"){
                        ans = s.top();
                        s.pop();
                        ans -= s.top();
                        s.pop();
                        s.push(-1 * ans);
                }
                else if(op == "*"){
                        ans = s.top();
                        s.pop();
                        ans *= s.top();
                        s.pop();
                        s.push(ans);
                }
                else s.push(atoi(op.c_str()));

        }

        cout << s.top() << endl;

}

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

int main(void) {
	int x,s,m,h;

	scanf("%d",&x);

	s=x%60;
	x=x/60;
	m=x%60;
	h=x/60;

	printf("%d:%d:%d\n",h,m,s);

	return EXIT_SUCCESS;
}



Measured memory_bytes: 2760
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int k;
    cin >> k;
    if (k % 2 == 0 || k % 5 == 0) {
        cout << -1 << endl;
        return 0;
    }
    int num = 7;
    int ans = 1;
    while(1) {
        if (num % k == 0) break;
        num = (num * 10LL + 7LL) % k;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

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

int main() {
    int n;
    cin >> n;
    double h[n];
    repeat(n, i) {
        cin >> h[i];
    }
    int count[6];
    memset(count, 0, sizeof(count));
    repeat(n, i) {
        if (h[i] < 165.0) {
            count[0]++;
        } else if (165.0 <= h[i] && h[i] < 170.0) {
            count[1]++;
        } else if (170.0 <= h[i] && h[i] < 175.0) {
            count[2]++;
        } else if (175.0 <= h[i] && h[i] < 180.0) {
            count[3]++;
        } else if (180.0 <= h[i] && h[i] < 185.0) {
            count[4]++;
        } else {
            count[5]++;
        }
    }
    repeat(6, i) {
        cout << i+1 << ":";
        repeat(count[i], j) {
            cout << "*";
        }
        cout << endl;
    }
    return 0;
}
        

Measured memory_bytes: 0
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W, K = [int(x) for x in input().split()]
    A = [input().strip() for _ in range(H)]

    ans = 0
    for x in range(2 ** H):
        for y in range(2 ** W):
            xset = set()
            yset = set()
            for xx in range(H):
                if x >> xx & 1:
                    xset.add(xx)
            for yy in range(W):
                if y >> yy & 1:
                    yset.add(yy)

            tmp = 0
            for i in range(H):
                if i in xset:
                    continue
                for j in range(W):
                    if j in yset:
                        continue
                    if A[i][j] == "#":
                        tmp += 1

            if tmp == K:
                ans += 1

    print(ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 9408
def solve(l, lmt)
  m = (0..1).map{ Array.new(lmt+1, 0) }
  for v in l
    for j in 0..lmt
      m[1][j] = (j >= v ? [m[0][j-v] + v, m[0][j]].max : m[0][j])
    end
    m.rotate!
  end
  m[0][-1]
end
while n = gets.to_i
  break if n == 0
  l = gets.split.map(&:to_i)
  sum = l.reduce(:+)
  p sum - 2 * solve(l, sum/2)
end

Measured memory_bytes: 8976
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    int digitSum = 0;
    for(int i=0; i<s.size(); i++){
        digitSum -= s.at(i) - 48;
    }
    if(stoi(s)%digitSum==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    elif H%2==0 and W%2==0:
        for i in range(H//2):
            print("#."*(W//2))
            print(".#"*(W//2))
        print()
    elif H%2==0 and W%2==1:
        for i in range(H//2):
            print("#."*((W-1)//2)+"#")
            print(".#"*((W-1)//2)+".")
        print()
    elif H%2==1 and W%2==0:
        for i in range((H-1)//2):
            print("#."*(W//2))
            print(".#"*(W//2))
        print("#."*(W//2))
        print()
    elif H%2==1 and W%2==1:
        for i in range((H-1)//2):
            print("#."*((W-1)//2)+"#")
            print(".#"*((W-1)//2)+".")
        print("#."*((W-1)//2)+"#")
        print()



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

using namespace std;

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

  string s;
  cin >> s;
  int ss = s.size();
  int ans = ss;

  for (int i = 1; i < ss; ++i) {
    if (s[i] == s[i - 1]) {
      --ans;
      i += 2;
    }
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3760
//div 3 c
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
ll mod(ll x)
{
	if(x<0)
	return -x;
	else
	return x;
}
int main()
{
ll n,x,y;
cin>>n>>x>>y;
ll dis[n+1][n+1];
ll ans[n]={0};
for(ll i=1;i<n;i++)
{
	for(ll j=i+1;j<=n;j++)
	{
		dis[i][j]=min(mod(x-i)+mod(y-j)+1,j-i);
		ans[dis[i][j]]++;
    }
}
for(ll i=1;i<n;i++)
{
	cout<<ans[i]<<endl;
}
}

Measured memory_bytes: 30976
type SortDataType=String;
function SortCmp(const a,b:SortDataType):Boolean;forward;
procedure SortImpl(var A:Array of SortDataType;L,R:Longint);
var
	tmp:SortDataType;
	mid,il,ir:Longint;
begin
	if R-L<20 then begin
		for ir:=R-1 downto L+1 do for il:=L to ir-1 do if SortCmp(A[il+1],A[il])then begin
			tmp:=A[il];
			A[il]:=A[il+1];
			A[il+1]:=tmp;
		end;
	end else begin
		mid:=(L+R)div 2;
		if SortCmp(A[mid],A[L])then begin
			tmp:=A[mid];
			A[mid]:=A[L];
			A[L]:=tmp;
		end;
		if SortCmp(A[R-1],A[mid])then begin
			tmp:=A[R-1];
			A[R-1]:=A[mid];
			A[mid]:=tmp;
			if SortCmp(A[mid],A[L])then begin
				tmp:=A[mid];
				A[mid]:=A[L];
				A[L]:=tmp;
			end;
		end;
		il:=L;
		ir:=R-1;
		while il<=ir do begin
			while SortCmp(A[il],A[mid])do inc(il);
			while SortCmp(A[mid],A[ir])do dec(ir);
			if il<ir then begin
				tmp:=A[il];
				A[il]:=A[ir];
				A[ir]:=tmp;
				if mid=il then mid:=ir else if mid=ir then mid:=il;
				inc(il);
				dec(ir);
			end else if il=ir then begin
				inc(il);
				dec(ir);
			end;
		end;
		SortImpl(A,L,il);
		SortImpl(A,il,R);
	end;
end;
procedure Sort(var A:Array of SortDataType;size:Longint);
begin
	SortImpl(A,0,size);
end;
function SortCmp(const a,b:SortDataType):Boolean;
begin
	SortCmp:=a<b;
end;
var
	i,N,cnt:Longint;
	A:Array[1..200000]of String;
begin
	readln(N);
	for i:=1 to N do readln(A[i]);
	sort(A,N);
	cnt:=N;
	for i:=2 to N do if A[i-1]=A[i]then dec(cnt);
	writeln(cnt);
end.


Measured memory_bytes: 58416
#include <bits/stdc++.h>
#define MX 1000000
#define pf printf
#define sf scanf
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define db double
#define fl float
#define ii pair <int,int>
#define ff first
#define ss second
#define pb push_back
#define ps push
#define pp pop()
#define tp top()
#define ft front()
#define cl clear()
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define SA(name,size) sort(name, name+size)
#define SV(name) sort(name.begin(), name.end())
#define RV(name) reverse(name.begin(), name.end());
#define loop(a,n) for(int i=a; i<n; i++)
#define nloop(j,a,n) for(int j=a; j<n; j++)
#define Case int T; scanf("%d", &T); for(int cas = 1; cas <= T; ++cas)
#define CaseF(n) for(int cas=1; cas<=n; cas++)
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pr(x) cout << x << endl
#define pr2(x,y) cout << x << " " << y << endl
#define prln pf("\n")
using namespace std;

/**------------------------------Graph Moves-----------------------------------*/
/* anti-clockwise, starting from 0 degree */
///int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; // 4 direction
///int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1}; //8 direction
///int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1}; //Knight Direction
///int dx[]={2,1,-1,-2,-1,1}; int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction
/*----------------------------------------------------------------------------*/

int bigmod(int n, int pow, int mod){
    if(pow==0) return 1;
    int x=bigmod(n, pow/2, mod);
    x=((x%mod)*(x%mod))%mod;
    if(pow%2==1) x=((x%mod)*(n%mod))%mod;
    return x;
}

inline int getint(){
    int x;
    scanf("%d",&x);
    return x;
}
#define II getint()

inline long long getlonglong(){
    long long x;
    scanf("%lld",&x);
    return x;
}
#define LL getlonglong()

inline float getfloat(){
    float x;
    scanf("%f",&x);
    return x;
}
#define FF getfloat()

inline double getdouble(){
    double x;
    scanf("%lf",&x);
    return x;
}
#define DB getdouble()

inline string getstring(){
    string s;
    cin>>s;
    return s;
}
#define SS getstring()

/**------------------------------------------------------------------------------------------*/

struct point{
    double x,y;
};

int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    Case{
        point p0, p1, p2, p3;
        sf("%lf %lf %lf %lf %lf %lf %lf %lf",&p0.x,&p0.y,&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y);
        /// Eqn 1: Ax+By=C for s1
        db s1A = p0.y-p1.y;
        db s1B = p1.x-p0.x;
        db s1C = s1A*p0.x + s1B*p0.y;
        /// Eqn 2: Ax+By=C for s2
        db s2A = p2.y-p3.y;
        db s2B = p3.x-p2.x;
        db s2C = s2A*p2.x + s2B*p2.y;
        /// Building Matrix using eqn1 and eqn2
        db Det = (s1A*s2B) - (s1B*s2A);
        db x = ( (s1C*s2B)-(s1B*s2C) ) /Det;
        db y = ( (s1A*s2C)-(s1C*s2A) ) /Det;
        if(x==-0) x=0;
        if(y==-0) y=0;
        pf("%.10lf %.10lf\n",x,y);
    }

    return 0;
}


Measured memory_bytes: 3240
#include <stdio.h>
#include <math.h>

#define PI 3.141592653589793

int main(void){
    int a,b,c;
    double s,l,h;
    
    scanf("%d%d%d",&a,&b,&c);
    
    s = sin(c * PI / 180.0)*a*b/2;
    l = a + b + sqrt(a*a + b*b - 2*a*b * cos(c * PI / 180.0));
    h = s/a*2;
    
    printf("%lf %lf %lf\n" ,s,l,h);
    
    return 0;
}


Measured memory_bytes: 2132
n,m = map(int,input().split())
arrk = [list(map(int,input().split())) for i in range(n)]

syoki = [] 
for i in range(1,m+1):
    syoki.append(i)
nasi = []
for i in arrk:
    for j in syoki:
        
        if j not in i[1:]:
            nasi.append(j)
            

print(len(syoki)-len(set(nasi)))


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define all(x)     (x).begin() , (x).end()
typedef long long int ll;
using namespace std;

const ll     mod = 1e9+7;
const double eps = 1e-9;


int n;
const int N=102,nax=1e5+10;
ll w[N] , v[N] , W , dp[N][nax];

void solve(){
    cin >> n >> W;
    for(int i=1;i<=n;++i) {
        cin >> w[i] >> v[i];
        for(int j=0;j<=W;++j) {
            if(j>=w[i])
                dp[i][j] = max(dp[i-1][j] , v[i] + dp[i-1][j-w[i]]);
            else 
                dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[n][W] << "\n";
    
}


int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
        solve();
    return  0;
}


Measured memory_bytes: 81692
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(double.Parse).ToArray();

            double ave = a.Sum() / N;
            int ans = -1;
            double m = INF;
            for(var i = 0; i < N; i++)
            {
                if (Abs(a[i] - ave) < m)
                {
                    m = Abs(a[i] - ave);
                    ans = i;
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }
        
    }
    
    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

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


Measured memory_bytes: 13652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>


int main()
{
  int a,b,c;
  double S,L,lengc,h;
  double PI = acos(-1);


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

  S = 0.5*a*b*sin(c*PI*1/180);

  lengc = sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(c*PI*1/180));

  L = a+b+lengc;

  h = 2*S/a;

  printf("%lf %lf %lf",S,L,h);


  return(0);

}

Measured memory_bytes: 684
n = int(input())
def isPrime(n):
    for ele in range(2,int(n**0.5) +1):
        if n % ele == 0:
            return False
    return True
def main(n):
    if not isPrime(n):
        while True:
            n = n + 1
            if isPrime(n):
                return n
    else:
        return n

print(main(n))

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int n=s[0],w=s[1];
		long[] dp=new long[w+1];
		for(int i=1;i<=n;i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			for(int j=w;j>=q[0];j--){
				dp[j]=Math.Max(dp[j],dp[j-q[0]]+q[1]);
			}
		}
		Console.WriteLine("{0}",dp[w]);
	}
}

Measured memory_bytes: 13792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,tmp=0,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&k);
  rep(i,n) scanf("%d",&a[i]);
  
  qsort(a,n,sizeof(int),upint);
  
  tmp = a[k-1]-a[0];
  result=tmp;
  for(i=k;i<n;i++){
    tmp = zt(a[i],a[i-k+1]);
    result = min(result,tmp);
  }
  //rep(i,n) printf("%d ",a[i]);
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 2556
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
 
ans = sum(B) 
for i in range(N-1):
    if A[i+1] - A[i] ==1:
        ans += C[A[i]-1]
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

template< typename T >
using Edges =vector< edge<T> >;
template< typename T >
using WeightedGraph =vector< Edges<T> >;
using UnWeightedGraph =vector< vector<int> >;
template< typename T >
using Matrix =vector< vector<T> >;

int N, M;
Matrix<int> d;


template< typename T >
///与えられた隣接行列を用いてワーシャルフロイド法によりノード間最短距離を求める。閉路がある場合、ループ後にg[k][k] < 0なるノードkが存在
/// !!!!!!!!!!!!!gでエッジのない部分をINFに, d[i][i] = 0としておくことを忘れないように!!!!!!!!!!!!!
void warshall_floyd(Matrix< T > &g, T INF) {
    for(int k = 0; k < g.size(); k++) {
        for(int i = 0; i < g.size(); i++) {
            for(int j = 0; j < g.size(); j++) {
                if(g[i][k] == INF || g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

int main() {
    
    cin >> N >> M;

    d.resize(N);
    for(auto i = 0; i<N; i++){
        d[i].resize(N,INF);
    }
    
    for(auto i = 0; i<N; i++){
        d[i][i] = 0;
    }
    
    vector<int> st(M,0),gl(M,0),co(M,0);
    int a, b, c;
    Edges<int> path;
    for(auto i = 0; i<M; i++){
        cin >> a >> b >> c;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
        st[i] =a;
        gl[i] = b;
        co[i] = c;
        
    }
    
    warshall_floyd(d, INF);
    
    
    int ans=M;
    for(int i=0;i<M;++i){
        bool shortest=false;
        for(int j = 0; j < N; ++j) {
            if(d[j][st[i]]+co[i]==d[j][gl[i]]) shortest=true;
        }

        if(shortest==true){
            ans=ans-1;
        }
    }
    
    cout <<ans << endl;
    
    return 0;
}









Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define ULL unsigned  long long
#define maxn (LL)1e7
#define INF 0x3f3f3f3f
#define inf 0x7fffffff
#define PI  acos(-1.0)
#define pb push_back
#define re register LL
const double eps = 0.0000001;
using namespace std;
typedef pair<LL,LL> pii;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int flag=0;
    for(int i=0;i<3;i++)
    {
        if(s1[i]==s2[i]) flag++;
    }
    cout<<flag;
}


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

A, B = map(int, input().split())

n = 0

while n<11000:
 n+=1
 x1 = int(n * .08)
 x2 = int(n * .1)
 if A == x1 and B == x2:
     print(n)
     break
else:
    print(-1)

Measured memory_bytes: 2940
from math import tan, atan, degrees, pi
error = 10**(-8)

def calc(th):
    if th > atan(a / b):
        return a**2 * b - a**3 / (2*tan(th))
    else:
        return a * b**2 * tan(th) / 2


a,b,x = map(int, input().split())

left = 0.0
right = pi/2
while right - left > error:
    mid = (left + right) / 2
    if calc(mid) <= x: #まだこぼれてない
        left = mid
    else: #こぼれ始めている
        right = mid

ans = (left + right) / 2
print(90 - degrees(ans))

Measured memory_bytes: 3188
a500 = int(input())
b100 = int(input())
c50 = int(input())
_x = int(input())
answer = 0
for c in range(c50+1):
    for b in range( b100+1):
        for a in range(a500+1):
            #print (a,b,c)
            if a*500 + b*100 + c*50 == _x:
                answer += 1
print (answer)


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
ll T,n,m;
int main() {
	string s;
	cin>>n>>s;
	int cnt = 0;
	for(int i=0;i<n-2;i++)
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
			cnt++;
	cout<<cnt<<endl;
    return 0;
}



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

/*
(R + X) / 2 = G
R + X = 2 * G
X = 2 * G - R
*/

int main() {
  int inNumR = 0;
  int inNumG = 0;
  cin >> inNumR >> inNumG;
  cout << 2 * inNumG - inNumR << endl;
}

Measured memory_bytes: 256
function sum(a, b) {return a + b;}
function multi(a, b) {return a * b;}
function zip(a, b) {
    var z = [];
    for (var i = 0; i < a.length; ++i) {
        z.push([a[i], b[i]]);
    }
    return z;
}

const chunk = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = chunk.trim().split('\n');
const nm = lines.shift().split(' ').map(Number);

const a = lines.slice(0, nm[0]).map(
    function(ai){
        return ai.split(' ').map(Number);
    }
);

const b = lines.slice(nm[0]).map(Number);

const c = a.map(function(ai){
    return zip(ai, b).map(function(aijbi){
        return aijbi.reduce(multi);
    }).reduce(sum);
});

console.log(c.join('\n'));

Measured memory_bytes: 17952
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  int count=0;
  cin >>S;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='+'){
      count++;}
    if(S.at(i)=='-'){
      count--;}}  
  cout<<count<<endl;
}

Measured memory_bytes: 256
def main():
    from bisect import bisect_right as br
    n, d, a = map(int, input().split())
    xh = [list(map(int, input().split())) for _ in [0]*n]
    xh.sort()
    x_list = [x for x, h in xh]
    ac = [0]*(n+1)
    ans = 0
    temp = 0
    for i in range(n):
        j = xh[i][1]-temp
        if j > 0:
            atk_cnt = (j-1)//a+1
            k = br(x_list, x_list[i]+2*d)-1
            ac[i] += a*atk_cnt
            ac[k] -= a*atk_cnt
            ans += atk_cnt
        temp += ac[i]
    print(ans)


main()


Measured memory_bytes: 58072
n = int(input())
p = [float(i) for i in input().split()]

dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i, j in enumerate(p):
    for k in range(n):
        dp[i + 1][k + 1] += dp[i][k] * j
        dp[i + 1][k] += dp[i][k] * (1 - j)
ans = 0
for i in range(n + 1):
    if i > (n - i):
        ans += dp[-1][i]
print(ans)


Measured memory_bytes: 252168
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long dp[][] = new long[65][3];
		dp[0][0] = 1;
		long MOD = 1000000007;
		for(int i=0; i<64; i++) {
			long d = (n>>(63-i))&1;
			if(d==1) {
				dp[i+1][0] += dp[i][0]; //(1,0)(0,1)
				dp[i+1][1] += dp[i][0] + dp[i][1]; //(0,0), (1,1)
				dp[i+1][2] += 2 * dp[i][1] + 3 * dp[i][2]; //(0,0)(1,0)(0,1), (0,0)(1,0)(0,1)(1,1)
			}else {
				dp[i+1][0] += dp[i][0] + dp[i][1]; //(0,0),(1,1)
				dp[i+1][1] += dp[i][1]; //(1,1)
				dp[i+1][2] += dp[i][1] + 3 * dp[i][2];//(0,0), (0,0)(1,0)(0,1)(1,1)
			}
			dp[i+1][0] %= MOD;
			dp[i+1][1] %= MOD;
			dp[i+1][2] %= MOD;
		}
		long ans = dp[64][0] + dp[64][1] + dp[64][2];
		ans %= MOD;
		System.out.println(ans);
		sc.close();
	}

}


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

int main() {
    int n; 
    string s;
    cin >> n >> s;
    vector<int> lb(n), rw(n);
    for (int i=1; i<n; i++) {
        lb[i] = lb[i-1] + (s[i-1]=='#'); 
    }
    for (int i=n-1; i>=0; i--) {
        rw[i] = rw[i+1] + (s[i+1]=='.');
    }
    int ans = 200000;
    for (int i=0; i<n; i++) {
        ans = min(ans, lb[i]+rw[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2180
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[1100];
long long sum[1100];
long long t[1100000];
int sz=0;
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
		sum[i+1]=sum[i]+p[i];
	}
	for(int i=0;i<a;i++){
		for(int j=i;j<a;j++){
			t[sz++]=sum[j+1]-sum[i];
		}
	}
	long long ret=0;
	for(int i=39;i>=0;i--){
		long long ts=ret+(1LL<<i);
		int now=0;
		for(int j=0;j<sz;j++){
			if((ts&t[j])==ts)now++;
		}
		if(now>=b)ret+=(1LL<<i);
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 4224
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

const int MAX_N = 2e2 + 4, inf = 1e9 + 7;
int n;
string s[MAX_N];
int dp[MAX_N][MAX_N];

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> s[i];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            dp[i][j] = inf;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (s[i][j] == '1')
                dp[i][j] = 1;

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

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                if ((dp[i][j] + dp[i][k] + dp[j][k]) % 2 == 1) {
                    cout << "-1\n";
                    return 0;
                }

    int d = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            d = max(d, dp[i][j]);

    cout << d + 1 << "\n";
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Scanner.ReadDoubles();
        Console.WriteLine(inputs[0] / inputs[1]);
    }
}




public class Scanner
{
    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Console.ReadLine()); }
    public static double ReadDouble() { return double.Parse(Console.ReadLine()); }

    public static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Console.ReadLine().Split(' ').Select(_ => double.Parse(_)).ToArray(); }

}

Measured memory_bytes: 13268
#E
from math import gcd
N=int(input())
A=list(map(int,input().split()))
GCD=A[0]
for i in range(1,N):
    GCD=gcd(GCD,A[i])
    
def Fast_PFact(n):
    List=[0 for i in range(n+1)]
    List[1]=1
    for i in range(2,n+1):
        if List[i]==0:
            cnt=1
            while i*cnt<=n:
                List[i*cnt]=i
                cnt+=1
    return List

if GCD==1:
    P=Fast_PFact(10**6)
    L=[False for i in range(10**6+1)]
    flag=False
    for i in range(N):
        a=A[i]
        while a>1:
            if L[P[a]]:
                flag=True
                break
                
            else:
                L[P[a]]=True
                divisor=P[a]
                while divisor==P[a]:
                    a=int(a/divisor)        
    if flag:
        ans="setwise coprime"
    else:
        ans="pairwise coprime"
else:
    ans="not coprime"
print(ans)

Measured memory_bytes: 217780
const [xn, pStr] = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/)
const [x, n] = xn.split(/\s/).map(Number)
const ps = pStr.split(/\s/).map(Number)

const arr = []

for (const p of ps) {
  if (p === x) {
    arr[0] = 3
    continue
  }
  const d = p - x
  const abs = Math.abs(d)
  arr[abs] = (arr[abs] || 0) + (d > 0 ? 1 : 2)
}
for (let i = 0;; i++) {
  const v = arr[i]
  if (v === 3) {
    continue
  }
  if (v === 2) {
    console.log(x + i)
  } else {
    console.log(x - i)
  }
  break;
}

Measured memory_bytes: 29624
import java.util.Scanner;


public class Main {

	Scanner sc;
	final double EPS=1e-7;
	
	int ni(){
		return sc.nextInt();
	}
	
	void io(){
		sc=new Scanner(System.in);
		int n,m;
		while((m=ni())!=0){
			double s1=0;
			int theta;
			int remainder=360;
			for(int i=0;i<m-1;++i){
				theta=ni();
				s1+=Math.sin(Math.toRadians(theta));
				remainder-=theta;
			}
			s1+=Math.sin(Math.toRadians(remainder));
			
			n=ni();
			double s2=0;
			remainder=360;
			for(int i=0;i<n-1;++i){
				theta=ni();
				s2+=Math.sin(Math.toRadians(theta));
				remainder-=theta;
			}
			s2+=Math.sin(Math.toRadians(remainder));
			
			int ans;
			if(Math.abs(s1-s2)<EPS) ans=0;
			else if(s1>s2) ans=1;
			else ans=2;
			System.out.println(ans);
		}
		sc.close();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}

}

Measured memory_bytes: 20948
#ABC051C
x1,y1,x2,y2=map(int,input().split())
for i in range(y2-y1):
    print("U",end="")
for i in range(x2-x1):
    print("R",end="")
for i in range(y2-y1):
    print("D",end="")
for i in range(x2-x1):
    print("L",end="")
print("L",end="")
for i in range(y2-y1):
    print("U",end="")
print("U",end="")
for i in range(x2-x1):
    print("R",end="")
print("RDR",end="")
for i in range(y2-y1):
    print("D",end="")
print("DL",end="")
for i in range(x2-x1):
    print("L",end="")
print("U",end="")

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

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);
#define endl '\n'

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << " ";
	print(args...);
	#endif
}
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 1e6 + 5;

vector<vector<int>> adj, adj2;
int cc[MAXN];
bool v[MAXN];
int cur = 0;
int cnt[MAXN];
int cc_cnt[MAXN];

void dfs(int node){
	if(v[node]) return;

	v[node] = 1;
	cc[node] = cur;
	cc_cnt[cur]++;

	for(auto x : adj[node]){
		dfs(x);
	}
}



int main() {
	//usaco("milkvisits");

	#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
	#endif

	int n, m, k;
	cin >> n >> m >> k;
	adj.assign(n + 1, vector<int>());
	adj2.assign(n + 1, vector<int>());

	for(int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

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

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

	for(int i = 0; i < n; i++){
		if(!v[i]){
			dfs(i);
			cur++;
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < adj2[i].size(); j++){
			if(cc[i] == cc[adj2[i][j]]) cnt[i]++;
		}
	}

	for(int i = 0; i < n; i++){
		cout << cc_cnt[cc[i]] - adj[i].size() - 1 - cnt[i] << " ";
	}
}

Measured memory_bytes: 20096
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;

int main() {
	lli a, b, c, ans=0;
  cin >> a >> b >> c;
  for(lli i=a; i<=b; i++)
  {
    if(i%c==0)
    {
      for(lli j=i; j<=b; j+=c)
      {
        ans++;
      }
      goto A;
    }
  }
  A: cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3580
n = gets.to_i

# 1つ前の位置と時間
pt, px, py = 0, 0, 0
flag = true

n.times do |i|
    t, x, y = gets.split.map(&:to_i)
    # 位置と時間を正規化
    t-=pt
    x-=px
    y-=py
    # 時間で動ける距離以上の場所にはいられない
    if t<x.abs+y.abs then
        flag = false
        break
    end

    # 時間と距離の偶奇があっていない場所にはいられない
    if t%2!=(x.abs+y.abs)%2 then
        flag = false
        break
    end
end

puts flag ? "Yes" : "No"

Measured memory_bytes: 1788
class Contest:
    def __init__(self, member_cost,food_cost,k):
        self.member_cost = member_cost
        self.food_cost   = food_cost
        self.max_training_times = k
        
    def canAchieve(self,target):
        sum_training_times = 0
        for i in range(len(self.member_cost)):
            sum_training_times += max(0,self.member_cost[i] - target//self.food_cost[i])

        return  sum_training_times <= self.max_training_times
        


    def bisect(self,begin,end):
        if (end - begin <= 1 ):
            return end
        target = (begin + end)//2
        if self.canAchieve(target):
            return self.bisect(begin,target)

        else:
            return self.bisect(target,end)




def resolve():
    n,k  = map(int,input().split())
    
    member_cost = list(map(int,input().split()))

    food_cost = list(map(int,input().split()))
    member_cost.sort()
    food_cost.sort(reverse=True)
    total_cost = []
    for i in range(len(member_cost)):
        total_cost.append(member_cost[i]*food_cost[i])

    max_total_cost = max(total_cost)
    contest = Contest(member_cost,food_cost,k)
    print(contest.bisect(-1,max_total_cost))
    
resolve()

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    double a, b, x;
    cin >> a >> b >> x;
    
    double res;
    if(2 * x >= a * a * b){
        double d = 2 * (b - (x / (a * a)));
        res = atan2(d, a);
    }
    else{
        double d = 2 * x / (a * b);
        res = atan2(b, d);
    }

    cout << fixed << setprecision(10);
    cout << res / acos(-1) * 180 << "\n";
}

Measured memory_bytes: 256