akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n;
  cin >> n;
  vector<long>a(n);
  int i;
  long ans = 0;
  long const p = 1000000007;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  for(long bit = 1;bit<(1LL<<61);bit*=2){
    long bit1 = 0;
    for(i=0;i<n;i++){
      if((a[i]&bit)!=0)bit1++;
    }
    ans += (bit%p)*(bit1)%p*(n-bit1)%p;
    ans %= p;
  }

  cout << ans << endl;

}


Measured memory_bytes: 2560
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda x: x[1])
s = 0
for a, b in AB:
    s += a
    if s > b:
        print('No')
        break
else:
    print('Yes')

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;

    if (A == B && B == C && A % 2 == 0)
    {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
    {
        ll halfA = A / 2, halfB = B / 2, halfC = C / 2;
        A = halfB + halfC;
        B = halfA + halfC;
        C = halfA + halfB;
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[111111],b[111111];
int cnt[111111];
int ptr;
long long tot;
int ans;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=0;i<n;i++)
		if(a[i]<b[i]){
			tot+=b[i]-a[i];
			ans++; 
		}
	long long qwe=0;
	for(int i=0;i<n;i++)
		if(a[i]>b[i]){
			cnt[ptr++]=a[i]-b[i];
			qwe+=a[i]-b[i];
		}
	if(qwe<tot){
		cout<<-1<<endl;
		return 0;
	}
	if(tot==0){
		cout<<0<<endl;
		return 0;
	}
	sort(cnt,cnt+ptr);
	reverse(cnt,cnt+ptr);
	for(int i=0;i<ptr;i++)
		if(tot<=cnt[i]){
			ans++;
			break;
		}
		else{
			ans++;
			tot-=cnt[i];
		}
	cout<<ans<<endl;
	return 0;
}

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


int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int cnt = 0;
  while (a >= b) {
    b *= 2;
    cnt++;
  }
  while (b >= c) {
    c *= 2;
    cnt++;
  }
  if (cnt <= k) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3608
#coding:utf-8
import sys
S = 0

A,B = map(int,input().split())

if A == B:
    S += A*2
    print(S)
    sys.exit()

if A > B:
    S += A
    A = A - 1

else:
    S += B
    B = B - 1

S += max(A,B)
print(S)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int main(void){
    int a,b; cin >> a >> b;
    vector< int > xa;
    vector< int > xb;
    for(int i=0;i<b;i++){
        xa.push_back(a);
    }
    for(int i=0;i<a;i++){
        xb.push_back(b);
    }
    int flag = 0;
    for(int i=0;i<min(xa.size(),xb.size());i++){
        if(xa[i]<xb[i]){
            flag = 1;
            break;
        }else if(xa[i]>xb[i]){
            flag = -1;
            break;
        }
    }
    if(flag==1){
        rep(i,xa.size()) cout << xa[i];
    }else{
        rep(i,xb.size()) cout << xb[i];
    }
}







Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n, k;
  cin >> n >> k;
  vi a(n);
  vector<bool> b(n, false);
  vi c(n);
  ll count = 0;
  ll round;
  ll sub;
  rep(i,n){
    cin >> a[i];
  }
  bool z = true;
  ll next = 0;
  for(ll i=0;i<k;i++){
    if(b[next]){
      sub = c[next];
      round = count - sub;
      z = false;
      break;
    }
    else{
      b[next] = true;
      c[next] = count;
      next = a[next] - 1;
      count++;
    }
  }
  if(z){
    print(next+1);
  }
  else{
    k -= sub;
    k %= round;
    rep(i,k){
      next = a[next] - 1;
    }
    print(next+1);
  }
}

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

#define pb push_back 
#define ll long long 
#define forit(it,a) for(_typeof(a.begin()) it =a.begin();it!=a.end();it++)
#define mp make_apir 

using namespace std;


int main(){
	int n,k;
	cin >> n >> k;
	vector<int> arr;
	while(n--){
		int p;
		cin >> p;
		arr.pb(p);
		
	}
	sort(arr.begin(),arr.end());
	
	int sum=0;
	for(size_t i=0;i<k;i++){
		sum+=arr[i];
	}
	
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, m, ta;
string s[100], t[100];
map<string, int> mp;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> s[i];
		mp[s[i]]++;
	}
	cin >> m;
	rep(i, m) {
		cin >> t[i];
		mp[t[i]]--;
	}
	rep(i, n)ta = max(ta, mp[s[i]]);
	cout << ta << endl;
	ggr
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc132/tasks/abc132_f>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll dp[105][100005];
ll cnt[100005];
const ll MOD =1e9+7;
template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    
    ll M = 0;
    for(ll i = 1; i <= N;){
        ll j = N/i;
        if(i <= j){
            cnt[M++] = 1;
            i++;
        }else{
            cnt[M++] = N/j - i + 1;
            i = N/j + 1;
        }
    }
    
    auto add = [&](ll& l,const ll v){
        (l += v)%=MOD;
    };
    
    vector<ll> cusum(M+5);
    
    dp[0][0] = 1;
    for(int k = 0; k < K;k++){
        fill(cusum.begin(),cusum.end(),0);
        
        for(int j = 0; j <= M;j++){
            cusum[j+1] = cusum[j] + dp[k][j];
        }
        for(int j = 0; j < M;j++){
            add(dp[k+1][j],cusum[M-j]*cnt[j]%MOD);
        }
    }
    
    for(auto v:dp[K]){
        add(res,v);
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 79488
s = input()
t = input()
len_s = len(s)
len_t = len(t)

ans_ls = []
for start in range(len_s - len_t + 1):
    Pass = True
    for i in range(len_t):
        if s[start+i] != '?':
            if s[start+i] != t[i]:
                Pass = False
    if Pass:
        including = s[:start] + t + s[start + len_t:]
        replaced = including.replace('?', 'a')
        ans_ls.append(replaced)
ans_ls.sort()
if ans_ls:  
    print(ans_ls[0])
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    public class MainClass
    {

        public static void Main(string[] args)
        {
            checked
            {
                var paramsList = Console.ReadLine().Split(' ').ToList();
                var n = int.Parse(paramsList[0]);
                var m = int.Parse(paramsList[1]);

                var list = EnumerablePlus
                    .Repeat(n, () => Console.ReadLine())
                    .Select(line => line.Split(' ').Select(s => int.Parse(s)).ToList())
                    .Select(l => new { bid = l[0], max = l[1] })
                    .ToList();

                list.Sort((a, b) => a.bid - b.bid);

                long res = 0;
                foreach (var shop in list)
                {
                    if (m <= shop.max)
                    {
                        res += ((long)shop.bid * m);
                        break;
                    }

                    res += (long)shop.bid * shop.max;
                    m -= shop.max;
                }

                Console.WriteLine(res);
            }
        }

    }

    public static class EnumerablePlus
    {
        ///<summary>出力文字列に変換。</summary>
        public static string MkString<T>(this IEnumerable<T> list)
        {
            return list.Aggregate(
                new System.Text.StringBuilder(),
                (a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b)
                ).ToString();
        }

        ///<summary>添字付きfor。</summary>
        public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a)
        {
            int i = 0;
            foreach (var item in list)
            {
                a(item, i);
            }
        }

        ///<summary>指定回数デリゲートを呼び出す。</summary>
        public static IEnumerable<T> Repeat<T>(int n, Func<T> f)
        {
            for (int i = 0; i < n; i++)
            {
                yield return f();
            }
        }
    }

}


Measured memory_bytes: 23604
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    int ans = a[0];
    rep(i, n) ans = __gcd(ans, a[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

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

const long long INF = 1LL << 60;

long long teisu = 998244353;
unsigned long long dp[3000][3001];

int main(){

    int N, S;
    cin >> N >> S;
    int arr[N];

    for  (int i = 0; i < N ;++i){
        cin >> arr[i];
        for (int j=0; j < S+1; ++j){
            dp[i][j] = 0;
        }
    }

//    for (int i=0; i < teisu; ++i){
//        if (arr[0]==i){
//            dp[0][i] = 1;
//        }
//    }
    dp[0][arr[0]] = 1;
    dp[0][0] = 2;

    for  (int i = 1; i < N ;++i){
        for (int j=0; j < S+1; ++j){
            if(j-arr[i]>=0){
                dp[i][j] += dp[i-1][j-arr[i]];
                dp[i][j]%=teisu;
            }
            dp[i][j] += 2*dp[i-1][j];
            dp[i][j]%=teisu;
        }    
    }

    cout << dp[N-1][S] << endl;
    return 0;
}

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

int max(int *a);

int main(){
  int n,tmp[3];
  cin>>n;
  for(int i = 0;i < n;i++){
    cin>>tmp[0]>>tmp[1]>>tmp[2];
    sort(tmp,tmp + 3,greater<int>());
    if(tmp[0]*tmp[0] == tmp[1]*tmp[1] + tmp[2]*tmp[2])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;

const int N = (int) 2e5 + 10;
const int M = (int) 2e6 + 10;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double EPS = (double) 1e-9;
const double PI =  3.14159265359;

int n;
int was[N];

int f[N], inv[N];

int mult(int x, int y) {
    return 1ll * x * y % INF;
}

int bp(int x, int y) {
    int ans = 1;
    while (y) {
        if (y % 2) 
            ans = mult(ans, x);
        x = mult(x, x);
        y >>= 1;
    }
    return ans;
}

int cnk(int n, int k) {
    if (k > n || k < 0) return 0;
    return mult(f[n], mult(inv[n - k], inv[k]));
}

int main() {
    #define fn "bst"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        //freopen(fn".in", "r", stdin);
        //freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    ++n;
    int b, id; 
    f[0] = 1;
    for (int i = 1, A; i <= n; i++) {
        f[i] = mult(f[i - 1], i);
        cin >> A;
        if (!was[A]) {
            was[A] = i;
        } else {
            b = i - was[A] - 1;
            id = i;
        }
    }
    for (int i = 0; i <= n; i++) {
        inv[i] = bp(f[i], INF - 2);
    }
    int t = n - b - 2;
    for (int len = 1; len <= n; len++) {
        ll ans = 0; 
        ans += cnk(n - 2, len);
        ans += cnk(n - 1, len - 1) * 2;
        ans -= cnk(n - 2, len - 2);
        ans -= cnk(t, len - 1);
        ans += INF * 2;
        //ans -= + INF;
        cout << ans % INF << endl;
    }
    return 0;
}

Measured memory_bytes: 2432
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    return a * b // gcd(a,b)
N=int(input())
Ts=[]
c=1
for i in range(N):
 c=lcm(c,int(input()))
print(int(c))

Measured memory_bytes: 3060
#ifdef _WIN32
#define NOMINMAX
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#define DEBUGBREAK() ::DebugBreak()
#else
#define DEBUGBREAK() static_cast<void>(0)
#endif

#include <iostream>
#include <sstream>
#include <iomanip>
#include <valarray>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
#include <queue>
#include <array>
#include <functional>
#include <stack>
#include <bitset>
#include <random>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int64_t dx4[4] = { 0, -1, 1, 0 };
const int64_t dy4[4] = { -1, 0, 0, 1 };
const int64_t dx5[5] = { 0, -1, 0, 1, 0 };
const int64_t dy5[5] = { -1, 0, 0, 0, 1 };
const int64_t dx8[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int64_t dy8[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int64_t dx9[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
const int64_t dy9[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };

#define REP(i, K) for (int64_t i = 0; i < K; ++i)
#define REPYX() for (int64_t y = 0; y < H; ++y) for (int64_t x = 0; x < W; ++x)
#define REPX() REP(x, W)
#define REPY() REP(y, H)
#define INSIDE(x_, y_) (0 <= (x_) && 0 <= (y_) && (x_) < W && (y_) < H)
#define INSIDE_MARGIN(x_, y_, m_) ((m_) <= (x_) && (m_) <= (y_) && (x_) < W - (m_) && (y_) < H - (m_))
#define ALL(v) (v).begin(), (v).end()

int get_assert_level() {
    const char* s = getenv("ASSERT_LEVEL");
    if (s) { return atoi(s); }
    return 0;
}
static int g_assert_level = get_assert_level();

#define LV_1() if (g_assert_level >= 1)
#define LV_2() if (g_assert_level >= 2)
#define LV_3() if (g_assert_level >= 3)
#define ASSERT_1(expr) do { const bool b = bool(expr); if (g_assert_level >= 1 && !b) { std::cerr << "[ASSERT 1] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_2(expr) do { const bool b = bool(expr); if (g_assert_level >= 2 && !b) { std::cerr << "[ASSERT 2] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_3(expr) do { const bool b = bool(expr); if (g_assert_level >= 3 && !b) { std::cerr << "[ASSERT 3] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)

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

    int64_t N; // 1000000000000001 .. 50bit.
    cin >> N;

    vector<char> name_reversed;
    do {
        N -= 1;
        name_reversed.push_back(char(int('a') + int(N % 26)));
        N /= 26;
    } while (N > 0);
    reverse(ALL(name_reversed));

    string name(ALL(name_reversed));
    cout << name << endl;

    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <cstdint>

using namespace std;

int main() {
  int64_t X, K, D, ans, hop;
  cin >> X >> K >> D;
  X = abs(X);
  
  hop = X / D;
  if (K - hop <= 0) {
    ans = X - (K * D);
    cout << ans << "\n";
    return 0;
  }

  K = K - hop;
  X = X - (D * (X / D));

  if (K % 2) {
    ans = min(abs(X - D), abs(X + D));
  }
  else {
    ans = abs(X);
  }

  cout << ans << "\n";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;cin>>n>>m;
  ll x[n+1],y[m+1];
  for(ll i=1;i<=n;i++)cin>>x[i];
  for(ll i=1;i<=m;i++)cin>>y[i];
  ll mod=1000000007;
  ll sumx=0,sumy=0;
  for(ll i=1;i<=n;i++){
    sumx+=x[i]*(2*i-n-1);
    sumx=(sumx+mod)%mod;
  }
  for(ll i=1;i<=m;i++){
    sumy+=y[i]*(2*i-m-1);
    sumy=(sumy+mod)%mod;
  }
  cout<<(sumx*sumy)%mod<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

LL N, C;
vector<pair<LL, LL>> XV;
map<LL, LL> M;
vector<LL> X, V;

LL P[100004] = {0};
LL Q[100004] = {0};
LL R[100004] = {0};
LL S[100004] = {0};

LL XP[100004] = {0};
LL XQ[100004] = {0};
LL XR[100004] = {0};
LL XS[100004] = {0};


int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> C;
	V.push_back(0);
	X.push_back(0);
	for(int i=0; i<N; i++){
		long long x, v;
		cin >> x >> v;
		X.push_back(x);
		V.push_back(v);
		XV.push_back(make_pair(x, v));
		M[x] = v;
	}
	X.push_back(C);

	LL eg = 0, w = 0;
	LL ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
	for(int i=1; i<=N; i++){
		eg += (V[i] - (X[i] - X[i-1]));
		w = eg - X[i];
		P[i] = eg;
		Q[i] = w;
		if(ans1 < eg){
			ans1 = eg;
		}
	}
	P[N+1] = P[N] - (C - X[N]);
	Q[N+1] = P[N+1] - C;

	eg = 0, w = 0;
	for(int i=N; i>=1; i--){
		eg += (V[i] - (X[i+1] - X[i]));
		w = eg - (C - X[i]);
		R[i] = eg;
		S[i] = w;
		if(ans2 < eg){
			ans2 = eg;
		}
	}
	R[N+1] = 0;
	S[N+1] = 0;

	for(int i=1; i<=N; i++){
		if(i == 1){
			XP[i] = P[i];
			XQ[i] = Q[i];
		}
		else{
			if(P[i] > XP[i-1]){
				XP[i] = P[i];
			}
			else{
				XP[i] = XP[i-1];
			}
			if(Q[i] > XQ[i-1]){
				XQ[i] = Q[i];
			}
			else{
				XQ[i] = XQ[i-1];
			}
		}
	}
	for(int i=N; i>=1; i--){
		if(i == N){
			XR[i] = R[i];
			XS[i] = S[i];
		}
		else{
			if(R[i] > XR[i+1]){
				XR[i] = R[i];
			}
			else{
				XR[i] = XR[i+1];
			}
			if(S[i] > XS[i+1]){
				XS[i] = S[i];
			}
			else{
				XS[i] = XS[i+1];
			}
		}
	}

	eg = 0;
	for(int i=1; i<=N; i++){
		eg = XQ[i] + XR[i+1];
		if(ans3 < eg){
			ans3 = eg;
		}
	}

	eg = 0;
	for(int i=1; i<=N; i++){
		eg = XS[i+1] + XP[i];
		if(ans4 < eg){
			ans4 = eg;
		}
	}
	LL ans = max(max(max(ans1, ans2), ans3), ans4);
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    printf("%d\n", k * (int)pow(k-1, n-1));
}

Measured memory_bytes: 512
N = int(input())
Count = 0
if N>=357:
    Flag = True
    Now = ['33','35','37','53','55','57','73','75','77']
    TFS = ['3','5','7']
    Nex = []
    while int(Now[-1])<=N:
        for TNow in Now:
            for TTFS in TFS:
                Nex.append(TNow+TTFS)  
        for TNex in Nex:
            if all(TNex.count(C)>0 for C in '357') and int(TNex)<=N:
                Count += 1
        Now = Nex
        Nex = []
print(Count)

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

int main() {
  int keta,num;
  int tmp1, tmp2;
  
  cin >> keta >> num;
  
  map<int, int> m;
  vector<int> vec(10,0);

  if(keta == 1){
    if(num == 0){
      cout << 0;
      return 0;
    } 
    if(num == 1){
      cin >> tmp1 >> tmp2;
      if(tmp1 == 1 && tmp2 == 0){
        cout << 0;
        return 0;
      } 
    }
  }
  
  for(int i = 0; i < num; i++){
    cin >> tmp1 >> tmp2;
    
    if(tmp1 == 1 && tmp2 == 0){
      cout << -1;
      return 0;
    }
    
    if(vec.at(tmp1) != 0 && m[tmp1] != tmp2){
      cout << -1;
      return 0;
    }
    
    vec.at(tmp1) += 1;
    m[tmp1] = tmp2;
  }
  
  for(int i = 1; i <= keta; i++){
    if(i == 1 && m[i] == 0){
      cout << 1;
    }else{
      cout << m[i];
    }
  }
}


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

static const int N = 1000;

int lcs(string X, string Y)
{
    int c[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i <= m; i++)
        c[i][0] = 0;
    for (int j = 1; j <= n; j++)
        c[0][j] = 0;

    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (X[i] == Y[j])
            {
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else
            {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }

    return maxl;
}

int main()
{
    string s1, s2;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}


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

typedef struct d{
  string s;
  vector<int> v;
}D;
  
D a[1001];

void printd(int n)
{
  for(int i = 0; i < n; i++)
    cout << '.';
}

void f(D d, int x)
{
  printd(x);
  cout << d.s << endl;
  for(int i = 0; i < (int)d.v.size(); i++){
    f(a[d.v[i]],x+1);
  }
}

int main()
{
  int n;
  cin >> n;
  int k;
  cin >> k >> a[1].s;
  for(int i = 2; i <= n; i++){
    cin >> k >> a[i].s;
    a[k].v.push_back(i);
  }
  f(a[1],0);
}

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

int main(){
    string S;
    cin >> S;
    int min = 753;
    for(int i=0;i<S.size()-2;i++){
        int n = stoi(S.substr(i,3));
        if(abs(n-753)<min) min = abs(n-753);
    }
    cout << min << endl;

}

Measured memory_bytes: 256
s = input()

N = 13
dp = [0] * N
dp[0] = 1

mod = 10 ** 9 + 7
mul = 1
t = s[::-1]

for i in range(len(s)):
    nextDP = [0] * N
    c = t[i]
    if c == "?":
        for k in range(10):
            for j in range(N):
                nextDP[(k * mul + j) % N] += dp[j]
                nextDP[(k * mul + j) % N] %= mod
    else:
        k = int(t[i])
        for j in range(N):
            nextDP[(k * mul + j) % N] += dp[j]
            nextDP[(k * mul + j) % N] %= mod

    mul *= 10
    mul %= N
    dp = nextDP

print(dp[5])

Measured memory_bytes: 45052
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std;


int main() {

	char a[101], b[101];
	cin >> a >> b;
	cout << b << a << "\n";

	return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
ll H;
ll a[100001];
ll b[100001];
int main() {
	cin>>N>>H;
	for(int i=0;i<N;i++){
		cin>>a[i]>>b[i];
	}

	sort(a,a+N);
	sort(b,b+N);
	int T=0;
	int k=N-1;
	int c=0;
	while(T<H){
		if(a[N-1]>b[k]){
			c+=(H-T)/a[N-1];
			if((H-T)%a[N-1]>0)c++;
			T=H+1;
		}else{
			c++;
			T+=b[k];
			k--;
		}
	}
	cout<<c<<endl;

	return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


for i in a:
    if i%2 == 1:
        print(0)
        exit()

l = []
for i in a:
    l.append(factorization(i))

ans = 10 ** 9
for i in l:
    if i[0][0] == 2:
        ans = min(i[0][1], ans)

print(ans)

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

#define _USE_MATH_DEFINES
#define reb(i,b,n)         for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n)           reb(i,0,n)
#define each(it,v)         for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v)        for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vsort(v)           sort((x).begin(), (x).end()
#define rvsort(v)          sort((x).rbegin(), (x).rend()
#define mp(a, b)           make_pair(a, b)
#define fi                 first
#define se                 second
#define pb                 push_back
#define dbg(x)             cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;
#define dbgArr(table, n)   rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define dbg2Arr(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}

using namespace std; using std::stringstream;

typedef long long       ll; typedef unsigned long long ull; typedef long double     ld;
typedef pair <int, int> P;  typedef pair <int, P>      PP;
typedef vector<int>     vi; typedef vector<vi>         vvi; typedef vector<ll>      vl;
typedef vector<P >      vP; typedef vector<char>       vc;  typedef vector<string>  vs;

static const int    INF  = 0x3f3f3f3f;
static const ll     INFL = 0x3f3f3f3f3f3f3f3fLL;
static const double EPS  = 1e-9;
static const ll     MOD  = 1000000007LL;

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

int main(int argc, char *argv[])
{
    char A;
    cin >> A;
    if (A >= 'A' && A <= 'Z') {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
def goukei(n):
    sum=0
    while n>=1:
        sum+=n%10
        n=int(n/10)
    return int(sum)
    
n,a,b = map(int,input().split(' '))
sum = 0
for i in range(n+1):
    num = goukei(i)
    if num >=a and num <= b:
        sum +=i
print(sum)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define  int    long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff         first
#define  ss    second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
 
int32_t main()
{
    fast
    int n;
    f(i,1,5)
    {
        cin>>n;
        if(n==0)
        {
            cout<<i;
            exit(0);
        }
    }
}

Measured memory_bytes: 3640
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using ll = long long;

using namespace std;

ll pow_mod(ll a, ll b, ll p) {
	if (b == 0)return 1;
	else if (b % 2 == 0)return (pow_mod(a*a, b / 2, p) % p);
	else return (pow_mod(a, b - 1, p)*a%p);
}

ll sum_digit(ll N) {
	int ans = 0;
	for (; N != 0;) {
		ans += N % 10;
		N /= 10;
	}
	return ans;
}

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

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

int N, M;

ll ans;

int main(){
	scanf("%d %d", &N, &M);
	ll N_fact = 1,M_fact = 1;
	for (int i = 1; i < N + 1; i++) {
		N_fact = (N_fact*i) % MOD;
	}
	for (int i = 1; i < M + 1; i++) {
		M_fact = (M_fact * i) % MOD;
	}
	if (abs(N - M) > 1)ans = 0;
	else if (N == M)ans = (2 * ((N_fact*M_fact)%MOD)) % MOD;
	else ans = (N_fact*M_fact) % MOD;
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a1, a2, a3;

	scanf("%d%d%d", &a1, &a2, &a3);
	if (a1 + a2 + a3 >= 22)
		printf("bust\n");
	else
		printf("win\n");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int s,h,m;
	scanf("%d",&s);
	h=s/3600;
	s=s-h*3600;
	m=s/60;
	s=s-m*60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1020
loop = gets.to_i

info = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc)}
loop.times{
    b, f, r, v = gets.chomp.split
    if info[b][f][r] == {}
        info[b][f][r] = v.to_i
    elsif info[b][f][r] + v.to_i > 9
        info[b][f][r] += 9
    elsif info[b][f][r] + v.to_i < 0
        info[b][f][r] = 0
    else
        info[b][f][r] += v.to_i
    end
}

for b in 1..4
    for f in 1..3
        for r in 1..10
            tou = b.to_s
            kai = f.to_s
            room = r.to_s
            if info[tou][kai][room] == {}
                print " 0"
            else
                print " #{info[tou][kai][room]}"
            end
            if r == 10
                puts ""
            end
        end
    end
    print "####################\n" if b != 4
end


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	ll n, m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i, n)cin>>a[i];
	vector<int> b(m), c(m);
	rep(i,m) cin >> b[i] >> c[i];

	map<int,ll> mp;
	rep(i,n) mp[a[i]]++;

	rep(i,m){
		mp[c[i]] += b[i];
	}
	priority_queue<pair<ll,ll>> pq;
	for(auto x: mp){
		pq.push(x);
	}
	ll ans = 0;
	while(n > 0){
		auto p = pq.top(); pq.pop();
		ans += p.first * min(p.second,n);
		n -= min(n,p.second);
	}
	cout << ans << endl;
}


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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 666;
int a[N][N];
char used[N][N];
int n;

int isqrt(int n) {
	int x = sqrt(n);
	if (x * x == n) {
		return x;
	} else {
		return -1;
	}
}

void dfs(int x, int y, const vector<pair<int, int>>& q, int c, int cur = 0) {
	used[x][y] = 1;
	a[x][y] ^= cur;
	for (auto p : q) {
		for (int s1 : {-1, 1}) {
			for (int s2 : {-1, 1}) {
				int nx = x + p.first * s1;
				int ny = y + p.second * s2;

				if (nx < 0 || nx >= 2 * n || ny < 0 || ny >= 2 * n) {
					continue;
				}
				if (used[nx][ny]) {
					continue;
				}
				dfs(nx, ny, q, c, cur ^ c);
			}
		}
	}
}

void f(int d, int x) {
	vector<pair<int, int>> q;
	for (int i = 0; i * i <= d; ++i) {
		int j = isqrt(d - i * i);
		if (j != -1) {
			q.push_back({i, j});
		}
	}

	for (int i = 0; i < n * 2; ++i) {
		for (int j = 0; j < n * 2; ++j) {
			used[i][j] = 0;
		}
	}
	for (int i = 0; i < n * 2; ++i) {
		for (int j = 0; j < n * 2; ++j) {
			if (!used[i][j]) {
				dfs(i, j, q, x);
			}
		}
	}
}

int main() {
	n = nxt();
	f(nxt(), 1);
	f(nxt(), 2);

	vector<pair<int, int>> res[4];
	for (int i = 0; i < 2 * n; ++i) {
		for (int j = 0; j < 2 * n; ++j) {
			res[a[i][j]].push_back({i, j});
		}
	}
	auto v = *max_element(res, res + 4, [](const vector<pair<int, int>>& a, const vector<pair<int, int>>& b) {
		return a.size() < b.size();
	});

	v.resize(n * n);
	for (const auto& p : v) {
		printf("%d %d\n", p.first, p.second);
	}

	return 0;
}

Measured memory_bytes: 46580
#include<bits/stdc++.h> 
using namespace std; 
string firstLetterWord(string str) 
{ 
	string result = ""; 
	bool v = true; 
	for (int i=0; i<str.length(); i++) 
	{ 
		if (str[i] == ' ') 
			v = true;  
		else if (str[i] != ' ' && v == true) 
		{ 
			result.push_back(str[i]); 
			v = false; 
		} 
	} 

	return result; 
} 
int main() 
{ 
	string str;
getline(cin,str);
	cout << firstLetterWord(str); 
	return 0; 
}

Measured memory_bytes: 256
Q, H, S, D = map(int, input().split())
M = min(2 * Q, H)
# 0.5,1,2
N = int(input())

if N % 2 == 0:
  print(min(M * 2 * N, S * N, D * N // 2))
else:
  print(min((M * 2 * (N-1)) + M * 2, S * (N-1) + S, D * (N-1) // 2 + M * 2, D * (N-1) // 2 + S))

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

S=[input() for _ in range(N)]

AC=S.count("AC")
WA=S.count("WA")
TLE=S.count("TLE")
RE=S.count("RE")

print("AC x {}".format(AC))
print("WA x {}".format(WA))
print("TLE x {}".format(TLE))
print("RE x {}".format(RE))

Measured memory_bytes: 16272
K,N = map(int,input().split())

MOD = 998244353

fact = [1]*4000
t = 1
for i in range(1,4000):
    t = (t*i)%MOD
    fact[i] = t

factinv = [1]*4000
for i in range(1,4000):
    factinv[i] = pow(fact[i], MOD-2, MOD)

def ncr(n,r):
    if n < 0 or r < 0 or n-r < 0:
        return 0
    return (fact[n] * factinv[r] * factinv[n-r]) % MOD

def nhr(n,r):
    if n == 0 and r == 0:
        return 1
    return ncr(n+r-1, r)

for i in range(2,2*K+1):
    t1,t2 = 0,0
    Ans = 0
    # p : 足して i になる整数の組の数
    np = i//2 - max(i-1-K,0)
    # p組からq組, 片方を使用する場合の数を足し合わせる
    # 偶奇で場合分け
    if i%2==0:
        # 偶数の場合 : 1組だけ同じ数の組があるため特別扱いする
        np -= 1
        for nq in range(np+1):
            # 同じ数の組の数字を全く含まない場合
            t1 = ncr(np,nq)*pow(2, nq, MOD)
            t1 %= MOD
            t2 = nhr(K-np*2+nq-1,N-nq)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
            # 同じ数の組の数字を1つ含む場合
            t2 = nhr(K-np*2+nq-1,N-nq-1)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
    else:
        # 奇数の場合 : p組全て互いに異なる数
        for nq in range(np+1):
            t1 = ncr(np,nq)*pow(2, nq, MOD)
            t1 %= MOD
            t2 = nhr(K-np*2+nq,N-nq)
            t2 %= MOD
            Ans = (Ans + t1*t2) % MOD
    print(Ans%MOD)

Measured memory_bytes: 58712
N = int(input())
A = list(map(int, input().split()))

dp = [[-10**16 for __ in range(4)] for _ in range(N+10)]
A = A+[0,0,0,0,0,0,0]

if N == 2:
    print(max(A[0]+A[1], -A[0]-A[1]))
    exit()

dp[1][0] = A[0]+A[1] 
dp[1][1] = -A[0]-A[1]
# 0 -> ++
# 1 -> --
# 2 -> +-
# 3 -> -+

for i in range(1, N):
    # 0 ->
    dp[i+1][0] = max(dp[i+1][0], dp[i][0]+A[i+1])
    dp[i+1][1] = max(dp[i+1][1], dp[i][0]-A[i+1]-2*A[i])
    # 1 ->
    dp[i+1][3] = max(dp[i+1][3], dp[i][1]+A[i+1])
    dp[i+1][2] = max(dp[i+1][2], dp[i][1]-A[i+1]+2*A[i])
    # 2 ->
    dp[i+1][3] = max(dp[i+1][3], dp[i][2]+A[i+1])
    dp[i+1][2] = max(dp[i+1][2], dp[i][2]-A[i+1]+2*A[i])
    # 3 ->
    dp[i+1][0] = max(dp[i+1][0], dp[i][3]+A[i+1])
    dp[i+1][1] = max(dp[i+1][1], dp[i][3]-A[i+1]-2*A[i])    

print(max(dp[N-1]))
    

    


Measured memory_bytes: 34656
// AOJ 2799: Yamanote-line Game
// 2017.11.29 bal4u@uu

#include <stdio.h>

char buf[5003], *bp;
int getint() { int n = 0; while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf); return n; }

int main()
{
	int n, d, v, ans;

    fgets(bp=buf, 20, stdin);
	n = getint(), bp++, d = getint();
	fgets(bp=buf, sizeof(buf), stdin);
	ans = 0;
	while (n--) {
		v = getint() - d, bp++;
		if (v > 0) ans += v;
	}
	if (!ans) puts("kusoge");
	else printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1848
import sys
input = sys.stdin.readline
from collections import Counter
from operator import itemgetter

def mpsort(m):
	ary = sorted([[k, v] for (k, v) in m.items()], key=itemgetter(1), reverse=True)
	if len(ary) == 1:
		return ary[0], [0, 0]
	return ary[0], ary[1]

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	gu = [i for i in v[::2]]
	ki = [i for i in v[1::2]]
	gu_map = Counter(gu)
	ki_map = Counter(ki)
	gu_sum = sum(gu_map.values())
	ki_sum = sum(ki_map.values())
	# print(gu_map)
	gu_f, gu_s = mpsort(gu_map)
	ki_f, ki_s = mpsort(ki_map)

	if gu_f[0] == ki_f[0]:
			print(min(gu_sum - gu_s[1] + ki_sum - ki_f[1],
					  gu_sum - gu_f[1] + ki_sum - ki_s[1]))
	else:
		print(gu_sum - gu_f[1] + ki_sum - ki_f[1])
		
if __name__ == '__main__':
	main()


Measured memory_bytes: 73708
#include<stdio.h>

int main(void){
    int n,k;
    scanf("%d%d", &n, &k);

    double ans = 0;
    for(int i = 1; i <= n; i++){
        int x = i;//得点
        int y = 1;//回数

        while(x < k){
            x *= 2;
            y *= 2;
        }
        ans += 1.0 / (double)y;
    }

    printf("%.12lf\n", ans / (double)n);
    return 0;
}

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

using namespace std;

int main()
{
    vector<int> a(3), b(3);
    vector<int> town_path(4);
    for (int i = 0; i < 3; i++){
        cin >> a[i] >>b[i];
        town_path[a[i] - 1]++;
        town_path[b[i] - 1]++;
    }

    bool check_path = true;
    for (int i = 0; i < 4; i++){
        if(town_path[i] > 2){
            check_path = false;
            break;
        }
    }
    if(check_path)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
} 

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

int main() {
  int n, k, x, y, f;
  cin >> n >> k >> x >> y;
  f = min(n, k) * x;
  if (n > k) f += (n - k) * y;
  cout << f << endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
hist = Hash.new {|h, k| h[k] = 0 }
A = gets.split.map &:to_i
a = A.group_by{|i|i}.select {|i, a| a.size>=2 }.map(&:first).sort
b = A.group_by{|i|i}.select {|i, a| a.size>=4 }.map(&:first).sort
aa = a[-2]*a[-1] rescue 0
bb = b[-1]**2 rescue 0
puts [aa, bb].max


Measured memory_bytes: 29964
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    string s;

    cin >> s;

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    {
        cout << "Bad" << endl;
    }
    else
    {
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
#k = int(input())
arr = list(map(int, input().split()))
a = [0 for i in range(0,max(arr)+2)]
for ar in arr:
  if ar is not 0:
    a[ar-1] += 1
  a[ar] += 1
  #if ar is not max(arr)+1:
  a[ar+1] += 1 
ans = max(a)

print(ans)


Measured memory_bytes: 14092
#include <iostream>

using namespace std;

int main() {
  
  int  N,X,T;
  int ans=0;

  cin >> N>>X>>T;

  if(N%X==0){
    ans=N/X*T;
  }
  else{
    ans=N/X*T+T;
  }
  cout<<ans<<endl;
return 0;

}

Measured memory_bytes: 3548
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
    
    if(sc.nextInt()+sc.nextInt()+sc.nextInt()>=22){
    	System.out.println("bust");
    }else{
    	System.out.println("win");
    }
    
    }}


Measured memory_bytes: 21844
n = int(input())
a = []
tent = True
while True:
  if tent == True:
    for i in range(1,1001):
      if i ** 2 > 1000:
        tent = False
        break
      else:
        for j in range(2,10):
          if i**j <= 1000:
            a.append(i**j)
          else:
            break
  else:
    break
new_lst = [e for e in a if e <= n]
print(max(new_lst))

Measured memory_bytes: 9128
from bisect import bisect_right
s = input()
n = len(s)
t = input()
m = len(t)
tr = set(s)
for c in t:
  if c not in s:
    print(-1)
    exit(0)
d = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
for i, c in enumerate(s):
  d[c].append(i)
idx = -1
ans = 0
for c in t:
  tmp = bisect_right(d[c], idx)
  if tmp == len(d[c]):
    idx = d[c][0]
    ans += 1
  else:
    idx = d[c][tmp]
print(ans * n + idx + 1)


Measured memory_bytes: 7540
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<n;(i)++ )
#define FOR(i,m,n) for(int (i)=m;(i)<n;(i)++)
 
int main(){
    int n,m;
    cin>>n>>m;
    int a[m];
    int b[9]={2,5,5,4,5,6,3,7,6};
    int Max=0;
    vector<int> dp(n+1,-1000000);
    rep(i,m){
        cin>>a[i];
    }
    dp[0]=0;
    FOR(i,1,n+1){
        rep(j,m){
            if((i-b[a[j]-1])>=0) dp[i] = max(dp[i-b[a[j]-1]]+1,dp[i]);
        }
    }
    int tmp=n;
    for(int i=dp[n];i>=1;i--){
        rep(j,m){
            if((dp[tmp]-dp[tmp-b[a[j]-1]])==1&&(tmp-b[a[j]-1]>=0)){
                Max=max(Max,a[j]);
                //cout<<Max<<endl;
            }
        }  
        cout<<Max;
        //cout<<tmp<<endl;
        tmp-=b[Max-1];
        Max=0;
    }
    cout<<endl; 
    //rep(i,n+1){cout<<dp[i]<<" ";}
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  int snuke[n]={0};
  rep(i,k){
    int p;
    cin>>p;
    rep(j,p){
      int num;
      cin>>num;
      snuke[num-1]++;
    }
  }
  int ans=0;
  rep(i,n){
    if(snuke[i]==0) ans++;
  }
  cout<<ans<<endl;
  

  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	
	int n,m;
	scanf("%d%d", &n, &m);
	
	vector<int> p(n+5,0);
	vector<int> cant(n+5,1);
	
	p[1] = 1;
	int resp = 1;
	
	while(m--){
		int a,b;
		scanf("%d%d", &a, &b);
		
		cant[a]--;
		cant[b]++;
		
		if(p[a]){
			if(!p[b])resp++;
			p[b] = 1;
		}
		if(!cant[a]){
			if(p[a])resp--;
			p[a] = 0;
		}
	}
	
	printf("%d\n", resp);
		
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}
void submain();

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

int N; cin >> N;
VS S(N); invec(S);

VI cnt(4, 0);

rep(i, 0, N) {
    if (S[i] == "AC") ++cnt[0];
    else if (S[i] == "WA") ++cnt[1];
    else if (S[i] == "TLE") ++cnt[2];
    else if (S[i] == "RE") ++cnt[3];
}

cout << "AC x " << cnt[0] << "\n";
cout << "WA x " << cnt[1] << "\n";
cout << "TLE x " << cnt[2] << "\n";
cout << "RE x " << cnt[3] << "\n";


return 0;
}

// 制限が緩い場合での愚直解を書く。
void submain(){

}

// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



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

struct fenwick {
  int N;
  vector<int> bit;

  fenwick(int n = 1e5) {
    N = n + 5;
    bit.assign(N, 0);
  }

  void resize(int n) {
    N = n + 5;
    bit.assign(N, 0);
  }

  void update(int x, int val) {
    while (x < N) {
      bit[x] += val;
      x += x&-x;
    }
  }

  int query(int x) {
    int ret=0;
    while (x > 0) {
      ret += bit[x];
      x -= x&-x;
    }
    return ret;
  }
};

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  auto count = [&](int x) {
    long long tmp = 0, ret = 0;
    map<int, int> cc;
    vector<int> pre(n);
    for (int i = 0; i < n; ++i) {
      if (a[i] >= x) pre[i] = 1;
      else pre[i] = -1;
      if (i) pre[i] += pre[i-1];
      cc[pre[i]];
    }

    fenwick bit(n);
    cc[0];
    for (auto &i : cc) i.second = ++tmp;
    bit.update(cc[0], 1);

    for (auto &i : pre) {
      i = cc[i];
      ret += bit.query(i);
      bit.update(i, 1);
    }
    return ret;
  };

  long long total = 1ll * n * (n + 1) / 2;
  int l = 1, r = 1e9 + 5;
  while (l < r) {
    int mid = (l + r) / 2;
    if (count(mid) >= (total + 1) / 2) l = mid + 1;
    else r = mid;
  }

  cout << l - 1 << '\n';
}


Measured memory_bytes: 6144