akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 5e5 + 5;


struct query
{
    int l, r, idx;
};

int arr[MAXN], t[4 * MAXN], last[MAXN], ans[MAXN];
vector<query> queries;

void update(int v, int tl, int tr, int pos, int val)
{
    if(tl == tr)
        t[v] += val;
    else
    {
        int tm = (tl + tr) / 2;
        if(pos <= tm)
            update(2 * v, tl, tm, pos, val);
        else
            update(2 * v + 1, tm + 1, tr, pos, val);
        t[v] = t[2 * v] + t[2 * v + 1];
    }
}

int sum(int v, int tl, int tr, int l, int r)
{
    if(l > r)
        return 0;
    if(tl == l && tr == r)
    {
        return t[v];
    }
    else
    {
        int tm = (tl + tr) / 2;
        return sum(2 * v, tl, tm, l, min(r, tm)) + sum(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
    }
}

void cp()
{
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        l--, r--;
        queries.pb({l, r, i});
    }
    sort(all(queries), [&](query a, query b)
    {
        return a.r < b.r;
    });

    clr(last, -1);

    int pos = 0;
    for(int i = 0; i < n; i++)
    {
        if(last[arr[i]] != -1)
            update(1, 0, n - 1, last[arr[i]], -1);
        // reduce 1 at pos last[arr[i]]
        last[arr[i]] = i;
        update(1, 0, n - 1, last[arr[i]], 1);
        while(pos < q && queries[pos].r == i)
            ans[queries[pos].idx] = sum(1, 0, n - 1, queries[pos].l, queries[pos].r), pos++;
    }

    for (int i = 0; i < q; i++)
        cout << ans[i] << endl;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 19700
N = int(input())
c = [[0]*9 for _ in range(9)]
count = 0
for i in range(1,N+1):
    li = i//10**(len(str(i))-1) 
    ri = i%10
    if ri == 0:
        continue
    c[li-1][ri-1] += 1

for i in range(9):
    for j in range(9):
        count += c[i][j]*c[j][i]

print(count)

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

int main(){

	int W,H;
	char buf[2];

	scanf("%d %d %s",&W,&H,buf);

	printf("+");
	for(int i = 0; i < W-2; i++){
		printf("-");
	}
	printf("+");
	printf("\n");


	for(int row = 1; row < (H-2)/2+1; row++){
		printf("|");
		for(int col = 1; col < W-2+1; col++)printf(".");
		printf("|\n");
	}

	printf("|");
	for(int col = 1; col < (W-2)/2+1; col++){
		printf(".");
	}
	printf("%s",buf);
	for(int col = 1; col < (W-2)/2+1; col++){
		printf(".");
	}
	printf("|\n");

	for(int row = 1; row < (H-2)/2+1; row++){
		printf("|");
		for(int col = 1; col < W-2+1; col++)printf(".");
		printf("|\n");
	}

	printf("+");
	for(int i = 0; i < W-2; i++){
		printf("-");
	}
	printf("+");
	printf("\n");

	return 0;
}

Measured memory_bytes: 3188
import bisect
N = int(input())
A = []
for _ in range(3):
  a = list(map(int, input().split()))
  a.sort()
  A.append(a)
  
ans = 0
for b in A[1]:
  a = bisect.bisect_left(A[0], b)
  c = bisect.bisect_right(A[2], b)
  ans += a * (N-c)
print(ans)  

Measured memory_bytes: 22720
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define s(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;
int main() {
	int a, b,ans=0,abc=0;
	char s[52][52];
	cin >> a >> b;
	rep(i, b + 2)s[0][i] = '.',s[a+1][i]='.';
    rep(i, a+2)s[i][b + 1] = '.', s[i][0]='.';
	rep(i,a){
		rep(j, b) {
			cin >> s[i+1][j+1];
			if (s[i+1][j+1] == '#')abc++;
		}
	}
	rep(i, a) {
		rep(j, b) {
			if (s[i+1][j+1] == '#') {
				if (s[i + 2][j+1] == '#' || s[i ][j+1] == '#' || s[i+1][j + 2] == '#' || s[i+1][j] == '#')ans++;
			}
		}
	}
	if (abc == ans)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
	



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>

int min(int a ,int b){
  if(a<b){
    return a;
  }
  return b;
}


int max(int a ,int b){
  if(a<b){
    return b;
  }
  return a;
}

int main(){
  int ma=0,mi=1000000001,a,s=0,n,x;
  int h[1000]={};
  scanf("%d",&n);
  for (int i = 1; i<=n ; i++) {
    scanf("%d",&h[i]);
    ma=max(ma,h[i]);
    mi=min(mi,h[i]);
  }
  printf("%d",ma-mi);
  return 0;
}


Measured memory_bytes: 128
/**
  *  @Author: Pranta Sarker
  *
  */

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define pfn(x , k) printf(k , x)
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
#define clr clear()

typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;

const int mod = 1000007;
const int high = 1002;

/*


    0 <= A < B <= 100
    0 <= C < D <= 100
    All input values are integers.


*/


int main()
{
	fast;
	int A , B , C , D;
	while(cin >> A >> B >> C >> D)
	{
		int start = max(A , C);
		int end = min(B , D);

		if(start > end) outn(0);
		else cout << end - start << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include<bits/stdc++.h>
#define   ll   long long
#define   llu  unsigned long long
#define   _    printf("\n")
int      take() {
    int n;
    scanf("%d",&n);
    return n;

}
double  ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll     takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define  Int            take()
#define  Dnt            ttake()
#define  LL             takes()
#define  done           {return 0;}
#define  fr(i,x,n,a)    for(int i=x;i<=n;i+=a)
#define  FR(a,b,x)      for(int i=(a);i<=(b);i+=(x))
#define  rfr(i,x,n,a)   for(int i=x;i>=n;i--)
int      cas;
#define  print          printf("Case %d:",++cas)
#define  vi             vector<int>
#define  vl              vector<ll>
#define  pb              push_back
#define  pii             pair<int,int>
#define  vii             vector<pii>
#define  pll             pair<ll,ll>
#define  pil             pair<int,ll>
#define  pli             pair<ll,int>
#define  mk              make_pair
#define  fill(x,v)       memset(x,v,sizeof x)

using    namespace      std;

bool     approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define  STR            {struct info}
#define  dbg(x)         {cout<<"ekhane"<<x<<endl;}
#define  SS             second
#define  FF             first
#define  PQ             priority_queue
#define  great          greatest
#define  less           lesser
#define  mii            map<int,int>
#define  mil            map<int,ll>
#define  mll            map<ll,ll>
#define  msb            map<string,bool>
#define  V              vector
#define  M              100005
#define  pf             printf
//////////////////////////////////////////


int main(){

    int s = 0 , n = Int , x = Int ;
    int arr[ n + 1 ] ;
    fr( i , 1 , n , 1 ){
        s += ( arr[ i ] = Int ) ;
    }
    sort( arr + 1 , arr + 1 + n ) ;
   int ans = ( x >= s ) * n ;
   x -=s ;
   if( x <= 0 ) x = 0 ;
   ans += ( x / arr[ 1 ] ) ;
   cout<<ans<<"\n";
   done;
}





Measured memory_bytes: 256
while True:
    H,W=map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H-1 or j == 0 or j == W-1:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()



Measured memory_bytes: 7004
M, K = list(map(int, input().split()))

if M <= 1:
    if K > 0:
        print(-1)
        exit()
    else:
        if M == 1:
            print(" ".join(["0", "0" , "1", "1"]))
            exit()
        else:
            print("0 0")
            exit()
elif K >= 2 ** M:
        print(-1)
        exit()
ans = [str(K)]
exclude_k = [str(i) for i in range(2 ** M) if i != K]
ans.extend(exclude_k)
ans.append(str(K))
ans.extend(exclude_k[::-1])
print(" ".join(ans))

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

#define int long long

const int MOD = 1e9+7;

string A, B, C;
int N;
vector<vector<int> > dp;

int dfs(int n, int r) {
  if ( dp[n][r] >= 0 ) return dp[n][r];
  if ( n == N-1 ) {
    int ret = 0;
    for ( int i = 1; i <= 9; i++ ) {
      if ( A[n] != '?' && A[n]-'0' != i ) continue;      
      for ( int j = 1; j <= 9; j++ ) {
	if ( B[n] != '?' && B[n]-'0' != j ) continue;
	if ( i+j+r >= 10 ) continue;	
	if ( C[n] == '?' ) {
	  ret++;
	} else {
	  if ( C[n]-'0' == i+j+r ) ret++;	  
	}
	ret %= MOD;
      }
    }
    return dp[n][r] = ret;
  } else {
    int ret = 0;
    for ( int i = 0; i <= 9; i++ ) {
      if ( A[n] != '?' && A[n]-'0' != i ) continue;      
      for ( int j = 0; j <= 9; j++ ) {
	if ( B[n] != '?' && B[n]-'0' != j ) continue;
	if ( C[n] == '?' ) {
	  ret += dfs(n+1, (i+j+r)/10);
	  ret %= MOD;	  
	} else {
	  if ( C[n]-'0' == (i+j+r)%10 ) ret += dfs(n+1, (i+j+r)/10);
	  ret %= MOD;	  
	}
      }
    }

    return dp[n][r] = (ret%MOD);    
  }
}

signed main() {
  while ( cin >> A, A != "0" ) {
    cin >> B >> C;
    N = A.size();
    dp = vector<vector<int> >(N+1, vector<int>(3, -1));    
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());    
    reverse(C.begin(), C.end());

    cout << dfs(0, 0)%MOD << endl;    
  }
  return 0;
}


Measured memory_bytes: 3132
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 2e5 + 10;
int f[N], c[N];

int find(int x) {
  if (f[x] != f[f[x]]) f[x] = find(f[x]);
  return f[x];
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    f[i] = i;
    c[i] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    int rx = find(x), ry = find(y);
    if (rx != ry) {
      f[ry] = rx;
      c[rx] += c[ry];
    }
  }
  int best = 0;
  for (int i = 0; i < n; ++i) {
    if (find(i) == i) best = max(best, c[i]);
  }

  cout << best << '\n';
  return 0;
}


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

#define ll long long

using namespace std;

const ll mod = 1e9+7;
ll ara[100005],dp[100005];

///dp[i] - number of ways such that we used i candies so far

void addSelf(ll &x,ll y)
{
    x += y;
    if(x >= mod)
        x -= mod;
}

void subSelf(ll &x,ll y)
{
    x -= y;
    if(x < 0)
        x += mod;
}

void naiveDP(ll n,ll k)
{
    dp[0] = 1;
    for(ll i=1 ; i<=n ; i++){
        for(ll used = k ; used >= 0 ; used--){
            ll lft = used + 1;
            ll rgt = used + min(ara[i] , k-used);

            for(ll j=lft ; j<=rgt ; j++)
                addSelf(dp[j] , dp[used]);
        }
    }
    cout<<dp[k]<<endl;
}

void optimizedDP(ll n,ll k)
{
    dp[0] = 1;
    for(ll i=1 ; i<=n ; i++){
        vector<ll>temp(k+1);
        for(ll used=k ; used >= 0 ; used--){
            ll lft = used + 1;
            ll rgt = used + min(ara[i] , k-used);

            if(lft <= rgt){
                addSelf(temp[lft] , dp[used]);
                if(rgt+1 <= k)
                    subSelf(temp[rgt+1] , dp[used]);
            }
        }
        ll prefSum = 0;
        for(ll x=0 ; x <= k ; x++){
            addSelf(prefSum , temp[x]);
            addSelf(dp[x] , prefSum);
        }
    }
    cout<<dp[k]<<endl;
}

int main()
{
    ll i,j,n,k,ans;
    cin>>n>>k;
    for(i=1 ; i<=n ; i++)   cin>>ara[i];

    optimizedDP(n , k);

    return 0;
}


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

int minof(int a, int b)
{
	return ((a <= b) ? a : b);
}

int main(void)
{
	while(1) {
		int n, x;
		int cnt = 0;

		cin >> n >> x;
		if(!n && !x)	break;

		for(int i = 1; i <= minof(n, x / 3); i++)
			for(int j = i + 1; j <= minof(n, (x - 1) / 2); j++)
				for(int k = j + 1; k <= minof(n, x - 2); k++)
					if(i + j + k == x)	cnt++;

		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#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(v) v.begin(), v.end()
 
int main() {
  int N,R; cin >>N>>R;
  if(N>=10){
    cout<<R<<endl;
  }else{
    cout<<100*(10-N)+R;
  }
  return 0;
}

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

int main() {
    string S, T;
    cin >> S >> T;

    //Initialize ans with a temporal value.
    //This value should be large enough; otherwise you will get wrong answer
    //Make sure that the value will lead to the correct answer.
    int ans = T.size();

    //Brute force through all initial position in S
    for (int start = 0; start <= S.size() - T.size(); start++)
    {
        int diff = 0;
        for (int i = 0; i < T.size(); i++)
        {
            if (T[i] != S[i+start]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

 int main(void)
 {
 int W,H,x,y,r,f;

 printf("");
 scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

 f=0;
 if(x+r>W)f=1;
 if(y+r>H)f=1;
 if(r>x)f=1;
 if(r>y)f=1;

 if(f==0)printf("Yes\n");
 else printf("No\n");

 return 0;
 }


Measured memory_bytes: 2104
// A - Grouping

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int x, y;
	cin >> x >> y;

	vector<int> grp1 = {1, 3, 5, 7, 8, 10, 12};
	vector<int> grp2 = {4, 6, 9, 11};
	vector<int> grp3 = {2};

	int x_grp, y_grp;

	if (count(grp1.begin(), grp1.end(), x) > 0) x_grp = 1;
	if (count(grp2.begin(), grp2.end(), x) > 0) x_grp = 2;
	if (count(grp3.begin(), grp3.end(), x) > 0) x_grp = 3;

	if (count(grp1.begin(), grp1.end(), y) > 0) y_grp = 1;
	if (count(grp2.begin(), grp2.end(), y) > 0) y_grp = 2;
	if (count(grp3.begin(), grp3.end(), y) > 0) y_grp = 3;

	string ans;

	if (x_grp == y_grp) ans = "Yes";
	else ans = "No";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef unsigned long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll arr[30],hass[30];
string s,t;
vector<ll>v[30];

int main()
{
	ll i,sum=0,mark=0,temp=0;
	cin>>s>>t;
	for(i=0;i<s.size();i++)
	{
		arr[s[i]-'a']++;
		v[s[i]-'a'].pb(i+1);
	}
	for(i=0;i<t.size();i++)
		hass[t[i]-'a']++;
	for(i=0;i<=25;i++)
	{
		if(arr[i]==0&&hass[i]!=0)
		{
			cout<<-1;
			return 0;
		}
	}
	i=0;
	memset(arr,0,sizeof(arr));
	while(i<t.size())
	{
		ll d=t[i]-'a';
		while(v[d].size()>arr[d]&&mark>v[d][arr[d]])
		{
			arr[d]++;
		}
		if(v[d].size()==arr[d])
		{
			sum+=s.size();
			temp=0;
			mark=0;
			memset(arr,0,sizeof(arr));		
		}
		else
		{
			mark=v[d][arr[d]];
			temp=v[d][arr[d]];
			arr[d]++;
			i++;
		}	
	}
	cout<<sum+temp;
	return 0;
}

Measured memory_bytes: 1724
#include <stdio.h>

#define MAX_N 100

int main()
{
	
	int N, M, D, i, j, k, cnt = 0;
	char map[MAX_N + 1][MAX_N + 1];
	
	scanf("%d %d %d", &N, &M, &D);
	
	for(i = 0; i < N; i++)
		scanf("%s", map[i]);
	
	for(i = 0; i < N; i++) {
		for(j = 0; j < M; j++) {
			if(map[i][j] == '.') {
				if(i + D - 1 < N) {
					for(k = i; k < i + D && map[k][j] != '#'; k++);
					if(k == i + D) cnt++;
				}
				if(j + D - 1 < M) {
					for(k = j; k < j + D && map[i][k] != '#'; k++);
					if(k == j + D) cnt++;
				}
			}
		}
	}
	
	printf("%d\n", cnt);
	
	return 0;
	
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;cin>>a>>b;
  string s1="",s2="";
  for(int i=0;i<b;i++)
    s1+=a+'0';
  for(int i=0;i<a;i++)
    s2+=b+'0';
  if(a<b)
    cout<<s1<<endl;
  else
    cout<<s2<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC065
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Enumerable.Range(0, n).Select(i => int.Parse(Console.ReadLine())).ToArray();
            var hashSet = new HashSet<int>();

            var i = 0;
            while (true)
            {
                if (!hashSet.Add(i))
                {
                    Console.WriteLine(-1);
                    return;
                }

                i = a[i] - 1;

                if (i == 1)
                {
                    Console.WriteLine(hashSet.Count);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 35484
#include <stdio.h>

int main()
{
  int a,b,c,temp;
  
  scanf("%d %d %d",&a,&b,&c);
  temp=a;
  a=b;
  b=temp;
  temp=c;
  c=a;
  a=temp;
  printf("%d %d %d",a,b,c);
  
  return 0;
}



Measured memory_bytes: 128
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define CASET           \
    int ___T;           \
    scanf("%d", &___T); \
    for (int __CS = 1; __CS <= ___T; __CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
LL bin(LL x, LL n, LL MOD)
{
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1)
            ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6 + 10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9 + 7;
int n, a[4][4], b[4][4], x;
int main()
{
    FOR(i, 1, 4)
    FOR(j, 1, 4)
    cin >> a[i][j];
    cin >> n;
    FOR(i, 0, n)
    {
        cin >> x;
        FOR(i, 1, 4)
        FOR(j, 1, 4)
        {
            if (x == a[i][j])
                {b[i][j] = 1;break;}
        }
    }
    /*FOR(i , 1,  4){
    FOR(j , 1 , 4){
        cout << b[i][j] <<' ';
    }cout << '\n';}*/
    int fl = 0;
    /*FOR(i, 1, 4)
    {
        int tmp = 1;
        if (!b[i][4 - i])
            tmp = 0;
        if (tmp && i == 3)
            fl = 1;
    } //cout <<"fl1 ==== " << fl << endl;
    FOR(i, 1, 4)
    {
        int tmp = 1;
        if (!b[i][i])
            tmp = 0;
        if (tmp && i == 3)
            fl = 1;
    }*/
    // cout <<"fl2 ==== " << fl << endl;
    if((b[1][1]&&b[2][2]&&b[3][3]) || (b[1][3]&&b[2][2]&&b[3][1]))fl=1;
    FOR(i, 1, 4)
    {
        if (b[i][1] && b[i][2] && b[i][3])
            fl = 1;
    }
    // cout <<"fl3 ==== " << fl << endl;

    FOR(i, 1, 4)
    {
        if (b[1][i] && b[2][i] && b[3][i])
            fl = 1;
    }
    // cout <<"fl4 ==== " << fl << endl;

    puts(fl ? "Yes" : "No");
}

Measured memory_bytes: 256
def main():
    N = int(input())
    w = []
    for i in range(N):
        w.append(input())
        if i == 0:
            continue
        if w[i][0] != w[i-1][-1]:
            print('No')
            return

    if N == len(set(w)):
        print('Yes')
    else:
        print('No')

main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,a[1<<17],x,y;
int main(){
  cin>>n;
  for(int i=0;i<n;++i)cin>>a[i];
  sort(a,a+n);
  m=-a[0]+a[n-1];
  for(int i=1;i<n-1;++i)m+=abs(a[i]);
  cout<<m<<endl;
  x=a[0],y=a[n-1];
  for(int i=1;i<n-1;i++)
    if(a[i]<0){printf("%d %d\n",y,a[i]);y-=a[i];}
    else{printf("%d %d\n",x,a[i]);x-=a[i];}
  printf("%d %d\n",y,x);
  return 0;
}


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

int main() {
  int a,b,c,f,s,t;

  std::cin >> a >> b >> c;

  if (a < b && a < c) {
    f = a;
    if (b < c) {
      s = b;
      t = c;
    } else {
      s = c;
      t = b;
    }
  }

  else if (b < a && b < c) {
    f = b;
    if (a < c) {
      s = a;
      t = c;
    } else {
      s = c;
      t = a;
    }
  }

  else {
    f = c;
    if (a < b) {
      s = a;
      t = b;
    } else {
      s = b;
      t = a;
    }
  }

  std::cout << f << " " << s << " " << t << '\n';

  return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;

struct Pocz
{
    ll x, c;
};

struct Kon
{
    ll x, c;
};

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<ll> l(m), p(m), c(m);
    for (int i = 0; i < m; ++i)
    {
        cin >> l[i] >> p[i] >> c[i];
        --l[i];
        --p[i];
    }
    vector< vector<Pocz> > pocz(n);
    vector< vector<Kon> > kon(n);
    for (int i = 0; i < m; ++i)
    {
        pocz[p[i]].push_back({l[i], c[i]});
        kon[l[i]].push_back({p[i], c[i]});
    }
    multiset<ll> S;
    vector<ll> odl(n, -1);
    odl[0] = 0;
    for (int i = 0; i < kon[0].size(); ++i)
        S.insert(kon[0][i].c);
    for (int i = 1; i < n; ++i)
    {
        if (S.size() != 0)
            odl[i] = *S.begin();
        else
        {
            cout << "-1";
            return 0;
        }
        for (int j = 0; j < pocz[i].size(); ++j)
            S.erase(S.find(odl[pocz[i][j].x] + pocz[i][j].c));
        for (int j = 0; j < kon[i].size(); ++j)
            S.insert(odl[i] + kon[i][j].c);
    }
    cout << odl[n - 1];
    return 0;
}


Measured memory_bytes: 14976
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll a[111111][2];
bool used[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ii> vec;
	ll ans1=0; ll ans2=0;
	for(int i=0;i<n;i++)
	{
		ll x,y; cin>>x>>y;
		ans1+=x; ans2+=y;
		a[i][0]=x; a[i][1]=y;
		vec.pb(mp(x,i+1)); vec.pb(mp(y,-(i+1)));
	}
	sort(vec.begin(),vec.end());
	ll ans=min(ans1,ans2);
	ll S=0;
	for(int i=0;i<n-2;i++)
	{
		S+=vec[i].fi;
	}
	for(ll i=0;i<n;i++)
	{
		int k=n-2;
		ll x=a[i][0]; ll y=a[i][1];
		int lb = lower_bound(vec.begin(),vec.end(),mp(x,i+1))-vec.begin();
		int lb2 = lower_bound(vec.begin(),vec.end(),mp(y,-(i+1)))-vec.begin();
		ll res=S+x+y;
		if(lb>lb2) swap(lb,lb2);
		if(lb<k)
		{
			res-=vec[lb].fi; res+=vec[k].fi; k++;
		}
		if(lb2<k)
		{		
			res-=vec[lb2].fi; res+=vec[k].fi; k++;
		}
		ans=min(ans,res);	
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 7536
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    int a,b,c;
    int x,y;
    int sum = 1<<30;

    cin>>a>>b>>c>>x>>y;

    for(int i = 0;i <= 100000;i++) {
        sum = min(i*2*c + max(0,x-i)*a+max(0,y-i)*b,sum);
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
string s,t;
int ns,nt;
int main(void){
    cin>>s>>t;
    ns=s.size();
    nt=t.size();
    for(int i=0;i<ns+nt;i++){
        if(i%2==0)cout<<s[i/2];
        else cout<<t[i/2];
    }
    cout<<endl;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UF{
    vector<int>par,sz;
    void init(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N;
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};
int x[55555],y[55555];

void solve(){
    map<pint,int>dic;
    rep(i,2*N)dic[{y[i],x[i]}]=i;
    UF uf;uf.init(2*N);
    rep(i,2*N){
        rep(d,4){
            int ny=y[i]+dy[d],nx=x[i]+dx[d];
            if(dic.find({ny,nx})==dic.end())continue;
            int tmp=dic[{ny,nx}];
            if(tmp==(i^1))continue;
            uf.unite(tmp,i);
            uf.unite(tmp^1,i^1);
        }
    }

    rep(i,N){
        if(uf.same(i*2,i*2+1)){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}

signed main(){
    while(cin>>N,N){
        rep(i,N){
            cin>>x[i*2]>>y[i*2];
            x[i*2+1]=x[i*2];y[i*2+1]=y[i*2];
            char c;
            cin>>c;
            if(c=='x'){
                x[i*2+1]++;
            }
            else{
                y[i*2+1]++;
            }
        }
        solve();
    }
    return 0;
}

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

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

int main()
{
    const auto S(cin2var<string>());
    const auto T(cin2var<string>());

    auto iteS(S.cbegin());
    auto iteT(T.cbegin());

    size_t count = 0;
    for (size_t i = 0; i < S.size(); ++i, ++iteS, ++iteT) {
        if (*iteS == *iteT) ++count;
    }
    cout << count << endl;
    return 0;
}

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

int main(){
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)cin>>h[i];
	int c = h[0],res=1;
	for(int i=1;i<n;i++){
		if(c<=h[i]){
			res++;
			c=h[i];
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

ll n, m;
int main() {
  cin >> n >> m;
  int x, y;
  ll sumx = 0;
  ll sumy = 0;
  rep(i, n) {
    cin >> x;
    sumx = (sumx + (ll)x*(2*i-n+1))%mod;
  }
  rep(i, m) {
    cin >> y;
    sumy = (sumy + (ll)y*(2*i-m+1))%mod;
  }
  cout << (sumx*sumy)%mod << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 10000000;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };

int gcd(int a, int b) {
	if (!b)return a; return gcd(b, a%b);
}
int cnt[1000];
signed main() {
	int a, b; cin >> a >> b;
	if (b%a == 0)cout << a + b << endl;
	else cout << b - a << endl;
}

Measured memory_bytes: 256
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input
    .split("\n")[0]
    .split(" ")
    .map(e => parseInt(e));
  const H = input[0];
  const A = input[1];

  if (H % A === 0) {
    console.log(Math.floor(H / A));
  } else {
    console.log(Math.floor(H / A) + 1);
  }
}


Measured memory_bytes: 23112
// by adiforluls
#pragma GCC optimize ("-O2")
#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 FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define mii             map<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul             1000000007
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define mod             998244353 
#define pll             pair<ll,ll>
#define endl            '\n'
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{
    int n; cin>>n;
    vll v(n), presum(n+1,0);
    rep(i,0,n)
    {
        cin>>v[i];
        presum[i+1] = presum[i] + v[i];
    }
    ll ans = LLONG_MAX;
    rep(i,1,n)
    {
        ans = min(ans,abs(presum[n]-2*presum[i]));
    }
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;  //cin>>t;
    while(t--){
       solve();
    }
    return 0;
}

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

int main(int argc, char const *argv[])
{
    int N;
    string S;
    cin >> N >> S;

    for (size_t i = 0; i < S.size(); i++)
    {
        char c = S[i] + N;
        if (c > 'Z')
        {
            c = S[i] + N - 26;
        }

        cout << c;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
const int mod=1e9+7;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
int f[401][401];//第i个为j用了k颗
int a[401],b[404],c[404][404];
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
main(){
    //file("");
	int n=read(),C=read(),ans=0;
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		for(int j=a[i];j<=b[i];j++)
			for(int k=0;k<=C;k++)
				c[i][k]=(c[i][k]+ksm(j,k))%mod;
	for(int j=0;j<=C;j++)
		f[1][j]=c[1][j];
	for(int i=2;i<=n;i++)
		for(int k=0;k<=C;k++)
			for(int l=0;l<=k;l++)
				f[i][k]=(f[i][k]+f[i-1][l]*c[i][k-l])%mod;
		ans=(ans+f[n][C])%mod;
	cout<<ans;
    return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int function(int a, int b, int c) 
{
	if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
	{
		return 0;
	}
	if (a == b && b == c)
	{
		return -1;
	}

	return function((a + b) / 2, (b + c) / 2, (c + a) / 2) + 1;
}

int main(void)
{
	long long int a, b, c,count = 0;
	cin >> a >> b >> c;
	int ans = function(a, b, c);

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


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define inf 0x7fffffff
#define llinf 0x7fffffffffffffffll
using namespace std;
vector<int> a[600];
int find(int x,int e)
{
	int l=0,r=a[x].size()-1,mid;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(a[x][mid]<=e)
		{
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	return l;
}
int main()
{
	int i,j,k,n,m,x,y,q,ans=0;
	scanf("%d%d%d",&n,&m,&q);
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
	}
	for(i=1;i<=n;i++)
	{
		sort(a[i].begin(),a[i].end());
	}
	for(i=0;i<q;i++)
	{
		scanf("%d%d",&x,&y);
		ans=0;
		for(j=x;j<=y;j++)
		{
			ans+=find(j,y);
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();

        List<Integer> factors = primeFactor(N);

        int count =0;
        for (int i = 0; i < factors.size() ; i++) {
            int pow = factors.get(i);
            int increase=1;
            while(pow-increase>=0){
                pow -= increase;
                increase++;
                count++;
            }
        }


        System.out.println(count);
    }

    static List<Integer> primeFactor(long N){

        List<Integer> res = new ArrayList<>();

        for (long i = 2; i*i <=N ; i++) {
            int count =0;
            while(N%i==0){
                N /= i;
                count++;
            }
            if(count!=0)
            res.add(count);
        }
        if(N!=1){
            res.add(1);
        }
        return res;
   }


}

Measured memory_bytes: 35744
#include<cstdio>
#include<cmath>
#include<map>
#include<utility>

using namespace std;

typedef pair<int, int> P;

int main(){
	int h, w, d; scanf("%d %d %d", &h, &w, &d);
	int a[300][300]; map<int, P> m;
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++){
		scanf("%d", &a[i][j]);
		m[a[i][j]] = P(i, j);
	}
	int c[300][300] = {};
	for(int i = 1; i <= d; i++){
		int y1 = m[i].first, x1 = m[i].second;
		for(int j = i + d; j <= h * w; j += d){
			int y2 = m[j].first, x2 = m[j].second;
			c[y2][x2] = c[y1][x1] + abs(y2 - y1) + abs(x2 - x1);
			y1 = y2; x1 = x2;
		}
	}
	int q; scanf("%d", &q);
	for(int i = 0; i < q; i++){
		int l, r; scanf("%d %d", &l, &r);
		int res = c[m[r].first][m[r].second];
		res -= c[m[l].first][m[l].second];
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int s,w;
    cin >> s >> w;
    if(w>=s)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}
    



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

using namespace std;
using ll = long long;
using pint = pair<int, int>;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define ALL(x) (x).bigin(), (x).end()
#define MOD 1000000007
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
template<typename T> inline void chmin(T &a, T b){ if(a > b) a = b; }
template<typename T> inline void chmax(T &a, T b){ if(a < b) a = b; }
template<typename T> inline void xch(T &a, T &b){ T w = a; a = b; b = w; }

int main() {
    int n, k;
    cin >> n >> k;
    char s[n];
    cin >> s;
    s[k - 1] += 32;
    cout << s << endl;
    return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, C;
  cin >> A >> B >> C;
  cout << max(0, C - (A - B)) << '\n';
  return 0;
}


Measured memory_bytes: 3692
n = gets.to_i
a = gets.split.map(&:to_i)

c = Hash.new(0)
a.each {|e| c[e] += 1}

arr = [0,0]
c.each do |key,value|
    next if value == 1
    value = 4 if value > 4
    arr += [key] * (value/2)
end

puts arr.sort[-2,2].inject(:*)

Measured memory_bytes: 97296
import sys
from collections import deque
from collections import  Counter
import statistics
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
a_li = na()
for i in range(n):
    a_li[i] = a_li[i] - (i + 1)
m1 = statistics.median_high(a_li)
#m2 = statistics.median_high(a_li)
ans1 = 0
#ans2 = 0
for i in range(n):
    ans1 += abs(a_li[i] - m1)
    #ans2 += abs(a_li[i] - m2)
print(ans1)


Measured memory_bytes: 27252
import sys
from heapq import heapify, heappush, heappop

inf = 1<<60

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ps = [sum(a[:n])]
    minhp = a[:n]
    heapify(minhp)

    for i in range(n):
        heappush(minhp, a[n + i])
        x = heappop(minhp)
        ps.append(ps[-1] + a[n + i] - x)

    ss = [sum(a[2*n:])]
    maxhp = [-ai for ai in a[2*n:]]
    heapify(maxhp)

    for i in range(n):
        heappush(maxhp, -a[2*n - 1 - i])
        x = -heappop(maxhp)
        ss.append(ss[-1] + a[2*n - 1 - i] - x)

    ans = -inf

    for i in range(n + 1):
        ans = max(ans, ps[i] - ss[n - i])

    print(ans)

if __name__ == '__main__':  
    solve()

Measured memory_bytes: 37212
#115-C
n,k = (int(i) for i in input().split())
t = [int(input()) for i in range(n)] 
#t = [10,15,11,14,12]
t = sorted(t)
min = t[k-1]-t[0]
for i in range(n-k+1):
    s = t[i+k-1]-t[i]
    if s < min:
        min = s

print(min)
#print(t)
    

Measured memory_bytes: 8280
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    bool hasDouble = false;
    bool hasTriple = false;

    for (int i = A - 1; i < max(C, D); i++) {
        if (i < max(C, D) - 1 && S[i] == '#' && S[i + 1] == '#') hasDouble = true;
        if (i >= B - 2 && i < min(C, D) - 1 && S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') hasTriple = true;
    }


    bool result = false;
    if (C < D) result = !hasDouble;
    else result = !hasDouble && hasTriple;

    cout << (result ? "Yes" : "No") << endl;

    return 0;
}

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

    using namespace std;

    typedef long long int ll;
    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin>>t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()

    void __print(int x) {cerr << x;}
    void __print(long x) {cerr << x;}
    void __print(long long x) {cerr << x;}
    void __print(unsigned x) {cerr << x;}
    void __print(unsigned long x) {cerr << x;}
    void __print(unsigned long long x) {cerr << x;}
    void __print(float x) {cerr << x;}
    void __print(double x) {cerr << x;}
    void __print(long double x) {cerr << x;}
    void __print(char x) {cerr << '\'' << x << '\'';}
    void __print(const char *x) {cerr << '\"' << x << '\"';}
    void __print(const string &x) {cerr << '\"' << x << '\"';}
    void __print(bool x) {cerr << (x ? "true" : "false");}

    template<typename T, typename V>
    void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
    template<typename T>
    void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
    void _print() {cerr << "]\n";}
    template <typename T, typename... V>
    void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
    #ifndef ONLINE_JUDGE
    #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #else
    #define debug(x...)
    #endif
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }

    int MAX = 1e6+1;
    vector<int> SPF(MAX,0);
    void seive(){
      vector<bool> visited(MAX,0);
      for(ll i = 2; i <= MAX; i++){
        if(!visited[i]){
          SPF[i] = i;
          for(ll j = i*i; j <= MAX; j += i){
            if(!visited[j]){
              visited[j] = 1;
              SPF[j] = i;
            }
          }
        }
      }
    }

    /*CHECK FOR CORNER CASES FOR GOD'S SAKE*/
    int main()
    {
      //freopen("input.txt", "r", stdin);
      //freopen("output.txt", "w", stdout);
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      seive();
      int n;
      cin>>n;
      vector<int> a(n);
      forn(i,0,n){
        cin>>a[i];
      }
      map<int,bool> primes;
      bool flag = 1;
      forn(i,0,n){
        int temp = a[i];
        while(temp > 1){
          int factor = SPF[temp];
          if(primes[factor]){
            flag = 0;
            break;
          }
          primes[factor] = 1;
          while(factor == SPF[temp]){
            temp /= factor;
          }
        }
      }
      if(flag){
        cout<<"pairwise coprime"<<endl;
        return 0;
      }
      int gcd = 0;
      forn(i,0,n){
        gcd = __gcd(gcd,a[i]);
      }
      if(gcd == 1){
        cout<<"setwise coprime"<<endl;
      }
      else
        cout<<"not coprime"<<endl;  
      

  } 


Measured memory_bytes: 14732