akhauriyash/Code-Regression huggingface dataset:
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    string s; cin>>s;
    int f = 0;
    deque<int> order;
    for(int i = 0; i < s.size(); i++)
        order.push_back(i);
    int q; cin>>q;
    int move = s.size();
    while(q--){
        int type; cin>>type;
        if(type==1) f = !f;
        else{
            int op; cin>>op;
            string k; cin>>k;
            s+=k;
            op--;
            if(f^op){
                order.push_back(move);
            }
            else{
                order.push_front(move);
            }
            move++;
        }
       
    }
    if(f)
        reverse(all(order));
    for(int i : order){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

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

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

    string s;
    cin >> s;

    int res = 0;

    rep(i, 4){
        if(s[i] == '+') ++res;
        else --res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s;
	int c0=0,c1=0;
	cin >> s;
	for (int i = 0; s[i] != '\0'; i++) {
		if (s[i] == '0')c0++;
		else c1++;
	}
	cout << 2 * min(c0, c1) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int N;
  scanf("%d",&N);
  std::vector<long long > A(N);
  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
  }
  std::sort(A.begin(), A.end());
  bool same = false;
  for (int i=1; i<N; i++){
    if (A[i-1]==A[i]){
      same = true;
      break;
    }
  }
  if (same){
    printf("NO\n");
  } else {
    printf("YES\n");
  }
  return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  ll vec[n];
  ll ans=0;
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<=n-i;j++){
      if(i+j>m){
        continue;
      }
      ll vecb[i+j]={};
      for(int k=0;k<i;k++){
        vecb[k]=vec[k];
      }
      for(int k=0;k<j;k++){
        vecb[i+k]=vec[n-k-1];
      }
      sort(vecb,vecb+i+j);
      for(int k=0;k<min(m-i-j,i+j);k++){
        if(vecb[k]<0){
          vecb[k]=0;
        }
      }
      ll sum=0;
      for(int k=0;k<i+j;k++){
        sum+=vecb[k];
      }
      ans=max(ans,sum);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

// gcd
int gcd(int a,int b){
  if ( ( 0 == a ) || ( 0 == b ) )
    return 0;
  while( a != b ){
    if ( a > b ) a = a - b;
    else b = b - a;
  }
  return a;
}

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

  vector<ll> x(N);
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }
  x.pb(X);
  sort(all(x));
  vector<int> data;

  for(int i=1; i < x.size(); i++){
    data.pb(x[i]-x[i-1]);
    // cout << data[i-1] << endl;
  }
  
  int ans=data[0];
  for(int i = 1; i < data.size(); i++){
    ans = min(ans,gcd(ans,data[i]));
    // cout << min(ans,gcd(ans,data[i])) << endl;
  }
  cout << ans << endl;
}


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

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if ((e - a) <= k) {
        cout << "Yay!";
    }
    else {
        cout << ":(";
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

const int INF=1001001001001001001;
int N;
int A[5555];

vint G[5555];
int dp[5010][5010];
int dp2[5010];
int sz[5010];

int tmp[5010];
void dfs(int v,int p){
	sz[v]=1;

	if(A[v]>0){
		dp2[v]=1;
		dp[v][1]=A[v];
	}
	else{
		dp2[v]=INF;
		dp[v][1]=A[v];
	}
	for(auto u:G[v]){
		if(u==p)continue;
		dfs(u,v);
		int mi=dp2[u]-1;
		for(int i=1;i<=sz[u];i++)if(dp[u][i]<0)chmin(mi,i);
		dp2[v]+=mi;

		for(int i=1;i<=sz[v]+sz[u];i++)tmp[i]=INF;
		for(int i=1;i<=sz[v];i++){
			for(int j=1;j<=sz[u];j++){
				chmin(tmp[i+j-1],dp[v][i]+dp[u][j]);
			}
			if(dp2[u]<=N)chmin(tmp[i+dp2[u]],dp[v][i]);
		}

		sz[v]+=sz[u];
		for(int i=1;i<=sz[v];i++)dp[v][i]=tmp[i];
	}
}
signed main(){
	cin>>N;
	rep(i,N)cin>>A[i];
	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);G[b].pb(a);
	}
	
	dfs(0,-1);

	int ans=dp2[0];
	for(int i=1;i<=N;i++)if(dp[0][i]<0)chmin(ans,i);
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 195328
N = int(input())
A = [int(i) - 1 for i in input().split()]

def check(m) :
  dp = [0] * 40
  for i in range(1, N) :
    if A[i] <= A[i-1] and A[i] < 40 :
      for j in range(A[i] + 1, 40) :
        dp[j] = 0
      dp[A[i]] += 1
      for j in range(A[i], 0, -1) :
        if dp[j] >= m :
          dp[j-1] += 1
          dp[j] %= m
      if dp[0] >= m :
        return False
        
  return True

ng, ok = 0, N
for i in range(1, N) :
  if A[i] <= A[i-1] :
    ng = 1
    
while ok - ng > 1 :
  m = (ok + ng) // 2
  
  if check(m) :
    ok = m
  else :
    ng = m
    
print(ok)

Measured memory_bytes: 86868
import math
n = (int)(input())

ans = n
l = (int)(math.log(n, 9)+1)

for i in range(n+1):
  tmp_ans = 0
  a_six = i
  a_nine = n-i
  for i in reversed(range(7)):
    tmp = a_six//6**i
    tmp_ans += tmp
    a_six -= tmp*6**i
  a_nine += a_six
  for i in reversed(range(7)):
    tmp = a_nine//9**i
    tmp_ans += tmp
    a_nine -= tmp*9**i
  if ans > tmp_ans:
    ans = tmp_ans

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
static const int N = 4;
static const int N2 = 16;
static const int LIMIT = 100;

// マンハッタン距離を記録
int MDT[N2][N2];

struct Puzzle {
    int f[N2]; // パズルの状態
    int space; // スペースのある場所
    int MD; // マンハッタン距離
};

Puzzle state;
int limit; // 深さの制限
int path[LIMIT]; // 経路

// マンハッタン距離を取得
int getAllMD(Puzzle pz)
{
    int sum = 0;
    // i->pz.f[i]-1へのマンハッタン距離を計測
    rep(i, N2)
    {
        if (pz.f[i] == N2) {
            continue;
        }
        sum += MDT[i][pz.f[i] - 1];
    }
    return sum;
}

// 全てのパズルの位置が正しい時にtrue
bool isSolved()
{
    rep(i, N)
    {
        if (state.f[i] != i + 1) {
            return false;
        }
    }
    return true;
}

bool dfs(int depth, int prev)
{
    if (state.MD == 0) {
        return true;
    }
    // 現在の深さにヒューリスティックを足して制限を超えたら枝を刈る
    if (depth + state.MD > limit) {
        return false;
    }

    // 現在のスペースは(sx, sy)
    int sx = state.space / N;
    int sy = state.space % N;
    Puzzle tmp;

    rep(r, 4)
    {
        // 次の位置は(tx, ty)
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if (tx < 0 || ty < 0 || tx >= N || ty >= N) {
            continue;
        }
        //
        if (abs(prev - r) == 2) { // 前回の動きの真逆(uとd, rとl)のときはcontinue
            continue;
        }
        tmp = state;
        // マンハッタン距離の差分を計算しつつ,ピースをスワップ
        state.space = tx * N + ty;
        state.MD -= MDT[state.space][state.f[state.space] - 1];
        state.MD += MDT[sx * N + sy][state.f[state.space] - 1];
        swap(state.f[state.space], state.f[sx * N + sy]);
        if (dfs(depth + 1, r)) {
            path[depth] = r; // 方向を記録
            return true;
        }
        state = tmp; // stateを更新
    }
    return false;
}

// 反復深化
string iterative_deepen(Puzzle in)
{
    in.MD = getAllMD(in); // 初期状態のマンハッタン距離
    for (limit = in.MD; limit <= LIMIT; limit++) {
        state = in;
        if (dfs(0, -100)) {
            string ans = "";
            rep(i, limit)
            {
                ans += dir[path[i]];
            }
            return ans;
        }
    }

    return "unsolvable";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    rep(i, N2)
    {
        rep(j, N2)
        {
            // i->j でのマンハッタン距離
            MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
        }
    }
    Puzzle in;

    rep(i, N2)
    {
        cin >> in.f[i];
        if (in.f[i] == 0) {
            in.f[i] = N2;
            in.space = i;
        }
    }

    string ans = iterative_deepen(in);
    cout << ans.size() << endl;

    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char ar[maxn];
int main(void)
{
	int T, N, K;
	// cin >> T;
	// while (T--) {
	cin >> N >> K;
	cin >> (ar + 1);
	int cnt = 0;
	for (int i = 1; i <= N; ++i) {
		if (ar[i] == ar[i - 1])
			cnt++;
	}
	cout << min(N - 1, cnt + 2 * K) << endl;
	// }

	return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	ans := true

	if y%2 != 0 {
		ans = false
	}

	if y < 2*x || y > 4*x {
		ans = false
	}
	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;



int main(void)
{
    IOS
    const int C = 26;
    int n; cin >> n;
    string s; cin >> s;
    vector<set<int>> v(C);
    REP(i,n) {
        v[s[i]-'a'].insert(i+1);
    }

    int q; cin >> q;
    REP(i,q) {
        int x; cin >> x;
        if (x == 1) {
            int p; char to,from;
            cin >> p >> to;
            from = s[p-1];
            s[p-1] = to;
            v[from-'a'].erase(p);
            v[to-'a'].insert(p);
        } else {
            int l, r;
            cin >> l >> r;
            int ans = 0;
            REP(i,C) {
                auto it = v[i].lower_bound(l);
                if (it != v[i].end() && *it <= r) ans++;
            }
            cout << ans << '\n';
        }
    }


    return 0;
}

Measured memory_bytes: 24348
from collections import defaultdict, deque

n, m=map(int, input().split())

deq=deque()
dic=defaultdict(list)

for i in range(m):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)

sign=[-1]*(n+1)
sign[1]=0
for i in dic[1]:
    deq.append(i)
    sign[i]=1

while deq:
    p = deq.popleft()
    for i in dic[p]:
        if sign[i]!=-1:
            continue
        else:
            sign[i]=p
            deq.append(i)

bl = True
for i in range(2, n+1):
    if sign[i]<0:
        bl = False

if bl:
    print("Yes")
    for i in range(2, n+1):
        print(sign[i])
else:
    print("No")

Measured memory_bytes: 38348
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int[] iptmp = MyUtil.ReadIntArray();
        int koma = iptmp[0];
        int count = iptmp[1];
        List<int> input = new List<int>(MyUtil.ReadIntArray());
        input.Sort();

        List<int> list = new List<int>();
        List<List<int>> resultList = new List<List<int>>();

        for (int i = 0; i < input.Count; i++)
        {
            if (i == 0)
            {
                list.Add(input[0]);
            }
            else
            {
                if (list[list.Count - 1] + 1 == input[i])
                {
                    list.Add(input[i]);
                }
                else
                {
                    resultList.Add(new List<int>(list));
                    list.Clear();
                    list.Add(input[i]);
                }
            }
        }
        resultList.Add(list);

        int answer = 0;
        if (resultList.Count == koma)
        {
            foreach (List<int> li in resultList)
            {
                answer += li.Count - 1;
            }
        }
        else if (resultList.Count < koma)
        {
            int dif = koma - resultList.Count;
            foreach (List<int> li in resultList)
            {
                answer += li.Count - 1;
            }
            answer -= dif;
            if (answer < 0)
            {
                answer = 0;
            }
        }
        else
        {
            int dif = resultList.Count - koma;
            List<int> distList = new List<int>();

            int start = resultList[0][0];
            int end = resultList[0][resultList[0].Count - 1];
            for (int i = 1; i < resultList.Count; i++)
            {
                start = resultList[i][0];
                distList.Add(start - end);
                end = resultList[i][resultList[i].Count - 1];
            }
            distList.Sort();

            foreach (List<int> li in resultList)
            {
                answer += li.Count - 1;
            }

            for(int i = 0; i < dif; i++)
            {
                answer += distList[i];
            }
        }

        Console.WriteLine(answer);


        ReadKey();
    }
}


static class MyUtil
{
    public static int[] ReadIntArray()
    {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    /// <summary>
    /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ts"></param>
    public static void WriteToConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        Console.WriteLine(stringBuilder.ToString());
    }
}


Measured memory_bytes: 26156
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    string s, t;
    cin >> s >> t;

    int n = s.size();
    int m = t.size();

    for (int i = 0; i < n; i++) {
        s[i] -= 'a';
    }
    for (int i = 0; i < m; i++) {
        t[i] -= 'a';
    }

    vector<array<int, 26>> a(n * 2);
    for (int j = 0; j < 26; j++) {
        a[n * 2 - 1][j] = -1;
    }

    s += s;
    for (int l = 0; l < 2; l++) {
        for (int i = n * 2 - 2; i >= 0; i--) {
            for (int j = 0; j < 26; j++) {
                a[i][j] = s[i + 1] == j ? i + 1 : a[i + 1][j];
            }
        }
    }

    ll r = 0;
    int h = n - 1;
    for (int i = 0; i < m; i++) {
        int x = a[h][t[i]];
        if (x < 0) {
            r = -1;
            break;
        }
        r += x - h;
        h = x;
        if (h >= n) h -= n;
    }

    cout << r << endl;

    //次に現れる位置

    return 0;
}

Measured memory_bytes: 20972
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// ??????g????????????????????\?????????
void insertionSort(int A[],int n,int g) {
	for(int i=g;i<n;i++) {
		int v = A[i];
		int j = i - g;
		while(j>=0 && A[j] >v) {
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n) {
	// ??°???G = {1, 4, 13, 40, 121, 364, 1093, ...}?????????
	for(int h=1; ;) {
		if(h>n) break;
		G.push_back(h);
		h = 3*h + 1;
	}
	
	// ?????????G[i] = g?????????
	for(int i=G.size()-1; i>=0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main(void) {
	cin >> n;
	// ??????????????\???scanf??¢??°????????¨
	for(int i=0; i<n; i++) scanf("%d",&A[i]);
	cnt = 0;

	shellSort(A,n);
	
	cout << G.size() << endl;
	for(int i=G.size()-1; i>=0; i--) {
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++) printf("%d\n",A[i]);
	
	return 0;
}

Measured memory_bytes: 7200
def main():
    n = int(input())
    aa = list(map(int, input().split()))
    while len(aa) > 1:
        a_min = min(aa)
        a_min_i = aa.index(a_min)
        del aa[a_min_i]
        aa = [a % a_min for a in aa if a % a_min != 0]
        aa.append(a_min)
    print(aa[0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 14224
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <regex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//main code

int main(int argc, char const* argv[])
{
	LL a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	LL mi = a*x+b*y;
	dump(mi);
	if (x>y) {
		mi = min(mi,2*x*c);
		dump(mi);
		mi = min(mi,2*y*c + a*(x-y));
		dump(mi);
	}
	else {
		mi = min(mi,2*y*c);
		dump(mi);
		mi = min(mi,2*x*c + b*(y-x));
		dump(mi);
	}

	cout << mi << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

// keyの列をパース
vector<string> get_keys() {
    string S;
    getline(cin, S);
    vector<string> ret;
    for (int i = 0; i < S.length(); ++i) {
        if (S[i] == '.') {
            ret.push_back("");
        } else {
            ret.back().push_back(S[i]);
        }
    }
    return ret;
}

// YAMLの各行の情報
struct Line {
    int n;  // spaceの数
    string key, body;
};
vector<Line> inputs;

// YAMLをLineの形式にパースしてinputsへ
void get_inputs() {
    string S;
    while (getline(cin, S)) {
        Line line;
        int itr = 0;

        // スペースを数える
        line.n = 0;
        while (S[itr] == ' ') {
            ++line.n;
            ++itr;
        }

        // keyを抽出
        while (S[itr] != ':') {
            line.key.push_back(S[itr]);
            ++itr;
        }
        itr += 2;  // :とspace

        while (itr < S.length()) {
            line.body.push_back(S[itr]);
            ++itr;
        }
        inputs.push_back(line);
    }
}


struct Obj {
    string key, body;
    vector<Obj> ch;
};

vector<Obj> mapping(int, int&);

Obj mapping_item(int n, int& itr) {
    Obj ret;
    ret.key = inputs[itr].key;
    ret.body = inputs[itr].body;
    ++itr;
    if (!ret.body.empty()) return ret;  // string

    ret.ch = mapping(inputs[itr].n, itr);  // object
    return ret;
}

vector<Obj> mapping(int n, int& itr) {
    vector<Obj> ret;
    while (itr < inputs.size() && inputs[itr].n == n) {
        ret.push_back(mapping_item(n, itr));
    }
    return ret;
}

int main() {
    vector<string> keys = get_keys();
    get_inputs();

    int itr = 0;
    vector<Obj> res = mapping(0, itr);

    string ans = "";
    for (auto k : keys) {
        bool found = false;
        for (auto obj : res) {
            if (obj.key == k) {
                // 1つ下へ潜る
                ans = obj.body;
                res = obj.ch;
                found = true;
                break;
            }
        }

        if (!found) {
            cout << "no such property" << endl;
            return 0;
        }
    }

    cout << (ans.empty() ? "object" : "string \"" + ans + "\"") << endl;
    return 0;
}



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

int main() {
    int N;
    cin>>N;
    vector<int> vec(N);
    for(int i=0;i<N;i++)
      cin>>vec.at(i);
    sort(vec.begin(), vec.end());
    int sum=0;
    for(int i=0;i<N-1;i++)
      sum+=vec.at(i);
    if(sum>vec.at(N-1))
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;


}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AtCoder_ABC_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var amountAndID = new Dictionary<int, int>();
            int n = int.Parse(Console.ReadLine());

            String[] inputLine = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                int temp = int.Parse(inputLine[i]);
                amountAndID.Add(temp , i + 1);
            }

            for (int i = 1; i < n + 1; i++)
            {
                Console.Write(amountAndID[i] + " ");
            }
            
        }
    }
}

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

#define max 100000

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while (a!=0) {a=a/10;i++;}return i;}

int main()
{
    int k, x, i;
    
    scanf("%d %d", &k, &x);
    
    x-k-1;
    x+k-1;
    
    for (i=x-(k-1); i<=x+(k-1); i++) {
        if (i>=-1000000&&i<=1000000) {
            printf("%d ", i);
        }
    }
    
    return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;

string st;

int main() {
// #ifndef ONLINE_JUDGE
//   freopen("inp.txt", "r", stdin);
//   freopen("out.txt", "w", stdout);
// #endif
  string correct = "CODEFESTIVAL2016";
  cin >> st;
  int result = 0;
  for (int i = 0; i < st.length(); ++i) result += st[i] != correct[i];
  cout << result;
	return 0;
}

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

using namespace std;

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

  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = k;
  for (int i = 0; i < n; ++i) {
    int j = (i + 1) % n;
    ans = min(ans, k - (a[j] - a[i] + k) % k);
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int dp[1111][31][31][9][2][2],a[31];

int main() {
  int n,m,t;
  cin >> n >> m >> t;
  vector<PP> v[n];
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<m; i++) {
    int x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    v[x].push_back(PP(y,P(z,a[y])));
    v[y].push_back(PP(x,P(z,a[x])));
    v[x].push_back(PP(x,P(15,a[x])));
    v[y].push_back(PP(y,P(15,a[y])));
  }
  memset(dp,-1,sizeof(dp));
  dp[0][0][0][8][0][0]=0;
  for(int i=0; i<t; i++)
    for(int x=0; x<n; x++)
      for(int j=0; j<n; j++)
        for(int k=5; k<9; k++)
          for(int f=0; f<2; f++)
            for(int h=0; h<2; h++) {
              if(dp[i][x][j][k][f][h]==-1) continue;
              for(int l=0; l<v[x].size(); l++) {
                PP p=v[x][l];
                int y=p.first,c=p.second.first,d=p.second.second;
                if(!h||y!=j) dp[i+c][y][x][min(8,c)][1][f]=max(dp[i+c][y][x][min(8,c)][1][f],dp[i][x][j][k][f][h]+d);
                else {
                  dp[i+c][y][x][min(8,c)][0][f]=max(dp[i+c][y][x][min(8,c)][0][f],dp[i][x][j][k][f][h]);
                  int z=max(0,15-(k<8?k:15)-c);
                  dp[i+c+z][y][x][min(8,c+z)][1][f]=max(dp[i+c+z][y][x][min(8,c+z)][1][f],dp[i][x][j][k][f][h]+d);
                }
              }
            }
  int ans=0;
  for(int i=0; i<=t; i++)
    for(int j=0; j<n; j++)
      for(int k=0; k<9; k++)
        for(int l=0; l<2; l++)
          for(int f=0; f<2; f++) ans=max(ans,dp[i][n-1][j][k][l][f]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 153244
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
  }
  return false;
}

int main() {
  string S;
  cin >> S;
  for (char c = 'a'; c <= 'z'; c++) {
    bool not_found = true;
    rep(i, S.size()) {
      if (c == S[i])
        not_found = false;
    }
    if (not_found) {
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
bool contains0(vector<ll>&v,int l,int r){
	if(v[l]<=0&&v[r]>=0){
		return true;
	}
	return false;
}
bool allpos(vector<ll>&v){
	if(v[0]>=0){
		return true;
	}
	return false;
}
bool allneg(vector<ll>&v){
	if(v[v.size()-1]<0){
		return true;
	}
	return false;
}
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	ll n,k;
	cin>>n>>k;
	vector<ll>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	if(k==0){
		cout<<0<<endl;
		return 0;
	}
	ll ans=INT_MAX;
	int l=0,r=k-1;
	while(r<n){
		if(contains0(v,l,r)){
			ans=min(ans,min(2*v[r]+abs(v[l]),2*abs(v[l])+v[r]));
		}
		l++;
		r++;
	}
	if(allpos(v)){
		ans=min(ans,v[k-1]);
	}
	if(allneg(v)){
		ans=min(ans,abs(v[n-k]));
	}
	cout<<ans<<endl;
}

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

int main(void) {
    int K;
    cin >> K;
    vector< int > d(110);
    for (int i = 0; i < 100; i++) {
        d[i] = -1;
    }
    d[0] = 0;
    for (int i = 0; i < K; i++) {
        int j;
        for (j = 0; j < 100; j++) {
            ++d[j];
            if (d[j + 1] == -1 || (d[j] < 10 && abs(d[j] - d[j + 1]) <= 1)) {
                break;
            }
        }
        if (d[j + 1] == -1 && d[j] == 10) {
            d[j + 1] = 1;
            for (int k = 0; k <= j; k++) {
                d[k] = 0;
            }
        } else {
            for (int k = 0; k < j; k++) {
                d[j - k - 1] = max(d[j - k] - 1, 0);
            }
        }
    }
    for (int i = 0; i < 100; i++) {
        if (d[99 - i] != -1) {
            printf("%d", d[99 - i]);
        }
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;
int dpl[3010][3010];
int dpr[3010][3010];

int main(){
    int n;
    cin>>n;
    map<ll,ll> mp;
    vector<ll> canuse(0);
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        mp[a]++;
        if(mp[a]==2) canuse.push_back(a);
        if(mp[a]==4) canuse.push_back(a);
    }
    if(canuse.size()<2){
        cout<<0<<endl;
        return 0;
    }
    sort(canuse.begin(),canuse.end(),greater<ll>());
    ll ans=canuse[0]*canuse[1];
    cout<<ans<<endl;

}

Measured memory_bytes: 9708
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int r;
   int n,m,k=0,p,t;
   cin>>n>>m;
   int ara[m];
   for(int i=0;i<m;i++)
   {
   	cin>>ara[i];
   	k+=ara[i];
   	
   }
   if(k>n)cout<<-1<<endl;
   else 
   cout<<n-k<<endl;
  
  return 0;  
}


Measured memory_bytes: 3676
#include <vector>
#include <iostream>
typedef long long int ll;

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    // values[i][j]: use A[i:j]
    vector<vector<ll>> values(N + 1, vector<ll>(N + 1));
    for (int offset = 0; offset <= N; offset++) {
        for (int i = 0; i <= (N - offset); i++) {
            if (offset == 0) {
                values[i][i + offset] = 0LL;
            } else if ((offset % 2 == 1 && N % 2 == 1) || (offset % 2 == 0 && N % 2 == 0)) {
                ll value = max(values[i][i+offset-1] + A[i+offset-1], values[i+1][i+offset] + A[i]);
                values[i][i + offset] = value;
            } else {
                ll value = min(values[i][i+offset-1] - A[i+offset-1], values[i+1][i+offset] - A[i]);
                values[i][i + offset] = value;
            }
        }
    }
    cout << values[0][N] << endl;
    return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n;
  long long m;
  long long c=0;  
  while(1){
    c=0;
    cin >> n >> m;
    if(n==0&&m==0)break;
    pair<int,int> a[10000];
    for(int i=0;i<n;i++){
      cin >> a[i].second>>a[i].first;
      c+=a[i].first*a[i].second;
    }
    sort(a,a+n);
    for(int i=n-1;i>=0;i--){
      if(m>a[i].second){
	m-=a[i].second;
	c-=a[i].second*a[i].first;
      }
      else{
	c-=a[i].first*m;
	break;
      }
    }
    cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,m,L,i,ta,tb,tc,j,q;
pair<ll,ll> jar[330][330];
vector<ll> v[330];
vector<ll> w[330];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>L;
	for(i=1;i<=m;i++)
	{
		cin>>ta>>tb>>tc;
		v[ta].pb(tb);
		w[ta].pb(tc);
		v[tb].pb(ta);
		w[tb].pb(tc);
	}
	memset(jar,-1,sizeof(jar));
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
			if(i!=j)
				jar[i][j]=mp(1,0);
		priority_queue<pair<pair<ll,ll>,ll> > pq;
		pq.push(mp(mp(0,L),i));
		while(!pq.empty())
		{
			ll u=pq.top().se;
			ll ben=-pq.top().fi.fi;
			ll sisa=pq.top().fi.se;
			pq.pop();
			for(j=0;j<v[u].size();j++)
			{
				ll nx=v[u][j];
				ll wx=w[u][j];
				if(wx>L)continue;
				if(sisa<wx)
				{
					if(jar[i][nx].fi==1||(mp(-ben-1,L-wx)>jar[i][nx]))
					{
						jar[i][nx]=mp(-ben-1,L-wx);
						pq.push(mp(mp(-ben-1,L-wx),nx));
					}
				}
				else
				{
					if(jar[i][nx].fi==1||(mp(-ben,sisa-wx)>jar[i][nx]))
					{
						jar[i][nx]=mp(-ben,sisa-wx);
						pq.push(mp(mp(-ben,sisa-wx),nx));
					}
				}
			}
		}
	}
	cin>>q;
	while(q--)
	{
		cin>>ta>>tb;
		cout<<-jar[ta][tb].fi<<"\n";
	}
}


Measured memory_bytes: 4608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int N = n;
        int sum = 0;
        while (0 < n) {
            sum += n % 10;
            n /= 10;
        }

        if(N % sum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

int64_t f(int64_t k, int64_t x) {
  if(x == 1) {
    return k % 1000000007;
  }
  else if(x % 2 == 0) {
    int64_t ans = (f(k, x / 2) * f(k, x / 2)) % 1000000007;
    return ans;
  }
  else {
    int64_t ans = (f(k, x / 2) * f(k, x / 2)) % 1000000007;
    ans *= k;
    ans %= 1000000007;
    return ans;
  }
}
    

int main() {
  int X, Y;
  cin >> X >> Y;
  if((X + Y) % 3 != 0 || 2 * Y - X < 0 || 2 * X - Y < 0) {
    cout << 0 << endl;
  }
  else {
    int a = (X + Y) /3;
    int b = (2 * X - Y) / 3;
    int64_t ans = 1;
    for(int i = 0; i < b; i++) {
      ans *= a - i;
      ans %= 1000000007;
    }
    int64_t k = 1;
    for(int i = 0; i < b; i++) {
      k *= i + 1;
      k %= 1000000007;
    }
    int64_t c = f(k, 1000000005);
    ans *= c;
    ans %= 1000000007;
    cout << ans << endl;
  }
}

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

int main() {
    stack<int> railway;
    int n;
    while (cin >> n) {
        if (n == 0) {
            cout << railway.top() << endl;
            railway.pop();
        }
        else {
            railway.push(n);
        }
    }
    return 0;
}

Measured memory_bytes: 1200
def main():
	k = int(input())
	h = tuple(map(int,input().split()))
	ans = 1
	avoid = 0
	if (0 in h):
		print(0)
	else:
		for i in range(k):
			ans = h[i] * ans
			if ans > 10 **18:
				print(-1)
				avoid = 1
				break
		if avoid == 0:
			print(ans)
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 84644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
  if(b==0){
    return a;
  }
  return gcd(b,a%b);
}
int main(){
  ll n,m;cin >> n >> m;
  int b;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    ll num=a[i];
    int cnt=0;
    while(num%2==0){
      num/=2;
      cnt++;
    }
    if(!i){
      b=cnt;
    }
    else{
      if(b!=cnt){
        cout << 0 << endl;
        return 0;
      }
    }
    a[i]/=2;
  }
  ll t=a[0];
  for(int i=1;i<n;i++){
    t=t/gcd(t,a[i])*a[i];
  }
  cout << m/t-m/(2*t) << endl;
}

Measured memory_bytes: 1024
#include <iomanip>
#include <iostream>

bool isEven(int n) { return n % 2 == 0; }

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

  const auto p = isEven(n) ? 0.5 : ((n - 1) / 2 + 1) / static_cast<double>(n);
  std::cout << std::setprecision(10) << p << std::endl;
}

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

class Solve {
private:
	using vi = std::vector<int>;
	using vvi = std::vector<vi>;

	using i4 = std::array<int, 4>;
	using vi4 = std::vector<i4>;
	using vvi4 = std::vector<vi4>;

public:
	bool is_last_query{};
	Solve()
	{
		int W, H;
		scanf("%d%d", &W, &H);
		if (H == 0 && W == 0)
		{
			is_last_query = true;
			return;
		}
		vvi board(H + 2, vi(W + 2, -1));
		for (int i{1}; i <= H; i++)
			for (int j{1}; j <= W; j++)
				scanf("%d", &board[i][j]);
		
		int c[4];
		for (int i{}; i < 4; i++) scanf("%d", c + i);

		vvi4 distance(H + 2, vi4(W + 2));
		for (int i{}; i < H + 2; i++)
			for (int j{}; j < 4; j++)
				distance[i][0][j] = distance[i][W + 1][j] = -1;
		for (int i{}; i < W + 2; i++)
			for (int j{}; j < 4; j++)
				distance[0][i][j] = distance[H + 1][i][j] = -1;
		for (int i{1}; i <= H; i++)
			for (int j{1}; j <= W; j++)
				for (int k{}; k < 4; k++)
					distance[i][j][k] = 1 << 30;

		distance[1][1][0] = 0;
		std::priority_queue<i4, std::vector<i4>, std::greater<i4>> dij;
		dij.push({0, 1, 1, 0});
		
		int dir[4][2]{{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
		while (!dij.empty())
		{
			i4 now{dij.top()};
			dij.pop();
			if (now[1] == H && now[2] == W) break;
			if (now[0] > distance[now[1]][now[2]][now[3]]) continue;
			for (int i{}; i < 4; i++)
			{
				i4 next(now);
				next[3] = (next[3] + i) % 4;
				next[1] += dir[next[3]][0];
				next[2] += dir[next[3]][1];
				if (i != board[now[1]][now[2]]) next[0] += c[i];
				if (next[0] >= distance[next[1]][next[2]][next[3]]) continue;
				distance[next[1]][next[2]][next[3]] = next[0];
				dij.push(next);
			}
		}
		printf("%d\n", *std::min_element(distance[H][W].begin(), distance[H][W].end()));
	}

};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


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

int main() {
  
  int t,goukei = 0,md = 0;

  for ( int i = 0; i < 5; i++){
    cin >> t;
    if ( t % 10 == 0 ){
      goukei += t;
    }else{
      goukei += ( ( ( t / 10 ) + 1 ) * 10 );
      md = max(md,10 - (t % 10));
    }
    
  }
  
  cout << goukei - md << endl;  
  
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let cnt = read::<String>().chars().filter(|&c| c == 'o').count();
    println!("{}", 700 + 100 * cnt);
}


Measured memory_bytes: 4352
#![allow(non_snake_case)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        a1: usize,
        a2: usize,
        a3: usize,
    );
    println!("{}", if (a1+a2+a3) < 22 {
    	"win"
    } else {
    	"bust"
    });
}


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

using namespace std;

int main() {
    unordered_map<int, int> seen;
    int N;
    cin >> N;
    while (N > 0) {
        int num;
        cin >> num;
        seen[num]++;
        N--;
    }
    string result = "YES";
    for (const auto &a : seen) {
        if (a.second > 1) {
            result = "NO";
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 8520
while 1:
    n, p = map(int, input().split())
    if n == 0 and p == 0:
        break

    member = [ 0 for i in range(n) ]
    stock  = p
    while 1:
        for index in range(len(member)):
            if stock > 0:
                stock -= 1
                member[index] += 1	
            elif stock == 0:
                stock = member[index]
                if p not in member:
                    member[index] = 0
        if p in member:
            break
    print(member.index(p))

Measured memory_bytes: 7604
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	int K,S;
	int ans = 0;
	cin >> K >> S;
	for (int i = 0; i <= K; i++) {
		if (S - i >= 0) {
			if (S - i <= K) {
				ans += (S - i) + 1;
			}
			else if (S - i <= 2 * K) {
				ans += 2 * K - (S - i) + 1;
			}
		}
	}
	cout << ans;
	return 0;
}

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

if A % 2 or B % 2 or C % 2:
    print(0)
    exit(0)


def solve(n):
    i = 0
    while(n % 2 == 0):
        n = n // 2
        i += 1
    return(i)


a = solve(A+B)
b = solve(B+C)
c = solve(C+A)
if a == b and b == c:
    print(-1)
else:
    print(min(a, b, c))


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

#define rep(i, a, b) for (int i = a; i < (int)(b); i++)

using namespace std;

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

void print(const vi& num) {
    int n = num.size();
    rep(i, 0, n) {
        cout << num[i];
        if (i != n - 1) { cout << " "; }
        else { cout << endl; }
    }
}

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

    vi num(n);
    rep(i, 0, n) { cin >> num[i]; }

    print(num);
    rep(i, 1, n) {
        int v = num[i];
        int j = i - 1;

        while (j >= 0 && num[j] > v) {
            num[j + 1] = num[j];
            --j;
        }
        num[j + 1] = v;
        print(num);
    }

    return 0;
}


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

typedef long long ll;

int main(){
    int n, k;

    cin>>n>>k;

    vector<ll> p(n);
    vector<ll> s(n, 0);

    for(int i=0; i<n; i++){
        int p_tmp;
        cin>>p_tmp;
        p[i] = p_tmp+1;

        if(i>0){
            s[i] = s[i-1] + p[i];
        }else{
            s[i] = p[i];
        }
    }

    ll ans =s[k-1];
    for(int i=0; i<n-k; i++){
        ans = max(ans, s[i+k]-s[i]);
    }

    cout<< fixed << setprecision(10) <<(double)ans/2.0 <<endl;
    return 0;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int K; cin >> K;
    vec A(K); readvec(A);

    int nmin = 2, nmax = 2;

    IREP(i, K){
        if(A[i] > nmax){
            cout << -1;
            return 0;
        }
        nmin = (nmin / A[i] + min(1LL, nmin % A[i])) * A[i];
        nmax = (nmax / A[i]) * A[i] + A[i] - 1;
        if(nmin > nmax){
            cout << -1;
            return 0;
        }
    }

    cout << nmin << " " << nmax;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
    int H, W;
    cin >> H >> W;

    vector<string> v(H);
    for(auto& e : v)
        cin >> e;

    for(int i = 0; i < W + 2; ++i)
        cout << '#';
    cout << endl;

    for(auto& e : v)
    {
        cout << '#' << e << '#' << endl;
    }

    for(int i = 0; i < W + 2; ++i)
        cout << '#';
    cout << endl;

    return 0;
}

Measured memory_bytes: 888