akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int inf=1e9;
bool notloop[100010];
bool loop[100010];
int p[100010];
int laststep[100010];
int dp[100010];
int N;
int ans=inf;
typedef pair<int,int> P;
void loopcheck(int i)
{
  set<int> st;
  st.insert(i);
  int nxt=i+p[i];
  st.insert(nxt);
  int now=nxt;
  if(notloop[nxt] || p[nxt]==0)
    {
      notloop[i]=true;
      laststep[i]=laststep[nxt];
      return;
    }
  else
    {
      while(1)
	{
	  nxt=now+p[now];
	  auto it=st.find(nxt);
	  if(notloop[nxt] || p[nxt]==0)
	    {
	      for(auto it=st.begin();it!=st.end();it++)
		{
		  notloop[*it]=true;
		  laststep[*it]=laststep[nxt];
		}
	      return;
	    }
	  else if(it!=st.end())
	    {
	      for(auto it=st.begin();it!=st.end();it++)
		{
		  loop[*it]=true;
		  laststep[*it]=-1;
		}
	      return;
	    }
	  else if(it==st.end())
	    {
	      st.insert(nxt);
	      now=nxt;
	    }
	}
    }
}
int main(int argc,char const* argv[])
{
  cin >> N;
  memset(loop,false,sizeof(loop));
  memset(notloop,false,sizeof(notloop));
  for(int i=1;i<=N;i++)
    {
      cin >> p[i];
      if(p[i]==0) laststep[i]=i;
    }
  for(int i=1;i<=N;i++)
    {
      if(p[i]==0) notloop[i]=true;
      else
	{
	  if(notloop[i] || loop[i]) continue;
	  else
	    {
	      loopcheck(i);
	    }
	}
    }
  /*cout << endl;
    for(int i=1;i<=N;i++)
    {
      cout << laststep[i] << endl;
      }*/
  for(int i=1;i<100010;i++)
    {
      dp[i]=inf;
    }
  dp[1]=0;
  priority_queue<P,vector<P >,greater<P> > que;
  que.push(make_pair(0,1));
  while(!que.empty())
    {
      P nowstate=que.top();que.pop();
      int nowposition=nowstate.second;
      int nowcost=nowstate.first;
      for(int i=1;i<=6;i++)
	{
	  int nxtposition=laststep[nowposition+i];
	  if(loop[nxtposition] || laststep[nxtposition]==-1) continue;
	  else
	    {
	      if(dp[nxtposition]>nowcost+1)
		{
		  dp[nxtposition]=nowcost+1;
		  que.push(make_pair(nowcost+1,nxtposition));
		}
	    }
	}
    }
  for(int i=N;i<=N+6;i++)
    {
      ans=min(ans,dp[i]);
    }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 8368
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e6 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL cou[MAXN];
LL mm[MAXN];
int main(){
  fio();
  int n; cin>>n;
  vector<LL> v(n);
  forn(i,n){
   cin>>v[i];
   cou[v[i]]++;
   }

   for1(i,MAXN){
   	if(cou[i]>1) {
   		cou[i]=0;
   		mm[i] = 1;
   	}
   }
   LL an =0;
   for1(i,MAXN){
   		if(mm[i] || cou[i]) {
   			if(!mm[i]) an++;
   		for(int j = i; j<=MAXN; j+=i)
   			cou[j] = 0;
   	}
   }
   cout<<an<<endl;
  return 0;
}

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

int main(){
	long long x,k;
	cin>>x>>k;
	if(k==1 && x>0)cout<<"0\n";
	else if(x==0)cout<<"0\n";
	else {
		cout<<min(x%k,abs(x%k - k));
	}
    return 0;
}



Measured memory_bytes: 256
from sys import stdin
input = stdin.readline
from time import time
from random import randint
from copy import deepcopy

start_time = time()

def calcScore(t, s, c):
    scores = [0]*26
    lasts = [0]*26
    for i in range(1, len(t)):
        scores[t[i]] += s[i][t[i]]
        dif = i - lasts[t[i]]
        scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
        lasts[t[i]] = i
    for i in range(26):
        dif = len(t) - lasts[i]
        scores[i] -= c[i] * dif * (dif-1) // 2
    return scores

def update(socre, day, t, q):
    p = t[day]
    t[day] = q
    scores[p] = 0
    scores[q] = 0
    lasts = [0]*26
    for i in range(1, len(t)):
        if t[i] == p or t[i] == q:
            scores[t[i]] += s[i][t[i]]
            dif = i - lasts[t[i]]
            scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
            lasts[t[i]] = i
    for i in [p, q]:
        dif = len(t) - lasts[i]
        scores[i] -= c[i] * dif * (dif-1) // 2

def greedy(c, s):
    day_lim = len(s)
    socres = [0]*26
    t = [0]*day_lim
    lasts = [0]*26
    for i in range(1, day_lim):
        pls = [v for v in socres]
        mns = [v for v in socres]
        for j in range(26):
            pls[j] += s[i][j]
            mns[j] -= c[j] * (i - lasts[j])
        sum_mns = sum(mns)
        pt = sum_mns - mns[0] + pls[0]
        idx = 0
        for j in range(1, 26):
            tmp = sum_mns - mns[j] + pls[j]
            if pt < tmp:
                pt = tmp
                idx = j
        t[i] = idx
        lasts[idx] = i
        for j in range(26):
            if j == idx:
                socres[j] = pls[j]
            else:
                socres[j] = mns[j]
    return socres, t

D = int(input())
c = list(map(int, input().split()))
s = [[0]*26 for _ in range(D+1)]
for i in range(1, D+1):
    s[i] = list(map(int, input().split()))

scores, t = greedy(c, s)
sum_score = sum(scores)

while time() - start_time < 1.75:
    day = randint(1, D)
    q = randint(0, 25)
    if q == t[day]:
        continue
    tmp_t = deepcopy(t)
    tmp_t[day] = q
    tmp_scores = calcScore(tmp_t, s, c)
    sum_tmp_score = sum(tmp_scores)
    if sum_score < sum_tmp_score:
        sum_score = sum_tmp_score
        t = tmp_t
        scores = tmp_scores

for v in t[1:]:
    print(v+1)


Measured memory_bytes: 92148
"""
出典:https://atcoder.jp/contests/abc076/tasks/abc076_c
"""

def main():
  S, T = input(), input()
  if len(S)<len(T):
    print("UNRESTORABLE")
    return

  p_flg=False

  for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
      if S[len(S)-len(T)-i:len(S)-i][j] == T[j]:
        continue
      else:
        if S[len(S)-len(T)-i:len(S)-i][j] == '?':
          continue
        else: 
          break
    else:
      S2 = S[:len(S)-len(T)-i] + T + S[len(S)-i:]
      p_flg=True
      break
  if p_flg:
    print(S2.replace('?','a'))
    return
  else:
    print("UNRESTORABLE")
    return

if __name__ == "__main__":
  main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    int N; cin >> N;
    string S1, S2; cin >> S1 >> S2;
    ll ans = 1;
    bool past = false;

    for(int i = 0; i < N; i++){
        if(i == 0){
            if(S1[i] == S2[i]) { past = true; ans *= 3;}
            if(S1[i] != S2[i]) { past = false; i++; ans *= 6;}
            continue;
        }
        if(S1[i] == S2[i]){ // past = true;
            if(past) { ans *= 2; ans %= MOD; }
            past = true;
        }
        else{ // past = false;
            i++;
            if(past){ ans *= 2; ans %= MOD; }
            if(!past) { ans *= 3; ans%= MOD;}
            past = false;

        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	map<string, int> mp;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		mp[s] += 1;
	}

	vector<pair<int, string>> vs;
	for (auto it = mp.begin(); it != mp.end(); ++it) {
		vs.emplace_back(-(it->second), it->first);
	}

	sort(vs.begin(), vs.end());
	for (auto p : vs) {
		if (p.first == vs[0].first) {
			cout << p.second << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 29172
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int inf=1e9;
const LL mod=998244353;
#define mem(a,b) memset(a,b,sizeof(a))
int max(int a,int b) {return a>b?a:b;}
char str[ 510][510];
int vis[510][501];
int ds[4][2]={0,1,1,0,0,-1,-1,0};
struct node{
    int x,y;
};
int main()
{
    int h,w;
    scanf("%d%d",&h,&w);
    for(int i=1;i<=h;i++)
        scanf("%s",str[i]+1);
    LL ans=0,x,y;
    mem(vis,0);
    /*for(int i=1;i<=h;i++)
    {
        printf("%s\n",str[i]+1);
    }*/
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            queue<node>Q;
            if(vis[i][j]) continue;
            else{
                x=0;y=0;
                vis[i][j]=1;
                node point,temp;
                point.x=i;point.y=j;
                Q.push(point);
                while(!Q.empty())
                {
                    temp=Q.front();
                    Q.pop();
                    if(str[temp.x][temp.y]=='.') x++;
                    else y++;
                    for(int k=0;k<4;k++)
                    {
                        node tp;
                        tp.x=temp.x+ds[k][0];
                        tp.y=temp.y+ds[k][1];
                        if(vis[tp.x][tp.y]||tp.x<1||tp.x>h||tp.y<1||tp.y>w||str[temp.x][temp.y]==str[tp.x][tp.y])
                        continue;
                        vis[tp.x][tp.y]=1;
                        Q.push(tp);
                    }
                }
                ans+=x*y;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,m,k;
string a,b,c;
int32_t main(){
CODE_START;
cin >> a;
cin >> b;
cin >> c;
n=a.size();
m=b.size();
k=c.size();
ll s1=1;
while(s1!=0){
    if(s1==1){
             if(a.size()==0){
        rc("A");
    }
        if(a[0]=='a'){
            s1=1;
        }else if(a[0]=='b'){
        s1=2;
        }else {
        s1=3;
        }
        a.erase(0,1);
    }else if(s1==2){
        if(b.size()==0){
    rc("B");
    }
        if(b[0]=='a'){
            s1=1;
        }else if(b[0]=='b'){
        s1=2;
        }else {
        s1=3;
        }
        b.erase(0,1);
    }else if(s1==3){
        if(c.size()==0){
    rc("C");
    }
        if(c[0]=='a'){
            s1=1;
        }else if(c[0]=='b'){
        s1=2;
        }else {
        s1=3;
        }
        c.erase(0,1);
    }
}
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll n, tmp, sum;
  ll min_num = 2e+18;
  cin >> n;

  vector<ll> v(n);
  cin >> v[0];
  for (ll i = 1; i < n; i++)
  {
    cin >> tmp;
    v[i] = v[i-1] + tmp;
  }

  sum = v[n-1];

  for (ll i = 0; i < n; i++) min_num = min(min_num, abs(sum - 2*v[i]));
  
  cout << min_num << endl;

  return 0;
}

Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[4];
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    sort(a,a+4);
    if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

int n, m, q;
int a[maxn];
int ans[1000][1000];

bool read()
{
	if (scanf("%d", &n) != 1)
		return false;

	scanf("%d %d", &m, &q);

	forn (i, q)
		scanf("%d", a + i);

	return true;
}

void solve()
{
	for (int i = 0, j = 0, k = 0; k < q; ++k)
	{
		forn (ppp, a[k])
		{
			ans[i][j] = k + 1;

			if (i & 1 ^ 1)
				++j;
			else
				--j;

			if (j == m)
			{
				++i;
				j = m - 1;
			}

			if (j == -1)
			{
				++i;
				j = 0;
			}
		}
	}

	forn (i, n)
	{
		forn (j, m)
			printf("%d ", ans[i][j]);

		printf("\n");
	}
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>
typedef struct{
  int nam;
  int dis;
}set;
int main(){
  int n ,i ,way1 ,way2 ,top=0 ,rancer;
  while( scanf( "%d" ,&n ) ){
    if( n == 0 ){
      break;
    }

    set mem[10000];
    for( i=0 ; i<n ; i++ ){
      mem[i].dis = 0;
    }

  for( i=0 ; i<n ; i++ ){
    scanf( "%d %d %d" ,&mem[i].nam ,&way1 ,&way2 );
    mem[i].dis += way1 + way2;
  }
  
  for( i=0 ; i<n ; i++ ){
    if( mem[i].dis > top ){
      top = mem[i].dis;
      rancer = mem[i].nam;
    }
  }
  
  printf( "%d %d\n" ,rancer ,top );
  top = 0;
  }
  return 0;
}

Measured memory_bytes: 676
#include "iostream"
#include "string"


int main()
{
	int W, H, x, y, r;
	std::cin>> W >> H >> x >> y >> r;
	if ((x - r) < 0 || (x + r) > W || (y - r) < 0 || (y + r) > H) std::cout<< "No" <<std::endl;
	else std::cout<< "Yes" <<std::endl;
    return 0;
}

Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int K,x;
const int Max=1000000;
int main(){
	scanf("%d%d",&K,&x);
	for(register int i=max(-Max,x-(K-1));i<=min(Max,x+(K-1));++i)
	    printf("%d ",i);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

    int n, k;
    std::string str;
    std::cin >> n;
    std::cin >> str;
    std::cin >> k;


    char caracter = str[k-1];  //判定文字
//    std::cout << caracter << std::endl;
    //ok
    std::string result;


    for (int i = 0; i < str.size(); ++i) {
        if (str[i] == caracter) {
//            result[i] = caracter;
            result.push_back(caracter);
//            cout << "a" << endl;
        } else {
//            result[i] = str[i];
            result.push_back('*');
//            cout << "b" << endl;
        }

    }


//    cout << ".size()" << result.size() << endl;
//    cout << ".length()" << result.length() << endl;
//    for (int j = 0; j < result.size(); ++j) {
//        cout<< result[j]<<endl;
//    }
    std::cout << result;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,K; cin>>N>>K;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  int ans=A[0];
  REP(i,0,min(N,K)){
    REP(j,0,min(N-i,K-i)){
      int sum=0;
      priority_queue<int,vi,greater<int>> Q;
      rep(k,0,i){
        sum+=A[k];
        Q.push(A[k]);
      }
      rep(l,0,j){
        int k=N-1-l;
        sum+=A[k];
        Q.push(A[k]);
      }
      rep(k,0,K-i-j){
        if(Q.size()==0||Q.top()>=0)
          break;
        sum-=Q.top();
        Q.pop();
      }
      ans=max(ans,sum);
    }
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n){
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 1; i < n - 1; i++)
  {
    if(p[i-1] < p[i] && p[i] < p[i+1]){
      ans++;
    }
    else if (p[i - 1] > p[i] && p[i] > p[i + 1]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse=True)
cost = []
R = 0
for i in range(N):
    cost.append([A[i]*F[i],F[i]])
    R = max(R,A[i]*F[i])

def func(l,r):
    if l == r:
        return l
    t = (l+r)//2
    count = 0
    for a,b in cost:
        count += max(0,math.ceil((a-t)/b))
    if count <= K:
        return func(l,t)
    else:
        return func(t+1,r)

print(func(0,R))

Measured memory_bytes: 125900
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;
 
 int kk[10*10];
 
 int main()
 {
   int n;
   while(cin>>n)
   {
     int a,b,c,d;
     int count=0;
     for(a=0;a<10;a++)
     {
       for(b=0;b<10;b++)
       {
         for(c=0;c<10;c++)
         {
           for(d=0;d<10;d++)
           {
             if(a+b+c+d==n) count++;                 
           }                 
         }                 
       }                 
     }           
     cout<<count<<endl;  
   }
   //while(1);      
   return 0;    
 }

Measured memory_bytes: 3060
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif

template<typename T>
T& ckmin(T& a, T b){ return a = a > b ? b : a; }

template<typename T>
T& ckmax(T& a, T b){ return a = a < b ? b : a; }

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

vector<vi> adj_in, adj_out;
vi topo, vis;
void topoSort(int v){
	vis[v] = 1;
	for(auto u: adj_out[v])
		if(!vis[u]) topoSort(u);
	topo.pb(v);
}

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    #ifdef DEBUG
        freopen("debug", "w", stderr);
    #endif
    
    int N, M;
    cin >> N >> M;
    adj_out.resize(N), adj_in.resize(N);
    topo.reserve(N), vis.resize(N);
    rep(i, M){
    	int u, v;
    	cin >> u >> v;
    	--u, --v;
    	adj_out[u].pb(v), adj_in[v].pb(u);
    }

    for(int i = 0; i < N; i++)
    	if(!vis[i]) topoSort(i);

    reverse(all(topo));

	vi dp(N);

	for(auto&& v : topo)
		for(auto&& u : adj_in[v])
			ckmax(dp[v], 1 + dp[u]);

	cout << *max_element(all(dp)) << '\n';

    #ifdef DEBUG
        dbg::dout << "\nExecution time: " << clock() << "ms\n";
    #endif

    return 0;
}


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

using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;

class Line {
public:
	Point a, b;
};

ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

int ccw(Point a, Point b, Point c) {
	b -= a, c -= a;
	if (cross(b, c) > eps) return 1;
	if (cross(b, c) < -eps) return -1;
	if (dot(b, c) < 0) return 2;
	if (norm(b) < norm(c)) return -2;
	return 0;
}

int main()
{
	int q;
	ld p1x, p1y, p2x, p2y, x, y;
	cout << fixed << setprecision(9);
	cin >> p1x >> p1y >> p2x >> p2y;
	Point a(p1x, p1y), b(p2x, p2y);
	cin >> q;
	while (q--) {
		cin >> x >> y;
		Point c(x, y);
		switch (ccw(a, b, c))
		{
		case 1:
			cout << "COUNTER_CLOCKWISE" << endl;
			break;
		case -1:
			cout << "CLOCKWISE" << endl;
			break;
		case 2:
			cout << "ONLINE_BACK" << endl;
			break;
		case -2:
			cout << "ONLINE_FRONT" << endl;
			break;
		case 0:
			cout << "ON_SEGMENT" << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3244
def mozi(n , s):
    ans = ""
    for code in range(ord('a'), ord('z') + 1):
        azmin = 50
        for i in range(n):
            azmin = min(azmin , str(s[i]).count(chr(code)))

        if azmin != 0:
            for i in range(azmin):
                ans += chr(code)

    return ans

def main():
    n = int(input())
    #s = [list(map(str , input())) for i in range(n)]
    s = [list(map(str , input().split())) for i in range(n)]
    print(mozi(n , s))

if __name__ == '__main__':
    main()


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 064 A / Link: http://abc064.contest.atcoder.jp/tasks/abc064_a  ----- */


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

	LL r, g, b; cin >> r >> g >> b;
	LL ans = ((100 * r + 10 * g + b) % 4 == 0);


	cout << (ans?"YES":"NO") << "\n";

	return 0;
}


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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define sort(vec) std::sort(all(vec))
#define rev(vec) std::reverse(all(vec))

void input(){return;}
template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}

void inputVector(){return;}
template<typename First,typename... Rest> void inputVector(std::vector<First> &first,Rest&... rest){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i];
    }
    inputVector(rest...);
}





void calculate(){

}

int main(int,char**){
    unsigned int N,M;
    input(N,M);
    std::vector<int> vec(N);
    inputVector(vec);
    int min = 1010;
    int mini_sum = accumulate(all(vec),0);
    rep(i,N){
        min = std::min(min,vec[i]);
    }
    int res = N;
    res += (M - mini_sum) / min;
    std::cout << res << '\n';
}




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

int main(){
    string a;
    cin >> a;
    int count =700;
    if (a[0]=='o'){
        count+=100;
    }
    if (a[1]=='o'){
        count+=100;
    }
    if (a[2]=='o'){
        count+=100;
    }
    
    cout << count << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		long[] memo = { 2, 1 };
		long ans = 0;
		if (n >= 2) {
			for (int i = 0; i <= n - 2; i++) {
				ans = memo[0] + memo[1];
				memo[0] = memo[1];
				memo[1] = ans;
			}
		}else{
			if (n==1) {
				ans=1;
			}else {
				ans=2;
			}
		}

		System.out.println(ans);

		scanner.close();
	}

}


Measured memory_bytes: 22996
xy=[int(i) for i in input().split()]
a=abs(xy[2]-xy[0])
b=abs(xy[3]-xy[1])

ans="U"*b+"R"*a+"D"*b+"L"*a+"L"+"U"*(b+1)+"R"*(a+1)+"D"+"R"+"D"*(b+1)+"L"*(a+1)+"U"

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

vector<int> divisor(int n) {
  vector<int> ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ALL(ret));
  return (ret);
}

int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> m_d = divisor(m);
  int pos = upper_bound(ALL(m_d), m/n) - m_d.begin();
  cout << m_d[pos-1] << '\n';  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    int ans=0;
    REP(i,n){
        REP(j,n){
            chmax(ans,abs(vec[i]-vec[j]));
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

main(){
 
  int h, w;

  while(1){
    
    cin >>h >>w;
    if(h == 0 && w == 0)break;
      
    
      for( int j = 0; j < h; j++){

	for ( int i = 0; i < w; i++ ){
	  cout << "#";
	}
	cout << endl;

      }
      cout << endl;
    
  }
    
  
  
  return 0;
}

Measured memory_bytes: 1156
use std::io::stdin;
use std::str::FromStr;
use std::cmp::max;

fn main(){
    let (n, x): (i64, i64) = get_pair();
    let mut bs: Vec<i64> = get_vec();
    let mut ans = 0;

    for ii in 0..n-1 {
        let i = ii as usize;
        let d = bs[i] + bs[i+1] - x;
        if d <= 0 {
            continue;
        }
        ans += d;
        bs[i+1] = max(0, bs[i+1]-d);
    }

    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


Measured memory_bytes: 8444
import collections

S=input()
T=input()

def func(U):
    temp=dict(collections.Counter(U))
    lst=[]
    for v in temp.values():
        lst.append(v)
    return sorted(lst)

#print(func(S), func(T))
if func(S)==func(T):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 4144
import java.util.*;

public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long o=0;
        int n=sc.nextInt();
        int m=sc.nextInt();
        long[] x=new long[n];
        boolean[] id=new boolean[n];
      for(int i=0;i<m;i++){
        int s=sc.nextInt()-1;
        int c=sc.nextInt();
      	if(id[s]&&x[s]!=c){
          o=-1;
          break;
        }else{
          id[s]=true;
          x[s]=c;  
        }                
      }
      if(n>1&&id[0]&&x[0]==0)o=-1;
      if(o>=0){
        for(int i=0;i<n;i++){
              o*=10;
              if(id[i]){
                  o+=x[i];
              }else if(i==0&&n>1){
                  o++;
              }
          }
      }
      System.out.println(o);
    }
    
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n,l; cin >> n >> l;
    vector<string> v(n);
    rep(i,n){
        cin >> v[i];
    }
    sort(ALL(v));
    rep(i,n){
        cout<< v[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        int key = a[i];
        int j = i-1;
        while(j>=0 && a[j]>key){
            a[j+1]=a[j];
            j=j-1;
        }
        a[j+1]=key;
        
        for(int k=0; k<n; k++){
            if(k!=n-1)cout<<a[k]<<" ";
            else cout<<a[k]<<endl;
        }
      
    }
    



    
    return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <time.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,string> pip;
typedef vector<pip> vip;
const int inf=2*1e9+1;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

vl a(11),b(11);

int main(){
	a[0]=1;
	b[0]=10;
	for(int i=1;i<11;i++){
		a[i]=a[i-1]*10;
		b[i]=b[i-1]*10;
	}
	ll l=1e11,r=1e12;
	while(r-l>1){
		ll m=(l+r)/2,n=m;
		char c;
		cout<<"? "<<n<<endl;
		cin>>c;
		for(int i=10;i>=0;i--){
			n/=10;
			ll N=n+1;
			if(c=='Y') b[i]=N;
			else a[i]=N;
		}
		if(c=='Y') r=m;
		else l=m;
	}
	vl res;
	for(int i=0;i<11;i++) if(a[i]<b[i]) res.push_back(a[i]);
	ll A;
	for(int i=1;i<res.size();i++){
		cout<<"? "<<res[i]+1<<endl;
		char c;
		cin>>c;
		if(c=='Y'){
			A=res[i];
			break;
		}
	}
	cout<<"? "<<A-1<<endl;
	char c;
	cin>>c;
	if(c=='Y'^res[0]==1) cout<<"! "<<A<<endl;
	else cout<<"! "<<res[0]<<endl;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if ( x-a >= 0  and x-a <= b) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int64_t res = 0;
  for (int i = 0; i < N; i++) {
    res += A[i] / 2;
    A[i] %= 2;
    if (i + 1 < N && A[i] > 0 && A[i + 1] > 0) {
      A[i]--, A[i + 1]--;
      res++;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    char w[7];
    scanf("%s", w);
    if (strcmp(w,"Sunny")==0)
		printf("Cloudy\n");
    else if (strcmp(w,"Cloudy")==0)
		printf("Rainy\n");
    else if (strcmp(w,"Rainy")==0)
		printf("Sunny\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define ll long long int
ll a, b, ans;

int main(){
    cin >> a >> b;
    ll i = a / 16;
    ans = a;
    for (ll f = a+1; f < (i + 1) * 16; f++){
        ans = ans ^ f;
    }
    ll j = b / 16;
    for (ll f = j*16; f <= b; f++){
        ans = ans ^ f;
    }
    if (i!=j) ans = ans ^ 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
dp=[]
for i in range(n+2):
  dp.append([])
  for j in range(n+2):
    dp[-1].append([])
    for l in range(k+1):
      dp[-1][-1].append(10**12)
for l in range(k+1):
    dp[0][0][l]=0
h=list(map(int,input().split()))
h.append(0)
h.reverse()
h.append(0)
h.reverse()
for i in range(1,n+2):
  for j in range(n+2):
    for l in range(k+1):
      dp[i][i][l]=min(dp[i][i][l],dp[i-1][j][l]+max(0,h[i]-h[j]))
      if l>0:
        dp[i][j][l]=min(dp[i][j][l],dp[i-1][j][l-1])
        dp[i][0][l]=min(dp[i][0][l],dp[i-1][j][l-1]+h[j])
ans=dp[n+1][0][0]
for j in range(n+2):
  for l in range(k+1):
    ans=min(ans,dp[n+1][j][l])
print(ans)

Measured memory_bytes: 302600
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

const int N = 100 << 10;
int n, q, p[N], v[N];
bool mark[N], unused[N];
char cmd[N];

int up[N], depth[N], firstmark[N];

int top(int a) {
  return up[a] ? up[a] = top(up[a]) : a;
}

void merge(int a, int b) {
  a = top(a);
  b = top(b);
  if (a == b) return;
  if (depth[a] < depth[b]) {
    up[a] = b;
  } else {
    up[b] = a;
    if (depth[a] == depth[b]) ++depth[a];
  }
  return;
}

int main(int argc, char *argv[]) {
  while (scanf("%d %d", &n, &q) == 2 && n + q > 0) {
    FOR(i, 2, n) scanf("%d", &p[i]);
    REP(i, q) scanf(" %c %d", &cmd[i], &v[i]);
    CLR(up, 0); CLR(depth, 0); CLR(mark, 0); CLR(unused, false);
    mark[1] = true;
    REP(i, q) if (cmd[i] == 'M') {
      if (mark[v[i]]) unused[i] = true;
      mark[v[i]] = true;
    }
    FOR(i, 2, n) if (!mark[i]) {
      merge(i, p[i]);
    }
    FOR(i, 1, n) if (mark[i]) {
      firstmark[top(i)] = i;
    }

    long ans = 0;
    for (int i = q - 1; i >= 0; --i) {
      if (cmd[i] == 'Q') {
        ans += firstmark[top(v[i])];
      } else if (cmd[i] == 'M') {
        if (unused[i]) continue;
        int nextmark = firstmark[top(p[v[i]])];
        merge(v[i], p[v[i]]);
        firstmark[top(v[i])] = nextmark;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3492
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Mod=1e9+7;

int n;
char s[100010];
int tot[100010];
int ans;
int pow(int x,int y)
{
	int res=1;
	while (y)
	{
		if (y&1) res=(ll)res*x%Mod;
		x=(ll)x*x%Mod;
		y>>=1;
	}
	return res;
}

int main()
{
	scanf("%d%s",&n,s+1);
	for (int i=1;i<=n;i++) tot[s[i]-'a'+1]++;
	for (int i=1,pretot=0;i<=26;i++)
	{
		if (tot[i]<2)
		{
			pretot+=tot[i]; continue;
		}
		int tmp2=1;
		for (int j=i+1;j<=26;j++) tmp2=(ll)tmp2*(tot[j]+1)%Mod;
		int tmp=(ll)pow(2,pretot)*(((ll)pow(2,tot[i])-tot[i]-1+Mod)%Mod)%Mod*tmp2%Mod;
		ans=(ans+tmp)%Mod;
//		printf("get tmp %d\n",tmp);
		pretot+=tot[i];
	}
	ans=((ll)pow(2,n)-1-ans)%Mod;
	printf("%d\n",(ans+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = []
i = 1
while i <= n:
  if i == 1:
    s = input()
    l.append(s)
    i += 1
  else:
    s = input()
    if s in l or s[0] != l[-1][-1]:
      print('No')
      quit()
    else:
      l.append(s)
      i += 1
print('Yes')

Measured memory_bytes: 3060
N = int(input())
l = []
for i in range(N):
    a,b =map(int, input().split())
    l.append([a,b])
l.sort(key=lambda x:x[1])

deth =0
time =0
ans = 0
for i in l:
    deth = i[1]
    time += i[0]
    if deth < time:
        print("No")
        ans += 1
        break
if ans == 0:
    print("Yes")
    

Measured memory_bytes: 38036
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
using namespace std;

int main() {
  int n; cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    auto itr = mp.find(s);
    if (itr != mp.end()) {
      mp[s]++;
    } else {
      mp[s] = 1;
    }
  }

  int m; cin >> m;
  for (int i = 0; i < m; i++) {
    string s; cin >> s;
    auto itr = mp.find(s);
    if (itr != mp.end()) {
      mp[s]--;
    } else {
      mp[s] = -1;
    }
  }
  int ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    ans = max(ans, itr->second);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;
    
int main() {
  ill n;
  cin >> n;
  vector<ill> v(n);
  rep(i, 0, n) cin >> v[i];
  ill sum = 0, mx = v[0];
  rep(i, 1, n) {
    if(v[i] < mx) {
      sum += mx-v[i];
    } else {
      mx = v[i];
    }
  }
  cout << sum << "\n";
}

Measured memory_bytes: 4828
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        string s, t, g;
        cin >> s >> t >> g;
        map<string, vector<pair<string,int>>> ma;
        for(int i = 0; i < m; i++){
            string a, b;
            int c, d;
            cin >> a >> b >> c >> d;
            ma[a].push_back({b, c/40+d});
            ma[b].push_back({a, c/40+d});
        }
        map<string,int> dp;
        for(auto p : ma) dp[p.first] = 1<<30;
        dp[s] = 0;
        priority_queue<pair<int,string>> pq;
        pq.push({-0, s});
        while(!pq.empty()){
            auto p = pq.top();  pq.pop();
            string pos = p.second;
            int cost = -p.first;
            if(dp[pos] != cost) continue;
            for(auto next : ma[pos]){
                int ncost = cost + next.second;
                string npos = next.first;
                if(dp[npos] > ncost){
                    dp[npos] = ncost;
                    pq.push({-ncost, npos});
                }
            }
        }
        int ans = dp[t];
        for(auto p : ma) dp[p.first] = 1<<30;
        dp[t] = 0;
        pq.push({-0, t});
        while(!pq.empty()){
            auto p = pq.top();  pq.pop();
            string pos = p.second;
            int cost = -p.first;
            if(dp[pos] != cost) continue;
            for(auto next : ma[pos]){
                int ncost = cost + next.second;
                string npos = next.first;
                if(dp[npos] > ncost){
                    dp[npos] = ncost;
                    pq.push({-ncost, npos});
                }
            }
        }
        ans += dp[g];
        cout << ans << endl;
    }
    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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())

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

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL p(n);
	cin >> p;
	int ans = 0;
	for (int i = 0; i < n-2; i++) {
		VL pp(3);
		for (int j = 0; j < 3; j++) {
			pp[j] = p[j+i];
		}
		SORT(pp);
		if (pp[1] == p[i+1]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))

min=10000
for i in range(n):
  if min >= abs(T-H[i]*0.006-A):
    min = abs(T-H[i]*0.006-A)
    min_i = i+1
print(min_i)

Measured memory_bytes: 3060
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
bc=[list(map(int,input().split()))[::-1] for i in range(m)]
bc=sorted(bc)[::-1]
s=0
i=0
change=[]
while s<n and i<m:
  s+=bc[i][1]
  change+=[bc[i][0]]*bc[i][1]
  i+=1
if len(change)<n:
  change+=[0]*(n-len(change))
ans=0
for i in range(n):
  ans+=max(a[i],change[i])
print(ans)

Measured memory_bytes: 27080
#include <bits/stdc++.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;


signed main(){
  
  string S;
  cin >> S;
  int K;
  cin >> K;
  
  string ab = "abcdefghijklmnopqrstuvwxyz";
  
  int N = (int)S.size();
  vector<int> cnt(N);
  for( int i = 0; i < N; i++ ){
    for( int j = 0; j < 26; j++ ){
      if( S.at(i) == ab.at(j) ) cnt.at(i) = j;
    }
  }
  
  
  for( int i = 0; i < N; i++ ){
    if( cnt.at(i) != 0 ){
      if( K >= 26-cnt.at(i) ){
        int hiku = 26-cnt.at(i);
        K -= hiku;
        cnt.at(i) = 0;
      }
    }
  }
  
  if( K > 0 ){
    K %= 26;
    cnt.at(N-1) += K;
  }
  
  for( int i = 0; i < N; i++ ) cout << ab.at(cnt.at(i));
  cout << endl;
                                            

  
}


Measured memory_bytes: 1408
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

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

  constexpr int32_t INF = 1000001;
  int32_t N;
  cin >> N;
  vector<int32_t> A(INF, 0);
  for (int i = 0; i< N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  int32_t cnt = 0;
  for (int i = 1; i < INF; i++) {
    if (A[i] == 0) {
      continue;
    } else {
      if (A[i] == 1) {
        cnt++;
      }
      for (int j = 1; j * i < INF; j++) {
        A[j*i] = 0;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 7156
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = S()
    c = collections.Counter(s)
    r = 1
    for k,v in c.items():
        r *= v + 1
        r %= mod

    return (r-1) % mod


print(main())




Measured memory_bytes: 6352
#include<iostream>
using namespace std;
int main(){
  char A,B,C;
  char D,E,F;
  char G,H,I;

  cin >> A >> B >> C;
  cin >> D >> E >> F;
  cin >> G >> H >> I;

  cout << A << E << I <<"\n";

  return 0;
}


Measured memory_bytes: 256
/*
https://atcoder.jp/contests/dp/tasks/dp_i
*/
#include<bits/stdc++.h>
using namespace std;

/// dp[i][x] is the probablity of getting atleast ( >= x) heads on tossing first ith coins
const int N = 3001;

double dp[N][N];

double solve(vector<double>& p, int i,int x){

    if(x == 0){
        return 1;
    }
    if(i == 0){
        return 0;
    }
    if(dp[i][x] >= -0.9){
        return dp[i][x];
    }

    return dp[i][x] = p[i]*solve(p,i-1,x-1) + (1 - p[i])*solve(p,i-1,x);
}

int main(){

    int n;  cin>>n;
    vector<double> p(n+1);

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

    memset(dp,-1,sizeof(dp));

    double ans = solve(p,n,(n+1)/2);

    cout<<fixed<<setprecision(10)<<ans<<endl;

return 0;
}


Measured memory_bytes: 70784
N, K = map(int, input().split())
ary = list(map(int, input().split()))
ary2 = sorted(ary+[0])
zero = ary2.index(0)
k = [abs(i - zero) if i < zero else ((i + 1) - zero)for i in range(N)]
ans = float("Inf")
for i in range(N - K + 1):
    if k[i] <= K:
        if ans > abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)]):
            ans = abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)])
for i in range(N-1, K-2, -1):
    if k[i] <= K:
        if ans > abs(ary[i]) + abs(ary[i] - ary[i - (K-1)]):
            ans = abs(ary[i]) + abs(ary[i] - ary[i - (K-1)])
print(ans)


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

struct UnionFind
{
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1) {}
    int find(int x)
    {
        if (d[x] < 0)
            return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return false;
        if (d[x] > d[y])
            swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }
    set<int> s;
    int ans = 0;
    rep (i, n) {
        if (s.empty()) s.insert(uf.find(i));
        else {
            if (s.count(uf.find(i))) continue;
            if (!s.empty()) {
                s.insert(uf.find(i));
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7744