akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;	cin>>K;
	cout<<A[K-1]<<endl;


    return 0;
}



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

f = 0
s = 0
index = 0
for i in range(N):
  a = int(input())
  if a > f:
    index = i
    s = f
    f = a
  elif a > s:
    s = a

for i in range(N):
  if i == index:
    print(s)
  else:
    print(f)



Measured memory_bytes: 4540
#include <stdio.h>
#include <string.h>

int main(){
  int n,ans;
  scanf("%d",&n);
  if(n%10==9){
    ans +=1;
  }
  if(n>=90){
    ans +=1;
  }
  if(ans>=1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
    ll h, w;
    cin >> h >> w;
    if(h%3 == 0 || w%3==0) {
        cout << 0 << endl;
        return 0;
    }
    else {
        ll ans = 100000000000;
        for(ll i=1;i<w;i++){
            //area1 = abs(h*i - (h/2)*(w-i));
            ll area1 = h*i;
            ll area2 = (h/2)*(w-i);
            ll area3 = (h-h/2)*(w-i);
            ll mi = min<ll>(area1, min<ll>(area2, area3));
            ll ma = max<ll>(area1, max<ll>(area2, area3));

            if(ans > abs<ll>(ma-mi)){
                ans = abs<ll>(ma-mi);
            }
        }
        swap(h, w);
        for(ll i=1;i<w;i++){
            //area1 = abs(h*i - (h/2)*(w-i));
            ll area1 = h*i;
            ll area2 = (h/2)*(w-i);
            ll area3 = (h-h/2)*(w-i);
            ll mi = min<ll>(area1, min<ll>(area2, area3));
            ll ma = max<ll>(area1, max<ll>(area2, area3));

            if(ans > abs<ll>(ma-mi)){
                ans = abs<ll>(ma-mi);
            }
        }
        ll mi = h/3;
        ll ma = h/3 + 1;
        if(ans > (ma*w-mi*w))
            ans = ma*w - mi * w;
        mi = w/3;
        ma = w/3 + 1;
        if(ans > (ma*h-mi*h))
            ans = ma*h - mi * h;
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 256
from copy import deepcopy
h, w, k = map(int, input().split())
C = [['']*w for _ in range(h)]
for i in range(h):
    C[i] = list(input())

ans = 0
for i in range(2**h-1):
    for j in range(2**w-1):
        _C = deepcopy(C)
        H = bin(i)[2:].zfill(h)
        W = bin(j)[2:].zfill(w)
        for _k,_h in enumerate(H):
            if _h == '1':
                for _w in range(w):
                    _C[_k][_w] = 'x'
        for _k,_w in enumerate(W):
            if _w == '1':
                for _h in range(h):
                    _C[_h][_k] = 'x'
        tmp = []
        _ = [tmp.extend(c) for c in _C]
        if tmp.count('#')==k:
            ans += 1

print(ans)

Measured memory_bytes: 9348
/* ex3_3
   Acro  */

#include <stdio.h> 
#include <math.h>
int main(void){
    int num,base,ans;
    scanf("%d %d",&num,&base);
    /* 底の変換公式 */
    ans = log(num)/log(base) + 1;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
h,w = map(int,input().split())

import numpy as np
inf = 10**3
C = np.full((10,10),inf,dtype = int)#C[from][to]
for x in range(10):
    for inp,y in zip(input().split(),range(10)):
        C[x][y] = inp
        
A = [list(map(int,input().split())) for _ in range(h)]

def warshallfloyd(lis):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                if i != j and k != i and k != j:
                    C[i][j] = min(C[i][j],C[i][k]+C[k][j])
warshallfloyd(C)
ans = 0
for a in A:
    for aa in a:
        if aa != -1:
            ans += C[aa][1]
print(ans)

Measured memory_bytes: 14308
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;
typedef vector<long long int> vll;

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

Measured memory_bytes: 256
N = gets.to_i
d = gets.chomp.split.map(&:to_i)

(N-1).downto(1) do |i|
     if d[i] >= d[i-1]
     	next
     elsif d[i-1] - d[i] == 1
     	d[i-1] = d[i-1]-1
     else
     	puts 'No'
     	exit
     end
end

puts 'Yes'

Measured memory_bytes: 9604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
const double PI=3.14159265358979323846;
const long long INF = 1LL << 60;

int main() {
	int N, K;
	cin >> N >> K;
	bitset<1000> bit;
	int a=0, b=0, c=0, x, y, z;
	rep(i, K) {
		std::cin >> x;
		rep(r, x) {
			std::cin >> y;
			bit.set(y, 1);
		}
	}
	rep(i, N) {
		if (!bit.test(i+1)) {
			a++;
		}
	}
	std::cout << a << '\n';
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll n;
    cin >> n;
    ll a[n+1];
    rep1(i,n){
        cin >> a[i];
    }
    double total = 0;
    for(int i = 2; i <= n;i++){
        if(a[i-1] <= a[i]) continue;
        ll plus = a[i-1] - a[i]; 
        total += plus;
        a[i] += plus;
    }
    printf("%.0lf\n", total);
    return 0;
}

Measured memory_bytes: 4724
#include <stdio.h>
int main(){

  int x,y,z,e,a,b,i,j,k;

  while(1){

    a=b=1000000;
    scanf("%d",&e);
    if(e != 0){

    for(i = 0; i*i*i <= e; i++){

      for(j = 0; j*j <= e-i*i*i; j++){

        k=e-i*i*i-j*j;
	b=i+j+k;
        if(b < a) a=b;

      }

    }

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

  } else {

    break;

  }

  }

  return 0;


}

Measured memory_bytes: 600
#include <iostream>
     
    using namespace std;
     
    int main(){
      int a,b,c;
      
      cin >> a >> b >> c;
     
      if (a==7){
          if (b==5 and c==5){
             cout << "YES" << endl;
          }
        else{
          cout << "NO" << endl;
        }
      }else if (a==5){
        if ((b==5 and c==7) or (b==7 and c==5)){
         cout << "YES" << endl;
          }
        else{
          cout << "NO" << endl;
        }
      }
    }

Measured memory_bytes: 3548
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s("Sunny"),
  c("Cloudy"),
  r("Rainy");
  string t;
  cin>>t;
  if(t==s)t=c;
  else if(t==c)t=r;
  else t=s;
  cout<<t<<endl;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int f(int x){
  int cnt=0;
  while(x%2==0){
    cnt++;
    x/=2;
  }
  return cnt;
}

int main(){
  int n;
  cin>>n;
  ll sum=0;
  
  rep(i,n){
    int y;
    cin>>y;
    sum+=f(y);
  }
  cout<<sum<<endl;
  
  return 0; 
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long cnt = n;
        for (int i = 1; i <= Math.sqrt(n); i++) {
            if (n % i != 0) {
                continue;
            }
            cnt = Math.min(cnt, i + (n / i) - 2);
        }
        System.out.println(cnt);
    }

}


Measured memory_bytes: 25300
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll tmp = n;
    ll waru = 0;
    while (tmp > 0) {
        waru += tmp % 10;
        tmp /= 10;
    }
    string ans = "Yes";
    if (n % waru != 0) ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

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

    int ans = 0;
    if(5 < a && a < 13){
        ans = b / 2;
    }else if(13 <= a){
        ans = b;
    }

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

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    val sa = scanner.next()
    val sb = scanner.next()
    val a = Integer.parseInt(sa)
    val b = Integer.parseInt(sb)
    var c = a + b
    var d = a * b
    var e = a - b
    if (c < d){
        c = d
    }
    if (c < e){
        println(e)
    } else {
        println(c)
    }
}

Measured memory_bytes: 31384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5;
const int maxn = 3e5 + 5;
ll mod = 1e9 + 7;

int n, m;
int edg[800][800];
int col[800], f[800][800];
vector<int> g[800];
pii sz[800];
int cnt;

int color(int u,int c)
{
	col[u] = c;
	for(int j = 0; j < g[u].size(); ++j)
	{
		int &v = g[u][j];
		if (col[v] == col[u]) return 0;
		else if (!col[v] && !color(v, c ^ 1)) return 0;
	}
	return 1;
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		edg[u][v] = edg[v][u] = 1;
	}

	for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++)
	{
		if (!edg[i][j])
		{
			g[i].push_back(j);
			g[j].push_back(i);
		}
	}

	for (int i = 1; i <= n; i++) if (!col[i])
	{
		++cnt;
		if (color(i,cnt<<1))
		{
			for (int j = 1; j <= n; j++)
			{
				if (col[j] == col[i]) ++sz[cnt].first;
				else if (col[j] == (col[i] ^ 1)) ++sz[cnt].second;
			}
		}
		else
		{
			printf("-1");
			return 0;
		}
	}

	f[0][0] = 1;
	for (int i = 1; i <= cnt; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (j >= sz[i].first) f[i][j] |= f[i - 1][j - sz[i].first];
			if (j >= sz[i].second) f[i][j] |= f[i - 1][j - sz[i].second];
		}
	}

	int ans = 700 * 700;
	for (int j = 1; j <= n; j++) if(f[cnt][j])
	{
		ans = min(ans, j*(j - 1) / 2 + (n - j)*(n - j - 1) / 2);
	}
	printf("%d", ans);
}

Measured memory_bytes: 5120
import numpy as np
n,m=map(int,input().split())
L1,L2=[],[]
for s in range(n):
  L1.append(list(input()))
for s in range(m):
  L2.append(list(input()))
L1,L2=np.array(L1),np.array(L2)
for s in range(n-m+1):
  for t in range(n-m+1):
#    print(L1[s:s+m,t:t+m],L2)
    if np.all(L1[s:s+m,t:t+m]==L2):
      print("Yes")
      exit()
print("No")

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

using ll = long long;

template <typename T>
class node {
public:
	node<T> *l, *r;
	T val, val2;
	node() : val2(0) {}
	node(T val_, node<T>* l_ = nullptr, node<T>* r_ = nullptr) : l(l_), r(r_), val(val_), val2(0) {}
	void init(T val_, node<T>* l_ = nullptr, node<T>* r_ = nullptr) {
		val = val_;
		l = l_;
		r = r_;
	}
};

template <typename T>
class DynamicLazySegmentTree {
	using func_t = function<T(T, T)>;
	const ll n;
	const T id;
	func_t merge;
	node<T> *root;
	vector<node<T>> pool;
	int it;
	ll size(ll n) {
		ll res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	node<T> *new_node() {
		pool[it].init(id);
		return &pool[it++];
	}
	T sub(ll l, ll r, node<T>* n, ll lb, ll ub) {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return n->val + n->val2 * (ub - lb);
		return n->val2 * (min(r, ub) - max(l, lb)) + merge(n->l != nullptr ? sub(l, r, n->l, lb, (lb + ub) / 2) : id, n->r != nullptr ? sub(l, r, n->r, (lb + ub) / 2, ub) : id);
	}
	void suc(ll l, ll r, node<T>* n, ll lb, ll ub, T val) {
		if (ub <= l || r <= lb) return;
		if (l <= lb && ub <= r) {
			n->val2 += val;
			return;
		}
		n->val += val * (min(r, ub) - max(l, lb));
		if (n->l == nullptr) {
			n->l = new_node();
		}
		if (n->r == nullptr) {
			n->r = new_node();
		}
		suc(l, r, n->l, lb, (lb + ub) / 2, val);
		suc(l, r, n->r, (lb + ub) / 2, ub, val);
	}
public:
	DynamicLazySegmentTree(ll n_, T id_ = 0, func_t merge_ = [](ll a, ll b) { return a + b; }, int max_ = 1000000) :
		n(size(n_)), id(id_), merge(merge_), pool(max_)
	{
		it = 0;
		root = new_node();
	}
	void add(ll l, ll r, T val) {
		suc(l, r + 1, root, 0, n, val);
	}
	T getSum(ll l, ll r) {
		return sub(l, r + 1, root, 0, n);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	DynamicLazySegmentTree<ll> dlst(10000000000000000ll);
	for (int i = 0, type, s, t, x; i < q; i++) {
		cin >> type;
		if (type) {
			cin >> s >> t;
			printf("%lld\n", dlst.getSum(s, t));
		}
		else {
			cin >> s >> t >> x;
			dlst.add(s, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 34360
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;

    for (int i = 1; i <= 1009; ++i) {
        if (int(i*0.08) == A && int(i*0.10) == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

const ll MAX = 1e6 + 10;
ll n, a[MAX];
bool use[MAX], pr[MAX];

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    cin >> n;
    zep(i, 0, n)cin >> a[i];
    
    bool p = true;
    ll uq = n;

    zep(i, 0, n){
        if(use[a[i]]){
            if(a[i] != 1)p = false;
            uq--;
        }
        use[a[i]] = true;
    }

    bool s = true;
    memset(pr, true, sizeof(pr));

    for(ll i = 2; i <= 1e6; i++){
        if(pr[i]){
            ll cnt = 0;

            for(ll j = 1; j * i <= 1e6; j++){
                if(j > 1)pr[i * j] = false;
                if(use[i * j])cnt++;
            }

            if(cnt > 1)p = false;
            if(cnt == uq)s = false;
        }
    }
    
    if(p){print("pairwise coprime") return 0;}
    if(s){print("setwise coprime") return 0;}
    print("not coprime")

    return 0;
}

Measured memory_bytes: 13264
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
#pragma endregion

int main()
{
  init_main();

  ll n, k;
  cin >> n >> k;
  ll a[200010];
  rep(i, n)
  {
    cin >> a[i];
    a[i]--;
  }

  int db[200010][70];
  rep(i, n) db[i][0] = a[i];
  rep(di, 62)
  {
    rep(i, n)
    {
      db[i][di + 1] = db[db[i][di]][di];
    }
  }
  int now = 0;
  rep(di, 62)
  {
    if (k & (1LL << di))
    {
      now = db[now][di];
    }
  }
  cout << now + 1 << endl;
  return 0;
}


Measured memory_bytes: 59936
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const ll MOD = 925627363746413; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
string S[N];
int n, c[26];
V<P<int, int>> SI;
map<ll, map<int, int>> m;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> S[i];
    SI.emplace_back(sz(S[i]), i);
  }
  sort(all(SI));
  ll ans = 0;
  for(auto p:SI){
    int l = p.fi;
    string s = S[p.se];
    memset(c, 0, sizeof c);
    FOR(i, 0, l) c[s[i]-'a']++;
    ll h = 0;
    FORR(i, l-1, 0){
      if(m.count(h)) for(auto&q:m[h]) ans += (!!c[q.fi])*q.se;
      c[s[i]-'a']--;
      if(i) h = (h*27+s[i]-'a'+1)%MOD;
    }
    m[h][s[0]-'a']++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 33460
#include <iostream>
#include <vector>

using namespace std;

int check(vector<int> &v,vector<vector<int> > &map){
	int num=0;
	
	for(int i=0;i<map.size();i++){
		if(map[i][3]){
			v[map[i][0]]=1,v[map[i][1]]=1,v[map[i][2]]=1;
		} else {
			if(v[map[i][0]]==1&&v[map[i][1]]==1) v[map[i][2]]=0;
			else if(v[map[i][0]]==1&&v[map[i][2]]==1) v[map[i][1]]=0;
			else if(v[map[i][1]]==1&&v[map[i][2]]==1) v[map[i][0]]=0;
		}
	}
	for(int i=0;i<v.size();i++){
		if(v[i]==2) num++;
	}
	return num;
}

int main(){
	while(1){
		int a,b,c;
		cin>>a>>b>>c;
		if(a==0&&b==0&&c==0){
			break;
		}
		vector<int> v;
		v.resize(a+b+c);
		for(int p=0;p<a+b+c;p++){
			v[p]=2;
		}
		
		int n;
		cin>>n;
		vector<vector<int> > map;
		for(int p=0;p<n;p++){
			int i,j,k,l;
			vector<int> row;
			cin>>i>>j>>k>>l;
			i--,j--,k--;
			row.push_back(i);
			row.push_back(j);
			row.push_back(k);
			row.push_back(l);
			if(l){
				v[i]=1,v[j]=1,v[k]=1;
			} else {
				if(v[i]==1&&v[j]==1) v[k]=0;
				else if(v[i]==1&&v[k]==1) v[j]=0;
				else if(v[j]==1&&v[k]==1) v[i]=0;
			}
			map.push_back(row);
		}
		int och=0,ch;
		ch=check(v,map);
		while(ch!=och){
			och=ch;
			ch=check(v,map);
		}

		for(int i=0;i<v.size();i++){
			cout<<v[i]<<endl;
		}
	}
	return 0;
}

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

using namespace std;

using ll = long long;

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cin.ignore();

    vector <ll> v;
    v.push_back(a * c);
    v.push_back(a * d);
    v.push_back(b * c);
    v.push_back(b * d);
    ll ans = *max_element(v.begin(), v.end());
    cout << ans << endl;

    return 0;
}

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





int main(){
	int n;
	while(cin >> n && n){
		bool no = false;
		int dag[128][128]={};
		string p;
		for(int i = 0 ; i < n ; i++){
			string s;
			cin >> s;
			if(i){
				int j = 0;
				while( j < min(p.size(),s.size()) && s[j] == p[j] ) j++;
				
				if( j != p.size() && j != s.size() ){
					dag[p[j]][s[j]] = true;
				}else{
					if( p.size() > s.size() )
						no = true;
				}
			}
			p = s;
		}
		if( no ){
			cout << "no" << endl;
			continue;
		}
		
		for(int i = 'a' ; i <= 'z' ; i++){
			for(int j = 'a' ; j <= 'z' ; j++){
				for(int k = 'a' ; k <= 'z' ; k++){
					dag[j][k] |= dag[j][i] & dag[i][k];
				}
			}
		}
		string yes = "yes";
		for(int i = 'a' ; i <= 'z' ; i++)
			if( dag[i][i] ) yes = "no";
		cout << yes << endl;
	}
}

Measured memory_bytes: 1276
import java.util.*;

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

Measured memory_bytes: 23892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        String s = sc.next();
        int n = s.length();
        boolean yes = isPalindrome(s) && isPalindrome(s.substring(0, ((n-1)/2))) && isPalindrome(s.substring((n+3)/2-1));
        out.println(yes?"Yes":"No");
        out.flush();
        out.close();
    }

    static boolean isPalindrome(String s) {
        int n = s.length();
        for (int i = 0; i < n / 2; i++)
            if (s.charAt(i) != s.charAt(n - i - 1)) return false;
        return true;

    }


    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        boolean ready() throws IOException {
            return br.ready();
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        int nextChar() throws IOException {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

    }
}


Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

int main(void){
	int n,a,i,cnt[123456],ans=0;
	fill(cnt,cnt+123456,0);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a;
		++cnt[a-1];
	}
	for(i=0; i<100000; ++i){
		if(cnt[i]){
			++ans;
		}
	}
	cout << ((ans%2)?ans:ans-1) << endl;
	return 0;
}


Measured memory_bytes: 768
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


N = int(readline())
B = list(map(int, readline().split()))


def main():
    ans = []
    while B:
        found = False
        for i in range(len(B), 0, -1):
            if i == B[i - 1]:
                ans.append(i)
                del B[i - 1]
                found = True
                break
        if not found:
            print(-1)
            return
    print(*reversed(ans), sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int n,k,a[22];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0; i<n; i++)
		scanf("%d",&a[i]);
	long long int res = 1000000000000LL;
	for(int mask=1; mask<(1<<n); mask++){
		if(__builtin_popcount(mask)<k)continue;
		long long int now = 0;
		int mx = 0;
		for(int i=0; i<n; i++){
			int x = a[i];
			if(mask&(1<<i)){
				if(x <= mx){
					now += mx+1-x;
					x = mx+1;
				}
			}
			mx = max(mx,x);
		}
		if(now < res)res=now;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n/10==9||n%10==9)
            printf("Yes\n");
        else
            printf("No\n");
    }
}

Measured memory_bytes: 256
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut ret = 0f64;
    for i in 0..n {
        let x: f64 = iter.next().unwrap().parse().unwrap();
        let u = iter.next().unwrap();
        if u == "JPY" {
            ret += x;
        } else {
            ret += x * 380000f64;
        }
    }
    println!("{}", ret);
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);

    string S;
    cin >> S;

    ll a = 0;
    ll b = 0;
    REP(i, S.length()){
        if(S[i] == '0') a++;
        if(S[i] == '1') b++;
    }
    cout << min(a, b) * 2 << endl;
    return 0;
}

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

public class Main {
	
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		int a = in.readInt();
		int b = in.readInt();
		int c = in.readInt();
		if(a == c ) System.out.println(b);
		else if(a == b) System.out.println(c);
		else System.out.println(a);
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 22740
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator<(const Puzzle &p)const{
    for(int i=0;i<N2;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
};
static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','i','d','r'};
bool isTarget(Puzzle p){
  for(int i=0;i<N2;i++)if(p.f[i]!=(i+1))return false;
  return true;
}
string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle,bool> V;
  Puzzle u,v;
  s.path="";
  Q.push(s);
  V[s]=true;

  while(!Q.empty()){
    u=Q.front();Q.pop();
    if(isTarget(u))return u.path;
    int sx=u.space/N;
    int sy=u.space%N;
    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if(tx<0||ty<0||tx>=N||ty>=N)continue;
      v=u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
	V[v]=true;
	v.path+=dir[r];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main(){
  Puzzle in;
  for(int i=0;i<N2;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  string ans=bfs(in);
  cout<<ans.size()<<endl;
  return 0;
}

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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)

const ll inf = 1e15;
const ll mod = 1e9+7;

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

int main() {
    ll N; cin >> N;
    vector<ll> a(N); rep(i, N) cin >> a[i];
    
    ll ans = inf;
    for(i, -100, 101) {
        ll sum = 0;
        rep(j, N) sum += abs(a[j] - i) * abs(a[j] - i);
        ans = min(ans, sum);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys

N = int(input())
A = list(map(int, input().split()))
ans = 1
if  0 in A:
    print('0')
    sys.exit()
for i in A:
    ans = ans*i
    if ans > 10**18:
        print('-1')
        sys.exit()
print(ans)

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

#define int long long

const int N = 1e5 + 5, MOD = 1e9 + 7;

int32_t main(){
	
	int a,b,c; cin>>a>>b>>c;
	if(a==b and b==c){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;

	return 0;
}
 
/*

*/


Measured memory_bytes: 3636
#include <stdio.h>

char str[8][9];

void bomb(int x, int y)
{
	int i;
	
	str[y][x] = '0';
	
	for (i = 0; i <= 3; i++){
		if (str[y][x + i] == '1' && y >= 0 && y <= 7 && x + i >= 0 && x + i <= 7){
			bomb(x + i, y);
		}
		if (str[y + i][x] == '1' && y + i >= 0 && y + i <= 7 && x >= 0 && x <= 7){
			bomb(x, y + i);
		}
		if (str[y][x - i] == '1' && y >= 0 && y <= 7 && x - i >= 0 && x - i <= 7){
			bomb(x - i, y);
		}
		if (str[y - i][x] == '1' && y - i >= 0 && y - i <= 7 && x >= 0 && x <= 7){
			bomb(x, y - i);
		}
	}
	
	return;
}
		

int main(void)
{
	int n, i, j, x, y;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		for (j = 0; j < 8; j++){
			scanf("%s", str[j]);
		}
		
		scanf("%d %d", &x, &y);
		
		bomb(x - 1, y - 1);
		
		printf("Data %d:\n", i + 1);
		for (j = 0; j < 8; j++){
			printf("%s\n", str[j]);
		}
	}
	
	return (0);
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100005;

int n, dp[N][2], mod = 1e9 + 7;
string s;

int solve(int ind, bool b){
    if(ind == n) return 1;
    int &ret = dp[ind][b];
    if(ret != -1) return ret;
    if(b) ret = 3LL * solve(ind + 1, 1) % mod;
    else{
        if(s[ind] == '0') ret = solve(ind + 1, 0);
        else ret = (2LL * solve(ind + 1, 0) + solve(ind + 1, 1)) % mod;
    }
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> s;
    n = s.size();
    cout << solve(0, 0) << endl;
}


Measured memory_bytes: 5968
macro_rules! input {
    ($x:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        $x = buf.trim().parse().unwrap();
    };

    ($x:expr, $($y:expr), +) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        input_iter!(buf.split_whitespace(), $x, $($y), +);
    };

    ($v:expr; $size:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        for v in buf.split_whitespace() {
            $v.push(v.parse().unwrap());
        }
    };

    ($v:expr; $h_size:expr, $w_size:expr) => {
        for _ in 0..$h_size {
            let mut part_vec = Vec::new();
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).ok();
            for v in buf.split_whitespace() {
                part_vec.push(v.parse().unwrap());
            }
            $v.push(part_vec);
        }
    };
}

#[allow(unused_macros)]
macro_rules! input_iter {
    ($iter:expr, $x:expr) => {
        $x = $iter.next().unwrap().parse().unwrap();
    };

    ($iter:expr, $x:expr, $($y:expr), +) => {
        let mut iter = $iter;
        $x = iter.next().unwrap().parse().unwrap();
        input_iter!(iter, $($y), *);
    };
}

fn main() {
    let mut a: i32;
    let mut b: i32;
    input!(a, b);
    let mut ans = 0;
    for i in 0..2 {
        if a > b {
            ans += a;
            a -= 1;
        } else {
            ans += b;
            b -= 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int k;
    cin>>k;

    string s;
    cin>>s;

   long long  int n=s.size();

   if(n<=k){
       cout<<s;
   }
  else if(n>k){
  for(int i=0;i<k;i++){
    cout<<s[i];
  }

    cout<<"...";


  }
  
}


Measured memory_bytes: 3636
W, H, N = map(int, raw_input().split())
b_w = [0, W]
b_h = [0, H]

for i in range(N):
    # ta_list.append(map(int, raw_input().split()))
    x, y, a = map(int, raw_input().split())
    if a == 1 and x > b_w[0]:
        b_w[0] = x
    elif a == 2 and x < b_w[1]:
        b_w[1] = x
    elif a == 3 and y > b_h[0]:
        b_h[0] = y
    elif a == 4 and y < b_h[1]:
        b_h[1] = y

print max(b_w[1]-b_w[0], 0) * max(b_h[1]-b_h[0], 0)


Measured memory_bytes: 2568
houses = [[[0 for r in range(10)]for f in range(3)]for b in range(4)]
num = int(input())
for i in range(num):
    b,f,r,v = [int(x) for x in input().split()]
    
    houses[b-1][f-1][r-1] += v


    
for i in range(len(houses)):
    if(i!=0):
        print("####################")
    for j in range(len(houses[i])):
        print(" ",end="")
        print(" ".join(map(str,houses[i][j])))
            



Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans=0;
    if(2*c<=a+b)
    {
        ans+=min(x,y)*2*c;
        int cc=min(x,y);
        x-=cc;
        y-=cc;
    }
    //dbg(x,y);
    if(2*c<=a) ans+=x*2*c;
    else ans+=x*a;
    if(2*c<=b) ans+=y*2*c;
    else ans+=y*b;
    print(ans);
}

Measured memory_bytes: 256
N = int(input())
w_ls = list()
for i in range(N):
  w_ls.append(input())
def main(w_ls):
  last = ""
  for i, w in enumerate(w_ls):
    if i > 0:
      if last != w[0]:
        return False
    last = w[-1]
  return True
if main(w_ls) and len(w_ls) == len(set(w_ls)):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import java.util.Scanner;


public class Main {

	Scanner sc;
	
	int ni(){
		return sc.nextInt();
	}
	
	void io(){
		sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=ni();
			n%=39;
			if(n==0)n+=39;
			System.out.println("3C"+String.format("%02d",n));
		}
		sc.close();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}
}

Measured memory_bytes: 17192
import sys
sys.setrecursionlimit(10**7)
from collections import defaultdict
import math
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def L(): return list(map(int, input().split()))
def TWO(M):
  L=[0]*M
  R=[0]*M
  for i in range(M):
    L[i],R[i] = II()
  return L, R

class UF(object):
  def __init__(self, n=1):
    self.par = [i for i in range(n)]
    self.rank = [0 for _ in range(n)]
    self.size = [1 for _ in range(n)]

  def find(self, x):
    """
    x が属するグループを探索
    """
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]

  def union(self, x, y):
    """
    x と y のグループを結合
    """
    x = self.find(x)
    y = self.find(y)
    if x != y:
      if self.rank[x] < self.rank[y]:
        x, y = y, x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1
      self.par[y] = x
      self.size[x] += self.size[y]

  def is_same(self, x, y):
    """
    x と y が同じグループか否か
    """
    return self.find(x) == self.find(y)

  def get_size(self, x):
    """
    x が属するグループの要素数
    """
    x = self.find(x)
    return self.size[x]

N = I()
x,y = TWO(N)
G = UF(N)

#座標値をkeyにして辞書を作成
X = defaultdict(list)
Y = defaultdict(list)
for i in range(N):
  X[x[i]].append(i)
  Y[y[i]].append(i)

#xが同じ値のものをunion
for v in X.values():
  if len(v)==1:
    continue
  for i in v[1:]:
    G.union(v[0],i)
  
#yが同じ値のものをunion   
for v in Y.values():
  if len(v)==1:
    continue
  for i in v[1:]:
    G.union(v[0],i)

#同じグループに存在するx,y値
X2 = defaultdict(set)
Y2 = defaultdict(set)
for i in range(N):
  root = G.find(i)
  X2[root].add(x[i])
  Y2[root].add(y[i])

#同じrootの格子点が全て追加される　rootごとにdisjoint
checked = [False]*N
ans = -N
for i in range(N):
  root = G.find(i)
  if checked[root] == True:
    continue
  checked[root] = True
  ans += len(X2[root])*len(Y2[root])
print(ans)

Measured memory_bytes: 120324
n = int(input())

def dfs(s, mx):
    """
    :param s: 今の文字
    :param mx: 今までで最大の文字
    :return:
    """
    if len(s) == n:
        print(s)
        return
    for c in range(ord('a'), ord(mx) + 1 + 1):
        t = s
        t += chr(c)
        mx = chr(max(ord(mx), c))
        dfs(t, mx)

dfs('', chr(ord('a')-1))

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
  string s;
  cin >> s;
  int ss[10000]={0};
  FOR(i,s.size()){
    ss[s[i]-'A']++;
  }
  int ans=0;
  FOR(i,1000){
    if(ss[i]==2){
      ans++;
    }
  }
  if(ans==2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
int L;
cin>>L;
int MAX=40000;
int edge[60][3];
int e[60];
e[0]=L;
int now=0,e_now=0;
while(e[now]/2>0){
    if(e[now]%2==1){
        edge[e_now][0]=now+1;
        edge[e_now][1]=MAX;
        edge[e_now][2]=e[now]-1;
        e_now++;
    }
    e[now+1]=e[now]/2;
    edge[e_now][0]=now+1;
    edge[e_now][1]=now+2;
    edge[e_now][2]=e[now+1];
    e_now++;
        edge[e_now][0]=now+1;
        edge[e_now][1]=now+2;
        edge[e_now][2]=0;
        e_now++;
    now++;
}

for(int i=0;i<e_now;i++){
    if(edge[i][1]==MAX){
        edge[i][1]=now+1;
    }
}
cout<<now+1<<" "<<e_now<<endl;
for(int i=0;i<e_now;i++){
    cout<<edge[i][0]<<" "<<edge[i][1]<<" "<<edge[i][2]<<" "<<endl;
}
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

		int[] cards = new int[N];
		for (int i = 0; i < N ; i++) {
			cards[i] = sc.nextInt();
		}
		Arrays.sort(cards);

		int AlicePoint = 0;
		int BobPoint = 0;
		for (int i = 0; i < N ; i++) {
			if (i % 2 == 0) {
				AlicePoint += cards[N-1-i];
			} else {
				BobPoint += cards[N-1-i];
			}
		}
		System.out.println(AlicePoint - BobPoint);
	}
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int a;
    cin >> a;
    if(a==1){
        cout <<"Hello World" << endl;
    }else{
        int x,y;
        cin >> x >> y;
        cout << x+y << endl;
    }
}

Measured memory_bytes: 256