akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int x; cin >> x;

  while (1){
    bool is_prime = true;
    for (int i=2;i<=(int)sqrt(x);i++){
      if (x%i==0) is_prime = false;
    }

    if (is_prime) break;
    x++;
  }

  cout << x << endl;
  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    long long int x;
    cin >> x;
    long long int ans = x / 11 * 2;
    if (x % 11 > 6)
        ans += 2;
    else if (x % 11 != 0)
        ans += 1;
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000

using namespace std;

#define MAXN 16
int d[MAXN][MAXN];
int dp[1<<MAXN][MAXN];

int main(){
  int n,e;cin>>n>>e;
  rep(i, MAXN)rep(j, MAXN)d[i][j]=-1;
  rep(i, e){
    int s,t,dist;cin>>s>>t>>dist;
    d[s][t]=dist;
  }

  rep(i, 1<<MAXN)rep(j, MAXN)dp[i][j]=INF;
  // rep(i, n)dp[(1<<n)-1][i]=0;
  dp[(1<<n)-1][0]=0;

  for(int s=(1<<n)-2; s>=0; s--){
    rep(from, n)rep(to, n){
      // 頂点toに未到達 かつ fromからtoに行くパスが存在している
      if( !(s>>to & 1) && d[from][to]>=0 ){
        dp[s][from] = min( dp[s][from], dp[s | 1<<to][to] + d[from][to] );
      }
    }

    // rep(i, 1<<n){rep(j, n)cout<<dp[i][j]<<' ';cout<<endl;}cout<<endl;

  }

  // int result = INF;
  // rep(i, n)result = min(result, dp[0][i]);

  cout<<(dp[0][0]==INF ? -1 :dp[0][0])<<endl;

//  rep(i, 1<<n){rep(j, n)cout<<dp[i][j]<<' ';cout<<endl;}cout<<endl;

  return 0;
}



Measured memory_bytes: 7200
#include <iostream>

using namespace std;

int main(){
    int n, x;
    int a = 1000001;
    int msum = 0;
    int m[1000];
    cin >> n >> x;
    for (int i = 0; i < n; i++){
        cin >> m[i];
        msum += m[i];
        if (a > m[i]){
            a = m[i];
        }
    }
    int ans = n + (x - msum) / a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const int N=202;
int ar[N];
vector<int> ans;
int main(){
	int n,i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	bool cac=true;
	while(cac){
		cac=false;
		for(i=1;i<=n;i++){
			ans.push_back(1);
			if(i<n&&ar[i]>ar[i+1]){
				ans.push_back(n-1);
				swap(ar[i],ar[i+1]);
				cac=true;
			}
		}
	}
	cout<<ans.size()<<'\n';
	for(i=0;i<ans.size();i++){
		cout<<ans[i]<<'\n';
	}
}

Measured memory_bytes: 764
//B - Snuke's Coloring 2: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int w, h, n, x, y , a, xI, xF, yI, yF, ans;

    cin >> w >> h >> n;
    xI = yI = 0;
    xF = w; yF = h;
    while(n--) {
        cin >> x >> y >> a;
        if(a == 1) xI = max(xI, x);
        else if(a == 2) xF = min(xF, x);
        else if(a == 3) yI = max(yI, y);
        else yF = min(yF, y);
    }
    if(xF <= xI or yF <= yI) ans = 0;
    else ans = (xF- xI) * (yF - yI);
    cout << ans << "\n";
}
    

Measured memory_bytes: 256
use proconio::{fastout, input};
use itertools::Itertools;

#[fastout]
fn main() {
    input! {
        n: usize,
        l: [u64; n],
    }

    if n < 3 {
        println!("{}", 0);
        return;
    }

    let mut count = 0;

    for i in 0..n-2 {
    for j in i+1..n-1 {
    for k in j+1..n {
        if l[i] == l[j] { continue; }
        if l[j] == l[k] { continue; }
        if l[k] == l[i] { continue; }
        let comb: Vec<u64> = vec![l[i], l[j], l[k]];
        if comb.iter().sum::<u64>() <= (*comb.iter().max().unwrap()) * 2 { continue; }
        count += 1;
    }

    }
        /* l[i..i+3].iter().permutations(3).for_each(|comb| {
            let mut st_comb = comb.copy();
            if *comb[0] + *comb[1] > *comb[2] {
                count += 1;
            }
        }) */
    }
    /* for _ in 1..=l.len() {
        for i in 0..l.len()-3 {
            if l[i] + l[i+1] > l[i+2] {
                count += 1;
            } else if l[i+1] + l[i+2] > l[i] {
                count += 1;
            } else if l[i+2] + l[i] > l[i+1] {
                count += 1;
            }
        }
 */
        /* let tmp = l[0];
        l.drain(..1);
        l.push(tmp); */
    

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


Measured memory_bytes: 2172
use proconio::input;

fn main() {
    input! {
        s: String,
        _t: String,
        a: usize,
        b: usize,
        u: String,
    }

    if u == s {
        println!("{} {}", a - 1, b);
    } else {
        println!("{} {}", a, b - 1);
    }
}


Measured memory_bytes: 2140
n,m = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x)
temp = []
# if n>=m:
#     print(0)
# else:    

for i in range(m-1):
    temp.append(x[i+1]-x[i])
temp = sorted(temp)
# print(temp)
if n == 1:
    print(sum(temp))
else:
    print(sum(temp[:-(n-1)]))

Measured memory_bytes: 13968
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = tuple(map(int, input().split()))
  b = tuple(map(int, input().split()))
  sa = [0] * (n+1)
  sb = [0] * (m+1)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()

Measured memory_bytes: 125252
#include <stdio.h>

int main(){
    int x, y, size;
    int arry[14][14] = {};
    int i, j, count = 0, max = -1;
    
    while(scanf("%d,%d,%d", &x, &y, &size) != EOF){
        if (size == 1){
            arry[x+2][y+2]++;
            arry[x+1][y+2]++;
            arry[x+3][y+2]++;
            arry[x+2][y+1]++;
            arry[x+2][y+3]++;
        }
        if (size == 2){
            for (i = 0; i < 3; i++){
                for (j = 0; j < 3; j++){
                    arry[x+1+i][y+1+j]++;
                }
            }
        }
        if (size == 3){
            for (i = 0; i < 3; i++){
                for (j = 0; j < 3; j++){
                    arry[x+1+i][y+1+j]++;
                }
            }
            arry[x][y+2]++;
            arry[x+4][y+2]++;
            arry[x+2][y]++;
            arry[x+2][y+4]++;
        }
    }
    for (i = 2; i < 12; i++){
        for (j = 2; j < 12; j++){
            if (arry[i][j] == 0) count++;
            if (max < arry[i][j]) max = arry[i][j];
        }
    }
    printf("%d\n%d\n", count, max);
    
    return 0;
}

Measured memory_bytes: 596
let call n =
  let rec check_num i =
    let x = i in
    if x mod 3 = 0 then
      begin
        print_string " ";
        print_int i;
      end
    else
      begin
        let rec include_3 x i =
          if x mod 10 = 3 then
            begin
              print_string " ";
              print_int i
            end
          else
            begin
              let x' = x /10 in
              if x' != 0 then include_3 x' i
            end
        in
        include_3 x i;
      end
  in
  let rec loop i =
    let i' = i + 1 in
    if i' <= n then
      begin
        check_num i';
        loop i'
      end
  in
  loop 1;
  print_string "\n"
;;
let () =
  Scanf.sscanf (read_line()) "%d" (fun n -> call n)
;;


Measured memory_bytes: 2440
#include <bits/stdc++.h>
using namespace std;
int two(int x){
	int count=0;
	while(x%2==0){
		count++;
		x/=2;
	}
	return count;
}
int main(){
    int n,a[1000],count;
    cin>>n;
    for(int i=0;i<n;i++){
		cin>>a[i];
		if(i==0)count=two(a[i]);
		count=min(count,two(a[i]));
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN


int main(void){
	int N,a[60000]={};
	scanf("%d",&N);
	reg(i,2,300){
		if(a[i]==0){
			reg(j,2,55555){
				if(i*j>55555)break;
				a[i*j]=1;
			}
		}
	}
	reg(i,2,55555){
		if(a[i]==0 && i%5==2){
			printf("%d",i);
			N--;
			if(N!=0){
				printf(" ");
			}else{
				printf("\n");
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main(){
    //std::stack<int> stack;
    long long  n,a,b;
    cin >> n >> a >> b;
    long long ans = 0;
    long long cy = n/(a+b);
    ans += cy*a;
    long long yo = n%(a+b);
    ans += min(yo, a);
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

vector<ll> ss;

void dfs(ll s, int cnt){
    if (cnt==10) return;
    cnt++;
    ss.push_back(s);
    ll sita = s%10;
    ll tmp = s*10;
    if (sita == 9){
        dfs(tmp+8, cnt);
        dfs(tmp+9, cnt);
    }else if (sita == 0){
        dfs(tmp, cnt);
        dfs(tmp+1, cnt);
    }else{
        dfs(tmp+sita, cnt);
        dfs(tmp+sita+1, cnt);
        dfs(tmp+sita-1, cnt);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    rep(i, 9){
        dfs(i+1, 0);
    }
    sort(ss.begin(), ss.end());
    ss.erase(unique(ss.begin(), ss.end()), ss.end());
    cout << ss[x-1] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll ;
int main()
{
    long long  n, w;
    cin >>n >> w;
    long long  dp [n+1][w+1];
    vector<pair<long long , long long >> v;
    v.push_back(make_pair(0,0));
    for (int i=0;i<n ;i++){
            ll a, b; cin >>a>> b;
        v.push_back(make_pair(a,b));
    }
    for (int i=0;i<=w ; i++){
        dp[0][i]=0;
    }
        for (int i=0;i<=n ; i++){
        dp[i][0]=0;
    }
    for (int i=1;i<=n ;i++){
        for (int j=1;j<=w;j++){
                if (j>=v[i].first)
            dp[i][j] = max (v[i].second+dp[i-1][j-v[i].first],dp[i-1][j]);
        else {
             dp[i][j] =dp[i-1][j] ;
        }
        }
    }
    cout << dp[n][w];

}


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

int main(){
  int x,y;
  cin >> x >> y;

  while(x != 0 || y != 0){
    if(x <= y){
      cout << x << " " << y << endl;
    }else{
      cout << y << " " << x << endl;
    }
      cin >> x >> y;
  }
  
  return 0;
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  double r[512], l[512];
  for(int i = 0; i < N; i++) cin >> r[i];
  double ans = 0.0;
  for(int i = 0; i < N; i++){
    l[i] = r[i];
    for(int j = 0; j < i; j++){
      l[i] = max(l[i], l[j] + sqrt((r[i]+r[j])*(r[i]+r[j]) - (r[i]-r[j])*(r[i]-r[j])));
    }
    ans = max(ans, l[i] + r[i]);
  }
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;

int main(){
    ll A,B,C;
    cin >> A >> B >>C;
    ll ans=0;
    if(C<=A){
        ans=B+C;
    }else{
        ans+=A;
        C-=A;
        
        if(B>=C){
            ans+=B+C;
        }else{
            ans+=B*2+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  string s;
  cin >> s;
  rep(i,s.size()-1){
    if(s[i] == ',') s[i] = ' ';
  }
  cout << s << endl;
} 






Measured memory_bytes: 256
#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>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, k;
    cin>>n>>k;
    int h[n];
    f(i, n) cin>>h[i];
    int dp[n];
    dp[0] = 0;
    rep(i, 1, n - 1){
        dp[i] = INT_MAX;
        for(int j = i - 1; j >= max(0, i - k); j--){
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout<<dp[n - 1];
    return 0;
}

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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    ll n, t, a;
    cin >> n >> t >> a;
    
    vector<ll> h(n);
    for(auto &e: h) cin >> e;

    ll mi, m = 1e18;
    for(ll i=0; i<n; i++) {
        if(m > abs(1000*t-6*h[i] - 1000*a))
            m = abs(1000*t-6*h[i] - 1000*a), mi = i;
    }
    cout << mi+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    int C_0=0,C_1=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='0'){C_0++;}
        if(S[i]=='1'){C_1++;}
    }
    cout<<2*min({C_0,C_1})<<endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#pragma warning (disable : 4996)

int c[100001];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x);
		if (x) c[x - 1]++;
		c[x]++;
		if (x < 100000) c[x + 1]++;
	}
	int ans = 0;
	for (int i = 0; i <= 100000; i++)
		ans = max(ans, c[i]);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 512
s = list(input())
s1,s2 = int(s[0]+s[1]),int(s[2]+s[3])
ans = 'NA'
if 1<=s1<=12:
    if 1<=s2<=12:
        ans = 'AMBIGUOUS'
    else:
        ans = 'MMYY'
elif 1<=s2<=12:
    ans = 'YYMM'
print(ans)

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

int main() {
  int k;
  cin >> k;
  
  queue<long long> lun;
  for(int i = 1; i < 10; ++i) lun.push(i);
  for(int i = 0; i < k - 1; ++i){
    long long l = lun.front();
    lun.pop();
    for(int j = -1; j < 2; ++j){
      long long add = (l % 10) + j;
      if(add > -1 && add < 10) lun.push(l * 10 + add);
    }
  }
  
  cout << lun.front() << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <utility>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < 26; i++) {
		char c = 'a' + i;
		int cnt = 0;
		int cnts = 0;
		P ans = P(LINF, 0);
		for (int j = 0; j < n; j++) {
			cnts = cnt;
			if (s[j] == c) cnt++;
			else cnt--;
			if (cnt > ans.first) {
				cout << ans.second + 1 << ' ' << j + 1 << endl;
				return 0;
			}
			if (ans.first >= cnts) {
				ans = P(cnts, j);
			}
		}
	}
	cout << -1 << ' ' << -1 << endl;
}

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

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007
#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"

void solve(){
    ll x;
    cin>>x;
    ll p=100;
    for(int t= 1;t<4000;t++){
        p += (p/100);
        if(p>=x){
            cout<<t<<"\n";
            return ;
        }
    }
}
int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	while(_--){
        solve();
    }
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

Measured memory_bytes: 3620
#include <cstdio>

int main(){
    int a, b;
    scanf("%d %d", &a,&b);   

    if (a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }  
    return 0;
}

Measured memory_bytes: 1008
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define cins(s,n) rep(i,n)cin>>s.at[i];
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}
 


int main()
{
    ll s,c;cin>>s>>c;
        ll ans=min(s*2,c)/2;
        c-=ans*2;
        if(c>3)ans+=c/4;cout<<ans;    
}

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

int n;
vector<string> ans(200);
vector<int> Q(100);
string rea;
void f(){
  cout<<"?";
  for(int i=0;i<n;i++){
    if(Q[i]>2*n)Q[i]-=2*n;
    cout<<" "<<Q[i];
  }
  cout<<endl;
  cin>>rea;
  if(rea=="-1")exit(0);
}

string g(string s){
  return s.substr(0,1);
}
string h(string s){
  string t=g(s);
  if(t=="R")return "B";
  return "R";
}

signed main(){
  cin>>n;
  for(int i=0;i<n;i++)Q[i]=i+1;
  f();
  string ho=rea;
  int l=1,r=n+1;
  while(r-l>1){
    int m=(r+l)>>1;
    for(int i=0;i<n;i++)Q[i]=m+i;
    f();
    if(rea==ho)l=m;
    else r=m;
  }
  ans[l]=g(ho);
  ans[l+n]=h(ho);
  for(int i=l+1;i<l+n;i++){
    for(int j=0;j<n-1;j++){
      Q[j]=l+n+j+1;
    }
    Q[n-1]=i;
    f();
    ans[i]=g(rea);
  }
  for(int i=l+n+1;i<l+2*n;i++){
    for(int j=0;j<n-1;j++){
      Q[j]=l+1+j;
    }
    Q[n-1]=i;
    f();
    int t=i;
    if(t>2*n)t-=2*n;
    ans[t]=g(rea);
  }
  cout<<"! ";
  for(int i=1;i<=2*n;i++)cout<<ans[i];cout<<endl;
}


Measured memory_bytes: 724
import java.util.*;
public class Main{
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      long l = sc.nextLong();
      long r = sc.nextLong();
      long min = 10000;
      if(r-l >= 2019){
        System.out.println(0);
        return;
      }
      else{
      	for(long i = l;i <= r-1;i++){
        	for(long j = i+1;j <= r;j++){
            	min = Math.min(min,(i*j)%2019);
            }
        }
      }
      System.out.println(min);
	}
} 


Measured memory_bytes: 21972
// Rustで競技プログラミングの入力をスッキリ記述するマクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve(n: u16) {
    println!(
        "{}",
        match n {
            n if n <= 111 => 111,
            n if n <= 222 => 222,
            n if n <= 333 => 333,
            n if n <= 444 => 444,
            n if n <= 555 => 555,
            n if n <= 666 => 666,
            n if n <= 777 => 777,
            n if n <= 888 => 888,
            _ => 999,
        }
    );
}

fn main() {
    input! {
        n: u16
    };
    solve(n);
}


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

#define rep(i,n) for(int i=0;(i)<(n);++(i))

using namespace std;
using ll = long long;
const ll mod = 1000000007LL;

ll power(ll a,ll n){
	if(n < 0) return 0;
	ll b=1LL;
	while(n){
		if(n&1) b= b*a % mod;
		a = a*a % mod;
		n >>= 1;
	}
	return b;
}

template <class T> bool chmin(T &a,const T &b){return (b<a)?(a=b,1):0;}

const int limit = 100010;
ll fact[limit];
ll ifact[limit];

inline ll Fact(ll n){
	if(n < 0) return 0;
	return fact[n];
}

inline ll Comb(ll n,ll k){
	if(n <0 or k<0 or n-k <0) return 0LL;
	return fact[n] * ifact[k] % mod * ifact[n-k] % mod;
}

int main() {
	fact[0]=1LL;
	rep(i,limit-1) fact[i+1] = 1LL * (i+1) * fact[i] % mod;
	ifact[limit-1] = power(fact[limit-1],mod-2);
	for(int i = limit -2; i >=0 ; --i) ifact[i] = 1LL * (i+1) * ifact[i+1] % mod;

	int n;
	while(cin >> n,n){
		vector<int> a(n),ra(n,-1),used(n,0),num;

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

		rep(i,n){
			if(i==a[a[i]]) continue;
			ra[a[i]]=i;
		}

		rep(i,n){
			const int j = a[i];
			if(i > j or i != a[j]) continue;

			used[i]=used[j]=true;
			int cnt = 2;

			{
				int cur = ra[i];
				while(cur!=-1){
					used[cur] = true;
					cnt++;
					cur = ra[cur];
				}
			}

			{
				int cur = ra[j];
				while(cur!=-1){
					used[cur] = true;
					cnt++;
					cur = ra[cur];
				}
			}

			num.push_back(cnt);
		}

		ll ans = 0LL,two = 0LL;
		
		bool ok = true;
		rep(i,n) if(used[i]==false) ok =false;
		for(auto &elem:num) if(elem==2) two++;
		
		const ll k = num.size();
		const ll three = k - two;

		if(k == 0 or ok == false){
			cout << 0LL << endl;
			continue;
		}

		//cerr << three << " " << two << endl;

		if(three == 0){
			ll cur = ((k+2)/2);
			cur = cur * Fact(k) % mod;
			ans = (ans + cur) % mod;
		}

		if(three >= 1){
			rep(i,k+1){
				ll cur = 2LL * ((i+2)/2LL);
				cur = cur * Comb(two,i) % mod;
				cur = cur * Fact(i) % mod;
				cur = cur * Comb(three,1) % mod;
				cur = cur * Fact(two-i+three-1) % mod;
				ans = (ans + cur) % mod;
			}
		}

		
		if(three >= 2){
			rep(i,k+1){
				ll cur = 2LL * ((i+2)/2LL);
				cur = cur * Comb(two,i) % mod;
				cur = cur * Fact(i) % mod;
				cur = cur * Comb(three,2) % mod;
				cur = cur * Fact(two-i+three-2) % mod;
				cur = cur * (two -i + three -2 + 1) % mod;
				ans = (ans + cur) % mod;
			}
		}

		ans = 1LL * ans * power(2,k) % mod;
		cout << ans << endl; 

	}			
	
	return 0;
}

Measured memory_bytes: 6036
x, n = list(map(int, input().split()))
if n == 0 :
  print(x)
  exit()
p = list(map(int, input().split()))

for i in range(100) :
  if not x-i in p :
    print(x-i)
    exit()
  elif not x+i in p :
    print(x+i)
    exit()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename S, typename T>
void xmin(S&a, T const&b){if(b<a) a=b;}
template<typename S, typename T>
void xmax(S&a, T const&b){if(b>a) a=b;}


vector<int> a;

ll get_cnt(ll n){
    for(auto &e:a){
        n-=n%e;
    }
    return n;
}


ll search(bool up){
    ll l = 0, r=4e18;
    while(l+1<r){
        ll m = l+(r-l)/2;
        ll cnt = get_cnt(m);
        if(cnt<2){
            l=m;
        } else if(cnt>2){
            r=m;
        } else {
            if(up){
                l = m;
            } else {
                r = m;
            }
        }

    }
    return l;
}

signed main()
{
    #ifdef LOCAL_RUN
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int TTT; cin >> TTT; while(TTT--){
    #else
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    #endif // LOCAL_RUN

    int n;
    cin >> n;
    a.resize(n);
    for(auto &e:a) cin >> e;

    ll x = search(false), y = search(true);
    ++x;
    if(get_cnt(x)!=2){
        cout << "-1\n";
    } else {
        cout << x << " " << y << "\n";
    }



    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
    return 0;
}


Measured memory_bytes: 640
n=int(input())
s=input()
cnt = 0
for i in range(10):
  if str(i) not in s[:-2]: continue
  i1 = s[:-2].index(str(i))
  for j in range(10):
    if str(j) not in s[i1+1:-1]: continue
    j1 = s[i1+1:-1].index(str(j))
    for k in range(10):
      if str(k) not in s[i1+1+j1+1:]: continue
      k1 = s[i1+1+j1+1:].index(str(k))
      #print(s[i1],s[i1+j1+1],s[i1+j1+k1+2])
      cnt += 1
print(cnt)
      

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    int x=0;
    for(int i=0;i<s.size();i++)
        if(s[i]!=t[i])x++;
    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	string s;
	cin >> s;
	ll k;
	cin >> k;
	int id = 0;
	for(;id < s.size() && s[id] == s[0];)
		id ++;
	int l = id;
	id = s.size() - 1;
	for(;id >= 0 && s[id] == s.back();)
		id --;
	int r = id;
	if(r < l)
	{
		ll e = s.size();
		e *= k;
		cout << e / 2 << '\n';
		return 0;
	}
	if(s[0] != s.back())
	{
		l = 0; r = s.size() - 1;
	}
	ll cnt = 1, mid = 0;
	for(int i = l + 1; i <= r; i ++)
	{
		if(s[i] == s[i - 1])
			cnt ++;
		else
		{
			mid += cnt / 2;
			cnt = 1;
		}
	}
	mid += cnt / 2;
	ll foo = l, hoo = s.size() - r - 1;
	if(s[0] != s.back())
	{
		return cout << k * mid ,0;
	}
	ll ans = mid * k;
	ans += foo / 2;
	ans += hoo / 2;
	ans += ((foo + hoo)/2)*(k-1);
	cout << ans;


	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

int main()
{
    int a, b, c; cin >> a >> b >> c;
    int diff;
    if ( a == b && a != c)
    {
        cout << c;
        return 0;
    }
    else if ( a == c && a != b)
    {
        cout << b;
        return 0;
    }
    else
    {
     cout << a;
    }
}


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

int main()
{
    int n,k,ans;
    scanf("%d%d",&n,&k);
    if(n<10)
        ans=k+(10-n)*100;
    else
        ans=k;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 50
int Mystrcmp(char *a,char *b,int n)
{
    for(int i=0;b[i];i++)
        if(a[n+i]!='?'&&a[n+i]!=b[i])
            return 0;
    return 1;
}
int main()
{
    char a[LEN],b[LEN];
    gets(a);
    gets(b);
    int lenb = strlen(b);
    int lena = strlen(a);
    int i;
    for(i=lena-lenb;i>=0;i--)
        if(Mystrcmp(a,b,i))
            break;
    if(i>=0)
    {
        for(int j = 0;a[j];j++)
            if(a[j]=='?')
                a[j] = 'a';
        for(int j = 0;b[j];j++)
            a[i++] = b[j];
        puts(a);
    }
    else printf("UNRESTORABLE\n");
}


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

int main() {
	int n;
	string s;
	cin>>n>>s;
	if (n%2 == 0 && s.substr(0, n/2) == s.substr(n/2))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int bubblesort(int A[],int N)
{
  int i,j,v;
  int count = 0;
  for(i = 0; i < N - 1; i++)
  {
    for(j = N - 1; j > i - 1; j--)
    {
      if( *(A + j) < *(A + j - 1) )
      {
        v = 0;
      	v = *(A + j);
        *(A + j) = *(A + j - 1);
        *(A + j - 1) = v;
        count++;
      }
    }
  }
  return count;
}

int main()
{
  int N,count,i;
  int A[100];
  
  scanf("%d",&N);
  for(i = 0; i < N; i++)
  {
    scanf("%d",A + i);
  }
  
  count = bubblesort(A,N);
  
  for(i = 0; i < N; i++)
  {
    if(i > 0)
  	{
  	   printf(" ");
  	}
  	printf("%d", *(A + i));
  }
	printf("\n");
	printf("%d\n",count);
	
	return 0;
}

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


using namespace std;

int dfs_search(int s, vector<vector<int>> &edges, vector<int> &dp){
    if (dp[s] != -1) return dp[s];
    dp[s] = 0;
    for(auto v: edges[s]){
        dp[s] = max(dp[s], 1 + dfs_search(v, edges, dp));
    }
    return dp[s];
}


int main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);
   int N, M;
   cin >> N >> M;
   vector<vector<int>> edges(N+1);
   vector<int> dp(N+1, -1);
   for (int i = 0; i < M; ++i){
       int x, y;
       cin >> x >> y;
       edges[x].push_back(y);
       edges[0].push_back(x);
       edges[0].push_back(y);
   }
   sort(edges[0].begin(), edges[0].end());
   edges[0].erase(unique(edges[0].begin(), edges[0].end()), edges[0].end());
   cout << dfs_search(0, edges, dp) - 1<< "\n";
}



Measured memory_bytes: 9588
package main

import (
	"fmt"
	"math"
	"strconv"
)

var a, b int

func main() {
	fmt.Scanf("%d %d", &a, &b)

	ab, _ := strconv.Atoi(strconv.Itoa(a) + strconv.Itoa(b))

	if int(math.Sqrt(float64(ab)))*int(math.Sqrt(float64(ab))) == ab {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
N = int(input())

def dfs(x):
    if len(x) == N:
        s = "".join(chr(v + ord("a")) for v in x)
        print(s)
        return

    val = max(x)
    for i in range(val + 2):
        x.append(i)
        dfs(x)
        x.pop()

dfs([0])


Measured memory_bytes: 56920
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    string s;
    cin >> s;
    int n = s.size();
    char t, z = 'Z';
    for (int i = 0; i < n; i++) {
        t = (char)(s[i] - 3);
        if (t < 'A') cout << (char)(t + 26);
        else cout << t;
    }
    cout << endl;
}


Measured memory_bytes: 3224
import java.util.Scanner;

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

		int d = sc.nextInt();
		int[] c = new int[26];
		for (int i = 0; i < 26; i++) {
			c[i] = Integer.parseInt(sc.next());
		}

		int[][] s = new int[d][26];
		for (int i = 0; i < d; i++) {
			for (int j = 0; j < 26; j++) {
				s[i][j] = Integer.parseInt(sc.next());
			}
		}

		int[] ans = new int[d];
		int[] e = new int[26];
		for (int i = 0; i < 26; i++) {
			e[i]++;
		}

		for (int i = 0; i < d; i++) {
			int max = 0;
			for (int j = 0; j < 26; j++) {
				for (int k = 0; k < 26; k++) {
					if (max < s[i][j] - c[k] * e[k]) {
						max = s[i][j] - c[k] * e[k];
						ans[i] = j;
					}
				}
			}
			e[ans[i]] = 1;
			for (int j = 0; j < 26; j++) {
				if (ans[i] != j)
					e[j]++;
			}
		}

		for (int i = 0; i < d; i++) {
			System.out.println(ans[i] + 1);
		}
	}

}


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

void merge(vector<int> left, vector<int> right, vector<int> &merged_a, int &count) {
    int i = 0, j = 0;
    while (i < left.size() || j < right.size()) {
        if ((i < left.size() && left[i] < right[j]) || j == right.size()) {
            merged_a[i+j] = left[i];
            i++;
            count++;
        } else {
            merged_a[i+j] = right[j];
            j++;
            count++;
        }
    }
}

void merge_sort(vector<int> &a, int &count) {
    if (a.size() > 1) {
        int left_size = a.size() / 2;
        int right_size = a.size() - left_size;
        vector<int> left(left_size);
        vector<int> right(right_size);
        rep(i, left_size) {
            left[i] = a[i];
        }
        rep(i, right_size) {
            right[i] = a[left_size + i];
        }
        merge_sort(left, count);
        merge_sort(right, count);
        merge(left, right, a, count);
    }
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    rep(i, n) {
        scanf("%d", &a[i]);
    
    }
    int count = 0;
    merge_sort(a, count);
    rep(i, n) {
        printf("%d", a[i]);
        if (i < n - 1) printf(" ");
        else printf("\n");
    }
    printf("%d\n", count);
}


Measured memory_bytes: 8868
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;
#define fr first
#define sc second
#define INF ( 1 << 30 )
int m, n, k, d;
int min_cost[110][1 << 6];
vector< int > cal;
typedef pair < int , int > Pi;
typedef pair < int , Pi > Pii;
struct edge{
  int to, cost;
  edge(){}
  edge( int to, int cost): to(to), cost(cost){};
};
vector < edge > info[110];
int java(string& s){
  if(s[0] == 'H') return 0; //MyHome
  if(s[0] == 'D') return 1; //市役所
  if(s[0] == 'C') return atoi(s.substr(1).c_str()) + 1; //ケーキ屋さん
  if(s[0] == 'L') return atoi(s.substr(1).c_str()) + m + 1; //ランドマーク
}
int bfs(){
  int ret = INF;
  // コスト , 今の場所 , 逝った
  fill_n(*min_cost,110*(1<<6),INF);
  priority_queue< Pii , vector< Pii > , greater< Pii > > que;
  que.push(Pii( 0, Pi( 0, (1<<m) - 1)));
  min_cost[0][(1<<m)-1] = true;
  while(!que.empty()){
    Pii p = que.top();
    que.pop();
    if(p.sc.fr == 1){
      ret = min( ret, p.fr);
    }
    if(min_cost[p.sc.fr][p.sc.sc] < p.fr ) continue;
    for(int i = 0 ; i < info[p.sc.fr].size() ; i++ ){
      edge e = info[p.sc.fr][i];
      int cost = p.fr + e.cost * k, bit = p.sc.sc;
      if( e.to >= 2 && e.to < 2 + m ){
        if((bit >> (e.to-2)) & 1){
          cost -= cal[e.to-2];
          bit &= ~(1 << (e.to-2));
          if( cost < min_cost[e.to][bit] ){
            que.push(Pii( cost,Pi( e.to, bit)));
            min_cost[e.to][bit] = cost;
          }
        }
      }else{
        if( cost < min_cost[e.to][bit]){
          min_cost[e.to][bit] = cost;
          que.push(Pii( cost, Pi( e.to, bit)));
        }
      }
    }
  }
  return ret;
}
int main(){
  while(cin >> m >> n >> k >> d , m){
    cal.resize(m);
    for(int i = 0 ; i < m ; i++ ){
      cin >> cal[i];
    }
    for(int i = 0 ; i < d ; i++ ){
      string s1, s2;
      int cost;
      cin >> s1 >> s2 >> cost;
      info[java(s1)].push_back(edge( java(s2), cost));
      info[java(s2)].push_back(edge( java(s1), cost));
    }
    cout << bfs() << endl;
    for(int i = 0 ; i < 110 ; i++ ) info[i].clear();
  }
}

Measured memory_bytes: 1356
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
    bool ans = true;
    char S[27];
    cin >> S;
    int len = strlen(S);
    sort(S, S + len);
    for (int i = 1; i < len; i++) if (S[i] == S[i-1]) ans = false;
    cout << (ans ? "yes" : "no") << endl;
}

Measured memory_bytes: 256
/* created by <xrssa> */
#pragma GCC optimize("O3","unroll-loops","omit-frame-pointer","inline","fast-math","no-stack-protector") //Optimization flags
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
// #include <x86intrin.h> //AVX/SSE Extensions

#include <bits/stdc++.h>
using namespace std;

#define f(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define fa(elem, arr) for(auto &elem:arr)
#define gcd(x,y)         __gcd(x,y)
#define lcm(x,y)        (x/gcd(x,y))*y
#define mod             1000000007
#define all(a)           a.begin(),a.end()
#define INF 1e9 // # define INF 0x3f3f3f3f 
#define EPS 1e-6

void solve(){
    int n;cin>>n;int arr[n];f(i,n) cin>>arr[i];
    vector<int> dp(n,INF);
    dp[0]=0;
    f(i,n){
        for(int j: {i+1,i+2}){
            if (j<n){
                dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
            }
        }
    }
    cout << dp[n-1] << "\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    // for multiple test case use
    // int t;cin>>t;while(t--) solve();
    return 0;
}


Measured memory_bytes: 1024
def resolve():
    a, b, m = map(int,input().split())
    R = list(map(int, input().split()))
    M = list(map(int, input().split()))
    X = [list(map(int, input().split())) for i in range(m)]

    ans = min(R) + min(M)
    for i in range(m):
        ans = min(ans, R[X[i][0]-1]+M[X[i][1]-1]-X[i][2])
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38364
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var dic = new Dictionary<string,int>();
		for(var i=0;i<N;i++){
			string s = Console.ReadLine();
			var list = new List<string>();
			for(var j=0;j<s.Length;j++){
				list.Add(s.Substring(j,1));
			}
			list.Sort();
          	string s2 = "";
          	for(var j=0;j<s.Length;j++){
              s2 += list[j];
            }
			if(dic.ContainsKey(s2)){
				dic[s2]++;
			} else {
				dic[s2]=1;
			}
		}
		long ans = 0;
		foreach(var i in dic.Values){
			ans += (long)i*(i-1)/2;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 32256
#include <stdio.h>
#include <math.h>

#define MAX 1000000

void merge(int[],int,int,int);
void mergeSort(int[],int,int);

int count = 0;
int n;
int L[MAX/2],R[MAX/2];

int main(){
    int A[MAX];

    scanf("%d",&n);

    for(int i = 0;i < n;i++){
        scanf("%d",&A[i]);
    }


    mergeSort(A,0,n);

    for(int i = 0;i < n;i++){
        printf("%d",A[i]);
        if(i < n-1)printf(" ");
    }
    printf("\n");

    printf("%d\n",count);

    return 0;
}

void merge(int A[MAX],int left,int mid,int right){
    int i,j;
    int n1,n2;

    n1 = mid - left;
    n2 = right - mid;

    for(i = 0;i < n1;i++)L[i] = A[left + i];
    for(i = 0;i < n2;i++)R[i] = A[mid + i];
    L[n1] = 1e9+1;
    R[n2] = 1e9+1;

    i = 0;
    j = 0;

    for(int k = left;k < right;k++){
        count++;
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int A[MAX],int left,int right){
    int mid;

    if(left + 1 < right){
        mid = (left + right) / 2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}


Measured memory_bytes: 5608
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=2*1e6+5;
#define INF (1<<30)
int H,a[maxn];

void maxHeapify(int i)
{
    int l,r,tmp;
    l=i*2,r=l+1;
    if(l<=H&&a[l]>a[i]) tmp=l;
    else tmp=i;
    if(r<=H&&a[r]>a[tmp]) tmp=r;
    if(tmp!=i){
        swap(a[tmp],a[i]);
        maxHeapify(tmp);
    }
}

int extract()
{
    int maxv;
    if(H<1) return -INF;
    maxv=a[1];
    a[1]=a[H--];
    maxHeapify(1);
    return maxv;
}
void increaseKey(int i,int key)
{
    if(key<a[i]) return;
    a[i]=key;
    while(i>1&&a[i/2]<a[i]){
        swap(a[i],a[i/2]);
        i=i/2;
    }
}

void insert(int key)
{
    H++;
    a[H]=-INF;
    increaseKey(H,key);
}

int main()
{
    H=0;
    int key;
    char com[10];
    while(1){
        scanf("%s",com);
        if(com[0]=='e'&&com[1]=='n') break;
        if(com[0]=='i'){
            cin>>key;
            insert(key);
        }else{
            cout<<extract()<<endl;
        }
    }
    return 0;
}

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

using namespace std;
#define Pi acos(-1)
#define _terminated return 0
#define endl "\n"
#define yes cout << "yes" << endl 
#define no cout << "no" << endl 
#define booster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<long> > v2l;

const int mod = 1e+5;
const int mx = 2e+5;
const ll inf = 1e18;

using namespace std;

void solvio(void){
     int a,b,c;
     cin >> a >> b >> c;
     if((a==5 && b==7 && c==5)||(a==5 && b==5 && c==7)||(a==7 && b==5 && c==5))
     cout << "YES" << endl;
     else cout << "NO" << endl; 
}


int main(){ 
    booster;
    solvio(); 
    _terminated; 
}

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

using namespace std;

int main()
{
	set<int> s;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		s.insert(t);
	}
	scanf("%d",&n);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		ans+=s.count(t);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3220
import java.math.*;
import java.util.*;
import static java.lang.System.*;

public class Main {
	//初期フィールド・メソッド---------------------------------------------
	static Scanner sc = new Scanner(System.in);
	static int min(int... ar) {Arrays.sort(ar); return ar[0];}
	static int max(int... ar) {Arrays.sort(ar); return ar[ar.length-1];}
	//------------------------------------------------------------


	//フィールド追加場所-----------------------------------------------
	//------------------------------------------------------------


	//メソッド追加場所------------------------------------------------
	//------------------------------------------------------------


	//mainメソッド---------------------------------------------------
	public static void main(String[] args) {
		while (true) {
			int n = sc.nextInt();
			if (n == -1) break;
			
			int cost = 1150;
			if (n > 10) {
				cost += Math.min( 1250 , (n-10)*125 );
			}
			if (n > 20) {
				cost += Math.min( 1400 , (n-20)*140 );
			}
			if (n > 30) {
				cost += (n-30)*160;
			}
			
			out.println(4280-cost);
		}
	}
	//------------------------------------------------------------
}


Measured memory_bytes: 26144