akhauriyash/Code-Regression huggingface dataset:
from collections import deque
n,k = map(int,input().split())
a = list(map(int,input().split()))
k -= 1
mnlist = []
q = deque([0])
for i in range(1,k):
  while q:
    x = q.pop()
    if a[i]>a[x]:
      q.append(x)
      q.append(i)
      break
  if not q:
    q.append(i)

for i in range(k,n+1):
  t = q.popleft()
  mnlist.append(a[t])
  if t != i-k:
    q.appendleft(t)
  if i == n:
    break
  while q:
    x = q.pop()
    if a[i]>a[x]:
      q.append(x)
      q.append(i)
      break
  if not q:
    q.append(i)
mxlist = []
q = deque([0])
for i in range(1,k):
  while q:
    x = q.pop()
    if a[i]<a[x]:
      q.append(x)
      q.append(i)
      break
  if not q:
    q.append(i)

for i in range(k,n+1):
  t = q.popleft()
  mxlist.append(a[t])
  if t != i-k:
    q.appendleft(t)
  if i == n:
    break
  while q:
    x = q.pop()
    if a[i]<a[x]:
      q.append(x)
      q.append(i)
      break
  if not q:
    q.append(i)
ans = n-k
r = set()
for i in range(1,n-k):
  if a[i-1]<mnlist[i] and mxlist[i]<a[i+k]:
    r.add(i)
flg = 0
flg2 = 0
for i in range(1,n):
  if a[i-1] < a[i]:
    flg += 1
  else:
    flg = 0
  if flg >= k:
    r.add(i-k)
    flg2 = 1
print(ans-len(r)+flg2)

Measured memory_bytes: 103164
#include<cstdio>
#include<algorithm>
using namespace std;

#define MAXC 30
#define MAXN 500
#define INF 2147483647
int N,C;
int W[MAXN+5][MAXN+5],Num[3][MAXC+5];

int main(){
    scanf("%d%d",&N,&C);
    for(int i=1;i<=C;i++)
        for(int j=1;j<=C;j++)
            scanf("%d",&W[i][j]);
    for(int i=1;i<=N;i++)
        for(int j=1;j<=N;j++){
            int Color;
            scanf("%d",&Color);
            Num[(i+j)%3][Color]++;
        }
    int Ans=INF,T[3];
    for(T[0]=1;T[0]<=C;T[0]++){
        for(T[1]=1;T[1]<=C;T[1]++){
            if(T[0]==T[1]) continue;
            for(T[2]=1;T[2]<=C;T[2]++){
                if(T[0]==T[2]||T[1]==T[2]) continue;
                int Sum=0;
                for(int p=0;p<3;p++){
                    for(int q=1;q<=C;q++)
                        Sum+=Num[p][q]*W[q][T[p]];
                }
                Ans=min(Ans,Sum);
            }
        }
    }
    printf("%d",Ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;


int main()
{
    ll n;
    cin>>n;
    ll ans=1e18;
    ll m=sqrt(n+0.5);
    for(int i=1;i<=m;++i)
    {
        if(n%i==0)
            ans=min(ans,i+n/i);
    }
    cout<<ans-2;
    return 0;
}


Measured memory_bytes: 384
// I WILL FLY ONEDAY //1

#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007
using namespace std;

/*
check for corner cases(for n==1)
 check for int overflow
 run on some sample cases before submitting
*/

/*FERMAT THEOREM

       pow(x,m-1)%m=1 (x and m are co-prime)
*/
/*MODULAR INVERSE

        pow(x,-1)=pow(x,m-2) (x and m are co-prime)
*/

/*
ll  mode(ll x,ll n,ll mod)
{
    if(n==0)return 1%mod;

    ll u=mode(x,n/2,mod);
    u=(u*u)%mod;
    if(n & 1)u=(u*x)%mod;
}
*/

int main()
{
   fast;
   ll a;
   cin>>a;
    string s;
    cin>>s;
    if(a<3200)
        cout<<"red"<<endl;
    else
        cout<<s<<endl;
}











































































Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

        public static void insertSort(int arr[],int N) {
           for (int i = 0; i < N; i++){
               int v = arr[i];
               int j = i - 1;
               while (j >= 0 && arr[j] > v){
                   arr[j+1] = arr[j];
                   j--;
               }
               arr[j+1] = v;
               printArray(arr,N);
           }
        }

        public static void swap(int arr[], int i , int j){
            int tmp = arr[i];
            arr[i] = arr[j];
            arr[j] = tmp;
        }

        public static void printArray(int []arr , int N){
            System.out.print(arr[0]);
            for(int i = 1; i < N; i++) {
                System.out.print(" " + arr[i]);
            }
            System.out.println();
        }

        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int[] arr = new int[100];
            int N = in.nextInt();
                    for (int i = 0; i < N; i++) {
                        arr[i] = in.nextInt();
                    }
                    insertSort(arr,N);
                }

            }




Measured memory_bytes: 32632
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;

	if (S == "AAA" || S == "BBB") {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int n;
	n = readln.chomp.to!int;
	while (n) {
		auto a = new int[9][9];
		auto b = new int[9][9];
		auto c = new int[9][9];
		auto ans = new bool[9][9];
		int s, t;
		foreach (i; 0..9) {
			a[i] = readln.split.map!(to!int).array;
			c[s][(i%3)*3..(i%3)*3+3] = a[i][0..3];
			c[s+1][(i%3)*3..(i%3)*3+3] = a[i][3..6];
			c[s+2][(i%3)*3..(i%3)*3+3] = a[i][6..9];
			foreach (j; 0..9) {
				b[j][i] = a[i][j];
			}
			if ((i+1) % 3 == 0) s += 3;
			t = ++t % 3;
		}

		foreach (i; 0..9) {
			foreach (j; 0..9) {
				foreach (k; 0..9) {
					if (j == k) continue;
					if (a[i][j] == a[i][k]) ans[i][j] = ans[i][k] = 1;
					if (b[i][j] == b[i][k]) ans[j][i] = ans[k][i] = 1;
					if (c[i][j] == c[i][k]) ans[i/3*3 + j/3][(i%3)*3 + (j%3)] = ans[i/3*3 + k/3][(i%3)*3 + (k%3)] = 1;
				}
			}
		}

		foreach (i; 0..9) {
			foreach (j; 0..9) {
				write(ans[i][j] ? "*" : " ", a[i][j]);
			}
			writeln("");
		}
		if (--n) writeln("");
	}
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,w,i,j;
    long long int a[105][2],dp[101][100005];
    cin>>n>>w;
    for(i=1;i<=n;i++)
    cin>>a[i][0]>>a[i][1];
    for(i=0;i<=w;i++)
    dp[0][i]=0;
    for(i=0;i<=n;i++)
    dp[i][0]=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(j>=a[i][0])
            dp[i][j]=max(dp[i-1][j],a[i][1]+dp[i-1][j-a[i][0]]);
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w];
    return 0;


}

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



# import time, random
# start = time.time()
import time
start = time.time()

D = int(input())
c = list(map(int, input().split()))
s = [None]*D
for i in range(D):
    s[i] = list(map(int, input().split()))
    
current = [0]*26
ans = [None]*D
from itertools import permutations
def sub(vvs, i):
    best = -1
    bestinds = None
    for inds in permutations(range(len(vvs))):
        v = 0
        for ii, ind in enumerate(inds):
            v += s[i+ii][ind]
        if v>best:
            best = v
            bestinds = inds
    return bestinds[0]

def greedy(weight=1.0, diff=1):
    ans = [None]*D
    for i,ss in enumerate(s):
        vs = [None]*26
        for j in range(26):
            vs[j] = (ss[j] + current[j]*weight, j)
            current[j] += c[j]
        vs.sort()
        if diff==1 or i+diff>=D:
            v = vs[-1][1]
        else:
            vvs = [item[1] for item in vs[-diff:]]
            v = sub(vvs, i)
        ans[i] = v+1
        current[v] = 0
    return ans
def val(ans, c):
    current = [0]*26
    val = 0
    for i,(ss, v) in enumerate(zip(s, ans)):
        for j in range(26):
            current[j] += c[j]
        current[v-1] = 0
        val += ss[v-1] - sum(current)
    return val

ans = greedy()
best = ans
bval = val(ans, c)
num = 2
ren = 0
w = 1.0

for diff in [1]:
    for w in range(0, 5000, 10):
        weight = w/100
        tmpans = greedy(weight, diff)
        tmpval = val(tmpans, c)
        if tmpval>bval:
            bval = tmpval
            best = tmpans
            bw = weight
        if time.time() - start >= 1.8:
            break
    if time.time() - start >= 1.8:
        break
#         print(bval)
    
write("\n".join(map(str, best)))

Measured memory_bytes: 71820
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
public class Main {
	public static void main(String args[]) {
		Sc sc = new Sc(System.in);
		int N = sc.nI();
		int x = sc.nI();

		int[] a = new int[N];
		long sum = 0;
		for(int i = 0; i<N; i++) {
			a[i] = sc.nI();
			sum+= a[i];
		}
		while(true) {
			long diff = 0;
			int newa[] = new int[N];
			for(int i = 0; i<N; i++) {
				int prev = (i + N - 1)%N;
				if(a[i] > a[prev]) {
					diff += a[i] - a[prev];
					newa[i] = a[prev];
				} else {
					newa[i] = a[i];
				}
			}
			if(diff>x) {
				sum -= diff - x;
				a = newa;
			} else {
				break;
			}
		}
		System.out.println(sum);
	}
}
class Sc {
    public Sc(InputStream i) {
        r = new BufferedReader(new InputStreamReader(i));
    }

    public boolean hasM() {
        return peekToken() != null;
    }

    public int nI() {
        return Integer.parseInt(nextToken());
    }

    public double nD() { 
        return Double.parseDouble(nextToken());
    }

    public long nL() {
        return Long.parseLong(nextToken());
    }

    public String n() {
        return nextToken();
    }

    private BufferedReader r;
    private String line;
    private StringTokenizer st;
    private String token;

    private String peekToken() {
        if (token == null) 
            try {
                while (st == null || !st.hasMoreTokens()) {
                    line = r.readLine();
                    if (line == null) return null;
                    st = new StringTokenizer(line);
                }
                token = st.nextToken();
            } catch (IOException e) { }
        return token;
    }

    private String nextToken() {
        String ans = peekToken();
        token = null;
        return ans;
    }
}

Measured memory_bytes: 16460
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int secs = sc.nextInt();
            int hh = secs / (60 * 60);
            int hs = secs % (60 * 60);
            int mm = hs / 60;
            int ss = hs % 60;
            System.out.println(String.format("%d:%d:%d", hh, mm, ss));
        }
    }
}



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


#define lld long long 

lld max(lld x,lld y)
{
	if(x>y)
		return x;
	return y;
}		
lld min(lld x,lld y)
{

	if(x<y)
		return x;
	return y;
}

lld power(lld x, lld y) 
{ 
    lld temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
} 

void solve()
{
	lld n;
	cin>>n;
	long double dp[n+1][n+1];
	long double p[n+1];
	for(lld i=1;i<=n;i++)
		cin>>p[i];
	memset(dp,0.0,sizeof(dp));
	dp[0][0]=1.0;
	for(lld i=1;i<=n;i++)
	{
		for(lld j=0;j<=n;j++)
		{
			if(j==0)
			{
				dp[i][j]=dp[i-1][j]*(1-p[i]);
			}
			else
			{
				dp[i][j]=(dp[i-1][j]*(1-p[i]))+(dp[i-1][j-1] *p[i]);
			}
		}
	}
	long double ans=0.0;
	for(lld i=((n+1)/2) ;i<=n;i++)
	{
		ans=ans+dp[n][i];
	}
	cout<<setprecision(12);
	cout<<ans<<"\n";

}
	
int main()
{

	solve();
	//cout<<x<<setprecision(8)<<"\n";
}

Measured memory_bytes: 140928
#include <iostream>

int main(){
	using namespace std;
	int a,i,r = 0,j,k;
	cin >> a;
	int b[a];
	for (i = 0; i < a; i++) {
		cin >> b[i];
	}

	for (j = 0; j < a; j++) {
		for (k = j+1; k < a; k++) {
			r += b[j] * b[k];
		}
	}

	cout << r << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
ll _gcd(ll a, ll b)
{
    return b != 0 ? _gcd(b, a % b) : a;
} 
ll divnumber(ll a, ll b, ll c){
  ll l=b*c/_gcd(b,c);
  return a/b+a/c-a/l;
}

int main()
{
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll a,b,c,d; cin >> a >> b >> c >> d;
  cout << b-a+1-(divnumber(b,c,d) - divnumber(a-1,c,d)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){

  string s;
  cin >> s;
  int x, pre, back;
  x =  stoi(s);//*10;// +stoi(s[1]);

  pre = x/100;
  back = x - pre*100;
  int ans = 0;
  if(1 <= pre  && pre <= 12) ++ans;
  if(1 <= back && back <= 12) ans += 2;


  if(ans == 3) cout << "AMBIGUOUS" << endl;
  if(ans == 2) cout << "YYMM" << endl;
  if(ans == 1) cout << "MMYY" << endl;
  if(ans == 0) cout << "NA" << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

int main(void){
int n;
int i = 0;
float x1,y1,x2,y2,x3,y3,x4,y4;
double a,b;
scanf("%d",&n);
while(scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4) != EOF){
if( i >= n )break;
a = (y2 - y1) / (x2 - x1);
b = (y4 - y3) / (x4 - x3);
if( a == b ){
printf("YES\n");
}else{
printf("NO\n");
}
i++;
}
return 0;
}

Measured memory_bytes: 616
#include <cstdio>
#include <algorithm>
#include <iostream>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
#define min(q,w) ((q)>(w)?(w):(q))
#define max(q,w) ((q)<(w)?(w):(q))
using namespace std;
const int N=200500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,ans;
int a[N];
int a1[N][2];
int Go(int q)
{
	if(q<1||q>n)return q;
	fo(i,1,m)
	{
		if(a[q]==a1[i][0])q+=a1[i][1];
		if(q<1||q>n)return q;
	}
	return q;
}
int main()
{
	int q,w,e;
	read(n),read(m);
	char ch=' ';
	for(;ch<'A'||ch>'Z';ch=getchar());
	fo(i,1,n)a[i]=ch,ch=getchar();
	fo(i,1,m)
	{
		ch=' ';
		for(;ch<'A'||ch>'Z';ch=getchar());
		a1[i][0]=ch;
		ch=getchar();
		ch=getchar();
		a1[i][1]=ch=='L'?-1:1;
	}
	
	int l=0,r=n;
	for(;l<r;)
	{
		int mid=(l+r+1)>>1;
		if(Go(mid)==0)l=mid;
		else r=mid-1;
	}
	q=l;
	l=1,r=n+1;
	for(;l<r;)
	{
		int mid=(l+r)>>1;
		if(Go(mid)==n+1)r=mid;
		else l=mid+1;
	}
	printf("%d\n",n-q-(n-l+1));
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <map>
using namespace std;

constexpr int al = 26;

int main(){
  int h, w; cin >> h >> w;
  char a[h+1][w+1];

  int cnt[26];
  for(int i=0; i<al; i++) cnt[i] = 0;

  for(int y=1; y<=h; y++){
    for(int x=1; x<=w; x++){
      cin >> a[y][x];
      cnt[a[y][x] - 'a']++;
    }
  }

  bool f = true;
  if(h % 2 && w % 2){
    int m1 = 0, m4 = 0;
    for(int i=0; i<al; i++){
      m4 += cnt[i] / 4;
      if(cnt[i] % 2) m1++;
  }

    if(m4 < (h/2) * (w/2) || m1 != 1) f = false;
  } 
  else if(h % 2 || w % 2){
    int m4 = 0;
    for(int i=0; i<al; i++){
      if(cnt[i] % 2 == 0){
        m4 += cnt[i] / 4;
      }
      else f = false;
    }
    if(m4 < (h/2) * (w/2)) f = false;
  }
  else{
    for(int i=0; i<al; i++){
      if(cnt[i] % 4) f = false;
    }
  }

  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();
    static final int MOD = 1000000007;

    public static void main(String[] args){
        int N = in.i();
        int[] A = in.ii();
        int[] memo = new int[N];
        for(int i = 0; i < A.length; i++){
            memo[A[i]]++;
        }
        boolean flag = N%2 != 1 || memo[0] == 1;
        if(flag){
            for(int i = N%2+1; i < N; i += 2){
                if(memo[i] != 2){
                    flag = false;
                    break;
                }
            }
        }
        System.out.println(flag ? power(2, N/2) : 0);
    }

    static long power(long a, int b){
        long ret = 1;
        while(b != 0){
            if(b%2 == 1){
                ret = ret * a % MOD;
            }
            a = a * a % MOD;
            b >>= 1;
        }
        return ret;
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 38228
/*
 * 16-12-4_AOJ064_C.cpp
 *
 *  Created on: 2016/12/04
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

int N, x;
int a[100010];
int main() {
	cin >> N >> x;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	long long ans = 0;
	for (int i = 0; i + 1 < N; i++) {
		int r = a[i] + a[i + 1] - x;
		if (r <= 0)
			continue;
		ans += r;
		if (r > a[i + 1])
		 {
			r -= a[i + 1];
			a[i] -= r;
			a[i+1]=0;
		}
		else{
			a[i+1] -= r;
		}
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, max(b, c) - min(c, b) - a) << endl;
	return 0;
}


Measured memory_bytes: 256
# standard input
S = input()
Q = int(input())
Query = []
num_reverse = 0

L = []
R = []

rev = False

for _ in range(Q):

    q = tuple(map(str, input().split()))

    if q[0] == '1':
        rev = (not rev)

    else:
        if (rev and q[1] == '1') or (not rev and q[1] == '2'):
            R.append(q[2])
        else:
            L.append(q[2])

if rev:
    print(''.join(reversed(R)) + S[::-1] + ''.join(L))
else:
    print(''.join(reversed(L)) + S + ''.join(R))


Measured memory_bytes: 6400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long N = in.nextLong();
		long M = in.nextLong();
		if (N > M / 2) {
			System.out.println(M / 2);
		} else {
			System.out.println(N + (M - N * 2) / 4);
		}
		in.close();
	}
}

Measured memory_bytes: 23764
/* Harsh Pathak - pogba */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
const int N = 1e5;
int n;
int a[N];
int b[N];
int c[N];
int dp[N][3];
int main(int argc, char const *argv[])
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; ++i)
	{
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + c[i];
	}
	cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, x, t; cin >> n >> x >> t;

    ll ans = 0;
    while(true){
        n -= x;
        ans += t;
        if(n <= 0){
            cout << ans << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3612
using System;
using System.Linq;
class Program
{
static void Main(string[] argv)
{
var n = int.Parse(Console.ReadLine());
var v = Console.ReadLine().Split(' ');
var r = 0;
var t = 0;
for(int i=0;i<n-1;i++)
{
if(int.Parse(v[i+0])>= int.Parse(v[i+1]) )
{
t++;
r = t>r?t:r;
}
else
 t=0;
}
Console.WriteLine(
r
);
return;
}
}


Measured memory_bytes: 24668
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	private static BufferedReader br = null;

	public static void main(String[] args) {

		br = new BufferedReader(new InputStreamReader(System.in));

		while(true) {
			try {
				String line = null;
				String[] lines = null;

				line = br.readLine();
				lines = line.split(" ");
				int N = Integer.parseInt(lines[0]);
				int K = Integer.parseInt(lines[1]);

				if (N == 0 && K == 0) {
					return;
				}

				line = br.readLine();
				lines = line.split(" ");
				int[] bloodAmt = new int[K];
				for (int i = 0; i < K; i ++) {
					bloodAmt[i] = Integer.parseInt(lines[i]);
				}

				for (int i = 0; i < N; i ++) {
					line = br.readLine();
					lines = line.split(" ");
					for (int j = 0; j < K; j ++) {
						bloodAmt[j] -= Integer.parseInt(lines[j]);
					}
				}

				for (int i = 0; i < K; i ++) {
					if (bloodAmt[i] < 0) {
						System.out.println("No");
						break;
					}
					if (i == K-1) {
						System.out.println("Yes");
					}
				}

			} catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
}

Measured memory_bytes: 56460
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
struct UnionFind{
    vector<int> par;
    UnionFind(int N){
        par.resize(N);
        for(int i=0;i<N;i++){
            par[i] = i;
        }
    }
    void Union(int x,int y){
        par[Get(x)] = Get(y); 
    }
    bool Same(int x,int y){
        return Get(x) == Get(y);
    }
    int Get(int x){
        if(x != par[x]){
            par[x] = Get(par[x]);
        }
        return par[x];
    }
};
long DP[160000];
int Map[160000];
int Num1[160000];
int Num2[160000];
void Calc(){
	int H = rei();
	int W = rei();
	int c = 1;
	for(int i=0;i<H;i++){
		string S = res();
		for(int j=0;j<W;j++){
			if(S[j] == '#'){
				Map[i*400+j] = c++;
			}
		}
	}
	UnionFind U(160001);
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(Map[i*400+j]){
				if(j < W-2 && Map[i*400+j+2] != 0 && Map[i*400+j+1] == 0){
					U.Union(Map[i*400+j],Map[i*400+j+2]);
				}
				if(i < H-2 && Map[(i+2)*400+j] != 0 && Map[(i+1)*400+j] == 0){
					U.Union(Map[i*400+j],Map[(i+2)*400+j]);
				}
				if(i != H-1 && j != W-1 && Map[(i+1)*400+j+1] != 0 && (Map[i*400+j+1] == 0 || Map[(i+1)*400+j] == 0)){
					U.Union(Map[i*400+j],Map[(i+1)*400+j+1]);	
				}
				if(i != H-1 && j != 0 && Map[(i+1)*400+j-1] != 0 && (Map[i*400+j-1] == 0 || Map[(i+1)*400+j] == 0)){
					U.Union(Map[i*400+j],Map[(i+1)*400+j-1]);	
				}
			}
		}
	}
	for(int i=1;i<c;i++){
		Num1[U.Get(i)]++;
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(Map[i*400+j] == 0){
				if(i != 0 && Map[(i-1)*400+j]){
					Num2[U.Get(Map[(i-1)*400+j])]++;
				}
				else if(i != H-1 && Map[(i+1)*400+j]){
					Num2[U.Get(Map[(i+1)*400+j])]++;
				}
				else if(j != 0 && Map[i*400+j-1]){
					Num2[U.Get(Map[i*400+j-1])]++;
				}
				else if(j != W-1 && Map[i*400+j+1]){
					Num2[U.Get(Map[i*400+j+1])]++;
				}
			}
		}
	}
	long ans = 0;
	for(int i=1;i<c;i++){
		ans += Num1[i]*((long)(Num2[i]));
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

/**
 findChar - 文字列の中にどれだけ文字が存在するかを調べる関数。
 int findChar(String str, char nani, int dokokara)
 注意：naniの次文字目から検索します。("aaiueo"で'i'を見つけたいならnaniは2)
*/

int main()
{
	int n = 0;
	int a = 0;
	int b = 0;
	int c = 0;
	cin >> a;
	cin >> b;
	c = (a * 3 + b) / 2;
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 764
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
s,t = input().split()
u = ''
for i in range(n):
    u = u + s[i] + t[i]
print(u)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K;
  cin >> K;
  vector<int> S = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << S[K - 1];
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back

int main() {
    string s;
    int ans = 0;
    while(cin >> s) {
        int n = s.size();
        bool f=0;
        rep(i,n) {
            if(s[i] != s[n-1-i]) f = 1;
        }
        if(!f) ans++;
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 1188
def lcm(n,m):
  while m!=0:
    n,m=m,n%m
  return n
def gcd(n,m):
  return n*m//lcm(n,m)
n=int(input())
c=int(input())
for i in range(n-1):
  c1=int(input())
  c=gcd(c,c1)
print(c)

Measured memory_bytes: 2940
#include<iostream>
#include<queue>
#include<unordered_map>
#include<vector>
#include<cmath>

using namespace std;

int n, x, y;
unordered_map<int, int>M;
vector<int>V[103 * 2];

void input(){
    cin >> n >> x >> y;
}
/*
void makeGraph(){
    V[1].push_back(2);
    V[n].push_back(n - 1);
    for(int i = 2; i < n; ++i){
        V[i].push_back(i - 1);
        V[i].push_back(i + 1);
    }
    V[x].push_back(y);
    V[y].push_back(x);
}
*/
/*
int bfs(int v){
    queue<int> Q;
    bool visited[103 * 2];
    for(int i = 1; i <= n; ++i){
        visited[i] = 0;
    }
    visited[v] = 1;
    Q.push(v);
    int cnt = 0;
    while(!Q.empty()){
        int tmp = Q.front();
        Q.pop();
        for(int i = 0; i < V[tmp].size(); ++i){
            if(visited[i] == 0){
                visited[i] = 1;
                Q.push(i);
            }
        }
    }

}
*/

int shortedtpath(int s, int t){
    return min(abs(s - t), min(abs(x -s) + 1 + abs(t - y), abs(y - s) + 1 + abs(t - x)));
}



int main(){
    input();
    //makeGraph();
    
    for(int i = 1; i < n; ++i){
        //cout << "check" << endl;
        for(int j = i + 1; j <= n; ++j){
            M[shortedtpath(i, j)]++;
        }
    }
    
    for(int i = 1; i <= n - 1; ++i){
        cout << M[i] << endl;
    }
}

Measured memory_bytes: 384
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

ll MODP = 998244353;


int main(){
  int n ,m;
  cin >> n >> m;
  if(n == m)cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>

void print(int a[],int n){
  int i,j;
  for(i=0;i<n;i++){
    if(i > 0){
      
      printf(" ");

    }
    printf("%d",a[i]);
    
  }
  printf("\n");
}


void insertionSort(int a[],int n){
  int i,e,j;
  
  for(i=1;i<n;i++){
    
    e=a[i];
    j=i-1;//j is 0;  

    while(j>=0&&a[j]>e){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=e;
    
   print(a,n); 
  }
 
}


int main(){

  int n,i;
  int a[100];

  scanf("%d",&n);
  
  if(n>=0&&n<=100){
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }

  }
  
  print(a,n);
  
  insertionSort(a,n);

  return 0;
  
}



Measured memory_bytes: 2084
def chmax(x, y):
    if x == '-':
        return y

    lx = len(x)
    ly = len(y)
    if lx < ly:
        return y
    elif lx == ly:
        if x < y: return y
        else: return x
    else:
        return x


N, M = map(int, input().split())
a = list(map(int, input().split()))

cnt = [N + 1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = ['-' for _ in range(N + 10 + 1)]
dp[0] = ''
# dp[j]: j 本使ってできる最大の数

for i in range(N + 1):
    # print(dp)
    if dp[i] == '-': continue
    for aa in a:
        dp[i + cnt[aa]] = chmax(dp[i + cnt[aa]], dp[i] + str(aa))

print(dp[N])


Measured memory_bytes: 30196
x, y = map(int, input().split())
d = abs(abs(x) - abs(y))
if 0 <= x < y or x < y <= 0:
  print(d)
elif y <= 0 <= x or x < 0 < y:
  print(d+1)
elif 0 < y < x or y < x < 0:
  print(d+2)
else:
  raise Exception

Measured memory_bytes: 9080
X, Y = gets.split.map(&:to_i)
G = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]

A = G.map{|a| a.include?(X)}
B = G.map{|a| a.include?(Y)}

puts A == B ? "Yes" : "No"

Measured memory_bytes: 1788
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector <double> VD;
typedef vector <VD> VVD;

VVD C;	// cost
VD prev, next;
int n, m;	// ì¿ð^¦éñ
int i, j, k;

double solve()
{
	double answer = -1.0;
	for ( i = 0; i < n; i++ ) prev[i] = 1.0;
	for ( k = 1; k < m; k++ )
	{
		for ( i = 0; i < n; i++ )
		{
			next[i] = -1.0;
			for ( j = 0; j < n; j++ )
			{
				double tmp = prev[j] * C[j][i];
				next[i] = max( next[i], tmp );
			}
		}
		prev = next;
	}
	for ( i = 0; i < n; i++ ) answer = max( answer, prev[i] );
	return answer;
}

int main( void )
{
	C = VVD( 100, VD( 100 ) );
	prev = VD( 100 );
	next = VD( 100 );

	while ( scanf( "%d%d", &n, &m ) != EOF && n > 0 && m > 0 )
	{
		for ( i = 0; i < n; i++ ) for ( j = 0; j < n; j++ ) scanf( "%lf", &C[i][j] );
		printf( "%.2lf\n", solve() );
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c&&c<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var L = int.Parse(Console.ReadLine());
            decimal l = L / 3.0m;
            decimal ans = l * l * l;
            Console.WriteLine(ans);
        }

        public int Gcd(int a, int b)
        {
            for (var i = b; i > 1; i -= 1)
            {
                if (a % i == 0 && b % i == 0)
                {
                    return i;
                }
            }
            return 1;
        }

        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public List<int> ConvertIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }

        public List<double> ConvertDoubleList(string[] x)
        {
            var convertedList = new List<double>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(double.Parse(x[i]));
            }

            return convertedList;
        }

        public List<long> ConvertLongList(string[] x)
        {
            var convertedList = new List<long>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(long.Parse(x[i]));
            }

            return convertedList;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

Measured memory_bytes: 11092
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct couple
{
	double x, y;
	couple(){}
	couple(const double & _x, const double & _y) {x = _x; y = _y;}
	void scan(){scanf("%lf%lf", &x, &y);}
	const double len() const {return sqrt(x * x + y * y);}
	couple rev() {return couple(y, -x);}
} s[44444], d[44444], cp;
int n;
const double pi = 2 * acos(0.0), eps = 1e-9;
couple operator - (const couple & a, const couple & b)
{
	return couple(a.x - b.x, a.y - b.y);
}
couple operator + (const couple & a, const couple & b)
{
	return couple(a.x + b.x, a.y + b.y);
}
couple operator * (const double & lambda, const couple & a)
{
	return couple(lambda * a.x, lambda * a.y);
}
double operator * (const couple & a, const couple & b)
{
	return a.x * b.y - a.y * b.x;
}
double operator % (const couple & a, const couple & b)
{
	return a.x * b.x + a.y * b.y;
}
double len[44444], r, cl[44444], lim[44444], v, ans, a;
double getcos(const couple & a, const couple & b)
{
	double rtn = a % b / a.len() / b.len();
	if(rtn < -1) rtn = -1;
	if(rtn > 1) rtn = 1;
	//printf("acos %lf\n", rtn);
	return rtn;
}
void cross(const couple & s1, const couple & d1, const couple & s2, const couple & d2)
{
	double lambda = (s2 - s1) * (d2) / (d1 * d2);
	cp = couple(s1 + lambda * d1);
}
int main()
{
	while(scanf("%d%lf", &n, &a) == 2)
	{
		for(int i = 1; i <= n; i++)
		{
			s[i].scan();
			d[i].scan();
			d[i] = d[i] - s[i];
			len[i] = d[i].len();
		}
		lim[0] = lim[n] = 0;
		for(int i = 1; i < n; i++)
		{
			if(fabs(d[i] * d[i + 1]) < eps)
			{
				r = (s[i + 1] - s[i] - d[i]).len() / 2;
				lim[i] = sqrt(r * a);
				cl[i] = r * pi;
			}else
			{
				cross(s[i] + d[i], d[i].rev(), s[i + 1], d[i + 1].rev());
				r = (cp - s[i] - d[i]).len();
				lim[i] = sqrt(r * a);
				cl[i] = r  * ((d[i] * d[i + 1]) * (d[i] * (s[i + 1] - s[i])) < 0?2 * pi - acos(getcos(d[i], d[i + 1])):acos(getcos(d[i], d[i + 1])));
			}
		}
		cl[n] = 0;
		for(int i = n; i >= 1; i--)
		{
			lim[i - 1] = min(lim[i - 1], sqrt(2 * len[i] * a + lim[i] * lim[i]));
		}
		//for(int i = 1; i <= n; i++) printf("%lf\n", lim[i]);
		ans = 0; v = 0;
		for(int i = 1; i <= n; i++)
		{
			if(lim[i] > sqrt(2 * a * len[i] + v * v))
			{
				ans += (sqrt(2 * a * len[i] + v * v) - v) / a;
				v = sqrt(2 * a * len[i] + v * v);

			}else
			{
				ans += (2 * sqrt((2 * a * len[i] + v * v + lim[i] * lim[i]) / 2) - v - lim[i]) / a;
				double vmax = sqrt((2 * a * len[i] + v * v + lim[i] * lim[i]) / 2);
				//printf("%lf %lf %lf %lf %lf\n", v, lim[i], sqrt((2 * a * len[i] + v * v + lim[i] * lim[i]) / 2), (vmax * vmax * 2 - v * v - lim[i] * lim[i]) / a / 2, (2 * sqrt((2 * a * len[i] + v * v + lim[i] * lim[i]) / 2) - v - lim[i]) / a);
				v = lim[i];
			}
			//printf("ans = %lf\n", ans);
			if(fabs(v) > eps)ans += cl[i] / v;
		}
		printf("%.10f\n", ans);
	}
	fclose(stdin);
	return 0;
}

Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int max = 0;
    vector<int> V(n);
    vector<int> C(n);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> V[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> C[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (V[i] > C[i])
        {
            max += V[i] - C[i];
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 640
// きさま！ 見ているなッ！

#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>
#include<thread>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;


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

	set<ll> ru;

	for (int i = 1; i <= 9; ++i)
	{
		ru.insert(i);
	}

	for (int i = 0; i < K - 1; ++i)
	{
		ll r = *ru.begin();
		
		if (r % 10 != 0)
		{
			ru.insert(r * 10 + (r % 10) - 1);
		}
		ru.insert(r * 10 + (r % 10));
		if (r % 10 != 9)
		{
			ru.insert(r * 10 + (r % 10) + 1);
		}

		ru.erase(r);
	}

	cout << *ru.begin() << endl;

	return 0;
}


Measured memory_bytes: 9216
#include<iostream>

using namespace std;

int main(){

  int n;

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

    int data[n];
    int sum = 0;

    for(int i = 0; i < n; i++){
      cin >> data[i];
    }
    int tmp;
    for(int j = 0; j < n; j++){
      for(int i = 0; i < n-1-j; i++){
	if(data[i] > data[i+1]){
	  tmp = data[i];
	  data[i] = data[i+1];
	  data[i+1] = tmp;
	  sum++;
	}
      }
    }

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

Measured memory_bytes: 0
n = int(input())
l = list(map(float,input().split()))
dp = [[0]*(n+1) for i in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
    for j in range(n+1):
        dp[i][j] = dp[i-1][j]*(1-l[i-1])+dp[i-1][j-1]*l[i-1]
print(sum(dp[-1][n//2+1:]))

Measured memory_bytes: 259720
#include "bits/stdc++.h"
using namespace std;
#include <string>;
int main()
{
	string str1;
    string str2;
    string str3;
	cin >> str1;
    cin >> str2;
    cin >> str3;
	cout << str1[0] << str2[1] << str3[2];
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long ans=0;
int main()
{
    long N,A[5]={0};
    char S[15];

    scanf("%ld",&N);
    for(int i=0; i<N; i++){
        scanf("%s",S);
        if(S[0] == 'M'){
            A[0]++;
        }else if(S[0] == 'A'){
            A[1]++;
        }else if(S[0] == 'R'){
            A[2]++;
        }else if(S[0] == 'C'){
            A[3]++;
        }else if(S[0] == 'H'){
            A[4]++;
        }
    }

    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += A[i] * A[j] * A[k];
            }
        }
    }
    printf("%ld",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define FOR(i, r, n) for (int i=(int)(r); i<=(int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 2147483647
#define INF64 9223372036854775807
#define MOD 1000000007

int main(){

  	int x=26;
  
    rep(i, 365){
      cout<<x<<endl;
      x--;
      if(x==1) x=26;
    }

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,x;
    cin>>n>>x;
    ll val=0,ans=n+1;
    rep (i,0,n)
    {
        ll y;
        cin>>y;
        val+=y;
        if (val>x)
        {
            ans=i+1;
            val=-99999999999999;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
# ABC54 D
n,ma,mb = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    ai,bi,ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    
max_sum = n * 10
max_cost = 100000000
dp = [[[max_cost for k in range(max_sum+1)] for j in range(max_sum+1)] for i in range(n+1)]

dp[0][0][0] = 0
for i in range(n):
    for ca in range(max_sum+1):
        for cb in range(max_sum+1):
            if(dp[i][ca][cb] == max_cost):
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])

ans = max_cost
for ca in range(1,max_sum+1):
    for cb in range(1,max_sum+1):
        if(ca*mb == cb*ma):
            ans = min(ans, dp[n][ca][cb])

if(ans == max_cost):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 60780
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N;
int H[MAX_N];
int S[MAX_N];

int main(void)
{
  cin >> N;
  REP(i, N) cin >> H[i];

  S[N - 1] = 0;
  for (int i = N - 1; i > 0; i--) {
    if (H[i - 1] >= H[i]) {
      S[i - 1] = S[i] + 1;
    }
    else {
      S[i - 1] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, S[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
///
// File:  alds1_9_b.cpp
// Author: ymiyamoto
//
// Created on Sun Oct 15 23:11:24 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

static vector<int64_t> array;

void build_heap(int32_t index)
{
  int32_t left = index * 2;
  int32_t right = index * 2 + 1;

  int64_t max_index = index;
  if (left <= (int32_t)array.size()) {
    if (array[max_index - 1] < array[left - 1]) {
      max_index = left;
    }
  }
  if (right <= (int32_t)array.size()) {
    if (array[max_index - 1] < array[right - 1]) {
      max_index = right;
    }
  }

  if (max_index != index) {
    swap(array[index - 1], array[max_index - 1]);
    build_heap(max_index);
  }
}

void build_max_heap()
{
  for (int32_t i = array.size() / 2; i > 0; i--) {
    build_heap(i);
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    int64_t val;
    cin >> val;
    array.push_back(val);
  }

  build_max_heap();

  for (uint32_t i = 0; i < array.size(); i++) {
    cout << " " << array[i];
  }
  cout << endl;

  return 0;
}

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

#define rep(i,n) for(int i=0;(i)<(n);(i)++)

int main(){
    int N,res,tmp,cnt;
    cin>>N>>res;
    cnt=N;
    vector<int> a(N);
    rep(i,N)cin>>a[i];
    rep(i,N)rep(j,i)if(a[j]>a[i]){tmp=a[i];a[i]=a[j];a[j]=tmp;}
    rep(i,N)res-=a[i];
    cnt=cnt+res/a[0];
    cout<<cnt<<endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var result = "win";

            if ((a[0]+a[1]+a[2]) >= 22) {
                result = "bust";
            }

            Console.WriteLine(result);

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; cout.tie(NULL);
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007


int32_t main(){
    IOS;

int n;
cin>>n;
int a[3];
int dp[n][3];
cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
for(int i=1;i<n;i++)
{
    cin>>a[0]>>a[1]>>a[2];
    for(int j=0;j<3;j++)
    {
        dp[i][j] = a[j] + max(dp[i-1][(j+1)%3] , dp[i-1][(j+2)%3]);
    }
}
cout<<max(dp[n-1][0] ,   max(dp[n-1][1] , dp[n-1][2]))<<endl;
}


Measured memory_bytes: 2560