akhauriyash/Code-Regression huggingface dataset:
#アルゴリズム関数-サイコロを回転させる
def dice_rotation(list1, str1):
    if str1 == "S":
        list1[0],list1[1],list1[4],list1[5] = list1[4],list1[0],list1[5],list1[1]
    elif str1 == "E":
        list1[0],list1[2],list1[3],list1[5] = list1[3],list1[0],list1[5],list1[2]
    elif str1 == "N":
        list1[0],list1[1],list1[4],list1[5] = list1[1],list1[5],list1[0],list1[4]
    elif str1 == "W":
        list1[0],list1[2],list1[3],list1[5] = list1[2],list1[5],list1[0],list1[3]
    return list1

#アルゴリズム関数-上面・前面の番号を指定番号へサイコロを回転させる
def dice_find(list1, int1, int2):
    try:
        position_numnber = list1.index(int2)
    except:
        position_numnber = -1
    if position_numnber == 0:
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 2:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 4:
        list1 = dice_rotation(list1, "S")
        list1 = dice_rotation(list1, "S")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "N")
    try:
        position_numnber = list1.index(int1)
    except:
        position_numnber = -1
    if position_numnber == 2:
        list1 = dice_rotation(list1, "W")
    elif position_numnber == 3:
        list1 = dice_rotation(list1, "E")
    elif position_numnber == 5:
        list1 = dice_rotation(list1, "W")
        list1 = dice_rotation(list1, "W")
    return list1

#アルゴリズム関数-サイコロの内容が
def list_overlapping_check(list1):
    result = True
    for i in range(1, len(list1)):
        list1[i] = dice_find(list1[i], list1[0][0], list1[0][1])
        if list1[0] == list1[i]:
            result = False
            break
    if result == True and len(list1) > 2:
        result = list_overlapping_check(list1[1:])
    return result

#インプットdataの格納
input_count = int(input())
check_data = list()
for i in range(input_count):
    check_data.append(list(map(int, input().split())))

#結果表示
if list_overlapping_check(check_data) == True:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5640
// dp[i][K] denote the number of ways to distribute all K candies among first i people
// dp[i][K] = dp[i-1][K] + dp[i-1][K-1] + dp[i-1][K-2]....dp[i-1][K-A[i]]

// dp[0][0] = 1; dp[0][X] = 0;

// prefixSum of dp[i-1]

// dp[i][K] denote number of ways to distribute atmost K candies to first i students! 
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
ll a[101];
ll dp[101][100001];
ll prefix[101][100001];
ll mod = 1000000007LL;
void fix(ll &v) {
	if(v >= mod) {
		v-=mod;
	} 
	if( v < 0) {
		v+=mod;
	}
}
int main() {
	ll n, K;
	cin>>n>>K;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
	}
	dp[0][0] = 1;
	prefix[0][0] = 1;
	for(int j=1;j<=K;j++) {
		prefix[0][j] = prefix[0][j-1];
	}
	for(int i=1;i<=n;i++) {
		for(int j=0; j<=K;j++) {
			dp[i][j] = prefix[i-1][j] - 
				(j - a[i] -1 >=0 ? prefix[i-1][j-a[i] -1]:0LL);
			fix(dp[i][j]);
		}
		prefix[i][0] = dp[i][0];
		for(int j=1; j<=K;j++) {
			prefix[i][j] = prefix[i][j-1] + dp[i][j];
			fix(prefix[i][j]);
		}
	}
	cout<< dp[n][K] <<endl;
	return 0;
}

Measured memory_bytes: 158080
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	int k, abc[5];
	cin >> abc[0];
	cin >> abc[1];
	cin >> abc[2];
	cin >> abc[3];
	cin >> abc[4];
	cin >> k;
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5;j++) {
			if (abs(abc[i] - abc[j]) > k) {
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long 
#define pi 3.1415926536
using namespace std;
const ll N=1e18;
ll pr(ll a,ll b,ll c)
{
	if(b==0)
	return 1LL;
	ll ans=1;
	while(b>0)
	{
		if(b%2)
		ans=((ans%c)*(a%c))%c;
		a=((a%c)*(a%c))%c;
		b/=2;
		a%=c;
		ans%=c;
	}
	return ans;
}
void solve()
{ll n,k,h,x,y,z,w,mini,maxi=INT_MAX,prev,res;
 set<ll> s;
 map<ll,ll> m;
 cin>>x;
 for(ll i=-1000;i<=1000;i++)
 {
 	y=pr(i,5,N);
 	m[y]=i;
 	s.insert(y);
 }
 for(auto i:s)
 {
 	auto j=s.find(x+i);
 	if(j!=s.end())
 	{
 		cout<<m[(*j)]<<" "<<m[i];
 		break;
	}
 }
}
  
int main()
{
  fast
  //for(ll i=0;i<=9;i++)
  //cal(1,3234566667,i);
  //sort(v.begin(),v.end());
  //pre();
ll t=1;
//cin>>t;
//SieveOfEratosthenes();
//cout<<"ok";
while(t--)
{ //cout<<"ok";

solve();
 //cout<<ma<<endl;
}
return 0;}
/*
ll pr(ll a,ll b,ll c)
{
	if(b==0)
	return 1LL;
	ll ans=1;
	while(b>0)
	{
		if(b%2)
		ans=((ans%c)*(a%c))%c;
		a=((a%c)*(a%c))%c;
		b/=2;
		a%=c;
		ans%=c;
	}
	return ans;
}
vector<ll> fact(N+1);
void pre()
{
	fact[0]=1;
	for(ll i=1;i<=N;i++)
	fact[i]=fact[i-1]*i,fact[i]%=hell;
	
}
*/

Measured memory_bytes: 3832
S=input()
xs=S.split('x')
xs=''.join(xs)

if xs!=xs[::-1]:
    print(-1)
else:
    ans=0
    N=len(S)
    M=len(xs)
    count1=[0]*(M+1)
    count2=[0]*(M+1)
    rs=S[::-1]
    i=j=0
    a=b=0
    while i<N:
        if S[i]!='x':
            a+=1
        else:
            count1[a]+=1
        if rs[i]!='x':
            b+=1
        else:
            count2[b]+=1
        i+=1
    for a,b in zip(count1,count2):
        ans+=abs(a-b)
    print(ans//2)

Measured memory_bytes: 11000
#include <iostream>
#include <vector>
using namespace std;
#define SIZE 100000
long N;
void solve()
{
    vector < long > number;
    long i,ans=0;
    for (i=0;i<SIZE;i++)
        number.push_back(0);
    while(N--)
    {
        long x;
        cin>>x;
        number[x]++;
    }
    for (i=0;i<SIZE-2;i++)
    {
        long temp=number[i]+number[i+1]+number[i+2];
        ans=ans>temp?ans:temp;
    }
    cout<<ans<<endl;
}
int main()
{
    while(cin>>N)
        solve();
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <math.h>

int main() {
	long long N = 0;
	
	std::cin >> N;
	
	std::vector<long long> A(N, 0);
	long long sum = 0;

	for (int i = 0; i < A.size(); i++) {
		std::cin >> A[i];
		sum += A[i];
	}

	long long ii = -1;
	long long val = 0;
	long long bval = 0;

	while (val < sum / 2) {
		ii++;
		bval = val;
		val += A[ii];
	}

	
	if (val == sum / 2 && sum % 2 == 0) {
		std::cout << 0 << std::endl;
	}
	else if (val == sum / 2 && sum % 2 == 1) {
		std::cout << 1 << std::endl;
	}
	else if (ii == 0) {
		long long ans = 2 * A[ii] - sum;
		std::cout << ans << std::endl;
	}
	else if (ii == N - 1) {
		long long ans = 2 * A[ii] - sum;
		std::cout << ans << std::endl;
	}
	else {
		long long half = sum / 2;
		long long amr = sum % 2;
		long long vlt = half - bval;
		long long vgt = val - half - amr;
		long long jdg = std::min(vlt, vgt);
		long long ans = 2 * jdg + amr;

		std::cout << ans << std::endl;
	}
	

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

int main() {
    std::string s;
    std::cin >> s;
    for (int i = 0; i < 3; i++) {
        if (s[i] == '7') {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 3596
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

int main() {
	int a, b; cin >> a >> b;

	if (a == b)cout << "Draw" << endl;
	else if (a == 1) cout << "Alice" << endl;
	else if (b == 1)cout << "Bob" << endl;
	else if(a > b)cout << "Alice" << endl;
	else cout << "Bob" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,cap,rev;
	edge(){}
	edge(int tt,int cc,int rr){
		to=tt;
		cap=cc;
		rev=rr;
	}
};

vector<edge> G[20005];
bool used[20005];
int level[20005];
int iter[20005];

void add_edge(int from,int to,int cap){
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,cap,G[from].size()-1));
}

void add_edge2(int from,int to,int cap){
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size()-1));
}

int dfs(int v,int t,int f){
	if(v==t)return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		edge &e=G[v][i];
		if(!used[e.to] && e.cap>0){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow=0;
	while(1){
		memset(used,0,sizeof(used));
		int f=dfs(s,t,500);
		if(f==0)return flow;
		flow+=f;
	}
}

int h,w;
string str;
int fie[101][101];
int sx,sy,gx,gy;

int main(void){
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		string str;
		cin >> str;
		for(int j=0;j<w;j++){
			if(str[j]=='o')fie[i][j]=1;
			if(str[j]=='S'){
				fie[i][j]=1;
				sx=j;
				sy=i;
			}
			if(str[j]=='T'){
				fie[i][j]=1;
				gx=j;
				gy=i;
			}
		}
	}
	if(gx==sx || sy==gy){
		printf("%d\n",-1);
		return 0;
	}
	int s=20000,t=20001;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fie[i][j]==1){
				add_edge(10000+i*w+j,i*w+j,1);\
				for(int k=0;k<h;k++){
					if(fie[k][j]==1){
						add_edge2(i*w+j,10000+k*w+j,1);
					}
				}
				for(int k=0;k<w;k++){
					if(fie[i][k]==1){
						add_edge2(i*w+j,10000+i*w+k,1);
					}
				}
			}
		}
	}
	add_edge(s,sy*w+sx,500);
	add_edge(sy*w+sx+10000,sy*w+sx,500);
	add_edge(gy*w+gx,t,500);
	add_edge(gy*w+gx+10000,gy*w+gx,500);
	int res=max_flow(s,t);
	printf("%d\n",res);
	return 0;
}


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

const int LIMIT = 1000001;

int main()
{
	bool* prime = new bool[ LIMIT ]();
	prime[ 0 ] = prime[ 1 ] = true;
	for( int i = 2; i < LIMIT; ++i ){
		if( prime[ i ] ) continue;
		for( int j = i + i; j < LIMIT; j += i ){
			prime[ j ] = true;
		}
	}

	int n;
	while( cin >> n && n ){
		int count = 0;
		for( int i = 0; i < n / 2 + 1; ++i ){
			if( prime[ i ] || prime[ n - i ] ) continue;
			++count;
		}
		cout << count << endl;
	}

	delete[] prime;

	return 0;
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    double L;
    cin >> L;
    printf("%.10f\n",(L / 3) * (L / 3) * (L / 3));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	char s[100010];
	cin>>(s+1);
	int len=strlen(s+1),ans=0;
	for(int i=1;i<=len/2;i++){
		if(s[i]!=s[len-i+1]){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

namespace {
    struct Edge{
        int dst, cost;
    };
    typedef vector<Edge> Node;
    typedef vector<Node> Graph;
    Graph G;
    typedef tuple<int, int, int> TP;
    vector<TP> es;
    vector<bool> is_base;
    int N, T, K;

    int uf[10000];
    int have[10000];
    
    int root(int x) {
        if(uf[x] == x) return x;
        return uf[x] = root(uf[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        assert(x != y);
        bool res = have[x] && have[y];

        have[x] = have[x] || have[y];
        uf[y] = x;

        return res;
    }

    int solve() {
        REP(i, N) uf[i] = i;
        REP(i, N) have[i] = is_base[i];

        int ans = 0;
        reverse(es.begin(), es.end());
        int rest = (T-1) - K;
        for(auto tp : es) {
            int w, a, b;
            tie(w, a, b) = tp;
            if(unite(a, b)) {
                if(--rest < 0) {
                    ans += w;
                }
            }
        }
        return ans;
    }
}


int main(){
    iostream_init();
    int Case = 0;
    while(cin >> N >> T >> K && N > 0) {
        cout << "Case " << ++Case << ": ";
        G.assign(N, Node());
        es.clear();
        is_base.assign(N, false);

        REP(i, N-1) {
            int a, b, w;
            cin >> a >> b >> w;
            a--; b--;
            G[a].push_back({b, w});
            G[b].push_back({a, w});
            es.push_back(TP(w, a, b));
        }
        sort(es.begin(), es.end());

        REP(i, T){
            int base;
            cin >> base;
            base--;
            is_base[base] = true;
        }

        cout << solve() << endl;
    }
    return 0;
}

/* vim:set foldmethod=marker: */

Measured memory_bytes: 2192
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
      	int b = sc.nextInt();
      	if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0)
          System.out.println("Possible");
      	else
          System.out.println("Impossible");
    }
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

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

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

vector<string> num, ord;
int n, k;
set<string> st;
vector<bool> used;

void rec(int pos=0){
    if(pos == k){
        string s="";
        for(int i=0; i<k; i++) s=s+ord[i];
        st.insert(s);
        return;
    }
    for(int i=0; i<n; i++){
        if(used[i]) continue;
        used[i]=true;
        ord[pos]=num[i];
        rec(pos+1);
        used[i]=false;
    }
    return;
}

int main(){
    while(cin >> n >> k){
        if(n == 0 && k == 0) break;
        st.clear();
        num.resize(n), ord.resize(k);
        used.assign(n, 0);
        for(auto &x : num) cin >> x;
        rec();
        cout << st.size() << endl;
    }
    return 0;
}


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

int main(){
  int N, K, S;
  cin >> N >> K >> S;
  vector<int> A(N,1e9);
  for(int i = 0; i < K; ++i){
    A[i] = S;
  }
  if(S == 1e9){
    for(int i = 0; i < N; ++i){
      if(i < K) A[i] = S;
      else A[i] = 1;
    }
  }
  for(int i = 0; i < N; ++i){
    cout << A[i] << (i+1 < N ? " " : "\n");
  }
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x);

int main(){
    ll n, k, cnt1 = 0, cnt2 = 0, ans = 0;
    sc(n) sc(k)
    for (int i = 1; i <= n; i++){
        if (i%k == 0) cnt1++;
        if (i%k == k/2) cnt2++;
    }
    ans += cnt1 * cnt1 * cnt1;
    if (k%2 == 0) ans += cnt2 * cnt2 * cnt2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
n=n0()
a=n1()

ans=[0]*(n+1)
for i,s in enumerate(a,1):
    ans[s]=i
print(*ans[1:])

Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind{
  int a;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int n,int a):a(a){init(n);}
  void init(int n){
    r.clear();
    p.clear();
    r.resize(n);
    p.resize(n);
    for(int i=0;i<n;i++) r[i]=1,p[i]=i;
  }

  int find(int x){
    if(x!=p[x]) p[x]=find(p[x]);
    return p[x];
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

  int unite(int x,int y){
    x=find(x),y=find(y);
    if(x==y) return 0;
    if(r[x]<r[y]) swap(x,y);
    if(x>=a&&y>=a) return 1;
    if(y>=a) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    return 0;
  }
  
};
signed main(){
  int n,m,k;
  cin>>n>>m>>k;
  UnionFind uf(n+m,n);
  for(int i=0;i<k;i++){
    int t;
    cin>>t;
    int ng;
    if(t==1){
      int a,b;
      cin>>a>>b;
      a--;b--;
      ng=uf.unite(a,b);
    }
    if(t==2){
      int c,x;
      cin>>c>>x;
      c--;x--;
      ng=uf.unite(c,n+x);
    }
    if(ng){
      cout<<i+1<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 5972
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+30;
typedef long long ll;
ll ans;
char s[maxn];
int n,a[maxn],m,top,p[maxn],cnt;

int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for (int i=1;i<=n;i++) m+=(s[i]=='1');
    for (int i=1;i<=m;i++) ans+=(i+1)/2;
    for (int i=1;i<=n;i++){
        a[++top]=(s[i]=='1');
        if (top>1&&a[top]&&a[top-1]) top-=2,ans+=n-m;
    }
    for (int i=1;i<=top;i++) if (a[i]) p[++cnt]=i;
    for (int i=1;i<=cnt;i++) {
        int pre=p[i]-i,suf=n-m-pre;
        ans+=(pre+(i%2==0))/2+suf;
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector < int >h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (h[i] >= K) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P a){
  Q[tail]=a;
  tail=(tail+1)%LEN;
}
P dequeue(){
  P a = Q[head];
  head = (head+1)%LEN;
  return a;
}
int min(int n,int m){return n < m ? n : m;}
int main(){
  int elaps = 0,cha;
  int i,j;
  P u;
  scanf("%d %d",&n,&j);
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head=1;tail=n+1;
  while(head != tail){
    u = dequeue();
    cha = min(j,u.t);
    u.t -= cha;
    elaps += cha;
    if(u.t > 0)enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}



Measured memory_bytes: 11852
import java.util.Scanner;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N=sc.nextInt();
		long[] a=new long[N];
		long B=0;
		for(int i=0;i<N;i++) {
			a[i]=sc.nextLong();
			B^=a[i];
		}
		for(int i=0;i<N;i++) System.out.println(B^a[i]);
	}
}

Measured memory_bytes: 63500
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a; cin >> a;
    cout << a + a*a + a*a*a;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3652
fun main(args: Array<String>) {
    sumitrust2019d()
}

fun sumitrust2019d() {
    val n = readLine()!!.toInt()
    val s = readLine()!!


    val set = mutableSetOf<String>()

    for (l in 0..9) {
        for (m in 0..9) {
            for (r in 0..9) {
                val left = s.indexOfFirst { it.toString().toInt() == l }
                val right = s.indexOfLast { it.toString().toInt() == r }
                if (left == -1 || right == -1) continue
                
                val between = s.slice(left + 1..right - 1)
                if (between.contains(m.toString().toCharArray()[0])) {
                    set.add(l.toString() + m.toString() + r.toString())
                }
            }
        }
    }

    println(set.size)
}


Measured memory_bytes: 121312
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <cmath>
#include <sstream>
#define F first
#define S second
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int main() {
	int n;
	while (cin >> n && n) {
		vector<long long> a;
		a.push_back(0);
		for(int i=0;i<n;i++)
		{
			long long x;
			cin>>x;
			a.push_back(x);
		}
		for(int i=1;i<a.size();i++)
		{
			a[i]+=a[i-1];
		}
		long long ans=a[1];
		for(int r=0;r<a.size();r++)
		{
			for(int l=r+1;l<a.size();l++)
			{
				ans=max(ans,a[l]-a[r]);
			}
		}
		cout<<ans<<endl;
	}




	return 0;
}

Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String key = "keyence";
        if (s.length() < key.length()) {
            System.out.println("NO");
            return;
        }
        if (s.equals(key)) {
            System.out.println("YES");
            return;
        }
        int inx = s.indexOf(key);
        if (inx == 0) {
            System.out.println("YES");
            return;
        }
        if (key.equals(s.substring(s.length() - key.length()))) {
            System.out.println("YES");
            return;
        }
        for (int i = 1; i < key.length(); ++i) {
            String left = key.substring(0, i);
            String right = key.substring(i);
            int index = s.indexOf(left);
            if (index == 0) {
                String str = s.substring(s.length() - right.length());
                if (right.equals(str)) {
                    System.out.println("YES");
                    return;
                }
            }
        }
        System.out.println("NO");
    }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    if (abs(n - m) >= 2) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    ll np = 1, mp = 1;
    int mod = 1e9 + 7;
    for (int i = n; i >= 1; i--) {
        np *= i;
        np = np % mod;
    }
    for (int i = m; i >= 1; i--) {
        mp *= i;
        mp = mp % mod;
    }

    ans = np * mp % mod;

    if (n == m) {
        ans *= 2;
        ans = ans % mod;
    }

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


Measured memory_bytes: 256
#include <stdio.h>
int p=0;
int q[2000001];
int max_index(int a,int b){
  if(q[a]>q[b])return a;
  else return b;
}
void swap(int a,int b){
  int tmp;
  tmp=q[a];
  q[a]=q[b];
  q[b]=tmp;
}
 
void insert(int k){
  int tmp;
  int i,j;
  p++;
  q[p]=k;
  i=p;
  while(q[i]>q[i/2] && i>1){
    swap(i,i/2);
    i=i/2;
  }
}
int extract(){
  int ret=q[1];
  int i;
  int tmp;
  int M;
  q[1]=q[p];
  p--;
  i=1;
  while(i*2 <= p ){
    if(i*2+1 <= p)
      M=max_index(i*2,i*2+1);
    else M=i*2;
    if(max_index(M,i)==M){swap(M,i);i=M;}
    else break;
     
  }
  
  return ret;
}
 
int main(){
  char cmd[10];
  int i,j;
  int k;
  while(1){
    scanf("%s",cmd);
    if(cmd[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    if(cmd[0]=='e'){
      if(cmd[1]=='x')
    printf("%d\n",extract());
      if(cmd[1]=='n') break;
    }
  }
  return 0;
}


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

using namespace std;

map<int, int> done;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int rem = n - i;
    if (rem != i) ans++;
  }
  cout << ans / 2 << '\n';
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define endl '\n'

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n), b;
	rep(i, n) cin >> a[i];
	b = a;
	sort(all(b));
	int cnt = 0;
	rep(i, n) if(a[i] != b[i]) cnt++;
	if(cnt <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main() {
    int const MOD = 1e9 + 7;
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);

    vector<int> v;
    if (n % 2 == 0) {
        rep(i, n / 2) rep(j, 2) v.push_back(2 * i + 1);
    } else {
        rep(i, n / 2 + 1) rep(j, 2) v.push_back(2 * i);
        v.erase(v.begin());
    }

    bool ok = true;
    rep(i, n) if (a[i] != v[i]) ok = false;
    if (!ok) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    rep(i, n / 2) ans = (ans * 2) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4296
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  if(n%2==0){
    ll ans = 0;
    rep(i,n/2){
      ans -= a[i];
      ans += a[i+n/2];
    }
    ans = ans*2 + a[n/2-1] - a[n/2];
    cout << ans << endl; return 0;
  }

  ll ans1 = 0;
  rep(i,n){
    if(i<n/2){
      ans1 -= 2*a[i];
    } else {
      ans1 += 2*a[i];
    }
  }
    ans1 -= a[n/2] + a[n/2+1];

  ll ans2 = 0;
  rep(i,n){
    if(i<n/2+1){
      ans2 -= 2*a[i];
    } else {
      ans2 += 2*a[i];
    }
  }
    ans2 += a[n/2] + a[n/2-1];
  ll ans = max(ans1, ans2);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> A1(N+1);
    vector<int> B1(N);
    vector<int> A2(N+1);
    vector<int> B2(N);
    for(int i=0; i<N+1; i++){
        cin >> A1.at(i);
        A2.at(i)=A1.at(i);
    }
    for(int i=0; i<N; i++){
        cin >> B1.at(i);
        B2.at(i)=B1.at(i);
    }

    ll ans1=0;
    ll ans2=0;

    for(int i=0; i<N; i++){
        if(A1.at(i)<B1.at(i)){
            ans1 += A1.at(i);
            B1.at(i) -= A1.at(i);
            A1.at(i)=0;

            if(A1.at(i+1)<=B1.at(i)){
                ans1 += A1.at(i+1);
                A1.at(i+1) = 0;
            }else{
                ans1 += B1.at(i);
                A1.at(i+1) -= B1.at(i);
            }
        }else{
            ans1 += B1.at(i);
            A1.at(i) -= B1.at(i);
        }
    }
    
    cout << ans1;


}

Measured memory_bytes: 1792
while True:
    h,w=map(int,input().split())

    if h==0 and w==0:
        break

    for i in range(h):
        wid=''
        if i==0 or i==h-1:
            for l in range(w):  
                wid+='#'
            print(wid)
        
        else :
            wid+='#'
            for k in range(1,w-1):
                wid+='.'
            wid+="#"
            print(wid)
    print("")


Measured memory_bytes: 5616
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9+7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

LL N, S;

LL calc(LL B) {
	LL temp = 0;
	LL n = N;
	while (n > 0) {
		temp += n % B;
		n -= n % B;
		n /= B;
	}
	return temp;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> N >> S;
	if (N < S) {
		cout << -1 << "\n";
		return 0;
	}
	if (N == S) {
		cout << N + 1 << "\n";
		return 0;
	}
	LL ans = INF;
	for (LL b = 1; b * b <= N - S; b++) {
		if ((N - S) % b != 0)continue;
		if (calc(b + 1) == S)ans = min(ans, b + 1);
		if (calc((N - S) / b + 1) == S)ans = min(ans, (N - S) / b + 1);
	}
	if (ans == INF)cout << -1 << "\n";
	else cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338
#define int long long
#define double long double
struct RMQ{
  int n;
  vector<int> dat;
  const int def=0;
  RMQ(){}
  RMQ(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,def);
  }
  void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
  int query(int k){
    return dat[k+n-1];
  }
};

typedef pair<int,int> P;
signed main(){
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  
  int n;
  cin>>n;
  P p[n];
  for(int i=0;i<n;i++) cin>>p[i].first>>p[i].second;
  if(x1>x2){
    swap(x1,x2);
    swap(y1,y2);
  }
  if(y1>y2){
    for(int i=0;i<n;i++) p[i].second*=-1;
    y1*=-1;
    y2*=-1;
  }
  sort(p,p+n);
  vector<int> cx(n+2,x1),cy((n+2),y1);
  int cnx=0,cny=0;
  auto add_vx = [&](int x){
    cx[cnx++]=x;
  };
  auto add_vy = [&](int y){
    cy[cny++]=y;
    /*
    if(y1>y2) cy[cny++]=y-1;
    else cy[cny++]=y-1;
    */
  };

  add_vx(x1);
  add_vy(y1);
  add_vx(x2);
  add_vy(y2);
  
  
  for(int i=0;i<n;i++){
    add_vx(p[i].first);
    add_vy(p[i].second);
  }
  
  sort(cx.begin(),cx.end());
  cx.erase(unique(cx.begin(),cx.end()),cx.end());
  sort(cy.begin(),cy.end());
  cy.erase(unique(cy.begin(),cy.end()),cy.end());
  
  map<int,int> mx,my;
  for(int i=0;i<(int)cx.size();i++) mx[cx[i]]=i;
  for(int i=0;i<(int)cy.size();i++) my[cy[i]]=i;
  map<int,int> px,py;
  for(int i=0;i<n;i++){
    px[p[i].second]=p[i].first;
    py[p[i].first]=p[i].second;
  }
  RMQ rmq(cy.size()+100);
  double base=(abs(x1-x2)+abs(y1-y2))*100;
  double diff=5*PI-20,diff2=10*PI-20;
  double  ans=1e15;
  for(int i=mx[x1];i<=mx[x2];i++){
    int x=cx[i];
    if(!py.count(x)) continue;
    int y=py[x];
    int t=rmq.query(my[y1],my[y]);
    rmq.update(my[y],t-1);
  }
  int k=-rmq.query(my[y1],my[y2]+1);
  //cout<<k<<endl;
  if(k==min(abs(x2-x1),abs(y2-y1))+1) ans=base+diff*(k-1)+diff2;
  else ans=base+diff*k;
  printf("%.15Lf\n",ans);
  return 0;
}


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

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

  int g[] = { 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
  int x, y;
  cin >> x >> y;

  if (g[x-1] == g[y-1]) cout << "Yes\n";
  else cout << "No\n";

  return (0);
}


Measured memory_bytes: 3624
A,B = map(int,input().split())
import math

a_min=math.ceil(A/0.08)
b_min=math.ceil(B/0.1)
a_list=[]
b_list=[]

for i in range(a_min,a_min+12):
  a_list.append(i)
for j in range(b_min,b_min+10):
  b_list.append(j)
  
ans=-1
for item in a_list:
  if item in b_list:
    ans=item
    break
  
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define ff first
#define ss second
#define p pair<ll,ll>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define iof  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi acos(-1)
const int mxn=1e9+5;
int main()
{
    fast;
    ll n;
    cin>>n;
    vector<ll>vec(n);
    ll ans=0;
    for(auto &i:vec)
    {
        cin>>i;
    }
    for(ll i=1;i<n;i++)
    {
        if(vec[i]<vec[i-1])
        {
            ans+=vec[i-1]-vec[i];
            vec[i]=vec[i-1];

        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4780
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N, K, P[5123], C[5123];

int main() {

	cin >> N >> K;
	rep(i, N) cin >> P[i];
	rep(i, N) P[i]--;
	rep(i, N) cin >> C[i];

	ll ans[5123];
	rep(i, N) ans[i] = 1ll << 63;

	rep(i, N) {
		ll cur = P[i];
		ll curC = 0;
		ll k = 0;
		while (cur != i) {
			curC += C[cur];
			ans[i] = max(ans[i], curC);
			cur = P[cur];
			k++;
			if (k == K) break;
		}
		if (k == K) continue;
		curC += C[cur];
		ans[i] = max(ans[i], curC);
		k++;
		if (curC > 0) {
			ans[i] = curC * (K / k - 1);
			k = (K / k - 1) * k; curC = 0; cur = P[i];
			ll t = ans[i];
			while (k != K) {
				curC += C[cur];
				ans[i] = max(ans[i], t + curC);
				cur = P[cur];
				k++;
			}
		}
	}

	cout << *max_element(ans, ans + N) << endl;

	return 0;
}


Measured memory_bytes: 3708
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

vector<PII> g[6010];
int d[6010][2010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  while(true) {
    int n, m, cap;
    cin >> n >> m >> cap; cap *= 10;
    if(!n) break;
    string src, dst;
    cin >> src >> dst;
    int V = 0;
    map<string,int> mp;
    REP(i, 6010) g[i].clear();
    REP(i, n) {
      int l;
      string s, t;
      cin >> s >> t >> l;
      if(mp.find(s) == mp.end()) {
        mp[s] = V++;
      }
      if(mp.find(t) == mp.end()) {
        mp[t] = V++;
      }
      g[mp[s]].PB({mp[t], l});
      g[mp[t]].PB({mp[s], l});
      // cout << mp[s] << " " << mp[t] << " " << l << endl;
    }
    VI exist(V, 0);
    REP(i, m) {
      string s;
      cin >> s;
      exist[mp[s]] = 1;
    }
    int start = mp[src], goal = mp[dst];
    // cout << V << endl;

    REP(i, V) REP(j, cap+1) d[i][j] = LLINF;
    d[start][cap] = 0;
    priority_queue<VI, VVI, greater<VI>> que;
    que.push({d[start][cap], start, cap});

    while(que.size()) {
      VI v = que.top(); que.pop();
      // cout << v << endl;
      int dist = v[0], place = v[1], gas = v[2];
      if(dist > d[place][gas]) continue;
      for(PII &p: g[place]) {
        int rest = exist[p.first]?cap:gas-p.second;
        if(gas >= p.second && d[p.first][rest] > d[place][gas] + p.second) {
          d[p.first][rest] = d[place][gas] + p.second;
          que.push({d[p.first][rest], p.first, rest});
        }
      }
    }

    int ans = LLINF;
    REP(i, cap+1) chmin(ans, d[goal][i]);
    if(ans==LLINF) cout << -1 << endl;
    else cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 179988
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		while(H!=0&&W!=0){
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					System.out.print("#");
				}
				System.out.println("");
			}
			System.out.println("");
			H = sc.nextInt();
			W = sc.nextInt();
		}
	}
}

Measured memory_bytes: 25732
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,m,a,d,k;
map<int,int> mp;

int id(int x)
{
	if(!mp[x]) return x;
	return mp[x];
}
int main()
{
	int x,y,z;
	int yv,zv;
	RI(n,a,d,m);
	REP(i,1,m)
	{
		scanf("%d %d %d",&x,&y,&z);
		if(x==0)
		{
			yv = id(y);
			zv = id(z);
			mp[y] = zv;
			mp[z] = yv;
		}
		else
		{
			zv = id(z);
			mp[y] = zv;
		}
	}

	RI(k);
	k = id(k);
	printf("%lld\n", a+ 1LL*(k-1)*d);
	return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<algorithm>
#include<cstdio>
#define INF (1 << 20)
using namespace std;

int V, E, d[20][20];
int main()
{
  cin >> V >> E;
  for(int i = 0; i < 20; i++)
    for(int j = 0; j < 20; j++)
      d[i][j] = (i != j) * INF;
  for(int i = 0; i < E; i++)
  {
    int a, b, c1, c2;
    scanf("%d,%d,%d,%d", &a, &b, &c1, &c2);
    a--; b--;
    d[a][b] = c1;
    d[b][a] = c2;
  }
  int x1, x2, y1, y2;
  scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
  x1--; x2--;

  for(int k = 0; k < V; k++)
    for(int i = 0; i < V; i++)
      for(int j = 0; j < V; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  cout << y1 - y2 - d[x1][x2] - d[x2][x1] << endl;  
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);++i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 
int dp[100000][3],nums[100000][3],m;

int dpp(int n,int k) {
	if (n>=m) return 0;
	if (k<3 and dp[n][k]>0) return dp[n][k];
	fop (i,0,3) {
		if (i!=k) dp[n][k]=max(dp[n][k],dpp(n+1,i)+nums[n][i]);
	}
	return dp[n][k];
}



int main () {
	cin >> m;
	fop (i,0,m) {
		cin >> nums[i][0] >> nums[i][1] >> nums[i][2];
		dp[i][0]=0;
		dp[i][1]=0;
		dp[i][2]=0;
	}
	cout << dpp(0,3) << endl;
}

Measured memory_bytes: 10368
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll a , b , n ;
	cin>> a >> b >> n ;
	ll ps=min(n,b-1);
	ll ans= (a*ps)/b -a*(ps/b);
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.readline
n = int(input()[:-1])
li = list(map(int,input().split()))
li.sort()
ans = 0
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    l = 0
    r = j
    while r-l > 0:
      p = (r+l)//2
      if li[p] + li[j] > li[i]:
        r = p
      else:
        l = p + 1
    ans += j - r
print(ans)


Measured memory_bytes: 42220
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(n):
    if b[i] < a[i]:
        c += b[i]
    else:
        d = min(a[i+1],b[i]-a[i])
        a[i+1] -= d
        c += a[i]+d
print(c)


Measured memory_bytes: 19116
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
dic = Counter(a)
su = sum(a)
q = inp()
for _ in range(q):
    b,c = inpl()
    su += dic[b] * (c-b)
    print(su)
    dic[c] += dic[b]
    dic[b] = 0


Measured memory_bytes: 24564
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, S);
  set<char> st;
  each(x, S) {
    st.insert(x);
  }
  rep(i, 'a', 'z' + 1) {
    if (st.count((char)i) == 0) {
      print((char)i);
      return;
    }
  }
  print("None");
}


Measured memory_bytes: 512
# ABC125D - Flipping Signs
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    mi = min(abs(i) for i in A)
    abs_sum = sum(abs(i) for i in A)
    neg = sum(i < 0 for i in A)
    if 0 in A or neg % 2 == 0:
        print(abs_sum)
    else:
        print(abs_sum - mi * 2)


if __name__ == "__main__":
    main()

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

int main() {
  int a, b, c;
  int k;
  cin >> a >> b >> c;
  cin >> k;

  while ( k-- > 0 ) {
    if ( a >= b ) {
      b *= 2;
    } else {
      c *= 2;
    }
  }

  string ans = (a < b && b < c) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<vector<pair<int, int>>>dat;

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

	int N;
	cin >> N;
	dat.resize(N);
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		for (int j = 0; j < A; j++) {
			int x, y;
			cin >> x >> y;
			x--;
			dat[i].pb({ x,y });
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << N); i++) {
		vector<int>temp(N,1);
		int cont = 0;
		for (int j = 0; j < N; j++)if (!((1LL << j)&i))temp[j] = 0;
		for (int j = 0; j < N; j++) {
			if ((1LL << j)&i) {
				fore(x, dat[j]) {
					if (temp[x.first] != x.second)cont = 1;
				}
			}
		}
		if (cont)continue;
		int tempans = 0;
		for (int j = 0; j < N; j++)tempans += temp[j];
		ans = max(tempans, ans);
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 256