akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int tv = 200000;
  int fv = 0;
  while (tv - fv > 1){
    int mid = (tv + fv) / 2;
    vector<tuple<int, int, int>> S;
    S.push_back(make_tuple(0, A[0], A[0]));
    bool ok = true;
    for  (int i = 1; i < N; i++){
      if (A[i] > A[i - 1]){
        S.push_back(make_tuple(0, A[i] - A[i - 1], A[i]));
      } else {
        while (get<2>(S.back()) > A[i]){
          if (get<2>(S.back()) - get<1>(S.back()) >= A[i]){
            S.pop_back();
          } else {
            get<1>(S.back()) -= get<2>(S.back()) - A[i];
            get<2>(S.back()) = A[i];
          }
        }
        int p = get<0>(S.back());
        bool upd = false;
        while (get<0>(S.back()) == mid - 1){
          S.pop_back();
          upd = true;
          if (S.empty()){
            ok = false;
            break;
          }
        }
        if (!ok){
          break;
        }
        get<1>(S.back())--;
        get<2>(S.back())--;
        int q = get<0>(S.back());
        if (get<1>(S.back()) == 0){
          S.pop_back();
        }
        if (upd){
          if (S.empty()){
            S.push_back(make_tuple(q + 1, 1, 1));
          } else {
            S.push_back(make_tuple(q + 1, 1, get<2>(S.back()) + 1));
          }
          if (get<2>(S.back()) < A[i]){
            S.push_back(make_tuple(0, A[i] - get<2>(S.back()), A[i]));
          }
        } else {
          if (S.empty()){
            S.push_back(make_tuple(p + 1, A[i], A[i]));
          } else {
            S.push_back(make_tuple(p + 1, A[i] - get<2>(S.back()), A[i]));
          }
        }
      }
      if (!ok){
        break;
      }
    }
    if (ok){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}

Measured memory_bytes: 9472
package main
import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
func main() {
	var a, b int
	fmt.Fscan(r, &a, &b)
    
    // ↓ここを変える
	fmt.Printf("%d %d\n", a * b, 2 * a + 2 * b)
}


Measured memory_bytes: 1144
var
  s:string;
  i,j,n,m,d,x,y:longint;
begin
  s:='RGBY';
  readln(n,m,d);
  for i:=0 to n-1 do
  begin
  for j:=0 to m-1 do
  begin
    x:=(m+i+j)div d mod 2;
	y:=(m+i-j)div d mod 2;
	write(s[2*x+y+1]);
  end;
  writeln;
  end;
end.

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

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

  Graph G(N, vector<int>(N,1));
  int M;

  if (N % 2 == 0) {
    M = N * (N-2) / 2;
    rep(i,N) {
      G[i][i] = 0;
      G[i][N-1-i] = 0;
    }
  } else {
    M = N * (N-1) / 2 - N / 2;
    rep(i,N) {
      G[i][i] = 0;
      if (i != N-1) G[i][N-2-i] = 0;
    }
  }

  cout << M << endl;
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      if (G[i][j]) cout << i+1 << " " << j+1 << endl;
    }
  }
}

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

using namespace std;
typedef long long ll;
#define int ll

template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b)
{
    if (a > b)
        a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b)
{
    if (a < b)
        a = b;
}

#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

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

    if ((a == b && b != c) ||
        (a == c && b != c) ||
        (b == c && a != c))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a[5];
 
  for(int i=1;i<=5;i++)
   { 
       cin>>a[i];
   }
   for(int i=1;i<=5;i++)
   {
      if(a[i]==0)
      {
          cout<<i<<endl;
      }
   }
   return 0;
}

Measured memory_bytes: 3136
#include<stdio.h>

#define CNST_DAY 365
#define NUM_CONTEST 26

int D,c[NUM_CONTEST+1]={},s[CNST_DAY+1][NUM_CONTEST+1]={},last[NUM_CONTEST+1]={},t[CNST_DAY+1]={};
long v[CNST_DAY+1]={};

void Scoring(int d){
    int i;

    last[t[d]]=d;
    
    v[d]=v[d-1]+s[d][t[d]];
    for(i=1;i<=NUM_CONTEST;i++){
        v[d]-=c[i]*(d-last[i]);
    }
    return;
}


void ReAllScoring(int day, int newcon){
    int i,d,oldcon=t[day];

    t[day]=newcon;
    for(i=1;i<=NUM_CONTEST;i++){
        last[i]=0;
    }
    for(d=1;d<=D;d++){
        v[d]=0;
    }
    for(d=1;d<=D;d++){
        //開催するコンテストt[d]を決めた後
        last[t[d]]=d;
        Scoring(d);
    }

    return;

}

int main(void){

    int i,j,k,d,n;

    int smax[CNST_DAY+1]={},maxcon[CNST_DAY+1]={};

    //入力
    scanf("%d",&D);
    for(d=1;d<=NUM_CONTEST;d++){
        scanf("%d",&c[d]);
    }
    for(d=1;d<=D;d++){
        for(i=1;i<=NUM_CONTEST;i++){
            scanf("%d",&s[d][i]);
        }
    }
    
    //スコア計算
    //よさそうなものを選ぶ
    int z;
    for(d=1;d<=D;d++){
        smax[d]=s[d][1];
        maxcon[d]=1;
        for(i=2;i<=NUM_CONTEST;i++){
            z=s[d][i]+c[i]*(d-last[i]);
            if(z>smax[d]){
                smax[d]=z;
                maxcon[d]=i;
            }
        }
        t[d]=maxcon[d];
        last[maxcon[d]]=d;
    }
    for(d=1;d<=D;d++){
        Scoring(d);
    }
    for(d=1;d<=D;d++){
        //その日一番大きい満足度が得られるコンテストを開く(満足度の低下を無視したもの)

        //開催するコンテストt[d]を決めた後
        long oldscore;
        int newcon,oldcon,times=0;
        while(times++<9){
            newcon=rand()%26+1;
            oldscore=v[D];
            oldcon=t[d];
            t[d]=newcon;
            for(i=1;i<=NUM_CONTEST;i++){
                last[i]=0;
            }
            for(d=1;d<=D;d++){
                v[d]=0;
            }
            for(d=1;d<=D;d++){
                //開催するコンテストt[d]を決めた後
                last[t[d]]=d;
                Scoring(d);
            }
            if(v[D]>oldscore){
                break;
            }else{
                t[d]=oldcon;
            }
            
        }
    }

    //出力
    for(d=1;d<=D;d++){
        //printf("%ld\n",v[d]);
        printf("%d\n",t[d]);
    }

    return 0;
}

Measured memory_bytes: 1776
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e16;

lint N, M, A, B;
lint arr[100000];
bool flag[100000];
int main() {
	cin >> N >> M;
	REP(i, N) {
		cin >> arr[i];
		flag[i] = true;
	}
	REP(i, M) {
		cin >> A >> B; A--; B--;
		if (arr[A] <= arr[B]) flag[A] = false;
		if (arr[B] <= arr[A]) flag[B] = false;
	}
	lint cnt = 0;
	REP(i, N) {
		if (flag[i]) cnt++;
	}
	cout << cnt << endl;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;

    int ans = 0;
    int tmp = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'A' or s[i] == 'T' or s[i] == 'C' or s[i] == 'G') {
            tmp++;
            ans = max(ans, tmp);
        } else {
            tmp = 0;
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
	ll n, k;
	cin>>n>>k;
	vl a(n);
	ll prod=1;
	forr(i, n)
	{
		cin>>a[i];
	}
	for(ll i=k; i<n; i++)
	{
		if(a[i]>a[i-k])
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 4764
#include<algorithm>
#include<chrono>
#include<ctime>  
#include<climits>
#include<functional>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
// #include<bits/stdc++.h>
using namespace std;
 
struct Debug{
    int cnt = 0;
    bool on = false;
    char debug[10] = "debug";
    template<class T>
    Debug & operator<<(const T & v) {
        if(on && cnt++ == 0) cerr << "debug: ";
        if(on) cerr << v << ' ';
        return *this;
    }
    Debug & operator<<(ostream&(*pManip)(ostream&)) {
        if(on) cerr << (*pManip);
        cnt = 0;
        return *this;
    }
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

const int MAXN = 5e5 + 10;

int n;
pair<ll, ll> a[MAXN];
ll rt[MAXN] = {};
ll rt1[MAXN] = {};
ll lt[MAXN] = {};
int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

    cin >> n;
    for(int i = 0; i < n; i++)
    	cin >> a[i].first >> a[i].second;
    sort(a, a + n);

    long long res = 0;
    for(int i = 0; i < n; i++)
    	res = max(res, a[i].second - a[i].first + 1);

    for(int i = 0; i < n; i++) {
    	rt[i] = a[i].second;
    	if(i) rt[i] = min(rt[i], rt[i - 1]);
    }
    for(int i = 0; i < n; i++) {
    	rt1[i] = a[i].second;
    	if(i) rt1[i] = max(rt1[i], rt1[i - 1]);
    }
    for(int i = n - 1; i >= 0; i--) {
    	lt[i] = a[i].second;
    	if(i < n - 1) lt[i] = min(lt[i], lt[i + 1]);
    }

    for(int i = n - 2; i >= 0; i--) {
    	if(lt[i + 1] < a[n - 1].first)
    		break;
    	res = max(res, max(0LL, rt[i] - a[i].first + 1) + lt[i + 1] - a[n - 1].first + 1);
    	if(rt[i] >= a[n - 1].first)
	    	res = max(res, max(0LL, rt1[i] - a[i].first + 1) + min(rt[i], lt[i + 1]) - a[n - 1].first + 1);
    }
    cout << res << endl;


    return 0;
 
}














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

#define N (123456*2)

int n;
bool is_composite[N+1];
int num[N+1];

int main() {
  for (int i=2; i<=N; i++) {
    num[i] = num[i-1];
    if (!is_composite[i]) {
      num[i]++;
      for (int j=i+i; j<=N; j+=i) {
        is_composite[j] = true;
      }
    }
  }

  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    printf("%d\n", num[n*2]-num[n]);
  }
}

Measured memory_bytes: 4404
import java.io.*;
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        String op = sc.next();
        int b = sc.nextInt();
        
        while (!(op.equals("?"))) {
            switch (op) {
                case "+" :
                    System.out.println(a+b);
                    break;
                case "-" :
                    System.out.println(a-b);
                    break;
                case "*" :
                    System.out.println(a*b);
                    break;
                case "/" :
                    System.out.println(a/b);
                    break;
            }
            a = sc.nextInt();
            op = sc.next();
            b = sc.nextInt();
        }
    }
}

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

int main() {
    int t;
    int n;
    int s,f;
    int all;
    int temp;
    
    while (1) {
        all = 0;
        cin >> t;
        if (t == 0) {
            break;
        }
        
        cin >> n;
        for(int i = 0; i < n; i++) {
            cin >> s;
            cin >> f;
        
            temp = f - s;
            all += temp;
            temp = 0;
        }
    
        if ((t - all) > 0) {
            cout << (t - all) << "\n";
        }
        else
        {
            cout << "OK" << "\n" ;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
s=input()
t=''
skip=False
for i in range(len(s)-1):
    if skip:
        skip=False
        continue
    if s[i:i+2]=='BC':
        t+='D'
        skip=True
    else:
        t+=s[i]

ans,cnt=0,0
for i in range(len(t)):
    if t[i]=='A':
        cnt+=1
    if t[i] in ['B','C']:
        cnt=0
    if t[i]=='D':
        ans+=cnt
print(ans)

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
signed main(){
    ll h,w,k;cin>>h>>w>>k;
    vector<vector<ll> >d(h+2,vector<ll>(w+2));
    vector<vector<ll> >ans(h+2,vector<ll>(w+2,inf));
    queue<pll>q;
    ll x,y;cin>>x>>y;
    q.push(mp(x,y));
    ans[x][y]=0;
    cin>>x>>y;
    rep(i,h){
        rep(j,w){
            char c;cin>>c;
            if(c=='.')d[i+1][j+1]=1;
        }
    }
    while(!q.empty()){
        pll p=q.front();
        ll nx=p.fi,ny=p.se;
        q.pop();
        rep(i,4){
            REP(j,1,k+1){
                ll xx=nx+dx[i]*j,yy=ny+dy[i]*j;
                if(d[xx][yy]==0)break;
                if(ans[xx][yy]<ans[nx][ny]+1)break;
                if(ans[xx][yy]==ans[nx][ny]+1)continue;
                if(ans[xx][yy]==inf){
                    ans[xx][yy]=ans[nx][ny]+1;
                    q.push(mp(xx,yy));
                }
                if(ans[xx][yy]>ans[nx][ny]+1)ans[xx][yy]=ans[nx][ny]+1;
            }
        }
    }
    if(ans[x][y]<inf){
        cout<<ans[x][y]<<endl;
    }else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 58004
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		string S;
		cin >> S;
		if (cin.fail()) break;
        std::reverse(S.begin(), S.end());
		puts(
          std::regex_replace(S, std::regex("(maerd|remaerd|esare|resare)"), "")
		.empty() ? "YES" : "NO");
	}

	return 0;
}


Measured memory_bytes: 512
Module Module1

    Sub Main()
        'let
        Dim A As Long = Console.ReadLine()
        Dim B As Long = Console.ReadLine()
        Dim C As Long = Console.ReadLine()
        Dim X As Long = Console.ReadLine()

        'var
        Dim cnt As Long = 0

        For i As Long = 0 To A
            For j As Long = 0 To B
                For k As Long = 0 To C
                    If X = 500 * i + 100 * j + 50 * k Then
                        cnt += 1
                    End If
                Next
            Next
        Next

        Console.WriteLine(cnt)

    End Sub

End Module

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)

using namespace std;

typedef long long int lli;

int main() {
    int N, M;
    cin >> N >> M;
    cout << (M * 1900 + (N - M) * 100) * (1 << M) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
signed main(){
  int m,c,n;
  while(cin>>m>>c>>n,m||c||n){
    int k[n];
    int b[111][55];
    for(int i=0;i<n;i++){
      cin>>k[i];
      for(int j=0;j<k[i];j++) cin>>b[i][j];
    }
    list<int> l[m];
    queue<P> q;
    for(int i=0;i<n;i++) q.push(P(i,0));
    int ans=0;
    while(!q.empty()){
      P p=q.front();q.pop();
      int w=p.first,x=p.second;
      int pos=m;
      for(int i=0;i<m;i++){
	auto latte=find(l[i].begin(),l[i].end(),b[w][x]);
	if(latte!=l[i].end()){
	  pos=i;
	  l[i].erase(latte);
	  break;
	}
      }
      ans+=pos+1;
      if((int)l[0].size()<c){
	l[0].push_front(b[w][x]);
	ans+=1;
      }else{
	int tmp=m;
	for(int i=1;i<m;i++){
	  if((int)l[i].size()<c){
	    tmp=i;
	    l[tmp].push_back(b[w][x]);
	    break;
	  }
	}
	ans+=tmp+1;
	//cout<<ans<<endl;
	int le=l[0].back();
	l[0].pop_back();
	ans+=1;
	int pos=m;
	for(int i=1;i<m;i++){
	  if((int)l[i].size()<c){
	    pos=i;
	    l[pos].push_front(le);
	    break;
	  }
	}
	ans+=pos+1;
	//cout<<ans<<endl;
	if(tmp<m) l[tmp].pop_back();
	ans+=tmp+1;
	//cout<<ans<<endl;
	l[0].push_front(b[w][x]);
	ans+=1;
	//cout<<ans<<endl;
      }
      if(x+1<k[w]) q.push(P(w,x+1));
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long LL;

int main() {
  int N, K;
  cin >> N >> K;
  vector<LL> H(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> H[i + 1];
  }
  H.push_back(0);

  LL INF = 1LL << 60;
  vector<vector<LL>> dp(N + 2, vector<LL>(N + 2, INF));
  dp[0][0] = 0;
  for (int i = 0; i < N + 1; i++) {
    for (int k = 0; k <= K; k++) {
      // dp[i+1][k] = ...
      for (int j = 0; j <= k; j++) {
        if (i - j < 0) continue;
        if (k - j < 0) continue;
        dp[i + 1][k] =
            min(dp[i + 1][k], dp[i - j][k - j] + abs(H[i + 1] - H[i - j]));
      }
    }
    // for (int k = 0; k <= K; k++) cout << dp[i + 1][k] << " ";
    // cout << endl;
  }
  LL ans = INF;
  for (int k = 0; k <= K; k++) {
    ans = min(ans, dp[N + 1][k]);
  }
  cout << ans / 2 << endl;

  return 0;
}


Measured memory_bytes: 1024
S = gets.chomp
K = gets.to_i
ans = 0
if K == 1 || S[0] != S[-1]
    curr = nil
    streak = 1
    S.chars.each do |s|
        if curr == s
            streak += 1
        else
            ans += streak / 2
            streak = 1
        end
        curr = s
    end
    ans += streak / 2
    ans = ans * K 
elsif S.chars.uniq.size == 1
    ans = S.length * K / 2
else
    curr = nil
    streak = 1
    streaks = []
    S.chars.rotate(S.chars.index {|s| S[0] != s}).each do |s|
        if curr == s
            streak += 1
        else
            streaks << streak
            streak = 1
        end
        curr = s
    end
    streaks << streak
    streaks[-1] -= 1
    streaks[1..-2].each{|st| ans += (st / 2) *  K}
    ans += streaks[0] / 2
    ans += streaks[-1] / 2
    ans += (streaks[0] + streaks[-1]) / 2 * (K - 1)
end
p ans

Measured memory_bytes: 1788
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"2
10 30"# => r#"7.5"#,
r#"3
200 200 200"# => r#"66.66666666666667"#,
r#"1
1000"# => r#"1000"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        a: [f64; n]
    }
    (1f64/a.into_iter().map(|x| 1f64/x).sum::<f64>()).to_string()
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define N 200005
#define lb lower_bound
#define up upper_bound
#define ll long long
#define db double
#define dbg1(x) cout<<#x<<"="<<x<<" "
#define dbg2(x) cout<<#x<<"="<<x<<"\n"
int n,A[N],B[N],po[35],res,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	for(int i=1;i<=n;i++) scanf("%d",&B[i]);
	for(int i=0;i<30;i++) po[i]=1<<i;
	for(int k=28;~k;k--)
	{
		sort(A+1,A+1+n),sort(B+1,B+1+n),res=0;
//		dbg2(k);
		for(int i=1,pos1,pos2;i<=n;i++)
		{
			pos1=lb(B+1,B+1+n,po[k]-A[i])-B;
			pos2=lb(B+1,B+1+n,po[k+1]-A[i])-B-1;
//			dbg1(pos1),dbg2(pos2);
			if(pos1<=pos2) res+=pos2-pos1+1;
			pos1=lb(B+1,B+1+n,po[k]+po[k+1]-A[i])-B;
			pos2=lb(B+1,B+1+n,po[k+2]-A[i])-B-1;
//			dbg1(pos1),dbg2(pos2);
			if(pos1<=pos2) res+=pos2-pos1+1;
			res=res&1;
		}
		if(res&1) ans+=po[k];
		for(int i=1;i<=n;i++) A[i]%=po[k],B[i]%=po[k];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cout<<fixed<<setprecision(20);
	llint n,K;cin>>n>>K;K*=3;
	lldo bmax=1.3,bmin=0;
	for(int h=0;h<35;h++){
		lldo bgen=(bmax+bmin)/2;
		llint kaz=0;
		for(int i=1;i<=n-2;i++){
			//底の数
			lldo tei=2*sin(pai*i/n);//底辺の長さ
			lldo ter=bgen*2/tei-cos(pai*i/n);//これ以下の高さの点なら合格
			if(ter>=1){kaz+=n;}
			else{
				lldo mrad=acos(-ter);
				if(i%2==1){
					kaz+=2*((int)((mrad*n/(2*pai))+0.5));
				}else{
					kaz+=1+2*((int)((mrad*n/(2*pai))));
				}
			}
			kaz-=i+1;
		}
		if(kaz*n<K){bmin=bgen;}
		else{bmax=bgen;}
	}
	cout<<bmax<<endl;
	return 0;
}



Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	LLI n;
	cin >> n;
	vector<LLI> a(n);
	vector<LLI> sums(n + 1);
	LLI sum = 0;
	REP(i, n)
	{
		cin >> a[i];
		sum = (sum + a[i]) % MOD;
		sums[i + 1] = (sums[i] + a[i]) % MOD;
	}

	LLI ans = 0;
	REP(i, n - 1)
	{
		ans += (a[n - i - 1] * (sums[n - i - 1])) % MOD;
		ans %= MOD;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 6392
def main():
    MOD = int(1e9 + 7)
    h, w = map(int, input().split())
    grid = [input() for _ in range(h)]

    dp = [[0] * w for _ in range(h)]
    dp[0][0] = 1

    for i in range(h):
        for j in range(w):
            if grid[i][j] != '#':
                if i > 0:
                    dp[i][j] += dp[i-1][j]

                if j > 0:
                    dp[i][j] += dp[i][j-1]

                if dp[i][j] > MOD:
                    dp[i][j] -= MOD

    ans = dp[h-1][w-1]
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 51696
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(c.begin(), c.end());

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long j = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    long long k = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
    ans += j * (n - k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
    int n;
    float ans;
    cin>>n;
    ans = 2.0 * 3.14159 * (float)n;
    cout<<fixed<<setprecision(2)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3776
class UnionFind:
    def __init__(self, n: int):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x: int):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x: int, y: int):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        if self.parents[y] < self.parents[x]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x: int):
        return -self.parents[self.find(x)]
    
    def same(self, x: int, y: int):
        return self.find(x) == self.find(y)
    
    def members(self, x: int):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    N, M, K = map(int, input().split())
    uf_tree = UnionFind(N + 1)
    ans = [0] * (N + 1)
    for _ in range(M):
        a, b = map(int, input().split())
        uf_tree.union(a, b)
        ans[a] -= 1
        ans[b] -= 1
    for _ in range(K):
        c, d = map(int, input().split())
        if uf_tree.same(c, d):
            ans[c] -= 1
            ans[d] -= 1
    
    for i in range(1, N + 1):
        ans[i] += uf_tree.size(i) - 1
    
    print(' '.join(map(str, ans[1:])))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 18176
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int carrot[3000000];
int kiwi[3000000];
int carrotCnt[3000000];
int kiwiCnt[3000000];
pair<int, int> stack[3000000];
int head = -1;
int dif = 0;

inline void stackPush(int kiwi, int cnt) {
  if (head == -1 || stack[head].second != cnt) {
    head++;
    stack[head] = make_pair(kiwi, cnt);
  } else {
    stack[head].first += kiwi;
  }
}

int main() {
  //MEMSET(carrot, 0);
  //MEMSET(kiwi, 0);
  //MEMSET(carrotCnt, 0);
  //MEMSET(kiwiCnt, 0);
  //MEMSET(stack, 0);
  ll M, N, m0, n0, md, nd;
  scanf("%lld %lld %lld %lld %lld %lld", &M, &N, &m0, &md, &n0, &nd);
  ll prev = m0;
  REP(i, M) {
    carrotCnt[prev]++;
    prev = (prev * 58 + md) % (N + 1);
  }
  prev = n0;
  REP(i, N) {
    kiwiCnt[prev]++;
    prev = (prev * 58 + nd) % (M + 1);
  }
  int m = 0;
  REP(i, N + 1) {
    REP (j, carrotCnt[i]) { carrot[m++] = i; }
  }
  //assert(m == M);
  m = 0;
  REP(i, M + 1) {
    REP (j, kiwiCnt[i]) { kiwi[m++] = i; }
  }
  //assert(m == N);
  ll ans = 0;
  int sum = 0;
  int index = M;
  REP(iter, M) {
    int rest = 0;
    int use = 0;
    while (sum < carrot[iter] && index > 0) {
      //if (kiwiCnt[index] == 0) { index--; continue; }
      if (sum + kiwiCnt[index] > carrot[iter]) {
        rest = sum + kiwiCnt[index] - carrot[iter];
        use = kiwiCnt[index] - rest;
        ans += use;
        kiwiCnt[index - 1] += use;
        kiwiCnt[index] -= use;
        break;
      } else {
        sum += kiwiCnt[index];
        stackPush(kiwiCnt[index], index + dif);
      }
      kiwiCnt[index] = 0;
      index--;
    }
    //assert(head == -1 || stack[head].second - dif > index);
    //assert(sum <= carrot[iter]);
    ans += sum;
    dif++;
    if (head >= 0 && (stack[head].second - dif == 0 || stack[head].second - dif == index)) {
      sum -= stack[head].first;
      kiwiCnt[index] += stack[head].first;
      head--;
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 0
#include<stdio.h>
int main(){
    int n,i,a[6]={0},j;
    double s;
    while(scanf("%d",&n) != EOF){
        if(n==0) break;
        for(i=0;i<n;i++){
            scanf("%lf",&s);
            if(s < 165.0) a[0]++;
            else if(s >= 165.0 && s < 170.0) a[1]++;

            else if(s >= 170.0 && s < 175.0) a[2]++;

            else if(s >= 175.0 && s < 180.0) a[3]++;

            else if(s >= 180.0 && s < 185.0) a[4]++;

            else{
                a[5]++;
            }

        }
        for(i=0;i<6;i++){
            printf("%d:",i+1);
            for(j=0;j<a[i];j++){
                printf("*");
            }
            a[i] =0;
            puts("");
        }
    }
    return 0;
}

Measured memory_bytes: 648
#include<iostream>
#include<algorithm>
#include<math.h>
 #define ll long long
using namespace std;
int main()
{
	int co1=0, co2=0, co3=0, co4=0;
    string s; int t; cin >> t;
	while (t--)
	{
		cin >> s;
		if (s == "AC")
			co1++;
		else if (s == "WA")
			co2++;
		else if (s == "TLE")
			co3++;
		else {
			co4++;
		}
		
	}
	cout << "AC x " << co1 << endl;
	cout << "WA x " << co2 << endl;
	cout << "TLE x " << co3 << endl;
	cout << "RE x " << co4 << endl;
}

Measured memory_bytes: 3160
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  string s; cin >>s;
  int ans = 0, sl = s.length(), l, r;
  if(sl % 2){
    if(s[sl / 2] != 'i' && s[sl / 2] != 'w') ++ans;
    l = sl / 2 - 1;
    r = sl / 2 + 1;
  } else{
    l = sl / 2 - 1;
    r = sl / 2;
  }
  while(l >= 0){
    if(!((s[l] == 'i' && s[r] == 'i')
        || (s[l] == 'w' && s[r] == 'w')
        || (s[l] == '(' && s[r] == ')')
        || (s[l] == ')' && s[r] == '('))) ++ans;
    --l; ++r;
  }
  cout <<ans <<endl;
  return 0;
}

Measured memory_bytes: 1180
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

int main(){
    int N;
    scanf("%d",&N);
    while(N--){
        int gx,gy;
        scanf("%d%d",&gx,&gy);
        gx++;gy++;
        set<pair<pii,pii> >S;
        int M;
        scanf("%d",&M);
        while(M--){
            int x1,y1,x2,y2;
            scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
            x1++;y1++;x2++;y2++;
            S.insert(pair<pii,pii>(pii(x1,y1),pii(x2,y2)));
            S.insert(pair<pii,pii>(pii(x2,y2),pii(x1,y1)));
        }
        int dp[20][20]={{0}};
        dp[1][1]=1;
        rrep(i,1,gy+1){
            rrep(j,1,gx+1){
                if(S.find(pair<pii,pii>(pii(j,i),pii(j-1,i)))==S.end()){
                    dp[i][j]+=dp[i][j-1];
                }
                if(S.find(pair<pii,pii>(pii(j,i),pii(j,i-1)))==S.end()){
                    dp[i][j]+=dp[i-1][j];
                }
            }
        }

        if(dp[gy][gx])printf("%d\n",dp[gy][gx]);
        else puts("Miserable Hokusai!");
    }
    return 0;
}

Measured memory_bytes: 1212
module Main where

getChange :: Integer -> Integer
getChange n
	| n `mod` 1000 == 0 = 0
	| otherwise = 1000 - (n `mod` 1000)

thisLine :: String -> String
thisLine ('\n':_) = ""
thisLine (x:xs) = x : thisLine xs 

main :: IO ()
main = interact $ show . getChange . read -- . thisLine


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

bool check(string s)
{
    string tmp;
    tmp = s;
    reverse(tmp.begin(), tmp.end());
    if (s.compare(tmp) != 0)
        return false;
    else
        return true;
}

int main()
{
    int n;
    string s, tmp1, tmp2;
    cin >> s;

    // tmp1 = s;
    // tmp2 = s;
    // reverse(tmp1.begin(), tmp1.end());
    // if (s.compare(tmp1) != 0)
    // {
    //     cout << "No" << endl;
    //     return 0;
    // }

    // tmp1 = s.substr(0, (s.length() - 1) / 2);
    // tmp2 = s.substr(0, (s.length() - 1) / 2);
    // reverse(tmp2.begin(), tmp2.end());
    // if (tmp1.compare(tmp2) != 0)
    // {
    //     cout << "No" << endl;
    //     return 0;
    // }
    // tmp1 = s.substr((s.length() + 1) / 2, (s.length() - 1) / 2);
    // tmp2 = s.substr((s.length() + 1) / 2, (s.length() - 1) / 2);
    // reverse(tmp2.begin(), tmp2.end());
    // if (tmp1.compare(tmp2) != 0)
    // {

    //     return 0;
    // }

    if (check(s) && check(s.substr(0, (s.length() - 1) / 2)) 
        && check(s.substr((s.length() + 1) / 2, (s.length() - 1) / 2)))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main(){
    int h,w;
    int start = 1;
    while(1){
        scanf("%d %d",&h,&w);
        if(start)start = 0;
        else putchar('\n');
        if(h==0 && w == 0)break;
        for(int i = 0 ; i <h ;i++){
            for(int j = 0; j < w;j++)
                if(i==0 || j == 0 || i == h-1 || j == w-1)putchar('#');
                else putchar('.');
            putchar('\n');
        }
    }
    
    return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        int e=100000;
        for(int i=0;i<a.length()-2;i++){
            String b=a.substring(i,i+3);
            int c=Integer.parseInt(b);
            int d=c-753;
            e=Math.min(e, Math.abs(d));
        }
        System.out.println(e);
    }
    
}

Measured memory_bytes: 23636
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n, m =map(int, input().split())
ans_sub = make_divisors(m)
for i in ans_sub:
  if i >= n:
    print(m//i)
    break

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	double DP(double gn[][],int n,int m){
		double result = 0;
		double gli[][] = new double [n][m];
		for(int i = 0;i < n;i++){
			gli[i][0] = 1.00;
		}
		for(int i = 1;i < m;i++){
			for(int j = 0;j < n;j++){
				for(int k = 0;k < n;k++){
					if(gli[j][i] < gli[k][i-1]*gn[k][j]){
						gli[j][i] = gli[k][i-1]*gn[k][j];
					}
				}
			}
		}
		for(int j = 0;j < n;j++){
			if(gli[j][m-1] > result)result = gli[j][m-1];
		}
		return result;
	}
	void doIt() { 
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n+m==0)break;
			double gn[][] = new double [n][n];
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					gn[i][j] = sc.nextDouble();
				}
			}
			System.out.printf("%1.2f\n",DP(gn,n,m));
		}
     }
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
    	new Main().doIt();
    }
}

Measured memory_bytes: 66440
n = int(input())
a = list(map(int, input().split()))

sa = 0
count = [0, 0]

for i in range(n):
    now = a[i]
    sa += now
    if sa <= 0 and i%2 == 0:
        count[0] += 1 - sa
        sa = 1
    elif sa >= 0 and i%2 == 1:
        count[0] += 1 + sa
        sa = -1

sa = 0

for i in range(n):
    now = a[i]
    sa += now
    if sa <= 0 and i%2 == 1:
        count[1] += 1 - sa
        sa = 1
    elif sa >= 0 and i%2 == 0:
        count[1] += 1 + sa
        sa = -1

print(min(count))

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

using namespace std;

int main() {

	int r, c;
	cin >> r >> c;
	vector<string> inputs(r + 2);
	for (int i = 0; i < c + 2; ++i) {
		inputs[0] += "#";
	}
	for (int i = 1; i < r+1; ++i) {
		cin >> inputs[i];
		inputs[i] = "#" + inputs[i] + "#";
	}
	for (int i = 0; i < c + 2; ++i) {
		inputs[r+1] += "#";
	}
	for (int i = 0; i < r+2; ++i) {
		cout << inputs[i] << endl;
	}
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
// 10min
int main(void){
  int a, b;
  int sum = 0;
  int ans = 1;
  
  scanf("%d%d", &a, &b);

  if(b == 1){
    printf("0\n");
    return 0;
  }
  sum = a;
  //  printf("iii sum=%d\n", sum);
  
  while(sum < b){
    //    printf("aaa sum=%d\n", sum);
    sum += (a - 1);
    ans++;
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch EasyLinearProgramming | diff EasyLinearProgramming.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address EasyLinearProgramming.cpp && ./a.out

/*
 
 5/10/2020
 
 5:03-
 
 */

LL A,B,C,K;

LL solve() {
  if(A>=K) return K;
  LL res=A; K-=A;
  if(B>=K) return res;
  K-=B;
  if(K>0) return res-K;
  assert(false);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>A>>B>>C>>K;
  cout<<solve()<<endl;
  
  return 0;
}


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

int main(){
    enum{
        STARTMULTITABLE = 1,
        ENDMULTITABLE = 9
    };
    
    int i;
    for(i = STARTMULTITABLE; i <= ENDMULTITABLE; i++){
        int k;
        for(k = STARTMULTITABLE; k <= ENDMULTITABLE; k++){
            cout << i << "x" << k << "=" << (i*k) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1116