akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(K):
    return "ACL" * K


def main():
    k = read_int()
    print(slv(k))


if __name__ == '__main__':
    main()


Measured memory_bytes: 78332
#include<iostream>
using namespace std;
int main(){
  string s, result =" ";
  cin >> s;
  for(int i = 0; i < s.length(); i++){
    char c = s[i];
    switch(c){
      case'0':
        result += '0';
        break;
      case'1':
        result += '1';
        break;
      case'B':
      if(result.length() > 0){
        result = result.substr(0, result.length() - 1);
      }
      
    }
  }
  cout << result << '\n';
}

Measured memory_bytes: 3580
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
from scipy.sparse.csgraph import floyd_warshall

#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    n,m,r=map(int,input().split())
    grid=[[0]*n for i in range(n)]
    *R,=map(int,input().split())
    for i in range(m):
        a,b,c=map(int,input().split())
        grid[a-1][b-1]=c
        grid[b-1][a-1]=c
#    print(grid)
    d,p=floyd_warshall(csgraph=grid, directed=False, return_predecessors=True)
#    print(p)
#    print(d)
    print(int(min(sum(d[i[j]-1][i[j+1]-1]for j in range(len(i)-1))for i in permutations(R))))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 17388
import itertools
N=int(input())
a = []
for i in range(N):
	s,b = input().split()
	a.append([s, int(b), i+1])
#a=[["b", 2,1], ["a", 3,2],["a", 1,3]]

a.sort(key=lambda x:x[0])
for k,g in itertools.groupby(a, key=lambda x:x[0]):
	g= list(g)
	g.sort(key=lambda x:x[1],reverse=True)
	for a in g:
		print(a[2])


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(-1.0);
const int limit = 100010;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

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

int main() {
    int n;
    cin >> n;
    bool same = true;
    ll a[n], b[n];
    ll Min = LINF;
    ll sum = 0;

    rep(i, n) {
        cin >> a[i] >> b[i];
        if (a[i] != b[i]) same = false;
        if (a[i] > b[i]) Min = min(Min, b[i]);
        sum += a[i];
    }

    if (same) {
        cout << 0 << endl;
    } else {
        cout << sum - Min << endl;
    }

    return 0;
}


Measured memory_bytes: 764
# UnionTreeクラス：グループ分けを木構造で管理する
class UnionFind():
    def __init__(self, N):
        self.par = [i for i in range(N)]
        self.size = [1] * N
        self.N = N

    # xのrootを返す
    def root(self, x):
        if self.par[x] == x:
            return x
        else: 
            self.par[x] = self.root(self.par[x])
            return self.root(self.par[x])

    # x, yが同じrootの場合true
    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    # x,yのrootが違った場合、併合
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if self.size[rx] < self.size[ry]:
            self.par[rx] = ry
            self.size[ry] += self.size[rx]
        else:
            self.par[ry] = rx
            self.size[rx] += self.size[ry]

n, m = (int(i) for i in input().split())
input_arr = [[int(i) for i in input().split()] for i in range(m)] 

uf = UnionFind(n)
#input_arr = [[1,2],[3,4],[1,3],[2,3],[1,4]]

#print(output(uf))
result = [int(n*(n-1)/2)]
for i in input_arr[::-1]:
    a = i[0]-1
    b = i[1]-1
    if not uf.same(a,b):
        x = uf.size[uf.root(a)] * uf.size[uf.root(b)]
        uf.unite(a,b)
        result.append(int(result[-1]-x))
    else:
        result.append(result[-1])

for i in result[::-1][1:]:
    print(i)

#print(uf.par)


Measured memory_bytes: 30768
a, b = map(int, input().split())

if a > b:
    if (a + b ) % 2 == 0:
        print((a + b) //2)
    else:
        print("IMPOSSIBLE")
elif a < b:
    if (a + b ) % 2 == 0:
        print((b + a) //2)
    else:
        print("IMPOSSIBLE")


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
  unsigned long s, w;
  cin >> s >> w;

  if (s <= w)
  {
    cout << "unsafe";
  }
  else
  {
    cout << "safe";
  }

  return 0;
}

Measured memory_bytes: 3132
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n=ip()
s=0
for k in range(1,n+1):
    if len(str(k))%2:s+=1
print(s)

Measured memory_bytes: 13636
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
S = list(input())[:-1]
T = list(input())[:-1]
n = len(S)
c = 0
for i in range(n):
    if S[i] != T[i]:
        c = 1
        break
if c == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 27144
from collections import deque
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    graph[a - 1].append((b - 1, c))
    graph[b - 1].append((a - 1, c))
Q, K = map(int, input().split())
visited = [0] * N
visited[K - 1] = 1
q = deque([(K - 1, 0)])
while q:
    p, c = q.popleft()
    for dst, d in graph[p]:
        if not visited[dst]:
            visited[dst] = c + d
            q.append((dst, c + d))
for _ in range(Q):
    x, y = map(lambda n: int(n) - 1, input().split())
    print(visited[x] + visited[y])

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

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

  vector<string> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  map<string, int> goods;

  for(int i = 0; i < N; i++){
    if(goods.count(vec.at(i))){
      goods[vec.at(i)]++;
    }else{
      goods[vec.at(i)] = 1;
    }
  }

  int cnt = 0;
  for(map<string, int>::const_iterator i = goods.begin();
      i != goods.end(); ++i){
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 25176
#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;
using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;




int main(int argc, char *argv[])
{
    
    cin.tie(0) ;
    ios::sync_with_stdio(false) ;
    
    u64 A, B, K;
    cin >> A >> B >> K;
    
    B = (A <= K) ? (B - K + A) : B;
    B = max(B, (u64) 0);
    A = max(A - K, (u64) 0);
    
    cout << A << " " << B << endl;
    
    return 0;
    
}


Measured memory_bytes: 3512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

char S[256];

bool flg[256];

signed main()
{
	cin >> S;

	if (strcmp("zyxwvutsrqponmlkjihgfedcba", S) == 0)
	{
		cout << "-1" << endl;
		return 0;
	}

	int len = strlen(S);
	for (int i = 0; i < len; i++)
	{
		flg[S[i] - 'a'] = true;
	}

	if (len < 26)
	{
		for (int i = 0; i < 26; i++)
		{
			if (!flg[i])
			{
				cout << S << (char)(i + 'a') << endl;
				return 0;
			}
		}
	}
	else
	{
		for (int i = 25; i >= 0; i--)
		{
			for (int j = (S[i] - 'a') + 1; j < 26; j++)
			{
				if (!flg[j])
				{
					S[i] = j + 'a';
					cout << S;
					return 0;
				}
			}

			flg[S[i] - 'a'] = false;
			S[i] = '\0';
		}
	}
}







Measured memory_bytes: 256
N, M, X = map(int, input().split())
C = []
A = [[] for _ in range(N)]
for i in range(N):
    L = list(map(int, input().split()))
    C.append(L[0])
    A[i] = L[1:]

ans = 10 ** 9

for i in range(2**N):
    tmp = [0] * M
    tmp2 = 0
    for j in range(N):
        if i >> j & 1:
            for k in range(M):
                tmp[k] += A[j][k]
            tmp2 += C[j]
    flag = True
    for l in range(M):
        if tmp[l] < X:
            flag = False
    if flag:
        ans = min(ans, tmp2)
if ans != 10 ** 9:
    print(ans)
else:
    print("-1")

Measured memory_bytes: 9248
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque



def main():
    num = int(input())
    if num % 2 == 0:
        print(0.5)
    else:
        print(((num // 2) + 1) / num)






if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import sys 

n,y = map(int,input().split())

for i in range (n+1):
  for j in range(n-i+1):
    if i*10000 + j*5000+(n-i-j)*1000 ==y:
      print(i,j,n-i-j)
      sys.exit()

      
print("-1 -1 -1")



Measured memory_bytes: 2940
// B
// Resale

#include <iostream>
#include <vector>
using namespace std;

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

    int N;

    cin >> N;

    vector<int> V;

    for (int i = 0; i < N; i++)
    {
        int v;

        cin >> v;

        V.push_back(v);

    } 

    vector<int> C;

    for (int i = 0; i < N; i++)
    {
        int c;

        cin >> c;

        C.push_back(c);

    } 

    int sum = 0;

    for (int i = 0; i < N; i++)
    {
        if (V[i] > C[i])
        {
            sum += (V[i] - C[i]);
        }
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int n;string s;
int main(){
	cin>>n>>s;
	int cnt=0;
	rep(i,0,n-1)if(s[i]=='R')cnt++;
	if(cnt*2>n)cout<<"Yes\n";else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int H1, H2, M1, M2, K;
	
	scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);
	
	int ans = 60 * (H2 - H1) + M2 - M1 - K;
	printf("%d", ans);
	
}

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

    char chess(int h,int w){
        if((h+w)%2==0){
            return '#';
        }
        return '.';
    }
    int main (void){
    
        int H,W;
        while (true){
            cin >> H >> W;
            if (H==0 &&W==0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    cout << chess(i,j);
                }
                cout << endl;
            }
            cout << endl;
        }
    }


Measured memory_bytes: 3092
// ------------------------------------
// Date:2018/ 2/25
// Problem:ABC 049 UOIAUAI a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int main()
{
  char ch;
  string output = "consonant";
  cin >> ch;
  switch (ch) {
    case 'a':
    case 'i':
    case 'u':
    case 'e':
    case 'o':
      output = "vowel";
  }
  cout << output << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define MP(a, b) make_pair(a, b)
#define F first
#define S second

int main() {
	int n;
	while (cin >> n, n) {
		bool flag = true;
		char c[101];
		REP(i, 0, n) cin >> c[i];

		vector<pair<int, char>> v;
		REP(i, 0, n) {
			int j = 0;
			bool add_flag = true;

			while (j < v.size()) {
				if (v[j].S == c[i]) {
					v[j].F--;
					add_flag = false;
					break;
				}
				j++;
			}
			if (add_flag) {
				v.push_back(MP(-1, c[i]));
			}

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

			if (v.size() == 1) {
				if (i >= (n / 2)) {
					cout << v[0].S << " " << i + 1 << endl;
					flag = false;
					break;
				}
			}
			else {
				int rest = n - i - 1;

				if ((-v[0].F) - (-v[1].F) > rest) {
					cout << v[0].S << " " << i + 1 << endl;
					flag = false;
					break;
				}
			}
		}

		if (flag) {
			if (v.size() >= 2 && v[0].F == v[1].F) cout << "TIE" << endl;
			else cout << v[0].S << " " << n << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main() {
	// your code goes here
     ll a,b,n;
     cin>>a>>b>>n;
     if(n==b)
     {
     	ll ans=(a*(b-1))/b;
     	cout<<ans;
     }
     else if(n<b)
     {
     	ll ans=(a*n)/b;
     	cout<<ans;
     	
     }
     else
     {
     	ll ans=(a*(b-1))/b;
     	 cout<<ans;
     }
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
    fast;
    lli n;
    cin>>n;
    string s;
    cin>>s;
    lli i,ans=mod,countr=0,countw=0;
    fr(i,s.length())
    {
        if(s[i]=='R')
            countr++;
        else
            countw++;
    }
    ans=min(countw,countr);
    if(ans==0)
    {
        cout<<0;
        return 0;
    }
    lli count=0,count1=0;
    fr(i,countr)
    {
        if(s[i]=='W')
            count++;
    }
    for(i=s.length()-1;i>=s.length()-countw;i--)
    {
        if(s[i]=='R')
            count1++;
    }
    ans=min(ans,count);
    ans=min(ans,count1);
    cout<<ans;
    
    return 0;
}   

Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;




int main(void){
   int n;
   cin>>n;
   vector<int> a(n),b(n);
   rep(i,n)cin>>a[i];
   rep(i,n)cin>>b[i];
   vector<int> c(n);
   rep(i,n)c[i]=i+1;
   map<vector<int>,int> mp;

   do{
      mp[c]=mp.size();

   }while(next_permutation(c.begin(),c.end()));
int x = abs(mp[a]-mp[b]);
cout<<x<<endl;
return 0;
}




Measured memory_bytes: 8652
#include <bits/stdc++.h>
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FOR(x,n) for(int x = 0; x < n; x++)
#define FORR(x,n) for(int x = n-1; x >= 0; x--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)a.size())
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;

int main(){
  int N,X; cin >> N >> X;
  
  if(N ==1){ cout << "Yes\n1\n"; return 0; }
  if(N ==2){ if(X == 2) cout << "Yes\n1\n2\n3\n"; else cout << "No\n"; return 0; }
  
  if(X != 1 && X != 2*N-1){
    cout << "Yes\n";
    vector<int> A(2*N-1), used(2*N+1);
    int pos = (2*N-1)/2-2;
    if(X == 2*N-2){
      A[pos] = X-1;
      A[pos+1] = X;
      A[pos+2] = X+1;
      A[pos+3] = X-2;
      used[X+1] = used[X-1] = used[X] = used[X-2] = true;
    } else{
      A[pos] = X+1;
      A[pos+1] = X;
      A[pos+2] = X-1;
      A[pos+3] = X+2;
      used[X+1] = used[X] = used[X-1] = used[X+2] = true;
    }
    int i = 1;
    for(int x = 0; x < 2*N-1; x++) {
      if(!A[x]) {
        while(used[i]) i++;
        A[x] = i; used[i] = true;
      }
    }
    
    for(int x = 0; x < 2*N-1; x++)
      cout << A[x] << "\n";
  } else {
    cout << "No\n";
  }
}

Measured memory_bytes: 3200
A,B,K = map(int,input().split())
if B-A+1 < 2*K:
    for i in range(A,B+1):
        print(i)
else:
    for i in range(A,A+K):
        print(i)
    for i in range(B-K+1,B+1):
        print(i)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 200009;
int n, m, a, t, ans[maxn];

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

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define x first
#define y second

const int maxn = 1000005;
const ll INF = (ll)(1e17);
const int N = maxn;

pll tree[maxn << 2];

ll f(pll line, int x){
    return line.x * x + line.y;
}

void update(pll line, int lo = 1, int hi = N, int i = 1){
    int m = (lo + hi) >> 1;
    bool left = f(line, lo) < f(tree[i], lo);
    bool mid = f(line, m) < f(tree[i], m);

    if(mid) swap(tree[i], line);
    if(hi>lo){
        if(left != mid) update(line, lo, m, i << 1);
        else update(line, m + 1, hi, i << 1 | 1);
    }
}

ll query(int x, int lo = 1, int hi = N, int i = 1){
    int m = (lo+hi) >> 1;
    ll curr = f(tree[i], x);
    if(hi>lo){
        if(x<m) return min(curr, query(x, lo, m, i << 1));
        else return min(curr, query(x, m + 1, hi, i << 1 | 1));
    }else return curr;
}

int main(){
    int n;
    ll C;
    cin>>n>>C;
    vector<ll> dp(n, 0), h(n);
    for(int i=0; i<n; i++){
        cin>>h[i];
        if(i!=0) dp[i] = C + h[i]*h[i] + query(h[i]);
        update({-2*h[i], dp[i]+h[i]*h[i]});
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 16100
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	string s, t;
	cin>>s;
	cin>>t;
	
	int ns = s.length();
	int nt = t.length();
	int mini = INT_MAX;
	for(int i=0;i<=(ns-nt);i++) {
		int idx = 0;
		int ch = 0;
		for(int j=i;j<i+nt;j++,idx++) {
			if(s[j] != t[idx]) ch++;
		}
		mini = min(mini, ch);
	}
	cout<<mini<<en;
}

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


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ll n,k;
	cin>>n>>k;
	char str[n];
	for(ll i=0;i<n;++i){
		cin>>str[i];
	}
	char temp[n];
	temp[0]=str[0];
	ll s=1;
	for(ll i=1;i<n;++i){
		if(str[i]!=str[i-1])
			temp[s++]=str[i];
	}
	// for(ll i=0;i<s;++i){
	// 	cout<<temp[i];
	// }
	// cout<<endl;
	if(s<2*k+1)
		cout<<n-1<<endl;
	else{
		ll seg=s-(2*k);
		cout<<n-seg<<endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;
v<int> a,b;
int solve(int N,int X){
  if(N==0 && X>=1) return 1;
  if(X<=1) return 0;
  if(1<=X && X<= 1+a[N-1]){
    return solve(N-1,X-1);
  }
  if(2+a[N-1]<=X && X<=2+2*a[N-1]){
    return 1+b[N-1]+solve(N-1,X-a[N-1]-2);
  }
  if(X==3+2*a[N-1]) return b[N];
}

signed _main(){
  int N,X; cin >> N >> X;
  a.assign(50+10,0);
  b.assign(50+10,0);
  a[0]=1;
  b[0]=1;
  for(int i=1;i<=N;i++){
    a[i]=2*a[i-1]+3;
    b[i]=2*b[i-1]+1;
  }
  cout << solve(N,X) << endl;
  return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int A = read(), B = read(), C = read();
  int f, t;
  f = min(A, B);
  t = max(A, B);
  if (f < C && t > C)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    a,b,c,d = MII()
    print(max(a*c, a*d, b*c, b*d))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9188
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    S, T = sys.stdin.read().split()

    ls, lt = len(S), len(T)
    ans = lt
    for i in range(ls - lt+1):
        x = 0
        for j in range(lt):
            if S[i+j] == T[j]:
                continue
            x += 1
            if x > ans:
                break
        else:
            if x < ans:
                ans = x

    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 67632
#include <cstdio>
#include <iostream>
using namespace std;
char s[110];
int n,pos,maxn;
int main()
{
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;++i)
    {
        if(s[i]=='I')++pos;
        else --pos;
        maxn=max(maxn,pos);
    }
    printf("%d\n",maxn);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  string s,t; cin>>s>>t;
  s = s+s;
  for(int i=0; i<s.size(); i++){
    bool flg{1};
    for(int j=0; j<t.size(); j++){
      if(i+j>=s.size()) {
        flg=0;
        break;
      }
      if(s.at(i+j)!=t.at(j)) {
        flg=0;
        break;
      }
    }
    if(flg==0) continue;
    else {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No"<< endl;
  
}



Measured memory_bytes: 3220
// Author -- Frame

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<iostream>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG printf("Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;
const double eps=1e-10;

uint seed=19260817;
const uint _RAND_MAX_=4294967295u;
Finline uint Rand(){return seed=seed*998244353u+1000000007u;}

template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline bool _cmp(const _Tp &a,const _Tp &b){return abs(a-b)<=eps;}
template <typename _Tp>Finline void read(_Tp &x)
{
	register char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	register char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	register char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=100005;
struct edge{
	int v,nxt,w;
}c[N<<1];
int front[N],_cnt;
Finline void add(int u,int v,int w)
{
	c[++_cnt]=(edge){v,front[u],w},front[u]=_cnt;
}
bool vis[N];
int col[N];
int cnt[3];
int qwq,qaq;
bool dfs(int x,int C)
{
	if(vis[x])
	{
		if(col[x]!=C) return false;
		return true;
	}
	++qwq;
	vis[x]=true;
	col[x]=C;
	++cnt[C];
	bool flag=true;
	for(int i=front[x];i;i=c[i].nxt)
	{
		++qaq;
		flag&=dfs(c[i].v,(C+c[i].w)%3);
	}
	return flag;
}
int main()
{
	int n,m;
	read(n,m);
	int x,y;
	for(int i=1;i<=m;++i)
	{
		read(x,y);
		add(x,y,1),add(y,x,2);
	}
	ll ans=0;
	for(int i=1;i<=n;++i)
	{
		if(!vis[i])
		{
			qwq=qaq=0;
			cnt[0]=cnt[1]=cnt[2]=0;
			bool flag=dfs(i,0);
			if(flag)
			{
				if(cnt[0]&&cnt[1]&&cnt[2])
				{
					ans+=1ll*cnt[0]*cnt[1];
					ans+=1ll*cnt[1]*cnt[2];
					ans+=1ll*cnt[2]*cnt[0];
				}
				else
				{
					ans+=qaq>>1;
				}
			}
			else
			{
				ans+=1ll*qwq*qwq;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(a+b,min(b+c,a+c)) << endl;

    return 0;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	vector<pair<int, int>> vec;
	
	rep(i, n){
		int x, y;
		cin >> x >> y;
		pair<int, int> p = make_pair(x, y);

		vec.push_back(p);
	}

	vector<vector<long long int>> dp;

	rep(i, n + 1){
		vector<long long int> v;

		rep(j, w + 1){
			v.push_back(0);
		}

		dp.push_back(v);
	}

	for(int i = 1; i < n + 1; i++){
		for(int j = 1; j < w + 1; j++){
			if(vec[i - 1].first <= j){
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - vec[i - 1].first] + vec[i - 1].second);

				// cout << "? : " << dp[i - 1][j - vec[i - 1].first] + vec[i - 1].second << endl;
			}
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}

	/*
	rep(i, n + 1){
		rep(j, w + 1){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	*/

	cout << dp[n][w];

	return 0;
}

Measured memory_bytes: 80232
N,X = list(map(int,input().split()))
x = list(map(int,input().split()))

def euclid(x,y):
    if x > y:
        x,y = y,x
    d = 0
    while(True):
        if y%x == 0:
            return x
        else:
            d= x
            x = y%x
            y= d

ans = abs(x[0]-X)
for i in range(1,N):
    ans = euclid(ans,abs(x[i]-X))
print(ans)

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

using namespace std;

int main(){
    string s;
    cin >> s;

    int res = 0;
    bool black = false;
    if (s[0] == 'B') black = true;
    for (int i = 1; i < s.size(); i++){
	if (black && (s[i] == 'W')){
	    res++;
	    black = false;
	} else if (!black && (s[i] == 'B')){
	    res++;
	    black = true;
	}
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 512
def solve(i, cost, know, x, a):
    global res
    if i == len(a):
        for j in range(m):
            if know[j] < x:
                return
        res = min(res, cost)
        return
    solve(i + 1, cost, know, x, a)
    for j in range(m):
        know[j] += a[i][j + 1]
    solve(i + 1, cost + a[i][0], know, x, a)
    for j in range(m):
        know[j] -= a[i][j + 1]
n, m, x = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
know = [0] * (m)
res = 10 ** 7
solve(0, 0, know, x, a)
print(res if res != 10 ** 7 else - 1) 

Measured memory_bytes: 9232
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

bool check_encode(string str, char c, string sn) {
	string ss = "";
	for (int i = 0; i < str.length(); ++i) {
		if (str[i] == c) {
			ss += "ABC";
		}
		else {
			ss += str[i];
		}
	}
	cout << str << " " << ss << " " << sn << endl;
	if (ss == sn) {
		return false;
	}
	else {
		return true;
	}
}

int main(void) {
	string str;
	cin >> str;

	string sn = str;
	queue<string> gene;
	gene.push(str);
	bool find = false;

	while (sn.length() > 2 && !gene.empty()) {
		sn = gene.front();
		gene.pop();

		if (sn == "ABC") {
			find = true;
			break;
		}

		vector<bool> seq(sn.length(),false);
		bool cs = false;
		//ABC??????
		for (int i = 0; i < sn.length()-2; ++i) {
			if (sn[i] == 'A' && sn[i+1] == 'B' && sn[i+2] == 'C') {
				seq[i] = true;
				cs = true;
			}
		}

		bool fa,fb,fc;
		fa = fb = fc = false;
		//???????????????
		if (cs) {
			string astr,bstr,cstr;
			astr = bstr = cstr = "";
			for (int i = 0; i < sn.length(); ++i) {
				if (seq[i]) {
					astr += "A";
					bstr += "B";
					cstr += "C";
					i += 2;
				}
				else {
					astr += sn[i];
					bstr += sn[i];
					cstr += sn[i];
					if (sn[i] == 'A') {
						fa = true;
					}
					else if (sn[i] == 'B') {
						fb = true;
					}
					else if (sn[i] == 'C') {
						fc = true;
					}
				}
			}

			if (!fa) {
				gene.push(astr);
			}
			if (!fb) {
				gene.push(bstr);
			}
			if (!fc) {
				gene.push(cstr);
			}
			//cout << astr << " " << bstr << " " << cstr << endl;
		}
	}

	if (find) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3260
a = int(input())
b = input().split()
total = 0
max_case = 0
for i in range(len(b)-1):
    if int(b[i]) >= int(b[i+1]):
        total += 1
    else:
        total=0
    if max_case < total:
        max_case = total
print(max_case)

Measured memory_bytes: 64112
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        a, b = map(int, input().split())
        if a == 0 or b == 0:
            return 'Zero'
        elif a > 0:
            return 'Positive'
        else:
            if b<0:
                if (b-a)%2==0:
                    return 'Negative'
                else:
                    return 'Positive'
            else:
                return 'Zero'
    print(main())





resolve()

Measured memory_bytes: 38256
#include<stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if ((a * 100 + b * 10 + c) % 4 == 0)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
n = int(input())
out = []
ans = []
if n%2 == 0:
    for i in range(1,n//2+1):
        out.append([i, n-i+1])
else:
    for i in range(1, n//2+1):
        out.append([i,n-i])
for i in range(1,n+1):
    for j in range(i+1, n+1):
        if [i,j] not in out:
            ans.append([i,j])
print(len(ans))
for i in range(len(ans)):
    print(ans[i][0], ans[i][1])


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

int keta(int n) {
    int res;
    for(int i = 0; i < 100; i++) {
        n = n / 10;

        if(n == 0) {
            res = i + 1;
            break;
        }
    }
    return res;
}

int main() {
    int n,m,sum=0;
    cin>>n>>m;
    vector<int> a;
    rep(i,m) {
        int a;
        cin>>a;
        sum+=a;
    }
    if(sum>n){
        cout<<-1<<endl;
    }
    else cout<<n-sum<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

int dp[100010];

int h[100010];

int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		dp[i] = INF10;
	}

	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[N - 1] << endl;

	return 0;
}


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

using namespace std;

using ll = long long;

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

    for (int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
} 

Measured memory_bytes: 256
import sys
from collections import Counter

class UnionFind(object):
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0 for i in range(n + 1)]

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[y] = x
            self.rank[x] += 1

sys.setrecursionlimit(10 ** 5 + 1)

n, k, l = map(int, input().split())
Ur = UnionFind(n)
for i in range(k):
    p, q = map(int, input().split())
    Ur.union(p, q)

Ut = UnionFind(n)
for i in range(l):
    r, s = map(int, input().split())
    Ut.union(r, s)

x = [(Ur.find(i + 1), Ut.find(i + 1)) for i in range(n)]
c = Counter(x)
ans = []
for i in range(n):
    ans.append(c[x[i]])
print(' '.join([str(a) for a in ans]))


Measured memory_bytes: 72444
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

//#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}

//OJ freopen Template
void OJF(const char* inp, const char* out) {
	if (strlen(inp) > 0) freopen(inp, "r", stdin);
	if (strlen(out) > 0) freopen(out, "w", stdout);
}

signed main()
{
	fastio();
	int n; cin >> n;
	int cnt = (n / 500) * 1000;
	n %= 500;
	cnt += (n / 5) * 5;
	cout << cnt;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
 
int main(){
  string N, ans;
  cin >> N;
  
  if(N[0] == '7' || N[1] == '7' || N[2] == '7')
    ans = "Yes";
  else
    ans = "No";
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
n,k=map(int,input().split())


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

ar=[-1 for i in range(n+1)]
p=1

go=0


for i in range(1,k+1):
    
    
    
    

    ar[p]=i-1
    p=a[p-1]
    
    if ar[p]>0:
        j=ar[p]
        amari=(k-i)%(i-j)
        
        go=1
        break

if go==1:
    p=ar.index(j+amari)
    
    


print(p)


Measured memory_bytes: 32372
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	scanf("%d",&n);
	int arr[n];
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	printf("%d\n",*max_element(arr,arr+n)-*min_element(arr,arr+n));
	return 0;
}

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

const string INITIAL = "MARCH";

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

    int m = INITIAL.size();
    vector<int> cnt(m, 0);
    for(int i=0; i<n; ++i){
        string s;
        cin >> s;
        int j = INITIAL.find(s[0]);
        if(j != string::npos)
            ++ cnt[j];
    }

    vector<long long> dp(4, 0);
    dp[0] = 1;
    for(int i=0; i<m; ++i){
        for(int j=2; j>=0; --j){
            dp[j+1] += dp[j] * cnt[i];
        }
    }
    cout << dp[3] << endl;

    return 0;
}


Measured memory_bytes: 256
#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

map<ll,ll> pfact(ll n) {
  map<ll,ll> ret;
  while(n%2==0) {ret[2]++;n/=2;}
  for(ll i=3;i*i<=n;i+=2) while(n%i==0) {ret[i]++;n/=i;}
  if(n!=1) ret[n]=1;
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  for(ll i=1;i<=n;i+=2) {
    map<ll,ll> mp=pfact(i);
    ll v=1;
    for(P p:mp) v*=(p.second+1);
    if(v==8) ans++; 
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3632
import sys

def text_match_word(text, words):
    for word in words:
        if word == text[:len(word)]:
            return word

words_next = (("dream", "er"), ("erase", "r"))
words_next_dict = dict(words_next)

s = input()

before_match_word = ""
while "" != s:
    search_words = list(words_next_dict.keys())
    if before_match_word in words_next_dict:
        search_words.append(words_next_dict[before_match_word])
    match_word = text_match_word(s, search_words)
    if match_word != None:
        s = s[len(match_word):]
    else:
        print("NO")
        sys.exit()
    before_match_word = match_word
    
print("YES")
    

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long int a,b,c,d,p,q,r,s;
	cin>>a>>b>>c>>d;

	p = a*c;
	q = a*d;
	r = b*c;
	s = b*d;

	cout<< max(p,max(max(r,s),q)) <<endl;

	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
ll gcd(int a, int b){
	if (a%b==0){
		return b;
	}
	else {
		gcd(b, a%b);
	}
	
}
int main(){
	ll A, B, C, D,ans=0;
	cin >> A >> B >> C >> D;
	ll ss = (C*D) / gcd(C, D);
	A--;
	ll hkytB = B / ss,hkytA=(A)/ss;

	cin >> A >>  B >> C >> D;
	ans = (B - (B / C) - (B / D) + hkytB) - (A - (A / C) - (A / D) + hkytA);
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char *argv[])
{
	char a[11];

	while(scanf("%s",a) != EOF)
	{
	if(a[0] == 'Y' && a[1] == 'A' && a[2] == 'K' && a[3] == 'I')printf("Yes\n");
	else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
//
//  main.cpp
//  AOJ
//
//  Created by user on 2014/06/01.
//  Copyright (c) 2014年 user. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <cstring>
using namespace std;

const int SIZE = 3628810;
typedef pair< vector<int>, int > Pack;

int getPermId(const vector<int>& v){
    const int N = (int)v.size();
    
    int fact = 1;
    int res = 0;
    
    for(int i=N-1;i>=0;i--){
        for(int j=i+1;j<N;j++){
            if(v[j] < v[i]){
                res += fact;
            }
        }
        fact *= (N - i);
    }
    
    return res;
}

int dist[2][SIZE];
vector<Pack> Queue[2];

int bfs(const vector<int>& start, const vector<int>& goal){
    memset(dist, -1, sizeof(dist));
    
    const int N = (int)start.size();
    const int startId = getPermId(start);
    const int goalId  = getPermId(goal);
    
    if(startId == goalId){
        return 0;
    }
    
    int curr = 0, next = 1;
    
    dist[curr][startId] = 0;
    dist[next][goalId]  = 0;
    
    Queue[curr].push_back(make_pair(start, startId));
    Queue[next].push_back(make_pair(goal,  goalId));
    
    for(;;){
        vector<Pack> nextQueue;
        for(int i=0;i<Queue[curr].size();i++){
            Pack pack = Queue[curr][i];
            
            vector<int> perm = pack.first;
            int permId = pack.second;
            int nowCost = dist[curr][permId];
            
            for(int s=0;s<N;s++)for(int t=s+1;t<N;t++){
                reverse(perm.begin() + s, perm.begin() + t + 1);
            
                int nextPermId = getPermId(perm);
                if(dist[curr][nextPermId] == -1){
                    dist[curr][nextPermId] = nowCost + 1;
                    nextQueue.push_back(make_pair(perm, nextPermId));
                
                
                    if(dist[next][nextPermId] != -1){
                        return dist[curr][nextPermId] + dist[next][nextPermId];
                    }
                }
                
                reverse(perm.begin() + s, perm.begin() + t + 1);
            }
        }
        Queue[curr].swap(nextQueue);
        
        swap(curr, next);
    }
    
    return 1;
}

int main(){
    int N;
    cin >> N;
    
    vector<int> start(N);
    for(int i=0;i<N;i++){
        cin >> start[i];
        --start[i];
    }
    
    vector<int> goal = start;
    sort(goal.begin(), goal.end());
    
    int res = bfs(start, goal);
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 77324