akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n;
    scanf("%d",&n);
    int k;
    scanf("%d",&k);
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    ll b[n] = {};

    drep(i,n){
        if(i==n-1){
            b[i] = 0;
        }else{
            b[i] = 10000000000;
            srep(j,1,k+1){
                if(i+j>n-1){
                    break;
                }
                mins(b[i],b[i+j]+abs(a[i]-a[i+j]));
            }
        }
    }


    int ans = 0;
    ans = b[0];
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 1792
n = int(input())
s = str(input())
ans = set()
for i in range(10):
    if str(i) in s:
        for j in range(10):
            if str(j) in s[s.find(str(i))+1:]:
                for k in range(10):
                    if str(k) in s[s.find(str(j), s.find(str(i))+1)+1:]:
                        ans.add((i,j,k))
print(len(ans))


Measured memory_bytes: 3188
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  int x[n], a = 0, b = 0;
  for (int i = 0; i < n; i++) cin >> x[i];
  sort(x, x + n);
  for (int i = n - 1; i >= 0; i--) {
    if ((n % 2 == 0 && i % 2 == 1) || (n % 2 == 1 && i % 2 == 0)) a += x[i];
    else b += x[i];
  }
  cout << a - b << endl;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

class ModInt {
public:
  static void setMod(int m) {
    mod = m;
  }

  ModInt(int val = 0) : val(val%mod) {}

  const ModInt operator + (const ModInt& rhs) const {
    return ModInt((this->val + rhs.val) % mod);
  }

  const ModInt operator - (const ModInt& rhs) const {
    return ModInt((this->val + mod - rhs.val) % mod);
  }

  const ModInt operator * (const ModInt& rhs) const {
    return ModInt((this->val * rhs.val) % mod);
  }

  ModInt& operator += (const ModInt& rhs) {
    this->val = (this->val + rhs.val) % mod;
    return *this;
  }

  ModInt& operator -= (const ModInt& rhs) {
    this->val = (this->val + mod - rhs.val) % mod;
    return *this;
  }

  ModInt& operator *= (const ModInt& rhs) {
    this->val = (this->val * rhs.val) % mod;
    return *this;
  }

  int val;
  static int mod;
};
int ModInt::mod = MOD;

constexpr int MAX_N = 51;
constexpr int MAX_K = MAX_N*MAX_N;
int N, K;

ModInt dp[MAX_N][MAX_N][MAX_K];

signed main()
{
  cin >> N >> K;
  if(K == 0) {
    cout << 1 << endl;
    return 0;
  }

  dp[0][0][0] = 1;

  FOR(i,1,N+1) {
    REP(j,N+1) {
      REP(k,MAX_K) {
        if(k-2*j>=0) {
          dp[i][j][k] = ModInt(2*j+1)*dp[i-1][j][k-2*j] 
          + ModInt((j+1)*(j+1))*dp[i-1][j+1][k-2*j];
          if(j-1>=0) {
            dp[i][j][k] += dp[i-1][j-1][k-2*j];
          }
        }
      }
    }
  }

  cout << dp[N][0][K].val << endl;

  return 0;
}


Measured memory_bytes: 53628
readline = open(0).readline
writelines = open(1, 'w').writelines

Q = int(readline())
root = [None, None, None]
cursor = root[1] = [root, None, None]


def insert(x):
    global cursor
    cursor[0][1] = cursor[0] = cursor = [cursor[0], cursor, x]


def move(d):
    global cursor
    if d > 0:
        for _ in range(d):
            cursor = cursor[1]
    else:
        for _ in range(-d):
            cursor = cursor[0]


def erase():
    global cursor
    cursor[1][0] = cursor[0]
    cursor[0][1] = cursor = cursor[1]


C = [insert, move, erase].__getitem__
for q in range(Q):
    t, *a = map(int, readline().split())
    C(t)(*a)
root = root[1]
ans = []
while root[1]:
    ans.append("%d\n" % root[2])
    root = root[1]
writelines(ans)



Measured memory_bytes: 80948
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    int a,b,c,d;
    int ans=0;
   for(int i=A;i<=B;i++){
      a=i/10000;
      b=(i-a*10000)/1000;
      d=i%10;
      c=(i-d)%100/10;
      if(a==d&&b==c) ans++;
   }
   cout<<ans;
    return 0;
}

Measured memory_bytes: 256
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) {
	return ist >> right.first >> right.second;
}
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) {
	return ost << right.first << ' ' << right.second;
}

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N;
int main() {
	cin >> N;
	cout << ((N / 10 == 9 || N % 10 == 9) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int K,A,B; cin >> K >> A >> B;
    bool can=false;
    rng(i,A,B+1){
        if(i%K==0) can=true;
    }
    if(can) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>

long long int max(long long int a,long long int b){
	if(a>b)return a;
	else return b;
}

int main(void) {
	int n,W;
	scanf("%d%d",&n,&W);
	long long int w[n+1],v[n+1];
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&w[i],&v[i]);
	}
	long long int dp[101][100001];
	for(int i=0;i<n;i++){
		for(int j=0;j<=W;j++){
			if(j>=w[i]){//n個目の新たな荷物を導入する部分
				dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i+1][j]);
			}
			dp[i+1][j] = max(dp[i][j],dp[i+1][j]);
		}
	}
	printf("%lld\n",dp[n][W]);
}


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

using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vp;
#define all(q) q.begin(), q.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define X first
#define Y second
#define endl '\n'

main(){
    IOS;
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int mx = 0;
    for(int i=1; i<=n; i++)
        if(s.substr(n - i, i) == t.substr(0, i)) mx = i;
    cout << n + n - mx << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n){
    cin >> s.at(i);
  }
  map<string,int> m;
  rep(i,n){
    if(m.find(s.at(i)) == m.end()){
      m.insert(make_pair(s.at(i),1));
    }else{
      m.at(s.at(i))++;
      //cout << m.at(s.at(i)) << endl;
    }
  }
  
  set<string> ssss;
  int maxxx = 0;
  rep(i,n){
    if(m.at(s.at(i)) > maxxx){
      ssss.clear();
      maxxx = m.at(s.at(i));
      ssss.insert(s.at(i));
    }else if(m.at(s.at(i)) == maxxx){
      ssss.insert(s.at(i));
    }
  }
  auto itr = ssss.begin();
  while(itr != ssss.end()){
    cout << *itr << endl;
    ++itr;
  }
}

Measured memory_bytes: 36096
#include<stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    char s[n+1],t[n+1];
    scanf("%s%s",s,t);
    char v[2*n+1];
    for(i=0;i<2*n;i=i+2){
        v[i]=s[i/2];
    }
    for(i=1;i<2*n;i=i+2){
        v[i]=t[i/2];
    }
    v[2*n]=0;
    printf("%s\n",v);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265359
#define rep(i,n) for(int i=0;i<(n);i++)
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};


main()
{
    int n, count = 0;
    cin >> n;
    bool ok = false;
    rep(i,n)
    {
        int d1, d2;
        cin >> d1 >> d2;
        if(d1==d2)
            count++;
        else
            count = 0;
        if (count >= 3)
            ok = true;
    }
    if(ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3608
#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;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void factorial() {
    dp[0] = 1;
    for (int i = 1; i < MAX; i++)
        dp[i] = dp[i - 1] * i % MOD;
}

int exp(int base, int e, int mod) {
    int result = 1;
    base %= mod;
    while (e) {
        if (e & 1)
            result = result * base % mod;

        base = base * base % mod;
        e >>= 1;
    }
    return result;
}

void solve() {
    factorial();
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int maxi = 0;
    int mini = 0;
    for (int i = k - 1; i < n; i++) {
        maxi += ((dp[i] * exp(dp[k - 1], MOD - 2, MOD) % MOD) * exp(dp[i - k + 1], MOD - 2, MOD) % MOD) * a[i] % MOD;
    }
    for (int i = 0; i <= n - k; i++) {
        mini += ((dp[n - i - 1] * exp(dp[k - 1], MOD - 2, MOD) % MOD) * exp(dp[n - i - k], MOD - 2, MOD) % MOD) * a[i] % MOD;
    }
    cout<<(maxi - mini + MOD) % MOD <<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#define rep(i, n) for(Int (i) = 0; (i) < (n); (i)++)
using namespace std;
using Int = int64_t;
using Uint = uint64_t;
constexpr long long int mod = 1e9 + 7;

int main() {

	Int A, B, K; cin >> A >> B >> K;

	A -= K;
	if (A <= 0) {
		B += A;
		A = 0;
	}

	if (B < 0)B = 0;

	cout << A << " " <<  B << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n, s[100], i, max, min, total, average;

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

    for(i=0;i<n;i++){
      scanf("%d", &s[i]);
    }
    max = min = s[0];
    for(i=1;i<n;i++){
      if(max < s[i])
	max = s[i];
      if(min > s[i])
	min = s[i];

    }
    total = 0;
    for(i=0;i<n;i++){
      total += s[i];
    }
    
    total = total - max - min;
    average = total / (n-2);
    printf("%d\n", average);
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int const maxn=1e6+5,inf=0x3f3f3f3f;
int n,K,a[maxn],b[maxn],num=1,s,k=0;
int main()
{
    scanf("%d%d",&n,&K);
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    sort(a,a+n);
    s=a[0];
    a[n]=inf;
    for(int i=1;i<=n;i++)
    {
        if(s==a[i])
        {
            num++;
        }
        else
        {
            b[k]=num;
            k++;
            num=1;
            s=a[i];
        }
    }
    sort(b,b+k);
    long long res=0;
    int x=0;
    while(k>K)
    {
        res+=b[x];
        x++;
        k--;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[1000000]  = {0};
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        a[temp]++;
        if (temp != 0)
            a[temp - 1]++;
        a[temp + 1]++;
    }
    int num = 0;
    int index = 0;
    for (int i = 0; i < 1000000; i++)
    {
        if (num< a[i])
        {
            num = a[i];
            index = i;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 200010, M = 2010;
const LL MOD = 1E9 + 7;

LL Pow(LL a, LL b) {
    LL c = 1;
    while (b) {
        if (b & 1) c = c * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return c;
}

int n;
int a[N], b[N];
int f[M << 1][M << 1], c[M << 1][M << 1];

int main() {
    scanf("%d", &n);
    int Maxa = 0, Maxb = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &a[i], &b[i]);
        if (a[i] > Maxa) Maxa = a[i];
        if (b[i] > Maxb) Maxb = b[i];
    }
    c[0][0] = 1;
    for (int i = 1, t = Maxa << 1; i <= t; ++i)
        c[i][0] = 1;
    for (int i = 1, t = Maxb << 1; i <= t; ++i)
        c[0][i] = 1;
    for (int i = 1, t = Maxa << 1; i <= t; ++i)
        for (int j = 1, t = Maxb << 1; j <= t; ++j)
            c[i][j] = (c[i - 1][j] + c[i][j - 1]) % MOD;
    for (int i = 1; i <= n; ++i)
        ++f[Maxa - a[i]][Maxb - b[i]];
    for (int i = 1, t = Maxa << 1; i <= t; ++i)
        f[i][0] += f[i - 1][0];
    for (int i = 1, t = Maxb << 1; i <= t; ++i)
        f[0][i] += f[0][i - 1];
    for (int i = 1, t = Maxa << 1; i <= t; ++i)
        for (int j = 1, t = Maxb << 1; j <= t; ++j)
            f[i][j] = (f[i][j] + f[i - 1][j] + f[i][j - 1]) % MOD;
    LL res = 0;
    for (int i = 1; i <= n; ++i)
        res = (res + f[Maxa + a[i]][Maxb + b[i]] - c[a[i] << 1][b[i] << 1]) % MOD;
    res = (res + MOD) % MOD * Pow(2, MOD - 2) % MOD;
    printf("%lld\n", res);
    return 0;
}

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

int main() {
    int64_t a, b, c, k;
    cin >> a >> b >> c >> k;
    if(a >= k)          cout << k << endl;
    else if(a + b >= k) cout << a << endl;
    else                cout << 2*a + b - k << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#define MAX 100
#define INFTY (1<<21)

int main()
{
  int n,i,j,e,sum;
  int minv; 
  int M[MAX][MAX];
  int u,v;
  int vis[MAX];
  int d[MAX];
  int p[MAX];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  scanf("%d",&e);
	  M[i][j]=(e==-1)?INFTY:e;
	}
    }

  for(i=0;i<n;i++)
    {
      d[i]=INFTY;
      p[i]=-1;
      vis[i]=0;
    }

  d[0]=0;
  
while(1)
  {
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++)
      {
	if(minv>d[i]&&!vis[i])
	  {
	    u=i;
	    minv=d[i];
	  }
      }
    if(u==-1)
      break;
    vis[u]=1;
    for(v=0;v<n;v++)
      {
	if(!vis[v]&&M[u][v]!=INFTY)
	  {
	    if(d[v]>M[u][v])
	      {
		d[v]=M[u][v];
		p[v]=u;
	      }
	  }
      }
  }

sum=0;

for(i=0;i<n;i++)
  {
    if(p[i]!=-1) sum+=M[i][p[i]];
  }
printf("%d\n",sum);

return 0;

}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N,M;cin >> N >> M;
    char A[N][N],B[M][M];
    REP(i,N) REP(j,N) cin >> A[i][j];
    REP(i,M) REP(j,M) cin >> B[i][j];
    bool flag = 0;
    REP(i,N- M + 1) REP(j,N - M + 1){
        REP(k,M){
            REP(l,M){
                if(A[i+k][j+l] != B[k][l]){flag = 1;break;}
                if(k == M-1 && l == M-1){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
            if(flag) break;
        }
        flag = 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		String inputStr = sc.next();
		sc.close();
		
		String[] arrStr = inputStr.split("");
		long inputL = Long.parseLong(inputStr);
		long l = 0;
		for (String s: arrStr) {
			if ("".equals(s)) {
				continue;
			}
			l += Integer.parseInt(s);
		}
		
		System.out.println(inputL % l == 0  ? "Yes" : "No");
	}
}


Measured memory_bytes: 20820
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vl rcnt,gcnt,bcnt;
    rep(i,n){
        char x;cin >> x;
        if(x=='R')rcnt.pb(i);
        if(x=='G')gcnt.pb(i);
        if(x=='B')bcnt.pb(i);
    }
    ll ans=rcnt.size()*gcnt.size()*bcnt.size();
    rep(i,rcnt.size()){
        rep(j,gcnt.size()){
            ll a=rcnt[i],b=gcnt[j];
            if(a<b){
                if((b-a)%2==0){
                    ll c=(b+a)/2;
                    if(binary_search(all(bcnt),c)){
                        ans--;
                    }
                }
                ll c=b+(b-a);
                if(binary_search(all(bcnt),c)){
                    ans--;
                }
                c=a-(b-a);
                if(binary_search(all(bcnt),c)){
                    ans--;
                }
            }
            else{
                if((a-b)%2==0){
                    ll c=(b+a)/2;
                    if(binary_search(all(bcnt),c)){
                        ans--;
                    }
                }
                ll c=a+(a-b);
                if(binary_search(all(bcnt),c)){
                    ans--;
                }
                c=b-(a-b);
                if(binary_search(all(bcnt),c)){
                    ans--;
                }
            }
        }
    }
    cout <<ans <<endl;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str=br.readLine();
        int times=0;
        int score=0;
        for(int i=0;i<str.length();i++){
            if(times>0){
                if(str.charAt(i)=='g'){ score++; }
                times--;
            }else if(times==0){
                if(str.charAt(i)=='p'){ score--; }
                times++;
            }
        }System.out.println(score);
    }
}


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

typedef long long ll;
using namespace std;

const ll MAXN = (ll)1e5+10;
ll dp[110][MAXN];

int main(void) {
   ll N,W;
   cin>>N>>W;
   ll w[N];
   ll v[N];
   rep(i,N) {
      cin>>w[i];
      cin>>v[i];
   }
   memset(dp,0,sizeof(dp));

   for (int i = 0; i < N;i++) {
      rep(j,MAXN) {
         dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
         if (j<w[i]) continue;
         dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]] +v[i]);
      }
   }
   cout<<dp[N][W]<<endl;



   return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 059 C / Link: http://abc059.contest.atcoder.jp/tasks/abc059_c  ----- */


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

	LL N;
	cin >> N;
	vector<LL> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}

	auto f = [&](bool mode) {
		LL ret = 0;
		LL sum = 0;
		FOR(i, 0, N) {
			LL diff = sum + a[i];
			if (mode && diff <= 0) { // to + 
				ret += abs(diff) + 1;
				diff = 1;
			}
			if (!mode && diff >= 0) { // to -
				ret += abs(diff) + 1;
				diff = -1;
			}
			sum = diff;
			mode = !mode;
		}

		return ret;
	};
	LL ans = min(f(0), f(1));



	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  if(n < 1200) cout << "ABC" << endl;
  else if(n < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
      	int ac = 0;
      	int wa = 0;
      	int tle = 0;
      	int re = 0;
      	for (int i=0; i<n; i++) {
          String s = sc.next();
          if (s.equals("AC")) {
            ac++;
          } else if (s.equals("WA")) {
            wa++;
          } else if (s.equals("TLE")) {
            tle++;
          } else {
            re++;
          }
        }
      	sc.close();
      	System.out.println("AC x "+ac+ "\nWA x " +wa+ "\nTLE x " +tle+ "\nRE x " +re);
	}
}

Measured memory_bytes: 58808
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;


void Main()
{
	constexpr auto max = 1'000'000'000;
	std::int64_t S;
	std::cin >> S;
	auto x = max - S % max;
	auto y = S / max + 1;
	if (y > max)
	{
		y = max;
		x = max - x;
	}
	boost::copy(std::array<std::int64_t, 6>{ 0, 0, max, 1, x, y }, std::ostream_iterator<std::int64_t>(std::cout, " "));
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


K = ns()
D = ni()

dp = [0] * D
mod = 10 ** 9 + 7
now_mod = 0

for k in K:
    k = int(k)
    dp_old = dp
    dp = [0] * D
    for kk in range(k):
        dp[(now_mod+kk) % D] += 1
    now_mod = (now_mod + k) % D
    for i, d in enumerate(dp_old):
        for n in range(10):
            dp[(i+n) % D] += d
            dp[(i+n) % D] %= mod
    # print(now_mod, dp)
if now_mod == 0:
    dp[0] += 1
print((dp[0]-1) % mod)


Measured memory_bytes: 67956
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, limit = LI()
weight = []
value = []
for w, v in LIR(n):
    weight += [w]
    value += [v]


w1 = min(weight)
w2, w3, w4 = w1 + 1, w1 + 2, w1 + 3
w1_list = [0] + list(accumulate(sorted([value[i] for i in range(n) if weight[i] == w1], reverse=True)))
w2_list = [0] + list(accumulate(sorted([value[i] for i in range(n) if weight[i] == w2], reverse=True)))
w3_list = [0] + list(accumulate(sorted([value[i] for i in range(n) if weight[i] == w3], reverse=True)))
w4_list = [0] + list(accumulate(sorted([value[i] for i in range(n) if weight[i] == w4], reverse=True)))


ans = 0
for i, j, k, l in product(range(len(w1_list)), range(len(w2_list)), range(len(w3_list)), range(len(w4_list) )):
    if i * w1 + j * w2 + k * w3 + l * w4 > limit:
        continue
    ans = max(ans, w1_list[i] + w2_list[j] + w3_list[k] + w4_list[l])



print(ans)

Measured memory_bytes: 41456
array_num = gets.to_i
  array = gets.split(" ").map(&:to_i)
  flag = true
  loop_num = 0
  while flag
    flag = false
    array.size.times do |i|
      break if array.size == i + 1

      if array[i] > array[i + 1]
        tmp = array[i]
        array[i] = array[i + 1]
        array[i + 1] = tmp
        flag = true
        loop_num += 1
      end
    end
  end
  puts array.join(" ")
  puts loop_num


Measured memory_bytes: 8880
import scala.io.StdIn
import scala.collection.mutable.ListBuffer
import scala.annotation.tailrec

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val n = StdIn.readInt
  val a = StdIn.readLine.split(" ").map(_.toInt)

  @tailrec
  def rec(b:ListBuffer[Int], cnt:Int, num:Iterator[Int]):Unit = {
      if(num.hasNext) {
        if((cnt&1) == 0) rec(b += num.next, cnt+1, num)
        else rec(num.next +=: b, cnt+1, num)
      } else return
  }

  val b = ListBuffer.empty[Int]
  val ite = a.iterator

  if((n&1) == 0) rec(b, 0, ite)
  else rec(b, 1, ite)

  out.println(b.mkString(" "))
  out.flush
}

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

class MyDeque{
private :
	int sz;
	int buf_size;
	int hd;
	int tl;
	int * A;
public :
	MyDeque(){
		int init_size = 2;
		sz = 0;
		buf_size = init_size;
		hd = init_size / 2;
		tl = init_size / 2;
		A = new int[init_size];
	}
	~MyDeque(){
		delete[] A;
	}
	void push(int d,int x){
		if(d == 0){
			if(hd < 0){
				int * tmp = new int[buf_size*2];
				for(int i = 0; i < sz; i++){
					tmp[i+buf_size/2] = A[hd+1+i];
				}
				hd = buf_size/2-1; 
				tl = hd + sz + 1;
				buf_size *= 2;
				delete[] A;
				A = tmp;
			}
			if(hd == tl){
				tl++;
			}
			A[hd--] = x;
			sz++;
		}
		else if(d==1){
			if(tl >= buf_size){
				int * tmp = new int[buf_size*2];
				for(int i = 0; i < sz; i++){
					tmp[i+buf_size/2] = A[hd+1+i];
				}
				hd = buf_size/2-1; 
				tl = hd + sz + 1;
				buf_size *= 2;
				delete[] A;
				A = tmp;
			}
			if(hd == tl){
				hd--;
			}
			A[tl++] = x;
			sz++;
		}
	}
	int randomAccess(int p){
		if(hd+1+p < tl && p >= 0){
			return A[hd+1+p];
		}
		return INT_MAX;
	}
	void pop(int d){
		if(sz > 0){
			if(d == 0){
				hd++;
				sz--;
			}
			else if (d == 1){
				tl--;
				sz--;
			}
		}
	}
};

int main(){
	MyDeque md;
	int q,num,d,x,p;
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> num;
		if(num == 0){
			cin >> d >> x;
			md.push(d,x);
		}
		else if (num == 1){
			cin >> p;
			printf("%d\n",md.randomAccess(p));
		}
		else if (num == 2){
			cin >> d;
			md.pop(d);
		}
	}

	return 0;
}



Measured memory_bytes: 4816
N=int(input())
List = list(map(int, input().split()))
S=0
for i in range(len(List)):
    S+=List[i]
mod=10**9+7
S=S%mod
T=0
s=0
for i in range(len(List)):
    s+=List[i]
    s=s%mod
    T+=List[i]*(S-s)
    T=T%mod
print(T)

Measured memory_bytes: 31600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  string s,ss1,ss2;
  int size;
  cin>>s;
  size=s.size();
  if(size%2==0){
    rep(i,0,size/2){
      s.erase(s.size()-1);
      s.erase(s.size()-1);
      ss1=s.substr(0,s.size()/2);
      // cout<<ss1<<endl;
      ss2=s.substr(s.size()/2,s.size());
      // cout<<ss2<<endl;
      if(ss1==ss2){
        // cout<<ss1<<" "<<ss2<<endl;
        cout<<ss1.size()+ss2.size()<<endl;
        return 0;
      }
    }
  }else{
    s.erase(s.size()-1);
    rep(i,0,size/2){
      ss1=s.substr(0,s.size()/2);
      // cout<<ss1<<endl;
      ss2=s.substr(s.size()/2,s.size());
      // cout<<ss2<<endl;
      if(ss1==ss2){
        // cout<<ss1<<" "<<ss2<<endl;
        cout<<ss1.size()+ss2.size()<<endl;
        return 0;
      }
      s.erase(s.size()-1);
      s.erase(s.size()-1);
    }
  }
}

Measured memory_bytes: 256
def root(x):
  while par[x]>=0:x=par[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x!=y:
    if x>y:x,y=y,x
    par[x]+=par[y]
    par[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return-par[root(x)]
n,m,k,*t=map(int,open(0).read().split())
par=[-1]*n
f=[set()for _ in range(n)]
for a,b in zip(*[iter(t[:m*2])]*2):
  a-=1
  b-=1
  unite(a,b)
  f[a].add(b)
  f[b].add(a)
a=[size(i)-len(f[i])-1for i in range(n)]
for c,d in zip(*[iter(t[m*2:])]*2):
  c-=1
  d-=1
  if same(c,d):
    a[c]-=1
    a[d]-=1
print(*a)

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int operation(int a, int b, char op)
{
    int res;
    if (op == '+')
    {
        res = a + b;
    }
    else
    {
        res = a - b;
    }

    return res;
}

int main()
{
    string s;
    cin >> s;
    int A, B, C, D;
    A = s[0] - '0';
    B = s[1] - '0';
    C = s[2] - '0';
    D = s[3] - '0';

    char op[2] = {'+', '-'};
    bool isGood = false;
    REP(i, 2)
    {
        REP(j, 2)
        {
            REP(k, 2)
            {
                if (!isGood)
                {
                    char op1, op2, op3;
                    op1 = op[i];
                    op2 = op[j];
                    op3 = op[k];
                    int res = 0;
                    res = operation(A, B, op1);
                    res = operation(res, C, op2);
                    res = operation(res, D, op3);
                    if (res == 7)
                    {
                        cout << A << op1 << B << op2 << C << op3 << D << "=7" << endl;
                        isGood = true;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 256
N = int(input())
a= list(map(int,input().split()))
b= list(map(int,input().split()))
c = [a[i]-b[i] for i in range(N)]
d=sum(b)-sum(a)   #c回試行する
if d<0:
  print("No")
  exit()
  
must=0
cnt=0
for num in c:
  if num>0:
    must += abs(num)
  if num*(-1) >= 2:
    cnt += (-1)*num//2
if must>d:
  print("No")
  exit()

#nokori = d-must
#print(must,nokori,cnt)

if cnt<must:
  print("No")
else:
  print("Yes")


Measured memory_bytes: 4596
/*#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}

int main()
{
    fast_cin;
    int t;
    cin>>t;
    int tc=0;
    while(t--)
    {
      int n,w;
      cin>>n>>w;
      vector<int> val,wt;
      for(int i=0;i<n;i++)
      {
          int u;
          cin>>u;
          val.pb(u);
      }
      for(int i=0;i<n;i++)
      {
          int u;
          cin>>u;
          wt.pb(u);
      }
      int ans=0;
      for(int i=0;i<n;i++)
      {
          int netwt=w;
          int j=i;
          while(j<n)
          {

          }
      }
    cout<<ans<<endl;
    }
    return 0;
}*/
#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}
void binary(int n)
{
    // array to store binary number
    int binaryNum[32];

    // counter for binary array
    int i = 0;
    while (n > 0) {

        // storing remainder in binary array
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }

    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}
int main()
{
    fast_cin;
    int t;
    t=1;
    int tc=0;
    ll x=10000009;
    while(t--)
    {
        int n;
        cin>>n;
        int dp[n]={0};
        vector<int> v;
        for(int i=0;i<n;i++)
        {
            int u;
            cin>>u;
            v.pb(u);
        }
        for(int i=1;i<n;i++)
        {
            if(i==1)
                dp[i]=abs(v[1]-v[0]);
            else
            dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
        }
        cout<<dp[n-1];
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;

ll keta(ll num){
    if(num == 0)return 1;
    ll res = 0;
    while(num){
        num /= 10;
        res++;
    }
    return res;
}

int main(){
    cin >> n;
    ll ans = INF;
    for(ll i = 1;i * i <= n;i++){
        if(n % i == 0)ans = min(ans,keta(n / i));
    }
    cout << ans << endl;
}

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

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> h(n),d(n,0);
  int ans=0;
  for(int i=0;i<n;i++)cin >> h[i];
  for(int i=n-1;i;i--){
    if(h[i-1]>=h[i])d[i-1]=d[i]+1;
    if(d[i-1]>ans)ans=d[i-1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000
using ll=long long;

vector<int> parent;
int find(int x){
  int y=parent[x];
  while(y!=parent[y]){
    y=find(y);
  }
  return parent[x]=y;
}

void unite(int a,int b){
  int x=find(a);
  int y=find(b);
  if(x!=y){
    parent[x]=y;
  }
}


int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(M),B(M);
  for(int i=0;i<M;i++){
    cin>>A[i]>>B[i];
    A[i]--;
    B[i]--;
  }
  parent.resize(N);
  for(int i=0;i<N;i++){
    parent[i]=i;
  }
  for(int i=0;i<M;i++){
    unite(A[i],B[i]);
  }
  vector<int> count(N,0);
  for(int i=0;i<N;i++){
    count[find(i)]++;
  }

  int ans=0;
  for(int i=0;i<N;i++){
    ans=max(ans,count[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 12692
fun main(args: Array<String>) {
    abc072c()
}

fun abc072c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toInt() }
        .sorted()

    val grouped = aList.groupBy { it }

    val answer = grouped.map {
        (grouped[it.key - 1]?.size ?: 0) +
                it.value.size +
                (grouped[it.key + 1]?.size ?: 0)
    }.max()

    println(answer)
}


Measured memory_bytes: 62648
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
vector<int>dat[2][50000];
int p[2][5000];
 
void init(int t,int k, int l, int r) {
	if (r - l == 1) {
		dat[t][k].push_back(p[t][l]); return;
	}
	int lb = k * 2 + 1, rb = k * 2 + 2;
	init(t,lb, l, (l + r) / 2);
	init(t,rb, (l + r) / 2, r);
	dat[t][k].resize(r - l);
	merge(dat[t][lb].begin(), dat[t][lb].end(), dat[t][rb].begin(), dat[t][rb].end(), dat[t][k].begin());
}
int query(int t,int a, int b, int c, int d, int k, int l, int r) {//[a,b),[c,d)
	if (b <= l || r <= a)return 0;
	if (a <= l&&r <= b) {
		int u = lower_bound(dat[t][k].begin(), dat[t][k].end(), d) - dat[t][k].begin();
		int v = lower_bound(dat[t][k].begin(), dat[t][k].end(), c) - dat[t][k].begin();
		return u - v;
	}
	int lb = query(t,a, b, c, d, k * 2 + 1, l, (l + r) / 2);
	int rb = query(t,a, b, c, d, k * 2 + 2, (l + r) / 2, r);
	return lb + rb;
}
 
string c[5000];
int a[5000];
ll dp[3000][3000];
 
signed main(){
	int n;scanf("%d",&n);
	rep(i,2*n){
		cin>>c[i]>>a[i];a[i]--;
		if(c[i]=="B"){
			p[0][a[i]]=i;
		}
		else{
			p[1][a[i]]=i;
		}
	}
	vector<Bit>bit(2,Bit(n));
	ll ans=0;
	int c1=0,c2=0;
	rep(i,2*n){
		if(c[i]=="B"){
			ans+=c1-bit[0].sum(a[i]);
			c1++;
			bit[0].add(a[i],1);
		}
		else{
			ans+=c2-bit[1].sum(a[i]);
			c2++;
			bit[1].add(a[i],1);
		}
	}
	int N=1;while(N<n)N<<=1;
	rep(i,2)init(i,0,0,N);
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	rep(i,n+1)rep(j,n+1){
		if(i<n){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]+query(1,0,j,p[0][i],INF,0,0,N));
		}
		if(j<n){
			dp[i][j+1]=min(dp[i][j+1],dp[i][j]+query(0,0,i,p[1][j],INF,0,0,N));
		}
	}
	//for(int i=1;i<=n;i++)cout<<p[1][i]<<' ';
	//cout<<endl;
	/*rep(i,n+1){
		rep(j,n+1)cout<<dp[i][j]<<' ';
		cout<<endl;
	}*/
	cout<<dp[n][n]+ans<<endl;
}

Measured memory_bytes: 73600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    map<int, int> h;
    string str;
    for (int i = 1; i <= n; i++)
    {
        cin >> str;
        char* e = nullptr;
        int tmp = strtol(str.c_str(), &e, 10);
        h.insert(make_pair(tmp, i));
    }
    
    for (int i = 1; i <= n; i++)
    {
        int ans = h[i];
        cout << ans + 1;
      	if (i == n)
        {
          cout << endl;
        } else {
          cout << " ";
        }
    }
    
}

Measured memory_bytes: 5504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {

    int k, x;
    scanf("%d %d", &k, &x);

    if (k * 500 >= x) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <string>
#include<cmath>
using namespace std;

int main() {
  int a,a2,a3, x;
  cin >> a;
  a2 = pow(a,2);
  a3 = pow(a,3);
  x = a + a2 + a3;
  cout << x;
}


Measured memory_bytes: 3944
N,M=map(int, input().split())
H = list(map(int, input().split()))
ans=[0]*N
for i in range(M):
    A,B=map(int,input().split())
    if H[A-1]>H[B-1]:
        ans[B-1]=-1
    elif H[A-1]<H[B-1]:
        ans[A-1]=-1
    else:
        ans[A-1]=ans[B-1]=-1
print(len(ans)-ans.count(-1))

Measured memory_bytes: 84728
n = int(input())
b = list(map(int, input().split()))
b = list(reversed(b))
ans = 0
for i in range(n):
    if i == 0:
        ans += b[i]
    elif i == n-1:
        ans += b[i-1]
    else:
        ans += min(b[i], b[i-1])
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    int k;
    string s;
    cin >> k >> s;
      for(int i = 0; i < s.length(); i++){
        if(i == k){
            cout << "...\n";
            break;
        }
        cout << s[i];
      }
    return 0;
}
 
 

Measured memory_bytes: 3628