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

typedef long long ll;
typedef unsigned long long ull;

ll L(int N){
    return (1LL<<(N+2)) - 3;
}
ll B(int N){
    return (1LL<<(N+1)) - 1;
}

int main(){
    ll N, X;
    cin >> N >> X;

    ll ans = 0;
    for(int i=N;i>=0;i--){
        if(X <= 1){
            if(i==0 && X==1) ans++;
            cout << ans << endl;
            return 0;
        }
        if(X > L(i-1)+1){
            ans += B(i-1) + 1;
            X -= L(i-1) + 1;
        }
        X--;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt() * 2;
        List<Integer> l = new ArrayList<>();
        IntStream.range(0, n).forEach(i -> l.add(sc.nextInt()));
        Collections.sort(l);
        System.out.println(IntStream.range(0, n).filter(i -> i % 2 == 0).reduce(0, (a, b) -> a + l.get(b)));
    }
}

Measured memory_bytes: 28756
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL  INF = 10000000000;
const int V = 110;
const int E = 10000;
LL d[V][V];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int v, e;
	cin >> v >> e;
	
	for(int i = 0; i < v; ++i){
		for(int j = 0; j < v; ++j){
			d[i][j] = INF;
		}
		d[i][i] = 0;
	}
	
	int a, b;
	LL c;
	for(int i = 0; i < e; ++i){
		cin >> a >> b >> c;
		d[a][b] = c;
	}
	
	for(int k = 0; k < v; ++k){
		for(int i = 0; i < v; ++i){
			for(int j = 0; j < v; ++j){
				if(d[i][k] != INF && d[k][j] != INF)
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
	for(int i = 0; i < v; ++i){
		if(d[i][i] < 0){
			cout << "NEGATIVE CYCLE" << endl;
			return 0;
		}
	}
	
	for(int i = 0; i < v; ++i){
		for(int j = 0; j < v; ++j){
			if(d[i][j] != INF)
				cout << d[i][j];
			else
				cout << "INF";
			if(j != v - 1)
				cout << " ";
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 10000
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
 int n;
 while(cin>>n,n){
  vector<string> s(n);
  set<string> s_set;
  for(auto&i:s)cin>>i;
  rep(i,n){
   bool ok=true;
   rep(j,n) ok&=(i==j or s[j].find(s[i])==-1);
   if(ok) s_set.insert(s[i]);
  }
  s.clear();
  for(auto&i:s_set)s.push_back(i);
  n=s.size();
  
  vvi a(n,vi(n,0));
  rep(i,n)rep(j,n){
   if(i==j) {
    a[i][j]=INF;
    continue;
   }
   int si=s[i].size(), sj=s[j].size();
   for(int p=min(si,sj)-1;p>0;p--){
    if(s[i].substr(si-p) == s[j].substr(0,p)){
     a[i][j]=-p; break;
    }
   }
  }
  vvi dp(1<<n,vi(n,INF));
  rep(i,n) dp[1<<i][i]=0;

  rep(st,(1<<n)){
   rep(i,n) if(dp[st][i]!=INF) rep(j,n){
    if(st & (1<<j))  continue;
    int next=st|(1<<j);
    int cost=dp[st][i]+a[i][j];
    dp[next][j]=min(dp[next][j], cost);
   }
  }
  
  int ans=*min_element(all(dp[(1<<n)-1]));
  for(auto i:s)ans+=i.size();
  cout<<ans<<endl;
 }
 return 0;
}


Measured memory_bytes: 4324
n = int(input())
list_score = list(map(int, input().split()))
cnt = 1
for i in range(n):
    if list_score[i] == cnt:
        cnt += 1
ans = 0
cnt -= 1
if cnt == 0:
    ans = -1
else:
    ans = len(list_score) - cnt
print(ans)

Measured memory_bytes: 24744
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{s:String};
    for i in 0..s.len() { print!("x"); }
    println!("");
}

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

using namespace std;

const int N = 1e6 + 5;

int main() {
	string s;
	cin >> s;
	long long cnt = 0, n = s.size() - 1, ans = 0;
	while (cnt < (1 << n)) {
		long long val = s[0] - '0';
		for (int i = 0; i < n; i ++) {
			if (cnt & (1 << i)) {
				ans += val;
				val = 0;
			}
			val = val * 10 + (s[i + 1] - '0');
		}
		ans += val;
		cnt ++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define pai 3.1415926535


int main(void) {
	
	char a[4], b[4], c[4];
	scanf("%s %s %s", a, b, c);
	printf("%c%c%c", a[0], b[1], c[2]);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define text freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7 ;
const ld pi=3.1415926535897932384626433;
const ll inf = 1e18;
bool isprime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll sol=a>b?a:b;return sol;}
ll min(ll a,ll b){ll sol=a<b?a:b;return sol;}
ll dp[105][4][2];
ll k;
string s;
ll mkc(ll ind,ll noz,ll flag)
{
   if (noz>k)
      return 0;

   if (ind==s.size())
      return noz==k;

   if (dp[ind][noz][flag]!=-1)
   {
      return dp[ind][noz][flag];
   }


   ll ans=0;
   for (char i='0';i<='9';i++)
   {
      if (i<s[ind])
      ans+=mkc(ind+1,noz+(i!='0'),1);
      else
      {
         if (i==s[ind] or flag)
         ans+=mkc(ind+1,noz+(i!='0'),flag);
      }
   }
   dp[ind][noz][flag]=ans;
   return ans;
}
int main()
{
   bolt;
   memset(dp,-1,sizeof(dp));
   cin>>s>>k;
   cout<<mkc(0,0,0);
}


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

using namespace std;

class Element {
    public:
        int x, y, d, cost;
        Element(int x, int y, int d, int cost):
                x(x), y(y), d(d), cost(cost) {
        }
        bool operator<(const Element &e) const {
            return (e.cost < this->cost);
        }
};

class Solver {
    private:
    public:
        int w, h;
        int c[4];
        int s[30][30];
        int solve() {
            int retval = -1;
            int dx[] = {1, 0, -1, 0};
            int dy[] = {0, 1, 0, -1};
            priority_queue<Element> heap;
            int costs[30][30][4];
            for (int y = 0; y < h; ++y) {
                for (int x = 0; x < w; ++x) {
                    for (int d = 0; d < 4; ++d) {
                        costs[x][y][d] = -1;
                    }
                }
            }
            heap.push(Element(0, 0, 0, 0));
            costs[0][0][0] = 0;
            while (!heap.empty()) {
                Element e = heap.top();
                heap.pop();
                for (int di = 0; di < 4; ++di) {
                    int nd = (e.d + di) % 4;
                    int nx = e.x + dx[nd];
                    int ny = e.y + dy[nd];
                    int cost = e.cost;
                    if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                        continue;
                    }
                    if (di != s[e.x][e.y]) {
                        cost += c[di];
                    }
                    if (costs[nx][ny][nd] < 0 || cost < costs[nx][ny][nd]) {
                        costs[nx][ny][nd] = cost;
                        heap.push(Element(nx, ny, nd, cost));
                    }
                }
            }
            for (int d = 0; d < 4; ++d) {
                if (costs[w - 1][h - 1][d] >= 0) {
                    if (retval < 0) {
                        retval = costs[w - 1][h - 1][d];
                    } else {
                        retval = min(retval, costs[w - 1][h - 1][d]);
                    }
                }
            }
            return retval;
        }
};

int main() {
    Solver s;
    while (true) {
        cin >> s.w >> s.h;
        if (s.w == 0) {
            return 0;
        }
        for (int y = 0; y < s.h; ++y) {
            for (int x = 0; x < s.w; ++x) {
                cin >> s.s[x][y];
            }
        }
        for (int i = 0; i < 4; ++i) {
            cin >> s.c[i];
        }
        cout << s.solve() << endl;
    }
}

Measured memory_bytes: 1328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;



signed main(){
    string s; cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-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; }

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

    vector<ll> c(n);
    rep(i, n) c[i] = a[i] + b[i];
    sort(all(c));
    reverse(all(c));

    ll ans = 0;
    rep(i, n) {
        if (i % 2 == 0) {
            ans += c[i];
        }
        ans -= b[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 5600
{-# LANGUAGE OverloadedStrings #-}
import Data.Char
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  s <- BS.getLine
  BS.putStrLn $ if 'A' `BS.elem` s && 'B' `BS.elem` s then "Yes" else "No"
  where
     parseLine = unfoldr (BS.readInt . BS.dropWhile isSpace)

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

const int maxr = 96;
const int maxc = 100;

char a[maxr][maxc];
int main()
{
    int A, B;
    scanf("%d%d", &A, &B);

    int mx = min(16, min(A, B)), tempA = A, tempB = B, cnt = 0;
    for(int i = 0; i < maxr; i ++) {
        if(i % 6 == 0)
            tempA --;
        if(i % 6 == 3)
            tempB --;
        if(i % 6 == 2) {
            cnt ++;
            if(cnt == mx) {
                if(A <= B) {
                    for(int k = i; k < maxr; k ++)
                        for(int j = 0; j < maxc; j ++)
                            a[k][j] = '.';
                } else {
                    tempB --;
                    for(int k = i; k < maxr; k ++)
                        for(int j = 0; j < maxc; j ++)
                            a[k][j] = '#';
                }
                break;
            }
        }
        for(int j = 0; j < 100; j ++) {
            if((i % 6 ) <= 2)
                a[i][j] = '.';
            if((i % 6) > 2)
                a[i][j] = '#';
        }
    }

    int resW = tempA, resB = tempB;
    for(int i = 1; i < maxr; ) {
        if((i % 6) == 1) {
            for(int j = 0; j < maxc; j += 2)
                if(resB)
                    resB --, a[i][j] = '#';
        } else {
            for(int j = 0; j < maxc; j += 2)
                if(resW)
                    resW --, a[i][j] = '.';
        }
        i += 3;
    }
    int row = maxr;
    printf("%d %d\n", row, 100);
    for(int i = 0; i < row; i ++) {
        for(int j = 0; j < maxc; j ++)
            printf("%c", a[i][j]);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  char a;
  cin>>a;
  if(a=='A')
    out('T');
    else if(a=='C')
      out('G');
      else if(a=='G')
        out('C');
        else
          out('A');
}


Measured memory_bytes: 256
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()


def get_count(tot):
    '''
    tot以上を満たす幸福度の握手の個数を数える
    '''
    ret = 0
    for i in range(N):
        cnt = bisect_left(A, tot-A[i])
        ret += N - cnt
    return ret


# 右からの累積和
Asum = A[:]
for i in range(N-2, -1, -1):
    Asum[i] += Asum[i+1]


def get_sum(tot):
    '''
    左端を固定した時の右端の個数分だけ左端を足し、右端の区間和（累積和）も足す。
    '''
    ret = 0
    for i in range(N):
        idx = bisect_left(A, tot-A[i])
        cnt = N - idx
        ret += A[i]*cnt
        # print(idx)
        if idx == N:
            continue
        ret += Asum[idx]
        # print(f'ret = {ret}')
    return ret


# M回握手できる上限を求める
ok = 0
ng = 10**12
while ok + 1 != ng:
    md = (ok + ng)//2
    if M <= get_count(md):
        ok = md
    else:
        ng = md
# print(ok)
# print(get_sum(ok+1))
# print(M - get_count(ok+1))
# print(Asum)
ans = get_sum(ok+1) + (M - get_count(ok+1))*ok

print(ans)


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


int main()
{
  string s;
  cin>>s;
  int sum=0;
  for(int i=0;i<s.size();i++)
  {
      sum=sum+(s[i]-'0');
  }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


}

Measured memory_bytes: 3724
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m,r,ans=inf; cin>>n>>m>>r;
    vector<vector<int>> d(n,vector<int>(n,inf));
    vector<int> ro(r,0),p(r,0);
    rep(i,n) d[i][i]=0;
    rep(i,r){
        cin>>ro[i]; ro[i]--;
        p[i]=i+1;
    }
    sort(al(ro));
    rep(i,m){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        d[b][a]=d[a][b]=c;
    }
    rep(k,n)rep(i,n)rep(j,n){
        if(d[i][j]>d[i][k]+d[k][j])
        d[i][j]=d[i][k]+d[k][j];
    }
    do{
        int cnt=0;
        rep(i,r-1) cnt+=d[ro[p[i]-1]][ro[p[i+1]-1]];
        ans=min(ans,cnt);
    }while(next_permutation(al(p)));
    cout<<ans<<endl;
}

Measured memory_bytes: 384
import java.util.*;

class Main {
	Scanner sc;
	int N, K;
	int[] x, y, c;
	static final double eps = 1e-7;
	
	void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		
		x = new int[N];
		y = new int[N];
		c = new int[N];
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		
		double r = 2000d * Math.sqrt(2) * 100;
		double l = 0d;
		double m = 0;
		while (Math.abs(r-l)/r > eps) {
			m = (l + r) / 2;
			if (!Kintersects(m)) l = m;
			else r = m;
		}
		System.out.println(m);
	}
	
	private boolean Kintersects(double t) {
		for (int i = 0; i < N; i++) {
			if (Kcontains(t, x[i], y[i])) return true;
		}
		for (int i = 0; i < N-1; i++) {
			for (int j = i+1; j < N; j++) {
				double x2, y2, r1, r2, b, a, d, xa, ya;
				x2 = x[j] - x[i];
				y2 = y[j] - y[i];
				r1 = t/c[i];
				r2 = t/c[j];
				b = x2*x2 + y2*y2;
				a = (b + r1*r1 - r2*r2) / 2;
				d = b*r1*r1 - a*a;
				if (d < 0) continue;
				d = Math.sqrt(d);
				xa = (a*x2 + y2*d)/b + x[i];
				ya = (a*y2 - x2*d)/b + y[i];
				if (Kcontains(t, xa, ya)) return true;
				xa = (a*x2 - y2*d)/b + x[i];
				ya = (a*y2 + x2*d)/b + y[i];
				if (Kcontains(t, xa, ya)) return true;
			}
		}
		return false;
	}

	private boolean Kcontains(double t, double x, double y) {
		int c = 0;
		for (int i = 0; i < N; i++) {
			if (contains(i, t, x, y))
				if ( ++c >= K ) return true;
		}
		return false;
	}
	
	private boolean contains(int j, double t, double x, double y) {
		double xs, ys, d;
		xs = this.x[j] - x;
		ys = this.y[j] - y;
		d = Math.sqrt( xs*xs + ys*ys );
		return (d <= t/c[j]*(1+eps));
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 36912
#include<iostream>
#include<stdio.h>
#include<string>
#include<stdlib.h>
using namespace std;

int top;
int S[1000];

void push(int x) {
    top++;
    S[top] = x;
}

int pop() {
    
    top--;
    return S[top + 1];
}

int main() {
    int a, b;
    top = 0;
    char s[100];
    
    while(cin >> s) {
        if (s[0] == '+') {
            a = pop();
            b = pop();
            push(a + b);
        } else if (s[0] == '-') {
            b = pop();
            a = pop();
            push(a - b);
        } else if (s[0] == '*') {
            a = pop();
            b = pop();
            push(a * b);
        }
        else {
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
    
    return 0;
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 int main(){
   int a, b;
   cin >> a >> b;
   int now = 0;
   int ans;
  for(int i = 1; i <= b - a; i++){ 
    now += i;
    if(b - a == i) ans = now - b;
  }

print(ans);
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
vector<vector<int>>v;
vector<pair<int,int>> toPrint;
map<pair<int,int>, int> col;
int n, mxColor;
void bfs(){
    queue<int> q;
    int colorOfNode[n + 2];
    memset(colorOfNode, -1, sizeof colorOfNode);
    q.push(1);
    colorOfNode[1] = 0;
    while(q.size()){
        int numb = q.front(), curColor = 1;
        q.pop();
        mxColor = max(mxColor, (int)v[numb].size());
        for(int i = 0; i < v[numb].size(); i++){
            if(colorOfNode[v[numb][i]] != -1) continue;
            if(curColor == colorOfNode[numb]) curColor++;
            colorOfNode[v[numb][i]] = curColor;
            q.push(v[numb][i]);
            col[{numb, v[numb][i]}] = curColor;
            col[{v[numb][i], numb}] = curColor ++;
        }
    }
}
int main(){
    Hello
    cin >> n;
    v.resize(n + 2);
    for(int i = 1, a, b; i < n; i++){
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
        toPrint.push_back({a, b});
    }
    bfs();
    cout << mxColor << endl;
    for(int i = 0; i < toPrint.size(); i++) cout << col[toPrint[i]] << endl;
    return 0;
}


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

using namespace std;

int main(){
 	// ios_base::sync_with_stdio(false);
  //   cin.tie(NULL);
  int n,k;
  cin>>n>>k;
  double sum=0;
  for(int i=1;i<=n;i++){
    int j=i;
	double temp=1.0/n;
    //cout<<temp<<'\t'<<j<<'\n';
    while(j<k){
      j*=2;
      temp/=2;
    }
    sum+=temp;
    //cout<<temp<<'\n';
  }
  printf("%.12f\n",sum);
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int x,y;cin>>x>>y;
	int d=abs(abs(x)-abs(y));
	int ans=d;
	if(x>y){
		if(y>0) ans+=2;
		else if(x>=0&&0>=y) ans+=1;
		else ans+=2;
	}
	else{
		if(x>=0) ans+=0;
		else if(y>0&&0>x) ans+=1;
		else ans+=0;
	}

	cout<<ans<<"\n";
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String [] args) {
        new Main().run();
    }
    final int [] dx = {0, 1, 1,  1,  0, -1, -1, -1};
    final int [] dy = {1, 1, 0, -1, -1, -1,  0,  1};
    HashSet<String> occurOnce;
    //HashSet<Integer> occurOnce;
    String longestString(int y, int x) {
        String longest = "";
        for (int i = 0; i < 8; i++) {
            String cur = String.valueOf(F[y].charAt(x));
            StringBuilder sb = new StringBuilder(cur);
            int ny = (y + dy[i] + H) % H, nx = (x + dx[i] + W) % W;
            while (ny != y || nx != x) {
                //cur = cur + String.valueOf(F[ny].charAt(nx));
                sb.append(String.valueOf(F[ny].charAt(nx)));
                cur = sb.toString();
                int hashCode = cur.hashCode();
                if (occurOnce.contains(cur)) {
                //if (occurOnce.contains(hashCode)) {
                    if (longest.length() < cur.length()) {
                        //debug(cur);
                        longest = cur;
                    } else if (longest.length() == cur.length() && longest.compareTo(cur) > 0) {
                        //debug(cur);
                        longest = cur;
                    }
                } else {
                    if (cur.length() >= longest.length()) occurOnce.add(cur);
                    //occurOnce.add(hashCode);
                }
                ny = (ny + dy[i] + H) % H;
                nx = (nx + dx[i] + W) % W;
            }
        }
        //debug(longest);
        return longest;
    }
    void debug(Object ... o) {
        System.out.println(Arrays.deepToString(o));
    }
    void run() {
        while (init()) {
            String longest = "";
            occurOnce = new HashSet<String>();
            //occurOnce = new HashSet<Integer>();
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    String cur = longestString(i, j);
                    if (longest.length() < cur.length()) {
                        //debug(cur);
                        longest = cur;
                    } else if (longest.length() == cur.length() && longest.compareTo(cur) > 0) {
                        //debug(cur);
                        longest = cur;
                    }
                }
            }
            if (longest.length() < 2) {
                System.out.println(0);
            } else {
                System.out.println(longest);
            }
        }
    }
    Scanner sc;
    Main() {
        sc = new Scanner(System.in);
    }
    int W, H;
    String [] F;
    boolean init() {
        H = sc.nextInt();
        W = sc.nextInt();
        if (H == 0 && W == 0) return false;
        F = new String[H];
        for (int i = 0; i < H; i++) {
            F[i] = sc.next();
        }
        return true;
    }
}

Measured memory_bytes: 215148
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    string s,t;
    cin >> s >> t;
    s=t+s;
    cout << s << endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
import heapq
hq=[]
for i in range(N):
    if i==0:
        heapq.heappush(hq,-A[i])
        continue
    else:
        tmp=heapq.heappop(hq)*-1
        ans+=tmp
        heapq.heappush(hq,-A[i])
        heapq.heappush(hq,-A[i])
print(ans)

Measured memory_bytes: 31364
# A: 500, b: 100, c: 50, X: sum
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0

for a in range(0, A+1):
    for b in range(0, B+1):
        for c in range(0, C+1):
            if 500*a + 100*b + 50*c == X:
                counter += 1

print(counter)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void doIt() {
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		int cnt = 0;
		int[] dp = new int[n + 1];
		Arrays.fill(dp, 0);
		for(int i = 0; i <= n; i += r) {
			dp[i] = 1;
		}
		for(int i = 0; i <= n - g; i++) {
			dp[i + g] = dp[i + g] + dp[i] * 1;
		}
		//System.out.println(Arrays.toString(dp));
		for(int i = 0; i <= n - b; i++) {
			dp[i + b] = dp[i + b] + dp[i] * 1;
		}
		System.out.println(dp[n]);
		//System.out.println(Arrays.toString(dp));
	}


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


Measured memory_bytes: 23764
#include<stdio.h>
int main()
{
    long long int a,b,c,d,e,sum=0,i,n;
    scanf("%lld%lld",&a,&b);
    while(b--){
            scanf("%lld",&n);
          sum=sum+n;
    }
    if(sum>=a){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define rep(i,x) for(int (i)=1;(i)<=(x);(i)++)
#define repp(i,x,y) for(int (i)=(x);(i)<=(y);(i)++)
#define forn(i,x) for(int (i)=0;(i)<(x);(i)++)
#define foreach(i,x) for(auto (i):(x))
#define LEN 32
using namespace std;
typedef pair<int,int>pii;
int n;
int a[200010];
multiset<int>mm;
int ans;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1,[=](const int&x,const int&y)->bool{return x>y;});
	for(int i=1;i<=n;i++)mm.insert(a[i]);
	while(!mm.empty()){
		auto it=mm.end();
		it--;
		int x=*it;
		int p;
		mm.erase(it);
		for(p=1;p<=x;p*=2);
		if(mm.count(p-x)){
			mm.erase(mm.find(p-x));
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11136
# -*- coding: utf-8 -*-
s = input()
ans = ''
for i in range(len(s)):
    if s[i] == '0':
        ans += '0'
    elif s[i] == '1':
        ans += '1'
    else:
        if len(ans) > 0:
            ans = ans[:-1]
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s;
    cin >> t;
    int count = 0;
    for (int i=0; i<s.size(); i++){
        if (s.at(i) != t.at(i)) count += 1;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    vector<long long int> h(n);
    for(int i = 0 ; i < n ; i++)
        cin >> h[i];
    
    sort(h.rbegin(),h.rend());
    long long int ans = 0;
    for(int i = k ; i < n ; i++)
        ans += h[i];
    
    cout << ans << endl;
  
    return 0;
}

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

using namespace std;


int main() {

	int n;
	cin >> n;

	int a, b,c;
	deque<int> aa;
	for (int i = 0; i < n; i++) {
		cin >> a >> b ;
		if (a == 0) {
			cin >> c;
			if (b == 0) {
				aa.push_front(c);
			}
			else if (b == 1) {
				aa.push_back(c);
			}
		}
		if (a == 1) {
			cout << aa[b] << endl;;
		}
		if (a == 2) {
			if (b == 0) {
				aa.pop_front();
			}
			else if (b == 1) {
				aa.pop_back();
			}
		}
	}

}


Measured memory_bytes: 4568
import java.util.Scanner;

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

		while (true) {
			n = sc.nextInt();
			m = sc.nextInt();
			if ((n | m) == 0) {
				break;
			}
			a = new int[n];
			while (m-- != 0) {
				String k = sc.next();
				if (k.equals("A")) {
					for (int i = 0; i < n; i++) {
						if (a[i] == 0) {
							a[i] = 1;
							break;
						}
					}
				} else if (k.equals("B")) {
					boolean flag = false;
					for (int i = n - 1; 0 <= i; i--) {
						if (a[i] == 0 && (i - 1 < 0 || a[i - 1] != 1) && (n <= i + 1 || a[i + 1] != 1)) {
							a[i] = 2;
							flag = true;
							break;
						}
					}
					if (!flag) {
						for (int i = 0; i < n; i++) {
							if (a[i] == 0) {
								a[i] = 2;
								break;
							}
						}
					}
				} else if (k.equals("C")) {
					boolean flag = false;
					for (int i = 0; i < n; i++) {
						if (a[i] != 0) {
							if (i + 1 < n && a[i + 1] == 0) {
								a[i + 1] = 3;
								flag = true;
								break;
							} else if (0 <= i - 1 && a[i - 1] == 0) {
								a[i - 1] = 3;
								flag = true;
								break;
							}
						}
					}
					if (!flag) {
						a[n / 2] = 3;
					}
				} else if (k.equals("D")) {
					int max = 0;
					int minId = -1;
					for (int i = 0; i < n; i++) {
						if (a[i] == 0) {
							int tmp1 = 0;
							int tmp2 = 0;
							int id = i + 1;
							while (id < n && a[id] == 0) {
								tmp1++;
								id++;
							}
							if (id == n) {
								tmp1 = 1 << 29;
							}
							id = i - 1;
							while (0 <= id && a[id] == 0) {
								tmp2++;
								id--;
							}
							if (id == -1) {
								tmp2 = 1 << 29;
							}
							if (max < Math.min(tmp1, tmp2)) {
								max = Math.min(tmp1, tmp2);
								minId = i;
							}
						}
					}
					if (minId != -1) {
						a[minId] = 4;
					} else {
						for (int i = 0; i < n; i++) {
							if (a[i] == 0) {
								a[i] = 4;
								break;
							}
						}
					}
				}
			}
			for (int i = 0; i < n; i++) {
				if (a[i] != 0) {
					System.out.print((char)(a[i] + 'A' - 1));
				} else {
					System.out.print("#");
				}
			}
			System.out.println();
		}
	}
}

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

int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4] == s[5])
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long

int main(){
  ll h,n,a,i;
  scanf("%lld%lld",&h,&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    h-=a;
  }
  if(h<=0) printf("Yes");
  else printf("No");
  return 0;
}

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

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
  }
  else {
    cout << N*(N-1)/2 << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b,c;
    // 文字列の入力
    scanf("%d %d %d",&a, &b, &c);
  int ans;
  if((a-b) < c){
    ans= c-(a-b);
  }else{
    ans=0;
  }
  printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

using namespace std;

long long MOD = 998244353L;

long long pow(int a, int n) {
    long long ret = 1;
    for (int i = 0; i < n; i++) {
        ret = (ret * a) % MOD;
    }
    return ret;
}

map <int, long long> memo;

long long doit(vector <int> &a, int n, int suma, int index, int s) {
    if (s * 2 > suma) {
        return 0;
    }
    if (index >= n) {
        return 3;
    }
    int key = s * n + index;
    if (memo.find(key) == memo.end()) {
        memo[key] = (doit(a, n, suma, index + 1, s + a[index]) * 2 +
                     doit(a, n, suma, index + 1, s)) % MOD;
    }
    return memo[key];
}

map <int, long long> memo2;

long long doit2(vector <int> &a, int n, int suma, int index, int s) {
    if (s * 2 > suma) {
        return 0;
    }
    if (index >= n) {
        return (s * 2 == suma) ? 3 : 0;
    }
    int key = s * n + index;
    if (memo2.find(key) == memo2.end()) {
        memo2[key] = (doit2(a, n, suma, index + 1, s + a[index]) +
                     doit2(a, n, suma, index + 1, s)) % MOD;
    }
    return memo2[key];
}

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

    vector <int> a(n);
    int suma = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        suma += a[i];
    }

    vector <long long> dp1(suma + 1, 0);
    vector <long long> dp2(suma + 1, 0);
    dp1[0] = 3;
    dp2[0] = 3;
    for (int i = 0; i < n; i++) {
        vector <long long> next1(suma + 1, 0);
        vector <long long> next2(suma + 1, 0);
        for (int j = 0; j * 2 <= suma; j++) {
            next1[j] = (dp1[j] + (j >= a[i] ? dp1[j - a[i]] * 2 : 0)) % MOD;
            next2[j] = (dp2[j] + (j >= a[i] ? dp2[j - a[i]] : 0)) % MOD;
        }
        dp1 = next1;
        dp2 = next2;
    }
    long long ret = pow(3, n);
    for (int j = 0; j * 2 <= suma; j++) {
        ret = (ret - dp1[j] + MOD) % MOD;
    }
    if (suma % 2 == 0) {
        ret = (ret + dp2[suma / 2]) % MOD;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstdio>
#include <sstream>
#include <vector>
using namespace std;
int W,R[12],n;
int bit[12]={1,2,4,8,16,32,64,128,256,512,1024,2048};


double cal_r(int a,int b){
	return sqrt((double)(a+b)*(a+b)-(a-b)*(a-b));
}


int main(){
	string s;
	while(getline(cin,s)){
		
		vector <int>v;
		stringstream am;
		am<<s;
		n=0;
		am>>W;
		while(!am.eof()){
			int y;
			am>>y;
			v.push_back(y);
			n++;
		}
		//n=v.size();
		for(int i=0;i<v.size();i++)R[i]=v[i];
		
		
		double dp[4096][12];
		bool flag[4096][12]={0};
		for(int i=0;i<4096;i++){
			for(int j=0;j<12;j++){
				dp[i][j]=200.0;
			}
		}
		queue <int>first;
		queue <int>second;
		first.push(0);
		second.push(-1);
		double ans=200.0;
		for(int P,L;!first.empty();first.pop(),second.pop()){
			P=first.front();
			L=second.front();
			if(L<0){
				for(int i=0;i<n;i++){
					dp[bit[i]][i]=R[i];
					if(!flag[bit[i]][i]){
						first.push(bit[i]);
						second.push(i);
						flag[bit[i]][i]=1;
					}
				}
			}
			else{
				
				//for(int i=0;i<3;i++)cout<<((P&bit[i])?"1":"0");
				//cout<<" "<<L<<" "<<dp[P][L]<<endl;
				
				int f=1;
				for(int i=0;i<n;i++){
					if((~P)&bit[i]){
						f=0;
						int tmp=P|bit[i];
						if(!flag[tmp][i]){
							flag[tmp][i]=1;
							first.push(tmp);
							second.push(i);
						}
						dp[tmp][i]=min(dp[tmp][i],dp[P][L]+cal_r(R[L],R[i]));
					}
				}
				
				if(f){
					ans=min(ans,dp[P][L]+R[L]);
				}
			}
			
		}
		//cout<<ans<<endl;
		if(ans<=W)cout<<"OK\n";
		else cout<<"NA\n";
	}
	
	
	return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>
#define MAX 2001;
int adj[101][101];
int check[101];
int mst[101];
int v, count;

void setup(int n) {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (adj[i][j] == -1)
	adj[i][j] = MAX;
}

int minimum(int num) {
  int min = 1, sum = 0, step, minicost;
  int i, j;
  mst[++count] = num;
  check[num]++;

  while (1) {
    minicost = MAX;
    for (i = 1; i <= count; i++) {
      for (j = 1; j <= v; j++)
	if (minicost > adj[mst[i]][j] && check[j] == 0) {
	  min = j;
	  minicost = adj[mst[i]][j];
	}
    }
    sum += minicost;
    check[min]++;
    mst[++count] = min;
    if (count == v)
      break;
  }
  return sum;
}

int main(void) {
  int n;

  scanf("%d", &n);
  v = n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      scanf("%d", &adj[i][j]);

  setup(n);

  printf("%d\n", minimum(1));

  return 0;
}



Measured memory_bytes: 2128
n = input()
dp = [0,1]
ans = 0
for i in range(len(n)):
    cur1 = dp[0]
    cur2 = dp[1]
    if i != len(n)-1:
        dp[0] = min(cur1+int(n[i]), cur2+10-int(n[i]))
        dp[1] = min(cur1+int(n[i])+1, cur2+9-int(n[i]))
    else:
        ans = min(dp[0]+int(n[i]), dp[1]+10-int(n[i]))
print(ans)


Measured memory_bytes: 53484
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007;

ll modpow(ll n, ll p, ll m) {
  if(p==0) return 1LL;
  if(p%2==0) {
    ll t = modpow(n, p/2, m);
    return t * t % m;
  }
  return n * modpow(n, p-1, m) % m;
}

ll f(ll n, ll a, ll m) {
  ll x = 1LL;
  for(ll i = n-a+1; i<=n; i++) {
    x *= i;
    x %= m;
  }
  ll y = 1LL;
  for(ll i = 1; i<=a; i++) {
    y *= i;
    y %= m;
  }
  return x * modpow(y,m-2,m) % m;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = modpow(2,n,mod) - 1;
  ans -= f(n,a,mod);
  ans -= f(n,b,mod);
  while(ans<0) ans += mod;
  cout << ans << endl;
  return 0;
}

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

const int MOD = 1e9 + 7, mxN = 2e5;

void solve() {
    long long s = 0, ans = 0;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        s += a[i];
    }
    for (int i = 0; i < n-1; ++i) {
        s -= a[i];
        (ans += (a[i] * (s%MOD)) %MOD) %= MOD;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3976
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

int main() {
    ll N,M,K;
    cin >> N >> M >> K;
    bool jg=false;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=M;j++){
            if(i*M+j*N-2*i*j==K) jg=true;
        }
    }

   cout << (jg?"Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		String s = scan.next();
		
		if(s.length() <= k) {
			System.out.println(s);
		} else {
			for(int i = 0; i < k; i++) {
				char ini = s.charAt(i);
				System.out.print(ini);
			}
			System.out.println("...");
		}
		scan.close();
	}

}


Measured memory_bytes: 35832
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

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

    if (N / 100 == N % 10)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin, s;

    auto check = [&s](int a, int b) {
        string sub = s.substr(a, b);
        string rev = sub;
        reverse(rev.begin(), rev.end());
        int n = sub.size();
        REP(i, 0, n) {
            if (sub[i] != rev[i]) return false;
        }
        return true;
    };
    int n = s.size();
    cout << (check(0, n) && check(0, (n - 1) / 2) && check((n + 3) / 2 - 1, 1000000) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define scanf __builtin_scanf
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;

int a[100010];
pair<int, int> d[100010];

int main()
{
    int n, m; scanf("%d%d", &n, &m);

    for(int i=0; i<n; ++i) scanf("%d", a+i);
    sort(a, a+n);

    for(int i=0; i<m; ++i) {
        int b, c; scanf("%d%d", &b, &c);
        d[i]={c, b};
    }
    sort(d, d+m);
    reverse(d, d+m);

    int k=0;
    for(int i=0; i<n; ++i) {
        if (k<m and a[i]<d[k].first) {
            a[i]=d[k].first;
            if (--d[k].second==0) ++k;
        }
    }
    printf("%ld\n", accumulate(a, a+n, 0L));
}


Measured memory_bytes: 1280
S=str(input())
N=len(S)
a=[]
y=0
x=0
z=0
a=list(S)

y=([i for i, p in enumerate(a) if p == 'W'])
z=len(y) #Wの個数
x=sum(y) #Wのi番目の合計

b=(1/2)*z*(z-1)
print(int(x-b))


Measured memory_bytes: 13032
#! /usr/bin/env python3
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

A, B = map(int, readline().split())

print(A * B)

Measured memory_bytes: 9232
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((ll)5e5+5)
#define MOD ((ll)1e9 + 7)
#define INF ((ll)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<ll,ll>
#define mid ((l+r)/2)

ll fac[MAXN], invfac[MAXN];
ll n,m;
ll n_comb[MAXN];
ll m_nper[MAXN]; // 0 : (m-n, 0), k: (m-n+k, k)

ll fast(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
		{
			res*=a;
			res%=MOD;
		}
		b>>=1LL;
		a*=a;
		a%=MOD;
	}
	return res;
}

void precalc()
{
	// facs and 1/facs in MOD
	fac[0] = fac[1] = 1;
	invfac[0] = invfac[1] = 1;
	for (ll i = 2; i < MAXN; ++i)
		fac[i] = (fac[i-1] * i) % MOD;
	for (ll i = 2; i < MAXN; ++i)
		invfac[i] = fast(fac[i], MOD-2);

	// conbs and perms
	for (ll i = 0; i <= n; ++i)
		n_comb[i] = (fac[n] * ((invfac[i] * invfac[n-i]) % MOD )) % MOD;

	m_nper[n] = 1; // 0: P(m-0, n-0), k: P(m-k, n-k)
	for (ll i = n-1; i >= 0; --i)
		m_nper[i] = (m_nper[i+1] * (m - (i))) % MOD;
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	precalc();

	ll ans = 0;

	for (ll i = 0; i <= n; ++i)
	{
		ll val = (n_comb[i]* m_nper[i]) % MOD;

		// TRACE(i, n_comb[i], m_nper[i]);

		ans += val * (1 - 2*(i%2));
		ans %= MOD;
	}

	cout << ((ans * m_nper[0])%MOD + MOD) % MOD << endl;
}

/* stuff you should look for
	* ll overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

Measured memory_bytes: 19128