akhauriyash/Code-Regression huggingface dataset:
gets
x=gets.split.map(&:to_f)
y=gets.split.map(&:to_f)
da=[]
x.each_with_index{|v,i| da << (v-y[i]).abs}
d1=0.0
da.each{|i| d1+=i}
puts d1
d2=0.0
da.each{|i| d2=d2+i**2}
puts Math.sqrt(d2)
d3=0.0
da.each{|i| d3+=i**3}
puts Math.cbrt(d3)
puts da.max

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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<int> L(N);
	for(int i=0;i<N;i++)	cin >> L.at(i);
	
	sort(L.begin(),L.end());
	vector<int> sum(1001,0);
	for(int i=0;i<N;i++)	sum.at(L.at(i))++;
	for(int i=1;i<1001;i++)	sum.at(i)+=sum.at(i-1);
	int ans=0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			int a=L.at(i);
			int b=L.at(j);
			if(a+b>=1001){
				ans+=sum.at(1000);
				ans-=j+1;
			}
			else{
				ans+=sum.at(a+b-1);
				ans-=j+1;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


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


int main() {
  int n, m; cin >> n >> m;
  int ans[m+1] = {0};
  for(int i = 0; i < n; i++){
    int k; cin >> k;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      ans[a]++;
    }
  }
  int cnt = 0;
  for(int i = 0; i < m+1; i++){
    if(ans[i] == n) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3644
#include<stdio.h>

int main(){
  int n,a[100],i,j,v;
  int flag=1,num=0;

  scanf("%d",&n);

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

  for(i=0;i<n-1;i++){

    for(j=0;j<n-1;j++){
      flag=0;
      if(a[j]>a[j+1]){
	v=a[j+1];
	a[j+1]=a[j];
	a[j]=v;

	flag=1;
      }
      if(flag==1)
	num++;
    }
  }

   for(i=0;i<n-1;i++)
    printf("%d ",a[i]);
  printf("%d\n",a[n-1]);
  printf("%d\n",num);

  return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N,M,Q;
vector<int> a,b,c,d;
vector<int> A;

void input() {
  cin >>N >>M >>Q;
  a.assign(Q, 0);  
  b.assign(Q, 0);
  c.assign(Q, 0);
  d.assign(Q, 0);
  rep(i, Q) cin >>a[i] >>b[i] >>c[i] >>d[i];
  rep(i, Q){ a[i]--; b[i]--; }
  A.assign(N, 0);
}

int check(){
  // 現在のAの状態から得点を算出し返す
  int res = 0;
  rep(i, Q){
    if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
  }
  return res;
}

int dfs(int digit, int aa){
  if (digit == N){
    return check();
  }
  int res = 0;
  for (int i=aa; i<=M; i++){
    A[digit] = i;
    int tmp = dfs(digit+1, i);
    chmax(res, tmp);
    A[digit] = 0;
  }
  return res;
}

int main() {
  input();
  int res = dfs(0, 1);
  cout <<res <<endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
int main(){
  int h,n;
  cin>>h>>n;
  cout<<(h+n-1)/n<<endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();
    let d = read();
    let mut x: Vec<Vec<i32>> = Vec::new();
    x.resize(n, Vec::new());
    for i in 0..n {
        x[i] = (0..d).map(|_| read()).collect();
    }

    let mut ans = 0;
    for i in 0..n {
        for j in i + 1..n {
            let mut s = 0;
            for k in 0..d {
                s += (x[i][k] - x[j][k]).pow(2);
            }
            let s = (s as f64).sqrt();
            // 整数型(i32)にしてから、s と比較できるように f64 に戻している
            if s == s as i32 as f64 {
                ans += 1;
            }

        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<int>x[10]; int a, b, c, d; string S, T;
int main() {
    while (true) {
        cin >> S; int p = 0; if (S == "#")break; cin >> a >> b >> c >> d; a--; b--; c--; d--; S += '/';
        for (int i = 0; i < S.size(); i++) {
            if (S[i] == '/') {
                for (int j = 0; j < T.size(); j++) { 
                    if (T[j] == 'b')x[p].push_back(1);
                    else { for (int k = 0; k < (T[j] - '0'); k++)x[p].push_back(0); }
                }
                p++; T = "";
            }
            else { T += S[i]; }
        }
        swap(x[a][b], x[c][d]);
        for (int i = 0; i < p; i++) {
            int c = 0;
            for (int j = 0; j < x[i].size(); j++) {
                if (x[i][j] == 0) { c++; }
                if (x[i][j] == 0 && (j == x[i].size() - 1 || x[i][j + 1] == 1)) { cout << c; c = 0; }
                if (x[i][j] == 1)cout << 'b';
            }
            if (i < p - 1)cout << '/';
        }
        cout << endl; for (int i = 0; i < 10; i++)x[i].clear();
    }
    return 0;
}

Measured memory_bytes: 3152
def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    MAX = int(1e18)
    ans = 1
    for a in A:
        ans *= a
        if ans > MAX:
            print(-1)
            return
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 84456
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
int n,cnt0,cnt2;
int a[maxn];

void calc(int x){
	int res=0;
	while(x%2==0){
		res++;
		x/=2;
		if(res>=2)break;
	}
	if(res==0)cnt0++;
	else if(res>=2)cnt2++;
}

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	REP(i,n)cin>>a[i],calc(a[i]);
	if(cnt2>=cnt0||(cnt2+cnt0==n&&cnt2==cnt0-1))cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int N,K;
    char S[11];

    scanf("%d %s %d",&N,S,&K);
    for (int i = 0; i < N; i++)
    {
        if (S[i] == S[K-1]){
            putchar(S[K-1]);
        }else{
            putchar('*');
        }
    }
    
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        private struct Item
        {
            public int v;
            public int w;
            public Item(int v, int w)
            {
                this.v = v;
                this.w = w;
            }
        }
        private static void SolveA(string[] args)
        {
            int[] nw = ReadAndParseIntArr();
            int n = nw[0];
            int weight = nw[1];
            Item[] items = new Item[n + 1];
            for(int i=1;i<=n;++i)
            {
                int[] vw = ReadAndParseIntArr();
                items[i] = new Item(vw[0], vw[1]);
            }

            int[,] dp = new int[n + 1, weight + 1];
            for(int i=1;i<=n;++i)
            {
                for(int w = 1;w<=weight;++w)
                {
                    if(items[i].w <= w)
                    {
                        dp[i, w] = Math.Max(dp[i - 1, w], dp[i - 1, w - items[i].w] + items[i].v);
                    }
                    else
                    {
                        dp[i, w] = dp[i - 1,w];

                    }
                }
            }
            int max = dp[n, weight];
            Console.WriteLine(max);
        }
        
    }
}



Measured memory_bytes: 21360
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	double n, t; cin >> n >> t;
	double ma = 0.0;
	for(int i = 0; i < n; i++) {
		double a, b; cin >> a >> b;
		
		ma = std::max(ma, b / a);
	}
	
	cout << std::fixed << std::setprecision(10) << ma * t << endl;
	return 0;
}



Measured memory_bytes: 3292
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
int a,b,h;
cin >> a >> b >> h;
cout << (a+b)*h/2 << endl;






//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string x = Console.ReadLine();
        
            
            if(((x[0] == x[1]) && (x[2] == x[3])&&(x[1] != x[2])                
                
                || (x[0] == x[3]) && (x[1] == x[2])&&(x[1] != x[3])
                || (x[0] == x[2]) && (x[1] == x[3])&&(x[0] != x[1])))
       
                {
                    Console.WriteLine("Yes");
                }

                else
                {
                    Console.WriteLine("No");
                }
            }
        }
    }



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

using namespace std;

int linearSearch(vector<int> A, int key)
{
  A.push_back(key);
  
  int i = 0;
  while (A[i] != key) i++;
  if (i != A.size() -1) {
    return 1;
  } else {
    return 0;
  }
}

int main()
{
  int n;
  vector<int> S;
  int q;
  int temp;
  
  cin >> n;
  while (n--) {
    cin >> temp;
    S.push_back(temp);
  }

  int count = 0;
  cin >> q;
  while (q--) {
    cin >> temp;
    count += linearSearch(S, temp);
  }

  cout << count << endl;
}



Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;

int main(){
    int x;
    scanf("%d",&x);
    if(x>=400&&x<=599) cout<<"8";
    else if(x>=600&&x<=799) cout<<"7";
    else if(x>=800&&x<=999) cout<<"6";
    else if(x>=1000&&x<=1199) cout<<"5";
    else if(x>=1200&&x<=1399) cout<<"4";
    else if(x>=1400&&x<=1599) cout<<"3";
    else if(x>=1600&&x<=1799) cout<<"2";
    else if(x>=1800&&x<=1999) cout<<"1";
}


Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

using CostType = ll;
struct Edge {
  int src, dst; CostType cost;
  Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
  inline bool operator<(const Edge &x) const {
    return cost != x.cost ? cost < x.cost : dst != x.dst ? dst < x.dst : src < x.src;
  }
  inline bool operator<=(const Edge &x) const { return !(x < *this); }
  inline bool operator>(const Edge &x) const { return x < *this; }
  inline bool operator>=(const Edge &x) const { return !(*this < x); }
};

struct SCC {
  vector<int> id;
  vector<vector<int>> vertices;
  vector<vector<Edge>> comp;

  SCC(const vector<vector<Edge>> &graph, bool heavy = false) : graph(graph), heavy(heavy) {
    n = graph.size();
    rev_graph.resize(n);
    REP(i, n) for (const Edge &e : graph[i]) {
      rev_graph[e.dst].emplace_back(e.dst, e.src, e.cost);
    }
    used.assign(n, false);
    id.assign(n, -1);
    REP(i, n) {
      if (!used[i]) dfs(i);
    }
    int now = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (id[order[i]] == -1) {
        if (heavy) vertices.emplace_back();
        rev_dfs(order[i], now++);
      }
    }
    comp.resize(now);
    REP(i, n) for (const Edge &e : graph[i]) {
      if (id[i] != id[e.dst]) comp[id[i]].emplace_back(id[i], id[e.dst], e.cost);
    }
    // if (heavy) {
    //   REP(i, now) sort(ALL(vertices[i]));
    // }
  }

private:
  bool heavy;
  int n;
  vector<vector<Edge>> graph, rev_graph;
  vector<bool> used;
  vector<int> order;

  void dfs(int ver) {
    used[ver] = true;
    for (const Edge &e : graph[ver]) {
      if (!used[e.dst]) dfs(e.dst);
    }
    order.emplace_back(ver);
  }

  void rev_dfs(int ver, int now) {
    id[ver] = now;
    if (heavy) vertices[now].emplace_back(ver);
    for (Edge &e : rev_graph[ver]) {
      if (id[e.dst] == -1) rev_dfs(e.dst, now);
    }
  }
};

int main() {
  int n, m; cin >> n >> m;
  vector<vector<Edge>> graph(n);
  while (m--) {
    int a, b; cin >> a >> b;
    graph[a].emplace_back(a, b);
  }
  SCC scc(graph, true);
  int k = scc.vertices.size();
  cout << k << '\n';
  REP(i, k) {
    int l = scc.vertices[i].size();
    cout << l << ' ';
    REP(j, l) cout << scc.vertices[i][j] << " \n"[j + 1 == l];
  }
  return 0;
}


Measured memory_bytes: 136000
// Problem : C - Giant Graph
// Contest : AtCoder - AtCoder Grand Contest 043
// URL : https://atcoder.jp/contests/agc043/tasks/agc043_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

const int MOD = 998244353;
vector<int> powers;
int n;

struct Graph {
	vector<vector<int>> edges;
	vector<int> nimber;
	vector<int> groups;
	
	void read() {
		edges.resize(n + 1);
		int m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			int a, b;
			cin >> a >> b;
			edges[a].push_back(b);
			edges[b].push_back(a);
		}
		nimber.resize(n + 1);
		for (int a = n; a >= 1; a--) {
			set<int> nei;
			for (int b : edges[a]) {
				if (b > a) {
					nei.insert(nimber[b]);
				}
			}
			for (int val = 0; true; val++) {
				if (nei.count(val) == 0) {
					nimber[a] = val;
					break;
				}
			}
			int i = nimber[a];
			while (groups.size() <= i) {
				groups.push_back(0);
			}
			groups[i] += powers[a];
			groups[i] %= MOD;
		}
	}
};

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	powers.resize(n + 1);
	powers[0] = 1;
	for (int i = 1; i <= n; i++) {
		powers[i] = (long long) 1'000'000'000'000'000'000 % MOD * powers[i - 1] % MOD;
	}
	Graph graphs[3];
	for (int i : {0, 1, 2}) {
		graphs[i].read();
	}
	
	int answer = 0;
	for (int a = 0; a < graphs[0].groups.size(); a++) {
		for (int b = 0; b < graphs[1].groups.size(); b++) {
			int c = a ^ b;
			if (c < graphs[2].groups.size()) {
				answer += (long long) graphs[0].groups[a] * graphs[1].groups[b] % MOD * graphs[2].groups[c] % MOD;
				answer %= MOD;
			}
		}
	}
	cout << answer << endl;	
}



















Measured memory_bytes: 17280
#!/usr/bin/env python3
import math


def main():
    N = input_line(int)
    border = int(math.sqrt(N))
    for i in range(border, 0, -1):
        if N % i == 0:
            print((i-1) + (N // i - 1))
            break


def input_line(*types):
    if len(types) == 1:
        return types[0](input())
    else:
        return [t(x) for t, x in zip(types, input().split())]


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;

int main(){
    int n,Q;cin >> n >> Q;
    vector<vector<int>> vec(n);
    for(int i = 0;i < n-1;i++){
        int b,c;cin >> b >> c;
        vec.at(b-1).push_back(c-1);
        vec.at(c-1).push_back(b-1);
    }
    vector<ll> cnt(n);
    for(int i = 0;i < Q;i++){
        int b,c;cin >> b >> c;
        cnt.at(b-1) += c;
    }
    queue<int> que;
    que.push(0);
    vector<int> visit(n, 0);
    while(!que.empty()){
        int q = que.front();
        que.pop();
        if(visit.at(q))continue;
        visit.at(q) = 1;
        for(auto a : vec.at(q)){
            if(!visit.at(a)){
                cnt.at(a) += cnt.at(q);
                que.push(a);
            }
        }
    }
    for(int i = 0;i < n;i++){
        cout<<cnt.at(i)<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 17140
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include<iomanip>
#define sqr(x) (x)*(x)
#define ll long long
using namespace std;
ll n,m,fac[100005],i;
int main()
{
	cin>>n>>m;
	if (abs(n-m)>1) 
	{
		cout<<0<<endl;
		return 0;
	}
	fac[0]=1;
	for (i=1;i<=max(n,m);i++) fac[i]=(fac[i-1]*i)%((ll)(1e9+7));
	if (n==m)
	{
		cout<<fac[n]*fac[m]*2%((ll)(1e9+7))<<endl;
	}
	else cout<<fac[n]*fac[m]%((ll)(1e9+7))<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        NSlimes solver = new NSlimes();
        solver.solve(1, in, out);
        out.close();
    }

    static class NSlimes {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] a = new int[N + 1];
            long[] sum = new long[N + 1];
            for (int i = 1; i <= N; i++) {
                a[i] = in.nextInt();
                sum[i] = sum[i - 1] + a[i];
            }
            long[][] cost = new long[N + 1][N + 1];
            for (int start = N; start >= 1; start--) {
                for (int end = start + 1; end <= N; end++) {
                    cost[start][end] = Long.MAX_VALUE;
                    long sumAll = sum[end] - sum[start - 1];
                    for (int i = start + 1; i <= end; i++) {
                        long costLeft = cost[start][i - 1];
                        long costRight = cost[i][end];
                        cost[start][end] = Math.min(cost[start][end], costLeft + costRight + sumAll);
                    }
                }
            }
            out.println(cost[1][N]);
        }

    }
}



Measured memory_bytes: 24148
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    append = peaks.append
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            append(upPeak)
            append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

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

int buff[][7] = {
  {0, 1, 2, 4, 6, 7, 9},
  {1, 3, 4, 6, 8, 9, 11},
  {2, 4, 5, 7, 9, 10, 12},
  {4, 6, 7, 9, 11, 12, 14},
  {6, 8, 9, 11, 13, 14, 16},
  {7, 9, 10, 12, 14, 15, 17},
  {9, 11, 12, 14, 16, 17, 18}
};
int main()
{
  string S;
  int arr[7];
  
  while(cin >> S, S != "#") {
    bool f = true;
    for(int i = 0; i < 1 << 19; i++) {
      int sum = 0;
      for(int j = 0; j < 7; j++) {
        arr[j] = 0;
        for(int k = 0; k < 7; k++) arr[j] += ((i >> buff[j][k]) & 1) << k;
        sum += (S[arr[j]] - '0') << j;
      }
      if(S[sum] != S[arr[3]]) f = false;
    }
    cout << (f ? "yes" : "no") << endl;
  }
}

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

int main() {
    string s,p,q;
    int m,y;
    cin>>s;
   m = (s[0]-'0')*(10) + (s[1]-'0');
   y = (s[2]-'0')*(10) + (s[3]-'0');
    if((m<=0 || m>=13) && (y<=0 || y>=13))
       {
           cout<<"NA"<<endl;
       }
       else if((m>=1 && m<=12) &&(y>=1 && y<=12))
        {
            cout<<"AMBIGUOUS"<<endl;
        }
        else if(m>=1 && m<=12)
        {
            cout<<"MMYY"<<endl;
        }
        else if(y>=1 && y<=12)
        {
            cout<<"YYMM"<<endl;
        }

}


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

int main() {
   int p = 0;
   string n;
   cin >> n;
    for (int i = 0; i < n.size(); ++i) {
        if(n[i] == '+'){
            p++;
        }else{
            p--;
        }
    }
    cout << p << endl;
}

Measured memory_bytes: 256
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 
inline int gi() {
    register int data = 0, w = 1; 
    register char ch = 0; 
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
} 
const int MAX_N = 3e5 + 5; 
int N, M; 
pair<int, int> p[MAX_N]; 
int ls[MAX_N << 5], rs[MAX_N << 5], sum[MAX_N << 5]; 
int rt[MAX_N], tot; 
void modify(int &o, int p, int l, int r, int pos) { 
	o = ++tot; 
	ls[o] = ls[p], rs[o] = rs[p], sum[o] = sum[p] + 1; 
	if (l == r) return ; 
	int mid = (l + r) >> 1; 
	if (pos <= mid) modify(ls[o], ls[p], l, mid, pos); 
	else modify(rs[o], rs[p], mid + 1, r, pos); 
} 
int query(int u, int v, int l, int r, int ql, int qr) { 
	if (ql <= l && r <= qr) return sum[v] - sum[u]; 
	int mid = (l + r) >> 1, res = 0; 
	if (ql <= mid) res += query(ls[u], ls[v], l, mid, ql, qr); 
	if (qr > mid) res += query(rs[u], rs[v], mid + 1, r, ql, qr); 
	return res; 
} 

int main () { 
	N = gi(), M = gi(); 
	for (int i = 1; i <= N; i++)
		p[i].first = gi(), p[i].second = gi(); 
	sort(&p[1], &p[N + 1]); 
	for (int i = 1, j = 1; i <= M; i++) { 
		rt[i] = rt[i - 1]; 
		while (p[j].first == i && j <= N) modify(rt[i], rt[i], 1, M, p[j].second), ++j; 
	} 
	for (int d = 1; d <= M; d++) { 
		int ans = 0; 
		for (int i = d, pre = 0; i <= M; i += d) 
			ans += query(rt[pre], rt[i], 1, M, i, M), pre = i; 
		printf("%d\n", ans); 
	} 
    return 0; 
} 

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

int main() {
    int k,s;
    cin >> k >> s;
    int counter=0;
    for(int x=0; x <= k; x++){
        for(int y=0; y <= k; y++){
            int z = s - x - y;
            if(0 <= z && z <= k){
                counter++;
            }
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
from sys import stdin
import math

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    L = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = (L/3)**3
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 38384
import math
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

a = (2*X - Y) // 3
b = (2*Y - X) // 3

FACT = [1]*1000001
for i in range(1, 1000001):
    FACT[i] = (FACT[i-1]*i)%MOD

if (2*X - Y)%3 == 0 and (2*Y - X)%3 == 0 and a >= 0 and b >= 0:
    print(DIV(DIV(FACT[a+b], FACT[a]), FACT[b]))
else:
    print(0)


Measured memory_bytes: 47980
#include <bits/stdc++.h>
using namespace std;
int main(){
  int dx[]={0,1,1,1,0,-1,-1,-1};
  int dy[]={-1,-1,0,1,1,1,0,-1};
  int H,W;
  cin >> H >> W;
  vector<vector<char>> board(H+2,vector<char>(W+2,'x'));
  for(int i=1; i<H+1; i++){
    for(int j=1; j<W+1; j++){
      char x;
      cin >> x;
      board[i][j]=x;
    }
  }
  for(int i=1; i<H+1; i++){
    for(int j=1; j<W+1; j++){
      if(board[i][j]=='.'){
        int temp=0;
        for(int k=0; k<8; k++){
          if(board[i+dy[k]][j+dx[k]]=='#'){
            temp++;
          }
        }
        board[i][j]=temp+'0';
      }
    }
  }
  for(int i=1; i<H+1; i++){
    for(int j=1; j<W+1; j++){
      cout << board[i][j];
      if(j==W){
        cout << endl;
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100001

int partition(int A[],int p,int r){
  int x,i,j,m;
  x=A[r];
  i=p-1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      m=A[i];
      A[i]=A[j];
      A[j]=m;
    }
  }
  m=A[i+1];
  A[i+1]=A[r];
  A[r]=m;  
  return i+1;

}

int main(){
  int n,i,x,A[N];

  scanf("%d",&n);

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

  x=partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i==x)printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i<n-1)printf(" ");

  }
  printf("\n");


  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main() {
	int m,n;
	cin>>m>>n;
	int sum=0;
	while(n--){
		int x;
		cin>>x;
		sum+=x;
	}
	m-=sum;
	if(m<0){
		cout<<-1;
	}
	else{
		cout<<m;
	}

	return 0;
}


Measured memory_bytes: 3620
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
	Ryuga;

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("op.txt","w",stdout);
	#endif

	clock_t startTime=clock();

	ll n;
	cin>>n;
	if(n%1000==0)
	{
		cout<<"0";
		return 0;
	}

	ll val=(ll)ceil((n*1.0)/1000);
	cout<<1000*val - n;

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 3912
s = input();t=s[:len(s)//2];u=s[len(s)//2+1:]

def check(string):
  for i in range(len(string)):
    if string[i] != string[len(string)-i-1]:
      return False
  return True
  
print("Yes" if all([check(s),check(t),check(u)]) else "No")

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>



using namespace std;
int N,M,K,H,W,P[1000],ans,amari[10];
bool point[301][301],link[301][301],xsw,zero;
char a[100][100],b[100000];
string A,B,C;


int abs(int x){
	if(x<0){
		return -x;
	}
	return x;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}
int max(int x,int y){
	if(x>y)return x;
	
	return y;
}

int main(){
	cin >>N>>M>>K;
	ans=0;
	for(int i=1;i<M;i++){
		if(N*i%M==K){
			ans=1;
		}
	}


	if(ans==1){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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

typedef double                 ld;
typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = 3e3 + 10;
const ll MXM = 5e2 + 10;
const ll MX5 = 1e5 + 10;
const ll MX6 = 1e6 + 10;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

ll n, m, SZ[MX5];
vector<ll> G[MX5];
bool vis[MX5];
map<pll, ll> mp;
ll R[MX5];
vector<pll> V;

void DFS(ll u, ll par){
    vis[u] = 1;
    for(auto v : G[u]){
        if(!vis[v]){
            if(R[u] + 1 == mp[{u, par}] || R[u] + 1 == mp[{par, u}]) R[u]++;
            mp[{u, v}] = R[u] + 1;
            mp[{v, u}] = R[u] + 1;
            R[u] ++;
            DFS(v, u);
        }
    }
    return;
}

int main(){
    fast_io
    //file_io
    cin >> n;
    m = n - 1;
    for(int i = 0; i < m; i ++){
        ll u, v;
        cin >> u >> v;
        V.pb({u, v});
        G[u].pb(v);
        G[v].pb(u);
        SZ[u] ++;
        SZ[v] ++;
    }

    ll ans = *max_element(SZ, SZ + n);cout << ans << endl;

    DFS(1, -1);

    for(int i = 0; i < m; i ++){
        ll u = V[i].F, v = V[i].S;
        cout << mp[{u, v}] << endl;
    }


    return 0;
}

//! N.N


Measured memory_bytes: 22256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

string N;
bool f(int X) {
  int s = X-1, d = 9, r = 0;
  for (char c : N) {
    int digit = c-'0';
    int mx = s*9 + d + r;
    if (mx < digit) return false;
    int k = (mx - digit) / 10;
    r = k;

    int waste = mx - (10*k+digit);
    if (waste > d) {
      waste -= d;
      if (s == 0) return false;
      d = 9 - waste;
      s--;
    }
    else d -= waste;
  }
  return true;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  reverse(all(N));
  int lo = 0, hi = (int)N.length() + 1;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (f(mid)) hi = mid;
    else lo = mid;
  }
  cout << hi << "\n";
  return 0;
}


Measured memory_bytes: 1172
def readinput():
    n=int(input())
    return n

def main(n):
    MOD=10**9+7
    ans=pow(10,n,MOD)-pow(9,n,MOD)-pow(9,n,MOD)+pow(8,n,MOD)
    ans=(ans+MOD)%MOD
    return ans

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


Measured memory_bytes: 9176
N = int(input())
A = [int(x) for x in input().split()]
totalChooseNum = N // 2
dp = {0 : 0}
for i in range(0, N):
    ai = A[i]
    canChooseNum = (N - i + 1) // 2
    mustChooseNum = max(totalChooseNum - canChooseNum, 0)
    next = {}
    for j in range(mustChooseNum, N):
        if j > 0 and (2 * (j - 1)) in dp:
            next[2 * j + 1] = dp[2 * (j - 1)] + ai
        if 2 * j in dp:
            if 2 * j + 1 in dp:
                next[2 * j] = max(dp[2 * j] , dp[2 * j + 1])
            else:
                next[2 * j] = dp[2 * j]
        elif 2 * j + 1 in dp:
            next[2 * j] = dp[2 * j + 1]
        else:
            break
    dp = next
result = max(dp[totalChooseNum * 2] , dp[totalChooseNum * 2 + 1])
print(result)


Measured memory_bytes: 30876
# 整数の入力
City = int(input())
# スペース区切りの整数の入力
Mons = [int(a) for a in input().split()]
# スペース区切りの整数の入力
Blave = [int(b) for b in input().split()]


slash = 0


for i in range(City):
  if Blave[i] > Mons[i]:
    slash += Mons[i]
    Sword = Blave[i] - Mons[i]
    if Sword > Mons[i+1]:
      slash += Mons[i+1]
      Mons[i+1] = 0
    else :
      slash += Sword
      Mons[i+1] -= Sword
  else:
    slash += Blave[i]


print('{}'.format(slash))

Measured memory_bytes: 18624
var
 x,b,c,i,j:longint;
 a:array[1..3,1..3] of longint;
begin
 readln(x,b,c);
  a[1,1]:=x;
  a[1,2]:=b;
  a[2,2]:=c;  
  a[3,2]:=c*3-b-c;
  a[2,3]:=x*2-a[3,2];
  a[3,1]:=(a[2,3]+a[1,2]) div 2;
  a[2,1]:=c*3-a[1,1]-a[3,1];
  a[3,3]:=(a[2,1]+a[1,2]) div 2;
  a[1,3]:=(a[3,2]+a[2,1]) div 2;
 for i:=1 to 3 do
  begin
   for j:=1 to 3 do write(a[i,j],' ');
    writeln;
  end;
end.


Measured memory_bytes: 128
/* C++14(GCC5.4.1) */
#include <bits/stdc++.h>
using namespace std;
static const int MAX_N = 200100;
using Graph = vector<vector<int>>;

int counts_node[MAX_N] = {0};

// 木上の探索
// v: 現在探索中の頂点、p: v の親 (v が根のときは -1)
void dfs(const Graph &G, int v, int p) {
    if(p!=-1) counts_node[v] += counts_node[p];
    for (auto nv : G[v]) {
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v); // v は新たに nv の親になります
    }
}


int main(void){
    // 入力
    int n,q; cin >> n >> q;

    // グラフ入力
    Graph G(n);//ここ[n]にしててバグらせてた
    for(int i=0; i<n-1; i++){
        // i番目の辺が結ぶ頂点がa,b
        int a,b;
        cin >> a >> b;
        // 親から子へしかいけないものとする
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // q個の操作の入力
    vector<pair<int,int>> PX(q);
    for(int i=0; i<q; i++){
        cin >> PX[i].first >> PX[i].second;
    }


    // q個の操作を順に行う
    // ここでは親になるノードにだけ
    for(int i=0; i<q; i++){
        counts_node[PX[i].first-1] += PX[i].second;
    }

    // 子に自分の値を加算
    // 根に近い方からやると線形時間
    // 根から順に操作する方法は「木上のdfs」した時のを参考に.
    // 一回dfsすることになるのかな
    dfs(G,0,-1);

    for(int i=0; i<n; i++){
        cout << counts_node[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 25088
import sys
import numpy as np
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int,input().split()))

    mod = 10 ** 9 + 7

    a_bin = [format(i, 'b') for i in a]

    m = len(max(a_bin, key = len))

    ans = 0

    for i in range(n):
        a_bin[i] = '0' * (m - len(a_bin[i])) + a_bin[i]

    for i in range(1, m+1):
        count = [0, 0]
        for j in a_bin:
            count[int(j[-i])] += 1
        ans += count[0] * count[1] * 2 ** (i-1)

    print(ans % mod)

def main2():
    n = int(input())
    a = list(map(int,input().split()))

    a = np.array(a)
    ans = 0
    mod = 10**9 + 7

    for i in range(60):
        count = np.count_nonzero(a & 1)
        ans += count * (n - count) * 2 ** i
        a >>= 1

    print(ans % mod)

if __name__ == '__main__':
    main2()



Measured memory_bytes: 48776
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 100000;

int n, m;
vector<int> adj[MAXN];
int col[MAXN];
int q[MAXN], qhead, qtail;

void run() {
	scanf("%d%d", &n, &m);
	REP(i, m) { int a, b; scanf("%d%d", &a, &b); --a, --b; adj[a].PB(b); adj[b].PB(a); }

	REP(i, n) col[i] = -1; qhead = qtail = 0;
	col[0] = 0, q[qhead++] = 0; bool ok = true;
	while (qtail < qhead) {
		int at = q[qtail++];
		REPSZ(i, adj[at]) {
			int to = adj[at][i];
			if (col[to] == -1) { col[to] = 1 - col[at]; q[qhead++] = to; continue; }
			if (col[to] == col[at]) ok = false;
		}
	}

	ll ret;
	if (ok) {
		int na = 0, nb = 0; REP(i, n) if (col[i] == 0) ++na; else ++nb;
		ret = (ll)na*nb - m;
	} else {
		ret = (ll)n*(n - 1) / 2 - m;
	}
	printf("%lld\n", ret);
}

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


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n, k;
    cin >> n >> k;
    db v[n];
    rep(i, 0, n) {
        cin >> v[i];
    }
    db s = 0.0;
    rep(i, 0, k) {
        s += (((v[i] * (v[i] + 1)) / 2) / v[i]);
    }
    db ans = s;
    rep(i, k, n) {
        s = s - (((v[i-k] * (v[i-k] + 1)) / 2) / v[i-k]) + (((v[i] * (v[i] + 1)) / 2) / v[i]);
        ans = max(ans, s);
    }
    cout << fixed << setprecision(12) << ans << '\n';

    return 0;
}

Measured memory_bytes: 1792
N,A,B,C=map(int,input().split())
S=['']*(N+1)
for a in range(N):
    S[a]=input()

ans='Yes'
L_ans=['']*(N+1)
i=0
while i<N:
    if S[i]=='AB':
        if A>B:
            B+=1
            A-=1
            L_ans[i]='B'
        elif A<B:
            A+=1
            B-=1
            L_ans[i]='A'
        elif A==B and S[i+1]=='BC':
            B+=1
            A-=1
            L_ans[i]='B'
        else:
            A+=1
            B-=1
            L_ans[i]='A'
    elif S[i]=='AC':
        if A>C:
            C+=1
            A-=1
            L_ans[i]='C'
        elif A<C:
            A+=1
            C-=1
            L_ans[i]='A'
        elif A==C and S[i+1]=='BC':
            C+=1
            A-=1
            L_ans[i]='C'
        else:
            A+=1
            C-=1
            L_ans[i]='A'
    elif S[i]=='BC':
        if C>B:
            B+=1
            C-=1
            L_ans[i]='B'
        elif C<B:
            C+=1
            B-=1
            L_ans[i]='C'
        elif B==C and S[i+1]=='AB':
            B+=1
            C-=1
            L_ans[i]='B'
        else:
            C+=1
            B-=1
            L_ans[i]='C'
    i+=1
    if any([A<0,B<0,C<0]):
        ans='No'
        break

print(ans)
if ans=='Yes':
    j=0
    while j<N:
        print(L_ans[j])
        j+=1

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


using namespace std;

#define endl '\n'
#define PB push_back
#define MP make_pair
#define LL long long
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(5);
    cout << fixed;

    int a, b, c;

    cin >> a >> b >> c;


    if(a > b) {

        cout << 0 << endl;
     
    }
    else if(b/a < c) {

        cout << b/a << endl;
    }

    else if(b/a >= c){

        cout << c << endl;
    }


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXNUM 222111
#define rep(i,s,t) for(int i=s;i<t;i++)
#define pii pair<int,int>
typedef long long ll;
int a[MAXNUM],b[MAXNUM];
int main()
{
    int n;scanf("%d",&n);
    rep(i,1,n+1)scanf("%d",&a[i]);
    priority_queue<pii> pq;
    rep(i,1,n+1){
        scanf("%d",&b[i]);
        if(b[i]!=a[i])
            pq.emplace(b[i],i);
    }
    ll res=0;
    while(!pq.empty())
    {
        pii p=pq.top();pq.pop();
        int sum=(b[p.second%n+1]+b[(p.second-2+n)%n+1]),num=max(b[p.second%n+1],b[(p.second-2+n)%n+1]);
        num=max(num,a[p.second]);
        int k=max(1,(b[p.second]-num)/sum);
        b[p.second]-=k*sum,res+=k;
        if(b[p.second]<a[p.second]){res=-1;break;}
        else if(b[p.second]>a[p.second])
            pq.emplace(b[p.second],p.second);
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 3700
L,R = map(int,input().split())
N = R-L
if N >= 2019:
  print(0)
else:
  c = L*(L+1)%2019
  for i in range(L,R+1):
    for j in range(i+1,R+1):
      x = i*j % 2019
      if c > x:
        c = x
  print(c)

Measured memory_bytes: 3060
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn main() {
    let n: i64 = input!(i64);
    let a_vec:Vec<i64> = input!(i64; n);
    println!("{}", a_vec.iter().map(|x| x - 1).fold(0, |sum, i| sum + i));
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main (){
    int i;
    bool A;
    A = false;
    char S[6];
    cin >> S;
    for (i=0;i<5;i++){
        if(S[i]=='A'&& S[i+1]=='C'){A = true;}
    }
    if(A){cout << "Yes" << endl;}
    else {cout << "No" << endl;}
    return 0;
}


Measured memory_bytes: 256
// Example program
#include <iostream>
#include <string>

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int start = max(a, c);
    int end = min(b, d);
    if(start > end){
        cout << 0;
    }
    else cout << end - start;
}


Measured memory_bytes: 256
def grade(m, f, r):
    if m == -1 or f == -1:
        return 'F'

    if 80 <= m+f:
        return 'A'

    if 65 <= m+f:
        return 'B'

    if 50 <= m+f:
        return 'C'

    if 30 <= m+f:
        return 'C' if 50 <= r else 'D'

    return 'F'

def main():
    while True:
        m, f, r = [int(x) for x in input().split()]
        if m == f == r == -1:
            break

        print(grade(m,f,r))

if __name__ == '__main__':
    main()



Measured memory_bytes: 5604
import Data.Bits (xor)
import Data.Bool (bool)

main :: IO ()
main = do
    s <- getLine
    answer $ solve s

type Answer = Bool
answer :: Answer -> IO ()
answer = putStrLn . bool "First" "Second"

solve :: String -> Answer
solve = last' . flip (zipWith . ((.) xor . (==)) . head <*> id) (iterate not False)
  where
    last' = bool . last' . tail <*> head <*> null . tail


Measured memory_bytes: 12668
N,M,K=map(int,input().split())
MOD=998244353

#逆元を定義する
def inv(a):
  return pow(a,MOD-2,MOD)

#「n!」の剰余を求める
fact=[0,1]
for i in range(2,N+1):
  fact.append((fact[-1]*i)%MOD)

#nCr(MOD)を求める
def choose(n,r):
  if r==0 or r==n:
    return 1
  else:
    return fact[n]*inv(fact[r])*inv(fact[n-r])%MOD

#(M-1)**n(MOD)を求める
exp=[1]
for i in range(1,N):
  exp.append((exp[-1]*(M-1))%MOD)  
  

#答えを計算する
ans=0
for i in range(K+1):
  ans+=(M*choose(N-1,i)*exp[N-1-i]%MOD)  
  ans%=MOD
print(ans)  

Measured memory_bytes: 86196