akhauriyash/Code-Regression huggingface dataset:
require 'pp'

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end

def min(a, b)
  return a < b ? a : b
end

N, h_list = gets_n_and_i_list
INF = Float::INFINITY

# DP 配列全体を「DP の種類に応じた初期値」で初期化
dp = Array.new(N, INF)

# 初期条件を入力
dp[0] = 0
dp[1] = (h_list[1] - h_list[0]).abs

# 貰うDP
1.upto(N-2) do |i|
  diff1 = (h_list[i + 1] - h_list[i]).abs + dp[i]
  diff2 = (h_list[i + 1] - h_list[i - 1]).abs + dp[i - 1]
  dp[i + 1] = min(diff1, diff2)
end

puts dp.last

Measured memory_bytes: 22016
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int n;
    cin>>n;
    int act[n][3];
    rep(i,n) {
        rep(j,3) {
            cin >> act[i][j];
        }
    }
    int dp[n+1][3];
    rep(i,n+1){
        rep(j,3){
            dp[i][j]=0;
        }
    }

    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(k!=j){
                    dp[i+1][j]=max(dp[i][k]+act[i][j],dp[i+1][j]);
                }
            }
        }
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;



return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int k=sc.nextInt();
    int x=sc.nextInt();
    int ans=x-k+1;
    for (int i=0;i<k*2-1;i++) {
      System.out.print(ans+" ");
      ans++;
    }
    System.out.println();
  }
}


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

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;

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

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        cout << A[i] << " ";
    }
    cout << endl;
}

void solve() {
    string s;
    cin >> s;

    replace(s.begin(), s.end(), '?', 'D');

    cout << s << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();

    int t = 1;

    // cin >> t;

    for (int _ = t; _ > 0; _--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3776
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	answer := f(n, m)
	fmt.Println(answer)
}

func f(n, m int) int {
	res := 0
	if n > 1 {
		res += nCr(n, 2)
	}
	if m > 1 {
		res += nCr(m, 2)
	}
	return res
}

func nCr(n, r int) int {
	molecule, denominator := 1, 1
	for i := 0; i < r; i++ {
		molecule *= n - i
		denominator *= r - i
	}
	res := molecule / denominator

	return int(res)
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    int[] p = new int[n];
    for(int i = 0; i < m; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      if(h[a] > h[b]) {
        p[b]++;
      } else if(h[a] == h[b]) {
        p[a]++;
        p[b]++;
      } else {
        p[a]++;
      }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
      if(p[i] == 0) ans++; 
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 60056
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
#include<iomanip>
#define _for(i,a,b) for(int i = (a);i < (b);i++)
#define mset(x) memset(x,0,sizeof(x));
using namespace std;
int bubblesort(int A[],int N)
{
	int sw = 0;
	bool flag = 1;
	for(int i = 0;flag ;i++)
	{
		flag = 0;
		for(int j = N - 1; j >= i + 1;j--)
		{
			if(A[j] <A[j - 1])
			{
				swap(A[j],A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main() {
	int A[100],N,sw;
	cin>>N;
	for(int i = 0; i < N;i++)
	{
		cin>>A[i];
	 } 
	 sw = bubblesort(A,N);
	 for(int i = 0;i < N;i++)
	 {
	 	if(i) cout<<" ";
	 	cout<<A[i];
	 }
	 cout<<endl;
	 cout<<sw<<endl;
	return 0;
}


Measured memory_bytes: 3128
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, t;
	cin >> n >> t;
	vi v(n);
	REP(i, n)cin >> v[i];
	vl ans(n);
	ans[0] = t / v[0] + 1;
	vvl time(n, vl(2));
	time[0][0] = 0; time[0][1] = v[0];
	ll f = v[0], maxh = v[0];
	REP(i, n - 1) {
		time[i + 1][0] = time[i][0] + v[i];
		time[i + 1][1] = max(time[i][1]+v[i], time[i + 1][0] + v[i + 1]);
		ll d = time[i + 1][1] - time[i + 1][0];
		if (t < time[i + 1][0])ans[i + 1] = 1;
		else {
			ans[i + 1] = (t - (time[i + 1][0] - (d - v[i + 1]))) / d+1;
		}
	}
	REP(i, n)cout << ans[i] << endl;
}

Measured memory_bytes: 9480
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a, b = map(int, input().split())
pa, pb = set(prime_factorize(a)), set(prime_factorize(b))
print(len(list(pa & pb))+1)

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

ans=0
x=0
for i in range(0,n):
  ans+=b[i]
  
for j in range(1,n):
  if a[j]==a[j-1]+1:
    ans+=c[a[j-1]-1]
  else:
    x+=1
    
print(ans)    



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

using namespace std;


int main() {
    long long n, d;
    cin >> n >> d;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        long long x, y;
        cin >> x >> y;
        if(pow(x, 2) + pow(y, 2) <= pow(d, 2)) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;

ll lcm2(ll A, ll B){
	return (A*B)/(__gcd(A,B));
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll A; cin >> A;
	ll B; cin >> B;
	cout << lcm2(A,B);

	return 0;
}


Measured memory_bytes: 256
from collections import Counter

def main():
  n = int(input())
  l = [input() for _ in range(n)]
  s = Counter(l)
  ans = []
  max_value = max(s.values())
  for x in s:
    if s[x] == max_value:
      ans.append(x)
  ans.sort()
  for x in ans:
    print(x)
  

if __name__ == '__main__':
  main()

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

int main() {
 int n,flag=0;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=="Y")flag=1;
  }
  if(flag==1)cout<<"Four"<<endl;
  else cout<<"Three"<<endl;
}

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

int int_sort( const void * a , const void * b ) {
  if( *( int * )a < *( int * )b ) {
    return 1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return -1;
}

int main(void){
	int n,m;
	int a[100]={0};
	int i;
	int sum=0;

	scanf("%d %d\n",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	qsort(a,n,sizeof(a[0]),int_sort);
	if(a[m-1]*4*m<sum){
		printf("No");
	}else{
		printf("Yes");
	}
	return 0;
}


Measured memory_bytes: 128
import sys
sys.stdin.readline

def main():
    N, A, B = map(int, input().split())
    V = list(map(int, input().split()))
    DP1 = [[0] * (N + 1) for _ in range((N + 1))]
    DP2 = [[0] * (N + 1) for _ in range((N + 1))]
    DP2[0][0] = 1
    for i in range(1, N+1):
        DP1[i][0] = DP1[i-1][0]
        DP2[i][0] = DP2[i-1][0]
        for j in range(1, N+1):
            if DP2[i-1][j]:
                if DP1[i-1][j] == DP1[i-1][j-1] + V[i-1]:
                    DP1[i][j] = DP1[i-1][j]
                    DP2[i][j] = DP2[i-1][j] + DP2[i-1][j-1]
                elif DP1[i-1][j] > DP1[i-1][j-1] + V[i-1]:
                    DP1[i][j] = DP1[i-1][j]
                    DP2[i][j] = DP2[i-1][j]
                else:
                    DP1[i][j] = DP1[i-1][j-1] + V[i-1]
                    DP2[i][j] = DP2[i-1][j-1]
            elif DP2[i-1][j-1]:
                DP1[i][j] = DP1[i-1][j-1] + V[i-1]
                DP2[i][j] = DP2[i-1][j-1]
    mx = max(DP1[N][n]/n for n in range(A, B+1))
    print(mx)
    print(sum(DP2[N][n] for n in range(A, B+1) if DP1[N][n]/n == mx))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3192
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e for l in range(d)] for k 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 = 10**19
MOD = 10**9 + 7
EPS = 10**-10

N = INT()

dp = [0] * (N+1)
dp[0] = 1
for i in range(N+1):
    for j in range(3, N+1):
        if i+j <= N:
            dp[i+j] += dp[i]
            dp[i+j] %= MOD
ans = dp[N]
print(ans)


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

typedef long long ll;

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

    int n, m;
    cin>>n>>m;

    int A[n];
    memset(A, 0, sizeof(A));
    int l, r;
    for (int i=0;i<m;++i){
        cin>>l>>r;
        l--; r--;
        A[l] += 1;
        if (r<n-1) A[r+1] += (-1);
    }

    int cnt = 0;
    if (A[0] == m) cnt++;
    for (int i=1;i<n;++i){
        A[i] += A[i-1];
        if (A[i] == m) cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	cin >> n;
	
	vi h(n);
	for(int i = 0; i < n; i++) cin >> h[i];	
	
	vi dp(n, inf);
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		if(i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
		if(i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
	}
	
	cout << dp[n - 1] << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

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

int main(){
  string S;
  cin>>S;
  int a=0;
  int k=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='S'){
      k=max(0,k);
      k++;
    }
    if(S[i]=='T'){
      k--;
      if(k<0)a++;
    }
  }
  cout<<2*a<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr LL inv(LL x, LL m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr LL mpow(LL a, LL k, LL m) { LL r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }

int main() {
    int n;
    cin >> n;
    int a = 0, b = 0, c = 0;
    cin >> a >> b;
    int x = 0, y = 0, z = 0;
    FI(i, 1, n) {
        cin >> c;
        if (c <= a) x++;
        else if (c <= b) y++;
        else z++;
    }
    cout << min({x, y, z}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n,ans;
	cin>>n;
	ans=n*(n-1)*(n-2)/6;
	ll a[2005];
	for(ll i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	a[n+1]=2147483647;
	for(ll i=1;i<n-1;i++){
		for(ll j=i+1;j<n;j++){
			ans-=n-(lower_bound(a+1,a+n+2,a[i]+a[j])-a)+1;
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long long> ar(n,0);
    bool flag = false;
    for(int i=0;i<n;i++)
    {
        cin >> ar[i];
        if(ar[i] == 0)
            flag = true;
    }
    if(flag == true)
    {
        cout << 0 << endl;
        return 0;
    }
    long long prod = 1;
    for(int i=0;i<n;i++)
    {
        if(ar[i] <= 1000000000000000000/ prod)
        {
            prod *= ar[i];
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << prod << endl;
    return 0;
}


Measured memory_bytes: 4048
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

const int INF = INT_MAX / 2;

vector<ll> as;
vector<ll> dp;

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

    as.resize(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> as[i];
    }

    dp.resize(N + 1);
    dp[1] = 1000;

    for (int i = 2; i <= N; i++) {
        dp[i] = dp[i - 1];
        for (int j = 1; j < i; j++) {
            ll stocks = dp[j] / as[j];
            chmax(dp[i], dp[j] - stocks * as[j] + stocks * as[i]);
        }
    }

    // for (auto x : dp) {
    //     cout << x << " ";
    // }
    // cout << endl;

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        String S = sc.next();
        int cnt = 0;
        int[] SInts = new int[S.length()];

        for (int i = 0; i < N; i++) {
            SInts[i] = Character.getNumericValue(S.charAt(i));
        }

        for (int i = 0; i < 1000; i++) {
            int[] PIN = {i / 100, (i / 10) % 10, i % 10};
            int matchesCnt = 0;
            for (int j = 0; j < N; j++) {
                if (SInts[j] == PIN[matchesCnt]) {
                    matchesCnt++;
                }
                if (matchesCnt == 3) {
                    cnt++;
                    break;
                }
            }
        }

        System.out.println(cnt);
    }


}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) ans++;
        }
    }
    ans = (ans * k) % MOD;
    ll hoge = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) hoge++;
        }
    }
    ans += (k * (k - 1) / 2) % MOD * hoge % MOD;
    cout << ans % MOD << endl;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

class floating_median {
  public:
    priority_queue<ll> former;
    priority_queue<ll, vector<ll>, greater<ll>> latter;
    void push_former(ll num) {
        former.push(num);
        sum_former += num;
    }
    void push_latter(ll num) {
        latter.push(num);
        sum_latter += num;
    }

    ll sum_former = 0, sum_latter = 0;
    void push(ll num) {
        if (former.size() > latter.size()) {
            ll t = former.top();
            if (num >= t) {
                push_latter(num);
            } else {
                former.pop();
                sum_former -= t;
                push_former(num);
                push_latter(t);
            }
        } else {
            if (former.empty()) {
                push_former(num);
            } else {
                ll t = latter.top();
                if (num <= t) {
                    push_former(num);
                } else {
                    ll t = latter.top();
                    if (num <= t) {
                        push_former(num);
                    } else {
                        latter.pop();
                        sum_latter -= t;
                        push_latter(num);
                        push_former(t);
                    }
                }
            }
        }
    }
    ll get() { return former.top(); };
};

int main() {
source:
    ll q;
    cin >> q;
    ll b_all = 0;
    floating_median f;
    vector<pair<ll, ll>> ans;
    rep(i, q) {
        ll temp;
        cin >> temp;
        if (temp == 1) {
            ll a, b;
            cin >> a >> b;
            f.push(a);
            b_all += b;
        } else {
            ll x = f.get();
            ll result = (x * f.former.size() - f.sum_former) +
                        (f.sum_latter - x * f.latter.size()) + b_all;
            ans.push_back(make_pair(x, result));
        }
    }

    rep(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }

    return 0;
}



Measured memory_bytes: 5868
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

fn solve() {
    let N = read!(usize);
    let mut C = read![usize; N];

    for i in 0..N {
        C[i] -= 1;
    }
    let M = C.iter().cloned().max().unwrap();

    let mut last = vec![N; M + 1];
    let mut next = vec![N; N + 1];
    let mut i = 0;
    while i < N {
        while i + 1 < N && C[i] == C[i + 1] {
            i += 1;
        }

        next[last[C[i]]] = i;
        last[C[i]] = i;
        i += 1
    }
    debug!(next);

    // dp[r]: 0..r の塗り方が決まって、r.. に操作が及んでないときの場合の数

    let mut dp = vec![P; N + 1];
    dp[N] = 1;

    let mut memo = vec![P; N + 1];

    let mut i = N - 1;
    loop {
        let mut sum = dp[i + 1];

        let r = next[i];
        if r < N {
            sum += memo[r];
            sum %= P;
        }
        memo[i] = sum;

        dp[i] = sum;
        if i == 0 {
            break;
        }
        i -= 1;
    }
    debug!(dp);

    println!("{}", dp[0]);
}

fn main() {
    solve();
}


Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
 

int N;
ll W;
ll w[110],v[110],ans;

ll dp[212345]; //dp[i] 価値iのものを作るのに最小の重さ
signed main(){
    cin>>N>>W;
    rep(i,N){
        cin>>w[i]>>v[i];
    }

    rep(i,212345){
        dp[i]=INF+10;
    }

    dp[0]=0;
    for(int j=0;j<N;j++){
        for(int i=112345;i>=0;i--){
            dp[i+v[j]]=min(dp[i]+w[j],dp[i+v[j]]);
        }
    }

    for(int i=0;i<212345;i++){
        if(dp[i]<=W)ans=max(ans,(ll)i);
    }
    cout<<ans<<endl;

}

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


int main() {
	int N;
	int K;
	int h[100000];
	int a = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		if (h[i] >= K) {
			a++;
		}
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;

int x[4]={4,-4,1,-1};

bool in(int a){
  if(0<=a && a<=7)return true;
  return false;
}

int main()
{
  char c;
  string s;

  queue<string> q;
  map<string,int> m;
  q.push("01234567");
  m["01234567"]=0;
  int ans=0;
  while(!q.empty()){
    string u=q.front();
    q.pop();

    int index=u.find('0');
    for(int j=0;j<4;j++){
      if((index==3 && x[j]==1) || (index==4 && x[j]==-1))continue;
      if(in(index+x[j])){
	string t=u;
	swap(t[index],t[index+x[j]]);
	if(m.find(t)==m.end()){
	  m[t]=m[u]+1;
	  q.push(t);
	}
      }
    }
  }

  while(cin>>c){
    s=c;
    for(int i=0;i<7;i++){
      cin>>c;
      s+=c;
    }
    cout<<m[s]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3440
# coding: utf-8


H, W = map(int,input().split())
moto = []
for i in range(H):
    moto.append(list(input()))
for i in range(H):
    j = 0
    while moto[H-i-1][j] == ".":
        if j == W-1:
            moto.pop(H-i-1)
            break
        j += 1

for i in range(W):
    j = 0
    while moto[j][W-i-1] == ".":
        if j == len(moto)-1:
            for k in range(len(moto)):
                moto[k].pop(W-i-1)
            break
        j += 1
for i in range(len(moto)):
    for j in range(len(moto[0])-1):
        print(moto[i][j],end="")
    print(moto[i][len(moto[0])-1])

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

lli f(int a[], const int N, int mod)
{
  lli sum = 0;
  lli cost = 0;

  for (int i = 0; i < N; ++i) {
    sum += a[i];
    if (i % 2 == mod) {
      if (sum < 1) {
        cost += abs(sum) + 1;
        sum = 1;
      }
    } else {
      if (-1 < sum) {
        cost += abs(sum) + 1;
        sum = -1;
      }
    }
  }
  
  return cost;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  while (cin >> n) {
    int a[n];
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    cout << min(f(a, n, 0), f(a, n, 1)) << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 300001;
const ll M = 1;
struct point {
    ll x, y;
    ll i;
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    else if(n & 1)
        return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll tmp = fast_exp(x, n >> 1);
        return tmp * tmp % mod;
    }
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    int test = 0;
    while(_--)
    {
        ll n, m, x = 0, y = 0, ans = 0, k;
        cin >> n >> m;
        ll a[n + 1] = {};
        for(int i = 1; i <= n; i++) cin >> a[i];
        vector<int> tree[n + 1];
        while(m--)
        {
            cin >> x >> y;
            tree[x].pb(y);
            tree[y].pb(x);
        }
        for(int i = 1; i <= n; i++)
        {
            x = -INF;
            for(auto j:tree[i])
                x = max(x, a[j]);
            if(a[i] > x) ans++;
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 9528
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;

class Program
{
    static readonly double INF = double.PositiveInfinity;

    static void Main(string[] args)
    {
        while (true)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = input[0], M = input[1], P = input[2], A = input[3] - 1, B = input[4] - 1;
            if (N == 0) break;
            int[] nums = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            double[][] dist = E.Range(0, M).Select(i => E.Repeat(INF, M).ToArray()).ToArray();

            for (int i = 0; i < P; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                dist[input[0] - 1][input[1] - 1] = input[2];
                dist[input[1] - 1][input[0] - 1] = input[2];
            }
            double[][] dp = E.Range(0, 1 << N).Select(i => E.Repeat(INF, M).ToArray()).ToArray();
            dp[0][A] = 0;
            for (int mask = 0; mask < (1 << N); mask++)
                foreach (int use in E.Range(0, N).Where(use => (mask >> use & 1) == 0))
                    foreach (int i in E.Range(0, M).Where(i => dp[mask][i] < INF))
                        foreach (int j in E.Range(0, M).Where(j => i != j && dist[i][j] < INF))
                        {
                            double cost = dp[mask][i] + dist[i][j] / nums[use];
                            int nextMask = mask | 1 << use;
                            dp[nextMask][j] = Math.Min(dp[nextMask][j], cost);
                        }

            double ans = E.Range(0, 1 << N).Min(mask => dp[mask][B]);
            Console.WriteLine((ans > int.MaxValue) ? "Impossible" : ans.ToString("f3"));
        }
    }
}

Measured memory_bytes: 6440
#import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#threading.Thread(target=main).start()
import threading
threading.stack_size(2**26)
sys.setrecursionlimit(10**8)
mod=(10**9)+7
#fact=[1]
#for i in range(1,1000001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*1000001
#ifact[1000000]=pow(fact[1000000],mod-2,mod)
#for i in range(1000000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod
from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import math
import heapq
from random import randint as rn
from Queue import Queue as Q
def modinv(n,p):
    return pow(n,p-2,p)
def ncr(n,r,p):
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t
def ain():
    return map(int,sin().split())
def sin():
    return stdin.readline().strip()
def GCD(x, y):
   while(y):
       x, y = y, x % y
   return x
"""**************************************************************************"""
n=input()
h=ain()
d=[10**18]*n
d[0]=0
if(n>1):
    d[1]=abs(h[1]-h[0])
for i in range(2,n):
    d[i]=min(d[i-1]+abs(h[i]-h[i-1]),d[i-2]+abs(h[i]-h[i-2]))
print d[-1]


Measured memory_bytes: 44556
import array
def count_mizuyari(l):
    count = 0
    arr = array.array('i',[0])
    arr.extend(l)
    for i in range(len(arr)-1):
        if(arr[i]==0 and arr[i+1]!=0):
            count += 1
    return count
    

def mizuyari2(l):
    count = 0
    stopper = 0

    #要素が全部0かどうかの判定
    for i in l:
        stopper+=i 
    if(stopper == 0):
        return 0 
    else:     
        count=count_mizuyari(l)
    for index,i in enumerate(l):           
        l[index]-=1
        if(l[index]<0):
            l[index]=0

    return count+mizuyari2(l)

N = int(input())
h = array.array('i')

li = input().rstrip().split()
for i in li:
    h.append(int(i))


print(mizuyari2(h))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long N = scn.nextInt();
		int M = scn.nextInt();
		long ans = N;
		for(int i = 0;i<M;i++) {
			ans -= scn.nextInt();
		}
		scn.close();
		if(ans <= -1) {
			System.out.println(-1);
		} else {
			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 46416
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int H,W,h,w;
void Solve() {
    read(H);read(W);read(h);read(w);
    if(H % h != 0) {
	puts("Yes");
	for(int i = 0 ; i < H ; ++i) {
	    for(int j = 0 ; j < W ; ++j) {
		if(i % h == 0) {out(1000 * (h - 1) - 1);}
		else out(-1000);
		space;
	    }
	    enter;
	}
    }
    else if(W % w != 0) {
	puts("Yes");
	for(int i = 0 ; i < H ; ++i) {
	    for(int j = 0 ; j < W ; ++j) {
		if(j % w == 0) {out(1000 * (w - 1) - 1);}
		else out(-1000);
		space;
	    }
	    enter;
	}
    }
    else {
	puts("No");
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 1664
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io, flush := NewIO()
	defer flush()

	n, _ := io.ScanInt2()
	strs := io.ScanStrings(n)

	sort.Strings(strs)
	io.Println(strings.Join(strs, ""))
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 2208
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        // programming
        int n = getInputInteger(sc);
        int[] d = new int[n];
        for (int i = 0; i < n; i++) {
            d[i] = getInputInteger(sc);
        }
        int[] d_sort = sort(d, false);
        int temp = -1;
        int count = 0;
        for (int i = 0; i < d_sort.length; i++) {
            if (temp == d_sort[i]) {
                continue;
            }
            count++;
            temp = d_sort[i];
        }
        output(String.valueOf(count));
	}

	public static String getInputString(Scanner sc) {
		return sc.next();
	}

	public static int getInputInteger(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	public static void output(String... params) {
		boolean isInit = true;
		String str = "";
		for (String s : params) {
			if (!isInit) {
				str += " ";
			}
			str += s;
			isInit = false;
		}
		System.out.println(str);
	}

    public static int[] toIntegerList(String s) {
        int[] ret = new int[s.length()];
        for (int i = 0; i < s.length(); i++) {
            ret[i] = Integer.parseInt(String.valueOf(s.charAt(i)));
        }
        return ret;
    }

    public static int sum(int[] vals) {
        int sum = 0;
        for (int val : vals) {
            sum += val;
        }
        return sum;
    }

    public static int[] sort(int[] vals, boolean isAsc) {
        Arrays.sort(vals);
		if (isAsc) {
			return vals;
		}
        int[] ret = new int[vals.length];
        for (int i = 0; i < vals.length; i++) {
            ret[vals.length - i - 1] = vals[i];
        }
		return ret;
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=3010;
int tt;
int a[N],head[N],to[N*2],nxt[N*2];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline bool dfs(int x,int fa) {
    for(int i=head[x];i;i=nxt[i]) {
	int y=to[i];
	if(y!=fa&&a[y]<a[x]&&!dfs(y,x)) return 1;
    }
    return 0;
}
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi();
    for(int i=1;i<n;i++) {
	int x=gi(),y=gi();
	to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
	to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
    }
    for(int i=1;i<=n;i++)
	if(dfs(i,0)) printf("%d ",i);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    string o,e; cin >> o >> e;
    string res;
    FOR(i,0,e.size()){
        res = res + o[i] + e[i];
    }
    if(o.size()>e.size()) res = res + o[o.size()-1];
    cout << res << endl;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	string str;
	cin >> str;
	int cnt;
	sort(begin(str), end(str));
	for (int i = 0; i < str.size(); i += cnt) {
		cnt = upper_bound(begin(str) + i, end(str), str[i])
			- lower_bound(begin(str) + i, end(str), str[i]);
		if (cnt % 2) {
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}

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


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    def f():
        n = I()
        r,t = LF()
        a = [LI() for _ in range(n)]
        d = {}
        M = 32
        for i in range(n):
            ax,ay = a[i]
            for j in range(n):
                if i == j:
                    continue
                bx,by = a[j]
                d[i*M+j] = math.atan2(bx-ax,by-ay) / math.pi * 180
        ky = {}
        for i in range(n):
            ax,ay = a[i]
            for j in range(n):
                bx,by = a[j]
                ky[i*M+j] = pow(pow(ax-bx, 2) + pow(ay-by, 2), 0.5)
        e = collections.defaultdict(list)
        for i in range(n):
            for j in range(n):
                if i == j:
                    continue
                ij = i*M+j
                dij = d[ij]
                for k in range(n):
                    if k == j:
                        continue
                    jk = j*M+k
                    djk = d[jk]
                    if abs(dij-djk) <= t or 360 - abs(dij-djk) <= t:
                        e[(i,j)].append(((j,k), ky[jk]))

        def search():
            res = 0
            dp = [[None]*n for _ in range(n)]
            for j in range(1, n):
                k = ky[j]
                if k > r:
                    continue
                s = (j,1)
                res = 1
                dp[0][j] = k
            if res == 0:
                return 0
            while True:
                wf = False
                nd = [[None]*n for _ in range(n)]
                for i in range(n):
                    for j in range(n):
                        if dp[i][j] is None:
                            continue
                        dij = dp[i][j]
                        for nn,k in e[(i,j)]:
                            nk = dij + k
                            if nk > r or (not nd[j][nn[1]] is None and nd[j][nn[1]] < nk):
                                continue
                            nd[j][nn[1]] = nk
                            wf = True
                if wf:
                    res += 1
                    dp = nd
                else:
                    break
            return res

        return search()

    while True:
        rr.append(f())
        break

    return '\n'.join(map(str,rr))


print(main())



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

int main()
{
  i64 a, b, k;
  cin >> a >> b >> k;
  if (k < a)
    cout << a - k << " " << b << endl;
  else
    cout << 0 << " " << max(0LL, b - (k - a)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
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(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<ll,int> pli;

int main(){
    ll N,K;cin>>N>>K;
    vector<pli> sushi;
    vector<vector<ll> >val(N+1);
    rep(i,N){
        int a,b;
        cin >> a>> b;
        sushi.push_back(make_pair(b,a));
    }
    sort(All(sushi));
    reverse(All(sushi));
    for(auto &s:sushi)val[s.second].push_back(s.first);
    for(auto &v:val){
        sort(All(v));
        reverse(All(v));
    }
    set<ll> types;//Sの種類の集合
    priority_queue<ll,vector<ll>,greater<ll> >min_que;//Sからとりだすもの
    priority_queue<ll,vector<ll> >max_que;//余りからSへいれるもの
    ll f = 0;
    rep(i,K){//大きいものからK個選んでSを構成
        f+=sushi[i].first;
        //ベスト値以外のものをキューにいれる
        if(types.find(sushi[i].second)!=types.end())min_que.push(sushi[i].first);
        types.insert(sushi[i].second);
    }
    //解を改善できる可能性があるものをひとつずつ（Sにない種類で最大のもの）キューに入れる。
    for(int i=1;i<=N;i++)if(types.find(i)==types.end()&&val[i].size()>0)max_que.push(val[i][0]);
    ll num = types.size();
    ll res = f + num*num;

    while(!min_que.empty()&&!max_que.empty()){
        ll unes = min_que.top();min_que.pop();
        ll nes = max_que.top();max_que.pop();
        f -=unes;f+=nes;
        num++;
        res = max(res,f+num*num);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 10480
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N, M = [int(i) for i in input().strip().split()]
    hights = [int(i) for i in input().strip().split()]
    routes = [[int(i) for i in input().strip().split()] for _ in range(M)]

    counter = 0
    ans_table = [1] * N

    for route in routes:
        idx_0 = route[0] - 1
        idx_1 = route[1] - 1
        if hights[idx_0] > hights[idx_1]:
            ans_table[idx_1] = 0
        elif hights[idx_0] < hights[idx_1]:
            ans_table[idx_0] = 0
        else:
            ans_table[idx_0] = 0
            ans_table[idx_1] = 0

    return sum(ans_table)


if __name__ == "__main__":
    print(main())


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int a, b, c, d, n, x, y;
    string s, t;


    auto Yes = [&](bool t){
        cout << (t ? "Yes" : "No") << endl;
    };
    auto YES = [&](bool t){
        cout << (t ? "YES" : "NO") << endl;
    };
    auto tri = [&](bool t, string a, string b){
        cout << (t ? a : b) << endl;
    };

    cin >> n >> a;
    cout << n - a + 1 << endl;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> A(n);
    for(int i=0; i<n; ++i) cin>>A[i];
    vector<int> Dp(n,INT_MAX);
    Dp[0]=0;
    for(int i=0; i<n; ++i){
        for(int x: {1,2}){
            if(i+x<n){
                Dp[i+x]=min(Dp[i+x], Dp[i]+abs(A[i]-A[i+x]));
            }
        }
    }
    cout<<Dp[n-1]<<"\n";
}

Measured memory_bytes: 3996
n = int(input())
taro =0
hanako=0
alfa='abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    A,B = input().split()
    a = len(A)
    b=len(B)
    j=0
    while j<a and j<b:
        ta=alfa.find(A[j])
        ha=alfa.find(B[j])
        if ta>ha:
            taro+=3
            break
        elif ha>ta:
            hanako+=3
            break
        elif j==a-1 and j==b-1:
            taro+=1
            hanako+=1
            break
        j+=1
    else:
        if a>b:
            taro+=3
        else:
            hanako+=3
print(taro,hanako)


        
        
    
        
    
    


Measured memory_bytes: 5600
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	for {
		if c <= 0 {
			fmt.Println("Yes")
			break
		} else {
			c -= b
		}

		if a <= 0 {
			fmt.Println("No")
			break
		} else {
			a -= d
		}
	}
}

Measured memory_bytes: 1756