akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

string s;

int main(){
  getline(cin, s);
  int ans = 0;
  rep(i, 3){
    if(s[i] == 'R') ans++;
  }
  if(s[1] == 'S'){
    if(ans == 2) ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
(() => {

    var lines = [];

    require('readline').createInterface({
        input: process.stdin,
    }).on('line', (line) => {
        lines.push(Number(line));
    });

    process.stdin.on("end", () => {
        console.log(lines.filter(isPrime).length);
    });

    const isPrime = function(x){
        if(x == 2){
            return true;
        }

        if(x < 2 || (x & 0x01) === 0){
            return false;
        }

        const sqrt_x = Math.sqrt(x);
        for(let i = 3; i <= sqrt_x; i+=2){
            if(x % i === 0){
                return false;
            }
        }
        return true;
    }


})();


Measured memory_bytes: 19484
#include <bits/stdc++.h>
 
//#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n, p;
string s;
map<int, int> mp;
ll res;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> p >> s;

	mp[0] = 1;
	reverse(all(s));

	if (p == 2 || p == 5) {
		forn (i, n)
			if ((s[i] - '0') % p == 0)
				res += n - i;
		cout << res << endl;
		return 0;
	}

	for (ll i = 0, j = 1, acu = 0; i < n; i++, (j *= 10) %= p) {
		(acu += int(s[i] - '0') * j) %= p;
		res += mp[acu];
		mp[acu]++;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S, ans="NO";
  cin >>S;
  vector<string> Z={"dream","dreamer","erase","eraser"};   
  if(S.size()<=7){
    if(S.size()>4){
      for(int i=0; i<4; i++){
        if(S==Z[i]) ans="YES";
      }
    }
  cout << ans << endl;
  return 0;
  }

  for(int i=0; i<S.size()-5; i++){//eraser消す
    if(S[i]=='e'){
      for(int j=1; j<6; j++){
        if(S[i+j]!=Z[3][j]) break;
        if(j==5){
          for(j=0; j<6; j++){
          S[i+j]='x';
          }
        }
      }      
    }
  }
  for(int i=0; i<S.size()-4; i++){//erase消す
    if(S[i]=='e'){
      for(int j=1; j<5; j++){
        if(S[i+j]!=Z[2][j]) break;
        if(j==4){
          for(j=0; j<5; j++){
          S[i+j]='x';
          }
        }
      }
    }
  }
  for(int i=0; i<S.size()-6; i++){//dreamer消す
    if(S[i]=='d'){
      for(int j=1; j<7; j++){
        if(S[i+j]!=Z[1][j]) break;
        if(j==6){
          for(j=0; j<7; j++){
          S[i+j]='x';
          }
        }
      }
    }
  }    
  for(int i=0; i<S.size()-4; i++){//dream消す
    if(S[i]=='d'){
      for(int j=1; j<5; j++){
        if(S[i+j]!=Z[0][j]) break;
        if(j==4){
          for(j=0; j<5; j++){
          S[i+j]='x';
          }
        }
      }
    }
  }
  for(int i=0; i<S.size(); i++){
    if(S[i]!='x') break;
    if(i==S.size()-1) ans="YES";
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> v = new ArrayList<>();
        for (int i=0;i<n;i++){
            v.add(scanner.nextInt());
        }
        Collections.sort(v);
        double ans = (((double)v.get(0)) + ((double)v.get(1)))/2;
        for (int i=2;i<n;i++){
            ans = (ans + ((double)v.get(i)))/2;
        }
        System.out.println(ans);

    }

}


Measured memory_bytes: 36264
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const long long INF=0x3f3f3f3f;

long long n,a,cnt,ans,mn=INF;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n; 
    for (int i=0;i<n;++i) {
        cin>>a;
        if (a<0) ++cnt; 
        ans+=abs(a);
        mn=min(mn,abs(a));
    }
    if (cnt&1) ans-=mn+mn;
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int pow_(int a, int n){
  if(n == 0) return 1;
  else{
    return a * pow_(a, n - 1);
  }
}

int g(int n){
  if(n > 3) return 3 * g(n - 1) + pow_(2, n - 1) * 3 - 6;
  if(n == 3) return 6;
}

int
main(int argc, char *argv[])
{
  int n;
  scanf("%d", &n);

  int ans = 0, s, f, t, z, temp, x = 0;

  if(n <= 999){
    for(int l = 1; l <= n; l++){
      temp = l;
      s = 0; f = 0; t = 0; z = 0;
      while(temp > 0){
	if(temp % 10 == 7) s++;
        else if(temp % 10 == 5) f++;
        else if(temp % 10 == 3) t++;
        else { z++; break;}
        temp /= 10;
      }
      if(s*t*f > 0 && z == 0) ans++;
    }
    printf("%d\n", ans);
  }
  else{
    int d = 0;
    temp = n; int r;
    while(temp > 0){
      r = temp % 10;
      temp /= 10;
      d++;
    }
    for(int i = 3; i < d; i++){
      ans += g(i);
    }
    if(r == 3){
      for(int i = 3 * pow_(10, d - 1); i <= n; i++){
	s = 0; t = 0; f = 0; z = 0;
	temp = i;
	while(temp > 0){
	  if(temp % 10 == 3) t++;
	  else if(temp % 10 == 5) f++;
	  else if(temp % 10 == 7) s++;
	  else {z++; break;}
	  temp /= 10;
	}
	if(s*t*f > 0 && z == 0)ans++;
      }
    }
    else if(r == 4) ans += pow_(2, d - 1)  - 2 + g(d - 1);
    else if(r == 5){
      for(int i = 5 * pow_(10, d - 1); i <= n; i++){
	s = 0; t = 0; f = 0; z = 0;
	temp = i;
	while(temp > 0){
	  if(temp % 10 == 3) t++;
	  else if(temp % 10 == 5) f++;
	  else if(temp % 10 == 7) s++;
	  else {z++; break;}
	  temp /= 10;
	}
	if(s*t*f > 0 && z == 0)ans++;
      }
      ans += g(d) / 3;
    }
    else if(r == 6) ans += 2*(pow_(2, d - 1) - 2 + g(d - 1));
    else if(r == 7){
      for(int i = 7 * pow_(10, d - 1); i <= n; i++){
	s = 0; t = 0; f = 0; z = 0;
	temp = i;
	while(temp > 0){
	  if(temp % 10 == 3) t++;
	  else if(temp % 10 == 5) f++;
	  else if(temp % 10 == 7) s++;
	  else {z++; break;}
	  temp /= 10;
	}
	if(s*t*f > 0 && z == 0)ans++;
      }
      ans += 2 * g(d) / 3;
    }
    else if(r >= 8) ans += g(d);
    printf("%d\n", ans);
  }

	
    
  return 0;
}


Measured memory_bytes: 128
program main
  implicit none
  integer(8) :: n, x, a(100), i, j
  read(*, *) n, x
  read(*, *) a(1:n)

  call mergesort(a(1:n), n)

  if (sum(a(1:n)) == x) then
    write(*, "(i0)") n
  else if (sum(a(1:n)) < x) then
    write(*, "(i0)") n - 1
  else
    j = 0
    do i = 1, n
      j = j + a(i)
      if (j > x) then
        write(*, "(i0)") i - 1
        exit
      end if
    end do
  end if
  contains

  subroutine merge_arrays(a, na, b, nb, c, nc)
    ! Merge arrays a and b to c
    implicit none
    integer(8), intent(in) :: na, nb, nc
    integer(8), intent(in) :: a(na), b(nb)
    integer(8), intent(inout) :: c(nc)
    integer(8) :: i, j, k

    if (na + nb /= nc) then
      print *, "subroutine merge_arrays size error"
      stop 161
    end if

    i = 1; j = 1; k = 1
    do while(i <= na .and. j <= nb)
      if (a(i) <= b(j)) then
        c(k) = a(i)
        i = i + 1
      else
        c(k) = b(j)
        j = j + 1
      endif
      k = k + 1
    enddo
    do while (i <= na)
      c(k) = a(i)
      i = i + 1
      k = k + 1
    enddo
  end subroutine merge_arrays

  recursive subroutine mergesort(a, n)
    ! Sort an array a(n)
    implicit none
    integer(8), intent(in) :: n
    integer(8), intent(inout) :: a(n)
    integer(8) :: t((n + 1) / 2)
    integer(8) :: na, v

    if (n < 2) then
      return
    else if (n == 2) then
      if (a(1) > a(2)) then
        v = a(1)
        a(1) = a(2)
        a(2) = v
      endif
      return
    endif

    na = (n + 1) / 2
    call mergesort(a, na)
    call mergesort(a(na + 1), n - na)

    if (a(na) > a(na + 1)) then
      t(1:na) = a(1:na)
      call merge_arrays(t, na, a(na + 1:n), n - na, a, n)
    endif
  end subroutine mergesort
end program main


Measured memory_bytes: 640
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.container : DList;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto deque = Deque!int(400_000 * 3);
    int q = readint;
    for (int i = 0; i < q; i++) {
        auto xs = readints;
        switch (xs[0]) {
            case 0:
                if (xs[1] == 0) deque.insertFront(xs[2]);
                else deque.insertBack(xs[2]);
                break;
            case 1:
                writeln(deque[xs[1]]);
                break;
            case 2:
                if (xs[1] == 0) deque.removeFront();
                else deque.removeBack();
                break;
            default:
                break;
        }
    }
}

struct Deque(T) {
    private T[] _buffer;
    private int _front;
    private int _back;

    this(int size) {
        _buffer = new int[size];
        _front = _back = size / 2;
    }

    bool empty() @property { return  _front == _back; }
    int length() @property { return _back - _front; }

    void insertFront(T value) {
        if (empty) {
            _buffer[_front] = value;
            _back++;
            return;
        }

        _buffer[--_front] = value;
    }

    void insertBack(T value) {
        if (empty) {
            _buffer[_front] = value;
            _back++;
            return;
        }

        _buffer[_back++] = value;
    }

    void removeFront() {
        assert(!empty);
        ++_front;
    }

    void removeBack() {
        assert(!empty);
        --_back;
    }

    T opIndex(int index) {
        return _buffer[_front + index];
    }
}



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

int main()
{
    int a, b;
    cin >> a >> b;
    if(a > b)
    {
        for (int i = 1; i <= a; i++)
        {
            cout << b;
        }
        cout << endl;
    }
    else
    {
        for (int i = 1; i <= b; i++)
        {
            cout << a;
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[100], b[100], c[100];
	int n = 0,diamond=0,rectangle=0;
	int i;

	while (scanf("%d,%d,%d", &a[n], &b[n], &c[n]) != EOF) {
		n++;
	}

	for (i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			diamond++;
		}
		else if((a[i] != b[i]) && (c[i]*c[i] == a[i]*a[i]+b[i]*b[i])){
			rectangle++;
		}
	}

	printf("%d\n", rectangle);
	printf("%d\n", diamond);

	return 0;
}

Measured memory_bytes: 596
import sys

sys.setrecursionlimit(1000000)


def solve(N, S):
    C = {"R": 0, "G": 0, "B": 0}
    ans = 0
    for c in S:
        if c == "B":
            ans += C["R"] * C["G"]
            C["B"] += 1
        elif c == "G":
            ans += C["R"] * C["B"]
            C["G"] += 1
        elif c == "R":
            ans += C["B"] * C["G"]
            C["R"] += 1

    for d in range(1, N):
        for i in range(N):
            j = i + d
            k = j + d
            if j < N and k < N:
                if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                    ans -= 1
    return ans


if __name__ == "__main__":
    N = int(input())
    S = input()
    print(solve(N, S))


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int odd = 0, even = 0;
  vector<ll> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i) >> y.at(i);
    if ((abs(x.at(i)) + abs(y.at(i))) % 2 == 1) odd++;
    else even++;
  }
  
  if (odd > 0 && even > 0) {
    cout << "-1\n";
    return 0;
  }
  
  vector<ll> arms;
  for (ll i = 35; i >= 0; i--) arms.emplace_back(1LL << i);
  if (even > 0) arms.emplace_back(1);
  
  cout << arms.size() << '\n';
  for (int i = 0; i < arms.size(); i++) {
    if (i) cout << " ";
    cout << arms.at(i);
  }
  cout << '\n';
  
  for (int i = 0; i < n; i++) {
    ll gu = x.at(i) + y.at(i), gv = x.at(i) - y.at(i);
    ll nowx = 0, nowy = 0;
    for (int j = 0; j < arms.size(); j++) {
      ll nowu = nowx + nowy, nowv = nowx - nowy;
      if (nowu <= gu && nowv <= gv) {
        cout << 'R';
        nowx += arms.at(j);
      }
      else if (nowu >= gu && nowv >= gv) {
        cout << 'L';
        nowx -= arms.at(j);
      }
      else if (nowu <= gu && nowv >= gv) {
        cout << 'U';
        nowy += arms.at(j);
      }
      else {
        cout << 'D';
        nowy -= arms.at(j);
      }
    }
    cout << '\n';
    // cout << nowx << " " << nowy << endl;
  }
}

Measured memory_bytes: 3616
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7
    #epsilon = 10**-9

    n = int(input())
    a,b,c,d = 0, 0, 0, 0
    for _ in range(n):
        s = input().rstrip()
        if s == 'AC':
            a += 1
        elif s == 'WA':
            b += 1
        elif s == 'TLE':
            c += 1
        else:
            d += 1

    print('AC x {}'.format(a))
    print('WA x {}'.format(b))
    print('TLE x {}'.format(c))
    print('RE x {}'.format(d))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9480
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
#define VMAX 100000

int partition(int *A, int p, int r){
  int i, j;
  int x, a;

  x = A[r];
  i = p-1;

  for(j = p; j < r; j++){
      if(A[j] <= x){
          i++;
          a = A[j];
          A[j] = A[i];
          A[i] = a;
      }
  }

  a = A[r];
  A[r] = A[i+1];
  A[i+1] = a;

  return i+1;
}

int main(){
  int *A;
  int n, i, q;

  scanf("%d", &n);

  A = malloc(sizeof(int)*(n+1));

  for(i = 1; i <= n; i++){
      scanf("%d",&A[i]);
  }

  q = partition(A, 1, n);

  for(i = 1; i < n; i++){
      if(i == q) printf("[%d] ",A[i]);
      else printf("%d ",A[i]);
  }


  if(i == q) printf("[%d]\n",A[i]);
  else printf("%d\n",A[i]);

  free(A);

  return 0;
}



Measured memory_bytes: 2140
n,m = gets.split.map &:to_i
a = m.times.map { gets.split.map &:to_i }

0.upto(999) do |i|
  b = i.to_s.chars.map(&:to_i)
  next if b.size != n
  if a.all? { |s,c| b[s-1] == c }
    puts i
    exit
  end
end

puts -1

Measured memory_bytes: 1788
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    auto edge = initVec2<int>(n + 1, 0);
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> c(n);
    rep(i, n) cin >> c[i];

    int root = 0;
    for(int v = 1; v <= n; v++){
        if(SZ(edge[root]) <= SZ(edge[v])){
            root = v;
        }
        sort(ALL(edge[v]), [&](int a, int b){return SZ(edge[a]) > SZ(edge[b]);});
    }

    sort(ALL(c), greater<int>());

    vector<int> ans(n + 1);
    stack<P> st;
    st.emplace(root, 0);
    int x = 0;
    while(not st.empty()){
        int v = st.top().first;
        int p = st.top().second;
        st.pop();

        ans[v] = c[x++];
        for(int u : edge[v]){
            if(u == p){
                continue;
            }
            st.emplace(u, v);
        }
    }

    int sum = 0;
    for(int i = 1; i < n; i++){
        sum += c[i];
    }
    cout << sum << endl;
    rep(i, n){
        cout << ans[i+1] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=(int)((int)1e5 +5);
int dp[N];int arr[N];
 int n,k;
int solve(int i)
{
    if(i<2)return dp[i];
    else
    {
        if(dp[i]!=-1)return dp[i];
        else
        {  
              dp[i]=min((int)1e9,solve(i-1)+abs(arr[i]-arr[i-1]));
            for(int j=i-2;j>=max(i-k,0);j--)
            {
            dp[i]=min(dp[i],solve(j)+abs(arr[i]-arr[j]));
            }
            return dp[i];
        }
    }
    return 0;
}

int main()
{ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
for(int i=0;i<N;i++)dp[i]=-1;

 cin>>n>>k;
 for(int i=0;i<n;i++)cin>>arr[i];
 dp[0]=0;dp[1]=abs(arr[0]-arr[1]);
 cout<< solve(n-1)<<endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#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 f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

bool check(string x){
    int tot = 0,fo = 1;
    FOR(i,0,sz(x)){
        if(x[i] == '(')tot++;
        else tot--;
        if(tot < 0)return 0;
    }
    if(tot != 0)return 0;
    return 1; 
}

void solve(){
    int n;
    cin >> n;
    string s[n+5];
    vector<pii>pos,neg;
    string ans = "";
    FOR(i,0,n){
        cin >> s[i];
        int mi = mod,tot = 0;
        FOR(j,0,sz(s[i])){
            if(s[i][j] == '(')++tot;
            else tot--;
            mi = min(tot,mi);
        }   
        if(mi >= 0)ans += s[i];
        else if(tot >= 0)pos.pb({mi,i});
        else neg.pb({mi-tot,i});
    }
    sort(pos.begin(),pos.end(),greater<pii>());
    sort(neg.begin(),neg.end());
    for(auto &x:pos)ans += s[x.se];
    for(auto &x:neg)ans += s[x.se];
    if(check(ans))cout << "Yes";
    else cout << "No";
}

signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
       solve();
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


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

int main(){
  long long n,d;
  cin>>n>>d;
  d=d*d;
  int ans=0;
  for(int i=0;i<n;i++){
    long long p,q;
    cin>>p>>q;
    if(p*p+q*q<=d){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
def main():
  n = int(input())
  a, b = map(int, input().split())
  ps = map(int, input().split())
  first = 0
  second = 0
  third = 0
  for p in ps:
    if p <= a:
      first += 1
    elif p <= b:
      second += 1
    else:
      third += 1
  print(min(first, second, third))


if __name__ == '__main__':
  main()


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int q; cin>>q;
    vi sum(q);
    vi t(q),f(q);
    vector<char> c(q);
    rep(i,q){
        cin>>t[i];
        if (t[i]==1){
            sum[i]++;
        }else{
            cin>>f[i]>>c[i];
        }
    }
    rep(i,q-1) sum[q-i-2]+=sum[q-i-1];
    string ans=s;
    string left,right;
    if (sum[0]%2==1) reverse(all(ans));
    rep(i,q){
        if (t[i]==2){
            if (sum[i]%2==0){
                if (f[i]==1) left.pb(c[i]);
                if (f[i]==2) right.pb(c[i]);
            }else{
                if (f[i]==1) right.pb(c[i]);
                if (f[i]==2) left.pb(c[i]);
            }
        }
    }
    reverse(all(left));
    ans = left+ans+right;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  cin >> N;
  vector <int> H(N);
  rep(i,N) cin >> H[i];

  int mx = H[0];  //その時点で西側にある旅館の最大の高さ
  int ans = 1;  //海を眺められる旅館の数
  for (int i = 1; i < N; i++){
    if (H[i] >= mx) ans ++;
    mx = max(mx, H[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
n,m=map(int,input().split())
x=list(map(int,input().split()))
if n>=m:
  print(0)
else:
  x.sort()
  delta=[x[i+1]-x[i] for i in range(len(x)-1)]
  delta.sort()
  summation=0
  for i in range(len(delta)-n+1):
    summation+=delta[i]
  print(summation)

Measured memory_bytes: 13964
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> l(2 * n);
    REP(i, 2 * n){
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    ll ans = 0;
    for(ll i = 0; i < 2 * n; i += 2){
        ans += l.at(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
blues = {}
n.times do
  item = gets.chomp
  blues[item] = (blues[item] || 0) + 1
end
m = gets.to_i
m.times do
  item = gets.chomp
  next if blues[item].nil?
  blues[item] = blues[item] - 1
end

puts [0, blues.max_by(&:last).last].max


Measured memory_bytes: 1788
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
typedef long long ll ;
#define pll pair<ll , ll >
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
using namespace std;
const int maxn = 1000*100+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;

int main()
{
	migmig ;
	string s ;
	cin>>s ; 
	cout<<s ; 
	if(s[s.size() - 1] == 's') cout<<"es" ;
	else cout<<"s" ;  
}








Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB") cout << "No";
    else cout << "Yes";
}


Measured memory_bytes: 256
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
s=0
ans1=0
ans2=0
for i in range(n):
    if i%2==0:
        s+=a[i]
        if s>=0:
            ans1+=s-(-1)
            s=-1
    else:
        s+=a[i]
        if s<=0:
            ans1+=1-s
            s=1

s=0
for i in range(n):
    if i%2==1:
        s+=a[i]
        if s>=0:
            ans2+=s-(-1)
            s=-1
    else:
        s+=a[i]
        if s<=0:
            ans2+=1-s
            s=1
print(min(ans1,ans2))

Measured memory_bytes: 14708
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
#include <iostream>
// #include <iomanip>
// #include <sstream>
using namespace std;
// const int dx[] = {0, 1, 0, -1};
// const int dy[] = {1, 0, -1, 0};
// const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
// const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dx[] = {2, 2, -2, -2, 1, 1, -1, -1};
// const int dy[] = {-1, 1, 1, -1, 2, -2, 2, -2};
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define test_ fr(_iii_, 0, 66)pf(">");puts("in")
#define deb(x) fr(_iii_, 0, 66)cerr<<'>';cerr<<#x"="<<x<<"\n"
#define fr(i, a, b) for(int i = a ; i < (int)b ; i++)
#define frr(i, a, b) for(int i = a ; i >= (int)b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false)
#define boost2 cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
int on_bit(int x, int pos) {x |= (1 << pos); return x;}
int off_bit(int x, int pos) {x &= ~(1 << pos); return x;}
bool is_on_bit(int x, int pos) {return ((x & (1 << pos)) != 0);}
int flip_bit(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
ll on_bit_all(ll x, int pos) {x = (1LL << pos)-1; return x;}
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int MOD = 1e9+7;
int add(ll a, ll b){return ((a%MOD)+(b%MOD))%MOD;}
int sub(ll a, ll b){return ((a%MOD)-(b%MOD))%MOD;}
int mult(ll a, ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}

int main(){
	int n;
	sf("%d",&n);
	puts(n==3||n==5||n==7?"YES":"NO");
	return 0;
}

Measured memory_bytes: 256
dmd = []
cnt = 0
while l = gets
  dmd[cnt] = l.split(",").map(&:to_i)
  cnt += 1
end
s = Array.new(cnt){ Array.new(cnt, 0) }
s[0][0] = dmd[0][0]
(1..cnt/2).each do |i|
  (i+1).times do |j|
    a = b = 0
    a = s[i-1][j-1] if j - 1 >= 0
    b = s[i-1][j] if j < i
    s[i][j] = ([a,b].max) + dmd[i][j]
  end
end
(cnt/2+1..cnt).each do |i|
  (cnt-i).times do |j|
    a = s[i-1][j+1]
    b = s[i-1][j]
    s[i][j] = ([a,b].max) + dmd[i][j]
  end
end
p s[cnt-1][0]

Measured memory_bytes: 8852
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int l = n.length();
		int count = 0; 
		for(int i = 0; i<l; i++) {
			count+=Character.getNumericValue(n.charAt(i));
		}
		if(count%9==0)System.out.println("Yes");
		else System.out.println("No");
		
		}
}

Measured memory_bytes: 40496
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//小数点以下　cout << fixed << setprecision(10) << num << endl;

int main(){
    string s; cin >> s;
    if(s=="SUN") cout << 7;
    if(s=="MON") cout << 6;
    if(s=="TUE") cout << 5;
    if(s=="WED") cout << 4;
    if(s=="THU") cout << 3;
    if(s=="FRI") cout << 2;
    if(s=="SAT") cout << 1;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = input().rstrip()

    d = N[-1]
    if d in ["2", "4", "5", "7", "9"]:
        ans = "hon"
    elif d in ["0", "1", "6", "8"]:
        ans = "pon"
    else:
        ans = "bon"

    print(ans)


if __name__ == "__main__":
    main()


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


int main(){
    string a,b,c;
   cin >> a >> b >> c;
  
    a.at(0) = toupper(a.at(0));
    b.at(0) = toupper(b.at(0));
    c.at(0) = toupper(c.at(0));
    cout << a.at(0) << b.at(0) << c.at(0) << endl;

  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n,0),ans(n,0);
  rep(i,n-1){
    cin >> t1;
    ans[t1-1]++;
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 6424
//input.c
#include <stdio.h>

void main(void)
{
  int N;
  char A[100];
  char B[100];
  char C[100];
  scanf("%d",&N);
  scanf("%s",A);
  scanf("%s",B);
  scanf("%s",C);
  int count = 0;
  for( int i = 0;i<N;i++ )
  {
    if(A[i] == B[i])
    {
      if(B[i] == C[i])
      {
        // 処理なし
      }
      else
      {
        count++;
      }
    }
    else
    {
      count++;
      if(A[i] == C[i])
      {
        // 処理無し
      }
      else if(B[i] == C[i])
      {
        // 処理無し
      }
      else
      {
        count++;
      }
    }
  }
  
  printf("%d",count);
}




Measured memory_bytes: 128
#include<stdio.h>

int main( ){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if ( W < x+r ){
    printf("No\n");
  } else if ( 0 > x-r ){
    printf("No\n");
   
  } else if ( H < y+r ){
    
    printf("No\n");
    
  } else if ( 0 > y-r ){
    
    printf("No\n");
   
  } else printf("Yes\n");

  return 0;

}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const LL INF=1e18;
int n,A,B,a[5555],s[5010][5010];
LL f[5555],ans;
int main(){
	cin>>n>>A>>B;
	FOR(i,1,n) getint(a[i]);
	FOR(i,1,n){
		FOR(j,1,n) s[i][j]=s[i-1][j];
		FOR(j,a[i],n) s[i][j]++;
	}
	f[0]=0;
	FOR(i,1,n){
		f[i]=INF;
		FORD(j,i-1,0){
			//j+1..i-1
			if (a[i]<a[j]) continue;
			f[i]=min(f[i],f[j]+1ll*(i-j-1-(s[i-1][a[i]]-s[j][a[i]]))*A+1ll*(s[i-1][a[j]]-s[j][a[j]])*B+1ll*(s[i-1][a[i]]-s[i-1][a[j]]-s[j][a[i]]+s[j][a[j]])*min(A,B));
		}
	}
	ans=INF;
	FOR(i,1,n){
		ans=min(ans,f[i]+1ll*B*(s[n][a[i]]-s[i][a[i]])+1ll*((n-i)-s[n][a[i]]+s[i][a[i]])*min(A,B));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,z,x;
int main()
{
	cin>>n>>m>>a>>b;
	if(n>m)
	cout<<a*m+(n-m)*b;
	if(n<=m)
	cout<<n*a;
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
typedef long long ll;

using namespace std;

const int mod1 = 1e9 + 7;
ll n;

ll ksm(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1)ans = (ans * a) % mod1;
		a = (a * a) % mod1;
		b = b / 2;
	}
	return ans;
}

int main() {
	cin>>n;
	cout << (ksm(10, n) % mod1 - (ksm(9, n) * 2) % mod1 + ksm(8, n) % mod1 + mod1) % mod1;
	return 0;
}

Measured memory_bytes: 3604
import sys
def decode(s):
    result=""
    for c in s:
        if not (c==" " or c=="."):
            result+=chr(ord(c)+1)
        else:
            result+=c
    return result.replace(chr(ord("z")+1),"a")
for line in sys.stdin.readlines():
    s=line.strip()
    for i in xrange(ord("z")-ord("a")+1):
        if "the" in s or "that" in s or "this" in s:
            print s
            break
        s=decode(s)

Measured memory_bytes: 4232
N = int(input())
line1 = [int(n) for n in input().split()]
line2 = [int(n) for n in input().split()]
u = []
res = 0
for i in range(N):
    u.append(line1[i]-line2[i])
for i in range(N):
    if u[i]>0:
        res += u[i]
print(res)

Measured memory_bytes: 3064
#include <stdio.h>

long long gcd(long long a, long long b) {
	return b == 0 ? a : gcd(b, a % b);
}

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

int main() {
	int n;
	long long ans;

	scanf("%d", &n);
	ans = 1;
	while (n--) {
		long long t;

		scanf("%lld", &t);
		ans = lcm(ans, t);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: String,
    }
    println!("{}", if n.contains('7') { "Yes" } else { "No" })
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = max((a),(b))
#define chmin(a, b) a = min((a),(b))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000
 
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
 
int main() {
    ll n,k;
    cin>>n>>k;
    vector<vector<int>> root(n);
    vector<int> clear(n);
    vector<ll> ans;

    rep(i,n-1){
        int x,y;
        cin>>x>>y;
        root[x-1].pb(y-1);
        root[y-1].pb(x-1);
    }
    rep(i,n)clear[i]=0;

    priority_queue<pii,vector<pii>,greater<pii>> que;
    que.push(mp(0,0));
    while(!que.empty()){
        pii q=que.top();
        que.pop();  
        clear[q.first]=1;
        ans.pb(q.second);
        int init=min(q.second+1,2);
        int count=0;
        for(auto x:root[q.first]){
            if(clear[x]==1){
                continue;
            }
            que.push(mp(x,init+count));
            count++;
        }   
    }     
    ll true_ans=1;
    rep(i,n){
        //cout<<ans[i]<<endl;
        if(ans[i]>=k){
            cout<<0<<endl;
            return 0;
        }
        true_ans=true_ans*(ll)(k-ans[i])%mod;
    }
    cout<<true_ans<<endl;



}

Measured memory_bytes: 8820
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> d(n);
    REP(i, 0, n) {
        cin >> d[i];
    }
    ll ans = 0;
    REP(i, 0, n) {
        REP(j, i + 1, n) {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

struct magic{
    int a, b;
};

int main(){
    int h, n;
    const int h_max = 1e9;
    cin >> h >> n;

    vector<magic> v(n);
    for(auto& vi : v) cin >> vi.a >> vi.b;
    vector<int> mpv(h+1, h_max);
    mpv.at(0) = 0;
    for(const auto& vi : v){
        for(int j=vi.a; j < h; j++) mpv.at(j) = min(mpv.at(j-vi.a)+vi.b , mpv.at(j));
        //for(int j=0; j<vi.a; j++) mpv.at(h) = min(mpv.at(h-vi.a+j)+vi.b, mpv.at(h)); // ここにバグが入るのんだろう。
        for(int j=max(h-vi.a, 0); j<h; j++) mpv.at(h) = min(mpv.at(j)+vi.b, mpv.at(h));
    }

    cout << mpv.at(h) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#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++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back
#define vs vector<string>

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long 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.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N,M;
    cin>>N>>M;
    if(N==M) cY;
    else cN;
}


Measured memory_bytes: 3664
a=lambda x:print(x,end="")
sx,sy,tx,ty=map(int,input().split())
l=["U","R","D","L"]
for i in[0,2]:
 a(l[i]*(ty-sy))
 a(l[i+1]*(tx-sx))
for i in[0,2]:
 a(l[(i+3)%4])
 a(l[i]*(ty-sy+1))
 a(l[i+1]*(tx-sx+1))
 a(l[(i+2)%4])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;

int main()
{
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A,A+3);
  cout << (A[0] == 5 && A[1] == 5 && A[2] == 7 ? "YES" : "NO") << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        double h = Double.parseDouble(sc.next());
        double a = Double.parseDouble(sc.next());

        int result = (int)Math.ceil(h / a);
        System.out.println(result);

        sc.close();
    }
}


Measured memory_bytes: 23760
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  int n,k;cin>>n>>k;
  int a[n];
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int cnt=0;
  rep(i,k)cnt+=a[i];
  cout<<cnt<<endl;
}


Measured memory_bytes: 3656
s = input()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print(i+1, i+2)
        exit()
for i in range(len(s)-2):
    if s[i] == s[i+2]:
        print(i+1, i+3)
        exit()
print(-1, -1)

Measured memory_bytes: 3188
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;
#include<string>

int main()
{
    int n, k;
    cin >> n >> k;
    k--;
    string s;
    cin >> s;

    s[k] = s[k] - 'A' + 'a';
    cout << s << endl; 
}


Measured memory_bytes: 888
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1

def main():
    n=int(input())
    a=input()
    b=input()
    c=input()
    ans=0
    for i in range(n):
        if a[i]==b[i]==c[i]:continue
        elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i]:
            ans+=1
        else:
            ans+=2
    print(ans)

main()

Measured memory_bytes: 3064
def main():
    h, n = map(int, input().split())
    *a, = map(int, input().split())
    print('No' if h > sum(a) else 'Yes')


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef pair<double, double> P;

void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

class UnionFind {
public:
    // 親の番号を格納する。親だった場合-size
    vector<int> parents;

    UnionFind(int n) {
        parents = vector<int>(n, -1);
    }

    // aがどのグループに属しているか
    int root(int a) {
        if (parents[a] < 0) {
            return a;
        }
        return parents[a] = root(parents[a]);
    }

    int size(int a) {
        return -parents[root(a)];
    }

    // aとbをくっつける
    bool connect(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb) {
            return false;
        }
        // 大きいほうにA
        if (size(ra) < size(rb)) {
            swap(ra, rb);
        }
        parents[ra] += parents[rb];
        parents[rb] = ra;
        return true;
    }

};

struct Road {
    int from, to, cost;
};

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

    vector<Road> road;

    rep(i, n) rep(j, n) {
            int cost;
            cin >> cost;
            if (cost == -1) continue;
            road.push_back({i, j, cost});
        }

    sort(road.begin(), road.end(), [](Road &r, Road &s) { return r.cost < s.cost; });

    UnionFind uf(n);
    ll cost = 0;
    for (Road &r : road) {
        if (uf.root(r.from) == uf.root(r.to)) continue;
        uf.connect(r.from, r.to);
        cost += r.cost;
    }
    cout << cost << endl;
}




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

int main()
{
	int N, W;
	cin >> N >> W;
	vector<ll> w(N), v(N);
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	map<ll, ll> dp;
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		auto tmp = dp;
		for (auto p : tmp) {
			dp[p.first + w[i]] = max(dp[p.first + w[i]], p.second + v[i]);
		}
	}
	ll res = 0;
	for (auto ans : dp) {
		if (ans.first <= W) {
			res = max(res, ans.second);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
program string_palindrome
  implicit none
  character(99) :: s
  integer :: n
  read(*,*) s
  n = len_trim(s)
  if (is_palindrome(s(1:n)) .and. &
  & is_palindrome(s(1:(n-1)/2)) .and. &
  & is_palindrome(s((n+3)/2:n))) then
    write(*,'(a)') "Yes"
  else
    write(*,'(a)') "No"
  end if
contains
  logical function is_palindrome(s)
    character(*), intent(in) :: s
    integer :: n, i, j
    n = len_trim(s)
    i = 1
    j = n
    is_palindrome = .true.
    do while (i < j)
      if (s(i:i) /= s(j:j)) then
        is_palindrome = .false.
        return
      end if
      i = i+1
      j = j-1
    end do
  end
end program string_palindrome

Measured memory_bytes: 768
n, k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10 ** 9
for l in range(n - k + 1):
    dist = abs(x[l] - x[l + k - 1])
    dist += min(abs(x[l]), abs(x[l+k-1]))
    ans = min(ans,dist)
print(ans)


Measured memory_bytes: 15020