akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int N,K,inf = 2e9;
int A[100010],B[100010],even[100010] = {0},visited[100010] = {0},ans[100010];
vector<vector<int>> v(100010);
bool judge = true;


void dfs1(int n,int mod){
	visited[n] = 1;
	even[n] = mod;
	if(A[n]!=-inf && A[n]%2!=mod) judge = false;
	for(int i=0;i<v[n].size();i++){
		int s = v[n][i];
		if(visited[s]==0){
			dfs1(s,1-mod);
		} 
	}
}

void dfs2(int n){
	visited[n] = 1;
	int ma = B[n],mi = A[n];
	for(int i=0;i<v[n].size();i++){
		int s = v[n][i];
		if(visited[s]==0){
			int s = v[n][i];
			dfs2(s);
			if(ma<A[s]-1 || B[s]+1<mi) judge = false;
			else if(A[s]-1<=mi && ma<=B[s]+1) continue;
			else if(mi<=A[s]-1 && B[s]+1<=ma){
				ma = B[s]+1;
				mi = A[s]-1;
			}
			else if(ma>=B[s]+1 && B[s]+1>=mi){
//				mi = max(A[s]-1,mi);
				ma = B[s]+1;
//				ma = min(B[s]+1,ma);
			}else{
				mi = A[s]-1;
			}
			if(ma<mi) judge = false;
		}
	}
	if(ma==mi && ma%2!=even[n]) judge = false; 
//	if(ma!=inf){
		B[n] = ma;
		A[n] = mi;
//	}
}

void write(int n,int t){
	visited[n] = 1;
	if(t+1<=B[n]) ans[n] = t+1;
	else ans[n] = t-1;
/*	if(A[n]==B[n]) ans[n] = A[n];
	else if(A[n]==-inf) ans[n] = t+1;
	else if(t<A[n]) ans[n] = A[n];
	else if(t>B[n]) ans[n] = B[n];
	else{
		if(t+1<=B[n]) ans[n] = t+1;
		else ans[n] = t-1;
	}*/
	for(int i=0;i<v[n].size();i++){
		int s = v[n][i];
		if(visited[s]==0){
			write(s,ans[n]);
		}
	}
}

int main(){
	cin >> N;
	for(int i=1;i<=N;i++){
		A[i] = -inf;
		B[i] = inf;
		even[i] = -1;
	}
	int a,b;
	for(int i=0;i<N-1;i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	cin >> K;
	for(int i=0;i<K;i++){
		cin >> a >> b;
		A[a] = b;
		B[a] = b;
		even[a] = b%2;
	}
	dfs1(a,even[a]);
	if(!judge){
		cout << "No" << endl;
		return 0;
	}
	for(int i=1;i<=N;i++) visited[i] = 0;
	dfs2(1);
	if(!judge) cout << "No" << endl;
	else{
		for(int i=1;i<=N;i++) visited[i] = 0;
		if(A[1]==-inf){
//			ans[1] = even[1];
			write(1,even[1]-1);
		}
		else if(A[1]%2==even[1]){
//			ans[1] = A[1];
			write(1,A[1]-1);
		}
		else if(A[1]%2!=even[1]){
//			ans[1] = A[1]+1;
			write(1,A[1]);
		}
		cout << "Yes" << endl;
		for(int i=1;i<=N;i++){
			cout << ans[i] << endl;
		}
	}
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int N,K;
vector<int> x,y; //入力
vector<int> xx,yy; //位置がソートされる
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>N>>K;
    
    for(int i=0;i<N;i++){
        int a,b;
        cin>>a>>b;
        x.push_back(a); y.push_back(b);
        xx.push_back(x[i]); yy.push_back(y[i]);
    }
    
    sort(xx.begin(),xx.end());
    sort(yy.begin(),yy.end());
    
    ll ans=1ll*(xx[N-1]-xx[0])*(yy[N-1]-yy[0]);
    
    for(int xi=0;xi<N;xi++){
        for(int xj=xi+1;xj<N;xj++){
            for(int yi=0;yi<N;yi++){
                for(int yj=yi+1;yj<N;yj++){
                    int lx=xx[xi],rx=xx[xj]; //左、右
                    int by=yy[yi],uy=yy[yj]; //下、上
                    
                    int num=0;
                    for(int i=0;i<N;i++){
                        if(lx<=x[i]&&x[i]<=rx
                           &&by<=y[i]&&y[i]<=uy) num++;
                    }
                    if(num>=K)
                        ans=min(ans,1ll*(rx-lx)*(uy-by));
                }
            }
        }
    }
    
    cout<<ans<<"\n";
    
    
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Checkpoints
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	a := make([]float64, N)
	b := make([]float64, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%f %f", &a[i], &b[i])
	}

	c := make([]float64, M)
	d := make([]float64, M)
	for i := 0; i < M; i++ {
		fmt.Scanf("%f %f", &c[i], &d[i])
	}

	var ans int
	for i := 0; i < N; i++ {
		min := 1000000000
		for j := 0; j < M; j++ {
			temp := int(math.Abs(a[i]-c[j]) + math.Abs(b[i]-d[j]))
			if min > temp {
				min = temp
				ans = j + 1
			}
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 1844
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

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

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// 別の書き方を使ってみる

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n, q;
vector<int> p, x;
vector<int> cnts;

vector<int> hd; // max_n
vector<int> nxt, to; // 2*max_n
int edge_cnt;
void add_edge(int u, int v) { // u to v
    edge_cnt++; // 辺が1つ増える
    to[edge_cnt] = v; // edge_cnt本目の辺の行き先はv
    nxt[edge_cnt] = hd[u]; // edge_cnt本目の辺の次に見る(uから出る)辺は、はじめに見ていた(uから出る)辺であるhd[u]本目の辺
    hd[u] = edge_cnt; // 新しくはじめに見る(uから出る)辺はedge_cnt本目の辺
}

void dfs(int cur = 0, int parent = -1)
{
    for (int e = hd[cur]; e > 0; e = nxt[e]) {
       int child = to[e];
       if (child == parent) { continue; }
       cnts[child] += cnts[cur];
       dfs(child, cur);
   }
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10); // 浮動小数の表示の精度

    cin >> n >> q;
    p.resize(q);
    x.resize(q);
    cnts.resize(n);
    hd.resize(n);
    nxt.resize(2*n);
    to.resize(2*n);
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        add_edge(a,b);
        add_edge(b,a);
    }
    rep(j, q)
    {
        cin >> p[j] >> x[j];
        p[j]--;
    }

    // q回足す
    rep(j, q)
    {
        cnts[p[j]] += x[j];
    }

    // 集計
    dfs();

    rep(i, n)
    {
        cout << cnts[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 21916
#!/usr/bin/env python3

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

if A > B:
    ans = 0
elif N == 1:
    ans = 1 if A == B else 0
else:
    min_total = A * (N - 1) + B
    max_total = B * (N - 1) + A
    ans = max_total - min_total + 1

print(ans)


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

int main(){

long long N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;

long long minv = min({A, B, C, D, E});
  
long long time = ((N + minv - 1) / minv) + 4; 

cout << time << endl;

}

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

using namespace std;
int a[1000005];
map<int,bool>mp;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	int n;
	cin>>n;
	bool f=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		for(int j=1;j*j<=a[i];j++){
			if(a[i]%j==0){
				int k=a[i]/j;
				if(j!=k){
					if(mp[j]&&j!=1){
						f=1;
						break;
					}
					else mp[j]=1;
					if(mp[k]){
						f=1;
						break;
					}
					else mp[k]=1;
				}
				else{
					if(mp[j]&&j!=1){
						f=1;
						break;
					}
					else mp[j]=1;
				}
			}
		}
	}
	int gc=a[0];
	for(int i=1;i<n;i++){
		gc=gcd(gc,a[i]);
	}
	if(!f&&gc==1)cout<<"pairwise coprime"<<endl;
	else if(gc==1)cout<<"setwise coprime"<<endl;
	else if(gc!=1)cout<<"not coprime"<<endl;
	return 0;
}

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

int main()
{
  cout << fixed << setprecision(10);
  
  int D, E;
  while(cin >> D >> E, D) {
    double ret = 1e9;
    for(int x = 0; x <= D; x++) {
      int y = D - x;
      ret = min(ret, fabs(sqrt(x * x + y * y) - E));
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();

		long[][] A = new long[n][m];
		long[][] B = new long[m][l];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				A[i][j] = sc.nextLong();
			}
		}
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < l; k++) {
				B[j][k] = sc.nextLong();
			}
		}

		long[][] sum = new long[n][l];

		for (int p = 0; p < n; p++) {
			for (int q = 0; q < l; q++) {
				sum[p][q] = 0;
				for (int k = 0; k < m; k++) {
					sum[p][q] = sum[p][q] + A[p][k] * B[k][q];
				}
				if (q != l - 1) {
					System.out.print(sum[p][q] + " ");
				} else {
					System.out.print(sum[p][q]);
				}
			}
			System.out.println("");
		}

	}

}



Measured memory_bytes: 53412
n = gets.to_i
lines = gets.split.map(&:to_i)

tally = lines.tally

selected = []

tally.keys.sort.reverse.each do |length|
  next if tally[length] < 2

  selected.push length

  if tally[length] >= 4 && selected.size == 1
    selected.push length
  end

  break if selected.size == 2
end

answer = selected.size == 2 ? selected.first * selected.last : 0

puts answer


Measured memory_bytes: 26404
sx, sy, tx, ty = map(int,input().split())

for _ in range(ty-sy):
    print("U", end="")
for _ in range(tx-sx):
    print("R", end="")

for _ in range(ty-sy):
    print("D", end="")
for _ in range(tx-sx):
    print("L", end="")

print("L", end="")
for _ in range(ty-sy):
    print("U", end="")
print("U", end="")
for _ in range(tx-sx):
    print("R", end="")
print("R", end="")
print("D", end="")

print("R", end="")
for _ in range(ty-sy):
    print("D", end="")
print("D", end="")
for _ in range(tx-sx):
    print("L", end="")
print("L", end="")
print("U", end="")

print()

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

signed main() {
    int N, C;
    cin >> N >> C;

    vector<int> s(N), t(N), c(N);
    vector<vector<int>> imos(C, vector<int> (200010));
    for (int i = 0; i < N; i++) {
        cin >> s[i] >> t[i] >> c[i];
        s[i] *= 2;
        t[i] *= 2;
        c[i]--;

        imos[c[i]][s[i] - 1]++;
        imos[c[i]][t[i] + 1]--;
    }

    for (int i = 0; i < C; i++) {
        for (int j = 1; j < imos[i].size(); j++) {
            imos[i][j] += imos[i][j - 1];
        }
    }

    int ans = 0;
    for (int i = 0; i < imos[0].size(); i++) {
        int t = 0;
        for (int j = 0; j < C; j++) {
            t += !!imos[j][i];
        }
        ans = max(ans, t);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 51072
N,M = map(int,input().split())

#nの約数列挙
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass #sortされていない

div = divisor(M)
ans = 0
for d in div:
    if M//d >= N:
        ans = max(ans,d)
print(ans)


Measured memory_bytes: 3060
import math
import itertools

N=int(input())
N_fac=math.factorial(N)
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
p=0
q=0

S=[_ for _ in range(1,N+1)]
A=[]
for i in itertools.permutations(S,len(S)):
    A.append(list(i))

for j in range(N_fac):
    if P==A[j]:
        p=j
    if Q==A[j]:
        q=j

print(abs(p-q))





Measured memory_bytes: 10228
fun readInts() = readLine()!!.split(' ').map(String::toInt)

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val pp = readInts()
    var cnt = 0
    for (i in 1..n - 2) {
        val p1 = pp[i - 1]
        val p2 = pp[i]
        val p3 = pp[i + 1]
        if ((p1 < p2 && p2 < p3) || (p1 > p2 && p2 > p3)) cnt++
    }
    println(cnt)
}


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

using namespace std;

#define endl "\n"
#define F first
#define S second
#define PB push_back
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;

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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

    string a,b;
    cin >> a >> b;
    b = b.substr(0,a.size());

    if(a == b)
    {
        cout << "Yes";
    }
    else
        cout << "No";

	return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<algorithm>
#define ull unsigned long long 
#define ll long long
using namespace std;
bool cmp (ll x, ll y)
{
	return x > y;
}
int main()
{
	int n, a, b;
	ll v[50];
	double ans = 0;
	ull cnt = 0;
	scanf("%d %d %d", &n, &a, &b);
	for(int i = 1; i <= n;i++)
	{
		scanf("%lld", &v[i]);
	}
	sort(v + 1, v + n + 1, cmp);
	if(v[1] == v[a])
	{
		printf("%0.6lf\n",(double)v[1]);
		int x = a;
		while(x <= n && v[1] == v[x])
		{
			x++;	
		}
		x--;
		ull tmp = 1;
		for(int i = 1; i < a; i++)
			tmp = tmp * (x - i + 1) / i;
		if(x >= b)
			for(int i = a; i <= b; i++)
			{
				tmp = tmp * (x - i + 1) / i;
				cnt += tmp;
			}
		else
			for(int i = a; i <= x; i++)
			{
				tmp = tmp * (x - i + 1) / i;
				cnt += tmp;
			}
	}	
	else
	{
		for(int i = 1; i <= a; i++)
			ans += (double)v[i];
		ans /= a;
		printf("%0.6lf\n",ans);
		int l, r;
		for(l = a; v[a] == v[l]; l--);
			l++;
		for(r = a;r <= n && v[a] == v[r]; r++);
			r--;
		int x = a - l + 1;
		int y = r - l + 1;
		cnt = 1;
		for(int i = 1; i <= x; i++)
			cnt = cnt * (y - i + 1) / i;
	}
	printf("%llu\n",cnt);
	return 0;
 } 

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

int main()
{
    int N = 0;
    cin >> N;
    
    for (int i = 0; i <= 25; ++i){
        for (int j = 0; j <= 14; ++j){
            if( 4*i+ 7*j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

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>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
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 };

int main() {
	int n, i, j;
	cin >> n;
	vi t(n), a(n);
	for (i = 0; i < n; i++) {
		cin >> t[i] >> a[i];
	}
	ll ta = 1, ao = 1;
	for (i = 0; i < n; i++) {
		ll m = max(ta / t[i], ao / a[i]) - 1;
		while (m*t[i] < ta || m*a[i] < ao) {
			m++;
		}
		ta = m*t[i]; ao = m*a[i];
	}
	cout << ta + ao << endl;
	
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll x;
    cin >> x;
    cout << !x << endl;

    return 0;
}

Measured memory_bytes: 3592
N, K = map(int, input().split())
dicts = {i:False for i in range(N)}
for i in range(K):
    d = int(input())
    for j in map(lambda n:int(n) - 1, input().split()):
        dicts[j] = True
        
ans = 0
for i in range(N):
    if not dicts[i]:
        ans += 1

print(ans)


Measured memory_bytes: 9176
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;

namespace at_coder
{
#if TEST
    [TestClass]
#endif
    public class Test_168_d
    {

#if TEST
        public static void Test_Main()
#else
        public static void Main()
#endif
        {
            int []ar = ReadIntArray();
            int A = ar[0]; // 時間
            int B = ar[1]; // 分
            int H = ar[2];
            int M = ar[3];

            // 中間の角度の差を求める (Radian)
            double H2 = H + M / 60.0;
            double d1 = H2 / 12.0 * 2 * Math.PI;
            double d2 = M / 60.0 * 2 * Math.PI;
            double dd = Math.Abs(d1 - d2);

            // 時 針
            double x1 = A; 
            double y1 = 0;

            // 分
            double x2 = Math.Cos(dd) * B;
            double y2 = Math.Sin(dd) * B;

            // 距離を求める
            double l = Math.Sqrt((x1 - x2) * (x1 - x2)+ (y1 - y2) * ( y1 - y2));

            Write(l.ToString());
        }


        private static void Write(string s)
        {
            Console.WriteLine(s);
        }

        private static int[] ReadIntArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int[] ar = new int[ss.Length];
            for (int i = 0; i < ss.Length; i++)
            {
                ar[i] = int.Parse(ss[i]);
            }
            return ar;
        }
        private static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static void ReadInt(out int a, out int b)
        {
            var ar = ReadIntArray();
            a = ar[0];
            b = ar[1];
        }
        private static void ReadInt(out int a, out int b, out int c)
        {
            var ar = ReadIntArray();
            a = ar[0];
            b = ar[1];
            c = ar[2];
        }
        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            return ss;
        }
#if !TEST
    }
}
#endif

Measured memory_bytes: 27996
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> d){
    ll res = 0;
    rep(i, N){
        for(ll j = i+1; j< N; j++){
            res += d[i]*d[j];
        }
    }
    cout << res << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> d(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&d[i]);
    }
    solve(N, std::move(d));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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;}

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


//////////////////////////////////////////////////


int main() {
    int n, k, s; cin >> n >> k >> s;
    if (n == 1) {
        cout << s << endl;
    } else {
        if (k>0) printf("%d", s);
        else {
            if (s+1 <= 1000000000) printf("%d", s+1);
            else printf("%d", s-1);
        }
        k--;
        for (int i = 1; i < n; i++) {
            if (k > 0) {
                printf(" %d", s);
                k--;
            } else {
                if (s+1 <= 1000000000) printf(" %d", s+1);
                else printf(" %d", s-1);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>

using namespace std;

typedef long long ll;

int main(void){
    string s;
    cin >> s;
    const ll mod = 1000000007;
    vector<vector<ll> > dp(s.size() + 1,vector<ll> (13, 0));
    dp[0][0] = 1;
    for(ll i = 0;i < s.size(); i++){
        // 各桁を取得
        ll target;
        if(s[i] == '?'){
            target = -1;
        }else{
            target = s[i] - '0';
        }
        for(ll j = 0;j < 10; j++){
            // 取得した桁の値が、?じゃない かつ 数と一致しない場合はスキップ
            if(target != -1 && target != j){
                continue;
            }
            // 一致した場合は各余りに対して過去桁の計算結果を加算する
            for(ll k = 0;k < 13; k++){
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        for(ll j = 0;j < 13; j++){
            dp[i + 1][j] %= mod;
        }
    }
  // 全ての桁を考慮した場合の余りが5の値を出力
    cout << dp[s.size()][5] << endl;
    return 0;
}


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

double coin(int d, int K){

    int max_trial;
    max_trial = ceil(log2l(double(K)/double(d)));
    return 1.0/pow(2, max_trial);
}


int main(){
    int N,K;
    cin >> N >> K;
    double res = 0;
    for(int i=1; i < N + 1; i++){
        if(i >= K){
            res += 1.0;
        }else{
            res += (coin(i, K));

        }
    }
    cout << std::setprecision(20) << res/N << endl;
    return 0;


}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v(n,0);
    rep(i,n) cin>>v[i];
    sort(v.begin(),v.end());
    int min=inf;
    //rep(i,n) cout<<v[i]<<" ";
    //cout<<endl;
    for(int i=0;i<n-k+1;i++){

        if(abs(v[i]-v[i+k-1])<min){

            min=abs(v[i]-v[i+k-1]);
        } 
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 640
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(lld i = 0; i < n; i+=1)
#define fod(i,n) for(lld i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld n, w;
      cin >> n >> w;
      lld A[n+1],W[n+1];
      for(lld i = 1; i <= n; i += 1){
      	cin >> W[i] >> A[i];
      }
      lld dda[n+1][w+1];
      for(lld i = 0; i <= n; i += 1){
      	for(lld j = 0; j <= w; j += 1){
      		if (i == 0 || j == 0){
      			dda[i][j]  = 0;
      		}
      		else{
      			if (j-W[i]>= 0){
      				dda[i][j] = max(dda[i-1][j], dda[i-1][j-W[i]] + A[i]);
      			}
      			else{
      				dda[i][j] = dda[i-1][j];
      			}
      		}
      	}
      }
      cout << dda[n][w];
      return 0;
}

Measured memory_bytes: 82476
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int N;

signed main()
{
	cin >> N;

	for(int i=1; i<=9; i++)
		for (int j = 1; j <= 9; j++)
			if (i * j == N)
			{
				cout << "Yes" << endl;
				return 0;
			}

	cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
int N,M;
char c[26];
int h[26],w[26];
int flipto[26];
string bs[26][15];
vector<P> g[52];
int mxh;
int H,W;
string s[100];
bool isbox(int x,int y){
	int t=x;
	while(t<H&&s[t][y]=='*') t++;
	return t-x>mxh;
}
string seq(int u,int l,int d,int r){
	vector<string> ret;
	bool flip=0;
	int y=l,x=u;
	while(y<r){
		if(s[x][y]=='*'){
			if(isbox(x,y)){
				int nu=x+1,nl=y+1;
				int nd=nu,nr=nl;
				while(nd<H&&s[nd][y]=='*') nd++;
				while(nr<W&&s[x][nr]=='*') nr++;
				nd--,nr--;
				ret.pb(seq(nu,nl,nd,nr));
				x=u,y=nr+1;
				continue;
			}else{
				vector<P> vc;
				int L=y,U=1e5;
				for(;y<r;y++){
					bool iscol=0;
					for(x=u;x<d;x++){
						if(s[x][y]=='*') vc.pb(P(x,y)),iscol=1,chmin(U,x);
					}
					if(!iscol) break;
				}
				for(P& p:vc) p=P(p.fs-U,p.sc-L);
				sort(all(vc));
				rep(i,2*N){
					if(vc==g[i]){
						ret.pb(string(1,c[i%N]));
						if(i>=N) flip=1;
						break;
					}
				}
				x=u;
				continue;
			}
		}
		x++;
		if(x==d){
			y++;
			x=u;
		}
	}
	if(flip){
		reverse(all(ret));
		for(string& str:ret) if(str.size()==1){
			int tmp=flipto[str[0]-'a'];
			if(tmp>=0) str[0]=tmp+'a';
		}
	}
	string st="[";
	for(string str:ret) st+=str;
	st+="]";
	return st;
}
int main(){
	while(true){
		cin>>N>>M;
		if(N==0) break;
		rep(i,N*2) g[i].clear();
		mxh=0;
		rep(i,N){
			cin>>c[i]>>h[i]>>w[i];
			chmax(mxh,h[i]);
			rep(j,h[i]) cin>>bs[i][j];
			rep(j,h[i]) rep(k,w[i]) if(bs[i][j][k]=='*') g[i].pb(P(j,k)),g[i+N].pb(P(j,w[i]-1-k));
		}
		rep(i,2*N) sort(all(g[i]));
		rep(i,N) flipto[i]=-1;
		rep(i,N) rep(j,N) if(g[i+N]==g[j]) flipto[c[i]-'a']=c[j]-'a';
		rep(tt,M){
			cin>>H>>W;
			rep(i,H) cin>>s[i];
			string ans=seq(0,0,H,W);
			cout<<ans.substr(1,ans.size()-2)<<endl;
		}
		puts("#");
	}
}

Measured memory_bytes: 3332
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int a[15][15];
int main(){
	int n,d,i,j,k,sum,total=0;
	double t;
	cin>>n>>d;
	for(i=0;i<n;i++)
		for(j=0;j<d;j++)
			cin>>a[i][j];
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++){
			sum=0;
			for(k=0;k<d;k++)
				sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			t=sqrt(sum);
			if(t==(int)(t))
				total++;
		}
	cout<<total;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int n,q; cin>>n>>q;
	vector<int> a(n);
	rep(i,0,n) cin>>a[i];
	reverse(a.begin(),a.end());
	vector<ll> sum(n+1,0),even(n+1,0);
	rep(i,0,n){
		sum[i+1]=sum[i]+a[i];
		even[i+1]=even[i]+(i%2==0?a[i]:0);
	}
	vector<ll> idx,val;
	rep(i,0,(n-1)/2){
		ll j=(a[i+1]+a[2*i+2])/2+1;
		ll k=(sum[i+1]-sum[0])+(even[n]-even[2*i+2]);
		idx.push_back(j);
		val.push_back(k);
	}
	reverse(idx.begin(),idx.end());
	reverse(val.begin(),val.end());
	rep(i,0,q){
		ll x; cin>>x;
		int ite=upper_bound(idx.begin(),idx.end(),x)-idx.begin();
		if(ite==0) printf("%lld\n",sum[(n+1)/2]-sum[0]);
		else printf("%lld\n",val[ite-1]);
	}
 	return 0;
}


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

int main(void) {
    
    int N,L;
    cin >> N >> L;
    vector<string> str;
    for(int i = 0; i < N; i++ ) {
        string s;
        cin >> s;
        str.push_back(s);
    }
    sort(str.begin(),str.end());
    for(int i = 0 ; i < N; i++) cout << str[i];
    cout << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,m;
    cin >> n >> m;
    int ans[n],a,b;
    rep(i, n)ans[i] = 0;
    rep(i, m){
        cin >> a >> b;
        ++ans[a - 1];
        ++ans[b - 1];
    }
    rep(i, n)cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf 1e6
int main(){
        ll n,w;
        cin>>n>>w;
        vector<ll> a(inf,1e12);
        a[0] = 0;
        for(int i=0;i<n;i++){
                int we,v;
                cin>>we>>v;
                for(int j=inf-v-1;j>=0;j--){
                        a[j+v] = min(a[j+v],a[j]+we );
                }
        }
        for(int i=inf-1;i>=0;i--)if(a[i]<=w){
                cout<<i<<endl;
                break;
        }
        return 0;
}


Measured memory_bytes: 8064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main
{
    public static void main(String[] arg) throws IOException
    {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	double x=0, y=0, deg=0;
	while(true)
	{
    	    String s = br.readLine();
	    double steps = Double.parseDouble(s.split(",")[0]);
	    double turn  = Double.parseDouble(s.split(",")[1]);
	    if(steps==0 && turn==0)
		break;
	    else {
 	        x += steps*Math.sin(Math.toRadians(deg));
	        y += steps*Math.cos(Math.toRadians(deg));
	        deg += turn;
	    }
	}
	System.out.println((int)x);
	System.out.println((int)y);	
    }
}

Measured memory_bytes: 9764
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int n,m,c,count;
    count=0;
    cin>>n>>m>>c;
    vector<int> vec(m);
    rep(i,m){
        cin>>vec.at(i);
        //cout<<vec.at(i);
    }
    vector<vector<int>> data(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> data.at(i).at(j);
            //cout<<data.at(i).at(j);
        }
    } 
    int sum;
    rep(i,n){
        sum=0;
        rep(j,m){
            sum+=data.at(i).at(j)*vec.at(j);
        }
        if(sum+c>0)
            count++;
    }
    cout<<count<<endl;
    
}



Measured memory_bytes: 256
n = int(input())
tree = [[] for i in range(n)]
degree = [0 for i in range(n)]

for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)
    degree[a] += 1
    degree[b] += 1

leaf = []
for i in range(n):
    if degree[i] == 1:
        leaf.append(i)

color = ['' for i in range(n)]

first = False
while leaf:
    v = leaf.pop()
    if degree[v] == 0:
        first = True
        continue
    degree[v] = 0
    p = tree[v][0]
    # tree[p].remove(v)
    # degree[p] -= 1
    color[v] = 'B'
    color[p] = 'W'
    for np in tree[p]:
        tree[np].remove(p)
        degree[np] -= 1
        if degree[np] == 0:
            first = True
        elif degree[np] == 1:
            leaf.append(np)

for i in range(n):
    if color[i] == '' and degree[i] == 0:
        first = True

print('First' if first else 'Second')


Measured memory_bytes: 27028
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<ll, int>;
const ll INF = (ll)1e17;

struct edge{
	int to, cost;
};

vector<edge> G[100010];
ll d[100010];

int main(void){
	int N; cin >> N;
	for(int i = 0; i < N-1; i++){
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		edge e; e.to = b; e.cost = c; G[a].push_back(e);
		e.to = a; G[b].push_back(e);
	}
	int Q, K; cin >> Q >> K;

	// for(int i = 0; i < N; i++){
	// 	printf("G[%d]: ", i);
	// 	for(auto& v: G[i]){
	// 		printf("%d ", v.to);
	// 	}
	// 	printf("\n");
	// }

	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, K-1));
	fill(d, d+N, INF); d[K-1] = 0;
	while(not que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;
		// printf("#1\n");
		if(d[v] < p.first) continue;
		// printf("#2\n");
		for(int i = 0; i < (int)G[v].size(); i++){
			edge e = G[v][i];
			// printf("e = {%d, %d}\n", e.to, e.cost);
			if(d[e.to] > d[v] + (ll)e.cost){
				d[e.to] = d[v] + (ll)e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}

	// for(int i = 0; i < N; i++) printf("d[%d] = %lld\n", i, d[i]);

	for(int i = 0; i < Q; i++){
		int x, y; cin >> x >> y;
		x--; y--;
		printf("%lld\n", (ll)d[x] + d[y]);
	}

	return 0;
}


Measured memory_bytes: 10096
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <cstdlib>
#include <iterator>
#include <algorithm>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x, t;
    cin >> n >> x >> t;
    cout << ((n / x) + ((n % x) > 0))*t;
    return 0;
}

Measured memory_bytes: 3648
x, y = map(int, input().split())
ans = 4*x - y


def is_odd(num):
    if num % 2 == 0:
        return False
    else:
        return True


if is_odd(ans):
    print('No')
elif ans/2 <= x:
    if ans/2 < 0:
        print('No')
    else:
        print('Yes')
else:
    print('No')


Measured memory_bytes: 9172
using System;
using System.Collections.Generic;

namespace ABC110_D___Factorization
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NM[0];
            var M = NM[1];
            if (M == 1) return 1;

            var primeFactors = new List<int>();
            var factor = 2;
            long MOD = 1000000007;
            while (M > 1)
            {
                if (factor > Math.Sqrt(M))
                {
                    primeFactors.Add(M);
                    break;
                }
                while (M % factor == 0)
                {
                    M /= factor;
                    primeFactors.Add(factor);
                }
                factor += 1;
            }

            var primeCounts = new List<int>();
            primeCounts.Add(1);
            for (int i = 1; i < primeFactors.Count; i++)
                if (primeFactors[i] == primeFactors[i - 1])
                    primeCounts[primeCounts.Count - 1] += 1;
                else
                    primeCounts.Add(1);

            Combination.combInit(1000000, MOD);
            long result = 1;
            foreach (int i in primeCounts)
            {
                result *= Combination.combination(N + i - 1, i);
                result %= MOD;
            }
            return result;
        }
    }
    static class Combination
    {
        static long combMax;
        static long combMOD;

        static long[] factorial;
        static long[] inverse;
        static long[] factInv;

        public static void combInit(long _max, long _mod)
        {
            combMax = _max;
            combMOD = _mod;
            factorial = new long[combMax];
            inverse = new long[combMax];
            factInv = new long[combMax];

            factorial[0] = factorial[1] = 1;
            factInv[0] = factInv[1] = 1;
            inverse[1] = 1;

            for (int i = 2; i < combMax; i++)
            {
                factorial[i] = factorial[i - 1] * i % combMOD;
                inverse[i] = combMOD - inverse[combMOD % i] * (combMOD / i) % combMOD;
                factInv[i] = factInv[i - 1] * inverse[i] % combMOD;
            }
        }

        public static long combination(int n, int k)
        {
            if (n < k) return 0;
            if (n < 0 || k < 0) return 0;
            return factorial[n] * (factInv[k] * factInv[n - k] % combMOD) % combMOD;
        }
    }
}


Measured memory_bytes: 36692
from operator import add
import sys
input=sys.stdin.readline


class SegTree():
    def __init__(self, N, e, operator_func=add):
        self.e = e # 単位元
        self.size = N
        self.node = [self.e] * (2*N)
        self.operator_func = operator_func # 処理(add or xor max minなど)

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.operator_func(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size-1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.operator_func(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        # [l, r) についてqueryを求める
        x = self.e
        l += self.size
        r += self.size

        while l<r:
            if l&1:
                x = self.operator_func(x, self.node[l-1])
                l += 1
            if r&1:
                r -= 1
                x = self.operator_func(x, self.node[r-1])
            l >>= 1
            r >>= 1
        return x


def main():
    S = input()
    T = input()
    treeS = SegTree(len(S), 0)
    treeT = SegTree(len(T), 0)
    treeS.set_list([1 if s=="A" else 0 for s in S])
    treeT.set_list([1 if s=="A" else 0 for s in T])

    q = int(input())
    for _ in range(q):
        a, b, c, d = map(int, input().split())
        sa = treeS.get(a-1, b)
        sb = b-a+1-sa
        ta = treeT.get(c-1, d)
        tb = d-c+1-ta

        if (2*(sb-sa)+tb-ta)%3 or (sb-sa+2*(tb-ta))%3:
            print("NO")
        else:
            print("YES")

main()


Measured memory_bytes: 121312
#include<iostream>
#include<algorithm>
using namespace std;
int N;
int main(){
    cin>>N;
    int A[2][N];
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            cin>>A[i][j];
        }   
    }   
    int x[N];                                                       
    for(int i=0;i<N;i++)x[i]=0;

    for(int k=0;k<N;k++){
        for(int i=0;i<=k;i++) 
            x[k]+=A[0][i];
        for(int i=k;i<N;i++)
            x[k]+=A[1][i];
    }   
    sort(x,x+N-1,greater<int>());
    cout<<x[0]<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,i,a[100000],last;
    long long int m;
    scanf("%d",&n);
    m=0;last=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        m+=abs(a[i]-last);
        last=a[i];
    }
    m+=abs(0-last);
    if((a[0]<=a[1]&&a[0]>=0)||(a[0]>=a[1]&&a[0]<=0))
        printf("%I64d\n",m);
    else if(abs(a[1]-a[0])>abs(a[0]-0))
        printf("%I64d\n",m-2*(abs(a[0]-0)));
    else printf("%I64d\n",m-2*abs(a[1]-a[0]));
    for(i=1;i<n-1;i++)
    {
        if((a[i]<=a[i+1]&&a[i]>=a[i-1])||(a[i]>=a[i+1]&&a[i]<=a[i-1]))
        printf("%I64d\n",m);
        else if(abs(a[i+1]-a[i])>abs(a[i]-a[i-1]))
            printf("%I64d\n",m-2*(abs(a[i]-a[i-1])));
        else printf("%I64d\n",m-2*abs(a[i+1]-a[i]));
    }
    if((a[n-1]<=a[n-2]&&a[n-1]>=0)||(a[n-1]>=a[n-2]&&a[n-1]<=0))
        printf("%I64d\n",m);
    else if(abs(0-a[n-1])>abs(a[n-1]-a[n-2]))
        printf("%I64d\n",m-2*(abs(a[n-1]-a[n-2])));
    else printf("%I64d\n",m-2*abs(0-a[n-1]));
    return 0;
}


Measured memory_bytes: 6912
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
	string str, ans[100], p, ex;
	int a, b, q, cou = 0;
	char c;
	cin >> str;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> ex;
		cin >> a >> b;
		if (ex == "print") {
			ans[cou] = str.substr(a, (b - a) + 1);
			cou++;
		}
		if (ex == "reverse") {
			for (int j = 0; j < (b - a + 1) / 2; j++) {
				c = str[a + j]; str[a + j] = str[b - j]; str[b - j] = c;
			}
		}
		if (ex == "replace") {
			cin >> p;
			str = str.replace(a, (b - a) + 1, p);
		}
	}
	for (int i = 0; i < cou; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 1224
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	n,k=map(int,input().split())
	p=list(map(int,input().split()))
	
	s=sum(p[:k])
	ans=s
	
	for i in range(n):
		try:
			s=s-p[i]+p[i+k]
			ans=max(ans,s)
		except:
			break
	
	print((ans+k)/2)
	
	
	
if __name__ == "__main__":
	main()


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

int main() {
    int n, m;
    cin >> n >> m;
    // (accuracy rate) p = 1 / pow(2, m)
    // (one time) x = 1900 * m + 100 * (n - m)
    // ans = x + (1 - p) * ans
    // ans = x / p
    cout << pow(2, m) * (1900 * m + 100 * (n - m)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import collections

n, m = map(int, input().split())

res_list = []

for _ in range(n):
  temp_list = list(map(int, input().split()))
  for i in range(1, temp_list[0]+1):
    res_list.append(temp_list[i])


print(list(collections.Counter(res_list).values()).count(n))

Measured memory_bytes: 3316
#include <ios>
#include <iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);

	int n, i, j, c = 0, a[100] = {};
	cin >> n;
	for(i = 0; i < n; ++i)
		cin >> a[i];

	for(i = 0; i < n; ++i){
		for(j = n-1; j > i; --j){
			if( a[j] < a[j-1] ){
				swap(a[j], a[j-1]);
				++c;				
			}
		}
	}

	for(i = 0; i < n; ++i){
		cout << a[i];
		if( i != n-1 )
			cout << " ";
	}
	cout << "\n" << c << "\n";

	return 0;
}

Measured memory_bytes: 1204
//Make Them Even - code written by Korneliusz Litman

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int coins[500][500];
vector <pair<int, int> > v1, v2;

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

	int n, m;
	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++) cin >> coins[i][j];
	}

	bool if_moved = false; int j = -1;
	for (int i = 0; i < n; i++)
	{
		if (i % 2)
		{
			while (j-- > 0)
			{
				if (if_moved)
				{
					coins[i][j]++;
					v2.push_back(make_pair(i, j));
				}

				if (coins[i][j] % 2)
				{
					if_moved = true;
					v1.push_back(make_pair(i, j));
				}
				else if_moved = false;
			}
		}
		else
		{
			while (++j < m)
			{
				if (if_moved)
				{
					coins[i][j]++;
					v2.push_back(make_pair(i, j));
				}

				if (coins[i][j] % 2)
				{
					if_moved = true;
					v1.push_back(make_pair(i, j));
				}
				else if_moved = false;
			}
		}
	}

	cout << v2.size() << '\n';
	for (unsigned int i = 0; i < v2.size(); i++)
	{
		cout << v1[i].first + 1 << ' ' << v1[i].second + 1 << ' ' << v2[i].first + 1 << ' ' << v2[i].second + 1 << '\n';
	}
	//getchar(); getchar();
}

Measured memory_bytes: 5228
s = list(input())
for i in range(int(input())):
    command = input().split()
    a, b = int(command[1]), int(command[2])
    if command[0] == 'print':
        print("".join(s[a:b+1]))
    elif command[0] == 'reverse':
        s[a:b+1] = reversed(s[a:b+1])
    elif command[0] == 'replace':
        s[a:b+1] = command[3]


Measured memory_bytes: 5628
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n, q;

int main() {
	while (cin >> n >> q) {
		if (n == 0)return 0;
		int m; int ok[110];
		for (int i = 0; i < 110; i++)ok[i] = 0;
		for (int i = 0; i < n; i++) {
			cin >> m; 
			for (int j = 0; j < m; j++) {
				int d; cin >> d;
				ok[d]++;
			}
		}
		int ans = 0;
		int nowpeople=0;
		for (int i = 1; i < 110; i++) {
			if (ok[i] >= q && nowpeople<ok[i]) {
				nowpeople = ok[i];
				ans = i;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3012
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll a, b, c;
	cin>>a>>b>>c;
	cout<<min(a*b, c)<<endl;
	return 0;
}


Measured memory_bytes: 256
from math import pi, cos

a, b, h, m = map(int, input().split())
x = pi/6
y = pi/30
z = x/60
C = abs(x*h+z*m - y*m)
print(f"{(a**2 + b**2 - 2 * a*b * cos(C))**2**-1:.20f}")


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
        var N = input[0];
        var K = input[1];
        var A = Console.ReadLine().Split(" ").Select(int.Parse);

        var dict = new Dictionary<int, int>();
        foreach (var a in A)
        {
            if (!dict.ContainsKey(a))
            {
                dict[a] = 1;
            }
            else
            {
                dict[a] += 1;
            }
        }

        var count = 0;
        foreach (var (k, v) in dict.OrderBy(v => v.Value))
        {
            if (K >= dict.Count) break;
            count += v;
            dict.Remove(k);
        }
        
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 51860