akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>
#include<fstream>
#include<list>
#include<sstream>

#define loopi(x,y) for(int i = x;i<(y);i++)
#define loopj(x,y) for(int j = x;j<(y);j++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)


#define nl cout<<"\n";
#define ll long long int
#define mod  1000000007

using namespace std;

ll power(int n, int a)
{
	if (n == 1)
		return a;
	if (n == 0)
		return 1;

	ll t = power(n / 2, a) % mod;

	if (n % 2)
		return (((t * t) % mod) * a) % mod;
	return (t * t) % mod;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	ll ans = 0;

	if (n > 1)
	{
		ans = power(n, 10) - (2 * power(n, 9) % mod);
		ans %= mod;
		ans += power(n, 8);
		ans %= mod;
	}

	cout << (ans + mod) % mod;

	return 0;
}



Measured memory_bytes: 3664
// Sum of Large Numbers

func rangeSum(_ start: Int, _ end: Int) -> Int {
    let count = end - start + 1
    return (start + end) * count / 2
}

func combi(n: Int, k: Int) -> Int{
    let min = rangeSum(0, k-1)
    let max = rangeSum(n-k+1, n)
    return max - min + 1
}

func main() {
    let nk = readLine()!.split(separator: " ").map{Int($0)!}
    let n = nk[0]
    let k = nk[1]
    var sum = 0
    for i in k...(n+1) {
        sum += combi(n: n, k: i)
        while sum > 1000000007 {
            sum -= 1000000007
        }
    }
    print(sum)
}

main()

Measured memory_bytes: 8256
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
struct P{
	int x,y,cost;
	P(int a,int b,int c){x = a, y = b , cost = c;}
	P(){}
};
#define INF (1<<25)
#define rep(i,n) for(int i=0; i<n ;i++)

int dist(P a,P b){
	return abs(a.x-b.x) + abs(a.y-b.y);
}
int main(){
	int w,h;
	
	while(cin >> w >> h , w) {
		vector<P> data[5];
		P start , goal ;
		
		start.cost = 0 , goal.cost = 0;
		
		rep(i,h)rep(j,w){
			char c;	cin >> c;
			if(c != '.'){
				if(c == 'S')start.x = j , start.y = i;	
				else if(c == 'G')goal.x = j , goal.y = i;
				else {P t(j,i,0) ; data[c-'1'].push_back(t);}
			}
		}
		int ret = INF , num ;
		
		P dp[5][1000];
		
		rep(lp,5){ // start
			rep(i,5)rep(j,1000){dp[i][j].cost = INF;}
			
			int so = (lp+1)%5;
			rep(i,data[so].size()){
				dp[so][i] = data[so][i];
				dp[so][i].cost = dist(data[so][i],start);
			}
			
			rep(Z,3){ // remain 
				int z = (lp+Z+2)%5;
				int prev = (z+4)%5;
				rep(i,data[prev].size()){ // prev
					rep(j,data[z].size()){ //cur
						int cost = dp[prev][i].cost + dist(dp[prev][i],data[z][j]);
						if(dp[z][j].cost > cost){
							dp[z][j] = data[z][j] , dp[z][j].cost = cost;
						}
					}
				}
			}
			rep(i,data[(lp+4)%5].size() ){
				int kCost = dp[(lp+4)%5][i].cost + dist(dp[(lp+4)%5][i],goal);
				if( kCost < ret){
					ret = kCost , num = lp+1; 
				}
			}
		}
		
		if(ret == INF)cout << "NA" << endl; 
		else cout << num << " " << ret << endl; 
	}
}

Measured memory_bytes: 1060
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main(){
    int N,W; cin >> N >> W;
    int ww[N][2];
    for(int i=0;i<N;i++){
        cin >> ww[i][0] >> ww[i][1];
    }

    int V[N+1][W+1];
    for(int i=0; i<= N;i++){
        for(int j=0; j<= W;j++){
            if(i<=0 || j <=0){
                V[i][j] = 0;
            }
            else{
                if(j-ww[i-1][1]<0)
                    V[i][j] = V[i-1][j];
                else
                    V[i][j] = max(ww[i-1][0]+V[i-1][j-ww[i-1][1]], V[i-1][j]);
            }
        }
    }

    cout << V[N][W] << endl;
}

Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,K;
  cin >> N >> K;
  vector<int long long> H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  sort(H.begin(),H.end());
  int long long count=0;
  for(int i=0;i<N-K;i++){
    count+=H.at(i);
  }
  cout << count << endl;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
	"math"
)

func main() {
	var n,a,b int
	fmt.Scan(&n,&a,&b)
	mod := int(math.Pow(float64(10),float64(9))) + 7
	result := mPow(2,n,mod)
	result -= 1 // 0本選択がないため
	result -= mChooce(n,a,mod)
	result += mod
	result %= mod
	result -= mChooce(n,b,mod)
	result += mod
	result %= mod
	fmt.Println(result)
}

func twoPow (n int) (int) {
	// 全組み合わせ列挙
	// 2^nを求めるやつ
	if n == 0 {
		return 1
	}
	number := twoPow(n/2)
	number *= number
	if (n%2 == 1 ) { number*=2}
	return number
}
// modに+- する時は、目的の数字をmchooceなどを使い計算した後に、
// 元のresultにmodを足した後に,modを計算する
func mPow(a int, n int, m int) int {
	if n == 0 {
		return 1
	}
	result := 1
	for n != 0 {
		if n%2 != 0 {
			// 奇数の時
			result *= a
			result %= m
		}
		a *= a
		a %= m
		n >>= 1 //割る2 //右にビットずらす
	}
	return result
}
func mChooce(n,k,m int) int {
	a := 1
	b := 1
	for i:= 0; i<k; i++ {
		a *= n-i
		a %= m
		b *= i+1
		b %= m
	}
	// フェルマーの小定理より
	// x^n-1 ≡ (mod p) より x^n-2 ≡ 1/x (mod p)
	return a * mPow(b,m-2,m) %m
}
//func choose (n int ,a int) int{
//
//}
func (n *mint)pow(number int) int {
if number == 0 {
return 1
}
num := n.pow(number >> 1)
num *= num
if number%2 == 1 {
 num *= n.num
}
return num
}

type mint struct {
	num int
}
const (mod = 10000007)

Measured memory_bytes: 1836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  cin >> N;
  
  vector<bool> is_prime(N+1, true);
  is_prime[0]=false; is_prime[1]=false;
  for(int i=2; i*i<=N; i++) {
    if(!is_prime[i]) continue;
    for(int j=2; i*j<=N; j++) is_prime[i*j]=false;
  }
  vi prime;
  rep(i,N+1) {
    if(is_prime[i]) prime.push_back(i);
  }
  
  int size=prime.size();
  int c2=0,c4=0,c14=0,c24=0,c74=0;
  vi ind(size);
  rep(i,size) {
    int num=N;
    while(num) {
      num/=prime[i];
      ind[i]+=num;
    }
    if(ind[i]>=2) {
      c2++;
      if(ind[i]>=4) {
        c4++;
        if(ind[i]>=14) {
          c14++;
          if(ind[i]>=24) {
            c24++;
            if(ind[i]>=74) c74++;
          }
        }
      }
    }
  }
  
  cout << c74+c24*(c2-1)+c4*(c4-1)/2*(c2-2)+c14*(c4-1) << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll mygcd(ll a,ll b){
	if(b==0ll)return a;
	return mygcd(b,a%b);
}
void solve(ll A,ll B,ll C,ll D){
	if(A<B){
		printf("No\n");
		return;
	}
	if(D<B){
		printf("No\n");
		return;
	}
	if(C>=B-1ll){
		printf("Yes\n");
		return;
	}
	ll s = A%B;
	ll d = D%B;
	ll k = mygcd(B,d);
	ll L = (C+1ll)%k, R =(B-1ll)%k;
	ll S = s%k;
	bool flag = true;
	if(L<=R){
		if(L<=S&&S<=R)flag = false;
	}else{
		if(S<=R||L<=S)flag = false;
	}
	if(s<=C&&k>=B-C&&flag){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return;
}
int main(){
	int T;
	cin >> T;
	for(int i=0;i<T;i++){
		ll a,b,c,d;
		cin >> a >> b >> c >> d;
		solve(a,b,c,d);
	}
	return 0;
}

Measured memory_bytes: 256
# include <algorithm>
# include <iostream>
# include <cmath>
# include <string>
# include <vector>
#include <numeric>

const long long int INF = 1e14;
typedef long long int ll;
#define rep(i,n) for(ll i=0; i<n; i++)
#define Rep(i,n) for(ll i=1; i<=n; i++)


using namespace std;

int main() {
    ll N, W, v, w, vsum=0;
    cin >> N >> W;
    ll vi[N+4], wi[N+4], vsumi[N+4];
    Rep(i,N){
        cin >> w >> v;
        vi[i] = v;
        wi[i] = w;
        vsum += v;
        vsumi[i] = vsum;
    }

    ll dp[N+4][vsum+4];
    dp[1][0] = 0;
    Rep(i, vsum){
        dp[1][i] = INF;
    }
    dp[1][vi[1]] = wi[1];

    for(ll i=2; i<=N; i++){
        rep(j,vsum+1){
            if (j >= vi[i]){
                dp[i][j] = min( dp[i-1][j], dp[i-1][j-vi[i]] + wi[i] );
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    // Rep(i,N){
    //     rep(j,vsum+1){
    //         cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
    //     }
    // }

    ll maxval = 0;
    rep(i, vsum+1){
        if (dp[N][i] <= W){
            // cout << "i = " << i << ": " << maxval << endl;
            maxval = i;
        }
    }
    cout << maxval << endl;
    
    return 0;
}


Measured memory_bytes: 79744
import collections
import sys
input = sys.stdin.readline

h, w, n = [ int(v) for v in input().split() ]
ans_list = [ 0 for i in range(10) ]
ans_list[0] = (h-2)*(w-2) 
adjust_counter = collections.Counter([])
adjust_list = [ [i,j] for i in range(-1,2) for j in range(-1,2)]


def makehash(a,b):
    return a*10**9+b

for i in range(n):
    a, b = [ int(v) - 1 for v in input().split() ]
    for j in adjust_list:
        p, q = j
        if 1 <= p+a <= h-2 and 1 <= q+b <= w-2:
            c = adjust_counter[makehash(p+a,q+b)]
            adjust_counter[makehash(p+a,q+b)] += 1
            ans_list[c] -= 1
            ans_list[c+1] += 1

for i in ans_list:
    print(i)

Measured memory_bytes: 130556
def main():
    from collections import deque
    from math import ceil
    n, h, *ab = map(int, open(0).read().split())
    a = ab[::2]
    *b, = map(lambda x: -x, ab[1::2])
    c = a + b
    c.sort(key=lambda x: abs(x), reverse=True)

    q = deque(c)
    cnt = 0
    while h > 0:
        cnt += 1
        x = q.popleft()
        h -= abs(x)
        if x > 0:
            cnt += ceil(h / x)
            break

    print(cnt)


if __name__ == '__main__':
    main()


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

typedef pair<int, int> P;
typedef struct cheese {
    P p;
    int hd;
    cheese(P p, int hd) : p(p), hd(hd) {}
} cheese;

const int INF = 1e8;
const int MAX_N = 1010;
int m, n, total;
char map[MAX_N][MAX_N];
int tm[MAX_N][MAX_N];
vector<cheese> che;

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

int bfs(int sx, int sy, int ex, int ey) {
    queue<P> que;
    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++)
            tm[i][j] = INF;
    que.push(P(sx, sy));
    tm[sx][sy] = 0;
    
    while (que.size() > 0) {
        P p = que.front();
        que.pop();
        if (p.first == ex && p.second == ey) return tm[ex][ey];
        
        for (int i = 0; i < 4; i++) {
            int nx = p.first+dx[i], ny = p.second+dy[i];
            if (nx >= 0 && nx < m && ny >=0 && ny < n && map[nx][ny] != 'X' && tm[nx][ny] == INF) {
                que.push(P(nx, ny));
                tm[nx][ny] = tm[p.first][p.second]+1;
            }
        }
    }
    return -1;
}

bool cmp(cheese a, cheese b) {
    return a.hd < b.hd;
}

int main() {
    cin >> m >> n >> total;
    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++) {
            cin >> map[i][j];
            if (map[i][j] == 'S') {
                sx = i;
                sy = j;
            }
            if (map[i][j] > '0' && map[i][j] <= '9')
                che.push_back(cheese(P(i, j), map[i][j]-'0'));
        }
    sort(che.begin(), che.end(), cmp);
    int sum = bfs(sx, sy, che[0].p.first, che[0].p.second);
    for (vector<cheese>::iterator it = che.begin(); it < che.end()-1; it++) {
        int sx = it->p.first, sy = it->p.second;
        int ex = (it+1)->p.first, ey = (it+1)->p.second;
        sum += bfs(sx, sy, ex, ey);
    }
    cout << sum << endl;
    return 0;
}



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

class Main {
    public static void main(String[] args) {
        try {
        	BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        	int n = Integer.parseInt( kb.readLine( ) );
			String[] str = kb.readLine( ).split( " " );
			int[] S = new int[ n ];
			for( int i=0; i<n; i++ ) {
				S[i] = Integer.parseInt( str[i] );
			}

        	int q = Integer.parseInt( kb.readLine( ) );
			str = kb.readLine( ).split( " " );
			int[] T = new int[ q ];
			for( int i=0; i<q; i++ ) {
				T[i] = Integer.parseInt( str[i] );
			}

			int cnt = 0;
			for( int i=0; i<q; i++ ) {
				for( int j=0; j<n; j++ ) {
					if( T[i] == S[j] ) {
						cnt++;
						break;
					}
				}
			}
			System.out.println( cnt );

        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

Measured memory_bytes: 23316
#include <stdio.h>

int main(void)
{
	char* s = new char[100000];
	int ans = 0;

	scanf("%s", s);

	int idx = 1, tmpCnt = 0, cnt = 0;
	char frontColor = s[0];
	for (int i = 1; s[i] != '\0'; i++)
	{
		if (s[i] != frontColor)
			tmpCnt++;
		else
		{
			tmpCnt = 0;
			if (tmpCnt > cnt)
			{
				cnt = tmpCnt;
				idx = i;
			}
		}
		frontColor = s[i];
	}
	idx = idx - 1;
	char firstChar, secondChar;

	if (idx % 2 == 0)
	{
		if (s[idx] == '0')
			firstChar = '1';
		else
			firstChar = '0';
		secondChar = s[idx];
	}
	else
	{
		if (s[idx] == '0')
			secondChar = '1';
		else
			secondChar = '0';
		firstChar = s[idx];
	}

	for (int i = 0; s[i] != '\0'; i++)
	{
		if (i % 2 == 0 && s[i] != secondChar)
			ans++;
		if (i % 2 == 1 && s[i] != firstChar)
			ans++;
	}

	printf("%d", ans);

	delete[] s;
	return 0;
}

Measured memory_bytes: 384
S = input()
ok = True

ok &= list(S) == list(reversed(S))
ok &= list(S[:(len(S)-1)//2]) == list(reversed(S[:(len(S)-1)//2]))
ok &= list(S[(len(S)+3)//2-1:]) == list(reversed(S[(len(S)+3)//2-1:]))

if ok:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}
bool bitcheck(ll x, ll y) { return (x >> y) & 1; }

template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

const ll INF = 1LL << 60;

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
int main() {
    ll q;
    cin >> q;
    map<string, ll> cnt;
    REP(i, q) {
        ll a, x;
        string key;
        cin >> a;
        if (a == 0) {
            cin >> key >> x;
            cnt[key] = x;
        } else {
            cin >> key;
            cout << cnt[key] << endl;
        }
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	int a[n];
	rep(i, n) cin >> a[i];

	int ans = 0;
	rep(i, n){
		while(a[i] % 2 == 0){
			a[i] /= 2;
			ans++;
		}
	}

	cout << ans << endl;
}

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


int main() {
    ll H, W;

    cin >> H >> W;

    ll A,B,C,D;
    A = (W+1)/2;
    B = (H+1)/2;
    C = W/2;
    D = H/2;
    
    ll ans = A*B + C*D;

    if (H == 1 || W == 1) {
        ans = 1;
    }
    

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int n; int a[100000];
int gcd(int x,int y) {
	if (x < y)swap(x, y);
	while (y) {
		int r = x % y; x = y; y = r;
	}
	return x;
}
bool tra() {
	int cnt = 0;
	rep(i, n) {
		if (a[i] % 2 == 0)cnt++;
	}
	if (cnt % 2)return true;
	else if (cnt != n - 1)return false;
	else {
		rep(i, n) {
			if (a[i] % 2) {
				if (a[i] == 1)return false;
				a[i]--;
			}
		}
		int g = a[0];
		Rep(i, 1, n) {
			g = gcd(a[i], g);
		}
		rep(i, n) {
			a[i] /= g;
		}
		return !tra();
	}
}
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	if (tra())cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
cin >> S >> T; 
int A[30] = {}; 
string ans = "Yes"; 
for(int i = 0; i < S.size(); i++){
if(A[S.at(i) - 'a'] == 0){
A[S.at(i) - 'a'] = T.at(i) - 'a' + 1; 
}
else if(A[S.at(i) - 'a'] != T.at(i) - 'a' + 1){
ans = "No"; 
break; 
}
}
int B[30] = {}; 
for(int i = 0; i < T.size(); i++){
if(B[T.at(i) - 'a'] == 0){
B[T.at(i) - 'a'] = S.at(i) - 'a' + 1; 
}
else if(B[T.at(i) - 'a'] != S.at(i) - 'a' + 1){
ans = "No"; 
break; 
}
}
cout << ans << endl; 
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int a,b,c,x,y; cin >> a >> b >>c >>x >>y;

    int res=INF;
    for(int ab=0; ab<=max(x,y)*2; ab+=2){
        chmin(res,max(0LL,(x-ab/2))*a+max(0LL,(y-ab/2))*b+c*ab);
    }
    cout<<res<<endl;
}

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

int main(){
  string a;
  cin >> a;
  int b=0,c=0;
  for(int i=0;i<3;i++){
    if(a.at(i)=='A'){
      b++;
    }
    if(a.at(i)=='B'){
      c++;
    }
  }
  if(b==3 || c==3)cout << "No" <<endl;
  else{
    cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 256
tanka = (5, 7, 5, 7, 7, 0)
words = list()
n = int()

def rec(step, itr, word):
    if step == 5:
        return True

    if word == 0:
        return rec(step + 1, itr, tanka[step + 1])
    elif word < 0:
        return False
    
    return rec(step, itr + 1, word - words[itr])

while True:
    n = int(input())
    if n == 0:
        break

    words = [len(str(input())) for i in range(n)]
    for i in range(n):
        if rec(0, i, tanka[0]):
            print(i + 1)
            break


Measured memory_bytes: 5616
fun main(args :Array<String>){
    readLine()
    val cities = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    val powers = readLine()!!.split(" ").map { it.toInt() }.toMutableList()

    var sum :Long = 0
    for(i in powers.indices){
        val con1 = Math.min(cities[i],powers[i])
        cities[i] -= con1
        powers[i] -= con1
        val con2 = Math.min(cities[i+1],powers[i])
        cities[i+1] -= con2
        powers[i] -= con2

        sum += con1+con2
    }
    println(sum)
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define PQ priority_queue
#define GT(type) greater < type >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 47;
const int MAXM = 4007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}

	int u, v, last;
}edge[MAXM];

int n, m;
int ans;
int a[MAXN];
int ke, la[MAXN];
int cc[MAXN];

void init ();
void input ();
void work ();

void srch ( int now, int na );



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d%d", &n, &m );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
	int u, v;
	ke = 0;
	INIT ( la, -1 );
	lp ( i, 0, m ){
		scanf ( "%d%d", &u, &v );
		edge[ke].setd ( u, v, la[u] );
		la[u] = ke++;
		edge[ke].setd ( v, u, la[v] );
		la[v] = ke++;
	}
}

void work ()
{
	// main work

	ans = INF;
	cc[1] = 1;
	srch ( 1, a[1] );

	printf ( "%d\n", ans );
}



void srch ( int now, int na )
{
	if ( na >= ans ) return;
	if ( now == n ){
		for ( int i = la[now]; ~i; i = edge[i].last ) if ( !cc[edge[i].v] ) na += a[edge[i].v];
		ans = qmin ( ans, na );
		return;
	}

	int ta;
	ta = na;
	for ( int j = la[now]; ~j; j = edge[j].last ) if ( !cc[edge[j].v]++ ) ta += a[edge[j].v];

	for ( int i = la[now]; ~i; i = edge[i].last ){
		if ( cc[edge[i].v] == 1 ){
			srch ( edge[i].v, ta );
		}
	}

	for ( int j = la[now]; ~j; j = edge[j].last ) --cc[edge[j].v];
}

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

int main(){
	int w,h,n,kazu=0;
  	cin >> w >> h >>n;
  	int x[n],y[n],a[n];
  	for (int i=0;i<n;i++){
    	cin >> x[i] >> y[i] >> a[i];
    }
  	for (float tate=0.5;tate<=h;tate++){
    	for (float yoko=0.5;yoko<=w;yoko++){
        	int f=0;
          	for (int i=0;i<n;i++){
            if (a[i]==1 && x[i]>yoko) f++;
            if (a[i]==2 && x[i]<yoko) f++;
            if (a[i]==3 && y[i]>tate) f++;
            if (a[i]==4 && y[i]<tate) f++;
            }
            if (f==0) kazu++;
        }
    }
  	cout << kazu << endl;
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    assert_eq!(!0usize, std::usize::MAX); //🙊
    assert!(0 == 0); //😇

    let (x, n) = (io.read::<usize>(), io.read::<usize>());
    let p = io.readn::<usize>(n);
    let mut v = vec![false; 102];
    for &i in p.iter() {
        v[i] = true;
    }
    let mut ans = 102;
    for i in (0..102).rev() {
        if !v[i] {
            if (x as i64 - i as i64).abs() <= (x as i64 - ans as i64).abs() {
                ans = i;
            }
        }
    }
    io.writeln(ans);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


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

int main(){
  int n;cin>>n;
  vector<int> x(n,0);
  REP(i,n) cin>>x.at(i);
  sort(x.begin(),x.end());
  cout<<x.at(x.size()-1)-x.at(0);
}

Measured memory_bytes: 256
S = input()

Q = int(input())

array = ["" for i in range(Q*2+1)]

array[Q] = S
order = 0

for i in range(Q):
    s = input().split()
    #print ("s=", s)
    if s[0] == '1':
        order = 1 - order
    elif s[1] == '1':
        if order == 0:
            array[Q-(i+1)] = s[2]
        else:
            array[Q+(i+1)] = s[2]
    elif s[1] == '2':
        if order == 0:
            array[Q+(i+1)] = s[2]
        else:
            array[Q-(i+1)] = s[2]

#print("array=",array)

if order == 0:
    for i in range(2*Q+1):
        print(array[i],sep="",end="")
else:
    for i in range(2*Q, -1,-1):
        for j in range(len(array[i])):
            print(array[i][len(array[i])-1-j],sep="",end="")


Measured memory_bytes: 17008
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

ll cnt_digit(ll n){
    ll ret = 0;
    while(n>0){
        n /= 10;
        ret++;
    }
    return ret;
}

int main(){
    ll n;
    cin >> n;
    ll ans = cnt_digit(n);
    for (ll i = 1LL; i*i <= n; i++) {
        if(n%i!=0)continue;
        ll a = i, b = n/i;
        ll f = max(cnt_digit(a), cnt_digit(b));
        chmin(ans,f);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
hs = list(map(int, input().split()))


max_cnt = 0
tmp_cnt = 0
for i in range(n-1):
    if hs[i] >= hs[i+1]:
        tmp_cnt += 1
    else:
        tmp_cnt = 0

    max_cnt = max(max_cnt, tmp_cnt)

print(max_cnt)


Measured memory_bytes: 14228
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

bool Check(string& s){
  stack<char> stk;
  for(auto c:s){
    if(c=='('){
      stk.push(c);
    }else{
      if(stk.empty()){
        return false;
      }else{
        stk.pop();
      }
    }
  }
  return (stk.empty());
}

bool comp_pre(string& a, string& b){
  int c=-1,d=-1;
  for(int i=0;i<a.size();i++){
    if(a[i]=='('){
      c=i;
      break;
    }
  }
  for(int i=0;i<b.size();i++){
    if(b[i]=='('){
      d=i;
      break;
    }
  }
  assert(c>=1);
  assert(d>=1);

 return c<d;


}

bool comp_aft(string& a, string& b){
  int c=-1,d=-1;
  for(int i=0;i<a.size();i++){
    if(a[i]=='('){
      c=i;
      break;
    }
  }
  for(int i=0;i<b.size();i++){
    if(b[i]=='('){
      d=i;
      break;
    }
  }
  assert(c>=1);
  assert(d>=1);

  return a.size()-c>b.size()-d;


}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  vector<string> l,r,wp,wa;

  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    stack<char> stk;
    for(auto c:s){
      if(c=='('){
        stk.push(c);
      }else{
        if(stk.empty()||stk.top()==')'){
          stk.push(c);
        }else{
          stk.pop();
        }
      }
    }
    string res;
    while(!stk.empty()){
      res+=stk.top();
      stk.pop();
    }

    reverse(res.begin(),res.end());
    if(res.empty()){
      continue;
    }
    if(res.front()!=res.back()){
      assert(res.front()==')');
      int c=-1;
      for(int i=0;i<res.size();i++){
        if(res[i]=='('){
          c=i;
          break;
        }
      }
      if(res.size()-c>=c){
        wp.push_back(res);
      }else{
        wa.push_back(res);
      }
    }else{
      if(res.front()=='('){
        l.push_back(res);
      }else{
        r.push_back(res);
      }
    }




  }

  sort(wp.begin(),wp.end(),comp_pre);
  sort(wa.begin(),wa.end(),comp_aft);

  string remain;
  for(auto& t:l){
    remain+=t;
  }
  for(auto& t:wp){
    remain+=t;
  }
  for(auto t:wa){
    remain+=t;
  }
  for(auto& t:r){
    remain+=t;
  }


  cout<<(Check(remain)?"Yes":"No")<<endl;


  return 0;
}




Measured memory_bytes: 37456
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

int main(void){
	uint32_t x=nextpint();
	for(int32_t a=-119; a<=119; a++){
		int64_t p=(int64_t)a*a*a*a*a-(int64_t)(a+1)*(a+1)*(a+1)*(a+1)*(a+1);
		if(p==x){
			printf("%"PRId32" %"PRId32"\n", a, a+1);
			return 0;
		}
		if(-p==x){
			printf("%"PRId32" %"PRId32"\n", a+1, a);
			return 0;
		}
	}
	for(int32_t a=-100; a<=100; a++){
		for(int32_t b=-100; b<=100; b++){
			int64_t p=(int64_t)a*a*a*a*a-(int64_t)b*b*b*b*b;
			if(p==x){
				printf("%"PRId32" %"PRId32"\n", a, b);
				return 0;
			}
		}
	}
}


Measured memory_bytes: 1600
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

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

const int INF = 0x0f0f0f0f;

int H, W;
int n_edges;
vector<int> adj[900];
vector<int> edges[900];
int dist[2*29*30][900];
int dp[900*2][900];

void make_edge(int y1, int x1, int y2, int x2) {
  adj[W*y1 + x1].push_back(W*y2 + x2);
  adj[W*y2 + x2].push_back(W*y1 + x1);
  edges[W*y1 + x1].push_back(n_edges);
  edges[W*y2 + x2].push_back(n_edges);
  ++n_edges;
}

int main() {
  while (scanf("%d%d", &H, &W), H|W) {
    n_edges = 0;
    REP(i, H*W) { adj[i].clear(); }
    REP(i, H*W) { edges[i].clear(); }

    REP(i, 2*H-1) {
      int l = i%2, y = i/2;
      REP(x, W+l-1) {
        int d; scanf("%d", &d);
        if (d == 0) { make_edge(y, x, y+l, x-l+1); }
      }
    }

    memset(dist, INF, sizeof(dist));
    REP(i, n_edges) {
      queue<int> Q;
      Q.push(H*W-1);
      dist[i][H*W-1] = 0;
      while (!Q.empty()) {
        int v = Q.front(); Q.pop();
        REP(j, adj[v].size()) {
          int w = adj[v][j], e = edges[v][j];
          if (e == i || dist[i][w] != INF) { continue; }
          dist[i][w] = dist[i][v] + 1;
          Q.push(w);
        }
      }
    }

    memset(dp, INF, sizeof(dp));
    REP(k, 2*H*W) { dp[k][H*W-1] = 0; }
    FOR(k, 1, 2*H*W) {
      REP(v, H*W) {
        REP(i, adj[v].size()) {
          int w = adj[v][i], e = edges[v][i];
          dp[k][v] = min(dp[k][v], max(dist[e][v], dp[k-1][w]+1));
        }
      }
    }

    printf("%d\n", dp[2*H*W-1][0] < INF ? dp[2*H*W-1][0] : -1);
  }
}

Measured memory_bytes: 0
S = input()
ans = "No"
if S == "hi":
    ans = "Yes"
elif S == "hihi":
    ans = "Yes"
elif S == "hihihi":
    ans = "Yes"
elif S == "hihihihi":
    ans = "Yes"
elif S == "hihihihihi":
    ans = "Yes"
print(ans)


Measured memory_bytes: 38384
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  vector<int> v(3);
  for (int i = 0; i < 3; ++i) cin >> v[i];
  sort(all(v));
  for (int i = 0; i < 3; ++i) {
    cout << v[i];
    if (i != 2) {
      cout << " ";
    } else {
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main(){
    int h,w;
    cin>>h>>w;
    char a[102][102];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i+1][j+1];
        }
    }
    for(int i=0;i<h+3;i++){
        a[i][0]='#';
        a[i][w+1]='#';
    }
    for(int j=0;j<w+3;j++){
        a[0][j]='#';
        a[h+1][j]='#';
    }
    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#define inf 999999999
using namespace std;

typedef int weight;
typedef vector<weight> array;
typedef vector<array> matrix;

void backward_traverse(int v, int s, int r, matrix &g,
  vector<int> &no, vector< vector<int> > &comp,
  vector<int> &prev, vector<weight> &mcost,
  vector<int> &mark, weight &cost, bool &found) {
  const int n = g.size();
  if (mark[v]) {
    vector<int> temp = no;
    found = true;
    do {
      cost += mcost[v];
      v = prev[v];
      if (v != s) {
        while (comp[v].size() > 0) {
          no[comp[v].back()] = s;
          comp[s].push_back(comp[v].back());
          comp[v].pop_back();
        }
      }
    } while (v != s);
    for (int j = 0; j < n; ++j)
      if (j != r && no[j] == s)
        for (int i = 0; i < n; ++i)
          if (no[i] != s && g[j][i] < inf)
            g[j][i] -= mcost[ temp[j] ];
  }
  mark[v] = true;
  for (int i = 0; i < n; ++i)
    if (no[i] != no[v] && prev[ no[i] ] == v)
      if (!mark[ no[i] ] || i == s)
        backward_traverse(i, s, r, g,
            no, comp, prev, mcost, mark, cost, found);
}

weight minimum_spanning_arborescence(int r, matrix &g) {
  const int n = g.size();

  vector<int> no(n);
  vector< vector<int> > comp(n);
  for (int i = 0; i < n; ++i) {
    no[i] = i;
    comp[i].push_back(i);
  }
  weight cost = 0;
  while (1) {
    vector<int> prev(n, -1);
    vector<weight> mcost(n, inf);
    for (int j = 0; j < n; ++j) {
      if (j == r) continue;
      for (int i = 0; i < n; ++i) {
        if (no[i] != no[j] && g[j][i] < inf) {
          if (g[j][i] < mcost[ no[j] ]) {
            mcost[ no[j] ] = g[j][i];
            prev[ no[j] ] = no[i];
          }
        }
      }
    }
//for(int I=0;I<n;I++)printf("%d\n",mcost[I]);
    bool stop = true;
    vector<int> mark(n);
    for (int i = 0; i < n; ++i) {
      if (i == r || mark[i] || comp[i].size() == 0) continue;
      bool found = false;
      backward_traverse(i, i, r, g,
          no, comp, prev, mcost, mark, cost, found);
      if (found) stop = false;
    }
    if (stop) {
      for (int i = 0; i < n; ++i)
        if (prev[i] >= 0)
          cost += mcost[i];
      return cost;
    }
  }
}

int main(){
	int V,E,r,s,t,w;
	scanf("%d%d%d",&V,&E,&r);
	matrix g(V);
	for(s=0;s<V;s++){
		g[s].resize(V);
		for(t=0;t<s;t++)g[s][t]=inf;
		g[s][t++]=0;
		for(;t<V;t++)g[s][t]=inf;
	}
	for(;E--;)scanf("%d%d%d",&s,&t,&w),g[t][s]=w;
	printf("%d\n",minimum_spanning_arborescence(r,g));
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int table[365][26];
int main()
{	
	int D;
	cin >> D;
	vec(C);
	vec(Las);
	fx(26) {
		vecp(C);
		Las.push_back(0);
	}

	fx(D) {
		fy(26) {
			cin >> table[x][y];
		}
	}
	vector<int> T(D);
	int k = 0;
	fx(26) {
		if (k < table[0][x]) {
			T[0] = x+1;
			k = table[0][x];
		}
	}
	fx(D-1) {
		ll res = -LLONG_MAX;
		int las = 0;
		fy(26) {
			ll sum = 0;
			sum += table[x + 1][y];
			fz(26){
				if (y == z) { continue; }
				sum -= C[z] * (x + 1 - Las[z]);
			}

			if (res<sum) {
				res = sum;
				T[x + 1] = y+1;
				las = y;
			}
		}
		Las[las] = x + 1;
	}

	ll sum = -INT_MAX,sumPre=-INT_MAX;
	srand(time(NULL));
	fx(200000) {
		int d, q;
		d = rand() % D + 1;
		q = rand() % 26 + 1;
		if (sum==sumPre) {
			int d3 = rand() % 4;
			while (d3==0) {
				d3 = rand() % 4;
			}
			int sign = rand() % 2;
			int d2;
			if (sign==0) {
				d2 = min(d + d3,D);
			}
			else {
				d2 = max(d - d3,1);
			}
			T[d - 1] ^= T[d2 - 1];
			T[d2 - 1] ^= T[d - 1];
			T[d - 1] ^= T[d2 - 1];
		}
		int pre = T[d - 1];

		T[d - 1] = q;
		ll ans = 0;

		fy(26) {
			Las[y] = 0;
		}
		fw(D) {

			ans += table[w][T[w] - 1];
			Las[T[w] - 1] = w + 1;
			fz(26) {
				ans -= C[z] * (w + 1 - Las[z]);
			}

		}
		if (ans > sum) {
			sum = ans;
		}
		else {
			T[d - 1] = pre;
		}
	}


	fx(D) {
		ce(T[x])
	}
    return 0;
}



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

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define nfor(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i < int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define x first
#define y second

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int, int> pti;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

template<typename A, typename B> inline ostream& operator<< (ostream& out, const pair<A, B>& p) { return out << "(" << p.x << ", " << p.y << ")"; }
template<typename T> inline ostream& operator<< (ostream& out, const vector<T>& a) { out << "["; forn(i, sz(a)) { if (i) out << ','; out << ' ' << a[i]; } return out << " ]"; }
template<typename T> inline ostream& operator<< (ostream& out, const set<T>& a) { return out << vector<T>(all(a)); }
template<typename X, typename Y> inline ostream& operator<< (ostream& out, const map<X, Y>& a) { return out << vector<pair<X, Y>>(all(a)); }
template<typename T> inline ostream& operator<< (ostream& out, const pair<T*, int>& a) { return out << vector<T>(a.x, a.x + a.y); }

inline ld gett() { return ld(clock()) / CLOCKS_PER_SEC; }

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;

#ifdef SU1
//#define GEN
#ifndef GEN
#define LOG
#endif
#endif

string s;

bool read() {
  return !!(cin >> s);
}

void solve() {
  if (s[0] != 'A') {
    clog << 1 << endl;
    puts("WA");
    return;
  }

  if (std::count(s.begin() + 2, s.end() - 1, 'C') != 1) {
    clog << 2 << endl;
    puts("WA");
    return;
  }

  for (auto c : s)
    if (c != 'A' && c != 'C' && isupper(c)) {
      clog << 3 << endl;
      puts("WA");
      return;
    }

  puts("AC");
}

int main() {
#ifdef SU1
  assert(freopen("input.txt", "rt", stdin));
  //assert(freopen("output.txt", "wt", stdout));
#endif

  cout << setprecision(10) << fixed;
  cerr << setprecision(5) << fixed;

  while (read()) {
    ld stime = gett();
    solve();
#ifdef SU1
    cerr << "Time: " << gett() - stime << endl;
#endif
    //break;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  char C;
  cin >> C;
  string s = "abcdefghijklmnopqrstuvwxyz";
  // 26 letters at total
  for (int i = 0; i < 25; i++){
    if (C == s.at(i)){
      cout << s.at(i+1) << endl;
      break;
    }
    else{
    }
    
  }
  return 0;
}
  
  


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <algorithm>
#define mp make_pair

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;

const int MAXN = 1e5 + 7;

template<typename T> inline T read() {
	T res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

template<typename T> inline void chkmax(T &a, T b) { if(a < b) a = b; }
template<typename T> inline void chkmin(T &a, T b) { if(a > b) a = b; }

int dp[MAXN], h[MAXN], n, k;

inline void solve() {
	n = read<int>(); k = read<int>();
	for(int i = 1; i <= n; ++i) h[i] = read<int>();
	memset(dp, 0x3f, sizeof dp);
	dp[0] = dp[1] = 0;
	for(int i = 2; i <= n; ++i)
		for(int j = 1; j < i && j <= k; ++j) chkmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
	printf("%d\n", dp[n]);
}

int main() {
	solve();

	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define re(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int b[n-1];
    rep(i,n-1){
        cin>>b[i];
    }
    int ans=b[0]+b[n-2];
    if(n==2){
        cout<<ans<<endl;
        return 0;
    }
    rep(i,n-2){
        ans+=min(b[i],b[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256