akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int a=INF,b;
	string s;
	cin >> s;
	rep(i, s.size() - 2) {
		b = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		a=min(a, (int)max(b - 753, 753 - b));
	}
	cout << a << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
    int n, m, i, x, y, z;
    set<int> st;
    cin >> n >> m;
    UnionFind uf(n);
    for(i=0; i<m; i++){
        cin >> x >> y >> z;
        if(uf.find(x-1) != uf.find(y-1)){
            uf.unite(x-1, y-1);
        }
    }
    for(i=0; i<n; i++){
        st.insert(uf.find(i));
    }
    cout << st.size() << "\n";
    return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vector<pint> v(N);
    for(int i=0;i<N;i++){
        int a,b; cin>>a>>b;
        v[i]=pint(b,a);
    }
    sort(v.begin(),v.end());

    int cur=0;
    for(int i=0;i<N;i++){
        cur+=v[i].second;
        if(cur>v[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3328
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sr = new Scanner(System.in);
    int H1= sr.nextInt();
    int M1= sr.nextInt();
    int H2= sr.nextInt();
    int M2= sr.nextInt();
    int K= sr.nextInt();
    System.out.println((H2*60+M2)-(H1*60+M1)-K);
  }
}

Measured memory_bytes: 35636
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    vector<int> num_w(n, 0);
    vector<int> num_e(n, 0);
    int ans=n;
    if(s[0]=='W'){
        num_w[0]++;
    }
    for(int i=1; i<n; i++){
        num_w[i]=num_w[i-1];
        if(s[i]=='W'){
            num_w[i]++;
        }
    }
    if(s[n-1]=='E'){
        num_e[n-1]++;
    }
    for(int i=n-2; i>=0; i--){
        num_e[i]=num_e[i+1];
        if(s[i]=='E'){
            num_e[i]++;
        }
    }
    if(num_e[1]<ans){
        ans=num_e[1];
    }
    for(int i=1; i<n-2; i++){
        if(num_w[i-1]+num_e[i+1]<ans){
            ans=num_w[i-1]+num_e[i+1];
        }
    }
    if(num_w[n-2]<ans){
        ans=num_w[n-2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3076
import sys
from itertools import combinations
from collections import Counter
ct = Counter()
Ass = []
ans = []
N, M, X = map(int, input().split())
for i in range(N):
	Ass.append(list(map(int, input().split())))

for z in range(M):	
	B = []
	for i in range(N):
		B.append(Ass[i][z])
	D = []
	for i in range(1, N+1):
		for j in combinations(Ass, i):
			flag = True
			d = [0]*(M+1)
			for k in j:  # (2, 7, 3)
				for l in range(M+1):
					d[l] += k[l]
			for x in range(1, M+1):
				if d[x] >= X:
					pass
				else:
					flag=False
					break
			if flag:
				ans.append(d[0])


if len(ans) > 0:
	print(min(ans))
else:
	print('-1')


Measured memory_bytes: 11032
#include<iostream>
#include<string>
using namespace std;
int main(){
    int cnt = 0;
    string word;cin >> word;
    string t;
    while(1){
        cin>>t;
        if(t=="END_OF_TEXT")break;
        for(int i=0;i<=t.size();i++){
            if(isupper(t[i])){
                t[i]=tolower(t[i]);
            }
        }
        if(t == word)cnt++;
    }cout << cnt << endl;
    return 0;
}


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

int dp[12][10];
string getAns(int k, int di, int n){
    if(di == 0) return "";
    if(n == 0){
        if(dp[di-1][0] >=k) return "0"+getAns(k, di-1, 0);
        else return "0"+getAns(k-dp[di-1][0], di-1, 1);
    }
    else if(n == 9){
        if(dp[di-1][8] >=k) return "9"+getAns(k, di-1, 8);
        else return "9"+getAns(k-dp[di-1][8], di-1, 9);
    }
    if(dp[di-1][n-1] >= k) return to_string(n)+getAns(k, di-1, n-1);
    else if(dp[di-1][n-1]+dp[di-1][n] >= k) return to_string(n) + getAns(k-dp[di-1][n-1], di-1, n);
    else return to_string(n) + getAns(k-dp[di-1][n-1]-dp[di-1][n], di-1, n+1);
}

int main(){
    //freopen("a.in", "r", stdin);
    int k; cin >> k;
    fill(dp[0], dp[0]+10, 0);
    for(int i = 1; i<12; i++){
        for(int j = 0; j<10; j++){
            if(i == 1){
                dp[i][j] = 1;
                continue;
            }
            if(j == 0){
                dp[i][j] = dp[i-1][j]+dp[i-1][j+1];
            }
            else if(j == 9){
                dp[i][j] = dp[i-1][j-1]+dp[i-1][j];
            }
            else{
                dp[i][j] = dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1];
            }
        }
    }
    int i = 1;
    int j = 1;
    int cur = 0;
    for(i; i<12; i++){
        for(j = 1; j<10; j++){
            if(cur + dp[i][j] >= k){
                cout << getAns(k-cur, i, j) << endl;
                exit(0);
            }
            cur += dp[i][j];
        }
    }

}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

a,b,k = na()
if (b-a+1) // 2 >= k:
    ans = list(range(a,a+k)) + list(range(b-k+1,b+1))
else:
    ans = list(range(a,b+1))
for i in ans:
    print(i)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <memory>
const int MAX_N = 524288;

using namespace std;

int tree[MAX_N*2-1][256];
void query(vector<int>& result, int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
        for (int i=0; i<256; i++) {
            result[i] += tree[k][i];
        }
    }
    else {
        query(result, a, b, k*2+1, l, (l+r)/2);
        query(result, a, b, k*2+2, (l+r)/2, r);
    }
}
int main() {
    int N;
    char S[MAX_N];
    cin >> N;
    cin >> S;

    int Q;
    cin >> Q;
    //cerr << "Q=" << Q << endl;

    for (int i=0; i<N; i++) {
        char s = S[i];
        int node = MAX_N - 1 + i; // leaf
        tree[node][s] += 1;
        while (node > 0) {
            node = (node-1) / 2;
            tree[node][s] += 1;
        }
    }

    for (int i=0; i<Q; i++) {
        int qtype, q0;
        cin >> qtype >> q0;
        if (qtype == 1) {
            char q1; cin >> q1;
            q0--; //0-indexed

            int node = MAX_N - 1 + q0;
            char s = S[q0];
            tree[node][s] -= 1;
            tree[node][q1] += 1;
            while (node > 0) {
                node = (node-1) / 2;
                tree[node][s] -= 1;
                tree[node][q1] += 1;
            }
            S[q0] = q1;
            //cerr << "update done" << endl;
        }
        if (qtype == 2) {
            int q1; cin >> q1;
            q0--; q1--; // 0-indexed

            vector<int> result(256);
            query(result, q0, q1+1, 0, 0, MAX_N);
            int answer = 0;
            for (int j=0; j<256; j++) {
                if (result[j] > 0) {
                    answer++;
                    //cerr << (char)j;
                }
            }
            //cerr << endl;
            cout << answer << endl;
        }
        //cerr << "query done" << endl;
    }
    return 0;
}



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

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

struct MyStruct {
	int idx, a, b, pl;
};

bool comp(const MyStruct& s, const MyStruct& t) {
	if (s.pl != t.pl)
		return s.pl > t.pl; // 降順
	return s.idx < t.idx;
}

const int MAX_N = 400;

const int di[] = { 1,0,-1,0 };
const int dj[] = { 0,1,0,-1 };

bool color[MAX_N][MAX_N];
int H, W;

char ch[MAX_N + 1];

void input() {
	cin >> H >> W;
	string s;
	REP(i, H) {
		cin >> s;
		REP(j, W) {
			if (s[j] == '#') {
				color[i][j] = 1;
			}
			else {
				color[i][j] = 0;
			}
		}
	}

}

bool isin(int i, int j) {
	return i >= 0 && i < H && j >= 0 && j < W;
}

bool check(int i, int j, int d) {
	int ni = i + di[d];
	int nj = j + dj[d];
	if (!isin(ni, nj)) return false;
	if (color[i][j] == color[ni][nj]) return false;
	return true;

}

bool used[MAX_N][MAX_N];


long long solve() {
	long long ans = 0;
	long long b = 0, w = 0;
	REP(i, H) {
		REP(j, W) {
			if (used[i][j]) continue;
			b = 0;
			w = 0;
			queue<P> que;
			used[i][j] = true;
			que.push(P(i, j));
			while (!que.empty()) {
				P p = que.front();
				que.pop();
				int ci = p.first, cj = p.second;
				if (color[ci][cj]) b++;
				else w++;
				REP(d, 4) {
					if (!check(ci, cj, d)) continue;
					int ni = ci + di[d], nj = cj + dj[d];
					if (used[ni][nj]) continue;
					used[ni][nj] = true;
					que.push(P(ni, nj));
				}

			}
			ans += b*w;
		}
	}
	return ans;
}
int main() {

	input();
	long long ans = solve();
	ANS(ans);
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll N,K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    ll s=0;
    ll ans=0;
    for (int i=0; i<N; ++i) {
        s += p[i];
        int r = i-K;
        if (r >= 0)
            s -= p[r];
        if (i+1 >= K)
            updmax(ans, s);
    }
    ans += K;
    printf("%.10f\n", (double)ans / 2);
}

Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];

	rep(i, 0, n) {
		rep(j, i, n) {
			swap(a[i], a[j]);

			bool ok = true;
			rep(k, 0, n - 1) {
				if (a[k] > a[k + 1]) ok = false;
			}
			if (ok) {
				cout << "YES";
				return 0;
			}
			swap(a[i], a[j]);
		}
	}
	cout << "NO";
	return 0;

}


Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define SZ(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool inline rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool inline rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}


/**
 * Author: Lukas Polacek
 * Date: 2009-10-26
 * License: CC0
 * Source: folklore
 * Description: Disjoint-set data structure.
 * Time: $O(\alpha(N))$
 */
struct DSU {
	std::vector<int> e;
	DSU(int n) : e(n, -1) {}
	bool same_set(int a, int b) { return find(a) == find(b); }
	int size(int x) { return -e[find(x)]; }
	int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
	bool merge(int a, int b) {
		a = find(a), b = find(b);
		if (a == b) return false;
		// make a as parent of b
		if (e[a] > e[b]) swap(a, b); // size of dsu(a) is -e[a] 
		e[a] += e[b]; e[b] = a;
		return true;
	}
};
///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n,m; cin>>n>>m;
DSU d(n);
for(int i=0;i<m;++i){
	int x,y,z; cin>>x>>y>>z;
	--x, --y;
	d.merge(x,y);
}
set<int> s;
for(int i=0;i<n;++i){
	s.insert(d.find(i));
}
cout<<SZ(s);


return 0;
}


Measured memory_bytes: 5760
T = gets.to_i

class A
  def initialize(n, a, b, c, d)
    @n, @a, @b, @c, @d = n, a, b, c, d
    @m = {0 => 0, 1 => @d}
  end

  def go(n)
    @m[n] ||= begin
                f5, f3, f2 = n/5, n/3, n/2
                c5, c3, c2 = (n + 4)/5, (n + 2)/3, (n + 1)/2
                @m[n] = [@d*n,
                         @d*(n - f5*5) + @c + go(f5),
                         @d*(n - f3*3) + @b + go(f3),
                         @d*(n - f2*2) + @a + go(f2),
                         @d*(c5*5 - n) + @c + go(c5),
                         @d*(c3*3 - n) + @b + go(c3),
                         @d*(c2*2 - n) + @a + go(c2)].min
              end
  end

  def solve
    puts go(@n)
  end
end

T.times{A.new(*gets.split.map(&:to_i)).solve}

Measured memory_bytes: 17140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        int[] num = new int[n];
        String[] strings = br.readLine().split("\\s");
        for (int i=0; i<strings.length; i++){
            num[i] = Integer.parseInt(strings[i]);
        }

        int q = Integer.parseInt(br.readLine());
        String[] strs = br.readLine().split("\\s");
        int sum = 0;
        for (int i=0; i<q; i++){
            if (binarySearch(num, Integer.parseInt(strs[i]))){
                sum++;
            }
        }

        System.out.println(sum);

    }

    private static boolean binarySearch(int[] num, int key) {
        
        // left??¨???????´¢?????´?????´???????´????right??????????°?????´?????????????????´?
        int left = 0;
        int right = num.length;
        
        // ?????¶???????????¶??? <
        while (left < right){
            int mid = (left+right)/2;
            if (key == num[mid]){
                return true;
            }
            else if (key < num[mid]){
                right = mid;
            }
            else {
                left = mid+1;
            }
        }

        return false;
    }
}

Measured memory_bytes: 54596
#ifndef ___Class_RMQ
#define ___Class_RMQ

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

// ------ RMQ Class ------ //
template<typename Type> class RMQ {
private:
	unsigned size_; std::vector<Type> dat;
	Type query_(unsigned a, unsigned b, unsigned k, unsigned l, unsigned r) {
		if (r <= a || b <= l) return std::numeric_limits<Type>::max();
		if (a <= l && r <= b) return dat[k];
		Type lc = query_(a, b, (k << 1), l, (l + r) >> 1);
		Type rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
		return std::min(lc, rc);
	}
public:
	RMQ() : size_(0), dat(std::vector<Type>()) {};
	RMQ(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RMQ(T begin_, T end_) {
		unsigned n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (unsigned i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (unsigned i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	unsigned size() { return size_; }
	void update(unsigned i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
		}
	}
	Type query(unsigned l, unsigned r) {
		return query_(l, r, 1, 0, size_);
	}
};

#endif

#include <cstdio>
#pragma warning(disable : 4996)

int n, q, c, x, y;
int main() {
	scanf("%d%d", &n, &q);
	RMQ<int> Q(n);
	while (q--) {
		scanf("%d%d%d", &c, &x, &y);
		if (c == 0) Q.update(x, y);
		else printf("%d\n", Q.query(x, y + 1));
	}
	return 0;
}

Measured memory_bytes: 3408
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Edge
{
public:
    int to;
    bool same;
    Edge(int to0, bool same0){
        to = to0;
        same = same0;
    }
};

vector<vector<Edge> > edges;
vector<bool> check;

void solve(int curr, vector<vector<int> >& group)
{
    group[0].push_back(curr);
    check[curr] = true;

    for(unsigned i=0; i<edges[curr].size(); ++i){
        int next = edges[curr][i].to;
        if(check[next])
            continue;

        if(!edges[curr][i].same)
            group[0].swap(group[1]);
        solve(next, group);
        if(!edges[curr][i].same)
            group[0].swap(group[1]);
    }
}

int main()
{
    for(;;){
        int q, a, b;
        cin >> q >> a >> b;
        if(q == 0 && a == 0 && b == 0)
            return 0;

        int n = a + b;
        edges.assign(n+1, vector<Edge>());
        for(int i=0; i<q; ++i){
            int x, y;
            string s;
            cin >> x >> y >> s;
            edges[x].push_back(Edge(y, s == "yes"));
            edges[y].push_back(Edge(x, s == "yes"));
        }

        check.assign(n+1, false);
        vector<vector<vector<int> > > group;
        for(int i=1; i<=n; ++i){
            if(check[i])
                continue;
            group.resize(group.size()+1, vector<vector<int> >(2));
            solve(i, group.back());
        }

        vector<vector<int> > dp(group.size()+1, vector<int>(a+1, 0));
        dp[0][0] = 1;
        for(unsigned i=0; i<group.size(); ++i){
            for(int j=0; j<=a; ++j){
                int k = j + group[i][0].size();
                if(k <= a)
                    dp[i+1][k] += dp[i][j];

                k = j + group[i][1].size();
                if(k <= a)
                    dp[i+1][k] += dp[i][j];
            }
        }

        if(dp[group.size()][a] != 1){
            cout << "no" << endl;
            continue;
        }

        vector<int> ret;
        for(int i=group.size()-1; i>=0; --i){
            int k = 0;
            int a2 = a - group[i][k].size();
            if(a2 < 0 || dp[i][a2] != 1)
                k = 1;

            for(unsigned j=0; j<group[i][k].size(); ++j)
                ret.push_back(group[i][k][j]);

            a -= group[i][k].size();
        }

        sort(ret.begin(), ret.end());
        for(unsigned i=0; i<ret.size(); ++i)
            cout << ret[i] << endl;
        cout << "end" << endl;
    }
}

Measured memory_bytes: 1324
import math
a,b = map(str,input().split())
a = int(a)
new_b = ""
for i in b:
    if "." != i:
        new_b += i
ans = a*int(new_b)
s = str(ans)
s_len = len(s)
if s_len >= 3:
    print(s[0:s_len - 2])
else:
    print(0)

Measured memory_bytes: 9132
n, k, *a = map(int, open(0).read().split())
a = [None] + a
done = [None] + [0] * n
t = 0
p = 1
while not done[p]:
    done[p] = t
    p = a[p]
    t += 1

loop = t - done[p]
orig = done[p]

if k - orig > 0:
    k = (k - orig) % loop + orig
p = 1
while k:
    p = a[p]
    k -= 1

print(p)

Measured memory_bytes: 32592
#include <stdio.h>
#define INF 1e12
#define min(a, b) ((a < b) ? a : b)

typedef long long int LL;
 
int main()
{
    int i, j, k;
    int v, e;
    int s, t, d;
    LL G[101][101];
 
    scanf("%d %d", &v, &e);
 
    for (i = 0; i < v; i ++) {
        for (j = 0; j < v; j++) {
            G[i][j] = (i == j) ? 0 : INF;
        }
    }
 
    for (i = 0; i < e; i++) {
        scanf("%d %d %d", &s, &t, &d);
        G[s][t] = d;
    }
 
    for (k = 0; k < v; k++) {
        for (i = 0; i < v; i++) {
            for (j = 0; j < v; j++) {
                if (G[i][k] != INF && G[k][j] != INF) {
                    G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
                }
            }
        }
    }
 
    for (i = 0; i < v; i++) {
        if (G[i][i] < 0) {
            printf("NEGATIVE CYCLE\n");
            return 0;
        }
    }
 
    for (i = 0; i < v; i++) {
        for (j = 0; j < v; j++) {
            printf(G[i][j] == INF ? "INF" : "%lld", G[i][j]);
            printf((j == v-1) ? "\n" : " ");
        }
    }
 
    return 0;
}

Measured memory_bytes: 1904
#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(a), std::end(a)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...) 
#endif
#pragma endregion

const int MAX = 3100;
int a, b, c, d, e, f;

void solve() {
	int cw[MAX] = { 0 }, cs[MAX] = { 0 };
	cw[0] = cs[0] = 1;
	for (int m = 0; m < MAX; m++) {
		if (cw[m] && m + a < MAX) cw[m + a] = 1;
		if (cw[m] && m + b < MAX) cw[m + b] = 1;
		if (cs[m] && m + c < MAX) cs[m + c] = 1;
		if (cs[m] && m + d < MAX) cs[m + d] = 1;
	}

	int rw = 0, rs = 0;
	for(int mw = 0; mw < MAX; mw++)
		for (int ms = 0; ms < MAX; ms++) {
			if (!cw[mw] || !cs[ms]) continue;
			if (mw * 100 + ms > f) continue;
			if (e * mw < ms) continue;
			if (rw == 0 && rs == 0 || rs * (ms + mw * 100) < (rw * 100 + rs) * ms)
				rs = ms, rw = mw;
		}

	printf("%d %d\n", rw * 100 + rs, rs);
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) == 6) {
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  int m = 1000000000;
  int M = 0;
  
  for (int i = 0; i < N; i++) {
    int x = A.at(i);
    if (m > x) m = x;
    if (M < x) M = x;
  }
  cout << M - m << endl;
}


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

using namespace std;

int main()
{
	int n; cin >> n;
	vector<long long int> v(n);
	for(int i = 0; i < n; ++i) cin >> v[i];

	sort(v.begin(), v.end());
	long long int total = 0;
	int index = n-1;
	int times = 1;
	int count = 1;
	int loop = 0;
	while(count < n)
	{
		int remain = min(times, n - count);
		count += remain;
		total += (v[index]*remain);
		--index;
		times = 2;
		++loop;
		assert(loop < n);
	}

	cout << total;

	return 0;
}

Measured memory_bytes: 4816
#include<stdio.h>

int main()
{
  int price,a,b,c,t,i,j,k,sum[60]={0},temp,m,n;

  while(scanf("%d",&price) != 0)
    {
      if(price==0)break;
      else
	{
	  a=0;
	  b=0;
	  c=0;
	  n=0;
	  m=0;

	  price=price/100;
	  n=0;
	  for(i=0;i<price;i++)
	    for(j=0;j<price-i;j++)
	      for(k=0;k<price-j-i;k++)
		{
		  if(price == i*2 + j*3 + k*5)
		    {
		      a = ((i-i%5)*0.8 + (i%5))*380;
		      b = ((j-j%4)*0.85 + (j%4))*550;
		      c = ((k-k%3)*0.88 + (k%3))*850;
		      if(i==0)a=0;
		      if(j==0)b=0;
		      if(k==0)c=0;
		      t = a+b+c;
		      sum[n] = t;
		      n++;
		    }
		}
	  while(sum[m+1] != 0)
	    {
	      if(sum[m]>sum[m+1])
		{
		  temp = sum[m];
		  sum[m] = sum[m+1];
		  sum[m+1] = temp;
		  m=0;
		}
	      else
		m++;
	    }
	  printf("%d\n",sum[0]);
	}
    }

  return 0;
}		

Measured memory_bytes: 600
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
#define clr0(n) (memset(n,0,sizeof n))
#define clr1(n) (memset(n,-1,sizeof n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
}
ull Gcd(ull a, ull b){
	if (a == 0)
		return b;
	if (b == 0)
		return a;
	while (a %= b ^= a ^= b ^= a);

	return b;
}
ull Lcm(ull x, ull y){
	return x* (y/Gcd(x,y));
}
#define pair1 pair<ll,ll>

vector<vector<pair1> > graph(100001);
vector<ll> vis(100001), prev(100001, -1), dist(100001, 1e18);

void dijkstranN(int src, vector<vector<pair1> > graph, int dest){
	priority_queue<pair1, vector<pair1>, greater<pair1>> pq;
	pq.push({ 0, src });
	dist[src] = 0;
	while (!pq.empty()){
		pair1 p = pq.top();
		pq.pop();
		for (int i = 0; (p.first <= dist[p.second]) && i < graph[p.second].size(); i++){
			pair1 p1 = graph[p.second][i];
			if (dist[p1.first]> p1.second + dist[p.second]){
				dist[p1.first] = p1.second + dist[p.second];
				pq.push({ dist[p1.first], p1.first });
			}
		}
	}
}
int main()
{
	//file();
	int n;
	cin >> n;
	for (int i = 0; i < n-1; i++){
		ll u, v, cost;
		scanf("%lld%lld%lld", &u, &v, &cost);
		graph[u].push_back({ v, cost });
		graph[v].push_back({ u, cost });
	}
	int q, k;
	cin >> q >> k;
	dijkstranN(k, graph,n);
	for (int i = 0; i < q; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		ll ans = dist[x] + dist[y];
		printf("%lld\n", ans);
	}

}

Measured memory_bytes: 19696
require "set"
n, m = gets.chomp.split(" ").map {|c| c.to_i}
h = gets.chomp.split(" ").map {|c| c.to_i}
all = Array.new(n, 1)
m.times do
    ai, bi = gets.chomp.split(" ").map {|c| c.to_i-1}
    if h[ai] == h[bi]
        all[ai] = 0
        all[bi] = 0
        next
    end
    # h[ai] > h[bi]
    if h[ai] < h[bi]
        temp = ai
        ai = bi
        bi = temp
    end
    #all[ai] = 1
    if all[bi] == 1
        all[bi] = 0
    end
end

puts all.sum

Measured memory_bytes: 23136
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int n;
    cin >> n;
    vector<int> c(n-1);
    vector<int> s(n-1);
    vector<int> f(n-1);
    rep(i,n-1) cin >> c[i] >> s[i] >> f[i];

    rep(i,n-1)
    {
        int t = 0;
        rep2(j,i,n-1)
        {
            if(s[j]>t) t = s[j];

            int r = (t-s[j])%f[j];
            if(r>0) t += f[j]-r;

            t += c[j];
        }
        cout << t << endl;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
#define N 101
#define INF 1e9
typedef pair<int,int> P;
vector<P> G[N];
int n,g[N][N];

vector<int> U,V;
int can[N],ans;
vector<bool> used(N);
set<vector<bool> > S;


int calc(){
  
  int res=0;
  for(int i=0;i<V.size();i++){
    int mn=INF;
    for(int j=0;j<V.size();j++)if(i!=j) mn=min(mn,g[V[i]][V[j]]);
    res+=mn;
  }
  if(V.size()==1)return 0;
  return res;
}


void solve(int idx){
  if(idx==U.size()){
    ans=max(ans,calc());
    return;
  }
  solve(idx+1);

  V.push_back(U[idx]);
  solve(idx+1);
  V.pop_back();
}


void dfs(int pos){
  int flg=1;
  U.push_back(pos),used[pos]=1;
  if(S.count(used)){
    U.pop_back(),used[pos]=0;
    return;
  }
  S.insert(used);
  
  for(int i=0;i<G[pos].size();i++) can[G[pos][i].f]++;
  
  for(int i=0;i<G[pos].size();i++){
    int nx=G[pos][i].f;
    if(used[nx]||can[nx]!=U.size())continue;
    flg=0;
    dfs(nx);
  }
  if(flg)solve(0);
  U.pop_back(),used[pos]=0;
  for(int i=0;i<G[pos].size();i++) can[G[pos][i].f]--;
}


int main(){
  int m;
  cin>>n>>m;
  for(int i=0,a,b,c;i<m;i++){
    cin>>a>>b>>c;
    a--,b--;
    G[a].push_back(P(b,c));
    G[b].push_back(P(a,c));
    g[a][b]=g[b][a]=c;
  }
  
  for(int i=0;i<n;i++)dfs(i);
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 4988
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+100;
int n,k,a[N],ans;


int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        a[i]=abs(a[i]-k);
        if(i==1)
        {
            ans=a[i];
        }
        ans=__gcd(ans,a[i]);
    }

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


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Dice dice = new Dice();
		for(int i = 0 ; i < 6 ; i ++){
			dice.d[i]=scan.nextInt();
		}
		for(int i = 0 ; i < 6 ; i ++){
			dice.d2[i]=scan.nextInt();
		}
		dice.check();
	}
}
class Dice{
	public int[] d = new int[6];
	public int[] d2 = new int[6];
	private int temp=0;	
	void N(){
		temp=d[0];
		d[0]=d[1];
		d[1]=d[5];
		d[5]=d[4];
		d[4]=temp;
	}
	void S(){
		temp=d[0];
		d[0]=d[4];
		d[4]=d[5];
		d[5]=d[1];
		d[1]=temp;
	}
	void E(){
		temp=d[0];
		d[0]=d[3];
		d[3]=d[5];
		d[5]=d[2];
		d[2]=temp;
	}
	void W(){
		temp=d[0];
		d[0]=d[2];
		d[2]=d[5];
		d[5]=d[3];
		d[3]=temp;
	}
	void R(){
		temp=d[1];
		d[1]=d[2];
		d[2]=d[4];
		d[4]=d[3];
		d[3]=temp;
	}
	void check(){
		for(int i = 0 ; i <= 3 ; i ++){
			if(checkAll()){
				break;
			}
			N();
			for(int j = 0 ; j <= 3 ; j ++){
				if(checkAll()){
					break;
				}
				R();
			}
		}
		for(int j = 0 ; j <= 3 ; j ++){
			if(checkAll()){
				break;
			}
			W();
			for(int i = 0 ; i <= 3 ; i ++){
				if(checkAll()){
					break;
				}
				R();
			}
		}
		if(Arrays.equals(d,d2)){
			System.out.println("Yes");
		}
		else
			System.out.println("No");
	}
	boolean checkAll(){
		if(d[0] == d2[0] && d[1] == d2[1] && d[2] == d2[2] &&
				d[3] == d2[3] && d[4] == d2[4] && d[5] == d2[5]){
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 17360
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define deb(x) cout<<#x<<" "<<x<<el;
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n==1) return x;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                              //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

template<typename T>
T maxx(T a,T b)
{
  if(a<b) re b;
  re b;
}
template<typename T, typename... Args>
T maxx(T a,T b, Args... args)
{
    re(maxx(maxx(a,b),args...));
}

template<typename T>
T minn(T a,T b)
{
  if(a<b) re a;
  re b;
}
template<typename T, typename... Args>
T minn(T a,T b, Args... args)
{
    re(minn(minn(a,b),args...));
}

template<typename T>
void read(T& a)
{
  cin>>a;
}
template<typename T, typename... Args>
void read(T& a,Args&... args)
{
  cin>>a; read(args...);
}

template<typename T>
void write(T a)
{
  cout<<a<<' ';
}
template<typename T, typename... Args>
void write(T a,Args... args)
{
  cout<<a<<' '; write(args...);
}

inline ll min(ll a,ll b)
{
  if(a<b) re a;
  else re b;
}
inline ll max(ll a,ll b)
{
  if(a<b) re b;
  else re a;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=((ans*((n-i)%N))%N*modInverse(i+1,N))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ld n,m,k;
    cin>>n;
    k=0;
    m=100;
    while(true)
    {
      m=floor(m+(m/100));
      k++;
      if(m>=n) break;
    }
    cout<<k<<el;
  }


  return 0;
}


Measured memory_bytes: 3808
//Volume1-0105
import java.util.*;

class Index implements Comparable<Index>{
	
	public final String ward;
	public ArrayList<Integer> page;

	public  Index(String s,int i){
		this.ward = s;
		this.page = new ArrayList<Integer>();
		this.page.add(i);
	}
	
	public int compareTo(Index I){
		return this.ward.compareTo(I.ward);
	}
}

public class Main {

	public static void main(String[] args) {

		//declare
		ArrayList<Index>   list = new ArrayList<Index>(); 
		ArrayList<Integer> p;
		String[]           s;
		String             ward;
		int                page,
                           size;
		boolean            find;
		
		//input
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			s = sc.nextLine().split("\\s");
			ward = s[0];
			page = Integer.parseInt(s[1]);

			//calculate
			find = false;
			for(Index I:list){
				if(I.ward.equals(ward)){
					I.page.add(page);
					find = true;
					break;
				}
			}
			if(!find){list.add(new Index(ward,page));}
		}
		Collections.sort(list);
		for(Index i:list){Collections.sort(i.page);}
		
		//output
		for(Index I:list){
			System.out.println(I.ward);
			p = I.page;
			size = p.size();
			for(int i=0;i<size;i++){
				System.out.print(p.get(i));
				if(i<size-1){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 17412
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define N 500
int w[N][N];
char m[N][N+1];

int sol(int r,int c){
  rep(i,r){
    w[i][0]=m[i][0]=='.'?1:0;
    REP(j,1,c)w[i][j]=m[i][j]=='*'?0:w[i][j-1]+1;
  }
  int ret=0,mw;
  rep(j,c){
    rep(i,r){
      ret=max(ret,mw=w[i][j]);
      REP(k,i+1,r&&mw){
	mw=min(mw,w[k][j]);
	ret=max(ret,(k-i+1)*mw);
      }
    }
  }
  return ret;
}

main(){
  int r,c;
  while(cin>>r>>c && r){
    rep(i,r)cin>>m[i];
    cout<<sol(r,c)<<endl;
  }
}

Measured memory_bytes: 2096
def main():
    n = int(input())
    a =list(map(int,input().split()))
    ans = 1
    tmp = 10 ** 18
    a.sort()
    for i, aa in enumerate(a):
        ans *= aa
        if ans > tmp:
            print(-1)
            return
    print(ans)
if __name__=='__main__':
    main()


Measured memory_bytes: 21612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N,x; cin >> N >> x;
	vector<int> a(2*N);
	rep(i,N){
		cin >> a[i];
		a[i+N] = a[i];
	}
	vector<vector<int>> b(N,vector<int>(N));
	rep(i,N){
		b[0][i] = a[i];
	}
	repr(i,1,N){
		rep(j,N){
			b[i][j] = min(b[i-1][j],a[j+N-i]);
		}
	}
	ll ans = LINF;
	rep(i,N){
		ll now = (ll)x*i;
		rep(j,N){
			now += b[i][j];
		}
		ans = min(ans,now);
	}
	cout << ans << endl;
}



Measured memory_bytes: 16000
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[52];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>s;
    a=s.size();
    cout<<s[0]<<a-2<<s[a-1];
    return 0;
}



Measured memory_bytes: 256
import math
a, b, h, m = map(int,input().split())
f = h * 30 + m * 0.5 # 短針
g = m * 6 # 長針
mm = abs(f - g)
l = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(mm)))
print('{:.20f}'.format(l))

Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  int n;  cin >> n;
  vector<ll> v(n);
  map<ll,ll> ma;
  rep(i,0,n){
    cin >> v[i];
    ma[v[i]]++;
  }
  ll ans=1;
  bool ok=true;
  if(n%2==1){
      for(auto j : ma){
        if(j.fi==0){
          if(j.se!=1){
            ok=false;
          }
        }else{
          if(j.se!=2)ok=false;
          else{
            ans *= 2;
            ans %= mod;
          }
        }
      }
  }else{
    for(auto j : ma){
      if(j.se!=2) ok=false;
      else{
        ans *= 2;
        ans %= mod;
      }
    }
  }
  if(ok)cout << ans << endl;
  else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 4992
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<String,Integer> blue = new HashMap<>();
		Map<String,Integer> red = new HashMap<>();
		int n=sc.nextInt();

		for(int i=0;i<n;i++) {
			String s=sc.next();
			if(blue.get(s)==null) {
				blue.put(s,1);
			}else {
				blue.put(s,blue.get(s)+1);
			}
		}
		int m=sc.nextInt();
		for(int i=0;i<m;i++) {
			String s=sc.next();
			if(red.get(s)==null) {
				red.put(s,1);
			}else {
				red.put(s,red.get(s)+1);
			}
		}
		int max = 0;
		for(String key : blue.keySet()) {
			int tmp;
			if(red.containsKey(key)) {
				tmp =blue.get(key)-red.get(key);
			}else {
				tmp=blue.get(key);
			}
			if(max<tmp) {
				max=tmp;
			}
		}
		System.out.println(max>0?max:0);
	}
}

Measured memory_bytes: 27148
#include <iostream>
#include <string>
using namespace std;
int main(){
		
		int N,T[100],M,P[100],X[100];
		int r=0;
		
		cin>>N;
		for(int i=0;i<N;i++){
			cin>>T[i];
		}
		cin>>M;
		for(int i=0;i<M;i++){
			cin>>P[i]>>X[i];
		}
		for(int i=0;i<N;i++){
			r=r+T[i];
		}
		for(int i=0;i<M;i++){
			cout<<r-T[ P[i]-1 ]+X[i]<<endl;
	    }
	    
	}

Measured memory_bytes: 256
# Here your code !
length = STDIN.gets.to_s.to_i
r = Array.new
 
for i in 0..length - 1 do
    r.push(STDIN.gets.to_s.to_i)
end
 
 
max_num = r[1]
max_point = 1
 
min_num = r[0]
min_point = 1
 
max_profit = max_num - min_num
 
k = 0
 
while k < length - 1 
    max_num = r[k+1]
    max_point = k+1
    for j in (k+1)..(length - 1) do
        if max_num <= r[j] then
            max_num = r[j]
            max_point = j
        end
    end

    for i in k..(max_point - 1) do
        if min_num > r[i]
            min_num = r[i]
            min_point = i
        end
    end

    if max_profit < max_num - min_num then
        max_profit = max_num - min_num
    end
     
    k = max_point + 1
end
 
p max_profit

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

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

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let len = s.len();
    let mut ans = 0;
    let mut i = 0;

    while i < (len / 2) {
        if s[i] != s[len - 1 - i] {
 //           println!("{}", s[i]);
 //          println!("{}", s[len - 1 -i]);
            ans = ans + 1;
        }
        i = i + 1;
    }
//    println!("{:?}, {}", s, len);
    println!("{}", ans);

}



Measured memory_bytes: 4352
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int main(void) {
    string s;
    cin >> s;
    if (
        s[0] == s[1] ||
        s[1] == s[2] ||
        s[2] == s[3]) {
        cout << "Bad" << endl;
    } else {
            cout << "Good" << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct StronglyConnectedComponents {
  int V;
  std::vector<std::vector<int>> G, rG;
  std::vector<int> vs, cmp;
  std::vector<bool> used;

  StronglyConnectedComponents(int V) : V(V) {
    used.assign(V, false);
    G.resize(V), rG.resize(V);
    cmp.resize(V);
  }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void dfs(int v) {
    used[v] = true;
    for (int c : G[v])
      if (not used[c]) dfs(c);
    vs.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int c : rG[v])
      if (not used[c]) rdfs(c, k);
  }

  int run() {
    fill(used.begin(), used.end(), false);
    vs.clear();
    for (int v = 0; v < V; v++)
      if (!used[v]) dfs(v);
    fill(used.begin(), used.end(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--)
      if (!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
};


int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int V, E; cin >> V >> E;
  StronglyConnectedComponents scc(V);
  REP(i, E) {
    int s, t; cin >> s >> t;
    scc.add_edge(s, t);
  }
  scc.run();
  vector<int> order(V);
  REP(i, V) order[scc.cmp[i]] = i;
  REP(i, V) cout << order[i] << endl;

  return 0;
}



Measured memory_bytes: 4428
import numpy as np

D=int(input())
c=np.array(list(map(int,input().split())))
s=[list(map(int,input().split())) for _ in range(D)]
last=np.array([0]*26)
t=[int(input()) for _ in range(D)]

v=0
for d in range(1,D+1):
    v+=s[d-1][t[d-1]-1]
    last[t[d-1]-1]=d
    v-=np.dot(c,d-last)
    print(v)

Measured memory_bytes: 27484