akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    string s;
    ll Q;
    cin >> s >> Q;
    deque<char> que;
    REP(i, s.size()){
        que.push_back(s[i]);
    }
    bool h = false;
    REP(i, Q){
        ll t;
        cin >> t;
        if(t == 1){
            h = !h;
        }
        else{
            ll f;
            char c;
            cin >> f >> c;
            if(f == 1){
                if(!h){
                    que.push_front(c);
                }
                else{
                    que.push_back(c);
                }
            }
            else{
                if(h){
                    que.push_front(c);
                }
                else{
                    que.push_back(c);
                }
            }
        }
    }
    string ans;
    while(!que.empty()){
        ans += que.front();
        que.pop_front();
    }
    if(h) reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 1412
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    string s, t;
    cin >> s >> t;
	for (int i = 0; i < n; i++) {
		bool ok = 1;
		for (int j = i; j < n; j++) {
			if (s[j] != t[j - i]) {
				ok = 0;
			}
		}	
		if (ok) {
			cout << 2 * n - (n - i);
			return 0;
		}
	}
	cout << 2 * n << endl;
    return 0;
}

Measured memory_bytes: 256
function main()
  n=parse(Int,readline())
  a=parse.(Int,split(readline()))
  ans=0
  for i=2:n
    if a[i]<a[i-1]
      ans+=a[i-1]-a[i]
      a[i]=a[i-1]
    end
  end
  println(ans)
end
main()

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

namespace AtCoder
{
    class Program
    {
        static int LoadInt() { return int.Parse(Console.ReadLine()); }
        static int[] LoadIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }

        static void Main(string[] args)
        {
            var N = LoadInt();
            var array = new List<int>();
            foreach(var i in Enumerable.Range(0, N))
            {
                array.Add(LoadInt());
            }
            var sortedArray = array.OrderByDescending(x => x).ToList();
            foreach(var i in Enumerable.Range(0, N))
            {
                if(array[i] == sortedArray[0])
                {
                    Console.WriteLine(sortedArray[1]);
                }
                else
                {
                    Console.WriteLine(sortedArray[0]);
                }
            }
        }

    }
}


Measured memory_bytes: 22740
def right(n, D):
    for i in range(D):
        if n == 0 or n % 100 != 0:
            return False
        n = int(n / 100)
    if n % 100 == 0:
        return False
    return True


D, N = map(int, input().split())
count = 0
i = 0
while count < N:
    if right(i, D):
        count += 1
    i += 1
print(i - 1)


Measured memory_bytes: 3060
k = gets.to_i

a = []
16.times{|i|
  10000.times{|j|
    w = ((j+1).to_s + "9"*i).to_i
    a << w if w <= 10**15
  }
}

a.uniq!.sort!

a = a.map{|t|
  tmp = t
  x = 0
  while tmp>0
    x += tmp%10
    tmp /= 10
  end
  [(t/x)+((t%x).to_f/x),t]
}

a.sort!{|a,b|a[0]<=>b[0]}

prev = 0
ans = []
a.each{|(v,t)|
  if prev < t
    ans << t
    prev = t
  end
}

ans[0...k].each{|t| p t}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;

int main(void) {
	li k, x;
	cin >> k >> x;
	cout << (k * 500 >= x ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var str="";
while(true){
   var v=Arr.shift()-0;
   if(v==0)break;
   var m=(Arr.shift()).split(" ").map(Number);
   var money=(10*m[0]+50*m[1]+100*m[2]+500*m[3])-v;
   var M=[0,0,0,0];
   while(500<=money){M[3]++;money-=500;}
   while(100<=money){M[2]++;money-=100;}
   while(50<=money){M[1]++;money-=50;}
   while(10<=money){M[0]++;money-=10;}
   var coin=[10,50,100,500];
   m.forEach(function(v,i){
      if(v>M[i])str+=coin[i]+" "+(v-M[i])+"\n";
   });
   str+="\n";
}
console.log(str.trim());

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 1000000005
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    int t, d, ans;
    cin>>t;
    d=t/1000;
    if(t%1000!=0)d++;
    ans=(d*1000)-t;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i,n){
    cin >> v[i];
  }
  int hmax=v[0];
  int ans=0;
  rep(i,n){
    if(v[i]>=hmax){
      ans++;
      hmax=v[i];
    }
  }
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
// ConsoleApplication.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <deque>
#include <stack>

using namespace std;

int main()
{
	stack<int> stack;
	string element;
	while (cin>> element) {
		const bool plus = element == "+";
		const bool minus = element == "-";
		const bool multi = element == "*";
		if (plus || minus || multi) {
			const int secondOperand = stack.top();
			stack.pop();
			const int firstOperand = stack.top();
			stack.pop();
			int result; {
				if (plus) result = firstOperand + secondOperand;
				else if (minus)result = firstOperand - secondOperand;
				else result = firstOperand * secondOperand;
			}
			stack.push(result);
		}
		else {
			stack.push(stoi(element));
		}
	}
	cout << stack.top() << endl;


	return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	double b,sum;
	string s;
	cin>>a;
	for(int i=0;i<a;i++)
	{
		cin>>b;
		sum=sum+1/b;
	}
	
	cout<<1/sum;
}

Measured memory_bytes: 256
MAX = 2100
MOD = 1000000007

fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX


def com_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


def resolve():
    com_init()
    N, K = map(int, input().split())
    R = N - K

    for i in range(K):
        print(com(K-1, i) * com(R+1, i+1) % MOD)
        

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 43248
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

template<typename T>
struct BIT{
  int n;
  vector<T> d;
  BIT(int n = 0):n(n),d(n+1){}
  void add(int i,T x=1){
    for(i++;i<=n;i += i&-i){
      d[i] += x;
    }
  }
  T sum(int i){
    T x = 0;
    for(i++;i>0;i -= i&-i){
      x += d[i];
    }
    return x;
  }
};
 
int main(){
  int h,w,n;cin >> h >> w >> n;
  int sr,sc; cin >> sr >> sc;
  string s,t;cin >> s >> t;
  string right = "",left = "",up = "",down = "";
  rep(i,n){
    char ch = s[i];
    if(ch == 'U') up.push_back(ch);
    else if(ch == 'D') down.push_back(ch);
    else if(ch == 'R') right.push_back(ch);
    else left.push_back(ch);
    ch = t[i];
    if(ch == 'U') down.push_back(ch);
    else if(ch == 'D') up.push_back(ch);
    else if(ch == 'R') left.push_back(ch);
    else right.push_back(ch);
  }
  int cnt = sr;
  rep(i,up.size()){
    if(up[i]=='U') cnt--;
    else {
      cnt++;
      if(cnt > h) cnt = h;
    }
    if(cnt <= 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cnt = sr;
  rep(i,down.size()){
    if(down[i]=='D') cnt++;
    else {
      cnt--;
      if(cnt <= 0) cnt = 1;
    }
    if(cnt > h){
      cout << "NO" << endl;
      return 0;
    }
  }
  cnt = sc;
  rep(i,right.size()){
    if(right[i]=='R') cnt++;
    else {
      cnt--;
      if(cnt <= 0) cnt = 1;
    }
    if(cnt > w){
      cout << "NO" << endl;
      return 0;
    }
  }
  cnt = sc;
  //cout << left << endl;
  rep(i,left.size()){
    if(left[i]=='L') cnt--;
    else {
      cnt++;
      if(cnt > w) cnt = w;
    }
    if(cnt <= 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  
}

Measured memory_bytes: 4468
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n, d, x;
  cin >> n >> d >> x;
  int a[101];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++){
    for (int j = 1; j <= d; j += a[i]){
      x++;
    }
  }

  cout << x << endl;
  return 0;
}

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

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


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

using namespace std;

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

    vector <int> height(no_of_stones + 1, 0);
    for(int i = 0; i < no_of_stones; i++)
        cin >> height[i];

    vector <int> minimum_cost(no_of_stones + 1);
    minimum_cost[1] = abs(height[1] - height[0]);
    for(int i = 2; i < no_of_stones; i++)
        minimum_cost[i] = min(minimum_cost[i - 1] + abs(height[i] - height[i - 1]),
                              minimum_cost[i - 2] + abs(height[i] - height[i - 2]));

    cout << minimum_cost[no_of_stones-1];
    return 0;
}

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

const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

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

    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    rep(i, h) cin >> s[i];

    int ans = 0;
    rep(si, h) rep(sj, w){
        if(s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x){
            if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i, j));
        };

        update(si, sj, 0);

        while(!q.empty()){
            int i = q.front().first;
            int j = q.front().second;
            q.pop();

            rep(dir, 4){
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
                if(s[ni][nj] == '#') continue;

                update(ni, nj, dist[i][j]+1);
            }

            rep(i, h) rep(j, w){
                if(dist[i][j] == INF) continue;
                ans = max(ans, dist[i][j]);
            }
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#def main(S, b):

if __name__ == '__main__':
    a, b, c = map(int, input().split())

    ans = 0

    if (a == b):
        ans += 1
    if (b == c):
        ans += 1
    if (a == c):
        ans += 1
    if (ans == 1):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(auto i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll INF = ~(1<<31);
#define fs first
#define sc second
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
    return (a % b + b) % b;
}

ll n;
vi A;
ll m[3020][3020];

ll dp(ll start, ll end) {
    if(start > end) {
        return 0;
    } else {
        if(m[start][end] != -1) return m[start][end];
        ll moves = start+(n-end-1);
        if(moves % 2 == 0) {
            return m[start][end] = max(dp(start+1,end)+A[start], dp(start,end-1)+A[end]);
        } else {
            return m[start][end] = min(dp(start+1,end)-A[start], dp(start,end-1)-A[end]);
        }
    }

}


int main() {
    cin.sync_with_stdio(false);
    memset(m,-1,sizeof(m));
    cin >> n;
    A = vi(n);
    rep(i,0,n) cin >> A[i];
    cout << dp(0,n-1) << endl;
    return 0;
}


Measured memory_bytes: 71680
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n, d;
  cin >> n >> d;
  ll mireru = d * 2 + 1;
  ll res = n / mireru;
  if (n % mireru != 0)
  {
    res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define multi_test true and false
#define all(a) (a).begin(), (a).end()
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int &i : arr)
        cin >> i;
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j < 3; j++)
        {
            if (j + i < n)
            {
                dp[j + i] = min(dp[j + i], dp[i] + abs(arr[j + i] - arr[i]));
            }
        }
    }
    cout << dp.back() << endl;
}

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

    int test = 1;
    if (multi_test)
        cin >> test;
    while (test--)
        solve();

    return 0;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 1000 + 47;

LL I, O, T, J, L, S, Z;
LL getAns()
{
	return (I / 2) * 2 + O + (L / 2) * 2 + (J / 2) * 2;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	
	cin >> I >> O >> T >> J >> L >> S >> Z;
	LL ans = getAns();
	if (J && L && I)
	{
		J--;
		L--;
		I--;
		ans = max(ans, getAns() + 3);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

int n;
int64_t h[100001];
int64_t dp[100001];

const int64_t INF = 1000000000LL * 100000000LL;

int64_t f(int i) {
  if (i >= n) return INF;
  if (i == n-1) return 0;
  if (dp[i] != -1) return dp[i];
  int64_t cost = INF;
  if (i + 1 < n)
    cost = std::min(cost, std::abs(h[i] - h[i + 1]) + f(i + 1));
  if (i + 2 < n)
    cost = std::min(cost, std::abs(h[i] - h[i + 2]) + f(i + 2));
  return dp[i] = cost;
}

int main() {
  std::memset(dp, -1, sizeof(dp));
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> h[i];
  }
  std::cout << f(0) << '\n';
}


Measured memory_bytes: 6528
#include <stdio.h>

int main(void) {
	int N;
	int h[128];
	int i;
	int cur[128] = {0};
	int count = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &h[i]) != 1) return 1;
	}
	for (;;) {
		int start = -1, end = -1;
		for (i = 0; i < N; i++) {
			if (cur[i] < h[i]) {
				if (start < 0) start = i;
			} else {
				if (start >= 0) {
					end = i;
					break;
				}
			}
		}
		if (start < 0) break;
		if (end < 0) end = N;
		for (i = start; i < end; i++) {
			cur[i]++;
		}
		count++;
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
/**
*    created: 21.06.2020 21:33:02
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int s;
    rep(i,n) {
        if (i == 0) s = a[i];
        else s = s ^ a[i];
    }
    rep(i,n) {
        int ans = s ^ a[i];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4768
# -*- coding: utf-8 -*-
"""
Created on Sat Dec  8 20:51:13 2018

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
    
all(nstr.count(c) for c in '753')
"""
N, K = map(int, input().split())


h = [0]*N
for n in range(N):
    h[n] = int(input())

h.sort()
diff_min = math.pow(10, 9)
#print(h)
for i in range(len(h)-K+1):
    #print(h[i], h[i+K-1])
    temp_diff = h[i+K-1] - h[i]
    
    if diff_min > temp_diff:
        diff_min = temp_diff
    if diff_min == 0:
        break
"""
for l in list(itertools.combinations(h,K)):
    
    temp_diff = l[np.argmax(l)] - l[np.argmin(l)]
    if diff_min > temp_diff:
        diff_min = temp_diff
    if diff_min == 0:
        break
"""     
print(diff_min)

Measured memory_bytes: 17612
package main

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

func main() {
	A := nextInt()
	B := nextInt()
	K := nextInt()
	var cnt int
	for i := min(A, B); i >= 1; i-- {
		if A%i == 0 && B%i == 0 {
			if cnt == K-1 {
				fmt.Println(i)
				return
			}

			cnt++
		}
	}
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  if(N%1000==0){
    cout<<0<<endl;
  }
  else{
    cout<<(1+N/1000)*1000-N<<endl;
  }
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
typedef unsigned long long ll;
using namespace std;
ll gcd(ll a,ll b)
{
    if(a<b) swap(a,b);
    if(b==0) return a;
    else if(a&1&&b&1) return gcd(b,(a-b)>>1);
    else if(a&1&&b) return gcd(a,b>>1);
    else if(a&&b&1) return gcd(a>>1,b);
    else return 2*gcd(a>>1,b>>1);
}
int main(void)
{
    ll a,b;
    while(cin>>a>>b) {
        cout<<gcd(a,b)<<' '<<a*b/gcd(a,b)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3104
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

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

    if (m == 0) {
        if (k == 0) {
            printf("0 0\n");
            return 0;
        }
        printf("-1\n");
        return 0;
    }

    if (m == 1) {
        if (k == 0) {
            printf("0 0 1 1\n");
            return 0;
        }
        printf("-1\n");
        return 0;
    }

    auto Mx = (1LL << m) - 1;
    if (k > Mx) {
        printf("-1\n");
        return 0;
    }

    for (auto i = 0LL; i <= Mx; ++i)
        if (i != k)
            printf("%lld ", i);

    printf("%lld ", k);

    for (auto i = Mx; i >= 0; --i)
        if (i != k)
            printf("%lld ", i);

    printf("%lld\n", k);
    return 0;
}


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

int n, A, B, flag, mn = 2e9;
long long ans;

int main() {
	scanf("%d", &n);
	while (n--) {
		scanf("%d%d", &A, &B);
		if (A != B) flag = 1;
		ans += A; 
		if (A > B) mn = min(mn, B);
	}
	ans -= mn;
	printf("%lld\n", flag * ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		int sum = 0;
		for(int i = 1; i < num + 1 ; i++){
			sum += i;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
bool rMin(int &a, int b) {
    return b < a ? a = b, true : false;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n, k;
    cin>>n>>k;
    vector<int> dp(n, 1e9);
    int h[100000];
    for(int i = 0; i< n; i++) cin>>h[i];
    dp[0] = 0;
    for(int i = 1; i< n; i++){
        for(int j = 1; j<= k; j++){
            if(i-j >= 0) rMin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout<<dp[n-1]<<"\n";
        
}


Measured memory_bytes: 4024
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    ll a,b;
    cin>>n>>a>>b;
    if(n%(a+b)==0) cout<<a*(n/(a+b))<<endl;
    else if(n%(a+b)>=a)cout<<a*(n/(a+b))+a<<endl;
    else cout<<a*(n/(a+b))+n%(a+b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A[5];
     int loss[5];
    for(int i=0;i<5;i++){
        cin >> A[i];
        if(A[i]%10==0){
            loss[i] = 0;
        }else{
        loss[i] = 10-(A[i]%10);
        }
    }

    sort(loss,loss+5,greater<int>());
    loss[0]=0;
    int ans=0;
    
    for(int i=0;i<5;i++){
        ans += A[i]+loss[i];
    }
    cout << ans << endl;
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M, H[101010];
vector<int> E[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> H[i];
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}

	int ans = 0;
	rep(cu, 0, N) {
		bool ok = true;
		fore(to, E[cu]) if (H[cu] <= H[to]) ok = false;
		if (ok) ans++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 9188
#include<stdio.h>
#define MAX 100000
#define NIL 200000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left ,int mid,int right){
	int i,j,k;
	int n1 = mid - left;
	int n2 = right - mid;
	
	for(i=0; i<n1; i++){ L[i] = A[left+i]; }
	for(i=0; i<n2; i++){ R[i]=A[mid+i]; }
	
	L[n1].value = NIL;
	R[n2].value = NIL;
	i=0, j=0;
	
	for(k=left;k<right;k++){
		if(L[i].value <= R[j].value){ A[k]=L[i++]; }
		else { A[k] = R[j++]; }
	}
}
void quick(struct Card A[],int n,int p,int r){
	int q;
	
	if(p<r){
		q = partition(A, n, p, r);
		quick(A, n, p, q-1);
		quick(A, n, q+1, r);
	}
}

void mergeSort(struct Card A[],int n,int left,int right){
	int mid;
	
	if(left + 1 < right){
		mid = (left + right)/2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int partition(struct Card A[],int n,int p,int r){
	int i,j;
	struct Card t,x;
	
	x = A[r];
	i = p-1;
	
	for(j=p; j<r; j++){
		if(A[j].value<=x.value){
			i++;
			t = A[i];
			A[i] = A[j];
			A[j] = t;
		}
	}
	
	t = A[i+1];
	A[i+1] = A[r];
	A[j] = t;
	
	return i+1;
}


int main(){
	int n, i, v;
	struct Card A[MAX],B[MAX];
	char S[10];
	int stable = 1;
	scanf("%d", &n);
	
	for(i=0; i<n; i++){
		scanf("%s %d", S, &v);
		A[i].suit = S[0];
		B[i].suit = S[0];
		A[i].value = v;
		B[i].value = v;
	}
	mergeSort(A,n,0,n);
	quick(B,n,0,n-1);
	
	for(i=0;i<n;i++){
		if(A[i].suit != B[i].suit)stable=0;
	}
	
	if(stable==1)printf("Stable\n");
	else printf("Not stable\n");
	
	for(i=0;i<n;i++){
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}



Measured memory_bytes: 4084
# 129 B

n = int(input())
l = list(map(int, input().split()))
diff = (100 ** 100)

for t in range(len(l)):
    s1 = 0
    s2 = 0

    for i in range(len(l)):
        if i <= t:
            s1 += l[i]
        else:
            s2 += l[i]
    x = abs(s2 - s1)     
    if x <= diff:
        diff = x 
         
print(diff)
    


Measured memory_bytes: 9124
#include <stdio.h>
int solve(int A[], int size, int i, int m){
  int res=0;
  if(m==0)
	return 1;
  if(i>=size)
	return 0;
  res=solve(A, size, i+1, m)||solve(A, size, i+1, m-A[i]);
  return res;
}
int main(){
  int n, q, A[22];
  scanf("%d", &n);
  int i;
  int key;
  for(i=0; i<n; ++i){
	scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; ++i){
	scanf("%d", &key);
	if(solve(A, n, 0, key)==1)
	  printf("yes\n");
	else if(solve(A, n, 0, key)==0)
	  printf("no\n");
  }
  return 0;
}



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

int main(){
    string s,t;
    cin>>s>>t;
    int ans = 0;
    for(int i=0; i<3; i++){
        if(s[i] == t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import bisect

N = int(input())
lst_a = sorted([int(x) for x in input().split()])
lst_b = sorted([int(x) for x in input().split()])
lst_c = sorted([int(x) for x in input().split()])
ans = 0
for b in lst_b:
    i = bisect.bisect_left(lst_a, b)
    j = bisect.bisect_right(lst_c, b)
    if i > 0 and j != len(lst_c):
        ans += i * (N - j)

print(ans)


Measured memory_bytes: 22452
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
    if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

int main() {
    while(true) {
        int N;
        cin >> N;
        if(N == 0) break;

        vector<int> acum(24 * 3600 + 5);
        vector<int> simul(24 * 3600 + 5);
        REP(i, N) {
            string s, t;
            cin >> s >> t;
            vector<string> s_split = split(s, ':');
            vector<string> t_split = split(t, ':');
            int s_int = stoi(s_split[0]) * 60 * 60 + stoi(s_split[1]) * 60 + stoi(s_split[2]);
            int t_int = stoi(t_split[0]) * 60 * 60 + stoi(t_split[1]) * 60 + stoi(t_split[2]);
            // if(s_int == t_int) cerr << s << " " << t << endl;
            acum[s_int]++;
            acum[t_int]--;
            // if(s_int == t_int) simul[s_int]++;
        }
        FOR(i, 1, 24 * 3600)
            acum[i] += acum[i-1];

        int ans = 0;
        FOR(i, 0, 24 * 3600)
            ans = max(ans, acum[i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>

using namespace std;

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

    bool can = false;
    for (int i = 0; i < 25; i++){   // 25: 100 / 4
        for (int j = 0; j < 15; j ++){  // 15: 100 / 7
            if (4 * i + 7 * j == N){
                can = true;
                break;
            }
        }
        if (can) break;
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF (1e9)
int main(){
  while(1){
    int N;
    int x[100],y[100];
    vector<int> X,Y;
    int ax=INF,bx=-INF;
    int ay=INF,by=-INF;
     
    scanf("%d",&N);
    if(N==0)break;
    for(int i=0;i<N;i++){
      scanf("%d %d",&x[i],&y[i]);
      X.push_back(x[i]);
      Y.push_back(y[i]);
    }
    for(int i=0;i<4;i++){
      int px,py;
      cin>>px>>py;
      ax=min(ax,px);
      ay=min(ay,py);
      bx=max(bx,px);
      by=max(by,py);
    }
    X.push_back(ax);
    Y.push_back(ay);
    X.push_back(bx);
    Y.push_back(by);
     
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    X.erase( unique( X.begin(), X.end() ), X.end() );
    Y.erase( unique( Y.begin(), Y.end() ), Y.end() );
     
    for(int i=0;i<N;i++){
      x[i]=lower_bound(X.begin(),X.end(),x[i])-X.begin();
      y[i]=lower_bound(Y.begin(),Y.end(),y[i])-Y.begin();
    }
    ax=lower_bound(X.begin(),X.end(),ax)-X.begin();
    ay=lower_bound(Y.begin(),Y.end(),ay)-Y.begin();
    bx=lower_bound(X.begin(),X.end(),bx)-X.begin();
    by=lower_bound(Y.begin(),Y.end(),by)-Y.begin();
    vector<int> G[300];
    for(int i=0;i<N;i++){
      int px=x[i],py=y[i];
      int qx=x[ (i+1)%N ];
      int qy=y[ (i+1)%N ];
      if(qy!=py)continue;
      G[py].push_back( min(px,qx) );
      G[py].push_back( max(px,qx) );
    }
 
    int t[300]={};
     
    long long ans=0;
    for(int py=0;py+1<(int)Y.size();py++){
      for(int i=0;i<(int)G[py].size();i+=2){
        int ax=G[py][i];
        int bx=G[py][i+1];
        for(int px=ax;px<bx;px++){
          t[px]=1-t[px];
        }
      }
      for(int px=0;px+1<(int)X.size();px++){
        if(t[px]==0)continue;
        if(ax<=px&&px<bx&&ay<=py&&py<by)continue;
        long long dy=Y[py+1]-Y[py];
        long long dx=X[px+1]-X[px];
        ans+=dy*dx;
      }
    }
    printf("%lld\n",ans);
  }
   
  return 0;
}

Measured memory_bytes: 3272
#include <iostream>
#include <queue>
#include <functional>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 1e5+10;

struct edge{
	int to,dis,cost;
	edge(){}
	edge(int to,int dis,int cost) : to(to),dis(dis),cost(cost){}
	bool operator>(const edge& rhs) const{
		return dis != rhs.dis ? dis>rhs.dis : cost>rhs.cost;
	}
};

int V,M;
bool vis[maxn];

vector<edge> G[maxn];

int dijkstra(int s){
	int res = 0;
	priority_queue<edge,vector<edge>,greater<edge> > Q;

	Q.push(edge(0,0,0));

	while(!Q.empty()){
		edge p = Q.top(); Q.pop();
		int v = p.to;
		if(vis[v]) continue;
		vis[v] = true;
		res += p.cost;
		for(int i=0; i<G[v].size(); i++){
			Q.push(edge(G[v][i].to,p.dis+G[v][i].dis,G[v][i].cost));
		}
	}

	return res;
}


int main(){
	while(scanf("%d%d",&V,&M) && V){
		memset(vis,0,sizeof(vis));
		for(int i=0; i<=V; i++) G[i].clear();

		for(int i=0; i<M; i++){
			int u,v,d,c;
			scanf("%d%d%d%d",&u,&v,&d,&c);
			--u,--v;
			G[u].push_back(edge(v,d,c));
			G[v].push_back(edge(u,d,c));
		}

		printf("%d\n",dijkstra(0));

	}
}

Measured memory_bytes: 7656
#include<iostream>

int main(){
  int i;
  double v,t,h;

  while(std::cin >> v){
    t = v / 9.8;
    h = 4.9 * t * t;
    for(i=2;h>5.0;i++){
      h -= 5.0;
    }
    std::cout << i << std::endl;
  }
}

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

using namespace std;
int main()
{
    string str;
    cin >> str;

    int minv = 1000;
    for (int i = 0; i < str.length() - 2; i++)
    {
        int numi = stoi(str.substr(i, 3));
        minv = min(minv, abs(numi - 753));
    }
    cout << minv << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,c,d,e,f;
while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=EOF){
float x=(float)(c*e-b*f)/(a*e-b*d);
if(x==0) x=0;
float y=(float)(c*d-a*f)/(b*d-e*a);
if(y==0) y=0;
printf("%.3f %.3f\n",x,y);
}
return 0;
}

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

using namespace std;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    cout << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    cout << ']';
    return s;
}


vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.rbegin(), res.rend());
    return res;
}
int main(){

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

    ll n, m;
    cin >> n >> m;
    vector<ll> divisor = calc_divisor(m);

    for(int x : divisor){
        if(m%x == 0 and x*n <= m){
            ppp(x);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
    int n;
    cin>>n;
    int ans = 0;
    int last = 1e9;
    for(int i = 0; i<n; ++i)
    {
        int t;
        cin>>t;
        if(t<=last)
        {
            last = t;
            ans += 1;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<cmath>
#include<iterator>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,b,c;
	cin >> a >> b >> c;
	if(a+b+c>=22)	cout << "bust" << endl;
	else	cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define double long double
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = a; i < (int)(b); ++i)
#define all(x) x.begin(), x.end()
#define deb(x) cout << (#x) << " is " << (x) << endl;
const int mod = 1000 * 1000 * 1000 + 7;
using namespace std;

inline int add(int a, int b){
	a += b;
	if(a >= mod)
        a -= mod;
	return a;
}
 
inline int sub(int a, int b){
	a -= b;
	if(a < 0)
        a += mod;
	return a;
}

int32_t main() {
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    FOR(i, 1, n + 1) {
        cin >> a[i];
    }
    int d[n + 1][k + 1];
    int p[n + 1][k + 1];
    memset(d, 0, sizeof(int) * (n + 1) * (k + 1));
    memset(p, 0, sizeof(int) * (n + 1) * (k + 1));
    FOR(i, 0, a[1] + 1) {
        d[1][i] = 1;
    }
    p[1][0] = d[1][0];
    FOR(i, 1, k + 1) {
        p[1][i] = add(p[1][i - 1], d[1][i]);
    }
    FOR(i, 2, n + 1) {
        FOR(j, 0, k + 1) {
            if (j - a[i] > 0) {
                d[i][j] = sub(p[i - 1][j], p[i - 1][j - a[i] - 1]);
            }
            else {
                d[i][j] = p[i - 1][j];
            }

            if (j > 0)
                p[i][j] = add(p[i][j - 1], d[i][j]);
            else 
                p[i][j] = d[i][j];
                
        }
    }
    cout << d[n][k];
    return 0;
}

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

const long long int MOD = 1000000007;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    factorial_Initialize(1e5);
    if(abs(n-m) >= 2) cout << 0 << endl;
    if(abs(n-m) == 1) cout << f[n]*f[m] % MOD << endl;
    if(abs(n-m) == 0) cout << 2*f[n]*f[m] % MOD << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main()
{
    vector<vector<char>> orig(2, vector<char>(3));
    for (int i = 0; i < 2; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            cin >> orig[i][j];
        }
    }

    for (int i = 0; i < 2; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            if (orig[i][j] != orig[1 - i][2 - j])
            {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;

    return 0;
}

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

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

    int n; cin >> n;
    map<ll, ll> mp;
    for (int i = 0; i < n; ++i) {
        ll a; cin >> a;
        mp[a]++;
    }

    ll s1 = 1, s2 = 1;
    int c1 = 0, c2 = 0;
    for (auto itr = mp.rbegin(); itr != mp.rend(); ++itr) {
        if (itr->second >= 4 && c1 < 1) {
            s1 = itr->first * itr->first;
            c1++;
        }
        if (itr->second >= 2 && c2 < 2) {
            s2 *= itr->first;
            c2++;
        }
    }

    cout << ((s1 == 1 && s2 == 1) ? 0 : max(s1, s2)) << endl;

    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define N 805
using namespace std;
int n,m,k,a[N][N],sx,sy,dis[N][N];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
char s[N];
pair<int,int>q[N*N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for (int j=1;j<=m;j++)
		{
			if (s[j]=='S') sx=i,sy=j;
			if (s[j]=='#') a[i][j]=1;
		}
	}
	int l=0,r=1,Ans=100000000;
	q[1]=make_pair(sx,sy);
	memset(dis,0x3f ,sizeof dis);
	dis[sx][sy]=0;
	while(l<r)
	{
		l++;
		int x=q[l].first,y=q[l].second;
	//	cout<<x<<' '<<y<<endl;
		Ans=min(Ans,min(min(x-1,n-x),min(y-1,m-y)));
		if (dis[x][y]<k)
		{
			for (int i=0;i<4;i++)
				if (x+dx[i]&&y+dy[i]&&x+dx[i]<=n&&y+dy[i]<=m&&dis[x+dx[i]][y+dy[i]]>10000000&&a[x+dx[i]][y+dy[i]]==0)
				{
					q[++r]=make_pair(x+dx[i],y+dy[i]);
					dis[x+dx[i]][y+dy[i]]=dis[x][y]+1;
				}
		}
	}
//	cout<<Ans<<endl;
	printf("%d\n",(Ans+k-1)/k+1);
}

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

using namespace std;

int main() {
    int n,k=0;
    cin>>n;
    vector<int>a(n);
    bool ans=true;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (a[k]==2){
            cout<<i+1<<endl;
            ans=false;
            break;
        }
        k=a[k]-1;
    }
    if (ans){
        cout<<-1<<endl;
    }
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

int inf = 1e9;
int dp[200010];
set<int> st[26];
bool ok[200010];
int main(){
	string s;
	cin>>s;
	int N = s.size();
	rep(i,N){
		st[s[i]-'a'].insert(i);
	}
	rep(i,26) st[i].insert(N);

	rep1(i,N+1) dp[i] = inf;
	rep(i,N+1){
		rep(c,26){
			int nxt = *st[c].lower_bound(i);
			int j = nxt+1;
			chmin(dp[j],dp[i]+1);
		}
	}

	ok[N+1] = 1;
	for(int i = N;i>=0; i--){
		rep(c,26){
			int nxt = *st[c].lower_bound(i);
			int j = nxt+1;
			if(dp[j] == dp[i]+1 && ok[j]) ok[i] = 1;
		}
	}

	string ans;

	for(int i=0;i!=N+1;){
		rep(c,26){
			int nxt = *st[c].lower_bound(i);
			int j = nxt+1;
			if(dp[j] == dp[i]+1 && ok[j]){
				i = j;
				ans += 'a'+c;
				break;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 10756