akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main(){
	ll n, k;
	cin >> n >> k;
	ll x = n%k;
	ll y = abs(x-k);
  	cout << min(x,y) << endl; 
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

using namespace std;

int main()
{
    int a, b ,c;
    cin >> a >> b;

    int p = a * b * 1;
    int q = a * b * 3;
    //c = a * b * 2;
    if(p % 2 == 1 and q % 2 == 1)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
/* Filename: ARC084C.java
 * Author: Mushiyo
 */

import java.util.Scanner;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			int N = input.nextInt();
			int[] A = new int[N];
			int[] B = new int[N];
			int[] C = new int[N];
			
			for(int i = 0; i < A.length; ++i){
				A[i] = input.nextInt();
			}
			
			for(int i = 0; i < B.length; ++i){
				B[i] = input.nextInt();
			}
			
			for(int i = 0; i < C.length; ++i){
				C[i] = input.nextInt();
			}
			
			Arrays.sort(A);
			Arrays.sort(B);
			Arrays.sort(C);
			
			long[] CLargerB = new long[N];
			for(int b = 0 , c = 0; b < B.length; ++b){
				while(c < C.length && C[c] <= B[b]){
					++c;
				}
				
				CLargerB[b] = C.length - c;
			}
			
			for(int i = C.length - 1; i > 0; --i){
				CLargerB[i - 1] += CLargerB[i];
			}
			
			long ways = 0;
			for(int a = 0, b = 0; a < A.length; ++a){
				while(b < B.length && B[b] <= A[a]){
					++b;
				}
				
				if(b < B.length){
					ways += CLargerB[b];
				}
			}
			
			System.out.println(ways);
		}
	}

}


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

const ll INF = 1000000000000000000;

int main()
{
    ll a;
    long double b;
    cin >> a >> b;
    long double k = a * b;
    ll ans;
    ans = floor(k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

int main()
{
  int N, A, B;
  std::cin >> N >> A >> B;
  std::cout << std::min(N * A, B) << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int main(void) { 
  int N ;
  int A [101];
  cin >> N ;
  int Max = 0;
  int Min =1e9;
  for(int i=0; i < N ; i++){
    cin >> A[i] ;
    Max = max(Max,A[i]);
    Min = min(Min,A[i]);
      
  }
  
  cout << Max-Min << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long int 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define INF 0x3f3f3f3f
#define FASTIO ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(0)
#define PI acos(-1)
using namespace std;
void solve()
{
   int n,d;
   cin>>n>>d;
   int ans = 0;
   while(n--)
   {
       int x,y;
       cin>>x>>y;
       if((x*x + y*y) <=d*d)ans++;
   }
   cout<<ans;
}
signed main()
{
    FASTIO;
    size_t  t = 1;
    while(t--)
    {
        solve();
    }
   return 0;
}




Measured memory_bytes: 3692
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
int n;cin>>n;
string s;cin>>s;
int ans=0;
for(int i=0;i<47;i++){
  if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
    ans=ans+1;
  }
}
cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];

    ll sum1 = 0, sum2 = 0, tmp1 = 0, tmp2 = 0;
    rep(i, 0, n) {
        sum1 += a[i], sum2 += a[i];
        if (i % 2 == 0) {
            if (sum1 <= 0) tmp1 += abs(sum1) + 1, sum1 = 1;
            if (sum2 >= 0) tmp2 += abs(sum2) + 1, sum2 = -1;
        } else {
            if (sum1 >= 0) tmp1 += abs(sum1) + 1, sum1 = -1;
            if (sum2 <= 0) tmp2 += abs(sum2) + 1, sum2 = 1;
        }
    }
    cout << min(tmp1, tmp2) << endl;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda x : x[0])
ans = 0
for a, b in ab:
    ans += min(m, b) * a
    m -= b
    if m <= 0:
        break
print(ans)


Measured memory_bytes: 29024
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		int s =scanner.nextInt();
		
		
		int h = s / 3600;
		s -= h * 3600;
		
		int m = s / 60;
		s -= m * 60;
		
		System.out.println(h + ":" + m + ":" + s);
}
}

Measured memory_bytes: 26360
from collections import Counter, deque
from heapq import heappush, heappop, heapify
C = Counter(input())
N = len(C)

if N == 1:
    print(sum(C.values()))
    exit(0)

G = [0]*(N*2)

G[:N] = C
que = [(v, i) for i, v in enumerate(C.values())]
heapify(que)

cur = len(C)
while len(que) > 1:
    v0, nd0 = heappop(que)
    v1, nd1 = heappop(que)
    G[cur] = (nd0, nd1)
    heappush(que, (v0+v1, cur))
    cur += 1
root = que[0][1]

ans = 0
que = deque([(0, root)])
while que:
    d, nd = que.popleft()
    if nd < N:
        ans += d * C[G[nd]]
        continue
    u, v = G[nd]

    que.append((d+1, u))
    que.append((d+1, v))
print(ans)


Measured memory_bytes: 6164
#include<iostream>
using namespace std;
int n,s,o;
void rec(int d,int k,int x){
  if(d>n) return;
  else if(d==n){
    if(x==s) o++;
  }else{
    for(int i=k+1;i<=9;i++){
      rec(d+1,i,x+i);
    }
  }
}
int main(){
  cin >> n >> s;
  while(n!=0){
    o=0;
    rec(0,-1,0);
    cout << o << endl;
    cin >> n >> s;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test IOS long long t;cin >> t;while(t--)
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define MX 99999
const double pi=acos(-1.0);
vector<int>v;
map<int,int>mp;
int main()
{

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
    //test
    {
         int n;cin>>n;
         cout<<n+n*n+n*n*n<<endl;
    }
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long int lli;
#define tc int t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define mx 1000000


int main() {
    long double a,b,c;
    cin>>a>>b>>c;
    long double t1= a+b+2*sqrt(a)*sqrt(b);
    if(t1<c)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int calc(int x){
    int ret = 0;
    while(x % 2 == 0) {
        x /= 2;
        ++ret;
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<ll> a(N,0);
    ll sum = 0;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        sum += calc(a[i]);
    }
    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int N;
vector<int> G[10010];
vector<int> c;
bool flag[10010];
int ans[10010];
int main(){
    cin >> N;
    for(int i = 1; i < N; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int sum = 0;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        sum += x;
        c.push_back(x);
    }
    sort(c.rbegin(), c.rend());
    queue<int> q;
    q.push(1);
    flag[1] = true;
    int idx = 0;
    while(!q.empty()){
        int a = q.front();
        ans[a] = c[idx++];
        q.pop();
        for(int i = 0; i < G[a].size(); i++){
            int g = G[a][i];
            if(!flag[g]){
                flag[g] = true;
                q.push(g);
            }
        }
    }
    cout << sum - c[0] << endl;
    for(int i = 1; i <= N; i++){
        cout << ans[i] << (i != N ? " " : "\n");
    }
    cout << endl;
    return 0;
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int solve(int h)
{
	if(h==1)
		return 1;

	return 2*solve(h/2)+1;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif

    int h;
    cin>>h;

    cout<<solve(h);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib> //絶対値abs
#include <vector>
#include <algorithm> //minmax
using namespace std;
int A,B;
long long h[100010];
long long dp[100010];
const long long INF = 1LL << 62;

int main(){
	cin >> A >> B;
	if(B%A==0){
		cout << A+B;
	}else{
		cout << B-A;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n;
string s;
ll flag = 0;
ll mem;
ll ans = INF;
ll a[e5];
ll b[e5];

int main(){
  cin >> n;
  cin >> s;
  for(ll i = 1;i <= n;i++){
    if(s[i-1] == '#') a[i]++;
    if(s[i-1] == '.') b[i]++;
  }
  for(ll i = 1;i <= n;i++){
    a[i] += a[i-1];
    b[i] += b[i-1];
  }
  for(ll i = 0;i <= n;i++){
    ans = min(ans,a[i]-a[0]+b[n]-b[i]);
  }
  cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int  main() {
	
	vector<pair<ll,ll>>v;

	ll n, k;
	cin >> n >> k;
	rep(i, n) {
		ll a, b;
		cin >> a >> b;
		v.push_back(mp(a, b));
	}

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

	int cnt = 0;

	while (1) {
		k -= v[cnt].second;
		if (k <= 0) {
			pr(v[cnt].first);
			break;
		}
		cnt++;
	}

	return 0;

}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    string s; cin >> s;
    int n = s.size();
    if((n % 2 == 0) ^ (s[0] == s[n-1])) cout << "Second" << endl;
    else cout << "First" << endl;
}

Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>t(100000), x(1000000), y(1000000);
	for (int i = 0; i < n; i++) {
		cin >> t.at(i) >> x.at(i) >> y.at(i);
	}
	for (int i = 0; i < n; i++) {
		int s = t.at(i) - x.at(i) - y.at(i);
		if (!(s >= 0 && s % 2 == 0) ){
			cout << "No";
			break;
		}
		else if (i == n - 1) {
			cout << "Yes";
		}
	}
}

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

typedef long long int ll;

int main()
{
    ll a, b;
    cin >> a >> b;
    if(a > 0 && b > 0 && a < 10 && b < 10){
        cout << a * b;
    }
    else{
        cout << -1;
    }

    
    return 0;
}

Measured memory_bytes: 256
import sys

from collections import deque
sys.setrecursionlimit(1000000)


def dfs(current, prev):
    global time
    # node currentを訪問した直後の処理
    ord[current] = time
    low[current] = time
    time += 1
    color[current] = BLACK

    for next in G[current]:
        if color[next] == WHITE:
            # node currentからnode nextへ訪問する直前の処理
            parent[next] = current
            dfs(next, current)

            # node nextの探索が終了した直後の処理
            low[current] = min(low[current], low[next])
        elif next != prev:
            # edge current --> next がback-edgeの場合の処理
            low[current] = min(low[current], ord[next])


def bridge():
    global time
    time = 1
    dfs(0, -1)  # 0をrootとしてlowの計算
    for u, v in edges:
        if ord[u] < low[v] or ord[v] < low[u]:
            br.add((u, v))


G = {}
edges = set([])
br = set([])
v, n = map(int, input().split())
for i in range(0, v):
    G[i] = []
for i in range(n):
    s, t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)
    edges.add((s, t))
WHITE = 0
BLACK = 2

color = [WHITE] * (v)
parent = [0] * (v)
ord = [0] * (v)
low = [0] * (v)
parent = [0] * (v)
bridge()
if br:
    br = list(map(sorted, br))
    br.sort(key=lambda x: x[1])
    br.sort(key=lambda x: x[0])
    # 安定ソートだからこれができる
    for ans in br:
        print(*ans)



Measured memory_bytes: 25392
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        String S = sc.next();
        String T = sc.next();
        for(int i=0;i<S.length();i++){
            if(S.charAt(i)!=T.charAt(i))ans++;
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 41096
import java.util.*
fun main(arg: Array<String>) {
    val N = nextInt()
    val V = listOfDouble().sorted()
    var ans = V[0]
    for (n in 1 until N) ans = (ans + V[n]) / 2
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfDouble() = listOfString().map { java.lang.Double.parseDouble(it) }

Measured memory_bytes: 37868
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	int[] nineArr = {9,81,729,6561,59049};
	int[] sixArr = {6,36,216,1296,7776,46656};
	
	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		System.out.println(dfs(n, 0));
	}
	
	int dfs(int value, int depth) {
		
		if(value < 6) {
			return depth + value;
		}
		
		if(value < 9) {
			return depth + 1 + (value - 6);
		}
		
		int sixMax=6, nineMax=9;
		for(int i = nineArr.length - 1; i >= 0; i--) {
			if(nineArr[i] <= value) {
				nineMax = nineArr[i];
				break;
			}
		}
		
		for(int i = sixArr.length - 1; i >= 0; i--) {
			if(sixArr[i] <= value) {
				sixMax = sixArr[i];
				break;
			}
		}
		
		return Math.min(dfs(value - sixMax, depth+1), dfs(value - nineMax, depth+1));
	}

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 23252
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    ll res = 1;
    for(ll i = 1; i <= N; i++) {
        res = (res * i) % MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int eaten = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            eaten += (d - 1) / a + 1;
        }

        System.out.println(x + eaten);
    }
}


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

void solve() {
	int h, w; cin >> h >> w;
	int startx, starty, endx, endy;
	cin >> startx >> starty >> endx >> endy;
	startx--; starty--; endx--; endy--;
	vector<string> grid(h);
	for (auto &i : grid)cin >> i;
	vector<vector<int> > distance(h, vector<int> (w, 1e9));
	distance[startx][starty] = 0;
	priority_queue<pair<int, pair<int, int> > > q;
	q.push({0, {startx, starty}});
	while (!q.empty()) {
		int curdis = q.top().first;
		int x = q.top().second.first, y = q.top().second.second;
		q.pop();
		for (int i = -2; i <= 2; i++)for (int j = -2; j <= 2; j++) {
				int newx = x + i, newy = y + j;
				if (newx >= h || newx < 0 || newy >= w || newy < 0)continue;
				if (grid[newx][newy] == '#')continue;
				if (abs(i) + abs(j) == 1) {
					if (distance[newx][newy] > distance[x][y]) {
						distance[newx][newy] = distance[x][y];
						q.push({ -distance[newx][newy], {newx, newy}});
					}
				}
				if (abs(i) + abs(j) > 1) {
					if (distance[newx][newy] > distance[x][y] + 1) {
						distance[newx][newy] = distance[x][y] + 1;
						q.push({ -distance[newx][newy], {newx, newy}});
					}
				}
			}




	}
	if (distance[endx][endy] == 1e9)cout << -1;
	else cout << distance[endx][endy];


}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 8568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++)sum+=a[i];
    cout<<sum;
}


Measured memory_bytes: 3636
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double ans = sqrt(a * a + b * b - 2 * a * b * cos((6 * m - 30 * h - 0.5 * m) * M_PI / 180));
    cout << setprecision(30) << ans << endl;

    return 0;
}


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

int main() {
	string a, b = "+";
	int ans = 0;
	while (cin >> a, "=" != a) {
		if ("*" == a || "+" == a || "-" == a || "/" == a) b = a;
		else {
			if ("*" == b) ans *= stoi(a);
			else if ("+" == b) ans += stoi(a);
			else if ("-" == b) ans -= stoi(a);
			else ans /= stoi(a);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;
ll inf = pow(2, 62);
//x2 + y2 + z2 + xy+yz+zx = x2 + x(y + z) + zy + y2+z2
//(x + y)2 + (y + z)2 + (y + z)2 = 2n
int main()
{
    ll n;
    cin >> n;
    for(int p = 1;p <= n;p++){
        ll count = 0;
    for(int i = 1;i*i <= n;i++){
        for(int j = i;j*j + i*i <= n;j++){
            for(int k = j;k*k+i*i + j*j <= n;k++){
                if(i*i + j*j + k*k+ i*j +j*k + k*i == p){
                    if(i == j && j == k){
                        count++;
                    }
                    else if((i == j && j != k)|| (j == k && k != i)|| (k == i && i != j)){
                        count += 3;
                    }else{
                        count += 6;
                    }
                }
            }
        }
    }
    cout << count << endl;
    }
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= c && c <= b || b <= c && c <= a) cout << "Yes" << endl; 
    else cout << "No" << endl;
     
    return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    s = stdin.readline().rstrip()
    K = int(stdin.readline().rstrip())
    result = set()
    for c in sorted(list(set(s))):
        for x in sorted([s[i:] for i, x in enumerate(s) if x == c]):
            for y in [x[:j + 1] for j in range(len(x))]:
                result.add(y)
                if len(result) == K:
                    print(sorted(list(result))[-1])
                    return


if __name__ == '__main__':
    main()


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

#define pb push_back
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define beg begin()
#define en end()
#define rbeg rbegin()
#define ren rend()
#define mem(a,b) memset(a,b,sizeof a)
#define mem0(a) memset(a,0,sizeof a)
#define mem1(a) memset(a,1,sizeof a)
#define memm(a) memset(a,-1,sizeof a)


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
//~ const int tam=1000;
const int inf=(int)1e9;

using namespace std;

vector<ll> divisors(long long n) {
	long long lim = sqrt(n)+1;
	vector<ll> v;
	for(long long i = 1; i <= lim; ++i){
		if(n%i==0){
			v.push_back(i);
			if(i!=n/i) //To avoid adding a number twice in case that n is a perfect square
				v.push_back(n/i);
		}
	}
	return v;
}
int main(){
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    if(n==1){
		cout<<m;cout<<endl;
		return 0;
	}
    auto v=divisors(m);
    ll ans=1;
    sort(v.beg,v.en);
    for(ll i=((int)v.size())-1; i>=0;--i){
		if(v[i]*n>m){
			continue;
		}
		ans=v[i];
		break;
	}
	cout<<ans;cout<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 998244353;

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

  string S;
  cin >> S;

  //r_i
  vector<LL> dp(4001, 0);
  dp[0] = 1;

  LL r = 0;
  LL b = 0;
  REP(i, S.size())
  {
    LL num = S[i] - '0';
    r += 2 - num;
    b += num;

    vector<LL> newdp(4001, 0);
    REP(j,i+1){
      if(j==r){
        newdp[j] += dp[j];
      }
      else if (i - j == b)
      {
        newdp[j+1] += dp[j];
      }else{
        newdp[j] += dp[j];
        newdp[j+1] += dp[j];
      }
      newdp[j] %= mod;
      newdp[j+1] %= mod;
    }
    REP(i,4001){
      dp[i] = newdp[i]%mod;
    }
  }

  REP(i, S.size())
  {
    vector<LL> newdp(4001, 0);
    REP(j,i+1+S.size()){
      if(j==r){
        newdp[j] += dp[j];
      }
      else if (i+S.size() - j == b)
      {
        newdp[j+1] += dp[j];
      }else{
        newdp[j] += dp[j];
        newdp[j+1] += dp[j];
      }
      newdp[j] %= mod;
      newdp[j+1] %= mod;
    }
    REP(i,4001){
      dp[i] = newdp[i]%mod;
    }
  }

  LL sum = 0;

  REP(i,4001){
    sum += dp[i];
    sum %= mod;
  }

  cout << sum%mod << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

// dp[i][j] := i個目まで見たとき、重さがj以下のときの価値の最大値
int N, W;
ll weight[1 << 17], value[1 << 17], dp[111][1 << 17];

int main()
{
    cin >> N >> W;
    for (int i = 0; i < N; i++)
    {
        cin >> weight[i + 1] >> value[i + 1];
    }

    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            if (j - weight[i] < 0)
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 105472
from collections import Counter

n = int(input())
s = []

for i in range(n):
    a = input()
    a = sorted(a)
    a = ''.join(a)
    s.append(a)

c = Counter(s)


ans = 0
for x in c:
    ans += c[x]*(c[x]-1)//2

print(ans)

Measured memory_bytes: 68440
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
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;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	string str,t;
	set<string> s;
	int i,n;
	set<string>::iterator it;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>str;
		if(i!=0&&str[0]!=t[t.length()-1]){
			cout<<"No"<<endl;
			return 0;
		}
		s.insert(str);
		t=str;
	}
	if(s.size()!=n){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	
	
	return 0;
}


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

def count(A, B, C):
    ret = 0
    while B <= A:
        B *= 2
        ret += 1
    while C <= B:
        C *= 2
        ret += 1
    return ret
    
A, B, C = input().split(' ')
K = int(input())

A = int(A)
B = int(B)
C = int(C)

if count(A, B, C) <= K:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61864
n, m = map(int, input().split())
h = [int(i) for i in input().split()]
path = [[] for i in range(n)]
set_path = set()
for i in range(m):
    a, b = map(int, input().split())
    path[a - 1].append(b - 1)
    path[b - 1].append(a - 1)
    set_path |= set((a - 1, b - 1))
cnt = n - len(set_path)
path_ = {int(i) for i in range(n)}
for i in set_path:
    if max([h[j] for j in path[i]]) < h[i]:
        cnt += 1
print(cnt)

Measured memory_bytes: 46136
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string s;cin>>s;

  rep(bit,1<<3){
    ll ans=s[0]-'0';
    string t="";
    t+=s[0];
    rep(i,3){
      if(bit&(1<<i)){
        ans+=s[i+1]-'0';
        t+='+';
      }
      else {
        ans-=s[i+1]-'0';
        t+='-';
      }
      t+=s[i+1];
    }
    if(ans==7){
      cout<<t<<"=7"<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int N;

int main(int argc, char const *argv[])
{
    cin >> N;
    int ans = 0;
    for (int i = 0; i < 100000; i++)
    {
        if (i * i > N)
        {
            ans = (i - 1) * (i - 1);
            i=100000;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 998244353;

vector<int> fac(300001); //n!(mod M)
vector<int> ifac(300001); //k!^{M-2} (mod M)

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}
int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}

int dp[102][100002];
signed main(){
    int N, W;
    cin >> N >> W;
    vector<int> w(N);
    vector<int> v(N);
    rep(i, N) {
        cin >> w[i] >>v[i];
        dp[i][w[i]] = v[i];
    }
    rep(i,N+1) {
        rep(j, W+1) {
            if(i==0)dp[i][j] = 0;
            else {
                if(j-w[i-1]>=0)dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
                else dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[N][W] << endl;

    return 0;
}



Measured memory_bytes: 83840
# コッホ曲線 Koch curve

import math

class Point():

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __repr__(self):
        return str(self.x) + " " + str(self.y)


def Koch(p1, p2, n):
    if n == 0:
        print(p1)
    else:
        s = Point(p1.x * 2 / 3 + p2.x * 1 / 3, p1.y * 2 / 3 + p2.y * 1 / 3)
        u = Point(p1.x / 2 + p2.x / 2 + p1.y * r3 / 6 - p2.y * r3 / 6, p1.y / 2 + p2.y / 2 + p2.x * r3 / 6 - p1.x * r3 / 6)
        t = Point(p1.x * 1 / 3 + p2.x * 2 / 3, p1.y * 1 / 3 + p2.y * 2 / 3)
        Koch(p1, s, n - 1)
        Koch(s, u, n - 1)
        Koch(u, t, n - 1)
        Koch(t, p2, n - 1)


r3 = math.sqrt(3)
start = Point(0, 0)
goal = Point(100, 0)
n = int(input())
Koch(start, goal, n)
print(goal)



Measured memory_bytes: 5716
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

vector<pair<int,ll>> d[100001];
ll dist[100001];

void dfs(int x){
    for(int i=0;i<d[x].size();i++){
        int a=d[x].at(i).first; ll b=d[x].at(i).second;
        if(dist[a]==-1){
            dist[a]=dist[x]+b;
            dfs(a);
        }
    }
    return;
}


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

    for(int i=0;i<N-1;i++){
        int a,b; ll c; cin>>a>>b>>c;
        d[a].push_back(make_pair(b,c));
        d[b].push_back(make_pair(a,c));
    }

    int Q,K; cin>>Q>>K;
    for(int i=0;i<=N;i++) dist[i]=-1;
    dist[K]=0;
    dfs(K);

    vector<ll> ans;
    for(int i=0;i<Q;i++){
        int a,b; cin>>a>>b;
        ans.push_back(dist[a]+dist[b]);
    }

    for(int i=0;i<Q;i++) cout<<ans.at(i)<<endl;

    
}

Measured memory_bytes: 15220
#include<iostream>
#include<string>
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

int main(){
  int A;
  cin>>A;
  int a=A/100;
  int b=A%100;
  if((a>0 && 13>a) && (b>0 && 13>b)) cout<<"AMBIGUOUS"<<endl;
  else if((a==0 || a>12) && (b>0 && 13>b)) cout<<"YYMM"<<endl;
  else if((b==0 || b>12) && (a>0 && 13>a)) cout<<"MMYY"<<endl;
  else cout<<"NA"<<endl;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  rep(i, 5) { ll x;
    cin >> x;
    if(x == 0){
      cout << i + 1 << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3580
import collections
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = collections.Counter(s)
dic = dic.most_common()

ans = [dic[0][0]]

for i in range(len(dic)-1):
    if dic[i][1] == dic[i+1][1]:
        ans.append(dic[i+1][0])
    else:
        break
        
ans = sorted(ans)

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 45040
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    int a[100005];

    cin >> n;
    rep(i, n) cin >> a[i];

    sort(a, a + n);
    cout << a[n / 2] - a[n / 2 - 1] << endl;

    return 0;
}


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

#define int long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    string s;
    cin >> s;
    reverse(all(s));
    s += '0';
    reverse(all(s));
    int n = s.length();
    int cost = 0;
    for(int i = n - 1;i >= 1; --i){
        if(s[i] < '5'){
            cost += (s[i] - '0');
        }else if(s[i] == '5'){
            if(s[i - 1] >= '5'){
                s[i - 1]++; 
            }
            cost += 5;
        }else{
            cost += (10 - (s[i] - '0'));
            s[i - 1]++;
        }
    }
    cost += (s[0] - '0');
    cout << cost;
}

Measured memory_bytes: 1948
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    int n;
    cin>>n;
    vector<double> a(n);
    for(int i =0;i<n;i++)
        cin>>a[i];
    vector<vector<double> > dp(n+1,vector<double>(n+1,1));
//    for(int i=1;i<n;i++)
//        dp[0][i]=0;
//    dp[1][0]=1-a[0];
//    dp[1][1]=a[0];
    for(int i=1;i<=n;i++)
    {
        dp[i][i]=dp[i-1][i-1]*a[i-1];
        for(int j=i-1;j>=0;j--)
            dp[i][j]=dp[i-1][j]*(1-a[i-1])+dp[i-1][j-1]*a[i-1];
    }
//    for(int i=1;i<=n;i++)
//    {
//        for(int j=0;j<n;j++)
//            cout<<dp[i][j]<<" ";
//        cout<<endl;
//    }
    double ans=0;
    for(int i=n/2+1;i<=n;i++)
        ans+=dp[n][i];
    //cout<<<<ans<<endl;
    printf("%.10f",ans);
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}


Measured memory_bytes: 73752
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

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

    vector<vector<int>> a(n, vector<int>(m));
    vector<vector<int>> dp(n, vector<int>(m));

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            a[i][j] = s[j];
        }
    }

    for (int i = 0; i < n and a[i][0] != '#'; i++) {
        dp[i][0] = 1;
    }

    for (int j = 0; j < m and a[0][j] != '#'; j++) {
        dp[0][j] = 1;
    } 

    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            if (a[i][j] == '#') {
                continue;
            }
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
        }
    }

    cout << dp[n - 1][m - 1] << "\n";
    return 0;
}


Measured memory_bytes: 16000
import java.util.*;
import java.math.BigDecimal;

public class Main {
  public static void main(String[] args) {
    int N;
    int[] A;
    try(Scanner sc = new Scanner(System.in)) {
      N = sc.nextInt();
      A = new int[N];
      for(int i = 0; i < N; i++) {
        A[i] = sc.nextInt();
      }
    }
    double answer = solve(A);
    System.out.println(answer);
  }
  
  private static double solve(int[] a) {
    int n = a.length;
    if ( n == 0 ) {
      throw new IllegalStateException("n must be positive");
    }
    if ( n == 1 ) {
      return (double)a[0];
    }
    int n0 = (int)Math.ceil(n/2);
    int n1 = n - n0;
    double r = 0.0d;
    if ( n0 > 0 ) {
      int[] a0 = new int[n0];
      System.arraycopy(a, 0, a0, 0, n0);
      double s0 = solve(a0);
      r += 1/s0;
    }
    if ( n1 > 0 ) {
	  int[] a1 = new int[n1];
      System.arraycopy(a, n0, a1, 0, n1);
      double s1 = solve(a1);
      r += 1/s1;
    }
    return 1/r;
  }

}

Measured memory_bytes: 21588
#include <iostream>
using namespace std;
string s, t;
int n, m;
int dp[3100][3100];

int main() {
    cin >> s >> t;
    n = s.size(); m = t.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        } 
    }
    string ans;
    while (n > 0 && m > 0) {
        if (dp[n][m] == dp[n-1][m]) n--;
        else if (dp[n][m] == dp[n][m-1]) m--;
        else { n--; m--; ans = s[n] + ans; } 
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> s(N);
  
  for(int i = 0; i < N; i ++){
    cin >> s.at(i);
  }
  
   set<int> values; 
   for (int i = 0; i < N; ++i) {
   values.insert(s.at(i));
    }
  
  if( values.size() == N ) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>
#include<set>
using namespace std;

int n,k,c,cnt,ans=1,a[200005];
set<int> st;

int main()
{
	int i;
	cin>>n>>k;
	for(i=0; i<n; i++)
		scanf("%d",&a[i]);
	for(i=0; i<n-1; i++)
	{
		if(a[i]<a[i+1]) 
			c++;
		else 
			c=0;
		if(c==k-1)
			cnt++;
	}
	for(i=0; i<k; i++)
		st.insert(a[i]);
	while(i<n)
	{
		st.erase(a[i-k]);
		if(a[i-k]>*st.begin() || a[i]<*st.rbegin())
			ans++;
		st.insert(a[i]);
		i++;
	}
	cout<<ans-max(0,cnt-1);
	return 0;
}


Measured memory_bytes: 10368
def deque(a):
    n = len(a)
    cur = a[:]
    nxt = [0] * (n - 1)
    for l in range(2, n + 1):
        for i in range(n - l + 1):
            j = i + l - 1
            nxt[i] = max(a[i] - cur[i + 1], a[j] - cur[i])
        cur, nxt = nxt, cur
    return cur[0]


def main():
    input()  # n
    a = [int(x) for x in input().split()]
    return deque(a)


print(main())


Measured memory_bytes: 39920
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 300 + 5;
const int M = N*N + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,m,L,a,b,c,t,vis[N],cur=-1,src,dist,out[M];
typedef pair<int,int> p;
p ans[N];
vector<p> g[N];
pair<p, int> q[M];

void init() {}

void Dijkstra() {

    for (int i = 1; i <= n; ++i) {
        ans[i] = {OO, 0};
        vis[i] = 0;
    }

    ans[src] = {0, -L};

    for (int i = 0; i < n; ++i) {

        int u = -1;
        p curMin = {OO, 0};

        for (int j = 1; j <= n; ++j) {

            if(!vis[j] && ans[j]<curMin) {

                curMin = ans[j];
                u = j;

            }

        }

        if(!~u) break;

        vis[u] = 1;

        for(auto j:g[u]) {

            int &v = j.f, &cost = j.s;

            p newAns;

            if(-curMin.s >= cost) {
                newAns = {curMin.f, curMin.s + cost};
            } else {
                newAns = {curMin.f + 1, -(L-cost)};
            }

            if(!vis[v])
                ans[v] = min(ans[v], newAns);

        }

    }

}

int main() {

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

    cin >> n >> m >> L;

    for (int i = 0; i < m; ++i) {
        cin >> a >> b >> c;
        if(c>L) continue;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }

    cin >> t;

    for (int i = 0; i < t; ++i) {
        cin >> q[i].f.f >> q[i].f.s;
        q[i].s = i;
    }

    sort(q,q+t);

    for (int i = 0; i < t; ++i) {
        src = q[i].f.f;
        dist = q[i].f.s;
        if(cur!=src) {
            Dijkstra();
            cur = src;
        }
        out[q[i].s] = (ans[dist].f==OO ? -1 : ans[dist].f);
    }

    for (int i = 0; i < t; ++i) {
        cout << out[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 6032