akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

//@@@@@@@
//@ snippet edge
//@ alias   graph
//@ options  head
struct Edge {
    int src, to;
    i64 cost;
    Edge(int src,  int to, i64 cost) : src(src), to(to), cost(cost) {}
    Edge(int to, i64 cost = 0) : Edge(-1, to, cost) {}
    bool operator< (const Edge &o) const { return cost < o.cost; }
    bool operator> (const Edge &o) const { return cost > o.cost; }
};
using Edges = vector<Edge>;
using WGraph = vector<vector<Edge>>;
using Ugraph = vector<vector<int>>;
//@@@@@@



//@@@@@@@
//@ snippet dijkstra
//@ options head
vector<i64> dijkstra(const WGraph &G, int src)
{
    vector<i64> dist(G.size(), LINF);
    priority_queue<pii, vector<pii>, greater<pii>> pq;

    dist[src] = 0;
    pq.emplace(0, src);

    while(!pq.empty()) {
        const i64 nowCost = pq.top().first;
        const int nowNode = pq.top().second;
        pq.pop();
        if (dist[nowNode] < nowCost) continue;

        for (const auto &e : G[nowNode]) {
            const i64 newCost = nowCost + e.cost;
            if (chmin(dist[e.to], newCost)) {
                pq.emplace(newCost, e.to);
            }
        }
    }

    return dist;
}
//@@@@@@@@



//@@@@@@@@
//@ snippet bellmanFord
//@ options head
vector<i64> bellmanFord(const Edges &es, int V, int src)
{
    vector<i64> dist(V, LINF);
    dist[src] = 0;

    int updateCnt = 0;
    bool updated;
    do {
        updated = false;
        for (const auto &e : es) {
            if (dist[e.src] == LINF) continue;
            updated |= chmin(dist[e.to], dist[e.src] + e.cost);
        }
    } while(updated && ++updateCnt < V);

    if (updateCnt >= V) return {};
    return dist;
}
//@@@@@@@



/*
   Verified On: 2019-07-14
   https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_A
*/
void AOJ_GRL_1_A()
{
    int V, E, src;
    cin >> V >> E >> src;

    WGraph G(V);
    for (int i = 0; i < E; ++i) {
        int s, t, c;
        cin >> s >> t >> c;
        G[s].emplace_back(t, c);
    }

    auto dist = dijkstra(G, src);

    for (i64 d : dist) {
        if (d >= LINF) cout << "INF" << endl;
        else cout << d << endl;
    }
}



/*
   Verified On: 2019-07-14
   https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_B
*/
void AOJ_GRL_1_B()
{
    int V, E, src;
    Edges es;

    cin >> V >> E >> src;
    for (int i = 0; i < E; ++i) {
        int s, t, c;
        cin >> s >> t >> c;
        es.emplace_back(s, t, c);
    }

    auto dist = bellmanFord(es, V, src);

    if (dist.empty()) {
        cout << ("NEGATIVE CYCLE") << endl;
    } else {
        for (auto e : dist) {
            if (e >= LINF) cout << "INF" << endl;
            else cout << e << endl;
        }
    }
}


signed main()
{
    AOJ_GRL_1_A();
    return 0;
}



Measured memory_bytes: 19300
N, L = map(int, input().split())
rng = []
for i in range(N):
    rng.append(L + i)
minimini = 1000000000000
mini = 100000000000
for i in rng:
    if minimini > abs(i):
        mini = i
        minimini = abs(i)

print(sum(rng) - mini)

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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 INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int mi=min({a,b,c,d}),ma=max({a,b,c,d});
  int sum1=mi+ma, sum2=a+b+c+d-sum1;
  cout<<abs(sum1-sum2)<<endl;
}



Measured memory_bytes: 3216
// Problem : I - Coins
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_i
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

Falling down is an accident, Staying down is a choice.

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    io;
    
    ll n;
    cin>>n;
    vector<long double> p(n+1);
    
    FOR(i,1,n+1)
    {
    	cin>>p[i];
    }
    
    vector< vector<long double> > dp(n+2,vector<long double>(n+2));
    
    dp[1][0]=(1-p[1]);
    dp[1][1]=p[1];
    
    FOR(i,2,n+1)
    {
    	dp[i][0]=dp[i-1][0]*(1-p[i]);
    }
    
    FOR(i,2,n+1)
    {
    	FOR(h,1,i+1)
    	{
    		dp[i][h]=dp[i-1][h-1]*p[i];
    		if(h<i)
    		{
    			dp[i][h]+=dp[i-1][h]*(1-p[i]);
    		}
    	}
    }
    
    ll x=n/2+1;
    
    long double ans=0.0;
    FOR(i,x,n+1)
    {
    	ans+=dp[n][i];
    }
    
    cout<<setprecision(10)<<ans;
    
    return 0;
}



Measured memory_bytes: 144228
using System;

public class my
{
	public static void Main()
	{
		long n = my.GetLong();
		
		long cnt = 0;
		for(int i = 0; i < n; i++ ) {
			if(my.IsPrime(my.GetLong())) { 
				cnt++;
			}
		}
		
		Console.WriteLine(cnt);
	}
	
	public static bool IsPrime(long n)
	{
		if(n == 2) return true;
		
		for(int i = 2; i <= Math.Sqrt(n); i++) {
			if(n%i == 0) return false;
		}
		
		return true;
	}
	
	private static long GetLong()
	{
		return long.Parse(Console.ReadLine());
	}
}

Measured memory_bytes: 9208
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<iomanip>
#include<bitset>
#define mod 998244353
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

#define N 600010
ll fac[N],ivf[N],inv[N];
ll C(ll n,ll k){
    if(n<k)return 0;
    if(k<0)return 0;
    return fac[n]*ivf[k]%mod*ivf[n-k]%mod;
}
int main(){
    fac[0]=ivf[0]=inv[1]=1;
    for(ll i=1;i<N;i++){
	if(i>1)inv[i]=(mod-(mod/i*inv[mod%i]%mod))%mod;
	fac[i]=fac[i-1]*i%mod;
	ivf[i]=ivf[i-1]*inv[i]%mod;
    }//cout<<C(5,2)<<endl;
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    ll ans=0;
    for(int i=0;i<=n;i++){
	ll rem=k-i*a;
	if(rem%b==0){
	    mad(ans,C(n,i)*C(n,rem/b));
	}
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 14336
#include<math.h>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define    ll   long long int
#define    py   printf("Yes\n")
#define    pn   printf("No\n")
#define    in   cin>>
using namespace std;

int main()
{
  // int n,a,b;
  // in n>>a>>b;
  // if(b-a<=a)cout<<"OK"<<endl;
  // else cout<<"NG"<<endl;
  ll n,tmp=100,year=0;
  in n;
  bool flag=true;
  while(flag==true)
  {
    tmp = tmp+tmp/100;
    if(n<=tmp)flag=false;
    year++;
  }
  cout<<year<<endl;
}


Measured memory_bytes: 3632
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int count=0;
void isprime(int);

int main(){
  int N,i,array[10000];
  scanf("%d",&N);
  if(N<1||N>10000){
    printf("N ha 1-10000 dene!\n");
    exit(1);
  }
  for (i=0;i<N;i++){
    scanf("%d",&array[i]);
  }
  for (i=0;i<N;i++){
    if(array[i]<2 ||array[i]>100000000){
      printf("2-100000000 de iretene.\n");
      exit(2);
    }
  }
  for (i=0;i<N;i++){
    isprime(array[i]);
  }
  printf("%d\n",count);
  return 0;
}

void isprime(int num){
  int i;
  for(i=2;i<=(int)sqrt(num);i++){
    if (num%i==0){
      return;
    }
  }
  count++;
  return;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
 int a;
 cin>>a;
 if(a<1000)
 cout<<"ABC"<<endl;
 else
 cout<<"ABD"<<endl;
 return 0;
}


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

string s1,s2;

signed main()
{
	cin>>s1>>s2;
	
	if (s2.substr(0,s1.size())==s1&&s1.size()+1==s2.size())  cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#define Pi 3.1415926535898
#define _1 first
#define _2 second
#define LL long long
#define maxn 200010
#define P pair <int ,int>
const int INF = 1e9+7;
using namespace std;
int k,flag=1,x1,pos,x2,y1,x,y,y2,n,cnt,st[maxn];
double ans;
P a[maxn];
int cmp(P A,P B){return A._1<B._1;}
int main()
{
	scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
	if (x1>x2) swap(x1,x2),swap(y1,y2);
	if (y1>y2) flag=-1,y1*=flag,y2*=flag;
	for (int i=1;i<=n;++i)
	  {
	  	scanf("%d%d",&x,&y);y*=flag;
	  	if (!(x<x1||x>x2||y<y1||y>y2)) a[++cnt]={x,y};
	  }
	sort(a+1,a+1+cnt,cmp);
	st[0]=-INF;for (int i=1;i<=n+2;++i) st[i]=INF;
	for (int i=1;i<=cnt;++i)
	{
		y=a[i]._2;
		pos=upper_bound(st,st+n+2,y)-st;
		st[pos]=y;
	}
	k=lower_bound(st,st+n+2,INF)-st-1;
	printf("%.15f\n",(LL)(x2-x1+y2-y1)*(LL)100-20*k+5*k*Pi+(min(x2-x1,y2-y1)+1==k?5*Pi:0));
	return 0;
}

Measured memory_bytes: 2560
N, A, B = map(int, input().split())

if abs(A-B) % 2 == 0:
    print(abs(A-B)//2)
else:
    top = (B-A-1)//2 + A-1
    low = (B-A-1)//2+N-B
    print(min(top, low)+1)


Measured memory_bytes: 38384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  class Pair<T extends Comparable<T>, U extends Comparable<U>> implements
      Comparable<Pair<T, U>> {
    T f;
    U s;

    Pair(T f, U s) {
      this.f = f;
      this.s = s;
    }

    public int compareTo(Pair<T, U> o) {
      return 0;
    }

    public String toString() {
      return "{" + f + ", " + s + "}";
    }
  }

  int gcd(int m, int n) {
    for ( ; m != 0; ) {
      int t = n % m;
      n = m;
      m = t;
    }
    return n;
  }

  int lcm(int n, int m) {
    return ( n / gcd( n, m ) ) * m;
  }

  int p;
  int q;
  int n;
  int a;

  int equalF(int p1, int q1, int p2, int q2) {
    int v1 = p1 * q2;
    int v2 = p2 * q1;

    return new Integer( v1 ).compareTo( new Integer( v2 ) );
  }

  Pair<Integer, Integer> add(int p1, int q1, int p2, int q2) {
    int pro = q1 * q2;
    int v1 = p1 * q2;
    int v2 = p2 * q1;

    int gcd = gcd( v1 + v2, pro );

    return new Pair<Integer, Integer>( ( v1 + v2 ) / gcd, pro / gcd );
  }

  int dfs(int depth, int pro, int p_, int q_, int lastq) {
    if ( equalF( p, q, p_, q_ ) == 0 ) {
      // debug("cnt up!");
      return 1;
    }
    if ( depth == n ) {
      return 0;
    }
    if ( equalF( p, q, p_, q_ ) < 0 ) {
      return 0;
    }
    {
      Pair<Integer, Integer> np = add( p_, q_, n - depth, lastq );
      if ( equalF( p, q, np.f, np.s ) > 0 ) {
        return 0;
      }
    }
    int cnt = 0;
    for ( int i = lastq; i <= a / pro; ++i ) {
      Pair<Integer, Integer> np = add( p_, q_, 1, i );
      // debug( depth, i, p );
      cnt += dfs( depth + 1, pro * i, np.f, np.s, i );
    }
    return cnt;
  }

  void run() {
    for ( ;; ) {
      p = ni();
      q = ni();
      a = ni();
      n = ni();

      if ( ( p | q | n | a ) == 0 ) {
        break;
      }

      System.out.println( dfs( 0, 1, 0, 1, 1 ) );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 158000
#include <stdio.h>

int main()
{
	int n,q,s[100000],t[100000],count;
	
	scanf("%d",&n);

	for(int i=0; i<n;i++)
	{
		scanf("%d",&s[i]);
	}
	
	scanf("%d",&q);
	
	count = 0;
	
	for(int i = 0;i<q;i++)
	{
		scanf("%d",&t[i]);
		
		for(int j=0;j<n;j++)
		{
			if(s[j] == t[i])
			{
				count++;
			    break;
			}
		}
	}
	
	printf("%d\n",count);
	
	return 0;
}


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

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    ll total = 0;
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
        total += a[i];
    }
    ll x = a[0];
    ll y = total - a[0];
    ll mini = abs(x - y);
    for (int i = 1; i < N - 1; i++) {
        x += a[i];
        y -= a[i];
        mini = min(mini, abs(x - y));
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

int main() {
    std::string s, t;
    std::cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

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

    int n;
    cin >> n;

    ll p = 0, q = LLONG_MAX;
    ll dist = LLONG_MAX;
    ll a[n];

    rep(i, n){
        cin >> a[i];
        p = max(p, a[i]);
    }

    sort(a, a+n);

    rep(i, n){
        if(abs((double)p/2 - (double)a[i]) < dist){
            q = a[i];
            dist = abs(p/2 - a[i]);
        }

    }

    cout << p << sp << q << endl;




    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(){
  int n,p1,q1,i,j,a1,a2,S,R[10000]={0};  
  for(i=1;i<=10000;i+=2){
    for(j=3;j<sqrt(i);j+=2){
      if(i%j==0)break;
    }
    if(i%j==0)R[i]=0;
    else R[i]=1;
  }
  R[3]=1;

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

    for(i=n;i>=5;i--){
      if(R[i]==1 && R[i-2]==1){
	printf("%d %d\n",i-2,i);
	break;
      }      
    }

  }
  return 0;
}

    

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int D;
    cin >> D;
    vector<LL> c(26);
    vector<vector<LL>> s(D + 1, vector<LL>(26, 0));
    REP(i, 26) {
        cin >> c[i];
    }
    FOR(i, 1, D + 1) {
        REP(j, 26) {
            cin >> s[i][j];
        }
    }
    vector<int> t(D + 1, 0);
    FOR(i, 1, D + 1) {
        cin >> t[i];
        t[i]--;
    }
    vector<int> last(26, 0);

    LL score = 0;
    FOR(i, 1, D + 1) {
        int satisfaction = s[i][t[i]];
        last[t[i]] = i;
        REP(k, 26) {
            satisfaction -= (i - last[k])*c[k];
        }
        score += satisfaction;
        cout << score << endl;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> c(n,0);
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    c[a-1]++,c[b-1]++;
  }
  for(int i=0;i<n;i++){
    if(c[i]%2){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 640
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A: d[a] += 1
    cand = []
    for key in d:
        for _ in range(d[key] // 2): cand.append(key)
    cand.sort(reverse=True)
    if len(cand) < 2:
        print(0)
        return
    print(cand[0] * cand[1])
    
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 93556
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int h, w, sum[500][500];
  char mas[500][500];
 
  while(cin >> h >> w, h){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> mas[i][j];
      }
    }
    for(int i = 0; i < h; i++){
      int cnt = 0;
      for(int j = w - 1; j >= 0; j--){
        if(mas[i][j] == '.'){
          sum[i][j] = cnt +++ 1;
        }else{
          sum[i][j] = cnt = 0;
        }
      }
    }

    
    int ret = 0;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){ //とりあえず起点を決める
        int minw = sum[i][j];
        int java = 1;
        for(int k = i; k < h; k++,java++){
          minw = min( minw, sum[k][j]);
          ret = max( ret, minw * java);
        }
      }
    }
    cout << ret << endl;
    
  }
}

Measured memory_bytes: 2376
K = int(input())
ans = [0]
def f(n):
    tmp = str(n)
    if int(n) > 3234566667:
        return
    else:
        ans.append(int(n))
    f(str(tmp)+tmp[-1])
    if int(tmp[-1])-1 >= 0:
        f(str(tmp)+str(int(tmp[-1])-1))
    if int(tmp[-1])+1 <= 9:
        f(str(tmp)+str(int(tmp[-1])+1))
for i in range(1,10):
    f(i)
ans.sort()
print(ans[K])

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

int main(){
  string s,ans;
  cin >> s;
  cout << ans << endl;
  int l = s.size();
  vector<int> c(l,1);
  for(int i = 0; i < l; i++){
    if(s.at(i)=='B'){
        for(int j = i-1; j >=0; j--){
          if(c.at(j)==1){
            c.at(j) = 0;
            break;
          }
        }
        c.at(i) = 0;
    }
  }
  for(int i = 0; i < l; i++){
    if(c.at(i)==1)cout<<s.at(i);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
using ll = long long;
typedef long long lint;

int main() {
  int H,N;
  cin >> H >> N;
  int sum;
  rep(i,N){
    int x;
    cin >> x;
    sum += x;
  }
  if(sum >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#define N 100
using namespace std;
main () {
	int n;
	double x[N], y[N];
	cin >> n;
	for (int i=0; i<n; i++) cin >> x[i];
	for (int i=0; i<n; i++) cin >> y[i];

	double d[4] = {};
	for (int k=0; k<3; k++) {
		for (int i=0; i<n; i++)
			d[k] += pow(abs(x[i]-y[i]), k+1);
		d[k] = pow(d[k], 1.0/(k+1));
	}
	for (int i=0; i<n; i++)
		d[3] = max(d[3], abs(x[i]-y[i]));
	
	for (int k=0; k<4; k++) printf("%.6f\n", d[k]);
}

Measured memory_bytes: 3416
n = int(input())
x_li = list(map(int, input().split()))
x_li.sort()
hp_min = -1

for i in range(x_li[0], x_li[n-1] + 1):
    hp = sum((x - i)**2 for x in x_li)
    if hp < hp_min or hp_min == -1:
        hp_min = hp

print(hp_min)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
n = int(input())
txy = [list(map(int, input().split())) for _ in range(n)]
t, x, y = 0, 0, 0
flag = True
for nt, nx, ny in txy:
    dt = nt - t
    dx = nx - x
    dy = ny - y
    if (dt < dx + dy) or ((dx + dy) % 2 != dt % 2):
        flag = False
        break
    t = nt
    x = nx
    y = ny
if flag:
    print('Yes')
else:
    print('No')

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

#define MAX 100

long matA[MAX][MAX] = {{}};
long matB[MAX][MAX] = {{}};
long ans[MAX][MAX] = {{}};

void multiply(int n, int m, int l)
{
    int i,j,k;

    for(i=0;i<l;i++) {
        for(j=0;j<n;j++) {
            for(k=0;k<m;k++) {
                ans[j][i] += matA[j][k] * matB[k][i];
            }
        }
    }

    return;
}

void show(int h, int w)
{
    int i,j;

    for(i=0;i<h;i++) {
        for(j=0;j<w;j++) {
            if(j!=0) putchar(' ');
            printf("%ld", ans[i][j]);
        }
        putchar('\n');
    }

    return;
}

int main(void)
{
    int i,j;
    int n, m, l;
    char str[6*MAX+1], *tok;
    char temp[] = " \n";

    scanf("%d %d %d", &n, &m, &l);

    scanf("%*c");
    for(i=0;i<n;i++) {
        fgets(str, 6*MAX+1, stdin);
        tok = strtok(str, temp);
        matA[i][0] = atol(tok);

        for(j=1;j<m;j++) {
            tok = strtok(NULL, temp);
            matA[i][j] = atol(tok);
        }
    }

    for(i=0;i<m;i++) {
        fgets(str, 6*MAX+1, stdin);
        tok = strtok(str, temp);
        matB[i][0] = atol(tok);

        for(j=1;j<l;j++) {
            tok = strtok(NULL, temp);
            matB[i][j] = atol(tok);
        }
    }

    multiply(n,m,l);
    show(n,l);

    return 0;
}

Measured memory_bytes: 840
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>

int main()
{
	map<char,int> m;
	rep(i,4){
		char tmp;
		cin >> tmp;
		m[tmp]++;
	}
	if(m.size() != 2){
		cout << "No" << endl;
	}
	else{
		for (auto itr = m.begin(); itr != m.end();itr++){
			if(itr->second != 2){
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}	
	return 0;
}

Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    
    for i in range(H):
        for j in range(W):
            if (i+j)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print() 


Measured memory_bytes: 7004
import sys
from math import atan, pi

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    a, b, x = map(int, readline().split())
    if x > a * a * b / 2:
        angle = atan(2 * (a * a * b - x) / a ** 3)
    else:
        angle = atan(a * b * b / (2 * x))

    print(angle / pi * 180)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
def main():
    n = int(input())
    v = list(map(int, input().split()))

    dic1 = {0:0}
    for i in range(0, n, 2):
        if v[i] in dic1:
            dic1[v[i]] += 1
        else:
            dic1[v[i]] = 1
    
    dic2 = {0:0}
    for i in range(1, n, 2):
        if v[i] in dic2:
            dic2[v[i]] += 1
        else:
            dic2[v[i]] = 1
    
    dic1 = sorted(list(dic1.items()), key=lambda x: -x[1])
    dic2 = sorted(list(dic2.items()), key=lambda x: -x[1])
    # print(dic1)
    # print(dic2)
    if dic1[0][0] != dic2[0][0]:
        print(n-dic1[0][1]-dic2[0][1])
    else:
        print(min(n-dic1[0][1]-dic2[1][1], n-dic1[1][1]-dic2[0][1]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 17912
s=input()
K=int(input())
ans=''
for c in s:
    if c!='a' and ord('z')+1-ord(c)<=K:
        ans+='a'
        K-=ord('z')+1-ord(c)
    else:
        ans+=c
if K>0:
    ans=ans[:-1]+chr(ord(ans[-1])+K%26)

print(ans)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200005],b[200005],l[10005];
char s[200005];
int main()
{
    int n,p;
    scanf("%d%d%s",&n,&p,s+1);
    for(int i=1;i<=n;i++)a[i]=s[i]-'0';
    if(p==2)
    {
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]%2==0)ans+=i;
        }
        printf("%lld\n",ans);
    }
    else if(p==5)
    {
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]==0||a[i]==5)ans+=i;
        }
        printf("%lld\n",ans);
    }
    else
    {
        ll num=1;
        for(int i=n;i>=1;i--)
        {
            b[i]=(b[i+1]+a[i]*num%p)%p;
            l[b[i]]++;
            num=num*10%p;
        }
        ll ans=0;
        l[0]++;
        for(int i=0;i<p;i++)
        {
            if(l[i])
            {
                ans+=l[i]*(l[i]-1)/2;
            }
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 3584
n, y = gets.chomp.split(" ").map(&:to_i)
# 難しい
a = y / 10000
b = y / 5000
c = y / 1000
if a < n && b < n
    (0..a).each do |i|
        (0..b).each do |e|
            k = n - ( i + e )
            if k >= 0 && i * 10 + e * 5 + k == c then
                puts "#{i} #{e} #{k}"
                exit
            end
        end
    end
end
if a > n && b > n
    (0..n).each do |i|
        (0..n).each do |e|
            k = n - ( i + e )
            if k >= 0 && i * 10 + e * 5 + k == c then
                puts "#{i} #{e} #{k}"
                exit
            end
        end
    end
end

if a < n && b > n
    (0..a).each do |i|
        (0..n).each do |e|
            k = n - ( i + e )
            if k >= 0 && i * 10 + e * 5 + k == c then
                puts "#{i} #{e} #{k}"
                exit
            end
        end
    end
end

if a > n && b < n
    (0..n).each do |i|
        (0..b).each do |e|
            k = n - ( i + e )
            if k >= 0 && i * 10 + e * 5 + k == c then
                puts "#{i} #{e} #{k}"
                exit
            end
        end
    end
end

if a == n && b > n
    (0..a).each do |i|
        (0..n).each do |e|
            k = n - ( i + e )
            if k >= 0 && i * 10 + e * 5 + k == c then
                puts "#{i} #{e} #{k}"
                exit
            end
        end
    end
end

if a == n && b < n
    (0..n).each do |i|
        (0..b).each do |e|
            k = n - ( i + e )
            if k >= 0 && i * 10 + e * 5 + k == c then
                puts "#{i} #{e} #{k}"
                exit
            end
        end
    end
end

if a > n && b == n
    (0..n).each do |i|
        (0..b).each do |e|
            k = n - ( i + e )
            if k >= 0 && i * 10 + e * 5 + k == c then
                puts "#{i} #{e} #{k}"
                exit
            end
        end
    end
end

if a < n && b == n
    (0..a).each do |i|
        (0..n).each do |e|
            k = n - ( i + e )
            if k >= 0 && i * 10 + e * 5 + k == c then
                puts "#{i} #{e} #{k}"
                exit
            end
        end
    end
end
puts "-1 -1 -1"


Measured memory_bytes: 1788
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(){
  int n, ans, i;
  cin >> n;
  ans = 0;
  int a[n];

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

  for (i = 0; i < n; i++){
    for (int j = i + 1; j < n; j++){
      ans += a[i] * a[j];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//
//  line_plus.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/01.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <map>
#include <queue>

int main(int argc, const char* argv[]) {
    int n, x, y;
    std::cin >> n >> x >> y;
    std::map<int, int> vertex_distance;
    std::queue<int> vertexes;
    int visitedVertex[n];
    int results[n-1];
    for (int i=0; i<n-1; i++) {
        results[i] = 0;
    }
    
    for (int i=0; i<n-1; i++) {
        for (int j=i+1; j<n; j++) {
            int distance = std::min(j-i, abs(x-1-i) + abs(y-1-j) + 1);
//            std::cout << "distance of " << i << j << ": " << distance << std::endl;
            results[distance-1]++;
        }
    }
    
    for (int i=0; i<n-1; i++) {
        std::cout << results[i] << std::endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
	int m;
	cin >> m;
	for(int i = 0; i < m; i++){
		ll money, ans = 0;
		int year, n;
		cin >> money >> year >> n;
		for(int j = 0; j < n; j++){
			int method, fee;
			ll tmpmoney, profit = 0;
			double per;
			tmpmoney = money;
			cin >> method >> per >> fee;
			if(method){
				for(int k = 0; k < year; k++){
					tmpmoney = (ll)(tmpmoney*(1+per))-fee;
				}
			} else{
				for(int k = 0; k < year; k++){
					profit += (ll)(tmpmoney*per);
					tmpmoney -= fee;
				}
			}
			ans = max(ans,tmpmoney+profit);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i;
    cin>>n>>k;
    int digit[k];
    for(i=0;i<k;i++){
        cin>>digit[i];
    }
    while(1){
        int m,ck=0;
        m=n;
        while(m){
            int r;
            r = m%10;
            ck=0;
            for(i=0;i<k;i++){
                if(r==digit[i]){
                    ck=1;
                    break;
                }
            }
            if(ck==1) break;
            m/=10;
        }
        if(ck==0){
            cout<<n<<endl;
            break;
        }
        else
            n++;

    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b, c, d, ans=0;

	cin>>a>>b>>c>>d;

	if(a<b){
		ans+=a;
	}else{
		ans+=b;
	}
	if(c<d){
		ans+=c;
	} else{
		ans+=d;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
// E - Second Sum
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<pair<int, int> > p;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		p.push_back(make_pair(a[i], i));
	}
	sort(p.begin(), p.end(), greater<pair<int, int> >());
	multiset<int> s;
	s.insert(-1);
	s.insert(-1);
	s.insert(n);
	s.insert(n);
	long long ans = 0;
	for (int i = 0; i < p.size(); i++) {
		int x = p[i].first, j = p[i].second, l1, l2, r1, r2;;
		multiset<int>::iterator it = s.lower_bound(j);
		r1 = *it++;
		r2 = *it--;
		l1 = *--it;
		l2 = *--it;
		ans += (long long) x * (r1 - j) * (l1 - l2);
		ans += (long long) x * (j - l1) * (r2 - r1);
		s.insert(j);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6132
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  //input
  int n; cin >> n;
  vector<int> s(n);
  for(int i = 0; i < n; i++)  cin >> s[i];
  
  //compute
  int ans;
  int mint;
  sort(s.begin(), s.end());
  mint = 0;
  ans = 0;

  for(int i = 0; i < n; i++) {
     ans += s[i];
  }

  for(int i = 0; i < n; i++) {
      if(s[i] % 10 != 0){
          mint = s[i];
          break;
      }
  }

  if(ans % 10 == 0){
    ans = ans - mint;
  }

  //output
  if(ans % 10 != 0){
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }

}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;

int main()
{
    fast;
    

	string s;
	cin>>s;
	ll n=s.size();
	
	string dream,erase;
	dream="dream";
	erase="erase";
	ll ok=0;
	for(ll i=0;i<n;)	
	{
		if(s.substr(i,5)==dream||s.substr(i,5)==erase)
		{
			if(s.substr(i,6)=="eraser")
			{
				i+=6;
			}
			else
			i+=5,ok=1;
			
			
		}
		else
		{
			if(s.substr(i,2)=="er" &&ok)
			{
				i+=2;
				ok=0;
			}
			else
			{
				cout<<"NO";
				return 0;
			}
		}
	}
	
	
	cout<<"YES";
	
	
}



		
	
	
	
	


Measured memory_bytes: 3760
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
long long inf=1000000000000000007;
class Edge{
    public:
    int s;
    int t;
    long long c;
};
class Node{
    public:
    int no;
    long long dist;
    bool comp;
    int edge_num;
    vector<Edge> edge;
    void in_edge(Edge const& in){
        edge.push_back(in);
    }
    void setup(int const& i){
        no=i;
        dist=inf;
        comp=true;
        edge_num=edge.size();
    }
};
bool operator >(const Node& a,const Node &r){
    return a.dist > r.dist;
    }
void dijkstra(int const& s,int const& t,int const& n,vector<Node>& node){
    for(int i=0;i<=n;i++)node[i].setup(i);
    priority_queue<Node,vector<Node>,greater<Node>> que;
    que.push(node[s]);
    node[s].dist=0;
    while(!que.empty()){
        Node buf=que.top();
        que.pop();
        int k=buf.no;
        if(buf.comp){
            node[k].comp=false;
            for(int i=0;i<buf.edge_num;i++){
                int buf_t=buf.edge[i].t;
                if(node[buf_t].dist>node[k].dist+buf.edge[i].c){
                    node[buf_t].dist=node[k].dist+buf.edge[i].c;
                    que.push(node[buf_t]);
                }
            }
        }
    }
}
int main(){
    int n;cin>>n;
    vector<Node> node(n+1);
    for(int i=1;i<n;i++){
        int a,b,c;cin>>a>>b>>c;
        Edge buf;
        buf.s=a;
        buf.t=b;
        buf.c=c;
        node[a].in_edge(buf);
        buf.s=b;
        buf.t=a;
        node[b].in_edge(buf);
    }
    int q,k;cin>>q>>k;
    int kk=(k+1)%n;
    dijkstra(k,kk,n,node);
    vector<long long> sum(q);
    for(int i=0;i<q;i++){
        int x,y;cin>>x>>y;
        sum[i]=node[x].dist+node[y].dist;
    }
    for(int i=0;i<q;i++)cout<<sum[i]<<endl;
    return 0;
}

Measured memory_bytes: 22356
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for _ in range(K):
    B = [0]*(N+1)
    for i in range(N):
        l = max(0, i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        B[r+1] -= 1
    for i in range(N):
        B[i+1] += B[i]
    A = B[:N]
    if all([x == N for x in A]):
        break
print(*A)

Measured memory_bytes: 173188
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
struct SegmentTree {
private:
    int n;
    vector<ll> node;

public:
    SegmentTree(vector<ll> v){
        ll sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);

        rep(i,0,sz) node[i+n-1] = v[i];
        rrep(i,n-2,0) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(ll x, ll val){
        x += (n-1);
        node[x] = val;
        while(x > 0){
            x = (x-1)/2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    ll getMin(ll a, ll b, ll k = 0, ll l = 0, ll r = -1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];
        ll vl = getMin(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getMin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

struct SegmentTree2 {
private:
    int n;
    vector<ll> node;

public:
    SegmentTree2(vector<ll> v){
        ll sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, -INF);

        rep(i,0,sz) node[i+n-1] = v[i];
        rrep(i,n-2,0) node[i] = max(node[2*i+1], node[2*i+2]);
    }

    void update(ll x, ll val){
        x += (n-1);
        node[x] = val;
        while(x > 0){
            x = (x-1)/2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

    ll getMax(ll a, ll b, ll k = 0, ll l = 0, ll r = -1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return -INF;
        if(a <= l && r <= b) return node[k];
        ll vl = getMax(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getMax(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll P[200010];
    rep(i,0,N) cin >> P[i];
    SegmentTree sg_min(vector<ll>(200010));
    SegmentTree2 sg_max(vector<ll>(200010));
    rep(i,0,N){
        sg_min.update(i, P[i]);
        sg_max.update(i, P[i]);
    }
    ll ans = N-K+1;
    ll kk = K-1;
    vector<ll> v;
    ll cnt = 0;
    rep(i,0,N-1){
        if(P[i] < P[i+1]){
            cnt++;
        }else{
            v.push_back(cnt);
            cnt = 0;
        }
    }
    v.push_back(cnt);
    ll val = 0;
    for(auto &e: v){
        if(e >= K-1){
            val++;
        }
    }

    rep(i,0,N-kk+1){
        if(i == 0 || i == N-kk) continue;
        ll max_val = sg_max.getMax(i, i+kk);
        ll min_val = sg_min.getMin(i, i+kk);
        if(P[i-1] < min_val && P[i+kk] > max_val) ans--;
    }
    if (val > 0) ans -= (val-1);
    print(ans);
    

    
}

Measured memory_bytes: 11876
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
int n, a[maxn], cnt[maxn];
pii oddMax, oddSub, evenMax, evenSub;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
		scanf("%d", &a[i]); 
	for(int i = 1; i <= n; i += 2)
		++cnt[a[i]];
	for(int i = 1; i < maxn; ++i)
	{
		pii cur = mp(cnt[i], i);
		if(cur > oddMax)
		{
			oddSub = oddMax;
			oddMax = cur;
		}
		else if(cur > oddSub)
			oddSub = cur;
	}
	memset(cnt, 0, sizeof cnt);
	for(int i = 2; i <= n; i += 2)
		++cnt[a[i]];
	for(int i = 1; i < maxn; ++i)
	{
		pii cur = mp(cnt[i], i);
		if(cur > evenMax)
		{
			evenSub = evenMax;
			evenMax = cur;
		}
		else if(cur > evenSub)
			evenSub = cur;
	}
	if(oddMax.second != evenMax.second) printf("%d\n", n - oddMax.first - evenMax.first);
	else printf("%d\n", n - max(oddMax.first + evenSub.first, oddSub.first + evenMax.first));
	return 0;
}
			
		
	

Measured memory_bytes: 4528
import java.io.IOException;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			String a = sc.next();
			a=a.toLowerCase();
			String b = sc.next();
			b=b.toLowerCase();
			int c=0;
			while(a==a){
				if(a.equals(b)){
					c=c+1;
				}
				b=sc.next();
				if(b.equals("END_OF_TEXT")){
					break;
				}
				b=b.toLowerCase();
			}
			System.out.println(c);
	}

}

Measured memory_bytes: 26184
// Practice 40 hours a day to become Ling Ling
// Code by Nguyen Huu Lam
#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;

typedef long long LL;

#define y0 Sword_Art_Online
#define y1 Your_lie_in_April
#define yn Darling_in_the_Franxx
#define tm Plastic_Memories
#define lr Charlotte
#define norm Weathering_with_you
#define left Violet_Evergarden
#define have Date_a_live
#define ends Your_name
#define prev Five_centimeters_per_second
#define hash Silent_voice
#define endl "\n"

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

LL Rand(LL l, LL h){
    return uniform_int_distribution<LL>(l, h)(rng);
}

template <typename T> void read(T &t){
    t = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    do { (t *= 10) += ch - '0'; ch = getchar(); } while (isdigit(ch)); t *= f;
}

const LL MaxN = 1 + 2e5;

LL nLamp, nStep, lamps[MaxN], temp[MaxN];

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> nLamp >> nStep;
    for(int iLamp = 0 ; iLamp < nLamp ; ++iLamp) cin >> lamps[iLamp];
    while(nStep--){
        bool isChanged = 0;
        memset(temp, 0, sizeof temp);
        for(int iLamp = 0 ; iLamp < nLamp ; ++iLamp){
            LL lo = max(0LL, iLamp - lamps[iLamp]);
            LL hi = min(nLamp - 1, iLamp + lamps[iLamp]);
            temp[lo]++;
            temp[hi + 1]--;
        }
        for(int iLamp = 0 ; iLamp < nLamp ; ++iLamp){
            if(iLamp != 0) temp[iLamp] += temp[iLamp - 1];
            if(!isChanged && temp[iLamp] != lamps[iLamp]) isChanged = 1;
        }
        if(!isChanged) break;
        memcpy(lamps, temp, sizeof temp);
    }
    for(int iLamp = 0 ; iLamp < nLamp ; ++iLamp) cout << lamps[iLamp] << " ";

    return 0;
}

Measured memory_bytes: 6760
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, m, P;
int dp[MAXN][MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int main() {
	read(n), read(P), m = (n - 1) / 2;
	dp[0][0] = 1;
	for (int i = 1; i <= m; i++)
	for (int j = 0; j <= n; j++) {
		int tmp = 0;
		for (int k = 0; k * i <= j; k++)
			update(tmp, 1ll * dp[i - 1][j - k * i] * (k + 1) % P);
		dp[i][j] = tmp;
	}
	int ans = 0;
	if (n & 1) {
		for (int i = 1; i <= n; i++)
		for (int j = 0; j * (m + 1) <= n - i; j++)
			update(ans, dp[m][n - i - j * (m + 1)]);
	} else {
		for (int i = 1; i <= n; i++)
		for (int j = 0; j * (m + 1) <= n - i; j++)
			update(ans, 1ll * dp[m][n - i - j * (m + 1)] * (j + 1) % P);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 49408
N = int(input())
for _ in range(N):
    train = input()
    result = set([])
    for i in range(1,len(train)):
        ft = train[:i]
        bt = train[i:]
        if ft + bt not in result: result.add(ft+bt)
        if ft[::-1] + bt not in result : result.add(ft[::-1]+bt)
        if ft + bt[::-1] not in result : result.add(ft+bt[::-1])
        if ft[::-1] + bt[::-1] not in result:result.add(ft[::-1] + bt[::-1])
        if bt + ft not in result : result.add(bt+ft)
        if bt[::-1] + ft not in result : result.add(bt[::-1]+ft)
        if bt + ft[::-1] not in result : result.add(bt+ft[::-1])
        if bt[::-1] + ft[::-1] not in result:result.add(bt[::-1] + ft[::-1])
    print(len(result))



Measured memory_bytes: 5640
#include <cstdio>

int f(int y, int z) {
	return (y - z) * (y - z);
}

int main() {
	int n, d;
	int x[10][10];

	scanf("%d %d", &n, &d);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < d; j++) {
			scanf("%d", &x[i][j]);
		}
	}

	int result = 0;
	for(int i = 0; i < n - 1; i++) {
		for(int j = i + 1; j < n; j++) {
			int sum = 0;
			for(int k = 0; k < d; k++) {
				sum += f(x[i][k], x[j][k]);
			}

			for(int k = 0; k * k < 40 * 40 * 10 + 1; k++) {
				if(k * k == sum) {
					result++;
					break;
				}
			}
		}
	}

	printf("%d\n", result);

	return 0;
}

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

template <typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0) : n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for (i++; i <= n; i += i & -i) d[i] += x;
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) x += d[i];  // 最下位bitの加算
    return x;
  }
  T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

int main() {
  ll n, d, a, ans = 0;
  cin >> n >> d >> a;
  vector<pair<ll, ll>> p(n);

  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());

  BIT<ll> bit(n + 1);

  rep(i, n) {
    ll x = p[i].first;
    ll h = p[i].second;
    h -= bit.sum(i);
    if (h <= 0) continue;
    ll num = (h + a - 1) / a;
    ans += num;
    ll damage = num * a;
    bit.add(i, damage);
    ll rx = min(x + d * 2, (ll)1e10);
    bit.add(
        upper_bound(p.begin(), p.end(), pair<ll, ll>(rx + 1, -1)) - p.begin(),
        -damage);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7928