akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define pb push_back
#define ALL(v) v.begin(),v.end()
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }
using Graph = vector<vector<int>>;

#if 0
string f(ll n)
{
    if(n == 0) return "";
    n--;
    //char t = 'a'+n%26;
    return f(n/26) + string(1, 'a'+n%26);
}
int main()
{
    ll N;
    cin >> N;
    cout << f(N) << endl;
    return 0;
}
#else
int main()
{
    ll N;
    cin >> N;
    string ans;
    while(N)
    {
        N--;
        ans += 'a'+N%26;
        N /= 26;
    }
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}
#endif

Measured memory_bytes: 3612
from queue import Queue
import sys
N, M = map(int,input().split())
edges = [[] for _ in range(3 * N)]
flag = [0] * (3 * N)
for _ in range(M):
    u, v = map(int,input().split())
    u -= 1
    v -= 1
    edges[u % (3 * N)].append((v + N) % (3 * N))
    edges[(u + N) % (3 * N)].append((v + 2 * N) % (3 * N))
    edges[(u + 2 * N) % (3 * N)].append(v % (3 * N))

S, T = map(int,input().split())
q = Queue()
q.put([0,S-1])
while not q.empty():
    p = q.get()
    if p[1] == T-1:
        print(p[0] // 3)
        sys.exit()
    for i in edges[p[1]]:
        if flag[i] == 0:
            flag[i] = 1
            q.put([p[0]+1,i])
print(-1)

Measured memory_bytes: 95008
#include <iostream> 

  

using namespace std; 

  

int main() { 

    int a , b , c; 

    cin >> a >> b >> c; 

    if (a <= b&& b <= c ) 

    cout << a << " " << b << " " << c << endl;

  else if (a <= c&& c <= b ) 

   cout << a << " " << c << " " << b << endl;
   
     else if (b <= a&& a <= c ) 

     cout << b << " " << a << " " << c << endl;
     
     else if (b <= c&& c <= a ) 

     cout << b << " " << c << " " << a << endl; 

      else if (c <= b&& b <= a ) 
      cout << c << " " << b << " " << a << endl;
       else if (c <= a&& a <= b ) 
       cout << c << " " << a << " " << b<< endl;
}
       


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main(){
	//long long int h1,m1,h2,m2,k;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='?')
		s[i]='D';
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  double x[20],ans;
  ll n;
  string u[20];
  cin >> n;
  rep(i,n)cin >> x[i] >> u[i];
  ans=0;
  rep(i,n){
    if(u[i]=="JPY")ans+=x[i];
    else ans+=(x[i]*380000);
  }
  printf("%lf",ans);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	auto kill = [](){
		cout << -1;
		exit(0);
	};
	vector<int> a(n + 1);
	for(auto i = 0; i <= n; ++ i){
		cin >> a[i];
	}
	if(!n){
		if(a[0] > 1){
			kill();
		}
		else{
			cout << 1;
			return 0;
		}
	}
	if(a[0]){
		kill();
	}
	vector<long long> pref(n + 2);
	for(auto i = 0; i <= n; ++ i){
		pref[i + 1] = pref[i] + a[i];
	}
	auto sum = [&](int i, int j){
		return pref[j] - pref[i];
	};
	vector<long long> res(n + 1), alive(n + 1);
	res[0] = 1, alive[0] = 1;
	for(auto i = 1; i <= n; ++ i){
		if(2 * alive[i - 1] < a[i]){
			kill();
		}
		alive[i] = min(2 * alive[i - 1] - a[i], sum(i + 1, n + 1));
		if(alive[i] + a[i] < alive[i - 1]){
			kill();
		}
		res[i] = alive[i] + a[i];
	}
	cout << accumulate(res.begin(), res.end(), 0LL);
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 6264
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
ans=[]
s=''
l=[]
for i in range(1,n+1):
    s=str(i)
    l=list(s)
    for j in range(len(l)):
        l[j]=int(l[j])
    if a<=sum(l)<=b:
        ans.append(i)
print(sum(ans))

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

int main()
{
    string S;
    cin >> S;
    if (S.size() % 2 != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < S.size(); i++)
    {
        if (i % 2 == 0)
        {
            if (S[i] != 'h')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if (S[i] != 'i')
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main()
{
	int x,y,z,t;
  cin >> x >> y >> z;
  t=x;
  x=y;
  y=t;
  
  t=x;
  x=z;
  z=t;
  cout << x <<" "<< y <<" "<<z;
  return 0;

}

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

using namespace std;

void solve(void)
{
	long n, k;
	cin >> n >> k;
	long ans = pow(n / k, 3);
	if (k % 2L == 0L)
	{
		ans += pow((n + k / 2) / k, 3);
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main(void) {
  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int result = 0;
  for (int i = 0; i <= n / r; i++) {
    for (int j = 0; j <= (n - r * i) / g; j++) {
      if ((n - r * i - g * j) % b == 0) result++;
    }
  }

  std::cout << result << endl;
  return 0;
}

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

int main()
{
    string s;

    while(cin>>s)
    {
        int sz=s.size();

        while(s.size()>1)
        {
            int flag=0;
            for(int i=0;i<s.size()-1;i++)
            {
                if((s[i]=='0' && s[i+1]=='1') || (s[i]=='1' && s[i+1]=='0'))
                {
                    s.erase(i,2);
                    i-=2;

                    if(i==-2)
                        i=-1;

                    flag=1;
                }
                if(s.size()<2)
                    break;
            }
            if(flag==0)
                break;
        }

        cout<<sz-s.size()<<endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;




int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


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


    a[0]--;
    for (int i = 1; i < n; i++) {
        if (a[i] > a[i - 1]) a[i]--;
        if (a[i] < a[i - 1]) {
            cout << "No";
            return 0;
        }
    }


    cout << "Yes";

}

Measured memory_bytes: 640
use std::io::stdin;

fn f(n: i32) -> i32 {
    if n % 2 == 0 {
        n / 2
    } else {
        3 * n + 1
    }
}

fn main() {
    let stdin = stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    let s: i32 = buf.trim().parse().unwrap();
    
    let mut a: Vec<i32> = vec![s];

    for i in 1.. {
        let a_i = f(a[i - 1]);
        
        if a.contains(&a_i) {
            println!("{}", i + 1);
            break;
        }

        a.push(a_i);
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////


int main() {
	int K; cin >> K;
	queue<ll>q;
	for (int i = 1; i <= 9; ++i) {
		q.push(i);
	}
	int cnt = 0;
	while (!q.empty()) {
		cnt++;
		ll key = q.front();
		if (cnt == K) {
			cout << key << endl;
			return 0;
		}
		q.pop();
		if (key % 10 != 0) {
			q.push(key * 10 +(key%10)-1);
		}
		q.push(key * 10 + (key % 10));
		if (key % 10 != 9) {
			q.push(key * 10 + (key % 10) + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	int N,L;
	cin>>N>>L;
	int plan = 0;
	for(int i = 0; i < N; i++){
		int aji = L + i;
		plan += aji;
	}
	int ans = plan;
	int minDiff = 10000000;
	for(int i = 0; i < N; i++){
		int aji = L + i;
		if( abs((plan - aji) - plan) < minDiff){
			ans = plan - aji;
			minDiff = abs( (plan-aji) - plan);
		} 
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
A, B, K = map(int,input().split())

if ((B + 1) - A ) / 2 <= K:
    for i in range(A, B+1):
        print(i)

else:
    for j in range(A, A+K):
        print(j)
    for k in range(B-K+1, B+1):
        print(k)

Measured memory_bytes: 9088
"use strict";

// read lines from stdin
const S = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .trim();

let countZero = 0;
let countOne = 0;

for (let i = 0; i < S.length; i++) {
  if (S.charAt(i) === "0") {
    countZero++;
  } else {
    countOne++;
  }
}

console.log(Math.min(countZero, countOne) * 2);


Measured memory_bytes: 7500
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 10010
using namespace std;
int ans[N],w[N];
int nxt[N<<1],to[N<<1],head[N<<1],cnt;
void add(int u,int v)
{
	nxt[++cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
int g[2][N];
void dfs(int u)
{
	for(int i=head[u];i;i=nxt[i]) dfs(to[i]);
	memset(g[0],0x3f,sizeof(g[0]));
	int now=0;
	g[now][0]=0;
	for(int i=head[u];i;i=nxt[i])
	{
		int v=to[i];
        int pre=now;
        now=!now;
        memset(g[now],0x3f,sizeof(g[now]));
        for(int j=0;j<=w[u];j++)
		{
            if(j>=w[v]) g[now][j]=min(g[now][j],g[pre][j-w[v]]+ans[v]);
            if(j>=ans[v]) g[now][j]=min(g[now][j],g[pre][j-ans[v]]+w[v]);
        }
	}
	for(int i=0;i<=w[u];i++) ans[u]=min(ans[u],g[now][i]);
}
int main()
{
	int n;
	scanf("%d",&n);
    for(int i=2;i<=n;i++)
	{
		int fa;
		scanf("%d",&fa);
        add(fa,i);
    }
    for(int i=1;i<=n;i++) scanf("%d",&w[i]);
    memset(ans,0x3f,sizeof(ans));
    dfs(1);
    if(ans[1]<0x3f3f3f3f) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 384
import sys
readline = sys.stdin.readline

n, k, q = list(map(int, readline().split()))
a = [(k - q) for i in range(n)]
for i in range(q):
    a[int(readline())-1] += 1

for i in range(n):
    if a[i] > 0:
        print('Yes')
    else:
        print('No')

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

using namespace std;

int a,b;

int main()
{
	scanf("%d%d",&a,&b);
		
	if ((a+b)%2==0) printf("%d\n",(a+b)/2); else printf("%d\n",(a+b)/2+1);
	
	return 0;	
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Logs | diff Logs.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Logs.cpp && ./a.out

/*

 8/2/2020

 5:42-

 */

const int MAX_N=1e6+1;
LL A[MAX_N],K;
int N;

bool ok(LL m) {
  LL res=0;
  REP(i,N) {
    res+=(A[i]+m-1)/m-1;
  }
  return res<=K;
}
void solve() {
  LL good=2e9,bad=0;
  while(abs(good-bad)>1) {
    LL m=(good+bad)/2;
    bool res=ok(m);
    (res?good:bad)=m;
  }
  cout<<good<<endl;
}

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

  cin>>N>>K;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}


Measured memory_bytes: 5144
def min(a, b)
  if(a > b)
    return b
  else
    return a
  end
end

n = gets.to_i
b = gets.split("\s").map(&:to_i)

result = b[0] + b[n-2]

(n-2).times do |i|
  result += min(b[i], b[i+1])
end

puts result

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    vector<ll> dp;
    REP(i, N + 1)
    {
        dp.push_back(INF);
    }
    REP(i, N)
    {
        int index = lower_bound(dp.begin(), dp.end(), A[i]) - dp.begin();
        dp[index] = A[i];
    }

    int ans = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    cout << ans << endl;
    return 0;
}


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


int main(){
    int N,K,X,Y;
    int total=0;
    cin>>N>>K>>X>>Y;
    if(N<=K){
        total = X*N;
    }else{
        total = X*K+Y*(N-K);
    }
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N, M;
vector<int> s, t;
vector<int> g[600], rg[600];

double e[600], ef[600], dp[600];

int main() {
	cin >> N >> M;
	s.resize(M);
	t.resize(M);
	REP(i, M) {
		scanf("%d %d", &s[i], &t[i]);
		
		s[i]--; t[i]--;
		g[s[i]].push_back(t[i]);
		rg[t[i]].push_back(s[i]);
	}
	
	e[N - 1] = 0;
	for (int i = N - 2; i >= 0; i--) {
		for (int v : g[i]) e[i] += e[v];
		e[i] /= g[i].size();
		e[i]++;
	}
	
	REP(i, N) {
		memset(dp, 0, sizeof(dp));
		dp[i] = 1;
		for (int j = i - 1; j >= 0; j--) {
			for (int v : g[j]) dp[j] += dp[v];
			dp[j] /= g[j].size();
		}
		ef[i] = dp[0];
	}
	
	double ans = e[0];
	
	REP(i, M) {
		if (g[s[i]].size() == 1) continue;
		double sum = (e[s[i]] - 1) * g[s[i]].size();
		sum -= e[t[i]];
		sum /= g[s[i]].size() - 1;
		sum++;
		double diff = sum - e[s[i]];
		double cur = diff * ef[s[i]] + e[0];
		chmin(ans, cur);
	}
	
	printf("%.15f\n", ans);
	
	return 0;
}



Measured memory_bytes: 3968
N = int(input())
ans = N
for i in range(N + 1):
	count = 0
	t = i
	while t > 0:
		count += int(t % 9)
		t = int(t / 9)
	t = N - i
	while t > 0:
		count += int(t % 6)
		t = int(t / 6)
	if count < ans:
		ans = count
print(ans)

Measured memory_bytes: 3064
import java.util.*;

class Main{
	public static void main(String[] $) {
		Scanner s=new Scanner(System.in);
		int l=s.nextInt(),r=s.nextInt();

		if(l%2019==0||r%2019==0||l/2019<r/2019) {
			System.out.println(0);
			return;
		}

		long res=Integer.MAX_VALUE;
		for(long i=l;i<=r;++i) {
			for(long j=i+1;j<=r;++j) {
				res=Math.min(res,i%2019*j%2019);
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 22736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
static const int MAX = 1e5;
int n, m, p[MAX], y[MAX];
inline bool cmp(int a, int b){
    return y[a] < y[b];
}
int main(){
    sc(n), sc(m);
    vector<int> g(m,0), order(m,0), d(n,0);
    for (int i = 0; i < m; i++) sc(p[i]), sc(y[i]);
    for (int i = 0; i < m; i++) g[i] = i;
    sort(g.begin(), g.end(), cmp);
    for (int i = 0; i < m; i++) order[g[i]] = ++d[p[g[i]]];
    for (int i = 0; i < m; i++) printf("%06d%06d\n", p[i], order[i]);
    return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        long a,b,i,j;
		while(true){
        a = sc.nextInt();
        b = sc.nextInt();
            if(a==0&&b==0)break;
            
		for(i=0;i<a;i++){
            for(j=0;j<b;j++){
                if(i%2==0&&j%2==0)System.out.print("#");
                else if(i%2!=0&&(j-1)%2==0)System.out.print("#");
                else System.out.print(".");
        } 
         System.out.println();
      }
            System.out.println();
    }
  }
}


Measured memory_bytes: 36224
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll x;
            cin>>x;
            ll ct=100;
            ll ans=0;
            while(ct<x)
            {
                ++ans;
                ct=(ct*1.01);
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n,k;
  cin>>n>>k;
  int p[n];
  rep(i,0,n) cin>>p[i];
  sort(p,p+n);
  ll sum=0;
  rep(i,0,k) sum+=p[i];
  cout<<sum<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
vector<ll> arr, psum;
int main () {
    int N;
    scanf("%d", &N);
    arr.resize(N+1);
    psum = vector<ll>(N+1, 0);
    for(int i=1;i<=N;i++) {
        scanf("%lld", &arr[i]);
        psum[i] = psum[i-1]+arr[i];
    }
    ll mn = 1e18;
    for(int i=1;i<=N-1;i++) {
        mn = min(mn, abs(psum[i]-(psum[N]-psum[i])));
    }
    printf("%lld", mn);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vi p(n);
	REP(i, n)
	{
		cin >> p[i];
		p[i]--;
	}
	vi a(n), b(n);
	REP(i, n)
	{
		a[i] = 30000 * (i + 1);
		b[i] = 30000 * (n - i);
	}
	REP(i, n)
	{
		a[p[i]] -= 20000 - i;
		b[p[i]] -= 20000 - i;
	}
	REP(i, n) cout << a[i] << (i == n - 1 ? "\n" : " ");
	REP(i, n) cout << b[i] << (i == n - 1 ? "\n" : " ");
	return 0;
}

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

int main(){
  long k;
  int n;
  cin>>k>>n;
  
  vector<long> a(n+1);
  vector<long> d(n);
  
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  a.at(n)=k+a.at(0);
  
  for(int i=0;i<n;i++){
    d.at(i)=a.at(i+1)-a.at(i);
  }
  
  sort(d.begin(),d.end());
  
  int sum=0;
  for(int i=0;i<n-1;i++){
    sum+=d.at(i);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int H, W;

long long dif(int height, int width) {
    int h = height / 3;
    long long ret = 1e10;
    for (int i = 0; i < 2; i++) {
        if (i) ++h;
        long long rect1 = h * width, rect2 = (height - h) * (width / 2), rect3 = (height - h) * ((width + 1) / 2);
        ret = min(ret, max(rect3, rect1) - min(rect2, rect1));
    }
    return ret;
}

int main() {
    cin >> H >> W;
    long long ans = min(((H + 2) / 3 - (H / 3)) * W, ((W + 2) / 3 - (W / 3)) * H);  //縦3分割と横3分割
    ans = min(ans, dif(H, W));
    ans = min(ans, dif(W, H));
    cout << ans << endl;
}




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

using namespace std;

int main(){
    int a,cnt=0;
    for(int i=0;i<4;i++){
        cin >> a;
        cnt+=a;
    }
    
    cout << cnt/60 << endl;
    cout << cnt%60 << endl;
    
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>

using namespace std;

const int MOD = 998244353;

typedef long long ll;

ll dp[90001];
ll dp_[90001];
ll dp1[90001];
ll dp1_[90001];

void copy(){
    for(int i = 0; i <= 90001; i++){
        dp_[i] = dp[i];
        dp1_[i] = dp1[i];
    }
}

int main(){
    int N;
    int a[300];
    ll ans;
    cin >> N;
    ll sum = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sum += a[i];
    }
    ans = 1;
    for(int i = 0; i < N; i++){
        ans = ans*3;
        ans %= MOD;
    }
    dp[0] = 1;
    dp1[0] = 1;
    for(int i = 0; i < N; i++){
        copy();
        for(int j = 0; j <= 90000; j++){
            dp[j] *= 2;
            dp[j]%= MOD;
        }
        for(int j = 0; j+a[i] <= 90000; j++){
            dp[j+a[i]] += dp_[j];
            dp[j+a[i]]%= MOD;
            dp1[j+a[i]] += dp1_[j];
            dp1[j+a[i]]%= MOD;
        }
    }
    for(int i = (sum+1)/2; i <= 90000; i++){
        ans -= dp[i]*3;
        ans %= MOD;
        ans += MOD;
        ans %= MOD;
    }
    if(sum%2 == 0){
        ans += 3*dp1[sum/2];
    }
    ans %= MOD;
    //cout << dp1[sum/2] << endl;
    cout << ans << endl;
}

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

const int mod = 1e9 + 7;
signed main(void)
{
	string s;
	ll n, m;
	cin >> s;
	n = s.size();
	VV dp(n + 1, V(13, 0));
	dp[n][0] = 1;
	m = 1;
	for (int i = n - 1; i >= 0; i--)
	{
		if (s[i] == '?')
		{
			// '?' = j (0-9) 
			rep(j, 10)
			{
				rep(k, 13)
				{
					dp[i][(j * m + k) % 13] += dp[i + 1][k];
					dp[i][(j * m + k) % 13] %= mod;
				}
			}
		}
		else
		{
			int j = s[i] - '0';
			rep(k, 13)
			{
				dp[i][(j * m + k) % 13] += dp[i + 1][k];
				dp[i][(j * m + k) % 13] %= mod;
			}
		}
		m *= 10;
		m %= 13;
	}
	cout << dp[0][5] << endl;
	return 0;
}


Measured memory_bytes: 16628
extern crate proconio;

use proconio::*;


fn main() {
    input! {
        n: i64,
    }
    let ans = match n % 10 {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => unreachable!(),
    };
    println!("{}",ans);
    //println!("n = {}", n);
}


Measured memory_bytes: 2080
N = int(input())

paths = []

for _ in range(N):
    x, y = map(int, input().split())
    paths.append((x, y))

all_path_len = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        xa, ya = paths[i]
        xb, yb = paths[j]
        all_path_len += ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5

ans = all_path_len / N

print(ans)



Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>

using namespace std;
#define PI 3.14159265359

// 約数の数
int divisor_count(int n)
{
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(n % i == 0) ans++;
    }

    return ans;
}

// 公約数
void common_divisor(int a, int b, int *array)
{
    int k = 0;
    for(int i = min(a, b); i >= 1; i--){
        if(a % i == 0 && b % i == 0){
            array[k] = i;
            k++;
        }
    }
}

// 桁数
int digit_count(long long n)
{
    int ans = 0;
    while(1){
        n /= 10;
        ans++;
        if(n == 0) break;
    }

    return ans;
}



int main()
{
    long long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    long long ans = 1000000000;
    for(int ABpizza = 0; ABpizza <= max(2 * X, 2 * Y); ABpizza += 2){
        int Apizza = X - ABpizza / 2;
        int Bpizza = Y - ABpizza / 2;
      if(Apizza <= 0) Apizza = 0;
      if(Bpizza <= 0) Bpizza = 0;
        ans = min(ans, Apizza * A + Bpizza * B + ABpizza * C);
    }

    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int N,M;
	cin>>N>>M;
	int lm=0,rm=N;
	rep(i,M){
		int l,r;
		cin>>l>>r;
		lm=max(lm,l);
		rm=min(rm,r);
	}
	cout<<max(0,rm-lm+1);
	
}

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




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;


map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}
ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}



int main() {
	int a, b;
	cin >> a >> b;
	if (a * b % 2 == 0)cout << "No" << endl;
	else cout<<"Yes"<<endl;
	return 0;
}













Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long int N,syou,amari,ans;
    cin>>N;
    syou=N/15;
    amari=N%15;
    ans=0;
    int i=0;
    ans=ans+syou*syou*60;
    for(;amari>0;amari--){
        if(amari%3==0){
            i=i+1;
        }
        if(amari%5==0){
            i=i+1;
        }
        if(i==0){
            ans=ans+syou*15+amari;
        }
        i=0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i, n) for(int i = n-1; i >= (int)0; i--)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    string s;
    std::cin >> s;
    int ca=0,cb=0;
    rep(i,n){
        if(s[i]=='a'){
            if(ca+cb<a+b){
                std::cout << "Yes" << std::endl;
                ca++;
            }
            else std::cout << "No" << std::endl;
        }
        if(s[i]=='b'){
            if(ca+cb<a+b&&cb<b){
                std::cout << "Yes" << std::endl;
                cb++;
            }
            else std::cout << "No" << std::endl;
        }
        if(s[i]=='c'){
            std::cout << "No" << std::endl;
        }
        
    }
}

Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#define MAX 10000

using namespace std;

struct Node{int parent,left,right;};
Node T[MAX];
int n;

void preorder(int u){
	if(u==-1)
	return;
	printf(" %d",u);
	preorder(T[u].left);
	preorder(T[u].right);
}

void inorder(int u){
	if(u==-1)
	return;
	inorder(T[u].left);
	printf(" %d",u);
	inorder(T[u].right);
}

void postorder(int u){
	if(u==-1)
	return;
	postorder(T[u].left);
	postorder(T[u].right);
	printf(" %d",u);
}

int main(){
	int id,l,r,root;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		T[i].parent=-1;
	}
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&id,&l,&r);
		T[id].left=l;
		T[id].right=r;
		if(l!=-1)
		T[l].parent=id;
		if(r!=-1)
		T[r].parent=id;
	}
	for(int i=0;i<n;i++){
		if(T[i].parent==-1)
		root=i;
	}
	printf("Preorder\n");
	preorder(root);
	printf("\n");
	printf("Inorder\n");
	inorder(root);
	printf("\n");
	printf("Postorder\n");
	postorder(root);
	printf("\n");
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll;
int main() {
  int N ;
  cin >> N ;
  map<string, int> mp ;
  rep(i,N){
    string S ;
    cin >> S ;
    sort(S.begin(),S.end());
    mp[S] = mp[S] + 1 ;
  }
  ll ans = 0 ;
for (auto p : mp) {
  //string key ; 
  int value; 
  //key = p.first;
  value = p.second;
  ans += (ll) value * (value - 1 ) / 2 ;
  //cout << key << value << endl;
}
  cout << ans << endl;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str string
#define all(x) (x).begin(),(x).end()
#define for(x,c) for(int x=0;x<c;x++)
#define  pb(x) push_back(x)
int main(){
    str a,b;
	cin>>a>>b;
	int c,d;
	cin>>c>>d;
	str s;
	cin>>s;
	if(s==a) cout<<c-1<<" "<<d;
	else if(s==b) cout<<c<<" "<<d-1; 
	return 0;
}



Measured memory_bytes: 256
a = int(input())
N = []
b = a
for i in reversed(range(1,10)):
  #print(i)
  if b % i == 0:
    N.append(i)
    b = b//i
    for i in reversed(range(1,10)):
        if b % i == 0:
          N.append(i)
          b = b//i
    #print(b)
if len(N) == 1:
  if a < 10:
    print("Yes")
  else:
    print("No")
else: 
  if N[0]*N[1]== a:
    print("Yes")
  else:
    print("No")

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE     ;
#define dumpV(v);
#define STOP     ;
#endif
#define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


int main() {
    string s;
    ll k;
    cin >> s >> k;
    int n = s.size();
    ll ans = 0LL;
    if (s[0] == s[n - 1]) {
        int lastCnt = 1;
        for(int i = n-2; i >= 0; --i) {
            if (s[i + 1] == s[i]) lastCnt++;
            else break;
        }
        dump(lastCnt);
        if (lastCnt & 1) {
            ll x = 0, y = 0;
            string t = s;
            rep(i, n - 1) {
                if (s[i + 1] == s[i]) {
                    s[i + 1] = '_';
                    ++x;
                }
            }
            t[0] = '_';
            y++;
            rep(i, n-1) {
                if (t[i + 1] == t[i]) {
                    t[i + 1] = '_';
                    ++y;
                }
            }
            if(t[n-1] == '_') {
                ans = x*((k+1)/2) + y*(k/2);
            }
            else {
                ans = x + y*(k-1);
            }
        } else {
            rep(i, n - 1) {
                if (s[i + 1] == s[i]) {
                    s[i + 1] = '_';
                    ++ans;
                }
            }
            ans *= k;
        }
    } else {
        rep(i, n - 1) {
            if (s[i + 1] == s[i]) {
                s[i + 1] = '_';
                ++ans;
            }
        }
        ans *= k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Scanner;

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

	static void solver() {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt() + 100;
		int sy = sc.nextInt() + 100;
		int gx = sc.nextInt() + 100;
		int gy = sc.nextInt() + 100;
		int n = sc.nextInt();
		int[][] map = new int[201][201];
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt() + 100;
			int y = sc.nextInt() + 100;
			map[x][y] = -1;
		}
		int lx = sc.nextInt();
		int ly = sc.nextInt();

		boolean[][][] arrived = new boolean[201][201][6];
		PriorityQueue<P> q = new PriorityQueue<>();
		if (map[sx][sy] == -1)
			throw new AssertionError();
		q.add(new P(sx, sy, 0, 0));
		q.add(new P(sx, sy, 1, 1));
		q.add(new P(sx, sy, 2, 2));
		q.add(new P(sx, sy, 3, 3));
		q.add(new P(sx, sy, 4, 4));
		q.add(new P(sx, sy, 5, 5));
		while (!q.isEmpty()) {
			P p = q.poll();
			if (p.x > 100 + lx || p.y > 100 + ly || p.x < 100 - lx || p.y < 100 - ly || map[p.x][p.y] == -1
					|| arrived[p.x][p.y][p.t]) {
				continue;
			}
			for (int i = 0; i < 6; i++) {
				for (int j = 0; j < 6; j++) {
					P np = nextP(p, i);
					np.betrayal = p.betrayal + (i != p.rand() ? 1 : 0) + j;
					np.t = (j + 1 + p.t)%6;
					q.add(np);
				}
			}
			arrived[p.x][p.y][p.t ] = true;
			if (p.x == gx && p.y == gy) {
				System.out.println(p.betrayal);
				return;
			}
		}
		System.out.println(-1);
	}

	static P nextP(P p, int rand) {
		if (rand == 0) {
			return new P(p.x, p.y + 1, p.t + 1, p.betrayal);
		} else if (rand == 1) {
			return new P(p.x + 1, p.y + (p.x % 2 == 0 ? 0 : 1), p.t + 1, p.betrayal);
		} else if (rand == 2) {
			return new P(p.x + 1, p.y + (p.x % 2 == 0 ? -1 : 0), p.t + 1, p.betrayal);
		} else if (rand == 3) {
			return new P(p.x, p.y - 1, p.t + 1, p.betrayal);
		} else if (rand == 4) {
			return new P(p.x - 1, p.y + (p.x % 2 == 0 ? -1 : 0), p.t + 1, p.betrayal);
		} else if (rand == 5) {
			return new P(p.x - 1, p.y + (p.x % 2 == 0 ? 0 : 1), p.t + 1, p.betrayal);
		} else {
			throw new AssertionError(rand);
		}
	}

	static class P implements Comparable<P> {
		int x;
		int y;
		int t;
		int betrayal;

		P(int x, int y, int t, int betrayal) {
			this.x = x;
			this.y = y;
			this.t = t;
			this.betrayal = betrayal;
		}

		int rand() {
			return Math.abs((x-100) * (y-100) * t) % 6;
		}

		@Override
		public int compareTo(P o) {
			return Integer.compare(this.betrayal, o.betrayal);
		}
	}
}

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

int n;
int d;
char buf[114514];
map<string, set<int> > mp; 
string names[114514];
set<int> ans[114514];

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    scanf("%d", &d);
    for (int i=0; i<n; i++) {
      scanf("%s", buf);
      names[i] = buf;
      ans[i].clear();
    }
    sort(names, names+n);
    mp.clear();
    for (int i=0; i<n; i++) {
      mp[names[i]].insert(i);
    }

    if (d == 1) {
      for (int i=0; i<n; i++) {
        for (int j=0; j<names[i].size(); j++) {
          for (int k : mp[names[i].substr(0, j) + names[i].substr(j+1)]) {
            if (k != i) {
              ans[min(i, k)].insert(max(i, k));
            }
          }

          for (char k='a'; k<='z'; k++) {
            //cout << "rep: " << names[i].substr(0, j)+k+names[i].substr(j+1) << "\n";
            for (int t : mp[names[i].substr(0, j)+k+names[i].substr(j+1)]) {
              if (t != i) {
                ans[min(i, t)].insert(max(i, t));
              }
            }

            //cout << "ins: " << names[i].substr(0, j)+k+names[i].substr(j) << "\n";
            for (int t : mp[names[i].substr(0, j)+k+names[i].substr(j)]) {
              if (t != i) {
                ans[min(i, t)].insert(max(i, t));
              }
            }
          }

          for (int k=j+1; k<names[i].size(); k++) {
            string g = names[i].substr(0, j)+names[i][k]+names[i].substr(j+1, k-j-1)+names[i][j]+names[i].substr(k+1);
            //cout << "sw: " << g << "\n";
            for (int t : mp[g]) {
              if (t != i) {
                ans[min(i, t)].insert(max(i, t));
              }
            }
            break;
          }
        }

        for (char k='a'; k<='z'; k++) {
          //cout << "ins: " << names[i]+k << "\n";
          for (int t : mp[names[i]+k]) {
            if (t != i) {
              ans[min(i, t)].insert(max(i, t));
            }
          }
        }
      }
    } else if (d == 2) {
      for (int i=0; i<n; i++) {
        for (int j=0; j<names[i].size(); j++) {
          //cout << "del: " << names[i].substr(0, j) + names[i].substr(j+1) << "\n";
          mp[names[i].substr(0, j) + names[i].substr(j+1)].insert(i);
          for (char k='a'; k<='z'; k++) {
            mp[names[i].substr(0, j)+k+names[i].substr(j+1)].insert(i);
            mp[names[i].substr(0, j)+k+names[i].substr(j)].insert(i);
          }

          for (int k=j+1; k<names[i].size(); k++) {
            string g = names[i].substr(0, j)+names[i][k]+names[i].substr(j+1, k-j-1)+names[i][j]+names[i].substr(k+1);
            mp[g].insert(i);
            break;
          }
        }

        for (char k='a'; k<='z'; k++) {
          mp[names[i]+k].insert(i);
        }
      }

      for (auto itr : mp) {
        for (int i : itr.second) {
          for (int j : itr.second) {
            if (i < j) ans[i].insert(j);
          }
        } 
      }
    } else assert(0);

    int cnt = 0;
    for (int i=0; i<n; i++) {
      for (int j : ans[i]) {
        printf("%s,%s\n", names[i].c_str(), names[j].c_str());
        cnt++;
      }
    }
    printf("%d\n", cnt);
  }
}

Measured memory_bytes: 38968
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int a;
    string s; 
   
    cin >> a >> s; 
    
    if (a >= 3200) { 
      cout << s << endl; 
    }else{
      cout << "red" << endl;
    }
 
}



Measured memory_bytes: 888