akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc177/tasks/abc177_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
const int MOD = 1e9 + 7;

// 参考
// https://atcoder.jp/contests/s8pc-1/submissions/15772604
template <int mod> struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using modint = ModInt<MOD>;

void solve() {
    int N;
    cin >> N;
    vector<modint> A(N);
    modint sum = 0;
    REP(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    modint ans = 0;
    REP(i, N - 1) { ans += A[i] * (sum -= A[i]); }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 4788
using System;
using System.Linq;

namespace ABC123_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var p = new long[5];
            p[0] = long.Parse(Console.ReadLine());
            p[1] = long.Parse(Console.ReadLine());
            p[2] = long.Parse(Console.ReadLine());
            p[3] = long.Parse(Console.ReadLine());
            p[4] = long.Parse(Console.ReadLine());

            long min = p.Min();
            long sum = 4;

            if (min < n)
            {
                sum += n % min == 0 ? n / min : 1 + n / min;
            }
            else
            {
                sum++;
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}
inline void read(int &x)
{
	x=0;
	int p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
const int N = 1e5 + 1e3;
int tag[N][31];
int Last = 0;
int main () {
	int n,c;
	read(n);read(c);
	for(int i=1;i<=n;i++)
	{
		int S,T,cn;
		read(S);read(T);read(cn);
		chkmax(Last, T);
		++tag[S][cn];
		--tag[T + 1][cn];
	}
	int res[31] = {0}, ans = 0;
	for(int i=1;i<=Last;i++)
	{
		int now = 0;
		for(int j=1;j<=c;j++)
		{
			res[j] += tag[i][j];
			if (res[j]) ++ now;
		}
		chkmax(ans, now);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12416
#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>;

const ll INF = ll(1e16)+1;

ll gcd(ll x,ll y){
    if(y>x){
       ll temp;
       temp = y;
       y = x;
       x = temp; 
    }
    ll z=1;
    while(z>=1){
        z = x%y;
        x = y;
        y = z;
    }
    return x;
}

ll lcm(ll x, ll y){
    ll z;
    z = gcd(x,y);
    return x*y/z;
}

int main(){
    int n; ll m;
    cin >> n >> m;
    vector<ll> a;
    bool flag = false;
    int num_2 = 0;
    rep(i,n){
        ll x;
        int temp = 0;
        cin >> x;
        x/=2;
        a.push_back(x);

        while(x>=2){
            if(x%2==0){
                temp++;
                x/=2;
            }
            else break;
        }
        if(i==0){
            num_2 = temp;
        }
        else{
            if(temp!=num_2) flag = true;
        }
        //cout << "i:" << i <<":" <<temp << endl;
    }
    
    ll LCM = 1;

    rep(i,n){
        LCM = lcm(LCM,a[i]);
        if(LCM>m) {
            flag = true;
            break;
        }
    }

    //cout << "lcm" << LCM << endl;

    if(flag){
        cout << 0 << endl;
        return 0;
    }
    
    if(m<LCM) cout << 0 << endl;
    else cout << ((m-LCM)/(LCM*2)) + 1 << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

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

const ll MOD=1000000007;
map<ll, ll> dp[2000][2];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    ll Z,W;
    cin>>N>>Z>>W;
    ll a[N];
    rep(i,0,N) cin>>a[i];
    cout << max((N>1?abs(a[N-2]-a[N-1]):0),abs(a[N-1]-W))<<"\n";
}

Measured memory_bytes: 512
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
# from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
K = INT()
 
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += gcd(gcd(i, j), k)
print(ans)

Measured memory_bytes: 10052
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;
int n;
string s;
unordered_map<string,ll> dic;
void solve(){
  int n2=n*2;
  char c[20]={};
  int cnt,l,r;
  for(int i=0;i<(1<<n);i++){
    cnt=__builtin_popcount(i);
    c[cnt]='_';
    l=0;r=cnt+1;
    REP(j,n){
      if(((1<<j)&i)==0)
	c[r++]=s[j];
      else
	c[l++]=s[j];
    }
    string str{c};
    //    cout<<str<<endl;
    if(dic.find(str)==dic.end())
      dic[str]=1;
    else
      dic[str]++;
  }
  ll result=0;
  for(int i=0;i<(1<<n);i++){
    cnt=__builtin_popcount(i);
    c[cnt]='_';
    l=0;r=cnt+1;
    REP(j,n){
      if(((1<<j)&i)==0)
	c[r++]=s[n2-j-1];
      else
	c[l++]=s[n2-j-1];
    }
    string str{c};
    //    cout<<str<<endl;
    result+=dic[str];
  }
  cout<<result<<endl;
}
int main(){ _;
  cin>>n;
  cin>>s;
  int a[26]={};
  int b[26]={};
  REP(i,n){
    a[s[i]-'a']++;
    b[s[i+n]-'a']++;
  }
  REP(i,26){
    if(a[i]!=b[i]){
      cout<<0<<endl;
      return 0;
    }
  }
  solve();
}


Measured memory_bytes: 69492
import sys
readline = sys.stdin.buffer.readline
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    N = int(readline())
    T = [0]*N
    for i in range(N):
        T[i] = int(readline())
    ans = lcm_list(T)
    print(ans)


if __name__ == '__main__':
    main()

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

int main(){
  int N,*A,i,flag,a,count=0;

  scanf("%d",&N);
  A=(int*)malloc(N*sizeof(int));
  for(i=0;i<N;i++)  scanf("%d",&A[i]);
  flag=1;
  while(flag){
    flag=0;
    for(i=N-1;i>0;i--){
      if(A[i]<A[i-1]){
	a=A[i];
	A[i]=A[i-1];
	A[i-1]=a;
	count++;
	flag=1;
      }
    }
  }
  printf("%d",A[0]);
  for(i=1;i<N;i++)printf(" %d",A[i]);
  printf("\n%d\n",count);
  free(A);
  return 0;
}

Measured memory_bytes: 600
N,A = map(int,input().split())
x = list(map(int,input().split()))

for i in range(N):
    x[i] -= A

dp = [0]*5000###-2500~2499,idx=2500が0に対応
dp[2500] = 1

for i in range(N):
    pre = dp[:]
    for j in range(max(0,-x[i]),min(4999,4999-x[i])):
        dp[j+x[i]] += pre[j]
    #print(pre[2490:2510])
    #print(dp[2490:2510])

#print(x)
print(dp[2500]-1)

Measured memory_bytes: 38896
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll A, B, C, K;
    cin >> A >> B >> C>> K;
    if(!cin) return;
    ll ans = A - B;
    if(K % 2){
        ans *= -1;
    }
    cout << ans << endl;

    
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll MOD = 1000000007LL;
ll dp[101][4][4][4];

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

  for(int j=0;j<4;j++){
    for(int k=0;k<4;k++){
      for(int l=0;l<4;l++){
        dp[3][j][k][l] = 1;
      }
    }
  }

  dp[3][0][2][1] = 0;
  dp[3][0][1][2] = 0;
  dp[3][2][0][1] = 0;

  for(int i=4;i<=N;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        for(int l=0;l<4;l++){
          for(int m=0;m<4;m++){
            if(j==0 && l==2 && m==1) continue;
            if(j==0 && k==2 && m==1) continue;
            if(j==0 && k==2 && l==1) continue;
            if(j==0 && k==1 && l==2) continue;
            if(j==2 && k==0 && l==1) continue;
            if(k==0 && l==2 && m==1) continue;
            if(k==0 && l==1 && m==2) continue;
            if(k==2 && l==0 && m==1) continue;

            dp[i][k][l][m] += dp[i-1][j][k][l];
            dp[i][k][l][m] %= MOD;
          }
        }
      }
    }
  }

  ll ans = 0LL;
  for(int j=0;j<4;j++){
    for(int k=0;k<4;k++){
      for(int l=0;l<4;l++){
        ans += dp[N][j][k][l];
      }
    }
  }

  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

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

const ll N=1e6;

ll A[N], B[N];
ll n, m, k;

bool check(ll x){
	ll acum=0;
	int deA=0, deB=0;
	For(i,0,min(n,x)){
		deA++;
		acum+=A[i];
	}
	while(deA+deB<x){
		acum+=B[deB];
		deB++;
	}
	if(acum<=k) return 1;
	while(deB<m && deA>0){
		deA--;
		acum-=A[deA];
		acum+=B[deB];
		deB++;
		if(acum<=k) return 1;
	}
	return 0;
}

int main(){
	fastio;
	cin>>n>>m>>k;
	For(i,0,n) cin>>A[i];
	For(i,0,m) cin>>B[i];
	ll lo = 0, hi = n+m+1;
	while(lo+1<hi){
		ll mid = (lo+hi)>>1;
		if(check(mid)) lo = mid;
		else hi=mid;
	}
	cout << lo << endl;
	return 0;
}



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

#define N 100

int main(void)
{
    int n, length[N];
    
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> length[i];
    }
    
    
    int cnt = 0;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            for (int k = j+1; k < n; k++){
                if ( length[i]==length[j] || length[j]==length[k] || length[k]==length[i] ){
                    continue;
                }
                if(length[i]+length[j]<=length[k] || length[j]+length[k]<=length[i] || length[k]+length[i]<=length[j] ){
                    continue;
                }
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define ll long long

constexpr ll MOD = 1000000007;
using namespace std;
vector<ll> fac, facInv, inv;
void facInit(int nmax)
{
    fac = facInv = inv = vector<ll>(nmax + 1, 1);
    for (int i = 2; i <= nmax; i++)
    {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        facInv[i] = facInv[i-1] * inv[i] % MOD;
    }
}
ll ncr(ll n, ll r) 
{
    if (n<r || r<0) return 0;
    if (n >= (int)fac.size()) facInit(n);
    return (fac[n] * facInv[r] % MOD) * facInv[n-r] % MOD;
}
int main() {
    ll x,y;
    cin >> x >> y;
    facInit(3e6);
    ll a = (x+y)/3;
    if (a * 3 != (x+y))
    {
        cout << "0";
    }
    else 
    {
        x -= a;
        y -= a;
        cout << ncr(a, x) << endl;
    }
    return 0;
}

Measured memory_bytes: 70528
n, k = map(int, input().split())

d = [0] * k
a = []
snuk = [False] * n
for i in range(k):
    d[i] = int(input())
    a = list(map(int, input().split()))
    for j in a:
        snuk[j - 1] = True
    

ans = 0
for i in range(n):
    if snuk[i] == False:
        ans += 1


print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// int dx[4]    = {1, 0, -1, 0};
// int dy[4]    = {0, 1, 0, -1};
// ll pas[5001][5002];

int main() {
	IOS();
	string s;
	cin >> s;
	int n = s.size();

	ll cnt[3] = {};
	for (int i = 0; i < n; ++i) { cnt[s[i] - 'a']++; }
	ll m = INF, M = 0;
	for (int i = 0; i < 3; ++i) {
		M = max(M, cnt[i]);
		m = min(m, cnt[i]);
	}

	dump(M - m <= 1 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)


struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<pair<ULL, UL>> V(N * 2);
		vector<pair<ULL, ULL>> V2(N);
		ULL ansL = 0, ansR = 0;
		rep(i, N) {
			cin >> V[i * 2].first >> V[i * 2 + 1].first;
			V2[i].first = V[i * 2].first;
			V2[i].second = V[i * 2 + 1].first;
			ansL += V[i * 2].first;
			ansR += V[i * 2 + 1].first;
		}
		rep(i, N) { V[i * 2].second = V[i * 2 + 1].second = i; }
		sort(V.begin(), V.end());
		vector<UL> F(N);
		ULL ans = 0;
		rep(i, N) {
			ans += V[i].first;
			F[V[i].second]++;
		}
		rep(i, N) if (V2[i].first > V2[i].second) swap(V2[i].first, V2[i].second);
		bool ok = false;
		rep(i, N) if (F[i] == 2) ok = true;
		if (!ok) {
			ULL tmp = 10000000000;
			sort(V2.begin(), V2.end());
			rep(i, N - 1) {
				tmp = min(tmp, V2[i].second - V2[N - 1].first);
			}
			tmp = min(tmp, V2[N - 1].second - V2[N - 2].first);
			ans += tmp;
		}
		ans = min(ans, min(ansL, ansR));
		cout << ans << endl;
	}
	
	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 5376
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)
ans=0

n=int(input())
a=[]
b=[]
c=0
for i in input().split():
    x=int(i)
    if x<0:
        c+=1
    a.append(x)
    b.append(abs(x))

b.sort()
ans=sum(b[1:])
if c%2==1:
    ans+=-b[0]
else:
    ans+=b[0]
print(ans)

Measured memory_bytes: 19020
N = int(input())
S = list(input())

sum_W = [0]
for i in range(1, N):
    if S[i-1] == "W":
        sum_W.append(sum_W[i-1]+1)
    else:
        sum_W.append(sum_W[i-1])

sum_E = [S[1:].count("E")]
for i in range(0, N-1):
    if S[i+1] == "E":
        sum_E.append(sum_E[i]-1)
    else:
        sum_E.append(sum_E[i])

counts = []
for i in range(N):
    count = 0
    counts.append(sum_W[i]+sum_E[i])

print(min(counts))

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

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 2e5 + 9, M = 50 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(12);
//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

vector<vector<int>> edges(N);
int n, q, x, y;
ll counter[N];
bool vis[N];

int main() {
	OUTPUT();
//	INPUT();
	cin >> n >> q;
	for (int i = 1; i < n; ++i) {
		cin >> x >> y;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	for (int i = 0; i < q; ++i) {
		cin >> x >> y;
		counter[x] += y;
	}
	queue<int> path;
	path.push(1);
	while (!path.empty()) {
		int cur = path.front();
		path.pop();
		vis[cur] = 1;
		for (auto child : edges[cur]) {
			if (!vis[child]) {
				counter[child] += counter[cur];
				path.push(child);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << counter[i] << " ";
	}

	return 0;

}


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

using namespace std;

#define EPS (1e-8)
#define INF 101010

struct Point {
    double x, y;
    
    Point () {}
    Point (double x, double y) : x(x), y(y) {}

    Point operator - (const Point &p) const {
        return Point(x - p.x, y - p.y);
    }
};

double cross(const Point &a, const Point &b)
{
    return a.x * b.y - a.y * b.x;
}

int ccw(const Point &p0, const Point &p1, const Point &p2)
{
    Point a = p1 - p0, b = p2 - p0;
    if (cross(a, b) > EPS)  return -1; // COUNTER CLOCK WISE
    return +0;
}

#define next(G,i) (G[(i+1)%G.size()])

double get_area(double l, double r, int W)
{
    vector<Point> pg(4);
    pg[0] = Point(0, 0);
    pg[1] = Point(W, 0);
    pg[2] = Point(W, r);
    pg[3] = Point(0, l);
    
    double res = 0;
    for (int i = 0; i < (int)pg.size(); i++) {
	res += cross(pg[i], next(pg, i));
    }
    return abs(res)/2.0;
}


int main()
{
    int N, M, W, H, S;
    while (cin >> N >> M >> W >> H >> S, N) {
        vector<double> l(M+1), r(M+1);
        l[0] = r[0] = 0;
        
        vector<int> s(M+1, 0);
        for (int i = 1; i <= M; i++) {
            scanf("%lf %lf", &l[i], &r[i]);
            s[i] = get_area(l[i], r[i], W);
        }        

        vector<int> choco(M+1, 0);
        
        Point p;
        for (int i = 0; i < N; i++) {
            scanf("%lf %lf", &p.x, &p.y);
            int lb = 0, ub = M+1;
            while (ub - lb > 1) {
                int mid = (lb + ub) / 2;
                if (ccw(Point(0, l[mid]), Point(W, r[mid]), p) == -1) {
                    lb = mid;
                } else {
                    ub = mid;
                }
            }
            choco[ub]++;
        }

        for (int i = 1; i <= M; i++) {
            choco[i] += choco[i-1];
        }
        int res = INF;
        for (int i = 0; i <= M; i++) {
            int lb = i, ub = M+1;
            int ns = s[i];
            while (ub - lb > 1) {
                int mid = (lb + ub) / 2;
                if (ns + (s[M] - s[mid]) < S) {
                    ub = mid;
                } else {
                    lb = mid;
                }
            }

            if (ns + (s[M] - s[lb]) >= S) {
                res = min(res, choco[M] - (choco[lb] - choco[i]));
            }
        }
        cout << res << endl;
    }        
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
int main()
{
    ft
    ll t,i,j,n,m,l=1ll,r;
    ll rr=1e9+7;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        l=(l*i)%rr;
    }
    cout<<l<<"\n";
    return 0;
}

Measured memory_bytes: 256
//##MohK
//18/02/2020 .... 8,12.
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
using ld = long double;
int main(){
    ll a,k,sum=0;
    cin>>a>>k;
    ll x[a];
    for(ll i=0;i<a;i++){
        cin>>x[i];
    }
    sort(x,x+a);
    reverse(x,x+a);
    for(ll i=0;i<k;i++){
        sum+=x[i];
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 500100
using namespace std;
char s[maxn];
int nxt[maxn][27],f[20][maxn],n,q;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=0;i<=26;++i)nxt[n+1][i]=n+2,nxt[n+2][i]=n+2;
	for(int i=0;i<=18;++i)f[i][n+2]=n+2,f[i][n+1]=n+2;
	for(int i=n;i>=1;--i){
		nxt[i][s[i]-'a']=i+1;
		for(int j=s[i]-'a'+1;j<=26;++j)
			nxt[i][j]=nxt[nxt[i][j-1]][j-1];
	//	printf("[%d]",nxt[i][26]);
		for(int j=s[i]-'a'-1;j>=0;--j)
			nxt[i][j]=nxt[nxt[i][26]][j];
	}
	for(int i=1;i<=n;++i)
		f[0][i]=nxt[i][26];
	for(int i=1;i<=18;i++)
		for(int j=1;j<=n;++j)
			f[i][j]=f[i-1][f[i-1][j]];
	scanf("%d",&q);
	for(int i=1,l,r;i<=q;++i){
		scanf("%d%d",&l,&r);
		for(int i=18;i>=0;--i)
			if(f[i][l]-1<=r)l=f[i][l];
	//	printf("[%d]",l);
		if(l-1==r)printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 92928
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int a[333333];
int S[333333];
int sum;

void out(int diff)
{
	cout<<(sum+diff)/2<<' '<<(sum-diff)/2<<'\n'; exit(0);
}

int getS(int l, int r)
{
	if(l==0) return S[r];
	else return S[r]-S[l-1];
}

int dp[333333];

int cost(int i, int j)
{
	return max((j>=2?dp[j-2]:-int(1e9)), getS(j, i));
}

set<ii> SS; 

void add(ii x)
{
	auto it = SS.lower_bound(x);
	if(it!=SS.begin())
	{
		it--; 
		if(it->se<=x.se) return ;
		it++;
	}
	while(it!=SS.end()&&it->se>=x.se) 
	{
		it=SS.erase(it);
	}
	SS.insert(x);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]; sum+=a[i];
		if(i%2==0) a[i]*=-1;
		S[i]=a[i]+(i>0?S[i-1]:0);
	}
	if(n%2==0) out(abs(S[n-1]));
	dp[0] = min(0, getS(0,0));
	int shift = a[0]; add(mp(-int(1e9), 0));
	for(int i=2;i<n;i+=2)
	{
		shift+=a[i-1]+a[i];
		add(mp(dp[i-2], a[i]-shift));
		int lo = -int(1e9); int hi = int(1e9);
		while(lo<=hi)
		{
			int mid=(lo+hi)>>1;
			//is mid reachable
			//check the largest pair with (<= mid, ?)
			//cerr<<"LO HI : "<<lo<<' '<<hi<<'\n';
			auto it = SS.upper_bound(mp(mid+1,-int(1e9)));
			//cerr<<"LARGE : "<<it->fi<<' '<<it->se<<'\n';
			bool pos=1;
			if(it==SS.begin()) pos=0;
			else
			{
				it--;
				//cerr<<"IT "<<it->fi<<' '<<it->se<<'\n';
				if(it->se+shift>mid) pos=0;
			}
			if(pos)
			{
				dp[i]=mid; hi=mid-1;
			}
			else
			{
				lo=mid+1;
			}
		}
		//cerr<<i<<' '<<dp[i]<<'\n';
	}
	out(S[n-1]-2*dp[n-1]);
}


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

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

const int MAXN=5000;

char s[MAXN+1]; int n;
int k;

string z[MAXN];
int lcp(const string &a,const string &b) { int ret=0; while(ret<SZ(a)&&ret<SZ(b)&&a[ret]==b[ret]) ++ret; return ret; }

void run() {
	scanf("%s",s); n=strlen(s); scanf("%d",&k); --k;
	//n=MAXN; REP(i,n) s[i]='a'; s[n]='\0';

	REP(i,n) z[i]=string(s+i);
	sort(z,z+n);
	REP(i,n) {
		int common=i==0?0:lcp(z[i-1],z[i]);
		int cnt=SZ(z[i])-common;
		if(k>=cnt) { k-=cnt; continue; }
		int len=common+k+1; printf("%.*s\n",len,z[i].c_str()); return;
	}
	assert(false);
}

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


Measured memory_bytes: 16128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n; cin >> n; int a[123456]; for (int i = 0; i < n; i++)cin >> a[i];
	int ans = 0;
	for (int i = 2; i < n; i++) {
		if (a[i - 2] < a[i - 1] && a[i - 1] < a[i])ans++;
		else if (a[i - 2] > a[i - 1] && a[i - 1] > a[i])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MOD 1000000007

void input();
void calc();
	long long llModPow(long long x, int y, int d);
	long long llMod_xCy(long long x, int y, int d);
		long long llModDivison(long long x, long long y, int d);
void output();

long long n, ans;
int a, b;

int main() {
	input();
	calc();
	output();
	return 0;
}

void input() {
	scanf("%lld %d %d", &n, &a, &b);
	return;
}

void calc() {
	ans = llModPow(2, n, MOD) - 1;
	ans -= (llMod_xCy(n, a, MOD) + llMod_xCy(n, b, MOD));
	ans %= MOD;
	while (ans < 0)
		ans += MOD;
	return;
}

long long llModPow(long long x, int y, int d) {
	long long llRet;
	if (y == 1)
		llRet = x % d;
	else if (y % 2 == 1)
		llRet = x * llModPow(x, y - 1, d) % d;
	else {
		long long tmp = llModPow(x, y / 2, d);
		llRet = (tmp * tmp) % d;
	}
	return llRet;
}

long long llMod_xCy(long long x, int y, int d) {
	long long llRet = 1;
	if (y > x - y)
		y = x - y;
	for (int i = 0; i < y; i++) {
		llRet *= (x - i);
		llRet %= d;
		llRet = llModDivison(llRet, (long long)i + 1, d);
	}
	return llRet;
}

long long llModDivison(long long x, long long y, int d) {
	long long llRet;
	llRet = x * llModPow(y, d - 2, d) % d;
	return llRet;
}

void output() {
	printf("%lld\n", ans);
	return;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

template< typename T >
using Matrix = vector< vector< T > >;


void solve(void)
{
  int N;
  cin>>N;
  Matrix<int> MAT(N,vector<int>(N,INF));
  Matrix<int> D(N,vector<int>(N,0));
  int SUM = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cin>>MAT[i][j];
    }
    
  }
  for (int k = 0; k < N; k++)
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      {
        // if(i == j)continue;
        if(MAT[i][j] > MAT[i][k] + MAT[k][j])
        {
          cout<<-1<<endl;
          return;
        }
        if(MAT[i][j] == MAT[i][k] + MAT[k][j] && MAT[i][k] > 0 && MAT[k][j] > 0)
        D[i][j] = 1;
      }
      
    }
    
  }
  int ANS = 0;
  // DEBUG(D);
  for (int i = 0; i < N; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      if(D[i][j] ==0)ANS += MAT[i][j];
    }
    
  }
  cout<<ANS<<endl;
  
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

#define int long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second


signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int k;
    cin >> k;
    int ans = 0;
    for(int i = 1; i <= k; ++i){
        for(int j = 1;j <= k; ++j){
            for(int z = 1;z <= k; ++z){
                int g = __gcd(i,j);
                g = __gcd(g,z);
                ans += g;
            }
        }
    }
    cout << ans;
}		

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
typedef long long ll;
typedef long double ld;

int main() {
    char c;
    cin >> c;
    c++;
    cout << c << endl;
}


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

int main()
{
  string s;
  cin >> s;
  if(s.at(5)=='0' && s.at(6) <= '4')
  {
    cout << "Heisei" << endl;
  }
  else
  {
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
//2018.12.29 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline int read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline int _abs(const res &x){
    return x>0?x:-x;
}
inline int _max(const res &x,const res &y){
    return x>y?x:y;
}
inline int _min(const res &x,const res &y){
    return x<y?x:y;
}
namespace MAIN{
    int A,B,C;
    inline void MAIN(){
        A=read(),B=read(),C=read();
        if(C-1<=A+B)printf("%d\n",B+C);
        else printf("%d\n",A+B+B+1);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(){
    
    int x,n;
    cin>>x>>n;
    int p[n];
    int ans=x;
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int min=1000;
    for(int i=-100;i<=200;i++){
        
        int tmp=0;
        int f=1;
         for(int j=0;j<n;j++){
            if(i==p[j]){
                f=-1;
                break;
            }
         }
         if(f==1){
             if(i>=0){
                tmp=abs(x-i);
             }else{
                tmp=x+(-1*i);
             }
            if(min>tmp){
                min=tmp;
                ans=i;
            }
         }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

template<class T> inline int sgn(T n) { if (n > 0) return 1; else if (n < 0) return -1; else return 0; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  ll x;
  cin >> x;

  ll ans;
  if (x%11==0) {
    ans = x/11*2;
  }
  else if (x%11 <= 6) {
    ans = x/11*2 + 1;
  }
  else {
    ans = x/11*2 + 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using static Prog;
using NX = System.Int64;

public class Solver
{
    public void Solve()
    {
        string s = NextString();
        Console.WriteLine((s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No");
    }
}

public class Prog
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    public struct Pair { public int x, y; public Pair(int a, int b) { x = a; y = b; } }
    static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Solver().Solve();
        Console.Out.Flush();
        return;
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 26268
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  string S;
  cin >>N>>S;
  int count=0;
  vector<int> vec(N-1);
  rep(i,N-1) {
    bool hidari=false;
    bool migi=false;
    int countingh=0;
    int countingm=0;
    
    for(char p='a'; p<='z'; p++) {
    //左
         repl(k,0,i+1) {
    
          if(S.at(k)==p) {
          countingh++;
           // cout<<countingh<<endl;
          }
          }
      //右
            repl(l,i+1,N) {
    
           if(S.at(l)==p) {
           countingm++;
            // cout<<countingm<<endl;
           }
           }
      
            if(countingh>0) {
             hidari=true;
             countingh=0;
             } 
             if(countingm>0) {
             migi=true;
              countingm=0;
               }
         if(hidari&&migi) {
        count++;
        }
    hidari=false;
      migi=false;
    }
    //for 終わり
    
    vec.at(i)=count;
   // cout<<vec.at(i)<<endl;
    count=0;
    
  }
 sort(all(vec));
  cout<<vec.at(N-2)<<endl;
}
    
   
    
    
  
  

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;

int calc(vii& dp, const vector<pair<int, int>>& M, int i, int j) {
    if (i == j) { return 0; }
    if (dp[i][j] != 0) { return dp[i][j]; }

    int mul = M[i].first * M[j].second;
    int tmp = calc(dp, M, i + 1, j) + mul * M[i].second;
    rep(k, i + 1, j) {
        tmp = min(tmp, calc(dp, M, i, k) + calc(dp, M, k + 1, j) + mul * M[k].second);
    }
    return dp[i][j] = tmp;
}

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

    int n;
    cin >> n;

    vector<pair<int, int>> M(n);

    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        M[i] = make_pair(x, y);
    }

    vii dp(n, vi(n, 0));

    cout << calc(dp, M, 0, n - 1) << endl;

    return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
using ll = long long;


int main(void)
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10));
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin >> c[i][j];
        }
    }
    vector<vector<int>> A(H, vector<int>(W));

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> A[i][j];
        }
    }
    
    for (int k = 0; k < 10; k++)
    {
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                if(c[i][j] > c[i][k] + c[k][j]){
                    c[i][j] = c[i][k] + c[k][j];
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if(A[i][j] == -1) continue;
            ans += c[A[i][j]][1];
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a,b;
    long long int ans=0;
    cin>>n>>a>>b;
    /*if (n<a+b) {
        ans=a;
    } else if (n>=a+b) {*/
        ans+=a*(n/(a+b));
        if (n%(a+b)!=0) {
            n=n-(a+b)*(n/(a+b));
            if (n<=a) {
                ans+=n;
            } else {
                ans+=a;
            }
        }
    //}
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
use proconio::input;
use std::collections::HashSet;

fn main() {
    input! {
        N: usize,
        Ss: [String; N],
    }

    let mut set = HashSet::new();
    for s in Ss.iter() {
        set.insert(s);
    }

    let ans = set.len();
    println!("{}", ans);
}


Measured memory_bytes: 18468
def solve(n, s):
    D = {"R": 0, "G": 0, "B": 0}
    for c in s:
        D[c] += 1
    ans = D["R"] * D["G"] * D["B"]
    for i in range(n):
        for j in range(i+1,(i+n+1)//2):
            k = 2*j - i
            if (s[i] != s[j]) and (s[j] != s[k]) and (s[k] != s[i]):
                ans -= 1
    return ans

n = int(input())
s = input()
print(solve(n, s))


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

int main()
{
    int n,k;
    cin >> n >> k;
    while(n !=0 && k !=0){
        int a;
        int s[100010];
        s[0]=0;
        for(int i=0;i<n;i++){
            cin >> a;
            s[i+1]=s[i]+a;
        }
        int m=0;
        for(int i=0;i<n-k;i++){ 
            if(m < s[i+k]-s[i]){
                m = s[i+k]-s[i];
            }
        }
        cout << m << endl;
        cin >> n >> k;
    }
}



Measured memory_bytes: 3388
# -*- coding: utf-8 -*-


def main():
    w, h, x, y = map(int, input().split())
    s = w * h / 2

    if h == 2 * y and w == 2 * x:
        print(s, 1)
    else:
        print(s, 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
w,h,n = map(int,input().split())
A = [tuple(map(int,input().split())) for _ in range(n)]
l = 0
r = w
d = 0
u  =h
for x,y,a in A:
    if a==1:
        l = max(x,l)
    elif a ==2:
        r = min(r,x)
    elif a ==3:
        d = max(y,d)
    else:
        u = min(y,u)
if u-d<0 or r-l<0:
    print(0)
else:
    print((u-d)*(r-l))

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

using namespace std;

const long long INF = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<long long>> g(n, vector<long long>(n, INF));
  for (int i = 0; i < n; i++) {
    g[i][i] = 0ll;
  }
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u][v] = (long long) w;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      } 
    }
  }
  for (int i = 0; i < n; i++) {
    if (g[i][i] < 0) {
      return cout << "NEGATIVE CYCLE" << '\n', 0;
    }
  }
  for (auto& v : g) {
    for (int i = 0; i < (int) v.size(); i++) {
      if (i > 0) {
        cout << ' ';
      }
      if (v[i] > 1e10) {
        cout << "INF";
      } else {
        cout << v[i];
      }
    }
    cout << '\n';
  }
  return 0;
}



Measured memory_bytes: 3316
#k=int(input())
n,m,x=map(int,input().split())
#pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
al=[]
cl=[]
for i in range(n):
    l=list(map(int,input().split()))
    cl.append(l[0])
    al.append(l[1:])

price_list=[]
#bit全探索
for i in range(2**n):
    b=bin(i)
    score=[0 for k in range(m)]
    price=0

    for j in range(n):
        if ((i >> j) & 1):#二進数iの下から数えてj桁目が1か否か
            a=al[j]
            price+=cl[j]
            for k in range(m):
                score[k]+=a[k]
    if min(score)>=x:
        price_list.append(price)

if len(price_list)==0:
    print(-1)
else:
    print(min(price_list))




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

#define ll long long
using namespace std;


int gcd(int a, int b)
{
	if(b==0)
		return a;
	return gcd(b, (a%b));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	int n, m;
	cin>>n>>m;
	cin>>s>>t;
	//cerr<<n<<" "<<m<<endl;
	int g = gcd(n,m);
	
	int n1 = n/g;
	int m1 = m/g;
	for(int i=0; i<g; ++i)
	{

		if(s[n1*i]!=t[m1*i])
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	//cerr<<n<<" "<<m1<<endl;
	cout<<(ll)n*(ll)m1<<endl;

		
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define fi  first
#define se second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dub(x) cerr<<#x<<" : "<<(x)<<"\n";
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define forn(i,n) for(int i = 0;i <(int)(n);++i)
#define fora(i,a,b) for(int i = (int)(a); i<=(int) (b); ++i)
const int mod = 1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n&1)
        cout<<"No\n";
    else
    {
        string fhl = s.substr(0,n/2);
        string sec = s.substr(n/2,n/2);
        if(fhl==sec)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
}

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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;
#define END cout << endl;

int main() {
  int n,k; cin >> n >> k;
  vector<ll> a(n);
  vector<ll> sum(n+1), b(n+1);
  sum[0] = b[0] = 0;
  rep(i,n) {
    cin >> a[i];
    sum[i+1] = a[i] + sum[i];
    b[i+1] = max<ll>(0,a[i]) + b[i];
  }
  ll ans = -10e12;
  for (int i = 0; i <= n - k; ++i) {
    int left = i+1, right = i + k;
    ll mmax, tmp_sum = sum[right] - sum[left-1];
    mmax = (max<ll>(tmp_sum,0) > 0) ? tmp_sum : 0;
    mmax += (b[n] - b[right]) + (b[left-1] - b[0]);
    ans = max(ans, mmax);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
using System;
using System.Linq;
class Program{
    static void Main(){
        int[] ab = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int a = ab[0], b = ab[1];
        if (a > 0)
            Console.WriteLine("Positive");
        else if (a <= 0 && b >= 0)
            Console.WriteLine("Zero");
        else if ((b - a + 1) % 2 != 0)
            Console.WriteLine("Negative");
        else
            Console.WriteLine("Positive");
    }
}

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

int main(){
  ll N;
  string X;
  cin >> N >> X;
  ll ans = 0;
  ll mod=0, tm = 0, tp=0;
  for(ll i=N-1;i>=0;--i) {
    if (X[i] == '1') mod++;
  }
  for(ll i=0; i<N; ++i) {
    tp = (tp * 2) % (mod+1);
    if (X[i] == '1') {
      tp = (tp + 1) % (mod+1);
    }
  }
  if ( mod == 1 ) {
    tm = 0;
  } else {
    for(ll i=0; i<N; ++i) {
      tm = (tm * 2) % (mod-1);
      if (X[i] == '1') tm = (tm + 1) % (mod-1);
    }
  }
//  cout << "mod-1 : " << tm << " ,  mod : " << t << " ,  mod+1 : " << tp << endl;
  vector<ll> pm2(N+1,0), pp2(N+1);
  pp2[0] = 1;
  pm2[0] = 1;
  for( int i=1;i<N+1; ++i ) {
    pp2[i] = (pp2[i-1] * 2) % (mod+1);
  }
  if ( mod != 1 ) {
    for( int i=1;i<N+1; ++i )
      pm2[i] = (pm2[i-1] * 2) % (mod-1);
  }
  for( int i=0; i<N; i++ ) {
    ll subt;
    ans = 1;
    if ( X[i] == '1' ) {
      if ( mod == 1 ) subt = 0, ans = 0;
      else {
        subt = tm - pm2[N-1-i];
//        cout << "i: " << i << ", " << subt << " " << pm2[N-1-i] << endl;
      }
      if ( subt < 0 ) subt += (mod-1);
    } else {
      subt = (tp + pp2[N-1-i]) % (mod+1);
    }
    while (subt != 0) {
      ll a = subt;
      ll pc = 0;
      while (a > 0) {
        pc += (a%2);
        a /= 2;
      }
      subt %= pc;
      ans++;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 6828