akhauriyash/Code-Regression huggingface dataset:
from collections import deque
N, M = map(int, raw_input().split(' '))
route = [map(int, raw_input().split(' ')) for _ in xrange(M)]

A = {}
for a, b in route:
    A.setdefault(a, []).append(b)
    A.setdefault(b, []).append(a)


def bfs(A, start, end):
    visited = set()
    queue = deque()
    visited.add(start)
    queue.append((start, 0))
    while len(queue) > 0:
        a, d = queue.popleft()
        if d >= 2:
            break
        for b in A[a]:
            if b == end:
                return True
            if b not in visited:
                visited.add(b)
                queue.append((b, d+1))
    return False


if bfs(A, 1, N):
    print 'POSSIBLE'
else:
    print 'IMPOSSIBLE'


Measured memory_bytes: 84008
w,h,n = map(int,input().split())
area = h*w
a1=0
a2=w
a3=0
a4=h
for i in range(n):
  x,y,a = map(int,input().split())
  if a ==1:
    a1 = max(a1,x)
  elif a ==2:
    a2 = min(a2,x)
  elif a ==3:
    a3 = max(a3,y)
  elif a==4:
    a4 = min(a4,y)
#print(a1,a2,a3,a4)
if a1>=a2 or a3>=a4:
  print(0)
else:
  area -= a1*h + (w-a2)*h + a3*w + (h-a4)*w 
 # print(area)
  print(area+(a1*(a3+(h-a4))+(w-a2)*(a3+(h-a4))))

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

long gcd(long a, long b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

long lcm(long C, long D) {
    return C * D / gcd(C, D);
}

long count(long A, long B, long X) {
    long min_Xx = 0;
    if (A % X == 0) {
        min_Xx = A;
    } else {
        min_Xx = A + X - (A % X);
    }

    if (min_Xx > B) {
        return 0;
    } else {
        return (B - min_Xx) / X + 1;
    }
}

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

    long A, B, C, D;
    cin >> A >> B >> C >> D;

    long lcm_CD = lcm(C, D);

    /*
    cout << B - A + 1 << '\n';
    cout << count(A, B, C) << '\n';
    cout << count(A, B, D) << '\n';
    cout << count(A, B, lcm_CD) << "\n";*/

    cout << B - A + 1 - count(A, B, C) - count(A, B, D) + count(A, B, lcm_CD) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
using LL = long long;
const int N = 200005;

LL a[N];
LL sz[N];

int main()
{
	LL n;
	cin >> n;

	LL f;
	for (int i = 2; i <= n; ++i)
	{
		cin >> f;
		a[i] = f;//i的父亲
		++sz[f];
	}

	for (int i = 1; i <= n; ++i)
	{
		cout << sz[i] << endl;
	}

	

	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
			b[i]=a[i];
		}
		scan.close();
		Arrays.sort(b);
		for(int i=0;i<n;i++) {
			System.out.println((a[i]!=b[n-1])?b[n-1]:b[n-2]);
		}
	}
}

Measured memory_bytes: 92352
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr(j,i,n) for(int i=j;i<n;++i)
#define frr(j,i,n) for(int i=j;i<=n;++i)
using namespace std;

int main()
{
	ll k;
	cin>>k;
	if(k%2 == 0)
		cout<<-1<<"\n";
	else
	{
		ll x=7;
		ll cnt=0;
		int f=0;
		while(cnt<=1000000)
		{
			cnt++;
			if(x%k == 0)
			{
				f=1;
				break;
			}
			x=(x*10+7)%k;
		}
		if(f==1)
			cout<<cnt<<"\n";
		else
			cout<<-1<<"\n";
	}
}



Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string str;
    cin >> str;
    ll sz    = str.size();
    ll count = 1;
    ll sum   = 0;
    ll pre   = -1;
    ll start = 0;
    if (str == ">") { cout << "1" << endl; return 0; }
    for (int i = 1; i < sz; i++) {
        if (str.at(start) == str.at(i))
        {
            count++;
        }
        else
        {
            // 中
            for (int j = 1; j < count; j++) {
                sum += j;
            }
            if (str.at(i) == '>') {
                pre = count;
            }
            // <>の真ん中の数値決め
            else if (pre != -1) {
                sum += max(pre, count);
            }
            start = i;
            count = 1;
        }
    }
    for (int j = 1; j < count; j++) {
        sum += j;
    }

    if (str.at(sz - 1) == '>' && pre != -1) {
        sum += max(pre, count);
    }

    // 文頭処理
    if (str.at(0) == '>') {
        int count_top = 1;
        int j         = 1;
        while (str.at(j) == '>') {
            count_top++;
            if (j == sz - 1) { break; }
            j++;
        }
        sum += count_top;
    }

    // 文末処理
    if (str.at(sz - 1) == '<') {
        sum += count;
    }

    cout <<  sum << endl;


    return 0;
}


Measured memory_bytes: 1172
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    ll n, t;
    cin >> n >> t;
    vector<ll> l(n);
    for(ll i = 0; i < n; i++) cin >> l[i];

    ll ans = t;
    ll lastTiming = l[0];
    for(ll i = 1; i < n; i++){
        if(abs(lastTiming - l[i]) >= t){
            ans += t;
        } else {
            ans += abs(lastTiming - l[i]);
        }
        lastTiming = l[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, t;
	cin >> n >> t;
	vi num(n);
	REP(i, n)
		cin >> num[i];
	SORT(num);
	vll memo(n, 0);
	int idx = 0;
	ll mod = 1000000007;
	REP(i, n) {
		if (i == 0) {
			memo[i] = 1;
		}
		else {
			while(num[idx] < num[i] - t) {
				idx++;
			}
			memo[i] = (memo[i - 1] * ll(i - idx + 1))%mod;
		}
	}
	cout << memo[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>     
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)2e5 + 100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int n, x, cnt[70][2], ans;
main () {
	scanf("%lld", &n);
	forn(i, 1, n){
		scanf("%lld", &x);
		forn(i, 0, 60){
			int b = (x >> i) & 1;
			ans = (ans + (1ll << i) % mod * 1ll * cnt[i][b ^ 1] % mod) % mod;
			cnt[i][b]++;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
s = input()
flag = True
if(s[0] != 'A'):
    flag = False
if(s[-1] == 'C' or s[1] == 'C'):
    flag = False
if(s.count('C') == 0 or s.count('C') >= 2):
    flag = False
for i in s:
    if(i != 'A' and i != 'C' and i.isupper()):
        flag = False
if(flag):
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 998244353
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long

void solve()
{   
    string t="ACL";
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cout<<t;
}

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
   
}

Measured memory_bytes: 3576
from math import sqrt
N, M = map(int, input().split())
l = []
for i in range(1, int(sqrt(M)) + 1):
  if M % i == 0:
    l.append(i)
    l.append(M // i)

ans = 1
for d in l:
  if d * N <= M:
    ans = max(ans, d)
print(ans)

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

int main() {
    string S, T;
    int find, sub_seq_idx = -1;
    cin >> S >> T;

    for (int i = S.length() - T.length(); i >= 0; i--) {
        find = 0;
        for (int j = 0; j < T.length(); j++) {
            if (S[i + j] == T[j]) continue;
            else {
                if (S[i + j] == '?') continue;
                else {
                    find = 1;
                    break;
                }
            }
        }
        if (! find) {
            sub_seq_idx = i;
            break;
        }
    }

    if (sub_seq_idx == -1) cout << "UNRESTORABLE" << endl;
    else {
        for (int i = 0; i < T.length(); i++) {
            S[sub_seq_idx + i] = T[i];
        }
        for (int i = 0; i < S.length(); i++) {
            if (S[i] == '?') S[i] = 'a';
        }
        cout << S << endl;
    }

    return 0;

}

Measured memory_bytes: 256
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''

def myAnswer(x:int) -> int:
   total = 0
   if (x > 11):
      total = x // 11 * 2
      x = x % 11
   if(x == 0):
      return total
   elif(x <= 6):
      return total + 1
   else:
      return total + 2


def modelAnswer():
   return
def main():
   x = int(input())
   print(myAnswer(x))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
#include <stdio.h>
#include <inttypes.h>

#define KI_MAX 64

int ki[KI_MAX];

void ki_init(void) {
	int i;
	for (i = 0; i < KI_MAX; i++) {
		ki[i] = 1;
	}
}

int ki_root(int x) {
	if (ki[x] > 0) {
		return x;
	} else {
		int root = ki_root(-ki[x]);
		ki[x] = -root;
		return root;
	}
}

int ki_size(int x) {
	return ki[ki_root(x)];
}

void ki_merge(int a, int b) {
	int ar = ki_root(a);
	int br = ki_root(b);
	if (ar != br) {
		int as = ki_size(ar);
		int bs = ki_size(br);
		if (as >= bs) {
			ki[ar] += ki[br];
			ki[br] = -ar;
		} else {
			ki[br] += ki[ar];
			ki[ar] = -br;
		}
	}
}

int N;
int64_t x[64], y[64];

int main(void) {
	int i, j;
	int ansaa;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNd64 "%" SCNd64, &x[i], &y[i]) != 2) return 1;
	}
	ansaa = N;
	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			int64_t dx = x[i] - x[j], dy = y[i] - y[j];
			int k, l;
			int kaunto = 1, fr;
			ki_init();
			for (k = 0; k < N; k++) {
				for (l = k + 1; l < N; l++) {
					int64_t cx = x[k] - x[l], cy = y[k] - y[l];
					if ((cx == dx && cy == dy) || (cx == -dx && cy == -dy)) {
						ki_merge(k, l);
					}
				}
			}
			for (k = 1; k < N; k++) {
				if (ki_root(k) != ki_root(0)) {
					kaunto++;
					ki_merge(0, k);
				}
			}
			if (kaunto < ansaa) ansaa = kaunto;
		}
	}
	printf("%d\n", ansaa);
	return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll h,w,cnt=0;
	char c;
	cin >> h >> w;
	rep(i,h){
		rep(j,w){
			cin >> c;
			if(c=='#') cnt++;
		}
	}
	cout << (cnt==h+w-1?"Possible":"Impossible") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n, n){
    string S[n];
    int M = 0;
    for(int i = 0; i < n; ++i){
      cin >> S[i];
      M = max(M,(int)S[i].size());
      for(int j = 0; j < S[i].size()-1; ++j){
	if(S[i][j] == '.' && S[i][j+1] != '.'){
	  S[i][j] = '+';
	  break;
	}
      }
    }
    for(int j = 0; j < M; ++j){
      int s = -1;
      for(int i = 0; i < n; ++i){
	if(j >= (int)S[i].size() || (S[i][j] != '.' && S[i][j] != '+')){
	  s = -1;
	  continue;
	}
	if(s > -1 && S[i][j] == '+'){
	  for(int k = s+1; k < i; ++k){
	    S[k][j] = '|';
	  }
	}
	if(S[i][j] == '+'){
	  s = i;
	}
      }
    }
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < (int)S[i].size(); ++j){
	if(S[i][j] == '.') S[i][j] = ' ';
	if(S[i][j] == '+') break;
      }
    }

    for(int i = 0; i < n; ++i)
      cout << S[i] << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll h,w;
ll gy,gx;

ll d[30][30][4];

vector<vector<ll>> G;
ll c[4];

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

bool in(int y,int x){
    return y >= 0 && y < h && x >= 0 && x < w;
}

void dijkstra(ll sy,ll sx,ll dir){
    rep(i,30)rep(j,30)rep(k,4)d[i][j][k] = INF;
    d[sy][sx][dir] = 0;

    typedef pair<P,P> PP;
    priority_queue<PP, vector<PP>, greater<PP>> que;
    que.push(PP(P(0,dir),P(sy,sx)));

    while (!que.empty()){
        PP p = que.top();
        que.pop();
        ll cdir = p.first.second;
        ll cost = p.first.first;
        ll cy = p.second.first;
        ll cx = p.second.second;
        if(cost > d[cy][cx][cdir])continue;
        if(cy == gy && cx == gx)continue;
        rep(i,4){
            ll ny = cy + dy[(i + cdir)%4];
            ll nx = cx + dx[(i + cdir)%4];
            ll ndir = (cdir + i)%4;
            if(!in(ny,nx))continue;
            ll ncost = cost;
            if(i != G[cy][cx])ncost += c[i];
            if(d[ny][nx][ndir] > ncost){
                d[ny][nx][ndir] = ncost;
                que.push(PP(P(ncost,ndir),P(ny,nx)));
            }
        }
    }
}

int main(){
    while(cin >> w >> h && w){
        gy = h - 1; gx = w - 1;
        G.clear();
        G.resize(h);
        rep(i,h)G[i].resize(w);
        rep(i,h){
            rep(j,w){
                cin >> G[i][j];
            }
        }
        cin >> c[0] >> c[1] >> c[2] >> c[3];
        dijkstra(0,0,0);
        ll ans = INF;
        rep(i,4)ans = min(ans,d[h-1][w-1][i]);
        cout << ans << endl;
    }

}


Measured memory_bytes: 3244
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int a, p;
    cin >> a >> p;

    p += a * 3;

    cout << p / 2 << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<random>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 21000000145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
struct edge { int to, cost; };
int dp[114514];
signed main() {
	int n; cin >> n;
	vector<int>Q;
	int a = 1;
	rep(i, 10) {
		Q.push_back(a);
		a *= 6;
	}a = 1; rep(i, 10) {
		Q.push_back(a);
		a *= 9;
	}
	int ans = 0;
	sort(Q.begin(), Q.end());
	fill(dp, dp + 114514, 1145141919);
	dp[0] = 0;
	dp[1] = 1;
	rep(i, Q.size()) {
		for (int j= 2; j <= n; j++) {
			int b = j - Q[i];
			if (b >= 0)dp[j] = min(dp[j], dp[b] + 1);
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1152
local n, k = io.read("*n", "*n")
local sum, psum = {}, {}
local cur, pcur = 0, 0
for i = 1, n do
  local a = io.read("*n")
  cur = cur + a
  sum[i] = cur
  if 0 < a then
    pcur = pcur + a
  end
  psum[i] = pcur
end
local mma = math.max
local ret = 0
for i = 1, n - k + 1 do
  local v = sum[i + k - 1]
  if 1 < i then
    v = v - sum[i - 1]
  end
  v = mma(0, v)
  v = v + psum[n] - psum[i + k - 1]
  if 1 < i then
    v = v + psum[i - 1]
  end
  ret = mma(ret, v)
end
print(ret)


Measured memory_bytes: 4444
class EmployeeRecord
  NUM_EMPLOYEE = 4000
  MILLION = 1000000
  
  def initialize
    @sales = Array.new(NUM_EMPLOYEE + 1).fill(0, 0...(NUM_EMPLOYEE+1))
  end
  
  def updateSales(id, newSales)
    @sales[id] += newSales
  end
  
  def printIdOverMillionSales(inputId)
    count = 0
    for i in 0...inputId.size
      if @sales[inputId[i]] >= MILLION
        count += 1
        puts inputId[i]
      end
    end
    puts "NA"   if count == 0
  end
end

employee = nil
while true
  n = gets.to_i
  a = Array.new
  break   if n == 0
  employee = EmployeeRecord.new
  n.times do
    input = gets.split(" ")
    id = input[0].to_i
    a << id   if a.index(id) == nil
    price = input[1].to_i
    numItems = input[2].to_i
    employee.updateSales(id, price * numItems)
  end
  employee.printIdOverMillionSales(a)
end

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

using namespace std;

int main(){
    bool f = false;
    string str;
    int ans = 0;
    cin >> str;
    for(auto x : str){
        if(x == 'R' && f)
            ans++;
        else if(x == 'R'){
            ans = 1;
            f = true;
        }else{
            f = false;
        }
    }
    cout << ans << "\n"
;    return 0;
}

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

int main(){
    string S;
    cin >> S;

    if(S=="Sunny"){
        printf("Cloudy\n");
    }
    else if(S=="Cloudy"){
        printf("Rainy\n");
    }
    else{
        printf("Sunny\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

ll d[1001]={};
int a[100001]={};
int main() {
	char chr;
	int k=0;
	for(int i=0;i<3;++i){
		cin>>chr;
		if(chr=='1')k++;
	}
	cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 1010
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],k,now,ans[N];
const vector<int> inf(1,23333);
bool check(){
	int x=*max_element(a+1,a+k+1);
	int y=*min_element(a+1,a+k+1);
	return x<=(y<<1);
}
void Merge(vector<int> &a,vector<int> &b,vector<int> &c){
	int pa=0,pb=0;
	while(pa<(int)a.size()&&pb<(int)b.size()){
		c.push_back(a[pa]<b[pb]?a[pa++]:b[pb++]);
	}
	while(pa<(int)a.size())c.push_back(a[pa++]);
	while(pb<(int)b.size())c.push_back(b[pb++]);
}
vector<int> Solve(int len){
	static int vis[N],b[N];
	for(int i=1;i<=k;++i){
		vis[i]=0,b[i]=a[i];
	}
	for(int i=now+len-k+1;i<=now;++i){
		vis[ans[i]]=1;
	}
	for(int i=1;i<=k;++i){
		if(!vis[i])if((--b[i])<0)return inf;
	}
	int mn=*min_element(b+1,b+k+1);
	int mx=*max_element(b+1,b+k+1);
	if(mn*2+1<mx)return inf;
	vector<int> res;
	if(mn*2>=mx){
		for(int i=1;i<=k;++i){
			if(!vis[i])res.push_back(i);
		}
	}
	else{
		vector<int> A,B,all;
		for(int i=1;i<=k;++i){
			if(!vis[i]&&b[i]==mx)A.push_back(i);
		}
		for(int i=1;i<=k;++i){
			if(!vis[i]&&b[i]==mn)A.push_back(i);
		}
		for(int i=1;i<=k;++i){
			if(!vis[i]&&b[i]^mn&&b[i]^mx)B.push_back(i);
		}
		for(int i=now+len-k+1;i<=now;++i)all.push_back(ans[i]);
		Merge(A,B,res);
		all.insert(all.end(),res.begin(),res.end());
		int pmx=-1,pmn=n+1;
		for(int i=0;i<(int)all.size();++i){
			if(b[all[i]]==mx)pmx=max(pmx,i);
			if(b[all[i]]==mn)pmn=min(pmn,i);
		}
		if(pmx>pmn)res=inf;
	}
	return res;
}
void Extend(){
	vector<int> ext=inf;
	for(int len=1;len<=k&&len+now<=n;++len){
		if(len+now>=k){
			ext=min(ext,Solve(len));
		}
	}
	for(auto x:ext){
		ans[++now]=x;
		--a[x];
	}
}
int main(){
	k=read();
	for(int i=1;i<=k;++i){
		n+=a[i]=read();
	}
	if(!check()){
		puts("-1");
		return 0;
	}
	while(now<n){
		Extend();
	}
	for(int i=1;i<=n;++i){
		printf("%d ",ans[i]);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 3760
N = int(input())
L = [int(i) for i in input().split()]
C = [0 for i in range(N)]
for i in L:
    C[i-1] += 1
res = 0

for i in range(N):
    res += C[i]*(C[i]-1)//2
# 合計最初に出す
for i in range(N):
    j = L[i]-1
    print(res - C[j]*(C[j]-1)//2 + (C[j]-1)*(C[j]-2)//2)

Measured memory_bytes: 86092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll sum=0;
    vec A(n),num(100001,0);
    rep(i,n) cin>>A[i],num[A[i]]++,sum+=A[i];
    int q;
    cin>>q;
    rep(query,q){
        int b,c;
        cin>>b>>c;
        sum+=(c-b)*num[b];
        num[c]+=num[b];
        num[b]=0;
        cout<<sum<<"\n";
    }
}

Measured memory_bytes: 4748
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;


int hoge(int n){
    if (n < 10) {
        return n;
    }
    int sum = 0;
    while(n != 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main()
{
    int N;
    cin >> N;
    
    if (N % hoge(N) == 0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main(void) {
  int count = 0;
  string s, t;
  cin >> s;
  cin >> t;

  for(int i = 0; i<s.size();i++){
    if(s[i] != t[i]){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}

struct can{
    ll tk,mxi;
};

bool cmp(can a, can b)
{
    return a.tk<b.tk;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    ll n,m,ans=0;
    cin>>n>>m;
    can a[n+5];
    for(int i=0; i<n; i++)cin>>a[i].tk>>a[i].mxi;
    sort( a,a+n,cmp);
    for(int i=0; i<n; i++){
        //cout<<m<<" ";
        if(m>=a[i].mxi)ans+=(a[i].tk*a[i].mxi),m-=a[i].mxi;
        else{
            ans+=(a[i].tk*m);
            m=0;
        }
        if(m==0)break;
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 1792
let main = (input) => {
    let usrInput = input.split(/\n/)
    let time = 0
    for (let index = 0; index < usrInput[0].length; index++) {
        if (usrInput[0][index]!=usrInput[1][index]) {
            time++
        }
    }
    console.log(time)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  int cnt=0;

  while(!(a[0]==a[1]&&a[1]==a[2])){
    sort(a,a+3);
    if(a[0]==a[1]){
      a[0]++;
      a[1]++;
      cnt++;
    }
    else if(a[1]==a[2]){
      a[0]+=2;
      cnt++;
    }
    else if(a[1]-a[0]==1){
      a[0]++;
      a[2]++;
      cnt++;
    }
    else{
      a[0]+=2;
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); (i)++)
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x, T) sort(ALL(x), greater<T>())
#define REVERCE(x) reverce(ALL(x))

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

itn main() {
	ios::sync_with_stdio(false);

	int x, y;

	cin >> x >> y;

	int cnt = 1;

	while (x <= y / 2) {
		x *= 2;
		cnt++;
	}

	cout << cnt;

	return 0;
}


Measured memory_bytes: 256
/*main*/
#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;

typedef long long LL;
LL N,molecule,denominator;
int main()
{
    LL h,n,w;
    int flag = 0;
    scanf("%I64d",&N);
    for(h=1; h<=3500; h++)
    {
        for(n=1; n<=3500; n++)
        {
            molecule = 4*h*n - N*n - N*h;
            denominator = N*h*n;
            if(molecule>0 && denominator%molecule==0 && denominator/molecule<=3500)
            {
                w = denominator / molecule;
                printf("%I64d %I64d %I64d",h,n,w);
                flag = 1; break;
            }
        }
        if(flag) break;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimze("Ofast")
#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;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
#define vi vector<int>
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      
    x = x % p;  
    while (y > 0) {  
        if (y & 1){  
            res = (res*x) % p;  
        }
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;       
    while (y > 0) {    
        if (y & 1) 
            res = (res*x) ;  
        y = y>>1; 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
const int nax=2e5+5;

void solve(){
    int n;cin>>n;
    if(n>=30)cout<<"Yes\n";
    else cout<<"No\n";
    return;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
map<int, int> mmp;
multiset<int> mst;
 
int main( void ) {
    
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        
        if (mmp[x] == 0)
            mmp[x] = 1;
        else
            mst.insert(x), mmp[x] = 0;
    }
    
    if (mst.size() <= 1)
        cout << 0;
    else
        cout << 1LL * (*mst.rbegin()) * (*prev(prev(mst.end())));
    
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=200005,mod=998244353;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll ji[max_n];
ll inv(ll a)
{
	return pow(a,mod-2,mod);//逆元
}
ll C(ll n,ll m)
{
	return 1ll*ji[n]*inv(1ll*ji[m]*ji[n-m]%mod)%mod;//阶乘地求组合数
}
void jiecheng(int n)//预处理阶乘
{
	ji[0]=1;
	for(int i=1;i<=n;i++)
	{
		ji[i]=1LL*ji[i-1]*i%mod;
	}
}
ll ans=0;
int main()
{
	int n,m,k;cin>>n>>m>>k;
	jiecheng(n);
	for(int i=0;i<=k;i++)
	{
		ans+=(1LL*m*C(n-1,i))%mod*pow(m-1,n-i-1,mod)%mod;
	}
	cout<<(ans%mod+mod)%mod;
}

Measured memory_bytes: 5084
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    int x = 0;
    int y = 0;
    int z = 0;
    int k = 0;
    long[] a = new long[0];
    long[] b = new long[0];
    long[] c = new long[0];
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      String[] s = br.readLine().split("\\s+");
      x = Integer.parseInt(s[0]);
      y = Integer.parseInt(s[1]);
      z = Integer.parseInt(s[2]);
      k = Integer.parseInt(s[3]);
      a = Arrays.stream(br.readLine().split("\\s+"))
        .mapToLong(Long::parseLong)
        .map(i -> -i).sorted().map(i -> -i).toArray();
      b = Arrays.stream(br.readLine().split("\\s+"))
        .mapToLong(Long::parseLong)
        .map(i -> -i).sorted().map(i -> -i).toArray();
      c = Arrays.stream(br.readLine().split("\\s+"))
        .mapToLong(Long::parseLong)
        .map(i -> -i).sorted().map(i -> -i).toArray();
    } catch (IOException e) {
      e.printStackTrace();
    }
    PriorityQueue<Longs> pq = new PriorityQueue<>();
    Set<Longs> set = new HashSet<>();
    Longs n = new Longs(a[0]+b[0]+c[0],0,0,0);
    Longs m;
    pq.add(n);
    set.add(n);
    for (int i=0;i<k;i++) {
      n = pq.poll();
      System.out.println(n.n);
      int p = n.i;
      int q = n.j;
      int r = n.k;
      if (p+1 < x) {
        m = new Longs(a[p+1]+b[q]+c[r],p+1,q,r);
        if (!set.contains(m)) {
          pq.add(m);
          set.add(m);
        }
      }
      if (q+1 < y) {
        m = new Longs(a[p]+b[q+1]+c[r],p,q+1,r);
        if (!set.contains(m)) {
          pq.add(m);
          set.add(m);
        }
      }
      if (r+1 < z) {
        m = new Longs(a[p]+b[q]+c[r+1],p,q,r+1);
        if (!set.contains(m)) {
          pq.add(m);
          set.add(m);
        }
      }
    }
  }
  private class Longs implements Comparable<Longs> {
    private long n;
    private int i;
    private int j;
    private int k;
    private long priority;
    Longs(long n,int i,int j,int k) {
      this.n = n;
      this.i = i;
      this.j = j;
      this.k = k;
      priority = n;
    }
    @Override
    public int compareTo(Longs other) {
      return -Long.compare(priority,other.priority);
    }
    @Override
    public int hashCode() {
      int prime = 31;
      int result = 1;
      result = prime * result + (int)(n ^ (n >>> 32));
      result = prime * result + i;
      result = prime * result + j;
      result = prime * result + k;
      return result;
    }
    @Override
    public boolean equals(Object obj) {
      if (this == obj) return true;
      if (obj == null) return false;
      if (getClass() != obj.getClass()) return false;
      Longs other = (Longs)obj;
      return n == other.n && i == other.i && j == other.j && k == other.k;
    }
  }
}

Measured memory_bytes: 28308
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static class Card implements Cloneable{
		public char suit;
		public char value;
		public Card() {}
		public Card(char suit, char value) {
			this.suit = suit; this.value = value;
		}
		public Card clone() {
			Card card = new Card();
			card.suit = this.suit; card.value = this.value;
			return card;
		}
	}
	public static void bubble(ArrayList<Card> A) {
		for(int i = 0; i < A.size(); i++) {
			for(int j = A.size() - 1; j >= 1; j--) {
				if(A.get(j).value < A.get(j-1).value) {
					Card t = A.get(j).clone(); A.set(j, A.get(j-1).clone()); A.set(j-1, t);
				}
			}
		}
	}
	public static void selection(ArrayList<Card> A) {
		for(int i = 0; i < A.size(); i++) {
			int minj = i;
			for(int j = i; j < A.size(); j++) {
				if(A.get(j).value < A.get(minj).value)minj =j;
			}
			Card t = A.get(i).clone(); A.set(i, A.get(minj).clone()); A.set(minj, t);
		}
	}
	public static void print(ArrayList<Card> A) {
		for(int i = 0; i < A.size(); i++) System.out.printf("%s%s%s",A.get(i).suit,A.get(i).value,i==A.size()-1?"\n":" ");
	}
	public static boolean isStable(ArrayList<Card> C1, ArrayList<Card> C2) {
		for(int i = 0; i < C1.size(); i++) {
			if(C1.get(i).suit != C2.get(i).suit) return false;
		}
		return true;
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = (int)scanner.nextLine().charAt(0);
		ArrayList<Card> C1 = new ArrayList<>(),C2 = new ArrayList<>();
		String[] str = scanner.nextLine().split(" ");
		for(String s : str) {
			C1.add(new Card(s.charAt(0), s.charAt(1)));
			C2.add(new Card(s.charAt(0),s.charAt(1)));
		}
		bubble(C1);
		selection(C2);
		print(C1);
		System.out.println("Stable");
		print(C2);
		if(isStable(C1,C2)) System.out.println("Stable");
		else System.out.println("Not stable");

		scanner.close();
	}
}


Measured memory_bytes: 26524
#include <stdio.h>
#include <stdlib.h>

int main()
{
	char S[27];
	scanf("%s", S);
	
	int i, j, flag = 1;
	for (i = 0; S[i] != 0; i++) {
		for (j = i + 1; S[j] != 0; j++) {
			if (S[j] == S[i]) flag = 0;
		}
	}
	
	if (flag == 1) printf("yes\n");
	else printf("no\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
//
//  main.cpp
//  adsfdsgsg
//
//  Created by h3037175 on 2017/07/31.
//  Copyright ?? 2017??´ h3037175. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <math.h>
#include<algorithm>
#include <utility>
#define nan -100000
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}

Measured memory_bytes: 3124
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a ,b ,c ,x;
    for(x=1;x<=3000;x++)
    {
    cin >> a >> b;
    if(a==0 && b==0)
       break;
    //Swap a & b
    if(a > b)
    {
        
        c = b;
        b = a;
        a = c;
    }
 
    
    cout << a << " " << b << endl;
   }
}


Measured memory_bytes: 3068
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define NMAX 1000
#define MIN(a,b) ((a) < (b) ? (a) : (b))
int cmatrix[NMAX][NMAX], dmatrix[NMAX][NMAX], visit[NMAX], dist[NMAX], prev[NMAX], h[NMAX];
int Maxflow(int, int, int);
int Mincostflow(int, int, int, int);
int main(void)
{
  int i, v, e, f, a, b, c, d, mincost = 0;
  scanf("%d %d %d", &v, &e, &f);
  for (i = 0; i < e; i++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    cmatrix[a][b] = c;
    cmatrix[b][a] = 0;
    dmatrix[a][b] = d;
    dmatrix[b][a] = -d;
  }
  printf("%d\n", Mincostflow(0, v - 1, v, f));
}
int Maxflow(int s, int t, int size)
{
  int i;
  for (i = 0; i < size; i++) {
    dist[i] = INT_MAX;
    prev[i] = -1;
    visit[i] = 0;
  }
  dist[s] = 0;
  while(1) {
    int u = -1, min = INT_MAX;
    for (i = 0; i < size; i++) {
      if (!visit[i] && dist[i] < min) {
        u = i;
        min = dist[i];
      }
    }
    if (u == -1) break;
    visit[u] = 1;
    for (i = 0; i < size; i++) {
      if (cmatrix[u][i] > 0) {
        int newlen = dist[u] + dmatrix[u][i] + h[u] - h[i];
        if (newlen < dist[i]) {
          dist[i] = newlen;
          prev[i] = u;
        }
      }
    }
  }
  return dist[t] != INT_MAX;
}
int Mincostflow(int s, int t, int size, int f)
{
  int mincost = 0;
  while (f > 0 && Maxflow(s, t, size)) {
    int i, delta = f;
    for (i = t; i != s; i = prev[i]) {
      delta = MIN(delta, cmatrix[prev[i]][i]);
    }
    f -= delta;
    for (i = t; i != s; i = prev[i]) {
      cmatrix[prev[i]][i] -= delta;
      cmatrix[i][prev[i]] += delta;
    }
    for (i = 0; i < size; i++) h[i] += dist[i];
    mincost += delta * h[t];
  }
  if (f) mincost = -1;
  return mincost;
}


Measured memory_bytes: 2596
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>
#include<fstream>
#include<list>
#include<sstream>

#define loopi(x,y) for(int i = x;i<(y);i++)
#define loopj(x,y) for(int j = x;j<(y);j++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)


#define nl cout<<"\n";
#define ll long long int
#define mod  1000000007

using namespace std;



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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << max(a * c, max(b * d, max(a * d, b * c)));

}


Measured memory_bytes: 3644
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        sc.close();

        // 主処理
        int result = 0;
        if (n != 1) {
            List<Integer> list = primeFactorization(n);
            Map<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < list.size(); i++) {
                int num = list.get(i);
                if (map.containsKey(num)) {
                    map.put(num, map.get(num) + 1);
                } else {
                    map.put(num, 1);
                }
            }

            int[] count = new int[40];
            for (int i = 1; i < count.length; i++) {
                count[i] = count[i - 1] + i;
            }

            for (int key : map.keySet()) {
                int val = map.get(key);
                for (int i = 0; i < count.length; i++) {
                    if (val < count[i]) {
                        result += i - 1;
                        break;
                    }
                }
            }
        }

        // 出力
        System.out.println(result);

    }

    public static List<Integer> primeFactorization(long num) {
        List<Integer> list = new ArrayList<>();
        int max = (int) Math.sqrt(num);
        int div = 2;
        while (div <= max) {
            if (num % div == 0) {
                num /= div;
                list.add(div);
            } else {
                div++;
            }
        }
        if (num != 1) {
            list.add((int) num);
        }
        return list;
    }
}


Measured memory_bytes: 35724
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e6+5;
char s[maxn];
char q[maxn];
int main(){
	int l=2e5,r;
	r=l-1;
	cin>>(s+1);
	int len=strlen(s+1);
	for(int i=1;i<=len;i++){
		q[++r]=s[i];
	}
	int t;
	cin>>t;
	int flag=0;
	while(t--){
		int op;
		cin>>op;
		if(op==1){
			flag^=1;
		}
		else {
			int z;char c;
			cin>>z>>c;
			if(z==2)z=0;
			if(flag)z^=1;
			if(z!=1){
				q[++r]=c;
			}
			else {
				q[--l]=c;
			}
		}
	}
	if(!flag)
	for(int i=l;i<=r;i++)cout<<q[i];
	else for(int i=r;i>=l;i--)cout<<q[i];
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int f[100][10];
int p[100][11];

signed main() {
	int i, j, k;
	
	cin >> n;
	rep(i, n) rep(j, 10) cin >> f[i][j];
	rep(i, n) rep(j, 11) cin >> p[i][j];
	
	int ans = -1e+15;
	rep(i, (1 << 10)) {
		if (i == 0) continue;
		int sumP = 0;
		rep(j, n) {
			int cnt = 0;
			rep(k, 10) {
				if ((i >> k) % 2 == 1 && f[j][k] == 1) {
					cnt++;
				}
			}
			sumP += p[j][cnt];
		}
		ans = max(ans, sumP);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(x):
    k = b*x
    sm = 0
    for i in range(n):
        sm += max(0, (h[i]-k+c-1)//c)
    #ddprint(f"foo {x} sm {sm}")
    return (sm<=x)

n,a,b = inm()
h = []
for i in range(n):
    h.append(inn())
c = a-b
mn = 0
mx = (max(h)+b-1)//b
while mx>mn+1:
    mid = (mx+mn)//2
    if foo(mid):
        mx = mid
    else:
        mn = mid
print(mx)


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

typedef long long LL;
const int MAXN = 18;
int A[MAXN], n;
LL dp(int l, int r, LL vl, LL vr) {
	if (l > r) return 0;
	if (l == r) return (vl + vr) * A[l];
	LL res = 0x7fffffffffffffffLL;
	for (int i = l; i <= r; ++i)
		res = std::min(res, dp(l, i - 1, vl, vl + vr) + dp(i + 1, r, vl + vr, vr) + (vl + vr) * A[i]);
	return res;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	std::cout << dp(2, n - 1, 1, 1) + A[1] + A[n] << std::endl;
	return 0;
}


Measured memory_bytes: 384