akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define f first

#define pb push_back
#define M (L+R)/2
#define N 500009
#define inf 99999999999
#define ll long long
#define mod 1000000007
#define sz size();
using namespace std;
ll n,m;
string s,s1,s2;

bool p(string a){
	int nn=a.size();
	nn--;
	for(int i=0;i<=nn/2;i++){
		if(a[i]!=a[nn-i])return false;
	}
	return true;
}
int main(){

	ios::sync_with_stdio(0);
	
	cin>>s;
	n=s.size();
	for(int i=0;i<s.size();i++){
		if(i<n/2)s1+=s[i];
		if(i>n/2)s2+=s[i];
	}

	if(p(s) && p(s1) && p(s2))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a,b,h;
int main(){
    cin >> a >> b >> h;
    pr((a+b)*h/2);
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    long N, K;
    long[] A, B;
    void Solve() {
        //input
        N = io.Long;
        K = io.Long;
        A = new long[N];
        B = new long[N];
        for (var i = 0; i < N;++i){
            A[i] = io.Long;
            B[i] = io.Long;
        }
        //cal
        var ans = 0L;
        //Kのbitwise_orを変更しない範囲での最大値を求める
        //i番目について調べる
        for (var i = 0; i < N;++i){
            var f = true;
            for (int j = 0; j <= 30;++j){
                //Kの該当するビットが1じゃないのにA[i]の該当するビットが1
                //->bitwise_orを変更してしまうので加えない
                if(((K>>j)&1)==0&&((A[i]>>j)&1)==1){
                    f = false;break;
                }
            }
            if (f)ans += B[i];
        }
        //最終状態をKより小さくして総和が大きくなるかもしれない
        //最終的な形から考える
        //K=5=(101)のとき,(100),(10?),(0??)が他の最終状態として考えられる(?はどっちでもいい)
        for (var i = 0; i <= 30; ++i) {
            //iビットを0に反転して，以降を1にしたK
            if (((K >> i) & 1) == 1) {
                //iビットを0にして，iビット以降を1にしたK
                var converted_K = (K & ~(1 << i)) | ((1 << i) - 1);
                var cur = 0L;
                for (int j = 0; j < N; ++j) {
                    var f = true;
                    for (int k = 0; k < 30; ++k) {
                        if (((converted_K >> k) & 1) == 0 && ((A[j] >> k) & 1) == 1) {
                            f = false;break;
                        }
                    }
                    if (f)cur += B[j];
                }
                //更新
                ans = Math.Max(ans, cur);
            }
        }
        //ret
        Console.WriteLine(ans);
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}

Measured memory_bytes: 18656
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

vector<vi> g;

int n, m;

int dfs(int u, int p) {
    int c = 0;
    int ans = 0;
    for (int v : g[u]) if (v != p) {
            int ret = dfs(v, u);
            ans += ret;
            if (!ret) c ++;
        }
    if (c) ans += c - 1;
    return ans;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n);
    REP(i, n-1) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int ans = n;
    int c = 0;
    REP(i, n) {
        if (g[i].size() <= 1) {
            ans = min(ans, dfs(i, -1) + 1);
            c ++;
        }
        if (c > 100) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12032
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;
 
class dice {
public:
    int face[7];
    int get;

    dice() {
        for (int i = 1; i <= 6; i++)
            face[i] = 0;
    }
 
    void input(int x[]) {
        for (int i = 1; i <= 6; i++)
            face[i] = x[i];
    }

    void print() {
        for (int i = 1; i <= 6; i++){
            cout << face[i];
        }
    }

    void round(char x) {
            switch (x) {
            case 'E':
                get = face[1];
                face[1] = face[4];
                face[4] = face[6];
                face[6] = face[3];
                face[3] = get;
                break;
            case 'W':
                get = face[1];
                face[1] = face[3];
                face[3] = face[6];
                face[6] = face[4];
                face[4] = get;
                break;
            case 'N':
                get = face[1];
                face[1] = face[2];
                face[2] = face[6];
                face[6] = face[5];
                face[5] = get;
                break;
            case 'S':
                get = face[1];
                face[1] = face[5];
                face[5] = face[6];
                face[6] = face[2];
                face[2] = get;
                break;
            }
    }

    int match(dice x) {
        int ident = 0, i;
        string operate="EEENEEENEEESEEESEEENEEEN";

        if(face[1]==x.face[1] && face[2]==x.face[2] && face[3]==x.face[3] && face[4]==x.face[4] && face[5]==x.face[5] && face[6]==x.face[6]  ){
            ident=1;
        }

        for(i=0;i<operate.size();i++){
            x.round(operate[i]);
            if(face[1]==x.face[1] && face[2]==x.face[2] && face[3]==x.face[3] && face[4]==x.face[4] && face[5]==x.face[5] && face[6]==x.face[6]  ){
                ident=1;
                break;
            }
        } 
        return ident;
    }
};
 
int main() {
    int facef[7], i, j, k, num, ident=0;
    dice d[100];
 
    cin >> num;

    for (i = 1; i <= 6; i++) {
        cin >> facef[i];
    }
 
    d[0].input(facef);
 
    for(j=1;j<num;j++){
        for (i = 1; i <= 6; i++) {
            cin >> facef[i];
        }
        d[j].input(facef);

        for (k=0;k<j;k++){
            ident=d[j].match(d[k]);
            if(ident)break;
        }
        if(ident)break;
    }
 
    if(ident==1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 3220
#include <stdio.h>
int main(void){
  long long n,a[100005],b[100005],sum=0,min,x ;
  scanf("%lld",&n);
  for(int i=1;i<=n+1;i++){
    scanf("%lld",&a[i]);
  }
  for(int i=1;i<=n;i++){
    scanf("%lld",&b[i]);
  }
  for(int i=1;i<=n;i++){
    if(a[i]>=b[i]){
      min=b[i];
    }else if(a[i]<b[i]){
      x=b[i]-a[i];
      if(x<=a[i+1]){
      min=a[i]+x;
      a[i+1]=a[i+1]-x;
      }else{
        min=a[i]+a[i+1];
        a[i+1]=0;
      }
    }
    sum=sum+min;
  }
  printf("%lld\n",sum);



  return 0;
}


Measured memory_bytes: 3268
N, C, K = map(int, input().split())
Tn = [int(input()) for _ in range(N)]
sTn = sorted(Tn)

bus_count = 1
bus_rider_count = 0
min_T = sTn[0]
for T in sTn:
    if bus_rider_count < C and min_T + K >= T:
        bus_rider_count += 1
    else:
        bus_count += 1
        bus_rider_count = 1
        min_T = T

print(bus_count)


Measured memory_bytes: 8256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>      // std::setprecision
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

int main() {
  long long N, r = 0;

  cin >> N;
  

  cout << N * (N - 1LL) / 2LL << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int workNum[] = new int[2];
		workNum[0] = sc.nextInt();
		workNum[1] = sc.nextInt();

		int diff = workNum[0] - workNum[1];
		diff = (diff < 0) ? diff * -1 : diff;
		if(diff % 2 == 1) {
			System.out.println("IMPOSSIBLE");
		}else {
			diff /= 2;
			System.out.println(workNum[0] > workNum[1] ?
					workNum[1] + diff : workNum[0] + diff);
		}
	}
}


Measured memory_bytes: 21844
#include <cstdio>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}

int S(int N){
    int ans = 0;
    while(N>0){
        ans += N % 10;
        N /= 10;
    }
    return ans;
}

int main(){
    int N;
    scanf("%d", &N);
    printjudge(N%S(N)==0);
    return 0;
}

Measured memory_bytes: 128
import math

A,B,H,M = map(int,input().split())

radH = 2*math.pi*H/12 + 30/180*math.pi*M/60
radM = 2*math.pi*M/60

L = math.sqrt(A**2+B**2-2*A*B*math.cos(radH-radM))

print(L)

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

int main(void) {
	int i;
	int N, K;
	long long int ans;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	ch = strtok(NULL, " ");
	K = atoi(ch);

	ans = K;
	for(i = 0; i < N - 1; i += 1) {
		ans *= (K - 1);
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,L;
  cin >> N >> L;
  vector<string> S(N);
  vector<long long> A(N,0);
  for (int i=0;i<N;i++) {
	cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  for (int i=0;i<N;i++) {cout << S.at(i);}
  cout << endl;
}

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

int cmp(const void *a, const void *b){
  int x = *(int*)a, y = *(int*)b;
  if( x > y ) 		{ return 1; }
  else if( x < y) 	{ return -1; }
  else 				{ return 0; }
}

int main(void)
{
  int n, i, oth; scanf("%d", &n);
  int a[n];
  for(i = 0; i < n; ++i) { scanf("%d", &a[i]); }
  qsort(a, n, sizeof(int), cmp);
  //for(i = 0; i < n; ++i) { printf(" %d", a[i]); }
  //printf("\n");
  
  oth = 0;
  for(i = 0; i < n-1; ++i) { oth += a[i]; }
  if( a[i] < oth ) { printf("Yes\n"); } else { printf("No\n"); }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       String a=sc.nextLine();
      String b=sc.nextLine();
      String c=sc.nextLine();
      System.out.println(a.substring(0,1)+b.substring(1,2)+c.substring(2,3));
      
    }
}


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

int main() {

  int a,c;
  string b;
  cin >>a>>b>>c ;
for(int i=0;i<a;i++){
  if(b[i]==b[c-1]) {
  }
  else {
  b[i]='*';
  }
  }
cout<<b<<endl;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int first = 0;
        for (int i = 0 ; i < s.length() ; i++ ) {
            if (s.charAt(i) == 'A') {
                first = i ;
                break;
            }
        }
        int last = 0;
        for (int i = s.length() - 1 ; i >= 0 ; i-- ) {
            if (s.charAt(i) == 'Z') {
                last = i;
                break;
            }
        }

        System.out.println(last - first + 1);
    }

}

Measured memory_bytes: 27624
import java.io.*;

public class Main{
  public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s=br.readLine();
        String[] spl=s.split(" ");
        int a=Integer.parseInt(spl[0]);
        int b=Integer.parseInt(spl[1]);
        int c=Integer.parseInt(spl[2]);
 
        if(a<b&&b<c) System.out.println("Yes");
        else System.out.println("No");
    }
}

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

int main() {
	int n;cin >>n;
	int out = 0;
	for (int i=0;i<n;++i){
		int t;cin>>t;
		if((i+1)%2==1 && t%2==1)++out;
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 3496
import numpy as np
N=int(input())
a = list(map(int, input().split())) 

pA=[]
pB=[]
  
for i in range(N):
  m=max(a)
  if i%2==0:
    pA.append(m)
  else:
    pB.append(m)
  a.remove(m)
print(sum(pA)-sum(pB))

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

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

int main() {
    ll n , m, wa = 0,x =0, ac = 0, cnt = 0;
    cin >> n >> m;
    string s[m];
    std::vector<ll> v;
    std::vector<bool> vb(MOD, false);
    for(int i = 0; i< m; i++){
        cin >> x;
        v.push_back(x);
        cin >> s[i];
        if(s[i] == "AC") {
            vb[x] = true;
        }
    }
    for(int i = 0; i< m; i++){
        if(vb[v[i]] && s[i] == "AC"){
            vb[v[i]] = false;
            ac++;
        }
        else if(vb[v[i]] && s[i] == "WA"){
            wa++;
        }
    }
    cout << ac << " "<< wa;
  return 0;
}


Measured memory_bytes: 128628
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
typedef long long ll;

int A,B,C;

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

    cin>>A>>B>>C;
    cout<<min( C, B/A )<<'\n';

    return 0;
}


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

int main() {
	int h,w;
	int i, j;
	int ai, aj;
	string s[26][26];
	cin >> h >> w;
	for (i = 0; i < h; i++)for (j = 0; j < w; j++) {
		cin >> s[i][j];
		if (s[i][j] == "snuke") {
			ai = i;
			aj = j;
		}
	}
	char a = aj + 65;
	cout << a << ai + 1 << endl;


	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int n,a,b,sum;
bool aa[100005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		for(int ii=a;ii<=b;ii++)aa[ii]=1;
	}
	for(int i=1;i<=100001;i++)
	{
		if(aa[i]==1)sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<queue>
using namespace std;

typedef struct{
	string _name;
	int _time;
}prcs;


int main(){

	int n, q, i, tm, sum=0;
	string nm;
	prcs p;
	queue<prcs> qu;

	cin >> n >> q;

	for (i = n; cin >> nm >> tm, p._name = nm, p._time = tm, qu.push(p), --i;);

	while (!qu.empty()){

		p = qu.front();

		if (p._time - q <= 0){
			sum+=(p._time);
			cout << p._name << " " << sum << endl;
			qu.pop();
		}
		else
		{
			sum+=q;
			p._time -= q;
			qu.push(p);
			qu.pop();
		}
	}

}

Measured memory_bytes: 4404
#include<stdio.h>
#include<string.h>



int main(){
	
	int tairu=0,i;
	char S[100010];
	
	scanf("%s",S);
	
	if(S[0]=='0'){
		for(i=1;i<strlen(S);i++){
		if(i%2==0){
		if(S[i]=='1'){
		tairu++;
		}
		}else{
			if(S[i]=='0'){
			tairu++;
			
			}
		}
		}
		
	}else if(S[0]=='1'){
		for(i=1;i<strlen(S);i++){
		if(i%2==0){
		if(S[i]=='0'){
		tairu++;
		}
		}else{
			if(S[i]=='1'){
			tairu++;
			
			}
		}
		}	
	}
	
	printf("\n%d\n\n",tairu);
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>


using namespace std;

int main()
{
  int n, q;
  cin >> n >> q;
  queue< pair<string, int> > Q;

    string name;
    int time;
  for (int i = 0; i < n; ++i) {

    cin >> name >> time;
    Q.push(make_pair(name, time));
  }

  int time_stamp = 0;

  while (!Q.empty()) {
    if (Q.front().second <= q) {
    time_stamp += Q.front().second;
cout << Q.front().first << " " << time_stamp  << endl;
      Q.pop();
    } else {
      time_stamp += q;
      Q.front().second -= q;
      pair<string, int> rescheduled = Q.front();
      Q.pop();
      Q.push(rescheduled);
    }
  }
      

  
  
  return 0;
}

Measured memory_bytes: 4404
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	int N;
	cin >> N;
	vector<int> d(N);
	REP(i, N)cin >> d[i];
	map<int, int>mp;
	set<int> st;
	for (auto num : d) {
		st.insert(num);
		mp[num]++;
	}

	int res = 0;
	int cnt = 0;
	for (auto itr = st.begin(); itr != st.end(); itr++) {
		cnt += mp[*itr];
		if (cnt * 2 == N) {
			int now = *itr;
			itr++;
			int next = *itr;
			res = next - now;
			break;
		}
	}
	cout << res << endl;
	return 0;
}


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

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if(b <= 0)              cout << (b-a)*c << endl;
    else if(a < 0 && 0 < b) cout << abs(a)*c+d+b*e << endl;
    else                    cout << (b-a)*e << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  unsigned int N, a, b, c, temp = 0;
  int count = 0, sum;
  int A[200];
   cin >> N;
   for(int i = 0; i < N; i++){
     cin >> A[i];
   }
 
  
    for(int i = 0; i < N; i++){
      sum += A[i];
      if(A[i]>temp) temp=A[i];
    }
    
  cout << (sum-temp+temp/2) << endl;
  
  return 0;
}

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

using namespace std;

int main(){
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    for(int i=1;;i++){
    	if(i*k > b) {
    		cout<<"NG"<<endl;
    		break;
		}
		if(i*k>=a && i*k<=b){
			cout<<"OK"<<endl;
			break;
		}
	}
	return 0;
} 

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
inline int read () {
	int num = 0;
	char c = ' ';
	bool flag = true;
	for (;c > '9' || c < '0';c = getchar())
		if (c == '-')
			flag = false;
	for (;c >= '0' && c <= '9';num = (num << 1) + (num << 3) + c - 48, c = getchar());
	return flag ? num : -num;
}
namespace INIT {
	const int maxn = 200200;
	int n, a[maxn];
	void init () {
		n = read ();
		for (int i = 1;i <= n;i ++)
			a[i] = read ();
	}
} using namespace INIT;
struct node {
	int num,val;
} c1[maxn],c2[maxn];
int map1[maxn],cnt1 = 0;
void work1 () {
	for (int i = 1;i <= n;i += 2) {
		if (map1[a[i]] == 0) {
			map1[a[i]] = ++ cnt1;
			c1[cnt1].num = a[i];
		}
		c1[map1[a[i]]].val ++;
	}
}

int map2[maxn],cnt2 = 0;
void work2 () {
	for (int i = 2;i <= n;i += 2) {
		if (map2[a[i]] == 0) {
			map2[a[i]] = ++ cnt2;
			c2[cnt2].num = a[i];
		}
		c2[map2[a[i]]].val ++;
	}
}
node a1,a2,b1,b2;
void SORT () {
	for (int i = 1;i <= cnt1;i ++) {
		if (c1[i].val > a1.val) {
			a2 = a1;
			a1 = c1[i];
		}
		else if (c1[i].val > a2.val) {
			a2 = c1[i];
		}
	}
	for (int i = 1;i <= cnt2;i ++) {
		if (c2[i].val > b1.val) {
			b2 = b1;
			b1 = c2[i];
		}
		else if (c2[i].val > b2.val) {
			b2 = c2[i];
		}
	}
}
void work () {
	int ans = 0x7fffffff,now;
	if (a1.num != b1.num) {
		now = n - a1.val - b1.val;
		ans = min (ans,now);
	}
	if (a1.num != b2.num) {
		now = n - a1.val - b2.val;
		ans = min (ans,now);
	}
	if (a2.num != b1.num) {
		now = n - a2.val - b1.val;
		ans = min (ans,now);
	}
	cout << ans << endl;
}
int main () {
	init ();
	work1 ();
	work2 (); 
	SORT ();
	work ();
	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100100;
int main(){
  ll n,i,ans = inf,All = 0,now = 0;scanf("%lld",&n);
  ll a[n];
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);All += a[i];
  }
  for(i=0;i<n-1;i++){
    now += a[i];
    ans = min(ans,abs(All-now-now));
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;
priority_queue <ll> que;
Pll CB[int(1e5 + 5)];

int main(){
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++){
    int A; scanf("%d", &A);
    que.push(A);
  }

  for (int i = 0; i < M; i++){
    ll B, C; scanf("%lld%lld", &B, &C);
    CB[i] = {C, B};
  }
  sort(CB, CB + M, greater<Pll>());

  ll cnt = 0;
  for (int i = 0; i < M; i++){
    cnt += CB[i].se;
    for (int j = 0; j < CB[i].se; j++) que.push(CB[i].fi);
    if (cnt >= N) break;
  }

  ll ans = 0;
  for (int i = 0; i < N; i++){
    ll now = que.top(); que.pop();
    ans += now;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6872
import java.util.Scanner;

public class Main {

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

    int k = sc.nextInt();
    int x = sc.nextInt();

    for (int i = x - k + 1; i < x + k; ++i) {
      System.out.print(i + " ");
    }
  }
}

Measured memory_bytes: 21844
/**
 *    author:  math2do
 *    created: 28.03.2020 17:50:06
**/

#include <bits/stdc++.h>

using namespace std;

template <typename T>
class graph {
 public:
  struct edge {
    int from;
    int to;
    T cost;
  };
 
  vector<edge> edges;
  vector<vector<int>> g;
  int n;
 
  graph(int _n) : n(_n) {
    g.resize(n);
  }
 
  virtual int add(int from, int to, T cost) = 0;
};

template <typename T>
class undigraph : public graph<T> {
 public:
  using graph<T>::edges;
  using graph<T>::g;
  using graph<T>::n;
 
  undigraph(int _n) : graph<T>(_n) {
  }
 
  int add(int from, int to, T cost = 1) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    int id = (int) edges.size();
    g[from].push_back(id);
    g[to].push_back(id);
    edges.push_back({from, to, cost});
    return id;
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  undigraph <int> g(n);
  for (int i = 0; i < n - 1; i++) {
    g.add(i, i + 1);
  }
  g.add(x - 1, y - 1);

  vector <bool> seen(g.n);
  vector <int> d(n, 0);
  vector <int> done(n, false);

  auto Bfs = [&](int from, int depth) {
    queue <int> q;
    q.push(from);
    seen[from] = true;

    while (!q.empty()) {
      int size = (int) q.size();
      while (size--) {
        int u = q.front(); q.pop();
        if (!done[u]) {
          d[depth]++;
        } 
        for (int id : g.g[u]) {
          int v = g.edges[id].from ^ g.edges[id].to ^ u;
          if (!seen[v]) {
            seen[v] = true;
            q.push(v);
          }
        } 
      }
      depth += 1;
    }
  };

  for (int i = 0; i < n; i++) {
    fill(seen.begin(), seen.end(), false);
    Bfs(i, 0);
    done[i] = true;
  }   
  for (int i = 1; i < n; i++) {
    cout << d[i] << endl;    
  } 
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FORD(i,a,b) for(int i=(a);i>=b;i--)
#define FOR(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
using namespace std;
int main() {
	int n;
	int cnt=1e9,ans=0;
	cin>>n;
	FOR(i,0,n) {
		int p;
		cin>>p;
		if(cnt>=p)ans++;
		cnt=min(cnt,p);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  ll a, b, c;
  cin >> a >> b >> c;

  cout << (a + b >= c ? b + c : a + 2 * b + 1) << '\n';
  




  
  return 0;
}

Measured memory_bytes: 256
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
import math

def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())
    t, a = [int(x) for x in input().rstrip().split(" ")]

    min_diff = float('inf')

    for i, h in enumerate(input().rstrip().split(" ")):
        h = int(h)

        temp = t - h * 0.006
        diff = abs(temp - a)
        if min_diff > diff:
            min_diff = diff
            ans = i+1

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 80968
n, a, b = map(int, input().split())
ab = a + b
nab = n // ab
jouyo = n % ab

if ab == n:
    print(a)
elif a == 0:
    print(a)
elif ab < n:
    naba = nab * a
    if jouyo <= a:
        print(naba + jouyo)
    else:
        print (naba + a)
elif ab > n:
    if n <= a:
        print(n)
    else:
        print(a)

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

using namespace std;
using ll = long long;

const int mxn = 11;
vector<bool> val(mxn, 1);

bool valid(string s){
	bool ok = 1;
	int n = int(s.size());
	for(int i = 0; i < n && ok; ++i){
		ok &= (val[s[i] - '0']);
	}
	return ok;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n, k;
	cin >> n >> k;
	for(int i = 0, x; i < k; ++i){
		cin >> x;
		val[x] = 0;
	}	
	while(1){
		string s = to_string(n);	
		if(valid(s)){
			break;
		}
		++n;
	}
	cout << n << '\n';
	return 0;
}

Measured memory_bytes: 3684
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 1e5 + 10;
ll a[maxN];
ll ans[maxN];
ll sum[maxN];
ll delta[maxN];
ll real_ans[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    vector < pair < ll, int > > st;
    ll sm = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sm += a[i];
    }
    for (int i = n; i >= 1; i--) {
        while (!st.empty() && st.back().first <= a[i]) st.pop_back();
        st.emplace_back(a[i], i);
    }
    reverse(st.begin(), st.end());
    priority_queue < ll > q;
    ll lft = 0;
    ll sz_equal = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] <= st[0].first) continue;
        int p = lower_bound(st.begin(), st.end(), make_pair(a[i], -1)) - st.begin();
        assert(p > 0);
        sum[0] += a[i];
        delta[0]++;
        sum[p] -= a[i];
        delta[p]--;
    }
    for (int i = 0; i + 1 < st.size(); i++) {
        if (i) {
            sum[i] += sum[i - 1];
            delta[i] += delta[i - 1];
        }
        ans[st[i + 1].second] = sum[i] - delta[i] * st[i].first;
    }
    for (int i = 1; i < st.size(); i++) {
        real_ans[st[i].second] = ans[st[i].second];
        if (i + 1 < st.size()) real_ans[st[i].second] -= ans[st[i + 1].second];
    }
    for (int i = n; i >= 2; i--) {
        lft += real_ans[i];
    }
    real_ans[1] = sm - lft;
    for (int i = 1; i <= n; i++) {
        cout << real_ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 6640
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;




int main(void){
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string k;
    cin>>k;
    if(k==s){
        a--;
    }else{b--;}
    cout<<a<<" "<<b;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int h,w;
    cin >>h >>w;
    while(h || w)
    {
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
            {
                if(i%2==0)
                {
                    if(j%2==0)
                        cout<< "#";
                    else
                        cout<< ".";
                    if(j==w-1)
                        cout<< endl;
                }
                else
                {
                    if(j%2==1)
                        cout<< "#";
                    else
                        cout<< ".";
                    if(j==w-1)
                        cout<<endl;
                }
            }
        cout <<endl;
        cin >>h >>w;
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int k;
  cin >> n >> k;
  int sum = 0;
  
  for (int i = 0; i < n; i++){
    int xi;
  	cin >> xi;
    
    if(xi < k){
    	if(k - xi > xi) {
        	sum += 2 * xi;
        } else {
        	sum += 2 * (k - xi);
        }
    } else {
      sum += 2 * (xi - k);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

r = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if X == 500 * a + 100 * b + 50 * c:
                r += 1

print(r)


Measured memory_bytes: 3060
#include<stdio.h>

int main(void)

{
    
    int h,m,s,d;
    
    scanf("%d",&d);
    
    h=d/3600;
    m=d%3600/60;
    s=d%3600%60;
    
    printf("%d:%d:%d\n",h,m,s);
    
    
    return 0;
}



Measured memory_bytes: 2124
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


a, b, c, d = inl()
if abs(a-b) <= d and abs(b-c) <= d or abs(a-c) <= d:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3572
#include <stdio.h>
#define ll long long
#define rep(i,l,r,d) for(ll i=(l);i<(r);i+=(d))
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
int main(void){
    ll A, B, C, X, Y, ANS;
    scanf("%lld %lld %lld %lld %lld", &A, &B, &C, &X, &Y);
    if(A+B < 2*C) ANS = A*min(X,Y) + B*min(X,Y);
    else ANS = 2*C*min(X,Y);
    if(X>Y){
        if(A<2*C) ANS += A*(X-Y);
        else ANS += 2*C*(X-Y);
    }
    else {
        if(B<2*C) ANS += B*(Y-X);
        else ANS += 2*C*(Y-X);
    }
    printf("%lld\n", ANS);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	static long INF = 1L << 60;
	static int[][] dp = new int [3100][3100];
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		sc.close();

		// DPループ
	    for (int i = 0; i < s.length; i++) {
	        for (int j = 0; j < t.length; j++) {
	            if (s[i]==t[j]) dp[i+1][j+1]=Math.max(dp[i+1][j+1], dp[i][j] + 1);
	            dp[i+1][j+1]=Math.max(dp[i+1][j+1], dp[i+1][j]);
	            dp[i+1][j+1]=Math.max(dp[i+1][j+1], dp[i][j+1]);
	        }
	    }
	    // 復元
	    String res = "";
	    int i = s.length, j = t.length;
	    while (i > 0 && j > 0){
	        // (i-1, j) -> (i, j) と更新されていた場合
	        if (dp[i][j] == dp[i-1][j]) {
	            i--; // DP の遷移を遡る
	        } // (i, j-1) -> (i, j) と更新されていた場合
	        else if (dp[i][j] == dp[i][j-1]) {
	            j--; // DP の遷移を遡る
	        }// (i-1, j-1) -> (i, j) と更新されていた場合
	        else {
	            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
	            i--;j--; // DP の遷移を遡る
	        }
	    }
	    System.out.println(res);
	}
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int diff = min(B, D) - max(A, C);
    if (diff >=0)
        cout << diff << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

int main() {
	int n, q, com, x, y;
	int A[1000000];

	cin >> n >> q;

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

	for (int i = 0; i < q; i++) {
		int sum = 0;
		cin >> com >> x >> y;

		if (com == 0) {
			A[x] += y;
		}
		else {
			for (int j = x; j <= y;j++) {
				sum += A[j];
			}
			cout << sum << endl;
		}
	}
	return 0;
}


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

typedef long long int ll;




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int k, n;
    cin >> k >> n;
    
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a, a+n);
    int mDif = -1;
    for (int i=1; i<n; i++) {
		mDif = max(mDif, a[i]-a[i-1]);
	}
	mDif = max(k-a[n-1]+a[0], mDif);
	cout << k-mDif << endl;
    
    return 0;
}


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

int main(){
    
    //料理の頼み方は5!
    //順列だからnext_permutationを使ってみる

    vector<int> m(5);

    for(int i=0; i<5; i++){
        cin>>m[i];
    }

    int sum,ans=1e9;

    do{
        sum =0;

        for(int i=0; i<5; i++){

            sum += m[i];

            if(i==4)continue;

            while(sum % 10 != 0) sum++;
        }

        ans = min(sum,ans);
    }while(next_permutation(m.begin(),m.end()));

    cout<<ans<<endl;

    return 0;    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    String S = scan.next();
    
    char prev = '0';
    int ans = 0;
    for(int i=0; i<S.length(); i++) {
      if(S.charAt(i) != prev) { ans++; }
      prev = S.charAt(i);
    }
    System.out.println(ans);
  }
}

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

typedef pair<int, int> pii;
#define INF 100000000

void solve(long long H, long long W, std::vector<string> A){
    vector<vector<int> > D(H, vector<int>(W, INF)); //* for distance
    int dx[]={1, 0, -1, 0}, dy[]={0, 1, 0, -1}; 
    queue<pii> que;
    for (int i=0; i< H; i++){
        for (int j=0; j< W; j++){
            if(A[i][j] == '#') {
                D[i][j] = 0;
                que.push(pii(i, j));
            }
        }
    }
    while(!que.empty()){
        pii p = que.front(); que.pop();
        //* search adjacent positions
        for (int i=0; i< 4; i++){
            int nx, ny;
            nx = p.first + dx[i];
            ny = p.second + dy[i];
            if(0<= nx && nx < H && 0<= ny && ny < W  && A[nx][ny]!='#' && D[nx][ny] == INF) {
                    D[nx][ny] = D[p.first][p.second] + 1;
                    que.push(pii(nx, ny));
            }
        }
    }
    //* search for max distance
    int maxd = 0;
    for(int i=0; i< H; i++){
        for (int j=0; j< W; j++){
            if(D[i][j] != INF){
                maxd = max(maxd, D[i][j]);
            }
        }
    }
    cout << maxd << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<string> A(H);
    for(int i = 0 ; i < H ; i++){
        std::cin >> A[i];
    }
    solve(H, W, std::move(A));
    return 0;
}


Measured memory_bytes: 13456
#include <iostream>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <cstring>
#include <climits>
#include <iomanip>

#define EPS 1e-7
#define LLMAX 9223372036854775807
#define INTMAX 2147483647
#define ULLMAX 18446744073709551615
#define precision(n) cout << setprecision(n) << fixed
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rforr(i, t, n) (int i = n-1; i>=t; --i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAXN = 1024;

//STRUCTS


//OPERATORS


//GLOBALS


//FUNCTIONS


//PROBLEM: 
//LINK: 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
		int n, k, q;
		cin >> n >> k >> q;
		int a[n];
		forn(i, n) a[i] = 0;
		forn(i, q)
		{
			int aux;
			cin >> aux;
			a[aux-1]++;
		}
		forn(i, n)
		{
			if (k - (q - a[i]) > 0) cout << "Yes";
			else cout << "No";
			cout << "\n";
		}




	return 0;
}

Measured memory_bytes: 1024
// @Author :- Gaurav Bharti
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define vii vector<int>
#define vbl vector<bool>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int,int> 
#define mapll map<ll,ll>
#define lcm(a,b) a*b/(__gcd(a,b))
#define all(a) a.begin(),a.end()
#define test int t; cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define ItsFUN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

struct unionFind {
	vii par;
	unionFind(int n): par(n, -1) {}

	void init(int n) {
		par.assign(n, -1);
	}
	
	int root(int x) {
		if(par[x] < 0) {
			return x;
		}
		else return par[x] = root(par[x]);
	}	

	bool isSame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x);
		y = root(y);

		if(x == y) return false;

		if(par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return - par[root(x)];
	}
};

int main() {
   	ItsFUN;

   	int n, m; cin >> n >> m;
   	unionFind ob(n);

   	for(int i = 0; i<m ;++i) {
   		int x, y; cin >> x >> y;
   		--x, -- y;
   		ob.merge(x, y);
   	}

   	set<int> v;

   	for(int i = 0; i < n; ++i) {
   		v.insert(ob.root(i));
   	}

   	cout << v.size() - 1 << "\n";


   	return 0;
}

Measured memory_bytes: 7624
def initialize(N):
    i=1
    while i<N:
        i*=2
    return [0]*(2*i-1),i

def update(i,x):
    i+=d-1
    bit=ord(x)-97
    SEG[i]=0 | (1<<bit)
    while i>0:
        i=(i-1)//2
        SEG[i]=SEG[i*2+1]|SEG[i*2+2]
        
def find(a,b,k,l,r):
    if r<=a or b<=l:
        return 0
    if a<=l and r<=b:
        return SEG[k]
    else:
        c1=find(a,b,2*k+1,l,(l+r)//2)
        c2=find(a,b,2*k+2,(l+r)//2,r)
        return c1|c2
        
N=int(input())
S=input()
Q=int(input())

SEG,d=initialize(N)
for i in range(N):
    update(i,S[i])

for i in range(Q):
    com,s,t=map(str,input().split())
    if(com=='1'):
        update(int(s)-1,t)
    else:
        cnt=0
        bit=find(int(s)-1,int(t),0,0,d)
        while(bit>0):
            if(bit&1):
                cnt+=1
            bit//=2
        print(cnt)

Measured memory_bytes: 84824
#include<iostream>
#include<set>
#include<string>
using namespace std;

string rev(string s){
	string res="";
	for(int i=s.size()-1;i>=0;i--){
		res+=s[i];
	}
	return res;
}

int main()
{
	int n;
	cin>>n;
	for(int z=0;z<n;z++){
		int count=0;
		string s;
		cin>>s;
		set<string> S;
		for(int i=1;i<s.size();i++){
			string s1=s.substr(0,i),s2=s.substr(i);
			if(!S.count(s1+s2)){
				S.insert(s1+s2);
				count++;
			}
			if(!S.count(s1+rev(s2))){
				S.insert(s1+rev(s2));
				count++;
			}
			if(!S.count(rev(s1)+s2)){
				S.insert(rev(s1)+s2);
				count++;
			}
			if(!S.count(rev(s1)+rev(s2))){
				S.insert(rev(s1)+rev(s2));
				count++;
			}
			swap(s1,s2);

			if(!S.count(s1+s2)){
				S.insert(s1+s2);
				count++;
			}
			if(!S.count(s1+rev(s2))){
				S.insert(s1+rev(s2));
				count++;
			}
			if(!S.count(rev(s1)+s2)){
				S.insert(rev(s1)+s2);
				count++;
			}
			if(!S.count(rev(s1)+rev(s2))){
				S.insert(rev(s1)+rev(s2));
				count++;
			}

		}

		cout<<count<<endl;

	}
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
    long long coin = 0;
    int ki,ic1,ic2;
    long long min;
    int n,m;
    int sum,big;
    long cum[100001];
    long suu[100001]={0};
    cin >> n >> m >> cum[1];
    for(int i=2;i<=m;i++)
    {
        cin >> cum[i];
        if(cum[i]<cum[i-1])
        {
        	sum=cum[i];
        	big=cum[i-1];
        }
        else
        {
        	sum=cum[i-1];
        	big=cum[i];
         }
        while(sum<big)
        {
        	suu[sum]++;
        	sum++;
         }
    }
    for(int i=1;i<n;i++)
    {
        cin >> ki >> ic1 >> ic2;
        min = ki*suu[i];
        if(min>ic2+ic1*suu[i])
        {
        	min=ic2+ic1*suu[i];
        }
        coin+=min;
    }
    cout << coin << endl;
    return 0;
}

Measured memory_bytes: 4692
N, K = map(int, input().split())
P = list(map(int, input().split()))
ans = 0
for i in range(K):
    ans += (P[i]+1)/2

tmp = ans
for i in range(K, N):
    tmp = tmp + (P[i]+1)/2 - (P[i-K]+1)/2
    ans = max(ans, tmp)

print(ans)

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

int main() {
  int64_t n, m;
  int64_t a, b;
  int64_t ans = 0;

  cin >> n >> m;
  vector<int64_t> h;
  for (int64_t i = 0; i < n; i++) {
    cin >> a;
    h.push_back(a);
  }
  vector<int64_t> rnk(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (h[a - 1] < h[b - 1] && rnk[b - 1] == 0) {
      rnk[a - 1] = 1;
    } else if (h[a - 1] > h[b - 1] && rnk[a - 1] == 0) {
      rnk[b - 1] = 1;
    } else {
      rnk[a - 1] = 1;
      rnk[b - 1] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (rnk[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4964
N = gets.to_i
A = (0..1).to_a.map{ gets.split.map(&:to_i) }

ans = ame = A[1].inject(:+) + A[0][0]
(1...N).each do |i|

  ame += (A[0][i] - A[1][i-1])
  ans  = ame if ans < ame
  
end

p ans

Measured memory_bytes: 1788