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

int main(){
	int n;
	cin >> n;
	int ans = 0,l,r;
	REP(i,n){
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 100000000;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;
int h[200005],s[200005]={0}; 
int main(){
    int n,m,l,r;
    
    scanf("%d%d",&n,&m);
    int sum=n;
    for(int i=1;i<=n;i++){
    	scanf("%d",&h[i]);
    }
    for(int i=1;i<=m;i++){
    	scanf("%d%d",&l,&r);
    	if(h[l]<=h[r]&&s[l]==0){
    		sum--;
    		s[l]=1;
    	} 
    	if(h[l]>=h[r]&&s[r]==0){
    		sum--;
    		s[r]=1;
    	} 
    }
    
    
    
    printf("%d",sum);
 	return 0;
}




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

int main(void){
   int n;
   cin >> n;
   int a[n];
   map<int,int>mp;
   for(int i = 0;i < n;i++){
       cin >> a[i];
       mp[a[i]]++;
   }
   sort(a,a+n);
   
   int check[1000005] = {},num[n];
   int q = 0;
   for(auto p:mp){
       if(p.second > 0){
            //if(check[p.first] == 0){
                num[q] = p.first;
                for(int j = 2*p.first;j <= a[n-1];j+=p.first){
                    check[j]++;
                }
            //}
        }
   }
   
   int sum = 0;
   for(auto p:mp){
       if(p.second == 1 && check[p.first] == 0)sum++;
       //cout << p.first << ":" << p.second << " " << check[p.first] << endl;
   }
   cout << sum;
}

Measured memory_bytes: 17592
def main():
    n,a,b,k=map(int,input().split())
    fact=[1]
    mod=998244353
    for i in range(1,n+1):fact.append(fact[-1]*i%mod)
    fn=fact[n]
    ncr=[pow(fact[n-i]*fact[i],mod-2,mod)*fn%mod for i in range(n+1)]
    ans=0
    ans_list=[]
    for i in range(n+1):
        j=(k-a*i)//b
        if i*a+j*b==k:
            if 0<=j<=n:
                ans_list.append([i,j])
    for p,q in ans_list:
        ans=(ans+ncr[p]*ncr[q])%mod
    print(ans)
main()

Measured memory_bytes: 64636
#include <stdio.h>
#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
typedef long long ll;

using namespace std;

const int N = 3e5 + 111, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1.0), eps = 1e-9;

int n, a[N];

void build(int x){
	for(int i = 1; i <= x + 1; ++i){
		int len = max(i - 1, x + 1 - i);
		a[len]--;
		if(a[len] < 0){
			cout << "Impossible";
			exit(0);
		}
	}
}

int main(){
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cout << setprecision(10) << fixed;

	cin >> n;
	for(int i = 1; i <= n; ++i){
		int x;
		cin >> x;
		a[x]++;
	}

	int mx = 100;
	while(a[mx] == 0)
		mx--;

	build(mx);

	for(int i = mx; i >= (mx + 1) / 2 + 1; --i)
		a[i] = 0;

	for(int i = 100; i >= 0; --i)
		if(a[i] != 0){
			cout << "Impossible";
			return 0;
		}	

	cout << "Possible";
	
	return 0;
	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
const ll mod = 1e9 + 7;
 
int main() {
  ll x;
  cin >> x;
  ll rem = x % 11;
  ll ans = (x/11) * 2;
  if (rem != 0){
    if (rem <= 6) ans += 1;
    else ans += 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
 
 
void solve(){
    int n,k;
    cin>>n>>k;

    vector<ll> dp(n),h(n);
    for(int i=0;i<n;i++)cin>>h[i];

    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);

    for(int i=2;i<n;i++){
        dp[i]=INT_MAX;
        for(int j=1;j<=k && i-j>=0; j++){
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

    // for(auto x:dp)cout<<x<<' ';
    // cout<<endl;

    cout<<dp.back()<<endl;
}


int main()
{   
    // int n;
    // cin>>n;

    // while(n--)
    solve();

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    
    freopen("output.txt", "w", stdout);
    #endif

    ll n,i;
    cin>>n;

    vector< pair<ll,ll> >v(n);
    for(i=0;i<n;i++){
        cin>>v[i].fi>>v[i].se;
    }

    ll flag=0;
    for(i=0;i<n-2;i++)
    {
        if(v[i].fi==v[i].se && v[i+1].fi==v[i+1].se && v[i+2].fi==v[i+2].se){
            flag=1;
            break;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    } 
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <valarray>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstring>
#include <sstream>
using namespace std;
 
#define REP(i,n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-9;
 
int dp[2][1<<16];
int r,c;
string input[128];
 
int main() {
  cin>>r>>c;
  for(int i=0; i<r; ++i) cin>>input[i];
 
  memset(dp,-1,sizeof(dp));
 
  int *cur = dp[0];
  int *nxt = dp[1];
 
  cur[0] = 0;
  REP(i,r) {
    REP(j,c) {
      REP(S,1<<c) nxt[S] = -1;
      REP(S,1<<c) {
        if (cur[S] == -1) continue;
 
        int S1 = S & ((1<<j)-1);
        int S2 = S ^ S1;
        int n1 = __builtin_popcount(S1);
        int n2 = __builtin_popcount(S2);
        char left = '_';
        if (j&&n1) {
          if (S>>(j-1)&1) {
            left = input[i][n1-1];
          }
        }
        char up = '_';
        if (i>0 && n2) {
          if ((S>>j)&1) {
            up = input[i-1][input[i-1].size()-n2];
          }
        }
        // cout << bitset<3>(S) << " " << bitset<3>(S1) << " "<< bitset<3>(S2) << endl;
        // printf("(%d,%d) %d %c %c\n", i,j, cur[S],left,up);
        // bit たてる
        if (n1 < input[i].size()) {
          char now = input[i][n1];
          int score = 0;
          if (now == left) score+=2;
          if (now == up) score+=2;
          int T = S|1<<j;
          // if (score) {
          //   printf("(%d,%d) %d %c %c %c\n", i,j, cur[S],left,up, now);
          // }
          nxt[T] = max(nxt[T], cur[S]+score);
        }
        int len = input[i].size();
        if (len-n1 <= c-j-1) {
          // たてない
          int T = S & (~(1<<j));
          nxt[T] = max(nxt[T], cur[S]);
        }
      }
      swap(cur, nxt);
    }
  }
  int ans = 0;
  REP(S,1<<c) {
    // if (cur[S] == 18) {
    //   cout <<bitset<16>(S) << endl;
    // }
    ans = max(ans, cur[S]);
  }
 
  cout << ans << endl;
}

Measured memory_bytes: 1736
#include <iostream>
#include<algorithm>
using namespace std;
static const int MAX = 105;

/*

*/
int bubbleSort(int a[],int m)
{
    int k = 0;
    int flag = 1;
    for(int i = 0;flag;i++)
    {
        flag = 0;
        for(int j = m-1;j>=i+1;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                flag=1;
                k++;
            }
        }
    }
    return k;
}

int main()
{
    int n,a[MAX],m=0;
    cin>>n;
    for(int i =0; i<n; i++)
    {
        cin>>a[i];
    }
    //cout<<m;
    m = bubbleSort(a,n);

    for(int i =0;i<n;i++)
    {
        if(i)
        {cout<<" ";}
        cout<<a[i];
    }
    cout<<endl;
    cout<<m<<endl;

    return 0;
}

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

const int N = 201000;
char str[N];
int f[26][N], n;
int nxt[N], t;

ll calc(int*a, ll p) {
	if(p <= n) return a[p];
	if(p <= (n<<1)) return a[n] + a[p-n];
	ll t0 = n, t1 = n + t;
	ll r0 = a[n], r1 = a[n] + a[t];
	while(t0 + t1 <= p) {
		t0 += t1, r0 += r1;
		swap(t0, t1), swap(r0, r1);
	}
	return r1 + calc(a, p - t1);
}

bool fac;

ll work(int*a, ll p) {
	if(p <= n) return a[p];
	if(p <= (n<<1)) return a[n] + a[p-n];
	if(fac) {
		p -= n;
		return a[n] + (p/t) * a[t] + a[p%t];
	}
	return calc(a, p);
}

int main() {
	scanf("%s", str+1);
	n = strlen(str+1) >> 1;
	for(int i=0;i<26;++i) {
		int*arr = f[i];
		for(int j=1;j<=n;++j)
			arr[j] = arr[j-1] + (str[j] == (i+'a'));
	}
	
	for(int i=2,k=0;i<=n;++i) {
		while(k and str[k+1] != str[i]) k = nxt[k];
		if(str[k+1] == str[i]) ++k;
		nxt[i] = k;
	}
	
	t = n - nxt[n];
	fac = (n%t == 0);
	
	ll l, r; scanf("%lld%lld",&l,&r);
	for(int i=0;i<26;++i)
		printf("%lld ", work(f[i], r) - work(f[i], l-1));
	putchar(10);
	return 0;
}

Measured memory_bytes: 20352
#include <stdio.h>

int main(void) {
  int a, b, me, ma, ve;

  scanf("%d", &a);
  scanf("%d", &b);

  me = a-b;
  ma = a+b;
  ve = a*b;

  if(ve > me && ve > ma){
    printf("%d\n", ve);
  } else if(me > ma){
    printf("%d\n", me);
  } else {
    printf("%d\n", ma);
  }
  return 0;
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}
	b := make([]int, n)
	for i := range b {
		b[i] = readInt()
	}
	c := make([]int, n)
	for i := range c {
		c[i] = readInt()
	}

	sort.Ints(a)
	sort.Ints(c)
	ans := 0
	for _, v := range b {
		ai := sort.SearchInts(a, v)
		ci := len(c) - sort.SearchInts(c, v+1)
		ans += ai * ci
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6016
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
int mod = 1000000007;

class Solution {
public:
    ll d(int n, vector<int>& a) {
        ll res = 0;
        sort(a.begin(), a.end(), greater<int>());
        int k = 0;
        int f = 0;
        for(int i = 1; i < n; ++i) {
            if(i == 1) {
                res += a[k];
                k++;
            }
            else {
                if(f == 0) {
                    res += a[k];
                    f = 1;
                }
                else {
                    res += a[k];
                    k++;
                    f = 0;
                }

            }
        }

        return res;
    }

};

int main() {
    int n;
    cin >> n;
    vector<int> a(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    Solution zhy;
    cout << zhy.d(n, a) << endl;
    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
// constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
template <class T> bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// v ector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(w + 1, vector<int>(k+1, 0)));

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    ll K;
    cin >> s >> K;
    ll n = s.size();
    vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(K+1,vector<ll>(2,0)));
    dp[0][0][0] = 1;
    rep(i,n) {
        rep(j,K+1) {
            rep(k,2) {
                ll ns = s[i]-'0';
                rep(l,10) {
                    ll ni = i+1;
                    ll nj = j;
                    ll nk = k;
                    if (l != 0) nj++;
                    if (nj > K) continue;
                    if (k == 0) {
                        if (l > ns) continue;
                        if (l < ns) nk = 1;
                    }
                    dp[ni][nj][nk] += dp[i][j][k];

                }
            }
        }
    }
    print(dp[n][K][0]+dp[n][K][1]);




    return 0;
}


Measured memory_bytes: 3644
import re
 
N,Q = list(map(int,input().split()))
s = input()
lis=[0]*N
 
count = 0
for i in range(1,len(s)):
    if s[i-1] == 'A' and s[i] == 'C':
        count +=1
    lis[i]+=count
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])


Measured memory_bytes: 13908
import sys
import math

# get input
input = sys.stdin.readline()

N = int(input)

# number of connections
M = (N*(N-1)/2)-N/2
print(math.ceil(M))

# NG sum
X = N + 1 - N % 2
for i in range(1, N+1):
    for j in range(i+1,N+1):
        if not i + j == X:
            print(i, " ", j)



Measured memory_bytes: 3680
import sys
from bisect import bisect_left, insort_left

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    s = INT()

    a = s
    l = [a]
    for i in range(1000000):
        a = 3*a + 1 if a % 2 else a//2

        if bisect_left(l, a) == len(l):
            l.append(a)
        elif l[bisect_left(l, a)] == a:
            print(i + 2)
            sys.exit()
        else:
            insort_left(l, a)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
long long a,b,c[200002],i;
long long ans=0;
int main(){
scanf("%lld%lld",&a,&b);
for (i=0;i<=a-1;i++)
scanf("%lld",&c[i]);
sort(c,c+a);
if (b>=a){
printf("0");
return 0;
}
for (i=0;i<=a-1-b;i++)
ans=ans+c[i];
printf("%lld",ans);
return 0;
}

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

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

    int count = 0;

    while (N != 0)
    {

        if (N % 2 == 0)
        {
            N -= 1;
            continue;
        }

        int c = 0;

        for (int i = 1; i <= N; ++i)
        {
            if (N % i == 0)
            {
                ++c;
            }
        }

        if (c == 8)
        {
            ++count;
        }

        N -= 1;
    }

    std::cout << count << endl;
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int E = A + B;
  int F = C + D; 
  if (E == F) {
    cout << "Balanced" << endl;
  }
  else if (E > F) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
/*I love Korosensei forever.*/
/**/
int main()
{
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    int n;
    read(n);
    char c;
    int cnt1=0,cnt2=0;
    for(int i=1;i<=n;i++)
    {
        cin>>c;
        if(c=='R') cnt1++;
        else cnt2++;
    }
    if(cnt1>cnt2) puts("Yes");
    else puts("No");
}

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

struct Job{
    int a, b;
    Job(int ai, int bi){
        a = ai;
        b = bi;
    }
};

bool cmp(const Job &p, const Job &q)
{
    return p.b < q.b;
}

int main(){
    int n, ai, bi, f;
    cin >> n;

    vector<Job> job;

    for (int i=0; i<n; i++){
        cin >> ai >> bi;
        job.push_back(Job(ai,bi));
    }
    sort(job.begin(), job.end(),cmp);

    ai = 0;
    bi = 0;
    f = 0;
    for (auto task:job){
        ai += task.a;
        bi = task.b;
        if (bi < ai){
            f += 1;
        }
    }
    if (f>0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int sum=0;
  for(int i=0;i<s.length();i++)
    sum+=((int)s[i]-'0');
  if(sum%9==0)
    cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 3720
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int>data(n);
	map<int, int>Omp;
	map<int, int>Emp;
	for (int i = 0; i < n; i++) {
		cin >> data[i];
		if (i % 2 == 0) {
			Omp[data[i]]++;
		}
		else {
			Emp[data[i]]++;
		}
	}
	int OM, Om, EM, Em, On, En;
	OM = EM = Om = Em = 0;
	for (auto it = Omp.begin(); it != Omp.end(); ++it) {
		if (OM <= it->second) {
			OM = it->second;
			On = it->first;
		}
		if (it == next(Omp.end(), -1) ) {
			Omp[On] = 0;
		}
	}
	for (auto it = Omp.begin(); it != Omp.end(); ++it) {
		chmax(Om, it->second);
	}
	for (auto it = Emp.begin(); it != Emp.end(); ++it) {
		if (EM <= it->second) {
			EM = it->second;
			En = it->first;
		}
		if (it == next(Emp.end(), -1)) {
			Emp[En] = 0;
		}
	}
	for (auto it = Emp.begin(); it != Emp.end(); ++it) {
		chmax(Em, it->second);
	}
	if (On == En) {
		cout << min(n - (OM + Em), n - (EM + Om)) << endl;
	}
	else {
		cout << n - (OM + EM) << endl;
	}
}


Measured memory_bytes: 5376
#include<cstdio>
#include<algorithm>
using namespace std;
int a[200001];
int main()
{
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	int k=1<<30;
	for(i=30;i>=1;i--,k>>=1)
	{
		int p=0;
		int q=n-1;
		while(p<q)
		{
			if(a[p]+a[q]==k)
			{
				ans++;
				a[p++]=0;
				a[q--]=0;
			}
			else if(a[p]+a[q]<k)
				p++;
			else
				q--;
		}
    	int len=0;
    	for(p=0;p<n;p++)
			if(a[p])
				a[len++]=a[p];
		n=len;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n); rep (i, a.size()) cin >> a[i];
    int ans = 0;
    rep (i, n) {
        if (i % 2 == 0 && a[i] % 2 == 1) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3612
n = int(input())
A1 = tuple(map(int, input().split()))
A2 = tuple(map(int, input().split()))

from itertools import accumulate
A1S = [0] + list(accumulate(A1))
A2S = [0] + list(accumulate(A2))

ma = 0
for i in range(1, n+1):
    ma = max(ma, A1S[i] + A2S[-1] - A2S[i-1])
print(ma)

Measured memory_bytes: 3064
#define GODSPEED ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define f(i,x,n) for(i=x;i<n;i++)
#define rf(i,x,n) for(i=n;i>x;i--)
#define ll long long
#define GCD(a,b) __gcd(a,b);
#define adios return 0;

/*
SHERAJUL ARIFIN
Dept. of CSE,
IUT.
*/


#include <bits/stdc++.h>
using namespace std;

int main()
{
    GODSPEED;
    ll t,n,a,b,c,d,s=0,i,j,flag;
    cin>>a>>b;
    vector<ll>v(b);
    f(i,0,b) cin>>v[i];
    v.pb(v[0]+a);
    f(i,0,b)
    {
        s=max(s,v[i+1]-v[i]);
    }
    cout<<a-s;
    adios;
}


Measured memory_bytes: 4608
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int H,W;
int g[1001][1001];
int main(){
    int H,W; cin >> H >> W;
    fill(g[0],g[1001],MM);
    queue<Pair> que;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            char c;
            cin >> c;
            if(c == '#'){
                que.push(Pair(i,j));
                g[i][j] = 0;
            }
        }
    }
    while(!que.empty()){
        Pair p = que.front();
        que.pop();
        int h = p.first, w = p.second;
        if(h >= 1 && g[h-1][w] == MM){
            g[h-1][w] = g[h][w]+1;
            que.push(Pair(h-1,w));
        }
        if(w >= 1 && g[h][w-1] == MM){
            g[h][w-1] = g[h][w]+1;
            que.push(Pair(h,w-1));
        }
        if(h+1 < H && g[h+1][w] == MM){
            g[h+1][w] = g[h][w]+1;
            que.push(Pair(h+1,w));
        }
        if(w+1 < W && g[h][w+1] == MM){
            g[h][w+1] = g[h][w]+1;
            que.push(Pair(h,w+1));
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            ans = max(ans,g[i][j]);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 12304
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int k = Integer.parseInt(input[2]);
        
        int present = -1;

        for(int i = 0; i < k; i++){
            present = a+i;
            if(present > b) return;
            System.out.println(present);
        }

        int start = Math.max(present+1, Math.max(0,b-k+1));
        for(int i = start; i <= b; i++){
            System.out.println(i);
        }
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,answer=0;
  cin >> N;
  int a[N];
  map<int,int> b;
  for (int i = 0; i < N; b[a[i++]]++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    answer = max(answer,b[a[i]]+b[a[i]-1]+b[a[i]+1]);
  }
  cout << answer;
}

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

int main() {
	int N;
	cin >> N;
	set<pair<int,int>> X,Y;
	map<int, pair<int, int>> Ixy;
	set<pair<int,pair<int,int>>> Q;
	int x, y, i;
	for (i = 0;i < N;i++) {
		cin >> x >> y;
		X.insert({ x,i });
		Y.insert({ y,i });
		Ixy.insert({ i,{x,y} });
	}
	i--;
	ll cnt = 0;
	while (1) {
		auto xf = X.find({ x,i });
		auto xd = xf;
		auto xu = xf;
		if (xd != X.begin()) {
			xd--;
			Q.insert({ abs((*xd).first - x),*xd });
		}
		xu++;
		if (xu != X.end()) {
			Q.insert({ abs((*xu).first - x),*xu });
		}
		X.erase(xf);

		auto yf = Y.find({ y,i });
		auto yd = yf;
		auto yu = yf;
		if (yd != Y.begin()) {
			yd--;
			Q.insert({ abs((*yd).first - y),*yd });
		}
		yu++;
		if (yu != Y.end()) {
			Q.insert({ abs((*yu).first - y),*yu });
		}
		Y.erase(yf);
		Ixy.erase(i);

		while (!Q.empty()) {
			auto b = Q.begin();
			i = (*b).second.second;
			N = (*b).first;
			Q.erase(b);
			if (Ixy.find(i) != Ixy.end()) {
				cnt += N;
				x = Ixy[i].first;
				y = Ixy[i].second;
				break;
			}
		}
		if (Ixy.empty())
			break;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 22144
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		sc.close();

		char[] s = S.toCharArray();
		boolean ans = true;
		for(int i=0;i<S.length();i++) {
			char c = s[i];
			if((i+1)%2==1) {
				if(c!='R'&&c!='U'&&c!='D') {
					ans = false;
				}
			} else {
				if(c!='L'&&c!='U'&&c!='D') {
					ans = false;
				}
			}
		}
		if(ans) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const long long mod = 1e9+7;

vector< vector<long long> > matrix_product(vector< vector<long long> > &A, vector< vector<long long> > &B){
  int n = A.size(), m = B[0].size(), l = A[0].size();
  vector< vector<long long> > ret(n,vector<long long>(m));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      ret[i][j] = 0;
      for(int k = 0; k < l; ++k){
        ret[i][j] += (A[i][k]*B[k][j])%mod;
        ret[i][j] %= mod;
      }
    }
  }
  return ret;
}

vector< vector<long long> > matrix_pow(const vector< vector<long long> > &P, long long N){
  vector< vector<long long> > ret(P.size(),vector<long long>(P.size(),0)), t = P;
  for(int i = 0; i < P.size(); ++i) ret[i][i] = 1;
  while(N > 0){
    if(N&1){
      ret = matrix_product(ret,t);
    }
    t = matrix_product(t,t);
    N /= 2;
  }
  return ret;
}

int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector< vector<long long> > M(N, vector<long long>(N,0));
  for(int i = 0; i < N; ++i)
    for(int j = 0; j < N; ++j)
      cin >> M[i][j];
  M = matrix_pow(M,K);
  long long ans = 0;
  for(int i = 0; i < N; ++i)
    for(int j = 0; j < N; ++j)
      ans += M[i][j], ans %= mod;
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

typedef pair<int, int> P;

P f(int x){
    int a = x%10;
    int b = 0;
    while(x){
        b = x;
        x /= 10;
    }
    return P(a, b);
}

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

    int n;
    cin >> n;
    map<P, int> freq;

    for(int i=1; i<=n; i++){
        freq[f(i)]++;
    }
    lint ans = 0;

    // for(auto it = begin(freq); it != end(freq); it++){
    //     pair<const P, int> p = *it;
    //     cout << "["s << p.first.first << ","s << p.first.second << "]: "s << p.second << endl;
    // }

    for(int i=1; i<=n; i++){
        P p = f(i);
        swap(p.first, p.second);
        ans += freq[p];
    }

    COUT(ans);

    return 0;
}

Measured memory_bytes: 256
////////////////////////////////////////////////
//  ********  *      *    *******    * *      //                 :
//  *         *      *   *       *   *   *    //     64 BITS     C     64 BITS
//  *****     *      *  *         *  *     *  //                 +
//  *         *      *  ***********  *     *  //:  16 - 6 - 2020 +   16 - 6 - 2020 :
//  *         *      *  *         *  *   *    //                 1
//  *         ********  *         *  * *      //     64 BITS     7     64 BITS
////////////////////////////////////////////////                 :
#define ll long long
#define ui unsigned int
#define ud unsigned double
#define mp make_pair
#define pii pair<int,int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pdi pair<double,int>
#define pb push_back
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
using namespace std;
const double pi = acos(-1.0);
int main()
{
    string s;
    cin>>s;
    if (s[0] == s[1] && s[1] == s[2]){
        puts("No\n");
    }
    else{
        puts("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> M;
	K = M - N;
	cout << K * (K + 1) / 2 - M << endl;

	return 0;
}


Measured memory_bytes: 256
// ===================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}
 
const int N=50+10;
 
struct edge { int v,nxt; } e[N];
int head[N];
void addEdge(int u,int v) {
    static int cnt=0;
    e[++cnt]=(edge){v,head[u]},head[u]=cnt;
}
 
int n,X,d;
struct node { ll v; int w,id; } a[N];
int operator <(node a,node b) { return a.w*b.v>b.w*a.v; }
ll dp[N*N*N];
 
void dfs(int u) {
    a[u].w=1,a[u].id=u;
    for (int i=head[u];i;i=e[i].nxt)
        dfs(e[i].v),a[u].v+=a[e[i].v].v,a[u].w+=a[e[i].v].w;
}
 
int main() {
    n=read(),X=read(),d=read();
    a[1].v=read();
    for (int i=2;i<=n;++i)
        a[i].v=read(),addEdge(read(),i);
    dfs(1); int mx=n*n*n,L=min(n,d);
    memset(dp,0x3f,sizeof(dp)),dp[0]=0;
    for (int i=1;i<=n;++i) {
        int x=L;
        for (int j=0;1<<j<=x;++j) {
            int w=a[i].w*(1<<j); ll v=a[i].v*(1<<j);
            for (int k=mx;k>=w;--k) dp[k]=min(dp[k],dp[k-w]+v);
            x-=1<<j;
        }
        if (x) {
            int w=a[i].w*x; ll v=a[i].v*x;
            for (int j=mx;j>=w;--j) dp[j]=min(dp[j],dp[j-w]+v);
        }
    }
    sort(a+1,a+n+1);
    while (a[n].id!=1) --n;
    ll ans=0;
    for (int i=0;i<=mx;++i) {
        if (dp[i]>X) continue;
        ll w=i,v=dp[i];
        for (int j=1;j<n;++j) {
            ll c=min((ll)d-L,(X-v)/a[j].v);
            w+=c*a[j].w,v+=c*a[j].v;
        }
        ll c=(X-v)/a[n].v;
        w+=c*a[n].w,v+=c*a[n].v;
        ans=max(ans,w);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<string.h>
int main(){
	int n;
	scanf("%d", &n);
	int ctrAc=0, ctrWa=0, ctrTle=0, ctrRe=0;
	for(int i=0; i<n; i++){
		char word[5];
		scanf("%s", word);
		
		if(word[0]=='A' && word[1]=='C'){
			ctrAc++;
		}
		else if(word[0]=='W' && word[1]=='A'){
			ctrWa++;
		}
		else if(word[0]=='T' && word[1]=='L' && word[2]=='E'){
			ctrTle++;
		}
		else if(word[0]=='R' && word[1]=='E'){
			ctrRe++;
		}
	}
	printf("AC x %d\n", ctrAc);
	printf("WA x %d\n", ctrWa);
	printf("TLE x %d\n", ctrTle);
	printf("RE x %d\n", ctrRe);
	return 0;
}

Measured memory_bytes: 1732
s = input()

if s[0] != 'A':
    print('WA')
    exit()

cntC = 0
for i in range(2,len(s)-1):
    if s[i] == 'C':
        cntC += 1

if cntC != 1:
    print('WA')
    exit()

cntL = 0
for i in range(len(s)):
    if s[i].islower():
        cntL+=1

if cntL != len(s)-2:
    print('WA')
    exit()

print('AC')


Measured memory_bytes: 38384
#include <stdio.h>
int H,W,i,j;
int main(){
  for(;;){
    scanf(" %d %d",&H,&W);
    if(H==0&&W==0){
      return 0;
    }
    for(i=0;i<W;i++){
      printf("#");
    }
    printf("\n#");
    for(i=0;i<H-2;i++){
      for(j=0;j<W-2;j++){
        printf(".");
      }
      printf("#\n#");
    }
    for(i=0;i<W-1;i++){
      printf("#");
    }
    printf("\n\n");
  }
}

Measured memory_bytes: 2652
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

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


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))
#define each(itr,v) for(auto (itr):(v))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

template <typename T>
T gcd(T a, T b) {
	if (a > b) return gcd(b, a);
	return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}



// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	ll c = N / 11;
	if (N % 11 == 0) cout << 2 * c << endl;
	else if (N % 11 != 0) {
		if (N % 11 <= 6) cout << 2 * c + 1 << endl;
		else cout << 2 * c + 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[3][11];
int main(){
	rep(i,0,3)scanf("%s",s[i]);
	puts(s[0][strlen(s[0])-1]==s[1][0]&&s[1][strlen(s[1])-1]==s[2][0]?"YES":"NO");
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

const int MAX_H = 100000;

/**
 * 入力制約
 * 2 <= N <= 10^5
 * 1 <= K <= 100
 * 1 <= hi <= 10^4
 */
int N;
int K;
int H[MAX_H+1];
int C[MAX_H+1];

void solve()
{
    for (int i=1; i<N+1; i++) {
        C[i] = 1000000000;
    }
    for (int i=1; i<N+1; i++) {
        if (i == 1) {
            C[i] = 0;
        } else {
            for (int j = max(i-K, 1); j < i; j++) {
                C[i] = min(C[i], C[j] + abs(H[j] - H[i]));
            }
        }
    }
    cout << C[N] << endl;
}


int main()
{
    cin >> N >> K;
    for(int i = 1; i < N+1; i++) {
        cin >> H[i];
    }
    solve();
}

Measured memory_bytes: 1024
n = int(input())
arr = [[0]*10 for i in range(10)]
for i in range(1, n+1):
    i = str(i)
    arr[int(i[0])][int(i[-1])]+=1
s = 0
t = 0
# print(arr)
for i in range(10):
    for j in range(10): t+=arr[i][j]*arr[j][i]
    s+=t
print(t)
    


Measured memory_bytes: 73524
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

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

    int N;
    cin >> N;
    using Point = pair<int, int>;
    vector<pair<int, Point>> txy(N);
    cin >> txy;

    auto caluLen = [](Point p1, Point p2) {
        return abs(p2.first - p1.first) + abs(p2.second - p1.second);
    };

    txy.insert(txy.begin(), make_pair<int, Point>(0, { 0,0 }));
    REP(i, N) {
        int len = caluLen(txy[i + 1].second, txy[i].second);
        int t = txy[i + 1].first - txy[i].first;
        if (len > t || len % 2 != t % 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
#include<iomanip>
#include<cassert>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

	int n;//要素数
	int v;
	int j;

	cin >> n;

	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
		if (i != n - 1){
			cout << a[i] << ' ';
		}
		else{
			cout << a[i] << '\n';
		}
	}

	for (int i = 1; i < n; i++){//1からn-1まで
		v = a[i];
		j = i - 1;

		while (j >= 0 && a[j] > v){
			a[j + 1] = a[j];
			j--;
		}

		a[j + 1] = v;

		rep(k, n){
			if (k != n - 1){
				cout << a[k] << ' ';
			}
			else{
				cout << a[k] << '\n';
			}
		}
	}

	return 0;
}


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

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

int main()
{
	ll n, d;
	cin >> n >> d;
	ll dd = d * d;

	ll cnt = 0;
	for (ll i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		ll xx, yy;

		xx = x * x;
		yy = y * y;
		if (xx + yy <= dd)
		{
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3636
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


    
s=input()
t=input()
n=len(t)
if(s==t[:n-1]):
    print("Yes")
else:
    print("No")

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll d, t, s; cin >> d >> t >> s;

    cout << (s*t>=d?"Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 3632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class BRollerCoaster {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, K;
        in>>N>>K;
        vc<int> H(N);
        for(auto& h : H) in>>h;
        int ans = 0;
        for(auto& h : H) if(h>=K) ++ans;
        out<<ans<<'\n';
    }
};


int main() {
	BRollerCoaster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3652