akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];
    ll res = 0;
    rep(i, N - 1) { res += min((X[i + 1] - X[i]) * A, B); }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
s = input().split(" ")
N = int(s[0])
K = int(s[1])

h = []
for i in range(N) : 
    s = input()
    h.append(int(s))
    
h = sorted(h)
minDiff = h[len(h) - 1] - h[0]
for i in range(N) : 
    try : 
        diff = h[i + K - 1] - h[i]
        minDiff = min(minDiff , diff)
        
    except : 
        if i == 0 : minDiff = 0
        continue
print(minDiff)

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

using namespace std;

string s;
typedef pair<int, int> Result;
Result parse(int k) {
    if(isdigit(s[k + 1])) {
        k++;
        int res = 0;
        while(isdigit(s[k])) {
            res = res * 10 + s[k++] - '0';
        }
        assert(s[k++] == ']');
        return make_pair(k, res / 2 + 1);
    }
    vector<int> v;
    k++;
    while(true) {
        if(s[k] == ']') break;
        Result r = parse(k);
        k = r.first;
        v.push_back(r.second);
    }
    assert(s[k++] == ']');
    sort(v.begin(), v.end());
    int res = 0;
    REP(i, v.size() / 2 + 1) {
        res += v[i];
    }
    return make_pair(k, res);
}

int main(){
    int T;
    cin >> T;
    while(T--) {
        cin >> s;
        Result r = parse(0);
        //cout << r.first << endl;
        assert(r.first == s.size());
        cout << r.second << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
N = int(input())
xyh = [list(map(int,input().split())) for i in range(N)]

for i in range(N):
    if xyh[i][2] != 0:
        xs, ys, hs = xyh[i]

for xt in range(101):
    for yt in range(101):
        ht = hs + abs(xt - xs) + abs(yt - ys)
        if all([xyh[i][2] == max(0, ht - abs(xt-xyh[i][0]) - abs(yt-xyh[i][1])) for i in range(N)]):
            xa, ya, ha = xt, yt, ht
            
print(xa,ya,ha)


Measured memory_bytes: 3064
using System;
using System.IO;

namespace Sandbox
{
    class Program
    {
        static void Main(string[] args)
        {
            var scanner = new Scanner();
            var n = scanner.GetNextAsInt();

            Console.WriteLine(180 * (n - 2));
        }
    }

    #region String Scanner
    public class Scanner
    {
        private const char Separator = ' ';
        private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput());
        private int _Pos;
        private string[] _Line = new string[0];

        #region get a element
        public string GetNext()
        {
            // ReSharper disable once InvertIf
            if (this._Pos >= this._Line.Length)
            {
                // ReSharper disable once PossibleNullReferenceException
                this._Line = this._Stream.ReadLine().Split(Separator);
                this._Pos = 0;
            }
            return this._Line[this._Pos++];
        }
        public int GetNextAsInt()
        {
            return int.Parse(this.GetNext());
        }
        public long GetNextAsLong()
        {
            return long.Parse(this.GetNext());
        }
        public double GetNextAsDouble()
        {
            return double.Parse(this.GetNext());
        }
        #endregion

        #region get array
        public string[] ToArrayFromNextLine()
        {
            if (this._Pos >= this._Line.Length)
            {
                // ReSharper disable once PossibleNullReferenceException
                this._Line = this._Stream.ReadLine().Split(Separator);
            }

            this._Pos = this._Line.Length;
            return this._Line;
        }
        public int[] ToIntArrayFromNextLine()
        {
            return ToIntArray(this.ToArrayFromNextLine());
        }
        public long[] ToLongArrayFromNextLine()
        {
            return ToLongArray(this.ToArrayFromNextLine());
        }
        public double[] ToDoubleArrayFromNextLine()
        {
            return ToDoubleArray(this.ToArrayFromNextLine());
        }
        #endregion

        #region convert array
        private static int[] ToIntArray(string[] array)
        {
            var result = new int[array.Length];
            for (var i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }
            return result;
        }
        private static long[] ToLongArray(string[] array)
        {
            var result = new long[array.Length];
            for (var i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }
            return result;
        }
        private static double[] ToDoubleArray(string[] array)
        {
            var result = new double[array.Length];
            for (var i = 0; i < array.Length; i++)
            {
                result[i] = double.Parse(array[i]);
            }
            return result;
        }
        #endregion
    }
    #endregion
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?'\n':' ');
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    for (int i=0;i<M;++i){
        int A; cin >> A;
        N-=A;
    }
    cout << max(-1,N) << '\n';
}

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

const int MAX = 3000;
int dp[MAX+1][MAX+1];
int parent[MAX+1][MAX+1];
int n, m;

int main(void){
    string s, t;
    cin>>s>>t;
    n = s.length();
    m = t.length();
    memset(dp, 0, sizeof dp);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else dp[i][j]=max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
        }
    }
    //cout<<dp[n][m]<<endl;
    int i=n, j=m;
    string out;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            out+=s[i-1];
            i--;
            j--;
        }
        else if(dp[i][j]==dp[i-1][j]){
            i--;
        }
        else j--;
    }
    for(int i=out.length()-1;i>=0;i--){
        cout<<out[i];
    }
    cout<<endl;

    return 0;
}


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

#define rep(i, n) for (int i=0; i< (n); ++i)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

// 無向グラフの問題。同じ連結成分を見つける。ある頂点からたどり着けるのはその連結成分だけ。その同じ連結成分のサイズがわかればいい。
//
// 連結成分の管理をどうするか。今回は途中で連結が増えたりとかは置きない。
// 1つずつ頂点を見ていく。そこでBFSとかDFSとかをする。

// UnionFind: ある点と点を同じグループにしてくださいみたいなのが簡単にできるデータ構造
// Union (くっつける), Find(どのグループ？)
// https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396

// https://www.youtube.com/watch?v=TdR816rqc3s
// https://atcoder.jp/contests/abc157/submissions/10472433
struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}  // コンストラクタには頂点数を渡しておく。最初は全員根なので-1で初期化
    int find(int x) {
        // 子は親のID、親はサイズを負にしたものを持つ。
        //
        if (d[x] < 0) return x;
        // return find(d[x]); 何の工夫もない状態はこう。だけどメモ化するために↓のようにやる
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);  // ルート成分を取り出してくる
        if (x == y) return false;  // ルートが一緒ならfalseを返す。今回の用途では返り値はなくてもいい。

        // 部分木が小さい方を大きい方にくっつけるための処理。
        // 深さを大きくなりすぎないようにするための処理だけど、なくても動く。
        // xの方が大きいようにしたいんだけど、負で持ってるからこの比較になる。
        if (d[x] > d[y]) swap(x,y);

        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int deg[100005]; // 辺の情報はいらなくて友達関係の数だけ覚えておけばいい。
vector<int> to[100005]; // ある頂点のブロック関係を隣接リストとして保存

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    UnionFind uf(n);

    int a, b;
    rep(i, m) {
        cin >> a >> b;
        --a; --b;
        deg[a]++;
        deg[b]++;
        // 友達関係の辺でUnionFindをくっつける
        uf.unite(a, b);
    }

    int c, d;
    rep(i, k) {
        cin >> c >> d;

        --c, --d;
        to[c].push_back(d);
        to[d].push_back(c);
    }

    rep(i, n) {
        int ans = uf.size(i) - 1 - deg[i];  // 連結成分サイズから自分自身と直接の友達の個数を引く
        for (int u: to[i]) {
            if (uf.same(i, u)) --ans;  // さらに同じ連結成分内のブロック関係の人数を引く。
        }
        printf("%d%c", ans, i == n-1 ? '\n' : ' ');  // 最後の行だけ改行にするテクニック
    }
}



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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if(a!=0 && b!=0) cout << n/(a+b)*a + min(n-n/(a+b)*(a+b), a) << endl;
  else if(a!=0 && b==0) cout << n << endl;
  else cout << 0 << endl;
  return 0;
}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x,int y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(int x,int y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(int x,int y)
{
    return (x%mod *1LL* y%mod)%mod;
}
inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}

lli MX = 1e6 + 7;

lli mypow(int b , int p){

    if(p<0) return -1;

    lli ret = 1;
    for(int i=1; i<=p; i++){
        ret *= b;
        if(ret>=MX) return -1;
    }
    return ret;
}

int main()
{
    ///freopen("output.txt","w",stdout);

    int n;
    scn(n);
    
    for(int i=1; i<10; i++){
        if(n%i) continue;
        
        if((n/i)<10 ){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";



    return 0;
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
string s;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

class UnionFind {
 public:
  UnionFind(int n) : n_(n) {}
  void Initialize();
  int GetRoot(int x);
  bool IsSame(int x, int y);
  void Unite(int x, int y);
  int GetSize(int x);

 private:
  const int n_;
  std::vector<int> parent_;
};

void UnionFind::Initialize() {
  parent_.assign(n_, -1);
}

int UnionFind::GetRoot(int x) {
  if (parent_[x] < 0) return x;
  else return parent_[x] = GetRoot(parent_[x]);
}

bool UnionFind::IsSame(int x, int y) {
  return GetRoot(x) == GetRoot(y);
}

void UnionFind::Unite(int x, int y) {
  x = GetRoot(x); y = GetRoot(y);
  if (x == y) return;
  if (parent_[x] > parent_[y]) std::swap(x, y);
  parent_[x] += parent_[y];
  parent_[y] = x;
  return;
}

int UnionFind::GetSize(int x) {
  return -parent_[GetRoot(x)];
}

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

  int64 n; int m; cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    --a[i]; --b[i];
  }
  // 最後は 1 + 2 + ... + n - 1
  int64 huben = n * (n - 1) / 2;
  vector<int64> ans;
  ans.emplace_back(huben);

  UnionFind uf(n);
  uf.Initialize();

  for (int i = m - 1; i >= 1; --i) {
    if (uf.IsSame(a[i], b[i])) {
      ans.emplace_back(huben);
    } else {
      huben -= uf.GetSize(a[i]) * uf.GetSize(b[i]);
      uf.Unite(a[i], b[i]);
      ans.emplace_back(huben);
    }
  }

  reverse(all(ans));
  for (int64 x : ans) {
    cout << x << '\n';
  }

  return 0;
}

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)

using namespace std;

int dp[3001][3001]={};

int main(){
	string s,t,ans;
	cin >> s >> t;
	int i, j;
	myfor(i,s.size())myfor(j,t.size()){
		if(s[i] == t[j])dp[i+1][j+1] = dp[i][j] + 1;
		dp[i+1][j+1] = max(dp[i+1][j],dp[i+1][j+1]); 
		dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j+1]);
	}
	int ansSize = dp[s.size()][t.size()];
	ans.resize(ansSize,'0');
	i = s.size();
	j = t.size();
	while(i>0 && j>0){
		if(dp[i][j] == dp[i-1][j]){
			i--;
		}else if(dp[i][j] == dp[i][j-1]){
			j--;
		}else{
			ans[--ansSize] = s[i-1];
			i--,j--;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35456
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdbool.h>

#define limit 1200
#define alpnum 26

int main(void) {
	char s[100],p[100];

	scanf("%s",s);
	scanf("%s",p);

	for(int i=0;i<strlen(s);i++){//開始地点をずらす
		int scount=i;
		bool canMake=true;
		for(int j=0;j<strlen(p);j++){//一文字ずつ比較
			if(s[scount]=='\0'){
				scount=0;
			}
			if(s[scount]!=p[j]){
				canMake=false;
				break;
			}
			if(scount+1>strlen(s)){
				scount=0;
			}
			else{
				scount++;
			}
		}
		if(canMake){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
 
int main()
{
    int  a[] ={0, 0};
    scanf("%d %d", &a[0], &a[1]);
    int d = a[0] / a[1];
    double f = (double)a[0] / a[1];
 
    cout.flags(ios::fixed);
    cout << d <<  " " << a[0] % a[1]  << " " << f << endl;
 
}

Measured memory_bytes: 3260
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

N=int(input())
ans=num2alpha(N)
print(str.lower(ans))

Measured memory_bytes: 9168
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>

typedef long long ll;
using namespace std;

void solve(int n){
    int c=0,d=0;
    string a[2];
    char last;
    
    cin >> a[0];
    
    for(int i=0;i<n;i++){
        last=a[i%2].c_str()[0];
        a[(i+1)%2]="";
        d=0;c=0;
        for(int j=1;a[i%2].c_str()[j]!='\0';j++){
            if(last==a[i%2].c_str()[j])
                c++;
            else{
                a[(i+1)%2]+=to_string(c+1)+last;
                last=a[i%2].c_str()[j];
                c=0;
            }
        }
        a[(i+1)%2]+=to_string(c+1)+last;
    }
    
    cout << a[n%2] << endl;
    
    return;
}

int main(){
    int n;
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        solve(n);
    }
}

Measured memory_bytes: 1380
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  int N, D;
  int X[10][10];
  cin >> N >> D;
  rep(i, N) {
    rep(j, D) {
      cin >> X[i][j];
    }
  }

  int ans = 0;
  rep(i, N-1) {
    for (int k = i + 1; k < N; k ++) {
      int distance = 0;
      rep(j, D) {
        int yz = X[i][j] - X[k][j];
        distance += yz * yz;
      }
      float dis = (int)(sqrt(distance));
      if (distance == dis * dis) {
        ans += 1;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

#define M 187
#define P 16

int mark[M][M];

int dp[M][M][P][M]; //y1 y2 x1 
int cut[M][M][M];

int H, W;

int main() {

	cin >> H >> W;
	for (int i = 0; i < H; i++)
	{
		string S;
		cin >> S;
		for (int j = 0; j < W; j++)
		{
			//if ((rand()) % 2 == 0) mark[i][j] = 0;
			if (S[j] == '.') mark[i][j] = 0;
			else mark[i][j] = 1;
		}
	}

	for (int w = 1; w <= W; w++)
	{
		for (int y1 = 0; y1 + w <= H; y1++)
		{
			int y2 = y1 + w;

			for (int x1 = 0; x1 < W; x1++)
			{
				dp[y1][x1][0][y2] = x1;
				
				if (w <= 2) {
					int flag = 0;
					for (int x2 = x1; x2 < W; x2++)
					{
						for (int y = y1; y < y2; y++)
						{
							flag |= (1 << mark[y][x2]);
						}
						if (flag == 3) break;
						else dp[y1][x1][0][y2] = x2 + 1;
					}
				}
				else {
					dp[y1][x1][0][y2] = min(dp[y1 + 1][x1][0][y2], dp[y1][x1][0][y2 - 1]);
				}
			}
		}
	}




	for (int p = 1; p < P; p++)
	{
		for (int h = 1; h <= H; h++)
		{
			for (int y1 = 0; y1 + h <= H; y1++)
			{
				int y2 = y1 + h;
				for (int x1 = 0; x1 < W; x1++)
				{
					//yoko
					int ans = dp[y1][x1][p - 1][y2];
					if (ans != W) ans = dp[y1][ans][p - 1][y2];

					if (h >= 2 && dp[y1][x1][p][y2 - 1] > ans) {
						int tmin = min(dp[y1][x1][p][y2 - 1], dp[y1 + 1][x1][p][y2]);

						//tate
						for (int y3 = y1 + 1; y3 < y2 && ans < tmin; y3++)
						{
							if (ans > dp[y1][x1][p - 1][y3]) break;
							while (y3 < y2 - 1 && dp[y1][x1][p - 1][y3] == dp[y1][x1][p - 1][y3 + 1]) {
								y3++;
							}

							if (ans < dp[y3][x1][p - 1][y2]) ans = max(ans, min(dp[y1][x1][p - 1][y3], dp[y3][x1][p - 1][y2]));
						}
					}

					dp[y1][x1][p][y2] = ans;

					//cout << y1 << " " << y2 << " " << x1 << " " << p << " " << ans << endl;
				}
			}
		}
	}

	int ret = P;
	for (int i = 0; i < P; i++)
	{
		if (dp[0][0][i][H] == W) {
			ret = i;
			break;
		}
	}

	cout << ret << endl;
	cin >> H;
}



Measured memory_bytes: 405760
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b; //隣り合う辺の長さ
    int c; //対角線の長さ
    int rectangular = 0, rhombus = 0; //長方形と菱形の個数
    
    while(scanf("%d,%d,%d", &a, &b, &c) != EOF){
        if(a * a + b * b == c * c) rectangular++;
        else if(a == b) rhombus++;
    }
    cout << rectangular << endl;
    cout << rhombus << endl;
}



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

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c;
  cin >> a >> b >> c;
  ll len = 0;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    if (len > 1e6) break;
    ll x = a / 2, y = b / 2, z = c / 2;
    a = x + y;
    b = y + z;
    c = z + x;
    len++;
  }
  cout << (len > 1e6 ? -1 : len) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
    cin>>n;
    n=n%1000;
    n=(1000-n)%1000;
    cout<<n<<endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <array>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>

#pragma warning(disable:4996)
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
typedef long long Int;

using namespace std;

struct point{
	int x;
	int y;
	point(int _y, int _x) :y(_y), x(_x){}
};

char tile[101][101];
stack<point> st;

int main()
{
	cin.tie(0); ios::sync_with_stdio(false);
	//fstream fs("input.txt");
	////////////ここから開始///////////


	int x(-1), y(-1);
	while (cin >> y >> x, x && y){
		REP(i, 101)REP(j, 101)tile[i][j] = 'C';
		REP(i, y){
			REP(j, x){
				cin >> tile[i][j];
			//	fs >> tile[i][j];
			}
		}

		int ans(0);
		int dx[]{0, 1, 0, -1};
		int dy[]{1, 0, -1, 0};

		REP(i, y){
			REP(j, x){
				if (tile[i][j] != 'C'){
					++ans;
					char now_c(tile[i][j]);
					tile[i][j] = 'C';
					st.emplace(i, j);
					while (!st.empty()){
						point now = st.top();
						st.pop();
						REP(i, 4){
							int x1 = now.x + dx[i];
							int y1 = now.y + dy[i];
							if (x1 >= x || x1 < 0 || y1 >= y || y1 < 0)
								continue;

							if (tile[y1][x1] == now_c){
								st.emplace(y1, x1);
								tile[y1][x1] = 'C';
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1272
#include <cstdio>
using namespace std;
#define ll long long
ll a,b,k;
int main(){
	scanf("%lld%lld%lld",&a,&b,&k);
	if (a+b<=k){
		puts("0 0");
	}
	else{
		if (a<=k){
			printf("0 %lld\n",b-(k-a));
		}
		else{
			printf("%lld %lld\n",a-k,b);
		}
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
a = [int(input()) for _ in range(N)]
count = 1
value = 1

for i in range(len(a)):
    if a[value-1] == 2:
        break
    value = a[value-1]
    count += 1

if count > len(a):
    count = -1

print(count)

Measured memory_bytes: 7084
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> inline bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

vector<int> LISLDS(const int N, const int A, const int B) {
    vector<int> ret;
    for(int i = B - 1; i >= 0; i--)
        ret.push_back(i);

    int n = N - B;
    int a = A - 1;
    if(a == 0) return ret;

    rep(i, a) {
        int siz = ret.size();
        for(int j = n / a - (i < n % a ? 0 : 1); j >= 0; j--)
            ret.push_back(siz + j);
    }

    return ret;
}

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

    int N, A, B;
    cin >> N >> A >> B;
    if(A + B > N + 1 || (ll)A * B < N) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> ret = LISLDS(N, A, B);

    rep(i, ret.size()) cout << ret[i] + 1 << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3568
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()

print(180*(N-2))

Measured memory_bytes: 5144
//#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <climits>
#include <bitset>

using namespace std;

const int SIZE = 1 << 17;
int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

const int MAXN = 100000;

char s[1 + MAXN];

bool Check(int k, int n) {
    if (k <= n - k + 1)
        return true;
    for (int i = n - k + 1; i < k; i++)
        if (s[i] != s[i + 1])
            return false;
    return true;
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    int left = 1, right = n, answer = 1;
    while (left <= right) {
        int middle = (left + right) / 2;
        if (Check(middle, n)) {
            answer = middle;
            left = middle + 1;
        }
        else
            right = middle - 1;
    }
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 256
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int a, b ,c ;
    cin >> a >> b >> c ;
    swap(a,b);
    swap(a,c);
    cout << a <<" " << b <<" " << c <<"\n";
}


Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
vector<int> each[100000+10];
int indeg[100000+10];
stack<int> s;
int dp[100000+10];
int res=0;
int main(){
	int n,m;
	cin>>n>>m;
	rep(i,m){
		int x,y;
		cin>>x>>y;
		each[x].PB(y);
		indeg[y]++;
	}
	rb(i,1,n)
		if(!indeg[i])
			s.push(i);
	while(!s.empty()){
		int now=s.top();s.pop();
		res=max(res,dp[now]);
		rep(i,each[now].size()){
			dp[each[now][i]]=max(dp[each[now][i]],dp[now]+1);
			if(!--indeg[each[now][i]]) s.push(each[now][i]);}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define lli long long int

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

lli lcm(lli a,lli b)
{
    return (a*b)/__gcd(a,b);
}
lli max(lli a,lli b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}

lli min(lli a,lli b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
lli power(lli x,lli n)
{
    lli res=1;
    while(n>0)
    {
        if(n%2==1)
        {
            res=(res*x);
        }
        x=(x*x);
        n=n/2;
    }

    return  res;

}
lli a,b,k;
int main()
{

        cin>>k;
        cin>>a>>b;
        if(a%k==0)
        {
            cout<<"OK"<<"\n";
            return 0;
        }
        lli d=a/k;
        lli res;
        res=(d+1)*k;
        if(res>=a && res<=b)
        {
            cout<<"OK"<<"\n";
        }
        else
        {
            cout<<"NG"<<"\n";
        }


	return 0;
}





Measured memory_bytes: 3624
def is_month(s):
    return 1 <= int(s) and int(s) <= 12


s = input()

first = s[:2]
second = s[2:]

if is_month(first) and is_month(second):
    print('AMBIGUOUS')
elif is_month(first) and not is_month(second):
    print('MMYY')
elif not is_month(first) and is_month(second):
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 38256
#include<stdio.h>

int main(void){
    int a, b;
    int i;
    int count = 0;

    scanf("%d %d", &a, &b);
    for(i=a;i<=b;i++){
        if(i%10 == i/10000){
            if((i%100)/10 == (i/1000)%10){
                count +=1;
            }
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
int main() {
	int N, M;
	int ans;
	scanf("%d%d",&N, &M);
	ans = (1900 * M + 100*(N - M))*(int)pow(2,(double)M);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long LL;
const int INF = int(1e9);
const int MAX = 40002;

char a[MAX];
char b[] = "KIHBR";
char c[] = "AKIHABARA";

int main()
{
    cin>>a;
    int len = strlen(a);

    if(len>9)
    {
        cout<<"NO"<<endl;
        return 0;
    }


    int ci = 0,ai = 0;
    while(ci<9)
    {
        if(a[ai]!=c[ci])
        {
            if(c[ci]=='A')
            {
                ci++;
            }
            else
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }
        else
        {
            ai++;ci++;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){
	string s; cin >> s;
	while(1){
		if(s == "") break;
		int l = s.length();
		if(s.length() >= 5 && s.substr(s.length() - 5, 5) == "dream") s.resize(s.length() - 5);
		if(s.length() >= 7 && s.substr(s.length() - 7, 7) == "dreamer") s.resize(s.length() - 7);
		if(s.length() >= 5 && s.substr(s.length() - 5, 5) == "erase") s.resize(s.length() - 5);
		if(s.length() >= 6 && s.substr(s.length() - 6, 6) == "eraser") s.resize(s.length() - 6);
		if(s.length() == l) break;
	}
	cout << (s == "" ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 512
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vp v;
    int ma = 2 * inf, Ma = 0;
    int mb = 2 * inf, Mb = -inf;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        int a = x + y, b = x - y;
        chmin(ma, a);
        chmax(Ma, a);
        chmin(mb, b);
        chmax(Mb, b);
    }
    cout << max(Ma - ma, Mb - mb);
}

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

#define EQ(a,b) (abs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()

using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Poly;
typedef pair<P,D> C;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<D,int> pdi;

const D EPS = 1e-8;
const D PI = acos(-1);

//for vector
inline P unit(P p){return p/abs(p);}

inline pair<P,P> norm(P p){return make_pair(p*P(0,1),p*P(0,-1));}

inline D dot(P x, P y){return real(conj(x)*y);}

inline D cross(P x, P y){return imag(conj(x)*y);}

//for line(segment)
inline int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

inline P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

//for polygon

//all vertex is already sorted.
inline D area(Poly p){
  if(p.sz<3)return 0;
  D res = cross(p[p.sz-1],p[0]);
  rep(i,p.sz-1)res += cross(p[i],p[i+1]);
  return res/2;
}

//vertexes are in the counter-clockwise order.
inline Poly convex_cut(Poly p,L l){
  Poly res;
  rep(i,p.sz){
    int nxt = (i+1)%p.sz;
    if(ccw(l.fs,l.sc,p[i]) != -1)res.pb(p[i]);
    if(ccw(l.fs,l.sc,p[i]) * ccw(l.fs,l.sc,p[nxt]) < 0){
      res.pb( line_cp(l, L(p[i],p[nxt]) ) );
    }
  }
  return res;
}

int main(){
  int n,d,V;
  while(scanf("%d%d%d",&n,&d,&V), n){
    D S = (D)V/d;
    Poly p(n);
    rep(i,n){
      int x,y; scanf("%d%d",&x,&y); p[i] = P(x,y);
    }

    D res = 0;
    rep(i,n){
      L b = L(p[i],p[(i+1)%n]);
      P n = unit(norm(b.sc-b.fs).fs);

      D left = 0, right = 4*1e3;
      rep(azu,30){
	D med = (left + right) / 2;
	L cut = L(b.sc+med*n,b.fs+med*n);
	Poly subp = convex_cut(p,cut);

	if(area(subp)<S)left = med;
	else right = med;
      }

      res = max(res, left);
    }

    printf("%.6lf\n",res);
  }
}

Measured memory_bytes: 1244
import numpy as np

def main():
    N, K = [int(i) for i in input().split()]
    v = [int(i) for i in input().split()]
    res = 0
    max_ext = min(K, N)
    for ext in range(1, max_ext + 1):
        for a in range(ext+1):
            v_ext = v[:a]
            if a < ext:
                v_ext += v[-(ext-a):]
            v_ext = sorted(v_ext)
            max_ret = K - ext
            cnt_neg = 0
            for i in range(min(max_ret, ext)):
                if v_ext[i] < 0:
                    cnt_neg += 1
            res = max(res, sum(v_ext[cnt_neg:]))

    print(res)



if __name__ == '__main__':
    main()



Measured memory_bytes: 12428
#import time

N = int(input())
datas = [int(input()) for _ in range(N)]
#start = time.time()
now_max = max(datas[1:])
max_index = datas.index(now_max)
diff = now_max - datas[0]

for i in range(1,N-1):
    if i == max_index:
        d = datas[i+1:]
        now_max = max(d)
        max_index = d.index(now_max)+i+1
    new_diff = now_max - datas[i]
    if diff < new_diff:
        diff = new_diff

print(diff)
#print('time :',time.time()-start)


Measured memory_bytes: 16452
#include <stdio.h>
int main(){
    for(int i=0; ;i++){
    int a,b,r;
    scanf("%d %d",&a,&b);
    if((a==0)&&(b==0)) break;
    if(a>b){
        r=a;
        a=b;
        b=r;
    }
    printf("%d %d\n",a,b);}
}


Measured memory_bytes: 2672
import java.util.Scanner;
class Main{
public static void main(String[] args){
  Scanner scan = new Scanner(System.in);
  int A1 = scan.nextInt();
  int A2 = scan.nextInt();
  int A3 = scan.nextInt();
  if((A1+A2+A3)<22){
    System.out.println("win");
  }else{
    System.out.println("bust");
  }
  }
}

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

int main(void)
{
    ios::sync_with_stdio(false);
    int sum=0;
    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++)
        sum += s[i]-'0';
    if(sum%9)
        cout<<"No\n";
    else
        cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 3708
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int N = sc.nextInt();
		int max = 0;
		int data[] = new int[N];
		int data1[] = new int[N];
		for(int i = 0;i<N;i++) {
			data[i] = sc.nextInt();
		}
		max =Math.abs(k-data[N-1] + data[0]);
		for(int i =0; i<N-1; i++) {
			    max = Math.max (data[i+1]-data[i],max);
		
		}
	
		System.out.println(k-max);
	}

}

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

using namespace std;

int main(){
    int ans=0,N;
    cin >> N;
    vector<int> L(2*N);
    for(int i=0;i<2*N;i++){
        cin >> L[i];
    }

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

    for(int i=0;i<2*N;i++){
        if(i%2==0){
            ans += L[i];
        }
    }

    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
  
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, b[N], a[N];
int main (){
    scanf ("%d", &n);
    for (int i = 1; i < n; ++i) scanf ("%d", b + i);
    for (int i = n - 1; i >= 1; --i){
        if (i == n - 1) a[i + 1] = b[i];
        if (i != 1) a[i] = min(b[i], b[i - 1]);
        else a[i] = b[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) ans += a[i];
    return !printf ("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double pi = 3.141592653589793238;
    double theta = (m / 60.0 - (60 * h + m) / 720.0) * 2.0 * pi;

    double ans2 = a * a + b * b - 2 * a * b * cos(theta);
    double ans = sqrt(ans2);
    cout << fixed << setprecision(20);
    cout << ans << endl;
}

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

int a[666666], d[666666], x[222222], y[222222];
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n + n; i++)
        scanf("%d", a + i);
    for(int i = 0; i < n; i++)
        a[i + n + n] = a[i + n];
    fill(x, x + n, 1);
    for(int k = 1; k < 1 << 30; k += k) {
        fill(y, y + n, 0);
        for(int l : {0, k}) {
            int j;
            d[0] = j = -1;
            for(int i = 0; i < n * 3; d[++i] = ++j)
                while(j >= 0 &&
                      ((a[i] ^ a[j] ^ (i < n) * l ^ (j < n) * l) & k ||
                       i == n || j == n))
                    j = d[j];
            for(int i = 0; i < n; i++)
                y[i] |= d[i + n + n + 1] >= n;
        }
        for(int i = 0; i < n; i++)
            x[i] &= y[i];
    }
    for(int i = 0; i < n; i++)
        if(x[n - i - 1])
            cout << i << ' ' << (a[i] ^ a[n + n]) << '\n';
    cout << flush;
    return 0;
}


Measured memory_bytes: 9984
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s; cin >> s;
	unsigned long long k; cin >> k;
	if (k < s.size()) {
		for (int i = 0; i < k - 1; i++) {
			if (s[i] != '1') {
				cout << s[i] << endl;
				return 0;
			}
		}
		cout << s[k - 1] << endl;
	}
	else {
		for (int i = 0; i < s.size() - 1; i++) {
			if (s[i] != '1') {
				cout << s[i] << endl;
				return 0;
			}
		}
		cout << s[s.size() - 1] << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#define N 505
inline long long _c(long long x,long long y){return x<y?x:y;}
int i,j,k,n;long long a[N][N],b[N][N],f[N][N],x;
inline long long _a(int o,int p,int u,int v){return a[p][v]-a[p][u]-a[o][v]+a[o][u];}
inline long long _b(int o,int p,int u,int v){return b[p][v]-b[p][u]-b[o][v]+b[o][u];}
int main()
{
    scanf("%d",&n),x=0x3f3f3f3f3f3f3f3fll;
    for(i=1;i<=n;i++)for(j=1;j<=n;a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1],b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1],f[i][j++]=x)i!=j?i<j?scanf("%lld",a[i]+j):scanf("%lld",b[i]+j):0;
    for(i=1;i<=n;i++)f[0][i]=_a(0,i,0,i);
    for(i=1;i<n;i++)for(j=i+1;j<=n;j++)for(k=0;k<i;k++)f[i][j]=_c(f[i][j],f[k][i]+_a(i,j,i,j)+_b(i,j,0,k));
    for(i=0;i<n;i++)x=_c(x,f[i][n]);
    return 0*printf("%lld\n",x);
}

Measured memory_bytes: 6144
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;
char g[10][10],g2[10][10];
int h,w,k,ans=0;

int main() {
    scanf("%d%d%d",&h,&w,&k);
    for(int i=0;i<h;i++){
        scanf("%s",g[i]);
    }
    for(int s=0;s<(1<<(h+w));s++){
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                g2[i][j]=g[i][j];
        for(int i=0;i<h;i++){
            if(s&(1<<i)){
                for(int j=0;j<w;j++)
                    g2[i][j]='r';
            }
        }
        for(int j=0;j<w;j++){
            if(s&(1<<(j+h))){
                for(int i=0;i<h;i++)
                    g2[i][j]='r';
            }
        }
        int cntb=0;
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                if(g2[i][j]=='#') cntb++;
        if(cntb==k) ans++;
    }
    printf("%d",ans);
    return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int num[5000];

int main() {
	int a, b, c;
	int rec = 0, rho = 0;
	while(scanf("%d,%d,%d", &a, &b, &c) != EOF) {
		if(c * c == a * a + b * b) rec++;
		if(a == b) rho++;
	}
	printf("%d\n%d\n",rec, rho);
	return 0;
}

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

bool my_compare(string a, string b) {
    if (a.length() == b.length()) {
        for (int i = 0; i < a.length(); i++) {
            if (a[i] != b[i]) {
                return a[i] < b[i];
            }
        }
        return true;
    } else {
        return a.length() < b.length();
    }
}

int main() {
    int K;
    cin >> K;
    set<string> s;
    set<string> tmp1{"1", "2", "3", "4", "5", "6", "7", "8", "9"};
    for (int i = 1; i <= 9; i++) {
        s.insert(to_string(i));
    }
    for (int i = 0; i < 9; i++) {
        set<string> tmp2;
        for (string t : tmp1) {
            tmp2.insert(t + t.back());
            s.insert(t + t.back());
            if (t.back() == '9') {
                s.insert(t + '8');
                tmp2.insert(t + '8');
            } else if (t.back() == '0') {
                s.insert(t + '1');
                tmp2.insert(t + '1');
            } else {
                char c1 = (char)(t.back() - 1);
                char c2 = (char)(t.back() + 1);
                s.insert(t + c1);
                s.insert(t + c2);
                tmp2.insert(t + c1);
                tmp2.insert(t + c2);
            }
        }
        tmp1 = tmp2;
    }
    vector<string> list;
    for (string t : s) {
        list.push_back(t);
    }
    sort(list.begin(), list.end(), my_compare);
    cout << list[K - 1] << "\n"; 
    return 0;
}

Measured memory_bytes: 46448
@L=1..($z=<>)+2;
@B=1e9;
map{
	$z+=!--$B[$-=/ /&&$L[$A[$`-1]]++];
	$z-=!$B[$-=--$L[/ /?$A[$`-1]=$':$_]]++;
	/ /&&print$z,$/
}(@A=glob<>),<>


Measured memory_bytes: 113612
# solution 2
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
L = []
for i in range(X):
    for j in range(Y):
        if (i+1)*(j+1) > K:
            break
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) > K:
                break
            else:
                L.append(A[i] + B[j] + C[k])
L.sort(reverse=True)
for l in range(K):
    print(L[l])

Measured memory_bytes: 8708