akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(uint.Parse).ToArray();
        var b = Console.ReadLine().Split().Select(uint.Parse).ToArray();
        b = b.Concat(b).ToArray();
        var aDiffXor = a.Skip(n - 1).Concat(a).Zip(a, (x, y) => x ^ y).ToArray();
        var bDiffXor = b.Skip(n - 1).Concat(b).Zip(b, (x, y) => x ^ y).ToArray();
        RollingHash aHash = new RollingHash(aDiffXor);
        RollingHash bHash = new RollingHash(bDiffXor);
        for (int i = n; i >= 1; i--)
        {
            var aHashVal = aHash.Slice(0, n);
            var bHashVal = bHash.Slice(i, n);
            if (aHashVal != bHashVal) continue;
            Console.WriteLine($"{n - i} {a[0] ^ b[i]}");
        }
    }
}


class RollingHash
{
    const ulong MASK30 = (1UL << 30) - 1;
    const ulong MASK31 = (1UL << 31) - 1;
    const ulong MOD = (1UL << 61) - 1;
    const ulong POSITIVIZER = MOD * ((1UL << 3) - 1);
    static uint Base;
    static ulong[] powMemo = new ulong[500000 + 1];
    static RollingHash()
    {
        Base = (uint)new Random().Next(int.MaxValue / 2, int.MaxValue);
        powMemo[0] = 1;
        for (int i = 1; i < powMemo.Length; i++)
            powMemo[i] = CalcMod(Mul(powMemo[i - 1], Base));
    }

    ulong[] hash;

    public RollingHash(uint[] s)
    {
        hash = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash[i + 1] = CalcMod(Mul(hash[i], Base) + s[i]);
    }

    public ulong Slice(int begin, int length)
    {
        return CalcMod(hash[begin + length] + POSITIVIZER - Mul(hash[begin], powMemo[length]));
    }

    private static ulong Mul(ulong l, ulong r)
    {
        var lu = l >> 31;
        var ld = l & MASK31;
        var ru = r >> 31;
        var rd = r & MASK31;
        var middleBit = ld * ru + lu * rd;
        return ((lu * ru) << 1) + ld * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    private static ulong Mul(ulong l, uint r)
    {
        var lu = l >> 31;
        var rd = r & MASK31;
        var middleBit = lu * rd;
        return (l & MASK31) * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    private static ulong CalcMod(ulong val)
    {
        val = (val & MOD) + (val >> 61);
        if (val >= MOD) val -= MOD;
        return val;
    }
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

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

map<int,int> card;
int N;
int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i,N){
        int t;
        cin >> t;
        card[t]++;
    }
    if(card.size()%2==1) cout << card.size() << endl;
    else cout << card.size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 4992
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-03-07 21:01:45
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    LL n, a, b;
    cin >> n >> a >> b;

    LL c, x, y;
    c = a + b;
    
    x = n/c;
    y = n%c;

    LL ans = 0;
    ans += x*a;
    if (y >= a) {
        ans += a;
    } else {
        ans += y;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int x=n/1000;
	if(x*1000==n)
		cout<<"0"<<endl;
	else
		cout<<(x+1)*1000-n;
	return 0;
}




Measured memory_bytes: 3636
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int board[44][44];
int h, w;

int DFS(int x, int y, int n){
	int ret = 0;
	while(board[x][y] != 0){
		x++;
		if(x > w){
			y++;
			x = 1;
			if(y > h)return 1;
		}
	}
	//たて向き
	if(board[x][y+1]==0){
		int check = 0;
		if(board[x][y-1] != board[x+1][y-1])check++;
		if(board[x+1][y-1] != board[x+1][y])check++;
		if(check != 2){
			board[x][y] = n;
			board[x][y+1] = n;
			ret += DFS(x,y,n+1);
			board[x][y] = 0;
			board[x][y+1] = 0;
		}
	}
	//よこ向き
	if(board[x+1][y]==0){
		int check = 0;
		if(board[x+1][y-1] != board[x+2][y-1])check++;
		if(board[x+2][y] != board[x+2][y-1])check++;
		if(check != 2){
			board[x][y] = n;
			board[x+1][y] = n;
			ret += DFS(x,y,n+1);
			board[x][y] = 0;
			board[x+1][y] = 0;
		}
	}
	return ret;
}

int main(){
	while(1){
		memset(board, 0, sizeof(board));
		cin >> h>> w;
		if(h==0)break;
		REP(i,w+2){
			board[i][0] = 1000;
			board[i][h+1] = 1000;
		}
		REP(i,h+2){
			board[0][i] = 1000;
			board[w+1][i] = 1000;
		}
		if(h==0)return 0;
		cout << DFS(1, 1, 1) << endl;
	}
}

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

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll maxn=55, maxm=5e4+10, lg=21, mod=1e9+7, inf=1e18;

ll n,a[maxn],b[maxn],ii,adj[maxn][maxn];
bool mk[maxn];
void edd(ll m,ll d){for(int i=m;i<=50;i++) adj[i][i%m]+=d;}
bool dfs(ll v){
	if(v==b[ii]) return 1;
	if(mk[v]) return 0;
	mk[v]=1;
	for(int i=0;i<v;i++)if(adj[v][i])if(dfs(i)) return 1;
	return 0;
}
bool check(){
	for(ii=0;ii<n;ii++){
		memset(mk,0,sizeof(mk));
		if(!dfs(a[ii])) return 0;
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	ll ans=0,p2=1;
	for(int i=1;i<=50;i++) edd(i,+1), p2*=2;
	if(!check()) return cout<<-1,0;
	for(int i=50;i>=1;i--){
		edd(i,-1);
		if(!check()) edd(i,+1), ans+=p2;
		p2/=2;
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 3716
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int main() {
	int a,b;
	scanf("%d%d", &a, &b);
	printf("%d %d %lf\n",a/b,a%b,a/(double)b);
	return 0;
}

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

int main(){
  int N,Y;
  cin >> N >> Y;
  for(int i=0; i<=N; i++){
    for(int j=0; j<=N; j++){
      if(i+j>N) continue;
      int rem=Y-10000*i-5000*j;
      if(rem%1000==0 && i+j+(rem/1000)==N){
        cout << i << " " << j << " " << rem/1000 <<endl;
        // cout << "  " << Y-10000*i-5000*j-1000*(rem/1000) <<endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" <<endl;
}

Measured memory_bytes: 256
let n = read_int()
let f () = Array.init n (fun _ -> Scanf.scanf " %d" (fun i -> i))
let a = f ()
let b = f ()
let c = f ()

let rec f j ans =
  if j = n then ans
  else
    let rec g l r =
      if l = r then l + 1
      else
        let m = (l + r + 1) / 2 in
        if a.(m) < b.(j) then g m r
        else g l (m - 1) in
    let rec h l r =
      if l = r then n - l
      else
        let m = (l + r) / 2 in
        if b.(j) < c.(m) then h l m
        else h (m + 1) r in
    let i = g ~-1 (n - 1) in
    let k = h 0 n in
    f (j + 1) (ans + i * k)

let () =
  Array.sort (fun x y -> x - y) a;
  Array.sort (fun x y -> x - y) c;
  let ans = f 0 0 in
  Printf.printf "%d\n" ans


Measured memory_bytes: 8324
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;

const int MAXN = 400002;
int a[MAXN], b[MAXN];

int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
    string s;
    cin >> s;
    if (s.length() != 26) {
        vector<bool> w(26, 0);
        for (char c : s) {
            w[c - 'a'] = true;
        }

        int p = 0;
        while (w[p]) {
            ++p;
        }

        cout << s + char('a' + p) << "\n";
    } else {
        string t = s;
        if (next_permutation(s.begin(), s.end())) {
            int c = 0;
            while (s[c] == t[c]) {
                ++c;
            }

            ++c;

            cout << s.substr(0, c) << "\n";
        } else {
            cout << "-1\n";
        }
    }
}

Measured memory_bytes: 256
//ABC094C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long int> x(n), y(n);
	for(int i=0;i<n;i++){
		cin >> x.at(i);
		y.at(i) = x.at(i);
	}
	sort(y.begin(),y.end());
	long long int c = y.at(n/2-1);
	for(int i=0;i<n;i++){
		if(x.at(i) <= c){
			cout << y.at(n/2) << endl;
		}else{
			cout << y.at(n/2-1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> G[4];
int main() {
	for (int i = 0; i < 3; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int odd = 0;
	for (int i = 0; i < 4; i++) {
		if (G[i].size() % 2) odd++;
	}
	if (odd == 0 || odd == 2) cout << "YES" << endl;
	else cout << "NO" << endl;

}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

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

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

idx = [0] * (N+1)
for i in range(N):
    a = A[i]
    idx[a] = i


class SegmentTree:
    """
    引数：
        N: 処理する区間の長さ
        operator: モノイド演算 (max, min, __add__,ラムダ式,関数定義など)
        UNIT: 単位元
        a: 長さNの配列 a で初期化（a を与えない場合、単位元で初期化）
    注意: 内部的には 1-indexed
    """

    def __init__(self, N, operator, unit, a=None):
        self.op = operator
        self.UNIT = unit

        self.N0 = 2**(N-1).bit_length()
        self.tree = [self.UNIT]*(2*self.N0)
        if a != None:
            self.tree[self.N0:self.N0+N] = a[:]
            for k in range(self.N0-1, 0, -1):
                self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])

    # a_k の値を x に更新
    def update(self, k, x):
        k += self.N0
        self.tree[k] = x
        k //= 2
        while k:
            self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])
            k //= 2

    # 区間[l,r)をopでまとめる
    def query(self, l, r):
        L = l + self.N0
        R = r + self.N0
        s = self.UNIT
        while L < R:
            if R & 1:
                R -= 1
                s = self.op(self.tree[R], s)
            if L & 1:
                s = self.op(s, self.tree[L])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def get(self, k):  # k番目の値を取得。query[k,k]と同じ
        return self.tree[k + self.N0]

    def all(self):
        return self.tree[1]


seg_sml = SegmentTree(N, min, N)
seg_big = SegmentTree(N, max, -1)

ans = 0

for a in range(1, N + 1):
    i = idx[a]
    l = seg_big.query(0, i)
    r = seg_sml.query(i, N)

    left = i - l - 1
    right = r - i - 1

    cnt = (r - l - 1) * (r - l) // 2
    cnt -= left * (left + 1) // 2
    cnt -= right * (right + 1) // 2

    ans += cnt * a

    seg_sml.update(i, i)
    seg_big.update(i, i)


print(ans)


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

int main()
{
	char a, b;
	cin >> a >> b;
	if (a == 'H'&& b == 'D')
		cout << "D";
	else if (a == 'H'&& b == 'H')
	
		cout << "H";
	
	else if (a == 'D'&& b == 'H')
	
		cout << "D";
	
	else if (a == 'D'&& b == 'D')
	
		cout << "H";
	
	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int t1,t2,t3,max,mi,cost=0;
    scanf("%d %d %d",&t1,&t2,&t3);
    if(t1>t2 && t1>t3){
        max=t1;
        mi=1;
    }else if(t2>t3){
        max=t2;
        mi=2;
    }else{
        max=t3;
        mi=3;
    }
    if(mi==1){
        if(t2>t3){
            cost=abs(t1-t2)+abs(t2-t3);
        }else{
            cost=abs(t1-t3)+abs(t3-t2);
        }
    }else if(mi==2){
        if(t1>t3){
            cost=abs(t2-t1)+abs(t1-t3);
        }else{
            cost=abs(t2-t3)+abs(t3-t1);
        }
    }else{
        if(t1>t2){
            cost=abs(t3-t1)+abs(t1-t2);
        }else{
            cost=abs(t3-t2)+abs(t2-t1);
        }
    }
    printf("%d\n",cost);
    return 0;
}



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

int main() {
	int n,k;
	cin >> n >> k;
	int arr[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
		for(int j=2;j<=min(i,k);j++){
			dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
		}
	}
	cout << dp[n-1];
	// your code goes here
	return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n: break
        if n % i == 0: return False
    return n != 1


x = int(input())

while 1:
    if is_prime(x):
        print(x)
        exit()
    x += 1


Measured memory_bytes: 62840
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k,l = list(map(int, input().split()))
from collections import defaultdict
ns0 = defaultdict(list)
ns1 = defaultdict(list)
for i in range(k):
    p,q = map(int, input().split())
    p-=1;q-=1
    ns0[p].append(q)
    ns0[q].append(p)
for i in range(l):
    p,q = map(int, input().split())
    p-=1;q-=1
    ns1[p].append(q)
    ns1[q].append(p)
def sub(ns):
    seen = [None]*n
    num = 1
    for i in range(n):
        if seen[i] is not None:
            continue
        q = [i]
        seen[i] = num
        while q:
            u = q.pop()
            for v in ns[u]:
                if seen[v] is not None:
                    continue
                seen[v] = num
                q.append(v)
        num += 1
    return seen

s1 = sub(ns0)
s2 = sub(ns1)

import gc
del ns0, ns1
gc.collect()

d1 = [None]*(max(s1)+1)
d2 = [None]*(max(s2)+1)
def update(d,ind,i):
    if d[ind] is None:
        d[ind] = set([i])
    else:
        d[ind].add(i)
for i in range(n):
    update(d1,s1[i],i)
    update(d2,s2[i],i)
#     d1[s1[i]].add(i)
#     d2[s2[i]].add(i)
d = {}
ans = [None]*n
for i in range(n):
    u,v = s1.pop(), s2.pop()
    if (u,v) not in d:
        d[u,v] = len(d1[u] & d2[v])
    ans[-(i+1)] = d[u,v]
write(" ".join(map(str, ans)))

Measured memory_bytes: 254804
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


long long A, B, C, X, Y;
int main() {
    while (cin >> A >> B >> C >> X >> Y) {
        long long res = A * X + B * Y;
        
        for (long long i = 0; i <= max(X, Y) * 2; ++i) {
            long long tmp = C * (i*2);
            long long nA = max(0LL, X - i);
            long long nB = max(0LL, Y - i);
            tmp += nA * A + nB * B;
            chmin(res, tmp);
        }
        
        cout << res << endl;
    }
}
























Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = INF; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
w = wi()
s1 = 0
s2 = 0
for i in range(n + 1):
    s1 = 0
    s2 = 0
    for j in range(n):
        if j < i:
            s1 += w[j]
        else:
            s2 += w[j]
    ans = min(ans, abs(s1 - s2))

print(ans)

Measured memory_bytes: 6476
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){
    int N;
    cin >> N;
    int x[9];
    int y[9];
    rep(i, N){
        cin >> x[i] >> y[i];
    }
    vector<int> v;
    rep(i, N){
        v.push_back(i);
    }
    double ans = 0;
    do {
        double tmp = 0;
        rep(i, N-1){
            double t = pow(x[v[i]]-x[v[i+1]], 2);
            double t1 = pow(y[v[i]] - y[v[i+1]], 2);
            double s = sqrt(t + t1);
            tmp += s;
        }
        ans += tmp;

    } while (std::next_permutation(v.begin(), v.end()));
    ll tt = 1;
    rep(i, N){
        tt = tt * (i+1);
    }
    cout << setprecision(14)<< ans / (tt) << endl;

}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
k=max(h)

ans=0
for i in range(k):
  j=0
  while j<n:
    #連結成分の数を数える
    if h[j]==0:
      j=j+1
    else:
      while j<n and h[j]!=0:
        h[j]=max(h[j]-1,0)
        j=j+1
      ans=ans+1
print(ans)

        

Measured memory_bytes: 9180
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <sstream>
#include <malloc.h>
using namespace std;

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

	double sum = 0;
	for(int i=0; i<N; i++)
	{
		double value;
		string type;
		cin>>value>>type;
		if(type == "JPY")
		{
			sum += value;
		}
		else if(type == "BTC")
		{
			sum += value * 380000.0;
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
typedef vector<LL> V;
int main() {
	int N; LL H;
	cin >> N >> H;
	LL a=0;
	V b(N);
	for (auto i : range(N)) {
		LL aa;
		cin >> aa >> b[i];
		chmax(a, aa);
	}
	sort(ALL(b));
	reverse(ALL(b));
	LL ret = (H + a - 1) / a;
	LL sum = 0;
	for (auto i : range(N)) {
		sum += b[i];
		chmin(ret, i + 1 + max(0ll, (H + a - 1 - sum) / a));
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main (void) {
    int A, B;

    cin >> A >> B;

    if (A == 1) A += 13;
    if (B == 1) B += 13;

    if (A > B) cout << "Alice" << endl;
    else if (A < B) cout << "Bob" << endl;
    else cout << "Draw" << endl;
    
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<numeric>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    string s;
    cin >> s;
    int n = s.size()+1;
    vector<ll> a(n);
    rep(i,n-1) if ( s[i] == '<' ) a[i+1] = max(a[i+1],a[i]+1);
    for ( int i = n-2; i >= 0; --i) {
        if ( s[i] == '>' ) a[i] = max(a[i], a[i+1]+1);
    }
    cout << accumulate(a.begin(), a.end(), ll(0) ) << endl;
    return 0;
}



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

int v[100], dp[50][50][100];

int f(int i, int j, int k) {
	if (k == 0 || i > j)
		return 0;
	if (dp[i][j][k] != -1)
		return dp[i][j][k];
	int ans = 0;
	if (k > 0) {
		ans = max(v[i] + f(i + 1, j, k - 1), ans);
		ans = max(v[j] + f(i, j - 1, k - 1), ans);
	}
	if (k > 1) {
		ans = max(f(i + 1, j, k - 2), ans);
		ans = max(f(i, j - 1, k - 2), ans);
	}
	return dp[i][j][k] = ans;
}

int main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> v[i];
	memset(dp, -1, sizeof(int) * 250000);
	cout << f(0, n - 1, k) << endl;

	return 0;
}


Measured memory_bytes: 1280
n,m = map(int,input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
MOD = 10**9 + 7

def bruteforce():
    total = 0
    for i in range(n-1):
        for j in range(i+1, n):
            for k in range(m-1):
                for l in range(k+1, m):
                    total += (x[j]-x[i]) * (y[l]-y[k])
    return total % MOD

def solve():
    width = 0
    for i in range(1, n):
        w = x[i] - x[i-1]
        width += w * (n-i)*i
        width %= MOD
    height = 0
    for i in range(1, m):
        h = y[i] - y[i-1]
        height += h * (m-i)*i
        height %= MOD

    return width * height % MOD

if __name__ == '__main__':
    # print(bruteforce())
    print(solve())

Measured memory_bytes: 18556
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 500005;

int n, m;
int col[MAXN], bad;
vector<int> gph[MAXN];
vector<int> dfn;

void dfs(int x, int c){
	if(col[x]){
		if(col[x] != c) bad = 1;
		return;
	}
	col[x] = c;
	dfn.push_back(x);
	for(auto &i : gph[x]) dfs(i, 3 - c);
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=0; i<m; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	lint ret = 0;
	for(int i=1; i<=n; i++){
		if(!col[i]){
			bad = 0;
			dfn.clear();
			dfs(i, 1);
			if(bad){
				int w = dfn.size();
				ret += 1ll * w * (w-1) / 2;
				continue;
			}
			int c1 = 0, c2 = 0;
			for(auto &j : dfn){
				if(col[j] == 1) c1++;
				else c2++;
			}
			ret += 1ll * c1 * c2;
		}
	}
	cout << ret - m << endl;
}


Measured memory_bytes: 17532
import random
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
ans = 0
a = []
last = [0]*26
for i in range(1,d+1):
    res = -float("inf")
    index = 0
    for k in range(26):
        x = k
        tnplast = last
        tnplast[x] = i
        tnp = 0
        tnp += s[i-1][x]
        for j in range(26):
            tnp -= c[j]*(i-last[j])
        if (tnp > res):
            res = tnp
            index = k+1
    ans += res
    a.append(index)

def rec(t,x,y,ans):
    ans -= s[x-1][t[x-1]-1]
    ans += s[x-1][y-1]
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==t[x-1]):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==t[x-1]):
            mi = j
            break
    ans -= c[t[x-1]-1]*(x-mi)*(ma-x)
    ma = d+1
    mi = 0
    for j in range(x+1,d+1):
        if (t[j-1]==y):
            ma = j
            break
    for j in range(x-1,0,-1):
        if (t[j-1]==y):
            mi = j
            break
    ans += c[y-1]*(x-mi)*(ma-x)
    return ans
    
for i in range(20000):
    x = random.randrange(1,d+1)
    y = random.randrange(1,27)
    t = a
    t[x-1] = y
    A = rec(t,x,y,ans)
    if (ans < A):
        a = t
        ans = A

print(*a ,sep="\n")
    
    

Measured memory_bytes: 9704
W = input().lower()
#print(W)
t=0

while(1):
	char_list = list(x for x in input().split())
	#print(char_list)
	if char_list[0] == 'END_OF_TEXT':
		break
	
	for i in range(len(char_list)):
		if W == char_list[i].lower():
			t += 1

print(t)

Measured memory_bytes: 7384
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.NoSuchElementException;

public class Main {

	void run() {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		long[] A = new long[N];
		long sum1 = 0, sum2 = 0;
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextLong();
			sum1 += A[i];
		}
		long ans = Long.MAX_VALUE / 3;
		for (int i = 0; i < N; ++i) {
			sum2 += A[i];
			ans = Math.min(ans, Math.abs(sum2 - (sum1 - sum2)));
		}
		System.out.println(ans);
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 25332
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main(){
   long long n;
   cin >> n;
   if(n%2 == 1){
      cout << 0 << endl;
      return 0;
   }
   long long sum = 0;
   for(long long i=10;i<=n;i*=5){
      sum += n/i;
   }

   cout << sum << endl;
   return 0;
}

Measured memory_bytes: 256
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = array_map("intval", explode(" ", trim(fgets(STDIN))));

  for($i=0;$i<$n;$i++){
    $a[$i] = $a[$i]-($i+1);
  }

  sort($a);

  //var_dump($a);

  if($n % 2 == 0){
    $b = $a[$n/2];
  }else{
    $b = $a[($n-1)/2];
  }
  //echo $b." ";

  $ans = 0;
  for($i=0;$i<$n;$i++){
    $ans+=abs($a[$i]-$b);
  }
  echo $ans;


Measured memory_bytes: 38000
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<list>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back

#define ll __int64
#define P pair<ll,ll>
//#define __int64 long long
string s;
int k;
map<string,int>t;

int main(){	
	cin>>s>>k;

	int n=s.size();
	rep(i,n){
		string tmp="";
		tmp.push_back(s[i]);
		t[tmp]++;
		//cout<<tmp<<endl;
		for(int j=i+1;j<min(i+5,n);j++){
			tmp.push_back(s[j]);
			t[tmp]++;
			//cout<<tmp<<endl;
		}
	}

	map<string,int>::iterator it=t.begin();

	rep(i,k-1)it++;

	cout<<(*it).first<<endl;
	
	return 0;

}


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

int main()
{
    int a[4], d, i, count=0;

    for(i=0; i<3; i++)
        cin>>a[i];
    cin>>d;
    a[3] = a[0];

    if((abs(a[0] - a[1]) <=d && abs(a[2] - a[1]) <=d) || abs(a[0] - a[2]) <=d)
        cout<<"Yes";
    else
        cout<<"No";





}


Measured memory_bytes: 256
class Bounding:
    def __init__(self):
        self.N, self.X = map(int, input().split())
        self.L = [int(i) for i in input().split()]

    def count_bound(self):
        d = 0
        counter = 1

        # 2回目から
        for l in self.L:
            d += l
            if d <= self.X:
                counter += 1
            else:
                break

        print(counter)


bounding = Bounding()
bounding.count_bound()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)




using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;



int main(){
  string s;
  cin>>s;
  auto n=size(s);
  map<int,int> nr,nl; //group iのr数，l数．
  map<int,int> pr; //group iの最終r位置．
  vector<int> ans(n); //最終位置．
  
  rep(i,n){
    ans[i]=0;
  }
  
  
  int g=0;
  char prev='R';
  int nturn=0;
  
  rep(i,n){
    if(s[i]==prev){
      if(s[i]=='R'){
        //cout<<"R"<<endl;
        nr[g]++;
      }else{
        nl[g]++;
      }
    }else{
      nturn++;
      if(nturn%2==0){
        g++;
        nr[g]+=1;
      }else{
        pr[g]=i-1;
        nl[g]+=1;
      }
    }
    prev=s[i];
  }
  
  g=0;
  rep(i,size(pr)){
    ans[pr[i]]=(nr[i]+1)/2+nl[i]/2;
    ans[pr[i]+1]=(nr[i])/2+(nl[i]+1)/2;    
    g++;
  }
  rep(i,n){
    cout<<ans[i]<<" ";
  }
  
  








}


Measured memory_bytes: 10848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		String w = sc.next().toLowerCase();
		int count = 0;

		String word = sc.next();
		for (; !word.equals("END_OF_TEXT"); word = sc.next()) {
//			System.out.println(word);
			if (w.equals(word.toLowerCase())) {
				count++;
			}
		}

		System.out.println(count);
		
		sc.close();
	}
}

Measured memory_bytes: 18028
base_num = input()
unit = base_num.split(' ')
vec_a_max = int(unit[0])
vec_b_max = int(unit[1])
end_num = 0

input_list = []
while True:
    base_suit = input()
    input_list.append(base_suit)

    end_num += 1
    if (vec_a_max + vec_b_max) == end_num:
        break

matrix_a = []
matrix_b = []
for i, r in enumerate(input_list):
    if i < vec_a_max: 
        row = r.split(' ')
        matrix_a.append([int(x) for x in row])
    else:
        matrix_b.append(int(r))

for row_a in matrix_a:
    c = 0
    for a,b in zip(row_a,matrix_b):
        c += a * b
    print(c)



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

const int MAXN = 1e5 + 10;

bool vis[MAXN];
int n, m, k;
int u, v;
int a[MAXN];
long long ans;
vector<int> adj[MAXN];
vector<int> ret;
vector<vector<int>> b;
 
void dfs(int x, vector<int>& k) {
	k.push_back(a[x]);
	vis[x] = true;
	for (int u: adj[x]) 
		if (!vis[u]) 
			dfs(u, k);
}
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	///////////////////////////////////////////////////////////
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= m; i++) {
		cin >> u >> v;
		u++;
		v++;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	/////////////////////////////////////////////////////////////
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			dfs(i, ret);
			b.push_back(ret);
			ret.clear();
		}
	}
	k = b.size();
 
	if (n < 2 * k - 2)
		return cout << "Impossible" << '\n', 0;

	if (k == 1)
		return cout << 0 << '\n', 0;
		
	vector<int> res;
	for (auto v: b) {
		sort(v.rbegin(), v.rend());
		ans += v.back();
		v.pop_back();
		copy(v.begin(), v.end(), back_inserter(res));
	}
	
	sort(res.begin(), res.end());
	ans = accumulate(res.begin(), res.begin() + k - 2, ans);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 9524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
template <class T>
void show(vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    cerr << v[i] << " ";
  }
  cerr << endl;
}
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;
}

int main() {
  string a, b;
  cin >> a >> b;
  for (int i = a.length() - b.length(); i >= 0; --i) {
    for (int q = 0; q < b.length(); ++q) {
      if (a[i + q] != b[q] && a[i + q] != '?') goto failed;
    }
    for (int q = 0; q < b.length(); ++q) {
      a[i + q] = b[q];
    }
    for (int q = 0; q < a.length(); ++q) {
      if (a[q] == '?') a[q] = 'a';
    }
    cout << a << endl;
    return 0;
  failed:;
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	string s;  cin >> s;

	int64_t c = 0;
	int na = 0;
	for (int i = 0; i < s.size();) {
		if (s[i] == 'A') {
			na++;
			i++;
		}
		else if (i + 1 < s.size() && s[i] == 'B' && s[i + 1] == 'C') {
			c += na;
			i += 2;
		}
		else {
			na = 0;
			i++;
		}
	}

	cout << c << endl;

	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n;
  cin >> n;
  vi a(n), b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll asum = 0, bsum = 0;
  rep(i,n) asum += a[i];
  rep(i,n) bsum += b[i];
  if(asum < bsum){
    cout << -1 << endl;
    return 0;
  }
  vi c(n);
  rep(i,n) c[i] = a[i]-b[i];
  ll csum = asum - bsum;
  int cnt = 0;
  sort(all(c));
  rep(i,n){
    if(c[i] < 0) continue;
    csum -= c[i];
    if(csum < 0){
      break;
    }
    cnt++;
  }
  cout << n - cnt << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	int n;
	cin >> n;
	vector<int> now(n);
	now[0]=3;
	ll ans = 1;
	rep(i,n)
	{
		int foo;
		cin >> foo;
		ans *= now[foo];
		now[foo]--;
		now[foo+1]++;
		ans %= (int)1e9+7;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import math

def f(a,b):
    if a+90 >= b and a-90 <= b:
        return True
    if a+270 <= b and b <= 180:
        return True
    if a-270 >= b and b >= -180:
        return True
    return False

n = int(input())

xy = []
ang = []
for _ in range(n):
    x,y = map(int,input().split())
    xy.append((x,y))
    ang.append(math.degrees(math.atan2(y,x)))




res = 0
p = -180.0
d = 360.0/1000
for _ in range(1000):
    xx = 0.0
    yy = 0.0
    for i,e in enumerate(ang):
        if f(p,e):
            xx += xy[i][0]
            yy += xy[i][1]
    p += d
    tmp = (xx**2+yy**2)**0.5

    res = max(tmp,res)
print(res)

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

typedef unsigned long long ll;
#define mod 1000000007
#define all(x) (x).begin(),(x).end()

void solve(){
	int n,x,t;
	cin>>n>>x>>t;
	int tmp=0;
	if(n%x==0){
		tmp = n/x;
	}else{
		tmp = (n/x)+1;
	}
	cout<<t*tmp<<endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//  int testcase;
//  cin>>testcase;
//  while(testcase--){
      solve();
  //}
  return 0;
}

Measured memory_bytes: 3652
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i,a,b) for (int i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)
 
#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 	//ll ans = 1;
	//freopen ("test.txt","r",stdin);
 	ll h,w;
 	cin>>h>>w;
 	char arr[h][w];
 	for(int i=0;i<h;i++)
 	{
 		for(int j=0;j<w;j++)
 		{
 			cin>>arr[i][j];
 		}
 	}

 	ll dp[h][w];

 	for(int i=0;i<h;i++)
 	{
 		for(int j=0;j<w;j++)
 		{
 			if(arr[i][j] == '#')
 			{
 				dp[i][j] = -1;
 			}
 			else
 			{
 				dp[i][j] = 0;
 			}
 			
 		}
 	}

 	
 	dp[0][0] = 1;

 	for (int i = 1; i < h; ++i)
 	{
 		bool f = 0;
 			if(dp[i][0] == -1){
 				f = 1;
 				while(i<h)
 				{
 					dp[i][0] = -1;
 					i++;
 				}
 			}
 			if(f)break;

 		dp[i][0] = dp[i-1][0];
 	}

 	for (int i = 1; i < w; ++i)
 	{
 		bool f = 0;
 			if(dp[0][i] == -1){
 				f = 1;
 				while(i<w)
 				{
 					dp[0][i] = -1;
 					i++;
 				}
 			}
 			if(f)break;

 		dp[0][i] = dp[0][i-1] ;
 	}


	

 	for(int i=1;i<h;i++)
 	{
 		for(int j=1;j<w;j++)
 		{
 			
 			
 			if(dp[i][j] == -1)continue;
 			

 			if(dp[i][j-1] == -1 && dp[i-1][j] == -1)
 			{
 				dp[i][j] = -1;
 				
 			}
 			else if(dp[i][j-1] == -1)
 			{
 				dp[i][j] = dp[i-1][j]; 
 			}
 			else if(dp[i-1][j] == -1)
 			{
 				dp[i][j] = dp[i][j-1];
 			}
 			else
 			{
 				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
 			}


 		}
 	}
 	
 	if(dp[h-1][w-1] == -1)
 	{
 		cout<<0;return 0;
 	}
 	cout<<dp[h-1][w-1];
}

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

long inf = 1000000007;


int main() {
  long a,b,n; cin >> a >> b >> n;
  long score = 0;
  long i = 0;
  
  if(n<b-1){
    i = n;
  }
  else{
    i = b-1;
  }

     score = (a*i)/b - a*(i/b);
   
  
  
  cout << score << endl;
}

	


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;


int main() {
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  for(int i = 1; i < n; ++i){
    int cnt = 0;
    for(char c='a'; c <= 'z' ;++c){
      bool left = false, right=false;
      rep(j,i){
        if(s[j]==c) left=true;
      }
      for(int j = i; j<n ; ++j){
        if(s[j]==c) right=true;
      }
      if(left&&right) cnt++;
    }
    if(ans<cnt) ans=cnt;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 110;
int N;
int deg[MAX_N];
vector<int> A;
bool ok;

bool check() {
  for (int i = 0; i < MAX_N; i++) {
    if (deg[i] > 0) {
      return false;
    }
  }
  return true;
}
int main() {
  ok = true;
  cin >> N;
  A.resize(N);
  for (auto &val : A) {
    cin >> val;
    deg[val]++;
  }
  sort(A.rbegin(), A.rend());
  int max_val = A[0];
  int min_val = A[N - 1];
  if (max_val % 2) {
    int res = max_val;
    for (int i = 0; i <= max_val / 2; i++) {
      deg[res] -= 2;
      if (deg[res] < 0) {
        ok = false;
        goto END;
      }
      res--;
    }
    int left = max_val - ((max_val / 2) - 1);
    int right = max_val;
    for (int i = 0; i < MAX_N; i++){
      if (deg[i] > 0){
        if (not (left <= i and i <= right)){
          ok = false;
          goto END;
        }
        deg[i] = 0;
      }
    }
  } else {
    int res = max_val;
    for (int i = 0; i < max_val / 2; i++) {
      deg[res] -= 2;
      if (deg[res] < 0) {
        ok = false;
        goto END;
      }
      res--;
    }
    deg[res]--;

    int left = max_val - ((max_val / 2) - 1);
    int right = max_val;
    for (int i = 0; i < MAX_N; i++){
      if (deg[i] > 0){
        if (not (left <= i and i <= right)){
          ok = false;
          goto END;
        }
        deg[i] = 0;
      }
    }
  }
END:;
  ok &= check();
  if (ok){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  return 0;
}


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

int main()
{
    int n,m;
    cin >> n;
    int t[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> t[i];
        sum += t[i];
    }
    cin >> m;
    for(int i = 0; i < m; i++){
        int p,x;
        cin >> p >> x;
        cout << sum + x - t[p-1] << endl;
    }
}

Measured memory_bytes: 256
from math import *
def calcAngle(h,m):
         
        # validate the input
        if (h < 0 or m < 0 or h > 12 or m > 60):
            print('Wrong input')
         
        if (h == 12):
            h = 0
        if (m == 60):
            m = 0
            h += 1;
            if(h>12):
                   h = h-12;
         
        # Calculate the angles moved by 
        # hour and minute hands with 
        # reference to 12:00
        hour_angle = 0.5 * (h * 60 + m)
        minute_angle = 6 * m
         
        # Find the difference between two angles
        angle = abs(hour_angle - minute_angle)
         
        # Return the smaller angle of two 
        # possible angles
        angle = min(360 - angle, angle)
         
        return angle
a,b,h,m=[int(i) for i in input().split()]
theta=calcAngle(h,m)*pi/180
ans=(a**2+b**2-2*a*b*cos(theta))**(1/2)
print("{:.15f}".format(ans))


Measured memory_bytes: 9416