akhauriyash/Code-Regression huggingface dataset:
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

typedef struct datum_name{
	int x;
	int y;
	int whosay;
	bool operator==(const datum_name &data) const
	{
		return (x == data.x && y == data.y);
	}
} datum;

typedef vector<datum> all_data;
typedef vector<bool> honest_data;

bool cmp_who(const datum &left, const datum &right) {
	return left.whosay < right.whosay;
}

bool cmp_xval(const datum& left, const datum& right) {
	return left.x < right.x;
}

bool cmp_yval(const datum& left, const datum& right) {
	return left.y < right.y;
}


bool logical_check(all_data data_in, honest_data honest_list) {
	all_data data = data_in;
	for (unsigned int i = 0; i < data.size(); i++) {
		if (honest_list[data[i].whosay-1] == false) {
			data[i].x = 0;
			data[i].y = 0;
		}
	}
	sort(data.begin(), data.end(), cmp_xval);
	data.erase(unique(data.begin(), data.end()), data.end()); // 個人ごとに評価データを抽出
	if (data.size() == 0) return true;
	for (unsigned int i = 0; i < data.size(); i++) {
		if (data[i].x == 0) continue;
		if (honest_list[data[i].x-1] != (bool)(data[i].y)) return false;
	}
	for (unsigned int i = 0; i < data.size() - 1; i++) {
		if (data[i].x == data[i + 1].x) return false;
	}
	return true;
}

int count_false(honest_data& honest_list) {
	int count = 0;
	for (unsigned int i = 0; i < honest_list.size(); i++) {
		if (honest_list[i] == false) count++;
	}
	return count;
}

int main()
{
	int N;
	cin >> N;
	all_data data; //証言データ
	honest_data honest_list;
	honest_list.resize(N);

	for (int i = 0; i < N; i++) {
		int data_num;
		cin >> data_num;

		for (int j = 0; j < data_num; j++) {
			datum tmp_datum;
			cin >> tmp_datum.x >> tmp_datum.y;
			tmp_datum.whosay = i + 1;
			data.push_back(tmp_datum);
		}
		honest_list[i] = true;
	} // read all data
	if (logical_check(data, honest_list)) {
		cout << N << endl;
		return 0;
	}
	int max_num = 0;
	while (true) {
		// falseを増やしながら全探索
		bool upcount = false;
		if (honest_list[0] == true) {
			honest_list[0] = false;
			upcount = false;
		}else { // fale->trueは繰り上がり
			honest_list[0] = true;
			upcount = true;
		}
		for (int i = 1; i < N; i++) {
			if (upcount) {
				honest_list[i] = !(honest_list[i]);
				if (honest_list[i] == false) {
					upcount = false;
					break;
				}
			}
		}
		bool check_res = logical_check(data, honest_list);
		int honest_num = N - count_false(honest_list);
		if (check_res) {
			max_num = max(max_num, honest_num);
		}
		if (honest_num==0) break;
	}
	cout << max_num << endl;
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())

D = np.ones([N, N]) * np.inf
D[np.eye(N, dtype=bool)] = 0

for _ in range(M):
  A, B, C = map(int, input().split())
  D[A-1, B-1] = C
  D[B-1, A-1] = C

D = floyd_warshall(D)
D2 = D <= L

D2 = floyd_warshall(D2)

Q = int(input())
for _ in range(Q):
  s, t = map(int, input().split())
  r = D2[s-1, t-1] - 1
  if r < np.inf:
    print(int(r))
  else:
    print(-1)



Measured memory_bytes: 26956
#include<stdio.h>
int main()
{
	long long a,b;
	while(scanf("%lld %lld",&a,&b)!=EOF)
	{
		long long c;
		c=a+b;
		if(c%3==0||a%3==0||b%3==0)
			printf("Possible\n");
		else
			printf("Impossible\n");
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<ll> a(N);
  for(int i = 0; i < N; ++i){
    cin >> a[i];
  }
  ll tmp = 0;
  for(int i = 0; i < N; ++i){
    if(i%2) tmp -= a[i];
    else tmp += a[i];
  }
  vector<int> x(N);
  x[0] = tmp/2;
  for(int i = 1; i < N; ++i){
    x[i] = a[i-1] - x[i-1];
  }
  for(int i = 0; i < N; ++i){
    if(i) cout << " ";
    cout << 2 * x[i];
  }
  cout << endl;
}


Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
typedef long long ll;

ll   sum = 0;
int  siz;
int  roop   = 0;
bool my_end = false;

vector <int> buf(10, 0);

// 先頭の場所s,+の数がplus_num
int sigma(vector <int> &series, int s, int plus_num, int memorize)
{
    // memorize -> 前回置いた場所の記憶
    // s -> +を置こうとしている場所0
    // plus_num -> あと何個+を置くか2

    // もうplusを置けない -> 失敗(return 0;)
    // cout << "plus_num=" << plus_num << endl;
    if (siz - s - 1 < plus_num) { my_end = true; return 0; }

    // plusを置き終わった時
    if (plus_num == 0) {
        // cout << "fail" << endl;
        for (int j = memorize; j < siz; j++)
        {
            buf.at(roop) += series.at(j) * pow(10, siz - j - 1);
        }

        // bufの記録位置と記録値のチェック
        // cout << "roop=" << roop << endl;
        // cout << "buf.at(roop)=" << buf.at(roop) << endl;

        for (int x : buf)
        {
            sum += x;
        }

        // sum値のチェック
        // cout << "sum=" << sum << endl;

        buf.at(roop) = 0;
        my_end = true;

        return 0;
    }

    // まだ続く -> プラスを置いて、プラスに挟まれた場所の数値を出す
    for (int k = memorize; k <= s; k++)
    {
        buf.at(roop) += series.at(k) * (int) pow(10, s - k);
    }
    // bufの記録位置と記録値のチェック
    // cout << "roop=" << roop << endl;
    // cout << "buf.at(roop)=" << buf.at(roop) << endl;
    roop++;

    // cout << siz - s - 1 << plus_num << endl;

    for (int i = s + 1; i < siz; i++)
    {
        sigma(series, i, plus_num - 1, s + 1);
        if (my_end) { break; }
    }
    my_end = false;


    roop--;
    buf.at(roop) = 0;

    // cout << "sigma脱出" << endl;
    // cout << "-------------------" << endl;

    return 0;
}

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


    string str;
    cin >> str;
    siz = str.size(); // 何桁か確認
    vector <int> series(siz, 0);
    rep(i, siz)
    {
        // 文字列 ->　数値へ変換
        series.at(i) = str.at(i) - 48;
    }

    // +が0個入る
    rep(i, siz) {
        sum += series.at(i) * pow(10, siz - 1 - i);
    }

    // +が1個以上の時の再帰ループ
    for (int i = 1; i < siz; i++)
    {
        rep(j, siz)
        {
            sigma(series, j, i, 0); // +の数i,スタート位置j
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define EB emplace_back
#define PB push_back
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=100005;
int n,dep[N];
int pp,lnk[N],nxt[N*2],to[N*2];
void ae(int k1,int k2){to[++pp]=k2,nxt[pp]=lnk[k1],lnk[k1]=pp;}
void dfs(int k1,int k2){
	dep[k1]=dep[k2]+1;
	for(int i=lnk[k1];i;i=nxt[i])if(to[i]!=k2)dfs(to[i],k1);
}
vector<int>lu;
vector<int>G[N];
bool getlu(int k1,int k2,int k3){
	if(k1==k3){
		lu.EB(k1);
		return 1;
	}
	for(int i=lnk[k1];i;i=nxt[i])if(to[i]!=k2){
		if(getlu(to[i],k1,k3)){
			lu.EB(k1);
			return 1;
		}
	}
	return 0;
}
int main(){
	scanf("%d",&n);
	rep(i,2,n){
		int k1,k2;scanf("%d%d",&k1,&k2);
		ae(k1,k2),ae(k2,k1);
	}
	dfs(1,0);
	int rt1=max_element(dep+1,dep+1+n)-dep;
	dfs(rt1,0);
	int rt2=max_element(dep+1,dep+1+n)-dep;
	getlu(rt1,0,rt2);
	vector<bool>vis(n+1);
	vis[0]=1;
	for(auto k1:lu)vis[k1]=1;
	for(auto k1:lu){
		for(int i=lnk[k1];i;i=nxt[i]){
			if(!vis[to[i]]){
				G[k1].EB(to[i]);
				vis[to[i]]=1;
			}
		}
	}
	if(count(vis.begin(),vis.end(),0)){
		puts("-1");
		return 0;
	}
	vector<int>p1(n+1),p2(n+1);
	int ind=1;
	for(auto k1:lu){
		int cur=ind;
		rep(_,0,SZ(G[k1])-1)p1[ind]=ind+1,++ind;
		p1[ind++]=cur;
	}
	ind=1;
	reverse(lu.begin(),lu.end());
	for(auto k1:lu){
		int cur=ind;
		rep(_,0,SZ(G[k1])-1)p2[ind]=ind+1,++ind;
		p2[ind++]=cur;
	}
	if(p2<p1)p1=p2;
	rep(i,1,n)printf("%d ",p1[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 15500
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
    cin>>a[i];
  ll j=1;
  ll res=0;
  for(ll i =0;i<n;i++)
  {
    if(a[i]==j)
      j++;
    else
      res++;
  }
  if(res==n)
    cout<<-1<<endl;
  else 
    cout<<res<<endl;
  return 0;
}
  

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
ll mod = 1e9 + 7;

int main(){
    ll h,w;
    cin>>h>>w;
    vector<vector<bool> > used(h,vector<bool>(w,false) );
    for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	    char tmp ;
	    cin>>tmp;
	    if(tmp == '.'){
		used[i][j] = true;
	    }
	}
    }

    vector<vector<ll>  > dp(h,vector<ll>(w,0) );
    for(int i=0;i<w;i++)if(used[0][i])dp[0][i] = 1;
    else break;
    for(int i=0;i<h;i++)if(used[i][0])dp[i][0] = 1;
    else break;

    for(int i=1;i<h;i++)
	for(int j=1;j<w;j++){
	    if(used[i][j]) dp[i][j] = ( dp[i][j-1] + dp[i-1][j] )%mod;
	}
    cout<<dp[h-1][w-1]<<endl;
    return 0;
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  for(int i = 0; i <= A; ++i) {
    for(int j = 0; j <= B; ++j) {
      int r = X - 500*i - 100*j;
      if (0 <= r && r/50 <= C) ans++;
    }
  }
      
  cout << ans << endl;
}

Measured memory_bytes: 3568
N = int(input())

# 証言者ごとに整理する
testimony_list = []
for i in range(N):
    array = [-1] * N
    testimony_list.append(array)
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        # iさんの、xさんへの証言
        testimony_list[i][x - 1] = y

max_count = 0
for i in range(2 ** N):
    failed = False
    for j in range(N):
        if not (i >> j & 1):
            continue
        array = testimony_list[j]
        for k in range(N):
            if array[k] != -1 and (i >> k & 1) != array[k]:
                failed = True
                break
    if failed is False:
        max_count = max(max_count, bin(i)[2:].count("1"))
print(max_count)


Measured memory_bytes: 3064
import numpy as np

N, X, Y = map(int, input().split())
X -= 1
Y -= 1

ans = [0 for _ in range(N - 1)]

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]


Measured memory_bytes: 14440
let onesdigit x y = (x + y) mod 10

let rec bottom lst r c = 
  if r = 0 then List.nth lst c
  else onesdigit (bottom lst (r - 1) c ) (bottom lst (r - 1) (c + 1))

let _ =
  try
    while true do
      let lst = List.map int_of_string (Str.split (Str.regexp "") (read_line ())) in
      print_endline @@ string_of_int @@ bottom lst 9 0
    done
  with
    End_of_file -> ()

Measured memory_bytes: 2228
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double W= sc.nextInt();
		double H = sc.nextInt();
		double x = sc.nextInt();
		double y = sc.nextInt();
		int kaisu = 0;
		double square = W * H/2;
		if(x == W/2 && y == H/2) {
			kaisu = 1;
		}
		System.out.println(square + " " + kaisu);
	}
}

Measured memory_bytes: 21844
import sys
if sys.version_info[0]>=3: raw_input=input

def insertionSort(a, g):
    global cnt
    for i in range(g, len(a)):
        v = a[i]
        j = i - g
        while(j >= 0) and (a[j]>v):
            a[j+g] = a[j]
            j -= g
            cnt += 1
            a[j+g] = v


def shellSort(a):
    global cnt
    cnt = 0
    g = []
    h = 1
    while(h <= len(a)):
        g.append(h)
        h = 3*h+1
    g.reverse()
    m = len(g)
    print(m)
    print(' '.join(map(str,g)))
    for i in range(m):
        insertionSort(a, g[i])

a=[int(raw_input()) for i in range(int(raw_input()))]
shellSort(a)
print(cnt)
for e in a: print(e)


Measured memory_bytes: 45512
from sys import stdin
input = stdin.readline


def main():
  A, B = list(map(int, input().split()))

  for i in range(10000):
    if int(i * 0.08) == A and \
       int(i * 0.10) == B:

      print(i)
      return
  print(-1)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 63576
n = int(input())
final = n % 10
if final == 2 or final == 4 or final == 5 or final == 7 or final == 9:
  print("hon")
elif final == 0 or final == 1 or final == 6 or final == 8:
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9116
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;

long long int gg(long long int h) {
	long long int y = 0;
	while (h) {
		y++; h /= 10;
	}
	return y;
}

int main() {
	
	long long int x,y;
	cin >> x;
	long long int ans = 1222;
	for (long long int i = 1; i*i <= x; i++) {
		if (x%i)continue;
		long long int h = max(i,x / i);
		//cout << h << endl;
		ans = min(ans, gg(h));
	}
	cout << ans << endl;

	return 0;

}


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

public class Hello
{
    public static void Main()
    {
        // Your code here!
        
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int sum = a[0] + a[1];
        int sub = a[0] - a[1];
        int mul = a[0] * a[1];
        int[] array = new int[]{sum,sub,mul};
        int max = array[0];
        foreach(var x in array)
        {
            if(x > max)
            {
                max = x;
            }
        }
        Console.WriteLine(max);
        
    }
}

Measured memory_bytes: 13268
A,B=map(int,input().split())
a,b = A,B
Common = 1
for n in range(min(A,B)-1):
  while True:
    if a%(n+2) == 0 and b%(n+2) == 0:
      Common*=n+2
      a/=n+2
      b/=n+2
    else:
      break
print(int(A/Common*B))

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

int main(){
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        std::cin >> a.at(i);
    }

    int numEven = std::count_if(a.begin(), a.end(), [](int i){
            return 0 == i % 2;
            });

    int numFour = std::count_if(a.begin(), a.end(), [](int i){
            return 0 == i % 4;
            });

    int numOdd  = std::count_if(a.begin(), a.end(), [](int i){
            return 1 == i % 2;
            });

    bool flg1 = n == numEven;
    bool flg2 = (std::abs(numFour - numOdd) <= 1) && (n == numFour + numOdd);
    bool flg3 = (numFour == numOdd) && (n == numEven + numOdd);
    
    std::string ans = "No";
    if(flg1 || flg2 || flg3){
        ans = "Yes";
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 640
using System;

public class Hello
{
    public static void Main()
    {
        var team = new char[] { 'B', 'C', 'D', 'E' };
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a1 = int.Parse(line[0]);
            var a2 = int.Parse(line[1]);
            if (a1 == 0 && a2 == 0) break;
            var amax = a1 + a2;  var amaxt = 'A';
            for (int i = 0; i < 4; i++) 
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                var at = int.Parse(line2[0]) + int.Parse(line2[1]);
                if (at> amax) { amax = at; amaxt = team[i]; }
            }
            Console.WriteLine("{0} {1}", amaxt, amax);
        }
    }
}

Measured memory_bytes: 9144
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	l := make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = nextInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(l)))

	ans := 0
	for i := 0; i < n-2; i++ {
		largest := l[i]
		for j := i+1; j < n-1; j++ {
			middle := l[j]
			for k := n-1; k > j; k-- {
				if largest < middle + l[k] {
					ans++
				}
			}
		}
	}

	fmt.Println(ans)
}

Measured memory_bytes: 640
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  int n, a;
  cin >> n >> a;
  YesorNo(n % 500 <= a);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    
    int W,H,x,y,r;
    cin>>W;
    cin>>H;
    cin>>x;
    cin>>y;
    cin>>r;
    if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){cout<<"Yes"<<endl;}
    else{
        cout<<"No"<<endl;
    }
    return 0;}

Measured memory_bytes: 3100
import sys
import numpy as np

def main(N, P):
    minDist = np.ones((N, N), dtype=np.int32)
    isFilled = np.ones((N, N), dtype=np.int32)

    for h in range(N):
        for w in range(N):
            minDist[h][w] = min(h, N - h - 1, w, N - w - 1)

    ans = 0
    for p in P:
        h, w = divmod(p, N)
        ans += minDist[h][w]
        isFilled[h][w] = False

        st = [(h, w)]
        while st:
            h, w = st.pop()
            dist = minDist[h][w] + isFilled[h][w]

            for toH, toW in ((h + 1, w), (h - 1, w), (h, w + 1), (h, w - 1)):
                if 0 <= toH < N and 0 <= toW < N:
                    if minDist[toH][toW] > dist:
                        minDist[toH][toW] = dist
                        st.append((toH, toW))
    return ans

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'i4(i4, i4[:])')(main)
    cc.compile()

if sys.argv[-1] == 'ONLINE_JUDGE':
    cc_export()
    exit(0)
if sys.argv[-1] != 'LOCAL':
    from my_module import main

N = int(input())
P = np.asarray(list(map(lambda a: int(a) - 1, input().split())), dtype=np.int32)

print(main(N, P))


Measured memory_bytes: 56572
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N,ans=1e18 ;
int m[222222];
int ABS(int x){return x>0?x:-x;}
int diff(int a, int b, int c,int d){
    if(a&&b&&c&&d){
        int r=0;
        r = max(r, ABS(a-b));
        r = max(r, ABS(a-c));
        r = max(r, ABS(a-d));
        r = max(r, ABS(b-c));
        r = max(r, ABS(b-d));
        r = max(r, ABS(c-d));
        return r;
    }
    return 1e18;
}
signed main(){
    cin>>N;
    for(int i=1;i<=N;i++){
        int x;
        cin>>x;
        m[i]=m[i-1]+x;
    }
    for(int i=1;i<=N;i++){
        auto p = lower_bound(m+1, m+i+1, m[i]/2); 
        auto q = lower_bound(m+i+1, m+N+1, (m[N]+m[i])/2); 
        int a,b,c,d;
        a = *p;
        b = m[i] - *p;
        c = m[N] - *q;
        d = *q - m[i];
        ans=min(ans,diff(a,b,c,d));
        a = *(p-1);
        b = m[i] - *(p-1);
        c = m[N] - *q;
        d = *q - m[i];
        ans=min(ans,diff(a,b,c,d));
        a = *p;
        b = m[i] - *p;
        c = m[N] - *(q-1);
        d = *(q-1) - m[i];
        ans=min(ans,diff(a,b,c,d));
        a = *(p-1);
        b = m[i] - *(p-1);
        c = m[N] - *(q-1);
        d = *(q-1) - m[i];
        ans=min(ans,diff(a,b,c,d));
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 1792
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;

    cout<<(((n*500)>=m)?"Yes":"No")<<endl;
}


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

int ED(string str1, string str2)
{
  int n1, n2, maxi;
  n1 = (int)(str1.length());
  n2 = (int)(str2.length());

  str1 = '_' + str1; n1++;
  str2 = '_' + str2; n2++;
  //cout << str1 << " " << str2 << "\n";

  //n1 = maxi; n2 = maxi;
  
  int dp[n1][n2], change;

  for(int i = 0; i < n1; i++) {
    for(int j = 0; j < n2; j++) {
      dp[i][j] = 0;
    }
  }

  for(int i = 1; i < n1; i++) {
      dp[i][0] = i;
  }

  for(int i = 1; i < n2; i++) {
      dp[0][i] = i;
  }

  for(int i = 1; i < n1; i++) {
    for(int j = 1; j < n2; j++) {
      if(str1[i] != str2[j]) {
	change = 1;
      }
      else {
	change = 0; 
      }
      dp[i][j] = min({dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + change});
    }
  }

  /*
  for(int i = 0; i < n1; i++) {
    for(int j = 0; j < n2; j++) {
      cout << dp[i][j] << " ";
    }
    cout << "\n";
  }
  */

  return dp[n1-1][n2-1];
}

int main()
{
  string str1, str2;
  cin >> str1;
  cin >> str2;

  cout << ED(str1, str2) << "\n";
 

  return 0;
}




Measured memory_bytes: 7076
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i[] = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main(){
  char z;cin >> z;
  if(z <= 'Z'){
    cout << "A";
  }
  if('a' <= z)cout << "a";
}


Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


//////////////////////////////////////////////////////////////////////////////////////b,cl
int main(){
    int64_t n,k;
    cin >> n >> k;

    int64_t num = n / k;

    int64_t ans = n - num*k;

    ans = min(abs(ans-k),ans);

    cout << ans << endl;
}

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

int main(void) {
	char str[1025];
	char ans[7];
	int i, j;
	int count = 0;
	
	gets(str);
	for (i = 0; i < strlen(str); i++) {
		for (j = 0; str[i+j] != ' ' && str[i+j] != ',' && str[i+j] != '.'; j++) {
			ans[j] = str[i+j];
		}
		if (j >= 3 && j <= 6) {
			ans[j] = '\0';
			if (count != 0)
				putchar(' ');
			printf("%s", ans);
			count++;
		}
		i += j;
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 524
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

ll LCM(ll x , ll y){
	return (x*y) / __gcd(x,y) ;
}

ll NumOfDiv(ll a , ll b , ll k){
	return b/k - a/k + (a%k == 0) ;
}
void start(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int res(int a , int b , int c){
	int x[3] = {a,b,c} ;
	sort(x,x+3);
	return x[1] ;
}

bool chekInt(double n){
    return int(n) == n ;
}

int main()
{
	start();
	int n , d; 
    cin >> n >> d ;
    int x[n][d] ;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> x[i][j] ;
        }
    }
    int c = 0 ;
    for (int i = 0; i < n-1; i++)
    {
        for (int k = i+1; k < n; k++)
        {
            int res = 0;
            for (int j = 0; j < d; j++)
            {
                res += pow(abs(x[i][j] - x[k][j]) , 2) ;
            }
            double f = sqrt(res) ;
            if(chekInt(f)){
                c++ ;
            }
        }
    }
    cout << c << endl;
	return 0 ;
}


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

#define vd vector<double>
 
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
// #define mp make_pair
//#define endl '\n'
 
int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vi a(q+1);
    rep1(i,q){
        cin >> a[i];
    }
    vi points(n+1);
    rep1(i,q){
        points[a[i]]++;
    }
    rep1(i,n){
        points[i] = k - (q - points[i]);
    }
    
    string yes = "Yes";
    string no = "No";
    rep1(i,n){
        if(points[i] > 0){
            cout << yes << endl;
        }
        else{
            cout << no << endl;
        }
    }
    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n;
	cin >> n;
	string s = to_string(n);
	ll sum = 0;
	for(int i = 0; i < s.size(); i++) {
		sum += int(s[i] - 48);
	}
	if(n % sum == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;

    multiset<int, greater<int>> ms;
    rep(i, 0, N)
    {
        int A;
        cin >> A;
        ms.insert(A);
    }

    int ans = 0;

    while (!ms.empty())
    {
        const int x = *ms.begin();
        ms.erase(ms.begin());

        int two = 1;
        while (two <= 2000000000)
        {
            if (two > x) break;
            two *= 2;
        }

        const int y = two - x;
        auto it = ms.find(y);
        if (it != ms.end())
        {
            ++ans;
            ms.erase(it);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 9600
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

candidates = []
for i in range(len(A)):
    for j in range(len(B)):
        for k in range(len(C)):
            if (i+1) * (j+1) * (k+1) <= K:
                candidates.append(A[i] + B[j] + C[k])
            else:
                break
candidates.sort(reverse=True)

for c in candidates[:K]:
    print(c)

Measured memory_bytes: 47192
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n = inp()

V = inlist()

V = sorted(V)
m = V[0]
for i in range(1, n):
    m += V[i]
    m /= 2
print(m)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 1047483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
ll n,m;
vector<vector<ll> >a(100010);
ll color[100010]={};
bool dfs(int col,int now){
  color[now]=col;
  for(int i=0;i<a[now].size();i++){
    if(color[a[now][i]]==col)return false;
    if(color[a[now][i]]==0){
      if(dfs(-col,a[now][i])==false){
	return false;
      }
    }
  }
  return true;
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    ll A,B;cin>>A>>B;
    A--;B--;
    a[A].pb(B);
    a[B].pb(A);
  }
  if(dfs(-1,0)){
    ll red=0,blue=0;
    for(int i=0;i<n;i++){
      if(color[i]>0)
	blue++;
      else if(color[i]<0)
	red++;
    }
    cout<<blue*red-m<<endl;
  }else{
    cout<<n*(n-1)/2-m<<endl;
  }
  return 0;
}


Measured memory_bytes: 7424
using System;
using System.Collections.Generic;
using System.Linq;

public class Pg
{

    static void Main()
    {
        var r = new Reader();
        var cur = r.Read().ToLookup(x => x[0]);
        r.Read().GroupBy(x => x[0])
            .Where(x => cur.Contains(x.Key)).ToDictionary(x => x.Key, x => cur[x.Key].Count() + x.Count())
            .OrderBy(x => x.Key).ToList().ForEach(x => Console.WriteLine("{0} {1}",x.Key,x.Value));
    }
}
class Reader
{
    internal IEnumerable<int[]> Read()
    {
        string line;
        while (!string.IsNullOrEmpty(line = Console.ReadLine()))
            yield return line.Split(',').Select(int.Parse).ToArray();
    }

}


Measured memory_bytes: 16724
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MOD 1000000007

long long int dp[3005][3005];

int main(){
    rep(i,3005) rep(j,3005)  dp[i][j] = 0;
    int n; cin >> n;
    vector<long long int> a(n); rep(i,n) cin >> a[i];
    rep(i,n){
        for(int j=0;j+i<n;j++){
            int len = i + 1;
            bool turn = ((n - len)   % 2 == 0);
            
            if(len == 1){
                if(turn) dp[j][j+i] = a[j];
                else dp[j][j+i] = -a[j];
            }else if (turn){
                dp[j][j+i] = max(a[j] + dp[j+1][j+i], a[j+i] + dp[j][j+i-1]);
            }else{
                dp[j][j+i] = min(-a[j] + dp[j+1][j+i], -a[j+i] + dp[j][j+i-1]);
            }  
            //cout << j <<  ":" << i+j << ":" << dp[j][i+j] <<  endl;
        }
    }
    cout << dp[0][n-1] << endl;
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    vector<int> A{1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                  1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << A[K - 1] << endl;
    return 0;
}

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

// dp[n][s] := n個の数字を使って合計がsのときの組合せ数
int dp[10][110] = {0};

int main(){
	dp[0][0] = 1;
	for(int i = 0; i < 10; i++){
		for(int j = 100; j >= 0; j--){
			for(int k = 9; k >= 1; k--){
				if( j - i >= 0 ){
					dp[k][j] += dp[k - 1][j - i];
				}
			}
		}
	}
	
	int n, s;
	while( cin >> n >> s , n || s ){
		cout << dp[n][s] << endl;
	}
}

Measured memory_bytes: 1164
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower

using namespace std;

int main()
{
    //system("chcp 65001");

    int N;
    string S;
    cin >> S;

    if(S == "Sunny")
    {
        cout << "Cloudy";
    }
    else if(S == "Cloudy")
    {
        cout << "Rainy";
    }
    else if (S == "Rainy")
    {
        cout << "Sunny";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >> c;
    if ((a * 100 + b * 10 + c) %  4 == 0)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}


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

#define ll long long
#define endl "\n"
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define f first
#define s second
#define vecll vector<ll>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<ll,ll>>
#define mapllll map<ll,ll>
#define mapstrll map<string,ll>
#define mapllvecll map<ll,vecll>
#define setll set<ll>
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL); cout.tie(NULL);

using namespace std;

ll const N=1e5+5;
ll const inf=1e18+5;
ll const MOD=1e9+7;

ll t,n,m,x,y,z,w,k;

int main()
{
    fio

    cin>>x>>y>>z>>w;

    while(1)
    {
        z -= y;
        x -= w;

        if(z<=0)
        {
            cout<<"Yes";
            break;
        }
        else if(x<=0)
        {
            cout<<"No";
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007

int main(){
  ll A, B;
  string S, T, U;
  cin >> S >> T >> A >> B >> U;
  
  if(S == U){
    A--;
  } else {
    B--;
  }

  cout << A << endl << B << endl;
  return 0;
}

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

using namespace std;

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

    map<string, int> profit;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        profit[s]++;
    }

    int m;
    cin >> m;

    for (int i = 0; i < m; i++) {
        string t;
        cin >> t;
        profit[t]--;
    }

    int res = 0;
    for (map<string, int>::iterator i = profit.begin(); i != profit.end(); i++) {
        if (res < i->second) {
            res = i->second;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> G(H);
  for(int i=0; i<H; i++){
    cin >> G[i];
  }
  map<char,int> mp;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      mp[G[i][j]]++;
    }
  }
  int cnt_4=0,cnt_2=0,cnt_odd=0;
  for(auto m: mp){
    cnt_4 += m.second/4;
    if(m.second%2){
      cnt_odd++;
    }
  }
  if(cnt_4 >= (H/2)*(W/2)){
    if((H%2 && W%2 && cnt_odd==1) || ((H%2==0 || W%2==0) && cnt_odd==0)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,l,a[3111];
int main()
{
	get2(n,l);
	for(int i=1;i<=n;i++)get1(a[i]);
	
	double dx=0,dy=0;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)
	{
		int num=(j-i-1)*2-(n-2);
		double rad=pi/l*(a[i]+a[j]);
		dx-=cos(rad)*num;dy-=sin(rad)*num;
	}
	dx/=(LL)n*(n-1)*(n-2)/6;
	dy/=(LL)n*(n-1)*(n-2)/6;
	printf("%.10lf %.10lf\n",dx,dy);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	

}
int main(){
  
  ll N,M;
  cin>>N>>M;
  
  cout<<(M*1900+(N-M)*100)*power(2,M)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int a,b;cin>>a>>b;
    int k=b-a-1;
    cout<<k*(k+1)/2-a<<endl;
}


Measured memory_bytes: 256
s=input()
n=len(s)
cnt=0
if n%2==0:
  for i in range(n//2):
    if s[:n//2][::-1][i]!=s[n//2:n][i]:
      cnt+=1
  print(cnt)
else:
  for i in range(n//2):
    if s[:(n-1)//2][::-1][i]!=s[(n+1)//2:n][i]:
      cnt+=1
  print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
string s;
int main()
{
	cin >>s;
	int sum=0;
	for (int i=0;i<s.size();i++) sum+=s[i]-'0';
	cout <<(sum%9==0 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;
ll gcd(ll x, ll y){
  if(y==0)return x;
  else return gcd(y,x%y);
}
int main() {
  string s;
  cin >> s;
  int n=s.size();
  int m=n+1;
  for(int i=0;i<n;i++){
    if(s[i]!=s[i+1]) m=min(m,max(i+1,n-1-i));
  }
  if(m==n+1) cout << n << endl;
  else cout <<m << endl;
  
}

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

string s,t;
ll n,m;

int gcd(int a, int b){
  return b?gcd(b,a%b):a;
}

int main() {
  cin >> n >> m >> s >> t;
  int g = gcd(n,m);
  
    for(int i=0; i<n; i++){
      if(i*m%n==0 && s[i]!=t[i*m/n]){
        cout << "-1" << endl;
        return 0;
      }
    }

  cout << n*m/g << endl;
  return 0;
}

Measured memory_bytes: 764
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long

string s;
map<int,int>lake,last;//gap,node
bool isl[25000]={};//node
int sum=0,hei=0,h[25000]={};//gap
vector<int>L;

int main() {
	cin>>s;
	last.insert({0,0});
	for(int i=1;i<=s.size();i++){
		if(s[i-1]=='\\'){
			hei--;
			h[i]=h[i-1]-1;
			last[hei+1]=i-1;
			last[hei]=i;
		}
		else if(s[i-1]=='/'){
			hei++;
			h[i]=h[i-1]+1;
			if(last.count(hei)){
				sum+=i-last[hei]-1;
				lake.insert({last[hei],i});
			}
		}
		else h[i]=h[i-1];
	}
	int now=-1,len=0;
	for(auto itr=lake.begin(); itr!=lake.end(); itr++){
		auto top = *itr;
		if(top.second<=now)continue;
		now=top.second;
		len=0;
		for(int i=top.first;i<top.second;i++)len+=h[top.first]-h[i];
		L.push_back(len);
	}
	cout << sum << endl << L.size();
	for(int i=0;i<L.size(); i++)cout << " " << L[i];
	cout << endl;
	return 0;
}




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

int main() {
  int q,w,e,r,t;
  cin>>q>>w>>e>>r>>t;
  if(q==0){
    cout<<"1"<<endl;
  }
  else if(w==0){
    cout<<"2"<<endl;
  }
  else if(e==0){
    cout<<"3"<<endl;
  }
  else if(r==0){
    cout<<"4"<<endl;
  }
  else{
    cout<<"5"<<endl;
  }
  
}

Measured memory_bytes: 3588
N = int(input())
p = list(map(int, input().split()))
count = 0


for i in range(0,N-2):
    if p[i] < p[i+1] and p[i+1] < p[i+2]:
        count += 1
    elif p[i] > p[i+1] and p[i+1] > p[i+2]: 
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define N 200100

char s[N];
int n,last,cnt;
int u[N],v[N];

int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	if (s[1]=='0' || s[n]=='1' || s[n-1]=='0') return puts("-1"),0;
	last=1;
	for (int i=2;i<n;i++) if (s[i]=='1')
	{
		if (s[n-i]=='0') return puts("-1"),0;
		for (int j=last;j<i;j++) {
			u[++cnt]=i;
			v[cnt]=j;
		}
		last=i;
	}
	for (int i=last;i<n;i++) u[++cnt]=n,v[cnt]=i;
	for (int i=1;i<n;i++) printf("%d %d\n",u[i],v[i]);
	return 0;
}

Measured memory_bytes: 2304
//Cat Snuke and a Voyage

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a) vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using graph = vector<vector<int>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n,m;cin>>n>>m;
    graph g(200001);
    rep(i,0,m){
        int a,b;cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    if(g[1].size()==0){
        cout<<"IMPOSSIBLE"<<nnn;
        return 0;
    }
    irep(i,g[1]){
        irep(j,g[*i]){
            if(*j==n){
                cout<<"POSSIBLE"<<nnn;
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE"<<nnn;
    return 0;
}

Measured memory_bytes: 12016
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val baisuu = LongArray(n+1) { 1L }
    for (i in 2..n) {
        var j = i
        while(j <= n) {
            baisuu[j]++
            j += i
        }
    }

    var ans = 0L
    for (i in 1..n) {
        ans += i * baisuu[i]
    }
    println(ans)
}


Measured memory_bytes: 114576
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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























int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &v[i]);
    }
    
    int ans = 0;
    for(int i = 0; i <= min(k, n); i++){
        for(int j = 0; j <= min(k - i, n); j++){
            priority_queue<int, vector<int>, greater<int>> que;
            int sum = 0;
            for(int l = 0; l < i; l++){
                que.push(v[l]);
                sum += v[l];
            }
            for(int l = n - 1; l > max(n - 1 - j, i - 1); l--){
                que.push(v[l]);
                sum += v[l];
            }
            int cnt = 0, tmp;
            while(cnt < k - i - j && !que.empty() && (tmp = que.top()) < 0){
                sum -= tmp;
                que.pop();
                cnt++;
            }
            ans = max(ans, sum);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256