akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long  ll ;
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define bug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}



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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
using namespace std;
int main(){
    int M;
    cin >> M;
    string S;
    queue<int> Q;
    for(int i = 0; i<M; ++i) {
        cin >> S;
        typedef set<string> set_t;
        set_t all;
        all.insert(S);
        for (size_t i=1; i<S.size(); ++i) {
            string L;
            L = S.substr(0,i);
            string R;
            R = S.substr(i);
            string L2, R2;
            L2 = L;
            reverse(L2.begin(), L2.end());
            R2 = R;
            reverse(R2.begin(), R2.end());
            all.insert(L + R2);
            all.insert(L2 + R);
            all.insert(L2 + R2);
            all.insert(R + L);
            all.insert(R + L2);
            all.insert(R2 + L);
            all.insert(R2 + L2);
        }
        Q.push(all.size());
    }
    while(! Q.empty()) {
      cout << Q.front() << endl;
      Q.pop();
    }
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  char c;int a,b;cin>>a>>c>>b;
  if(c=='+'){
    P(a+b);
  }else{
    P(a-b);
  }
  return 0;
}


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

// 小数点以下桁数
// fixed << setprecision(i)

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

int lcm(int a, int b)
{
  return a * b / gcd(a, b);
}

int main()
{
  int a, ans;

  for (int i = 1; i <= 5; i++)
  {
    cin >> a;
    if (a == 0)
      ans = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3552
n, m = map(int, input().split())
mod = pow(10, 9) + 7
dp = [0] * (n + 5)
for _ in range(m):
    a = int(input())
    dp[a] = -1
dp[0] = 1
for i in range(n):
    if not dp[i] == -1:
        dp[i] %= mod
    else:
        continue
    if not dp[i + 1] == -1:
        dp[i + 1] += dp[i]
    if not dp[i + 2] == -1:
        dp[i + 2] += dp[i]
ans = dp[n] % mod
print(ans)

Measured memory_bytes: 12528
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    string s;
    in>>n>>s;
    int c{};
    fr(i,n-2){
        if(s.substr(i,3)=="ABC") ++c;
    }
    cout<<c<<endl;
}

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

#define int long long
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);


main(){
	FIO
	int n,d,i,j,k;
	cin>>n>>d;
	d = d*d;
	int count=0;
	for(i=0;i<n;i++){
		cin>>j>>k;
		int x = j*j + k*k;
		if(x<=d){
			count++;
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const ll mod = 100003;
const int cons = 100001;
const double pi = 3.141592653589793;

vector < vector <int> > adj;

void getDist(int st, int n, vector <int> & dist)
{
	dist.resize(n + 1, 0x30000000);
	dist[st] = 0;
	queue <int> qu;
	qu.push(st);
	vector <bool> vis(n + 1, false);
	vis[st] = true;

	while (!qu.empty())
	{
		int u = qu.front();
		qu.pop();

		for (int i = 0; i < adj[u].size(); i++)
		{
			int v = adj[u][i];
			
			if (vis[v])continue;
			vis[v] = true;

			dist[v] = dist[u] + 1;
			qu.push(v);
		}
	}
}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	adj.resize(n + 1);

	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	int ans = INF;

	if (k % 2)
	{
		for (int i = 1; i <= n; i++)
		{
			for (int j = 0; j < adj[i].size(); j++)
			{
				int v = adj[i][j];

				vector <int> d1, d2;

				getDist(i, n, d1);
				getDist(v, n, d2);
				int tmp = 0;

				for (int p = 1; p <= n; p++)
				{
					if (min(d1[p], d2[p]) > k / 2)tmp++;
				}

				ans = min(ans, tmp);
			}
		}
	}
	else
	{
		for (int i = 1; i <= n; i++)
		{
			vector <int> d;

			getDist(i, n, d);
			int tmp = 0;

			for (int p = 1; p <= n; p++)
			{
				if (d[p] > k / 2)tmp++;
			}

			ans = min(ans, tmp);
		}
	}

	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int max(int a, int b){
	if(a>b) return a;
	else return b;
}
int min(int a, int b){
	if(a>b) return b;
	else return a;
}
int main(){
	int n;
	int i;
	int r[200000];
	int maxv,minv;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&r[i]);
	minv=r[0];
	maxv=r[1]-r[0];
	for(i=1;i<n;i++){
		maxv=max(maxv,r[i]-minv);
		minv=min(minv,r[i]);
	}
	printf("%d\n",maxv);
	return 0;
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map
#define mtv(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out( 
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cout << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    stringstream ss; ss << H;
    cout << args[idx] << "- " << ss.str() << ", ";
    debug_out(args, idx + 1, LINE_NUM, T...);
}

void doit(){
	ll a, b;
	cin >> a >> b;
	cout << max({a+b, a-b, a*b});
}

int main(){ 
#ifndef ONLINE_JUDGE
 //   freopen("input1.txt","r",stdin);
  //  freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}



Measured memory_bytes: 3640
#include <cstdio>

#define mx 200005
char S[mx];

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

    int l=0,r=n-1;

    int ans=0;
    while(1){
        while(l<n and S[l]=='R') l++;
        while(r>=0 and S[r]=='W') r--;

        if(r<l) break;
        ans++;l++;r--;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

ll n, p;
int prime[1000000], pcnt, mark[1000005];
void init(int m)
{
	for (int i = 2; i <= m; i ++)
	{
		if (!mark[i]) prime[++ pcnt] = i;
		for (int j = 1; j <= pcnt; j ++)
		{
			int np = prime[j];
			int now = np * i;
			if (now > m) break;
			mark[now] = 1;
			if (i % np == 0)
				break; 
		}
	}
}

inline ll qpow(ll x, ll y)
{
	if (y < 0) return 1;
	ll res = 1;
	for (; y; y >>= 1LL, x = x * x)
		if (y & 1) res = res * x;
	return res;
}

int main()
{
	n = read(), p = read();
	if (n == 1)
		return printf("%lld\n", p), 0;
	init(1000000); ll res = 1;
	for (int i = 1; i <= pcnt; i ++)
	{
		int np = prime[i];
		if (p % np == 0)
		{
			int y = 0;
			while (p % np == 0)
				++ y, p /= np;
			if (y >= n) res = res * qpow(np, y / n);
		}
	}
	printf("%lld\n", res);
	
	return 0;
}

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

void kyu(int x)
{
    if (x >= 400 && x <= 599)
        cout<<"8"<<endl;
    if (x >= 600 && x <= 799)
        cout<<"7"<<endl;
    if (x >= 800 && x <= 999)
        cout<<"6"<<endl;
    if (x >= 1000 && x <= 1199)
        cout<<"5"<<endl;
    if (x >= 1200 && x <= 1399)
        cout<<"4"<<endl;
    if (x >= 1400 && x <= 1599)
        cout<<"3"<<endl;
    if (x >= 1600 && x <= 1799)
        cout<<"2"<<endl;
    if (x >= 1800 && x <= 1999)
        cout<<"1"<<endl;
}

int main ()
{
    int x;
    cin>>x;
    kyu(x);
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int, int> P;
#define F first
#define S second
int dx[8] = {1,1,1,0,-1,-1,-1,0};
int dy[8] = {-1,0,1,1,1,0,-1,-1};

int main(){
  int H;
  bool f = false;
  while(cin>>H && H){
    if(f) cout<<"----------"<<endl;
    else f = true;
    cin.ignore();
    const int W = 80;
    vector<string> grid(H);
    REP(i, H){
      string s; getline(cin, s);
      REP(x, W){
        if(x < s.size()) grid[i] += s[x];
        else grid[i] += ' ';
      }
    }
    //REP(y, H) cout<<grid[y]<<endl;
    map<int, int> ans;
    REP(y, H)REP(x, W)if(grid[y][x] == '*'){
      queue<P> que;
      int count[1000] = {};
      int miny = y;
      int maxy = y;
      que.push(P(x, y));
      while(!que.empty()){
        P p = que.front(); que.pop();
        if(grid[p.S][p.F] != '*') continue;
        //printf("%d %d\n", p.F, p.S);
        miny = min(miny, p.S);
        maxy = max(maxy, p.S);
        grid[p.S][p.F] = '#';
        //REP(y, H) cout<<grid[y]<<endl;
        count[p.S] += 1;
        REP(r, 8){
          int nx = p.F + dx[r];
          int ny = p.S + dy[r];
          if(nx >= 0 && ny >= 0 && nx < W && ny < H && grid[ny][nx] == '*'){
            //if(nx == 16 && ny == 5) printf("%d %d %d->16,5\n", r, dx[r], dy[r]);
            que.push(P(nx, ny));
          }
        }
      }
      //printf("miny:%d(%d) maxy:%d(%d)\n", miny, count[miny], maxy, count[maxy]); 
      ans[(count[maxy] + count[miny]) * (maxy - miny + 1) / 2] += 1;
    }
    FORIT(it, ans) cout<<it->first<<" "<<it->second<<endl;

  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,dp[N],ans=-1;
vector<int>v[N];
int dfs(int now)
{
	if(dp[now]!=-1)return dp[now];
	if(v[now].empty())
	{
		dp[now]=0;
		return 0;
	}
	for(int i=0;i<v[now].size();i++)
		dp[now]=max(dp[now],dfs(v[now][i])+1);
	return dp[now];
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].push_back(b);
	}
	for(int i=0;i<n;i++)dfs(i);
	for(int i=0;i<n;i++)ans=max(ans,dp[i]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int a[200000], b[200000], dp[200000];
signed main(){
  int n, m;cin >> n >> m;
  rep(i,m)cin >> a[i];
  rep(i,m)b[a[i]] = 1;
  dp[1] = 1, dp[2] = 2;
  if(a[0] == 1 or a[1] == 1)dp[1] = 0, dp[2] = 1;
  if(a[0] == 2 or a[1] == 2)dp[2] = 0;
  repi(i,3,n+1){
    if(b[i] == 1)continue;
    dp[i] = dp[i-1] + dp[i-2];
    dp[i] %= mod;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int minimum_number_of_coin(const vector<int> &coins, const int &price)
{
	// number_of_coin[i] : i円を支払うための最小コイン枚数
	vector<int> number_of_coin(price + 1, price);
	number_of_coin[0] = 0;

	// 動的計画法
	for (int i = 0; i < coins.size() + 1; ++i) {
		for (int j = coins[i]; j <= price; ++j) {
			number_of_coin[j] = min(number_of_coin[j], number_of_coin[j - coins[i]] + 1);
		}
	}
	
	return number_of_coin[price];
}

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

	// コインの種類
	vector<int> coins(m);
	for (int i = 0; i < m; ++i) {
		cin >> coins[i];
	}

	int min = minimum_number_of_coin(coins, n);
	cout << min << endl;

	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

long long modinv(long long a){//a ÷ b mod. MOD の求め方 : a * modinv(b) % MOD
    long long b = MOD, u = 1, v = 0;
    while(b){
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if(u < 0) u += MOD;
    return u;
}

signed main(){
    ll n,k;
    cin >> n >> k;
    vector<P> v(n);
    REP(i,n){
        cin >> v[i].first;
        v[i].second = i;
    }
    ll a[n];
    REP(i,n){
        int cnt = 0;
        for(int j = i + 1; j < n; j++){
            if(v[j].first < v[i].first){
                cnt++;
            }
        }
        a[i] = cnt;
    }
    sort(ALL(v));
    ll d[n];
    d[v[0].second] = 0;
    for(int i = 1; i < n; i++){
        if(v[i - 1].first < v[i].first){
            d[v[i].second] = i;
        }else{
            d[v[i].second] = d[v[i - 1].second];
        }
    }
    ll ans = 0;
    REP(i,n){
        ans += (k * 2 * a[i]) / 2 % MOD + k % MOD * (k - 1) % MOD * d[i] % MOD * modinv(2) % MOD;
        ans %= MOD;
    }
    cout << ans % MOD << endl;
}

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds; 
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 998244353

// typedef tree<pii,null_type,less<pii>,rb_tree_tag,
// tree_order_statistics_node_update>PBDS; 

int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif  
 
    ll t;
    t=1;
    // cin>>t;
    while(t--){
     string s;
     cin>>s;
     cout<<s;
     if(s[s.size()-1]=='s')cout<<"es";
     else cout<<"s";
     
  






    }
      
     
      

      

    

    
return 0;
}     



Measured memory_bytes: 3668
def resolve():
    n, a, b, c, d = map(int, input().split())
    ss = input()

    for i in range(a-1, d-1):
        if ss[i:i+2] == '##':
            print('No')
            return

    if c < d:
        print('Yes')
    else:
        for i in range(b-2,d-1):
            if ss[i:i+3] == '...':
                print('Yes')
                return
        print('No')
resolve()

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

#define INF 1E18



int main(){
    ll n,m,x;
    cin>>n>>m>>x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m) cin>>a[i][j];
    }

    ll ans = INF;

    for(int i=0; i < (1<<n); ++i ){
        vector<int> syutoku(m);
        ll cost_sum = 0;
        for(int j=0; j<n; ++j){
            if((i>>j)%2 == 0) continue;
            else{
                for(int k=0; k<m; ++k){
                    syutoku[k] += a[j][k];
                }
                cost_sum += c[j];
            }
            bool flag = true;
            for(int k=0; k<m; ++k){
                if(syutoku[k] < x) flag = false;
            }
            if(flag) ans = min(ans, cost_sum);
        }
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    LL ans = 0;
    int h = A[0];
    rep(i, N) {
        if (A[i] < h) {
            ans += h-A[i];
        } else {
            h = A[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n), dp(n, inf);
    rep(i, n) cin >> h[i];
    dp[0] = 0;
    reps(i, 1, n) {
        reps(j, 1, min(i + 1, k + 1)) {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    for (int i = 0; (i < b); ++i) {
        if (((a * (i + 1)) % b) == c) {
            std::cout << "YES" << std::endl;
            return 0;
        }
    }
    std::cout << "NO" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long int li;
typedef unsigned long long ull;

int main(int argc,char* argv[])
{
    vs s(3);
    rep(i,3) cin>>s[i];
    int turn=0;
    while(1){
        if(s[turn].size()==0) {cout<<(char)(turn+'A')<<endl; break;}
        int t=s[turn][0]-'a';  
        s[turn]=s[turn].substr(1);
        turn=t; 
    }
    return 0;
}   

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

using namespace std;

int main(){
	int n,c = 0;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	sort(a,a+n);
	
	for(int i = 0; i < n; i++){
		if(a[i] == a[i+1]){
			if(a[i+1] == a[i+2]){
				i++;
				c += 2;
			}
			else{
				c++;
				i += 2;
				while(a[i] != a[i+1]){
					i++;
				}
				c++;
			}
		}
		else
			continue;
	}
	
	cout << n-c << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  int n;
  cin >> n;
  cout << "ABC" << n << endl;
}


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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vll = vector<ll>;
using vbool = vector<bool>;

int main() {
    int N;
    string S;
    cin >> N >> S;
    for (auto c : S) {
        cout << (char)('A' + (c - 'A' + N) % 26);
    }
}

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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    string ans = "No";

    string S1;
    for (int i=0; i<=((N-1)/2)-1; i++) {
        S1.push_back(S[i]);
    }

    string S_temp = S;
    string S1_temp = S1;
    reverse(S_temp.begin(),S_temp.end());
    reverse(S1_temp.begin(),S1_temp.end());
    if (S == S_temp and S1 == S1_temp) {
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
n=int(input())
l=[]

def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
  
for i in range(1,n+1):
  for j in range(1,n+1):
    l.append(gcd(i,j))
    
ans=0
for i in range(1,n+1):
  for j in l:
    ans+=gcd(i,j)
    
print(ans)

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

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

  vector<int> p(N);

  for (int i = 0; i < N; i++)
    cin >> p.at(i);

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

  int ans = 0;
  for (int i = 0; i < K; i++)
    ans += p.at(i);

  cout << ans << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int a[5];
int main(){
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    int f5,f7,i;
    f5 = f7 = 0;
    for(i = 0; i < 3; i++){
        if(a[i] == 5)
            f5++;
        if(a[i] == 7)
            f7++;
    }
    if(f5==2&&f7==1)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, d; cin>>n>>d;
	vector<vll> x(n, vll(d));
	rep(i, n)rep(j, d){
		cin>>x[i][j];
	}

	ll ans=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			ll sum=0;
			rep(k, d){
				sum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			bool sq = true;
			for(int k=2; k*k<=sum; k++){
				ll cnt=0;
				while(sum%k==0){
					sum/=k;
					cnt++;
				}
				if (cnt%2!=0) sq = false;
			}
			if (sum!=1) sq = false;
			if (sq) ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
c1,c2 = 0,0
while arr = gets
  a,b,c = arr.chomp.split(",").map(&:to_i)
  unless (c**2 == a**2 + b**2) && (a == b)
    c1 = c1 + 1 if c**2 == a**2 + b**2
    c2 = c2 + 1 if a == b
  end
end
puts c1; puts c2

Measured memory_bytes: 8568
#include <iostream>
using namespace std;
int a, b, c;
int main(void){
    // Your code here!
    cin >> a >> b;
    if (a < b) swap(a, b);
    while (b > 0) {
        c = a % b;
        a = b;
        b = c;
    }
    cout << a << endl;
}



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

int main( void ) {
    
    string str1 = "CODEFESTIVAL2016", str2;
    cin >> str2;
    
    int cnt = 0;
    for( int i = 0; i < str1.length(); i ++ )
        cnt += str1[i] != str2[i];
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t;
    }
    return n*rep_jijo(n,x-1);
}

int main(){
    int h,w,k;
    ll ans = 0;
    cin >> h >> w >> k;
    vector<vector<char>>c(h,vector<char>(w));
    rep(i,h) rep(j,w) cin >> c[i][j];

    rep(i,1<<h){

        vector<int>binh(h,0);
        rep(a,h){
            if(i>>a&1) binh[a]=1;
        }

        rep(j,1<<w){
            int cnt = 0;
            vector<int>binw(w,0);
            rep(b,w){
                if(j>>b&1) binw[b]=1;
            }
            rep(x,h){
                rep(y,w){
                    if(binh[x]==0 && binw[y]==0 && c[x][y]=='#'){
                        cnt ++;
                    }
                }
            }
            if(cnt ==k ) ans ++;

        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

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

	string s;
	cin >> s;

	int z = 0, o = 0;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1' && i % 2 == 0) {
			z++;
		}
		if (s[i] == '0' && i % 2 == 0) {
			o++;
		}
		if (s[i] == '1' && i % 2 == 1) {
			o++;
		}
		if (s[i] == '0' && i % 2 == 1) {
			z++;
		}
	}

	int ans = min(z, o);

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

void open(){
	freopen("D:/Code/in.txt","r",stdin);
	freopen("D:/Code/out.txt", "w", stdout);
}
ll arr[2][100010];
int main(void){
	int n;
	sc(n);
	FOR(i,n){
		cin >> arr[0][i] >> arr[1][i];
	}

	ll tot = 0;

	for(int i = n-1;i>=0;i--){
		ll cur = tot + arr[0][i];
		ll need = cur % arr[1][i];
		if(need == 0)continue;
		tot += arr[1][i] - need;
	}
	cout << tot;
    return 0;
}




Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define int long long
using namespace std;
void print(vector<int> a){
    for (int i=0; i < a.size(); i++) cout << a[i]+1 << " ";
    exit(0);
}
vector<int> rev(vector<int> &a){
    int n = a.size();
    vector<int> res(n);
    for (int i=0;i<n;i++) res[a[i]] = i;
    return res;
}
vector<int> mult(vector<int> a, vector<int> b){
    int n = a.size();
    vector<int> res(n);
    for (int i=0; i < n; i++) res[i] = b[a[i]];
    return res;
}
vector<int> pw(vector<int> &a, int d){
    if (d==0){
        vector<int> K;
        for (int i=0;i<a.size();i++) K.push_back(i);
        return K;
    }
    if (d==1) return a;
    if (d % 2 == 0){
        vector<int> res = pw(a,d/2);
        return mult(res, res);
    }
    return mult(a, pw(a,d-1));
}
vector<int> get(vector<vector<int> > kek, int d){
    int n = kek[0].size();
    vector<int> cp;
    for (int i=0;i<n;i++) cp.push_back(i);
    for (int i=0;i<4;i++) cp = mult(cp, kek[i]);
    int N = d/4;
    cp = pw(cp, N);
    for (int i=0;i<(d%4);i++) cp = mult(cp, kek[i]);
    return cp;
}
main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    for (int i=0; i < n; i++) cin >> a[i];
    for (int i=0; i < n; i++) a[i]--;
    for (int i=0; i < n; i++) cin >> b[i];
    for (int i=0; i < n; i++) b[i]--;
    if (k==1) print(a);
    if (k==2) print(b);
    int deg = ((k-3)/3) * 4 + 2;
    if (k%3 == 1) deg++;
    if (k%3==2) deg += 3;
    vector<int> reva = rev(a), revb = rev(b);
    vector<vector<int> > revlist = {revb, a, b, reva};
    int need = (deg-1)/2;
    vector<int> relax = get(revlist, need);
    vector<int> R = rev(relax);
    if (deg % 2 != 0){
        if (deg % 8 == 7) relax = mult(relax, mult(a, R));
        if (deg % 8 == 1) relax = mult(relax, mult(b, R));
        if (deg % 8 == 3) relax = mult(relax, mult(reva, R));
        if (deg % 8 == 5) relax = mult(relax, mult(revb, R));
    }
    else{
        if (deg % 8 == 2) relax = mult(relax, mult(reva, mult(b, R)));
        if (deg % 8 == 6) relax = mult(relax, mult(a, mult(revb, R)));
    }
    print(relax);

}




Measured memory_bytes: 13736
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

int main(){
	int n=ci(), m=ci();
	if( n<m ) swap(n,m);
	rep(i,1,n) pt('0'+m); pt('\n');
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}



int main(void){
    int n;
    cin >> n;
    int count = 0;

    for(int i=1;i<=n;++i){
        string str;
        str = to_string(i);
        if(str.size()%2!=0){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
int X, Y, Z, K; 
#define INF LLONG_MAX

int main(){
    cin >> X >> Y >> Z >> K;
    std::vector<ull> A(X, 0);
    std::vector<ull> B(Y, 0);
    std::vector<ull> C(X, 0);
    
    for (int i = 0; i < X; ++i) cin >> A[i]; sort(A.begin(), A.end(), greater<ull>());
    for (int i = 0; i < X; ++i) cin >> B[i]; sort(B.begin(), B.end(), greater<ull>());
    for (int i = 0; i < X; ++i) cin >> C[i]; sort(C.begin(), C.end(), greater<ull>());
    vector<ull> vals(0);
    for (int x = 0; x < X; x++){
        for (int y = 0; y < Y; y++){
            for (int z = 0; z < Z; z++){
                if ((x + 1)*(y + 1)*(z + 1) <= K){
                    vals.push_back(A[x] + B[y] + C[z]);
                }
            }
        }
    }
    sort(vals.begin(), vals.end(), greater<ull>());
    int sum = 0;
    for (int i = 0; i < K; ++i){
        cout << vals[i] << endl;
    }
}

Measured memory_bytes: 1404
#include<cstdio>
using namespace std;
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if(a == 1 || b == 1)
	{
		if(a == b)
		{
			printf("Draw");
			return 0;
		}
		if(a == 1)
		{
			printf("Alice");
			return 0;
		}
		if(b == 1)
		{
			printf("Bob");
			return 0;
		}
	}
	else
	{
		if(a > b)
		{
			printf("Alice");
			return 0;
		}
		if(a < b)
		{
			printf("Bob");
			return 0;
		}
		if(a == b)
		{
			printf("Draw");
			return 0;
		}
	}
	
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define io_optimized ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main () {
#define int int_fast32_t
	io_optimized
	string s;
	while(cin>>s)
	{
		for(int i=0;i<s.length();i++)
		{
			cout<<"x";
		}
		cout<<"\n";
	}

	return 0;
}


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

int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int> x(N);
  vector<int> y(M);
  for (int i=0; i<N; i++){
    cin>>x.at(i);
  }
  for (int i=0; i<M; i++){
    cin>>y.at(i);
  }
  bool flag2=false;
  for (int Z=-100; Z<=100; Z++){
    bool flag=false;
    for (int i=0; i<N; i++){
      if (Z<=x.at(i)){
        flag=true;
      }
    }
    for (int i=0; i<M; i++){
      if (Z>y.at(i)){
        flag=true;
      }
    }
    if (Z<=X||Y<Z){
      flag=true;
    }
    if(!flag){
      flag2=true;
      break;
    }else{
      continue;
    }
  }
  if (flag2){
    cout<<"No War"<<endl;
  }else{
    cout<<"War"<<endl;
  }
}
      

Measured memory_bytes: 3612
//Author:- S_Aditya

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;         
const int N=3e3+4;

void add_self(int &a,int b)
{
    a+=b;
    
    if(a>=mod)
    a-=mod;
}

void sub_self(int &a,int b)
{
    a-=b;
    
    if(a<0)
    a+=mod;
}

//dp[i][j] tells the no. of permutations of numbers from [1 to i] considering the 
//comparision string for the first i numbers with the ith letter of all these 
//permutations being j.

int dp[N][N];

int main()                  
{
    int n;
    
    scn(n);
    
    string comp;
    
    cin>>comp;
    
    dp[1][1]=1; //one way to fill a single length permutation and last digit should be 1

    for(int len=2;len<=n;len++)
    {
        //compute prefix sums of the dp states of len-1
        for(int i=1;i<=len-1;i++)
        add_self(dp[len-1][i],dp[len-1][i-1]);
        
        for(int last_digit=1;last_digit<=len;last_digit++)
        {
            int l,r;
            
            if(comp[len-2]=='<')
            l=1,r=last_digit-1;
            else
            l=last_digit,r=len-1;
            
            add_self(dp[len][last_digit],dp[len-1][r]);
            
            sub_self(dp[len][last_digit],dp[len-1][l-1]);
        }
    }
    
    int ans=0;
    
    for(int last_digit=1;last_digit<=n;last_digit++)
    add_self(ans,dp[n][last_digit]);
    
    printf("%d ",ans);
} 

Measured memory_bytes: 34176
#include<bits/stdc++.h>
using namespace std;
int main(){ int n;
int p=1e5 ;
cin>>n;
int a[n];
for(int i=0 ;i<n ;i++){ int cnt=0 ;
cin>>a[i];

 while(a[i]%2==0){a[i]=a[i]/2; cnt++; }
p=min(p,cnt) ;
 }
cout<< p << endl;
return 0;
}




Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int a[100005];
int dp[2][100005];
vector<pii> v1, v2;
int main(){
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
	}
	for(int i=1;i<=n;i+=2){
		dp[0][a[i]]++;
	}
	for(int i=2;i<=n;i+=2){
		dp[1][a[i]]++;
	}
	for(int i=1;i<=100000;i++){
		v1.push_back(pii(dp[0][i], i));
		v2.push_back(pii(dp[1][i], i));
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	reverse(v1.begin(), v1.end());
	reverse(v2.begin(), v2.end());
	int ans = 1e9;
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			if(v1[i].second == v2[j].second) continue;
			int res1 = n/2-v1[i].first;
			int res2 = n/2-v2[j].first;
			ans = min(ans, res1+res2);
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main () {
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe\n";
  } else {
    cout << "safe\n";
  }
  return 0;
}
  

Measured memory_bytes: 3648
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;
set<string> S;

void Work(){
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++){
        if(s[i] == '?' || s[i] == t[0]){
            string tmp = s;
            for(int j = 0; j < i; j++) if(tmp[j] == '?') tmp[j] ='a';
            bool can = false;
            for(int j = 0; j < lent; j++){
                if(tmp[i+j]!= '?' && tmp[i+j] != t[j]) break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can){
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
                S.insert(tmp);
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << *S.begin() << endl;
}
int main(){
    cin >> s >> t;
    Work();
}


Measured memory_bytes: 384
def insertSort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)

n = int(input())
a = list(map(int, input().split()))
print(*a)

f = insertSort(a, n)


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  cout << min(K,A)-max(K-A-B,0) << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

bitset<4000005> bt;
int n;

int main(){
	cin>>n;
	bt[0]=1;
	int S=0;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		S+=A;
		bt|=bt<<A;
	}
	for(int i=(S+1)/2;;i++) if(bt[i]){
		cout<<i<<endl;
		return 0;
	}
}

Measured memory_bytes: 1664
#include<stdio.h>
int main(){
	char x[20]="CODEFESTIVAL2016";
	char y[20];
	scanf("%s",y);
	int cnt=0;
	for(int i=0;i<16;i++)
		if(x[i]!=y[i])cnt++;
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
// https://atcoder.jp/contests/abc082/tasks/abc082_b

bool solver(string first,string second){
    sort(first.begin(),first.end()) ;
    sort(second.begin(),second.end(),greater<int>());
    if(first < second){
        return true;
    }
    else{
        return false;
    }
}

int main(void){
    string s,t,ansstr;
    bool result ;
    cin >> s;
    cin >> t;
    result = solver(s,t);
    if(result){
        ansstr = "Yes";
    }
    else{
        ansstr = "No";
    }
    cout << ansstr << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
int a[MAX_N];
int main() {
	int n;
  	scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    int cnt=0, ans=0;
    for(int i=n-2; i>=0; i--) {
       if(a[i]>=a[i+1]) cnt++;
       else {
       		ans=max(ans, cnt);
       		cnt=0;
       }
    }
  	printf("%d\n", max(cnt, ans));

 	return 0; 
}

Measured memory_bytes: 640
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200'005)
#define MOD (1000000000ll + 7ll)
#define OO (1050000000)
#define OOL (1100000000000000000)

//global
pair<ll,ll> a[N];

int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	ll n;
	cin >> n;
	rep(i,0,n){
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a,a+n);
	set<ll> gr;
	set<ll,greater<ll>> ls;
	ll ans = 0;
	rep(i,0,n){
		if(gr.lower_bound(a[i].second) == gr.end()){
			if(ls.lower_bound(a[i].second) == ls.end()){
				ans += a[i].first*(n-a[i].second)*(a[i].second+1);
			}else{
				ans += a[i].first*(n-a[i].second)*
				(a[i].second-*ls.lower_bound(a[i].second));
			}
		}else{
			if(ls.lower_bound(a[i].second) == ls.end()){
				ans += a[i].first*
				(*gr.lower_bound(a[i].second)-a[i].second)
				*(a[i].second+1);
			}else{
				ans += a[i].first*
				(*gr.lower_bound(a[i].second)-a[i].second)*
				(a[i].second-*ls.lower_bound(a[i].second));
			}
		}
		gr.insert(a[i].second);
		ls.insert(a[i].second);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 22144
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

public class HelloWorld
{
    static public void Main ()
    {
        //Console.WriteLine(1);
        var KT = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        
        var K = KT[0];
        var T = KT[1];
        //Console.WriteLine(1);
        var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        //Console.WriteLine(1);
        var pq = new PriorityQueue<long>(4000,true);
        //Console.WriteLine(1);
        for(int i = 0;i < T;i++){
            pq.Enqueue(A[i]);
           // Console.WriteLine(pq.Count);
        }
        //Console.WriteLine(1);
        var top = pq.Dequeue();
       
        while(pq.Count > 0){
            
            
            var next = pq.Dequeue();
            top--;
            next--;
            if(top > 0){
                pq.Enqueue(top);
            }
            
            if(next > 0){
                pq.Enqueue(next);
            }
            
            if(pq.Count > 0){
                top = pq.Dequeue();
            }else{
                top = 1;
            }
            
            
        }
        
        Console.WriteLine(top-1);
    }
    
    public static long RepPow(long x, long p, long m = 998244353){
        if (p == 1) return x % m;
        long b = RepPow(x, p / 2, m) % m; if (p % 2 == 0) { return (b * b) % m; } else { return (x * ((b * b) % m)) % m; }}
        static long Pow(long n, long p, int mod = 998244353) { if (p == 0) return 1;　else if (p % 2 == 0) { var x = Pow(n, p / 2, mod); return (x * x) % mod; } else { return Pow(n, p - 1, mod) * n % mod; } }
        

}

class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(long capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { 
// 先頭要素を末尾にして再構成 
this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { // 親要素の座標 
var parent = (n - 1) / 2; if (this.Compare(this.Array[n], this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { // 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
 child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }


Measured memory_bytes: 27956
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);

  long long L[N+1];
  L[0] = 2; L[1] = 1;

  for(int i = 2;i <= N;i++){
    L[i] = L[i-1]+L[i-2];
  }
  printf("%lld\n",L[N]);

return 0;
}

Measured memory_bytes: 128