akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int cnt_bit(int b) {

    int cnt = 0;

    if(b < 0) {
        b *= -1;
    }

    while(b) {
        cnt += b & 1;
        b >>= 1;
    }

    return cnt;
}

int main() {

    int n;
    int s, d;

    cin >> n;

    for(int i = 0; i < n; ++i) {

        int bs, bd;

        cin >> s >> d;

        bs = cnt_bit(s);
        bd = cnt_bit(d);

        if(s == 0) {
            cout << bd << endl;
        } else if(d == 0) {
            cout << bs << endl;
        } else if(s < 0 && d < 0) {
            int digit, cnt = 0;
            s *= -1;
            d *= -1;
            while(s != d) {
                digit = 0;
                while(!((d >> digit) & 1)) {
                    ++digit;
                }
                for(int i = digit; i >= 0; --i) {
                    if(d + (1 << i) <= s) {
                        d += 1 << i;
                        ++cnt;
                        break;
                    }
                }
            }
            cout << cnt << endl;
        } else if(s > 0 && d > 0) {
            int digit, cnt = 0;
            while(s != d) {
                digit = 0;
                while(!((s >> digit) & 1)) {
                    ++digit;
                }
                for(int i = digit; i >= 0; --i) {
                    if(s + (1 << i) <= d) {
                        s += 1 << i;
                        ++cnt;
                        break;
                    }
                }
            }
            cout << cnt << endl;
        } else {
            cout << bs + bd << endl;
        }

    }

    /*
    3  11
    5 101

    23 10111
    18 10010

    12 1100
    9  1001

    1 2 3 4 5 6
    2 4 6 8 10 12
    4 8 12 16 20
    8 16 24 32 40
    */

}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
int a,b5,b7;
int main()
{
	for(int s=0;s<3;s++)
	{
		cin>>a;
		if(a==5)b5++;
		if(a==7)b7++;
	}
	if(b5==2&&b7==1)cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(),M = in();
    vector<bool> prob(N);
    vector<int> probb(N);
    vector<int> p(M);
    vector<string> S(M);
    REP(i,M){
        p[i] = in()-1;
        S[i] = in<string>();
    }
    int wa = 0;
    int ac = 0;
    REP(i,M){
        if(S[i] == "WA" && prob[p[i]] == 0)probb[p[i]]++;
        if(S[i] == "AC" && prob[p[i]] == 0){
            ac++;
            prob[p[i]] = 1;
        }
    }
    REP(i,N){
        if(prob[i] == 1)wa+=probb[i];
    }
    cout << ac << "\n";
    cout << wa << "\n";
}

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

int main(){
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int h = 0;
    int w = 0;
    char v = 'r';
    vector<vector<int>> c(H, vector<int>(W, 0));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < a[i]; j++){
            c[h][w] = i+1;
            if(h != 0 && w == 0 && v == 'l'){
                v = 'r';
                h++;
            }
            else if(w == W-1 && v == 'r'){
                v = 'l';
                h++;
            }
            else if(v == 'r'){
                w++;
                //cout << w << endl;
            }
            else if(v == 'l'){
                w--;
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << c[i][j] << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

var (
	dp    [3001][3001][4]int
	goods [3000][3000]int
)

func main() {
	defer flush()

	R := readInt()
	C := readInt()
	K := readInt()
	for i := 0; i < K; i++ {
		r := readInt() - 1
		c := readInt() - 1
		v := readInt()
		goods[r][c] = v
	}

	for i := 0; i < R; i++ {
		for j := 0; j < C; j++ {
			if goods[i][j] != 0 {
				for k := 2; k >= 0; k-- {
					dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k]+goods[i][j])
				}
			}
			for k := 0; k < 4; k++ {
				dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k])
				dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k])
			}
		}
	}

	result := -1
	for k := 0; k < 4; k++ {
		result = max(result, dp[R-1][C-1][k])
	}

	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 357600
#include<stdio.h>

int h,i,a,b,c,x,y,z;

int main(){
    scanf("%d",&h);
    while(h--){
        scanf("%d",&a);
        b=c=0;x=y=1;
        for(i=1;i<10;i++){
            scanf("%d",&z);
            if(a>z && b>z)c=1;
            else if(a<z && b<z){
                if(a>b)a=z;
                else b=z;
            }else{
                if(a>b)b=z;
                else a=z;
            }
        }
        printf("%s\n",(c==0)?("YES"):("NO"));
    }
    
    return 0;
}
		


Measured memory_bytes: 2048
#!/usr/bin/env pypy3

import sys
import pprint
from math import gcd


sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	k = int(sys.stdin.readline())
	s = 0
	for a in range(1, k+1):
		for b in range(1, k+1):
			x = gcd(a, b)
			for c in range(1, k+1):
				s += gcd(x, c)
	print(s)
	


main()

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

int N;
int A[210];

int main(){
    
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;

    while (true) {
        bool exist_odd = false;
        for (int i = 0; i < N; ++i) {
            if (A[i]%2!=0) exist_odd = true;
        }

        if (exist_odd) break;

        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;

    }

    cout << res << endl;

}

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

typedef long long ll;
ll n,s,ans=1e12;

ll work(ll x,ll y){
    ll res=0;
    while(y){
        res+=y%x;
        y/=x;
    }
    return res;
}

int main(){
    scanf("%lld%lld",&n,&s);
    if(s>n) return printf("-1"),0;
    if(s==n) return printf("%lld",n+1),0;
    ll ed=sqrt(n-s);
    for(ll i=1;i<=ed;i++){
        if((n-s)%i) continue;
        if(work(i+1,n)==s)
            ans=min(ans,i+1);
        if(work((n-s)/i+1,n)==s)
            ans=min(ans,(n-s)/i+1);
    }
    printf("%lld\n",ans==1e12?-1:ans);
}


Measured memory_bytes: 128
#[allow(non_snake_case)]

fn main() {
    for n in 1..10001 {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let X = buf.trim().parse::<isize>().unwrap();
        if 0 == X {break;}
        println!("Case {}: {}", n, X);
    }
}



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

class SegmentTree {
private:
	int sequence_size_{1};
	std::vector<int> container_;
	int find_impl_(int, int, int, int, int);
	int update_impl_(int, int, int, int, int);
public:
	SegmentTree(int);
	void update(int, int);
	int find(int, int);
};

SegmentTree::SegmentTree(int n)
{
	// 要素数は簡単のために2べきで
	while (sequence_size_ < n) sequence_size_ <<= 1;
	// 根ノード:0
	// 内部ノード:[1, sequence_size - 1)
	// 葉ノード（数列要素）:[sequence_size - 1, 2 * sequence_size - 1)
	container_.resize(2 * sequence_size_ - 1, ((long long)1 << 31) - 1);
}

// 数列のplaceの場所をkeyに変える
int SegmentTree::update_impl_(int place, int key, int index, int node_left, int node_right)
{
	// 範囲に入ってなかったらそのまま値を返す
	if (place < node_left || node_right <= place) return container_[index];
	// 以下範囲にplaceが入ってるノードのみ

	// 葉ノードなら変更箇所そのものだからただ更新してその値を返す
	if (node_left + 1 == node_right)
	{
		container_[index] = key;
		return container_[index];
	}
	// 内部ノードならその子ノードについて再帰的に更新
	// 子ノードの最小値がこのノードの最小値
	int mid{(node_left + node_right) / 2};
	int left_min{this->update_impl_(place, key, 2 * index + 1, node_left, mid)};
	int right_min{this->update_impl_(place, key, 2 * index + 2, mid, node_right)};
	container_[index] = std::min(left_min, right_min);
	return container_[index];
}

void SegmentTree::update(int place, int key)
{
	this->update_impl_(place, key, 0, 0, this->sequence_size_);
}

// 入力範囲[left, right)に対する最小値を探す
// 注目しているノードindexの範囲は[node_left, node_right)
int SegmentTree::find_impl_(int left, int right, int index, int node_left, int node_right)
{
	// 入力の範囲がノードの範囲と一切一致しない場合infを返す
	if (node_right <= left || right <= node_left) return ((long long)1 << 31) - 1;
	// 葉ノードなら値をそのまま返す
	if (node_left + 1 == node_right) return container_[index];
	// ノードの範囲が入力の範囲に完全に含まれる場合はそのまま値を返す
	if (left <= node_left && node_right <= right)
		return container_[index];
	
	// 内部ノードなら再帰的に
	int mid{(node_left + node_right) / 2};
	int left_min{this->find_impl_(left, right, 2 * index + 1, node_left, mid)};
	int right_min{this->find_impl_(left, right, 2 * index + 2, mid, node_right)};
	return std::min(left_min, right_min);
}

int SegmentTree::find(int left, int right)
{
	return this->find_impl_(left, right, 0, 0, this->sequence_size_);
}

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	SegmentTree rmq(n);
	for (int q_loop{}; q_loop < q; q_loop++)
	{
		int com, x, y;
		scanf("%d%d%d", &com, &x, &y);
		switch(com)
		{
		case 0:
			rmq.update(x, y);
			break;
		case 1:
			printf("%d\n", rmq.find(x, y + 1));
			break;
		}
	}
	return 0;
}


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

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

  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> pref_year_city(m);
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    pref_year_city[i] = make_tuple(p, y, i);
  }
  sort(pref_year_city.begin(), pref_year_city.end());
  vector<int> pref_id(m), cnt_id(m), cnt(n + 1);
  for(auto& pyc : pref_year_city) {
    int pref, city;
    tie(pref, ignore, city) = pyc;
    pref_id[city] = pref;
    ++cnt[pref];
    cnt_id[city] = cnt[pref];
  }
  rep(i, m) {
    cout << setfill('0') << setw(6) << pref_id[i];
    cout << setfill('0') << setw(6) << cnt_id[i] << "\n";
  }
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
int n, q;
struct N {
  ll l, r, x, i;
};
struct M {
  ll type, x, i, d;
};

bool operator<(const M &l, const M &r) {
  if (l.x == r.x) {
    return l.type < r.type;
  }
  return l.x < r.x;
}


bool operator<(const N &l, const N &r) { return l.x < r.x; }

vector<N> ps;
vector<ll> d;

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

  ps.resize(n);
  vector<M> ms(q + n * 2);
  for (int i = 0; i < n; i++) {
    cin >> ps[i].l >> ps[i].r >> ps[i].x;
    ps[i].i = i;
    ms[q + i * 2].d = ps[i].x;
    ms[q + i * 2].type = ps[i].x;
    ms[q + i * 2].x = ps[i].l - ps[i].x;
    ms[q + i * 2].i = i;
    ms[q + i * 2 + 1].d = ps[i].x;
    ms[q + i * 2 + 1].type = -ps[i].x;
    ms[q + i * 2 + 1].i = i;
    ms[q + i * 2 + 1].x = ps[i].r - ps[i].x;
  }
  sort(ps.begin(), ps.end());
  reverse(ps.begin(), ps.end());
  for (int i = 0; i < q; i++) {
    cin >> ms[i].x;
    ms[i].i = i;
    ms[i].d = -1;
    ms[i].type = 101010101010LL;
  }
  sort(ms.begin(), ms.end());
  vector<ll> ans(q);
  map<ll, int> s;
  for (int i = 0; i < ms.size(); i++) {
    if (ms[i].type == 101010101010LL) {
      if (s.size()) {
        ans[ms[i].i] = s.begin()->first;
      } else {
        ans[ms[i].i] = -1;
      }
    } else if (ms[i].type > 0) {
      s[ms[i].d]++;
    } else {
      if (s[ms[i].d] == 1) {
        s.erase(s.find(ms[i].d));
      } else {
        s[ms[i].d]--;
      }
    }
  }
  for (auto &d : ans) cout << d << endl;

  return 0;
}


Measured memory_bytes: 40320
n=gets.to_i


def tanaka(s)
i=1
answer=0   


s.times{
    
   answer+=i 
    
    i+=1
    
}
return answer    
    
end

answer2=(n*2)**0.5-1
answer2=answer2.to_i

loop{
  if tanaka(answer2)<n
     answer2+=1
else break
    
    
end
    
    
}


puts answer2




Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
int N, q;
std::vector<int> s, t;
int ubins(int a){
    int lb = 0, ub = t.size();
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        if(t[mid] > a) ub = mid;
        else lb = mid;
    }
    if(a == t[0]) return ub;
    return lb;
}
int lbins(int a){
    int lb = 0, ub = t.size();
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        if(t[mid] >= a) ub = mid;
        else lb = mid;
    }
    return lb;
}
int main(){
    std::cin >> N;
    s.resize(N);
    for(int i = 0; i < N; i++) std::cin >> s[i];
    std::cin >> q;
    t.resize(q);
    for(int i = 0; i < q; i++) std::cin >> t[i];
    std::sort(s.begin(), s.end());
    std::sort(t.begin(), t.end());
    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(i + 1 == N) ans += ubins(s[i]) - lbins(s[i]);
        else if(s[i] != s[i + 1]) ans += ubins(s[i]) - lbins(s[i]);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3316
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
#include <set>
using namespace std;


int main() {
    int N;
    string S;
    set<string> set;

    //
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> S;
        set.insert(S);
    }

    //
    if(set.size() == 3){
        cout << "Three" << endl;
    }else{
        cout << "Four" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from itertools import product
import numpy as np
N = int(input())
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = np.array([list(map(int, input().split())) for _ in range(N)])
M = np.array([0]*1023)
for i, f in enumerate(product([0, 1], repeat=10)) :
    if not any(f) : continue
    f = np.array(f)
    a = np.sum(F*f, axis=1)
    M[i-1] = sum([l[i] for l, i in zip(P, a)])
print(np.max(M))

Measured memory_bytes: 12480
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int e;
	while(cin>>e,e){
		int ans=INT_MAX;
		for(int z=0;z*z*z<=e;z++){
			for(int y=0;y*y+z*z*z<=e;y++){
				int x=e-y*y-z*z*z;
				ans=min(ans,x+y+z);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#define INF 1000000001
using namespace std;
typedef long long ll;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int a[3001];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += a[i] - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N;
    vector<LL> a(N);
    LL sn, ar;
    sn = 0; ar = 0;
    REP(i,N)
    {
        cin >> a[i];
        ar += a[i];
    }

    LL ans = LINF;

    REP(i,N)
    {
        if(i == N-1) continue;
        ar -= a[i];
        sn += a[i];
        LL tmp = abs(ar - sn);
        if(tmp < ans) ans = tmp;
    }
    cout << ans << endl;


}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,k,x;
vec ans,a[4],L,R;
vec rev(vec v){
	vec ans;
	ans.resize(n+1);
	FOR(i,1,n) ans[v[i]]=i;
	return ans;
}
vec mul(vec a,vec b){
	vec c;
	c.clear();
	c.pb(0);
	FOR(i,1,n) c.pb(b[a[i]]);
	return c;
}
vec pw(vec x,int y){
	vec t;
	t.clear();
	t.pb(0);
	FOR(i,1,n) t.pb(i);
	for (;y;y>>=1){
		if (y&1) t=mul(t,x);
		x=mul(x,x);
	}
	return t;
}
int main(){
	//a1 0
	//rev a1 1
	//a2 2
	//rev a2 3
	cin>>n>>k;
	a[0].pb(0);
	FOR(i,1,n){
		getint(x);
		a[0].pb(x);
	}
	a[2].pb(0);
	FOR(i,1,n){
		getint(x);
		a[2].pb(x);
	}
	a[1]=rev(a[0]);
	a[3]=rev(a[2]);
	L=mul(mul(mul(a[3],a[0]),a[2]),a[1]);
	R=mul(mul(mul(a[0],a[3]),a[1]),a[2]);
	if (k==1){
		FOR(i,1,n) printf("%d ",a[0][i]);
		return 0;
	}
	if (k%6==2){
		ans=pw(L,k/6);
		ans=mul(ans,a[2]);
		ans=mul(ans,pw(R,k/6));
	}
	if (k%6==3){
		ans=pw(L,k/6);
		ans=mul(ans,a[1]);
		ans=mul(ans,a[2]);
		ans=mul(ans,pw(R,k/6));
	}
	if (k%6==4){
		ans=pw(L,k/6);
		ans=mul(ans,a[3]);
		ans=mul(ans,a[1]);
		ans=mul(ans,a[2]);
		ans=mul(ans,pw(R,k/6));
	}
	if (k%6==5){
		ans=pw(L,k/6);
		ans=mul(ans,a[3]);
		ans=mul(ans,pw(R,k/6+1));
	}
	if (k%6==0){
		ans=pw(L,k/6-1);
		ans=mul(ans,a[3]);
		ans=mul(ans,a[0]);
		ans=mul(ans,pw(R,k/6));
	}
	if (k%6==1){
		ans=pw(L,k/6-1);
		ans=mul(ans,a[3]);
		ans=mul(ans,a[0]);
		ans=mul(ans,a[2]);
		ans=mul(ans,pw(R,k/6));
	}
	FOR(i,1,n) printf("%d ",ans[i]);
	return 0;
}
/*
0
2
12
312
30312
300312
3020312
302120312
3021120312
30213120312
3021303120312
30213003120312
302130203120312
30213021203120312
302130211203120312
3021302131203120312
302130213031203120312
3021302130031203120312
30213021302031203120312
3021302130212031203120312
30213021302112031203120312
302130213021312031203120312
30213021302130312031203120312
302130213021300312031203120312
3021302130213020312031203120312
302130213021302120312031203120312
3021302130213021120312031203120312
30213021302130213120312031203120312
3021302130213021303120312031203120312
30213021302130213003120312031203120312
*/

Measured memory_bytes: 6664
from collections import*
import sys
input = sys.stdin.readline


class UnionFind(object):
    def __init__(self, n):
        # 親の番号を格納する。親だった場合は-(その集合のサイズ)
        # 作るときはParentsの値を全て-1にする
        # こうすると全てバラバラになる
        self.parents = [-1 for i in range(n)]

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return

n, k, l = map(int, input().split())

ro_cl = UnionFind(n)
ra_cl = UnionFind(n)
d = defaultdict(int)

# =================================================================

# w = [list(map(int, input().split())) for i in range(k+l)]
# ro = w[:k]
# ra = w[l:]
# for p, q in ro:
#     ro_cl.union(p-1, q-1)
# for p, q in ra:
#     ra_cl.union(p-1, q-1)

# =================================================================

for i in range(k):
    p, q = map(int, input().split())
    ro_cl.union(p-1, q-1)
for i in range(l):
    p, q = map(int, input().split())
    ra_cl.union(p-1, q-1)

# =================================================================

for i in range(n):
    d[(ro_cl.find(i), ra_cl.find(i))] += 1
print(*[d[(ro_cl.find(i), ra_cl.find(i))]for i in range(n)])


Measured memory_bytes: 41472
n, x = map(int, input().split())
a = list(map(int, input().split()))

# 空間計算量を減らしてみる
DP = a[:]
ans = sum(DP)
for i in range(n-1):
    DP = [min(DP[j],DP[j-1]) for j in range(n)]
    ans = min(ans, sum(DP) + (i+1)*x)
print(ans)

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n;
    cin>>n;
    map<ll,ll> mp;
    mp[0]=1;
    ll sum=0,ans=0;
    fr(i,0,n)
    {
        ll x;
        cin>>x;
        sum+=x;
        if(mp.count(sum))
        {
            ans+=mp[sum];
        }
        mp[sum]+=1;
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 16160
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;



int main()
{
	int n,q,a,m,last,temp=0;
	bool dp[2001]={0};

	cin >> n;

	dp[0] = true;
	last = 0;

	for(int i = 0; i < n; i++)
	{
		cin >> a;
		temp = 0;

		for(int j = last; j >= 0; j--)
		{
			if (dp[j])
			{
				temp = max(j+a,temp);
				dp[j + a] = true;
			}
		}

		last = max(temp,last);
	}

	cin >> q;

	for(int i = 0; i < q; i++)
	{
		cin >> m;

		if (dp[m])
		{
			cout << "yes" << endl;
		}else
		{
			cout << "no" << endl;
		}
	}

	return 0;
}
	

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

int main(){
  
  int n; cin >> n;
  
  vector<int> a(n), c;
  int m = 0;
  int m2 = 0;
  
  for (int i = 0; i < n; i++){
    int b; cin >> b;
    a[i] = b;
    m = max(m, b);
  }
  
  for (int i = 0; i < n; i++){
    if(a[i] == m) c.push_back(i);
    else m2 = max(m2, a[i]);
  }
  
  if(c.size() != 1){
    for (int i = 0; i < n; i++){cout << m << endl;}
  }else {
    for (int i = 0; i < n; i++){
      if (i != c[0]) cout << m << endl;
      else cout << m2 << endl;
    }
  }
  
}

Measured memory_bytes: 3316
import numpy as np
import re

mod = 10**9 + 7
letters = "ACGT"

# 文字を添え字に
def to_int(s):
    res = 0
    for x in s:
        res <<= 2
        res += letters.index(x)
    return res

# 添え字を文字に
def to_str(x, digit):
    res = ""
    for _ in range(digit):
        res += letters[x&3]
        x >>= 2
    return res[::-1]

# 部分文字列として含んではいけないものを正規表現で判定
def is_ok(s):
    ng = [r"AGC", r"ACG", r"GAC", r"A.GC", r"AG.C"]
    for x in ng:
        if re.search(x, s):
            return False
    return True

# 行列作成　各状態からの各遷移が有効か確かめる
A = [[0]*64 for _ in range(64)]
for i in range(64):
    s = to_str(i, 3)
    for j in range(4):
        t = s + to_str(j, 1)
        if is_ok(t):
            A[i][to_int(t[1:])] = 1
A = np.array(A, dtype = "object")


# 行列の二分累乗
def mat_power(A, p, mod):
    res = np.eye(A.shape[0], dtype = "object")
    while p:
        if p & 1:
            res = np.dot(res, A) % mod
        A = np.dot(A, A) % mod
        p >>= 1
    return res

# ベクトル作成　TTTのみ立てておく
x = [0]*64
x[63] = 1
x = np.array(x)

N = int(input())
print((np.dot(mat_power(A, N, mod), x) % mod).sum() % mod)

Measured memory_bytes: 27484
#include<stdio.h>

int main(){


int n,i,ai;


int min=1000000,max=-1000000;


long int sum=0;


scanf("%d",&n);


for(i=0;i<n;i++){


scanf("%d",&ai);


if(min>ai){


min=ai;


}


if(max<ai)


{


max=ai;


}


sum+=ai;


}


printf("%d %d %ld\n",min,max,sum);


return 0;


}

Measured memory_bytes: 600
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int[] num= new int[3];
        int max = 0;
        int maxNum = 0;
        for(int i=0;i<3;i++){
            num[i]=scn.nextInt();
            if(max<num[i]){
                max = num[i];
                maxNum=i;
            }
        }
        int k = scn.nextInt();
        int answer = 0;
        for(int i=0;i<3;i++){
            if(maxNum==i){
                max *= Math.pow(2,k);
                answer += max;
            }else{
                answer+=num[i];
            }
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<vector<int>> D(C, vector<int>(C)), c(N, vector<int>(N));
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			cin >> D.at(i).at(j);
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> c.at(i).at(j);
			c.at(i).at(j)--;
		}
	}

	vector<vector<int>> cost(3, vector<int>(C));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < C; k++) {
				cost.at((i + j) % 3).at(k) += D.at(c.at(i).at(j)).at(k);
			}
		}
	}

	int ans = INT_MAX;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			if (i == j) continue;
			for (int k = 0; k < C; k++) {
				if (k == i) continue;
				if (k == j) continue;
				ans = min(ans, cost.at(0).at(i) + cost.at(1).at(j) + cost.at(2).at(k));
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 4564
#include "bits/stdc++.h"
using namespace std;
 
#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long
 
int n;
vector<int> g[202020];
bool fav[202020];
int far[202020];
int second_farthest[202020];
int closest[202020];
bool in_fav[202020];
long long ans = 0;
 
static const int INF = 0x3f3f3f3f;
 
void dfs1(int v, int prev) {
        if (fav[v]) in_fav[v] = true;
        for (auto u : g[v]) if (u != prev) {
                dfs1(u, v);
                in_fav[v] |= in_fav[u];
                far[v] = max(far[v], far[u] + 1);
        }
}
 
void dfs2(int v, int ma, bool par_fav, int prev) {
        vector<pair<pii, bool>> children;
        children.push_back(mp(mp(0, -1), false));
        for (auto u : g[v]) {
                if (u == prev) children.push_back(mp(mp(ma + 1, u), par_fav));
                else children.push_back(mp(mp(far[u] + 1, u), in_fav[u]));
        }
        vector<pii> fav_children;
        for (auto c : children) if (c.second) fav_children.push_back(mp(c.first.first, c.first.second));
        sort(all(fav_children));
        sort(all(children), greater<pair<pii, bool>>());
        if (fav_children.empty()) closest[v] = INF;
        else closest[v] = fav_children[0].first;
        if (children.size() > 1) second_farthest[v] = children[1].first.first;
        else second_farthest[v] = -1;
        for (auto u : g[v]) if (u != prev) { 
                int maa = children[u == children[0].first.second ? 1 : 0].first.first;
                bool par_f = fav[v] || par_fav;
                if (!in_fav[u]) par_f |= !fav_children.empty();
                else par_f |= fav_children.size() > 1;
                if (maa < far[u]) ans += par_f;
                else if (far[u] < maa) ans += in_fav[u];
                else ans += par_f || in_fav[u];
                dfs2(u, maa, par_f, v);
        }
}
 
int main() {
        cin >> n;
        for (int i = 0; i < n - 1; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        string s;
        cin >> s;                                            
        for (int i = 0; i < n; i ++) fav[i] = s[i] == '1' ? true : false;
        dfs1(0, -1);
        dfs2(0, 0, fav[0], -1);
//cerr << ans << endl;
        for (int i = 0; i < n; i ++) {
                if (fav[i]) ans += 1 + (second_farthest[i] != -1 ? second_farthest[i] : 0);
                else ans += max(0, second_farthest[i] - closest[i] + 1);
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 54660
#include <iostream>
using namespace std;
int main()
{
    int n,m;
   cin>>n>>m;
char arr1[n][n];
char arr2[m][m];
    for(int i=0; i<n; i++)
        cin>>arr1[i];
 
    for(int i=0; i<m; i++)
        cin>>arr2[i];
 
 
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            int count=0;
            for(int a=0; a<m; a++)
            {
                for(int b=0; b<m; b++)
                {
                    if(arr2[a][b]==arr1[i+a][j+b])
                        count++;
                }
 
            }
            if(count==(m*m))
            {
               cout<<"Yes";
               return 0;
            }
 
        }
    }
 
 
    cout<<"No";
 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long MOD = 1e9 + 7;
long long repow(long long x, long long y){
    if(y == 0) return 1;
    if(y % 2 == 0){
        long long t = repow(x, y / 2);
        return t* t % MOD;
    }
    return x * repow(x, y - 1) % MOD;
}
const int MAX = 2010;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = 1;
    finv[0] = 1;
    inv[0] = 1;
    for(int i = 1; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = repow(i, MOD - 2);
        finv[i] = finv[i -1] * inv[i] % MOD;
    }
}
long long COM(long long n, long long k){
    if(k > n || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n - k] % MOD;
}
int main(){
    COMinit();
    int N, K;
    cin >> N >> K;
    int aka = N - K;
    for(int i = 1; i <= K; i++){
        long long ans = COM(aka + 1, i) * COM(K - 1, i - 1) % MOD;
        cout << ans << endl;
    }
}

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

int kaiju(int k) {
	int ans = 1;
	if (k == 1) { return 1; }
	for (int i = 1; i <= k-1; i++) {
		ans *= 10;
	}
	return ans;
}

int main() {
	int n;
	int ans = 0;
	cin >> n;
	int k = n;
	int ketasu = 0;
	while (k) {
		k = k / 10;
		ketasu++;
	}

	for(int i = 1; i <= ketasu; i++) {
		if (i % 2 != 0) {
			if (i == ketasu) {
				ans += n - kaiju(i) + 1;
			}
			else {
				ans += kaiju(i) * 9;
			}
		}
	}

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

Measured memory_bytes: 256
#include <stdio.h>
int main(){
        int res = 0;
        int Scount = 0;
        char c='\0';
        while (scanf("%c",&c) != EOF){                                                                                                                                                                                                
                if (c == 'S'){
                        Scount ++; 
                        res ++; 
                        continue;
                }           
                if (c == 'T'){
                        if (Scount){
                                Scount --; 
                                res --; 
                                continue;
                        }else{
                                res ++ ;
                                continue;
                        }   
                }   
        }   
        printf("%d", res);
}

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

int a, b, c, k;
int main(){
	scanf("%d %d %d %d", &a, &b, &c, &k);
	
	int r = 0;
	while(b <= a){
		b *= 2;
		r++;
	}
	while(c <= b){
		c *= 2;
		r++;
	}
	
	if(r <= k)printf("Yes\n");
	else printf("No\n");
	
	return 0;
}


Measured memory_bytes: 3680
while True:
	try:
		char = raw_input()
		ans = ""
		while "@" in char:
			ans += char[0:char.index("@")]
			char = char[char.index("@"):]
			char = char[2] * int(char[1]) + char[3:]
		ans += char
		print ans
	except:
		break

Measured memory_bytes: 4208
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]



    xxxx = 0
    while True:
        xxxx += 1
        imos = [0] * (N + 2)
        if xxxx == 100 or xxxx == K + 1:
            break
        for i, a in enumerate(A):
            imos[max(0, i + 1 - a)] += 1
            imos[min(N + 1, i + 1 + a + 1)] -= 1

        ruiseki = [0] * (N + 2)
        for i in range(N + 2):
            ruiseki[i] = imos[i] + ruiseki[i - 1]

        for i, v in enumerate(ruiseki[1:N + 1]):
            A[i] = v

    print(*ruiseki[1:N + 1])



if __name__ == '__main__':
    main()


Measured memory_bytes: 170820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+5;
int tab[MAXN];

int main(){
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b==c+d) cout << "Balanced";
    if(a+b>c+d) cout << "Left";
    if(a+b<c+d) cout << "Right";
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
  
int main() {
  	unsigned int rc[101][101];
  	int r,c; cin>>r>>c;
  	for(int i=0;i<=r;i++){
    	for(int j=0;j<=c;j++){
    		rc[i][j]=0;
     }
   }
  	for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
    		cin>>rc[i][j];
          	rc[i][c]+=rc[i][j];
          	rc[r][j]+=rc[i][j];
    		rc[r][c]+=rc[i][j];
    }
  }
  	for(int i=0;i<=r;i++){
    	for(int j=0;j<=c;j++){
    	cout<<rc[i][j];
        if(j!=c) cout<<" ";
    }
      cout<<endl;
  }
}
 


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 605;
int N, M;
vector<int> edge[MAX_N];

double dp[MAX_N];
double initDp[MAX_N];
II D;

void init()
{
  REP(n,MAX_N) {
    dp[n] = -1;
  }
}

double solve(int pos)
{
  if(dp[pos] != -1) {
    return dp[pos];
  }

  if(pos == N) {
    return 0.0;
  }

  double ret = 0.0;
  int counter = 0;

  for(int next : edge[pos]) {
    if(D.first == pos && D.second == next) {
      continue;
    }
    counter++;
    double tmp = solve(next);
    if(tmp == INF_LL) {
      return INF_LL;
    }
    ret += tmp + 1;
  }

  if(counter == 0) {
    return INF_LL;
  }

  return dp[pos] = ret / counter;
}

signed main()
{
  cin >> N >> M;
  REP(m,M) {
    int a, b; cin >> a >> b;
    edge[a].push_back(b);
  }

  init();
  double ans = solve(1);
  memcpy(initDp, dp, sizeof(dp));

  FOR(pos,1,N) {
    if(edge[pos].size() == 1) continue;
    vector<pair<double, int>> tmp;
    for(int next : edge[pos]) {
      tmp.push_back(pair<double, int>(initDp[next], next));
    }
    sort(begin(tmp), end(tmp), greater<pair<double, int>>());
    D = II(pos, tmp[0].second);
    init();
    ans = min(ans, solve(1));
  }
  printf("%.10f\n", ans);

  return 0;
}


Measured memory_bytes: 2560
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for k in range(N)]
hole = [[0,0,0] for i in range(3)]
ans = "No"

for i in range(3):
  for j in range(3):
    for k in range(N):
      if A[i][j] == b[k]:
        hole[i][j] = 1
  flag_hol = 1
  for j in range(3):
    flag_hol *= hole[i][j]
  if flag_hol == 1:
  	ans = "Yes"

flag_diag1 = 1
flag_diag2 = 1
for j in range(3):
  flag_vert = 1
  for i in range(3):
    flag_vert *= hole[i][j]
  if flag_vert ==1:
    ans = "Yes"
  flag_diag1 *= hole[j][j]
  flag_diag2 *= hole[j][2-j]
if (flag_diag1 == 1) or (flag_diag2 == 1):
  ans = "Yes"
  
print(ans)


Measured memory_bytes: 62124
n,k=gets.split.map(&:to_i)
x=gets.split.map(&:to_i)
s=x.bsearch_index {|x| x>=0}
if s==nil
  x << 0
  s=n
  n+=1
  k+=1
elsif x[s]>0
  x.insert(s,0)
  n+=1
  k+=1
end
a=1/0.0
[s-k+1,0].max.upto([s,n-k].min) do |i|
  t=-x[i]*2+x[i+k-1]
  if t<a
    a=t
  end
  t=-x[i]+x[i+k-1]*2
  if t<a
    a=t
  end
end
puts a

Measured memory_bytes: 8460
n,m,*t=map(int,open(0).read().split())
d=[0,0]+[1e18]*n
for l,r,c in sorted(zip(*[iter(t)]*3)):
  for i in range(r,l,-1):
    if d[l]+c<d[i]:d[i]=d[l]+c
    else:break
print(d[-2]%10**18or-1)

Measured memory_bytes: 124200
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[])
{
	LL n, c;
	cin >> n >> c;
	LL d[30][30];
	for (LL i = 0; i < c; ++i) {
		for (LL j = 0; j < c; ++j) {
			cin >> d[i][j];
		}
	}
	LL cost[3][30] = {};
	for (LL i = 0; i < n; ++i) {
		for (LL j = 0; j < n; ++j) {
			LL color;
			cin >> color;
			--color;
			LL r = (i + j) % 3;
			for (LL k = 0; k < c; ++k) {
				cost[r][k] += d[color][k];
			}
		}
	}
	LL ans = 1LL << 60;
	for (LL i = 0; i < c; ++i) {
		for (LL j = 0; j < c; ++j) {
			if (i == j) continue;
			for (LL k = 0; k < c; ++k) {
				if (i == k || j == k) continue;
				LL seq[3] = { 0, 1, 2 };
				do {
					ans = min(ans, cost[seq[0]][i] + cost[seq[1]][j] + cost[seq[2]][k]);
				} while (next_permutation(seq, seq + 3));
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int solve(string s1,string s2)
{
    ll x = min(s1.length(),s2.length());
    for(ll i =0;i<x;i++)
    {
        if(s1[i]>s2[i]) return 1;
    }
    return 0;
}
string s = "abcdefghijklmnopqrstuvwxyz";
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int x = a+b,y = c+d;
if(x>y) cout<<"Left";
else if(x==y) cout<<"Balanced";
else cout<<"Right";
return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-16;
const ll inf = 1e10;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
db X[N], Y[N];
int D[N];
db cal(db t) {
	db mxx = -inf, mnx = inf, mxy = -inf, mny = inf;
	rep(i, 0, n) {
		db nx = X[i], ny = Y[i];
		if(D[i]==1) ny += t;
		if(D[i]==3) ny -= t;
		if(D[i]==2) nx += t;
		if(D[i]==4) nx -= t;
		mxx = max(nx, mxx);
		mnx = min(nx, mnx);
		mxy = max(ny, mxy);
		mny = min(ny, mny);
	}
	return (mxx - mnx) * (mxy - mny);
}
db three_search(db l, db r) {
	db ret = 1e18;
	int cnt = 0;
    while (r > eps + l && cnt <= 200) {
        db lm=(l+(r-l)/3),rm=(l+(r-l)*2/3);
        // 如果是求最小值的话这里判<=即可
        db tmp1 = cal(lm), tmp2 = cal(rm);
        if(tmp1 <= tmp2) r = rm;
        else l = lm;
        ret = min(ret, tmp1);
        ret = min(ret, tmp2);
        cnt++;
    }
    return ret;
}
int main() {
	// dp[i][j] 表示以s[i]和t[j]结尾的相同子序列的个数
	// 到后面就是前缀和了
	while(~scanf("%d", &n)) {
		rep(i, 0, n) {
			char c;
			scanf("%lf%lf %c", X + i, Y + i, &c);
			if(c=='U') D[i] = 1;
			if(c=='R') D[i] = 2;
			if(c=='D') D[i] = 3;
			if(c=='L') D[i] = 4;
		}
		printf("%.10f\n", three_search(0, 1e12));
	}
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>

using namespace std;
int cate_cifre(long long x)
{
    int cate = 0;
    while (x)
    {
        x/=10;
        ++cate;
    }
    return cate;
}
int main()
{
    long long n, maxim = 0;
    cin >> n;
    for (long long i = 1; i*i<=n; ++i)
    {
        if (n%i == 0)
            maxim = cate_cifre(1LL*n/i);
    }
    cout << maxim;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
using namespace std; 
void solve(); 
int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("error.txt", "w", stderr); 
    freopen("output.txt", "w", stdout); 
#endif 
  
    int t = 1; 
    // cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 

void solve() 
{ 
	int x;
    string s;

    cin >> x >> s;

    if (s.size() <= x) {
        cout << s << "\n";
    } else {
        cout << s.substr(0, x) << "...\n";
    }
}

Measured memory_bytes: 3832
#include <stdio.h>

int main(void){
    int n,x,l,d=0, count = 1;
    scanf("%d%d",&n,&x);
    for(int i = 0; i<n; i++){
        scanf("%d",&l);
        d += l;
        if(d<=x)
            count++;
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n,k;
cin>>n>>k;

int ans=1e9+7;

rep(msk,0,(1<<n)-1)
{
	int kk=1;
	rep(i,0,n-1)
	{
		if(msk&(1<<i))kk*=2;
		else kk+=k;
	}
	ans=min(ans,kk);
}
ol(ans);
return 0;
}



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

using namespace std;

#define int long long
#define PB push_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;

int w, h, dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
bool field[100][100];

int dfs(int x, int y) {
  field[x][y] = false;

  int temp = 0;
  for (int i = 0; i < 4; ++i) {
    int tx = x + dx[i], ty = y + dy[i];
    if (!field[tx][ty]) continue;
    temp = max(temp, dfs(tx, ty));
  }

  field[x][y] = true;
  return temp + 1;
}

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

  while (cin >> w >> h, w) {
    fill(field[0], field[100], 0);

    for (int y = 1; y <= h; ++y) {
      for (int x = 1; x <= w; ++x) {
        cin >> field[x][y];
      }
    }

    int ans = 0;
    for (int y = 1; y <= h; ++y) {
      for (int x = 1; x <= w; ++x) {
        if (!field[x][y]) continue;

        ans = max(ans, dfs(x, y));
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1208