akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt(), q = scan.nextInt();
		int[] p = new int[n+1];
		char prev = 'z';
		char[] a = scan.next().toCharArray();
		for(int i = 1; i <= n; i++) {
			if(a[i-1] == 'C' && prev == 'A') p[i]++;
			p[i] += p[i-1];
			prev = a[i-1];
		}
		for(int i = 0; i < q; i++) {
			int l = scan.nextInt() - 1, r = scan.nextInt();
			int get = p[r] - p[l];
			if(l > 0 && a[l] == 'C' && a[l-1] == 'A') get--;
			out.println(get);
		}
		out.close();
	}
	
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }

}


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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define PB push_back
#define MP make_pair
#define MOD 1000000000
#define FOR(i,a,b) for(int i=(a);(i)<(b);(i)++)

typedef unsigned int UI;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<char, int> PCI;
int a , b;
int main()
{
	scanf("%d %d" , &a , &b);
	if(a <= 0 && b >= 0)
	{
		cout << "Zero";
		return 0;
	}
	if(a > 0)
	{
		cout << "Positive";
		return 0;
	}
	int len =  b - a + 1;
	if(!(len % 2))
	{
		cout << "Positive";
	}
	else
		cout << "Negative";
    return 0;
}





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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

vector< pair<char, int> > runlength(string S) {
    vector< pair<char, int> > len;
    char cur = S[0];
    int cnt = 0;
    REP(i, S.size()) {
        if (S[i] == cur) {
            cnt++;
        } else {
            len.pb(make_pair(cur, cnt));
            cur = S[i];
            cnt = 1;
        }
    }
    len.pb(make_pair(cur, cnt));
    return len;
}

int calc(vector< pair<char, int> > len) {
    int ans = 0;
    for (auto& e: len) {
        ans += e.second - 1;
    }
    return ans;
}

signed main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    priority_queue<pi> L, R;
    vector< pair<char, pi> > len;
    char cur = S[0];
    int cnt = 0;
    REP(i, S.size()) {
        if (S[i] == cur) {
            cnt++;
        } else {
            len.pb(make_pair(cur, make_pair(i-cnt, cnt)));
            if (cur == 'R') R.push(make_pair(cnt, i-cnt));
            else L.push(make_pair(cnt, i-cnt));
            cur = S[i];
            cnt = 1;
        }
    }
    len.pb(make_pair(cur, make_pair(S.size()-cnt, cnt)));

    string S1 = S;
    string S2 = S;

    // L戦略
    int k = K;
    while (k > 0 && !R.empty()) {
        auto a = R.top(); R.pop();
        //cout << a.first << " " << a.second << endl;
        REP2(i, a.second, a.first + a.second - 1) {
            S1[i] = 'L';
        }
        //cout << S1 << endl;
        k--;
    }

    // R戦略
    k = K;
    while (k > 0 && !L.empty()) {
        auto a = L.top(); L.pop();
        REP2(i, a.second, a.first + a.second - 1) {
            S2[i] = 'R';
        }
        //cout << S2 << endl;
        k--;
    }

    /*
    cout << S1 << endl;
    cout << S2 << endl;
    */

    auto rl1 = runlength(S1);
    auto rl2 = runlength(S2);
    int ans = max(calc(rl1), calc(rl2));

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define pb push_back

long long x, ans;
string s;

int main() {

    cin >> s;

    for(int i = 0; i < s.size(); ++i){
        if(s[i] == 'A'){
            x++;
        }
        else if(s[i] == 'B'){
            if(s[i + 1] == 'C') {ans += x; i++;}
            else x = 0;
        }
        else{
            x = 0;
        }
    }

    cout << ans;

    return 0;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d;
	cin>>n>>d;
	vector<vector<int>>arr(n,vector<int>(d));
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin>>arr[i][j];
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int temp=0;
			for(int k=0;k<d;k++){
				temp+=pow(arr[i][k]-arr[j][k],2);
			}
			// cout<<temp<<" "<<(int)sqrt(temp)*(int)sqrt(temp)<<"\n";
			if(temp==(int)sqrt(temp)*(int)sqrt(temp)){
				res++;
			}
		}
	}
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
vector<ll> divisor(ll n){
    vector<ll> ret;
    for (ll i = 1 ; i*i <= n ; i++){
      if(n%i == 0 ){
        ret.push_back(i);
        if(i!=1&&i*i!=n){
          ret.push_back(n/i);
        }
      }
    }
    sort(ret.begin(),ret.end());
    return ret;
  }
 
int main(){
  vector<int> Ans ;
  int j = 0 ;
  for(int i = 3 ; i < 100000 ; i++ ){
    auto A = divisor(i) ; auto B = divisor( ( i + 1 )/2 ) ;
    if( A.size() == 1 && B.size() == 1 ){
      Ans.push_back(i) ;
    }
  }
  int Q ;
  cin >> Q ;
  j = 0 ;
  int count = 0 ;
  int C , D ;
  rep(i,Q){
    count = 0 ;
    cin >> C >> D ;
    rep( j , Ans.size() )if( C <= Ans.at(j) && Ans.at(j) <= D ) count++  ;
    cout << count << endl;
    //cout << Ans.size() << endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main() {
    string S, T;
    cin >> S >> T;
    bool ok = true;
    map<char,char> ma, ima;
    for (int i = 0; i < S.size(); ++i) {
        char s = S[i], t = T[i];
        if (ma.count(s)) if (ma[s] != t) ok = false;
        if (ima.count(t)) if (ima[t] != s) ok = false;
        ma[s] = t; ima[t] = s;
    }
    if (ok) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 776
#include "cstdio"
#include "cstring"

int N,M;
int island[200004];
bool dag[200004];
int min(int x,int y)
{
    return x>y?y:x;
}
int main()
{
    int a,b,flag;
    while (scanf ("%d%d",&N,&M) != EOF)
    {
        flag = 0;
        for (int i=1;i<=N;i++)
        {
            island[i] = 200001;
        }
        memset(dag,0,sizeof(dag));
        for (int i=0;i<M;i++)
        {
            scanf ("%d%d",&a,&b);
            if (b != N)
            {
                 island[b] = min(island[b],a);
            }
            else
            {
                 dag[a] = 1;
            }
        }
        for (int i=1;i<=N;i++)
        {
            if (island[i] == 1 && dag[i])
            {
                flag=1;
                break;
            }
        }
        printf ("%s\n",flag?"POSSIBLE":"IMPOSSIBLE");
    }
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int bit_counter(int x){
    if(x==0) return 0;
    return bit_counter(x>>1)+(x&1);
}
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    set<string> si[5];
    rep(i,n){
        string s;
        cin >> s;
        if(s[0] == 'M') si[0].insert(s);
        if(s[0] == 'A') si[1].insert(s);
        if(s[0] == 'R') si[2].insert(s);
        if(s[0] == 'C') si[3].insert(s);
        if(s[0] == 'H') si[4].insert(s);
    }
    ll sum = 0;
    rep(i,1<<5){
        ll now = 1;
        if(bit_counter(i)!=3) continue;
        rep(j,5){
            if((i>>j)&1){
                now *= (ll)si[j].size();
            }
        }
        sum += now;
    }
    cout << sum << endl;
    return 0;
}

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

int main(){
    
    int n;
    cin>>n;
    std::vector<int>va(n) ;
    std::vector<int>vb(n) ;
    std::vector<int>vc(n) ;
    for(int i=0;i<n;i++){
        cin>>va[i]>>vb[i]>>vc[i];
    }
    int a=va[0],b=vb[0],c=vc[0];
    int x,y,z;
    for(int i=1;i<n;i++){
        x=va[i]+max(b,c);
        y=vb[i]+max(a,c);
        z=vc[i]+max(b,a);
        a=x;
        b=y;
        c=z;
    }
    cout<<max(max(a,b),c);
    
}
        

Measured memory_bytes: 1408
n, a, b = map(int, input().split())
x = list(map(int, input().split()))

ans = 0

for i in range(n-1):
    if x[i+1] - x[i] <= b // a:
        ans += a * (x[i+1] - x[i])
    else:
        ans += b

print(ans)

Measured memory_bytes: 15020
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0; i<s.size()/2; i++){
        if(s[i] != s[s.size()-1-i]){
         ans++;   
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n = inp()
remain = n - (n//500)*500

print((n//500)*1000 + 5*(remain//5))
#print()


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int N,i,j,c[13][7],mv[5]={0,1,0,-1,0};
char M[13][7],t;


int ch(int h,int w,char p)
{
	int i,j,nh,nw,r=1;
	c[h][w]=1;
	for(i=0;i<4;i++)
	{
		nh=h+mv[i];nw=w+mv[i+1];
		if(M[nh][nw]==p&&!c[nh][nw])
		{
			c[nh][nw]=1;
			r+=ch(nh,nw,p);
		}
	}
	return r;
}

void del(int h,int w,char p)
{
	int i,j,nh,nw;
	M[h][w]='.';
	for(i=0;i<4;i++)
	{
		nh=h+mv[i];nw=w+mv[i+1];
		if(M[nh][nw]==p)
			del(nh,nw,p);
		else if(M[nh][nw]=='O')
			M[nh][nw]='.';
	}
}

int sh()
{
	int f=0,i,j;
	for(i=0;i<12;i++)
		for(j=0;j<6;j++)
		{
			if(M[i][j]=='.'||M[i][j]=='O')continue;
			memset(c,0,sizeof(c));
			if(ch(i,j,M[i][j])>=4)
			{
				del(i,j,M[i][j]);
				f=1;
				//dbg();
			}
		}
	return f;
}

int main()
{
	scanf("%d\n",&N);
	for(;N--;)
	{
		int c=0,i,j,a,b;
		for(i=0;i<12;i++)gets(M[i]);
		//dbg();
		for(;sh();c++)
		{
			for(i=11;i>=0;i--)
				for(j=0;j<6;j++)
				{
					if(M[i][j]=='.')
					{
						for(a=0;M[i][j]=='.'&&a<i;a++)
						{
							for(b=i;b>0;b--)
							{
								t=M[b-1][j];
								M[b-1][j]=M[b][j];
								M[b][j]=t;
							}
						}
					}
				}
			//dbg();
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 596
C_0 = 0
C_1 = 0
C_2 = 0
C_3 = 0  
N = int(input())
for result in range(N) :
	result = input()
	if result == 'AC':
		C_0 += 1
	elif result == 'WA':
		C_1 += 1
	elif result == 'TLE':
		C_2 += 1
	elif result == 'RE':
		C_3 += 1

print('AC x',C_0)
print('WA x',C_1)
print('TLE x',C_2)      
print('RE x',C_3)
       

       
       
       

Measured memory_bytes: 9144
#include<stdio.h>
 
void bsort(int a[], int n){
	int i, j, temp;
 
	for(i = 0; i < n - 1; i++){
		for(j = n - 1; j > i; j--){
			if(a[j-1] > a[j]){
				temp = a[j-1];
				a[j-1] = a[j];
				a[j] = temp;
			}
		}
	}
}
 
int main(void){
	int i, N, M, SUM, A[101] = {0};
 
	scanf("%d %d", &N, &M);
 
	for(i = 0; i < N ; i++)
		scanf("%d", &A[i]);
 
 
	for(i = 0; i < N; i++)
		SUM = SUM + A[i];
 
	bsort(A, N);
 
 
	if(A[N-M] >= (float) SUM/(4*M))
		printf("Yes");
	else
		printf("No");
 
	return 0;
}

Measured memory_bytes: 128
n = int(input())
arr = list(input())

head = 0
tail = n-1
ans = 0
while head < n:
    if arr[head] == "R":
        head += 1
    else:
        break
while tail >= 0:
    if arr[tail] == "W":
        tail -= 1
    else:
        break
while head < tail:
    head += 1
    tail -= 1
    ans += 1
    while head < n:
        if arr[head] == "R":
            head += 1
        else:
            break
    while tail >= 0:
        if arr[tail] == "W":
            tail -= 1
        else:
            break

print(ans)

Measured memory_bytes: 10640
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f,g,h;
int main()
{
	cin>>a;
	b=sqrt(a);
	while(b>0)
	{
		if(a%b==0)
		{
			cout<<a/b+b-2;
			return 0;
		}
		b--;
	}
	return 0;
 } 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 5000
 
typedef struct list
{
  int x,y,ground;
  struct list *prev;
  struct list *next;
} list;
 
list head;
list tail;
void Insert(char);
list *FarSide(list *);
int PubbleArea(list *, list *);
 
int main(){
  int i,pubbleCount=0,pubble[N],sumPubble=0;
  char c;
  list *p,*farSide;     
  head.next = &tail;
  tail.prev = &head;
  while(1){
    c = getchar();
    if(c == '\n') break;
    Insert(c);
  }
  for(p = head.next; p != &tail; p = p->next){
    if(p->ground=='\\' &&(farSide=FarSide(p)) != NULL){
      pubble[pubbleCount] = PubbleArea(p, farSide);
      sumPubble += pubble[pubbleCount];
      p = farSide;
      pubbleCount++;
    }  
  }
  printf("%d\n%d", sumPubble, pubbleCount);
  for(i = 0; i < pubbleCount; i++){
    printf(" %d", pubble[i]);
  }
  printf("\n");
  return 0;
}
 
void Insert(char c){
  static int xCount = 0;
  static int yCount = 0;
  list *p;
  p = (list*)malloc(sizeof(list));
  p->prev = tail.prev;
  tail.prev->next = p;
  p->next = &tail;
  tail.prev = p;
  xCount++;
  if(c == '\\'){
    yCount--;
  }
  if(c == '/' ){
    yCount++;
  }
  p->x = xCount;
  p->y = yCount;
  p->ground = c;
}
 
list *FarSide(list *s){
  list *i_p;
  int height;
  height = s->y + 1;
  for(i_p = s->next; i_p != &tail; i_p = i_p->next){
    if(i_p->y == height){
      return i_p;
    }
  }
  return NULL;
}

int PubbleArea(list *pS, list *pE){
    list *i_p;
    list *farSide;
    int area = 0;
    for(i_p = pS; i_p != pE; i_p = i_p->next){
        if(i_p->ground == '\\'){
            farSide = FarSide(i_p);
            area += farSide->x - i_p->x;
        }
    }
    return area;
}

Measured memory_bytes: 1488
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

// Returns n divisors ORDER BY ASC.
vector<i64> getDivisors(i64 n)  // {{{
{
    vector<i64> ret;
    i64 i = 1;
    for (i = 1; i * i < n; ++i) {
        if (n % i == 0) {
            ret.emplace_back(i);
            ret.emplace_back(n / i);
        }
    }
    if (i * i == n) ret.emplace_back(i);
    sort(begin(ret), end(ret));
    return ret;
}  // }}}

// n が素数ならtrueを返す。 O(sqrt(N))
constexpr bool isPrime(i64 n)  // {{{
{
    if (n < 2) return false;
    if (n % 2 == 0) return (n == 2);
    for (i64 i = 3; i * i <= n; i += 2)
        if (n % i == 0) return false;
    return true;
}  // }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(i64, A, B);
    i64 ans = 0;
    for (const i64 d : getDivisors(__gcd(A, B))) {
        ans += isPrime(d);
    }
    print(ans + 1);

    return 0;
}


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

#define ll long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define all(v) (v).begin(), (v).end()

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

    int a, b, h, m;
    double a1, a2, a3, c;
    cin >> a >> b >> h >> m;
    a1 = h * 30 + m * 0.5;
    a2 = m * 6;
    a3 = ((a1 - a2 >= 0 ? a1 - a2 : a2 - a1) / 180) * acos(-1);
    c = sqrt((double)(a * a + b * b) - ((double)2 * a * b) * cos(a3));
    cout << setprecision(12) << c;
}

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

string strs[4] = {"dream", "dreamer", "eraser", "erase"};

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

  reverse(str.begin(), str.end());
  for (int i = 0; i < 4; i++) {
    reverse(strs[i].begin(), strs[i].end());
  }

  bool can = true;
  int tmp;
  for (int i = 0; i < str.size();) {
    bool can2 = false;
    for (int j = 0; j < 4; j++) {
      string d = strs[j];
      if (str.substr(i, d.size()) == d) {
        can2 = true;
        i += d.size();
      }
    }
    if (can2 == false) {
      can = false;
      break;
    }
  }

  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int H, W, DP[100][100];
char S[100][100];

int main(){
  cin >> H >> W;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> S[i][j];
    }
  }
  fill((int*)DP, (int*)(DP + H), -1);

  priority_queue <pair<int,Pii>, vector<pair<int,Pii>>, greater<pair<int, Pii>>> que;


  if (S[0][0] == '.') que.push(make_pair(0, make_pair(0, 0)));
  else que.push(make_pair(1, make_pair(0, 0)));
  int di[2] = {1, 0}, dj[2] = {0, 1};

  while (!que.empty()){
    pair<int, Pii> P = que.top(); que.pop();
    int i = P.second.first, j = P.second.second;

    if (DP[i][j] != -1) continue;
    DP[i][j] = P.first;

    for (int k = 0; k < 2; k++){
      int I = i + di[k], J = j + dj[k];
      if (I < H && J < W){
        if (DP[I][J] != -1) continue;

        if (S[i][j] == '.' && S[I][J] == '#'){
          que.push(make_pair(P.first + 1, make_pair(I, J)));
        }else{
          que.push(make_pair(P.first, make_pair(I, J)));
        }
      }
    }
  }

  cout << DP[H - 1][W - 1] << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll  long long 
#define dl long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second


int main ()
{

    ll n ,sum=0;
    cin >>n ;
    ll arr[n];
    for (int i = 0 ;i<n;i++){
    	cin>>arr[i];
    }
    sort (arr,arr+n);
    int k=n-1;

    for (int i = n-1 ;i>=1;i--)
    {
        if(i==n-1)
        {
        	sum+=arr[i];
        	k--;
        }
        else{
        	sum+=arr[i];
        	k--;
        }
        if (i!=n-1 && k>0)
        {
        	sum+=arr[i];
        	k--;
        }
        if (k==0)
        	break;
        
    }
    cout<<sum<<endl;
	return 0;

}

Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <map>
#define _GLIBCXX_DEBUG
using namespace std;

int main()
{
    int n;
    cin >> n;
    map<int, int> A;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        A[a] += 1;
    }
    for (auto p : A)
    {
        if (p.second == 1)
        {
            continue;
        }
        if (p.second != 1)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12912
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];
        for(int i = 0;i<n;i++) {
            a[i] = stdIn.nextInt();
        }

        for(int i = 0;i<n;i++) {
            b[i] = stdIn.nextInt();
        }

        for(int i = 0;i<n-1;i++) {
            c[i] = stdIn.nextInt();
        }

        int count = 0;

        for(int i = 0;i<b.length;i++) {
            count += b[i];
        }
        //System.out.println(count);

        for(int i = 0;i<b.length-1;i++) {
            if(a[i]!=n && a[i]+1 == a[i+1]) {
                count += c[a[i]-1];
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21716
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readStringAsByte() []byte {
	return []byte(readString())
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()

	s := readStringAsByte()
	var ans int64
	var w int64
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == 'W' {
			w++
		} else {
			ans += w
		}
	}
	println(ans)
}

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


Measured memory_bytes: 1536
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int a,b,c;
  while(cin>>a>>b>>c!='\0'){
    int out=20-a-b;
    int han=0;
    if(out>=a)han++;
    if(out>=b)han++;
    if(out>=c)han++;
    if(out-han>3)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(void) {
	int n;
	char c[100][4];
	int i, j;
	while (scanf("%d", &n) == 1 && n > 0) {
		int hyou[27] = {0}; /* 26 letters + one more candidate */
		int won = 0;
		for (i = 0; i < n; i++) {
			if (scanf("%s", c[i]) != 1) return 1;
		}
		for (i = 0; i < n; i++) {
			int left = n - i - 1;
			int max = 0, max_index = 0, second_max = 0;
			hyou[c[i][0] - 'A']++;
			for (j = 0; j < 27; j++) {
				if (hyou[j] >= max) {
					second_max = max;
					max = hyou[j];
					max_index = j;
				} else if (hyou[j] >= second_max) {
					second_max = hyou[j];
				}
			}
			if (max > second_max + left) {
				printf("%c %d\n", max_index + 'A', i + 1);
				won = 1;
				break;
			}
		}
		if (!won) puts("TIE");
	}
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n;
   cin>>n;

   vector<long int> v(n);
   for(long int i = 0; i < n; i++)
   	 cin>>v[i];

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

   	long int idx = n - 1;
   	long int cnt = n - 1;
   	long int ans = 0;

   	while(true){
   		if(!cnt)
   			break;
   		if(cnt == n - 1){
   			ans += v[idx];
   			idx--;
   			cnt--;
   		}
   		else if(cnt == 1){
   			ans += v[idx];
   			idx--;
   			cnt--;
   		}
   		else{
   			ans += 2 * v[idx];
   			idx--;
   			cnt -= 2;
   		}
   	}

   	cout<<ans;
   return 0;
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

bool isa(string s){
    if(s.substr(0,2) != ">'") return false;
    int x = 2;
    int c = 0;
    while(s[x+c] == '='){
	c++;
    }
    if(s[x+c] != '#') return false;
    x = x + c + 1;
    for(int i=0;i<c;i++){
	if(s[x+i] != '=') return false;
    }
    x += c;
    if(s[x] != '~') return false;
    return true;
}

bool isb(string s){
    if(s[0] != '>') return false;
    if(s[1] != '^') return false;
    int x = 2;
    int c = 0;
    while(s[x+c] == 'Q' && s[x+1+c] == '='){
	c += 2;
    }
    x += c;
    if(s[x] != '~') return false;
    if(s[x+1] != '~') return false;
    return true;
}

int main(){
    string s = "";
    int n;
    cin >> n;
    REP(i,n){
	cin >> s;
	if(s.size() < 6){
	    cout << "NA" << endl;
	    continue;
	}
	if(isa(s)) cout << "A"<<endl;
	else if(isb(s)) cout << "B" << endl;
	else cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastReader scan = new FastReader();
        //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("marathon.out")));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        Task solver = new Task();
        //int t = scan.nextInt();
        int t = 1;
        for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
        out.close();
    }
    static class Task {
        public void solve(int testNumber, FastReader sc, PrintWriter pw) {
            int n = sc.nextInt();
            int c = sc.nextInt();
            int[] arr = new int[n];
            for(int i=0;i<n;i++){
                arr[i]=sc.nextInt();
            }
            long ct = 0;
            Arrays.sort(arr);
            for(int i=0;i<n-c;i++){
                ct+=arr[i];
            }
            pw.println(ct);
        }
    }
    static class tup implements Comparable<tup>{
        int a, b;
        tup(int a, int b){
            this.a=a;
            this.b=b;
        }

        @Override
        public int compareTo(tup o) {
            return a!=o.a?Integer.compare(a,o.a):Integer.compare(b,o.b);
        }
    }
    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 54996
import sys
from operator import itemgetter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, x = na()
li = na()
ct = 1
h = 0
for num in li:
    h += num
    if h <= x:
        ct += 1
print(ct)


Measured memory_bytes: 3060
#!/usr/bin/env python3

W = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

def solve(n, m, a):

    a.sort(reverse = True)

    tmp = a.copy()
    for i in range(len(a) - 1, 0, -1):
        for j in range(i - 1, -1, -1):
            if W[a[i]] == W[a[j]]:
                a.pop(i)
                break

    by_value = [(v, W[v]) for v in a]
    by_weight = sorted(by_value, key = lambda x: x[1])
    v_to_w = {}
    w_to_v = {}
    for i, x in enumerate(by_value):
        for j, y in enumerate(by_weight):
            if x == y:
                v_to_w[i] = j
                w_to_v[j] = i
                break


    a_len = len(a)
    if a_len == 1:
        v, w = by_weight[0]
        return str(v) * (n // w)


    cnd = []
    w0 = by_weight[0][1]
    p = [0] * (a_len + 1)
    while p[-1] == 0:
        x = 0
        for i in range(1, a_len):
            x += p[i] * by_weight[i][1]
        if x <= n and (n - x) % w0 == 0:
            p[0] = (n - x) // w0
            cnd.append((sum(p), tuple([p[v_to_w[j]] for j in range(a_len)])))
        p[1] += 1
        for i in range(1, a_len):
            if p[i] == w0:
                p[i] = 0
                p[i + 1] += 1

    cnd.sort(key = lambda x: x[0], reverse = True)
    digits, _ = cnd[0]
    for i in range(1, len(cnd)):
        d, _ = cnd[i]
        if d < digits:
            cnd = cnd[:i]
            break

    cnd.sort(key = lambda x: x[1], reverse = True)

    ans = ''
    _, t = cnd[0]
    for i, x in enumerate(by_value):
        v, _ = x
        cnt = t[i]
        ans += str(v) * cnt

    return ans


def main():
    n, m = input().split()
    n = int(n)
    m = int(m)
    a = list(map(int, input().split()))


    print(solve(n, m, a))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3192
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j,k,l,m;
  int a[5002][5],n,d,p,q,c;
  a[5001][0]=a[5001][1]=a[5001][2]=a[5001][3]=a[5001][4]=1;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    memset(a,0,5*5001*sizeof(int));
    for(i=0;i<n;i++){
      cin>>d>>p>>q;
      for(j=0;j<5002;j++){
	if(d==1){
	  for(k=q-1;k<p+q-1;k++){
	    if(a[j][k])
	      break;
	  }
	  if(k!=p+q-1){
	    for(k=q-1;k<p+q-1;k++)
	      a[j-1][k]=1;
	    break;
	  }
	}else{
	  if(a[j][q-1]){
	    for(k=j-p;k<j;k++)
	      a[k][q-1]=1;
	    break;
	  }
	}
      }
      if(d==1){
	for(k=0;k<5;k++){
	  if(a[j-1][k]==0)
	    break;
	}
	if(k==5){
	  for(k=2;;k++){
	    for(l=0;l<5;l++){
	      if(a[j-k][l])
		break;
	    }
	    memcpy(&a[j-k+1][0],&a[j-k][0],5*sizeof(int));
	    if(l==5)
	      break;
	  }
	}
      }else{
	h=0;
	for(k=0;k<p;k++){
	  for(l=0;l<5;l++){
	    if(a[j-h-1][l]==0)
	      break;
	  }
	  if(l==5){
	    for(l=2;;l++){
	      for(m=0;m<5;m++){
		if(a[j-h-l][m])
		  break;
	      }
	      memcpy(&a[j-h-l+1][0],&a[j-h-l][0],5*sizeof(int));
	      if(m==5)
		break;
	    }
	  }else
	    h++;
	}
      }
    }
    c=0;
    for(i=1;i<5001;i++){
      for(j=0;j<5;j++){
	if(a[i][j])
	  c++;
      }
    }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 964
#include<iostream>

using namespace std;

	int a, b, c;
	int x;

int solve(){
	int ans = 0;
	for (int i = 0; i <= a; ++i) {
		for (int j = 0; j <= b; ++j) {
			for (int k = 0; k <= c; ++k) {
				int tmp = i * 500 + j * 100 + k * 50;
				if (tmp == x) ans++;
			}
		}
	}
	return ans;
}

int main() {
	cin >> a >> b >> c >> x;
	int ans = solve();
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for(int i = x; i < n; i++)

int N;
int prime[1000+1];

void factfact(int n) {
  int i, j;

  for (i = 2; i <= n; i++) {
    prime[i] = 1;
  }
  for (i = 2; i <= n; i++) {
    if (prime[i]) {
      for (j = i*2; j <= n; j += i) {
        prime[j] = 0;
      }
    }
  }
  for (i = 2; i <= n; i++) {
    if (prime[i]) {
      prime[i] = 0;
      for (j = i; j <= n; j *= i) {
        prime[i] += n/j;
      }
      //printf("%d^%d\n", i, prime[i]);
    }
  }
  //printf("\n");
}

int m = 1000000007;

int main()
{
    cin >> N;
    factfact(N);
    ll ans = 1;
    vector<int> t;
    rep(i, N + 1)
    {
        if (prime[i] == 0) continue;
        t.push_back(prime[i]);
    }
    for (auto v : t)
    {
        ans = (((v + 1) % m)*(ans % m)) % m;
    }
    cout << ans;
    return 0;   
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){

	int H,W,h,w;

	for(;;){

	scanf("%d %d",&H,&W);

	for(h=0;h<H;h++){
		for(w=0;w<W;w++){
			if(h==0||h+1==H||w==0||w+1==W){
				printf("#");
			}
			else{
				printf(".");
			}
		}
		printf("\n");
	


	}
		if(W==0&&H==0){
		break;
	}

	printf("\n");
	}
	

	return 0;
}

Measured memory_bytes: 1000
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

ans = A[K-1]
print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e6;
const int Nmax=2e5+1;
const int Nd=61;



int main(){
  string s;
  cin>>s;
  int ans=0;
  int now=0;
  rep(i,3){
    if(s[i]=='S'){
      now=0;
    }else{
      now++;
    }
    ans=max(ans,now);
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 3620
from heapq import heappop, heappush

x, y, z, k = [int(i) for i in input().split()]

a_list = sorted([-int(i) for i in input().split()])
b_list = sorted([-int(i) for i in input().split()])
c_list = sorted([-int(i) for i in input().split()])

hq = []
flag_set = set()

heappush(hq, (a_list[0] + b_list[0] + c_list[0], 0, 0, 0))
flag_set.add((0, 0, 0))
for _ in range(k):
    d, ai, bi, ci = heappop(hq)
    print(-d)
    
    temp = (ai + 1, bi, ci)
    if temp[0] < x and temp not in flag_set:
        heappush(hq, (a_list[ai + 1] + b_list[bi] + c_list[ci], ai + 1, bi, ci))
        flag_set.add(temp)
    
    temp = (ai, bi + 1, ci)
    if temp[1] < y and temp not in flag_set:
        heappush(hq, (a_list[ai] + b_list[bi + 1] + c_list[ci], ai, bi + 1, ci))
        flag_set.add(temp)

    temp = (ai, bi, ci + 1)
    if temp[2] < z and temp not in flag_set:
        heappush(hq, (a_list[ai] + b_list[bi] + c_list[ci + 1], ai, bi, ci + 1))
        flag_set.add(temp)

Measured memory_bytes: 5108
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  long long N,Y;
	cin>>N>>Y;
	rep(i,N+1){
		rep(j,N+1){
			rep(k,N+1){
				if(i+j+k==N && 10000*i+5000*j+1000*k==Y){
				  cout<<i<<" "<<j<<" "<<k<<endl;
					return 0;
				}
				if(i+j+k>N) break;
			}
			if(i+j>N) break;
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    vector<int64_t> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    vector<int64_t> b(n, 0);
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) b[0] += a[i];
        else b[0] -= a[i];
    }
    
    for (int i = 0; i < n - 1; i++) {
        b[i + 1] = 2 * a[i] - b[i];
    }
    
    for (int i = 0; i < n; i++) {
        if (i != n - 1) cout << b[i] << ' ';
        else cout << b[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2944
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [i32; n]
    };
    let mut dp = vec![1<<30; n];
    dp[0] = 0;
    for i in 0..n {
        for j in 1..=k {
            if i+j >= n { break }
            dp[i+j] = dp[i+j].min(dp[i] + (h[i]-h[i+j]).abs());
        }
    }
    println!("{}", dp[n-1]);
}


Measured memory_bytes: 3160
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(void){
	REP(i, 9){
		REP(j, 9){
			printf("%dx%d=%d\n", i+1, j+1, (i+1)*(j+1));
		}
	}
	return 0;
}

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

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

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

const int INF =  1e9 + 5;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	vector<int>dp(3);

	for (int day = 0; day < n; day++)
	{
		vector<int>new_dp(3, 0);
		vector<int>c(3);
		for (int i = 0; i < 3; i++)
		{
			scanf("%d", &c[i]);

		}
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				if (i != j)
					new_dp[j] = max(new_dp[j], dp[i] + c[j]);
		dp = new_dp;
	}
	cout << max({dp[0], dp[1], dp[2]});
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e5 + 5;


int32_t main()
{
   IOS;
   int a[5];

   for(int i=0; i<5; i++)
   {
   		cin >> a[i];
   		if(a[i]==0)
   			cout << i+1 << endl;
   }




   return 0;
}
 

Measured memory_bytes: 3624
while True:
    a, b, c = input().split()
    a = int(a)
    c = int(c)
    if b == "?":
        break
    if b == "+":
        print(a + c)
    if b == "-":
        print(a - c)
    if b == "*":
        print(a * c)
    if b == "/":
        print(a // c)



Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    
    cout << N*(N+1)/2 << endl;


    return 0;
    

}

Measured memory_bytes: 3624
# coding:utf-8
import sys
while True:
    array = map(int, raw_input().split())
    if array[0] == 0 and array[1] == 0:
        break
    for i in range(array[0]):
        for j in range(array[1]):
            if i % 2 == 0 and j % 2 == 0:
                sys.stdout.write('#')
            elif i % 2 == 1 and j % 2 == 0:
                sys.stdout.write('.')
            elif i % 2 == 0 and j % 2 == 1:
                sys.stdout.write('.')
            else:
                sys.stdout.write('#')
        else:
            print
    else:
        print



Measured memory_bytes: 4656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int n; cin>>n;
    long long T=1,A=1;
    rep(i,n){
        long long t,a; cin>>t>>a;
        if(T/t>A/a){
            long long x=(T+t-1)/t;
            T=x*t;
            A=x*a;
        }else{
            long long x=(A+a-1)/a;
            T=x*t;
            A=x*a;
        }
        // cout<<T<<" "<<A<<endl;
    }
    cout<<T+A<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
    long long int a,b,c[100010],d[100010],e[100010],f[100010],ans =0;
     cin >> a >> b;
  
  for(int i=0;i<a;i++){
    cin >> c[i] >> d[i];
    f[i] = d[i];
    e[i] = c[i];
  }
  
  sort(c,c+a,greater<int>());
  sort(d,d+a,greater<int>());
  
  for(int i=0;i<a;i++){
    
    if(c[0]<=d[i]){
      
      b -= d[i];
      ans++;
      
      if(b<=0){
        cout << ans << endl;
        
        return 0;
      }
        
    }
  }
  
 cout << ans + (b+c[0]-1)/c[0] << endl;
  }
    
    


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    reverse(ALL(s));
    ll n = s.size();
    map<ll,ll> m;
    m[0]++;
    ll x = 0, y = 1;
    rep(i,n){
        x += y*(s[i]-'0');
        y*=10;
        x%=2019;
        y%=2019;
        m[x]++;
    }
    ll ans = 0;
    for(auto p:m){
        ans += p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3768