akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);
            int C = int.Parse(s[2]);

            int m = Math.Max(A, Math.Max(B, C));

            int ans = 0;
            ans += (m - A);
            ans += (m - B);
            ans += (m - C);

            if (ans % 2 == 0)
            {
                ans /= 2;
            }
            else
            {
                ans /= 2;
                ans += 2;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
string n,st;
int sum;
int main()
{
	cin>>n;
	st="CODEFESTIVAL2016";
	for(int i=0;i<=15;i++)
	    if(st[i]!=n[i]) sum++;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//
// g++ -std=c++14 main.cpp
//

//#include "main.hpp"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    string s;
    cin >> s;
    
    ll abc[100010], a[100010], ab[100010], inf = 1e9 + 7, q = 1;
    abc[0] = ab[0] = a[0] = 0;
    
    for (int i = 0; i < s.size(); i++) {
        a[i + 1] = a[i];
        ab[i + 1] = ab[i];
        abc[i + 1] = abc[i];
        if (char(s[i]) == 'A') a[i + 1] = a[i] + q;
        if (char(s[i]) == 'B') ab[i + 1] = ab[i] + a[i];
        if (char(s[i]) == 'C') abc[i + 1] = abc[i] + ab[i];
        if (char(s[i]) == '?') {
            a[i + 1] = 3 * a[i] + q;
            ab[i + 1] = 3 * ab[i] + a[i];
            abc[i + 1] = 3 * abc[i] + ab[i];
            q = (3 * q) % inf;
        }
        a[i + 1] %= inf;
        ab[i + 1] %= inf;
        abc[i + 1] %= inf;
    }
    
    cout << abc[s.size()] << endl;
    
    //for (int i = 0; i <= s.size(); i++) cout << a[i] << " " << ab[i] << " " << abc[i] << endl;
    
    /*int cnt = 0;
    for (int i = 0; i < pow(3, 4); i++) {
        int ic = i;
        for (int j = 0; j < 4; j++) {
            if (ic % 3 == 0) cnt++;
            ic /= 3;
        }
    }
    cout << cnt << endl;*/
}

/*
g++ -std=c++14 main.cpp
*/


Measured memory_bytes: 2816
#include <bits/stdc++.h>
//Fast io
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//Class shorthands
#define ll long long
#define db long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
//Function Shorthands
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define po pop_back
#define eb emplace_back
//Code Shorthands
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
//Constants
#define hell 1000000007
#define PI acos(-1.0)
using namespace std;

void solve(){
	int h,w,m;
	cin>>h>>w>>m;
	set<pii> s;
	map<int, int> m1, m2;
	rep(i,0,m){
		int t1, t2;
		cin>>t1>>t2;
		s.insert({t1,t2});
		m1[t1]++;
		m2[t2]++;
	}
	vii v1,v2;
	for(auto i:m1){
		v1.pb({i.se, i.fi});
	}
	for(auto i:m2) v2.pb({i.se, i.fi});
	sort(all(v1));
	reverse(all(v1));
	sort(all(v2));
	reverse(all(v2));
	int ans = -1;
	for(int i=0;i<v1.size();i++){
		for(int j=0;j<v2.size();j++){
			int cur = v1[i].fi+v2[j].fi;
			if(cur<=ans) break;
			if(s.find({v1[i].se, v2[j].se})!=s.end()) cur--;
			ans = max(ans, cur);
		}
	}
	cout<<ans<<endl;
}

int main(){
	io;
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 53776
using System;

class Program{
    class Pair{
        public double x;
        public double y;
        public Pair(double x, double y){
            this.x=x;
            this.y=y;
        }
    }

    static void koch(int n, Pair p1, Pair p2){
        if(n>0){
            var s=new Pair(2.0/3*p1.x+1.0/3*p2.x, 2.0/3*p1.y+1.0/3*p2.y);
            var t=new Pair(1.0/3*p1.x+2.0/3*p2.x, 1.0/3*p1.y+2.0/3*p2.y);
            var st=new Pair(t.x-s.x, t.y-s.y);
            var u=new Pair(1.0/2*st.x-Math.Sqrt(3)/2*st.y+s.x,
                    Math.Sqrt(3)/2*st.x+1.0/2*st.y+s.y);
            koch(n-1, p1, s);
            Console.WriteLine(s.x+" "+s.y);
            koch(n-1, s, u);
            Console.WriteLine(u.x+" "+u.y);
            koch(n-1, u, t);
            Console.WriteLine(t.x+" "+t.y);
            koch(n-1, t, p2);
        }
    }

    public static void Main(){
        var n=int.Parse(Console.ReadLine());
        var p1=new Pair(0, 0);
        var p2=new Pair(100, 0);
        Console.WriteLine(p1.x+" "+p1.y);
        koch(n, p1, p2);
        Console.WriteLine(p2.x+" "+p2.y);
    }
}

Measured memory_bytes: 9316
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string iti,ni,san,si,go,ro,mo,to;
    cin>>mo>>to;
    iti=mo[0];
    ni=mo[1];
    san=mo[2];
    si=to[0];
    go=to[1];
    ro=to[2];
    if(iti==ro&&ni==go&&san==si){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i = 0, j = n - 1;
    int ans = 0;
    while(i < j){
        while(i < j && s[i] == 'R'){
            i++;
        }
        while(i < j && s[j] == 'W'){
            j--;
        }
        if(i < j){
            ans++;
            i++,j--;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    string s[n], t[m];
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> t[i];
    }
    int cnt = 0;
    for (int i = 0; i <= n - m; i++)
    {
        for (int j = 0; j <= n - m; j++)
        {
            for (int tx = 0; tx < m; tx++)
            {
                for (int ty = 0; ty < m; ty++)
                {
                    if (s[i][j] == t[tx][ty])
                    {
                        cnt = 0;
                        for (int k = i; k < i + m; k++)
                        {
                            for (int z = j; z < j + m; z++)
                            {
                                if (s[k][z] == t[k - i][z - j])
                                {
                                    cnt++;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        if (cnt == m * m)
                        {
                            cout << "Yes\n";
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<climits>
#include<set>
#define ll long long
using namespace std;
int main() {
	ll n;
	cin >> n;
	vector<string>s(n);
	vector<ll>p(n);
	vector<ll>a(n);
	for (ll i = 0; i < n; i++) {
		cin >>s[i]>>p[i];
		a[i] = i+1;
	}
	for (ll i = 0; i < n; i++) {
		for (ll j = i+1; j < n; j++) {
			if (s[i] > s[j]) {
				swap(p[i], p[j]);
				swap(a[i], a[j]);
				swap(s[i], s[j]);
			}
			else if (s[i] == s[j]&&p[i]<p[j]) {
				swap(p[i], p[j]);
				swap(a[i], a[j]);
				swap(s[i], s[j]);
			}
		}
	}

	for (ll i = 0; i < n; i++) {
		cout << a[i] << endl;
	}





}




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

int s;

void com(int c,int p[100],int a,int b){
	if(c==a){
		int m = 0;
		for(int i=1;i<=a;i++) m += p[i];
		if(b==m) s++;
	}
	else{
		for(int i=p[c]+1;i<=min(9,b-p[c]);i++){
			p[c+1] = i;
			com(c+1,p,a,b);
		}
	}
}

int main(){
	int a,b;
	while(1){
		cin >> a >> b;
		if(a+b==0) break;
		s = 0;
		int p[100];
		p[0] = -1;
		com(0,p,a,b);
		cout << s << endl;
	}
}

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

int main() {
  vector<int> a(3);
  for (auto &i : a) cin >> i;
  sort(a.begin(), a.end());
  if (a[0] != a[1])
    cout << a[0] << endl;
  else
    cout << a[2] << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

func sortDecrease(ar []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(ar)))
	return ar
}

func maxes(ints []int) []int {
	result := make([]int, len(ints))
	sorted := sortDecrease(append([]int{}, ints...))

	first := sorted[0]
	second := sorted[1]

	for i, v := range ints {
		if v == first {
			result[i] = second
		} else {
			result[i] = first
		}
	}
	return result
}

func main() {
	n := nextInt()
	ar := nextInts(n)
	results := maxes(ar)
	for _, v := range results {
		fmt.Println(v)
	}
}


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

int field[50][50];
const int dx[] = { -1,-1,-1,0,0,1,1,1 };
const int dy[] = { -1,0,1,-1,1,-1,0,1 };

int w, h;

void crawler(int y, int x) {
	field[y][x] = 0;
	for (int i = 0; i < 8; i++) {
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (nx < 0 || ny < 0 || w <= nx || h <= ny)continue;
		if (field[ny][nx] == 1)crawler(ny, nx);
	}
}

int main() {
	while (cin >> w >> h, w | h) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> field[i][j];
			}
		}
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (field[i][j] == 1) {
					crawler(i, j);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1236
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#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 <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//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 unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

LL s[100005];
int v[100005];

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n)scanf("%lld", &s[i]);
	LL ret = 0;
	for (int d = 1; d < n - 1; d++) {
		LL tmp = 0;
		for (int l = 0, r = n - 1; l < n-1 && d<r && l!= r&& v[l] != d && v[r] != d; l += d, r-=d) {
			tmp += s[l]+s[r];
			v[l] = v[r] = d;
			ret = max(ret, tmp);
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); 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; }

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

int main(){
    int h, w, ans = 0;
    cin >> h >> w;
    vector<vector<char> > s(w, vector<char>(h));
    rep(y, h) {
        rep(x, w) {
            cin >> s[x][y];
        }
    }
    rep(y, h) {
        rep(x, w) {
            if(s[x][y] == '#') continue;
            map<pair<int, int>, int> dp;
            queue<pair<int, int> > que;
            que.push(make_pair(x, y));
            dp[make_pair(x, y)] = 0;
            while(que.size()) {
                pair<int, int> p = que.front();
                que.pop();
                rep(i, 4) {
                    int nx = p.first + dx[i];
                    int ny = p.second + dy[i];
                    pair<int, int> n = make_pair(nx, ny);
                    if(nx >= 0 && nx < w && 0 <= ny && ny < h && dp.count(n) == 0 && s[nx][ny] == '.') {
                        que.push(n);
                        dp[n] = dp[p] + 1;
                        chmax(ans, dp[n]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3

MOD = 2  # type: int
import itertools


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N, M = list(map(int,input().split()))

    K = []
    S = []
    for i in range(M):
        l = list(map(int,input().split()))
        K.append(l[0])
        S.append(l[1:])

    P = list(map(int,input().split()))

    swl = list(itertools.product([1,0],repeat=N))
    
    ok_cnt = 0
    for sw in swl:
        bOK = True
        for i,s in enumerate(S):
            on_cnt = 0
            for ss in s:
                if sw[ss-1]:
                    on_cnt += 1

            if (on_cnt % 2) != P[i]:
                bOK = False
                break
        if bOK:
            ok_cnt+=1

    print(ok_cnt)


    pass

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll D;
  cin >> D;
  vector<ll> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<ll>> s(D,vector<ll>(26));
  rep(i,D)
  {
    rep(j,26)
    {
      cin >> s[i][j];
    }
  }
  vector<int> t(D);
  rep(i,D)
  {
    ll M = 0;
    ll m = 0;
    rep(j,26)
    {
      M = max(M,s[i][j]);
      if(M!=m)
      {
        t[i] = j;
      }
      m = M;
    } 
  }
  vector<int> lastday(26);
  rep(i,26) lastday[i] = -1;
  ll satisfy = 0;
  rep(i,D)
  {
    ll dissatisfy = 0;
    satisfy += s[i][t[i]];
    lastday[t[i]] = i;
    rep(j,26)
    {
      dissatisfy += c[j] * (i-lastday[j]);
    }
    satisfy -= dissatisfy;
    cout << i%26 + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define long long long
using namespace std;
int n,arr[10002],ans,cnt;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin>>n;
  for(int i=1;i<=n;i++)
    cin>>arr[i];
  arr[++n]=-1;
  for(int i=1;i<=n;i++)
  {
    if(arr[i]==arr[i-1])
      cnt++;
    else
    {
      ans+=(cnt/2);
      cnt=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  
  vector<int>x(N);//Aを小大小大...に並べた場合の係数.偶数番目は小さいので'-'
  vector<int>y(N);//   大小大小...　　　　場合の係数.         大きい　 '+'
  for(int i=0;i<N;i++){
    if(i%2!=0){if(i-1>=0){x[i]++;y[i]--;}
               if(i+1<N){x[i]++;y[i]--;}
    }
    if(i%2==0){if(i-1>=0){x[i]--;y[i]++;}
               if(i+1<N){x[i]--;y[i]++;}
    }
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  //小さい係数に小さいAを割り当てる
  int64_t sumx=0,sumy=0;
  for(int i=0;i<N;i++){
    //cout<<"x "<<x[i]<<" "<<"y "<<y[i]<<endl;
    sumx+=(x[i]*A[i]);
    sumy+=(y[i]*A[i]);
  }
  cout<<max(sumx,sumy)<<endl;
  
  return 0;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,p;
    cin>>n>>p;
    vector<int>a(n);
    bool ok=true;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==1)ok=false;
    }
    if(ok==false)cout<<(ll)pow(2,n)/2<<endl;
    else{
        if(p==1)cout<<0<<endl;
        else cout<<(ll)pow(2,n)<<endl;
    }
}


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

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  ll ans = 0;
  x = abs(x);
  if (x/d >= k) {
    ans = x-k*d;
    cout << ans << endl;
  } else {
    ll now = x - x/d * d;
    k -= x/d;
    if (k%2==1) {
      ans = min(abs(now+d), abs(now-d));
      cout << ans << endl;
      return 0;
    } else {
      ll tmp = abs(now - 2*d);
      ll tmp2 = abs(now + 2*d);
      ans = min(min(tmp, tmp2), now);
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}

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

using namespace std;

int n;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
  }
  sort(s.begin(), s.end(), [&](string a, string b){return a.length() > b.length();});
  vector<int> leaf(1);
  vector<vector<int>> to(1, vector<int>(26, -1));
  vector<vector<int>> sum(1, vector<int>(26));
  long long res = 0;
  for(string p : s) {
    int sz = p.length();
    int cur = 0;
    vector<int> path;
    path.push_back(cur);
    for(int i = 0; i < sz; i++) {
      int c = p[i] - 'a';
      if(to[cur][c] == -1) {
        to[cur][c] = leaf.size();
        leaf.push_back(0);
        to.push_back(vector<int>(26, -1));
        sum.push_back(vector<int>(26));
        cur = leaf.size() - 1;
      } else {
        cur = to[cur][c];
      }
      path.push_back(cur);
    }
    int root = path[sz - 1];
    int last_char = p.back() - 'a';
    res += sum[root][last_char];
    for(int i = 1; i <= sz; i++) {
      int node = path[i];
      int par = path[i - 1];
      vector<int> rev = sum[node];
      for(int j = 0; j < 26; j++) if(to[par][j] == node) rev[j] = leaf[node];
      for(int j = 0; j < 26; j++) sum[par][j] -= rev[j];
    }
    for(int i = 0; i <= sz; i++) {
      int node = path[i];
      leaf[node]++;
    }
    for(int i = sz; i > 0; i--) {
      int par = path[i - 1];
      int node = path[i];
      vector<int> add = sum[node];
      for(int j = 0; j < 26; j++) if(to[par][j] == node) add[j] = leaf[node];
      for(int j = 0; j < 26; j++) sum[par][j] += add[j];
    }
  }
  cout << res;
  return 0;
}


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

int main()
{
    int H,W,i,j;
    char temp;
    cin>>H>>W;
    int block[H+1][W+1];
    int dp[H+1][W+1];
    for(i=0;i<H;i++)
    {
        for(j=0;j<W;j++)
        {
            cin>>temp;
            if(temp=='.')   block[i][j]=0;
            else block[i][j] = 1;
        }
    }
    
    //Filling up the bottom up table
    if(block[0][0]!=1)dp[0][0] = 1;
    else dp[0][0] = 0;
    for(i=0;i<H;i++)
    {
        for(j=0;j<W;j++)
        {
            if(i==0)
            {
                if(j==0) continue;
                else 
                {
                    if(block[i][j-1]!=1) dp[i][j] = dp[i][j-1]%MOD;
                    else dp[i][j] =0;
                }
            }
            else if(j==0)
            {
                if(block[i-1][j]!=1) dp[i][j] = dp[i-1][j]%MOD;
                else dp[i][j] =0;
            }
            else
            {
                if(block[i][j-1]!=1)
                {
                    if(block[i-1][j]!=1)
                    {
                        dp[i][j] = (dp[i-1][j]%MOD + dp[i][j-1]%MOD)%MOD;
                    }
                    else
                    {
                        dp[i][j] = dp[i][j-1]%MOD;
                    }
                }
                else if(block[i-1][j]!=1)
                {
                    dp[i][j] = dp[i-1][j]%MOD;
                }
                else dp[i][j] = 0;
            }
        }
    }
    if(block[H-1][W-1]!=1) cout<<dp[H-1][W-1]%MOD<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n, m;
    cin >> n >> m;
    if (n == 1){
        cout << m << endl;
        return 0;
    }
    ll ans = 0;
    for (ll x = 1; x * x <= m; x++){
        if (m % x) continue;
        if (m / x >= n) ans = max(ans, x);
        ll y = m / x;
        if (m / y >= n) ans = max(ans, y);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int E,Y;
    cin>>E>>Y;
    if (E==0&&1868<=Y&&Y<=1911){
        cout<<"M"<<Y-1867<<endl;
    }else if (E==0&&1912<=Y&&Y<=1925){
        cout<<"T"<<Y-1911<<endl;
    }else if(E==0&&1926<=Y&&Y<=1988){
        cout<<"S"<<Y-1925<<endl;
    }else if(E==0&&1989<=Y&&Y<=2016){
        cout<<"H"<<Y-1988<<endl;
    }else if (E==1&&1<=Y&&Y<=44){
        cout<<1867+Y<<endl;
    }else if (E==2&&1<=Y&&Y<=14){
        cout<<1911+Y<<endl;
    }else if (E==3&&1<=Y&&Y<=63){
        cout<<1925+Y<<endl;
    }else if (E==4&&1<=Y&&Y<=28){
        cout<<1988+Y<<endl;
        
    }
    }


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int n,a[100005];
map<int,int>mp;
signed main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    mp[a[i]]++;
    mp[a[i]+1]++;
    mp[a[i]-1]++;
  }
  sort(a,a+n);
  int ans=0;
  for(int i=a[0]-1;i<=a[n-1]+1;i++){
    ans=max(ans,mp[i]);
  }
  cout<<ans<<endl;
}

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

//絶対値
int abs(int x, int y){
  if(x>y){
    return x-y;
  }
  else{
    return y-x;
  }
}

int main(){
  int n,m;
  cin >> n >> m;
  int a[n],b[n],c[m],d[m];
  int i,j,ans;
  int min,num[n];
  //num[n]={0};
  
  for(i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  for(j=0;j<m;j++){
    cin >> c[j] >> d[j];
  }

  
  for(i=0;i<n;i++){
      ans=abs(a[i],c[0])+abs(b[i],d[0]);
      min=ans;
      num[i]=0;
    for(j=0;j<m;j++){
      ans=abs(a[i],c[j])+abs(b[i],d[j]);
      if(ans<min){
	num[i]=j;
	min=ans;
      }
    }
    cout << num[i]+1 << endl;
  }
}


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

int main() {
  int year, month, day;
  char c1, c2;
  cin >> year >> c1 >> month >> c2 >> day;
  if ( month >= 5 )
    cout << "TBD" << endl;
  else
    cout << "Heisei" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define EPS (1e-10)
#define equal(a,b)  fabs((a)-(b))<EPS
using namespace std;
struct Point{
	double x,y;
	Point(double _x,double _y):x(_x),y(_y){  }
	Point operator + (Point &a){
		return Point(x+a.x,y+a.y);
	}
	Point operator - (Point &a){
		return Point(x-a.x,y-a.y);
	}
	Point operator *(double k){
		return Point (k*x,k*y);
	}
	Point operator /(double k){
		return Point(x/k,y/k);
	}
	
	friend double norm(Point &a){
		return a.x*a.x+a.y*a.y;
	}
	friend double abs(Point &a){
		return sqrt(norm(a));
	}
	
	friend double dot(Point &a,Point &b){
		return a.x*b.x+a.y*b.y;
	}
	friend double cross(Point &a,Point &b){
		return fabs(a.x*b.y-b.x*a.y);
	}
};
typedef Point Vector;
bool isOrthogonal(Vector &a,Vector & b){
	return equal(cross(a,b),0.0);
}
bool isParallel(Vector &a,Vector &b){
	return equal(dot(a,b),0.0);
}

int main(){
	int q;
	cin>>q;
	while(q--){
		int x1,x2,y1,y2;
		cin>>x1>>y1>>x2>>y2;
		Vector v1(x1-x2,y1-y2);
		cin>>x1>>y1>>x2>>y2;
		Vector v2(x1-x2,y1-y2);
		if(isParallel(v1,v2)) cout<<1<<endl;
		else if(isOrthogonal(v1,v2)) cout<<2<<endl;
		else cout<<0<<endl;
	}
	return 0;
}


Measured memory_bytes: 3100
n,m,c=map(int,input().split())
l=list(map(int,input().split()))
h=0
for i in range(n):
    d=list(map(int,input().split()))
    s=c
    for i in range(m):
        s+=l[i]*d[i]
    if(s>0):
        h+=1
print(h)


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

int main (){
	
	int n,t,a,temp2;
	float h[1001],temp;

	cin >> n >> t >> a;
	temp=100000;
	temp2 = 1;
	for(int i=1;i<n+1;i++){
		cin >> h[i];
		h[i] = t - h[i] * 0.006;
		//cout << h[i] << endl;
			}
	for(int i=1;i<n+1;i++)
		h[i] = abs(a - h[i]);
	/*if(a<0){
	for(int i=1;i<n+1;i++)
		h[i] = abs(a + h[i]);
	}*/
	for(int i=1;i<n+1;i++){
		if(temp > h[i]){
			temp = h[i];
		temp2 = i;
		}
	}

	cout << temp2 <<endl;

	return 0;
}

Measured memory_bytes: 256
# https://note.com/tanon_cp/n/ne423915acdaa
from bisect import bisect

INF = 10 ** 18

def check_neg(m, k, pos, neg):
    len_pos = len(pos)
    less = 0  # かけたら m 未満になるペア数
    j = 0
    for a in neg:
        d = m // a
        while j < len_pos and pos[j] <= d:
            j += 1
        if len_pos == j:
            break
        less += len_pos - j
    return less < k

def check_pos(m, k, pos, neg):
    less_eq = 0  # かけたら m 以下になるペア数
    j = 0
    len_pos = len(pos)
    len_neg = len(neg)
    for i in range(len_pos - 1, -1, -1):
        a = pos[i]
        d = m // a
        while j < len_pos and pos[j] <= d:
            j += 1
        if j == len_pos:
            less_eq += len_pos * (i + 1)
            break
        less_eq += j

    j = 0
    for i in range(len_neg - 1, -1, -1):
        a = neg[i]
        d = m // a
        while j < len_neg and neg[j] <= d:
            j += 1
        if j == len_neg:
            less_eq += len_neg * (i + 1)
            break
        less_eq += j

    m_sqrt = int(m ** 0.5)
    less_eq -= bisect(pos, m_sqrt)
    less_eq -= bisect(neg, m_sqrt)
    less_eq //= 2
    return less_eq < k


def solve(n, k, A):
    pos = []
    neg = []
    zeros = []
    for a in A:
        if a == 0:
            zeros.append(a)
        elif a > 0:
            pos.append(a)
        else:
            neg.append(a)

    pos = [a for a in A if a > 0]
    neg = [a for a in A if a < 0]
    num_neg = len(neg) * len(pos)
    num_zero = (len(neg) + len(pos)) * len(zeros) + len(zeros) * (len(zeros) - 1) // 2
    if k <= num_neg:
        l = -INF
        r = 0
        while l + 1 < r:
            m = (l + r) // 2
            if check_neg(m, k, pos, neg):
                l = m
            else:
                r = m
        return l
    elif num_neg < k <= num_neg + num_zero:
        return 0
    else:
        k -= (num_neg + num_zero)
        l = 0
        r = INF
        neg = [-a for a in neg]
        neg.reverse()
        while l + 1 < r:
            m = (l + r) // 2
            if check_pos(m, k, pos, neg):
                l = m
            else:
                r = m
        return r


n, k = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
print(solve(n, k, A))


Measured memory_bytes: 98516
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int sum = 0;
    rep(i,N) sum += A[i];
    sort(A.begin(), A.end(), greater<int>());
    bool ret = true;
    rep(i,M) {
        if (A[i] < sum/(4.0*M)) {
            ret = false;
            break;
        }
    }
    cout << (ret? "Yes" : "No") << endl;
    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    int64 k;
    cin >> n >> k;
    vector<int32> a(n);
    REP(i,n)cin >> a[i],a[i]--;
    vector<int64> dist(n,-1);
    dist[0] = 0;
    int32 cur = 0;
    int64 d = 0;
    while(true){
        cur = a[cur];
        ++d;
        if(dist[cur] == -1){
            dist[cur] = d;
        }else{
            int32 lp = d - dist[cur];
            d = d + (k - d) / lp * lp;
            dist[cur] = d;
        }
        if(d == k){
            ANS(cur+1);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 6368
#include <iostream>
#include <vector>
#include <string>

int main() {
    auto H = 0;
    auto W = 0;
    std::cin >> H >> W;

    auto grid = std::vector<std::string>(H);

    for (auto& y : grid) {
        std::cin >> y;
    }

    for (auto i = 0; i < H; ++i) {
        for (auto j = 0; j < W; ++j) {
            if (grid[i].substr(j, 1) == std::string("#") || grid[i].substr(j, 1) == std::string(
                    "b")) {
                auto x = j - 1;
                if (x >= 0 && (grid[i].substr(x, 1) == std::string("#"))) {
                    grid[i].replace(j, 1, "b");
                    grid[i].replace(x, 1, "b");
                }
                x = j + 1;
                if ((x <= W - 1) && (grid[i].substr(x, 1) == std::string("#"))) {
                    grid[i].replace(j, 1, "b");
                    grid[i].replace(x, 1, "b");
                }
                auto y = i - 1;
                if ((y >= 0) && (grid[y].substr(j, 1) == std::string("#"))) {
                    grid[i].replace(j, 1, "b");
                    grid[y].replace(j, 1, "b");
                }
                y = i + 1;
                if ((y <= H - 1) && (grid[y].substr(j, 1) == std::string("#"))) {
                    grid[i].replace(j, 1, "b");
                    grid[y].replace(j, 1, "b");
                }
            }
        }
    }

    for (const auto& y : grid) {
        for (auto i = std::size_t(0); i < W; ++i) {
            if (y.substr(i, 1) == std::string("#")) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b


signed main(){
	int n; cin>>n;
	ll ans=0;
	ll cnt=0;
	rep(i,0,n){
		ll a; cin>>a;
		if(a==0){
			ans+=(cnt/2);
			cnt=0;
		}
		cnt+=a;
	}
	ans+=cnt/2;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3636
// ABC147-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll mod=pow(10,9)+7;
    ll ans=0;
    ll twofact=1;
    for(int i=0;i<60;i++){
        ll one=0,zero=0;
        for(int j=0;j<n;j++){
            if((a[j]>>i)&1) one+=1;
            else zero+=1;
        }
        ll add=one*zero%mod*twofact%mod;
        ans=(ans+add)%mod;
        twofact=twofact*2%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


int main() {
    int x,n,ans = 0,mae = 1000;
    cin >> x >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    for (int i = -1; i <= 101; ++i) {
        int flg = 0;
        for (int j = 0; j < n; ++j) {
            if(p[j] == i){
                flg = 1;
            }
        }
        if(flg) continue;

        if(abs(x-i) < mae){
            mae = abs(x-i);
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3424
/*
DavitMarg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#define mod 1000000007
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
int n;
LL a,b,d[100005],s;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		s += a;
		s -= b;
		d[i] = a + b;
	}
	sort(d,d+n);
	reverse(d,d+n);
	for (int i = 0; i < n; i++)
		if (i % 2 == 0)
			s += d[i];
		else
			s -= d[i];

	cout << s / 2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  string s, t;
  cin >> s >> t;

  int n = s.size();
  int m = t.size();

  int minimum = n;

  for (int i = 0; i < n - m + 1; i++) {
    int mismatch = 0;
    for (int j = 0; j < m; j++) {
      if (s[i+j] != t[j]) mismatch++;
    }
    if (mismatch < minimum) minimum = mismatch;
  }

  cout << minimum << endl;

  return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n;
    cin >> n;
    double ans = 0;
    REP(i, n){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY"){
            ans += x;
        }
        else{
            ans += 380000.0 * x;
        }
    }
    printf("%.10lf\n", ans);
}


Measured memory_bytes: 256
mod = 2019
eps = 10**-9


def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    S = input().rstrip('\n')
    S = S[::-1]
    N = len(S)
    CS = [0] * (N+1)
    for i in range(N):
        CS[i+1] = (CS[i] + (int(S[i]) * pow(10, i, mod))%mod)%mod
    dic = defaultdict(int)
    for a in CS:
        dic[a] += 1
    ans = 0
    for v in dic:
        a = dic[v]
        ans += a * (a-1) // 2
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
	string a;
	getline(cin, a);
	int n;
	n = a.size();
	for (int i = 0;i < n;i++) {
		if (a[i] >= 'a'&&a[i] <= 'z') { a[i] = a[i] - 32; }
		else if (a[i] >= 'A'&&a[i] <= 'Z') {
			a[i] = a[i] + 32;
	}
	}cout<<a<< endl;
	return 0;
}


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

bool res = false;
int a[10];

void dfs(int i, int l, int r) {
    if (i >= 10) {
        res = true;
        return;
    }
    else {
        if (a[i] > l) dfs(i + 1, a[i], r);
        if (a[i] > r) dfs(i + 1, l, a[i]);
    }
}

int main() {
    int T;
    cin >> T;
    for (int i = 0; i < T; ++i) {
        for (int j = 0; j < 10; ++j) cin >> a[j];
        res = false;
        dfs(0, 0, 0);
        cout << (res?"YES":"NO") << endl;
    }
    return 0;
}


Measured memory_bytes: 3048
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^63.
// NOTE: This function does not handle error cases.
// Verified: ARC096D
fun fastReadLongs(n: Int): LongArray {
  val xs = LongArray(n)
  val s = readLine()!!
  var currentValue = 0L
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1L else 1L
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1L else 1L
  return xs
}

// Compute c to make x1 * 2^p <= x2 * 2^(p + c)
fun cost(x1: Long, x2: Long): Int {
  if (x1 == x2) return 0
  if (x2 < x1) {
    var c = 0
    var currentX2 = x2
    while (currentX2 < x1) {
      c += 2
      currentX2 *= 4
    }
    return c
  }
  // x1 < x2
  var c = 0
  var currentX1 = x1
  while (4 * currentX1 <= x2) {
    c -= 2
    currentX1 *= 4
  }
  return c
}

fun solveDP(n: Int, xs: LongArray): LongArray {
  // Solve all positive case.
  val M = 100
  // dp[k][i]: The cost to solve [i, n) when the cost at i is 2 * k.
  var dp = Array(M + 1, { LongArray(n) })
  for (i in n - 1 downTo 0) {
    if (i == n - 1) {
      for (k in 0..M) {
        dp[k][i] = 2L * k
      }
    } else {
      for (k in 0..M) {
        val k2 = k + cost(xs[i], xs[i + 1]) / 2
        if (0 <= k2 && k2 <= M) {
          dp[k][i] = 2 * k + dp[k2][i + 1]
        } else if (k2 < 0) {
          dp[k][i] = 2 * k + dp[0][i + 1]
        } else {
          // k2 > M
          dp[k][i] = 2 * k + (n - i - 1) * 2 * (k2 - M) + dp[M][i + 1]
        }
      }
    }
  }
//  println(dp[0].toList())
//  println(dp[1].toList())
  return dp[0]
}

fun main(args: Array<String>) {
//  println(cost(5, 16))
//  println(cost(4, 16))
//  println(cost(3, 16))
//  println(cost(16, 3))
//  println(cost(16, 4))
//  println(cost(16, 5))
  val n = readLine()!!.toInt()
  val xs = fastReadLongs(n)

  val dp1 = solveDP(n, xs)
  val ys = xs.reversedArray()
  val dp2 = solveDP(n, ys)

  var min = dp1[0]

  for (i in 1 until n) {
    // First i is negative, then positive
    val cost = i + dp2[n - i] + dp1[i]
    min = Math.min(min, cost)
  }

  // All negative
  min = Math.min(min, n + dp2[0])

  println(min)
}



Measured memory_bytes: 265280
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long cnt[10][10];
  for (int i = 1; i <= 9; i++) fill(cnt[i], cnt[i] + 10, 0);
  for (int i = 1; i <= N; i++) {
    int s = i % 10;
    if (s == 0) continue;
    int p = i;
    while (p >= 10) p /= 10;
    cnt[p][s]++;
  }
  long long ans = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3612
# AtCoder
from collections import defaultdict
N, K = map(int, input().split())

dt = defaultdict(int)
for i in range(N):
    dt[i+1] = 0

for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))

    for j in A:
        dt[j] += 1

cnt = 0
for k, v in dt.items():
    if v == 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 9468
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    
    int ans = s.size();
    
    for (int i = 0; i < 2; i++){
        int cnt = 0;
        for (int j = 0; j < s.size(); j++){
            if (j % 2 == 0 && s[j] != (char)(i + '0')) cnt++;
            if (j % 2 != 0 && s[j] == (char)(i + '0')) cnt++;
        }
        ans = min(ans, cnt);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 512
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = [int(x) for x in input().split()]

sum_d = 0
for i in range(N):
    for j in range(i + 1, N):
        sum_d += ((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2) ** 0.5

# (sum_d / NC2) * (N - 1)
print(2 * sum_d / N)

Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>

using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;



int main() {
    int m, d;
    cin >> m >>d;
    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= d; j++) {
            int d10 = j / 10;
            int d1 = j % 10;
            if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) {
                cnt++;
            }
        }
    }
    cout << cnt <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;


int main() {
  for (int N; cin >> N, N != 0; ) {
    int ans = 0;
    REP(i, 1, N) REP(j, i + 2, N + 1) {
      if (j * (j - 1) / 2 - i * (i - 1) / 2 == N) ans++;
    }
    cout << ans << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N){
    ll m, k, ans=0;
    for(ll k=1; k*k<= N; k++){
        if(N % k == 0){
            ll tmp = N/k;
            if(tmp > k+1)
                ans += tmp-1;
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

string ans="";
vector<string > v , all;
int arr[10]={0};


int main() {
	int a, b , ans=1;
	cin >> a>> b;
	
	
	while(a--){
	    ans=min(2*ans ,ans+b );
	}
	
	
	cout << ans << endl;
	
	
	
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int A, L;
vector<int> v;

void solve() {
  v.clear();
  stringstream ss;
  ss << A;
  string base = ss.str();
  while (base.size() < L) base.insert(0, 1, '0');
  v.push_back(atoi(base.c_str()));
  for (int i = 1; i <= 20; ++i) {
    string cur = base;
    sort(base.begin(), base.end());
    sort(cur.begin(), cur.end(), greater<char>());
    int value = atoi(cur.c_str()) - atoi(base.c_str());
    v.push_back(value);

    // printf("%s - %s = %d\n", cur.c_str(), base.c_str(), value);
    
    stringstream ns;
    ns << value;
    base = ns.str();
    while (base.size() < L) base.insert(0, 1, '0');
  }
  // puts("");
  // rep(i,v.size()) printf("%d\n", v[i]);
  // puts("");
  // printf(">>>>  %d %d \n", A, L);
  rep(i,v.size()) rep(j,v.size()) {
    if (i == j || i <= j) continue;
    if (v[i] == v[j]) {
      printf("%d %d %d\n", j, v[i], i - j);
      return;
    }
  }
}

int main() {
  while (scanf("%d%d", &A, &L), A | L) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0