akhauriyash/Code-Regression huggingface dataset:
import itertools
N, M, R = map(int, input().split())
INF = 2 ** 63 - 1
d = [[INF for i in range(N+1)] for j in range(N+1)]
r = list(map(int, input().split()))
r = list(itertools.permutations(r))
for i in range(M):
    a, b, c = map(int, input().split())
    d[a][b] = c
    d[b][a] = c
for i in range(N+1):
    d[i][i] = 0


for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = INF
for path in r:
    anstemp = 0
    for i in range(R-1):
        anstemp += d[path[i]][path[i+1]]
    ans = min(anstemp, ans)
print(ans)


Measured memory_bytes: 73180
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double minute_angle = m * M_PI * 2 / 60;
    double hour_angle = h * M_PI * 2 / 12 + m * M_PI * 2 / 12 / 60;
    double p = abs(minute_angle - hour_angle);
    // cout << M_PI * 2 - p << " " << cos(p) << endl;
    double c = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(p));

    cout << fixed << setprecision(20) << c << endl;
    return 0;
}

Measured memory_bytes: 4224
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(long long int i=a; i<n; i++)
#define rloop(i,a,n) for(long long int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcount(a)
#define mod 1000000007
#define ll long long int
#define ull unsigned long long int 
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define stkll stack<ll>
#define qll queue<ll>
#define pqll priority_queue<ll>
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power)
{
    ll ans=1;
    while(power>0)
    {
        if(power%2==1)
        {
            ans=(ans*B)%mod;
        }
        B=(B*B)%mod;
        power/=2;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1)
    { 
        return false; 
    }
    if(n<=3)
    { 
        return true;
    } 
    if(n%2==0 || n%3==0) 
    {
        return false; 
    }
    for(ll i=5; i*i<=n; i+=6) 
    {
        if(n%i==0 || n%(i+2)==0) 
        {
            return false; 
        }
    }
    return true; 
}
using namespace std;
int main() 
{
    FAST
    FO
    FI
    int r;
  	IN r;
  	OUT r*r<<endl
    return 0;
}

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import qualified Data.Map.Strict as Map

readInt :: B.ByteString -> Maybe (Int,B.ByteString)
readInt xs = do
    (x,ys) <- B.readInt xs
    return (x,B.tail ys)

analyze :: Map.Map Int Int -> [Int] -> Map.Map Int Int
analyze xx []     = xx
analyze xx (x:xs) = case Map.lookup x xx of
    Just y -> analyze (Map.update (\x -> Just (x+1)) x xx) xs
    Nothing -> analyze (Map.insert x 1 xx) xs

fun :: Int -> VU.Vector Int -> Map.Map Int Int -> Int -> Int
fun sums yy xx m = case Map.lookup (yy VU.! m) xx of
    Just z -> -z + 1 + sums
    Nothing -> sums

main :: IO ()
main = do
    n <- readLn
    as <- VU.unfoldrN n readInt <$> B.getLine
    let bs = VU.toList as
    let cs = analyze Map.empty bs
    let sums = Map.foldl' (\a b -> a + ((b*(b-1)) `div` 2)) 0 cs
    let ans = map (fun sums as cs) [0..n-1]
    mapM_ print ans

Measured memory_bytes: 28284
export class Main {
  static main(input): string {
    const [l, r]: number[] = input.split("\n")[0].split(" ").map(a => parseInt(a));
    const range = [];
    if (r - l >= 2019) {
      return "0";
    } else {
      for (let i = l; i <= r; i++) {
        range.push(i % 2019);
      }
    }
    let min = Infinity;
    for (let i = 0, len = range.length; i < len - 1; ++i) {
      for (let j = i + 1; j < len; ++j) {
        const p: number = (range[i] * range[j]) % 2019;
        if (p < min) {
          min = p;
        }
      }
    }
    return `${min}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define maxn 150005
typedef long long ll;
#define pii pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
int ch[maxn][2];
ll val[maxn][2];
ll len[maxn];
vector<pii>v[maxn];
pii tmp[maxn<<3]; int tot;
bool dfs(int u,ll mid)
{
    v[u].clear();
    if(!ch[u][0])
    {
        v[u].pb(mp(len[u],len[u]));
        return 1;
    }
    int ls=ch[u][0],rs=ch[u][1];
    if((dfs(ls,mid)|dfs(rs,mid))==0) return 0;
    tot=-1; if(v[rs].size()<v[ls].size()) swap(ls,rs);
    //sort(v[ls],v[ls]+v[ls].size()); sort(v[rs],v[rs]+v[rs].size());
    for(int i=0,j=v[rs].size()-1;i<v[ls].size();i++)
    {
        while(j>=0&&v[ls][i].fi+v[rs][j].fi>mid) j--; if(j<0) break;
        tmp[++tot]=mp(v[ls][i].se+len[u],v[rs][j].se+len[u]);
        tmp[++tot]=mp(v[rs][j].se+len[u],v[ls][i].se+len[u]);
    }
    if(tot==-1) return 0;
    sort(tmp,tmp+tot+1); ll h=1ll<<60;
    for(int i=0;i<=tot;i++)
    {
        if(tmp[i].se>=h) continue;
        v[u].pb(tmp[i]); h=tmp[i].se;
    }
    return 1;
}
int main ()
{
    int n; scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int f,w; scanf("%d%d",&f,&w); len[i+1]=1ll*w;
        if(!ch[f][0]) ch[f][0]=i+1,val[f][0]=1ll*w;
        else ch[f][1]=i+1,val[f][1]=1ll*w;
    }
    ll l=0,r=1ll<<40,ans;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(dfs(1,mid)) ans=mid,r=mid-1;
        else l=mid+1;
        /*for(int i=1;i<=n;i++)
        {
            printf(" %d : ",i);
            for(int j=0;j<v[i].size();j++)
            {
                printf(" (%d , %d) ",v[i][j].fi,v[i][j].se);
            }
            printf("\n");
        }
        printf("\n");*/
    }
    printf("%lld\n",ans); return 0;
}

Measured memory_bytes: 32424
<?php
  fscanf(STDIN,"%d",$n);
  $a = preg_split("/ /",trim(fgets(STDIN)));
  $sum = 0;
  for($i=0;$i<$n;$i++){
    $sum += $a[$i];
  }
  $presum = 0;
  for($i=1;$i<$n;$i+=2){
    $presum += $a[$i];
  }
  $ans[0] = $sum - 2*$presum;
  for($i=1;$i<$n;$i++){
      $ans[$i] = ($a[$i-1]-$ans[$i-1]/2)*2;
  }
  echo($ans[0]);
  for($i=1;$i<$n;$i++){
    echo(" ".$ans[$i]);
  }

Measured memory_bytes: 36388
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main(){
	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	ll m = max(A, max(B, C));
	ll ans = m*pow(2, K);
	ans = ans - m + A + B + C;
	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }
  else if(a+b<c+d){
    cout<<"Right"<<endl;
  }
  else{
    cout<<"Balanced"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N;
ll a[200010], b[200010];

/*==================================================*/
/*function*/

//最終的なxorにおいて, 下からd桁目が 1 かどうか判定
bool check(int d){
    ll t = (1 << d);

    //下d桁目までのみが必要
    ll aa[200010], bb[200010];
    REP(i,0,N){
        aa[i]  = a[i] % (2*t);
        bb[i]  = b[i] % (2*t);
    }

    //繰り上がりの条件分岐のために分類
    vector<ll> sb[2];
    REP(i,0,N){
        //if(bb[i] & t) sb[1].push_back(bb[i] - t);
        if(bb[i] & t) sb[1].push_back(bb[i] % t);
        else sb[0].push_back(bb[i]);
    }

    sort(sb[0].begin(), sb[0].end());
    sort(sb[1].begin(), sb[1].end());

    ll cnt = 0;

    REP(i,0,N){
        ll ta = aa[i];

        //a'=a[i]%2^(d+1),b'=b[i]%2^(d+1)

        //a',b'それぞれ(2^d)引いてのしきい値t(2^d)との大小比較
        //=> d桁目のビットの1/0をチェック (d桁目について, 繰り上がって1になるか or もとの1が残るか)

        if(ta & t){
            //ta -= t;
            ta %= t;

            //(d-1)桁目からの繰り上がりがなくa'のd桁目の1が残る (逆に繰り上がりがあるとd桁目が0になる)
            //((a'-(2^d))+(b'-(2^d))) < (2^d)
            cnt += lower_bound(sb[0].begin(), sb[0].end(), t - ta) - sb[0].begin(); //しきい値を超えない値(=未満)が欲しいのでこのまま

            //a'とb'の各d桁目の1で繰り上がるため,(d-1)桁目からの繰り上がりが必要
            //((a'-(2^d))+(b'-(2^d))) >= (2^d)
            cnt +=  sb[1].size()
                    - (lower_bound(sb[1].begin(), sb[1].end(), t - ta) - sb[1].begin()); //しきい値以上がほしいので"未満"のサイズとの差分
        }else{
            //a'とb'のどちらのd桁目にも0がないため,(d-1)桁目からの繰り上がりが必要
            //((a'-(2^d))+(b'-(2^d))) >= (2^d)
            cnt += sb[0].size()
                   -  (lower_bound(sb[0].begin(), sb[0].end(), t - ta) - sb[0].begin());

            //(d-1)桁目からの繰り上がりがなくb'のd桁目の1が残る (逆に繰り上がりがあるとd桁目が0になる)
            //((a'-(2^d))+(b'-(2^d))) < (2^d)
            cnt += lower_bound(sb[1].begin(), sb[1].end(), t - ta) - sb[1].begin();
        }
    }

    return cnt % 2 == 1;
}

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N) cin>>a[i];
    REP(i,0,N) cin>>b[i];

    ll ans = 0;
    REP(d,0,29){
        if(check(d)) ans += (1 << d);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 11040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string str[101];
int main() {
    int n, l;
    cin >> n >> l;
    for (int i = 0; i < n; ++i) {
        cin >> str[i];
    }
    sort(str, str + n);
    for (int i = 0; i < n; ++i) {
        cout << str[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/

int main(){
    int a, b; cin >> a >> b;
    cout << a * b / 2  << endl;
    
}

Measured memory_bytes: 256
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n,k,t; ll d; cin >> n >> k;
    vector<vector<ll>> t_list(n);
    vector<pair<ll,int>> dish(n);
    rep(i,n){
        cin >> t >> d;
        t--;
        dish[i] = make_pair(d, t);
    }
    sort(dish.begin(), dish.end(), greater<pair<ll,int>>());
    
    rep(i,n) t_list[dish[i].second].push_back(dish[i].first);

    sort(t_list.begin(), t_list.end(), [&](vector<ll> a, vector<ll> b){
        if(a.size() == 0) return false;
        else if(b.size() == 0) return true;
        return a[0] > b[0];
    });
    
    ll d_sum = 0LL;
    vector<bool> isUsed(n, false);
    priority_queue<ll, vector<ll>, greater<ll>> disposable_que; // 取り除けるネタの美味しさを管理
    priority_queue<ll> new_sushi_que; // 新種を管理 
    ll ncnt = 0LL; // 種数
    rep(i,k){ // k個選ぶ
        if(isUsed[dish[i].second]) disposable_que.push(dish[i].first);
        else{
            ncnt++;
            isUsed[dish[i].second] = true;
        }
        d_sum += dish[i].first;
    }

    for(int i = ncnt; i < t_list.size(); ++i){
        if(t_list[i].size() > 0) new_sushi_que.emplace(t_list[i][0]);
    }

    ll ret = ncnt*ncnt + d_sum;
    while(!new_sushi_que.empty() && !disposable_que.empty()){
        d_sum += new_sushi_que.top() - disposable_que.top();
        new_sushi_que.pop(); disposable_que.pop();
        ncnt++;
        ll tmp = ncnt*ncnt + d_sum;
        ret = max(ret, tmp);
    }

    cout << ret << endl;
}

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

#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A,*B;

  int C[VMAX+1];
  int n,i,j;
  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0;i<=VMAX;i++)C[i]=0;

  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++)C[i]=C[i]+C[i-1];

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

}



Measured memory_bytes: 9600
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	double l;
	cin>>l;
	printf("%.10lf\n", l/3.0*l/3.0*l/3.0);
	return 0;
}


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

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();

        if (n % 1000 == 0) {
            System.out.print(0);
        } else {
            System.out.print(1000 - n % 1000);
        }
    }


}



Measured memory_bytes: 35796
from itertools import combinations_with_replacement
n,m,q = map(int,input().split())
abcd = [0] * q
for i in range(q):
    abcd[i] = list(map(int,input().split()))
comb = combinations_with_replacement([i for i in range(1,m+1)], n)
a = list(comb)
ans = [0] * len(a)
for i in range(len(a)):
    for j in range(q):
        if a[i][abcd[j][1]-1] - a[i][abcd[j][0]-1] == abcd[j][2]:
            ans[i] += abcd[j][3]
print(max(ans))



Measured memory_bytes: 25072
# ARC083C - Sugar Water (ABC074C)
# input
a, b, c, d, e, f = list(map(int, input().rstrip().split()))
A = a * 100
B = b * 100

# default values
x, y = min(a, b) * 100, 0  # density may be 0%
dens = y / x


# exhaustive search
for i in range(f // A + 1):
    for j in range(((f - A * i) // B) + 1):
        if i == 0 and j == 0:
            continue
        water = i * A + j * B
        rest = f - water
        for k in range(rest // c + 1):
            for l in range((rest - c * k) // d + 1):
                sugar = c * k + d * l
                total = water + sugar

                if sugar / total > e / (e + 100):  # compare to e (the max density)
                    break
                else:
                    if sugar / total > dens:
                        dens = sugar / total
                        x, y = total, sugar
print(x, y)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int d,n;
    cin >> d >> n;
    if(n!=100){
        rp(i,d) n*=100;
        print(n);
        return;
    }
    if(d==0) print(101);
    else if(d==1) print(10100);
    else print(1010000);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int H,R;
    scanf("%d %d",&H,&R);
    if(H+R==0){
        printf("0\n");
    }else if(H+R<=-1){
        printf("-1\n");
    }else if(H+R>=1){
        printf("1\n");
    }
    return 0;
}


Measured memory_bytes: 2692
#include<stdio.h>
#include<string.h>
int main()
{
	char s[10+5];
	scanf("%s",s);
	int len=strlen(s);
	int i,flag=0,tot=0;
	if(s[0]=='A') {
		for(i=2;i<len-1;i++)
			if(s[i]=='C') flag++;
		for(i=1;i<len;i++)
		if(s[i]>='a'&&s[i]<='z' ) tot++;
	}
	if(flag==1 && tot+2==len) printf("AC\n");	
	else printf("WA\n");
	return 0;	
} 

Measured memory_bytes: 128
// if文による条件分岐　比較演算子
#include <stdio.h>
int main(void){
    int a,b;
    char buf[100];
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%d %d",&a,&b);
    int mx;
    mx=a+b;
    if (mx<=(a-b)) {
        mx=a-b;
    }
    if (mx<=(a*b)) {
        mx=a*b;
    }
    printf("%d",mx);
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
string S, T;

int main() {
	cin >> S >> T;

	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) ans++;
	}
	cout << ans;
	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,h1,h2,k1,k2,h,k;
	scanf("%d %d %d %d %d %d %d %d",&h1,&h2,&k1,&k2,&a,&b,&c,&d);
	h=h1*a+(h1/10)*c+h2*b+(h2/20)*d;
	k=k1*a+(k1/10)*c+k2*b+(k2/20)*d;
	if(h>k){
	printf("hiroshi\n");
	}
	else if(h<k){
	printf("kenjiro\n");
	}
	else {
	printf("even\n");
	}
	return 0;
}
	
	


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i++)
	{
		if ((i%2==0 && S[i] =='L')|| (i % 2 == 1 && S[i] == 'R'))
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int n=0;
  for(int i=0;i<4;i++){
    if(s[i]=='+'){
      n++;
    }else{
      n--;
    }
  }
  cout<<n<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define scs(ch) scanf("%s", ch)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

ll ara[1000],cnt[22][22];
char ch[100];

int main()
{
    ll n,m,i,j,k,a,b,c,x,y,z,ans=0;
    scl(n);
    for(i=0;i<n;i++){
        scs(ch);

        for(z=0,j=0,k=0;ch[z]!='\0';z++)
        {
            if(ch[z]=='.'){
                k++;
                continue;
            }
            k*=10;
            j*=10;
            j+=ch[z]-'0';
        }
        if(k==0)k=1;
        x=__gcd(j,k);
        j/=x;
        k/=x;
        //cout<<j<< " " <<k<<endl;
        //if(k>=10000)continue;
        a=0;
        while(j%5==0){
            j/=5;
            a++;
        }
        while(k%5==0){
            k/=5;
            a--;
        }
        b=0;
        while(j%2==0){
            j/=2;
            b++;
        }
        while(k%2==0){
            k/=2;
            b--;
        }
        a+=10;
        b+=10;
        a=min(a,20ll);
        b=min(b,20ll);
        //cout<<i<< " " <<a<< " " <<b<<endl;
        for(j=0;j<21;j++){
            for(k=0;k<21;k++){
                if(j+a>=20 && k+b>=20){
                    ans+=cnt[j][k];
                }
            }
        }
        //cout<<ans<<endl<<endl;
        cnt[a][b]++;

    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
const int N = 2e3 + 3;
const int S = 2e6 + 2e5;
int n;
int arr[N];
int sum;
bitset < S > bit;
int main(){
	cin >> n;
	for(int i = 1 ; i <= n ; ++i){
		cin >> arr[i];
		sum += arr[i];
	}
	int ans;
	sum = sum + 1 >> 1;
	bit.set(0);
	for(int i = 1 ; i <= n ; ++i){
		bit |= bit << arr[i];
	}
	for(int j = sum ; ; ++j){
		if(bit.test(j)){
			ans = j;
			break;
		}
	}
	printf("%d\n" , ans);
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] =new int[N];
		int B[] =new int[9];
        for(int i = 0; i < N; i++){
            A[i]=sc.nextInt();
            if(A[i]<400){
                B[0]++;
            }else if(A[i] < 800) B[1]++;
            else if(A[i] < 1200) B[2]++;
            else if(A[i] < 1600) B[3]++;
            else if(A[i] < 2000) B[4]++;
            else if(A[i] < 2400) B[5]++;
            else if(A[i] < 2800) B[6]++;
            else if(A[i] < 3200) B[7]++;
            else B[8]++;
        }
        
        int min = 0;
    
        for(int i = 0 ; i < 8 ; ++i){
        if(B[i] != 0){
            min++;
            }
        }
    
        int max = min + B[8];
        if(min == 0) min++;
    
        System.out.println(min+" "+max);
 
    }
}


Measured memory_bytes: 38760
N, M, X = map(int, input().split())
item = []
ans = []
for i in range(N):
  item.append(list(map(int, input().split())))
for i in range(2**N):
  bag = []
  money = 0
  for j in range(N):
    if ((i>>j) & 1):
      bag.append(item[j])
  if bag == []:
    continue
  total = [0] * M
  for k in bag:
    money += k[0]
    for l in range(1, M+1):
      total[l-1] += k[l]
  if min(total) >= X:
    ans.append(money)
if ans == []:
  print(-1)
else:
  print(min(ans))

Measured memory_bytes: 9268
#include <bits/stdc++.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++)
#define _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

string s, t;

int main(){
    cin >> s >> t;
    int ans = -1;
    for(int i=0; i<s.size()-t.size()+1; i++){
        int cnt = 0;
        string tmp = s.substr(i, t.size());
        for(int j=0; j<t.size(); j++){
            if(tmp[j] == t[j]) cnt++;
        }
        if(cnt > ans) ans = cnt;
    }
    cout << t.size() - ans << endl;
    return 0;
}

Measured memory_bytes: 3628
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
p=nl()
q=nl()

cnt=0

pnum=0
qnum=0

def comb(nums):
  global cnt
  global pnum
  global qnum
  if len(nums)==n:
    cnt+=1
    if nums == p:
      pnum = cnt
    if nums == q:
      qnum = cnt
    return
  for i in range(1,n+1):
    if i not in nums:
      comb(nums+[i])


comb([])

print(abs(pnum-qnum))


Measured memory_bytes: 52188
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        ll r = n/i;
        ans += r*(r+1)/2 * i;
    }
    cout << ans << endl;
    

}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <map>
#include<set>
using namespace std;

int main() {
	int N;
	set<string> s;
	cin >> N;
	for (int i = 0; i < N;i++) {
		string a;
		cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;
}


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

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

int main(){
    ll n;
    cin>>n;
    vector<ll> v(n);
    rep(i,n){
        cin>>v[i];
    }
    ll sum = 0;
    ll pre = v[0];
    for(int i=1;i<n;i++){
        if(v[i]<pre){
            sum+=pre-v[i];
        }else{
            pre=v[i];
        }
    }
    cout<<sum<<endl;
    
return 0;
}


Measured memory_bytes: 4772
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

ll n;
ll a[212345];
ll keta[31]={};

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

  ll tmp;
  for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);
    tmp = a[i];
    int kt=0;
    while(tmp>0){
      if(tmp%2==1) keta[kt]++;
      kt++;
      tmp/=2;}
  }
  //xor(all)
  for(int i=0;i<31;i++){
    keta[i] = keta[i]%2;
    //printf("%lld ",keta[i]);
  }

  ll ans;
  for(int i=0;i<n;i++){
    ans=0;
    tmp=a[i];
    ll mul=1;
    for(ll j=0;j<31;j++){
      if(tmp%2 != keta[j]) ans+=mul;
      mul*=2;
      tmp/=2;}
    printf("%lld ",ans);
  }
  
  
  printf("\n");
  
  return 0;
}


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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int a, b;

signed main()
{

    cin >> a >> b;

    if ((a + b) % 2 == 0)
    {
        cout << (a + b) / 2 << endl;
    }

    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, m, i, j, k;
    char c;
    int card[4][13] = {0};
    char mark[4] = {'S', 'H', 'C', 'D'};
   
    scanf("%d\n",&n);
    
    for(i=0; i<n; i++) {
        scanf("%c %d\n", &c, &m);
        for(j=0; j<4; j++) {
            if (c == mark[j]) {
                card[j][m-1] = 1;
                break;
            }
        }
    }
    
    for(j=0; j<4; j++) {
        for(k=0; k<13; k++) {
            if (card[j][k] == 0) {
                printf("%c %d\n", mark[j], k+1);
            }
        }
    }
    
    return 0;
}



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

using namespace std;

const int N = 1e5 + 10;

int n, a[N];

bool cmp(int a, int b) {
  return a > b;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (a[i + 1] == i) {
      int pos = i + 1;
      while (pos < n && a[pos + 1] == i) pos++;
      if (a[i] > i) {
        if (!((a[i] - i) & 1) && !((pos - i) & 1)) {
          puts("Second");
          return 0;
        } else {
          puts("First");
          return 0;
        }
      } else {
        if (!((pos - i) & 1)) {
          puts("Second");
          return 0;
        } else {
          puts("First");
          return 0;
        }
      }
    }
    if (a[i + 1] < i) {
      if (!((a[i] - i) & 1)) {
        puts("Second");
        return 0;
      } else {
        puts("First");
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n;
    scanf("%lld",&n);
    ll a[n],buka[n];
    rep(i,0,n) buka[i]=0;
    rep(i,1,n){
        scanf("%lld",&a[i]);
        buka[a[i]-1]++;
    }
    rep(i,0,n){
        printf("%lld\n",buka[i]);
    }

    
    // printf("%lld\n");
    return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int maxn = 305;

struct Floyd {

    int n;
    int d[maxn][maxn];
    bool vis[maxn][maxn];
    bool ok;

    void Init(int n) {
        this->n = n;
        memset(vis,false,sizeof(vis));
    }

    void AddEdge(int from, int to, int dist) {
        d[from][to] = dist;
    }

    void floyd() {
        rep(k,1,n+1) rep(i,1,n) rep(j,i+1,n+1) {
            if (d[i][k] + d[k][j] < d[i][j]) {
                ok = false; return ;
            }
            if (d[i][k] + d[k][j] == d[i][j] && i != j && i != k && j != k) {
                vis[i][j] = true;
                //cout<<i<<' '<<j<<' '<<k<<endl;
            }
        }
    }


};

int main ()
{
    int N;
    scanf("%d",&N);
    Floyd ans;
    ans.Init(N);
    rep(i,1,N+1) rep(j,1,N+1) {
        int w;
        scanf("%d",&w);
        ans.AddEdge(i,j,w);
    }
    //de(tot);
    ans.floyd();
    if (ans.ok) {
        ll len = 0;
        rep(i,1,N) rep(j,i,N+1)
            if (!ans.vis[i][j]) {
                //cout<<i<<' '<<j<<endl;
                len += ans.d[i][j];
            }
        printf("%lld\n",len);
    } else {
        printf("-1\n");
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  getline(cin,s);
  cout<<"A";
  for(int i=0;i<(s.length());i++)
  {
  	if(s[i]==' ')
  	cout<<s[i+1];
  }
	
return 0;	
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        long X=sc.nextLong();
        
        long now=100;
        int count=0;
        
        while(now<X){
            now*=1.01;
            count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 35836
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
lower = 0
upper = 10**9
while upper.ceil != lower.ceil
  mid = (upper+lower).to_f/2
  x = 0
  a.each do |i|
    x += ((i.to_f / mid)-1).ceil
  end
  if x <= k
    upper = mid
  else
    lower = mid
  end
end

puts upper.ceil

Measured memory_bytes: 27944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int n, q;	cin >> n >> q;
  	string s;	cin >> s;
  	vector<int> l(q), r(q);	rep(i,q) cin >> l.at(i) >> r.at(i);
  	
  	vector<int> nm(n,0);
  	for(int i = 1; i < n; i++){
    	if(s.at(i-1) == 'A' && s.at(i) == 'C') nm.at(i-1)++;
    }
  	
  	vector<int> sm(n+1,0);
  	rep(i,n){
    	sm.at(i+1) = sm.at(i) + nm.at(i);
    }
  	
  	rep(i,q){
    	cout << sm.at(r.at(i)-1) - sm.at(l.at(i)-1) << endl;
    }
  	rep(i,n+1){
 //   	cout << sm.at(i) << endl;
    }
}

Measured memory_bytes: 2688
#include <iostream>
 
using namespace std;
 
int N, K, A[5000];
bool dp1[5002][5001];
bool dp2[5002][5001];
 
 
int main()
{
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] = min(A[i], K);
  }
 
  dp1[0][0] = true;
  for(int i = 0; i < N; i++) {
    for(int j = K; j >= A[i]; j--) {
      dp1[i + 1][j] |= dp1[i][j - A[i]];
    }
    for(int j = K; j >= 0; j--) {
      dp1[i + 1][j] |= dp1[i][j];
    }
  }
 
  dp2[N][0] = true;
  for(int i = N - 1; i >= 0; i--) {
    for(int j = K; j >= A[i]; j--) {
      dp2[i][j] |= dp2[i + 1][j - A[i]];
    }
    for(int j = K; j >= 0; j--) {
      dp2[i][j] |= dp2[i + 1][j];
    }
  }
 
  int ret = N;
  for(int i = 1; i <= N; i++) {
    bool flag = false;
   // u can optimise the below part using prefix sums over dp array
    for(int j = K - A[i - 1]; j < K; j++) {
     
      for(int k = 0; k <= j; k++) {
        int other = j - k;
        if(0 <= other && other < K) {
          if(dp1[i - 1][k] && dp2[i][other]) {
            flag = true;
            break;
          }
        }
      }
      if(flag) break;
    }
    ret -= flag;
  }
 
  cout << ret << endl;
}

Measured memory_bytes: 49152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  int add = 0;
  if(S.at(0) == 'o') add++;
  if(S.at(1) == 'o') add++;
  if(S.at(2) == 'o') add++;
  
  cout << 700 + (add*100) << endl;
}

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

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    //s.size()=N;
    int cr = 0,cb = 0;
    rep(i,N)
        if(s[i]=='R') cr++;
        else cb++;
    if (cr>cb) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
//const int mod = 1e9+9;
/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
*void exEuclid(int a, int b){
	if(b==0){x = 1; y=0; d=a; return ;}
	exEuclid(b, a%b);
	int x1 = y;
	int y1 = x-(a/b)*y;
	x = x1; 100000
	y = y1;
} 
* */
//===========================================================//
int n;
const int nx = 1e5+5;
int ac[nx][3];
int dp[3][nx];
int go(int a, int i){
	if(i == n) return 0;
	if(dp[a][i] != -1) return dp[a][i];
	int& ans = dp[a][i];
	
	if(a==0){
		ans=max(ans, go(1, i+1)+ac[i][0]);
		ans=max(ans, go(2, i+1)+ac[i][0]);
	}
	if(a==1){
		ans=max(ans, go(0, i+1)+ac[i][1]);
		ans=max(ans, go(2, i+1)+ac[i][1]);
	}
	if(a==2){
		ans=max(ans, go(0, i+1)+ac[i][2]);
		ans=max(ans, go(1, i+1)+ac[i][2]);
	}
	
	return ans;
}
int main(){
	cin>>n;
	for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1]>>ac[i][2];
	memset(dp, -1, sizeof dp);
	cout<<max(go(0,0),max(go(1,0),go(2,0)))<<"\n";
	return 0;
}

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

using namespace std;

#define int long long

const int MOD=1000000007;

signed main(){
    int n=0;
    string str[2];
    int ans=1;
    cin >> n;
    cin >> str[0];
    cin >> str[1];
    int i=0;
    int before=0;
    if(str[0][0]==str[1][0]){
        ans*=3;
        i=1;
        before=1;
    }else{
        ans*=6;
        i=2;
        before=2;
    }
    for(;i<n;i++){
        if(str[0][i]==str[1][i]){
            if(before==1){
                ans*=2;
            }else{
                ans*=1;
            }
            before=1;
        }else{
            if(before==1){
                ans*=2;
            }else{
                ans*=3;
            }
            before=2;
            i++;
        }
        ans%=MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

struct UnionFind{
    vl par,dist;
    UnionFind(int x){par.assign(x,-1); dist.assign(x,0);}
    ll find(ll x){return par[x]<0?x:find(par[x]);}
    ll depth(ll x){return par[x]<0?0:depth(par[x])+dist[x];}
    bool same(ll x,ll y){return find(x)==find(y);}
    ll size(ll x){return -par[find(x)];}
    ll diff(ll x,ll y){return same(x,y)?depth(x)-depth(y):LINF;}
    void unite(ll x,ll y,ll k=0){
        k+=depth(y); k-=depth(x); k=-k;
        x=find(x); y=find(y);
        if(x==y)return;
        if(size(x)<size(y)){swap(x,y);k=-k;}
        par[x]+=par[y]; par[y]=x; dist[y]=k;
    }
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,x,y,z;
	cin>>n>>m;
	int ans=n;
	UnionFind u(n);
	rep(i,m){
		cin>>x>>y>>z;
		x--;y--;
		if(!u.same(x,y))ans--;
		u.unite(x,y);
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 100;
string s, t;
int mem[N][N];
pair<int, int> to[N][N];
bool vis[N][N];

int dp(int i, int j) {
	if (i == s.size() || j == t.size()) {
		return 0;
	}
	if (vis[i][j]) {
		return mem[i][j];
	}
	vis[i][j] = true;

	int ans = dp(i + 1, j);
	to[i][j] = {1, 0};

	if (dp(i, j + 1) > ans) {
		ans = dp(i, j + 1);
		to[i][j] = {0, 1};
	}

	if (s[i] == t[j] && dp(i + 1, j + 1) + 1 > ans) {
		ans = dp(i + 1, j + 1) + 1;
		to[i][j] = {1, 1};
	}

	return mem[i][j] = ans;
}

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

	cin >> s >> t;

	int l = dp(0, 0);

	int i = 0, j = 0;
	while (i < s.size() && j < t.size()) {
		if (to[i][j].first && to[i][j].second) {
			cout << s[i];
		}

		int ni = i + to[i][j].first;
		int nj = j + to[i][j].second;
		i = ni, j = nj;
	}
	cout << endl;

	return 0;
}


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

""" def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

print(make_divisors(n))
#[1, 2, 3, 4, 6, 8, 12, 24] """

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table
li = prime_decomposition(n)
#print(prime_decomposition(n))
#[2, 2, 2, 3.0]
import collections
c = collections.Counter(li)
v_li = list(c.values())
#print(v_li)
#[3, 1]
ans = 0
for v in v_li:
    ans += 1
    tmp = 1
    while v >= tmp:
        v -= tmp
        tmp += 1
        if v >= tmp:
            ans += 1
print(ans)


Measured memory_bytes: 9532
#include<iostream>
#include<cstring>
#include<vector>
#include <set>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	if (n <= 599)
		cout << "8" << endl;
	else if (n <= 799)
		cout << "7" << endl;
	else if (n <= 999)
		cout << "6" << endl;
	else if (n <= 1199)
		cout << "5" << endl;
	else if (n <= 1399)
		cout << "4" << endl;
	else if (n <= 1599)
		cout << "3" << endl;
	else if(n<= 1799)
		cout << "2" << endl;
	else if(n<= 1999)
		cout << "1" << endl;

}

Measured memory_bytes: 3632
import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Main {
    public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
		 String a = sc.nextLine();
		 System.out.println(myFunction(a));
	}
	
	public static String myFunction(String s) {
		if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) return "Yes";
		return "No";
    }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

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

  double x1 = ceil(a / 0.08);
  double x2 = ceil(b / 0.1);

  double ans = -1;
  if (floor(0.1 * x1) == b) {
    ans = x1;
  }
  if (floor(0.08 * x2) == a) {
    if (ans == -1) ans = x2;
    else ans = min(ans, x2);
  }

  cout << ans << endl;
  return 0;
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int s;
  cin >> s;
  COUTS("0 0");
  COUTS("1000000000 1");
  const int nine_zeros = 1e9;
  int x = (nine_zeros - (s%nine_zeros))%nine_zeros;
  int y = (s+x) / nine_zeros;
  cout << x << " " << y;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

public class Main {

    public static void solve(InputReader in, PrintWriter out) throws Exception {

        int n = in.nextInt();
        int k = in.nextInt();


        int[] arr = new int[n+1];

        for(int i=1;i<=n;i++)
            arr[i]=in.nextInt();

        int[] dp = new int[n+1];

        dp[0]=0;
        dp[1]=0;
        dp[2]= Math.abs(arr[2]-arr[1]);


        for(int i=3;i<=n;i++)
        {
            int j=i;
            int c=1;
            dp[i]=Integer.MAX_VALUE;
            while(j-c>=1 && c<=k)
            {
                dp[i]= Math.min(dp[i],Math.abs(arr[i]-arr[j-c])+dp[j-c]);
                c++;
            }

        }
        out.println(dp[n]);

    }

    /////////////////////////////////////////////////////////


    private final static long hash(long x, long y) {
        x += offset;
        y += offset;
        return x << 32 | y;
    }

    private final static int offset = (int) 3e5;

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solve(in, out);
        out.close();
    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        private String nextToken() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(reader.readLine());
            return tokenizer.nextToken();
        }

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

        public int nextInt() throws IOException {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(nextToken());
        }

    }
}


Measured memory_bytes: 44052