akhauriyash/Code-Regression huggingface dataset:
#ABC076C
S_dash=str(input())
T=str(input())
location=-1
for i in range(len(S_dash)-len(T)+1):
    j=0
    while j<=len(T)-1:
        if S_dash[i+j]==T[j] or S_dash[i+j]=='?':
            if j==len(T)-1:
                location=i
            j+=1
        else:
            break
if location>=0:
    S_dash_list=list(S_dash)
    for i in range(len(T)):
        S_dash_list[location+i]=T[i]
    S_tmp="".join(S_dash_list)
    S=S_tmp.replace('?','a')
if location>=0:
    print(S)
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

int n, m;
vector<int> e[1000];

bool used[1000];
vector<int> ans, v;
void dfs(int x) {
    v.push_back(x);
    used[x] = true;
    for(int y : e[x]) {
        if(v[0] == y)
            if(ans.empty() || ans.size() > v.size()) ans = v;
        if(!used[y]) dfs(y);
    }
    v.pop_back();
}

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

    cin >> n >> m;
    rep(i, m) {
        int u, v;
        cin >> u >> v;
        e[u - 1].push_back(v - 1);
    }

    rep(i, n) {
        rep(i, n) used[i] = false;
        dfs(i);
    }

    if(ans.empty())
        cout << -1 << endl;
    else {
        cout << ans.size() << endl;
        for(int x : ans)
            cout << x + 1 << endl;
    }

    return 0;
}

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

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    std::sort(h.begin(), h.end());
     std::cout <<h[n/2] - h[n/2 -1] << std::endl;

    return 0;
}


Measured memory_bytes: 768
x=[list(map(int,input().split())) for i in range(3)]

ax=x[0][1]-x[0][0]
bx=x[0][2]-x[0][1]
for i in range(3):
    if ax!=x[i][1]-x[i][0] or bx!=x[i][2]-x[i][1]:
        print("No")
        break
else:
    ay=x[1][0]-x[0][0]
    by=x[2][0]-x[1][0]

    for i in range(3):
        if ay!=x[1][i]-x[0][i] or by!=x[2][i]-x[1][i]:
            print("No")
            break
    else:
        print("Yes")


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

// n:品物の数, W:入れられる重さの総和の限界
int N, W;
// w[i]: i個目の荷物の重さ
vector<int> w;
// v[i]: i個目の荷物の価値
vector<int> v;
vector<vector<int>> dp;

// //
// i番目以降の品物から重さの総和がj以下となるように選んだときの最大の価値が返ってくる
// int rec(int i, int j) {
//   if(dp[i][j] >= 0) { return dp[i][j]; }
//   int res;
//   if(i == N) {
//     res = 0;
//   }
//   // w[j]が重さオーバーで入れられないとき
//   else if(j < w[i]) {
//     res = rec(i + 1, j);
//     // 入れる場合と入れない場合を両方試し、価値が最大になるほうを選ぶ
//   } else {
//     res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);
//   }
//   dp[i][j] = res;
//   return res;
// }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> W;
  w.assign(N, 0);
  v.assign(N, 0);
  dp.assign(N + 1, vector<int>(W + 1, -1));
  REP(i, N) cin >> v[i] >> w[i];
  for(int j = 0; j < W + 1; j++) {
    dp[N][j] = 0;
  }

  for(int i = N - 1; i >= 0; i--) {
    for(int j = 0; j <= W; j++) {
      if(j < w[i]) {
        dp[i][j] = dp[i + 1][j];
      } else {
        dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
      }
    }
  }

  cout << dp[0][W] << endl;
  return 0;
}


Measured memory_bytes: 6756
#include <iostream>

using namespace std;

const int mod = 1e9 + 7;
int n, c[200005], dp[200005], cnt[200005];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> c[i];
        if (c[i] == c[i - 1])
        {
            i--;
            n--;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        dp[i] = (dp[i - 1] + cnt[c[i]]) % mod;
        cnt[c[i]] = (cnt[c[i]] + dp[i - 1] + 1) % mod;
    }
    cout << (dp[n] + 1) % mod << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define inf (int)(1e9)
#define INF 1.1529215e+18
#define MAXX 999999
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*--------------------------------------------*/

int main(){
    int n;cin>>n;   
    string s[n+1];
    rep(i,n){
        cin>>s[i];
        //cout<<s[i]<<endl;
    }
    int flag2=1;
    rep(i,n-1){
        string tmp=s[i];
        int flag=1;
        rep(j,n){if(i!=j)if(s[i]==s[j])flag=0;}
        char last=tmp[tmp.size()-1];
        if(s[i+1][0]!=last||flag==0)flag2=0;
       
    }
    cout<<(flag2?"Yes":"No")<<endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli a,b;

	cin>>a>>b;

	cout<<max(a-2*b,0LL)<<endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main()
{
     string a[] = {"Sunny","Cloudy","Rainy"};
     string s;
     cin>>s;
     for(ll i=0;i<3;i++)
     {
          if(s==a[i])   cout<<a[(i+1)%3];
     }
}


Measured memory_bytes: 256
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def main():
  s=input()
  t=input()
  n=len(s)
  flg=0
  for i in range(n):
    if s[i]!=t[i]:
      flg=1
  Yes(flg==0)

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 67232
const log = console.log;

const createScanFunctions = (input: string) => {
  const str = input.trim();
  const len = str.length;
  let index = 0;

  const scan = () => {
    const startIndex = index;

    while (index < len) {
      const char = str[index];

      if (char === " " || char === "\n")
        return str.substring(startIndex, index++);

      index++;
    }

    return str.substr(startIndex);
  };

  const scanInt = () => parseInt(scan());

  return { scan, scanInt };
};

const createArrayOfNumberArrays = (length: number) => {
  const array = new Array<number[]>(length);
  for (let i = 0; i < length; i++) array[i] = [];

  return array;
};

const isEven = (n: number) => (n & 1) === 0;

// ----

function Main(input: string): void {
  const { scanInt } = createScanFunctions(input);

  // prepare graph
  const n = scanInt();
  const neighborIdTable = createArrayOfNumberArrays(n);
  const neighborDistanceTable = createArrayOfNumberArrays(n);
  const vertexColorArray = new Array<number | undefined>(n).fill(undefined);

  function linkVertices(id: number, neighborId: number, distance: number) {
    neighborIdTable[id].push(neighborId);
    neighborDistanceTable[id].push(distance);
    neighborIdTable[neighborId].push(id);
    neighborDistanceTable[neighborId].push(distance);
  }

  // read edges data
  const edgeCount = n - 1;

  for (let i = 0; i < edgeCount; i++)
    linkVertices(scanInt() - 1, scanInt() - 1, scanInt());

  // prepare search, visit first vertex
  const recentVisitedStack: number[] = [];

  vertexColorArray[0] = 0;
  recentVisitedStack.push(0);

  const visitVertices = (recentVisitedStack: number[]) => {
    const recentVertexId = recentVisitedStack.pop() as number; // checked before calling this function

    const neighborIdArray = neighborIdTable[recentVertexId];
    const neighborDistanceArray = neighborDistanceTable[recentVertexId];
    const neighborCount = neighborIdArray.length;
    const recentColor = vertexColorArray[recentVertexId] as number; // unsafe

    for (let i = 0; i < neighborCount; i++) {
      const neighborId = neighborIdArray[i];

      if (vertexColorArray[neighborId] !== undefined) continue; // already visited

      vertexColorArray[neighborId] = isEven(neighborDistanceArray[i])
        ? recentColor
        : recentColor ^ 1;

      recentVisitedStack.push(neighborId);
    }
  };

  // search & paint
  while (recentVisitedStack.length > 0) visitVertices(recentVisitedStack);

  // output
  for (const color of vertexColorArray) log(color);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 80928
M=998244353;
char S[2001];
N;
d[4001][4001];
x,y;
i,j,k;
main(){
	N=strlen(gets(S));
	for(**d=1;i<2*N;++i){
		if(i<N)y=2*(i+1)-(x+=S[i]-'0');
		for(j=0;j<=i;++j){
			for(k=0;k<2;++k){
				if(j+!k<=x&&i-j+k<=y){
					d[j+!k][i-j+k]+=d[j][i-j]%M;
				}
			}
		}
	}
	printf("%d",d[x][y]%M);
}


Measured memory_bytes: 60288
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            Console.WriteLine(new string(Enumerable.Repeat('x', S.Length).ToArray()));
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    if (n % 2 == 0) {
        println(n);
    }
    else {
        println(n * 2)
    }
    return 0;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

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

  ll all_sum = 0;
  ll num_sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    all_sum += nums[i] * num_sum;
    all_sum %= MOD;

    num_sum += nums[i];
    num_sum %= MOD;
  }

  cout << all_sum << endl;

  return 0;
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr ll INF=1e18;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

ll calc(ll n,ll c,vl xs,vl vs)
{
	vl ss(n+1),ts(n+1);
	rep(i,n) ss[i+1]=ss[i]+vs[i];
	rep(i,n) ss[i+1]-=2*xs[i];
	per(i,n) ts[i]=ts[i+1]+vs[i];
	per(i,n) ts[i]-=c-xs[i];

	vl ps=ss,qs=ts;
	rep(i,n) chmax(ps[i+1],ps[i]);
	per(i,n) chmax(qs[i],qs[i+1]);

	ll res=0;
	rep(i,n+1)
		chmax(res,ps[i]+qs[i]);
	return res;
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(ll n,c;cin>>n>>c&&n|c;){
		vl xs(n),vs(n);
		rep(i,n) cin>>xs[i]>>vs[i];

		ll res=calc(n,c,xs,vs);
		reverse(all(xs));
		rep(i,n) xs[i]=c-xs[i];
		reverse(all(vs));
		chmax(res,calc(n,c,xs,vs));

		cout<<res<<endl;
	}
}


Measured memory_bytes: 6560
def main():
    n = int(input())
    s = input()

    wnum = s.count("W")
    enum = s.count('E')

    first = enum
    ans = first

    for i in range(n):
        if s[i] == "E":
            first -= 1
        if i >= 1:
            if s[i-1] == "W":
                first += 1
        if ans > first:
            ans = first
        #print(i, ans, first)
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 73544
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    int N, i, L[11], sum=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> L[i];
    }

    sort(L+1, L+N+1);

    for(i=1; i<=N-1; i++){
        sum += L[i];
    }

    if(sum > L[N]){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
        long long x, k, d;

        cin >> x >> k >> d;

        x = abs(x);

        if (k < x / d) {
                for (long long i = k; i > 0; i--) {
                        x -= d;
                }
                cout << x << endl;
        } else {
                long long div = x / d;
                if (div == k) {
                        cout << abs(x-div*d) << endl;
                } else {
                        if ((k - div) % 2)
                                div++;
                        cout << abs(x-div*d) << endl;
                }
        }

        return 0;
}

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

int main()
{
	unsigned int pm,pe,pj;
	unsigned int i,n,ave;
	char *class;

	scanf("%d",&n);
	while(n!=0) {
	class = malloc(n);
	for(i = 0; i < n; i++) { 
	scanf("%d %d %d", &pm,&pe,&pj);
	ave = (pm+pe+pj)/3;
	if ((pm == 100 || pe == 100 || pj == 100) || (pm+pe)/2 >= 90 || ave>=80) class[i] = 'A';
	else if (ave >= 70 || (ave >= 50 && (pm>=80 || pe>=80))) class[i] = 'B';
	else class[i] = 'C';
}
	for(i = 0; i < n; i++) printf("%c\n",class[i]);
	free(class);
	scanf("%d",&n);
}
	return 0;
}

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

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

int binary_search(ll x, vel a) {
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin();
    } else {
        return -1;
    }
}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    ll N,ac = 0, wa = 0, tle = 0, re = 0;
    cin >> N;
    string S;
    REP(i, N){
        cin >> S;
        if(S == "AC"){
            ac++;
        } else if(S == "WA"){
            wa++;
        } else if(S == "TLE") {
            tle++;
        } else if(S == "RE") {
            re++;
        }
    }

    cout << "AC " << "x " << ac << endl;
    cout << "WA " << "x " << wa << endl;
    cout << "TLE " << "x " << tle << endl;
    cout << "RE " << "x " << re << endl;
}

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

using namespace std;

using ll = long long;

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

    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    for (auto &&x : h) cin >> x;
    sort(h.begin(), h.end());

    int res = INT_MAX;
    for (int i = 0; i + k <= n; ++i)
        res = min(res, h[i + k - 1] - h[i]);

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 640
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = long.Parse(Console.ReadLine());
            long currentM = 100;
            int year = 0;
            while (true)
            {
                currentM = currentM + (long) (currentM / 100);
                year++;
                if (currentM >= x)
                {
                    Console.WriteLine(year);
                    return;
                }
            }
        }
    }
}

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

int main(void)
{
    int N;
    std::cin >> N;

    std::vector<std::string> s(N);
    for (int i = 0; i < N; i++) {
        std::cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());

    uint64_t ans = 0;
    uint64_t i = 0;
    while (i < N - 1) {
        uint64_t j = i + 1;
        for (; j < N; j++) 
            if (s[i] != s[j]) break;
        ans += (j - i) * (j - i - 1) / 2;
        i = j;
    }

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

    return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    vector<int> n(3);
    for(int i = 0; i < 3; i++) {
        cin >> n[i];
    }
    int ans = 0;

    sort(n.begin(),n.end());

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

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

int grid[1000][1000];
int cnt[27][500][500] = {};

void solve(){
	int n, m;
	cin >> n >> m;
	REP(i, n) {
		string s;
		cin >> s;
		REP(q, m) {
			if (s[q] != '.') {
				grid[i][q] = s[q] - 'A' + 1;
			}
		}
	}
	int erased = 1;
	int ans = 0;
	while (erased != 0) {
		REP(i, 27) {
			REP(q, n) {
				REP(j, m) {
					cnt[i][q][j] = 0;
				}
			}
		}
		erased = 0;
		const int dx[4] = { 1,-1,0,0 };
		REP(i, n) {
			REP(q, m) {
				if (grid[i][q] == '.') continue;
				REP(t, 4) {
					for (int j = 1; j <= 500;++j) {
						int x = i + dx[t] * j;
						int y = q + dx[3 - t] * j;
						if (x >= 0 && x < n && y >= 0 && y < m) {
							if (grid[x][y] == 0) {
								cnt[grid[i][q]][x][y]++;
							}
							else {
								break;
							}
						}
						else break;
					}
				}
			}
		}
		REP(i, n) {
			REP(q, m) {
				for (int j = 1; j < 27; ++j) {
					if (cnt[j][i][q] == 2) {
						erased |= (1 << j);
					}
				}
			}
		}
		REP(i, n) {
			REP(q, m) {
				if ((1 << grid[i][q]) & erased) {
					ans++;
					grid[i][q] = 0;
				}
			}
		}
		//cout << erased << endl;
	}
	cout << ans << endl;
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 56144
#include <cstdio>

using namespace std;

const int N = 19;

char s[N];
char t[N];

int main() {
  scanf("%s%s", s, t);
  bool ans = true;
  for (int i = 0; s[i]; ++i) {
    if (t[i] != s[i]) {
      ans = false;
    }
  }
  puts(ans ? "Yes" : "No");
}


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

int main() {
	long long n,x=0,y=0;
	cin>>n;
	long long a[n],b[n-1];
	for(long i=0;i<n;i++)cin>>a[i];
	x=a[0];
	for(long i=0;i<n;i++)y+=a[i];
	y-=a[0];
	for(long i=0;i<n-1;i++){
		b[i]=max(x-y,y-x);
		x+=a[i+1];
		y-=a[i+1];
	}
	sort(b,b +(n-1));
	cout<<b[0]<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int k, s;
    cin >> k >> s;
    ll cnt = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            int z = s - i - j;
            if (z >= 0 && z <= k && i + j + z == s) {
                //cout << i << " " << j << " " << z << endl;
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) {
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) {
	return mod_pow(a , mod-2);
}

void solve() {
	
	int f[10000005] {};
	
	for(int i = 1; i <= 10000000; ++i) {
		for(int j = i; j <= 10000000; j += i) {
			f[j]++;
		}
	}
	
	int n;
	
	cin >> n;
	
	int sm = 0;
	
	for(int i = 1; i <= n; ++i) {
		sm += i*f[i];
	}
	
	cout <<sm;
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 81756
n = int(input())
amx = -float("inf")
amn = float("inf")
bmx = -float("inf")
bmn = float("inf")
ans = -float("inf")
for i in range(n):
    a,b = map(int,input().split())
    amx = max(amx,a+b)
    amn = min(amn,a+b)
    bmx = max(bmx,a-b)
    bmn = min(bmn,a-b)
print(max(amx-amn,bmx-bmn))

Measured memory_bytes: 9056
N = int(input())
X = [0]*N
sum = 0
P = 0
P1 = 0
T = 0
T1 = 0
X = [int(N) for N in input().split()]
for i in range(N):
    sum +=X[i]
P = int(sum/N)
P1 = int((sum/N)+1)
for i in range(N):
    T += (X[i]-P)*(X[i]-P)
    T1 += (X[i]-P1)*(X[i]-P1)
if T>T1:
    print(T1)
else:
    print(T)

Measured memory_bytes: 3064
n,k=map(int,input().split())
h=list(map(int,input().split()))
INF = 10**4+1
dp = [INF]*n
dp[0]=0
for i in range(1,n):
  dp[i] = min([dp[j] + abs(h[j]-h[i]) for j in range(max(0, i-k),i)])
print(dp[n-1])

Measured memory_bytes: 52592
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	int a[4], b[4];
	vector<int> count(4, 0);

	FOR(i, 1, 3) {
		cin >> a[i] >> b[i];
		count[a[i]-1]++;
		count[b[i]-1]++;
	}

	sort(count.begin(), count.end());

	if (count[0] == 1 && count[1] == 1 && count[2] == 2 && count[3] == 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

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


int main(int argc, char *argv[]){

  int i;
  char s[11];
  char a[11];
  int l, r;

  scanf("%s", s);

  l = strlen(s);
  r = strlen(a);

  for(i=0; i<=10; i++){
    a[i] = '\0';
  }



  for(i=0; i<=l-1; i++){
    r = strlen(a);

    if(s[i] == 'B'){
      if(r != 0){
        a[r-1] = '\0';
      }
    }else{
      a[r] = s[i];
    }
    //printf("%s\n", a);
  }







/*

  for(i=0; i<=l-1; i++){
    r = strlen(a);

    if(s[i] == '0'){
      a[r] = '0';
    }else if(s[i] == '1'){
      a[r] = '1';
    }else if(s[i] == 'B'){
      if(r != 0){
        a[r-1] = '\0';
      }
    }
    //printf("%s\n", a);
  }

  */



  printf("%s\n", a);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int num[3],tmp;
    for(int i=0;i<3;i++){
        cin>>num[i];
    }
    for (int i=0; i<3; ++i) {
    for (int j=i+1; j<3; ++j) {
      if (num[i] > num[j]) {
        tmp =  num[i];
        num[i] = num[j];
        num[j] = tmp;
      }
    }
  }
    cout<<num[0]+num[1];
    
  return 0;
}
    



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

#define dbg(x) cerr << #x"=" << x << endl;


int main() {
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
	string s;
	string t = "keyence";
	while(cin >> s){
        int sz = s.size();
        bool ans = 0;
        if(s.substr(sz-7, 7) == t) ans = 1;
        else if(s.substr(0, 7) == t) ans = 1;
        else {
            int x = 7;
            for(int i = 0; i < min(sz, 7); ++i) {
                if(s[i] != t[i]) break;
                --x;
            }
            int idx = 6;
            for(int i = sz-1; i >= 0 && idx >= 0; --i, --idx){
                if(s[i] != t[idx]) break;
                --x;
            }
            if(x <= 0) ans = 1;
        }
        cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int a[110];
int main() {
	int n, x;
	scanf("%d%d", &n, &x);
	for(int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
	sort(a+1, a+n+1);
	int ans = 0;
	for(int i = 1; i < n; i ++ ) {
		if(a[i] <= x) x -= a[i], ans ++;
		else break;
	}
	ans += x == a[n];
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

int n;

int main() {
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    map<int,int> mp;
    
    REP(i,n){
        auto itr = mp.find(a[i]-1);
        if(itr!=mp.end()){
            mp[a[i]] = mp[a[i]-1]+1;
            mp.erase(a[i]-1);
        }else{
            mp[a[i]]=1;
        }
    }
    int res = 0;
    for(auto itr:mp){
        chmax(res,itr.second);
    }
    put(n-res);
    return 0;
}




Measured memory_bytes: 10368
n = int(input())
value = list(map(int,input().split()))
cost = list(map(int,input().split()))

difplus = []
for i in range(n):
  dif = value[i] - cost[i]
  if dif > 0:
    difplus.append(dif)
    
if difplus == []:
  print(0)
else:
  ans = 0
  for j in difplus:
    ans += j
  print(ans)

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

int main()
{
	int n;
	int a;
	int min, max;
	long int sum = 0;

	cin >> n;
	cin >> a;

	min = a;
	max = a;
	sum += a;

	for (int i = 0; i < n - 1; i++) {
		cin >> a;

		if (min > a) {
			min = a;
		}

		if (max < a) {
			max =a;
		}

		sum += a;
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = s.length();
  int m = t.length();
  int res = 1e9;
  for (int i = 0; i <= n - m; i++) {
    int k = 0;
    int diff = 0;
    for (int j = i; j < i + m; j++) {
      if (s[j] != t[k])
        ++diff;
      ++k;
    }
    res = min(res, diff);
  }   
  cout << res << '\n';
  return 0;
}

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

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

		int n = sc.nextInt();
		long k = sc.nextLong();
		int q = sc.nextInt();

		long ten[] = new long[n + 1];
		Arrays.fill(ten, k - q);

		for (int i = 0; i < q; i++) {
			ten[sc.nextInt()]++;
		}
		for (int i = 1; i <= n; i++) {
			if (ten[i] > 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}

	}
}

Measured memory_bytes: 60064
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,K=map(int,input().split())
for i in range(1,K+1):
  if(N-K+1>=i):
    a=comb(N-K+1,i)%(10**9+7)
    b=comb(K-1,i-1)%(10**9+7)
    print((a*b)%(10**9+7))
  else:
    print("0")

Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
    int A, B;
    scanf("%d %d",&A,&B);
    if(B % 2 ==0)
    {
        if (A<=5)
        {
            printf("0\n");
        }
        else if(A>5 && A<13)
        {
            printf("%d\n",B/2);
        }
        else
        {
            printf("%d",B);
        }

    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<boost/range/irange.hpp>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/algorithm/string/classification.hpp>
#include<boost/algorithm/string/split.hpp>
#include<boost/algorithm/string/join.hpp>
#include<boost/algorithm/string/replace.hpp>
#include<boost/math/tools/minima.hpp>
#include<boost/pending/disjoint_sets.hpp>
using namespace std;
using boost::irange;
using boost::multiprecision::cpp_int;
using boost::algorithm::split;
using boost::is_any_of;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::math::tools::brent_find_minima;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}
int main(){
    int n, k, ans = 0;
    cin >> n >> k;
    //vector<int>h(n);
    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        if(h >= k)ans += 1;
    }
    cout << ans << endl;
}   



Measured memory_bytes: 256
from itertools import accumulate as ac

N, K = map(int, input().split())
*S, = map(int, input())

l = []
c0, c1 = 0, 0

prev = 0
for i, j  in enumerate(S):
    if i==0:
        if j==0:
            c0 += 1
        else:
            c1 += 1
    else:
        if prev!=j:
            if prev==1:
                l.append(c1)
                c1 = 0
            else:
                l.append(c0)
                c0 = 0
        if j==0:
            c0 += 1
        else:
            c1 += 1
    prev = j

if c0:
    l.append(c0)
if c1:
    l.append(c1)

if S[0]==0:
    l = [0]+l
if S[-1]==0:
    l.append(0)

size = len(l)
accum = list(ac([0]+l))
start = min(2*K+1,size)

ans = 0
for i in range(start, size+1, 2):
    ans = max(ans, accum[i]-accum[i-start])
print(ans)

Measured memory_bytes: 9996
import Control.Applicative
import Control.Monad
 
main :: IO ()
main = do
    [a, b] <- map read . words <$> getLine
    putStrLn $ show (solve a b)
    
solve :: Int -> Int -> Int 
solve a b = if a <= 5 then 0
            else if a <= 12 then div b 2
            else b

Measured memory_bytes: 508
n=int(input())
s=input()

count=0
rgb={'R':0, 'G':0, 'B':0}
for i in range(n):
  rgb[s[i]]+=1

count=rgb['R']*rgb['G']*rgb['B']

if n<=3:
  print(0)
  exit()

for sa in range(1,(n-1)//2+1):
  for i in range(n-2*sa):
    j=i+sa
    k=j+sa
    if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
      count-=1

print(count)

Measured memory_bytes: 9152
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n ; cin >> n ;
	vll a(n+1,2) ;
	a.at(1) = 1 ;
	for(int i=2;i<=n;i++){
		a.at(i) = a.at(i-1)+a.at(i-2) ;
	}
	cout << a.at(n) << endl ;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
set<int>s1;
set<int>s2;
set<int>s3;
int main(void)
{
    s1.insert(1);
    s1.insert(3);
    s1.insert(5);
    s1.insert(7);
    s1.insert(8);
    s1.insert(10);
    s1.insert(12);
    s2.insert(4);
    s2.insert(6);
    s2.insert(9);
    s2.insert(11);
    s3.insert(2);
    int x,y;
    cin>>x>>y;
    if(s1.count(x)==1&&s1.count(y)==1)
    {
        cout <<"Yes"<<endl;
    }
    else if(s2.count(x)==1&&s2.count(y)==1)
    {
        cout <<"Yes"<<endl;
    }
    else if(s3.count(x)==1&&s3.count(y)==1)
    {
        cout <<"Yes"<<endl;
    }
    else
    {
        cout <<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define ni(n) scanf("%d", &n)
#define nl(n) scanf("%I64d", &n)
#define nai(a,n) for (int i = 0; i < (n); i++) ni((a)[i])
#define nal(a,n) for (int i = 0; i < (n); i++) nl((a)[i])
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 2e3 + 5;
const double eps = 1e-9;
using namespace std;
int arr[MAXN][MAXN][2];
int sum[MAXN][MAXN][2];

int main()
{
    int n, k;
    ni(n), ni(k);
    int w = 0, b = 0;
    for (int i = 0; i < n; i++)
    {
        int x, y;
        string c;
        ni(x), ni(y);
        cin >> c;
        x = x % (2 * k);
        y = y % (2 * k);
        if (c[0] == 'W') arr[x][y][0]++, w++; else arr[x][y][1]++, b++;
    }
    for (int i = 0; i < 2 * k; i++)
    {
        for (int j = 0; j < 2 * k; j++)
        {
            sum[i][j][0] = arr[i][j][0];
            if (i && j) sum[i][j][0] += sum[i - 1][j][0] + sum[i][j - 1][0] - sum[i - 1][j - 1][0];
            else if (i) sum[i][j][0] += sum[i - 1][j][0];
            else if (j) sum[i][j][0] += sum[i][j - 1][0];

            sum[i][j][1] = arr[i][j][1];
            if (i && j) sum[i][j][1] += sum[i - 1][j][1] + sum[i][j - 1][1] - sum[i - 1][j - 1][1];
            else if (i) sum[i][j][1] += sum[i - 1][j][1];
            else if (j) sum[i][j][1] += sum[i][j - 1][1];
        }
    }
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < k; j++)
        {
            int ux = i + k - 1, uy = j + k - 1;
            int cnt1 = sum[ux][uy][0];
            if (j) cnt1 -= sum[ux][j - 1][0];
            if (i) cnt1 -= sum[i - 1][uy][0];
            if (i && j) cnt1 += 2 * sum[i - 1][j - 1][0];
            if (j) cnt1 += sum[2 * k - 1][j - 1][0] - sum[ux][j - 1][0];
            if (i) cnt1 += sum[i - 1][2 * k - 1][0] - sum[i - 1][uy][0];
            cnt1 += sum[2 * k - 1][2 * k - 1][0] - sum[2 * k - 1][uy][0] - sum[ux][2 * k - 1][0] + sum[ux][uy][0];

            int cnt2 = sum[ux][uy][1];
            if (j) cnt2 -= sum[ux][j - 1][1];
            if (i) cnt2 -= sum[i - 1][uy][1];
            if (i && j) cnt2 += 2 * sum[i - 1][j - 1][1];
            if (j) cnt2 += sum[2 * k - 1][j - 1][1] - sum[ux][j - 1][1];
            if (i) cnt2 += sum[i - 1][2 * k - 1][1] - sum[i - 1][uy][1];
            cnt2 += sum[2 * k - 1][2 * k - 1][1] - sum[2 * k - 1][uy][1] - sum[ux][2 * k - 1][1] + sum[ux][uy][1];
            ans = max(ans, max(cnt1 + b - cnt2, cnt2 + w - cnt1));
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  ll N;
  cin >> N;

  map<ll, ll> m;
  rep(i, N) {
    ll a;
    cin >> a;
    m[a]++;
  }

  ll ans = 0;
  for (auto mm : m) {
    if (mm.first == mm.second) continue;
    if (mm.first < mm.second) {
      ans += mm.second - mm.first;
    } else {
      ans += mm.second;
    }
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 9644
n,m = gets.split.map{|tmp|tmp.to_i}
counter = Array.new(n+1,0)
m.times do |i|
    a,b = gets.split.map{|tmp|tmp.to_i}
    counter[a] += 1
    counter[b] += 1
end
(1..n).each do |i|
    puts counter[i]
end

Measured memory_bytes: 1788
#include "stdio.h"

int main()
{
	int tall[3];
	for (int i=0; i<3; i++) {
		scanf("%d",&tall[i]);
	}

	if ((tall[1] - tall[0]) == (tall[2] - tall[1]))
		printf("YES");
	else
		printf("NO");

    return 0;
}

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

using namespace std;

int main(void){
  int a[5];

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

  for (int i = 0; i < 2; i++){
    for (int j = i; j < 2; j++){
      if (a[i] > a[j + 1]){
        int tmp = a[i];
        a[i] = a[j + 1];
        a[j + 1] = tmp;
      }
    }
  }

  cout << a[0];
  for (int i = 1; i < 3; i++){
    cout << " " << a[i];
  }
  cout << "\n";
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;	cin >> s;
	string t = "CODEFESTIVAL2016";
	int ret = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i])	ret++;
	}
	cout << ret << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    int N, X; cin >> N >> X;
    vector<int> L(N); REP(i, N) cin >> L[i];
    int cnt = 1;
    int l = 0;
    REP(i, N) {
        l = l + L[i];
        if(l > X) break;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int INF = INT_MAX / 2;

int solve(const string& s, const string& t)
{
    int n = s.size();
    vector<vector<int> > cost(n+1, vector<int>(n+1, 0));
    for(int i=n; i>=0; --i){
        for(int j=n; j>=0; --j){
            if(i < n && j < n){
                cost[i][j] = cost[i+1][j+1];
                if(s[i] == t[j])
                    ++ cost[i][j];
            }
        }
    }

    vector<vector<int> > dp(n+1, vector<int>(n+1, INF));
    dp[0][0] = 0;
    for(int i=0; i<=n; ++i){
        for(int j=0; j<=n; ++j){
            if(i < n)
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + cost[i][j]);
            if(j < n)
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + cost[i][j]);
        }
    }
    return dp[n][n];
}

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> c(w, string(h, ' '));
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            cin >> c[x][h-1-y];
        }
    }

    int ans = 0;
    for(int i=0; i<w-1; ++i)
        ans += solve(c[i], c[i+1]);
    cout << ans << endl;

    return 0;
}

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

int main() {
    long long t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    if (t1 * a1 + t2 * a2 > t1 * b1 + t2 * b2) {
        swap(a1, b1);
        swap(a2, b2);
    }
    if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) {
        cout << "infinity";
    } else if (a1 < b1) {
        cout << 0;
    } else {
        long long top = t1 * (a1 - b1), bot = t1 * (b1 - a1) + t2 * (b2 - a2);
        long long result = 2 * (top / bot);
        if (top % bot != 0) {
            result++;
        }
        cout << result;
    }
    return 0;
}


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

char arr[1002];
int dir[5];

int main(){
    scanf("%s",arr);
    for(int i=0; i<strlen(arr); i++){
        if(arr[i]=='N')
            dir[0]=1;
        if(arr[i]=='S')
            dir[1]=1;
        if(arr[i]=='E')
            dir[2]=1;
        if(arr[i]=='W')
            dir[3]=1;
    }
    if(dir[0] == dir[1] && dir[2] == dir[3])
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

int main(){
  int n,m,t;
  cin>>n>>m>>t;
  int a[n],td=t,nd=n;
  for(int i=0;i<nd;i++){
    cin>>a[i];
    if(i!=0 && a[i]-a[i-1]<2*m){t-=(a[i]-a[i-1]); n-=1;}
  }
  if(a[nd-1]+m>td){t+=a[nd-1]+m-td;}
  t-=n*m*2;
  cout<<t<<endl;
  
  return 0;
}



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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define MOD 1000000007
#define int ll
int N;
#define maxn 200001

map <pi,int64_t> num;

ll pow2[maxn];



pi simp(pi x){
	if (x.s < 0) x.f = -x.f, x.s = -x.s;
	
	int a = __gcd(abs(x.f),abs(x.s));
	return pi(x.f/a,x.s/a);
}

int num00=0;
int numA0=0,numB0=0;

int32_t main(){
	fast;
	
	cin>>N;
	
	set <pi> S;
	
	FOR(i,1,N){
		ll a,b;
		cin>>a>>b;
		if (a == 0 && b == 0){
			num00++;
			continue;
		}
		if (a == 0){
			numA0++;
			continue;
		}
		if (b == 0){
			numB0++;
			continue;
		}
		pi res = simp(pi(a,b));
		num[res]++;
		if (res.f < 0) S.insert(pi(res.s,-res.f));
		else S.insert(res);
	}

	pow2[0] = 1;
	FOR(i,1,N) pow2[i] = (pow2[i-1] * 2) % MOD;
	
	ll ans = 1;
	aFOR(i,S){
		pi cur = i;
		
		pi x = pi(-cur.s,cur.f);
		if (x.s < 0) x.f = -x.f, x.s = -x.s;

		ans *= (pow2[num[i]] + pow2[num[x]] - 1 + MOD) % MOD;
		ans %= MOD;
	}

	ans *= (pow2[numA0] + pow2[numB0] - 1 + MOD) % MOD;
	ans %= MOD;
	cout<<(ans + num00 - 1 + MOD) % MOD;
}



Measured memory_bytes: 42640
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int N,K,X,Y; cin >>N >>K >>X >>Y;

  int ans=0;

  if (K<N) {
    rep_eq(i,1,K) {ans+=X;}
    rep_eq(i,1,N-K) {ans+=Y;}
  } else if (N<=K) {
    rep_eq(i,1,N) {ans+=X;}
  }

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


Measured memory_bytes: 256