akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
import itertools
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))

    f = -1
    s = -1

    for i, perm in enumerate(itertools.permutations(range(1, n + 1))):
        if perm == p:
            f = i
        if perm == q:
            s = i

    print(abs(f - s))


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 32796
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if (e - a <= k)cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long long m,n,q;
char s[200];

int main()
{
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++)
	{
		if(s[i]=='C') m=1;
		if(m==1&&s[i]=='F') q=1;
	}
	if(q==1) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:128777216")
#pragma GCC optimize("fast-maths")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#include <complex>
using namespace std;
 
#define forx(_name, _from, _to, _value) for (int _name = _from; _name < _to; _name += _value)
#define rforx(_name, _from, _to, _value) for (int _name = _from; _name > _to; _name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST, _SECOND)
 
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-6;
mt19937 rndm;
 
void start() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(6); cout.setf(ios::fixed);
	string FILENAME = "\-_-/";
	rndm.seed(time(0));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
	//freopen((FILENAME + ".in").c_str(), "rt", stdin);
	//freopen((FILENAME + ".out").c_str(), "wt", stdout);
#endif
}
 
int main() {
	/* File On */
	start();
	ll d, t, s;
	cin >> d >> t >> s;
	if (t * s >= d)
		cout << "Yes";
	else
		cout << "No";
#ifdef _DEBUG
	cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}

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

int main()
{
    int S, W;
    cin >> S >> W;
    if (W >= S)
    {
        cout << "unsafe" << endl;
        return 0;
    }
    cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      long N = scan.nextLong();

      String res = "";
      //Nが0ではない間
      while(N != 0){
          N--;
          res += (char)('a' + (N % 26));
          N /= 26;
      }
      //文字列を反転
      StringBuilder builder = new StringBuilder(res);
      String result = builder.reverse().toString();

      System.out.println(result);
    }
}

Measured memory_bytes: 39448
"use strict";

function Main(input) {
    input = input.split("\n");

    input[0] = input[0].split(" ");
    const maxH = parseInt(input[0][0], 10);
    const maxW = parseInt(input[0][1], 10);

    input[1] = input[1].split(" ");
    const h = parseInt(input[1][0], 10);
    const w = parseInt(input[1][1], 10);

    let answer = maxH * maxW;
    for (let i = 0; i < maxH; i++) {
        for (let j = 0; j < maxW; j++) {
            if (i < h || j < w) {
                answer--;
            }
        }
    }

    console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
import Data.List hiding (find)
import Data.Tree
import Data.Array as A
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Data.Graph
--import Data.Vector as V
import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Debug.Trace

type DP s = STUArray s Int Int

dp_i :: DP s -> Vertex -> [Vertex] -> Int -> ST s Int
dp_i dparr v0 [] n = return 0
dp_i dparr v0 (v:vs) n = do
   dpv0 <- readArray dparr v0
   dpv  <- readArray dparr v
   -- 閉路はないので以下のことができる
   let next = (max dpv (dpv0+1))
   writeArray dparr v next
   n <- dp_i dparr v0 vs n
   return $ max next n

solve :: [Edge] -> Int -> Int -> ST s Int
solve ls' n m = do
  let  graph = buildG (1,n) ls'
       ls = topSort graph
  dparr <- newArray (1,n) 0
  list <- forM ls $ \v0 -> dp_i dparr v0 (graph A.! v0) n
  let ans = maximum list
  return ans

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine
  ls <- replicateM m $ do
    (x:y:e) <- map read.words <$> getLine
    return (x,y)
  putStrLn $ show $ runST $ solve ls n m


Measured memory_bytes: 96764
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 3; i <= n; i++)
            if (i % 3 == 0 || i.ToString().Contains("3")) Console.Write(" " + i);
        Console.WriteLine();
    }
}


Measured memory_bytes: 17916
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long int n,W,tot=0;
    cin>>n>>W;
    long long int dp[100005];
    for(int i=1;i<100005;i++)
    dp[i]=1e9;
  //  memset(dp,20,sizeof(dp));
    dp[0]=0;int sum=0;
    for(int i=0;i<n;i++)
    {
        int w,v;
        cin>>w>>v;
        sum+=v;
        for(int j=sum-v;j>=0;j--)
        dp[j+v]=min(dp[j+v],dp[j]+w);
        
    }
    
    for(int i=sum;i>=0;i--)
    {
        if(dp[i]<=W)
        {
            cout<<i;
            return 0;
        }
    }
    
    
}















Measured memory_bytes: 4452
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    bool x = true;
    rep(i, n) {
        int a;
        cin >> a;
        if(a&1) x = false;
    }

    cout << (x ? "second":"first") << endl;
}

Measured memory_bytes: 384
from collections import deque


def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    friendliness.sort()
    friendliness = deque(friendliness)

    edges = deque()
    popped = friendliness.pop()
    edges.append(popped)
    ans = 0
    while friendliness:
        ans += edges.popleft()
        popped = friendliness.pop()
        edges.append(popped)
        edges.append(popped)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32632
//AnkitCode99
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define vl vector<ll>
#define all(v) (v.begin(),v.end())
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
using namespace std;
int main()
{
	fast;
 //   #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	
	ll k,m;
	cin>>k>>m;
	if(500*k>=m)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
from sys import stdin


def sortFirst(val):
    return val[0]
N=stdin.readline().rstrip()
N=int(N)
l={}
for i in range(1,N+1):
    S,P = stdin.readline().rstrip().split()
    if S in l.keys():
        l[S].append([int(P),i])

    else:
        l[S]=[[int(P),i]]


for key in l.keys():
    l[key].sort(key=sortFirst,reverse=True)
for key in sorted(l):
    for val in l[key]:
        print(val[1])


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;

ll x,y,z;

int main()
{
	cin>>x;
	cin>>y;
	cin>>z;
	if(z - x - y < 0)
	{
		puts("No");
	}
	else
	{
		ll p = (z - x - y) * (z-x-y);
		ll t = 4 * x * y;
		if(t < p)
		{
			puts("Yes");	
		} 
		else
		{
			puts("No");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lambda(res,...) (function<res(__VA_ARGS__)>)[&](__VA_ARGS__)
#define method(name,res,...) function<res(__VA_ARGS__)> name = lambda(res,__VA_ARGS__)
using namespace std;
#define int long long

signed main(){
	int n;
	int t;
	cin >> n >> t;
	method(func,vector<int>,int t,vector<int> line){
		vector<int> ans;
		vector<int> times;
		ans.emplace_back(t/line.front()+1);
		times.emplace_back(ans.front()*line.front());
		int last_ans = ans.front();
		int last_time = times.front();
		int d = line.front();
		for(int i=1;i<line.size();++i){
			last_time += line[i];
			while(last_time>t){
				last_time -= d;
				--last_ans;
			}
			++last_ans;
			last_time += d;
			ans.emplace_back(last_ans);
		}
		return ans;
	};

	method(sum,int,vector<int> line){
		int res = 0;
		for(auto&i:line)res+=i;
		return res;
	};

	method(output,void,vector<int> line){
		for(auto&i:line)cout << max(1LL,i) << endl;
	};
	vector<int> line;
	for(int i=0;i<n;++i){
		int h;
		cin >> h;
		if(line.empty() or line.front()>h){
			line.emplace_back(h);
		}else{
			output(func(t,line));
			t -= sum(line);
			line.clear();
			line.emplace_back(h);
			t = max(t,0LL);
		}
	}

	output(func(t,line));

	return 0;
}



Measured memory_bytes: 5876
#include <stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b); 
    if(a < b){
     printf("a < b\n");
}
    else if(a > b){
     printf("a > b\n");
}
    else if(a == b){
     printf("a == b\n");
}
    return 0;
}


Measured memory_bytes: 1996
from itertools import product
from collections import deque
H,W=list(map(int, input().split()))
C=list(map(int, input().split()))
D=list(map(int, input().split()))
S=[list(input()) for _ in range(H)]
# print(S)
C[0]-=1
C[1]-=1
D[0]-=1
D[1]-=1

a=[-2,-1,0,1,2]
wk={(1,0),(-1,0),(0,1),(0,-1)}
wp=set(product(a,a)).difference(wk)
wp-={(0,0)}

stk=deque([[C[0],C[1],0]])
dp=[[float('inf')]*W for _ in range(H)]

def BFS():
    while len(stk)>0:
        l=stk.pop()
        i=l[0]
        j=l[1]
        ct=l[2]
        if ct>=dp[i][j]:
            continue
        dp[i][j]=ct
        for k in wk:
            x=i+k[0]
            y=j+k[1]
            if 0<=x<H and 0<=y<W and S[x][y]=='.':
                stk.append([x,y,ct])
        for k in wp:
            x=i+k[0]
            y=j+k[1]
            if 0<=x<H and 0<=y<W and S[x][y]=='.':
                stk.appendleft([x,y,ct+1])

BFS()
# print(dp)
ans=dp[D[0]][D[1]]
if ans ==float('inf'):
    print(-1)
else:
    print(dp[D[0]][D[1]])

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

using namespace std;
const long long INF = 1LL <<60;
const long long Mo=1000000007;
         

long long gcn(long long x,long long y){
  if(x%y==0){  
    return y;    
  }
  else{
    return gcn(y,x%y);
  }
}

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

int main(void){
  long long tmp1,tmp2;
  long long n,m;
  long long x=0;
  long long i,j;
  long double res=0.0;

  cin>>n>>m;
  long long n_b[n];
  int b[n]={};
  b[0]=1;
  for(i=0;i<n;i++){
    n_b[i]=1;
  }
  
  for(i=0;i<m;i++){
    cin>>tmp1>>tmp2;
    tmp1--;
    tmp2--;
    if(b[tmp1]==1){
      if(n_b[tmp1]==1){
        b[tmp1]=0;
        b[tmp2]=1;
      }
      else{
        b[tmp2]=1;
      }
    }
    n_b[tmp1]--;
    n_b[tmp2]++;
  }
  
  for(i=0;i<n;i++){
    res+=b[i];
  }
  
  //cout<<setprecision(15)<<res<<endl;
  cout<<res<<endl;

  
  return 0;
    }

Measured memory_bytes: 4880
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 100005;
int n, m, a[mx], b[mx];
vector<int> ans;
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d", a+i);
	auto J = [&]{
		int v[mx];
		rep(i,m+1) v[i] = -1;
		rep(i,n){
			auto t = lower_bound(v,v+m,a[i]);
			if(t != v) v[t-v-1] = a[i];
			else return true;
		}
		return false;
	};
	for(int l=0,r=n;(m=(l+r)/2)>l;(J()?l:r)=m);
	printf("%d\n", m+1);
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    int n,m;
    cin>>n>>m;
    vector<bool>a(n+1);
    rep(i,n+1)a[i] = true;
    rep(i,m)
    {
        int s;
        cin>>s;
        a[s] = false;
    }

    vector<ll>fib(n+1);
    rep(i,n+1)fib[i] = 0;
    fib[0] = 1;
    fib[1] = 1;
    for(int i = 2; i < n+1;i++)
    {
        if(!a[i]){
         //   cout<<i<<" continue\n";
            continue;
        }
        if(a[i-2]) fib[i]+=fib[i-2];
        if(a[i-1]) fib[i]+=fib[i-1];
        fib[i]%=1000000007;
    }

    cout<<fib[n]<<endl;
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<string>

using namespace std;

int main(void){
  int n;
  string str;
  while(cin>>n,n){  
  vector<int> aa(n);
  vector<int> bb(n);
  int a,b;
  cin>>str;
  for(int i = n - 1 ; i>=0 ; i --){
    cin>>aa[i]>>bb[i];
  }
  for(int i = 0 ; i < n ; i ++){
    aa[i]--,bb[i]--;
    char sw = ((str[aa[i]] - 'a' + abs( aa[i] - bb[i]))%26)+'a';
    str[aa[i]] = ((str[bb[i]] - 'a' + abs(aa[i] - bb[i]))%26)+'a';
    str[bb[i]] = sw;
  }
  cout<<str<<endl;
  }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v.at(i);
    }
    vector<int> sum(n);
    vector<int> sum2(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (v[i] < v[j]) {
                if (i > j)
                    sum[i]++;
                else if (i < j)
                    sum2[i]++;
            }
        }
    }
    int result = 0;
    int com1 = (k * (k + 1) / 2) % MOD;
    int com2 = (k * (k - 1) / 2) % MOD;
    for (int i = 0; i < n; ++i) {
        result += (sum[i] * com1 + sum2[i] * com2) % MOD;
    }
    cout << result % MOD<< "\n";
}

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

using namespace std;

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> x(n, 0);

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

    int counter = 0;

    for(int i = 0; i < n; i++){
        counter += min(x[i], k - x[i]) * 2 ;
    }
    cout << counter << endl;
    return 0;

}

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

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, k;
    cin >> n;
    akari<int> as(n);
    for (int &a : as)
        cin >> a;
    cin >> n;
    while (n--)
    {
        cin >> k;
        cout << binary_search(as.begin(), as.end(), k) << '\n';
    }
}

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



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll a[N],x=0,z=LLONG_MAX,y=0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    x+=a[i];
  }
  for (int i = 0; i < N-1; i++) {
    y += a[i];
    x -= a[i];
    z = min(z,abs(x-y));
  }
  cout<<z;
}

Measured memory_bytes: 5200
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, m; cin >> n >> m;
	string s; cin >> s;
	rep(i, n + 1)
	{
		int cnt = 0;
		if (s[i] == '1')++cnt;
		while (i < n && s[i + 1] == '1')
		{
			++cnt;
			++i;
		}
		if (cnt >= m)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	reverse(all(s));
	vector<int> dp(n + 1);
	dp[0] = 0;
	int now = 0;
	vector<int> res;
	while (now < n)
	{
		int next = now + m;
		while (next > n || s[next] == '1')--next;
		res.push_back(next - now);
		now = next;
	}
	reverse(all(res));
	for (int x : res)cout << x << " ";
}

Measured memory_bytes: 1528
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<int, pair<int, int>>PP;
typedef long long ll;

int px[90001], py[90001];
int b[90001];
int main() {
	int h, w, d, a;
	int q, l, r;
	cin >> h >> w >> d;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a;
			px[a] = i;
			py[a] = j;
		}
	}
	for (int i = d + 1; i <= h * w; i++) {
		b[i] = b[i - d] + abs(px[i] - px[i - d]) + abs(py[i] - py[i - d]);
	}
	cin >> q;
	while (q--) {
		cin >> l >> r;
		cout << b[r] - b[l] << endl;;
	}
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		char c;
		map<char, int>a;
		for (int i = 0; i < 26; i++) {
			a.insert(map<char, int>::value_type((char)(int)'A' + i, 0));
		}
		bool l = false;
		string w = "TIE";
		int h = -1;
		for (int z = n-1; z >= 0; z--) {
			cin >> c;
			a[c]++;
			if (!l) {
				int d = 0, e = 0, f = 0;
				char k = 'a';
				for (int i = 0; i < 26; i++) {
					int g = a[(char)('A' + i)];
					if (d < g) {
						f = d;
						d = g;
						e = 1;
						k = 'A' + i;
					}
					else if (d == g) e++;
					if (g < d&&f < g) {
						f = g;
					}
				}
				if (e == 1 && f + z < d) {
					w = k;
					h = (n - z);
					l = true;
				}
			}
		}
		if (!l) cout << w << endl;
		else cout << w << " " << h << endl;
	}
}

Measured memory_bytes: 3144
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author apurba_debnath
 */

#include <bits/stdc++.h>

#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl

using namespace std;

class BDistance {
public:
    void solve(std::istream &in, std::ostream &out) {
        ll n, d;
        in >> n >> d;
        ll ctr = 0;
        while (n > 0) {
            ll x, y;
            in >> x >> y;
            double dist = sqrt(x * x + y * y);
            if (dist <= d)
                ctr++;
            n--;
        }
        out << ctr;
    }
};


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

    BDistance solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);

    return 0;
}


Measured memory_bytes: 3696
#include <stdio.h>

int main(void) {
	int x, y, i, j;
	
	while(1){
		scanf("%d %d", &x, &y);
		
		if(x == 0 && y == 0){
			break;
		}
		for(i = 0; i < x; i++){
			if(i == 0 || i == x - 1){
				for( j = 0; j < y; j++){
					putchar('#');
				}
				putchar('\n');
			}else if( i > 0 && i < x - 1){
				for(j = 0; j < y; j++){
					if( j == 0){
						putchar('#');
					}else if( j == y - 1){
						putchar('#');
						putchar('\n');
					
					}else if( j > 0 && j < y -1){
						putchar('.');
					}
				}
			}	
		}
		putchar('\n');
		
	}
	
	return 0;
}

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

class Mondai
{
    static void Main()
    {
        var ab = Console.ReadLine().Split(' ').Select(n => Int32.Parse(n)).ToArray();
        var A = ab[0];
        var B = ab[1];
        var ans = 0;
        if (A <= 12 && 6 <= A) ans = B / 2;
        else if (13 <= A) ans = B;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, ma, mb; cin >> n >> ma >> mb;
  vector<int> A(n), B(n), C(n);
  rep(i, n) cin >> A[i] >> B[i]>> C[i];
  vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(405, vector<ll>(405, longinf)));
  dp[0][0][0] = 0;
  rep(i, n) {
    rep(j, 405) rep(k, 405) {
      dp[i+1][j][k] = min(dp[i][j][k], dp[i+1][j][k]);
      if(j+A[i]<405 && k+B[i]<405) {
        dp[i+1][j+A[i]][k+B[i]] = min(dp[i][j][k]+C[i], dp[i+1][j+A[i]][k+B[i]]);
      }
    }
  }
  ll ans = longinf;
  rep(j, 405) rep(k, 405) {
    if(j < 1 || k < 1) continue;
    if(1LL*j*mb == 1LL*k*ma) {
      ans = min(dp[n][j][k], ans);
    }
  }
  cout << (ans==longinf ? -1 : ans) << endk;
  return 0;
}


Measured memory_bytes: 57572
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_2_B&lang=jp
# Queue

from collections import deque
import sys
input = sys.stdin.readline

def loop_proc():
    (n1,n2) = map(int,input().split())
    wl =[]
    for i in range(n1):
        wl.append(deque())
    for i in range(n2):
        l = list(map(int,input().split()))  
        if (l[0] == 0 ):
            wl[l[1]].appendleft(l[2])
        elif (l[0] == 1 ):
            if ( len(wl[l[1]]) != 0 ):
                tl = wl[l[1]]
                print (tl[-1])
        elif (l[0] == 2 ):
            if ( len(wl[l[1]]) != 0 ):
                wl[l[1]].pop()
 

loop_proc()




Measured memory_bytes: 14588
n = int(input())
a,b = map(int,input().split())
p_lst = list(map(int,input().split()))

ans_1 = len([p for p in p_lst if p <= a])
ans_2 = len([p for p in p_lst if p >  a and p <= b])
ans_3 = len([p for p in p_lst if p > b])
print(min(ans_1,ans_2,ans_3))


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

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    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;
    }
    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;
    }

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

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    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;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    combination nck(b);
    mint ans = mint(2).pow(n) - mint(1);

    mint apat = 1, bpat = 1;
    rep(i, a) apat *= n - i;
    rep(i, b) bpat *= n - i;
    apat /= nck.fact[a];
    bpat /= nck.fact[b];
    ans -= apat;
    ans -= bpat;
    cout << ans.x << endl;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int a,b,c; cin >> a >> b >> c;
	int ans=0;
	for(int i=a;i<=b;i++){
		if(c%i==0)ans ++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3120
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
using namespace std;
int main() {
	int a;
	cin >> a;
	cout << 2 * a * 3.14159265 << endl;
}


Measured memory_bytes: 3780
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;
    ll n, m, m1, k, i, j, x, y, p=0, s=0, h, f=0, an=100000000000;
    cin>>n>>k;
    ll a[n+1];
    for(i=1; i<=n; i++){
        cin>>a[i];
    }
    for(i=1; i<=n-k+1; i++){

        x=a[i];
        y=a[i+k-1];
        if(x>=0 && y>0){
            an=min(an, y);
        }
        else if(x<0 && y<=0){
            p=abs(x);
            an=min(an, p);
        }
        else{
            p=abs(x);
            s=2*p;
            h=2*y;

            m=s+y;
            m1=h+p;

            m=min(m, m1);
            an=min(an, m);
        }
    }
    cout<<an<<endl;
    return 0;
}



Measured memory_bytes: 4380
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var S = Console.ReadLine();
            var answer = Math.Min(S.Count(elem => elem == '0'), S.Count(elem => elem == '1')) * 2;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13408
n = int(input())
a = list(map(int, input().split()))
cnt = 0
index = 0
while cnt >= 0:
  for i in a:
    if i % 2 == 0:
      a[index] = i // 2
    else:
      print(cnt)
      exit()
    index += 1
  index = 0
  cnt += 1
print(cnt)

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

//#define int long long

const int MAXN = 1010;
const int INF = 2e9;
const int mod = 1e9 + 7;

double n;

signed main () {
	cin >> n;
	n /= 3.;
	printf("%.6lf",n * n * n);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a,b;

    scanf("%d %d",&a,&b);

    if(13<=a){
        printf("%d",b);
    }else if(6<=a&&a<=12){
        printf("%d",b/2);
    }else{
        printf("%d",0);
    }
    return 0;
}


Measured memory_bytes: 128
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
const val MOD = 1000000007L
const val INF = 2147483647
const val LINF = 9223372036854775807L

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

fun solve() {
    val (a, b) = nextLongList()
    val l = gcd(a, b)
    val div: MutableList<Long> = mutableListOf()
    for (i in 1..l) {
        if (i * i > l) break
        if (l % i == 0L) {
            div.add(i)
            if(i != l / i) div.add(l / i)
        }
    }

    div.sort()
    val flag = Array(div.size) { true }
    for (i in 0 until div.size - 1){
        if(!flag[i]) continue
        for (j in i + 1 until div.size){
            if(gcd(div[i], div[j]) != 1L) flag[j] = false
        }
    }


    println(flag.count { it })

}


fun println(v: String) {
    pw.println(v)
}

fun print(v: String) {
    pw.print(v)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ").toMutableList()
fun nextIntList(index: Int = 0) = next().split(" ").map { it.toInt() + index }.toMutableList()
fun nextLongList(index: Long = 0L) = next().split(" ").map { it.toLong() + index }.toMutableList()
fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toMutableList()

fun ary(n: Int, init: String = "") = Array(n) { init }
fun intAry(n: Int, init: Int = 0) = IntArray(n) { init }
fun longAry(n: Int, init: Long = 0L) = LongArray(n) { init }
fun doubleAry(n: Int, init: Double = 0.0) = DoubleArray(n) { init }
fun ary2(n: Int, m: Int, init: String = "") = Array(n) { Array(m) { init } }
fun intAry2(n: Int, m: Int, init: Int = 0) = Array(n) { IntArray(m) { init } }
fun longAry2(n: Int, m: Int, init: Long = 0) = Array(n) { LongArray(m) { init } }
fun doubleAry2(n: Int, m: Int, init: Double = 0.0) = Array(n) { DoubleArray(m) { init } }
fun ary3(n: Int, m: Int, k: Int, init: String = "") = Array(n) { Array(m) { Array(k) { init } } }
fun intAry3(n: Int, m: Int, k: Int, init: Int = 0) = Array(n) { Array(m) { IntArray(k) { init } } }
fun longAry3(n: Int, m: Int, k: Int, init: Long = 0L) = Array(n) { Array(m) { LongArray(k) { init } } }
fun doubleAry3(n: Int, m: Int, k: Int, init: Double = 0.0) = Array(n) { Array(m) { DoubleArray(k) { init } } }

fun abs(n: Int): Int = Math.abs(n)
fun abs(n: Long): Long = Math.abs(n)
fun abs(n: Double): Double = Math.abs(n)
fun max(a: Int = -INF, b: Int = -INF, c: Int = -INF, d: Int = -INF, e: Int = -INF): Int = listOf(a, b, c, d, e).max()!!
fun max(a: Long = -LINF, b: Long = -LINF, c: Long = -LINF, d: Long = -LINF, e: Long = -LINF): Long =
    listOf(a, b, c, d, e).max()!!.toLong()

fun min(a: Int = INF, b: Int = INF, c: Int = INF, d: Int = INF, e: Int = INF): Int = listOf(a, b, c, d, e).min()!!
fun min(a: Long = LINF, b: Long = LINF, c: Long = LINF, d: Long = LINF, e: Long = LINF): Long =
    listOf(a, b, c, d, e).min()!!.toLong()

fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, (a % b))
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

Measured memory_bytes: 37888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();

        int count =0;
        int div = 100;
        while ( count<K ) {
            if(A%div==0 && B%div==0  ){
                count++;
                if(count==K) break;
            }
            div--;
        }
        System.out.println(div);


    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
using namespace std;
typedef long long ll;

int main()
{

  ll N, K;
  cin >> N >> K;

  ll *as = new ll[N];
  REP(i, N)
  {
    cin >> as[i];
  }

  bool *dp = new bool[K + 1];
  dp[0] = false;

  FOR(k, 1, K)
  {
    dp[k] = false;

    REP(i, N)
    {
      ll kk = k - as[i];
      if (0 <= kk && !dp[kk])
      {
        dp[k] = true;
        break;
      }
    }
  }

  cout << (dp[K] ? "First" : "Second") << endl;
  return 0;
}

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

long long a,b;
long long f(long long x) {
  long long f1 = a*x/b;
  long long f2 = x/b;
  return f1-a*f2;
}

int main(){
  long long n;
  cin >> a >> b >> n;
  if(b <= n) cout <<  f(b-1) << endl;
  else cout << f(n) << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include<functional>
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#include<vector>
#include<cmath>
using namespace std;
int a[1000000];
int b[1000000];
int main() {
	int r;
	cin >> r;
	cout << 3 *pow(r,2);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

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

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    graph g(n);
    rep(i,0,n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    vector<int> c(n);
    int ans = 0;
    rep(i,0,n){
        cin >> c[i];
        ans += c[i];
    }
    sort(rall(c));
    ans -= c[0];
    vector<int> p(n,-1);
    queue<int> que;
    que.push(0);
    p[0] = c[0];
    int index = 1;
    while(!que.empty()){
        int x = que.front();
        que.pop();
        for(auto nx: g[x]){
            if(p[nx]>=0) continue;
            p[nx] = c[index];
            index++;
            que.push(nx);
        }
    }
    cout << ans << endl;
    rep(i,0,n){
        cout << p[i] << " ";
    }
    cout << endl;
} 

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
void A()
{
    // 入力
    string N;
    cin >> N;
    
    // 出力
    if( N.find("7") != string::npos )
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
 
void B()
{
    // 入力
    int N;
    cin >> N;
    
    long long int ans = 0;
    
    // "Fizz", "Buzz", "FizzBuzz"のいずれでもない場合を合算する
    for( int i = 1; i < N+1; ++i )
        if( (i % 3 != 0) && (i % 5 != 0) )
            ans += i;
    
    // 出力
    cout << ans << endl;
}
 
long long int gcd(long long int a, long long int b)
{
    long long int ret;
     
    if( a < b ){
        long long int tmp = a;
        a = b;
        b = tmp;
    }
     
    if( b == 0 ) return a;
     
    ret = a % b;
    ret = gcd(b, ret);
     
    return ret;
}
 
void C()
{
    // 入力
    int K;
    cin >> K;
    
    int ans = 0;
    
    // 2重GCDで解ける
    for( int a = 1; a < K+1; ++a )
        for( int b = 1; b < K+1; ++b )
            for( int c = 1; c < K+1; ++c )
                ans += gcd(gcd(a, b), c);
    
    // 出力
    cout << ans << endl;
}
 
void D()
{
    // 入力
    int N;
    string S;
    cin >> N >> S;
    
    // SをR, G, Bに分割する
    unsigned long long int R = 0, G = 0, B = 0;
    for( int i = 0; i < N; ++i )
        switch( S[i] ){
            case 'R': ++R; break;
            case 'G': ++G; break;
            case 'B': ++B; break;
        }
    
    // {R, G, B}の組合せの数
    // 必ずR, G, Bそれぞれひとつずつの組合せになるが、i < j < k順に並びかえればいいので、それぞれの個数をかけた値になる
    //unsigned long long int ans = R * G * B;
    long long ans = R * G * B;
    
    // (j − i) == (k − j)の組合せの数を引く
    // i, jが決まればkを求められる
    for( int i = 1; i < N+1; ++i )
        for( int j = i+1; j < N+1; ++j ){
            int k = 2*j - i;
            if( k < j || N < k ) continue;
            if( S[i-1] != S[j-1] && S[j-1] != S[k-1] && S[k-1] != S[i-1] )
                --ans;
        }
    
    // 出力
    cout << ans << endl;   
}
 
int main()
{
    //A();
    //B();
    //C();
    D();
    
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
int main(void){
    char s;
    scanf("%c",&s);
    if(s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o'){
        printf("vowel\n");
    }else{
        printf("consonant");
    }
    return 0;
}

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

int dp[301][301][301];
const int mod=1e9+7;

signed main()
{

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

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

    int n,m;
    cin>>n>>m;
    dp[0][1][1]=1;
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            int tot=0;
            for(int k=1;k<=j;k++)
            {
                dp[i][j][k]+=dp[i-1][j-1][k];
                dp[i][j][k]+=(dp[i-1][j][k]*(j-k))%mod;
                tot+=dp[i-1][j][k]*k;
                tot%=mod;
                dp[i][j][k]%=mod;
            }
            dp[i][j][j]+=tot;
            dp[i][j][j]%=mod;
        }
    }

    int ans=dp[m][n][n];
    for(int i=1;i<=n-1;i++)
        ans=(ans*i)%mod;
    cout<<ans;

}



Measured memory_bytes: 212608