akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
n = int(input())
t,a = map(int,input().split())
h = list(map(int, input().split()))

ans = 0
ansc = 999999

for i in range(len(h)):
    c = abs(a - (t - h[i] * 0.006))
    if c < ansc:
        ansc = c
        ans = i + 1

print(ans)


Measured memory_bytes: 9168
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val k = in.readLine().toInt
    val s = in.readLine()

    out.println(
      if (s.length <= k) {
        s
      } else {
        s.substring(0, k) + "..."
      }
    )

    out.flush()
  }
}


Measured memory_bytes: 54588
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

# https://www.youtube.com/watch?v=GXZZB5vO78c
n = I()
a = RI()
b = deepcopy(a)
b.sort(reverse=True)
# print(a)
# print(b)

ans = 0
j = 0
for i in range(n):
    if i==0:
        ans += 0
    elif i==1:
        ans += b[j]
    else:
        if i%2==0:
            j += 1
            ans += b[j]
        else:
            ans += b[j]
print(ans)

Measured memory_bytes: 110336
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long 
#define ld long double
#define MOD 1000000007
#define mod9 1000000009
#define mod 1000003
#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define test ll t;cin>>t;while(t--)
#define bi begin()
#define ei end()
#define fi first 
#define se second  
#define forn(a,b) for(ll i=a;i<b;i++)
#define sz(s) s.size()     
#define pi 3.14159265358979323846
#define sp(x) cout<<fixed<<setprecision(x)
//ld round(ld var) 
//{ 
//    // 37.66666 * 100 =3766.66 
//    // 3766.66 + .5 =3767.16    for rounding off value 
//    // then type cast to int so value is 3767 
//    // then divided by 100 so the value converted into 37.67 
//    ld value = (int)(var * 100 + .5); 
//    return (ld)value / 100; 
//} 
int main()
{
	   ll n,k;
	   cin>>n>>k;
	   set<ll>s;
	   while(k--)
	   {
	   		ll d1;cin>>d1;
	   		while(d1--)
	   		{
	   			ll a;
	   			cin>>a;
				   s.insert(a);	
			}
	   }
	   cout<<n-s.size()<<endl;
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] p = new int[N];
    for (int i = 0; i < N; i++) p[i] = scanner.nextInt();

    int c = 0;
    int res = 0;
    for (int i = 0; i < N; i++) {
      if (p[i] == i + 1) {
        c++;
      } else {
        res += (c + 1) / 2;
        c = 0;
      }
    }
    res += (c + 1) / 2;
    System.out.println(res);
  }
}


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

int main()
{
    double t, n, i, x, sum;
    vector <double> N;
    cin >> t;
    for(i=0;i<t;i++)
    {
        cin >> n;
        N.push_back(n);
    }
    sort(N.begin(), N.end());
    sum = N[0];
    for(i=0;i<t-1;i++)
    {
        {
            x = (N[i] + N[i+1])/2;
            N[i+1] = x;
        }
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
data = input().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])

if a > b or a < 1 or c > 10000:
	exit()

cnt = 0
for num in range(a,b+1):
	if (c%num) == 0:
		cnt += 1
print(cnt)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  int c;
  while(1){
  c=a%b;
  if(c==0)
    return b;
  a=b;
  b=c;
  }
}
int main() {
  int n,a[111111],i;
  cin>>n;
  for(i=0;i<n;i++)
    cin>>a[i];
  int ans=a[0];
  for(i=1;i<n;i++)
    ans=gcd(a[i],ans);
  cout<<ans<<endl;
}

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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
        long long n,m;cin >> n >> m;
        int a[n],b[n],c[m],d[m];
        rep{
                cin >> a[i] >> b[i];
        }
        for(int i = 0;i<m;i++){
                cin >> c[i] >> d[i];
        }
        //for(int i = 0;i<n;i++){cout << a[i] << " " << b[i] << endl;}
        //for(int i = 0;i<m;i++){cout << c[i] << " " << d[i] << endl;}
        rep{
                int ans = 1;long long mindis = 10000000000;
                //それぞれのポイントとのマン距離を計算して、最小（近い）ポイントの番号を出力
                for(int j = 0;j<m;j++){
                        long long disi = abs(a[i]-c[j]) + abs(b[i]-d[j]);
                        if(disi<mindis){
                                mindis = disi;ans = j+1;
                        }
                }
                cout << ans << endl;
        }
}

Measured memory_bytes: 256
import java.util.*;

import java.io.*;

public class Main {

	static int n;
	static long memo[][];
	static int p;
	static int pl[][];
	static pair[] a;
	static int k;

	public static long dp(int msk, int idx) {
		if (idx == n)
			return 0;
		if (memo[msk][idx] != -1)
			return memo[msk][idx];
		long max = k - (idx - Integer.bitCount(msk)) > 0 ? dp(msk, idx + 1) + a[idx].x : dp(msk, idx + 1);

		for (int i = 0; i < p; i++) {
			if (((msk >> i) & 1) == 0) {
				max = Math.max(max, pl[a[idx].y][i] + dp(msk | 1 << i, idx + 1));
			}
		}
		return memo[msk][idx] = max;

	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		long a=Long.parseLong(st.nextToken());
		long b=Long.parseLong(st.nextToken());
		int lo=1;
		int hi=10000;
		int ans=-1;
		for (int i = 0; i < 100000; i++) {
			
			int x=(int) (i*0.08);
			int y=(int) (i*0.1);
			if(x==a&&y==b) {
				ans=i;
				break;
			}
		}
		
		System.out.println(ans);
	}
	

	static int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static class pair {
		int x;
		int y;

		pair(int r, int t) {
			x = r;
			y = t;
		}

		public String toString() {
			return "(" + x + "," + y + ")";
		}

	}
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define N 100000
#define inf 1e9+7
using namespace std;
typedef vector <int> vi;
int n, k;
vi iv(N,inf);

int calculation(int l, int r, int s){
    vi cost(N,0);
    vi target(N,inf);
    target[r] = -1;
    for (int i = r - 1; i >= l; i--){
        cost[i] = inf;
        target[i] = inf;
        for (int st = 1; st <= s; st++){
            int ts = abs(iv[i] - iv[i+st]) + cost[i+st];
            target[i] = (cost[i]<ts)? target[i] : i+st;
            cost[i] = (cost[i]<ts)? cost[i] : ts;
        }
    }
    return cost[l];
}

int main(){
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> iv[i];
    }
    cout << calculation(0,n-1,k);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define INF 100005
#define MOD 1000000007

int main()
{
    //freopen("output.txt","r",stdin);
    //freopen("input.txt","r",stdin);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    int aa=0;
    int bb=n;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin >> a >> b;
        aa=max(aa,a);
        bb=min(bb,b);
    }
    int ans=bb-aa+1;
    if(ans<0) ans=0;
    cout << ans << endl;
}


Measured memory_bytes: 256
import math
def resolve():
    A, B, H, M = map(int, input().split())

    hr = H/12 + (M/60)/12
    mr = M/60
    rad = math.pi * 2 * (hr-mr)
    req = (A*A + B*B) - (2*A*B) * math.cos(rad)
    print(req**0.5)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9512
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    K = int(input())
    S = input().rstrip('\n')

    if len(S) <= K:
        print(S)
    else:
        print(S[:K] + "...")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62092
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
static constexpr int SZ = 323456;
int basepow[2][SZ];
struct RollingHash{
    static constexpr int mod = 1e9+7;
    static const int basemod[2];
//    int basepow[2][SZ];
    vector<int> pre[2];
    const string s;
    const int n;
    void make(){
        rep(i,2){
            basepow[i][0] = 1;
            rep(j,SZ-1){
                basepow[i][j+1] = (long long)basepow[i][j] * basemod[i] % mod;
            }
        }
    }
    RollingHash(const string &_s) : s(_s),n((int)s.size()){
        if(!basepow[0][0])make();
        pre[0].resize(n + 1);
        pre[1].resize(n + 1);
        rep(i,2){
            rep(j,n){
                pre[i][j+1] =((long long)pre[i][j] * basemod[i] % mod + (int)s[j]) % mod;
            }
        }
    }
    // [l,r)
    ll cal_hash(int l, int r){
        ll a = (pre[0][r] - (long long)pre[0][l] * basepow[0][r-l] % mod + mod) % mod;
        ll b = (pre[1][r] - (long long)pre[1][l] * basepow[1][r-l] % mod + mod) % mod;
        return (ll)(a<<30) + b;
    }
    static ll cal(const string &t){
        ll temp[2] = {};
        rep(i,t.size()){
            rep(j,2){
                temp[j] = (temp[j] * basemod[j] + (ll) t[i]) % mod;
            }
        }
        return (ll)(temp[0]<<30) + temp[1];
    }
};
const int RollingHash::basemod[]= {1007, 1000000021};
int n;
string s;
bool ok(int k,RollingHash &rh){
    map<ll,int> mp;
    for(int i = 0; i < n - k + 1; i++){
        show(i,k);
        ll h = rh.cal_hash(i,i+k);
        if(mp.count(h)){
            if(mp[h] <= i - k)return true;
        }else{
            mp[h] = i;
        }
    }
    return false;
}
int main(){
    cin >> n >> s;
    int l = 0;
    int r = n;
    RollingHash rh(s);
    while(r - l >1){
        int mid = (l + r) / 2;
        if(ok(mid,rh)){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout << l << endl;
}


Measured memory_bytes: 3072
import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

// void main(string[] args)でもいい.
void main() {
  auto ab = readln.split.to!(int[]);
  writeln(ab[0] * ab[1]);
}


Measured memory_bytes: 2728
N, Q = map(int, input().split())
S = input()

cnt = [0] * 200010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 200010
flag = [0] * 200010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 :
        ans -= 1
    print("{}".format(ans))

Measured memory_bytes: 14740
S = input()
ans = True
if S[0]!='A':
    ans = False
    print("WA")
else:
    S = S.replace('A', '')

if ans:
    tmp = False
    for c in S[1:-1]:
        if c=='C':
            if not tmp:
                tmp = True
            else:
                ans = False
                print("WA")
                break
    if not tmp:
        ans = False
        print("WA")

if ans:
    S = S.replace('C', '')

if ans:
    tmp = True
    for c in S:
        if not (ord(c)>=97 and ord(c)<123):
            tmp = False
    if not tmp:
        print("WA")
        ans = False

if ans:
    print("AC")






Measured memory_bytes: 3064
function main()
	lines=readlines()
	N,H=map(x->parse(Int,x),split(shift!(lines)))
	A=Array{Int}(0)
	B=Array{Int}(0)
	for s=lines
		a,b=map(x->parse(Int,x),split(s))
		push!(A,a)
		push!(B,b)
	end
	a=maximum(A)
	ans=0
	sort!(B)
	reverse!(B)
	for b=B
		if b<a||H<=0
			break
		end
		H-=b
		ans+=1
	end
	println(ans+cld(max(H,0),a))
end
main()


Measured memory_bytes: 154648
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
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&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    string s;
    cin>s;
    int n=s.size();
    int mi=INF;
    int c=0;
    REP(i,n){
        if((s[i]=='1' )==i%2)c++;
    }
    chmin(mi,c);
    c=0;
    REP(i,n){
        if((s[i]=='1' )!=i%2)c++;
    }
    chmin(mi,c);
    cout<mi<endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define resort(v) sort((v).rbegin(), (v).rend())
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int modpow(int a, int n, int mod) {
    int hi = 1;
    while (n > 0) {
        if (n & 1) hi = hi * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return hi;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

/*signed*/int main(void) {
    ld d, t, s;
    cin >> d >> t >> s;
    if (d / s > t) {
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int c=0;
  int sum=0;
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]) c++;
    if(a[i]!=a[i+1]){
      sum+=(c+1)/2;
      c=0;
    }
  }
  sum+=(c+1)/2;
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>

void swap(char& left, char& right)
{
  char temp = left;
  left = right;
  right = temp;
}

void reverse(char* arr, int begin, int end)
{
  int i = begin, k = end;
  while (i < k)
  {
    k -= 1;
    swap(arr[i], arr[k]);
    i += 1;
  }
  for (int j = begin; j < end; j += 1)
    arr[j] = (arr[j] == 'L' ? 'R' : 'L');
}

long long count_happy(char* arr, int length)
{
  long long res = 0;
  for (int i = 1; i < length; i += 1)
    if (arr[i] == arr[i - 1])
      res += 1;
  return res;
}

void print(char* queue, int n)
{
  for (int i = 0; i < n; i += 1)
    std::cout << queue[i];
  std::cout << "\n";
}

int main()
{
  int n, k;
  std::cin >> n >> k;
  char* queue = new char[n];
  for (int i = 0; i < n; i += 1)
    std::cin >> queue[i];
  
  for (int i = 1; i < n && k > 0; i += 1)
    if (queue[i] != queue[i - 1])
      for (int j = i + 2; j < n; j += 1)
        if (queue[j - 1] == queue[i] && queue[j] == queue[i - 1])
        {
          reverse(queue, i, j);
          //std::cout << "[" << i + 1 << ", " << j << "]: ";
          //print(queue, n);
          k -= 1;
          break;
        }

  for (int i = 1; i < n - 1 && k > 0; i += 1)
    if (queue[i] != queue[i - 1] && queue[i] != queue[i + 1])
    {
      k -= 1;
      reverse(queue, i, i + 1);
    }

  for (int i = 1; i < n && k > 0; i += 1)
    if (queue[i] != queue[i - 1])
    {
      k -= 1;
      if (queue[i - 1] == queue[0])
      {
        reverse(queue, 0, i);
        //std::cout << "[" << 1 << ", " << i  << "]: ";
        //print(queue, n);
      }
      else if (queue[i] == queue[n - 1])
      {
        reverse(queue, i, n);
        //std::cout << "[" << i + 1 << ", " << n << "]: ";
        //print(queue, n);
      }
      else
        k += 1;
    }

  //std::cout << k << " " << count_happy(queue, n);
  std::cout << count_happy(queue, n);
  delete[] queue;
  return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
    string S, T;
    cin >> S >> T;

    int minChange = 20000;
    for (size_t i=0; i<=S.size()-T.size(); ++i) {
        int change = 0;
        for (size_t j=0; j<T.size(); ++j) {
            if (S[i+j] != T[j])
                ++change;
        }
        minChange = min(change, minChange);
    }
    cout << minChange << endl;
}



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

const int maxn = 1e5 + 10;
long long a[maxn], ans[maxn];

int main() {
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  #endif
  ios::sync_with_stdio(false);
  int n, sign = 1;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = n; i >= 2; --i) ans[2] += a[i] * sign, sign *= -1;
  ans[2] = (ans[2] - a[1]) / -2;
  ans[1] = a[1] - ans[2];
  for (int i = 3; i <= n; ++i) ans[i] = a[i - 1] - ans[i - 1];
  for (int i = 1; i <= n; ++i) cout << ans[i] * 2 << ' ';
  return 0;
}

Measured memory_bytes: 2944
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        while(k > 0 && b <= a){
            b *= 2;
            k--;
        }
        while(k > 0 && c <= b){
            c *= 2;
            k--;
        }
        if(b > a && c > b)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

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

typedef unsigned long long ll;
#define mod 1000000007
#define all(x) (x).begin(),(x).end()

void solve(){
  ll n,d;
  cin>>n>>d;
  //vector<pair<int,int>> v(n);
  double p1,p2,cnt=0;
  double sum=0;
  for(int i=0;i<n;i++){
  	cin>>p1>>p2;
  	sum = (p1*p1)+(p2*p2);
  	if(sum<=(d*d)){
  		cnt++;
	  }
  }
  cout<<cnt<<endl;  
}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}

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

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

  cin >> x >> k >> d;

  if (abs(x) / d <= k) {
    k = k - (abs(x) / d);
    x = abs(x) % d;
  } else {
    cout << abs(x) - (d * k);
    return 0;
  }

  if (k % 2 == 0) {
    cout << x;
  } else {
    if (abs(x - d) < abs(x + d)) {
      cout << abs(x - d);
    } else {
      cout << abs(x + d);
    }
  }

  return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void MAIN() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int ans = 1e18;
  for (int i = 0; i < n - k + 1; i++) {
    int t = a[i + k - 1] - a[i];
    t += min(abs(a[i]), abs(a[i + k - 1]));
    ans = min(ans, t);
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3976
import java.util.Scanner;

public class Main {
	static Scanner scan = new Scanner(System.in);
	public static void main(String[] a) {
		for (int i = 1; i <= 9; ++i) {
			for (int j = 1; j <= 9; ++j) {
				print(i + "x" + j + "=" + i * j);
			}
		}
	}
	
	public static void print(Object out) {
		System.out.println(out);
	}
}

Measured memory_bytes: 17136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a;cin>>n;
  double div=0.0;
  rep(i,n) {cin>>a;div+=1.0/a;}
  printf("%.7f\n",1.0/div);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

 
public class Main {

	static long mod = (long) (Math.pow(10, 9) + 7);
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long n  = sc.nextLong();
		
		long temp1 = (power(9, n) + power(9, n) - power(8, n)) % mod; 
		long ans = (power(10, n) - temp1) % mod;
		ans = ans % mod;
		System.out.println((ans + mod)% mod);
		sc.close();
	}
	
	private static long power(long x, long y) {
		long culc = 1;
		
		for(long i = 0; i < y; i++) {
			culc = culc * x % mod; 
		}

		return culc;
	}
}




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

int main() {
  string s;
  cin>>s;
  int n=s.size()/2;
  for(int i=n-1;i>0;i--){
    string t=s.substr(0,i);
    string u=s.substr(i,i);
    if(t==u){
      cout<<t.size()*2<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1],X[N][N];


void initialize()
{
  int i;
  for(i=0 ; i<N ; i++)
    {
      row[i] = FREE;
      col[i] = FREE;
    }
  for(i=0 ; i<2*N-1 ; i++)
    {
      dpos[i] = FREE;
      dneg[i]=FREE;
    }
    return;
}

void printBoard()
{
  int i,j;
  for(i=0 ; i<N ;i++)
    {
      for(j=0 ; j<N ; j++)
        {
          if(X[i][j])
            {
              if(row[i] != j) return;
            }
        }
    }
    for(i=0 ; i<N ; i++)
      {
        for(j=0 ; j<N ; j++)
          {
            if(row[i] == j) printf("Q");
            else printf(".");
          }
          printf("\n");
      }

      return;
  }

  void recursive(int i)
  {
    int j;
    if (i == N) {
      printBoard();
      return;
    }
    for(j=0 ; j<N ; j++)
    {
      if(NOT_FREE == col[j] || NOT_FREE == dpos[i+j] || NOT_FREE ==dneg[i-j+N-1]) continue;
      row[i]=j;
      col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
      recursive(i+1);
      row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    }
    return;
  }

  int main()
  {
    int i,j,k,r,c;
    initialize();

    for(i=0 ; i<N ; i++)
    {
      for(j=0 ; j<N ; j++)
      {
        X[i][j] = 0;
      }
    }

    scanf("%d",&k);
    for(i=0 ; i<k ; i++){
      scanf("%d %d",&r,&c);
      X[r][c]=1;
    }
    recursive(0);
    return 0;
  }



Measured memory_bytes: 2104
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
lis = [a, b, c, d, e]
for i in lis:
    for j in lis:
        if i - j > k:
            print(':(')
            exit()
print('Yay!')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int current = 1;
		int answer = 0;
		boolean isAble = false;

		for (int i = 0; i < N; i++) {
			int a = scan.nextInt();
			if (a != current) answer++;
			else {
				isAble = true;
				current++;
			}
		}

		System.out.println(isAble ? answer : "-1");
	}
}

Measured memory_bytes: 63364
n, m = gets.split.map(&:to_i)
a, b = m.times.map { gets.split.map(&:to_i) }.transpose

ans = Array.new(n + 1, 0)
m.times do |i|
  ans[a[i]] += 1
  ans[b[i]] += 1
end

puts ans[1..n]

Measured memory_bytes: 1916
def main():
  X, N = map(int, input().split())

  if N == 0:
    return print(X)

  P = list(map(int, input().split()))

  P2 = set([abs(p-X) for p in P])
  #print(P2)
  for i in range(101):
    ans1 = X - i
    ans2 = X + i
    #print(i, ans1, ans2)
    if ans1 not in P:
      print(ans1)
      return
    if ans2 not in P:
      print(ans2)
      return
  
main()

Measured memory_bytes: 9196
# 117b

def atc_117b(N: int, Li_input: str) -> str:
    Li = [int(i) for i in Li_input.split(" ")]
    Li = sorted(Li)
    max_length = Li.pop()
    if max_length < sum(Li):
        return "Yes"
    return "No"

N_input_value = int(input())
Li_input_value = input()
print(atc_117b(N_input_value, Li_input_value))


Measured memory_bytes: 9116
n=int(input())
#s=[int(x) for x in input()]+[i for i in range(10)]*3
s=[int(x) for x in input()]
cnt=0
for i in range(10):
 for j in range(10):
  for k in range(10):
   try:
    inx1=s.index(i)
   except:
    continue
   try:
    inx2=s[inx1+1:].index(j) + inx1 +1
   except:
    continue
   try:
    inx3=s[inx2+1:].index(k) + inx1 + inx2 +2
   except:
    continue
   cnt+=1
print(cnt)

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

using namespace std;
using namespace __gnu_pbds;

#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pii x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<cd> vcd;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pii>> vvpii;
typedef vector<vector<pll>> vvpll;
typedef unordered_map<int, int, int_hash> umpii;
typedef unordered_map<ll, ll, int_hash> umpll;
typedef unordered_set<int, int_hash> usi;
typedef unordered_set<ll, int_hash> usll;
typedef unordered_set<pii, pair_hash> uspii;
typedef queue<int> qi;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = numeric_limits<int>::max();
const int MX = 100001; //check the limits, dummy

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

    int r; cin >> r;
    cout << r * r << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

A.sort()

maxv = A[-1]
minv = A[0]

cash = set()
ok = set()
ans = 0
p = set()

for i in A:
    if i in cash:
        if i in p:
            ans -= 1
            p.remove(i)
        continue

    else:
        # print("NI:", i)
        # print("CUR:cash", cash)
        p.add(i)

        ans += 1

        c = 1
        cur = i

        while cur <= maxv:
            cash.add(cur)
            c += 1
            cur = i * c
# print(cash)
# print(p)
print(ans)


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

using namespace std;

int a;
int a_n[100001];
int N;
int main() {
  cin >> N;
  
  int MIN = 1000000;
  int MAX = 0;
  
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    a_n[a]++;
    MIN = min(MIN,a);
    MAX = max(MAX,a);
  }

  if(MAX - MIN > 1) {
    cout <<"No" <<endl; return 0;
  }

  if(MAX == MIN) {
    if(MAX == N - 1 || MAX <= N / 2) {
      cout << "Yes" <<endl;
      return 0;
    }
  }

   if(MAX - MIN == 1) {
     if(a_n[MIN] > MIN) {
       cout << "No" <<endl;
       return 0;
     }
     if(a_n[MAX] >= 2 * (MAX - a_n[MIN])) {
      cout << "Yes" <<endl;
      return 0;
    }
   }
   cout << "No" <<endl;
}
  

  


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e9+7
#define LINf 1e18+7
#define fr first 
#define sc second
#define ll long long
#define pb push_back
#define pii pair<int,int>

using namespace std;
ll n, w, wh[105] , val[105], dp[105][100005];
int main(){
	cin >> n >> w;
	for(int i = 1 ;i<= n; i++){
		cin >> wh[i] >> val[i];
	}
	for(int j = 1 ; j <= n; j++){
		for(int k = 1; k <= 100000 ; k++){
			dp[j][k] = dp[j-1][k];
			if(k >= wh[j]){
				dp[j][k] = max(dp[j][k],dp[j-1][k-wh[j]] + val[j]);
			}
		}
		for(int i = 1 ; i <= 100000 ; i++){
			dp[j][i] = max(dp[j][i-1],dp[j][i]);
		}
	}
	cout << dp[n][w];
}

Measured memory_bytes: 79360
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop
import bisect


"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""


X, N = map(int,input().split())

if N == 0:
  print(X)
  exit()

P = list(map(int,input().split())) 

  
current = 10000 ## big number
ans = 0
for i in range(0, 102):
  if i in P:
    continue
  else:
    var = abs(i - X)
    if current > var:
      current = var
      ans = i
    #print(i, var, ans)
    
print(ans)

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

int main(){
  int H, W;
  cin >> H >> W;
  string a[H];
  for (int i = 0; i < H; i++) cin >> a[i];
  
  bool x[W]={}, y[H]={};
  // cout << ' ';  for (bool j : x) cout << j << ' ';  cout << endl;  for (bool i : y) cout << i << endl;   cout << endl; 
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] == '#') {
        y[i] = true;
        x[j] = true;
      }
      // cout << ' ';  for (bool j : x) cout << j << ' ';  cout << endl;  for (bool i : y) cout << i << endl;   cout << endl; 
    }
  }
  
  for (int i = 0; i < H; i++) {
    if (y[i] == false) continue;
    for (int j = 0; j < W; j++) {
      if (x[j] == true) {
        cout << a[i][j];
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
from collections import *
import sys
inp = raw_input

def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

def lis(X):
    N = len(X)
    P = [0]*N
    M = [0]*(N+1)
    L = 0
    for i in range(N):
        lo, hi = 1, L + 1
        while lo < hi:
            mid = (lo + hi) >> 1
            if X[M[mid]] >= X[i]:
                lo = mid + 1
            else:
                hi = mid
        newL = lo
        P[i] = M[newL - 1]
        M[newL] = i
        L = max(L, newL)
    S = [0]*L
    k = M[L]
    for i in range(L-1, -1, -1):
        S[i] = X[k]
        k = P[k]
    return S

N = ni()
A = [ni() for _ in range(N)]

print(len(lis(A)))


Measured memory_bytes: 14056
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    n, x = map(int, input().split())

    pb = [1]
    p = [1]
    for _ in range(n):
        pb.append(pb[-1] * 2 + 3)
        p.append(p[-1] * 2 + 1)

    ans = 0
    for _ in range(n):
        if x == 0:
            break
        if x >= pb[-2] + 2:
            x -= pb[-2] + 2
            ans += 1 + p[-2]
        else:
            x -= 1
        pb.pop(-1)
        p.pop(-1)

    if x >= 1:
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;

int main()
{

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

	ll n; cin >> n;
	string s; cin >> s;
	ll res = n * (n - 1) * (n - 2) / 6;

	for (int i = 0; i < n; i++) {
		for (int k = i + 2; k < n; k++) {
			if ((i + k) & 1) continue;
			int j = (i + k) / 2;
			if (s[i] == s[j] or s[i] == s[k] or s[j] == s[k]) continue;
			res -= 1;
		}
	}

	vector<ll> cnt(26);
	for (int i = 0; i < n; i++) {
		cnt[s[i] - 'A']++;
	}
	for (int i = 0; i < 26; i++) {
		res -= cnt[i] * (cnt[i] - 1) / 2 * (n - cnt[i]);
	}
	for (int i = 0; i < 26; i++) {
		res -= cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 6;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3640
import sys
input = sys.stdin.readline

n,m = (int(x) for x in input().split())
seq = [int(x) for x in input().split()]
g = dict((i, []) for i in range(1, n+1))
for i in xrange(m):
    a,b = (int(x) for x in input().split())
    try:
        g[a].append(b)
    except:
        g[a] = [b]
    try:
        g[b].append(a)
    except:
        g[b] = [a]
ans = 0
for key in g:
    H = seq[key-1]
    if len(g[key]) == 0:
        ans += 1
    else:
        for val in g[key]:
            if seq[val-1] >= H:
                break
        else:
            ans += 1
print(ans)


Measured memory_bytes: 107900
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;

long long dp[100005][4];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N;
	cin >> N;

	string S1,S2;
	cin >> S1 >> S2;

	vector<bool>isVertical;
	for (int i = 0; i < N; ++i) {
		if (S1[i] == S2[i])isVertical.push_back(true);
		else {
			isVertical.push_back(false);
			++i;
		}
	}
	
	long long ans = 3;
	bool before = false;
	for (int i = 0; i < isVertical.size();++i) {
		long long num = 1;
		if (i == 0) {
			if (!isVertical[i])num *= 2;
		}
		else {
			if (isVertical[i]) {
				if (before) num *= 2;
			}
			else {
				if (before)num *= 2;
				else num *= 3;
			}
		}

		ans = (ans * num) % MOD;
		before = isVertical[i];
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll x,t;cin>>x>>t;
    if(x-t>0){
        cout<<x-t<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 3528
#include<stdio.h>

int main(){
  int a[100]={};
  int x,i=0;
  int s=0;

  while(scanf("%d",&x)!=EOF){
    for(i=0;i<x;i++);
    a[i]++;
  }
  for(i=0;i<100;i++){
    if(s<a[i])
      s=a[i];
  }
  for(i=0;i<100;i++){
    if(s==a[i])
      printf("%d\n",i);
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    int n,ans=0,count=1;
    scanf("%d",&n);
    int a[n];
    for (int i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    for (int i=0; i<n; i++){
        if (a[i]==a[i-1]){
            count++;
        } else {
            if (count%2==0){
                ans+=count/2;
                count=1;
            } if (count%2==1 && count>1){
                ans+=count/2;
                count=1;
            }
        }
    }
    ans+=count/2;
    printf ("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
s=input()
c=True
if s[0]=='A':
  if 'C' in s[2:-1]:
    s=s.replace('A','',1).replace('C','',1)
    if s.islower()==True:
      c=False
if c==False:
  print('AC')
else:
  print('WA')
    

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

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
int main() {
    int n, X;
    cin >> n >> X;
    int x[n];
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        x[i] = abs(tmp - X);
    }
    int ans = x[0];
    for (int i = 0; i < n; i++) {
        ans = gcd(ans, x[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
def draw(h, w):
	for i in range(h):
		if i % 2 == 0:
			print(("#."*w)[:w])
		else:
			print((".#"*w)[:w])
	print("")


while True:
	H, W = map(int, input().split())
	if H == W == 0: break
	draw(H, W)

Measured memory_bytes: 7728
//g++ -std=c++14 test.cpp -o test.out
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

string S;

string ans = "";

void solve(){
    ans = S;
    if(S[S.size()-1]=='s') ans += "es";
    else ans += "s";
}
 
int main(){
	cin >> S;
 
    solve();

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

Measured memory_bytes: 3128
# -*- coding: utf-8 -*-

"""
参考：http://hamko.hatenadiary.jp/entry/2018/01/30/210057
　　　http://at274.hatenablog.com/entry/2018/02/03/140504
・重み付きUnion-Find木
"""

class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = - w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

N, M = map(int, input().split())

wuf = WeightedUnionFind(N)
for i in range(M):
    x, y, w = map(int, input().split())
    # 同じ集合に属する場合は
    if wuf.same(x, y):
        # 記録された距離と今回の情報に矛盾がないか確認
        if wuf.diff(x, y) != w:
            print('No')
            exit()
    wuf.union(x, y, w)
# 全部無矛盾で木が構築できればOK
print('Yes')


Measured memory_bytes: 11536
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		
		Scanner scan = new Scanner(System.in);
		
		int H = scan.nextInt();
		int W = scan.nextInt();
		
		
		//char[][] moji = new char[H][W];
		
		String[] moji = new String[H];
		
		
		
		
		
		for(int i = 0;i<H;i++){
				moji[i] = scan.next();
		}
		
		
		String[] kakudaimoji = new String[H+2];
		
		kakudaimoji[0] = "";
		kakudaimoji[H+1] = "";
		
		
		
		for(int i = 0;i<W+2;i++){
			
			kakudaimoji[0] +="#";
			kakudaimoji[H+1] +="#";
			
		}
		
		
		for(int i = 1;i<H+1;i++){
			kakudaimoji[i] = "#"+moji[i-1]+"#";
		}
		
		
		
		for(int i = 0;i<H+2;i++){
			System.out.println(kakudaimoji[i]);
		}
		
		
		
		
		
		
		
		
	}

}


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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0)
{
  if (fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e3 + 2;
int a[maxn];

int main()
{
  ios::sync_with_stdio(false);
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  for(int i = 0; i < n ; i++)
  {
    ll x,y;
    cin >> x >> y;
    if(x*x + y *y <= d * d)
      ans++;
  }

  cout << ans << endl;
  

  return 0;
}

Measured memory_bytes: 3644
n = int(input())
d = list(map(int, input().split()))

d = sorted(d)

if len(d)%2 == 0:
    print(d[len(d)//2] - d[len(d)//2-1])
else:
    print(d[len(d)//2+1] - d[len(d)//2-1])

Measured memory_bytes: 13992