akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  


    int a,b,c;
    cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0)
    {
        cout<<0;
    }
    else
    {
        int mn=5e18;
        mn=min(mn,a*b);
        mn=min(mn,b*c);
        mn=min(mn,a*c);
        cout<<mn;
    }
} 


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type Pair struct{ A, B int }

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	pairs := make([]Pair, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&pairs[i].A, &pairs[i].B)
	}
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].A < pairs[j].A
	})

	money := 0
	for i := 0; i < n; i++ {
		if m-pairs[i].B <= 0 {
			money += m * pairs[i].A
			break
		} else {
			money += pairs[i].A * pairs[i].B
			m -= pairs[i].B
		}
	}
	fmt.Println(money)
}


Measured memory_bytes: 6332
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int a[100001],k[100001];
int main(){
while(1){
int d,n,m,s,sum=0;
cin >> d;
if(d==0)
break;
cin >> n;
cin >> m;
for(int i=1;i<n;i++)
cin >> a[i];
for(int i=0;i<m;i++)
cin >> k[i];

a[0]=0;
sort(a,a+n);
a[n]=d;

for(int i=0;i<m;i++){
s=lower_bound(a,a+n+1,k[i])-a;
sum+=min(abs(a[s]-k[i]),abs(k[i]-a[s-1]));
}

cout << sum << endl;
}
return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    vector<char> vec(N);
    for(int i = 0; i < N; i++){
        if(S[i] == "AB"){
            if(A == 0 && B == 0){
                cout << "No" << endl;
                return 0;
            }
            else if(A == 1 && B == 1 && C ==0 && i < N -1 && S[i + 1] == "BC"){
                A--;
                B++;
                vec[i] = 'B';
            }
            else if(A == 1 && B == 1 && C ==0 && i < N -1 && S[i + 1] == "AC"){
                A++;
                B--;
                vec[i] = 'A';
            }
            else{
                if(A > B){
                    A--;
                    B++;
                    vec[i] = 'B' ;
                }
                else{
                    A++;
                    B--;
                    vec[i] = 'A';
                }
            }
        }
        else if(S[i] == "AC"){
            if(A == 0 && C == 0){
                cout << "No" << endl;
                return 0;
            }
            else if(A == 1 && B == 0 && C ==1 && i < N -1 && S[i + 1] == "BC"){
                A--;
                C++;
                vec[i] = 'C';
            }
            else if(A == 1 && B == 0 && C == 1 && i < N -1 && S[i + 1] == "AB"){
                A++;
                C--;
                vec[i] = 'A'; 
            }
            else{
                if(A > C){
                    A--;
                    C++;
                    vec[i] = 'C';
                }
                else{
                    A++;
                    C--;
                    vec[i] = 'A';
                }
            }
        }
        else if(S[i] == "BC"){
            if(C == 0 && B == 0){
                cout << "No" << endl;
                return 0;
            }
            else if(A == 0 && B == 1 && C == 1 && i < N -1 && S[i + 1] == "AC"){
                B--;
                C++;
                vec[i] = 'C'; 
            }
            else if(A == 0 && B == 1 && C == 1 && i < N -1 && S[i + 1] == "AB"){
                C--;
                B++;
                vec[i] = 'B'; 
            }
            else{
                if(C > B){
                    C--;
                    B++;
                    vec[i] = 'B';
                }
                else{
                    C++;
                    B--;
                    vec[i] = 'C';
                }
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 0; i < N; i++) cout << vec[i] << endl;
}

Measured memory_bytes: 6448
use std::io;
use std::str::FromStr;

fn sum(s : &str) -> i32 {
    s.chars().map(|c| c.to_digit(10).unwrap() as i32).sum()
}

fn main() {
    let s = getline();
    let n: i32 = s.parse().ok().unwrap();
    sum(&s);
    println!("{}", if n % sum(&s) == 0 { "Yes" } else { "No" });
}



#[allow(dead_code)]
fn getline() -> String {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().to_string()
}

#[allow(dead_code)]
fn read<T>() -> T where T : FromStr {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn reads<T>() -> Vec<T> where T : FromStr {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}



Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>

int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if (std::abs(a - c) <= d || ((std::abs(a - b) <= d) && (std::abs(b - c) <= d))) {
		printf("%s\n", "Yes");
	} else {
		printf("%s\n", "No");
	}
}



Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const long long INFLL = 2e18;
const int MOD = 1000000007;
int main(){
	int n,m;
	cin >> n >> m;

	priority_queue<tuple<int,int,ll>,vector<tuple<int,int,ll>>,greater<tuple<int,int,ll>>> que;
	for(int i = 0;i < m;i++){
		int l,r;
		ll c;
		cin >> l >> r >> c;
		r--;
		que.push(make_tuple(l,r,c));
	}

	multiset<ll> costs;
	vector<vector<ll>> elase_list(n);
	vector<ll> dp(n,INFLL);
	dp[0] = 0;
	for(int i = 1 ;i < n;i++){
		while(que.size()){
			int l,r;
			ll c;
			tie(l,r,c) = que.top();
			if(l != i)break;
			que.pop();
			if(dp[i-1] != INFLL){
				costs.insert(dp[i-1] + c);
				elase_list[r].push_back(dp[i-1] + c);
			}
		}
		if(costs.size())dp[i] = *costs.begin();
		for(int j = 0;j < elase_list[i].size();j++){
			auto p = costs.find(elase_list[i][j]);
			costs.erase(p);
		}
	}

	if(dp[n-1] != INFLL)cout << dp[n-1] << endl;
	else cout << -1 << endl;
}


Measured memory_bytes: 11684
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T; 
  cin >> S >> T; 
if(S.at(0) == T.at(2) && S.at(1) == T.at(1) && S.at(2) == T.at(0))
  cout << "YES" << endl;
  else cout << "NO" << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


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

  int a,b;
  cin>>a>>b;
  cout<<a*b-a-b+1<<endl;


}

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

int main(){

	long int h, w;

	scanf("%ld %ld", &h, &w);
	long int total = 0;

	int b_even_h = h % 2;	// 縦が偶数か even == 0
	int b_even_w = w % 2;	// 横が偶数か even == 0

	total = (h*w)/2;

	if(b_even_h == 1) {
		if(b_even_w == 1) {
			total += 1;
		}
	}
	
	if(h == 1 || w == 1) {
		total = 1;
	}

	printf("%ld\n", total);

	return 0;

}


Measured memory_bytes: 128
module UF
	implicit none
	private
	type Union_Find
		integer(8), allocatable :: par(:), rank(:), counter(:)
	end type Union_Find
	public Union_Find, make_Union_Find, unite, UF_size, root,  same
	
	contains
	
	subroutine make_Union_Find(UFty, N)
		integer(8), intent(in)           :: N
		type(Union_Find), intent(out) :: UFty
		allocate(UFty%par(1:N), UFty%rank(1:N), UFty%counter(1:N))
		call format_Union_Find(UFty, N)
	end subroutine make_Union_Find
	
	subroutine format_Union_Find(UFty, N)
		integer(8), intent(in)             :: N
		type(Union_Find), intent(inout) :: UFty
		integer(8) :: i
		do i = 1, N
			UFty%par(i) = i
		end do
		UFty%rank    = 0
		UFty%counter = 1
	end subroutine format_Union_Find
	
	subroutine unite(UFty, x, y)
		integer(8), value                  :: x, y
		type(Union_Find), intent(inout) :: UFty
		x = root(UFty, x)
		y = root(UFty, y)
		if(x == y) return
		if(UFty%rank(x) < UFty%rank(y)) then
			UFty%par(x)     = y
			UFty%counter(y) = UFty%counter(y) + UFty%counter(x)	
		else
			UFty%par(y)     = x
			UFty%counter(x) = UFty%counter(x) + UFty%counter(y)	
			if(UFty%rank(x) == UFty%rank(y)) UFty%rank(x) = UFty%rank(x) + 1
		end if
	end subroutine unite
	
	function UF_size(UFty, x) result(y)
		integer(8), intent(in)             :: x
		type(Union_Find), intent(inout) :: UFty
		integer(8) :: y
		y = UFty%counter(root(UFty, x))
		return
	end function UF_size
	
	recursive function root(UFty, x) result(root_ans)
		integer(8), intent(in)             :: x
		type(Union_Find), intent(inout) :: UFty
		integer(8) :: root_ans
		if(UFty%par(x) == x) then
			root_ans = x
			return
		else
			UFty%par(x) = root(UFty, UFty%par(x))
			root_ans    = UFty%par(x)
			return
		end if
	end function root
	
	logical function same(UFty, x, y)
		integer(8), intent(in) :: x, y
		type(Union_Find), intent(inout) :: UFty
		if(root(UFty, x) == root(UFty, y)) then
			same = .TRUE.
		else
			same = .FALSE. 
		end if
	end function same
end module UF	

program main
	use UF
	implicit none
	integer(8) :: N, M, i
	integer(8), allocatable :: A(:), B(:)
	integer(8), allocatable :: ans(:)
	type(Union_Find) :: Island
	read(*, *) N, M
	allocate(A(1:M), B(1:M), ans(1:M))
	do i = 1, M
		read(*, *) A(i), B(i)
	end do
	
	
	call make_Union_Find(Island, N)
	
	ans(M) = (N*(N-1)) / 2
	do i = M, 2, -1
		if(same(Island, A(i), B(i))) then
			ans(i-1) = ans(i)
		else
			ans(i-1) = ans(i) - UF_size(Island, A(i))*UF_size(Island, B(i))
		end if
		call unite(Island, A(i), B(i))
	end do
	do i = 1, M
		write(*, *) ans(i)
	end do
end program main

Measured memory_bytes: 7040
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K[] = new int[N];
    int A[][] = new int[N][M];
    for (int i = 0; i < N; i++) {
      K[i] = sc.nextInt();
      for (int j = 0; j < K[i]; j++) {
        A[i][j] = sc.nextInt();
      }
    }
    int ans = 0;
    if (N == 1) {
      System.out.println(K[0]);
      return;
    }
    for (int j = 0; j < A[0].length; j++) {
      int tmp = A[0][j];
      int count = 0;
      for (int i = 1; i < N; i++) {
        for (int k = 0; k < K[i]; k++) {
          if (A[i][k] == 0) {
            break;
          }
          if (tmp == A[i][k]) {
            count++;
            break;
          }
        }
      }
      if (count == N - 1) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  int K,S;
  cin >> K >> S;
  int count=0;
  for(int x=0; x<=K; x++){
    for(int y=0; y<=K; y++){
      int z=S-x-y;
      if(z>=0 && z<=K){
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
N,K= map(int,input().split())
p=10**9+7
q=0
 
def calc(n,k):
  if k==1:
    return n+1
  else:
    maxi = k*n- k*(k-1)//2
    mini=  k*(k-1)//2
    #print(k,maxi,mini,maxi-mini+1)
    return maxi-mini+1
  
ans=0
for i in range(K,N+2):
  ans = ( ans+calc(N,i) )%p
  
print(ans)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    string s;
    ll q;
    cin >> s >> q;
    
    ll cnt_1 = 0;
    rep(i,0,q){
        ll query,f;
        char c;
        cin >> query;
        if(query == 1){
            cnt_1 ^= 1;
        }
        else{
            cin >> f >> c;
            f--;
            f ^= cnt_1;
            s.insert((f?s.end():s.begin()),c);
        }
    }

    if(cnt_1){
        rep(i,0,s.size()) cout << s[s.size()-i-1];
        cout << endl;
    }
    else cout << s << endl;
    return 0;
}

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

int main() {
  int N;
  std::cin >> N;
  std::vector<std::vector<int>> a(N + 3, std::vector<int>(N + 3, 0));
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      std::cin >> a[i][j];

  int mod = 1000000007;

  std::vector<std::vector<long long>> dp(
      N + 3, std::vector<long long>((1 << N) + 3, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int k = 0; k < 1 << N; ++k) {
      if (i != __builtin_popcount(k))
        continue;
      // int c = 0;
      // for (int j = 0; j < N; ++j)
      //   if (k & (1 << j))
      //     c += 1;
      // if (c != i)
      //   continue;

      for (int j = 0; j < N; ++j) {
        if (k & (1 << j))
          continue;
        dp[i + 1][k | (1 << j)] += a[i][j] * dp[i][k];
        dp[i + 1][k | (1 << j)] %= mod;
      }
    }
  }
  std::cout << dp[N][(1 << N) - 1] << std::endl;
}


Measured memory_bytes: 409984
from collections import defaultdict

H,W = map(int, input().split())
S = [input() for _ in range(H)]

es = defaultdict(list)
for i in range(H):
    for j in range(W):
        # 横
        if j != W-1 and S[i][j] != S[i][j+1]:
            es[(i,j)].append((i,j+1))
            es[(i,j+1)].append((i,j))

        # 縦
        if i != H-1 and S[i][j] != S[i+1][j]:
            es[(i,j)].append((i+1,j))
            es[(i+1,j)].append((i,j))


ans = 0
checked = [[False for _ in range(W)] for _ in range(H)]

stack  = es.keys()
for i,j in stack:
    # 開始位置
    if checked[i][j]:
        continue
    
    if S[i][j] == "#":
        cnt_b = 1
        cnt_w = 0
    else:
        cnt_b = 0
        cnt_w = 1


    checked[i][j] = True
    ns = es[(i,j)]
    #tmp = []
    while ns:
        tmp = []
        for a,b in ns:
            if checked[a][b] == True: continue

            checked[a][b] = True
            if S[a][b] == "#":
                cnt_b += 1
            else:
                cnt_w += 1

            for c,d in es[(a,b)]:
                if not checked[c][d]:
                    tmp.append((c,d))
        if len(tmp) > 0:
            ns = tmp
        else:
            ns = []            
    ans += cnt_b * cnt_w


print(ans)


Measured memory_bytes: 86712
#include <stdio.h>
#define INFTY 1000000001

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int cnt = 0;

int main(){
  int A[500001];
  int n, left, right;
  int i;

  scanf("%d", &n);

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

  left = 0;
  right = n;

  
  mergeSort(A, left, right);

  for(i = 0; i < n; i++){
    printf("%d", A[i]);

    if(i < n - 1) printf(" ");
    else printf("\n");
  }

  printf("%d\n", cnt);
  
  return 0;
  
}

void merge(int *A, int left, int mid, int right){
  int i, j, k;
  int L[250001], R[250001];
  int n1, n2;
  
  n1 = mid - left;
  n2 = right - mid;
  
  for(i = 0; i < n1; i++){
    L[i] = A[left + i];
  }



  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  
  L[n1] = INFTY;
  R[n2] = INFTY;

  i = 0;
  j = 0;

  for(k = left; k < right ; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];

      i++;
    }

    else{
      A[k] = R[j];

      j++;
    }

    cnt++;
  }
}

void mergeSort(int *A, int left, int right){
  int mid;
  int i;
  
  
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}



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

// @@ !! LIM(sieve)
// --> sieve
// ---- inserted library file sieve.cc

// sieve(upto) returns the list of prime numbers up to upto.
//   Size: upto(1e8).size() ... 5.7e6,  upto(1e9).size() ... 5.1e7
//   Performance: upto(1e8) ... 0.7sec,   upto(1e9) ... 9.2sec
vector<int> sieve(int upto) {
  vector<int> res;
  vector<bool> tbl(upto+1);
  ll lim = (int)(sqrt((double)upto)) + 1;
  for (int x = 2; x <= upto; x++) {
    if (tbl.at(x))  continue;
    res.push_back(x);
    if (x > lim)  continue;
    for (int y = x * 2; y <= upto; y += x) tbl.at(y) = true;
  }
  return res;
}

/*
  Prime Factorization
    Two versions:
      - prfac(n)
      - prfac(n, primes)
            primes should contain prime numbers at least up to sqrt(n)
 */

const vector<int> dummy_primes;

vector<pair<ll, int>> prfac(ll n, const vector<int>& primes = dummy_primes) {
  vector<int> tmp_primes;
  if (primes.size() == 0) {
    tmp_primes = sieve((int)sqrt((double)n) + 1);
  }
  const vector<int>& prms = primes.size() == 0 ? tmp_primes : primes;

  vector<pair<ll, int>> res;
  ll x = n;
  for (ll p : prms) {
    if (x == 1)  break;
    if (p * p > x)  break;
    if (x % p != 0)  continue;
    int c = 1;
    x /= p;
    while (x % p == 0) {
      c += 1;
      x /= p;
    }
    res.push_back(make_pair(p, c));
  }
  if (x != 1)  res.push_back(make_pair(x, 1));
  return res;
}

/*
vector<pair<ll, int>> prfac(ll n) {
  return prfac(n, sieve((int)(sqrt((double)n)) + 1));
}
*/

/*
    List of divisors
      - getDivisors(n)
      - getDivisors(n, primes)
            primes should contain prime numbers at least up to sqrt(n)
    Note: the results are NOT sorted
 */

// gdsub ... aux function used in getDivisors()
vector<ll> gdsub(int i, int n, auto fs) {
  if (i == n) { return vector<ll>({1}); }
  auto part = gdsub(i+1, n, fs);
  ll p  = fs.at(i).first;
  int r = fs.at(i).second;
  ll pp = p;    // pp = p^m, for m \in [1, r]
  int partOrigLen = part.size();
  for (int m = 1; m <= r; m++) {
    for (int j = 0; j < partOrigLen; j++) {
      part.push_back(pp * part.at(j));
    }
    pp *= p;
  }
  return part;
}

vector<ll> getDivisors(ll n, const vector<int>& primes = dummy_primes) {
  auto fs = prfac(n, primes);
  return gdsub(0, fs.size(), fs);
}

/*
vector<ll> getDivisors(ll n) {
  auto fs = prfac(n);
  return gdsub(0, fs.size(), fs);
}
*/

// ---- end sieve.cc
// @@ !! LIM  -- end mark --

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> vec(101);
  for (ll i = 2; i <= N; i++) {
    for (auto [p, r] : prfac(i)) {
      vec[p] += r;
    }
  }
  ll u = 0;
  ll v = 0;
  ll w = 0;
  ll x = 0;
  ll y = 0;
  for (ll i = 0; i <= 100; i++) {
    if (vec[i] >= 2) u++;
    if (vec[i] >= 4) v++;
    if (vec[i] >= 14) w++;
    if (vec[i] >= 24) x++;
    if (vec[i] >= 74) y++;
  }
  ll ans = 0;
  ans += v * (v - 1) / 2 * (u - 2);
  ans += w * (v - 1);
  ans += x * (u - 1);
  ans += y;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3604
'use strict'
const main = (input: string) => {
    const std: string[] = input.split('\n')
    const n = ~~std.shift()
    const w: number[] = std.shift().split(' ').map(Number)
    let abs: number = Infinity;
    for (let i = 1; i < n; i++) {
        let u: number = w.slice(0, i).reduce((c,v) => c+v,0)
        let p: number = w.slice(i).reduce((c,v) => c+v,0)
        abs = Math.min(Math.abs(u-p), abs)
    }
    console.log(abs)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())

Measured memory_bytes: 7624
def d_maze_master(INF=float('inf')):
    from collections import deque
    H, W = [int(i) for i in input().split()]
    Maze = [list(input()) for _ in range(H)]

    def bfs(start_row, start_col):
        diff = ((-1, 0), (0, 1), (1, 0), (0, -1))

        def is_inside(row, col):
            return 0 <= row < H and 0 <= col < W

        queue = deque([(start_row, start_col)])
        dist = [[INF for _ in range(W)] for _ in range(H)]
        dist[start_row][start_col] = 0
        while queue:
            row, col = queue.pop()
            for dr, dc in diff:
                nr, nc = row + dr, col + dc
                if is_inside(nr, nc) and Maze[nr][nc] != '#' and dist[nr][nc] == INF:
                    queue.appendleft((nr, nc))
                    dist[nr][nc] = dist[row][col] + 1
        return dist

    ans = 0
    for start_row in range(H):
        for start_col in range(W):
            if Maze[start_row][start_col] == '#':
                continue
            dist = bfs(start_row, start_col)
            for row in range(H):
                for col in range(W):
                    if Maze[row][col] != '#':
                        ans = max(ans, dist[row][col])
    return ans

print(d_maze_master())

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

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

using namespace std;

typedef long double ld;
typedef complex<ld> P;
typedef vector<P> VP;
const ld eps = 1e-8, pi = acos(-1.0);

#define EQ(a,b) (abs((a)-(b))<eps)

ld dot (P a, P b) { return real(conj(a) * b); }
ld cross (P a, P b) { return imag(conj(a) * b); }

struct L{ P a, b; };

P proj(L l, P p) {
  ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
  return l.a + t * (l.a - l.b);
}

P mirror(L l, P p) {
  return (ld)2 * proj(l, p) - p;
}

P is_ll(L s, L t){
  P sv = s.b - s.a, tv = t.b - t.a;
  return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

VP calc(VP lhs, VP rhs) {
  if (lhs.size() == 1) {
    if (rhs.size() == 1) {
      lhs.push_back(rhs[0]);
      return lhs;
    } else {
      return VP(1, mirror((L){rhs[0], rhs[1]}, lhs[0]));
    }
  } else {
    if (rhs.size() == 1) {
      return VP(1, mirror((L){lhs[0], lhs[1]}, rhs[0]));
    } else {
      return VP(1, is_ll((L){lhs[0], lhs[1]}, (L){rhs[0], rhs[1]}));
    }
  }
}

pair<int, int> num(const string &s, int i) {
  int v = 0;
  bool neg = false;
  if (s[i] == '-') {
    neg = true;
    ++i;
  }
  while(i < s.size() && '0' <= s[i] && s[i] <= '9') {
    v *= 10;
    v += s[i] - '0';
    ++i;
  }
  return make_pair(neg ? -v : v, i);
}

pair<VP, int> expr(const string &s, int i);

pair<VP, int> factor(const string &s, int i) {
  assert(s[i] == '(');
  if (s[i+1] == '(') {
    auto res = expr(s, i+1);
    ++res.second;
    return res;
  } else {
    auto lhs = num(s, i+1);
    auto rhs = num(s, lhs.second + 1);
    P p(lhs.first, rhs.first);
    return make_pair(VP(1, p), rhs.second + 1);
  }
}

pair<VP, int> expr(const string &s, int i) {
  VP res;
  tie(res, i) = factor(s, i);
  while(i < s.size() && s[i] == '@') {
    auto rhs = factor(s, i+1);
    res = calc(res, rhs.first);
    i = rhs.second;
  }
  return make_pair(res, i);
}

int main() {
  while(1){
    string s;
    cin>>s;
    if(s=="#") break;
    auto res = expr(s, 0).first;
    cout << setprecision(10) << fixed << real(res[0]) << ' ' << imag(res[0]) << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
	string s;
	cin >> s;
	map<char, int> mp;
	for (int i = 0; i < s.length(); i++) {
		mp[s[i]]++;
	}
	for (int i = 0; i < s.length(); i++) {
		if (mp[s[i]] % 2 == 1) {
			cout << "No" << endl;

			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

double dist(double x,double y) {
    return sqrt(x*x+y*y);
}

int main() {
    int n,d; std::cin>>n>>d;
    int ans=0;
    for(int i=0;i<n;++i) {
        double x,y; std::cin>>x>>y;
        if(dist(x,y)<=d)++ans;
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <vector>
 
void printArray(std::vector<int> a) {
  int n = (int)a.size();
  for (int i = 0; i < n; i++) {
    std::cout << a[i] <<std::endl; 
  }
}
 
int insertionSort(std::vector<int> &a, int g) {
  int cnt = 0, n = (int)a.size();
  for (int i = g; i < n; i++) {
    int v = a[i];
    int j = i - g;
    while (j >= 0 && a[j] > v) {
      a[j + g] = a[j];
      j = j - g;
      cnt++;
    }
    a[j + g] = v;
  }
  return cnt;
}
 
int shellSort(std::vector<int> &a) {
  std::vector<int> g;
  for (int i = 1; i <= (int)a.size(); i = i * 3 + 1) {
    g.push_back(i);
  }
  int m = (int)g.size();
  std::cout << m << std::endl;
 
  int cnt = 0;
  for (int i = m - 1; i >= 0; i--) {
    cnt += insertionSort(a, g[i]);
 
    std::cout << g[i];
    if (i > 0)
      std::cout << " ";
    else
      std::cout << std::endl;
  }
 
  return cnt;
}
 
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
 
  std::cout << shellSort(a) << std::endl;
  printArray(a);
}


Measured memory_bytes: 10712
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    nums = [i for i in range(n+1)]
    sums = [0]
    ans = 0
    x = 10**9 + 7
    for i in range(n):
        sums.append(nums[i+1]+sums[i])
    for j in range(k, len(nums)+1):
        if j == len(nums):
            ans += 1
        else:
            ans += sums[-1] - sums[-(1+j)] - sums[j-1] + 1
    print(ans%x)   

if __name__ == '__main__':
    main()

Measured memory_bytes: 27188
n = int(input())
A = []
for i in range(n):
  a = int(input())
  A.append(a)
m = max(A)
c = A.count(m)

if len(set(A)) > 1:
	m2 = sorted(set(A))[-2]

bool = False
if c == 1:
  bool = True

for i in A:
  if bool and i==m:
    print(m2)
  else:
    print(m)

Measured memory_bytes: 21016
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli a, b, c;
int main() {
  cin >> a >> b >> c;
  for (lli i=0; i<1000000; ++i) {
    if (a%2!=0 || b%2!=0 || c%2!=0) {
      cout << i << endl; return 0;
    }
    lli x, y, z;
    x = (b+c)/2;
    y = (c+a)/2;
    z = (a+b)/2;
    a = x; b = y; c = z;
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())
diffx,diffy = x2-x1,y2-y1
x3,y3 = x2-diffy, y2+diffx
x4,y4 = x3-diffx, y3-diffy
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int main()
{
    fsscan();
    int N,T;
    cin>>N>>T;
    int res=INT_MAX;
    while(N--)
    {
        int c,t;
        cin>>c>>t;
        if(t<=T)
        {
            res=min(res,c);
        }
    }
    if(res==INT_MAX)
    cout<<"TLE";
    else
    cout<<res;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    return gcd(y, x % y) if y!=0 else x

def F(init, add):
    w = [0]
    for i in range(init, init + add * N, add):
        w += [gcd(w[-1], A[i])]
    return w[:-1]

print(max(map(lambda x,y:gcd(x,y), F(0, 1), F(N-1, -1)[::-1])))


Measured memory_bytes: 14076
from sys import stdin, setrecursionlimit
from math import cos, pi

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


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

minutes = H * 60 + M
angle = abs((12*M-minutes)/720)
ans = (A**2 + B **2 - 2 * A * B * cos(angle * 2  *pi)) ** 0.5
print(ans)

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

using namespace std;

int main(){
  string s, ans = "yes";
  cin >> s;
  for(int i=0;i<s.size()-1;i++){
	for(int j=i+1;j<s.size();j++){
      if(s[i]==s[j]){
        ans = "no";
        break;
      }
	}
    if(ans=="no")break;
  }
  cout  << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define INF INT_MAX
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
   cin.tie(0);  
   ios::sync_with_stdio(false);
   int n;
   cin>>n;
   cout<<n*n*n<<endl;
   return 0;
}



Measured memory_bytes: 256
let gcd m n =
  let rec doit x y =
    if y <= 0 then x
    else doit y (x mod y)
  in
  if m > n then doit m n
  else doit n m

let () =
  Scanf.scanf "%d %d\n" (fun a b -> Printf.printf "%d\n" (gcd a b))

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

int main() {
  int i, n;
  int s=0;
  string s0, s1, s2;
  cin >> n >> s0;
  
  if(n==0||n%2==1){
    cout << "No" << endl;
  }
  else{
    for(i=0;i<n/2;i++){
      s1=s0.at(i);
      s2=s0.at(i+n/2);
      if(s1==s2){
        s++;
      }
    }
    if(s==n/2){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

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

int main() {
	// your code goes here
	int n,k;
	cin>>k>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	}
    int ans=k-(a[n-1]-a[0]);
    
    for(int i=0;i<n-1;i++)
    ans=max(ans,a[i+1]-a[i]);
    cout<<k-ans<<"\n";
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  int a1=1,a2=1;
  while(1){
    c=c-b;
    if(c<=0){
      a1=0;
      break;
    }
    a=a-d;
      if(a<=0){
        a2=0;
        break;
      }
    }
    
    
  if(a1==0){
    printf("Yes");
  }
  else if(a2==0){
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

int main()
{
    int N, D;
    cin >> N >> D;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        long long x, y;
        cin >> x >> y;
        if (sqrt(x * x + y * y) <= D)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll N, L, lst, tmp, flg = -1;
    cin>>N>>L;
    cin>>lst;
    for(int i=1;i<N;i++){
        cin>>tmp;
        if(lst+tmp>=L)flg=i;
        lst = tmp;
    }
    if(flg==-1){
        cout<<"Impossible"<<endl;
        return 0;
    }
    cout<<"Possible"<<endl;
    for(ll i=1;i<flg;i++)cout<<i<<endl;
    for(ll i=N-1;i>flg;i--)cout<<i<<endl;
    cout<<flg<<endl;


    return 0;
}


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

import sys

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 = INT()
A = LIST()

A.sort(reverse=1)
cur = [A[0]]
# 作成済を-1とする
A[0] = -1

for _ in range(N):
    cur.sort(reverse=1)
    nxt = cur[:]
    j = 0
    for i, a in enumerate(A):
        if a == -1:
            continue
        if a < cur[j]:
            # 大きい要素から順に、まだ作っていない大きい要素を作っていく
            nxt.append(a)
            A[i] = -1
            j += 1
            # この世代は作り終わった
            if j == len(cur):
                break
    else:
        # 子要素を作れない要素があった
        No()
        exit()
    cur = nxt[:]
Yes()


Measured memory_bytes: 34248
text_st = input()
text_ab = input()
u = input()

def get(text,n):
    ans = [""]*n
    i = 0
    for x in text:
        if x==" ":
            i = i + 1
        ans[i] = ans[i]+x
    return ans

s = get(text_st,2)[0]
t = get(text_st,2)[1]
a = int(get(text_ab,2)[0])
b = int(get(text_ab,2)[1])

if u ==s:
    a = a-1
else:
    b = b-1

print(str(a)+" "+str(b))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int s[200000], t[200000];
vector<int> g[601];
bool vis1[601][601], vis2[601][601];
double P1[601][601], P2[601][601];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=m;i++){
        scanf("%d%d", &s[i], &t[i]);
        g[s[i]].push_back(t[i]);
    }

    vis1[1][0] = 1;
    P1[1][0] = 1;
    for(int u=1;u<=n;u++){
        for(int d=0;d<=n;d++){
            if(vis1[u][d]){
                int sz = g[u].size();
                for(int i=0;i<sz;i++){
                    int v = g[u][i];
                    P1[v][d+1] += P1[u][d]*1/sz;
                    vis1[v][d+1] = 1;
                }
            }
        }
    }

    vis2[n][0] = 1;
    P2[n][0] = 1;
    for(int u=n-1;u>=1;u--){
        for(int d=1;d<=n;d++){
            int sz = g[u].size();
            for(int i=0;i<sz;i++){
                int v = g[u][i];
                if(vis2[v][d-1]){
                    P2[u][d] += P2[v][d-1];
                    vis2[u][d] = 1;
                }
            }
            P2[u][d] /= sz;
        }
    }

    double ans = 0, tmp = 0;
    for(int i=0;i<=n;i++) ans += P1[n][i]*i;
    tmp = ans;

    int cnt = 0;
    for(int u=1;u<=n;u++){
        if(g[u].size() <= 1) continue;

        double res = tmp, mx = 0;
        int sz = g[u].size();
        for(int i=0;i<sz;i++){

            cnt++;
            int v = g[u][i];

            long double Px = 0, Py = 0, p1 = 0, p2 = 0;
            for(int d1=0;d1<=n;d1++){
                if(!vis1[u][d1]) continue;
                Px += P1[u][d1]*d1;
                p1 += P1[u][d1];
            }

            for(int d2=0;d2<=n;d2++){
                if(!vis2[v][d2]) continue;
                Py += P2[v][d2]*(d2+1);
                p2 += P2[v][d2];
            }
            
            double sum = Px*p2 + Py*p1;
            res += sum/(sz-1) - sum/sz;
            mx = max(mx, sum/(sz-1));
        }
        ans = min(ans, res-mx);
    }
    printf("%.10f\n", ans);
}

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

using Graph = vector<vector<int>>;

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

    Graph G(N);
    vector<int> ans(N);
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist(N, -1);
    vector<int> cl(N, -1);
    queue<int> que;

    dist[0] = 0;
    cl[0]=true;
    que.push(0);

    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (int next_v : G.at(v))
        {
            if (dist.at(next_v) != -1)
                continue;

            dist.at(next_v) = dist.at(v) + 1;
            cl.at(next_v) = v;
            que.push(next_v);
        }
    }

    for (int i = 1; i < N; i++){
            if(cl.at(i)==-1){
                cout << "No" << endl;
                return 0;
            }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < N; i++)
            cout << cl.at(i)+1 << endl;

    return 0;
}


Measured memory_bytes: 11024
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int n,k;
	string s;
	cin>>n>>k;
	cin>>s;
	s[k-1]=s[k-1]+32;
	cout<<s<<endl;
 	
	return 0;
}
 	
 					

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a < 9 && b < 9) cout << "Yay!" << endl;
    else cout << ":(" << endl;
 }

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

ll mod_pow (ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main () {
    int N; cin >> N;
    map<int, int> m;
    rep(i, N) {
        int a; cin >> a;
        m[a]++;
    }
    bool flg = false;
    for (auto i : m) {
        // printf("(%d, %d)\n", i.first, i.second);
        if (i.first == 0 && i.second > 1) flg = true;
        else if (i.first != 0 && i.second != 2) flg = true;
    }

    if (flg) cout << 0 << endl;
    else cout << mod_pow(2, N/2) << endl;
}

Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n;cin>>n;
    int a[n];
    double avg=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        avg+=a[i];
    }
    avg=(double)avg/(double)n;
    double sub=1000000;
    int ans=-1;
    for(int i=0;i<n;i++){
        if(sub>abs(a[i]-avg)){
            sub=abs(a[i]-avg);
            ans=i;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int MOD = 1e9 + 7;

void add(int &x, int y) {
  x += y;
  if (x < 0) x += MOD;
  if (x >= MOD) x-= MOD;
}
int mul(int x, int y) {
  return (1LL * x * y) % MOD;
}

void solve() {
  int n; cin >> n;
  int sum = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    int v; cin >> v;
    add(ans, mul(sum, v));
    add(sum, v);
  }
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


Measured memory_bytes: 3592
// #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//functions: set.insert(val), *(set.find_by_order(order-1)), set.order_of_key(val)

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

const ll mod = 1e9+7;
const ll N = 1e6+6;
const ll maxN = 1e5+5;
const ll MAX_SIZE = 2e6+6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = mod){ // default argument
ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;}

ll power(ll x, ll y){
ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;}

int numLen(int K) 
{ 
	// If K is a multiple of 2 or 5 
	if (K % 2 == 0 || K % 5 == 0) 
		return -1; 
	int number = 0; 
	int len = 1; 
	for (len = 1; len <= K; len++) { 
		// Instead of generating all possible numbers 
		// 1, 11, 111, 111, ..., K 1's 
		// Take remainder with K 
		number = (number * 10 + 1) % K; 
		// If number is divisible by k 
		// then remainder will be 0 
		if (number == 0) 
			return len; 
	} 
	return -1; 
} 

int main()
{
    //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    //#endif
    FIO
    int k;
    cin>>k;
    if(k%7==0)
		k=k/7;
	cout << numLen(k); 
    return 0;
}

Measured memory_bytes: 3688
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 110;

int n,p;
int a[maxn];
ll f[maxn][2];

int main()
{
	scanf("%d%d",&n,&p);
	f[0][0]=1ll;
	for(int i=1;i<=n;i++)
	{
		int x; scanf("%d",&x); x&=1;
		f[i][0]=f[i-1][0],f[i][1]=f[i-1][1];
		if(x) f[i][1]+=f[i-1][0],f[i][0]+=f[i-1][1];
		else f[i][1]+=f[i-1][1],f[i][0]+=f[i-1][0];
	}
	printf("%lld\n",f[n][p]);
	
	return 0;
}


Measured memory_bytes: 256
import math
II=input().split()
A = int(II[0])
B = int(II[1])
H = int(II[2])
M = int(II[3])
a=H/12*360 + M/60/12*360
b = M/60*360
# print(a,b)
# print((A*math.sin(math.radians(a)) - B*math.sin(math.radians(b))))
# print((A*math.cos(math.radians(a)) - B*math.cos(math.radians(b))))
dist = math.sqrt((A*math.sin(math.radians(a)) - B*math.sin(math.radians(b)))**2 + (A*math.cos(math.radians(a)) - B*math.cos(math.radians(b)))**2)
print(dist)
# print(math.sin(math.radians(a)))
# print(math.sin(math.radians(b)))
# print(math.cos(math.radians(a)))
# print(math.cos(math.radians(b)))







Measured memory_bytes: 9456
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char *argv[])
{
    char S[101];
    long long K;
    long long tdup, idup, edup, duptmp;
    int i;

    tdup = 1;
    idup = 0;
    edup = 0;

    scanf("%s", S);
    scanf("%lld", &K);

    for (i=0; i<strlen(S)-1; i++) {
        if (S[i]==S[i+1]) {
            tdup++;
        }
        else
        {
            break;
        }
        
    }
    if(i<strlen(S)-1) {
        duptmp = 1;
        for(; i<strlen(S)-1; i++) {
            if (S[i]==S[i+1]){
                duptmp++;
            }
            else {
                idup += duptmp/2;
                duptmp = 1;
            }
        }
        if (duptmp>0) {
            edup = duptmp;
        }
    }
//    printf("t %lld i %lld e %lld tmp %lld\n", tdup, idup, edup, duptmp);

    if (tdup==strlen(S)) {
        printf("%lld\n", tdup*K/2);
    }
    else if (S[0]!=S[strlen(S)-1])
        printf("%lld\n", (tdup/2+idup+edup/2)*K);
    else {
//        printf("%lld %lld %lld %lld\n", tdup/2 ,idup * K, (tdup+edup)/2*(K-1) ,edup/2);
        printf("%lld\n", tdup/2 + idup * K + (tdup+edup)/2*(K-1) + edup/2);
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

double n,transfer[5],min_trans;
ll res;

int main()
{

    cin >> n ;
    for (int i = 0 ; i <= 4 ; i ++) cin >> transfer[i];
    min_trans = *min_element(transfer, transfer + 5);
    //cout << min_trans << endl;
    //cout <<(long dou-ble)(n/min_trans)<< endl;
    res = ceil((double)(n/min_trans)) + 4;
    cout << res;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 1002;
const ll M = 21;
ll n,a[N],q,m,dp[21*2001];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	FOR(i,0,21*2001)dp[i]=0;
	cin>>n;
	FOR(i,0,n)cin>>a[i];
	vector<ll> v;
	set <ll> s;
	s.insert(0);
	v.push_back(0);
	FOR(i,0,n){
		ll pp=v.size();
		FOR(j,0,pp){
			if(s.count(v[j]+a[i])==0){
				s.insert(v[j]+a[i]);
				v.push_back(v[j]+a[i]);
			}
		}
	}
	cin>>q;
	FOR(i,0,q){
		cin>>m;
		if(s.count(m)==1){
			cout<<"yes"<<endl;
		}else{
			cout<<"no"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;

int paths(bool **mat, int r, int c)
{
    //can go only right and down
    int dp[r][c];
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for (int i = 1; i < r; i++)
    {
        if (!mat[i][0])
            break;
        dp[i][0] = dp[i - 1][0];
    }

    for (int j = 1; j < c; j++)
    {
        if (!mat[0][j])
            break;
        dp[0][j] = dp[0][j - 1];
    }

    for (int i = 1; i < r; i++)
    {
        for (int j = 1; j < c; j++)
        {
            if (!mat[i][j])
                continue;

            if (mat[i - 1][j])
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
            if (mat[i][j - 1])
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
        }
    }
    return dp[r - 1][c - 1];
}

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    bool **mat = new bool *[n];
    for (int i = 0; i < n; i++)
    {
        mat[i] = new bool[m];
        for (int j = 0; j < m; j++)
        {
            char ch;
            cin >> ch;
            mat[i][j] = (ch == '.' ? true : false); //1 for path and 1 for no path
        }
    }

    printf("%d\n", paths(mat, n, m));
    return 0;
}

Measured memory_bytes: 5120