akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<ll> cnt(4, 0);
	REP(i, 3) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		cnt[a]++;
		cnt[b]++;
	}
	int odd = 0;
	REP(i, 4) if(cnt[i] % 2) odd++;
	if(odd == 2) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
using namespace std;
const int dx[] = { -1 ,0 };// U , L 
const int dy [] = { 0 ,-1 };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000*1000+ 5   ;
const int MAXN = 1000000 ;
const int INF = INT_MAX ;
int main ( ){
fast_io();
ll n ;
cin >> n ;
ll res = n / 2 ;
if(n & 1 )
res++;
cout << res;


return 0 ;
 
}


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

int main() {

  int N;
  string S, T;
  cin >> N >> S >> T;

  for(int i=0; i<N; i++) {
    cout << S.at(i) << T.at(i);
    if(i==N-1) cout << endl;
  }
  
}

Measured memory_bytes: 3612
#include <stdio.h>

int main(void){

	long long int N;
	scanf("%lld", &N);

	long long int i, mod = 0;
	long long int ans = 1;

	
	for(i = 0; i < N; i++){
		
		mod = ans % 1000000007;
		ans = mod * ((i + 1) % 1000000007);
		
		while(ans >= 1000000007){
			ans = ans % 1000000007;

			if(ans < 1000000007){
				break;
			}
		}
	}	

	printf("%lld\n", ans);
	return 0;

}

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

using namespace std;

const int z = 1e9+7;
const int C = 2e5;

int main() {
    int n;
    cin >> n;
    int last[C];
    fill(last, last+C, -1);

    int dp[n+1];
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        int c;
        cin >> c;
        c--;

        dp[i] = dp[i-1];
        if (last[c] != -1 && last[c] != i - 1) {
            dp[i] += dp[last[c]];
            if (dp[i] >= z) {
                dp[i] -= z;
            }
        }

        last[c] = i;
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<cstring>
//#define Mfc_Tanzim
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first
#define ss second
#define all(v) (v.begin(), v.end())
#define pi acos(-1.0)
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define bug(a) cerr << #a << " : " << a << endl
#define pq dp
using namespace std;
const ll mx = 4444444444;

ll posx[] = {1,-1, 0, 0};
ll posy[] = {0, 0, 1,-1};

int main()
{
    FastRead

#ifdef Mfc_Tanzim
    freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
#endif /// Mfc_Tanzim

    ll t=1, n, k, m, a, b, c, d;
    //cin >> t;

    while(t--){
              cin >> n;
              cout << (n>=30? "Yes" : "No") << endl;
    }
    return 0;
}


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

int main()
{
    string s;
    cin>>s;
  
   bool j = false;
   
   if(s[2]==s[3])
   {
      if(s[4]==s[5])
      {
          j = true;
      }
   }
   
   if(j)
     cout<<"Yes"<<endl;
  else
     cout<<"No"<<endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////


int main() {

	int N;
	string S;
	cin >> N;
	cin >> S;

	bool Num[10][10][10] = { false };

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				int target = i;
				bool ib = false;
				bool ij = false;
				for (int s = 0; s < N; s++) {
					if (target == S[s] - '0') {
						if (ib == false) {
							target = j;
							ib = true;
							continue;
						}
						if (ij == false) {
							target = k;
							ij = true;
							continue;
						}
						Num[i][j][k] = true;
						break;
					}

				}
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				if (Num[i][j][k])ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string str;
    cin >> str;

    string s = str;
    REP(i, s.length()){
        if(s[i] == '?') s[i] = 'D';
    }

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3928
def main():
  s = input()
  q = int(input())
  de = collections.deque(s)
  rev = True
  for _ in range(q):
    query = input().split()
    if len(query) == 1:
      rev = False if rev else True
      continue
    typ, f, c = query
    if rev:
      if f == '1':
        de.appendleft(c)
      if f == '2':
        de.append(c)
    else:
      if f == '1':
        de.append(c)
      if f == '2':
        de.appendleft(c)
  ans = list(de)
  if rev is False:
    ans.reverse()
  print(''.join(ans))
      

import math
import fractions
import itertools
import collections
main()

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

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

    for (size_t i = 0; i < b.length(); i++)
    {

        char in = b[i];
        if (in == 'A')
        {
            cout << 'T';
        }
        else if (in == 'C')
        {
            cout << 'G';
        }
        else if (in == 'G')
        {
            cout << 'C';
        }
        else if (in == 'T')
        {
            cout << 'A';
        }
    }
    cout << endl;

    return 0;
}


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

int n;
int A, B, C;
ll Now;


int main(){
    scanf("%d",&n);
    bool is_B = false;
    for(int i = 1; i <= n; i++){
        scanf("%lld", &Now);
        if(Now % 2 == 0){
            if(Now % 4 == 0) A++;
            else is_B = true;
        }
        else C++;
    }
    if(is_B) C++;
    if(A - C >= -1) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N, M;
	cin >> N >> M;
	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}
	vector<long long>X(M);
	for (long long i = 0; i < M; i++) {
		cin >> X.at(i);
	}
	sort(X.begin(), X.end());
	long long ans = X.at(M - 1) - X.at(0);
	vector<long long>Distance_point(M - 1);
	for (long long i = 0; i < M - 1; i++) {
		Distance_point.at(i) = X.at(i + 1) - X.at(i);
	}
	sort(Distance_point.begin(), Distance_point.end(), greater<long long>());
	for (long long i = 0; i < N - 1; i++) {
		ans -= Distance_point.at(i);
	}
	cout << ans << endl;
}
 

Measured memory_bytes: 1792
#include <stdio.h>

void magic(int i,int n,int *x,int *y,int table[n][n]);

int main(){
	int i,j,n;
	int x,y;
	
	while(scanf("%d",&n)!=EOF){
		if(n == 0) break;
		
		int table[n][n];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++) table[i][j] = 0;
		}
		
		x = n/2+1;
		y = n/2; 
		for(i=1;i<=n*n;i++){
			magic(i,n,&x,&y,table);
			x += 1;
			y += 1;
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				printf("%4d",table[i][j]);
			}
			printf("\n");
		}
		
	}
	
	return 0;
}

void magic(int i,int n,int *x,int *y,int table[n][n]){
	
		if(*x == n && *y == n){
			*x = 0;
			*y = 0;
			magic(i,n,x,y,table);
		}else if(*x == n){
			*x = 0;
			magic(i,n,x,y,table);
		}else if(*y == n){
			*y = 0;
			magic(i,n,x,y,table);
		}else if(*y == -1){
			*y = n-1;
			magic(i,n,x,y,table);
		}else if(table[*x][*y]!=0){
			*x += 1;
			*y -= 1;
			magic(i,n,x,y,table);
		}else{
			table[*x][*y] = i; 
		}

}

Measured memory_bytes: 616
from collections import defaultdict

N = int(input())
S = input()

d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i)
ans = 0

for i in range(1000):
    T = '%03d' % i
    j = -1
    for t in T:
        flag = True
        for k in d[t]:
            if k > j:
                flag = False
                j = k
                break
        if flag:
            break
    if not(flag):
        ans += 1

print(ans)

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

using namespace std;

const int MOD = 1000000007;

int main()
{
	char A[64], B[64], C[64];

	while (scanf("%s", A) && A[0] != '0'){
		scanf("%s", B);
		scanf("%s", C);

		int dp[64][10][10][2];
		memset(dp, 0, sizeof(dp));

		int L = strlen(A);

		for (int i = (L == 1); i <= 9; i++){
			for (int j = (L == 1); j <= 9; j++){
				if ((A[L - 1] == '?' || A[L - 1] == i + '0') &&
					(B[L - 1] == '?' || B[L - 1] == j + '0') &&
					(C[L - 1] == '?' || C[L - 1] == ((i + j) % 10) + '0')){
						dp[L - 1][i][j][0] = 1;
				}
			}
		}

		for (int d = L - 2; d >= 0; d--){
			for (int i = (d == 0); i <= 9; i++){
				for (int j = (d == 0); j <= 9; j++){
					if ((A[d] == '?' || A[d] == i + '0') &&
						(B[d] == '?' || B[d] == j + '0')){
						for (int k = 0; k <= 9; k++){
							for (int l = 0; l <= 9; l++){
								if (C[d] == '?' || C[d] - '0' == (i + j + (k + l) / 10) % 10){
									dp[d][i][j][(k + l) / 10] = (dp[d][i][j][(k + l) / 10] + dp[d + 1][k][l][0]) % MOD;
								}
								if (C[d] == '?' || C[d] - '0' == (i + j + (k + l + 1) / 10) % 10){
									dp[d][i][j][(k + l + 1) / 10] = (dp[d][i][j][(k + l + 1) / 10] + dp[d + 1][k][l][1]) % MOD;
								}
							}
						}
					}
				}
			}
		}

		int ans = 0;
		for (int i = 0; i <= 9; i++){
			for (int j = 0; i + j <= 9; j++){
				ans = (ans + dp[0][i][j][0]) % MOD;
				if (i + j + 1 <= 9) ans = (ans + dp[0][i][j][1]) % MOD;
			}
		}

		printf("%d\n", ans);
	}

	return (0);
}

Measured memory_bytes: 1192
#include <iostream>

using namespace std;
 
int main() {
    int h, w;
    
    cin >> h >> w;
    for(int j = 0 ; j < w + 2 ; j++) cout << "#";
    cout << "\n";
    for(int i = 0 ; i < h ; i++){
        string s;
        cin >> s;
        cout << "#" << s << "#" << endl;
    }
    for(int j = 0 ; j < w + 2 ; j++) cout << "#";
    cout << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1003][1003];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string x,y;
        cin>>x>>y;
        int len1=x.size();
        int len2=y.size();

        memset(a,0,sizeof(a));
        for(int i=0; i<len1; i++)
        {
            for(int j=0; j<len2; j++)
            {
                if(x[i]==y[j])
                {
                    a[i+1][j+1]=a[i][j]+1;
                }
                else a[i+1][j+1]=max(a[i][j+1],a[i+1][j]);
            }
        }
        cout<<a[len1][len2]<<endl;
    }

}



Measured memory_bytes: 7084
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	cnt := map[int]int{}
	for i := 1; i <= n; i++ {
		a := factorize(i)
		for num, e := range a {
			cnt[num] += e
		}
	}

	ans := 1
	for _, e := range cnt {
		ans = ans * (e + 1)%mod
	}
	fmt.Fprintln(wr, ans)
}

const mod = 1000000007

func factorize(n int) map[int]int {
	res := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			res[i]++
			n /= i
		}
	}
	if n != 1 {
		res[n] = 1
	}
	return res
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, K;
    cin >> N >> K;
    Vi ok(N);
    for (ll i = 0; i < K; i++) {
        ll d;
        cin >> d;
        for (ll j = 0; j < d; j++) {
            ll a;
            cin >> a;
            ok[a - 1] = 1;
        }
    }

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if (ok[i] == 0) ++ans;
    }

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

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

long long int min(long long int x, long long int y){
  long long int z;
  if(x < y){
    z = x;
  }else{
    z = y;
  }
  
  return z;
}

int main(){
  long long int win = 0;
  
  int n;
  scanf("%d", &n);
  
  long long int a[n+1];
  int i;
  for(i = 0; i < n+1; i++){
    scanf("%lld", &a[i]);
  }
  
  long long int b;
  for(i = 0; i < n; i++){
    scanf("%lld", &b);
    long long int tmp1 = min(b, a[i]);
    long long int tmp2 = min(a[i+1], b - tmp1);
    a[i+1] -= tmp2;
    win += (tmp1 + tmp2);
  }
  
  printf("%lld", win);
  
  return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int N, M;
	int L[100000], R[100000], min = 100000;
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d", &L[i]); scanf("%d", &R[i]);
		if (R[i] <= min) {
			min = R[i];
		}
	}
	sort(L, L + N,greater<int>());
	if (min - L[0] + 1 > 0) {
		printf("%d ", min - L[0] + 1);
	}
	else {
		printf("0");
	}
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 h, w, x, y;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32 "%" SCNi32, &h, &w, &x, &y);
  i32 ans = h * w - x * y * (h / x) * (w / y);
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> sum(n+1,0);
    for(int i = 0; i < n; i++){
        if(s[i]=='E')sum[i + 1] = sum[i] + 1;
        else sum[i + 1] = sum[i];
    }
    //rep(i,n+1) cout << sum[i];
    //cout << endl;
    int ans = INF;
    for(int leader = 0; leader < n; leader++){
        int count = 0;
        count = sum[leader] - sum[0];
        count = leader - count;
        count = count + sum[n] - sum[leader+1];
        ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1796
import heapq

n,m = list(map(lambda x: int(x), input().split()))

jobs = {}
for i in range(n):
    a,b = list(map(lambda x: int(x), input().split()))
    if a in jobs.keys():
        jobs[a].append(b)
    else:
        jobs[a] = [b]

# 貪欲解法
# 最終日から決める
ans = 0
day = m

possible_job = []
# heapqでjobを管理すれば現時点で最大の給与を得ることのできる仕事を容易に取り出せる
for i in range(m+1):
    if i in jobs.keys():
        for x in jobs[i]:
            heapq.heappush(possible_job, -1 * x)
    if len(possible_job)>0:
        day_work = heapq.heappop(possible_job)
        ans += -1 * day_work
    
print (ans)

Measured memory_bytes: 26468
#include<stdio.h>
int main(){
  int i,j,key,n,x,y;
  int a[100];

  scanf("%d",&n);
  for(y=0; y<n; y++){
    scanf("%d",&a[y]);
  }
  for(y=0; y<n; y++){
    if(y==n-1){
      printf("%d",a[y]);
    }
    else{
    printf("%d ",a[y]);
    }
    }
  printf("\n");
  
  for(i=1; i<n; i++){
    key=i;
  
    while((key>0)&&(a[key-1]>a[key])){
      j=a[key-1];
      a[key-1]=a[key];
      a[key]=j;
      

      key--;
    }
      for(x=0; x<n; x++){
	if(x==n-1){
	  printf("%d",a[x]);
	}
	else{
	printf("%d ",a[x]);
	}
      }
      
	printf("\n");
      
  }
  return 0;
}



Measured memory_bytes: 2144
import java.util.*;

public class Main {
    private class Point {
        long x, y;

        public Point(long x, long y) {
            this.x = x;
            this.y = y;
        }
    }

    private class Square {
        long xl, xr, yd, yu;

        public Square(Point p1, Point p2, Point p3, Point p4) {
            xl = Math.min(Math.min(Math.min(p1.x, p2.x), p3.x), p4.x);
            xr = Math.max(Math.max(Math.max(p1.x, p2.x), p3.x), p4.x);
            yd = Math.min(Math.min(Math.min(p1.y, p2.y), p3.y), p4.y);
            yu = Math.max(Math.max(Math.max(p1.y, p2.y), p3.y), p4.y);
        }

        public boolean isCheck(Point p) {
            return xl <= p.x && p.x <= xr && yd <= p.y && p.y <= yu;
        }

        public long getSize() {
            return (xr - xl) * (yu - yd);
        }
    }

    public void main(Scanner sc) {
        int n = sc.nextInt();
        int cntk = sc.nextInt();
        Point p[] = new Point[n];
        for (int i = 0; i < n; i++) {
            p[i] = new Point(sc.nextLong(), sc.nextLong());
        }

        long ans = Long.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                for (int k = j; k < n; k++) {
                    for (int l = k; l < n; l++) {
                        Square sq = new Square(p[i], p[j], p[k], p[l]);
                        int cnt = 0;
                        for (int m = 0; m < n; m++) {
                            if (sq.isCheck(p[m])) {
                                cnt++;
                            }
                        }
                        if (cnt >= cntk) {
                            ans = Math.min(ans, sq.getSize());
                        }
                    }
                }
            }
        }

        System.out.println(ans);
    }

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


Measured memory_bytes: 36820
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin>>h>>w;
    string s;
    ll masu[100][100],dp[100][100];
    rep(i,h){
        cin>>s;
        rep(j,w){
            masu[i][j]=0;
            if(s[j]=='#')masu[i][j]=1;
        }
    }

    rep(i,h){
        rep(j,w){
            dp[i][j]=INF;
            if(i==0&&j==0)dp[i][j]=0;
            if(i>0)chmin(dp[i][j],dp[i-1][j]+(masu[i][j]!=masu[i-1][j]?1:0));
                //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            if(j>0)chmin(dp[i][j],dp[i][j-1]+(masu[i][j]!=masu[i][j-1]?1:0));
            
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }
    }
    
    ans=dp[h-1][w-1];
    k=(ans+1)/2;
    if(ans%2==0&&masu[0][0]==1)k++;
    cout<<k<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
    #define sz(a) (int)(a).size()
     
    using namespace std;
     
    template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
    template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
    const int INF = 2e5+2;
    const long long hell = 998244353ll;
    

    int main(){
    	
    	ios_base::sync_with_stdio(0);cin.tie(0);
    	int a,b;
    	cin>>a>>b;
    	b = b-a;
    	if(b&1){
    	 	cout<<"IMPOSSIBLE"<<endl;
    	}else{
    	 	cout<<a+(b/2)<<endl;
    	}

    #ifdef LOCAL
        cout << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    #endif	
    	return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=10e5+10;
int a[maxn],dp[maxn];
int main(){
	int n,k;
	cin >> n >> k;
	for(int i =0;i<n;i++)
		cin >> a[i];
	sort(a,a+n);
	dp[0] = 0;
	int i = 1;
	while(i<a[0]){
		dp[i] = 0;
		i++;
	}

	for(int i=a[0];i<=k;i++){
		dp[i] = 0;
		for(int j =0;j<n;j++){
			if((i-a[j]>=0) && !dp[i-a[j]])
				dp[i]|=1;
		}
	}
	cout << (dp[k]?"First":"Second") << endl;

}


Measured memory_bytes: 2688
x, y = map(int, input().split())

ans = 10**18

if y - x >= 0:
    ans = min(ans, y-x)

x *= -1

if y - x >= 0:
    ans = min(ans, y-x+1)

x *= -1
y *= -1

if y - x >= 0:
    ans = min(ans, y-x+1)

x *= -1

if y - x >= 0:
    ans = min(ans, y-x+2)

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <vector>
#include <list>

using namespace std;
typedef long long llong;

int main(int argc, char *argv[])
{
    llong n;
    vector<int> vec;
    vector<int> s;
    int i;

    scanf("%lld", &n);

    n ++;
    for (i = 0; n != 0; n >>= 1, i++) {
        if (n%2 == 1) {
            vec.push_back(i);
        }
    }

    vector<int>::reverse_iterator it = vec.rbegin();
    i = 1;
    for (; i <= *it; i++) {
        s.push_back(i);
    }

    it++;
    for (; it != vec.rend(); it++, i++) {
        int j = 0;
        vector<int>::iterator it2;

        for(it2 = s.begin(); j < (*it); it2++, j++);
        s.insert(it2, i);
    }

    printf("%d\n", 2 * s.size());
    for (vector<int>::iterator it2 = s.begin(); it2 != s.end(); it2++) {
        printf("%d ", *it2);
    }
    for (i = 1; i <= s.size(); i++) {
        printf("%d ", i);
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 256
#include "stdio.h"

int main()
{
	//整数をグループ分けして配列に入れる
	int group1[7] = { 1,3,5,7,8,10,12 },
		group2[4] = { 4,6,9,11 },
		group3[1] = { 2 };

	//入力用の変数を宣言
	int x = 0, y = 0;

	//標準入力
	scanf("%d %d", &x, &y);

	//判定用の変数を宣言
	//それぞれ、グループ内にx,yと同じものがあるかどうかと、同じグループ内で両方一致があるかどうか
	int xOK = 0, yOK = 0, common = 0;

	//とりあえず、１つめのグループの要素と一致するかをそれぞれ見る
	for (int i = 0; i < 7; i++) {
		if (group1[i] == x)
			xOK = 1;
		if (group1[i] == y)
			yOK = 1;
	}

	//１つめのグループで両方一致しているか？
	if (xOK == 1 && yOK == 1)
		common = 1;



	//２つめのグループの要素と一致するかをそれぞれ見る
	xOK = 0;
	yOK = 0;
	for (int i = 0; i < 4; i++) {
		if (group2[i] == x)
			xOK = 1;
		if (group2[i] == y)
			yOK = 1;
	}

	//今見たグループで両方一致しているか？
	if (xOK == 1 && yOK == 1)
		common = 1;

	//３つめのグループの要素と一致するかをそれぞれ見る
	xOK = 0;
	yOK = 0;
	for (int i = 0; i < 1; i++) {
		if (group3[i] == x)
			xOK = 1;
		if (group3[i] == y)
			yOK = 1;
	}

	//今見たグループで両方一致しているか？
	if (xOK == 1 && yOK == 1)
		common = 1;


	//結果を出力する。
	if (common == 1)
		printf("Yes");
	else
		printf("No");

    return 0;
}



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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

div_list = make_divisors(n)

a = div_list[-1]
b = div_list[-2]
if n == a * a:
    print(a + a - 2)
else:
    print(a + b - 2)

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

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var r = new string[n, 3];
            for (int i = 0; i < n; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                for (int j = 0; j < 3; j++) r[i, j] = line[j];
            }
            getAns(r, n, m);
        }
    }
    static bool check(string r, string t)
    {
        for (int i = 0; i < 8; i++)
            if (r[i] != '?' && r[i] != t[i]) return false;
        return true;
    }
    static void getAns(string[,] r, int n, int m)
    {
        var oks = new List<string>();
        for (int i = 0; i < m; i++)
        {
            var s = Console.ReadLine().Trim();
            string[] line = s.Split(' ');
            var t1 = line[0];
            var t2 = line[1];
            var ok = false;
            for (int j = 0; j < n; j++)
            {
                if (r[j, 0] == "permit")
                {
                    if (check(r[j, 1], t1) && check(r[j, 2], t2)) ok = true;
                    //else ok = false;
                }
                else
                {
                    if (check(r[j, 1], t1) && check(r[j, 2], t2)) ok = false;
                }
            }
            if (ok) oks.Add(s);
        }
        Console.WriteLine(oks.Count());
        foreach (var x in oks) Console.WriteLine(x);
    }
}


Measured memory_bytes: 20512
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c,d;
	int score;
	int out=0;
	int n;
	cin>>n;
	while(n--){
		score=a=b=c=d=0;
		out=0;
		string e;
		while(out!=3){
			cin>>e;
			if(e=="HIT"){
				d=c;c=b;b=a;a=1;
				score+=d;d=0;	
			}else if(e=="HOMERUN"){
				score += a+b+c+1;
				a=b=c=0;
			}else{
				out++;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}

Measured memory_bytes: 1212
import java.util.*;
public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
			String s = sc.next();
			char  [] c = s.toCharArray();
				
			if(c[0] == c[1]) {
				System.out.println("Bad");
			}else if(c[1] == c[2]) {
				System.out.println("Bad");
			}else if(c[2] == c[3]){
				System.out.println("Bad");
			}else {
				System.out.println("Good");
			}			
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=998244353;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Union_Find_Tree{
	public:
	vi p,r,s;
	Union_Find_Tree(int n){
		p=r=vi(n);
		s=vi(n,1);
		for(int i=0;i<n;i++) p[i]=i;
	}
	int Par(int x){
		if(p[x]==x) return x;
		return p[x]=Par(p[x]);
	}
	int Size(int x){return s[Par(x)];}
	bool Unite(int x,int y){
		x=Par(x);
		y=Par(y);
		if(x==y) return 0;
		if(r[x]<r[y]){
			p[x]=y;
			s[y]+=s[x];
		}
		else{
			p[y]=x;
			s[x]+=s[y];
			if(r[x]==r[y]) r[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){return Par(x)==Par(y);}
};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	deque<int> q(n);
	bool B=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;q[i]=a[i];
		if(!a[i]) B=1;
	}
	if(a==vi(n,0)){
		ll res=1;
		for(ll i=1;i<=n;i++) (res*=i)%=mod;
		cout<<res<<endl;
		return 0;
	}
	if(!B){
		cout<<0<<endl;
		return 0;
	}
	while(q[0]!=0||q[n-1]==0){
		int tmp=q[n-1];
		q.push_front(tmp);
		q.pop_back();
	}
	for(int i=0;i<n;i++) a[i]=q[i];
	vi L,R;
	L=R=vi(n,-1);
	ll t=-1;
	for(int i=0;i<n;i++){
		int A=a[i];
		if(t!=A&&L[A]!=-1){
			cout<<0<<endl;
			return 0;
		}
		if(L[A]==-1){
			if(t!=-1) R[t]=i-1;
			t=A;L[A]=i;
		}
	}
	R[t]=n-1;
	ll k=R[0]-L[0],res=1;t=0;
	int N=0;
	vi c(n);
	Union_Find_Tree uft(n);
	for(int i=0;i<n;i++){
		if(L[i]==-1){
			(res*=max(0ll,t-i))%=mod;
			continue;
		}
		int K=R[i]-L[i];
		if(K>k) res=0;
		c[L[i]]=1;
		for(int j=L[i];j<R[i];j++){
			uft.Unite(j,j+1);
			c[j]=c[j+1]=1;
		}
		N+=K+1;
		int flag=0;
		if(L[i]-1>=0&&c[L[i]-1]){
			t-=uft.Size(L[i]-1)-k;
			uft.Unite(L[i]-1,L[i]);
			flag++;
		}
		if(c[(R[i]+1)%n]){
			t-=uft.Size((R[i]+1)%n)-k;
			uft.Unite(R[i],(R[i]+1)%n);
			flag++;
		}
		if(flag==2) (res*=k-K+1)%=mod;
		if(!flag&&k!=K) res=0; 
		t+=uft.Size(L[i])-k;
		if(N==n) t=n;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 9708
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  for(auto&& youso : A){
    cin >> youso;
  }
  sort(A.begin(), A.end());
  vector<P> CB(M);
  iikae kazumaisuu = CB;
  ll kazumaisuusize{};
  for(auto&& youso: kazumaisuu){
    cin >> youso.second >> youso.first;
    kazumaisuusize+= youso.second;
  }
  sort(kazumaisuu.rbegin(), kazumaisuu.rend());
  int j{}, k{};
  rep(i, 0, min(N, kazumaisuusize)){
    if(A.at(i) < CB.at(j).first){
      A.at(i) = CB.at(j).first;
    }
    k++;
    if(k == CB.at(j).second){
      j++;
      k = 0;
    }
  }
  ll sum{};
  for(auto&& i : A) sum += i;
  cout << sum << rt;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
LL v[100001];
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    v[0]=1;
    for(i=1;i<=100000;i++)
    {
      k=((v[i-1]%1000000007)*(i%1000000007))%1000000007;
      v[i]=k;
    }
    cin>>n>>m;
    if(abs(n-m)>1)
    {
        cout<<0<<endl;
    }
    else if(abs(n-m)==1)
    {
        cout<<(v[n]*v[m])%1000000007<<endl;
    }
    else
    {
        cout<<(v[n]*v[m]*2)%1000000007<<endl;
    }

    return 0;

}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int P = 1000000007;
const int N = 200010;

int n;
int dp[N];
int lst[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  dp[0] = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int a;
    scanf("%d", &a);
    if (!lst[a] || lst[a] == i - 1)
      dp[i] = dp[i - 1];
    else {
      dp[i] = dp[i - 1] + dp[lst[a]];
      if (dp[i] >= P)
        dp[i] -= P;
    }
    lst[a] = i;
  }
  printf("%d\n", dp[n]);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){    
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  double c, L, PI;
  PI = 3.14159265358979323846264338;
  c = cos((30*H + 0.5*M - 6*M)*PI/180);
  L = A*A + B*B - 2*A*B*c;
  
  cout << fixed << setprecision(15) << sqrt(L) << endl;
}


Measured memory_bytes: 4228
package main

import (
	"fmt"
)

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

	var str string
	fmt.Scanf("%s", &str)

	cnt := 0
	bcnt := 0
	for i := 0; i < n; i++ {
		s := str[i]

		if s == 'c' || cnt >= a + b {
			fmt.Println("No")
		} else {
			if s == 'a' {
				if cnt < a + b {
					fmt.Println("Yes")
					cnt += 1
				} else {
					fmt.Println("No")
				}
			} else {
				if cnt < a + b && bcnt < b {
					fmt.Println("Yes")
					cnt += 1
					bcnt += 1
				} else {
					fmt.Println("No")
				}
			}
		}
	}
}

Measured memory_bytes: 3200
import java.util.*;

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

    int len = sc.nextInt();
    // sc = new Scanner(System.in);
    String str = sc.next();

    if (len%2 == 1){System.out.println("No");return;}

    // String substr_former = str.substring(0, len/2);
    String substr_later = str.substring((len/2), len);

    if (str.startsWith(substr_later)){
      System.out.println("Yes");
    }else {
      System.out.println("No");
    }
  }
}

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

int main() {
  vector<vector<int>> A(3,vector<int> (3));
  vector<vector<int>> B(3,vector<int> (3));
  int N;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> A.at(i).at(j);
    }
  }
  cin >> N;
    for(int k=0;k<N;k++){
      int b=0;
      cin >> b;
        for(int i=0;i<3;i++){
          for(int j=0;j<3;j++){
            if(b==A.at(i).at(j)){
              B.at(i).at(j)=1;
            }
          }
        }
    }
  
  int bingo=0;
          for(int j=0;j<3;j++){
            if(3==(B.at(j).at(0)+B.at(j).at(1)+B.at(j).at(2))){
              bingo++;
            }
            if(3==(B.at(0).at(j)+B.at(1).at(j)+B.at(2).at(j))){
              bingo++;
            }
          }
        if(3==(B.at(0).at(0)+B.at(1).at(1)+B.at(2).at(2)) ||
           3==(B.at(2).at(0)+B.at(1).at(1)+B.at(0).at(2)) ){
          bingo++;
        }
  if(bingo>0){
    cout << "Yes" <<endl;
  }else{
    cout << "No" << endl;
  }
  }



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

int main(){
  int N;
  cin >> N;
  int X = N;
  int sum ;
  while(N >0){
    sum += N % 10;
    N /= 10;
  }
  
  if(X % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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 ll;

int main(){
	vector<int> v(3);
	rep(i,3) cin>>v[i];
	sort(v.begin(), v.end());
	cout << abs(v[1]-v[0]+v[2]-v[1]) << endl;	
}

Measured memory_bytes: 256
#include <cstdio>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
int a[100010], b[100010];
int n, k = 0,l = 1;
using namespace std;
int main()
{
    int n, k = 0,l = 1;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){scanf("%d", &b[i]);}
    for(int i = n; i >= 1;)//倒序搜索
    {
        if(b[i] == i) {
            a[l] = b[i],l++,k++;
            REP_(j, i, n){b[j] = b[j + 1];}
            i = n;
        }
        i--;
    }
    if(k == n)
    {
        for(int i = n; i >= 1; i--)
        {
            printf("%d\n",a[i]);//倒序输出
        }
    }
    else return printf("-1\n") * 0;
    return 0;
}





Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

int main(){
	int k; cin >> k;
	string s="ACL";
	REP(i,k)
		cout << s;
	cout << endl;
	return 0;
}

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

int main(void)
{
	int addition;
	cin>>addition;

	string character;
	cin>>character;

	int len = character.size();

	for (int i = 0; i < len; ++i)
	{
		if ( (character[i]+addition) >'Z')
			character[i]=character[i]+addition-'Z'+'A'-1;

		else 
			character[i]=character[i]+addition;
	}

		cout<<character<<endl;

	return 0;
}

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

int main(){
    char ch;
    
    while(1){
        scanf("%c",&ch);
        if(isalpha(ch)){
            if(isupper(ch)){
                printf("%c",tolower(ch));
            } else {
                printf("%c",toupper(ch));
            }
        } else {
            printf("%c",ch);
        }
        if(ch=='\n'){
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 2688
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
int n,ans,cnt,t;
int a[maxn],mx[maxn];

int main(){
	scanf("%d%d",&n,&t);
	REP(i,n)scanf("%d",&a[i]);
	mx[n]=a[n];
	for(int i=n-1;i>=1;i--)mx[i]=max(a[i],mx[i+1]);
	REP(i,n)ans=max(ans,mx[i+1]-a[i]);
	REP(i,n)if(mx[i+1]-a[i]==ans)cnt++;
	printf("%d",cnt);
	return 0;
}

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

int main() {
  
  int x, a, b;
  cin >> x >> a >> b;
  
  int xa = max(x-a,a-x);
  int xb = max(x-b,b-x);
  
  cout << ((xa > xb) ? "B" : "A") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
int main() {
	long long int a;
	cin >> a;
	for (int i = 1; i <= a; i++) {
		if (i*i > a) {
			cout << (i - 1)*(i - 1) << endl;
			break;
		}
		else if (i*i == a) {
			cout << a << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto i = readNums!int;
  writeln(i.sum - i.reduce!max);
}


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

class Main {

public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		long[] v = new long[N];
		for(int i=0; i<N; i++){
			v[i]  = sc.nextLong();
		}
		
		Arrays.sort(v);

		//最大値を調べるにはA個だけ選ぶ
		long max_sum = 0;
		for(int i=N-1; i>=N-A; i--){
			max_sum += v[i];
		}
		double max_ave = (double) max_sum / (double) A;
		System.out.println(max_ave);
		
		//選んだA個の中でv[N-A]と同じ値のものの個数
		int count1 = 1;
		long max_value = v[N-A];
		for(int i=N-A+1; i<=N-1; i++){
			if(v[i]==max_value){
				count1++;
			}else{
				break;
			}
		}
		
		//vの中でv[N-A]と同じ値のものの個数
		int count2 = count1;
		for(int i=N-A-1; i>=0; i--){
			if(v[i]==max_value){
				count2++;
			}else{
				break;
			}
		}
		
		//n_C_kをdp[n][k]で表す
		long[][] dp = new long[51][51];
		for(int i=0; i<=50; i++){
			dp[i][0] = 1;
		}
		for(int i=1; i<=50; i++){
			dp[i][i] = 1;
			for(int j=1; j<i; j++){	
					dp[i][j] = dp[i-1][j-1] + dp[i-1][j];		
			}
		}

		long count = 0;
		if(count1 == A){
			for(int j=A; j<=B; j++){
				count += dp[count2][j];
			}
		}else{
			count = dp[count2][count1];
		}

		System.out.println(count);		
		
	}

}


Measured memory_bytes: 23764
#N=input()
#N,M=map(int,input().split())
N=int(input())
B=list(map(int, input().split()))
A=[]
for i in range(N-1):
  A.append(B[i])
  if i!=0:
    if A[i]>B[i-1]:
      A[i]=B[i-1]
      
A.append(B[N-2])
print(sum(A))

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

int main(){
    int n , m ;
    cin >> n >> m ;
    if( n <= m )cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3624
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(); //レンガの数
        int count = 0;
        int  a = 0;
        for(int i = 1; i <= N; i++) {
            a = sc.nextInt();
            if(a == count+1) {
                count++;
            }
        }
        
        if(count == 0) {
            System.out.println(-1);
        }else {
            System.out.println(N-count);
        }
    }
}

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

int main(void){

  char s[200001];
  scanf("%s",s);

  int len = strlen(s);
  long count = 0 , wcount = 0 , flag = 1;
  
  for(int i = 0;i < len;i ++){
    if(s[i] == 'W'){
      count += (i - wcount);
      wcount ++;
    }
  }

  

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

  return 0;
}

Measured memory_bytes: 1932
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<unordered_map>
#define N 410
#define lint long long
#define ull unsigned long long
#define gc getchar()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int Gc;unordered_map<lint,int> cnt;lint val[1000];
int c[N][5];lint cv[N][4];
inline lint hv(int a,int b,int c,int d)
{
	return a*1000000000ll+b*1000000ll+c*1000ll+d;
}
inline lint hv(int *a)
{
	return hv(a[0],a[1],a[2],a[3]);
}
inline int Rot(int *a,int c)
{
	rep(i,1,c)
	{
		int tmp=a[0];
		rep(j,1,3) a[j-1]=a[j];
		a[3]=tmp;
	}
	return 0;
}
inline int Add(int x)
{
	rep(i,0,3) cnt[cv[x][i]]++;
	return 0;
}
inline int Del(int x)
{
	rep(i,0,3) cnt[cv[x][i]]--;
	return 0;
}
inline int Get(int a,int b,int c,int d)
{
	int t=cnt[hv(a,b,c,d)];
	if(!t) return 0;
	cnt[val[++Gc]=hv(a,b,c,d)]--;
	cnt[val[++Gc]=hv(b,c,d,a)]--;
	cnt[val[++Gc]=hv(c,d,a,b)]--;
	cnt[val[++Gc]=hv(d,a,b,c)]--;
	return t;
}
inline int Back()
{
	rep(i,1,Gc) cnt[val[i]]++;
	Gc=0;return 0;
}
int main()
{
	int n=inn();ull ans=0ll;
	rep(i,1,n) rep(j,0,3) c[i][j]=inn();
	rep(i,1,n)
	{
		#define a c[i]
		cnt[cv[i][0]=hv(a[0],a[1],a[2],a[3])]++;
		cnt[cv[i][1]=hv(a[1],a[2],a[3],a[0])]++;
		cnt[cv[i][2]=hv(a[2],a[3],a[0],a[1])]++;
		cnt[cv[i][3]=hv(a[3],a[0],a[1],a[2])]++;
		#undef a
	}
	rep(i,1,n)
	{
		Del(i);
		rep(p,0,3)
		{
//			Rot(c[i],p);
			rep(j,1,n) if(i!=j)
			{
				Del(j);
				rep(q,0,3)
				{
//					Rot(c[j],q);
					int s,x,z,y;
					s=Get(c[j][1],c[j][0],c[i][1],c[i][0]);//S
					if(!s) goto loop;
					x=Get(c[j][2],c[i][3],c[i][2],c[j][3]);//X
					if(!x) goto loop;
					z=Get(c[j][1],c[i][0],c[i][3],c[j][2]);//Z
					if(!z) goto loop;
					y=Get(c[i][1],c[j][0],c[j][3],c[i][2]);//Y
					if(!y) goto loop;
					ans+=1ll*s*x*z*y;
					loop:;
					Back();
					Rot(c[j],1);
				}
				Add(j);
			}
			Rot(c[i],1);
		}
		Add(i);
	}
	return !printf("%llu\n",ans/24);
}

Measured memory_bytes: 118096
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
using namespace std;
using lint = long long;
using ld = long double;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };

const lint INF = 1ll << 60;
const int mod = 1000000007;
void speed() {
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	return;
}



int main(void) {
	speed();
	string s; cin >> s;
	lint ans1 = -1, ans2 = -1;
	for (int i = 0; i < (int)s.length(); i++) {
		if (i != (int)s.length() - 1) {
			if (s[i] == s[i + 1]) { ans1 = i + 1; ans2 = i + 2; break; }
		}
		if (i != (int)s.length() - 1 && i != (int)s.length() - 2) {
			if (s[i] == s[i + 2]) { ans1 = i + 1; ans2 = i + 3; break; }
		}
	}
	cout << ans1 << ' ' << ans2 << endl;

	return 0;
}

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

int main()
{
    int A;
    int B;
    int C;
    int X;
    int Y;

    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;
    cin >> Y;

    int ab_num;
    int kaitasi;
    int ookii;

    if(A + B <= C * 2) {
        cout << A * X + B * Y << endl;
    } 
    else {
        if(X <= Y) {
            ab_num = X;
            ookii = Y;
            kaitasi = B * (Y - X);
        }
        else{
            ab_num = Y;
            ookii = X;
            kaitasi = A * (X - Y);
        }

        int answer1 = 2 * C * ookii;
        int answer2 = 2 * C * ab_num + kaitasi;

        if(answer1 <= answer2) {
            cout << answer1<< endl;
        }
        else {
            cout << answer2<< endl;
        }
    }
}

Measured memory_bytes: 256