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

ll dvs[] = {2,3,5};
ll cost[3], d, n;
unordered_map<ll, ll> dp;

ll solve(ll x){
  if(x <= 1) return x*d;
  if(dp.count(x)) return dp[x];

  ll res = LLONG_MAX;
  if(x < res/d) res = x*d;

  for(int i=0; i<3; i++){
    ll bwh = (x/dvs[i])*dvs[i];
    ll atas = ((x+dvs[i]-1)/dvs[i])*dvs[i];
    res = min(res, abs(x-bwh)*d + cost[i] + solve(bwh/dvs[i]));
    res = min(res, abs(x-atas)*d + cost[i] + solve(atas/dvs[i]));
  }
  return dp[x] = res;
}

int main(){

  ios_base :: sync_with_stdio(false);

  int T;
  cin >> T;
  while(T--){
    cin >> n;
    for(int i=0; i<3; i++) cin >> cost[i];
    cin >> d;
    dp.clear();
    cout << solve(n) << endl;
  }
  return 0;
}

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

using namespace std;

const int N = 1e5 + 100;

vector<int> adj[N];
int par[N], d[N];
queue<int> q;
int n, m;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n + m - 1; i++) {
		int v, u;
		cin >> v >> u;
		adj[--v].push_back(--u);
		d[u]++;
	}
	for (int i = 0; i < n; i++)
		if (d[i] == 0)
			q.push(i);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (auto u : adj[v]) {
			par[u] = v + 1;
			if (--d[u] == 0)
				q.push(u);
		}
	}
	for (int i = 0; i < n; i++)
		cout << par[i] << '\n';
}

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

int main()
{
    string s;
    cin>>s;
    if(s=="SUN")cout<<7<<endl;
    else if(s=="MON")cout<<6<<endl;
    else if(s=="TUE")cout<<5<<endl;
    else if(s=="WED")cout<<4<<endl;
    else if(s=="THU")cout<<3<<endl;
    else if(s=="FRI")cout<<2<<endl;
    else if(s=="SAT")cout<<1<<endl;
    return 0;
}


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

int V, Mod;
vector<vector<int>> es;
vector<ll> dp0, dp1, y;

void erase(vector<int>& v, int x) { v.erase(remove(v.begin(), v.end(), x), v.end()); }

ll dfs0(int u, int p)
{
	erase(es[u], p);
	for (int v : es[u]) dp0[u] = dp0[u] * (dfs0(v, u) + 1) % Mod;
	return dp0[u];
}

void dfs1(int u)
{
	int W = es[u].size();
	y[W] = 1;
	for (int i = W - 1; i >= 0; i--) y[i] = y[i + 1] * (dp0[es[u][i]] + 1) % Mod;
	ll x = 1;
	for (int i = 0; i < W; i++)
	{
		dp1[es[u][i]] = (dp1[u] + 1) * x % Mod * y[i + 1] % Mod;
		x = x * (dp0[es[u][i]] + 1) % Mod;
	}
	for (int v : es[u]) dfs1(v);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> V >> Mod;
	dp0 = vector<ll>(V, 1);
	dp1 = vector<ll>(V);
	y = vector<ll>(V + 1, 1);
	for (int i = 0; i < V; i++) es.emplace_back(vector<int>());
	for (int i = 0; i < V - 1; i++)
	{
		int x, y; cin >> x >> y;
		es[x - 1].push_back(y - 1);
		es[y - 1].push_back(x - 1);
	}
	dfs0(0, -1);
	dfs1(0);
	for (int u = 0; u < V; u++) cout << dp0[u] * (dp1[u] + 1) % Mod << "\n";
    return 0;
}


Measured memory_bytes: 13424
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b, c ] <- readInts
	putStrLn $ which "YES" "NO" $ b - a == c - b


Measured memory_bytes: 508
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
  static void Main(string[] args)
  {
    var nmLine = Console.ReadLine().Split(' ').Select(s => Int32.Parse(s)).ToArray();
    var N = nmLine[0];
    var M = nmLine[1];
    var Ps = new int[M];
    var Ys = new int[M];
    for (var i = 0; i < M; i++)
    {
      var pyLine = Console.ReadLine().Split(' ').Select(s => Int32.Parse(s)).ToArray();
      Ps[i] = pyLine[0];
      Ys[i] = pyLine[1];
    }

    var dict = new Dictionary<int, List<int>>();
    for (var i = 0; i < M; i++)
    {
      var m = i + 1;

      var p = Ps[i];

      if (!dict.ContainsKey(p))
      {
        dict[p] = new List<int>();
      }

      var y = Ys[i];

      dict[p].Add(y);
    }

    foreach (var pair in dict)
    {
      pair.Value.Sort();
    }

    var dictionary = new Dictionary<int, Dictionary<int, int>>();
    foreach (var pair in dict)
    {
      var p = pair.Key;
      if (!dictionary.ContainsKey(p))
      {
        dictionary[p] = new Dictionary<int, int>();
      }

      var ys = pair.Value;
      var ysCount = ys.Count();
      for (var i = 0; i < ysCount; i++)
      {
        var y = ys[i];
        dictionary[p][y] = i + 1;
      }
    }

    /*
    foreach (var p in dict)
    {
      Console.WriteLine(p.Key);
      foreach (var v in p.Value)
      {
        Console.WriteLine("  {0}", v);
      }
    }
    */

    for (var i = 0; i < M; i++)
    {
      var y = Ys[i];
      var p = Ps[i];
      var idx = dictionary[p][y];
      Console.WriteLine("{0:D6}{1:D6}", p, idx);
    }
  }
}


Measured memory_bytes: 56516
<?php
// Your code here!
    $x=0;
    $y=0;
    $num= intval(trim(fgets(STDIN)));
    while($line=trim(fgets(STDIN))){
        $line = explode(" ",$line);
        $a = strnatcmp($line[0],$line[1]);
        if($a<0){
            $x= $x+3;
        }elseif($a>0){
            $y=$y+3;
        }else{
            $x++;
            $y++;
        }
        
    }
    echo $y." ".$x."\n";
        


?>


Measured memory_bytes: 9240
mod = 10**9+7

h,w,k = map(int,input().split())
k = k-1
dp = [0]*1000 #dp[i]=i個縦棒がある時の横棒の引き方
dp[0]=1
dp[1]=1
dp[2]=2

for i in range(3,1000):
  dp[i] = (dp[i-1]+dp[i-2])%mod
  #i-1とi番目に横棒を引かないとき、横棒の置き方は1からi-1番目の置き方と同じ
  #i-1とi番目に横棒を引くとき、横棒の置き方は1からi-2番目の置き方と同じ（i-1とi-2の間には置けないから）
  #→iの横棒の置き方はf(i-1)+f(i-2) ※場合わけにおける組み合わせ総数

dp2=[[0 for j in range(w)] for i in range(h+1)] #上からi下がったところでj番目にいく縦線を引くようなあみだくじの総数

dp2[0][0] = 1
for i in range(h):
  for j in range(w):
    #dp[i][j]からdp[i+1][j]への遷移が起こる条件は
    #j-1とjの間、jとj+1の間に横棒がない
    #このような横棒の置き方は
    #（縦棒1から縦棒j-1の置き方）*（縦棒j+1からwまでの棒の置き方）

    dp2[i+1][j] = (dp2[i+1][j]+dp2[i][j]*dp[j]%mod*dp[w-j-1]%mod)%mod

    #dp[i][j]からdp[i+1][j-1]に遷移する条件
    #jとj-1の間に横棒がある
    #j-1とj-2の間、j+1とjの間に横棒がない
    #この置き方は
    #（縦棒1から縦棒j-2までの横棒の置き方）* （縦棒jから縦棒wまでの横棒の置き方置き方）
    if (j-1>=0):
      dp2[i+1][j-1]=(dp2[i+1][j-1]+dp2[i][j]*dp[j-1]%mod*dp[w-j-1]%mod)%mod

    #dp[i][j]からdp[i+1][j+1]への遷移が起こる条件は
    #j+1とjの間に横棒がある
    #jとj-1の間、j+2とj+1の間に横棒がない
    #この置き方は
    #(縦棒1から縦棒j-1の置き方)*(縦棒j+2*wまでの横棒の置き方)

    if (j+1<w):
      dp2[i+1][j+1]=(dp2[i+1][j+1]+dp2[i][j]*dp[j]%mod*dp[w-j-2]%mod)%mod


print(dp2[h][k])



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> P[51];
	int a, b;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		P[a].push_back(b);
		P[b].push_back(a);
	}
	for (int i = 1; i <= n; ++i)
	{
		cout << P[i].size() << endl;
	}
	return 0;
}

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

#define ll long long int

ll n;
ll h[100002];

ll memo[100002];

ll fil(ll s)
{
    if(s==n)return 0;
    if(memo[s]!=-1)return memo[s];

    ll ans=INT_MAX;
    for(ll i=s+1;i<=n && i<=s+2;i++)
    {
        ans=min(ans,fil(i)+abs(h[i]-h[s]));
    }
    memo[s]=ans;
    return ans;
}
int main()
{
    cin>>n;
    for(ll i=1;i<=n;i++)cin>>h[i];
    memset(memo,-1,sizeof(memo));

    cout<<fil(1);
}


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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int N;
    cin >> N;
    int A[N + 1];
    rep(i, N) cin >> A[i + 1];
    int ans = 0;
    rep(i, N) {
        if (A[A[i + 1]] == i + 1) ans++;
    }
    cout << ans / 2 << endl;



    return 0;
}


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

int main() {
  int p,q,r;
  cin >> p >> q >> r;
  vector<int> a={p,q,r};
  sort(a.begin(),a.end());
  cout << a.at(0)+a.at(1) << endl;
}



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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

const ll INF = 1e15;

struct city{
    ll x, y, p, ind;
};

bool xa(city x, city y) {
    return x.x < y.x;
}

bool ya(city x, city y) {
    return x.y < y.y;
}

int main() {
    vi pw3(16);
    pw3[0] = 1;
    FOR(i, 1, 15)
        pw3[i] = pw3[i - 1] * 3;
    int n; cin >> n;
    vector <city> ct(n);
    FOR(i, 0, n - 1) {
        cin >> ct[i].x >> ct[i].y >> ct[i].p;
        ct[i].ind = i;
    }
    vector <city> sx(ct), sy(ct);
    sort(all(sx), xa); sort(all(sy), ya);

    vvll xp(1 << n, vll(n)), yp(1 << n, vll(n));
    FOR(i, 0, (1 << n) - 1) {
        vi tx, ty;
        FOR(j, 0, n - 1) if (1 << j & i) {
            tx.pb(ct[j].x); ty.pb(ct[j].y);
        }

        tx.pb(0); ty.pb(0);
        // for (int k : tx) cout << k << ' ';
        // cout << endl;
        // for (int k : ty) cout << k << ' ';
        // cout << endl;
        FOR(j, 0, n - 1) {
            ll xmn = INF, ymn = INF;
            for (int k : tx) xmn = min(xmn, abs(k - ct[j].x));
            for (int k : ty) ymn = min(ymn, abs(k - ct[j].y));
            xp[i][j] = xmn, yp[i][j] = ymn;
            // cout << i << ' ' << j << ' ' << xp[i][j] << ' ' << yp[i][j] << endl;
        }
    }

    vll pc(n + 1, INF);
    FOR(j, 0, pw3[n] - 1) {
        int t = j;
        int xc = 0, yc = 0;
        int x_msk = 0, y_msk = 0;
        ROF(k, n - 1, 0) {
            if (t >= 2 * pw3[k]) {
                y_msk |= (1 << k);
                t -= 2 * pw3[k], yc++;
            }
            else if (t >= pw3[k]) {
                x_msk |= (1 << k);
                t -= pw3[k], xc++;
            }
        }
        ll sum = 0;
        FOR(i, 0, n - 1)
            sum += ct[i].p * min(xp[x_msk][i], yp[y_msk][i]);
        // cout << j << ' ' << sum << endl;
        int popcnt = xc + yc;
        // cout << popcnt << endl;
        pc[popcnt] = min(pc[popcnt], sum);
    }
    FOR(i, 0, n)
        cout << pc[i] << endl;
    
    // double tt = clock();
    // printf("%.3lf\n", tt / CLOCKS_PER_SEC);
}

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

#define N 999999+1
int prime[N];
void sieve(int en) {
  // prime[prime number] = 0
  // prime[not prime number] = 1
  for(int i=2;i<=(int)sqrt(en);i++) {
    for(int j=i*2;j<=en;j+=i) {
      prime[j] = 1;
    }
  }
}

int main() {
  int n;
  int max_n = 2;
  while(cin >> n) {
    if(n > max_n) {
      sieve(n);
    }
    int cnt = 0;
    for(int i=2;i<=n;i++) {
      if(prime[i] == 0)
        cnt++;
    }
    cout << cnt << endl;
  }
}

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

int main(){
    int n;  cin>>n;
    double x[n],y[n];

    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<n;i++)cin>>y[i];

    double max=0;
    for(int i=0;i<n;i++){
        if(max<abs(x[i]-y[i])) max = abs(x[i]-y[i]);
    }


    double d1=0,d2=0,d3=0;
    for(int i=0;i<n;i++){
        d1 += abs(x[i]-y[i]);

        d2 += pow(abs(x[i]-y[i]),2);
        d3 += pow(abs(x[i]-y[i]),3);

    }
    d2 = pow(d2,1.0/2.0);
    d3 = pow(d3,1.0/3.0);

    printf("%8lf\n",d1);
    printf("%8lf\n",d2);
    printf("%8lf\n",d3);
    printf("%8lf\n",max);

    return 0;
}



Measured memory_bytes: 3416
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
    string tmp = T.substr(0, T.size() - 1);
    if (S == tmp) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


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

// 内部定数
#define D_CARD_MAX		100000									// 最大カード枚数

// 内部構造体 - カード情報
typedef struct Card {
	int miVal;													// 値
	int miCnt;													// 枚数
} Card;

// 内部変数
static Card sz1Card[D_CARD_MAX];								// カード情報
static int siCCnt;												// カード情報数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// ソート関数 - カード情報 - 値昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	Card *lzpVal1 = (Card *)pzpVal1;
	Card *lzpVal2 = (Card *)pzpVal2;

	// 値昇順
	if (lzpVal1->miVal > lzpVal2->miVal) {
		return(1);
	}
	else if (lzpVal1->miVal < lzpVal2->miVal) {
		return(-1);
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// カード枚数取得
	int liCCnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liCCnt);

	// カード情報 - 取得
	for (i = 0; i < liCCnt; i++) {
#ifdef D_TEST
		fscanf(szpFpT, "%d", &sz1Card[i].miVal);
#else
		fscanf(stdin, "%d", &sz1Card[i].miVal);
#endif
		sz1Card[i].miCnt = 1;								// 枚数
	}

	// カード情報 - ソート
	qsort(sz1Card, liCCnt, sizeof(Card), fSortFnc);

	// カード情報 - 圧縮
	siCCnt = 1;
	for (i = 1; i < liCCnt; i++) {
		if (sz1Card[i].miVal == sz1Card[siCCnt - 1].miVal) {	// 値一致
			sz1Card[siCCnt - 1].miCnt++;							// 枚数
		}
		else {													// 値不一致
			sz1Card[siCCnt].miVal = sz1Card[i].miVal;				// 値セット
			siCCnt++;												// カード情報数
		}
	}

	// 重複３枚数以上を削除・重複２枚の数を取得
	int liDCnt = 0;
	int liTCnt = 0;
	for (i = 0; i < siCCnt; i++) {

		// 重複３枚数以上
		if (sz1Card[i].miCnt >= 3) {
			int liCnt = ((sz1Card[i].miCnt - 1) / 2) * 2;
			liDCnt += liCnt;
			sz1Card[i].miCnt -= liCnt;
		}

		// 重複２枚
		if (sz1Card[i].miCnt == 2) {
			liTCnt++;
		}
	}

	// 重複２枚の削除
	liDCnt += ((liTCnt + 1) / 2) * 2;

	// 結果セット
	sprintf(lc1Out, "%d\n", liCCnt - liDCnt);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string n; cin >> n;
    REP(i, n.length())
    {
        if(n[i] == '1') n[i] = '9';
        else if(n[i] == '9') n[i] = '1';
    }
    cout << n << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;



int main(){
	string s; cin>>s;
	int n=s.size();
	s='a'+s;
	
	
	bool comp=true;
	
	for(int i=1;i<=n; i++) if(s[i]!=s[n-i+1]) comp=false;
			
	for(int i=1; i<=(n-1)/2; i++) if(s[i]!=s[(n-1)/2-i+1]) comp=false;
	
	for(int i=(n+3)/2; i<=n; i++) if(s[i]!=s[n-i+(n+3)/2]) comp=false;
	
	if(comp) cout<<"Yes";
	else cout<<"No";
			
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <atcoder/all>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void)
{
    int N, M;
    cin >> N >> M;
    int a, b;
    dsu d(N + 1);
    for (int i = 0; i < M; i++)
    {
        cin >> a >> b;
        d.merge(a, b);
    }

    auto x = d.groups();
    cout << x.size() - 2 << endl;
    return 0;
}


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

int main(){
  string str[8];
  for(int i=0;i<8;i++){
    cin >> str[i];
  }
  cout << "90" << endl;
  for(int i=0;i<8;i++){
    for(int j=7;j>=0;j--){
      cout << str[j][i];
    }
    cout << endl;
  }
  cout << "180" << endl;
  for(int i=7;i>=0;i--){
    for(int j=7;j>=0;j--){
      cout << str[i][j];
    }
    cout << endl;
  }
  cout << "270" << endl;
  for(int i=7;i>=0;i--){
    for(int j=0;j<8;j++){
      cout << str[j][i];
    }
    cout << endl;
  }
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

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

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

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  if(b<a || n==1 && a!=b){
    cout<<0<<endl;
    return 0;
  }
  ll ans=(b*(n-1)+a)-(a*(n-1)+b)+1;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	if (a==1) a=100;
	if (b==1) b=100;
	if (a>b){
		cout<<"Alice";
	}else if (a==b){
		cout<<"Draw";
	}else{
		cout<<"Bob";
	}
	return 0;
} 

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

int main()
{
	long long N; cin >> N;
	long long a = 2, b = 1,c;
	for (int i = 2; i <= N; i++) {
		if (i%2)b+=a;
		else a+=b;
	}

	if (N % 2)cout << b << endl;
	else cout << a << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

void swap(long long &a, long long &b){
    long long c = a;
    a = b;
    b = c;
}

long long modadd(long long a, long long b, long long mod){
    return (a+b)%mod;
}

long long modsub(long long a, long long b, long long mod){
    long long c = (a-b)%mod;
    if(c < 0){
        c += mod;
    }
    return c;
}

long long modmul(long long a, long long b, long long mod){
    return ((a%mod) * (b%mod)) % mod;
}

long long modinv(long long a, long long mod) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

long long moddiv(long long a, long long b, long long mod) {
    return ((a%mod) * (modinv(b, mod))) % mod;
}


long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = modmul(res, a, mod);
        a = modmul(a,a,mod);
        n >>= 1;
    }
    return res;
}

long long modcomb(long long a, long long b, long long mod){
    long long x = 1;
    for(int i=0; i<b; i++){
        x = modmul(x, modsub(a,i,mod), mod);
    }
    long long y = 1;
    for(int i=0; i<b; i++){
        y = modmul(y, modsub(b,i,mod), mod);
    }
    return moddiv(x,y,mod);
}


int main()
{
    long long n, a, b;
    long long mod = 1000000007;
    scanf("%lld %lld %lld", &n, &a, &b);
    printf("%lld\n", modsub(modsub(modpow(2, n, mod), 1, mod), modadd(modcomb(n,a,mod), modcomb(n,b,mod), mod), mod));
    
    return 0;
}

Measured memory_bytes: 128
<?php

fscanf(STDIN, "%f %f %f", $a, $b, $C);

$S = $a * $b * sin(deg2rad($C)) / 2;
$L = sqrt($a**2 + $b**2 - 2*$a*$b*cos(deg2rad($C))) + $a + $b;
$h = $S * 2 / $a;

echo ("$S\n");
echo ("$L\n");
echo ("$h\n");



Measured memory_bytes: 9268
A, B, C, D = map(int, input().split())

takahasi_hp = A
aoki_hp = C

while(True):
    aoki_hp = aoki_hp - B
    if( aoki_hp <= 0):
        print("Yes")
        break

    takahasi_hp = takahasi_hp - D
    if( takahasi_hp <= 0):
        print("No")
        break


Measured memory_bytes: 9172
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)

sum = a.inject(:+)
kisu = 0
gusu = 0
for i in 0..n-1
  kisu += a[i%n] if i%2 == 0
  kisu -= a[i%n] if i%2 != 0
  gusu += a[(i+1)%n] if i%2 == 0
  gusu -= a[(i+1)%n] if i%2 != 0
end
ans = [kisu,gusu]
for i in 0..n-1
  if i % 2 == 0
    puts ans[0]
    ans[0] = ans[0] - 2*a[i%n] + 2 * a[(1+i)%n]
  else
    puts ans[1]
    ans[1] = ans[1] - 2*a[i%n] + 2 * a[(1+i)%n]
  end
end

Measured memory_bytes: 13324
from itertools import combinations
n = int(input())
name = [0 for i in range(5)]
for i in range(n):
    a = input()
    if a[0] in "MARCH":
        name[list("MARCH").index(a[0])] += 1
ans = 0
for h, j, k in combinations("01234", 3):
    ans += (name[int(h)] * name[int(j)] * name[int(k)])
print(ans)

Measured memory_bytes: 3188
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
#define N 4
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
int MDT[N*N][N*N];
struct Puzzle {
  vector<int> f;
  int space;
  int cost;
  int MD;
  int estimated;
  bool operator < (const Puzzle &s) const {
    return estimated > s.estimated;
  }
};
int getAllMD(Puzzle pz){
  int sum = 0;
  for(int i = 0; i < N * N; i++) {
    if(pz.f[i]==0) continue;
    sum += MDT[i][pz.f[i]-1];
  }
  return sum;
}
map<vector<int>, bool> checked;
priority_queue<Puzzle> que;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  // A* -> estimated = cost(これまでのコスト) + MD(今の状態と最終状態の差(ここではマンハッタン距離の総和))
  // マンハッタン距離計算
  for(int i = 0; i < N * N; i++) {
    for(int j = 0; j < N * N; j++) {
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
    }
  }
  Puzzle start;
  start.f.resize(N*N);
  FOR(i,0,N*N){
    cin >> start.f[i];
    if(start.f[i] == 0) {
      start.space = i;
    }
  }
  start.cost = 0;
  start.MD = getAllMD(start);
  start.estimated = start.cost + start.MD;
  que.push(start);
  checked[start.f] = true;

  while(!que.empty()){
    Puzzle now = que.top();
    que.pop();
    if(now.MD == 0) {
      cout << now.cost << endl;
      return 0;
    }
    checked[now.f] = true;
    int x = now.space % N;
    int y = now.space / N;
    FOR(i,0,4){
      int ny = y + dy[i];
      int nx = x + dx[i];
      if(ny < 0 || ny >= N || nx < 0 || nx >= N) continue;
      Puzzle next = now;
      next.space = ny * N + nx;
      next.cost++;
      next.MD -= MDT[ny * N + nx][next.f[ny * N + nx]-1]; // 空白になったので
      next.MD += MDT[y * N + x][next.f[ny * N + nx]-1];
      swap(next.f[ny * N + nx], next.f[y * N + x]);
      next.estimated = next.cost + next.MD;
      if(!checked[next.f] && next.estimated <= 45){
        que.push(next);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 242472
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp> 
#define int long long int
#define all(v) v.begin(),v.end() 
#define rev(v) v.rbegin(),v.rend()
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define en "\n"
using namespace std;
using namespace __gnu_pbds;
#define inp 200005

//dp[i][j] = min cost to combine range (i,j)
signed main() 
{
    ssd
    int i,j,k,n;
    cin>>n;
    vector<int> val(n+5);
    for(i=1;i<=n;i++) cin>>val[i];

    vector<vector<int>> dp(n+5, vector<int>(n+5,1e18+5));
    vector<int> pre(n+5,0);
    for(i=1;i<=n;i++)
    {
        pre[i] = pre[i-1] + val[i];
    }
    for(int l=n; l>=1; l--)
    {
        for(int r=l; r<=n; r++)
        {
            if(l==r) dp[l][r] = 0;
            else
            {
                for(i=l; i<r; i++)
                {
                    int sum = pre[r]-pre[l-1];
                    dp[l][r] = min(dp[l][i] + dp[i+1][r] + sum, dp[l][r]);
                }
            }
        }
    }
    cout<<dp[1][n];
    return 0;           
}

Measured memory_bytes: 4512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		int[][] abs = new int[n - 1][];
		for (int i = 0; i < abs.length; i++)
			abs[i] = new int[] { cin.nextInt(), cin.nextInt() };

		String ans = solve(n, abs);
		cout.println(ans);
	}

	private static String solve(int n, int[][] abs) {
		// Fennecの最善手：1からNに最短距離で向かう
		// Snukeの最善手：Nから1に最短距離で向かう

		ArrayList<ArrayList<Integer>> conn = new ArrayList<>();
		conn.add(null);
		for (int i = 1; i <= n; i++)
			conn.add(new ArrayList<>());
		for (int[] ab : abs) {
			conn.get(ab[0]).add(ab[1]);
			conn.get(ab[1]).add(ab[0]);
		}

		// ダイクストラ法
		PriorityQueue<int[]> q = new PriorityQueue<>((dhc1, dhc2) -> {
			int cmp;
			cmp = Integer.compare(dhc1[0], dhc2[0]);
			if (cmp != 0)
				return cmp;
			return Integer.compare(dhc1[2], dhc2[2]);
		});
		int[] paint = new int[n + 1];
		Arrays.fill(paint, -1);
		final int FENNEC = 0;
		final int SUNUKE = 1;
		q.add(new int[] { 0, 1, FENNEC });
		q.add(new int[] { 0, n, SUNUKE });
		while (!q.isEmpty()) {
			int[] arr = q.poll();
			int dist = arr[0];
			int here = arr[1];
			int color = arr[2];
			if (paint[here] != -1)
				continue;
			paint[here] = color;
			for (int to : conn.get(here)) {
				if (paint[to] != -1)
					continue;
				q.add(new int[] { dist + 1, to, color });
			}
		}

		long fennec = Arrays.stream(paint).filter(p -> p == FENNEC).count();
		long sunuke = Arrays.stream(paint).filter(p -> p == SUNUKE).count();
		if (fennec > sunuke)
			return "Fennec";
		return "Snuke";
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
	}

}


Measured memory_bytes: 56620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin>> N;
  int sum=0;
  int c = N.size();
  for(int i=0;i<c;i++){
  int a = N[i] - '0';
  //cout<<i<<":"<<a<<endl;
    sum+=a;
    //cout<<sum<<endl;
  }
  istringstream ss1;
  int M;
  ss1= istringstream(N);
  ss1>> M;
 // cout<<M<<endl;
  //cout<<sum<<endl;
  if ( M%sum == 0 ) {
  cout<<"Yes"<<endl; 
  }
  else{
  cout<<"No"<<endl;}
}

Measured memory_bytes: 3620
N, T = map(int, input().split())
c, t = [], []
for i in range(N):
    tmp = list(map(int, input().split()))
    c.append(tmp[0])
    t.append(tmp[1])

res = []
for x, y in zip(c, t):
    if y <= T:
        res.append(x)
if len(res) > 0:
    print(min(res))
else:
    print("TLE")

Measured memory_bytes: 38256
a, b, c, x, y = map(int, input().split())
ans = 0
if a+b >= 2*c:
    if x >= y:
        ans += 2*c*y
        ans += min(a, 2*c)*(x-y)
    else:
        ans += 2*c*x
        ans += min(b, 2*c)*(y-x)
else:
    ans = x*a+y*b
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 999999999999999;

int main(){
  string s;
  cin >> s;
  string t;
  cin >> t;
  if( t.size() == s.size()+1 && t.substr(0,s.size()) == s ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <utility>
#include <algorithm>

using namespace std;
using TB = pair<pair<int, int>, int>;
#define mp make_pair

constexpr int MaxN = 50;
int n, m;
pair<int, int> A[MaxN];
TB B[MaxN];

int Dist(const pair<int, int> &a, const pair<int, int> &b) {
    return abs(a.first - b.first) + abs(a.second - b.second);
}

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

    for (size_t i = 0; i < n; i++) {
        cin >> A[i].first >> A[i].second;
    }

    for (size_t i = 0; i < m; i++) {
        cin >> B[i].first.first >> B[i].first.second;
        B[i].second = i;
    }

    for (size_t i = 0; i < n; i++) {
        sort(B, B + m, [i](const TB &a, const TB &b) { return mp(Dist(A[i], a.first), a.second) < mp(Dist(A[i], b.first), b.second); });
        cout << (B[0].second + 1) << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct BIT {
    BIT(int n) : s(n + 1), n(n) {}
    int sum(int k) {
        int r = 0;
        for (; k > 0; k -= k & -k) r += s[k];
        return r;
    }
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) s[k] += v;
    }
    vector<int> s;
    int n;
};

struct Line {
    bool operator<(const Line& l) {
        return a * l.b < l.a * b ^ b * l.b < 0;
    }
    int16_t a, b, c;
    uint16_t j;
};

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

    int n;
    cin >> n;

    vector<Line> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i].a >> l[i].b >> l[i].c;
    }

    BIT b(n);
    int m = (n - 1) * n / 2;
    int h = (m + 1) / 2;

    for (int u = 0; u < 2; u++) {
        sort(l.begin(), l.end());
        for (int i = 0; i < n; i++) {
            l[i].j = i;
        }

        double x, x1 = 2e+8, x0 = -x1;
        while (1) {
            x = (x0 + x1) * 0.5;
            if (abs(x0 - x1) < 1e-10) break;

            sort(l.begin(), l.end(), [x](const Line& l0, const Line& l1) {
                return (l0.c - l0.a * x) * l1.b < (l1.c - l1.a * x) * l0.b ^ l0.b * l1.b < 0;
            });

            fill(b.s.begin(), b.s.end(), 0);

            int k = m;
            for (int i = 0; i < n; i++) {
                int j = l[i].j;
                k -= b.sum(j);
                b.add(j, 1);
            }
            if (k < h) x0 = x; else x1 = x;
        }

        cout << fixed << setprecision(12) << x << " \n"[u];

        if (u == 1) break;

        for (int i = 0; i < n; i++) {
            swap(l[i].a, l[i].b);
        }
    }

    return 0;
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int x = int.Parse(Console.ReadLine());

            while (true)
            {
                if (IsPrimeNumber(x) == true)
                {
                    Console.WriteLine(x);

                    return;
                }
                else
                {
                    x++;
                }
            }
        }

        static bool IsPrimeNumber(int x)
        {
            for (int i = 2; i < x; i++)
            {
                if (x % i == 0)
                {
                    return false;
                }
            }

            return true;
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => long.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

const int MAX_N = 110;

int par[MAX_N];
int ranks[MAX_N];
int ufSize;

void init(int n){
    ufSize = n;
    for(int i=0; i<n; i++){
        par[i] = i;
        ranks[i] = 0;
    }
}

int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    ufSize--;

    if(ranks[x] < ranks[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
    }
    
    if(ranks[x] == ranks[y]){
        ranks[x]++;
    }
}

int kruskal(int n, vector<T> &edge){
    sort(edge.begin(), edge.end());
    init(n);
    int res = 0;
    for(int i=0; i<edge.size(); i++){
        int cost, cv, nv;
        tie(cost, cv, nv) = edge[i];
        if(!same(cv, nv)){
            unite(cv, nv);
            res += (cost - 100) / 100;
        }
    }
    
    return res;
}

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;
        int m; cin>>m;
        
        vector<T> edge;
        for(int i=0; i<m; i++){
            int a, b, d;
            char c1, c2;
            cin>>a>>c1>>b>>c2>>d;
            edge.eb(T(d, a, b));
        }

        cout << kruskal(n, edge) << endl;
    }
}


Measured memory_bytes: 3192
#include<iostream>
using namespace std;
int main(void){
	int n, k;
	cin >> n >> k;
	char s[50];
  	cin >> s;
  	if (s[k-1] == 'A') s[k-1] = 'a';
  	else if(s[k-1] == 'B') s[k-1] = 'b';
  	else s[k-1] = 'c';
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 1; i + 1 < n; i++) {
        if (s[i] == 'B' && s[i + 1] == 'C' && s[i - 1] == 'A') ++ans;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset

using namespace std;

typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;

const int maxn = 100020;
const int maxm = 1000020;
const int MOd = 998244353;

int a, ar[maxn];

int main() {

    //freopen("asd.in","r",stdin);
    //freopen("output17.txt","w",stdout);
    int a;
    string s;
    scanf("%d",&a);
    for(int i=1;i<=a;i++) {
    	scanf("%d",&ar[i]);
    }
    sort( ar+1, ar+1+a );
    db ans = ar[1];
    for(int i=2;i<=a;i++)
    	ans = (ans+ar[i])/2;
    printf("%.12lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,n) for(int i=a;i<n;i++)
#define ps(x) cout<<x<<" "
#define pn(x) cout<<x<<"\n"
#define sz(a) int((a).size())
#define pb push_back
typedef vector< int > vi;
typedef pair< int,int > pairs;

int main()
{
 ll n;
 cin>>n;
 cout<<2*3.1428*n;   
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// UnionFindの実装
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }

    // 集合をマージする
    // すでに同じ集合ならfalseが返る
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) return false;
        //要素数の少ない方を多い方に繋げる
        if(data.at(y) < data.at(x)) swap(x, y);
        data.at(x) += data.at(y);
        data.at(y) = x;
        return true;
    }

    // ある要素がどの集合に属しているかを返す
    int root(int x) {
        // 根に直接つなぎ直す
        return data.at(x) < 0 ? x : (data.at(x) = root(data.at(x)));
    }

    // ある集合の大きさを答える
    int size(int x) {
        return -data.at(root(x));
    }

    // ある二つの要素が同じ集合か判定
    bool same(int x, int y) {
        x = root(x); y = root(y);
        return x == y;
    }
};

int n, q;

int main() {
    cin >> n >> q;
    UnionFind tree(n);
    for(int i = 0; i < q; ++i) {
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0) tree.merge(x, y);
        else cout << tree.same(x, y) << endl;
    }
}


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

int main() {
  // Nの入力
  string S,T,U;
  int A,B;
  cin >> S >> T >> A >> B >> U;

  if(U==S){
    A--;
  } else if(U==T){
    B--;
  }
  
  cout << A << " " << B << endl;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(N):
    C.append(A[i] - B[i])
C.sort()
C.reverse()
ans = 0
count = 0
for i in range(N):
    if A[i] < B[i]:
        ans += 1
        count += B[i] - A[i]
for i in range(N):
    if count > 0:
        count -= C[i]
        ans += 1
    else:
        break
        
if sum(A) < sum(B):
    ans = -1
print(ans)


Measured memory_bytes: 18292
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=mpowe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}

int main()
{
    fastio();
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ll n;
    cin>>n;
    ll a[n];
    cn(a,n);
    ll m = a[0];
    ll c=0;
    for(int i=0;i<n;i++)
    {
        m = min(m,a[i]);
        if(a[i]<=m)
        {
            c++;
        }
    }
    cout<<c<<endl;
}

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

const int lim = 2154;
long long n;
vector<long long> s;
set<long long> st;
map<long long, pair<int, int>> mp;

long long solve();

int main() {
  bool cube = 0;
  for (long long i = 1; i <= lim; ++i) st.insert(i * i * i);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long p;
    cin >> p;
    if (st.find(p) != st.end())
      cube = 1;
    else
      s.push_back(p);
  }
  n = s.size();
  cout << solve() + cube << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    long long now = 1, tmp = s[i];
    for (long long j = 2; j * j * j <= tmp; ++j) {
      while (s[i] % (j * j * j) == 0) s[i] /= j * j * j, tmp /= j * j * j;
      if (tmp % (j * j) == 0)
        now *= j, tmp /= j * j;
      else if (tmp % j == 0)
        now *= j * j, tmp /= j;
    }
    if ((long long)sqrt(tmp) * sqrt(tmp) == tmp)
      now *= (long long)sqrt(tmp);
    else
      now *= tmp * tmp;
    if (now < s[i])
      ++mp[min(s[i], now)].first;
    else
      ++mp[min(s[i], now)].second;
  }
  for (auto p : mp) res += max(p.second.first, p.second.second);
  return res;
}

Measured memory_bytes: 10436
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, K = read_int_list()
    H = read_int_list()
    res = 0
    if K < N:
      H = sorted(H, reverse=True)
      del H[0:K]
      res = sum(H)
    print(res)

main()


Measured memory_bytes: 27936
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


int square(int x){
    return x*x;
}
bool isPerfectSquare(int x){
    int sq=sqrt(x);
    return sq*sq==x;
}
bool check(const vector<int> &p1,const vector<int> &p2){
    int sum=0;
    for(int i=0;i<p1.size();i++){
        sum+=square(p1[i]-p2[i]);
    }
    return isPerfectSquare(sum);
}
void solve(){
    
    int n,m;
    cin>>n>>m;
    
    vector<vector<int>> points(n,vector<int> (m,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>points[i][j];
        }
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(check(points[i],points[j]))
                cnt++;
        }
    }
    cout<<cnt<<endl;
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3628
while True:
	n, m, a = map(int, raw_input().split())
	if n == m == a == 0: break
	hl = [tuple(map(int, raw_input().split())) for i in xrange(m)]
	hl.sort(lambda x, y: cmp(y, x))
	for h, p, q in hl:
		if p == a: a = q
		elif q == a: a = p
	print a

Measured memory_bytes: 4416