akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env ruby

class Dice
	attr_reader :top, :s, :e

    def initialize(top, s, e, w, n, bottom)
        @top    = top
        @s      = s
        @e      = e
        @w      = w
        @n      = n
        @bottom = bottom
	end

	def rotate!(dist)
		@top, @s, @e, @w, @n, @bottom = 
		case dist
		when 'N' then [@s, @bottom, @e, @w, @top, @n]
		when 'S' then [@n, @top, @e, @w, @bottom, @s]
		when 'E' then [@w, @s, @top, @bottom, @n, @e]
		when 'W' then [@e, @s, @bottom, @top, @n, @w]
		end
	end
end

if __FILE__ == $0 then
	dice = Dice.new(*gets.split.map(&:to_i))

	ref = {}
	while ref.size < 24 do
		ref[[dice.top, dice.s].to_s] = dice.e
		dice.rotate!('NSEW'[rand(4)])
	end

	gets.chomp.to_i.times do
		top, s = gets.split.map(&:to_i)
		p ref[[top, s].to_s]
	end
end



Measured memory_bytes: 6904
N, U, V = map(int, input().split())
A = [[] for _ in range(N)]
import sys
sys.setrecursionlimit(10**8)
for _ in range(N - 1):
    a, b = map(int, input().split())

    A[a - 1].append(b - 1)
    A[b - 1].append(a - 1)

C = [0] * N
D = [0] * N

def DFS(x, pre, cnt, C):
    C[x] = cnt
    cnt += 1
    for a in A[x]:
        if a == pre:
            continue

        DFS(a, x, cnt, C)


DFS(V - 1, -1, 0, C)
DFS(U - 1, -1, 0, D)
ans=0
for i in range(N):
    if C[i]>D[i]:
        ans =max(ans, C[i]-1)
print(ans)


Measured memory_bytes: 98348
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return [init]*size1
  else
    return [[init]*size2]*size1
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A=get_i.sort
m=Hash.new(0)
A.each do|a|
    m[a]+=1
end
MAX=A[N-1]
table=array(MAX+1,0)
ans=0
A.each do|a|
  if table[a].zero? and m[a]==1
    ans+=1
  end

    a_=a
    while a_<=MAX
      table[a_]=1
      a_+=a
    end
end
puts ans

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

int main() {
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == '1') ++counter;
    if (s[1] == '1') ++counter;
    if (s[2] == '1') ++counter;
    cout << counter << endl;
}


Measured memory_bytes: 256
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T

main :: IO ()
main = do
  let
    modulus = 1000000007 :: Int
    modAdd :: Int -> Int -> Int
    modAdd x y = (x + y) `mod` modulus
    modMul :: Int -> Int -> Int
    modMul x y = (x * y) `mod` modulus
    step :: (Int, Int) -> Int -> (Int, Int)
    step (s, c) x = (s `modAdd` (c `modMul` x), c `modAdd` x)
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getContents :: IO [Int]
  print . fst . foldl step (0, 0) $ as

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, k, h, m;
ll ans = 0, sum = 0, cnt = 0;
ld dh, dm;
string s/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

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

    cin >> n >> k >> h >> m;
	dh = (h * 30.0 + m * 0.5) / 180.0 * PI;
	dm = m / 30.0 * PI;
    cout << sqrt(n*n+k*k-2*n*k*cos(dh-dm)) << endl;
}


Measured memory_bytes: 4156
W,H,c = input().split()
W = int(W)
H = int(H)
for i in range(H):
    for j in range(W):
        if i == 0 and j == 0 or i == 0 and j == W-1 or \
           i == H-1 and j == 0 or i == H-1 and j == W-1:
            print("+", end="")
        elif i == 0 or i == H-1:
            print("-", end="")
        elif j == 0 or j == W-1:
            print("|", end="")
        elif i == H//2 and j == W//2:
            print(c, end="")
        else:
            print(".", end="")
    print()




Measured memory_bytes: 5636
# coding: utf-8

# 8問目

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


for i in range(n+1):
    for j in range(n+1 -i):
        k = n-i-j
        
        if (10000*i +5000*j +1000*k == y):
            print(i,j,k)
            exit()


print("-1 -1 -1")

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
    do           \
    {            \
    } while (0)
#define dump(x) \
    do          \
    {           \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template <class T>
inline T sqr(T x) { return x * x; }

void solve()
{
    int h, w;
    cin >> h >> w;
    string s;
    REP(i, 0, w + 2)
        cout << "#";
    cout << endl;
    REP(i, 0, h)
    {
        cin >> s;
        cout << "#" << s << "#" << endl;
    }
    REP(i, 0, w + 2)
        cout << "#";
    cout << endl;
}

int main()
{
    solve();

    return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if(a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if(a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

long long h[100010];

long long dp[100100];

int main() {
    int N, K;
    cin >> N >> K;
    
    for(int i = 0; i < N; ++i) cin >> h[i];
    for(int i = 0; i < 100100; ++i) dp[i] = INF;
    
    dp[0] = 0;

    // 配るDP
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define PI 3.14159265359
//#define gc() getchar_unlocked();
using namespace std;
clock_t start_time,end_time;

inline float ellapse(){ return (clock()-start_time)*1.0/CLOCKS_PER_SEC; }
//inline int read_int() {register char c = gc();while(c<'0' || c>'9') c = gc();int ret = 0; while(c>='0' && c<='9') {ret = 10 * ret + c - 48; c = gc();}return ret;}
long long int gcd( long long int a , long long int b )
{
    return b == 0 ? a : gcd( b , a%b );
}

long long power( long long a , long long b )
{
    long long ret = 1 ;
    while( b ) {
        if( b%2 == 1 ) ret = ( ret * a ) % mod  ;
        a = (a * a) % mod ;
        b /= 2 ;
    }
    return ret ;
}


#define N 310
int arr[ N ][ N ] , vis[ N ][ N ] ;

int main()
{

    int n ;
    cin >> n ;

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

    for( int i = 0 ; i < n ; i++ )
      for( int j = 0 ; j < n ; j++ )
        if( arr[ i ][ j ] != arr[ j ][ i ] ) {
          puts("-1") ;
          return 0 ;
        }

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

          for( int k = 0 ; k < n ; k++ ) {
             if( k != i && k != j ) {
               //try with this as middle
               int dist = arr[ i ][ k ] + arr[ k ][ j ] ;

               if( dist == arr[ i ][ j ] ) {
                  vis[ i ][ j ] = vis[ j ][ i ] = 1 ;
               }
               else if( dist < arr[ i ][ j ] ) {
                  puts("-1") ;
                  return 0 ;
               }
             }
          }
      }
    }

    long long ans = 0;

    for( int i = 0 ; i < n ; i++ ) {
      for( int j = 0 ; j < n ; j++ ) {
         if( vis[ i ][ j ] == 0 ) ans += arr[ i ][ j ] ;
      }
    }

    cout << ans/2 ;
    return 0 ;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int concat[][] = new int[N][2];

		for (int i = 0; i < N; i ++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			concat[i][0] = B;
			concat[i][1] = A;
		}

		Arrays.sort(concat, (a, b) -> Integer.compare(a[0], b[0]));

		boolean possible = true;
		long sum = 0;

		for (int i = 0; i < N; i++) {
			sum += concat[i][1];
			if (concat[i][0] < sum) {
				possible = false;
				break;
			}
		}

		if (possible) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    ll sum = 0;
    rep(i, k) sum += a[i];
    cout << sum << endl;
}


Measured memory_bytes: 256
N = int(input())
judge = False

for i in range(int(100/7)+1):
    if 7*i > N:
        break
    for j in range(26):
        if 7*i+4*j > N:
            break
        elif 7*i+4*j == N:
            judge = True
            break
    
if judge:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9+7 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void solve(){
    int k ;
    cin >> k ;
    int start = 1 ;
    priority_queue < ll > q ;
    for( int i = 1 ; i <= 9 ; i++)
        q.push(-i);
    while(true){
        ll x = -q.top();
        //cout << x << " " ;
        q.pop();
        k--;
        if(k==0){
            cout << x ;
            return ;
        }
         ll r = x%10;
         if(r!=0){
            q.push( -(x*10+r-1));
         }
         if(r!=9){
            q.push(-(x*10+r+1) );
         }
         q.push(-(x*10+r));
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t ;
    t = 1 ;

    //cin >> t ;
    while(t--){
        solve( );
    }
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using namespace std;

using key=pair<int,int>;
using Tree=tree<key,null_type,less<key>,rb_tree_tag,tree_order_statistics_node_update>;

struct Query{
    int index;
    int l,r;
};

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> lr(n);
    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        r++;
        lr[i]={l,r};
    }

    sort(lr.begin(),lr.end(),[](pair<int,int> &lhs,pair<int,int> &rhs){return lhs.first>rhs.first;});
    vector<int> ans(m,n);
    vector<Query> query;
    for(int i=0;i<m;i++){
        int d=i+1;
        for(int j=d;j-d<=m;j+=d){
            query.push_back(Query{i,j+1-d,j});
        }        
    }

    sort(query.begin(),query.end(),[](Query &a,Query &b){return a.l>b.l;});
    Tree t;

    int inde=0;
    for(int i=0;i<query.size();i++){
        while(inde<n && query[i].l<=lr[inde].first){
            t.insert({lr[inde].second,inde});
            inde++;
        }
        ans[query[i].index]-=t.order_of_key({query[i].r+1,-100});
    }
    for(int i=0;i<m;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 38884
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>

using namespace std;

int h,w,k;
char s[11][1001];

bool fun(vector<int> vec,int &cnt){
    int j = 0, j1 = -1;
    int len = vec.size(), c[11];
    memset(c,0,sizeof(c));
    while(j<w){
        int maxn = 0;
        for(int r=1;r<len;++r){
            for(int i=vec[r-1];i<vec[r];++i){
                if(s[i][j]=='1') ++c[r];
            }
            maxn = max(maxn,c[r]);
        }
        if(maxn>k){
            if(j-j1 == 1) return false;
            ++cnt;
            --j;
            j1 = j;
            memset(c,0,sizeof(c));
        }
        ++j;
    }
    return true;
}

int main(void)
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>h>>w>>k;
    for(int i=0;i<h;++i) cin>>s[i];
    int ans = 10000;
    for(int i=0;i<(1<<(h-1));++i){
        int cnt = 0;
        vector<int> vec;
        vec.push_back(0);
        for(int j=1;j<h;++j){
            if((1<<(j-1))&i){
                ++cnt;
                vec.push_back(j);
            }
        }
        vec.push_back(h);
        if(!fun(vec,cnt)) continue;
        else ans = min(ans,cnt);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    for i in range(26):
        for j in range(16):
            if 4 * i + 7 * j == N:
                print('Yes')
                return

    print('No')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9144
#include <stdio.h>
#include <stdlib.h>

#define N 8

int next(int n, int *aa) {
	int i, j, tmp;

	for (i = n - 2; i >= 0; i--)
		if (aa[i] < aa[i + 1])
			break;
	if (i < 0)
		return 0;
	for (j = n - 1; j > i; j--)
		if (aa[i] < aa[j])
			break;
	tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	for (i++, j = n - 1; i < j; i++, j--)
		tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	return 1;
}

int same(int n, int *aa, int *bb) {
	return n == 0 ? 1 : aa[0] != bb[0] ? 0 : same(n - 1, aa + 1, bb + 1);
}

int main() {
	static int pp[N], qq[N], xx[N];
	int n, i, a, b;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &pp[i]);
	for (i = 0; i < n; i++)
		scanf("%d", &qq[i]);
	for (i = 0; i < n; i++)
		xx[i] = i + 1;
	a = b = -1;
	i = 0;
	do {
		if (same(n, xx, pp))
			a = i;
		if (same(n, xx, qq))
			b = i;
		i++;
	} while (next(n, xx));
	printf("%d\n", abs(a - b));
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string A;
LL ans;

int main()
{
	in >> A;

	auto n = A.length() - 1;
	ans = (1 + n)*n / 2;
	std::sort(A.begin(), A.end());
	rep(i, A.length())
	{
		int j;
		for (j = i; j < A.length(); ++j)
		{
			if (A[j] != A[i]) { break; }
		}
		LL tmp = ((LL)j - (LL)i)*((LL)j - (LL)i - 1LL) / 2LL;
		ans -= tmp;
		i = (j - 1);
	}

	out << ans + 1 << std::endl;
	return 0;
}


Measured memory_bytes: 640
#include<queue>
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
int read()
{
	int s=0,c=getchar(),f=1;
	while(c<48||c>57)
	{
		if(c==45) f=-1;
		c=getchar();
	}
	while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return s*f;
}
void write(int x)
{
	if(x>=10) write(x/10);
	putchar(x%10+48);
}
int tot=0,aa[111111],bb[111111];
void W(int x)
{
	if(x<0) x=-x,putchar(45);
	write(x);
}
void Get(int x)
{
	for(int i=1;i<=x;++i)
	{
		for(int j=i+1;j<=x;++j)
		{
			if(i+j==x+1) continue;
			++tot;
			aa[tot]=i,bb[tot]=j;
		}
	}
}
int main()
{
	int N=read();
	if(N&1)
	{
		for(int i=1;i<N;++i) ++tot,aa[tot]=i,bb[tot]=N;
		--N;
	}
	Get(N);
	write(tot),puts("");
	for(int i=1;i<=tot;++i) 
	{
		write(aa[i]),putchar(32);
		write(bb[i]),puts("");
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
A=[int(i) for i in input().split()]
CL=[0]*9
for a in A:
  cl=min(8,a//400)
  if cl==8:
    CL[cl]+=1
  elif CL[cl]==0:
    CL[cl]=1
if sum(CL[:-1])==0:
  print(1,CL[-1])  
else:
  print(sum(CL[:-1]),sum(CL))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
vector<ll> memo(1e5+5, -1);
ll dp(vector<int> &v, int k, int i){
	if(i == v.size()-1)
		return 0;
	if(memo[i] != -1)
		return memo[i];
	memo[i] = 2e9;
	for(int n = 1; n <= k; n++){
		if(i+n>=v.size())
			break;
		memo[i] = min(memo[i], abs(v[i]-v[i+n]) + dp(v, k, i+n));
	}
	return memo[i];
}
signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	int n, k; 
	cin>>n>>k;
	vector<int> v(n);
	for(int &i : v)
		cin>>i;
	cout<<dp(v, k, 0);
}


Measured memory_bytes: 10752
#include<iostream>
#include<cctype>
#include <algorithm>
#include<string>
using namespace std;
int main(){
        string p;
        string in;
        string s[10000] ={""};
        getline(cin, p);
        int n = 0;
        int k = 0;
        int q = 0;
        bool j = true;
        while(1){
                getline(cin,in);
                for(int i = 0; i < in.length(); i++){
                        if(in[i] ==32){
                                k++;
                        }else{
                                s[k] += in[i];
                        }
                }
                for(;q <= k; q++){
                        if(s[q] =="END_OF_TEXT"){
                                j = false;
                        }
                        string l = s[q];
                     transform(l.begin(), l.end(), l.begin(), ::tolower);
                         if(l == p){
                                n++;
                        }
                }
                k++;
                if(j == false)break;
        }
            cout << n << endl;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll p = 1000000007;
int main(){
    ll n, m, A = 0, B = 0, lst, a = 0, b = 0;
    cin>>n>>m;
    cin>>lst;
    for(int i=1;i<n;i++){
        ll tmp;
        cin>>tmp;
        a = (a + (i*(tmp - lst)%p))%p;
        A = (A + a)%p;
        lst = tmp;
    }
    cin>>lst;
    for(int i=1;i<m;i++){
        ll tmp;
        cin>>tmp;
        b = (b + (i*(tmp-lst)%p))%p;
        B = (B + b)%p;
        lst = tmp;
    }
    cout<<A*B%p<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // B - ROT N

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String s = sc.next();

        byte[] bs = s.getBytes();
        byte[] bp = new byte[bs.length];

        for (int i = 0; i < bs.length; i++) {
            bp[i] = (byte) (bs[i] + (byte)n);
            if (bp[i] > 90) bp[i] -= 26;
        }

//        System.out.println(Arrays.toString(bs));
//        System.out.println(Arrays.toString(bp));
        for (byte b : bp) {
            System.out.print((char)b);
        }
        System.out.println();
    }
}

Measured memory_bytes: 25684
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

int N;
int A[200005];

int max1, max2;

vector<int> V;


int main(void) {


	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		V.push_back(A[i]);
	}

	sort(V.rbegin(), V.rend());

	max1 = V[0];
	max2 = V[1];

	for (int i = 1; i <= N; i++) {
		if (A[i] == max1) { cout << max2 << endl; }
		else { cout << max1 << endl; }
	}

	return 0;
}

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

#define int long long int
#define mp make_pair
using namespace std;

int n,m;
vector <int> v[100002];
int dp[100002];

int fun(int node)
{
    if(dp[node] != -1){
        return dp[node];
    }
    int ans = 0;
    for(int i = 0 ; i < v[node].size() ; i++){
        ans = max(ans , fun(v[node][i]));
    }
    dp[node] = ans + 1;
    return dp[node];
}
int32_t main() {
    scanf("%lld", &n);
    scanf("%lld", &m);
    int x,y;
    for (int i = 0; i < m; ++i) {
        scanf("%lld", &x);
        scanf("%lld", &y);
        v[x].push_back(y);
    }
    for (int i = 0; i < 100002; ++i) {
        dp[i] = -1;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans , fun(i));
    }
    printf("%lld",ans - 1);
    return 0;
}

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

class Program
{

    public static void Main( )
    {
        long N = long.Parse( Console.ReadLine( ) );
        string name = "";

        while ( N != 0 )
        {
            var rightNum = N % 26;
            var rightAlfa = (char)( 96 + ( rightNum == 0 ? 26 : rightNum ) );
            name = rightAlfa + name;
            N--;
            N /= 26;
        }

        Console.WriteLine( name.ToString( ) );
    }
}





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

using ll = long long;

int main()
{
    int X, Y;
    cin >> X >> Y;

    int d2 = X, d4 = 0;

    while ( d2 >= 0 ) {
        if ((d2 * 2 + d4 * 4) == Y) {
            cout << "Yes" << endl;
            return 0;
        }

        d2--;
        d4++;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3644
import java.lang.*;
import java.util.*;
public class Main{
public static void main(String[] args) 
{
	Scanner scanner=new Scanner(System.in);
	String s=scanner.next();
	int tr=0;
	int ans=1;
	int i=0;
	while(true)
	{	tr=0;
		if(i>=s.length())break;
		String s1=" ",s2=" ",s3=" ",s4=" ";
		if(i+5<=s.length())s1=s.substring(i,i+5);
		if(i+6<=s.length())s2=s.substring(i,i+6);
		if(i+7<=s.length())s3=s.substring(i,i+7);
		if(s1.compareTo("dream")==0)tr=1;
		if(s1.compareTo("erase")==0)tr=2;
		if(s2.compareTo("eraser")==0)tr=4;
		if(s3.compareTo("dreamer")==0){
			if(i+10<=s.length())s4=s.substring(i,i+10);
			if(s4.compareTo("dreamerase")==0)tr=1;
			else tr=3;
		}
		if(tr==0){ans=0;break;}
		if(tr==3){i+=7;continue;}
		if(tr==4){i+=6;continue;}
		if(tr==1 || tr==2)i+=5;
	}
	if(ans==1)System.out.println("YES");
	else System.out.println("NO");
}	
}


Measured memory_bytes: 29520
N, K = map(int, input().split())

X = []
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)

    # 白をKずらして黒に変換
    if c == "W":
        y += K

    # 2Kでmodをとる
    X.append((x % (2 * K), y % (2 * K)))


class Ruisekiwa2D:
    def __init__(self, h, w):
        self.H = h
        self.W = w
        self.G = [[0] * w for _ in range(h)]

    def load(self, points):
        # 問題によってイメージしやすいよう書き換えてください
        for x, y in points:
            self.G[x][y] += 1

    def load_imos(self, points):
        # pointsは[[左上h, 左上w, 右下h, 右下w], ...]であること
        for i1, j1, i2, j2 in points:
            self.G[i1][j1] += 1  # 左上
            if j2 + 1 < self.W:  # 右上
                self.G[i1][j2+1] -= 1
            if i2 + 1 < self.H:
                self.G[i2+1][j1] -= 1  # 左下
            if j2 + 1 < self.W and i2 + 1 < self.H:  # 右下
                self.G[i2+1][j2+1] += 1

    def calc(self):
        for y in range(self.W):
            for x in range(1, self.H):
                self.G[x][y] += self.G[x-1][y]

        for y in range(1, self.W):
            for x in range(self.H):
                self.G[x][y] += self.G[x][y-1]

    def get(self, i1, j1, i2, j2):
        if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
            return 0
        elif i1 > 0 and j1 > 0:
            return self.G[i2][j2] - self.G[i1-1][j2] - self.G[i2][j1-1] + self.G[i1-1][j1-1]
        elif i1 <= 0 < j1:
            return self.G[i2][j2] - self.G[i2][j1-1]
        elif j1 <= 0 < i1:
            return self.G[i2][j2] - self.G[i1 - 1][j2]
        else:
            return self.G[i2][j2]


R2D = Ruisekiwa2D(2*K, 2*K)
R2D.load(X)
R2D.calc()

# 真ん中の黒四角形について左上を全探索（K * Kまで）
ans = 0
for i in range(K):
    for j in range(K):
        tmp = 0
        tmp += R2D.get(0, 0, i - 1, j - 1)  # 左上
        tmp += R2D.get(0, j + K, i - 1, 2 * K - 1)  # 右上
        tmp += R2D.get(i, j, i + K - 1, j + K - 1)  # 真ん中
        tmp += R2D.get(i + K, 0, 2 * K - 1, j - 1)  # 左下
        tmp += R2D.get(i + K, j + K, 2 * K - 1, 2 * K - 1)  # 右下

        ans = max(ans, tmp, N - tmp)

print(ans)


Measured memory_bytes: 89560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const LL INF = 1e9 + 10;
char st[105];

int main(){
	scanf("%s", st);
	if(st[0] == 'Y' && st[1] == 'A' && st[2] == 'K' && st[3] == 'I') {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}

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

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

int main()
{
    int N, M;
    cin >> N >> M;
    int sum = N * (N - 1) / 2  + M * (M - 1) / 2;

    cout << sum << endl;
}

Measured memory_bytes: 256
from decimal import Decimal as d 
n,k=map(int,input().split())
ans=d(0)
for i in range(1,n+1):
    x=d(1)
    if i>=k:
        ans+=d(x)
    else:
        while i<k:
            x=d(x)/d(2)
            i*=2
        ans+=x
print(d(ans)/d(n))
        

        


Measured memory_bytes: 9916
using System;
using System.IO;
using System.Linq;

namespace Simultaneous_Equation
{
	class Program
	{
		static void Main(string[] args)
		{
			var result = Enumerable.Range(0, int.MaxValue)
				.Select(_ => Console.ReadLine())
				.TakeWhile(x => x != null)
				.Select(x => x.Split(' ').Select(y => double.Parse(y)).ToArray())
				.Select(x => new {
					X = (x[2] * x[4] - x[1] * x[5]) / (x[0] * x[4] - x[1] * x[3]),
					Y = (x[0] * x[5] - x[2] * x[3]) / (x[0] * x[4] - x[1] * x[3])
				});

			foreach (var item in result) {
				Console.WriteLine("{0:f3} {1:f3}", item.X, item.Y);
			}
		}
	}
}

Measured memory_bytes: 6196
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,K=LI()
AS=LI()
AS.sort()
FL=FLIST(N)
INV_FL=list(map(INV,FL))
K_2=K-2
N_1=N-1

if K == 1:
    print(0)
    exit()

# nC(k-2) の累積和
NCSUM=[0]*N
for i in range(K-2, N_1):
    # print("i:{} K-2:{} value:{}".format(i, K_2, (((FL[i]*INV_FL[i-K_2])%DVSR)*INV_FL[K_2])%DVSR))
    NCSUM[i+1] = (NCSUM[i] + (((FL[i]*INV_FL[i-K_2])%DVSR)*INV_FL[K_2])%DVSR )%DVSR

# print(NCSUM)

res = 0
# 最小値側
for i in range(N-K+1):
    res -= (NCSUM[N_1-i]-NCSUM[K_2])*AS[i]%DVSR
res %= DVSR

# 最大値側
for i in range(N-K+1):
    res += (NCSUM[N_1-i]-NCSUM[K_2])*AS[N_1-i]%DVSR
res %= DVSR
print(res)


Measured memory_bytes: 65576
#include <iostream>
using namespace std;
int n,m,sum,a[105],b[105],c[105];
int main() {
  //nを撮ってくる
        cin>>n;
//配列に値を代入
        for (int i=1; i<=n; ++i) {
          cin>>a[i],sum+=a[i];
        }
        //m撮ってくる
        cin>>m;
      
        for (int i=1; i<=m; ++i) {
                cin>>b[i]>>c[i];
                cout<<sum-a[b[i]]+c[i]<<endl;
        }
}


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

int main() {
  string a,b,c;cin>>a>>b>>c;
  cout << a[0] << b[1] << c[2] << endl;
}


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

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

  std::vector<int> D(N);
  for (int i = 0; i < N; i++) {
    std::cin >> D[i];
  }

  std::sort(D.begin(), D.end());
  std::cout << std::unique(D.begin(), D.end()) - D.begin() << std::endl;
}


Measured memory_bytes: 888
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <string>
using namespace std;



int main()
{
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int cnt = 0;
	for (int i = 1; i < n - 1; i++) {
		if (a[i] > a[i - 1] && a[i] < a[i + 1])
			cnt++;
		else if (a[i]<a[i - 1] && a[i]>a[i + 1])cnt++;
	}
	cout << cnt;
}

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

int main(void)
{
    int flag = 0;
    string S;
    cin >> S;
    int len = S.length();
    for( int i = 0; i < len; i++){
        flag = 0;
        S.pop_back();
        S.pop_back();
        for( int j = 0; j < S.length()/2; j++){
            if( S[j] != S[j+S.length()/2] ) flag = 1;
        }
        if( flag == 0 ){
            cout << S.length();
            return 0;
        }

    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    string T,S;
    cin>>S;
    cin>>T;
int count=0;

    for(int i=0;i<S.size();i++){
    	if(S.at(i)!=T.at(i)){
    		count++;
    	}
    }
if(count==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
    

    return 0;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli n;

int main(void){
    cin >> n;
    vector<vector<lli>> presuf(10, vector<lli>(10)), sufpre(10, vector<lli>(10));
    for(int i = 1; i <= n; i++){
        string s = to_string(i);
        presuf[s[0]-'0'][s[s.size()-1]-'0']++;
        sufpre[s[s.size()-1]-'0'][s[0]-'0']++;
    }
    lli ans = 0;
    rep(i, 10){
        rep(j, 10){
            ans += presuf[i][j]*sufpre[i][j];
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	cout << n*180 - 360 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int n = in.nextInt();
        int k = in.nextInt();

        int p = 0;
        double ep = 0;
        double sum = 0;
        Queue<Double> e = new LinkedList<>();

        for (int i = 0; i < k; i++) {
            p = in.nextInt();
            ep = (double) (((p * (p + 1)) / 2)) / p;
            sum += ep;
            e.offer(ep);
        }

        double maxSum = sum;

        for (int i = k; i < n; i++) {
            p = in.nextInt();
            ep = (double) (((p * (p + 1)) / 2)) / p;
            sum -= e.remove();
            sum += ep;
            e.offer(ep);
            maxSum = Math.max(maxSum, sum);
        }

        out.printf("%.12f%n", maxSum);
    }
}


Measured memory_bytes: 48860
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){
  if(u==NIL||k==u->key) return u;
  if(k<u->key) treeSearch(u->left,k);
  else treeSearch(u->right,k);
}




Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y=x;
    if(z->key < x->key) x =x->left;
    else x = x->right;
  }
  z->parent=y;
  if(y==NIL) root =z; 
  else if(z->key < y->key){
    y->left=z;
  }
  else y->right=z;
  
}   

void inorder(Node u){
  if(u != NIL){
     inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){

  if(u != NIL ){
    printf(" %d",u->key);
    preorder(u->left); 
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include<cmath>
using namespace std;
int iminus1;
int iminus2;
int minCost(int *arr,int n){
    for(int i=2;i<n;++i){
    int first=iminus2+fabs(arr[i]-arr[i-1]);
    int second=iminus1+fabs(arr[i]-arr[i-2]);
    iminus1=iminus2;
  iminus2=min(first,second);
     }
    return iminus2;
}
int main() {
    int n;
    cin>>n;
    int *arr=new int[n];
    
    for(int i=0;i<n;++i){
        cin>>arr[i];
    }
    iminus1=0;
    iminus2=fabs(arr[0]-arr[1]);
    cout<<minCost(arr,n);
}


Measured memory_bytes: 3976
//Littleboy123 Template 1.0

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

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(a) cout << (a) << '\n'
#define MEM(a,b) memset((a), (b), sizeof((a)));
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

//End of template

int main(){
	init();
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n*a, b) << nl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    int sum = (n - m) * 100 + m * 1900;
    //cout << sum << endl;
    double e = 0;
    double correct = pow(1.0 / 2, m);
    double wrong[1000] = {0};
    wrong[0] = 1; rrep(i, 1, 1000) wrong[i] = wrong[i - 1] * (1 - correct);
    rrep(i, 1, 1000) {
        double tmp = 0;
        rep(k, i) {
            tmp += wrong[i - 1] * correct;
        }
        tmp *= sum;
        e += tmp;
    }
    cout << e << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    double A,B,H,M;
    cin>>A>>B>>H>>M;
    double time = H*60+M;
    complex<double> hour(A,0),minute(B,0);
    double ttheta = time*0.5*M_PI/180,mtheta = time*6*M_PI/180;
    hour *= exp(complex<double>(0,ttheta));
    minute *= exp(complex<double>(0,mtheta));
    cout<<setprecision(20)<<abs(hour-minute);
    return 0;
}

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<pi> vpi;

#define debugone(x) cerr << #x << " " << x << endl;
#define debugtwo(x) cerr << #x << "-------------" << endl;for(auto &it: x) cerr << it << " ";cerr << endl;
#define debugthree(x, i, j) cerr << #x << "------------" << endl;cerr << "from " << i << " to " << j << endl;for(int k=i; k<=j; k++) cerr << x[k] << " ";cout << endl;

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

ll power_mod(ll x, ll n){
	if(n == 0) return 1LL;
	else if(n % 2 == 0){
		ll temp = power_mod(x, n/2);
		return (temp * temp)%mod;
	}
	else return (power_mod(x, n-1) * x)%mod;
}
long long inverse(long long n){
	return power_mod(n, mod - 2);
}
long long multiply(long long n, long long m){
	return (n * m)%mod;
}

long long divide(long long n, long long m){
	return (n * inverse(m))%mod;
}


int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m, k;
	cin >> n >> m >> k;
	const int N = (int)2e5 + 10;
	long long factorial[N];
	factorial[0] = 1;

	for(int i = 1; i < N; i++){
		factorial[i] = ((long long)(i) * factorial[i - 1]) % mod;
	}

	long long ans = 1;

	ans = multiply(ans, factorial[n * m - 2]);
	ans = divide(ans, factorial[k - 2]);
	ans = divide(ans, factorial[n * m - k]);


	ll tempSum = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			ll one = ((((ll)(m - j + 1)) * ((ll)(m - j)) * n)/2) % mod;
			ll two = ((((ll)(n - i + 1)) * ((ll)(n - i)) * m)/2) % mod;
			ll three = (one + two) % mod;
			tempSum += three;
			tempSum %= mod;
		}
	}

	ans = multiply(ans, tempSum);
	cout << divide(ans, 1) << endl;
}	

Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func sort(array []int) []int {
	n := len(array)
	for i:=0; i<n; i++ {
		for j:= i-1; j>=0; j-- {
			if array[j+1]>array[j] {
				l := array[j+1]
				array[j+1] = array[j]
				array[j] =  l
			}
		}
	}

	return array
}

func diff(a int, b int) int {
	if a-b>0 {
		return a-b
	} else {
		return b-a
	}
}

func main() {
	var n int
	var a []int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		a = append(a, tmp)
	}

	var a_score int
	var b_score int

	sorted_a := sort(a)

	for i:=0; i<n; i++ {
		if i%2 == 0 {
			a_score += sorted_a[i]
		} else {
			b_score += sorted_a[i]
		}
	}
	fmt.Println(diff(a_score, b_score))
}


Measured memory_bytes: 512
from collections import deque
import heapq
import sys
input = sys.stdin.readline


class SparseTable():
    """区間取得クエリをO(1)で答えるデータ構造をO(NlogN)で構築する
    query(l, r): 区間[l, r)に対するクエリに答える
    """
    def __init__(self, array, n):
        n = len(array)
        self.row_size = n.bit_length()

        # log_tableを構築する
        # log_table = [0, 0, 1, 1, 2, 2, 2, 2, ...]
        self.log_table = [0] * (n + 1)
        for i in range(2, n + 1):
            self.log_table[i] = self.log_table[i//2] + 1

        # sparse_tableを構築する
        self.sparse_table = [[0] * n for _ in range(self.row_size)]
        for i in range(n):
            self.sparse_table[0][i] = array[i]
        for row in range(1, self.row_size):
            for i in range(n - (1 << row) + 1):
                self.sparse_table[row][i] = self._merge(self.sparse_table[row - 1][i], \
                                            self.sparse_table[row - 1][i + (1 << row - 1)])

    def _merge(self, num1, num2):
        """クエリの内容"""
        return min(num1, num2)

    def query(self, l, r):
        """区間[l, r)に対するクエリに答える"""
        row = self.log_table[r - l]
        return self._merge(self.sparse_table[row][l], self.sparse_table[row][r - (1 << row)])


n = int(input())
p = list(map(int, input().split()))

q = [[0] * (n // 2) for i in range(2)]

for i in range(n):
    q[i%2][i//2] = p[i]

ind = {}
for i in range(n):
    ind[p[i]] = i

sp0 = SparseTable(q[0], n // 2)
sp1 = SparseTable(q[1], n // 2)

con = {}
ans = {}
div = 10**6
def solve(l, r):
    q = deque([l * div + r])
    while q:
        pos = q.pop()
        l, r = pos // div, pos % div 
        # min1 = min(q[l%2][l//2:r//2])
        if l % 2 == 0:
            min1 = sp0.query(l//2, r//2)
        else:
            min1 = sp1.query(l//2, r//2)
        use_pos1 = ind[min1]
        
        # min2 = min(q[(l+1)%2][(use_pos1+1)//2:(r+1)//2])
        if (l + 1) % 2 == 0:
            min2 = sp0.query((use_pos1 + 1) // 2, (r + 1) // 2)
        else:
            min2 = sp1.query((use_pos1 + 1) // 2, (r + 1) // 2)
        use_pos2 =  ind[min2]
        
        ans[pos] = min1 * div + min2
        con[pos] = []
        if l != use_pos1:
            con[pos].append(l * div + use_pos1)
            q.append(l * div + use_pos1)
        if use_pos1 + 1 != use_pos2:
            con[pos].append((use_pos1 + 1) * div + use_pos2)
            q.append((use_pos1 + 1) * div + use_pos2)
        if use_pos2 + 1 != r:
            con[pos].append((use_pos2 + 1) * div + r)
            q.append((use_pos2 + 1) * div + r)

    return


solve(0, n)
res = []
q = [(ans[n], n)]
while q:
    num, i = heapq.heappop(q)
    min1, min2 = num // div, num % div
    res.append(min1)
    res.append(min2)
    for new_num in con[i]:
        heapq.heappush(q, (ans[new_num], new_num))
print(*res)

Measured memory_bytes: 130616
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=-1){
		if(n==0){
			cout << 0 << endl;
			continue;
		}
		vector<int> v;
		while(n != 0){
			v.push_back(n%4);
			n /= 4;
		}
		for(int i=v.size()-1;i>=0;i--){
			cout << v[i];
		}
		cout << endl;
	}
}

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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int f=0;
	int e=0;
	for(int i=0;i<b;i++){
		int d[100];
		cin>>d[i];
		if(d[i]<c){
			e++;
		}
		else{
			f++;
		}
	}
	int g=min(f,e);
	cout<<g<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;

long long n, x;
vector<long long> bps, ps;
long long cnt=0, ans=0;

void rec(int l) {
  if (l == 0) {
    ans++;
    if(--x <= 0) return;
  } else {
    if(x - bps[l] >= 0) {
      ans += ps[l];
      x -= bps[l];
      if (x == 0) return;
    } else {
      if(--x <= 0) return; // b
      rec(l-1);
      if(x <= 0) return;
      ans++;
      if(--x <= 0) return; // p
      rec(l-1);
      if(--x <= 0) return; // b
    }
  }
}

int main() {
  cin >> n >> x;
  bps = vector<long long>(51);
  ps = vector<long long>(51);
  bps[0] = 1;
  ps[0] = 1;
  for (int i=1; i<=n; ++i) {
    bps[i] = 3 + 2*bps[i-1];
    ps[i] = 1 + 2*ps[i-1];
  }
  rec(n);
  cout << ans << endl;
  return 0;
}


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

int main()
{
	/*			
	int i,j;
	scanf("%d %d", &i,&j);
	*/
  int i;
	scanf("%d", &i);
	int h,m,s;
	h = i/3600;
	m = (i%3600)/60;
	s = i%60;
	cout << h << ":" << m << ":" << s << endl;
}




Measured memory_bytes: 3220
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順

using namespace std;
using ll = long long int;
using Graph = vector<vector<int>>;

int main(){
    int N,M;cin>>N>>M;
    Graph G(N);
    vector<int> H(N);
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    for(int i=0;i<M;i++){
        int A,B;cin>>A>>B;
        G[A-1].push_back(B-1);
        G[B-1].push_back(A-1);
    }
    int ans = 0;
    bool good = true;
    for(int i=0;i<N;i++){
        good = true;
        for(auto v:G[i]){
            if(H[i]<=H[v]){
                good = false;
            }
        }
        if(good) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8736