akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
    int d, r, a, b;
    double f;
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a /(double) b;
    printf("%d %d %.5f\n", d, r, f);
    return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	char a;
	cin >> a;
	if(a == 'a' or a == 'e' or a == 'i' or a == 'o' or a == 'u'){
		cout << "vowel";
	}
	else{
		cout << "consonant";
	}
	
	return 0;
}


Measured memory_bytes: 256
from collections import deque

k = int(input())


if k < 10:
    print(k)
    exit()

q = deque()
lun = []
for i in range(1, 10):
    q.append(i)
    lun.append(i)

cnt = 9
while cnt < k:
    x = q.popleft()
    if x % 10 == 0:
        nx = 10 * x
        q.append(nx)
        lun.append(nx)
        nx = 10 * x + 1
        q.append(nx)
        lun.append(nx)
        cnt += 2
    elif x % 10 == 9:
        nx = 10 * x + 8
        q.append(nx)
        lun.append(nx)
        nx = 10 * x + 9
        q.append(nx)
        lun.append(nx)
        cnt += 2
    else:
        m = x % 10
        nx = 10 * x + m - 1
        q.append(nx)
        lun.append(nx)
        nx = 10 * x + m
        q.append(nx)
        lun.append(nx)
        nx = 10 * x + m + 1
        q.append(nx)
        lun.append(nx)
        cnt += 3
lun.sort()
print(lun[k-1])


Measured memory_bytes: 13808
N,X,M = [int(a) for a in input().split()]
amari = [0]*M
i = 1
A = X
amari[A] = i
l = [X]
ichi = i
while i<=M:
    i += 1
    A = A**2 % M
    if amari[A]: i += M
    else:
        amari[A] = i
        l.append(A)
    if i==N: i = M+1
else:
    if i>M+1: ni = i-M - amari[A]
    else: ni = 0
#for j in range(M):
#    if amari[j]: print(j, amari[j])
#print(i,len(l))
ichi = len(l) - ni
#print(l)
if ni:
    ni_times, san = divmod((N - ichi), ni)
    #print(ichi, '%d*%d'%(ni,ni_times), san)
    print(sum(l[:ichi]) + 
          sum(l[ichi:])*ni_times + 
          sum(l[ichi:ichi+san]))
else:
    #print(ichi, '%d*%d'%(ni,ni_times), san)
    print(sum(l))

Measured memory_bytes: 13316
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    bool operator==(const mint a){
        return (x == a.x);
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

//nが非常に大きく、aが小さい場合
mint choose(int n, int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

vector<int> to[100005];
mint ans;
int N, K;
combination comb(100005);

mint f(int n, int k){
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n,k);
    res *= comb.fact[k];
    return res;
}

void dfs(int v, int p=-1){
    for (int u : to[v]){
        if (u==p) continue;
        dfs(u,v);
    }
    int nk = (p==-1) ? K : K -2;
    int c = (p==-1) ? to[v].size()+1 : to[v].size()-1;
    ans *= f(nk,c);
}

int main(){
    cin >> N >> K;
    rep(i,N-1){
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans = 1;
    dfs(0);
    cout << ans << endl; 
}

Measured memory_bytes: 13828
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
int main()
{
	int n;
	long long ans=0;
	cin>>n;
	vector<int> a(n);
	for(int& x:a)
	cin>>x;
	long long ss=0;
	for(int i=0;i<n;i++)
	{
		ans= (ans+(long long)a[i]*ss)%INF;
		//cout<<ans<<" ";
		ss=(ss+a[i])%INF;
		//cout<<ss<<endl;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4036
import java.util.*;
import java.io.*;
import java.text.*;
import java.util.zip.Adler32;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        char[]s = sc.nextLine().toCharArray();
        char[]t = sc.nextLine().toCharArray();
        int ans=0;
        for (int i =0;i<s.length;i++)if (s[i]!=t[i])ans++;
        pw.println(ans);
        pw.flush();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

Measured memory_bytes: 37820
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    String t;
    int count = 0;

    for(int i=0 ; i<=s.length()-3 ; i++){
      t = s.substring(i,i+3);
      if(t.equals("ABC")){
        count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21716
from bisect import bisect_left

def main():
    N = int(input())
    L = list(map(int, input().split()))
    
    L = sorted(L)
    ans = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            k = bisect_left(L[j+1:], a + L[j])
            ans += k

    print(ans)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 50528
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Main
{
    public static class Program
    {
        static void Main(string[] arg)
        {
            int n = int.Parse(Console.ReadLine());
            double answer = Math.Pow(n,3);

            Console.WriteLine(answer);
            Console.ReadLine();
 
        }
        
        #region libraries
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();
 
        }
        private static double[] GetDoubleList(string line)
        {
            return line.Split(' ').Select(x => double.Parse(x)).ToArray();
 
        }
        private static ulong[] GetUlongList(string line)
        {
            return line.Split(' ').Select(x => ulong.Parse(x)).ToArray();
        }
        private static long[] GetLongList(string line)
        {
            return line.Split(' ').Select(x => long.Parse(x)).ToArray();
        }
        private static int SearchNearest(this IEnumerable<int> list, int target)
        {
            var min = list.Min(c => Math.Abs(c - target));
            return list.First(c => Math.Abs(c - target) == min);
        }
        public static bool IsOdd(int i)
        {
            return i % 2 == 1 ? true : false;
        }
        public static int Gcd(int a,int b)
        {
            if(a < b)
            {
                Gcd(b, a);
            }
            while (b != 0)
            {
                var rm = a % b;
                a = b;
                b = rm;
            }
            return a;
        }
        #endregion
    }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        // educational dp 2

        int n = sc.nextInt();

        long[] dp = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            dp[i] = i;
        }

        int six = 1;

        while (six * 6 <= n) {
            six *= 6;
            for (int i = 0; i <= n - six; i++) {
                dp[i + six] = Math.min(dp[i + six], dp[i] + 1);
            }
        }

        int nine = 1;

        while (nine * 9 <= n) {
            nine *= 9;
            for (int i = 0; i <= n - nine; i++) {
                dp[i + nine] = Math.min(dp[i + nine], dp[i] + 1);
            }
        }
        System.out.println(dp[n]);
    }
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;

  int cnt_g = 0;
  int cnt_p = 0;

  int ans = 0;

  rep(i, s.length()){
    if(s[i] == 'g'){
      if(cnt_p < cnt_g){
        ans++;
        cnt_p++;
      }else{
        cnt_g++;
      }
    }else{
      if(cnt_p < cnt_g){
        cnt_p++;
      }else{
        cnt_g++;
        ans--;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

const int MAXN = 1010;
const int MAXM = 2.1e5;
int N, M;
int A[MAXM];
int B[MAXM];
vector<int> adj[MAXN];

bool reach[MAXN][MAXN];

bool vis[MAXN];
bool bad[MAXN][MAXN];

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

	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i]; A[i]--, B[i]--;
		adj[A[i]].push_back(B[i]);
	}

	// 1. reach[][]
	{
		for (int st = 0; st < N; st++) {
			function<void(int)> dfs = [&](int cur) -> void {
				if (reach[st][cur]) return;
				reach[st][cur] = true;
				for (int nxt : adj[cur]) {
					dfs(nxt);
				}
			};
			dfs(st);
		}
	}

	// 2. bad[][]
	{
		for (int st = 0; st < N; st++) {
			function<void(int)> dfs = [&](int cur) -> void {
				if (st == cur) return;
				if (vis[cur]) return;
				vis[cur] = true;
				for (int nxt : adj[cur]) {
					dfs(nxt);
				}
			};

			for (int z = 0; z < 2; z++) {
				fill(vis, vis+N, false);
				for (int nxt : adj[st]) {
					if (vis[nxt]) {
						bad[st][nxt] = true;
					} else {
						dfs(nxt);
					}
				}
				reverse(adj[st].begin(), adj[st].end());
			}
		}
	}

	for (int i = 0; i < M; i++) {
		int a = A[i], b = B[i];
		if (reach[b][a] == bad[a][b]) {
			cout << "same" << '\n';
		} else {
			cout << "diff" << '\n';
		}
	}

	return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
 
string kata;

int n;

int main(){
	int k,i,j;
	
	scanf("%d %d",&n,&k);
	cin>>kata;
	
	int cnt = 0, cnt1 = 0;
	set<ii> s, s1;
	int maks = 0;
	vii listPas;
	for(i=0;i<n;i++){
		if(kata[i] == '0'){
			if(cnt1){
				maks = max(maks, cnt1);
				s1.insert(ii(i-cnt1,i-1));
				// printf("dipush 1 %d %d\n",i-cnt1, i-1);
				cnt1 = 0;
			}
			cnt++;
		}else if(kata[i] == '1') {
			cnt1++;
			if(cnt){
				s.insert(ii(i-cnt,i-1));
				listPas.pb(ii(i-cnt, i-1));
				// printf("dipush 0 %d %d\n",i-cnt, i-1);
				cnt = 0;
			}
		}
	}
	if(kata[i-1] == '0'){
		s.insert(ii(i-cnt, i-1));
		listPas.pb(ii(i-cnt, i-1));
		// printf("dipush 0 %d %d\n",i-cnt, i-1);
	}else{
		maks = max(maks, cnt1);
		s1.insert(ii(i-cnt1,i-1));
		// printf("dipush 1 %d %d\n",i-cnt1, i-1);
	}
	
	if(listPas.size() <= k){
		printf("%d\n",n);
	}else{
		int left = 0, right = k-1;
		int ans = maks;
		set<ii>::iterator it, it2;
		while(right < listPas.size()) {
			int palingKiri = listPas[left].first;
			int palingKanan = listPas[right].second;
			it = s1.lower_bound(ii(palingKiri, 0));
			ii kiri = ii(1,0);
			if(it != s1.begin()){
				it--;
				kiri = *it;	
			}

			it = s1.lower_bound(ii(palingKanan+1, 0));
			ii kanan = ii(1,0);
			if(it != s1.end()){
				kanan = *it;
			}

			if(kiri != ii(1,0)){
				palingKiri = kiri.first;
			}
			if(kanan != ii(1,0)){
				palingKanan = kanan.second;
			}
			ans = max(ans, palingKanan - palingKiri + 1);

			right++;
			left++;
		}
		printf("%d\n",ans);
		return 0;
	}
	
	
	return 0;
};

Measured memory_bytes: 5368
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<ll, int>;

struct Edge{
  int to;
  ll weight;
  Edge(int t, ll w) : to(t), weight(w) {}
};

vector<vector<Edge>> g;
int n;

vector<ll> dist;
void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  dist[s] = 0;
  que.push({dist[s], s});

  while(!que.empty()){
    auto v = que.top();
    que.pop();
    int from = v.second;
    ll d = v.first;
    if(d > dist[from])continue;

    for(auto nv : g[from]){
      ll cost = nv.weight;
      int to = nv.to;
      if(dist[from] + cost < dist[to]){
        dist[to] = dist[from] + cost;
        que.push({dist[to], to});
      }
    }
  }
}


int main(){
  cin >> n;
  g.resize(n);
  for(int i = 0; i < n - 1; ++i){
    int a, b;
    ll c;
    cin >> a >> b >> c;
    --a;
    --b;
    g[a].push_back(Edge(b, c));
    g[b].push_back(Edge(a, c));
  }

  int q, k;
  cin >> q >> k;
  --k;
  dist.assign(n, LINF);
  dijkstra(k);

  for(int i = 0; i < q; ++i){
    int x, y;
    cin >> x >> y;
    --x;
    --y;

    cout << dist[x] + dist[y] << endl;
  }

  return 0;
}


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

long long* h;

bool f(long long p, long long q)
{
    return h[p] < h[q];
}

int main()
{
    long long N;
    cin >> N;
    h = new long long[N+1];
    long long a[N+1];
    for(long long i = 1; i <= N; i++) cin >> h[i];
    for(long long i = 1; i <= N; i++) cin >> a[i];

    long long ind[N];
    for(long long i = 0; i < N; i++) ind[i] = i+1;
    sort(ind, ind+N, f);

    long long BIT[N+1];
    for(long long i = 1; i <= N; i++) BIT[i] = 0;

    long long r, res = 0;
    for(long long i: ind)
    {
        r = a[i];
        for(long long j = i-1; j >= 1; j -= j&-j) r = max(r, BIT[j] + a[i]);
        res = max(res, r);
        for(long long j = i; j <= N; j += j&-j) BIT[j] = max(BIT[j], r);
    }
    cout << res << '\n';
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n,m;
  cin >> n >> m;
  map<int,int> mp;
  REP(i,n){
    int a;
    cin >> a;
    mp[a]++;
  }
  REP(i,m){
    int b,c;
    cin >> b >> c;
    mp[c]+=b;
  }
  vector<P> c;
  for(auto v: mp){
    c.push_back({v.first, v.second});
  }
  sort(RALL(c));

  ll ans=0;
  int cnt=0;
  REP(i,c.size()){
    if(cnt + c[i].second >= n){
      ans += (n-cnt)*(ll)c[i].first;
      break;
    }else{
      ans += (ll)c[i].first * c[i].second;
      cnt += c[i].second;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 14632
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main(){
    char p[200],p2[100],s[100];
 
    scanf("%s",p);
    strcpy(p2,p);
    strcat(p,p2);
    scanf("%s",s);
 
    if(strstr(p,s)){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

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

int main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  cout<<x2+y1-y2<<' '<<y2-x1+x2<<' '<<x1+y1-y2<<' '<<y1-x1+x2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <vector>

#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DV_NUM (100000007)

using namespace std;
 
int main()
{
    int N;
    cin >> N;

    int numPaper = N / 2 + N % 2;   

    cout << numPaper << endl;
 
    return 0;
 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>

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

using namespace std;

int main() {
	vector<int>a(3);
	rep(i, 3) {
		cin >> a[i];
	}
	swap(a[0], a[1]);
	swap(a[0], a[2]);
	rep(i, 3) {
		cout << a[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);

	int l[210];
	for (int i = 0; i < 2*n; i++) {
		scanf("%d",&l[i]);
	}
	sort(l, l + 2*n);

	int ans = 0;
	for (int i = 0; i < 2*n; i++) {
		if (i % 2 == 0)ans += l[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())

def make_divisors(num):
    divisors = []
    for i in range(1, int(num**0.5)+1):
        if n % i == 0:
            divisors.append(i)
    return divisors

divisors = make_divisors(n)
x, y = divisors[-1], n // divisors[-1]
print(x + y - 2)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,k=mii()
arr=limii()
ans=10**1000
for i in range(n-k+1):
    ans=min(ans, abs(arr[i])+abs(arr[i]-arr[i+k-1]),abs(arr[i+k-1])+abs(arr[i]-arr[i+k-1]))
print(ans)

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

using namespace std;

double dp[310][310][310];
int n;
double solve(int i,int j,int k){
   if(dp[i][j][k]!=-1.0)
      return dp[i][j][k];
   double ans=0;
   double e = 1.0*(n)/(1.0*(i+j+k));
   if(i){
      ans+=(solve(i-1,j,k)+e)*((1.0*i)/(1.0*(i+j+k)));

   }
   if(j){
      ans+=(solve(i+1,j-1,k)+e)*((1.0*j)/(1.0*(i+j+k)));

   }
   if(k){
      ans+=(solve(i,j+1,k-1)+e)*((1.0*k)/(1.0*(i+j+k)));

   }
   dp[i][j][k]=ans;
   return ans;

}
int main()
{
   cin >>n;
   for(int i=0;i<=n;++i)
    for(int j=0;j<=n;++j)
      for(int k=0;k<=n;++k)
        dp[i][j][k]=-1.0;
 vector<int>s(4,0);
 int t;
 for(int i=0;i<n;++i){
   cin >>t;
   s[t]++;
 }
 dp[0][0][0]=0;
 double ans = solve(s[1],s[2],s[3]);
 cout << fixed<< setprecision(11) <<ans <<endl;
 return 0;

}


Measured memory_bytes: 224372
#include<bits/stdc++.h>
using namespace std;
bool overlap(int a,int b,int c,int d){
  if(d<=a) return false;
  if(b<=c) return false;
    
  return true;
}
int main(){
  int a,b,s,f,n;
  cin >> a >> b >> n;
  for(int i=0;i<n;i++){
    cin >> s >> f;
    if(overlap(a,b,s,f)){
      cout << 1 << endl;
      return 0;
    }
  }
    cout << 0 << endl;
    return 0;
  }



Measured memory_bytes: 3084
n,k = map(int,input().split())
P = list(map(int,input().split()))

P[0] = (P[0]+1.)/2
for i in range(1,len(P)):
    P[i] = (P[i]+1.)/2
    P[i] = P[i-1]+P[i]

ans = 0.

if n==1:
    ans = P[0]

elif len(P)-k==0:
    ans = P[k-1]
else:
    for i in range(len(P)-k):
        ans = max(ans,(P[i+k]-P[i]))
        
    
print(ans)

Measured memory_bytes: 32064
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int h,w;
  char c[105][105];
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>c[i][j];
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<w;k++){
	cout<<c[i][k];
      }
      cout<<endl;
    }
  }
	  return(0);
}


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

int main()
{
    int w, h, n;
    int i;
    
    cin >> w >> h >> n;
    
    int x[n], y[n], a[n];
    
    int xmin = 0, ymin = 0, xmax = w, ymax = h;
    
    for(i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> a[i];
        
        if(a[i] == 1) {
            if(xmin < x[i]) {
                xmin = x[i];
            }
        } else if(a[i] == 2) {
            if(xmax > x[i]) {
                xmax = x[i];
            }
        } else if(a[i] == 3) {
            if(ymin < y[i]) {
                ymin = y[i];
            }
        } else {
            if(ymax > y[i]) {
                ymax = y[i];
            }
        }
    }
    
    if((xmax > xmin) && (ymax > ymin)) {
        cout << (xmax - xmin) * (ymax - ymin) << endl;
    } else {
        cout << "0\n";
    }
    
    return 0;
}

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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	bool inside = true;

	if( (x - r) < 0 ) { inside = false; }
	else if( (x + r) > W ) { inside = false; }
	else if( (y - r) < 0 ) { inside = false; }
	else if( (y + r) > H ) { inside = false; }

	cout << (inside ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3108
a,b,c = map(int,input().split())
if a == b and b == c and c == a:
    print(1)
elif a == b and b != c and c != a:
    print(2)
elif a != b and b == c and c != a:
    print(2)
elif a != b and b != c and c == a:
    print(2)
else:
    print(3)

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

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

int main() {
    int N, L; cin >> N >> L;
    int total = 0;
    vector<int> A(N, 0), B(N, 0);
    rep(i, N){
        A[i] = L + i;
        total += A[i];
        B[i] = abs(A[i]);
    }

    int mina = 1000000000, min_idx;
    rep(i, N){
        if(mina > B[i]){
            min_idx = i;
            mina = B[i];
        } 
    }

    cout << total - A[min_idx] << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var strs = str.Split(' ');

            var t = int.Parse(strs[0]);
            var x = int.Parse(strs[1]);

            Console.WriteLine((double)t / x);
        }
    }
}


Measured memory_bytes: 13140
import java.util.*;
 
public class Main {
 
    private static Scanner sc;
 
    public static void main(String[] args) {
        sc = new Scanner(System.in);
 
        long l = sc.nextInt();
 
        List<Long> u = new ArrayList<>();
        List<Long> v = new ArrayList<>();
        List<Long> w = new ArrayList<>();
 
        long p = 1;
        long i = 1;
        while (p <= l / 2) {
            u.add(i);
            v.add(i + 1);
            w.add(0L);
            u.add(i);
            v.add(i + 1);
            w.add(p);
            p *= 2;
            i++;
        }
 
        long r = l - p;
        long q = p;
        long b = 0;
        long rp2 = r;
        for (long j = i - 1; rp2 > 0; j--) {
            p /= 2;
            long rp21 = rp2 / p;
 
            if (rp21 == 0) {
                continue;
            }
            b += q;
            u.add(j);
            v.add(i);
            w.add(b);
            q = p;
            rp2 = rp2 - p;
        }
 
        System.out.println(i + " " + u.size());
        for (int j = 0; j < u.size(); j++) {
            System.out.println(u.get(j) + " " + v.get(j) + " " + w.get(j));
        }
    }
 
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, k;
int cnt[5000][5000];
int ans[5000][5000];
signed main() {
	cin >> n >> k;
	rep(i, n) {
		int a, b; cin >> b >> a;
		a %= 2 * k, b %= 2 * k;
		char c; cin >> c;
		if (c == 'B') {
			cnt[a + 1][b + 1]++;
			cnt[a + 1 + k][b + 1]--;
			cnt[a + 1][b + 1 + k]--;
			cnt[a + 1 + k][b + 1 + k]++;
		}
		else {
			cnt[a + 1 + k][b + 1]++;
			cnt[a + 1 + k * 2][b + 1]--;
			cnt[a + 1 + k][b + 1 + k]--;
			cnt[a + 1 + k * 2][b + 1 + k]++;
		}
	}
	rep(i, k * 4 + 1)REP(j, k * 4 + 1)cnt[i][j] += cnt[i][j - 1];
	rep(i, k * 4 + 1)REP(j, k * 4 + 1)cnt[j][i] += cnt[j - 1][i];
	rep(i, k * 4 + 1) {
		rep(j, k * 4 + 1) {
			ans[i % (k * 2)][j % (k * 2)] += cnt[i][j];
			//cout << cnt[i][j] << " ";
		}
		//cout << endl;
	}
	for (int i = k; i < 2 * k + 1; i++)for (int j = k; j < 2 * k + 1; j++) {
		ans[i % k][j % k] += ans[i][j];
	}
	for (int i = k; i < 2 * k + 1; i++) {
		rep(j, k) {
			ans[i - k][j + k] += ans[i][j];
		}
	}
	int ans_ = 0;
	rep(i, k * 2 + 1) {
		rep(j, k * 2 + 1) {
			ans_ = max(ans_, ans[i][j]);
			//cout << ans[i][j] << " ";
		}
		//cout << endl;
	}
	cout << ans_ << endl;
}


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

using namespace std ;

const int MAXN = 1e6 + 100 ; 

int a[MAXN] ; 
int32_t main() {	
	ios_base::sync_with_stdio(0) ; 
	cin . tie(0) ; cout . tie(0) ; 

	int n ; cin >> n ; 
	for(int i = 0 ; i < n ; i ++)
		cin >> a[i] ; 

	long long ans = 0 ;
	int sum = 0 ; 
	for(int i = 0 ; i < n ; i ++){
		sum += a[i] ; 
		if(i % 2) 	ans += max(0 , 1 - sum) , sum = max( +1 , sum) ; 
		else		ans += max(0 , sum + 1) , sum = min( -1 , sum) ; 
	}
	long long res = ans ; 
	ans = 0 , sum = 0 ; 
	for(int i = 0 ; i < n ; i ++){
		sum += a[i] ; 
		if(i % 2 == 0) 	ans += max(0 , 1 - sum) , sum = max( +1 , sum) ; 
		else			ans += max(0 , sum + 1) , sum = min( -1 , sum) ; 
	}
	cout << min(ans , res) ; 
}

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

int main(){
  int a,N,count=0,temp=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a;
    if(temp==a){count++;temp=0;}
    else{temp=a;}
  }
  cout << count << endl;
  return 0;
}

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

typedef struct{
    double x;
    double y;
}xy;
void kock(int,xy,xy);

int main(){
    xy p1={0.00,0.00},p2={100.000,0.00};
    int n;

    cin>>n;
    cout<<p1.x<<" "<<p1.y<<endl;
    kock(n,p1,p2);
    cout<<p2.x<<" "<<p2.y<<endl;


    return 0;
}

void kock(int n,xy p1,xy p2){
    xy s,t,u;
    if(n==0)return;
    s.x=(2*p1.x+p2.x)/3;
    s.y=(2*p1.y+p2.y)/3;
    t.x=(p1.x+2*p2.x)/3;
    t.y=(p1.y+2*p2.y)/3;
    u.x=(t.x-s.x)/2-(t.y-s.y)*sqrt(3)/2+s.x;
    u.y=(t.x-s.x)*sqrt(3)/2+(t.y-s.y)/2+s.y;


    kock(n-1,p1,s);
    cout<<s.x<<" "<<s.y<<endl;
    kock(n-1,s,u);
    cout<<u.x<<" "<<u.y<<endl;
    kock(n-1,u,t);
    cout<<t.x<<" "<<t.y<<endl;
    kock(n-1,t,p2);

}


Measured memory_bytes: 3256
a,b,c,d = map(int,input().split())

mod = 998244353

dp = [[0] * d for _ in range(c)]
dp[a-1][b-1] = 1

for i in range(c):
    for j in range(d):
        if i < a and j < b or i < a-1 or j < b-1:
            pass
        else:
            if i == 0:
                dp[i][j] = 1
            elif j == 0:
                dp[i][j] = 1
            else:
                dp[i][j] = dp[i-1][j] * (j+1) + dp[i][j-1] * (i+1) - dp[i-1][j-1] * i*j
        dp[i][j] %= mod

print(dp[-1][-1])


Measured memory_bytes: 138892
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

vector< vector<int> > a(11);

int memo[2001][2001] = {};

int dfs(int k, int g) {
	if (memo[k][g] != -1)return memo[k][g];
	if (g > 10)return 0;
	int M = 0;
	for (int i = 0; i <= a[g].size(); i++) {
		if (k - i == 0) {
			M = max(
				M,
				a[g][i - 1]
			);
		}
		else if (k - i > 0) {
			//cout << i << " " << k << " " << g << " " << M << " " << a[g].size() << endl;
			int x = 0;
			if (i >= 1)
				x = a[g][i - 1];
			M = max(
				M,
				(memo[k - i][g + 1] = dfs(k - i, g + 1)) + x
			);
		}
	}
	return M;

}

int main() {
	memset(memo, -1, sizeof(memo));
	int N, K; cin >> N >> K;

	for (int i = 0; i < N; i++) {
		int C, G; cin >> C >> G;
		a[G].push_back(C);
	}
	for (int i = 1; i <= 10; i++) {
		sort(a[i].rbegin(), a[i].rend());
		for (int j = 1; j < a[i].size(); j++)
			a[i][j] += a[i][j - 1];
		for (int j = 1; j < a[i].size(); j++)
			a[i][j] += j*(j + 1);
		//for (int j = 0; j < a[i].size(); j++)
		//	cout << i << " " << j + 1 << " " << a[i][j] << endl;
	}
	cout << dfs(K, 1) << endl;

	return 0;
}

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

int main(){
    int K, T; cin >> K >> T;
    vector<int> A(T); for(int i = 0; i < T; i++) cin >> A[i];
    sort(A.rbegin(), A.rend());
    int l=0, r=1;
    if(A.size() < 2){
        cout << A[0]-1 << endl;
        return 0;
    }
    while(1){
        if(r >= A.size()){
            break;
        }
        A[l] -= 1;
        A[r] -= 1;
        if(A[r] == 0){
            r++;
        }
        if(A[l] == 0){
            while(l < A.size()){
                if(A[l] == 0)l++;
                else break;
            }
            r=l+1;
        }
        
    }
    int ans;
    if(A[l] == 0 || A[l] == 1) ans = 0;
    else ans = A[l]-1;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int x = 30000;
const int LEN = 20005;
int i, j, k, n, m, s, t, ans;
int a[LEN], b[LEN], p[LEN];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
        a[i] = x * i;
        b[i] = x * (n - i + 1);
    }
    for (int i = 1; i <= n; i++) {
        a[p[i]] -= n - i;
    }
    for (int i = 1; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("%d\n", a[n]);
    for (int i = 1; i < n; i++) {
        printf("%d ", b[i]);
    }
    printf("%d\n", b[n]);
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

// 桁DPはグローバルにしたほうがいい？
string K;
int D;

// 桁DP dp[i][flg][D] = 総数
// 上から i 桁目まで決定
// flg : K 未満が確定しているかどうか
// D : mod D の値
int dp[10002][2][101];

// modつき足し算のテンプレートクラスを用意
template<class T>
void Add(T &a, const T &b, const T &mod=1e9+7){
    int val = ((a % mod) + (b % mod)) % mod;
    if(val < 0){val += mod;}
    // aにその値を上書き
    a = val;
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述
    cin >> K >> D;
    
    dp[0][0][0] = 1; // 初期化
    // DP
    REP(digit, K.size()){
        for(int smaller : {0,1}){
            REP(modD, D){
                // 未満フラグの値によってこの桁で調べるべき数字の限界を決定
                int limit = (smaller ? 9 : K[digit]-'0');
                // num : 次の桁となる数 --> modの状態遷移にかかわる
                REP(num, limit + 1){
                    // nSmaller : num == limit となるとき smaller == 0 で 0 となる
                    // つまり、前の桁まで決めたときにK未満と確定しない数において、
                    // 次の桁を決めてもK未満と確定しないときを分ける
                    int nSmaller = smaller || (num < limit);
                    if(smaller == 1 && nSmaller == 0) continue;
                    Add(dp[digit+1][nSmaller][(modD + num) % D], dp[digit][smaller][modD]);
                }
            }
        }
    }

    int ans = 0;
    for(int smaller : {0, 1}){
        Add(ans, dp[K.size()][smaller][0]);
    }

    Add(ans, -1); // 0になる場合の数を引く
    cout << ans << endl;


return 0;
}

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

int main() {
	int n, k, x, dist = 0;
	cin >> n;
	cin >> k;
	for (int i = 1; i <= n; i++) {
	    cin >> x;
	    if (k / 2 < x) dist += (k - x) * 2;
	    else dist += x * 2;
	}
	cout << dist;
	return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

dist = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dist += math.sqrt((s[i][0]-s[j][0])**2 + (s[i][1]-s[j][1])**2)
ans = dist/n
print(ans)


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

int main() {
	int loop = 0,tmp;
	int x[10000];
	while(true){
		cin >> tmp;
		if(tmp == 0){
			 break;
		}else{
			x[loop] = tmp;
			loop++;
		}
		
	}
	for(int i=0; i < loop; i++){
		cout << "Case " << i+1<< ": " << x[i] << "\n";
	}
	return 0;
}



Measured memory_bytes: 3048
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<int>);
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};


int main(){
    ll k;
    vector<ll> a;
    cin >> k;
    REP(i, (int)k){
        ll tmp;
        cin >> tmp; a.pb(tmp);
    }
    if(a[k - 1] != 2){
        cout << -1 << endl;
        return 0;
    }
    reverse(a.begin(), a.end());
    ll mi = 2, ma = 3, flag = 4;
    FOR(i, 1, (int)k){
        // mi の更新　割る
        if(mi <= a[i]){
            mi = a[i];
        }else{
            ll tmp = mi / a[i];
            if(mi % a[i]) tmp++;
            mi = a[i] * tmp;
        }
        // maの更新 
        if(ma < a[i]){
            cout << -1 << endl;
            return 0;
        }
        ma = (ma / a[i] + 1) * a[i] - 1;
        if(ma < mi){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << mi << " " << ma << endl;
}


Measured memory_bytes: 1400
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = I()
a = LI()
cnt = 0
s = 0
s = sum(a)
for k in a:
    cnt += k**2
ans = (s**2-cnt)//2
print(ans%mod)


Measured memory_bytes: 32412
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = (b - a) % 2 == 0;
        String result = judge ? "Alice" : "Borys";

        // 出力
        System.out.println(result);
    }
}


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

int N;
char c[5][5][5], tmp[5][5][5];

int main(){
	
	for(int t = 1; cin  >> N, N ; t++){
		if( 1 < t ) cout << endl;
		
		for(int z = 0; z < 5; z++){
			for(int y = 0; y < 5; y++){
				for(int x = 0; x < 5; x++){
					cin >> c[z][y][x];
				}
			}
		}
		
		int M1, M2, a[27], b[27];
		cin >> M1;
		for(int i = 0; i < M1; i++) cin >> a[i];
		cin >> M2;
		for(int i = 0; i < M2; i++) cin >> b[i];
		
		for(int i = 0; i < N; i++){
			for(int z = 0; z < 5; z++){
				for(int y = 0; y < 5; y++){
					for(int x = 0; x < 5; x++){
						int cnt = 0;
						for(int dz = -1; dz <= 1; dz++){
							for(int dy = -1; dy <= 1; dy++){
								for(int dx = -1; dx <= 1; dx++){
									int mx = x + dx, my = y + dy, mz = z + dz;
									if( mx < 0 || my < 0 || mz < 0 ) continue;
									if( 5 <= mx || 5 <= my || 5 <= mz ) continue;
									if( dx == 0 && dy == 0 && dz == 0 ) continue;
									
									if( c[mz][my][mx] == '1' ) cnt++;
								}
							}
						}
						if( c[z][y][x] == '0' && count(a, a + M1, cnt) ){
							tmp[z][y][x] = '1';
						}else if( c[z][y][x] == '1' && count(b, b + M2, cnt) == 0 ){
							tmp[z][y][x] = '0';
						}else{
							tmp[z][y][x] = c[z][y][x];
						}
					}
				}
			}
			
			for(int z = 0; z < 5; z++){
				for(int y = 0; y < 5; y++){
					for(int x = 0; x < 5; x++){
						c[z][y][x] = tmp[z][y][x];
					}
				}
			}
		}
		
		
		cout << "Case " << t << ":" << endl;
		for(int z = 0; z < 5; z++){
			for(int y = 0; y < 5; y++){
				for(int x = 0; x < 5; x++){
					cout << c[z][y][x];
				}
				cout << endl;
			}
			if( z != 4 ) cout << endl;
		}
	}
}

Measured memory_bytes: 1172
package main
import "fmt"
func main() {
  var a,b,c int
  fmt.Scan(&a,&b,&c)
  if a%2 == 1 || a%2 == 1 || a%2 == 1 {
    fmt.Println(0)
  } else {
    a,b,c = abs(a-b),abs(b-c),abs(c-a)
    fmt.Println(min(ord(a),ord(b),ord(c)))
  }
}
func abs(n int) int {
  if n < 0 { return -n }
  return n
}
func min(n... int) int {
  var m int = n[0]
  for i:=1;i<len(n);i++ {
    if m < n[i] { m = n[i] }
  }
  if m < 0 { return -1 }
  for i:=0;i<len(n);i++ {
    if m > n[i] && n[i] >= 0 { m = n[i] }
  }
  return m
}
func ord(n int) int {
  if n == 0 { return -1 }
  var k int = 0
  for {
    if n%2 != 0 { break }
    n = n/2
    k++
  }
  return k
}

Measured memory_bytes: 512
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();

    System.out.println(H*W-(h*W+w*H-w*h));

  }
}


Measured memory_bytes: 21972
#include <iostream>
#include <memory>
#include <stdio.h>

using namespace std;

int A[3]{};

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    A[i] = -1;
  }
  bool flg = true;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (A[s - 1] == -1 || A[s - 1] == c) {
      A[s - 1] = c;
    } else {
      flg = false;
    }
    if (N > 1 && s == 1 && c == 0) {
      flg = false;
    }
  }
  if (!flg) {
    printf("-1\n");
    return 0;
  }
  if (A[0] == -1) {
    if (N > 1) {
      A[0] = 1;
    } else {
      A[0] = 0;
    }
  }
  for (int i = 0; i < N; ++i) {
    if (A[i] == -1) {
      A[i] = 0;
    }
    printf("%d", A[i]);
  }
  printf("\n");
}

Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin>>N;
    long num[N];
    for(int i=0;i<=N;i++){
        if(i==0) {num[i]=2;}
        else if(i==1) {num[i]=1;}
        else num[i]=num[i-1]+num[i-2];
    }
    cout<<num[N];
    return 0;
}

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

int x[10000][2000];
int x2[10000][2000];
int y[10000];
int z[10000];

int main() {
	memset(x, 1, sizeof(x));
	memset(y, 1, sizeof(y));
	int n, a, b, c, d, e;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		for (int i = 0; i < b; i++) {
			cin >> c >> d;
			x[a][z[a]] = c;
			x2[a][z[a]] = d;
			z[a]++;
		}
	}
	y[0] = 0;
	e = min(n, 1600);
	for (int i = 0; i < e; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < z[j]; k++) {
				y[x[j][k]] = min(y[x[j][k]], y[j] + x2[j][k]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << ' ' << y[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 122044
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	int n,i,j,k;cin>>n;vvpi d(n+1,vpi(n+1));for(i=1;i<=n;i++) cin>>d[i][i].fs,d[i][i].se=0;
	for(i=1;i<n;i++){
		for(j=1;j<=n-i;j++){
			int a=j,b=i+j;
			for(k=a;k<b;k++){
				ll x=d[a][k].fs+d[k+1][b].fs+d[a][k].se+d[k+1][b].se;
				d[a][b].se=(d[a][b].se?min(d[a][b].se,x):x);
				d[a][b].fs=d[a][k].fs+d[k+1][b].fs;
			}
		}
	}cout<<d[1][n].se<<endl;
//	for(i=1;i<=n;i++){
//		for(j=1;j<=n;j++) cout<<d[i][j].fs<<" "<<d[i][j].se<<"  ";cout<<endl;
//	}
}


Measured memory_bytes: 2816
N,M = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(N)]
AB_sorted = sorted(AB, key=lambda x: x[0])

money = 0
drink = 0
for i in range(N):
    drink += AB_sorted[i][1]
    money += AB_sorted[i][0] * AB_sorted[i][1]
    if drink >= M:
        money -= (drink - M) * AB_sorted[i][0]
        break
print(money)

Measured memory_bytes: 29268
#include <iostream>
#include <algorithm>
#include <vector>

#define INF 100000000000

using namespace std;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int ans = (A*B > C*D) ? A*B : C*D;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256