akhauriyash/Code-Regression huggingface dataset:
-- FileName   : 163b
-- CreatedDate: 2020-04-19 21:08:11

import Control.Monad
import Data.List

main = do
   [n,m] <- getIntegerList
   a <- sum <$> getIntegerList
   if a > n
      then putStrLn "-1"
      else putStrLn $ show $ n - a


--------------------------------------------
getIntList        = map (read :: String -> Int) . words <$> getLine
getIntegerList    = map (read :: String -> Integer) . words <$> getLine
getIntegerListN m = map (read :: String -> Integer) <$> replicateM m getLine


base :: Integer
base = 1000000007

plus :: Integer -> Integer -> Integer
plus a b = (a+b) `mod` base

times :: Integer -> Integer -> Integer
times a b = a * b `mod` base

minus :: Integer -> Integer -> Integer
minus a b
   | a < b     = a-b + base
   | otherwise = a-b

power :: Integer -> Integer -> Integer
power n k
   | k == 0         = 1
   | k `mod` 2 == 0 = power (times n n) (k`div`2)
   | otherwise      = times n $! power n (k-1)

inv :: Integer -> Integer
inv n = power n $ base - 2

binom :: Integer -> Integer -> Integer
binom n m
   | (n-m) < m = times (foldr times 1 [m+1..n]) $ inv $ foldr times 1 [1..n-m]
   | otherwise = times (foldr times 1 [n-m+1..n]) $ inv $ foldr times 1 [1..m]


Measured memory_bytes: 7588
using System;
using System.Linq;

namespace AtCoderSnippet
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine().ToCharArray();
            var x = 0;
            foreach (var i in  N.ToList())
            {
                x += int.Parse(i.ToString());
            }
            if (x % 9 == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 34436
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int>fl(N + 2);
  for (int i = 1; i <= N; i ++) cin >> fl[i];
  fl[0] = fl[N + 1] = 0;
  int ans = 0;
  for (int i = 0; i < 100; i ++) {
    int kj = 0;
    for (int j = 1; j < N + 2; j ++) {
      if (fl[j - 1] <= 0 && fl[j] > 0) {
        kj ++;
      }
    }
    ans += kj;
    for (int j = 1; j <= N; j ++) fl[j] --;
  }
  cout << ans << endl;
}

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

using namespace std;

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

  if(a > 8 || b > 8) {
    cout <<  ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,x,t; cin >> n >> x >> t;
	cout << (n+x-1)/x*t << endl;
}

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

using namespace std;

int A,B,d[15][15],ans[105][105];
typedef pair<int, int> pi;

int main(){
//	freopen("graphxy.in","r", stdin);
//	freopen("graphxy.out","w", stdout);
	cin >> A >> B;
	for(int i = 1; i<=A; i++){ for(int j = 1; j<=B; j++) cin >> d[i][j]; }
	for(int a=0; a<=100; a++)
		for(int b=0; b<=100; b++)
			for(int x=1; x<=A; x++)
				for(int y=1; y<=B; y++)
					ans[a][b] = max(ans[a][b], d[x][y]-a*x-b*y);
	for(int i=1; i<=A; i++){
		for(int j = 1; j<=B; j++){
			int best = INT_MAX;
			for(int x=0; x<=100; x++){
				for(int y=0; y<=100; y++){
					best = min(best, ans[x][y]+i*x+j*y);
				}
			}
			if(best == d[i][j]){}
			else{
				cout << "Impossible";
				return 0;
			}
		}
	}
	cout << "Possible\n";
	cout << "200 10198\n";
	for(int i=0; i<100; i++){
		for(int j=0; j<100; j++) cout << i+1 << " " << 200-j << " " << ans[i][j] << "\n";
	}
	for(int i=1; i<100; i++) cout << i << " " << i+1 << " X\n";
	for(int i=101; i<200; i++) cout << i << " " << i+1 << " Y\n";
	cout << "1 200";
}


Measured memory_bytes: 384
# AtCoder Beginner Contest 044
# A - 高橋君とホテルイージー / Tak and Hotels (ABC Edit)
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
total = 0
if N > K:
    total = X*K + Y*(N-K)
else:
    total = X*N
print(total)

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

#define mod 1000000007

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

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N, M;
	
	cin >> N >> M;
	
	int P[M], Y[M];
	vector<int> yd[N + 1];
	
	rep(i, M){
		cin >> P[i] >> Y[i];
		yd[P[i]].push_back(Y[i]);
	}
	
	rep(i, N)
		sort(yd[i + 1].begin(), yd[i + 1].end());
	
	rep(i, M)
		printf("%012lld\n", ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin()) + 1);
		
	return 0;
}

Measured memory_bytes: 7808
def main():
    H, W = map(int, input().split())
    a = []
    for _ in range(H):
        a.append(input())
    h = []
    w = []
    for i in range(H):
        if a[i] == "."*W:
            h.append(i)
    for i in range(W):
        b = ""
        for j in range(H):
            b += a[j][i]
        if b == "."*H:
            w.append(i)
    
    for i in range(H):
        out = ""
        for j in range(W):
            if (i in h) or (j in w):
                out += ""
            else:
                out += a[i][j]
        if out != "":
            print(out)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;
    if (a == "D") {
        // flip
        b = b == "H" ? "D" : "H"; 
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i = 0; i < n - 2; i++) {
    string temp = s.substr(i, 3);
    if (temp == "ABC") ans++;
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

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

namespace {

#ifdef LOCAL
#define run_if_local(statement) statement
#else
#define run_if_local(statement)
#endif

#ifdef LOCAL
auto start_timestamp = clock();
void tag_execution_time() {
  std::cerr << "Execution timestamp: " << std::setprecision(4) << std::fixed
            << ((double)clock() - start_timestamp) / CLOCKS_PER_SEC << "s\n";
}
#else
void tag_execution_time() {}
#endif

template <typename Arg, typename... Args>
void __internal_print(std::ostream& out, Arg&& arg, Args&&... args) {
  out << std::forward<Arg>(arg);
  using expander = int[];
  (void)expander{0, (void(out << ' ' << std::forward<Args>(args)), 0)...};
  out << "\n";
}

template <typename Arg, typename... Args>
void __internal_read(Arg&& arg, Args&&... args) {
  std::cin >> std::forward<Arg>(arg);
  using expander = int[];
  (void)expander{0, (void(std::cin >> std::forward<Args>(args)), 0)...};
}

#define __internal_print_array(out, start, end)     \
  for (auto iter = start; iter != end; ++iter) {    \
    out << *iter << (iter + 1 == end ? "\n" : " "); \
  }

#define __internal_print_2d_array(out, array, rows, cols) \
  for (int i = 1; i <= rows; ++i) {                       \
    for (int j = 1; j <= cols; ++j) {                     \
      out << array[i][j] << (j == cols ? "\n" : " ");     \
    }                                                     \
  }

#define print(...) __internal_print(std::cout, __VA_ARGS__)
#define debug(...) __internal_print(std::cerr, __VA_ARGS__)
#define print_array(start, end) __internal_print_array(std::cout, start, end)
#define debug_array(start, end) __internal_print_array(std::cout, start, end)
#define print_2d_array(array, rows, cols) __internal_print_2d_array(std::cin, array, rows, cols)
#define read(...) __internal_read(__VA_ARGS__)
#define read_array(array, start, end)     \
  for (int _i = start; _i <= end; ++_i) { \
    std::cin >> (array)[_i];              \
  }
#define read_2d_array(array, n, m) \
  for (int i = 1; i <= n; ++i) {   \
    for (int j = 1; j <= m; ++j) { \
      std::cin >> array[i][j];     \
    }                              \
  }

#define update_max(a, b) if ((a) < (b)) (a) = (b)
#define update_min(a, b) if ((a) > (b)) (a) = (b)

}  // namespace

const int N = 100;

int a[N], b[N], c[N];
int n;

void run(int case_id = 0) {
  read(n);
  read_array(a, 1, n);
  read_array(b, 1, n);
  read_array(c, 1, n - 1);

  int answer = 0;
  int last = -1;
  for (int i = 1; i <= n; ++ i) {
    int x = a[i];
    answer += b[x];
    if (last != -1 && last == x - 1) {
      answer += c[last];
    }
    last = x;
  }
  print(answer);
}

void multi_cases_main() {
  int num_tests;
  std::cin >> num_tests;
  for (int t = 1; t <= num_tests; ++ t) {
    run(t);
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  run();
  return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int N,M,Q;
long long score=0;
vector<int> a(50),b(50),c(50),d(50);

void check_Q(vector<int> A){
  long long temp_score=0;
  for(int i=0;i<Q;i++){
    if(A.at(b.at(i)-1)-A.at(a.at(i)-1)==c.at(i)) temp_score+=d.at(i);
  }
  score=max(score,temp_score);
}

void make_A(int keta, vector<int> A){
  if(keta==N-1){
    check_Q(A);
    return;
  }
  for(int i=A.at(keta);i<=M;i++){
    A.at(keta+1)=i;
    make_A(keta+1,A);
  }
}

int main(){
  cin >> N >> M >> Q;

  for(int i=0;i<Q;i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  }

  vector<int> A(N);

  for(int i=1;i<=M;i++){
    A.at(0)=i;
    make_A(0,A);
  }

  cout << score << endl;
  
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X;
int K;
map<ll,vector<int>> V;
map<int,int> M;
int Q,T,A;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>K;
	vector<int> B={0,0,X,0};
	int pre=0;
	V[pre]=B;
	M[pre]=0;
	FOR(i,K) {
		cin>>x;
		int dif=x-pre;
		if(i%2==0) {
			
			if(B[2]<=dif) {
				B[0]=X;
				B[1]=B[2]=B[3]=0;
			}
			else {
				B[1]-=dif;
				B[2]-=dif;
				if(B[1]<0) {
					B[0]+=-B[1];
					B[1]=0;
				}
			}
		}
		else {
			if(B[1]+dif>=X) {
				B[0]=0;
				B[1]=B[2]=B[3]=X;
			}
			else {
				B[1]+=dif;
				B[2]+=dif;
				if(B[2]>X) {
					B[3]+=X-B[2];
					B[2]=X;
				}
			}
		}
		pre=x;
		V[pre]=B;
		M[pre]=(i%2)^1;
	}
	cin>>Q;
	while(Q--) {
		cin>>T>>A;
		auto it=V.lower_bound(T);
		if(it==V.end() || it->first>T) it--;
		
		int p=it->first;
		vector<int> v=it->second;
		
		int cur=0;
		if(v[0]>=A) cur=v[1];
		else cur=min(v[2],v[1]+(A-v[0]));
		
		
		if(M[p]==0) cur-=T-p;
		else cur+=T-p;
		cout<<min(max(0,cur),X)<<endl;
		
	}
	
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  string s,t; cin>>s>>t;
  int size=s.size();
  int yes=0;
  for(int i=0;i<size;i++){
    s=s.substr(1)+s[0];
    int sum=0;
    for(int j=0;j<size;j++){
      if(s[j]==t[j]) sum++;
    }
    if(sum==size){
      yes=1;
      break;
    }
  }
  if(yes==1) cout<<"Yes"<<endl; 
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
            #pragma comment(linker, "/stack:200000000")
            #pragma GCC optimize("unroll-loops")
             
            #include <algorithm>
            #include <bitset>
            #include <cassert>
            #include <chrono>
            #include <cmath>
            #include <complex>
            #include <cstdio>
            #include <cstdlib>
            #include <cstring>
            #include <ctime>
            #include <deque>
            #include <functional>
            #include <iomanip>
            #include <iostream>
            #include <iterator>
            #include <limits>
            #include <climits>
            #include <list>
            #include <map>
            #include <numeric>
            #include <queue>
            #include <random>
            #include <ratio>
            #include <set>
            #include <sstream>
            #include <stack>
            #include <string>
            #include <unordered_map>
            #include <unordered_set>
            #include <utility>
            #include <vector>
            using namespace std;
             
            typedef long long ll;
            typedef long double ld;
            #define int ll
            #define double ld
            #define pb push_back
            #define mp make_pair
            #define REP(i,n) for (int i = 0; i < n; i++)
            #define loop(i,n) for (int i = 0; i < n; i++)
            #define FOR(i,a,b) for (int i = a; i < b; i++)
            #define REPD(i,n) for (int i = n-1; i >= 0; i--)
            #define FORD(i,a,b) for (int i = a; i >= b; i--)
            #define remax(a,b) a = max(a,b)
            #define remin(a,b) a = min(a,b)
            #define mem(a, b) memset(a, b, sizeof a)
            #define append push_back
            #define all(v) v.begin(),v.end()
            #define F first
            #define S second
            #define print(x) cout << (x) << endl
            #define PRECISION(x) cout << fixed << setprecision(x)
            #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
            
            const double PI=acos(-1);
            const int MOD = 1000000007;
            const int FMOD = 998244353;
            const double eps = 1e-9;
             
            mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
 
signed main(){

	FAST_IO;
	
	int k,a,b;
	cin>>k>>a>>b;
	int flag=0;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK";
			flag=1;
			break;
		}
	}
	if(!flag)
	{
		cout<<"NG";
	}
}
			

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

int main(){
  int X,A,B,C;
  cin>>A>>B>>C>>X;
  int ans = 0;
  for(int i = 0;i<=A;i++){
    for(int j = 0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(i*500+j*100+k*50==X)ans++;
      }
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

const int N = 3e5 + 5000;

int main()
{
#ifdef ONLINE_JUDGE
#else
    // freopen("r.txt", "r", stdin);
    // freopen("w.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    long long x, y, z;

    cin >> x >> y >> z;
    if (z - x - y <= 0)
        cout << "No";
    else {
        z = (z - x - y) * (z - x - y);
        if (z > 4 * x * y)
            cout << "Yes";
        else
            cout << "No";
    }
    return 0;
}

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

using namespace std;

#define MAX 110
#define INF (1<<29)
typedef pair<int, int> pii;

struct Edge {
    int to, cost;
    Edge (int to, int cost) : to(to), cost(cost) {}
};

int main()
{
    int N, M, P;
    while (cin >> N >> M >> P, N) {
        int d[MAX][MAX];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = INF;
            }
            d[i][i] = 0;
        }
        
        vector<Edge> G[MAX];
        
        int a, b, c;
        for (int i = 0; i < M; i++) {
            cin >> a >> b >> c;
            d[a][b] = d[b][a] = c;
            G[a].push_back(Edge(b, c));
            G[b].push_back(Edge(a, c));
        }

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

        priority_queue<pii> Q;
        Q.push(pii(d[0][N-1], N-1));
        
        vector<bool> visited(MAX, 0);
        visited[N-1] = 1;

        vector<double> cnt(MAX, 0);
        cnt[N-1] = 1;
        
        while (!Q.empty()) {
            pii p = Q.top(); Q.pop();
            int v = p.second;
            for (int i = 0; i < (int)G[v].size(); i++) {
                Edge &e = G[v][i];
                if (d[0][e.to] + e.cost == d[0][v]) {
                    cnt[e.to] += cnt[v];
                    if (!visited[e.to]) {
                        visited[e.to] = 1;
                        Q.push(pii(d[0][e.to], e.to));
                    }
                }
            }
        }

        priority_queue<pii, vector<pii>, greater<pii>> Q2;
        Q2.push(pii(0, 0));

        vector<bool> visited2(MAX, 0);
        visited2[0] = 1;

        double dp[MAX] = {};
        dp[0] = 1;
        
        while (!Q2.empty()) {
            pii p = Q2.top(); Q2.pop();
            int v = p.second;
            for (int i = 0; i < (int)G[v].size(); i++) {
                Edge &e = G[v][i];
                if (visited[e.to] && d[0][v] + e.cost == d[0][e.to]) {
                    dp[e.to] += dp[v] * cnt[e.to] / cnt[v];                    
                    if (!visited2[e.to]) {
                        visited2[e.to] = 1;
                        Q2.push(pii(d[0][e.to], e.to));
                    }
                }
            }
        }

        int child;
        for (int i = 0; i < P; i++) {
            cin >> child;
            printf("%.10f\n", dp[child]);            
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3268
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	LL N;
	cin>>N;
	int x=1;
	LL x2=1;
	while (true){
		LL X22=x2;
		x2=x*x;
		if (x2==N){
			cout<<N<<endl;
			return 0;
		}else if (x2>N){
			cout<<X22<<endl;
			return 0;
		}
		x++;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct {
  int node;
  int p;
  int type;
  int left;
  int right;
  int a;
} Node;

Node T[100000];
int A[100000];

int depth(int count,int p){
  count++;
  if(T[p].p == -1) return count;
  depth(count,T[p].p);
}

int main(){
  int n,i,j,k,l,m;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    T[i].a = 0;
    T[i].right = T[i].left = -1;
  }

  for(i = 0;i < n;i++){
    scanf("%d",&j);
    T[j].node = j;
    T[j].type = 2;
    scanf("%d",&k);
    if(k) T[j].type = 1;
    for(l = 0;l < k;l++){
      scanf("%d",&m);
      if(l == 0) T[j].left = m;
      A[l] = m;
      T[m].p = j;
      T[m].a = 1;
      if(l) T[A[l-1]].right = A[l];
    }
  }

  for(i = 0;i < n;i++){
    if(T[i].a == 0){
      T[i].p = -1;
      T[i].type = 0;
    }
  }

  for(i = 0;i < n;i++){
    k = 0;
    printf("node %d: parent = %d, depth = %d, ",T[i].node,T[i].p,depth(-1,T[i].node));
    if(T[i].type == 0) printf("root, ");
    else if(T[i].type == 1) printf("internal node, ");
    else printf("leaf, ");
    printf("[");
    for(j = T[i].left;j != -1;j = T[j].right){
        if(k) printf(", ");
        printf("%d",T[j].node);
        k++;
    }
    printf("]\n");
  }

  return 0;
}



Measured memory_bytes: 4456
#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() {
  ll n, k;
  cin >> n >> k;
  ll ans = k;
  rep(i, n-1) ans *= k-1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,m,v,p;
	std::cin >> n >> m >> v >> p;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::sort(a.rbegin(),a.rend());
	// last instance of a[i]
	std::map<int,int> map;
	rep(i,n) map[a[i]] = i;
	std::map<int,int> map2;
	for(int i=n-1;i>=0;i--) map2[a[i]] = i;
	// binary search
	int l=-1,r=n;
	while(r-l>1) {
		int mid1 = (r+l)/2;
		int mid = map[a[mid1]];
		debug(l,r,mid1);
		if(mid>=r) { r=mid1; continue; }
		if(map2[a[mid1]]<=l) { l=mid1; continue; }
		int b = n-mid; int rem = (v-b-p+1)*m;
		if(p>map2[a[mid1]]) { l=mid1; continue; }
		int sum = 0;
		for(int i=p-1;i<mid;i++) {
			int x = a[mid]+m-a[i];
			if(x<0) { goto right; }
			sum+=std::min(m,x);
		}
		debug(a,sum,rem);
		if(sum<rem) { right:; r = mid1; debug(2); continue; }
		debug(n);
		l=mid1;
	}
	print(r);

	return 0;
}


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

int main()
{
    int A, B, C, D;

    cin >> A >> B >> C >> D;

    if (A + B < C + D)
    {
        cout << "Right" << endl;
    }
    else if (A + B > C + D)
    {
        cout << "Left" << endl;
    }
    else
    {
        cout << "Balanced" << endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;

#define sorted(vector) sort(vector.begin(),vector.end())
#define vmin(vector) *min_element(vector.begin(),vector.end())
#define vmax(vector) *max_element(vector.begin(),vector.end())
#define vsum(vector) accumulate(vector.begin(),vector.end(),0)
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())

//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n;
    cin>>n;
    L a(n,0);
    for(int i=0  ;i<n  ;i++){
        cin>>a[i];
    }
    long long pre=a[0];
    long long ans=0;
    L l;
    l.push_back(0);
    for(int i=1  ;i<n  ;i++){
        if (a[i]<=pre){
            ans++;
            pre=a[i];
            l.push_back(ans);
        }else{
            pre=a[i];
            ans=0;
        }
    }
    cout<<vmax(l)<<endl;
}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main(){
	ll h, w, n; cin >> h >> w >> n;
	map<P, ll> mp;
	for(int i = 0; i < n; ++i){
		ll a, b; cin >>a >> b;
		--a; --b;
		for(ll j = -2; j <=0 ; ++j){
			for(ll k = -2; k <=0; ++k){
				if(j+a<0 ||j+a+2>=h || k+b<0 || k+b+2>=w){continue;}
				++mp[{j+a, k+b}];
            }
        }
    }
    vector<ll> a(10);
    ll count=0;
    for(auto it : mp){
    	++a[it.second];
        ++count;
    }
    a[0]=((h-2)*(w-2)-count);
    
    for(int i = 0; i < 10; ++i){
    	cout << a[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 56448
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;



void main() {
    int N, M;
    scan(N, M);

    auto s = new int[](M);
    auto c = new int[](M);
    foreach (i ; 0 .. M) {
        scan(s[i], c[i]);
        s[i]--;
    }

    foreach (num ; 0 .. 10^^N) {
        auto ns = num.to!string;

        if (ns.length != N) {
            continue;
        }
        
        bool ok = true;

        foreach (i ; 0 .. M) {
            debug {
                writefln("%s, %s", ns[s[i]], c[i]);
            }
            if (ns[s[i]] - '0' != c[i]) {
                ok = false;
                break;
            }
        }

        if (ok) {
            writeln(ns);
            return;
        }
    }

    writeln(-1);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
#include<iostream>

using namespace std;

#define PII pair<int,int>
#define PPI pair<int,PII>

#define INF 1000000000

int c;	//øÌ	   1 <= c <=    10
int n;	//¬Ì		   2 <= n <=   100
int m;	//oXÌHü	   1 <= m <=   500
int s,g;//X^[gAS[n_
//int cost[512][512];		//[i][j]Åi©çjÖÌRXg
vector<PII> cost[512];		//firstªto secondªRXg

int d[128][16];

priority_queue< PPI, vector<PPI>, greater<PPI> > Q;
//first ÅZ£ ,second.first ¸_,second.second øðgÁ½


void dijkstra(int s){
	for(int i = 0; i < 128; i++){
		for(int j = 0; j < 16; j++){
			d[i][j] = INF;
		}
	}
	
	d[s][0] = 0;
	
	Q.push(PPI(0,PII(s,0)));
	
	while( !Q.empty() ){
		PPI ppi = Q.top();
		Q.pop();
		int v = ppi.second.first;
		int ca = ppi.second.second;
		
		if( d[v][ca] < ppi.first )continue;
		
		for(int i = 0; i < cost[v].size(); i++){
			PII a = cost[v][i];
			if(d[a.first][ca] > d[v][ca] + a.second ){
				d[a.first][ca] = d[v][ca] + a.second;
				Q.push(PPI(d[a.first][ca],PII(a.first,ca)));
			}
			if(ca < c){
				if(d[a.first][ca+1] > d[v][ca] + a.second/2 ){
					d[a.first][ca+1] = d[v][ca] + a.second/2;
					Q.push(PPI(d[a.first][ca+1],PII(a.first,ca+1)));
				}
			}
		}
	}
}


int main(void){
	
	while(scanf("%d%d%d%d%d", &c, &n, &m, &s, &g) && n != 0){
		int from, to, cos;
		int ans = INF;
		for(int i  =0; i < m; i++){
			scanf("%d%d%d", &from, &to, &cos);
			cost[from].push_back(PII(to,cos));
			cost[to].push_back(PII(from,cos));
		}
		
		dijkstra(s);
		
		for(int i = 0; i <= c; i++){
			ans = min(d[g][i],ans);
		}
		for(int i = 0; i < 512; i++){
			cost[i].clear();
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	arr := scanArrayInt()
	n, k, q := arr[0], arr[1], arr[2]
	as := make([]int, q)
	for i := 0; i < q; i++ {
		as[i] = func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
	}
	if k > q {
		for i := 0; i < n; i++ {
			fmt.Println("Yes")
		}
		return
	}
	points := map[int]int{}
	for i := 0; i < q; i++ {
		points[as[i]-1]++
	}
	for i := 0; i < n; i++ {
		if points[i] == 0 {
			fmt.Println("No")
			continue
		}
		if q-k < points[i] {
			fmt.Println("Yes")
			continue
		}
		fmt.Println("No")
	}
}
func scanArrayInt() []int {
	var ret = []int{}
	stdin.Scan()
	for _, s := range strings.Split(stdin.Text(), " ") {
		i, _ := strconv.Atoi(s)
		ret = append(ret, i)
	}
	return ret
}

Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int get() { int r; cin >> r; return r; }
int a[20][20];
signed main() {
	int n = get(), ans = 0;
	for1(i, n) {
		int k = i;
		while (k >= 10)k /= 10;
		a[k][i % 10]++;
	}
	for1(i, 9)for1(j, 9)ans += a[i][j] * a[j][i];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    long city[6] = {0};
    long v[5] = {0};
    long n;
    cin >> n;
    cin >> v[0];
    cin >> v[1];
    cin >> v[2];
    cin >> v[3];
    cin >> v[4];

    long time = ceill((double)n/(double)min(min(min(min(v[0],v[1]),v[2]),v[3]),v[4])) + 4;
    cout << time << endl;
    return 0;
}


Measured memory_bytes: 256
//  IT'S NEVER TOO LATE...

		    #include <bits/stdc++.h>
			#include <complex>
		    #define ll long long

			#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
			#define forn(i, n) fore(i, 0, n)
			#define fori(i, l, r) fore(i, l, (r) + 1)
			#define sz(v) int((v).size())
			#define all(v) (v).begin(), (v).end()
			#define pb push_back
			#define mp make_pair
		    #define ff first
		    #define ss second
			#define inf 1e9
		    
			#define C complex<int>
			#define X real()
			#define Y imag()

		    using namespace std; 

		    const double PI = atan(1)*4;


		    bool isprime(int n)
		    {
		        for(int i=2;i*i<=n;i++)
		            if(n%i==0)
		                return false;
		        return true;
		    }
		     
		    bool comp(pair<int,int> a, pair<int,int> b)
		    {
		    	return b.ff < a.ff ;
		    }

		    int modpow(int b,int p,int m)
		    {
		    	if(p==0) return 1%m;
		    	if(p%2) return (b*modpow(b,p-1,m))%m;
		    	int u=modpow(b,p/2,m);
		    	return (u*u)%m;
		    }

		    vector<int> ar[100005];
		    int vis[100005],from[100005];
		    double dis[100005];
		    
		     
		/*    void dikstra(int s,int n)
		    {
		    	forn(i,n+3)
		    	{
		    		dis[i]=inf;
		    		vis[i]=0;
		    		from[i]=-1;
		    	}

		    	dis[s]=0;
		    	priority_queue<pair<int,int>> q;
		    	q.push({0,s});
		    	from[s]=s;

		    	while(!q.empty())
		    	{
		    		pair<int,int> a;
		    		a=q.top();
		    		q.pop();
		    		//cout<<a.ss<<" ";

		    		if(vis[a.ss]) continue;
		    		vis[a.ss]=1;

		    		for(pair<int,int> b:ar[a.ss])
		    		{
		    			if(dis[b.ff]>dis[a.ss] + b.ss)
		    			{
		    				dis[b.ff]=dis[a.ss] + b.ss;
		    				from[b.ff]=a.ss;
		    				q.push({-dis[b.ff],b.ff});
		    			}
		    		}
		    	}
		    }*/

		    set<int> fact(int n)
		    {
		    	set<int> s;
		    	for(int i=1;i*i<=n;i++)
		    	{
		    		if(n%i==0)
		    		{
		    			s.insert(i);
		    			s.insert(n/i);
		    		}
		    	}
		    	return s;
		    }

		    int main()
		    {
		    //	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		     
		    	#ifndef ONLINE_JUDGE
		        freopen("input.txt","r", stdin);
		        freopen("output.txt", "w", stdout);
		        #endif
		     
		    	int t=1;
		    	//cin>>t;
		    	
		    	while(t--)
		    	{
		    		int x;
		    		cin>>x;

		    		fori(i,-150,150)
		    		{
		    			fori(j,-150,150)
		    			{
		    				if((ll)pow(i,5) - (ll)pow(j,5) == x)
		    				{
		    					cout<<i<<" "<<j;
		    					return 0;
		    				}
		    			}
		    		}	
		    	}

		    	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

		    	return 0;
		    }
		    				//              NOW IT'S TIME TO WAKE UP...

Measured memory_bytes: 6436
// インクルード
#include <bits/stdc++.h>

// 名前空間省略
using namespace std;

// メイン関数
int main()
{
    // 標準入出力　高速化
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int k;
    string s;
    cin >> k;
    cin >> s;

    if(s.length() <= k) cout << s << endl;
    else{
        cout << s.substr(0,k)+"..." << endl;
    } 
}


Measured memory_bytes: 3660
import math
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

iter = list(itertools.permutations(range(1,n+1)))

a = 0
b = 0

for i in range(math.factorial(n)):
    if iter[i] == p:
        a = i
    if iter[i] == q:
        b = i

print(abs(a-b))


Measured memory_bytes: 8052
#include "iostream"
#include "algorithm"
using namespace std;
int main()
{
	int n, x;
	cin >> n >> x;
	while (n!=0||x!=0)
	{
		int ans = 0;
		for (int i = 1; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				for (int k = j + 1; k <= n; k++)
				{
					if (i + j + k == x)
					{
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
		cin >> n >> x;
	}
}


Measured memory_bytes: 3076
// ABC166C - 

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> H(N);

	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	vector<int> A(M);
	vector<int> B(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
	}

	vector<bool> ans(N);
	for (int i = 0; i < N; i++) {
		ans[i] = true;
	}

	for (int i = 0; i < M; i++) {
		if (H[A[i]-1] > H[B[i]-1]) {
			ans[B[i]-1] = false;
		} else if (H[A[i]-1] < H[B[i]-1]) {
			ans[A[i]-1] = false;
		} else {
			ans[A[i]-1] = false;
			ans[B[i]-1] = false;
		}
	}

	int t = 0;
	for (int i = 0; i < N; i++) {
		if (ans[i]) {
			++t;
//			cout << i + 1 << " ";
		}
	}

	cout << t << endl;

	return 0;
}


Measured memory_bytes: 4512
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		//入力
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for(int i = 0; i < n; i++) h[i] = sc.nextInt();
		sc.close();

		//処理
		String ans = "Yes";
		for(int i = n-2; i >= 0; i--){
			if(h[i] > h[i+1]){
				h[i]--;
			}
		}
		for(int i = 0; i < n-1; i++){
			if(h[i] > h[i+1]) ans = "No";
		}
		
		//出力
		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 53188
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cassert>
using namespace std;
#define N 200005
#define ll long long
#define INF 0x3f3f3f3f
char s[N];
int main() 
{
    //freopen("prefix.in","r",stdin);
    //freopen("prefix.out","w",stdout);
	scanf("%s",s+1);
	string last,now="";
	int ans=1,len=strlen(s+1);
	last+=s[1];
	for(int i=2;i<=len;)
	{
		now+=s[i];
		//如果出现这种情况 应该是只有一个字符
		if(i==len&&now==last) break; 
		while(now==last)
		{
			now+=s[++i];
			if(i>len) break;
		}
		last=now,now="";
		i++,ans++;
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

    if (mp.find(0) != mp.end()){
        if (mp.size() == 1){
            cout << "Yes" << endl;
            return 0;
        }else if (mp.size() == 2 && mp[0] * 3 == n){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }else{
        if (mp.size() == 3){
            int ans = 0;
            for(auto m: mp){
                if (m.second * 3 != n){
                    cout << "No" << endl;
                    return 0;
                }
                ans ^= m.first;
            }
            if (ans == 0) cout << "Yes" << endl;
            else cout << "No" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 8244
#include <bits/stdc++.h>
using namespace std;
const int mn=3010;
int a,b,c,d,e,f,a1,a2;
bool fo=0;
bool v1[mn],v2[mn];
int main() {
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	for (int i=0;i*100*a<=f;i++)
		for (int j=0;i*100*a+j*100*b<=f;j++)
			v1[i*100*a+j*100*b]=1;
	for (int i=0;i*c<=f;i++)
		for (int j=0;i*c+j*d<=f;j++)
			v2[i*c+j*d]=1;
	for (int i=0;i<=f;i++) {
		if (!v1[i]) continue;
		for (int j=0;j+i<=f;j++) {
			if (!v2[j]) continue;
			if (i/100*e>=j) {
				if (!fo
				||(100*j*(a1+a2)>=(i+j)*100*a2)) {
					a1=i; a2=j;
					fo=1;
				}
			}
		}
	}
	printf("%d %d\n",a1+a2,a2);
	return 0;
}

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

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

    vector<long long> a;
    long long sum = 0;
    for(long long i = 0; i < n; i++){
        long long x;
        cin >> x;
        a.push_back(x);
        sum += x;
    }

    long long now = 0;
    long long min_delta = sum - now;
    long long min_length1;
    long long min_length2;
    for(long long i = 0; i < n; i++){
        now += a[i];
        if(min_delta > abs(sum-2*now)){
            min_delta = abs(sum-2*now);
            min_length1 = now;
            min_length2 = sum - now;
        }
    }

    cout << abs(min_length1-min_length2) << endl;

    return 0;


}

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

int time(int x){
    return (x+9)/10*10;
}


int main(void) {
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int sum = time(a)+time(b)+time(c)+time(d)+time(e);
    sum = sum-max({time(a)-a,time(b)-b,time(c)-c,time(d)-d,time(e)-e});
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	char a;
	scanf("%c", &a);
	if (a >= 65 && a <= 90)
	{
		printf("A");
	}
	else if (a >= 97 && a <= 122)
	{
		printf("a");
	}
	return 0;
}

Measured memory_bytes: 1576
#include <iostream>
#include <algorithm>

#define rep(i, first, to) for(ll i = first; i < to; ++i)
#define REP(i, first, to) for(ll i = first; i <= to; ++i)

using namespace std;
typedef long long ll;

int data[100];
int n;
int sum = 0;
int main() {
	cin >> n;
	rep(i, 0, n) {
		cin >> data[i];
	}
	sort(data, data + n);
	rep(i, 0, n) {
		sum = sum + data[i];
	}
	int num = 0;
	rep(i, 0, n) {
		if (data[i] % 10 != 0) {
			num = data[i];
			break;
		}
	}
	if (num == 0) {
		cout << 0 << endl;
	}else if (sum % 10 == 0) {
		cout << (sum - num) << endl;
	} else {
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
import collections

#文字列を一文字ずつ取得したいとき
def inputStrOnebyOne():
    s = list(input())
    return s

#整数を一つずつリストに入れる
def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a

def main():
    a = int(input())
    b = int(input())
    if(a%500<=b):
        print("Yes")
    else:
        print("No")
        
if __name__=='__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
		int n;
		cin>>n;
		int tmp;
		int ans=0;
		for(int i=0;i<n;++i)
		{
				cin>>tmp;
				if((tmp&1)&&((i+1)&1))
						++ans;
		}
		cout<<ans;




		return 0;
}



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

using namespace std;

int main() {
  int x[5],ans = 0;
  for(int i = 0; i < 5; i++) 
    cin >> x[i];

  for(int i = 0; i < 5; i++) {
    if(x[i] == 0) 
      ans = i+1;
  }
  cout << ans << endl;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  string S, T;
  cin >> S >> T;
  if(S + T.back() == T) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n; string s;
    cin >> n >> s;
    int a[n];
    rep(i, n){
        if(s[i] == 'R') a[i] = 1;
        if(s[i] == 'G') a[i] = 2;
        if(s[i] == 'B') a[i] = 3;
    }

    lint sum[4][n+1];
    rep(c, 4)rep(i, n+1) sum[c][i] = 0;
    rep(i, n) ++sum[a[i]][i+1];
    rep(c, 4)rep(i, n) sum[c][i+1] += sum[c][i];

    lint ans = 0;
    rep(i, n)For(k, i+2, n)if(a[i] != a[k]){
        int t = a[i]^a[k];
        ans += sum[t][k] - sum[t][i+1];
        if((k+i)%2 == 0 && a[(k+i)/2] == t) --ans;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 3800
n,k = map(int,input().split())
s = list(input())
k -= 1
mo = s.pop(k)

if mo == 'A':
    s.insert(k,'a')
elif mo == 'B':
    s.insert(k,'b')
else:
    s.insert(k,'c')

s= "".join(s)
print(s)

Measured memory_bytes: 3060
require 'prime'

n = gets.to_i

if Prime.prime?(n)
  puts n - 1
else
  ans = 0
  Math.sqrt(n).to_i.downto(1) do |i|
    quo, rem = n.divmod(i)
    break ans = (i - 1) + (quo - 1) if rem.zero?
  end
  puts ans
end


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

int main() {
  string s;
  cin >> s;
  if(s[0] == s[1] || s[1] == s[2] || s[0] == s[2]) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

// d[i] .. bit representation of boxes opened by a[i].
ll d[1005];

// dp[i+1][j] .. minimum const of state j by using a[0]..a[i]. j is the bit representation of state.
// dp[i+1][j | d[i]] = min(dp[i][j | d[i]], dp[i][j] + a[i])
ll dp[1005][5005]; // 2 ** 12 ~ 4e3

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;

  vector<int> a(M);
  vector<int> b(M); // the number of boxes
  vector< vector<int> > c(M);
  rep(i, M) {
    cin >> a[i] >> b[i];
    c[i].resize(b[i]);
    rep(j, b[i]) {
      cin >> c[i][j];
      --c[i][j]; // 0-indexed
    }
  }
  // rep(i, M) {
  //   rep(j, b[i]) {
  //     cout << c[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  rep(i, M) {
    rep(j, b[i]) {
      d[i] |= 1LL << (N - 1 - c[i][j]); // c[i][j] is from 0 to N - 1.
    }
  }
  // For Debug
  // cout << "d: " << endl;
  // rep(i, M) {
  //   cout << d[i] << endl;
  // }

  ll max_s = (1LL << N) - 1; // If N is 3, max_s is 111. The max value of representatable state.

  // Initialize dp.
  rep(i, M + 1) {
    rep(j, max_s + 1) {
      dp[i][j] = INF;
    }
  }
  // cout << dp[M-1][max_s] << endl;

  // Initialize dp.
  dp[0][0] = 0;
  // cout << "dp["<<0<<"]["<< d[0] <<"]: " << dp[0][d[0]] << endl;
  for (int i = 0; i < M; ++i) {
    rep(j, max_s + 1) {
      dp[i+1][j] = dp[i][j];
    }
    rep(j, max_s + 1) {
      // cout << "prev:" << endl;
      // cout << "dp["<<i<<"]["<< (j | d[i]) <<"]: " << dp[i][j | d[i]] << endl;
      // cout << "dp["<<i<<"]["<<j<<"] + a["<<i<<"]: " << dp[i][j] + a[i] << endl;
      dp[i+1][j | d[i]] = min(dp[i+1][j | d[i]], dp[i][j] + a[i]);
      // cout << "post:" << endl;
      // cout << "dp["<<i+1<<"]["<< (j | d[i]) <<"]: " << dp[i+1][j | d[i]] << endl;
    }
  }

  ll ans = dp[M][max_s];
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 39296
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
 
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 //   freopen("./input.txt","r",stdin);
 //   freopen("./output.txt","w",stdout);
    string a;
    cin>>a;
    int ct[26]={0};
    for(int i=0;i<a.size();i++)
    {
        ct[a[i]-'A']++;
    }
    for(int i=0;i<26;i++)
    {
        if(!(ct[i]==2||ct[i]==0))
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

}

Measured memory_bytes: 256