akhauriyash/Code-Regression huggingface dataset:
X = int(input())
for A in range(10000):
    if abs((abs(A**5-X))**0.2 - int(abs(A**5-X)**0.2)) < 0.0000001:
        B = int(abs(A**5-X)**0.2)
        if A**5 - B**5 == X:
            print(A, " ", B)
            break
        else:
            print(A, " ", -1*B)
            break

Measured memory_bytes: 9388
let n = Scanf.scanf " %d" (+) 0
let ds = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref 0
let _ = Array.iteri (fun i d -> for j = i + 1 to n - 1 do ans := !ans + d * ds.(j) done) ds; Printf.printf "%d\n" !ans

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int A, B, K; cin >> A >> B >> K;
	for (int _ = 0; _ < K; _++) {
		if (_ % 2 == 0) {
			if (A % 2 == 1)A--;
			A /= 2;
			B += A;
		}
		else {
			if (B % 2 == 1)B--;
			B /= 2;
			A += B;
		}

	}
	cout << A << " " << B << endl;




	



	return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int a[3][3];
  cin >> a[0][0] >> a[0][1] >> a[1][1];
  a[0][2] = 3 * a[1][1] - a[0][0] - a[0][1];
  a[1][0] = 4 * a[1][1] - 2 * a[0][0] - a[0][1];
  a[1][2] = 2 * a[0][0] + a[0][1] - 2 * a[1][1];
  a[2][0] = a[0][0] + a[0][1] - a[1][1];
  a[2][1] = 2 * a[1][1] - a[0][1];
  a[2][2] = 2 * a[1][1] - a[0][0];
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cout << a[i][j] << (j < 2 ? " " : "\n");
    }
  }
}


Measured memory_bytes: 384
n, k = map(int, input().split())
x = list(map(int, input().split()))

if x[0] >= 0:
    print(x[k - 1])
    exit()
elif x[n - 1] < 0:
    print(abs(x[n - k]))
    exit()
else:
    for i in range(n):
        if x[i] >= 0:
            ori = i
            break

f_inf = float("inf")
res = f_inf
for i in range(max(ori - k, 0), min(ori + k, n) - k + 1):
    time = min(abs(x[i + k - 1] - x[i]) + abs(x[i + k - 1]), abs(x[i]) + abs(x[i + k - 1] - x[i]))
    res = min(res, time)

print(res)


Measured memory_bytes: 14532
#include <bits/stdc++.h>
#include <cstdlib>
#define ll long long
#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define MX 100010
using namespace std;

int a,b,c;
string ans;
int main(){
        cin >> a >> b >> c;
        if(max(a,max(b,c)) != c && min(a,min(b,c)) !=c) ans="Yes";
        else ans="No";
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
import numpy as np
import functools
import math
import scipy
import fractions
import itertools
 
def solve():
    k, t = map(int, input().split())
    a = list(map(int, input().split()))
    print(max(0, max(a)-(sum(a)-max(a))-1))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 13508
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 型
#define ll long long

// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// for文
#define forn(i, size) for (long long(i) = 0; (i) < (size); (i)++)
#define for0(size) for (long(i) = 0; (i) < (size); (i)++)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length, type_name) sort(array, array + length, std::greater<type_name>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion

#pragma region 連想配列のkeyが存在するか
template <typename T>
bool containsKey(map<string, T> map, string key)
{
    if (map.count(key) == 0)
    {
        return false;
    }
    return true;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    string S;
    cin >> S;

    int i = 0;
    int max_len = 0;
    forn (i, S.size())
    {
        for (int j = 1; j < S.size() - i + 1; j++)
        {
            // 部分文字列を取得
            string temp = S.substr(i, j);

            // ACGT 文字列か判定
            for (int k = 0; k < temp.size(); k++)
            {
                if (temp[k] == 'A' || temp[k] == 'C' || temp[k] == 'G' || temp[k] == 'T')
                {
                    if (k == temp.size() - 1)
                    {
                        max_len = max(max_len, k + 1);
                    }
                }
                else
                {
                    break;
                }
            }
        }
    }

    // 結果出力
    cout << max_len << endl;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <cstdio>
#include<algorithm>
#include <utility>
#include<string>
using namespace std;
int main() {
	int  count=0,w, weight[10] = { 512,256,128,64,32,16,8,4,2,1 };
	bool bo[10] = { false };
	while (cin >> w) {
		for (int i = 0; i < 10; i++) {
			if (w == 0) {
				break;
			}
			if (w >= weight[i]) {
				w -= weight[i];
				count++;
				bo[i] = true;
			}
		}
		for (int i = 9; i >= 0; i--) {
			if (bo[i] && count == 1) {
				cout << weight[i] << endl;
				bo[i] = false;
				count = 0;
			}
			else if (bo[i]) {
				count--;
				cout << weight[i] << " ";
				bo[i] = false;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2984
def solve():
    N, M = map(int, input().split())
    INF = 10 ** 9
    
    dp = [INF] * (2 ** N)
    dp[0] = 0
    for _ in range(M):
        a, b = map(int, input().split())
        c = list(map(lambda x: int(x) - 1, input().split()))
        open = 0
        for i in range(b):
            open += 1 << c[i]
        for i in range(2 ** N):
            if dp[i] + a <= dp[i | open]:
                dp[i | open] = dp[i] + a
    
    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3188
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var lines = input.split('\n');

var line;
while (line = lines.shift()) {
    var nums = line.split(' ');
    var n = +nums[0];
    var r = +nums[1];
    if (n + r == 0) break;

    var deck = [];
    for (var i = n; i > 0; i--) {
        deck.push(i);
    } 

    for (var i = 0; i < r; i++) {
        d = lines.shift().split(' ').map(function(n){return +n;});
        var p = d[0];
        var c = d[1];

        var top = deck.splice(p - 1, c);
        for (var j = 0; j < c; j++) {
            deck.unshift(top.pop());
        }
    }
        console.log(deck[0]);
}

Measured memory_bytes: 10868
<?php
fscanf(STDIN, "%s", $C1);
fscanf(STDIN, "%s", $C2);

$flg = true;
for ($i = 0; $i < 3; $i++) {
    if ($C1[$i] !== $C2[2-$i]) $flg = false;
}

echo $flg ? "YES" . "\n" : "NO" . "\n";


Measured memory_bytes: 4604
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long LL;
const int mod = 1000000009;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    LL r, d, x;
    while (cin >> r >> d >> x)
    {
        int i = 10;
        while (i--)
        {
            x = r * x - d;
            cout << x << '\n';
           
        }
        
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){


    string s,t;
    cin>>s;
    cin>>t;

 if(s.substr(0,s.size())== t.substr(0,t.size()-1)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }






}


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

int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.length();i++){
    	sum=(sum+(s[i]-'0'))%9;
	}
	if(sum==0)cout<<"Yes";
	else cout<<"No";

return 0;
}


Measured memory_bytes: 3768
a,b,c,d=list(map(int,input()))

for i in range(7):  
  if i==0 and a+b+c+d==7:
    print('%d+%d+%d+%d=7' %(a,b,c,d))
    exit()
  elif i==1 and a+b+c-d==7:
    print('%d+%d+%d-%d=7' %(a,b,c,d))
    exit()
  elif i==2 and a+b-c+d==7:
    print('%d+%d-%d+%d=7' %(a,b,c,d))
    exit()
  elif i==3 and a+b-c-d==7:
    print('%d+%d-%d-%d=7' %(a,b,c,d))
    exit()
  elif i==4 and a-b+c+d==7:
    print('%d-%d+%d+%d=7' %(a,b,c,d))
    exit()
  elif i==5 and a-b+c-d==7:
    print('%d-%d+%d-%d=7' %(a,b,c,d))
    exit()
  elif i==6 and a-b-c+d==7:
    print('%d-%d-%d+%d=7' %(a,b,c,d))
    exit()
  elif i==7 and a-b-c-d==7:
    print('%d-%d-%d-%d=7' %(a,b,c,d))
    exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue;
#define um unordered_map<ll,ll>
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
int main()
{
    ios;
    ll a , b ;
    cin >> a >>  b ;
    cout << (a*  b - (a+b-1)) << el;

}


























Measured memory_bytes: 256
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
typedef long long Long;

const int N = 1003;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  m2 += 60 * h2;
  m1 += 60 * h1;
  cout << m2 - m1 - k << endl;

  return 0;
}

Measured memory_bytes: 3692
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#define P pair<float, pair<int,int> >
#define sqr(x) ((x) * (x))

using namespace std;

int parent[100],rank[100];

int findset(int x){
  if(x!=parent[x]) parent[x] = findset(parent[x]);
  return parent[x];
}

void link(int x,int y){
  if(rank[x]>rank[y])
    parent[y]=x;
  else{
    parent[x]=y;
    if(rank[x]==rank[y]) rank[y]++;
  }
}

void merge(int x,int y){
  link(findset(x),findset(y));
}

bool sameset(int x,int y){
  return findset(x)==findset(y);
}

float x[100],y[100],z[100],r[100];
vector<P> tako;

int main(){
  int n;
  while(scanf("%d",&n),n){
    tako.clear();
    for(int i=0; i<n; i++){
      double xx,yy,zz,rr;
      scanf("%lf %lf %lf %lf",&xx,&yy,&zz,&rr);
      x[i]=xx; y[i]=yy; z[i]=zz; r[i]=rr;

      parent[i]=i; rank[i]=0;
    }

    for(int i=0; i<n-1; i++) for(int j=i+1; j<n; j++){
      double dist = sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j])+sqr(z[i]-z[j]))-r[i]-r[j];
      //      printf("dist: %f, x: %d, y: %d\n",dist,i,j);
      dist = dist>0?dist:0;
      tako.push_back(make_pair(dist,make_pair(i,j)));
    }
    sort(tako.begin(),tako.end());

    double ans=0;
    for(int i=0; i<tako.size(); i++){
      double dist = tako[i].first;
      int x=tako[i].second.first, y=tako[i].second.second;
      if(sameset(x,y)) continue;
      ans+=dist;
      merge(x,y);
    }

    printf("%.3f\n",ans);
  }
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line[] = br.readLine().split(" ");
        int h = Integer.parseInt(line[0]);
        int w = Integer.parseInt(line[1]);
        char[][] picture = new char[h+2][w+2];
        
        for (int i = 1; i <= h; i++) {
            String row = br.readLine();
            for (int j = 1; j <= w; j++) {
                picture[i][j] = row.charAt(j-1);
            }
        }
        
        String ans = "Yes";
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (picture[i][j] == '#') {
                    if (picture[i][j-1] != '#' && picture[i][j+1] != '#' && picture[i-1][j] != '#' && picture[i+1][j] != '#') {
                        ans = "No";
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}


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

#define  int        long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n;
    cin>>n;
    if(n>=1800) cout<<"1";
    else  if(n>=1800) cout<<"1";
    else  if(n>=1600) cout<<"2";
    else  if(n>=1400) cout<<"3";
    else  if(n>=1200) cout<<"4";
    else  if(n>=1000) cout<<"5";
    else  if(n>=800) cout<<"6";
    else  if(n>=600) cout<<"7";
    else  if(n>=400) cout<<"8";
}

Measured memory_bytes: 3648
n = int(input())
li = list(map(int,input().split()))
ans = 0
for i in range(n):
    if i > 0:
        if  li[i-1] > li[i]:
            ans += li[i-1]-li[i]
            li[i] += (li[i-1]-li[i])

print(ans)


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

int main() {
  int N;
  string C;
  int counterY;
  cin >> N;
  
  for ( int i=0; i < N; i++) {
    cin >> C;
    if ( C == "Y") {
      counterY++;
    }
  }
  if (counterY != 0) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s; cin >> s;
    set<int> nums;
    for(int i = 2; i <= 1e8; i++){
        nums.insert(s);
        s = s & 1 ? s * 3 + 1 : s / 2;
        if(nums.count(s)){
            cout << i << '\n';
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    
    
    

    int a,b;
    cin>>a>>b;
    a--;b--;
    cout<<a*b<<endl;


    
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n, k; cin >> n >> k;
  vector<int> l(n); rep(i, n) cin >> l[i];
  sort(l);

  ll sum = 0;
  for (int i = 0; i < k; i++) {
    sum += l[n - 1 - i];
  }
  outl(sum);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int W, H;
char grid[52][52];
int min_cost[52][52];
 
int bfs(int sx, int sy, int gx, int gy)
{
    const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};
    memset(min_cost, -1, sizeof(min_cost));
    
    queue<P> Q;
    Q.emplace(sx, sy);
    min_cost[sx][sy] = 0;
    
    while(!Q.empty()) {
        auto p = Q.front(); Q.pop();
        REP(i, 4) {
            int nx = p.first + vx[i], ny = p.second + vy[i];
            if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;    // 場外
            if(min_cost[nx][ny] != -1) continue;    // コスト確定済
            if(grid[ny][nx] == '#') continue;       // 壁
            // cout << nx << " " << ny << "\n";
            min_cost[nx][ny] = min_cost[p.first][p.second] + 1;
            if(nx == gx && ny == gy) return min_cost[gx][gy];
            Q.emplace(nx, ny);
        }
    }
    return -1;
}

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

    cin >> H >> W;
    int white = 0;
    REP(i, H)REP(j, W){
        cin >> grid[i][j];
        if(grid[i][j] == '.') white++;
    }
    int route = bfs(0, 0, W-1, H-1);
    if(route == -1) puts("-1");
    else cout << white - route - 1<< "\n";
    
    return 0;
}

Measured memory_bytes: 256
N,M= map(int,input().split())
A = [int(i) for i in input().split()]
BC = []
for i in range(M):
    BC.append(list(map(int,input().split())))

A.sort()
BC.sort(key = lambda x:-x[1])

s = 0
for b,c in BC:
    s_tmp = 0
    for i in range(s,N):
        if A[i] < c and b > 0:
            A[i] = c
            b -= 1
            s_tmp = i + 1
        elif A[i] >= c:
            print(sum(A))
            exit()
        elif b == 0:
            s = s_tmp
            break

print(sum(A))

Measured memory_bytes: 36088
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, X, Y;
int d[20202];

int dist(int a, int b) {
    if (a > b)
        swap(a, b);
    return min({b - a, abs(a - X) + 1 + abs(b - Y)});
}

void solve() {
    FOR(i, 0, N) {
        FOR(j, i + 1, N) {
            d[dist(i, j)]++;
        }
    }


    FOR(k, 1, N) {
        cout << d[k] << endl;
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> X >> Y;
    X--;
    Y--;


    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;



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

    vector<vector<int>> a(n);

    rep(i,n){
        rep(j,d){
            int x; cin >> x;
            a[i].push_back(x);
        }
    }

    int ans = 0;

    rep(i,n-1){
        rep(j,i+1,n){
            int muld = 0;
            rep(k,d){
                int di = abs(a[i][k] - a[j][k]);
                di *= di;

                muld += di;
            }

            for(int k = 1; k*k <= muld ; k++){
                int c = k*k;
                if(muld == c) ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
INF = float("inf")

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]


def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 45020
#include<cstdio>
#include<iostream>
#define INF 1e+8

using namespace std;

int main(){
    int n,t;
    int h[500],m[500];
    cin>>n;
    for(int i=0;i<n;i++)cin>>h[i]>>m[i];
    cin>>t;
    for(int i=n;i<n+t;i++)cin>>h[i]>>m[i];
    //for(int i=0;i<n+t;i++)cout<<h[i]<<m[i]<<endl;
    for(int i=0;i<n+t-1;i++){
        for(int j=i+1;j<n+t;j++){
            if(h[i]>h[j]){
                int temp=h[i];
                h[i]=h[j];
                h[j]=temp;
                temp=m[i];
                m[i]=m[j];
                m[j]=temp;
            }
            if(h[i]==h[j]&&m[i]>m[j]){
                int temp=h[i];
                h[i]=h[j];
                h[j]=temp;
                temp=m[i];
                m[i]=m[j];
                m[j]=temp;
            }
        }
    }
    for(int i=0;i<n+t;i++){
        if(i!=n+t-1&&h[i]==h[i+1]&&m[i]==m[i+1])continue;
        m[i]<10?cout<<h[i]<<":0"<<m[i]:cout<<h[i]<<":"<<m[i];
        if(i==(n+t-1))puts("");
        else cout<<" ";
    }
    return 0;
}

Measured memory_bytes: 1164
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
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; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 



using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
struct Edge{ll to,dist;};
ll N; ll d[100000];
vector<Edge> G[100000];

void dijkstra(ll u){
    REP(i,100000)d[i]=INF;
    priority_queue<P,vector<P>,greater<P>> que;
    que.push({0,u});
    while(!que.empty()){
        auto r=que.top();que.pop();
        if(r.first>=d[r.second])continue;//更新不可
        d[r.second]=r.first;//更新

        for(Edge& e: G[r.second]){
            ll dist=d[r.second]+e.dist;
            if(dist>=d[e.to])continue;//更新不可
            que.push({dist,e.to});//更新
        }
    }
}
int main(void){
    ll N;cin>>N;
    ll a,b,c;
    REP(i,N-1){
        cin>>a>>b>>c;
        a--,b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    ll Q,K;cin>>Q>>K;
    K--;
    dijkstra(K);
    ll x[Q],y[Q];
    REP(i,Q){
        cin>>x[i]>>y[i];
    }
    REP(i,Q){
        x[i]--,y[i]--;
        cout<<d[x[i]]+d[y[i]]<<"\n";
    }
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    ll now = 1;
    for(int i = 0; i < n; i++) {
        // cout << "---" << endl;
        // cout << now << ' ' << ans << endl;
        // for(auto j : a) {
        //     cout << j << ' ';
        // }
        // cout << endl;
        if(a[i] == now) {
            now++;
        } else if(a[i] % now == 0) {
            ans += (a[i] - 1) / now;
            if(now == 1) {
                a[i] = 1;
                now++;
            } else {
                a[i] = now - 1;
            }
        } else {
            ll num = (a[i] - 1) / now;
            ans += num;
            a[i] -= now * num;
            if(a[i] >= now) {
                now = a[i] + 1;
            }
        }
    }
    // cout << "---" << endl;
    // cout << now << ' ' << ans << endl;
    // for(auto j : a) {
    //     cout << j << ' ';
    // }
    // cout << endl;
    cout << ans << endl;
}

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

using namespace std;

#define ll long long


int main(){
    int a,b,c,d;
    cin >> a;
    int mx = 1;
    for(int i=2; i*i<=a; i++)
    {
        int val = i;
        while(val*i<=a)
        {
            val*=i;
        }
        mx = max(mx,val);

    }
    cout << mx << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int,int>;
constexpr int INF = 1e9+7;
priority_queue<P, vector<P>, greater<P>> qu;
int ds[200005], H, W, a, b;
set<P> lv;
int main(){
	scanf("%d%d", &H, &W);
	rep(i,W){
		lv.emplace(i,i);
		qu.emplace(0,i);
	}
	rep(i,H){
		scanf("%d%d", &a, &b);
		auto tl = lv.lower_bound({a-1,0}), el = lv.lower_bound({b,0});
		if(tl != el){
			for(el--; tl != el; tl = lv.erase(tl)) ds[tl->second] = INF;
			auto[to, from] = *el;
			el = lv.erase(el);
			if(b != W){
				ds[from] = b - from;
				lv.emplace_hint(el, b, from);
				qu.emplace(b-from, from);
			}else ds[from] = INF;
		}
		while(!qu.empty()){
			auto [d, from] = qu.top();
			if(ds[from] != d) qu.pop();
			else break;
		}
		printf("%d\n", qu.empty() ? -1 : qu.top().first+i+1);
	}
}

Measured memory_bytes: 15256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    i64 n, k;
    cin >> n >> k;
    i64 ans = min(n % k, -(n % k - k));
    cout << ans << endl;
    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int di2[] = {1, 1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
const int dj2[] = {1, -1, 1, -1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};



int main()
{
  int n, x, t; cin >> n >> x >> t;
  cout << (int)ceil((double)n/x) * t << endl; 
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void) {
    long long X;
    scanf("%lld", &X);
    long long sum = 0;
    long long time = 0;
    // add unless exceed
    while (sum < X) {
        sum += (time++) + 1;
    }
    printf("%lld\n", time);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll k, n;
    cin >> k >> n;
    vector<ll> a(n), b(n-1);
    rep(i, n)cin >> a[i];
    REP(i, n-1)b[i-1] = a[i]-a[i-1];
    ll ans = accumulate(all(b), 0LL)-*max_element(all(b))+(k-a[n-1]+a[0]);
    cout << min(accumulate(all(b), 0LL), ans) << endl;
}      

Measured memory_bytes: 3328
import java.util.Arrays;
import java.util.Scanner;

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

        int N = sc.nextInt();
        long[] T = new long[N];
        for (int i = 0; i < T.length; ++i) {
            T[i] = sc.nextLong();
        }

        System.out.println(solve(T));

        sc.close();
    }

    static long solve(long[] T) {
        return Arrays.stream(T).reduce(Main::lcm).getAsLong();
    }

    static long lcm(long x, long y) {
        return x / gcd(x, y) * y;
    }

    static long gcd(long x, long y) {
        return (y == 0) ? x : gcd(y, x % y);
    }
}

Measured memory_bytes: 32644
N, M = map(int, input().split())
query = [list(input().split()) for _ in range(M)]
ans = -1
for num in range(10**N):
    if len(str(num)) != N:
        continue
    else:
        cnt = 0
        s = str(num)
        for sc in query:
            if s[int(sc[0])-1] == sc[1]:
                cnt += 1
        if cnt == M:
            ans = num
            break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll N,K;
        cin>>N>>K;
        ll a,b;
        b=0;
        a=N/K;
        if(K%2!=1)b=N*2/K-a;
        cout<<a*a*a+b*b*b<<endl;
    }

Measured memory_bytes: 256
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, S = iim()
    A = list(iim())
    mod = 998244353
    S1 = S + 1

    dp = [0] * (S+1)

    dp[0] = pow(2, N, mod)
    inv = pow(2, mod-2, mod)

    for ai in A:
        for i in range(S, ai-1, -1):
            dp[i] = (dp[i] + dp[i-ai]*inv) % mod

    print(dp[-1])


if __name__ == "__main__":
    resolve()


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int a, b;
  cin >> a >> b;

  int cnt = 0;
  fo(i, a, b+1) {
    if(i / 10000 == i % 10 && i / 1000 % 10 == i % 100 / 10) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int n = nextInt();
			if (n == 0) {
				break;
			}

			int m = nextInt();
			int a = nextInt();

			ArrayList<Edge> edges = new ArrayList<Edge>();
			for (int i = 0; i < m; i++) {
				int h = nextInt();
				int p = nextInt();
				int q = nextInt();
				edges.add(new Edge(h, p, q));
			}
			Collections.sort(edges);

			for (Edge edge : edges) {
				if (edge.p == a) {
					a = edge.q;
				} else if (edge.q == a) {
					a = edge.p;
				}
			}

			System.out.println(a);

		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

class Edge implements Comparable<Edge> {
	int height, p, q;

	Edge(int h, int p, int q) {
		this.height = h;
		this.p = p;
		this.q = q;
	}

	@Override
	public int compareTo(Edge o) {
		return o.height - this.height;
	}
}

Measured memory_bytes: 35888
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
a, b = map(int, input().split())
n = gcd(a, b)
primes = []
MAX = 10 ** 6 + 10
is_prime = [False] * 2 + [True] * (MAX - 2)
for i in range(2, MAX):
    if is_prime[i]:
        primes.append(i)
        for j in range(i * i, MAX, i):
            is_prime[j] = False
cnt = 1
for p in primes:
    if n % p == 0:
        cnt += 1
        while n % p == 0:
            n /= p
if n != 1:
    cnt += 1
print(cnt)

Measured memory_bytes: 24708
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map (fun x -> int x)

let a, b = readIntArray() |> fun x -> (x.[0], x.[1])


if a + b >= 10 then "error" else (a + b).ToString()
|> printfn "%s"

Measured memory_bytes: 14044
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] f1 = new int[n];
		int[] f2 = new int[n];
		for (int i = 0; i < n; i++) {
			f1[i] = sc.nextInt();
		}
		for (int i = 0; i < n; i++) {
			f2[i] = sc.nextInt();
		}
		Arrays.parallelPrefix(f1, Integer::sum);
		Arrays.parallelPrefix(f2, Integer::sum);
		int[] nums = new int[n];
		int a = f1[0];
		a += f2[n-1];
		nums[0] = a;
		for(int i = 1; i < n; i++) {
			int profit = f1[i];
			profit += (-f2[i-1] + f2[n-1]);
			nums[i] = profit;
		}
		System.out.println(Arrays.stream(nums).max().getAsInt());
	}
}

Measured memory_bytes: 29140
#include<iostream>
#include<string>

using namespace std;

int main(){
	int n,l1,l2,i;
	string a, b;
	char ans[80];
	int ia,ib,sum;
	cin>>n;
	while(n--){
		cin>>a>>b;
		if(a.length()>80 || b.length()>80){
			cout<<"overflow"<<endl;
			continue;
		}
		if(a.length()==80 || b.length()==80){
			if((int)a[0]-'0'+(int)b[0]-'0'>9){
				cout<<"overflow"<<endl;
				continue;
			}
		}
		if(a.length()<b.length()){
			swap(a,b);
		}
		l1=a.length();
		l2=b.length();
		for(i=0;i<80;i++)ans[i]=0;
		for(i=1;i<l2+1;i++){
			ia=(int)a[l1-i]-(int)'0';
			ib=(int)b[l2-i]-(int)'0';
			sum=ia+ib;
			ans[80-i]+=sum+'0';
		}
		for(i=l2+1;i<l1+1;i++){
			ans[80-i]=a[l1-i];
		}
		for(i=79;i>=0;i--){
			if(ans[i]-'0'>9 && ans[i]!=0){
				ans[i]=ans[i]-10;
				if(ans[i-1]==0)ans[i-1]+=1+'0';
				else ans[i-1]+=1;
			}
		}
		for(i=0;i<80;i++){
			if(ans[i]!=0){
				cout<<(int)ans[i]-'0';
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll ans=0;
    string str1,str2;
    cin>>str1>>str2;
    for(ll i=0;i<str1.length();i++){
        if(str1[i]!=str2[i])
            ans+=1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3784
# https://atcoder.jp/contests/abc160/tasks/abc160_c

K, N = gets.split.map(&:to_i)
As = gets.split.map(&:to_i)

ans = As.each_cons(2).reduce(0) { |memo, (a1, a2)| [memo, a2 - a1].max }
ans = [ans, As.first + (K - As.last)].max
puts K - ans


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(a - x) < abs(b - x)) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
  return 0;
}


Measured memory_bytes: 256