akhauriyash/Code-Regression huggingface dataset:
var n,w,k,i,j:longint;
    ans:int64;
    a,b,c:array[0..100001]of longint;  
    procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
    procedure sort1(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=b[(l+r) div 2];
         repeat
           while b[i]<x do
            inc(i);
           while x<b[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=b[i];
                b[i]:=b[j];
                b[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort1(l,j);
         if i<r then
           sort1(i,r);
      end;
    procedure sort2(l,r: longint);
      var
         i,j,x,y:longint;
      begin
         i:=l;
         j:=r;
         x:=c[(l+r) div 2];
         repeat
           while c[i]<x do
            inc(i);
           while x<c[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=c[i];
                c[i]:=c[j];
                c[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort2(l,j);
         if i<r then
           sort2(i,r);
      end;
begin
  readln(n);
  for i:=1 to n do 
    read(a[i]);
  for i:=1 to n do 
    read(b[i]);
  for i:=1 to n do 
    read(c[i]);
  sort(1,n);
  sort1(1,n);
  sort2(1,n);
  for i:=1 to n do 
    begin
      if b[1]>a[i]
      then k:=k+1;
    end;
  for i:=1 to n do 
    begin
      if c[i]>b[1]
      then w:=w+1;
    end;
  for i:=1 to n do 
    begin
      while (b[i]>a[k+1])and(k+1<=n) do k:=k+1;
      while (b[i]>=c[n-w+1])and(n-w+1<=n) do w:=w-1;
      ans:=ans+k*w;
    end;
  writeln(ans);
end.

Measured memory_bytes: 1408
package main
import (
  "fmt"
  "math"
)
func main() {
  var n, k int
  fmt.Scanf("%d %d", &n, &k)
  stones := make([]int, n)
  for i:=0;i<n;i++ {
    fmt.Scanf("%d", &stones[i])
  }
  fmt.Println(solve(n, k, stones))
}

func solve(n int, K int, arr []int) int {
  dp := make([]int, n)
  dp[0] = 0
  dp[1] = abs(arr[1]-arr[0])
  for i:=2;i<n;i++ {
    dp[i] = math.MaxInt32
    for k:=1;k<=min(i,K);k++ {
      dp[i] = min(dp[i], dp[i-k]+abs(arr[i]-arr[i-k]))
    }
  }
  return dp[n-1]
}

func abs(a int) int {
  if a < 0 {
    return -a
  }
  return a
}

func min(a, b int) int {
  if a < b {
    return a
  }
  return b
}


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

int main() {
    int N; cin >> N;
    vector<int> A(N+1,0), B(N+1,0), C(N+1, 0);
    rep(i, N) cin >> A.at(i+1);
    rep(i, N) cin >> B.at(i+1);
    rep(i, N-1) cin >> C.at(i+1);

    int sum = 0;
    for(int i=1; i<N+1; i++){
        sum += B.at(A.at(i));
        if(A.at(i) == A.at(i-1)+1) sum += C.at(A.at(i-1));
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(a) printf("Case %d: ", a)

using namespace std;
int main()
{
//    int t;
//    cin>>t;
//
//    for(int tc = 1;tc<=t; tc++){
//
//    }
    ll n;
    cin>>n;

    ll sum = 0;
    ll x = n/500;
    sum += 1000*x;

    n -= x*500;
    x = n/5;
    sum += 5*x;

    cout<<sum;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		long N = toLong(in);
		ArrayList<long[]> redList = new ArrayList<long[]>();
		ArrayList<long[]> blueList = new ArrayList<long[]>();
		for(int i=0;i<N;i++){
			long[] tmp = toLongArray(in);
			redList.add(tmp);
		}
		for(int i=0;i<N;i++){
			long[] tmp = toLongArray(in);
			blueList.add(tmp);
		}
		redList.sort(new Comparator<long[]>() {
			@Override
			public int compare(long[] o1, long[] o2) {
				return (int)(o1[0] - o2[0]);
			}
		});
		blueList.sort(new Comparator<long[]>() {
			@Override
			public int compare(long[] o1, long[] o2) {
				return (int)(o1[0] - o2[0]);
			}
		});

		long ans =0;
		int lastIndx =-1;
		for(int i=0;i<blueList.size();i++){
			lastIndx =-1;
			for(int k=0;k<redList.size();k++){
				if(redList.get(k)[0] < blueList.get(i)[0] &&
					redList.get(k)[1] < blueList.get(i)[1]	){
					if(lastIndx == -1 || redList.get(k)[1] > redList.get(lastIndx)[1]){
						lastIndx=k;
					}
				}
			}
			if(lastIndx !=-1){
				ans++;
				redList.remove(lastIndx);
			}
		}
		System.out.println(ans);
	}


	public static String[] readLineArray(BufferedReader in) throws Exception{
		return in.readLine().split(" ");
	}

	public static long[] toLongArray(String[] tmp) throws Exception{
		long[] ret = new long[tmp.length];
		for(int i=0;i<tmp.length;i++){
			ret[i] = Long.parseLong(tmp[i]);
		}
		return ret;
	}
	public static long[] toLongArray(BufferedReader in) throws Exception{
		return toLongArray(readLineArray(in));
	}
	public static String readLine(BufferedReader in) throws Exception{
		return in.readLine();
	}
	public static long toLong(String tmp) throws Exception{
		long ret = Long.parseLong(tmp);
		return ret;
	}
	public static long toLong(BufferedReader in) throws Exception{
		return toLong(readLine(in));
	}



}


Measured memory_bytes: 21332
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.00001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

double area(double ax, double ay, double bx, double by, double cx, double cy)
{
  double sum;
  double len1,len2,len3;

  len1=sqrt( (ax-bx)*(ax-bx) + (ay-by)*(ay-by) );
  len2=sqrt( (ax-cx)*(ax-cx) + (ay-cy)*(ay-cy) );
  len3=sqrt( (bx-cx)*(bx-cx) + (by-cy)*(by-cy) );

  double s=(len1+len2+len3)/2;

  sum=sqrt(s*(s-len1)*(s-len2)*(s-len3));

  return sum;
}


int main()
{
  double x1,x2,x3,y1,y2,y3,px,py;
  double s1,s2,s3,s4;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
	      &x1,&y1,&x2,&y2,&x3,&y3,&px,&py)!=EOF){

    s1=area(x1,y1,x2,y2,px,py);
    s2=area(x1,y1,x3,y3,px,py);
    s3=area(x2,y2,x3,y3,px,py);
    s4=area(x1,y1,x2,y2,x3,y3);

    if(s1+s2+s3-s4<EPS)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;

  }
}

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

vector<pair<int, int> > adj[100005];
int dist[100005];
int ft = 0;

void dfs(int v, int p = -1) {
  //printf("DFS v=%d p=%d\n", v, p);
  if (p == -1) dist[v] = 0, ft = v;
  if (dist[v] > dist[ft]) ft = v;
  for (auto h : adj[v])
    if (h.first != p) {
      dist[h.first] = dist[v] + h.second;
      dfs(h.first, v);
    }
}

int main() {
  int n; cin >> n;
  for (int i = 1; i < n; i++) {
    int s, t, w; cin >> s >> t >> w;
    adj[s].push_back({t, w});
    adj[t].push_back({s, w});
  }
  dfs(0);
  dfs(ft);
  cout << dist[ft] << endl;
}



Measured memory_bytes: 13616
import itertools

a,b,c,d,e,f = map(int,input().split())

A = list(range(0,101))
B = list(range(0,101))
ptr = list(itertools.product(A, repeat=2))
ptr2 = list(itertools.product(B, repeat=2))

tmp = 0
ans = [0,0]

for a1,b1 in ptr:
    for c1,d1 in ptr2:
        if (a*a1+b*b1) * e >= c * c1 + d * d1 and (a*a1+b*b1) * 100 + c * c1 + d * d1 <= f:
            if tmp*(a*a1+b*b1) <= (c * c1 + d * d1) and not (a1 == 0 and b1 == 0 and c1 == 0 and d1 == 0):
                tmp = (c * c1 + d * d1)/(a*a1+b*b1)
                ans = [(a*a1+b*b1) * 100 + c * c1 + d * d1, c * c1 + d * d1]

print(ans[0], ans[1])


Measured memory_bytes: 44848
#include<iostream>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;

int main() {
double x1, y1, x2, y2;
cin >> x1 >> y1 >>x2 >>y2;
double d;
d = sqrt(pow(x1 - x2,2) +pow(y1 - y2,2));
cout <<fixed << setprecision(5) << d <<endl;
return 0;
}


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

#define MEM(a, b) memset(a, b, sizeof a);
#define REP(i, k) for(int i = (0); i < (k); i++ )

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define debug puts("FANGO")
#define INF (int)INT_MAX
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007
#define endl "\n"

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef long long int32;
typedef unsigned long long uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

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

void solve(__attribute__((unused)) int tc = 0) {
  int n;
  cin >> n;

  vi v;
  REP(i, n) {
    int x;
    cin >> x;
    v.pb(x);
  }

  vi c;
  REP(i, n) {
    int x;
    cin >> x;
    c.pb(x);
  }

  int ans = 0;
  REP(i, n) {
    if (v[i] - c[i] < 0) continue;
    ans += v[i] - c[i];
  }
  cout << ans <<endl;
  
  return;
}

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  /*int TC;
  cin >> TC;
  REP(tc, TC) {
    solve(tc);
  }*/
  solve();
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 305;
int n, k;
string s;
char tmp[maxn];

int read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  n = sz(s);
  scanf("%d", &k);
  return true;
}

int dp[maxn][maxn], ndp[maxn][maxn];

void solve() {
  for (int it = 0; it <= k; it++) {
    for (int i = 0; i < n; i++) {
      ndp[i][i + 1] = 1;
    }
    for (int len = 2; len <= n; len++) {
      for (int i = 0; i + len <= n; i++) {
        auto &cur = ndp[i][i + len];
        cur = max(ndp[i][i + len - 1], ndp[i + 1][i + len]);
        if (s[i] == s[i + len - 1]) {
          cur = max(cur, ndp[i + 1][i + len - 1] + 2);
        }
        if (it) {
          cur = max(cur, dp[i + 1][i + len - 1] + 2);
        }
      }
    }
    swap(dp, ndp);
  }
  printf("%d\n", dp[0][n]);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <unordered_map>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

int N,M,V;
vector<pii> E[800500];
int timer = 0;
int dist[800500];
int main(){
	scanf("%d%d",&N,&M);
	timer = N;
	map<pii,int> mp;
	mp[{1,-1}] = ++timer; E[mp[{1,-1}]].push_back({1,0});
	int st = timer;
	mp[{N,-1}] = ++timer; E[N].push_back({mp[{N,-1}],0});
	int en = timer;


	for(int i=1;i<=M;i++){
		int x,y,z; scanf("%d%d%d",&x,&y,&z);
		
		// x<->y
		int v = ++timer;
		E[x].push_back({v,1}); E[y].push_back({v,1});
		E[v].push_back({x,0}); E[v].push_back({y,0});

		if( mp[{x,z}] == 0 ) mp[{x,z}] = ++timer;
		if( mp[{y,z}] == 0 ) mp[{y,z}] = ++timer;
		E[mp[{x,z}]].push_back({v,0});
		E[mp[{y,z}]].push_back({v,0});
		E[v].push_back({ mp[{x,z}], 0});
		E[v].push_back({ mp[{y,z}], 0});
	
	}

	int V = timer;
	for(int i=1;i<=timer;i++) dist[i] = 1e9;
	dist[st] = 0;
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	pq.push({0, st});

	while( !pq.empty() ){
		int cur = pq.top().Se, curd = pq.top().Fi;
		pq.pop();
		if( dist[cur] < curd ) continue;
		for(auto e : E[cur]){
			if( dist[e.Fi] > dist[cur]+e.Se ){
				dist[e.Fi] = dist[cur]+e.Se;
				pq.push({dist[e.Fi],e.Fi});
			}
		}
	}

	printf("%d\n",dist[en]<1e8?dist[en]:-1);
}













Measured memory_bytes: 76020
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
string s,p[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>s;
    for(i=0;i<7;i++)
    {
        if(p[i]==s)
        {
            cout<<(7-i)<<"\n";
            return 0;
        }
    }
}



Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
using namespace std;


int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;

    vector<double> s(n);
    for(int i=0; i<n; i++) cin >> s[i];

    double ave = accumulate(s.begin(), s.end(), 0.0) / n;

    double sgm = 0.0;
    for(int i=0; i<n; i++){
      sgm += ( s[i] - ave )*(s[i] - ave);
    }
    sgm /= n;

    double sd = sqrt(sgm);

    // cerr << " " << ave << " " << sgm << " " << sd << endl;

    printf("%.8lf\n", sd);

  }


  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};



struct P{
  ld x,y;
};

const ll MAX_N=50;
ll n;
vector<P> v(MAX_N);

ld dist(P a, P b){
  ld xd=a.x-b.x;
  ld yd=a.y-b.y;
  return sqrt(xd*xd+yd*yd);
}

ld f(P p){
  ld res=0;
  REP(i,n)
    res=max(res,dist(p,v[i]));
  return res;
}

ld fx(ld x){
  ld l=0;
  ld r=1000;
  REP(i,80){
    ld gl=(l*2+r)/3.0;
    ld gr=(l+r*2)/3.0;
    if(f(P{x,gl})<f(P{x,gr}))
      r=gr;
    else
      l=gl;
  }

  return f(P{x,l});
}

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

  cin>>n;
  REP(i,n)cin>>v[i].x>>v[i].y;

  ld l=0;
  ld r=1000;
  REP(i,80){
    ld gl=(l*2+r)/3.0;
    ld gr=(l+r*2)/3.0;
    if(fx(gl)<fx(gr))
      r=gr;
    else
      l=gl;
  }

  cout<<Decimal;
  cout<<fx(l)<<endl;


}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

#define MAXN 500009
#define MAXP 1050000

int aint[MAXP];
int heap[MAXN], osal[MAXN], sef[MAXN];
int v[MAXN], ans[MAXN];

int poz, left, right, val;
int n, m, k;

void dfs(int p, int st, int dr){
    if(st==dr) aint[p]=st;
    else{
        int m=(st+dr)/2;
        dfs(2*p, st, m);
        dfs(2*p+1, m+1, dr);
        if(v[aint[2*p]]>v[aint[2*p+1]])
            aint[p]=aint[2*p];
        else aint[p]=aint[2*p+1];
    }
}

void update(int p, int st, int dr){
    if(st==dr) aint[p]=0;
    else{
        int m=(st+dr)/2;
        if(poz<=m) update(2*p, st, m);
        else update(2*p+1, m+1, dr);
        if(v[aint[2*p]]>v[aint[2*p+1]])
            aint[p]=aint[2*p];
        else aint[p]=aint[2*p+1];
    }
}

void query(int p, int st, int dr){
    if((left<=st)&&(dr<=right)){
        if(v[aint[p]]>v[val])
            val=aint[p];
    }else{
        int m=(st+dr)/2;
        if(left<=m) query(2*p, st, m);
        if(m<right) query(2*p+1, m+1, dr);
    }
}

inline int tata(int p){
    return p/2;
}

inline int fiust(int p){
    return 2*p;
}

inline int fiudr(int p){
    return 2*p+1;
}

inline void mySwap(int p, int q){
    int aux=heap[p];
    heap[p]=heap[q];
    heap[q]=aux;
    sef[heap[p]]=p;
    sef[heap[q]]=q;
}

inline void urcare(int p){
    if(p>heap[0]) return ;
    while((p>1)&&(heap[p]>heap[tata(p)])){
        mySwap(p, tata(p));
        p=tata(p);
    }
}

inline void coborare(int p){
    int q;
    bool f=1;
    while((f)&&(fiust(p)<=heap[0])){
        q=fiust(p);
        if((fiudr(p)<=heap[0])&&(heap[fiudr(p)]>heap[q]))
            q=fiudr(p);
        if(heap[q]>heap[p]){
            mySwap(p, q);
            p=q;
        }else f=0;
    }
}

inline void scoate(int x){
    if(sef[x]!=0){
        int a=heap[heap[0]];
        heap[sef[x]]=heap[heap[0]];
        sef[heap[sef[x]]]=sef[x];
        heap[0]--;
        sef[x]=0;
        urcare(sef[a]);
        coborare(sef[a]);
    }
}

inline void baga(int x){
    sef[x]=heap[0]+1;
    heap[++heap[0]]=x;
    urcare(heap[0]);
}

inline void calc(int u){
    if(osal[u]!=0){
        left=osal[u]-k+1;
        right=osal[u]+k-1;
        val=0;
        query(1, 1, n);
        if(val==osal[u])
            baga(osal[u]);
    }
}

int main(){
    scanf("%d%d", &n, &k);

    for(int i=1; i<=n; i++)
        scanf("%d", &v[i]);

    dfs(1, 1, n);

    m=(n+k-1)/k;
    for(int i=1; i<=m; i++){
        osal[i]=(i-1)*k+1;
        for(int j=(i-1)*k+2; j<=i*k; j++)
            if(v[j]>v[osal[i]])
                osal[i]=j;
    }

    for(int i=m; i>0; i--)
        calc(i);

    for(int i=n; i>0; i--){
        int x=heap[1];

        scoate(x);

        ans[x]=i;

        poz=x;
        update(1, 1, n);

        int u=(x-1)/k+1;
        left=(u-1)*k+1;
        right=u*k;

        scoate(osal[u-1]);
        scoate(osal[u+1]);

        val=0;
        query(1, 1, n);

        osal[u]=val;

        calc(u);
        calc(u-1);
        calc(u+1);
    }

    for(int i=1; i<=n; i++)
        printf("%d\n", ans[i]);

    return 0;
}


Measured memory_bytes: 17408
package main

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

func main() {
	K, N := readI(), readI()
	A := readIs(N)
	sort.Ints(A)

	dis := make([]int, N)
	for i := 0; i < N-1; i++ {
		dis[i] = A[i+1] - A[i]
	}
	dis[N-1] = A[0] + K - A[N-1]
	fmt.Println(K - max(dis))
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

/*-----------Utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-2.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}


Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

//		long ans2 = 0;
		long ans = 0;
//		int ans = 0;

		Scanner sc = new Scanner(System.in);


		int n = sc.nextInt();
//		int x = sc.nextInt();
//		int y = sc.nextInt();

//		String string = sc.next();
//		StringBuilder s = new StringBuilder(string);

//		boolean f = true;
//
		long[] a = new long[n];
//		int[] b = new int[n];
//		int[] aa = new int[n];
//		int[] bb = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
//		for (int i = 0; i < n; i++) {
//			b[i] = sc.nextInt();
//			bb[i] = b[i];
//		}


		long r = 0;
		long l = 0;
		int index = n;
		int tmp = 0;

		if(n % 2 == 0) {
			for(int i =0; i<index; i++) {
				r += a[i];
				if(r > l) {
					while(r > l) {
						index--;
						if(i==index) break;
						l += a[index];
					}
				}
			}
		} else {
			for(int i =0; i<index; i++) {
				tmp = i;
				r += a[i];
				if(r > l) {
					while(r > l) {
						index--;
						if(i==index) break;
						l += a[index];
					}
				}
			}
//			l = l - a[tmp];
		}

		ans = Math.abs(r-l);

//		System.out.println(r);
//		System.out.println(l);
		System.out.println(ans);

		sc.close();
	}
}

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

using std::cin;
using std::cout;
using std::endl;

template<class T,class F>
struct segment_tree{
  std::vector<T> data;
  int n;
  F f;
  T identity;
  segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){
    n = 1;
    while(n<sz)n<<=1;
    data.resize(2*n,identity);
  }
  void set(int i,T x){
    i += n;
    data[i] = x;
    while(i){
      i>>=1;
      data[i] = f(data[i<<1|0],data[i<<1|1]);
    }
  }
  T query(int l,int r)const{
    l += n, r += n;
    T x = identity;
    while(l<r){
      if(l&1)x = f(x,data[l++]);
      if(r&1)x = f(x,data[--r]);
      l>>=1, r>>=1;
    }
    return x;
  }
  T operator[](int i)const{
    return data[i+n];
  }
};
template<class T,class F>
auto make_segtree(int n,T ide,F f){
  return segment_tree<T,F>(n,ide,f);
}

signed main(){
  int n;
  cin>>n;
  auto rmq = make_segtree<int64_t>(n,(1LL<<31)-1,[](int a,int b){return a<=b?a:b;});
  int q;
  cin>>q;
  while(q--){
    int com,x,y;
    cin>>com>>x>>y;
    if(com==0){
      rmq.set(x,y);
    }else{
      cout<< rmq.query(x,y+1) <<endl;
    }
  }
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7
#define MAX_V

ll euclid(ll a, ll b )
{
    ll temp;

    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return euclid( b, a % b );
}

int main(){
    ll a, b;
    cin>>a>>b;

    ll max_koyakusu = euclid(a, b);
    vector<ll> yakusu;

    //cout<<max_koyakusu<<endl;

    for(ll i=1; i<=(ll)sqrt(max_koyakusu); i++){
        if(max_koyakusu%i == 0){
            yakusu.push_back(max_koyakusu/i);
            yakusu.push_back(i);
        }
    }

    sort(yakusu.begin(), yakusu.end());

    ll ans = 1;
    ll gcd = 1;

    if(yakusu[0] == 1 && yakusu[1] == 1){
        cout<<"1"<<endl;
        return 0;
    }

    for(ll i=1; i<yakusu.size(); i++){
        if(euclid(gcd, yakusu[i]) == 1){
            ans++;
            gcd *= yakusu[i];
        }
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		N += 2;
		bo = new bool[2,N];
		memo = new long[2,N];
		
		AA = new long[N];
		AA[0] = Z; AA[1] = W;
		for(int i=0;i<N-2;i++) AA[i+2] = A[i];
		
		Console.WriteLine(dfs(0,1));
		
		
	}
	
	long dfs(int t, int l){
		if(bo[t, l]) return memo[t, l];
		
		if(t == 0){
			long max = Math.Abs(AA[N-1] - AA[l]);
			for(int i=l+1;i<N-1;i++){
				max = Math.Max(max, dfs(1,i));
			}
			bo[t, l] = true;
			return memo[t,l] = max;
		}
		if(t == 1){
			long min = Math.Abs(AA[N-1] - AA[l]);
			for(int i=l+1;i<N-1;i++){
				min = Math.Min(min, dfs(0,i));
			}
			bo[t, l] = true;
			return memo[t,l] = min;
		}
		return 0;
		
		
		
	}
	
	long[,] memo;
	long[] AA;
	bool[,] bo;
	
	int N;
	long Z,W;
	long[] A;
	public Sol(){
		var d = ria();
		N = d[0]; Z = d[1]; W = d[2];
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13292
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;



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

	for (long long int i = 1; i*i <= N; i++) {
		if (N%i == 0) { ans = i + N / i -2; }
	}

	cout << ans;

	system("PAUSE");
}



Measured memory_bytes: 504
#include <stdio.h>
int main(){
 int K,A,B;
 int flag=0;
 scanf("%d",&K);
 scanf("%d %d",&A,&B);
 for(int i=A;i<=B;i++){
 if(i%K==0)flag=1;
 }
 if(flag==1)printf("OK");
  else printf("NG");
 return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> k(m);
    vector<vector<int>> s(10,vector<int>(10));

    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j]; 
            s[i][j]--;
        }
    }

    vector<int> p(m);
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }
    
    int ans = 0;

    for(int bit = 0; bit < (1 << n); bit++){//bit全探索
        int cnt = 0;
        for(int i = 0; i < m; i++){//電球について全探索
            int num_sw = 0;
            for(int j = 0; j < n; j++){
                if(bit & (1 << j)){//jが点灯
                    for(int l = 0; l < k[i]; l++){//jがsにあるか探索
                        if(s[i][l] == j){
                            num_sw++;
                        }
                    }
                }
            }
            if(num_sw%2==p[i]){
                cnt++;
            }
        }
        if(cnt == m){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(N: int, A: "List[int]"):
    from collections import Counter
    c = Counter(A)
    if len([k for k,v in c.items() if v != 1]) == 0:
        print(YES)
    else:
        print(NO)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 46256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict
from operator import itemgetter

n = SI()
dicts = []
for i in range(n):
    s, p = LS()
    p = int(p)
    dicts.append((i+1, s, p))
dicts = sorted(dicts, key=lambda x:(x[1],-x[2]))
for i, s, p in dicts:
    print(i)

Measured memory_bytes: 3420
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int n, i;
  vector<ll> a;
  ll ans = 1, tmp;
  bool b = 0;

  cin >> n;
  a.resize(n);
  for(i=0;i<n;i++){
    cin >> a[i];

    if(a[i]==0){
      b = 1;
    }
  }

  if(b){
    cout << 0 << endl;
    return 0;
  }

  for(i=0;i<n;i++){
    if(ll(1e18)/a[i]<ans){
      cout << -1 << endl;
      return 0;
    }
    else ans *= a[i];
  }

  cout << ans << endl;

  return 0;
}


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

int group(int n)
{
  if (n == 2) return 0;
  if (n == 4 || n == 6 || n == 9 || n == 11) return 1;
  return 2;
}

int main()
{
  int x, y;
  cin >> x >> y;
  
  string ans = "No";
  if (group(x) == group(y)) ans = "Yes";
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#define M 51000
n[M];main(i,j){n[0]=n[1]=1;for(i=2;i<M;i++)if(!n[i])for(j=i*2;j<M;j+=i)n[j]=1;for(;~scanf("%d",&i);printf("%d %d\n",i,j)){for(j=i+1,i--;n[i];i--);for(;n[j];j++);}return 0;}

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

int main() {
  long double A, B, H, M, pi;
  cin >> A >> B >> H >> M;
  pi = 3.1415926535897932384626433832795028;
  long double Dh = H / 12 + M / 60 / 12;
  long double Dm = M / 60;
  long double ma = max(Dh, Dm);
  long double mi = min(Dh, Dm);
  long double D = ma - mi;
  D *= 2 * pi;
  cout << fixed << setprecision(18);
  cout << sqrt(A * A + B * B - 2 * A * B * cos(D)) << endl;
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans;
  cin >> n;
  long long a[n];
  double ave,mindis=10000;
  for(int i=0;i<n;i++){
    cin >> a[i];
    ave+=a[i];
  }
  ave/=(double)n;
  for(int i=0;i<n;i++){
    if(mindis>abs(ave-(double)a[i])){
      mindis=abs(ave-(double)a[i]);
      ans=i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0xfff;
const ll maxs = 1e18;
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);
}
ll a[1000005];
int main()
{
	ios::sync_with_stdio(false);
	ll a;
	long double b;
	cin >> a >> b;
	ll aa = a * b;
	cout << aa << endl;
}

Measured memory_bytes: 3708
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, n = list(map(int, input().rstrip('\n').split()))
    ab = []
    ma = 0
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        ab.append([a, b])
        ma = max(ma, a)
    ls = [10 ** 10] * (h + 1 + ma)
    ls[0] = 0
    for i in range(n):
        for j in range(h):
            ls[j+ab[i][0]] = min(ls[j] + ab[i][1], ls[j+ab[i][0]])
    print(min(ls[h:]))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> X(5);
  rep(i, 5) cin >> X[i];
  rep(i, 5) {
    if(X[i] == 0) cout << i+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll a[m] = {};
    rep(i,m){
        scanf("%lld",&a[i]);
    }

    ll ans = 0;
    if(n>=m){
        cout << ans << endl;
        return 0;
    }

    sort(a,a+m);
    ll b[m-1] = {};
    rep(i,m-1){
        b[i] = a[i+1] - a[i];
    }
    sort(b,b+(m-1));

    rep(i,m-n){
        ans += b[i];
    }




    
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 1792
n, x, y = map(int, input().split())
ans = [0 for i in range(n)]
for i in range(1,n+1):
  for j in range(i+1,n+1):
    d = min(j-i, abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1)
    ans[d] += 1
for a in ans[1:]:
  print(a)

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

int main(){
    int n,cnt=0;
    string s;
    cin >> n >> s;
    rep(i,n){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            cnt++;
        }
    }
    cout<< cnt << endl;
    return 0;
}


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

int main(){
	int N;
	cin >> N;
  	bool flag = 0;
	for(int i=0; i < N; i++){
    	char S;
      	cin >> S;
      	if(S == 'Y')
          flag++;
    }
  	cout << (flag?"Four":"Three") << endl;

}

Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val a = Array.fill(n){readLine.trim}
  val b = Array.fill(n){readLine.trim}
  println(
    (0 until n).map(y ⇒ (0 until m).count(x ⇒ a(y)(x) != b(y)(x))).sum
  )
}



Measured memory_bytes: 128496
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
using namespace std;
const int maxn = 1e2 + 10;
int s[maxn][maxn], light[maxn], p[maxn], n, m, k[maxn] = {0};
int main(){
    scanf("%d%d", &n, &m);
    memset(s, 0, sizeof(s));
    for(int i = 0; i < m; i++){
        scanf("%d", &k[i]);
        for(int j = 0; j < k[i]; j++){scanf("%d", &s[i][j]);}
    }
    for(int i = 0; i < m; i++){
        scanf("%d", &p[i]);
    }
    int total = 0;
    for(int i = 0; i < (1 << n); i++){
        bool ok = true;
        for(int j = 0; j < m; j++){
            int can = 0;
            for(int h = 0; h < k[j]; h++){
                int a1 = 1 << (s[j][h] - 1);
                if(i & a1){can++;}
            }
            if(can % 2 != p[j]){
                ok = false;
                break;
            }
        }
        if(ok){total++;}
    }
    printf("%d", total);
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = []
n.times do
  a.push(gets.chomp.to_i)
end

max_gap = -Float::INFINITY
low = a[0]

for i in 1..a.size-1
  if a[i] - low > max_gap
    max_gap = a[i] - low
  end
  if a[i] < low
    low = a[i]
  end
end

puts max_gap

Measured memory_bytes: 7804
using System;

public class Hello{
    public static void Main(){
        // Your code here!
        string Ns= System.Console.ReadLine();
        
        //System.Console.WriteLine("Hello C#");

        double N=double.Parse(Ns);
        double money=100;
        

        double count=0;
        while (N>money)
        {
            money*=1.01;
            money=Math.Floor(money);
            count+=1;
        }
        
        System.Console.WriteLine(count);
        
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    int A;
    cin >> A;
    a.at(i)=A-1;
  }
  int now=0;
  int ans=-1;
  for(int i=0; i<N; i++){
    if(a.at(now)==1){
      ans=i+1;
      break;
    }
    now=a.at(now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n];
    rep(i,0,n) cin>>a[i];
    int dp[400][400];
    rep(i,0,400) rep(j,0,400) dp[i][j]=1000000000000000005;
    int l=0,r=1;
    while(r<=n-1){
        dp[l][r]=a[l]+a[r];
        l++;
        r++;
    }
    int cum[n+1];
    cum[0]=0;
    rep(i,1,n+1) cum[i]=a[i-1];
    rep(i,1,n+1) cum[i]+=cum[i-1];
    rep(i,0,n) dp[i][i]=0;
    rep(i,2,n){
        l=0,r=l+i;

        while(r<=n-1){
            rep(k,l,r){

                dp[l][r]=min(dp[l][r], dp[l][k]+dp[k+1][r]);
            }
            //cout<<dp[l][r]<<endl;
            dp[l][r]+=cum[r+1]-cum[l];
            l++;
            r++;
        }
    }
    cout<<dp[0][n-1];



}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds; 
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif



  

 
int main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    IOS;
  
    int a, b, c, k;

    cin >> a>>b>>c>>k;

    if(b <= a)
    {
      while(b <= a)
      {
        b*=2;
        k--;
      }
    }

    if(c <= b)
    {
      while(b >= c)
      {
        c*=2;
        k--;
      }
    }

    if(k >=0 )
    {
      cout <<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
      


   


}

Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int n, c, w[110], v[110], memo[110][100010];

int dp(int pos, int val) {
	int ret = 1000000001;
	if (pos == 0) {
		if (val == 0)
			return 0;
		return ret;
	}
	if (memo[pos][val] != -1)
		return memo[pos][val];
	ret = min(ret, dp(pos - 1, val));
	if (val >= v[pos])
		ret = min(ret, dp(pos - 1, val - v[pos]) + w[pos]);
	memo[pos][val] = ret;
	return ret;
}

int main() {
	int sum = 0, ans;
	scanf("%d %d", &n, &c);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &w[i], &v[i]);
		sum += v[i];
	}
	memset(memo, -1, sizeof memo);
	for (int i = sum; i >= 0; i--)
		if (dp(n, i) <= c) {
			ans = i;
			break;
		}
	printf("%d\n", ans);
	return 0;
}

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

int main()
{
    int a, b, t, i;
    cin>>a>>b>>t;

    int bis = 0;

    for(i=a; i<=t+.5; i=i+a)
    {
        bis = bis + b;
    }

    cout<<bis;


}


Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())
    if H == W == 0:
        break
    for i in range(H):
        for p in range(W):
            if (i + p) % 2 == 0:
                print("#", end = "")
            else:
                print(".", end = "")
            
        print()
        
    print()
        


Measured memory_bytes: 7008
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

class StronglyConnectedComponents:
    def __init__(self,N):
        self.N = N
        self.G = [[] for _ in range(self.N)]
        self.rG = [[] for _ in range(self.N)]
        self.group = [1] * self.N
        self.order = []
    
    def add_edge(self,u,v): # u -> v
        self.G[u].append(v)
        self.rG[v].append(u)
    
    def build(self):
        stack = []
        for s in range(self.N):
            if self.group[s] > 0:
                stack.append(s + 1)
                while stack:
                    v = stack.pop()
                    if v < 0:
                        self.order.append(- v - 1)
                    else:
                        if self.group[v - 1] > 0:
                            stack.append(-v)
                            self.group[v - 1] = -1
                            for e in self.G[v - 1]:
                                stack.append(e + 1)
        
        cnt = 0
        for s in self.order[::-1]:
            if self.group[s] < 0:
                stack.append(s)
                self.group[s] = cnt
                while stack:
                    v = stack.pop()
                    for e in self.rG[v]:
                        if self.group[e] < 0:
                            self.group[e] = cnt
                            stack.append(e)
                cnt += 1
    
    def __getitem__(self,i):
        if 0 <= i < self.N:
            return self.group[i]
        else:
            raise ValueError("StrongglyConnectedComponents index out of range")

def main():
    V,E = map(int,input().split())
    scc = StronglyConnectedComponents(V)
    for _ in range(E):
        a,b = map(int,input().split())
        scc.add_edge(a,b)
    scc.build()

    Q = int(input())
    ans = []
    for _ in range(Q):
        u,v = map(int,input().split())
        if scc[u] == scc[v]:
            ans.append('1')
        else:
            ans.append('0')
    print('\n'.join(ans))
if __name__ == '__main__':
    main()


Measured memory_bytes: 10684
#include <stdio.h>
#include <limits.h>

/* 多分総当たりで間に合う */
int main(int argc, char *argv[])
{
    int i, j, N, list[100];
    long long min = LLONG_MAX, v;

    scanf("%d", &N);
    for ( i = 0; i < N; i++ ){
        scanf("%d", &list[i]);
    }

    for ( i = -100; i <= 100; i++ ){
        for ( j = 0, v = 0; j < N; j++ ){
            v += (list[j] - i)*(list[j] - i);
        }
        if ( min > v ){
            min = v;
        }
    }
    printf("%lld\n", min);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define N 44
int main() {
int i,n;
int f[N+1];
scanf("%d",&n);
f[0] = f[1] = 1;

for(i=2;i<=n;i++){
  f[i] = f[i-1]+f[i-2];
}
printf("%d\n",f[n]);
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;

#define LL long long

const int MAXN = 500000 + 5;



int main()
{
    int a[MAXN], N, i;
    LL ans = 0;
    cin >> N;
    for (i = 0; i < N; i ++){
        cin >> a[i];
    }
    for (i = 1; i < N; i ++){
        if (a[i] < a[i - 1]){
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    cout << ans;
    system("pause");
    return 0;
}

Measured memory_bytes: 4424
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long lint;

lint solve(lint n, lint k){
    lint ret = 0;
    lint l;
    if(k % 2 == 0){
        l = n / k;
        ret = l * l * l;
        l = 0;
        for (lint i = 1; i <= n; ++i){
            if(i % k != 0 && i % (k / 2) == 0){
                l++;
            }
        }
        ret += l * l * l;
    }
    else {
        l = n / k;
        ret = l * l * l;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    cout << solve(n, k) << endl;
    return 0;
}

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

int main() {
    string s,t;
    cin>>s>>t;
    
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<int>());
    if(s<t)cout<<"Yes";
    else cout<<"No";
    
    return 0;
    }

Measured memory_bytes: 3608
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Thu Jan  3 17:22:37 2019
//
package main

import "fmt"

func main() {
	var A, B, C, D int
	fmt.Scan(&A, &B, &C, &D)

	if A+B == C+D {
		fmt.Println("Balanced")
	} else if A+B > C+D {
		fmt.Println("Left")
	} else {
		fmt.Println("Right")
	}
}


Measured memory_bytes: 512
#
K,X = map( int, input().split())
n = K - 1
spos = X - n
epos = X + n 

if spos < -1000000:
    spos = -1000000
if epos > 1000000:
    epos = 1000000

for i in range(spos,epos+1,1):
    print(i,end=' ')


Measured memory_bytes: 3060