akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;
typedef vector<ll>		VLL;
typedef vector<VLL>		VVLL;
typedef vector<VVLL>	VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
bool check(const VLL &movList, int movMax, int stPos, int endPos)
{
	if (movMax < abs(endPos)) {
		return false;
	}

	movMax++;
	int dpSizeMax = movMax * 2;
	VVLL dp(2, VLL(dpSizeMax, INF));
	stPos += movMax;
	endPos += movMax;

	int nowIdx = 0;
	int nextIdx = 1;
	dp[nowIdx][stPos] = 0;
	for (auto movOne : movList) {
		fill(&dp[nextIdx][0], &dp[nextIdx][dpSizeMax - 1], INF);
		REP(i, dpSizeMax) {
			if (0 == dp[nowIdx][i]) {
				dp[nextIdx][i + movOne] = 0;
				dp[nextIdx][i - movOne] = 0;
			}		
		}
		swap(nowIdx, nextIdx);
	}
	
	return dp[nowIdx][endPos] != INF;
}

int main()
{
	int N;
	cin >> N;
	VLL a(N);

	int idx = 0;
	int maxAbs = 0;
	REP(i, N) {
		cin >> a[i];
		if (maxAbs <= abs(a[i])) {
			maxAbs = abs(a[i]);
			idx = i;
		}
	}

	vector<P> ans;
	REP(i, N) {
		if (idx != i) {
			a[i] += a[idx];
			ans.emplace_back(idx, i);
		}
	}

	if (0 < a[idx]) {
		REP(i, N - 1) {
			if (a[i + 1] < a[i]) {
				a[i + 1] += a[i];
				ans.emplace_back(i, i + 1);
			}
		}
	} else {
		for (int i = N - 1; i > 0; i--) {
			if (a[i - 1] > a[i]) {
				a[i - 1] += a[i];
				ans.emplace_back(i, i - 1);
			}
		}
	}
	
	cout << ans.size() << endl;
	for (auto oneAns : ans) {
		cout << oneAns.first + 1 << " " << oneAns.second + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import numpy as np

N,K = map(int, input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N, dtype = int)

for i in range(1,N):
  s = max(i-K,0)
  dp[i] = np.min(dp[s:i]+ np.abs(h[s:i] - h[i]))
  
print(dp[-1])
    


Measured memory_bytes: 22904
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend();
#define sz  size()
#define forr(i,a,b) for(int i=a ;i <= b ; i++ )
#define inp ios_base::sync_with_stdio(false);cin.tie(NULL);
#define PQ_INC vector<int>, greater<int> ;
using namespace std ;

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

const int N = 2e5+9 ,  mod = 1e7+9  , OO = 0x3f3f3f3f ;
int dX[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dY[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int a , b , x , y , ans ;
int g[30][30] ;
int main(){
  cin >> a >> b >> x >> y ;
    for (int i = 0 ; i < x ; i++ )
    for (int j = 0 ; j < b ; j++ ) g[i][j] = 1 ;

    for (int i = 0 ; i < y ; i++ )
    for (int j = 0 ; j < a ; j++ ) g[j][i] = 1 ;

    for (int i = 0 ; i < a ; i++ )
    for (int j = 0 ; j < b ; j++ ) ans += g[i][j] == 0 ;

    cout << ans ;


}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
   long long int ans;
   int n,k;scanf("%d %d",&n,&k);
   if(n == 1){
      printf("%d",k);
      return 0; 
   }
   ans = k;
   ans *= pow(k-1,n-1);
   printf("%lld",ans);
}

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

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var employeeNum = IO.ReadInt();
			var subordinateNums = new int[employeeNum + 1];
			foreach(var iBossIndex in IO.ReadIntArray())
			{
				++ subordinateNums[iBossIndex];
			}
			IO.Write(subordinateNums.Skip(1) , "\n");
		}
	}

	public static class IO
	{
		public static string   Read()								 { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')		 { return Read().Split(iSplitter); }
		public static int	   ReadInt()							 { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()							 { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ')	 { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static double   ReadDouble()							 { return double.Parse(Read()); }
		public static double[] ReadDoubleArray(char iSplitter = ' ') { return ReadArray().Select(iText => double.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()						 { return Read().ToCharArray(); }

		public static void Write(string iValue)									   { Console.WriteLine(iValue); }
		public static void Write(int iValue)									   { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue , string iJoinWord = " ") { Console.WriteLine(string.Join(iJoinWord , iValue)); }
		public static void Write(long iValue)									   { Console.WriteLine(iValue); }
		public static void Write(double iValue)									   { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)								   { Console.WriteLine(iValue); }
		public static void Write(bool iValue)									   { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


Measured memory_bytes: 45240
def func(x):
    while True:
        if x <= 0:
            x += N
        else:
            break
    return x


N, M = map(int, input().split())

if N % 2 == 1:
    a = 1
    b = 2
    for i in range(M):
        print(func(a), func(b))
        a -= 1
        b += 1

else:
    a = 1
    b = 2
    for i in range(M):
        print(func(a), func(b))
        a -= 1
        b += 1
        if b == int(2 + N / 4):
            a -= 1


Measured memory_bytes: 9276
c_0 = [int(_) for _ in input().split()]
c_1 = [int(_) for _ in input().split()]
c_2 = [int(_) for _ in input().split()]

d = [0] * 3
e = [0] * 3

for i in range(3):
    d[i] = c_0[i%3] + c_1[(i+1)%3] + c_2[(i+2)%3]
    e[i] = c_0[(i+2)%3] + c_1[(i+1)%3] + c_2[i%3]

flag = True

for i in range(2):
    if d[0] != d[i] or d[0] != e[i]:
        flag = False

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<ll>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll L, A, B, M;

mat mat_mul(const mat& m1, const mat& m2){
    mat res = {};
    for(int i = 0; i + 1 < m1.size(); ++i){
        if(m1[i].size() != m1[i + 1].size()) return res;
    }
    for(int i = 0; i + 1 < m2.size(); ++i){
        if(m2[i].size() != m2[i + 1].size()) return res;
    }
    if(m1[0].size() != m2.size()) return res;
    
    int n = m1.size(), m = m2[0].size();

    res = mat(n, vector<ll>(m, 0));
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            for(int k = 0; k < m1[0].size(); k++){
                res[i][j] += m1[i][k] * m2[k][j];
                res[i][j] %= M;
            }
        }
    }
    return res;
}

mat dia_mat(int sz){
    mat res = mat(sz, vector<ll>(sz, 0));
    for(int i = 0; i < sz; i++) res[i][i] = 1;
    return res;
}

mat mat_pow(mat m, ll exp){
    mat res = dia_mat(m.size());
    while(exp > 0){
        if(exp % 2){
            res = mat_mul(res, m);
        }
        m = mat_mul(m, m);
        exp /= 2;
        res[0][0] %= M;
        m[0][0] %= M;
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> L >> A >> B >> M;

    ll cnt = 0;
    mat m1 = {{0, A, 1}};
    ll d = 1;
    while(cnt < L){
        auto culc = [](ll num) -> ll{
            if(num < A) return 0;
            else return ((num - A) / B) + 1;
        };

        ll cnt2 = culc(d * 10 - 1);
        cnt2 -= culc(d - 1);
        if(cnt + cnt2 > L) cnt2 = L - cnt;
        cnt += cnt2;
        d *= 10;
        mat m2 = {{d % M, 0, 0},
                  {1, 1, 0},
                  {0, B, 1}};
        mat m3 = mat_pow(m2, cnt2);
        m1 = mat_mul(m1, m3);
        m1[0][0] %= M;
    }
    cout << m1[0][0] << endl;
    return 0;
}

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

using namespace std;

int v[1000][1000];

int color[10000];

int parent [1000];

int _time_;

int dt[10000];

int ft[10000];

int cycle_count;

int component_count;

void dfs_visit(int vertex,int n)
{


    color[vertex]=1;
    _time_+=1;
    dt[vertex]=_time_;
    int i;
    for (i=0;i<=n;++i){

        if (v[vertex][i]==1){

            if (color[i]==0){

                parent[i]=vertex;
                dfs_visit(i,n);

            }
            else if (color[i]==1)++cycle_count;

        }
    }
    color[vertex]=2;
    _time_+=1;
    ft[vertex]=_time_;

}


void dfs (int n)
{
   int i,j,k;
   for (i=0;i<=n;++i){

      color[i]= 0;
      parent[i]=-1;
      dt[i]=0;
      ft[i]=0;

   }
   _time_=0;
   for (i=0;i<=n;++i){

      if (color[i]==0){


         dfs_visit(i,n);

      }

   }



}


int main()
{
    int t,i,j,n,e,x,y,k;
    cycle_count = 0;

        cin>>n>>e;
        for (j=0;j<=n;++j){

            for (k=0;k<=n;++k){

                v[j][k]=0;

            }
        }
        for (j=1;j<=e;++j){

            cin>>x>>y;
            v[x][y]=1;


        }

        dfs(n);

    if(cycle_count!=0)cout<<1<<endl;
    else cout<<0<<endl;




    return 0;

}



Measured memory_bytes: 3528
use std::collections::BTreeMap;
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut dic: BTreeMap<String, u32> = BTreeMap::new();

    for _ in 0..n {
        let s: String = parse_line().unwrap();
        *dic.entry(s).or_insert(0) += 1;
    }

    let max_cnt = *dic.values().max().unwrap();
    let mut max_key = dic.iter().filter(|(_, &v)| v == max_cnt);
    while let Some(ans) = max_key.next() {
        println!("{}", ans.0);
    }
}


Measured memory_bytes: 19816
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}

bool f(string s){
    rep(i,0,s.size()/2){
        if(s[i]!=s[s.size()-i-1])return false;
        
    }
    return 1;
}

signed main (){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c){
        cout<<b+c<<endl;
    }else {
        cout<<b+(b+a+1)<<endl;
    }


    




}
/*
1-2
0.5-2

010
01110
00111
000000111
*/


Measured memory_bytes: 256
N = int(input())
s = [(input()) for _ in range(N)]
ans = 0
a_cnt = 0
b_cnt = 0
ab_cnt = 0
for i in range(N):
  if s[i][0] == 'B' and s[i][-1] == 'A':
    ab_cnt += 1
  elif s[i][0] == 'B':
    b_cnt += 1
  elif s[i][-1] == 'A':
    a_cnt += 1
  for j in range(len(s[i])-1):
    if s[i][j] + s[i][j+1] == 'AB':
      ans += 1
if ab_cnt == 0:
  print(ans + min(a_cnt, b_cnt))
else:
  ans += ab_cnt - 1 
  if a_cnt > 0:
    ans += 1
    a_cnt -= 1
  if b_cnt > 0:
    ans += 1
    b_cnt -= 1
  ans += min(a_cnt, b_cnt)
  print(ans)


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<double> p(n);
	rep(i,n) cin >> p.at(i);
	vector<vector<double>> dp(n+1,vector<double>(n+1));
	dp[0][0]=1;
	for(int i=0;i<n;++i){
		for(int j=0;j<=i;++j){
			dp[i+1][j+1]+=dp[i][j]*p[i];
			dp[i+1][j]+=dp[i][j]*(1-p[i]);
		}
	}
	double ans=0;
	for(int i=n/2+1;i<=n;++i) ans+=dp[n][i];
	cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef long long ll;
unordered_map<int, vector<int>> edges;
vector<ll> dp(100002,0);
bool visited[100002] = {false};

ll helper(int i) {
    if (visited[i]) return dp[i]; // 访问过的节点，直接返回i节点的Longest Path
    else {
        dp[i] = 0;
        visited[i] = true; // 访问过当前这个节点
        auto next = edges[i];
        for (auto j : next) {
            dp[i] = max(dp[i], helper(j) + 1);
        }
        return dp[i];
    }
}

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;
    int a,b;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        edges[a].push_back(b);
    }
    ll res = 0;
    for (int i = 1; i <= N; i++) {
        res = max(res, helper(i));
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 13988
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int n;
	cin >> n;
	vector<int> a1(n+1), a2(n+1);
	for (int i = 1; i <= n; i++){
		cin >> a1[i];
	}
	for (int i = 1; i <= n; i++){
		cin >> a2[i];
	}
	vector<int> sum1(n+1), sum2(n+1);
	sum1[0] = 0;
	sum2[0] = 0;
	for (int i = 1; i <= n; i++){
		sum1[i] += sum1[i-1] + a1[i];
		sum2[i] += sum2[i-1] + a2[i]; 
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		ans = max(sum1[i] + sum2[n] - sum2[i-1], ans);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    map<P, ll> mp;
    exrep(i, 1, n) {
        ll a;
        cin >> a;
        ll j = i;
        if(a < j) {
            swap(a, j);
        }
        mp[make_pair(j, a)]++;
    }

    ll ans = 0;
    for(auto p : mp) {
        if(p.second >= 2) {
            ans++;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    string X;
    cin >> X;
    vector<int> A;
    
    if(X[0] == 'S') A.push_back(1);
    if(X[0] == 'T') A.push_back(0),A.push_back(1);
    
    for (int i = 1; i < int(X.length()); i++) {
        if(X[i] == X[i-1]) A.back()++;
        else A.push_back(1);
        
    }
    if(X[int(X.length())-1] == 'S') A.push_back(0);
    
    int ans = 0;
    int ss = 0;
    
    int a = A[0],b = A[1];
    if(a >= b) a -= b,b = 0,ss = a;
    else b -= a, a = 0, ans += b;
    
    for (int i = 1; i < int(A.size())/2; i++) {
        A[i*2] += a;
        a = A[i*2];
        b = A[i*2+1];
        if(a >= b) a -= b,b = 0;
        else b -= a,a = 0, ans += b;
        
        ss = a;
        
    }
    
    
    cout << ans + ss << endl;
    //for(int i : A){cout << i << " ";cout << endl;}
    return 0;
}



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

ll MOD = 1000000007;
int n;
vector<vector<int>> g;

ll mod_inv(ll x)
{
  ll m = MOD, ret = 1, v = 0;
  while (m != 0)
  {
    ll t = x / m;
    x -= t * m;
    swap(x, m);
    ret -= t * v;
    swap(ret, v);
  }
  ret %= MOD;
  if (ret < 0)
    ret += MOD;
  return ret;
}

ll mod_pow(ll x, ll n)
{
  ll ret = 1;
  while (n > 0)
  {
    if (n & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return ret;
}

ll ans;
int dfs(int v, int p = -1)
{
  int ret = 1;
  vector<int> ts;
  for (int i: g[v])
  {
    if (i == p)
      continue;
    int t = dfs(i, v);
    ret += t;
    ts.push_back(t);
  }
  if (p != -1)
    ts.push_back(n - ret);
  ll tmp = mod_pow(2, n - 1) - 1;
  for (int i: ts)
    tmp -= mod_pow(2, i) - 1;
  ans = (ans + tmp) % MOD;
  return ret;
}

int main()
{
  cin >> n;
  g.resize(n);
  rep(i, n-1)
  {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans = 0;
  dfs(0);
  while (ans < 0)
    ans += MOD;
  cout << ans * mod_inv(mod_pow(2, n)) % MOD << endl;
  return 0;
}

Measured memory_bytes: 24832
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn dfs(p: usize, n: usize, grid: &mut Vec<Vec<usize>>, apo: &mut Vec<usize>) -> usize {
    apo[p] = 1usize;
    for i in 0..n {
        if grid[p][i] == 1 && apo[i] == 0 {
            dfs(i, n, grid, apo);
        }
    }
    return apo.iter().sum();
}

fn main() {
    input!{
        n: usize,
        m: usize,
        ab: [(usize1, usize1); m],
    }

    let mut grid = vec![vec![0; n]; n];
    for i in 0..m {
        grid[ab[i].0][ab[i].1] = 1;
        grid[ab[i].1][ab[i].0] = 1;
    }
    let mut ans = 0;
    for i in 0..m {
        let mut visit = vec![0; n];
        grid[ab[i].0][ab[i].1] = 0;
        grid[ab[i].1][ab[i].0] = 0;
        if dfs(0usize, n, &mut grid, &mut visit) != n {
            ans += 1;
        };
        grid[ab[i].0][ab[i].1] = 1;
        grid[ab[i].1][ab[i].0] = 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
n,k = map(int,input().split())

mod = 10**9 + 7

ans = 0
for i in range(k,n+2):
  min = i*(i-1)//2
  max = (n+1)*n//2 - (n+1-i)*(n-i)//2
  ans += (max - min + 1)%mod
print(ans%mod)

Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array

int main()
{   
	int n;
	cin >> n;
	if (n>=30) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
signed main(){
    string s;cin>>s;
    rep(i,s.size()){
        cout<<s[i];
        if(i==3)cout<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 256
/***** author :  C0d1ngPhenomena *****/

#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define TestCases int T; cin>>T; while(T--)
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define revrep(i,a,b) for(ll i = b-1; i >= a; i--)
#define vll vector<ll>
#define vvll vector < vll >
#define pll pair<ll, ll>
#define vpll vector <pll>
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define alld(c) c.begin(),c.end(),greater<int>()
#define mem(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
#define pb push_back
using namespace std;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}

set <int> divisors(int x)
{
	set <int> st;
	for (int i = 1; i * i <= x; ++i)
		if (x % i == 0)
			st.insert(i), st.insert(x / i);

	st.erase(1);
	return st;
}

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

	int n;
	cin >> n;

	vector<int> v(n);
	bool ok = true;
	set<int> s1;

	for (int i = 0; i < n; i++)
		cin >> v[i];

	for (int i = 0; i < n; i++)
	{
		set<int> s2 = divisors(v[i]);

		for (auto &j : s2)
		{
			if (s1.count(j))
			{
				ok = false;
				break;
			}

			s1.insert(j);
		}

		if (!ok)
			break;
	}

	if (ok)
		cout << "pairwise coprime";
	else
	{
		ok = true;

		int gc = v[0];

		for (int i = 1; i < n; i++)
			gc = __gcd(gc, v[i]);

		if (gc != 1)
			ok = false;

		if (ok)
			cout << "setwise coprime";
		else
			cout << "not coprime";
	}

	return 0;
}







Measured memory_bytes: 7264
#include <iostream>

int main()
{
	bool pos = true;
	
	int h, w;
	std::cin >> h >> w;
	
	char grid[h][w];
	
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			char val;
			std::cin >> val;
			grid[i][j] = val;
		}
	}
	
	for (int i = 0; i < h && pos; i++)
	{
		for (int j = 0; j < w && pos; j++)
		{
			if (i == 0 && j == 0)
			{
				if ( (grid[i][j] == '#') && (grid[i][j+1] != '#' && grid[i+1][j] != '#') )
					pos = false;
			}
			else if (i == h-1 && j == 0)
			{
				if ( (grid[i][j] == '#') && (grid[i-1][j] != '#' && grid[i][j+1] != '#') )
					pos = false;
			}
			else if (i == 0 && j == w-1)
			{
				if ( (grid[i][j] == '#') && (grid[i+1][j] != '#' && grid[i][j-1] != '#') )
				pos = false;
			}
			else if (i == h-1 && j == w-1)
			{
				if ( (grid[i][j] == '#') && (grid[i-1][j] != '#' && grid[i][j-1] != '#') )
					pos = false;
			}
			else if (i == 0 && j > 0 && j < w-1)
			{
				if ( (grid[i][j] == '#') && (grid[i][j+1] != '#' && grid[i+1][j] != '#' && grid[i][j-1] != '#') )
					pos = false;
			}
			else if (i == h-1 && j > 0 && j < w-1)
			{
				if ( (grid[i][j] == '#') && (grid[i-1][j] != '#' && grid[i][j+1] != '#' && grid[i][j-1] != '#') )
					pos = false;
			}
			else if (j == 0 && i > 0 && i < h-1)
			{
				if ( (grid[i][j] == '#') && (grid[i-1][j] != '#' && grid[i][j+1] != '#' && grid[i+1][j] != '#') )
					pos = false;
			}
			else if (j == w-1 && i > 0 && i < h-1)
			{
				if ( (grid[i][j] == '#') && (grid[i-1][j] != '#' && grid[i+1][j] != '#' && grid[i][j-1] != '#') )
					pos = false;
			}
			else if ( (grid[i][j] == '#') && (grid[i-1][j] != '#' && grid[i][j+1] != '#' && grid[i+1][j] != '#' && grid[i][j-1] != '#') )
				pos = false;
		}
	}
	
	if (pos)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;
		
	return 0;
}


Measured memory_bytes: 256
import copy

nabc = input().split()
n = int(nabc[0])
a = int(nabc[1])
b = int(nabc[2])
c = int(nabc[3])
llist = [int(input()) for i in range(n)]


def calc_minmp(lenlist, vals, validx):
    minmp = 9999999999999999999999
    minbit = None

    for i in range(1<<len(lenlist)):
        count = totallen = 0
        for j in range(len(lenlist)):
            if (i>>j) & 1:
                count += 1
                totallen += lenlist[j]
        if count <= 0 or len(lenlist) - (2 - validx) < count:
            continue
        mp = (count - 1) * 10 + abs(totallen - vals[validx])
        if mp <= minmp:
            minmp = mp
            minbit = i

    for i in range(len(lenlist)):
        if minbit & (1<<i):
            lenlist[i] = None
    for i in reversed(range(len(lenlist))):
        if lenlist[i] is None:
            del lenlist[i]

    return minmp


def calc_minmp_for_vals(lenlist, vals, old_minmp):
    lenlist = copy.copy(lenlist)
    mp = calc_minmp(lenlist, vals, 0)
    mp += calc_minmp(lenlist, vals, 1)
    mp += calc_minmp(lenlist, vals, 2)
    return min(mp, old_minmp)


mp = calc_minmp_for_vals(llist, [a, b, c], 99999999999999999999)
mp = calc_minmp_for_vals(llist, [a, c, b], mp)
mp = calc_minmp_for_vals(llist, [b, a, c], mp)
mp = calc_minmp_for_vals(llist, [b, c, a], mp)
mp = calc_minmp_for_vals(llist, [c, a, b], mp)
mp = calc_minmp_for_vals(llist, [c, b, a], mp)

print(mp)


Measured memory_bytes: 42352
#include<iostream>
#include<string>
using namespace std;
int solve(string str)
{
	int pos = 0;
	int s = 0;
	int t = 0;
	int ans = str.length();
	while (pos < str.length())
	{
		bool ju = false;
		while (pos < str.length() && str.at(pos) == 'S')
		{
			ju = true;
			pos++;
			s++;
		}
		while (ju && pos < str.length() && str.at(pos) == 'T')
		{
			pos++;
			t++;
		}
		if (t == s)
		{
			ans -= 2 * s;
			t = 0, s = 0;
		}
		else if (s > t)
		{
			ans -= 2 * t;
			s -= t, t = 0;
		}
		else
		{
			ans -= 2 * s;
			s = 0; t = 0;
		}
		if (!ju)
			pos++;
	}
	return ans;
}
int main()
{
	string str;
	cin >> str;
	cout << solve(str);
}

Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  int count=0;
  for(int i=1;i<n-1;i++){
    int max=0;
    if(A[i]>A[i-1])max++;
    if(A[i]>A[i+1])max++;
    if(max==1)count++;
  }
  cout<<count<<endl;
}

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

using pii = pair<int, int>;
using ll  = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " : " << x << endl

template <class T>
bool set_min(T &a, const T &b) {
    return a > b ? a = b, true : false;
}
template <class T>
bool set_max(T &a, const T &b) {
    return a < b ? a = b, true : false;
}
// vector
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &a : v) is >> a;
    return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &t : v) os << "\t" << t;
    return os << endl;
}
// pair
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
    return os << "<" << v.first << ", " << v.second << ">";
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;



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

    int N, M; cin >> N >> M;
    cout << (N * (N - 1) + M * (M - 1)) / 2 << endl;

    return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int a, b, k;
  cin >> a >> b >> k;
  for (int i = 0; i < k; i++) {
    if (i % 2 == 0) {
      if (a % 2 == 1) a--;
      b += a / 2;
      a -= a / 2;
    } else {
      if (b % 2 == 1) b--;
      a += b / 2;
      b -= b / 2;
    }
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<vector<ll>> cnt(10, vector<ll>(10, 0));
    reps(i, 1, n + 1) {
        string s = to_string(i);
        cnt[s[0] - '0'][s[len(s) - 1] - '0']++;
    }
    ll ans = 0;
    reps(i, 1, 10) {
        reps(ii, 1, 10) {
            ans += cnt[i][ii] * cnt[ii][i];
            // printf("cnt[%lld][%lld]=%lld\n", i, ii, cnt[i][ii]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
ans=1
p=1
q=1
for i in range(n):
    a,b=map(int,input().split())
    c=a+b
    k=ans//c
    if ans%c!=0:
        k+=1
    l=p//a
    if p%a!=0:
        l+=1
    m=q//b
    if q%b!=0:
        m+=1
    g=max(k,l,m)
    ans=c*g
    p=a*g
    q=b*g
print(ans)


Measured memory_bytes: 3064
N, M = map(int, input().split())
if N <= 2 or M <= 2:
    if N == 1 and M ==1:
        ans = 1
    elif N == 1 or M == 1:
        ans = max(N-2, M-2)
    else:
        ans = 0
else:
    ans = (N-2)*(M-2)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string str,str1;
    int n,cnt=0,i;
    cin>>str>>str1;
    if(str.size()<=str1.size())
    {
        n=str.size();

    }
    else
    {
        n=str1.size();
    }
    for(i=0;i<n;i++)
    {
        if(str[i]==str1[i])
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  long long int N,M1,M2,K;
  int c=2;

  scanf("%lld",&N);

  if(N==2)
  {
    printf("1\n");
    return 0;
  }

  for(K=2;K<sqrt(N)+1;K++)
  {
    M1=N;
    M2=N;
    if(K*K==N-1) c++;
    else if((N-1)%K==0) c+=2;
    if(K*K==N) c++;
    else if(N%K==0)
    {
      while(M1%K==0) M1/=K;
      while(M2%(N/K)==0) M2/=N/K;
      if(M1%K==1) c++;
      if(M2%K==1) c++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	int n=0;
	int a=0;
	int b=0;
	int flag=0;
	cin>>s;
	n=s.length();
	a=(n-1)/2;
	b=(n+3)/2;
	for(int i=0;i<n;i++)
	{
		if(s[i]!=s[n-1-i])
		{
			flag=1;
		}
	}
	for(int i=0;i<a;i++)
	{
		if(s[i]!=s[a-1-i])
		{
			flag=1;
		}
	}
	if(!(flag)) 
		{
			cout<<"Yes"<<endl;
		}
	else 
		{
			cout<<"No"<<endl;
		}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
char val[202];

int main() {
	scanf("%s", val);
	string a = string(val);
	int len = a.length();
	int ans = 0;
	for (int i = len - 1; i--; i >= 0) {
		string cur = a.substr(0, i);
		if (cur.length() % 2 != 0) {
			continue;
		}
		string c = cur.substr(0, cur.length() / 2);
		string d = cur.substr(cur.length() / 2, cur.length());
		if (c.compare(d) == 0) {
			ans = i;
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int L, M[12], N[12];
    cin >> L;
    if (!L) return 0;
    int r = 0;
    for (int i = 0; i < 12; i++)
      cin >> M[i] >> N[i];
    for (int i = 0; i < 12; i++) {
      r += M[i] - N[i];
      if (r >= L) {
        cout << i + 1 << endl;
        break;
      }
    }
    if (r < L)
      cout << "NA" << endl;
  }
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        int n;
        cin >> n;
        vector<string> vs(n);
        map<string, ll> mp;
        for (int i = 0; i < n; ++i) {
            cin >> vs[i];
            sort(all(vs[i]));
            mp[vs[i]]++;
        }

        ll ans = 0ll;
        for (auto e : mp) {
            ll tmp = e.second * (e.second - 1) / 2;
            ans += tmp;
        }
        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 10368
package main

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

func main() {
	scanInit()

	n := nextInt()
	m := map[string]int{}

	for i := 0; i < n; i++ {
		m[nextStr()]++
	}

	if len(m) == 3 {
		fmt.Println("Three")
	} else {
		fmt.Println("Four")
	}

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
n, k = [int(x) for x in input().split()]
w = [int(input()) for _ in range(n)]

P = 10 ** 4 * 10 ** 5

mi = 0
ma = P

while ma - mi > 1:
    ans = (ma + mi) // 2
    now = 0
    count = 1
    is_success = True
    for v in w:
        if now + v <= ans:
            now += v
        else:
            now = v
            count += 1
            if count > k or now > ans:
                mi = ans
                is_success = False
                break
    if is_success:
        ma = ans

print(ma)





Measured memory_bytes: 9560
if ARGV[0]=="LOCAL_DEV"
  define_method("debug") do |var|
    p var
  end
else
  define_method("debug") do |var|
  end
end

A, B = STDIN.gets.strip.split.map(&:to_i)

if A<=9 && B<=9
  puts A*B
else 
  puts -1
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//-----------------------------------//

int N, K;
int A[112345];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", A + i);

	int ans;
	if (N == K) ans = 1;
	else ans = (N - K + K - 2) / (K - 1) + 1;
	cout << ans << endl;

	return 0;
}


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

X = [int(x) - A for x in input().split()]
dp = [[0 for _ in range(100*N+1)] for _ in range(N+1)]
dp[0][50*N] = 1

for i in range(N):
  for j in range(50, 100*N+1-50):
    dp[i+1][j] = dp[i][j] + dp[i][j - X[i]]
print(dp[N][50*N] - 1)


Measured memory_bytes: 5748
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)					// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


struct Edge
{
	ll length;
	ll vertex;
	Edge(ll v, ll l)
	{
		length = l;
		vertex = v;
	}
};

using Graph = vector<vector<Edge>>;


class ABC126D
{
public:
	ABC126D()
	{
		cin >> n;
		g.resize(n);

		ll u, v, w;
		rep(ei, 0, n - 1)
		{
			cin >> u >> v >> w;
			--u; --v;
			g[u].push_back(Edge(v, w));
			g[v].push_back(Edge(u, w));
		}

	}
	void Run(void)
	{
		vector<ll> ans(n);
		DFS(0, -1, 0, ans);

		for (const auto& e : ans)
			cout << e << endl;
	}
private:
	ll n;
	Graph g;
	void DFS(ll v, ll r, ll c, vector<ll>& ans)
	{
		ans[v] = c;
		
		for (const auto& e : g[v])
		{
			if (e.vertex == r)
				continue;

			if (e.length % 2 == 1)
				c = (ans[v] == 1) ? 0 : 1;
			else
				c = ans[v];

			DFS(e.vertex, v, c, ans);
		}
	}
};


int main(void)
{
	ABC126D abc125d;
	abc125d.Run();

	return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  string s;
  bool flag=true;
  char cnt[27]={};
  cin>>s;
  rep(i,0,s.size()){
    cnt[s[i]-'a']++;
  }
  rep(i,0,27){
    if(cnt[i]!=0&&cnt[i]%2==0)flag=false;
  }
  if(flag)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        HashMap<Integer,Integer> odds = new HashMap<>();
        HashMap<Integer,Integer> evens = new HashMap<>();
        int n = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        for(int i = 0; i < n; i++){
            a[i] -= i+1;
        }
        Arrays.sort(a);
        long ans = 0;
        int median = a[n/2];
        for(int v : a){
            ans += (long)Math.abs(v-median);
        }
        System.out.println(ans);
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 50956
#include<cstdio>
int main()
{
	long long k,a,b;
	scanf("%lld %lld %lld",&k,&a,&b);
	if(k>a&&b>=a){
		printf("-1\n");
	}else if(k<=a){
		printf("1\n");
	}else{
		long long ans;
		if((k-a)%(a-b)==0){
			ans=(k-a)/(a-b)*2+1;
		}else{
			ans=(k-a)/(a-b)*2+2+1;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f,f){
        int h=100,g;
        f-=e+a*5+b*3;
        h+=(a+b)*15+d*2+(a*5+b*3)*13+c*7;
        cout<<h-f*3<<endl;
    }
}



Measured memory_bytes: 3076
s=input()
str=["A","K","I","H","A","B","A","R","A"]
count=0
ans=0
for i in range(9):
    if count==len(s) and i<8:
        ans=1
        break
    elif count==len(s):
        break
    if s[count]==str[i]:
        count+=1
    elif s[count]!=str[i] and str[i]!="A":
        ans=1
        break
if len(s)>9:
    ans=1
if ans==1:
    print("NO")
else:
    print("YES")


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

int main(void){
    string s,t;
    cin >> s >> t;
    
    int ans = t.size();
    for(int i = 0;i < s.size();i++){
        if(i + t.size() > s.size())continue;
        int num = 0;
        for(int j = 0;j < t.size();j++){
            if(s[i+j] != t[j])num++;
        }
        ans = min(ans,num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628