akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll dp[100010][3];
int v[100010][3];
int solve(){
  int n;
  cin>>n;
  rep(i,n)rep(j,3)cin>>v[i][j];
  rep(i,3)dp[0][i] = v[0][i]; 
  REP(i,1,n){
    rep(j,3){
      rep(k,3){
        if(j == k)continue;
        dp[i][k] = max(dp[i][k],dp[i - 1][j] + v[i][k]);
      }
    }
  }
  ll ans = 0;
  rep(i,3)ans = max(ans,dp[n - 1][i]);
  cout << ans << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}


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

typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  ll s = 0;
  for (ll b = 1; b <= N; b++) {
    ll p = N/b;
    ll r = N%b;
    ans += p * max(s, b-K) + max(s, r-K+1);
    if (K == 0) {
      ans -= 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define slowanddetermined ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x); cout<<#x<<"="<<x<<endl;
#define debug2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long
using namespace std;


int32_t main()
{
    slowanddetermined
    int n,m;
    cin>>n>>m;

    vector<int>arr(n);
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(sum<=arr[i]*(4*m))ans++;
    }
    if(ans>=m){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }





    return 0;

}




Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int yosinagasayuri(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a < b ? -1 : a > b;
}

int N, K;
int p[1024];

int main(void) {
	int i;
	int mareitaso = 0;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &p[i]) != 1) return 1;
	}
	qsort(p, N, sizeof(*p), yosinagasayuri);
	for (i = 0; i < K; i++) {
		mareitaso += p[i];
	}
	printf("%d\n", mareitaso);
	return 0;
}


Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int a,b,t;
    cin>>a>>b>>t;
    cout<<b*(t/a)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int N, A, B;
  if(scanf("%d %d %d", &N, &A, &B) == EOF) exit(1);
  if(N*A < B){
    printf("%d", N*A);
  }
  else
    printf("%d", B);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int a,b,c=1;
    scanf("%d %d",&a,&b);
    if((a*b*1)%2 == 1){
        printf("Yes");
    }else if((a*b*3)%2 == 1){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans=0
k=int(input())
for a in range(1,k+1):
    for b in range(a+1,k+1):
        for c in range(b+1,k+1):
            ans+=gcd(a,b,c)*6
for a in range(1,k+1):
        for c in range(a+1,k+1):
            b=a
            ans+=gcd(a,b,c)*3
for a in range(1,k+1):
        for c in range(a+1,k+1):
            b=c
            ans+=gcd(a,b,c)*3
print(ans+sum([i for i in range(1,k+1)]))

Measured memory_bytes: 9632
def freq(v)
  h=Hash.new
  v.each{|x|
    if h.has_key?(x)  then
      h[x] += 1
    else
      h[x] = 1
    end
  }
  return v.map{|x| h[x]}
end

def solv(v)
  m=0
  w=[]
  while true do
    w=freq(v)
    break if v==w
    m += 1
    v = w
  end

  return [m, w]
end

if true then
fh=STDIN
else
fh=open("in0108.txt")
end
while fh.gets do
  n=$_.to_i
  break if n==0
  v=fh.gets.chomp.split.map{|x|x.to_i}
  m,f=solv(v)
  puts m
  puts f.map{|x|x.to_s}.join(" ")
end

Measured memory_bytes: 8984
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 300015;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL n;
    cin >> n;
    LL a[SIZE];
    for( int i = 0; i < n * 3; ++i ) {
        cin >> a[i];

    }
    sort( a, a + ( n * 3 ), greater< LL >() );
    
    LL res = 0;
    for( int i = 1; i < n * 2; i += 2 ) res += a[i];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6+5
#define quick_pow_mod 1e9+7
#define PII pair<int,int>
const int factor_N = 1e7 + 5;
const int tree_arr_N = 1e6 + 5;
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
	return x * f;
}
int x;
int main() {
	x = read();
	if (x >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

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

  int multipleOf4 = 0;
  int multipleOf2 = 0;
  int odd = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A % 4 == 0) {
      multipleOf4++;
    } else if (A % 2 == 0) {
      multipleOf2++;
    } else {
      odd++;
    }
  }

  if (multipleOf2 > 1) {
    multipleOf2 = 1;
  }

  if (multipleOf4 + 1 >= odd + multipleOf2) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


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

using namespace std;

/*

1 -> 2 ->3->4
       ->4
  -> 3 ->4
       ->
*/

int n;
int MAX = 999999999;
vector<int> hi;
map<pair<int, int>, int> memo;

int jump(int ind, int to_ind, int total)
{
  if (to_ind > n)
    return MAX;
  int cur_cost = abs(hi[ind] - hi[to_ind]);
  if (to_ind == n)
    return cur_cost;
  if (memo.count({ind, to_ind}))
    return memo[{ind, to_ind}];
  int left = cur_cost + jump(to_ind, to_ind + 1, total + cur_cost);
  int right = cur_cost + jump(to_ind, to_ind + 2, total + cur_cost);
  // cout << "ind " << ind << " to_ind " << to_ind << " left " << left << endl;
  // cout << "ind " << ind << " to_ind " << to_ind << " right " << right << endl;
  memo[{ind, to_ind}] = min(left, right);
  return min(left, right);
}

int main()
{

  cin >> n;
  hi.resize(n + 1);
  // memo.resize(n + 1, -1);
  int sum = 0;
  for (int i = 1; i <= n; i++)
  {
    cin >> hi[i];
  }
  cout << jump(1, 1, 0) << endl;
  return 0;
}

Measured memory_bytes: 22528
import sys
input=sys.stdin.readline
def knapsack(N,W,weight,value):
  dp=[[999999999999 for i in range(W+1)] for j in range(N+1)]
  for i in range(W+1):
    dp[0][i]=0
 
  for i in range(N):
    for w in range(W+1):
      if weight[i]<=w:
        if dp[i][w-weight[i]]+value[i]>dp[i][w]:
          dp[i+1][w]=dp[i][w-weight[i]]+value[i]
        else:
          dp[i+1][w]=dp[i][w]
      else:
        dp[i+1][w]=dp[i][w]
  return dp
 
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
a=[];b=[]
for i in range(n):
  a.append(l[i][0])
  b.append(l[i][1])
dp=knapsack(n,t-1,a,b)
ans=[]
for i in range(n):
  if i!=n:
    ans.append(dp[i][t-1]+b[i])
  else:
    ans.append(dp[n][t])
print(max(ans))

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

int function(int n){
  if(n%2 == 1)
    return 3*n+1;
  else
    return n/2;
}

int main(){
  int s;
  int a,i;
  cin>>s;
  int b[1000000] = {0};
  while(true){
    if(b[s]== 0){
      b[s]++;
      i++;
      s = function(s);
    }
    else{
      cout<<i+1<<endl;
      break;
    }
  }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 1e5 + 9;
vi adj[maxn];
int dp[maxn], n, m;

int solve(int u){
    if (dp[u] != -1)
        return dp[u];
    if (sz(adj[u]) == 0)
        return dp[u] = 0;
    int res = 0;
    trav(a, adj[u]){
        res = max(res, 1 + solve(a));
    }
    return dp[u] = res;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
    }
    int res = 0;
    rep(i, 1, n + 1)
        res = max(res, solve(i));
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b;
    while(cin>>a>>b){
        if(a<=b)cout<<"0"<<endl;
        else cout<<(a-b)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl '\n'
#define pque priority_queue
#define pi acos(-1)
#define int long long
#define N 1000000
typedef pair < int, int > ii;
typedef vector < int > vi;
const int mod = 1000000007;
int n, m, a[1009][1009], f[1009][1009], row[1009][1009], col[1009][1009];
signed main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	swap(n, m);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++)
			cin >> a[i][j];
	for(int i = n; i > 0; i --)
		for(int j = m; j > 0; j --)
		{
			col[i][j] = col[i + 1][j] + a[i][j];
			row[i][j] = row[i][j + 1] + a[i][j];
			if((i + j) % 2)
				f[i][j] = max(f[i][j + 1] + col[i][j], f[i + 1][j] - row[i][j]);
			else
				f[i][j] = min(f[i][j + 1] + col[i][j], f[i + 1][j] - row[i][j]);
			//cout << i << ' ' << j << ' ' << f[i][j] << endl;
		}
	cout << abs(f[1][1]) << endl;
}




Measured memory_bytes: 34788
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    x = ri()
    fifths = {i**5: i for i in range(10000)}

    a = 0
    while 1:
        if x - a**5 in fifths:
            print (a, -fifths[x - a**5])
            return
        elif a**5 - x in fifths:
            print (a, fifths[a**5 - x])
            return
        a += 1






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 75196
#include<bits/stdc++.h>
#define MAX 2000001
using namespace std;
int main()
{
    string s;
    cin>>s;
    int c=0,a=MAX,z=0;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]=='A'&&i<a)
            a = i;
        if(s[i]=='Z'&&i>a)
            z = i;
    }
    if(z==0)
        cout<<0<<endl;
    else
    {
        cout<<(z-a)+1<<endl;
    }
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
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; }

int main(){
    int m,d;
    cin>>m>>d;

    int ans=0;
    rep(i,1,m+1){
      rep(j,20,d+1){
        if(j%10>=2 && (j/10)*(j%10)==i) ans++;
      }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
-module('Main').
-export([main/1]).

main(_) ->
    {ok, [N]} = io:fread("", "~d"),
    A = [XX || XX <- lists:map(fun(_) ->
                                       {ok, [X]} = io:fread("", "~d"),
                                       X
                               end,
                               lists:seq(1, N))],
    Ans = test(A),
    io:format("~p~n", [Ans]),
    halt().


test([]) ->
    0;
test([H]) ->
    H rem 2;
test([H1, _H2|T]) ->
    case H1 rem 2 == 1 of
        true ->
            1 + test(T);
        false ->
            0 + test(T)
    end.


Measured memory_bytes: 22212
#include<iostream>
using namespace std;
bool flg[300];

void make_table(){
  string s="yuiophjklnm";
  for(int i=0;i<(int)s.size();i++){
    flg[(int)s[i]]=true;
  }
}

int main(){
  make_table();
  while(1){
    string str;
    int ans=0;
    cin>>str;
    if(str=="#")break;
    for(int i=1;i<(int)str.size();i++)
      if(flg[(int)str[i-1]]!=flg[(int)str[i]])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
def sum1(N):
    S1 = int((((N // 3)) * (2 * 3 + (N //3 - 1) * 3) //2) )
    S2 = int((((N // 5)) * (2 * 5 + (N // 5 - 1) * 5) // 2) )
    S3 = int((((N // 15)) * (2 * 15+ (N // 15 - 1) * 15) // 2))
    a =  int(S1 + S2 - S3) 
    return a
N = int(input())
ans = (N*(N+1)/2)-sum1(N)
print(int(ans))

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int int_Inf = 2147483647;
const ll ll_Inf = 9223372036854775807LL;

int main() {

	ll n, k; cin >> n >> k;
	vector<ll> x(n);
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
	}
	ll ans = ll_Inf;
	for (ll i = 0; i < n - k + 1; i++) {
		ll tmpAns;
		ll left = x[i];
		ll right = x[i + k - 1];

		if (abs(left) <= abs(right)) {
			tmpAns = abs(left);
		}
		else {
			tmpAns = abs(right);
		}
		tmpAns += right - left;
		ans = min(ans, tmpAns);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 100100100
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

#define mod 998244353
 
int main(){
    int n,q; cin >> n >> q;
    string s; cin >> s;
    vector<int> sum(n);
    int x=0;
    for(int i=1; i<n; i++){
        if(s[i-1] =='A' && s[i] =='C'){
            ++x;
        }
        sum[i] = x;

    }
    vector<int> ans(q);
    rep(i,q){
        int l,r;
        cin >> l >> r;
        l--; r--;
        ans[i] = sum[r] - sum[l];
    }
    rep(i,q) {
        cout << ans[i]<< endl;
    }
    return 0;
    

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define NMAX 1000
using namespace std;
ll cmmmdc(int a, int b)
{
    ll r=a%b;
    while(r!=0)
    {
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main()
{
    ll S, W;
    cin>>S>>W;
    if(S>W)
      cout<<"safe";
      else
        cout<<"unsafe";
    return 0;
}


Measured memory_bytes: 3632
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int ans=0;
        for(int i=1;i<n;i++)
        {
            for(int j=1;j<n;j++)
            {
                if(i*j>=n)
                    break;
                ans++;
            }
        }
        System.out.println(ans);
    }

}


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


Measured memory_bytes: 5596
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int flag = 0;
    int i = 0;
    while(i < N){
        flag = A[flag]; i++;
        if(flag == 2){
            cout << i << endl;
            return 0;
        }
        flag--;
    }
    cout << -1;
    cout << endl;
    return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int n;
cin>>n;
  vector<int> d(n);
  for(int i=0;i<n;i++)
    cin>>d[i];
  
  
  sort(d.begin(),d.end());
  cout<<d[n/2]-d[n/2-1]<<endl;
  return 0;
}


Measured memory_bytes: 768
open Scanf
open Printf

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec take n xs_ = match xs_ with
  | (x::xs) when n > 0 -> x :: take (n-1) xs
  | _ -> []

let group_len xs_ =
  let rec f c x ys =
    match ys with
    | [] -> [c]
    | (y::ys') -> if x = y then f (c+1) x ys' else c :: f 1 y ys' in
  match xs_ with
    | [] -> []
    | (x::xs) -> f 1 x xs

let () =
  let n = read_int () in let k = read_int () in
  let ls = read_ints n |> List.sort (-) |> group_len |> List.sort (-) in
  take (List.length ls - k) ls |> List.fold_left (+) 0 |> printf "%d\n"


Measured memory_bytes: 26016
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = list(map(int, input()))
    K = I()
    l = len(n)
    if l < K:
        print(0)
        return
    dp = [[[0 for k in range(l+1)] for j in range(2)] for i in range(l+1)]
    dp[0][0][0] = 1
    for i in range(l):
        ni = i+1
        for j in range(2):
            for k in range(l):
                x = 9 if j else n[i]
                for d in range(x+1):
                    nk = k+(d!=0)
                    nj = j or d < n[i]
                    if nk <= l:
                        dp[ni][nj][nk] += dp[i][j][k]
    
    print(dp[l][0][K]+dp[l][1][K])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 43404
// =====================================================================================
//
//       Filename:  1643.cpp
//
//    Description:  
//
//        Version:  1.0
//        Created:  10/05/20 02:45:19 PM IST
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com
//   Organization:  
//
// =====================================================================================

#include<bits/stdc++.h>


using namespace std;

#define int long long 
#define pb push_back
//#define _SHOW_TIME

void solve(){
    //your code here;
    string s,t;
    cin>>s>>t;
    int ok =1;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]) ok=0;
    }
    if(ok && s.size()<t.size()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int32_t main(){
 /////////////////////////////////////
    #ifdef _SHOW_TIME
	int tt = (int) clock();
    #endif
    /////////////////////////////////////
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /////////////////////////////////////
    solve();
    /////////////////////////////////////
    #ifdef _SHOW_TIME
        cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl;
    #endif
    /////////////////////////////////////
    return 0;

}



Measured memory_bytes: 3644
n=int(input())

#初期値が0の辞書
from collections import defaultdict
sp = defaultdict(lambda: [])
town=set([])

for i in range(1,n+1):
    s,p=map(str,input().split())
    town.add(s)
    sp[s].append((int(p),i))
town=list(town)
town.sort()
for item in town:
    tmp=sp[item]
    tmp.sort(reverse=True)
    for t in tmp:
        print(t[1])




Measured memory_bytes: 38384
import java.util.*;
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int x = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
        String ans = (Math.abs(x-a) < Math.abs(x-b))? "A": "B";
      	System.out.println(ans);
	}
}

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

int main() {
  int N;
  cin >>N;
  int V[N];
  int C[N];
  int VC[N];
  for (int i=0;i<N; i++){
    cin >> V[i];
  }
  for (int i=0;i<N; i++){
    cin >> C[i];
  }
  for (int i=0; i<N ; i++){
    if (V[i]-C[i]>=0){
      VC[i]=V[i]-C[i];
    }
    else{
      VC[i]=0;
    }
  }
  int cost=0;
  for ( int i=0; i<N;i++){
    cost=cost+VC[i];
  }
  cout << cost << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
volatile int a[10000];
volatile int b[10000];
volatile int m;

int friend2(int s){
	int i;
	for (i=0;i<m;i++){
		if (a[i]==s){
			if(b[i]==1){
				return 1;
			}
		}else if (b[i]==s){
			if (a[i]==1){
				return 1;
			}
		}
	}
	return 0;
}

int friend(int s){
	int i;
	for (i=0;i<m;i++){
		if (a[i]==s){
			if (b[i]==1){
				return 1;
			}else if(friend2(b[i])==1){
				return 1;
			}
		}else if(b[i]==s){
			if (a[i]==1){
				return 1;
			}else if(friend2(a[i])==1){
				return 1;
			}
		}
	}
	return 0;
}

int main(void){
	for (;;){
		int i;
		for (i=0;i<10000;i++){
			a[i]=0;
			b[i]=0;
		}
		int n;
		int x=0;
		scanf("%d",&n);
		scanf("%d",&m);
		
		for (i=0;i<m;i++){
			scanf("%d %d",&a[i],&b[i]);
		}
		
		if (n==0&&m==0){
			break;
		}
		
		for (i=2;i<=n;i++){
			if(friend(i)==1){
				x++;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 676
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール
constexpr ll pdiv = 1000000007LL;

// 処理内容
int main() {
    
    string k; cin >> k;
    ll d; cin >> d;
    
    const ll n = k.size();
    // dp[i][j][l] := i桁見てj mod dのもので、k未満が確定している(l)ものの数
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(d, vector<ll>(2, 0)));
    dp[0][0][0] = 1;
    REP(i, n) {
        ll g = k[i] - '0';
        REP(j, d) {
            REP(h, 10) {
                // 俗
                (dp[i+1][(j + h) % d][1] += dp[i][j][1]) %= pdiv;
                if (h < g) { // 還俗
                    (dp[i+1][(j + h) % d][1] += dp[i][j][0]) %= pdiv;
                } else if (h == g) { // 精進
                    (dp[i+1][(j + h) % d][0] += dp[i][j][0]) %= pdiv;
                }
            }
        }
    }

    // 0は含まない
    cout << ((dp[n][0][0] + dp[n][0][1]) % pdiv + pdiv - 1) % pdiv << endl;

    
}

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

int main(){
	int a, b; cin >> a >> b;
	if(a != 1 && b != 1) cout << 1 << endl;
	if(a != 2 && b != 2) cout << 2 << endl;
	if(a != 3 && b != 3) cout << 3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int dp[3005][3005];
int main(){
    int n,t;cin >> n >> t;
    vector<P> p(n);
    for(int i=0; i<n; i++){
        int a,b;cin >> a >> b;
        p[i]=P(a,b);
    }
    sort(p.begin(),p.end());
    int ans=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<t; j++){
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            if(j+p[i].first<t){
                dp[i+1][j+p[i].first]=max(dp[i+1][j],dp[i][j]+p[i].second);
            }
        }
        ans=max(ans,dp[i][t-1]+p[i].second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 5005;


void solve()
{
    double d, t, s; cin >> d >> t >> s;
    if (d / s <= t) cout << "Yes";
    else cout << "No";
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    /*int tc;  cin >> tc;
    while (tc--)*/
        solve();
    return 0;
}







Measured memory_bytes: 3192
// https://atcoder.jp/contests/code-festival-2016-qualc/tasks/codefestival_2016_qualC_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

using pi = pair<int, int>;
void solve() {
    int K, T;
    cin >> K >> T;
    priority_queue<pi> q;
    REP(i, T) {
        int t;
        cin >> t;
        q.push({t, i});
    }
    int before = -1, ans = 0;
    while (!q.empty()) {
        auto t = q.top();
        q.pop();
        // 直前と同じケーキの場合
        if (t.second == before) {
            if (q.size() >= 1) {
                // 2番目に大きい値を取り出し、1番目の値はqueueに戻す
                auto t2 = q.top();
                q.pop();
                q.push(t);
                t = t2;
            } else {
                ans++;
            }
        }
        before = t.second;
        if (t.first >= 2) {
            q.push({t.first - 1, t.second});
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3680
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll Abs(ll x,ll y){
    if(x>=y)return x-y;
    else return y-x;
}



int main(void){
    ll h,w;
    cin>>h>>w;
    if(h==1){
        cout<<1<<endl;
        return 0;
    }
    if(w==1){
        cout<<1<<endl;
        return 0;
    }
    if(w%2==0){
        cout<<(w/2)*h<<endl;
    }
    else{
        if(h%2==0){
            cout<<w*(h/2)<<endl;
        }
        else {
            ll x = (w+1)/2;
            ll y = w/2;
            ll z = h/2;
            cout<<(x+y)*z+x<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin >> n)
	{
		int count = 0, a, maxn = 0, maxtime = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> a;
			if(a > maxn)
			{
				count = 0;
				maxn = a;
			}
			else if(a <= maxn)
			{
				count++;
				maxn = a;
				if(count > maxtime) maxtime = count;
			}
		}
		cout << maxtime << endl;
	}
	return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define nfor(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i < int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define x first
#define y second

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

template<typename A, typename B> inline ostream& operator<< (ostream& out, const pair<A, B>& p) { return out << "(" << p.x << ", " << p.y << ")"; }
template<typename T> inline ostream& operator<< (ostream& out, const vector<T>& a) { out << "["; forn(i, sz(a)) { if (i) out << ','; out << ' ' << a[i]; } return out << " ]"; } 
template<typename T> inline ostream& operator<< (ostream& out, const set<T>& a) { return out << vector<T>(all(a)); }
template<typename X, typename Y> inline ostream& operator<< (ostream& out, const map<X, Y>& a) { return out << vector<pair<X, Y>>(all(a)); }
template<typename T> inline ostream& operator<< (ostream& out, pair<T*, int> a) { return out << vector<T>(a.x, a.x + a.y); }

inline ld gett() { return ld(clock()) / CLOCKS_PER_SEC; }

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;

#ifdef SU1
#define LOG
#endif

int k, t;
int a[1000];

bool read() {
	if (!(cin >> k >> t))
		return false;
	forn(i, t)
		assert(cin >> a[i]);
	return true;
}

void solve() {
	int prev = -1;
	int res = 0;
	forn(_, k) {
		int v = -1;
		forn(i, t) {
			if (i == prev || a[i] == 0)
				continue;
			if (v == -1 || a[i] > a[v])
				v = i;
		}
		
	//	cerr << v << endl;
		
		if (v == -1) {
			v = prev;
			res++;
		}
		
		a[v]--;
		prev = v;
	}
	
	cout << res << endl;
}

int main() {
#ifdef SU1
    assert(freopen("input.txt", "rt", stdin));
    //assert(freopen("output.txt", "wt", stdout));
#endif
    
    cout << setprecision(10) << fixed;
    cerr << setprecision(5) << fixed;

    while (read()) {
		ld stime = gett();
		solve();
		cerr << "Time: " << gett() - stime << endl;
		//break;
	}
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
int color[100010];
vector<int> G[100010];

bool dfs(int v, int c) {
  color[v] = c;
  for (int i = 0; i < G[v].size(); i++) {
    if (color[G[v][i]] == c) return false;
    if (color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
  }
  return true;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A--; B--;
    G[A].emplace_back(B);
    G[B].emplace_back(A);
  }
  if (dfs(0, 1)) {
    int a = count_if(color, color+N, [&](int x) { return x == 1; });
    cout << (ll)a*(N-a) - M << endl;
  } else {
    cout << (ll)N*(N-1)/2 - M << endl;
  }
  
  return 0;
}

Measured memory_bytes: 6528
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var N int
var ans int
var x []int
var l []int
var robots []pair

const MAX_V int = 1e9

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	n := nextInt()
	x = make([]int, n)
	l = make([]int, n)
	robots = make([]pair, n)
	for i := 0; i < n; i++ {
		x[i] = nextInt()
		l[i] = nextInt()
		robots[i].a = x[i] + l[i]
		robots[i].b = x[i] - l[i]
	}
	sort.Sort(pairs(robots))
	// for i := 0; i < n; i++ {
	// 	log.Println(robots[i])
	// }
	var cur int = -MAX_V
	var ans int = 0
	for i := 0; i < n; i++ {
		if cur <= robots[i].b {
			ans++
			cur = robots[i].a
		}
	}
	fmt.Println(ans)
}

func cntbool(bs []bool) int {
	cnt := 0
	for i := 0; i < len(bs); i++ {
		if bs[i] == true {
			cnt++
		}
	}
	return cnt
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 99999999999999
#define MAX_V 100010
#define MAX_E 2019

    /*Solve*/

int main(){
    int N,T;
    cin >> N >> T;
    priority_queue<int,vector<int>,greater<int>> x;
    int c,t;
    
    rep(i,N){
        cin >> c >> t;
        if(t<=T){
            x.push(c);
        }
    }
    if(x.size()==0)cout << "TLE";
    else cout << x.top();
}

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

int main(){
  
  string s;
  map<char , int> m ;
  cin >> s;
  for(int i=0; i<s.length(); i++){
    if(m[s[i]] == 1 ){
      cout << "no" << endl;
      return 0 ;
    }
    m[s[i]] = 1;
  }
  cout << "yes" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

H,W,M = map(int, input().split())
BH = [0 for i in range(H)]
BW = [0 for i in range(W)]
Bomb = set()
for _ in range(M):
  h,w = map(int, input().split())
  h,w = h-1,w-1
  BH[h] += 1
  BW[w] += 1
  Bomb.add((h,w))
  
BHMAX = max(BH)
BWMAX = max(BW)
HS = set()
WS = set()
for i in range(H):
  if BH[i] == BHMAX:
    HS.add(i)
for i in range(W):
  if BW[i] == BWMAX:
    WS.add(i)
    
ans = 0
cnt = 0
for h,w in Bomb:
  if h in HS and w in WS:
    ans = max(ans, BHMAX + BWMAX - 1)
    cnt += 1

if cnt < len(HS) * len(WS):
  ans = BHMAX + BWMAX
print(ans)

Measured memory_bytes: 102000
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10][10];

int main()
{
	long long money, n, t;
	cin >> n;
	money = n * 800;
	t = n / 15;
	money -= t * 200;
	cout << money;
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> edge[N];
  rep (i, M) {
    int L, R, D;
    cin >> L >> R >> D;
    edge[L - 1].eb(mp(R - 1, D));
    edge[R - 1].eb(mp(L - 1, D * -1));
  }

  int dist[N];
  rep (i, N) dist[i] = INF;

  rep (i, N) {
    if (dist[i] != INF) continue;
    dist[i] = 0;

    queue<int> Q;
    Q.push(i);

    while (!Q.empty()) {
      int cur = Q.front();
      Q.pop();

      rep (i, sz(edge[cur])) {
        int next = edge[cur][i].F;
        int d = edge[cur][i].S;

        if (dist[next] == INF) {
          dist[next] = dist[cur] + d;
          Q.push(next);
        } else if (dist[next] != dist[cur] + d) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 9344
import numpy as np
h, w = map(int, input().split())
m = np.array([list(map(int, input().split())) for i in range(h)])

r = True
act = list()
for i in range(1, h+1):
  r = not r
  for j in sorted(range(1, w+1), reverse=r):
    if m[i-1, j-1] % 2 == 1:
      if not r:
        # 下に進む
        if j == w:
          if i == h:
            break
          m[i, j-1] += 1
          act.append((i, j, i+1, j))
        # 右に進む
        else:
          m[i-1, j] += 1
          act.append((i, j, i, j+1))
      else:
        # 下に進む
        if j == 1:
          if i == h:
            break
          m[i, j-1] += 1
          act.append((i, j, i+1, j))
        # 左に進む
        else:
          m[i-1, j-2] += 1
          act.append((i, j, i, j-1))
    #print(m[i, j], i, j, r, m[next_i, next_j])
    
print(len(act))
[print(*x) for x in act]  
#print(m)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll x;
    cin >> x;
    int res = 0;
    res += (x / 500) * 1000;
    x -= (x / 500) * 500;
    res += (x / 5) * 5;
    cout << res << endl;
    
    return 0;
}



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

int main() {
  double n;
  cin >> n;
  
  double base = n/1.08;
  double amari = base - double(int(base));
  
  if (amari == 0.0) {
    cout << int(base) << endl;
  } else if (int(base)*1.08 >= n && int(base)*1.08 < (n+1)) {
    cout << int(base) << endl;
  } else if (int(base+1)*1.08 >= n && int(base+1)*1.08 < (n+1)) {
    cout << int(base+1) << endl;
  } else {
    cout << ":(" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
[n,m] = [int(x) for x in input().split()]
hight_list = [int(x) for x in input().split()]
road_list = [[int(x) for x in input().split()] for _ in range(m)]

# 展望台の接続を辞書で整理する
## 辞書の初期化
temp_dic = {}
for x in range(1,n+1):
    temp_dic[x] = []

for a,b in road_list:
    temp_dic[a].append(hight_list[b-1])
    temp_dic[b].append(hight_list[a-1])

good_points = 0
for k,v in temp_dic.items():
    if len(v) == 0:
        good_points += 1
        continue

    if hight_list[k-1] > max(v):
        good_points += 1

print(good_points)


Measured memory_bytes: 48148
// https://atcoder.jp/contests/abl/tasks/abl_e
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using mint = atcoder::modint998244353;
struct S {
    mint val, unit;
};
using F = int;
const F ID = -1;

// 区間に対する演算方法
S op(S a, S b) { return {a.val + b.val, a.unit + b.unit}; }
// 単位元 a⋅e = e⋅a = a
S e() { return {0, 0}; }
// f(x) を返す関数
S mapping(F f, S x) {
    if (f != ID)
        x.val = f * x.unit;
    return x;
}
// f∘g を返す関数
F composition(F f, F g) { return (f == ID ? g : f); }
// id を返す関数
F id() { return ID; }

void solve() {
    int N, Q;
    cin >> N >> Q;
    vector<S> init(N);
    mint pow10 = 1;
    for (int i = N - 1; i >= 0; i--) {
        init[i] = {pow10, pow10};
        pow10 *= 10;
    }
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(init);
    while (Q--) {
        int l, r, d;
        cin >> l >> r >> d;
        seg.apply(l - 1, r, d);
        cout << seg.all_prod().val.val() << "\n";
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

using namespace std;
typedef long long ll;
const int maxn=1005;

int main()
{
    int a, b;
    while(cin>>a>>b){
        int ans = max(a*2-1, b*2-1);
        ans = max(ans, a+b);
        cout<<ans<<endl;
    }
    return 0;
}


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

#define MAX_N 300

using namespace std;

typedef long long ll;

int N, K;
vector<ll> H;

ll solve() {
  vector<vector<ll>> dp(N, vector<ll>(N + 1, 1e11));

  for (int i = 0; i < N; ++i) {
    dp[i][1] = H[i];
  }

  for (int i = 1; i < N; ++i) {
    for (int j = 1; j <= i + 1; ++j) {
      for (int k = 0; k < i; ++k) {
        dp[i][j] = min(dp[i][j], dp[k][j - 1] + max(0ll, H[i] - H[k]));
      }
    }
  }

  ll result = 1e11;

  for (int i = 0; i < N; ++i) {
    result = min(result, dp[i][N - K]);
    // cout << dp[i][N - K] << " ";
  }
  // cout << endl;

  return result == 1e11 ? 0 : result;
}

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

  H = vector<ll>(N);

  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }

  cout << solve() << endl;

  return 0;
}

Measured memory_bytes: 896
N = int(input())

A = [None] * N
B = [None] * N
C = [None] * N

for n in range(N):
    a, b = map(int, input().split())
    A[n] = a
    B[n] = b
    C[n] = a + b

Z = zip(A, B, C)
Z = sorted(Z, key=lambda x: [x[2]], reverse=True)

A, B, C = map(list, zip(*Z))

T = True
R = 0

for i in range(N):
    if T:
        R += A[i]
        T  = False
    else:
        R -= B[i]
        T  = True

print(R)


Measured memory_bytes: 33936
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define mod 1000000007
#define int long long

int f[66];

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int n; cin >> n;
        vector<int> v(n);
        lp(i, n) {
                cin >> v[i];
                for (int j = 0; j < 60; j++) {
                        if (v[i] & 1ll<<j) f[j]++;
                }
        }
        int an = 0;
        for (int i = n - 1; i > 0; i--) {
                for (int j = 0; j < 60; j++) {
                        if (v[i] & 1ll<<j) f[j]--;
                }
                for (int j = 0; j < 60; j++) {
                        if (v[i] & 1ll<<j) {
                                an += ( (i-f[j])% mod * ((1ll<<j)% mod) ) % mod;
                        } else an += ( (f[j])% mod * ((1ll<<j)% mod) ) % mod;
                        an %= mod;
                }
                an %= mod;
        }
        cout << an%mod;
return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#define ll long long
using namespace std;
const double PI=3.14159265;
double todeg(double rad){
    return rad/PI*180.0;
}
int main(){
    double a,b,x;
    cin>>a>>b>>x;
    if(2*x<=a*a*b){
        cout<<fixed<<setprecision(10)<<90.0-todeg(atan(2*x/a/b/b));
    }else{
        cout<<fixed<<setprecision(10)<<todeg(atan(2*(b/a-x/a/a/a)));
    }    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = [int(x) for x in input().split()]
maxd, temp = 0, 0
for i in range(n-1, 0, -1):
    if h[i-1] >= h[i]:
        temp += 1
        maxd = max(maxd, temp)
    else:
        temp += 0
        maxd = max(maxd, temp)
        temp = 0
print(maxd)

Measured memory_bytes: 14224
import heapq 
N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K) #KがNより大きい場合を防ぐ
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        A1 = A[:i] #前から取る
        A3 = A[N-j:] #後ろから取る
        new_A = A1+A3
        new_A.sort(reverse=True)
        h = K - len(new_A)
        while h >0 and new_A:
            if new_A[-1] > 0:
                break
            else:
                new_A.pop()
                h-=1
        M = max(M,sum(new_A))
print(M)

Measured memory_bytes: 3064
# D - RGB Triplets
	
N = int(input())
S = input()
	
r, g, b = 0, 0, 0
	
for s in S:
	if s == 'R':
		r += 1
	elif s == 'G':
		g += 1
	else:
		b += 1
	
ans = r * g * b
	
for i in range(N - 2):
	for j in range(i + 1, N - 1):
		k = j * 2 - i
			
		if k < N:
			if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
				if j -i == k -j:
					ans -= 1
	
print(ans)

Measured memory_bytes: 68364