akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	int dx[4] = { -1,0,0,1 };
	int dy[4] = { 0,-1,1,0 };
	char buf[1005][1005];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> buf[i][j];
		}
	}
	int dist[1005][1005];
	int inf = 1e5;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
		    
			dist[i][j] = inf;
		}
	}
	queue<int>v;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (buf[i][j] == '#') {
				dist[i][j] = 0;
				v.push(j); v.push(i);
			}
		}
	}
	while (v.size()) {
		int x = v.front(); v.pop();
		int y = v.front(); v.pop();
		for(int k = 0; k<4; k++){
			int a = x + dx[k];
			int b = y + dy[k];
			if (0 <= a && a < w && 0 <= b && b < h && dist[b][a] == inf && buf[b][a] == '.') {
				buf[b][a] = '#';
				dist[b][a] = dist[y][x] + 1;
				v.push(a); v.push(b);
			}
		}
	}
	
		    
	int max_dist = -100000;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (dist[i][j]!=inf) {
				max_dist = max(max_dist,dist[i][j]);
			}
		}
	}
	cout << max_dist << endl;
	return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int main() {

	FAST;

	string s;
	cin >> s;
	cout << s[0] << s[1] << s[2] << '\n';
	return 0;
}

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
N = len(S)

C = Counter(S)
# 区間(の始点終点ペア)の全組み合わせ + 元の文字列
ans = N*(N-1) // 2 + 1
for k, v in C.items():
    # 重複分を引いていく
    ans -= v*(v-1) // 2
print(ans)


Measured memory_bytes: 3864
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
string odd = "", even = "";
int cnt = 0;
string S,T;
void check_odd(int s_pos, int t_pos)
{
    bool tmp_flag = false;
    for(int i=t_pos; i<T.size(); i++)
    {
        if(s_pos >= odd.size()) break;
        if(odd[s_pos] != T[i]) continue;
        s_pos++;
        t_pos = i+1;
        cnt++;
        tmp_flag = true;
        break;
    }
    if(tmp_flag) check_odd(s_pos, t_pos);
}
void check_even(int s_pos, int t_pos)
{
    bool tmp_flag = false;
    for(int i=t_pos; i<T.size(); i++)
    {
        if(s_pos >= even.size()) break;
        if(even[s_pos] != T[i]) continue;
        s_pos++;
        t_pos = i+1;
        cnt++;
        tmp_flag = true;
        break;
    }
    if(tmp_flag) check_even(s_pos, t_pos);
}
int main()
{
    cin >> S >> T;
    rep(i, S.size())
    {
        if(i % 2) odd += S[i];
        else even += S[i];
    }
    bool flag = false;
    check_odd(0,0);
    if(cnt == odd.size()) flag = true;
    cnt = 0;
    check_even(0,0);
    if(cnt == even.size()) flag = true;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;  
     
    return 0;
}


Measured memory_bytes: 3216
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashSet;

fn main() {
    let s: usize = read();
    let mut tmp = s;
    let mut uniq: HashSet<usize> = HashSet::new();

    for i in 0..1_000_000 {
        // println!("{} {}", i, tmp);
        if uniq.get(&tmp) != None {
            println!("{}", i + 1);
            break;
        }
        uniq.insert(tmp);

        if tmp % 2 == 0 {
            tmp = tmp / 2;
        } else {
            tmp = 3 * tmp + 1;
        }
    }
}


Measured memory_bytes: 4352
# ABC 116 D

import heapq

def resolve():
    n, k = map(int, input().split())
    td = []

    # td に score が高い順に格納する
    for _ in range(n):
        t, d = map(int, input().split())
        heapq.heappush(td, (-d, t))

    score = 0
    types = set()
    discard = []

    for _ in range(k):
        d, t = heapq.heappop(td)  # 注意 d は符号が逆になってる
        score -= d
        if t not in types:
            types.add(t)
        else:
            # その type で1番じゃないものをスコアの小さい順に並べる -> 後で捨てるリスト
            heapq.heappush(discard, (-d, t))

    ans = score + len(types)**2

    while td and discard:
        d, t = heapq.heappop(td)  # 残り物からスコア高い順に取り出す; 注意 このリストのスコアは符号反転してる

        if t in types:
            # 選んでも種類が増えないやつはパス
            continue

        types.add(t)
        score -= d

        # 捨てても種類が減らないリストの中で最もスコアが低いやつを捨てる
        _d, _t = heapq.heappop(discard)  # 注意 このリストのスコアは符号反転していない
        score -= _d

        ans = max(ans, score + len(types)**2)

    print(ans)

if __name__ == "__main__":
    resolve()


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

int main() {
  ll n;
  cin >> n;
  if (n % 2 == 1) cout << 0 << endl;
  else {
    ll sum = 0;
    for (ll i = 10; i <= n; i *= 10) sum += n / i;
    for (ll i = 50; i <= n; i *= 5) sum += n / i;
    for (ll i = 100; i <= n; i *= 10) sum -= n / i;
    cout << sum << endl;
  }
}

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

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

    int res = 0;
    for (int l = 1; l < s.length() / 2; l++)
    {
        string head = s.substr(0, l);
        string tail = s.substr(l, l);
        if (head == tail)
        {
            res = l * 2;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import math
def calculate(n,k):
    res = 0
    for i in range(n):
        indexN = i + 1

        temp = k / indexN

        if temp < 1:
            res = res + (1/n)
        else:
            t = math.log(temp,2)
            t = math.ceil(t)
            res = res + (1/n) * math.pow(0.5,t)

    print("{:.12f}".format(res))

S = input()
S = S.split(" ")
n = int(S[0])
k = int(S[1])

calculate(n,k)



Measured memory_bytes: 3064
#include <cstdio>
#include <utility>
#include <climits>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s){int c;
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

void choice (int &price) {
	price = min(price, in());
}

int main() {
	int sum = 0;
	for (int n : {3, 2}) {
		int p = INT_MAX;
		for (int i = 0; i < n; i++)
			choice(p);
		sum += p;
	}
	out(sum - 50, '\n');
}


Measured memory_bytes: 2544
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<ll> A(N);
    REP(i, 0, N) {
        cin >> A[i];
    }
    vector<ll> skipsum(N + 2, 0), sum(N + 1, 0);

    REP(i, 0, N) {
        sum[i + 1] += sum[i] + A[i];
    }
    for (int i = !(N % 2); i < N; i += 2) {
        skipsum[i + 2] += skipsum[i] + A[i];
    }
    REP(i, 0, Q) {
        int q;
        cin >> q;
        int lb = 1, ub = N;
        int ans = 0;
        while (lb <= ub) {
            int mid = (lb + ub) / 2;
            int aoki = N - mid;
            int taka = N - (mid + 1) / 2;
            if (abs(A[aoki] - q) <= abs(A[taka] - q)) {
                ans = mid;
                lb = mid + 1;
            } else {
                ub = mid - 1;
            }
        }
        // 0 ~ N - 1
        ans = N - ans;

        if (N % 2 == 0) {
            ans = max(ans - 1, 0);
        }

        int j = (ans + 1) / 2;
        int k = (ans + 1) / 2 * 2 + !(N % 2);

        /*
        dump(ans);
        dump(j);
        dump(k);
        dump(skipsum[k]);
        //*/

        cout << skipsum[k] + sum[N] - sum[N / 2 + j] << endl;
    }

    return 0;
}


Measured memory_bytes: 4096
#include <stdio.h>
int main(void){
    int n,i;
    long long int sum=0,num;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&num);
        sum+=num;
    }
    printf("%lld\n",sum/n);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);


bool cmp(const PII& a, const PII& b){
    int af = a.first, as = a.second;
    int bf = b.first, bs = b.second;

    if(as > 0 and bs > 0){
        return af > bf;
    }else if(as > 0 and bs <= 0){
        return true;
    }else if(as <= 0 and bs > 0){
        return false;
    }else{
        //int da = -af - (-as);
        //int db = -bf - (-bs);
        //return da >= db;
        return af-as < bf-bs;
    }
    

    //if(as > 0 and bs <= 0) return true;
    //if(as <= 0 and bs > 0) return false;
    //if(as < 0) return af - as < bf - bs;
    //else return af > bf;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    vector<pair<int,int>> S;
    int sum = 0;
    REP(i,N){
        string s; cin >> s;
        int acc = 0;
        int tmin = 0;
        for(char c : s){
            if(c == '('){
                acc++;
            }else{
                acc--;
            }
            chmin(tmin,acc);
        }
        S.eb(tmin,acc);
        sum += acc;
    }
    if(sum != 0){
        cout << "No" << endl;
        return 0;
    }
    sort(S.begin(),S.end(),cmp);
    int now = 0;
    int tmin = 0;
    REP(i,N){
        int a,b;
        tie(a,b) = S[i];
        chmin(tmin,now+a);
        now += b;
    }
    if(tmin == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }



}

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


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const double pi=3.14159265358979323846;
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double one=((60*h+m)/720)*(2*pi);
    double two=(m/60)*(2*pi);
    cout << fixed << setprecision(20) << sqrt(a*a+b*b-2*a*b*cos(one-two)) << "\n";
    return 0;
}


Measured memory_bytes: 4180
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# slist = "abcdefghijklmnopqrstuvwxyz"
a,b = map(int,input().split())

if a<0 and b<0:
    if (b-a)%2==0:
        ans = "Negative"
    else:
        ans = "Positive"
elif a<0 and b>=0:
    ans = "Zero"
elif a==0:
    ans = "Zero"
else:
    ans = "Positive"

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  for(int i = 0; i + 1 < s.size(); i++) {
    if(s[i] == s[i+1]) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

void chmax(int &x, int y) {
  x = max(x, y);
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s;
  cin >> s;
  const int n = s.size();

  static int dp[200005][8];
  rep(i, n + 1) rep(j, 8) dp[i][j] = -1e9;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 8; j++) {
      if (dp[i][j] == -1e9) continue;
      for (int k = 0; k < 8 && i + k <= n; k++) {
        if (s.substr(i - j, j) != s.substr(i, k)) {
          chmax(dp[i+k][k], dp[i][j] + 1);
        }
      }
    }
  }
  int ans = -1e9;
  rep(j, 5) chmax(ans, dp[n][j]);
  cout << ans << endl;
}

Measured memory_bytes: 6804
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// make it understandable one day...
const int N=2e5+1;
int n;
const int ts=1e6+1;
int ch[ts][27];
int p[ts];
int f[ts];
string s[N];
int sz=0;
void insert(int id){
	int r=0;
	for(auto c:s[id]){
		if(ch[r][c-'a']==0){
			ch[r][c-'a']=++sz;
		}
		int prv=r;
		r=ch[r][c-'a'];
		p[r]=prv;
	}
	f[r]++;
}
bool can[27];
ll ans=0;
void solve(int id){
	int r=0;
	for(int i=0; i<=26 ;i++) can[i]=false;
	for(auto c:s[id]) r=ch[r][c-'a'];
	for(int i=s[id].size()-1; i>=0 ;i--){
		can[s[id][i]-'a']=true;
		r=p[r];
		for(int j=0; j<26 ;j++){
			if(can[j]) ans+=f[ch[r][j]];
		}
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	for(int i=1; i<=n ;i++){
		cin >> s[i];
		reverse(s[i].begin(),s[i].end());
		insert(i);
	}
	for(int i=1; i<=n ;i++){
		solve(i);
	}
	ans=(ans-n);
	cout << ans << '\n';
}

Measured memory_bytes: 123164
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 


void solve(){
    int n, m;
    cin >> n >> m;
    int ret = powerexp(n, m);
    cout << ret << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



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

int main () {
  int a , b, c ;
  cin >> a >> b >> c ;
  
  cout << min(b,c) << " ";
  if ( (b+c) -a <= 0) cout << 0 ;
  else cout << (b+c) -a << endl ;
}

Measured memory_bytes: 256
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int X = scanner.nextInt();
        int Y = scanner.nextInt();
        int ans = 0;
        ans += Math.max(0, 4 - X) * 100000;
        ans += Math.max(0, 4 - Y) * 100000;
        if (X == 1 && Y == 1) {
            ans += 400000;
        }
        System.out.println(ans);
    }

}



Measured memory_bytes: 23636
ABCD = list(map(int, input()))
a, b, c, d = ABCD[0], ABCD[1], ABCD[2], ABCD[3]
op = ['+', '-']
flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = 0
            if i == 0:
                ans = a + b
            else:
                ans = a - b
            if j == 0:
                ans += c
            else:
                ans -= c
            if k == 0:
                ans += d
            else:
                ans -= d
            if ans == 7:
                print('{}{}{}{}{}{}{}={}'.format(a,op[i],b,op[j],c,op[k],d,ans))
                flag = True
                break
        if flag:
            break
    if flag:
        break

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int r;
    cin >> r;
    cout << fixed << setprecision(10) << (double)(r * 2 * 3.1415926535) << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    vector<ll>dp(n);
    vector<ll>A(n);
    for (ll i = 0;i<n;i++){
        cin>>A[i];
        if (i==0){dp[i] = 0;continue;}
        if (i==1){dp[i] = abs(A[1]-A[0]);continue;}
        dp[i] = min(abs(A[i]-A[i-1])+dp[i-1],abs(A[i]-A[i-2])+dp[i-2]);
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveD();
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A = sc.nextLong();
		long B = sc.nextLong();
		List<Integer> list = new ArrayList<Integer>();
		int max = 0;
		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			list.add(val);
			if (max < val) {
				max = val;
			}
		}
		long minNum = (max + A - 1) / A;
		long maxNum = (max + B - 1) / B;
		do {
			long count = (minNum + maxNum) / 2;
			if (isWin(count, A, B, list)) {
				maxNum = count;
			} else {
				minNum = count + 1;
			}
		} while (minNum < maxNum);
		System.out.println(maxNum);
	}

	private boolean isWin(long count, long A, long B, List<Integer> hps) {
		long sum = 0;
		for (int hp : hps) {
			long num = (hp - count * B + A - B - 1) / (A - B);
			if (num > 0) {
				sum += num;
			}
		}
		return sum <= count;
	}
}

Measured memory_bytes: 62448
import numpy as np

X, K, D = input().split()

X = int(X)
if X < 0:
    X = -X
K = int(K)
D = int(D)

# KD, (K - 2)D, (K - 4)D, ...

q = X // D
if(K % 2 == q % 2):
    if (K * D >= X):
        print(X % D)
    else:
        print(abs(X - K * D))
else:
    if (K * D >= X):
        print(min(X % D + D, abs(X % D - D)))
    else:
        print(abs(X - K * D))


Measured memory_bytes: 26624
import math
import copy
import bisect







def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input().split())
m=nCast(input().split())

def cmp(l1,l2):

    if len(l1)!=len(l2):
        return len(l1)-len(l2)
    for idx in range(len(l1)-1,0,-1):
        if l1[idx]!=l2[idx]:
            return l1[idx]-l2[idx]
    return 0
def func():
    l=list()
    nn=[1,2,3,4,5,6,7,8,9]
    s=set(m)
    mm=[2,5,5,4,5,6,3,7,6]
    d=dict()
    for idx in nn:
        if idx in s:
            if idx==2 and 5 in s:
                continue
            if idx==3 and 5 in s:
                continue
            if idx==2 and 3 in s:
                continue
            if idx==6 and 9 in s:
                continue
            d[nn[idx-1]]=mm[idx-1]
    for idx in range(0,n[0]+1):
        l.append(list())
    for idx in range(1,n[0]+1):
        for idy in d:
            if idx-d[idy]>0:
                tmp=l[idx-d[idy]][:]
                if len(tmp)==0:
                    continue
                tmp.append(idy)
                #tmp.sort(reverse=True)
                if cmp(tmp,l[idx])>0:
                    l[idx]=tmp
            elif idx-d[idy]==0:
                max=0
                for dd in d:
                    if d[dd]==idx and dd>max:
                        max=dd
                if cmp([max],l[idx])>0:
                    l[idx]=[max]

    result=""
    l[-1].sort(reverse=True)
    for idx in range(0,len(l[-1])):
        result=result+str(l[-1][idx])
    return result



print(func()) 



Measured memory_bytes: 285288
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
 //ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 cout << fixed << setprecision(10);
    int n;
    cin>>n;
    int x;
    vector<queue<int>> b(n);
    rep(i,n)rep(j,n-1){
        cin>>x;
        x --;
        b[i].emplace(x);
    }
    set<int> seen;
    int ans=-1;
    bool f=1;
    while(f){
        f=0;
        rep(i,n){
            if(b[i].empty()) continue;
            int op=b[i].front();
            if(op<i) continue;
            if(seen.count(op) || seen.count(i)) continue;
            if(b[op].front() != i) continue;
            f=1;
            b[i].pop();
            b[op].pop();
            seen.emplace(op);
            seen.emplace(i);
        }
        ans ++;
        seen.clear();
    }
    rep(i,n){
        if(!b[i].empty()){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}/*
./problem.exe
*/


Measured memory_bytes: 8024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int solve()
{
    int A, B;

    std::cin >> A >> B;

    return std::max(A - B, std::max(A + B, A * B));
}

int main()
{
    std::cout << solve() << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
signed main() {
    int N,A,B;
    cin >> N >> A >> B;
    vector<int>X(N);
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> X[i];
        if(i) {
            ans+=min(A*(X[i]-X[i-1]),B);
        }
    }
    cout << ans << endl;
    return 0;
}


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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

ll a[500000],num[500000];
int main() {
   ll i,j,k;
   ll n,sum=0;
   cin >>n; 
   for(i=0; i<n; i++)
   {
     cin >>a[i];
     num[i]=0;
   }
   num[n]=0;

   for(i=0; i<n; i++)
   {
     num[a[i]]+=1;
     
   }

   for(i=0; i<n+1; i++)
   {
     sum+=num[i]*(num[i]-1)/2;
    //  cout<<sum<<endl;
    //  assert(sum>=0);
   }

   for(i=0; i<n; i++)
   {
     if(i)
     {
       cout<<endl;
     }
     cout<< sum-(num[a[i]]*(num[a[i]]-1)/2)+((num[a[i]]-1)*(num[a[i]]-2)/2);
   }
  
}

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

signed main(){
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i=0; i < n; i++){
        int x, y;
        cin >> x >> y;
        int r = floor(sqrt(x*y));
        if (r*(r+1) < x*y) cout << 2*r-1 << endl;
        else if (r*r < x*y) cout << 2*r-2 << endl;
        else cout << 2*r-3+(r==x) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String[] s = S.split("");
        int[] n = new int[4];
        for(int i = 0; i < 4; i++) {
            n[i] = Integer.parseInt(s[i]);
        }
        
        String ans;
        if(1 <= n[1] && n[0]*10+n[1] <= 12 && 1 <= n[3] && n[2]*10+n[3] <= 12) {
            ans = "AMBIGUOUS";
        }else if(1 <= n[1] && n[0]*10+n[1] <= 12) {
            ans = "MMYY";
        }else if(1 <= n[3] && n[2]*10+n[3] <= 12) {
            ans = "YYMM";
        }else {
            ans = "NA";
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	

 for(int i=0;i<=25;i++)
	{
		for(int j=0;j<=25;j++)
		{
			if(i*4+j*7==n)
			{
			cout<<"Yes";

			return 0;
		    }
	    }
	}

	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int i, j, N, d[101]={0}, max, tmp, out=0;
    scanf("%d", &N);
    for (i=0,max=100; i < N ;i++) {
        scanf("%d", &d[i]);
        if (d[i] > d[max]) max = i;
    }
    for (i=0; i < N ;i++) {
        for (j=0,tmp=100; j < N ;j++) {
            if (j != max && d[j] > d[tmp]) tmp = j;
        }
        if (tmp != 100 && d[max] > d[tmp]) {
            d[max] = 0;
            max = tmp;
            out++;
        } else {
            d[tmp] = 0;
        }
    }
    printf("%d\n", out+1);
    return 0;
}

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

char s[200005];
int len;
int main(){
  scanf("%s",s+1);
  len=strlen(s+1);
  int minv=1<<30,maxv=0;
  for (int i=1;i<=len;i++)
    if (s[i]=='A')
      minv=min(minv,i);
    else if (s[i]=='Z')
      maxv=max(maxv,i);
  printf("%d\n",maxv-minv+1);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	cin>>n;
	if(n==1){
		cout<<"Hello World"<<endl;
	}
	else{
		int a,b;
		
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    int n;
    cin >> n;
    string S[n];
    set <string> s;
    for(int i=0;i<n;++i) cin >> S[i];
    s.insert(S[0]);
    bool ok=true;
    for(int i=1;i<n;++i) {
        if(S[i-1].back()!=S[i][0]) ok=false;
        if(s.count(S[i])) ok=false;
        s.insert(S[i]);
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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


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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long

int main(){
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[10];
	int ans = 1;
	for(int i = 1;i <= 5;i++){
		scanf("%d",&a[i]);
		if(a[i] == 0) ans = i;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3756
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 11 15:09:04 2018
ABC081
@author: maezawa
"""

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

j = 0
ok = True
while ok:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] = a[i]//2
        else:
            ok = False
            break
    if ok:
        j += 1

print(j)
        

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	int a, b, c, cnt = 0;
	cin >> a >> b >> c;
	FOR(i,a,b+1){
		if(c % i == 0)cnt++;
	}
	FIN(cnt);
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long num;
  cin>>num;
  int count=2;
  for(int a=num;;a=a*count){
    if(a%2==0){
      cout<<a<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

#define MAXN 400010
#define MAXM 400005

struct Edge {
    int next, to, w;
} edge[MAXM];
int head[MAXN], cnt;

void Add(int u, int v, int w) {
    edge[++cnt].w = w;
    edge[cnt].next = head[u];
    head[u] = cnt;
    edge[cnt].to = v;
}
//上面是链式前向星存图
int N, M;
int dis[MAXN];
bool vis[MAXN];

void SPFA(int S) { //SPFA模版
    queue<int> Q;
    Q.push(S);
    for(int i=0; i<=N+1; i++) dis[i] = 1e9;
    dis[S] = 0;
    vis[S] = 1;
    while(!Q.empty()) {
        int k = Q.front();
        Q.pop();
        vis[k] = 0;
        for(int i=head[k]; i!=-1; i = edge[i].next) {
            int to = edge[i].to;
            if(dis[to] > dis[k] + edge[i].w) {
                dis[to] = dis[k] + edge[i].w;
                if(!vis[to]) {
                    Q.push(to);
                    vis[to] = 1;
                }
            }
        }
    }
}

int main() {
    int x, y, t, S;
    cin >> N >> M;
    S = N+1; //源点为N+1 
    memset(head, -1, sizeof(head));
    for(int i=0; i<=N; i++) Add(S, i, 0); //Sum(i) - Sum(N+1) <= 0
    for(int i=1; i<=M; i++) {
        cin >> x >> y;
        Add(y, x, -1); //Sum(x-1) - Sum(y) <= -t
    }
    for(int i=1; i<=N; i++) {
        Add(i-1, i, 1); //Sum(i) - Sum(i-1) <= 1
        Add(i, i-1, 0); //Sum(i-1) - Sum(i) <= 0
    }
    SPFA(S);
    int _min = 1e9;
    for(int i=0; i<=N; i++) _min = min(_min, dis[i]);
    cout << dis[N] - _min << endl;
    return 0;
}

Measured memory_bytes: 7552
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n;
string s[10000];
string t;

int main() {
	cin >> n;
	REP(i, n) cin >> s[i];
	cin >> t;
	
	int ans = 0, ansh = 0; // 必ず, 等しいかどちらでも
	
	REP(i, n) {
		int pos = 0;
		
		bool same = true;
		REP(j, s[i].size()) {
			if (s[i][j] == '?') {
				if (t[j] != 'z') {
					ansh++;
					same = false;
					break;
				}
			}
			else if (t[j] == '?') {
				if (s[i][j] != 'z') {
					ansh++;
					same = false;
					break;
				}
			}
			else if (s[i][j] > t[j]) {
				same = false;
				break;
			}
			else if (s[i][j] < t[j]) {
				ans++;
				same = false;
				break;
			}
		}
		
		if (same) {
			if (s[i].size() == t.size()) ansh++;
			if (s[i].size() < t.size()) ans++;
		}
	}
	
	vector<int> v;
	v.push_back(ans + 1);
	
	REP(i, ansh) v.push_back(ans + 1 + (i + 1));
	
	REP(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 896
n = gets.to_i
s = []
#使われてるアルファベットを入れておく
common = ("a".."z").to_a
n.times{|i|
	s[i] = gets.chomp
	common |= s[i].chars
}
#ここでcommonにはすべてのs[i]に含まれるアルファベットの配列
common.sort.each{|c|
	min = 50
	s.each{|si|
		min = [si.count(c), min].min
	}
	min.times{|i|
		print c
	}
}
puts


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll r, g, b, n;
    cin >> r >> g >> b >> n;
    ll res = 0;
    for (ll i = 0; i <= 3000;i++){
        for (ll j = 0; j <= 3000;j++){
            ll tmp = (n - r * i - g * j);
            if (tmp % b == 0 and tmp >= 0) res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
class abc166_c{
  public static void Main(){
    String[] str = Console.ReadLine().Split(' ');
    int n = int.Parse(str[0]);
    int m = int.Parse(str[1]);
    int[] h = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    List<int>[] to = new List<int>[n];
    for(int i=0; i<n; i++){
      to[i] = new List<int>();
    }
    for(int i=0; i<m; i++){
      int[] ab = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
      to[ab[0]-1].Add(ab[1]-1);
      to[ab[1]-1].Add(ab[0]-1);
    }
    int count = 0;
    bool flag = true;
    for(int i=0; i<n; i++){
      List<int> t = to[i];
      flag = true;
      for(int j=0; j<t.Count; j++){
        int cmp = t[j];
        if(h[i] <= h[cmp]){
          flag = false;
          break;
        }
      }
      if(flag){
        count++;
      }
    }
    Console.WriteLine(count);
  }
}


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

int GCD(int m,int n){
	int remain;
	if((remain = m % n) == 0)return n;
	else return GCD(n,remain);
}

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)cin >> a[i];
	int res = GCD(a[0], a[1]);
	for(int i = 2; i < n; i++)res = GCD(res, a[i]);
	cout << res << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
using namespace std;

int main()
{
    ll n, m, k = 0, ans = 0;
    cin>>n;
    for(int i = 0; i < n; i++){
        ll a, b;
        cin>>a>>b;
        if(a == b) ans++;
        else ans = 0;
        if(ans == 3) k = 1;
    }
    if(k) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3628
def gcd(x, y):
    if y == 0:
        return x
    if x < y:
        return gcd(y, x)
    return gcd(y, x % y)


A, B, C, D = map(int, input().split())

g = gcd(C, D)

print((B - A + 1) - (B // C - (A - 1) // C) - (B // D - (A - 1) // D) + (B // (C * D // g) - (A - 1) // (C * D // g)))


Measured memory_bytes: 38384
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int M = int.Parse(input[1]);
    
    Dictionary<int, List<int>> Jobs = new Dictionary<int, List<int>>();
    for (int i = 0; i < N; i++)
    {
      string[] input_ = Console.ReadLine().Split(' ');
      int A = int.Parse(input_[0]);
      int B = int.Parse(input_[1]);
      
      if (Jobs.ContainsKey(A))
      {
        Jobs[A].Add(B);
      }
      else
      {
        Jobs.Add(A, new List<int>{B});
      }
    }
    
    // 仕事の候補を格納するキュー
    List<Tuple<int, int>> Jobq = new List<Tuple<int, int>>();
    // 報酬の合計
    int sum = 0;
    
    for (int i = 1; i <= M; i++)
    {
      // i 日以内に報酬が獲得できる仕事を追加
      if (Jobs.ContainsKey(i))
      {
  	    foreach (int b in Jobs[i])
    	{
     	   PushHeap(Jobq, new Tuple<int, int>(i, b));
  	    }
      }
      if (Jobq.Count == 0)
        continue;
      
      // 最も報酬の大きい要素の報酬を加算
      sum += Jobq[0].Item2;
      // 最大要素を削除
      PopHeap(Jobq);
    }
    
    Console.WriteLine(sum);
  }
  
  // Heap に要素を追加
  static void PushHeap(List<Tuple<int, int>> array, Tuple<int, int> elem)
  {
    int n = array.Count;
    array.Add(elem);
    
    while (n != 0)
    {
      int i = (n-1) / 2; // parent's index
      if (array[n].Item2 > array[i].Item2) // if child is larger than parent
      {
        // switch the child and the parents
        Tuple<int, int> tmp = array[n];
        array[n] = array[i];
        array[i] = tmp;
      }
      n = i;
    }
  }

  // Heap から最大値を削除
  static void PopHeap(List<Tuple<int, int>> array)
  {
    // 末端の要素で置き換える. n := 新しいリストの大きさ
    int n = array.Count - 1;
    array[0] = array[n];
    array.RemoveAt(n);
    
    // i := 親の番号, j := (左側の)子の番号, j が n 未満の限り繰り返す
    for (int i = 0, j; (j = i*2 + 1) < n; ) 
    {
      // 右側の子の方が大きい場合は, 右側の子と親を入れ替える
      if ((j != n - 1) && (array[j].Item2 < array[j + 1].Item2))
      {
        j++;
      }
      // 親の方が小さければ，子と親の値を入れ替える
      if ((array[i].Item2 < array[j].Item2))
      {
        Tuple<int, int> tmp = array[j];
        array[j] = array[i];
        array[i] = tmp;
      }
      i = j;
    }
  }
}

Measured memory_bytes: 36476
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
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; }

const ll MAX_S = 1000000;
int D;

vector<ll> cvec(26, 0);
vector< vector<ll> > smap(365, vector<ll>(26, 0));
vector<int> lastvec(26, 0);

ll Scalc(int today, int no, ll now) {
    vector<int> plastvec = lastvec;
    // その日のコンテストの満足度
    now += smap.at(today).at(no);
    // コンテストが行われた記録
    plastvec.at(no) = (today+1);
    // 行われなかったコンテストへの不満
    for(int i = 0; i < 26; ++i) {
        now -= (cvec.at(i)*((today+1) - plastvec.at(i)));
    }
    return now;
}

int main() {
    cin >> D;
    for(int i = 0; i < 26; ++i) cin >> cvec.at(i);
    for(int i = 0; i < D; ++i) {
        for(int j = 0; j < 26; ++j) {
            cin >> smap.at(i).at(j);
        }
    }

    vector<int> tvec(D, 0);
    ll ans = 0;
    for(int i = 0; i < D; ++i) {
        // 毎日どれを選ぶか決める
        ll sum = 0;
        int tmax = 0;
        for(int j = 0; j < 26; ++j) {
            ll chsum = Scalc(i, j, ans);
            if(sum < chsum) {
                // その日の一番を採用
                sum = chsum;
                tmax = j;
            }
        }
        // tmaxを採用する
        lastvec.at(tmax) = (i+1);
        tvec.at(i) = tmax+1;
    }
    
    for(int i = 0; i < D; ++i) {
        cout << tvec.at(i) << endl;
    }
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <math.h>

using namespace std;

const long long mod = 998244353 ;



int main()
{
    int a,b,x;scanf("%d%d%d",&a,&b,&x);
    //printf("%.10lf\n", 2*(a*a*b-x)/(a*a*a*1.0) );
    if (2*x<=a*a*b)
    printf("%.10lf\n", atan(b*b*a*0.5/x)*180/M_PI);else
    printf("%.10lf\n",double(atan( 2*(a*a*b-x)/(a*a*a*1.0) ))*(180/M_PI) );

}


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

// int int_pow(int a, int b){
//     int ans = 1;
//     if (b<0) cout << "error: power()" << endl;
//     for (int i=0; i<b; i++){
//         ans *= a;
//     }
//     return ans;
// }

int main() {
    int N; cin >> N;
    if ( N == 0 ) {
        cout << 0 << endl;
    }
    int i = 0;
    int S[50];
    while (N != 0){
        S[i] = abs(N%2);
        N -= S[i];
        N /= -2;
        i++;
    }

    for (int j=i-1; j>-1; j--){
        cout << S[j];
    }
    cout << endl;
}

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

int main() {
  int n;	cin >> n;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==n){
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}

Measured memory_bytes: 3640
#include <stdio.h>          // printf(), fprintf(), scanf()
#include <stdlib.h>         // exit()
#include <stdbool.h>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define MAX_W 500
#define MAX_H 500
#define STACK_SIZE 100

typedef struct stack_tbl
{
	int height;
	int pos;
} stack_t;

int w, h;
char field[MAX_H][MAX_W + 2];
int T[MAX_H][MAX_W + 1];

stack_t stack[STACK_SIZE];
int sp;

void
cleanup(int ecode)
{
	exit(ecode);
}

bool
stack_empty()
{
	return sp == 0;
}

void
stack_push(stack_t *S)
{
	if (sp >= STACK_SIZE)
	{
		fprintf(stderr, "Stack overflow. size:%d\n", STACK_SIZE);
		cleanup(1);
	}

	stack[sp].height = S->height;
	stack[sp].pos = S->pos;
	sp++;
}

void
stack_pop()
{
	if (sp <= 0)
	{
		fprintf(stderr, "Stack underflow\n");
		cleanup(1);
	}

	sp--;
}

void
stack_front(stack_t *S)
{
	S->height = stack[sp - 1].height;
	S->pos = stack[sp - 1].pos;
}

int
getArea(int size, int row[])
{
	stack_t rect, S;
	int i;

	int maxv = 0;
	row[size] = 0;

	sp = 0;
	for (i = 0; i <= size; ++i)
	{
		rect.height = row[i];
		rect.pos = i;
		if (stack_empty())
			stack_push(&rect);
		else
		{
			stack_front(&S);
			if (S.height < rect.height)
				stack_push(&rect);

			else if (S.height > rect.height)
			{
				int target = i;
				while (!stack_empty())
				{
					stack_front(&S);
					if (S.height < rect.height)
						break;

					/* stack_front(&S); */ stack_pop();
					int area = S.height * (i - S.pos);
					maxv = max(maxv, area);
					target = S.pos;
				}

				rect.pos = target;
				stack_push(&rect);
			}
		}
	}

	return maxv;
}

int
getLargestRectangle()
{
	int i, j;

	for (j = 0; j < w; ++j)
	{
		for (i = 0; i < h; ++i)
		{
			if (field[i][j] == '*')
				T[i][j] = 0;
			else
				T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
		}
	}

	int maxv = 0;
	for (i = 0; i < h; ++i)
	{
		int area = getArea(w, T[i]);
		maxv = max(maxv, area);
	}

	return maxv;
}

int
main(int argc, char **argv)
{
	int i;

	while (true)
	{
		scanf("%d %d\n", &h, &w);
		if (w == 0 && h == 0)
			break;

		for (i = 0; i < h; ++i)
			scanf("%s", &field[i][0]);

		printf("%d\n", getLargestRectangle());
	}

	return 0;
}

Measured memory_bytes: 1832
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Console.WriteLine((x[0] / x[1]) + " " + (x[0] % x[1]) + " " + (1.0 * x[0] / x[1]).ToString("f12"));

	}
}


Measured memory_bytes: 16436