akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] stones = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            stones[i] = sc.nextInt();
        }

        int[] dp = new int[N + 1];
        dp[1] = 0;
        dp[2] = Math.abs(stones[1]-stones[2]);
        for (int i = 3; i <= N; i++) {
            dp[i]  = Math.min(dp[i-1]+Math.abs(stones[i]-stones[i-1]),dp[i-2]+Math.abs(stones[i]-stones[i-2]));
        }
        System.out.println(dp[N]);
    }
}


Measured memory_bytes: 48616
/*input
1
1
*/
/**
    Author: Kristopher Paul
    Date Created: 21-12-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

//Uncomment for File I/O
/*
#define cin fin
#define cout fout

ifstream fin("cowmbat.in");
ofstream fout("cowmbat.out");
*/

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    int arr[n];
    umap<int,vi> pos;
    FOR(i,0,n){
        cin >> arr[i];
        pos[arr[i]].pb(i);
    }
    int mn = n;
    int b = 0;
    int l = -1;
    FOR(i,1,n+1){
        int ind = n;
        FOR(j,0,pos[i].size()){
            if(pos[i][j] > l){
                ind = pos[i][j];
                break;
            }
        }
        if(ind == n){
            break;
        }
        b += (ind-l)-1;
        remin(mn,b+n-ind-1);
        l = ind;
    }
    if(mn == n){
        cout << "-1" << endl;
        return;
    }
    cout << mn << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 19400
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
			int w = sc.nextInt();
			int n = sc.nextInt();
			int x = 0;
				int[] num = new int[w];
					for(int i=0; i<w; i++)
					{
						num[i] = i+1;
					}
						for(int i=0; i<n; i++)
						{
							String[] str = sc.next().split(",");
							x = num[Integer.valueOf(str[0])-1];
							num[Integer.valueOf(str[0])-1] = num[Integer.valueOf(str[1])-1];
							num[Integer.valueOf(str[1])-1] = x;
						}
							for(int i=0; i<w; i++)
							{
								System.out.println(num[i]);
							}
	}
}

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

signed main()
{
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    double r = w * h / 2.0;
    cout << r << " ";
    if (x == w / 2.0 && y == h / 2.0)
    {
        cout << 1 << "\n";
    }
    else
    {
        cout << 0 << "\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v(n);
	for(int i=0;i<n;i++)cin>>v[i];

   vector<int> dp(k+1,0);
   for(int i=0;i<n;i++)
   {
   	  dp[v[i]] = 1;
   }

   for(int i=v[0];i<=k;i++)
   {
       if(dp[i]!=1)
       {
       	   int flag=0;
       	   for(int j=0;j<n && v[j]<=i;j++)
       	   {
       	   	   if(dp[i-v[j]]==0)
       	   	   	   {flag=1;
       	   	   	   	break;
       	   	   	   }
       	   }

       	   if(flag)
       	   	 dp[i]=1;
       	   
       }

   }

   if(dp[k])
   {
   	cout<<"First\n";
   }
   else
   {
   	cout<<"Second\n";
   }
}

Measured memory_bytes: 640
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
#define hell 1000000007
ll n;
ll dp[100005][2];
vector<ll>mm[100005];
bool visited[100005];
//0 - White
//1 - Black
void dfs(ll ind)
{
    visited[ind] = true;
    dp[ind][0] = 1%hell;
    dp[ind][1] = 1%hell;
    f(mm[ind].size())
    {
        if(visited[mm[ind][i]] == false)
        {
            dfs(mm[ind][i]);
            dp[ind][0] = dp[ind][0]%hell * (dp[mm[ind][i]][0]%hell+dp[mm[ind][i]][1]%hell);
            dp[ind][1] = dp[ind][1]%hell * dp[mm[ind][i]][0]%hell;
            dp[ind][0]%= hell;
            dp[ind][1]%= hell;
        }
    }
}
int main()
{
    _fast_
    ll t = 1;
   // cin>>t;
    while(t--){
    cin>>n;
    f(n)
    {
        mm[i].clear();
        visited[i] = false;
    }
    ll no1,no2;
    f(n-1)
    {
        cin>>no1>>no2;
        mm[no1-1].pb(no2-1);
        mm[no2-1].pb(no1-1);
    }
    dfs(0);
    cout<<(dp[0][0]%hell+dp[0][1]%hell)%hell<<"\n";

    }
    return 0;
}

Measured memory_bytes: 12928
n=int(input())
l=[]
for i in range(n):
  w=sorted(list(input()))
  l.append(w)
l=sorted(l)
c=0
c1=0
w1=l[0]
for i in range(n):
  if w1==l[i]:
    c1+=1
  else:
    w1=l[i]
    c+=c1*(c1-1)//2
    c1=1
    
c+=c1*(c1-1)//2
print(c)

Measured memory_bytes: 25420
#include<bits/stdc++.h>
using namespace std;
int n,m,t,x[100010];
long long f[100010],k=1e18;
int main()
{
	scanf("%d%d%d",&n,&m,&t);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	for(int i=1,j=0;i<=n;i++)
	{
		for(;2*(x[i]-x[j+1])>t;j++)
			k=min(k,f[j]-2*x[j+1]);
		f[i]=min(k+2*x[i],f[j]+t);
	}
	cout<<f[n]+m<<"\n";
	return 0;
}


Measured memory_bytes: 1408
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int[] d = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int result = 0, sum = 0, r = Math.min(n, k);
			SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
			for (int i = 0; i <= r; i++) {
				// iは左側から取り出す数
				if (i > 0) {
					sum += d[i - 1];
					map.put(d[i - 1], map.getOrDefault(d[i - 1], 0) + 1);
				}
				// jは右側から取り出す数
				if (0 == (i & 1)) {
					// iが偶数の場合、右側から取り出して、mapに追加していく
					for (int j = 0; j <= r - i; j++) {
						if (j > 0) {
							sum += d[n - j];
							map.put(d[n - j], map.getOrDefault(d[n - j], 0) + 1);
						}
						result = Math.max(result, checkRemove(sum, map, k - i - j));
					}
					if (r - i > 0) {
						sum -= d[n - r + i];
						remove(map, d[n - r + i], 1);
					}
				} else {
					// iが奇数の場合、右側から取り出して、mapから削除していく
					for (int j = r - i; j >= 0; j--) {
						if (j < r - i) {
							sum -= d[n - 1 - j];
							remove(map, d[n - 1 - j], 1);
						}
						result = Math.max(result, checkRemove(sum, map, k - i - j));
					}
				}
			}
			System.out.println(result);
		}
	}

	/**
	 * mapからkeyをamount分削除
	 * 
	 * @param map
	 * @param key
	 * @param amount
	 * @return 削除された数
	 */
	private static int remove(SortedMap<Integer, Integer> map, int key, int amount) {
		int value = map.get(key);
		if (value <= amount) {
			map.remove(key);
			return value;
		} else {
			map.put(key, value - amount);
			return amount;
		}
	}

	/**
	 * 手持ちの宝石の捨てる作業を実施する
	 * 
	 * @param sum    手持ちの宝石の価値の合計
	 * @param map    手持ちの宝石を保存するマップ
	 * @param remain 捨てる宝石の最大値
	 * @return 宝石を捨てた後の手持ちの宝石の価値の合計
	 */
	private static int checkRemove(int sum, SortedMap<Integer, Integer> map, int remain) {
		Map<Integer, Integer> tempMap = new HashMap<>();
		while ((!map.isEmpty()) && (remain > 0)) {
			int firstKey = map.firstKey();
			if (firstKey >= 0) {
				break;
			}
			int diff = remove(map, firstKey, remain);
			tempMap.put(firstKey, diff);
			remain -= diff;
			sum -= firstKey * diff;
		}
		tempMap.entrySet()
				.forEach(entry -> map.put(entry.getKey(), map.getOrDefault(entry.getKey(), 0) + entry.getValue()));
		return sum;
	}
}


Measured memory_bytes: 41944
d,m=1e9+7,p[10001][200]={1};i,j,k,x,I;char s[11111];main(L){scanf("%s%d",s,&d);for(;i<strlen(s);i+=++j/2,j%=2)for(x=L=j?9:s[i]-48,k=0;k<d?:(k=0,x--);k++)p[i+1][I=(j|x<L)*d+(k+x)%d]+=p[i][j*d+k],p[i+1][I]%=m;printf("%d",(*p[i]+p[i][d]-1+m)%m);}

Measured memory_bytes: 7936
/*
 * main.c
 *
 *  Created on: 2019/05/25
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int A = 0, B = 0;
    scanf("%d %d", &A, &B);
    B += (A*3);
    printf("%d\n", B/2);
    return 0;
}


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

ll gcd(ll a, ll b){
    if(b == 0){ return a;}
    else{ gcd(b, a%b);}
}

int main(){
    ll a, b, ab, abm;
    cin >> a >> b;
    ab = gcd(max(a, b), min(a, b));
    abm = ab;
    ll ans = 1;

    ll N = 1000100;
    vector<ll> arr(N);
    vector<ll> so(0);
    for(ll i = 0; i < N; i++){
        arr[i] = 1;
    }
    for(ll i = 2; i < sqrt(N); i++){
        if(arr[i]){
            for(ll j = 0; i * (j + 2) < N; j++){
                arr[i *(j + 2)] = 0;
            }
        }
    }
    for(ll i = 2; i < N; i++){
        if(arr[i]){
            so.push_back(i);
        }
    }

    rep(i, so.size()){
        if(ab%so.at(i) == 0) ans++;
        while(ab%so.at(i) == 0){
            ab /= so.at(i);
        }
        if(so.at(i)*so.at(i) > abm){
            if(ab == 1){
                break;
            }else{
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int,int>pii;

const int maxn=1e5+55;
int a[maxn];
int main() {
	// freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
	int n;
	cin>>n;
	// map<int,set<int> >mpp;
	for(int i=1 ; i<=n ; i++) {
		cin>>a[i];
	}
	int cnt=0;
	/*for(map<int,int>::iterator it=mpp.begin() ; it!=mpp.end() ; it++) {
		int u=it->ff;
		for(set<int>::iterator it2=it->ss.begin() ; it2!=it->ss.end() ; it2++) {
			int v=*it2;
			if(mpp[v].find(u)!=mpp.end()) {	
				++cnt;
				mpp[v].erase(u);
				break;
			}
		} 
		mpp[u].erase(v);
	}
	*/
	for (int i=1 ; i<=n ; i++) {
		if(a[a[i]]==i)
			cnt++;
	}
	cnt/=2;
	cout<<cnt<<endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (auto &i : A) cin >> i;
  
  long long ans = 0;
  for (int i = 0; i < N -1; ++i) {
    if (A[i] <= A[i+1]) continue;
    ans += A[i] - A[i+1];
    A[i+1] = A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
typedef pair< pairint , string> P;
//実装案　勝たなかった試合＆負けた試合のベクター　照準ソートして上から
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
bool pairCompare(const P& firstElof, const P& secondElof)
{
  if(firstElof.first.first!= secondElof.first.first)    return firstElof.first.first< secondElof.first.first;
else if(firstElof.first.second != secondElof.first.second)    return firstElof.first.second< secondElof.first.second;
else return false;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
string k;
while(std::cin >> x){
for(;;){
  if(x-39>0)x-=39;
  else break;
}
if(x<10)std::cout <<"3C0"<<x << '\n';
else std::cout << "3C" <<x <<'\n';
}
}



Measured memory_bytes: 3096
# -*- coding: utf-8 -*-
N, T = map(int, raw_input().split())
t = map(int, raw_input().split())
total = 0
for k in range(0, N - 1):
    if t[k + 1] - t[k] <= T:
        total += t[k + 1] - t[k]
    else:
        total += T
total += T
print total


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

int base = 1e9 + 7;

ll invmod(ll p, ll q) {
  ll r = 1;
  while (q) {
    if (q&1) r = (r*p) % base;
    p = p*p % base;
    q >>= 1;
  }
  return r;
}

ll combimod(ll n, ll m) {
  ll t = 1;
  while (m) {
    t = t * n % base;
    t = t * invmod(m, base-2) % base;
    n--; m--;
  }
  return t;
}

int main() {
  ll n, a, b; cin >> n >> a >> b;
  
  ll total = invmod(2, n) - 1;
  total = (total + base - combimod(n, a)) % base;
  total = (total + base - combimod(n, b)) % base;
  
  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

vll g[30];
vll dx{-1,1,0,0};
vll dy{0,0,1,-1};
ll h,w;
vstr s(30);

ll bfs(ll a,ll b)
{
    queue< pll > q;
    vector< vector<ll> > dist(30,vector<ll>(30,LLONG_MAX)), vis(30,vll(30));

    q.push({a,b});
    dist[a][b] = 0;
    vis[a][b] = 1;
    ll curr,ans=-1;

    while(!q.empty())
    {
        pll x = q.front();
        q.pop();
        curr = dist[x.F][x.S];
        ans = max(ans,curr);

        rep(p,0,4)
        {
            ll nx = x.F+dx[p],ny = x.S+dy[p];

            if(nx<0 || nx>=h || ny<0 || ny>=w || s[nx][ny]=='#' || vis[nx][ny])continue;
            vis[nx][ny] = 1;
            dist[nx][ny] = curr+1;
            q.push({nx,ny});
            
        }
    }

    return ans;
}

int main()
{
    ll t, i, j, k, ans, n, m, sum = 0, x;

    //cin>>t;
    t = 1;
    while (t--)
    {
        cin >> h >> w;
        rep(p,0,h)cin>>s[p];

        ans = -1;
        rep(p,0,h)
        {
            rep(q,0,w)
            {
                if(s[p][q]!='#')ans = max(ans,bfs(p,q));
            }
        }

        cout<<ans;
    }

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e9)
using namespace std;
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,T;
    ll t[200010];
    cin >> N >> T;
    rep(i,0,N){
        cin >> t[i];
    }
    ll ans = 0;
    ll tt = T;
    rep(i,1,N){
        if(tt > t[i] - t[i-1]){
            tt -= (t[i] - t[i-1]);
            ans += t[i] - t[i-1];
            tt = T;
        }else{
            tt = T;
            ans += tt;
        }

    }
    ans += tt;
    print(ans);


}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d ",a);
int n,m,num;
int a,b,c;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read(); m=read();
	for (int i=n;i>=0;i--) {
	  for (int j=n-i;j>=0;j--) {
	  	if (n-i-j>=0) {
		num=i*10000+j*5000+(n-i-j)*1000;
	  	//if (num<m&&num!=0) break;
	  	if (num==m) {
	  	  out(i); out(j); out(n-i-j);
	  	  return 0;
	    }
	  }
    }
    //if (num<m&&num!=0) break;
  }
    printf("%d %d %d",-1,-1,-1);
    return 0;
}

Measured memory_bytes: 256
def merge(A,left,mid,right):
	global count
	
	n1=mid-left
	n2=right-mid
	L=A[left:mid]
	R=A[mid:right]
	# for i in range(n1):
	# 	L[i]=A[left+i]
	# for i in range(n2):
	# 	R[i]=A[mid+i]
	L.append(float('inf'))
	R.append(float('inf'))
	i,j=0,0
	# print(L,R)
	for k in range(left,right):
		count+=1
		if L[i]<=R[j]:
			A[k]=L[i]
			i=i+1
		else:
			A[k]=R[j]
			j=j+1

def mergesort(A,left,right):
	if left+1<right:
		mid=(left+right)//2
		mergesort(A,left,mid)
		mergesort(A,mid,right)
		merge(A,left,mid,right)

n=int(input())
A=list(map(int,input().split()))
count=0
mergesort(A,0,n)
print(*A)
print(count)


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

#define mp make_pair
#define pb push_back

typedef pair<int, int> ii;
typedef long long ll;
typedef pair<ll, ll> l4;

const int maxn = 2e5+1;
int a[maxn], n;
inline void end()
{
  puts("-1");
  exit(0);
}
int main()
{
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a+i);
  if (a[1] != 0)
    end();
  for (int i = 1; i <= n-1; ++i)
    if (a[i] < a[i+1]-1)
      end();
  deque<int> dq;
  ll base = 0;
  ll ans = 0;
  for (int i = n; i >= 1; --i, --base)
    {
      while (!dq.empty() && dq.front()+base <= 0)
        dq.pop_front();
      if (a[i] == 0)
        continue;
      if (dq.empty() || dq.back()+base != a[i])
        dq.push_back(a[i]-base);
      ans += dq.size();
    }
  printf("%lld\n", ans);
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int x[4] = { -1,0,1,0 };
int y[4] = { 0,1,0,-1 };
int g[4][4];
int m = 0;

bool solve(int depth, int t, int zx, int zy) {
	int c = 0;
	for (int i=0;i<4;i++) {
		for (int j=0;j<4;j++) {
			if (g[i][j] != 0) {
				int t = g[i][j]-1;
				c += abs(t / 4 - i) + abs(t % 4 - j);
			}
		}
	}

	if (c+depth>m) return false;
	if (c==0) return true;
	int dx,dy;
	for(int i=0;i<4;i++) {
		if (abs(i-t)!=2) {
			dx = zx+x[i];
			dy = zy+y[i];
			if (dx < 0 || dx == 4 || dy < 0 || dy == 4) continue;
            swap(g[dx][dy], g[zx][zy]);
            if (solve(depth + 1, i, dx, dy)) return true;
            swap(g[dx][dy], g[zx][zy]);

		}
	}
	return false;
}

int main() {
	int zx,zy;
	for (int i=0;i<4;i++) {
		for (int j=0;j<4;j++) {
			cin>>g[i][j];
			if (g[i][j]==0) {
				zx=i;zy=j;
			}
		}
	}
	for (m=0;m>=0;m++) {
		if (solve(0,9,zx,zy)) {
			cout<<m<<endl;
			return 0;
		}
	}

	
	return 0;
}


Measured memory_bytes: 3096
//
//  main.cpp
//  DPpractice
//
//  Created by abhishek kumar on 20/04/20.
//  Copyright © 2020 abhishek kumar. All rights reserved.
//

#include <iostream>
#include<vector>
#include<math.h>
using namespace std;
typedef long long int ll;
const long long int N=1000;
//const int INF=1e9 + 5;
ll n,k,m,temp,arr[N+1][N+1],dp[N+1][N+1],visited[N+1][N+1];


int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    vector<int> dp(3,0);
    for (auto i=0;i<n;i++) {
        vector<int> new_dp(3,0);
        vector<int> c(3);
        for(auto& it : c) cin>>it;
        for(auto i=0;i<3;i++)
        {
            for(auto j=0;j<3;j++)
            {
                if(i!=j)
                    new_dp[j]=max(new_dp[j],dp[i]+c[j]);
            }
        }
        
        dp=new_dp;
    }
    
    
    cout<<max(dp[0],max(dp[1],dp[2]));
  
    return 0;
        
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  var a = input.split("ABC").length;
	console.log(a === 0 ? 0 : a - 1);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
using namespace std;
using LLI = long long int;


int main(int argc, char *argv[])
{
    int N, K;
    cin >> N >> K;
    vector<pair<int, int>> v;
    for (int i=0; i<N; i++) {
        int t, d;
        cin >> t >> d;
        v.emplace_back(t, d);
    }

    // dの降順ソート
    sort(v.begin(), v.end(),
        [](const auto& l, const auto& r) { return l.second > r.second; }
    );
    
    // まだ含まれていないt
    set<int> ts_out;
    for (const auto& x : v) {
        ts_out.insert(x.first);
    }

    // 各tとして含まれている数
    vector<int> in_cnt(N+1, 0);

    // tの数
    int t_cnt = 0;

    // ポイント
    set<LLI> pts;
    LLI cur_pt = 0;

    // vから先頭K個を起点に考える
    for (int i=0; i<K; i++) {
        int t = v[i].first;
        int d = v[i].second;
        if (in_cnt[t] == 0) {
            ts_out.erase(v[i].first);
            t_cnt++;
        }
        in_cnt[t]++;
        cur_pt += LLI(d);
    }
    cur_pt += LLI(t_cnt) * LLI(t_cnt);
    pts.insert(cur_pt);
    

    int a = K - 1;
    for (int i=K; i<N; i++) {
        int t = v[i].first;
        int d = v[i].second;

        // まだ含まれていないtなら
        if (ts_out.find(t) != ts_out.cend()) {
            while (a != 0) {
                if (in_cnt[v[a].first] >= 2) {
                    in_cnt[v[a].first]--;
                    cur_pt += d - v[a].second;
                    t_cnt++;
                    cur_pt += (LLI(t_cnt) * LLI(t_cnt) - LLI(t_cnt - 1) * LLI(t_cnt - 1));
                    ts_out.erase(t);
                    pts.insert(cur_pt);
                    a--;
                    break;
                }
                a--;
            }
        }


        if (a == 0) {
            break;
        }
    }

    LLI m = *pts.crbegin();
    cout << m;

    return 0;
}

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

int main() {

    int W, H, N;
    cin >> W >> H >> N;

    P bottom_left;
    bottom_left.first = 0;
    bottom_left.second = 0;

    P top_right;
    top_right.first = W;
    top_right.second = H;


    rep(i, N) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1 and bottom_left.first < x)
        {
            bottom_left.first = x;
        }
        else if (a == 2 and top_right.first > x)
        {
            top_right.first = x;
        }
        else if (a == 3 and bottom_left.second < y)
        {
            bottom_left.second = y;
        }
        else if (a == 4 and top_right.second > y)
        {
            top_right.second = y;
        }
    }


    cout << max((top_right.second - bottom_left.second), 0) * max((top_right.first - bottom_left.first),0) << endl;


    return 0;
}

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

using namespace std;

struct SegmentTree{
    int n;
    vector<int> data;
    SegmentTree(int N){
        n = 1;
        while(n < N) n *= 2;
        data.assign(2 * n, INT_MAX);
    }
    inline void update(int k, int x){
        k += n - 1;
        data[k] = x;
        while(k > 0){
            k = (k - 1) / 2;
            data[k] = min(data[2 * k + 1], data[2 * k + 2]);
        }
    }
    inline int query(int a, int b){
        return query(a, b, 0, 0, n);
    }
    inline int query(int a, int b, int k, int l, int r){
        if(b <= l || r <= a){
            return INT_MAX;
        }else if(a <= l && r <= b){
            return data[k];
        }else{
            int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
    void print(){
        for(int i = 0; i < 2 * n - 1; i++){
            printf("data[%d] = %d\n", i, data[i]);
        }
    }
};

int main(){
    int N, Q;
    while(cin >> N >> Q){
        SegmentTree tree(N);
        REP(i, Q){
            int com;
            cin >> com;
            if(com == 0){
                int k, x;
                cin >> k >> x;
                tree.update(k, x);
            }else{
                int a, b;
                cin >> a >> b;
                cout << tree.query(a, b + 1) << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 2052
#include<stdio.h>
#include<string.h>
#include<vector>
#include<stdlib.h>
using namespace std;
void mul(const char *a, const char *b);

int main() {
	char c[5], d[17];
	scanf("%s %s", d, c);
	for(int i = 1; i < 5; i++) {
		c[i] = c[i+1];
	}
	const char *p1 = d;
	const char *p2 = c;
	mul(p1, p2);
	return 0;
}

void mul(const char *a, const char *b) {
	int n1, n2;
	n1 = strlen(a);
	n2 = strlen(b);
	vector<int> s;
	for (int i = 0; i<n1 + n2; i++) {
		s.push_back(0);
	}	
	for (int i = 0; i < n1; i++) {
		for (int j = 0; j < n2; j++) {
			s[i + j + 1] += (a[i] - '0') * (b[j] - '0');
		}
	}
	for (int i=n1+n2-1; i>=0; i--) {
		if (s[i] >= 10) {
			s[i-1] += s[i] / 10;
			s[i] %= 10;
		}
	}
	int i=0;
	while(s[i]==0) {
		i++;
	}
	if (i >= n1 + n2 - 2) {
		printf("0");
	} else {
		for (; i < n1 + n2 - 2; i++) {
			printf("%d", s[i]);
		}
	}
	printf("\n");
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
int A[200100];

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

    std::cin >> N;

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

        A[i] -= i + 1;
    }

    sort(A, A+N);

    int b = A[N / 2];
    ll res = 0ll;
    for(int i=0;i<N;++i){
        res = res + abs(A[i] - b);
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

typedef long long ll;

int main() {
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int a, b, c;
	cin >> a >> b >> c;

	if (b - a == c - b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let n: isize;
    input!(n);
    let x = input_vector::<isize>();
    let center = x.iter().sum::<isize>() / n;
    let ans = x.iter().map(|z| (z - center).pow(2_u32)).sum::<isize>();
    let ans2 = x.iter().map(|z| (z - center - 1).pow(2_u32)).sum::<isize>();
    println!("{}", std::cmp::min(ans, ans2));
}


Measured memory_bytes: 4352
# coding: utf-8
class Case01

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  # 読込
  def read
    @n = gets.chomp.to_i
  end

  # 回答
  def solve
    @result = ((@n + 1) /2) * (1.0 / @n) 
  end
  
  # 出力
  def output
    puts @result
  end

end

Case01.new.execute if $0 == __FILE__



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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')

n_nodes = int(input())
graph = [[] for _ in range(n_nodes)]

for _ in range(n_nodes):
    line = list(map(int, input().split()))
    u, k = line[0], line[1]
    if k > 0:
        for v in line[2:]:
            graph[u - 1].append(v - 1)
# pprint(graph)


def dfs(v):
    global time
    time += 1
    for v_adj in graph[v]:
        if d[v_adj] == -1:
            d[v_adj] = time
            dfs(v_adj)
    f[v] = time
    time += 1


d = [-1] * n_nodes
f = [-1] * n_nodes
time = 1

for v in range(n_nodes):
    if d[v] == -1:
        d[v] = time
        dfs(v)

# pprint(d)
# pprint(f)

for v in range(n_nodes):
    print(f"{v + 1} {d[v]} {f[v]}")



Measured memory_bytes: 6692
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	int N;
	cin>>N;
	cout<<(N-1)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
M = 1000
S = 0

for i in range(0, N):
  if i != N-1 and A[i] < A[i+1]:
    if S == 0:
      S = M // A[i]
      M = M % A[i]
  elif i == N-1 or A[i] > A[i+1]:
    if S > 0:
      M += S * A[i]
      S = 0  
print(M)

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

using namespace std;

#define _47_days ""

typedef long long ll;

const int N = 2e3 + 5;

int lvl[N], up[N][25];

int n, k, ans = N, a, b;

vector < vector < int > > g(N);

void dfs(int v, int p = 0) {
    lvl[v] = lvl[p] + 1;
    up[v][0] = p;
    for (int i = 1; i <= 20; ++i) {
        up[v][i] = up[up[v][i - 1]][i - 1];
    }
    for (int to : g[v]) {
        if (to == p)
            continue;
        dfs(to, v);
    }
}

int lca(int a, int b) {
    if (lvl[a] > lvl[b])
        swap(a, b);
    for (int i = 20; i >= 0; --i) {
        if (up[b][i] && lvl[a] >= lvl[up[b][i]]) {
            b = up[b][i];
        }
    }
    if (a == b)
        return a;
    for (int i = 20; i >= 0; --i) {
        if (up[a][i] != up[b][i]) {
            a = up[a][i];
            b = up[b][i];
        }
    }
    return up[a][0];
}

int dist(int a, int b) {
    return lvl[a] + lvl[b] - (2 * lvl[lca(a, b)]);
}

int main() {
    cin >> n >> a >> b;
    cout << ((b - a + 1) % 2 ? "Alice" : "Borys");
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	long int a,b,z,aa,bb;
	for(;;){
		if(scanf("%ld",&a)==EOF){break;}
		scanf("%ld",&b);
		aa=a;
		bb=b;
		if(a>b){
			z=a;
			a=b;
			b=z;
		}
		while(a%b!=0){
			z=a%b;
			a=b;
			b=z;
		}
		printf("%d %d\n",b,aa/b*bb);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
ll mazei[110][110];
int main() {
	cin >> n;
	vector<ll> t(n);
	vector<P> xy(n);
	rep(i, n) {
		cin >> t[i] >> xy[i].first >> xy[i].second;
	}
	ll tmp = 0;
	ll kt = 0;
	rep(i, n) {
		ll p = xy[i].first + xy[i].second;
		if (abs(t[i]-kt) < abs(p - tmp)) {
			cout << "No" << endl;
			return 0;
		}
		else {
			if (abs(t[i] - kt) % 2 != abs(p - tmp) % 2) {
				cout << "No" << endl;
				return 0;
			}
		}
		tmp = p;
		kt = t[i];
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 2560
l = input().split(" ")
W = int(l[0])
H = int(l[1])
if W == 1 and H == 1:
  print(1)
elif W == 1 or H == 1:
  print(W * H - 2)
else:
  print(W * H - 2 * (W + H - 2))


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;
import static java.lang.Double.parseDouble;

/**
 * Calender Colors
 */
public class Main {

	static int N, M;
	static double[][] cs, ds;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		StringTokenizer st = new StringTokenizer(br.readLine());

		N = parseInt(st.nextToken());
		M = parseInt(st.nextToken());

		cs = new double[N][3];
		ds = new double[N][N];

		for (int i = 0; i < N; i++) {
			st = new StringTokenizer(br.readLine());
			for (int j = 0; j < 3; j++) cs[i][j] = parseDouble(st.nextToken());
		}

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				double d = 0.0;
				for (int k = 0; k < 3; k++) d += Math.pow(cs[i][k] - cs[j][k], 2);
				ds[i][j] = d;
			}
		}

		//solve
		double max = -0.0;

		for (int i = 0; i < 1 << N; i++) {
			int c = 0;
			for (int j = 0; j < N; j++) if ((i >> j & 1) == 1) c++;
			if (c == M) max = Math.max(max, total(i));
		}

		System.out.println(max);

	} //end main

	static double total(int b) {

		int[] c = new int[M];
		double d = 0.0;

		for (int i = 0, j = 0; i < N; i++) {
			if ((b >> i & 1) == 1) {
				c[j] = i;
				j++;
			}
		}

		for (int i = 0; i < M; i++) {
			for (int j = i + 1; j < M; j++) {
				d += ds[c[i]][c[j]];
			}
		}

		return d;
	}
}

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

int main(){
    int N, k;
    int a[1000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
        for(k = 0;k < N; k++){
            cout << dec << a[k];
            if( k == N - 1){
                break;
            }else{
                cout << " ";
            }
        }
        cout << endl;
    int v, j;
    for(int i = 1; i < N;i++){
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for(k = 0;k < N; k++){
            cout << dec << a[k];
            if( k == N - 1){
                break;
            }else{
                cout << " ";
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  int N, M; std::cin >> N >> M;
  std::cout << (100 * (N-M) + 1900*M) * (int)std::pow(2.,M) << std::endl;

  return 0;
}


Measured memory_bytes: 256
alph_list= ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
N = int(input())
S = input("")
ans = str()
for i in range(len(S)):
    t = alph_list.index(S[i]) + N
    if t < len(alph_list):
        ans += alph_list[t]
    else:
        ans += alph_list[t - len(alph_list)]
print(ans)

Measured memory_bytes: 3064
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        inp.close();
        int ans = 0;
        for (int i = 0; i <= a; i++) {
            ans += i;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
D = int(input())
c = list(map(int, input().split()))
s = [[] for _ in range(D)]
t = []
for i in range(D):
    s[i] = list(map(int, input().split()))
for i in range(D):
    t.append(int(input()))
stf = [0] * 26
ld = [0] * 26
d = 0

def lower():
    lw = 0
    for i in range(26):
        lw += c[i] * (d - ld[i])
    return lw

x = 0
for i in range(D):
    d += 1
    x += s[i][t[i]-1]
    ld[t[i]-1] = d
    x -= lower()
    print(x)
    

Measured memory_bytes: 9412
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var X = one[1];
  var T = one[2];
  myout(Math.ceil(N / X) * T);
}

Measured memory_bytes: 30064
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
#include<string.h>
#include<map>
#include<cmath>
#include<stack>
#include<algorithm>
#include<assert.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
inline ll floor(const ll&a,const ll&b){return a/b;};
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
const ll INF=4223372036854775807,max_n=100005,mod=1000000007;
inline ll ceil(const ll&a,const ll&b){if(a%b==0)return a/b;return a/b+1;};
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main()
{
	ll n;cin>>n;
	ll t=sqrt(n);
	if(t*t==n)
	{
		cout<<2*(t-1);return 0;
	}
	else
	{
		ll ans=1LL<<62;
		ll nn=sqrt(n);
		for(ll i=1;i<=nn;i++)
		{
			if(n%i==0)
			{
				ans=min(ans,i+n/i-2);
			}
		}
		cout<<ans;
	}
}

Measured memory_bytes: 3696
# 2019/12/28

n,a,b=map(int,input().split())
if a%2==b%2:
    print((b-a)//2)
else:
    left=a-1
    right=n-b
    if left<right:
        b-=1
        print(a-1+(b-a)//2+1)
    else:
        a+=1
        print(n-b+(b-a)//2+1)

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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    cout <<  (a.back() == b[0] && b.back() == c[0] ? "YES" : "NO") << "\n";
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3604
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<ll> dqll;

#define MOD 1000000007

ll N, sr, sc;
string S, T;

bool test(char u, char l, ll x, ll pos) {
  ll tmp = x;
  for (int i = N - 1; i >= 0; i--) {
    if (T[i] == l) tmp++;
    tmp = min(tmp, x);    
    if (S[i] == u) tmp--;
    if (tmp == 0) return true;
  }
  if (tmp < pos) return true;

  tmp = 1;
  for (int i = N - 1; i >= 0; i--) {
    if (T[i] == u) tmp--;
    tmp = max(tmp, 1LL);    
    if (S[i] == l) tmp++;
    if (tmp == x + 1) return true;
  }
  if (tmp > pos) return true;

  return false;
}  // test

int main() {
  ll H, W;
  cin >> H >> W >> N >> sr >> sc >> S >> T;

  if (test('D', 'U', H, sr) || test('R', 'L', W, sc))
    puts("NO");
  else
    puts("YES");

  return 0;
}


Measured memory_bytes: 776