akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    scanf("%d", &n);
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    int state = 0;
    int ans = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        if (state == 0)
        {
            if (a[i] > a[i + 1])
            {
                state = -1;
            }
            else if (a[i] < a[i + 1])
            {
                state = 1;
            }
        }
        else if (state == 1)
        {
            if (a[i] > a[i + 1])
            {
                state = 0;
                ++ans;
            }
        }
        else
        {
            if (a[i] < a[i + 1])
            {
                state = 0;
                ++ans;
            }
        }
    }
    ++ans;
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

#define mP make_pair
#define pB push_back
#define ll long long

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

	sort(a , a + n);

	int ans = 0;
	for(int i = 0 ; i < n ; ++i){
		while(a[i] == a[i + 1])
			++i;
		++ans;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int OFFSET = 12'720;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<vector<bitset<25441>>> f(n);
    for (int i = 0; i < n; ++i)
        f[i].resize(m);
    vector<vector<int>> a(n, vector<int>(m));
    f[0][0][OFFSET] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            int x;
            cin >> x;
            a[i][j] = abs(a[i][j] - x);
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (i > 0)
                f[i][j] |= f[i - 1][j];
            if (j > 0)
                f[i][j] |= f[i][j - 1];
            f[i][j] = f[i][j] << a[i][j] | f[i][j] >> a[i][j];
        }
    }
    for (int i = 0; ; ++i) {
        if (f[n - 1][m - 1][OFFSET - i] == 1 || f[n - 1][m - 1][OFFSET + i] == 1) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 20480
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1100100100;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> memo(n, INF);//memo[i]は長さi+1の最長増加部分列の末尾が取りうる最小値
    int len = 0;//memo[i]のうち有効な数値が埋められている部分の末尾要素の添字
    memo[0] = a[0];
    for(int i = 1; i < n; i++){
        //a[i]を最長増加部分列の末尾に追加できるか判定
        if(a[i] > memo[len]){
            //最長増加部分列(LIS)の末尾に追加できる場合はLISの長さを伸ばす
            len++;
            memo[len] = a[i];
        }else{
            /*
            memo[k] >= a[i] を満たすような最小のkを探し出し
            memo[k] に a[i] を代入
            二分探索でkを決定
            */
            int left = -1;//memo[left] > a[i] を満たさない
            int right = len;//memo[right] > a[i] を満たす
            while(right - left > 1){
                int mid = left + (right - left)/2;
                if(memo[mid] >= a[i]){
                    right = mid;
                }else{
                    left = mid;
                }
            }
            memo[right] = a[i];
        }
    }

    cout << len+1 << endl;
    return 0;
}


Measured memory_bytes: 3608
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        if n:
            f = '1' if f != '1' else '2'
        if f == '1':
            left=c+left
        elif f == '2':
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Measured memory_bytes: 41712
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
#define INF 100000000
int main(void){

    int N, L; cin >> N >> L;
    int base = 0;
    int m = INF , sub = 0;
    for(int i = 0 ; i < N ; i++){
        base += L + i;
        if(abs(L + i) < m){
            m = abs(L + i);
            sub = L + i;
        }
    }

    cout << base - sub << endl;

    return 0;
}

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



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

    long long d[k];
    long long m[k];
    for ( long long i =0; i<k; i++) {cin>>d[i]; }
    for(long long i=0; i<k; i++) {m[i]=-1; }
    //if(k>1){
    m[k-1]=0;
    m[k-2] = abs(d[k-2]-d[k-1]);
    for(long long i=k-2; i>=0; i--)
    {
        m[i] = min(abs(d[i]-d[i+1])+m[i+1],abs(d[i]-d[i+2])+m[i+2]);
    }
    if(k>1){

    cout << m[0]<< endl;
    }else{
    cout << 0 << endl;
    }


    return 0;
}


Measured memory_bytes: 1792
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		Set<String > set  = new HashSet<>();
		for (int i = 0; i < N; i++) {
			set.add(sc.next());
		}
		System.out.println(set.size() == N ? "YES" : "NO");
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 79188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class A2FightingOverCandies {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int a,b,c;
    cin >> a >> b >> c;
    cout << (a + b + c == 2*max({a,b,c})? "Yes":"No") << endl;
}
};


#undef int
int main() {
	A2FightingOverCandies solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	REP(i, n) {
		cin >> v[i];
	}
	vector<int> a(n, 0);
	REP(i, n) {
		while (true) {
			if (v[i] % 2 == 0) {
				a[i]++;
				v[i] /= 2;
			}
			else {
				break;
			}
		}
	}
	sort(ALL(a));
	cout << a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i=0; i<(int)(n); ++i)

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

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

    if(S.at(2) == S.at(3) && S.at(4) == S.at(5)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n=int(input())
k=[1,6,6**2,6**3,6**4,6**5,6**6,9,9**2,9**3,9**4,9**5]
dp=[n]*(n+1)
dp[0]=0

for i in range(1,n+1):
    for j in k:
        if i-j>=0:
            dp[i]=min(dp[i],dp[i-j]+1)

print(dp[n])

Measured memory_bytes: 3828
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		if(N % 2 != 0)
			System.out.println(0);
		else {
			long ans = 0;
			N /= 2;
			while(N > 0) {
				N /= 5;
				ans += N;
			}
			System.out.println(ans);
		}

	}

}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, sum = 0, ans = 0;
    cin >> n;
    int arr[n];
    int suffix[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for(int i = n - 1; i >= 0; i--)
    {
        sum += arr[i];
        suffix[i] = sum;
    }
    for(int i = 0; i < n - 1; i++)
    {
        int r = suffix[i + 1];
        ans += ((r % mod) * (arr[i] % mod)) % mod;
    }
    cout << ans % mod << endl;
    return 0;
}


Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long M, std::vector<long long> H, std::vector<long long> A, std::vector<long long> B) {
    vector<bool> b(N, true);
    rep(i, M) {
        if (H[A[i]] <= H[B[i]]) b[A[i]] = false;
        if (H[B[i]] <= H[A[i]]) b[B[i]] = false;
    }
    ll res = 0;
    rep(i, N) {
        if (b[i]) res++;
    }
    cout << res << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> H(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &H[i]);
    }
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
        A[i]--;
        B[i]--;
    }
    solve(N, M, std::move(H), std::move(A), std::move(B));
    return 0;
}


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

using namespace std;

typedef long long int ll;

int main()
{
  ll D;
  cin >> D;
  
  if(D==22)
  {
    cout << "Christmas Eve Eve Eve" << endl;
  }
  
  if(D==23)
  {
    cout << "Christmas Eve Eve" << endl;
  }
  
  if(D==24)
  {
    cout << "Christmas Eve" << endl;
  }
  
  if(D==25)
  {
    cout << "Christmas" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long int INF = 1e18 + 2;
long int getSum(int l, int r, vector<long int> &slimes) {
    long int s = 0;
    for (int index = l; index <= r; index++)
        s += slimes[index];
    return s;
}
int main() {
    long int n;
    cin>>n;
    vector<long int> slimes(n);
    for (long int index = 0; index < n; index++) {
        cin>>slimes[index];
    }
    long int minCost = 0;
    vector<vector<long int> > cost(n, vector<long int> (n, 0));
    for (int row = n-1; row >= 0; row--) {
        for (int col = row; col < n; col++) {
            if (row == col)
                cost[row][col] = 0;
            else {
                long int sum = getSum(row, col, slimes);
                cost[row][col] = INF;
                for (int mid = row; mid < col; mid++)
                    cost[row][col] = min (cost[row][col], cost[row][mid] + cost[mid+1][col] + sum);
            }
        }
    }
    cout<<cost[0][n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 4872
/**
 *    author:  Atreus
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;
ll w[maxn], v[maxn], dp[120][maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int n, W;
	cin >> n >> W;
	for (int i = 1; i <= n; i++)
		cin >> w[i] >> v[i];
	memset(dp, 63, sizeof dp);
	dp[0][0] = 0;
	int answer = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 0; j <= 100000; j++){
			if (j < v[i]){
				dp[i][j] = dp[i - 1][j];
				continue;
			}
			dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
			if (dp[i][j] <= W)
				answer = max(answer, j);
		}
	}
	cout << answer << endl;
}


Measured memory_bytes: 94464
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class EAlmostEverywhereZero {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      string s; cin >> s;
      int n = s.size();
      int k; cin >> k;
      vector<int> v;
      for(auto e: s) {
        v.push_back(e-'0');
      }

      vector<vector<ll>> a(n+1, vector<ll>(4)); // equal or under
      vector<vector<ll>> b(n+1, vector<ll>(4));

      a[0][0] = 1;

      rep(i, n) {
        int e = v[i];
        if (e != 0) {
          for(int j=0; j<=k; j++) {
            b[i+1][j] += a[i][j];
            if (j<k) b[i+1][j+1] += (e-1)*a[i][j];
            if (j<k) a[i+1][j+1] += a[i][j];
          }
          for(int j=0; j<=k; j++) {
            b[i+1][j] += b[i][j];
            if (j<k) b[i+1][j+1] += 9*b[i][j];
          }
        } else {
          for(int j=0; j<=k; j++) {
            a[i+1][j] += a[i][j];
            b[i+1][j] += b[i][j];
            if (j<k) b[i+1][j+1] += 9*b[i][j];
          }
        }
      }

      cout << a[n][k] + b[n][k] << endl;


    }
};

signed main() {
  EAlmostEverywhereZero solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a,b) a = min(a,(decltype(a))(b))
#define MAXS(a,b) a = max(a,(decltype(a))(b))

struct node {
	int id;
	vector<int> link;
};
ll N;
vector<node> nod;
int main() {
	cin >> N;
	nod.resize(N + 1);
	REP(i, 0, N - 1) {
		int u, v;
		cin >> u >> v;
		if (u < v)swap(u, v);
		nod[u].link.push_back(v);
	}
	ll A, B, C, D;
	vector<ll> E(N + 1);
	A = 0; B = 0; C = 0; D = 0;
	REP(L, 1, N + 1) A += N * (N + 1) / 2 - L * (L - 1) / 2 - (N - L + 1) * (L - 1);
	REP(i, 1, N + 1) {
		ll sum = 0;
		for (int c : nod[i].link)sum += c;
		E[i] = i * nod[i].link.size() - sum;
	}
	REP(i, 1, N + 1) D += (N - i + 1) * E[i];
	REP(i, 1, N + 1)C += i * (N - i + 1) * nod[i].link.size();
	B = C - D;
	ll ans = A - B;
	PRI(ans);
	return 0;
}

Measured memory_bytes: 17164
#include <bits/stdc++.h>
using namespace std;
int R;
int main () {
cin >> R;
if (R<=1199){
	cout << "ABC"<< endl;
}else if (R>1199 && R<=2799){
cout << "ARC" << endl;
}else if (R>2799){
	cout << "AGC" << endl;
}
return 0;
}

Measured memory_bytes: 256
k = []
for i in range(1,40):
  for j in range(2,30):
    if i**j <= 1000:
      k.append(i**j)
L = set(k)
P = list(L)
P.sort()
X = int(input())
ans = 0
if X == 1000:
  print(1000)
else:
  for i in range(len(P)):
    if X<P[i]:
      print(ans)
      break
    else:
      ans = P[i]


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9+7;

int main()
{
	int H,W;
	cin>>H>>W;
	vector<vector<char>> mat(H,vector<char>(W));
	vector<vector<int>> dp(H,vector<int>(W));
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin>>mat[i][j];
	dp[0][0] = 1;
	for(int i=1;i<H;i++)
		if(mat[i][0] == '.')
			dp[i][0] = dp[i-1][0];
		else
			break;
	for(int i=1;i<W;i++)
		if(mat[0][i] == '.')
			dp[0][i] = dp[0][i-1];
		else
			break;
	for(int i=1;i<H;i++)
		for(int j=1;j<W;j++)
			if(mat[i][j]=='.')
				dp[i][j] = (dp[i-1][j]%MOD + dp[i][j-1]%MOD)%MOD;
	cout<<dp[H-1][W-1]%MOD<<'\n';
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n;
    cin>>n;
    int cnt= 0;
    map<pair<int, int>, set<int>>u;
    for(int i = 1; i <= n; i++){
        if(i%10==0)continue;
        int sz = log10(i);
        int l = i%10, r = i/pow(10, sz);
        if(l>r)swap(l, r);
        u[{l, r}].in(i);
    }
    for(auto i:u){
        if(i.f.s==i.f.f){
            int d = sz(i.s);
            cnt+=d*(d-1)+d;
            continue;
        }
        map<int, int>cntl, cntr;
        for(auto j:i.s){
            int sz = log10(j);
            cntl[j/pow(10, sz)]++, cntr[j%10]++;
        } 
        cnt+=cntl[i.f.s]*cntr[i.f.s]*2;
    }
    cout<<cnt;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

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

public class Main {
  public static void main(String[] args) {
    // 標準入力取得
    Scanner sc = new Scanner(System.in);    
    String iShortNeedle = sc.next();
    String iLongNeedle = sc.next();
    String h = sc.next();
    String m = sc.next();
    // 入力値加工
    double hour = Double.parseDouble(h);
    double min = Double.parseDouble(m);
    double wholeMin = (hour*60) + min;
    double shortNeedle = Double.parseDouble(iShortNeedle);
    double longNeedle = Double.parseDouble(iLongNeedle);

// check
//    System.out.println("shortNlength:" + shortNeedle + "cm");
//    System.out.println("longNlength:" + longNeedle + "cm");
//    System.out.println("hour:" + hour + "H");
//    System.out.println("min:" + min + "min");
//    System.out.println("wholeMin: "+ wholeMin + "min");

    double shortAngleByOneMin = (360.0/12.0)/60.0;
    double longAngleByOneMin = 360.0/60.0;
//    System.out.println("1分で短針が動く度数: "+ shortAngleByOneMin + "°");
//    System.out.println("1分で長針が動く度数: "+ longAngleByOneMin + "°");
//    System.out.println("XX分で短針が動く度数: "+ shortAngleByOneMin * wholeMin);
//    System.out.println("XX分で長針が動く度数: "+ longAngleByOneMin * min);

    // 各針の角度を計算する
    double rHour = 0; 
    double rMin = 0;
    if(wholeMin!=0){
      rHour = shortAngleByOneMin * wholeMin; 
    }
    if(min!=0){
      rMin = longAngleByOneMin * min;
    }
    double diffAngle = Math.abs(rHour - rMin);    

// check
//    System.out.println("rHour: " + rHour + "°");
//    System.out.println("rMin: " + rMin + "°");
//    System.out.println("diffAngle: " + diffAngle + "°");

    double aLength = 0;
    if(diffAngle!=0 || diffAngle!=180){
	  aLength = Math.sqrt( Math.pow(shortNeedle,2) + Math.pow(longNeedle,2) - 2 * shortNeedle * longNeedle * Math.cos(Math.toRadians(diffAngle)) );
    }else if(diffAngle==0){
      aLength = longNeedle - shortNeedle;    
    }else if(diffAngle==180){
      aLength = longNeedle + shortNeedle;
    }
    
//answer
    System.out.println(aLength);
  }
}

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

typedef long long  LL;
int n,m,a[100010],b[100010],cnt;
LL ans,s;

bool cmp(int x,int y){return a[x]<a[y];}

void work()
{
	scanf("%d %d",&n,&m);
	for (int i=1; i<=n; i++)  scanf("%d",&a[i]),b[i]=i;
	sort(b+1,b+n+1,cmp);
	for (int i=1; i<n; i++)
		if (a[i]>a[i+1])  cnt++,s+=a[i+1];
		else  s+=a[i+1]-a[i];
	ans=s;
	for (int i=2,j=1; i<=m; i++)
		{
			s-=cnt;
			while ((j<=n)&&(a[b[j]]<i))
				{
					if (b[j]!=1)  cnt--,s+=(a[b[j]]-a[b[j]-1]+m)%m;
					if (b[j]!=n)  cnt++;
					j++;
				}
			ans=min(ans,s);
		}
	printf("%lld",ans);
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<string> S(n);
    for(int i = 0; i < n; i++) cin >> S.at(i);

    for(char alphabet = 'a'; alphabet <= 'z'; alphabet++){
        int min = 50;
        for(auto str : S){
            int count = 0;
            for(auto c : str) if(c == alphabet) count++;
            if(min > count) min = count;
        }
        for(int i = 0; i < min; i++) cout << alphabet;
    }
    cout << endl;

    return 0;
}

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

int main(){
    ll N;
    cin >> N;
    ll s = sqrt(N);
    ll ans = 0;
    for(int i = 1; i <= s; i++) if(i * (N / i) == N) ans = i + N/i - 2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	ll n, a, mi = INF, ma = 0;
	cin >> n;
	REP(i, n) {
		cin >> a;
		mi = min(mi, a);
		ma = max(ma, a);
	}
	cout << (ma - mi) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, A, B, C, L[10];

int abso(int a)
{
    if(a < 0)return -a;
    return a;
}

int dfs(vector<int> v)
{
    if((int)v.size() == N){
        int a = 0, b = 0, c = 0;
        int res = 0;
        bool flag1 = false, flag2 = false, flag3 = false;
        for(int i = 0; i < N; i++){
            if(v[i] == 1){
                a += L[i];
                if(flag1){
                    res += 10;
                }
                flag1 = true;
            }
            else if(v[i] == 2){
                b += L[i];
                if(flag2){
                    res += 10;
                }
                flag2 = true;
            }
            else if(v[i] == 3){
                c += L[i];
                if(flag3){
                    res += 10;
                }
                flag3 = true;
            }
        }
        if(flag1 && flag2 && flag3){
            //printf("%d %d %d\n", abso(A - a), abso(B - b), abso(C - c));
            return abso(A - a) + abso(B - b) + abso(C - c) + res;
        }
        return INF;
    }
    int res = INF;
    for(int i = 0; i < 4; i++){
        vector<int> t = v;
        t.pb(i);
        res = min(res, dfs(t));
    }
    return res;
}

signed main()
{
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
    vector<int> v;
    cout << dfs(v) << endl;


    return 0;
}
/*



*/


Measured memory_bytes: 256
#include <stdio.h>

#define abs(x) ((x) > 0 ? (x) : -(x))

int main(void) {
  long x, k, d;
  scanf("%ld %ld %ld", &x, &k, &d);
  long a = abs(x) / d;
  if (a > k) {
    printf("%ld\n", abs(x)- d * k );
    return 0;
  }
  long b = 0;
  if(abs(abs(x) - d * a) <= abs(abs(x) - d * (a + 1))) {
    b = abs(abs(x) - d * a);
    k -= a;
  } else {
    b = abs(abs(x) - d * (a + 1));
    k -= a + 1;
  }
  if(k % 2) {
    printf("%ld\n", abs(abs(b + d) < abs(b - d) ? b + d : b - d));
  } else {
    printf("%ld\n", abs(b));
  }
  return 0;
}

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

int main(){
 int a,b,c;
  cin >> a >> b >> c;
  if((a == 7 && b == 5 && c == 5) || (a == 5 && b == 7 && c == 5) || (a == 5 && b == 5 && c == 7))cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		var listA = new Dictionary<int,int>();
		var listB = new List<int>();
		int[]A = new int[N];
		string[] str = Console.ReadLine().Split();
		var flag1 = false;
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
			if(!listA.ContainsKey(A[i])){
				listA[A[i]] = 1;
			} else {
				listA[A[i]] = 0;
			}
			if(A[i] == 1){
				flag1 = true;
			}
		}
		var listC = new Dictionary<int,int>();
		foreach(var i in listA.Keys){
			if(!listC.ContainsKey(i)){
				listB.Add(i);
          		listC[i] = 1;
			}
		}
		listB.Sort();
		int ans = 0;
		var dic = new Dictionary<int,int>();
		for(var i=0;i<listB.Count;i++){
			bool flag = true;
			var listL = enum_div(listB[i]);
			for(var j=0;j<listL.Count;j++){
				if(dic.ContainsKey(listL[j])){
					flag = false;
					break;
				}
			}
			if(flag1 && listB[i]>1){
				break;
			}
			if(flag){
				dic[listB[i]] = 1;
				if(listA[listB[i]]==1){
					ans++;
				}
			}
		}
		Console.WriteLine(ans);
	}
	public static List<int> enum_div(int n){
		int tmp = n;
		var list = new List<int>();
		for(var i=1;i*i<=n;i++){
			if(n%i==0){
				list.Add(i);
				if(i*i!=n){
					list.Add(n/i);
				}
			}
		}
		return list;
	}
}

Measured memory_bytes: 53068
#include<bits/stdc++.h>        
using namespace std;           
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
                               
#define pb push_back           
#define PII pair<int,int>      
                               
#define VS vector<string>      
#define VI vector<int>         
#define ll long long int       
#define debug(x) cout << x << " :" <<#x << endl  
int main(void) {               
    int a,b;                   
    char s;                    
    cin >> a >> s >> b;        
    if(s == '+') cout << a + b << endl;
    else cout << a - b << endl;                                                                                                            
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	W, H, x, y := float64(getInt()),
		float64(getInt()),
		float64(getInt()),
		float64(getInt())

	ans := 0
	if W/2 == x && H/2 == y {
		ans = 1
	}
	out(W*H/2, ans)
}


Measured memory_bytes: 640
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#else
#define VS_ENDPAUSE()
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;

#if 0
#define INT8_MIN	(-127)
#define INT8_MAX	( 128)
#define UINT8_MAX	( 255)
#define INT16_MIN	(-32768)
#define INT16_MAX	( 32767)
#define UINT16_MAX	( 65535)
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18

void func(void);
#pragma endregion

int main(void)
{
	func();
	VS_ENDPAUSE();
	return 0;
}



void func(void)
{
	uint64 a,b;
	cin >> a >> b;

	if((a+b) >= 10){
		cout << "error" << endl;
	} else {
		cout << a+b << endl;
	}

	return;
}




Measured memory_bytes: 256
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
c = collections.Counter(prime_factorize(N))
o = 0
for i in c:
    m = 1
    s = 1
    while(c[i] >= s):
        m += 1
        s += m
    o += m - 1
print(o)

Measured memory_bytes: 9468
#include<stdio.h>
int main()
{
	int a,b,c,i,count=0;
	scanf("%d%d%d",&a,&b,&c);
	for(i=a;i>=a&&i<=b;i++)
	{
		if(i%c==0)
		{
			count++;
		}
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    map<char, int> mp;
    bool ok = true;
    for(auto c : s) {
        mp[c]++;
        if(mp[c] > 1) ok = false; 
    }
    if(ok) cout << "yes" << endl;
    else cout << "no" << endl;
}

Measured memory_bytes: 3656
/*input
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define ff first
#define ss second
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
 
template<typename T> using V = vector<T>;
 
int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int a, b; cin >> a >> b;
	cout << max(a+b,max(a-b,a*b));
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  while(true) {
    string s;
    cin >> s;
    if(s == "0") break;

    int n = s.size();
    int now = 0, cnt[15] = {}, ans = 0;
    cnt[0] = 1;
    REP(i, n) {
      if(i%2==0) now += (s[i]-'0')*10;
      else now += (s[i]-'0');
      now %= 11;

      if(i+1<n && s[i+1]!='0') {
        ans += cnt[now];
        cnt[now]++;
      }
      // leading-zeroになるのでcnt[now]に足さない
      else {
        ans += cnt[now];
      }
    }

    cout << ans << endl;
  }

  return 0;
}



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

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

	int ans = 0;
	for (int i = 1;i <= n;i++) {
		int tmp = i;
		int count = 0;
		for (int j = 1;j <= tmp;j+=2) {
			if (tmp%j == 0) {
				count++;
			}
		}
		if (count == 8) {
			ans++;
		}

	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    int a = sc.nextInt();
    int n = a%10;
    String name = "";
    
    if (n==2 || n==4 || n==5 || n==7 || n==9) {
      name = "hon";
    } else if (n==0 || n==1 || n== 6 || n==8) {
      name = "pon";
    } else {
      name = "bon";
    }
    

    System.out.println(name);
  }
}

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

using namespace std;

vector <int> p;
int N;
bool dp[101][10101];

int main(){
        cin>>N;
        for(int i=0;i<N;i++){
                int pp;
                cin>>pp;
                p.push_back(pp);
        }
        dp[0][0]=true;
        for(int i=0;i<N;i++){
                for(int j=10100;j>=0;j--){
                        if(dp[i][j]){
                                dp[i+1][j+p[i]]=true;
                                dp[i+1][j]=true;
                        }
                }
        }
        for(int i=10100;i>=0;i--){
                if(i==0||(dp[N][i]&&i%10!=0)){
                        cout<<i<<endl;
                        return 0;
                }
        }
        return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N,K,X;
  std::cin >> N >> K;
  if (N < K) {
    std::cout << min(N,K-N) << '\n';
  }
  else{
    X = N%K;
    if (N == 0) {
      std::cout << 0 << '\n';
    }
    else{
     std::cout << min(X,K-X) << '\n';
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long nature(long long a){
  if(a>=0){return a;}
  else{return -1*a;}
}
int main(){
  #define int long long
  int X, K, D;
  cin>>X>>K>>D;
  if(X>0){
    int rock=X/D;
    int remain=K-rock;
    if(remain<=0){
      cout<<X-D*K<<endl;
    }
    else{
      cout<<nature(X-D*rock-(remain%2)*D)<<endl;
    }
  }
  if(X==0){
    cout<<(K%2)*D<<endl;
  }
  if(X<0){
    int rock=(-1*X)/D;
    int remain=K-rock;
    if(remain<=0){
      cout<<-X-D*K<<endl;
    }
    else{
      cout<<nature(-X-D*rock-(remain%2)*D)<<endl;
    }
  }
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> H(N);
  rep(i, N) cin >> H[i];

  vector<int> dp(N, INT_MAX);
  dp[0] = 0;
  rep(i, N){
    rep(j, K){
      dp[i+j+1] = min(dp[i+j+1], dp[i]+abs(H[i]-H[i+j+1]));
    }
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
//#pragma optimize("Ofast")
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int len[2005];
char s[2005][10005];
bitset<10005> can[2005];
pair<int,int> dp[2][2005];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
		len[i]=strlen(s[i]);
	}
	for(int i=0;i<n;i++){
		can[i].reset();
	}
	can[n]=1;
	for(int i=n-1;i>=0;i--){
		can[i]=can[i+1]|(can[i+1]<<len[i]);
	}
	int cnt=0,ii=0;
	for(int i=0;i<n;i++){
		if(can[i+1][k-len[i]]) dp[0][cnt++]=make_pair(i,0);
	}
	string res;
	pair<int,int> *a=dp[0],*b=dp[1];
	for(int i=1;i<=k;i++){
		char mi='z';
		int cnt2=0;
		pair<int,int> *c=a;
		for(int j=0;j<cnt;j++,c++){
			mi=min(s[(*c).first][(*c).second],mi);
		}
		res+=mi;
		int miid=1e9;
		c=a;
		for(int j=0;j<cnt;j++,c++){
			int fi=(*c).first,se=(*c).second;
			if(s[fi][se]==mi){
				if(se+1==len[fi]) miid=min(miid,fi);
				else{
					b[cnt2++]=make_pair(fi,se+1);
				}
			}
		}
		for(int j=miid+1;j<n;j++){
			if(k-len[j]-i>=0&&can[j+1][k-len[j]-i]) b[cnt2++]=make_pair(j,0);
		}
		swap(a,b);
		cnt=cnt2;
	}
	cout<<res;
}

Measured memory_bytes: 21504
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    vector<int> values(3);
    for (int i = 0; i < 3; ++i)
        cin >> values[i];

    sort(values.begin(), values.end());
    if (values[0] == 5 && values[1] == 5 && values[2] == 7)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int N;cin>>N;
  VECINT dp(N+1);
  dp[1] = 1;
  FOR(i,2,N+1) {
    VECINT tmpvec{dp[i-1]};
    int six_cnt=0,nine_cnt=0;
    while (pow(6,six_cnt+1)<=i) {
      six_cnt++;
      tmpvec.push_back(dp[i-pow(6,six_cnt)]);
    }
    while (pow(9,nine_cnt+1)<=i) {
      nine_cnt++;
      tmpvec.push_back(dp[i-pow(9,nine_cnt)]);
    }
    sort(ALL(tmpvec));
    dp[i] = tmpvec[0]+1;
  }
  OUT(dp[N]);

  return 0;
}

Measured memory_bytes: 640
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

solve :: Int -> Int -> [(Int, Int)] -> Int
solve n ww wvs = iter n ww
  where
    wva = listArray (1, n) wvs
    memo = listArray ((0, 0), (n, ww)) [iter i j | i <- [0..n], j <- [0..ww]]
    iter i j
        | i == 0    = 0
        | j <  wi   = memo ! (i - 1, j)
        | otherwise = max (memo ! (i, j - wi) + vi) (memo ! (i - 1, j))
      where
        (wi, vi) = wva ! i

main :: IO ()
main = do
    [n, w] <- fmap read . words <$> getLine :: IO [Int]
    wvs <- replicateM n $ do
        [v, w] <- fmap read . words <$> getLine :: IO [Int]
        return (w, v)
    print $ solve n w wvs


Measured memory_bytes: 70852
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();

        // dp[i][j] ... i文字目までで、あまりがjのやつの個数

        int[] dp = new int[2019];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int[] dp2 = new int[2019];

            int next = Character.getNumericValue(s.charAt(i));
            dp2[next] = 1;
            for (int j = 0; j < 2019; j++) {
                dp2[(10 * j + next) % 2019] += dp[j];
            }
            for (int j = 0; j < 2019; j++) {
                dp[j] = dp2[j];
            }
            ans += dp2[0];
        }
        System.out.println(ans);
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

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

  int ans = 0;
  for (int i = 1; i < n - 1; i++)
  {
    if (p[i - 1] < p[i] && p[i] < p[i + 1])
      ans++;
    if (p[i - 1] > p[i] && p[i] > p[i + 1])
      ans++;
  }
  cout << ans << endl;
}

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

int g[20][20];

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,a,x,y,ans=0,tmp=0;
    bool f;
    cin>>n;
    rep(i,0,20){
        rep(j,0,20){
            g[i][j]=-1;
        }
    }
    rep(i,0,n){
        cin>>a;
        rep(j,0,a){
            cin>>x>>y;
            x--;
            g[i][x] = y;
        }
    }
    rep(i,0,1<<n){
        vector<int>d(n);
        f=true;
        rep(j,0,n){
            if(i>>j&1){d[j]=1;}
        }
        rep(j,0,n){
            if(d[j]){
                rep(k,0,n){
                    if(g[j][k]==-1){continue;}
                    if(d[k]!=g[j][k]){f=false;}
                }
            }
        }
        if(f){ans=max(ans,__builtin_popcount(i));}
    }
    cout<<ans<<endl;
}

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

long long sum[200005];
int main(){
    int n, ans=10e9, x;
    cin >> n;
    cin >> sum[0];
    for(int i=1; i<n; ++i) { cin >> x; sum[i] += x + sum[i-1];}

    int l=0, r=2;
    for(int m=2; m<n-1; ++m){
        while(l+1 < m-1 && abs(sum[l] - (sum[m-1] - sum[l])) > abs(sum[l+1] - (sum[m-1] - sum[l+1]))) ++l;
        while(r+1 < n-1 && abs(sum[r] - sum[m-1] - (sum[n-1] - sum[r])) > abs(sum[r+1] - sum[m-1] - (sum[n-1] - sum[r+1]))) ++r;
    
        long long maxs = max(max(sum[l], sum[m-1] - sum[l]), max(sum[n-1] - sum[r], sum[r] - sum[m-1]));
        long long mins = min(min(sum[l], sum[m-1] - sum[l]), min(sum[n-1] - sum[r], sum[r] - sum[m-1]));
        ans = min(ans*1ll, maxs - mins);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
N = int(input())
alplha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
anslist = []
for k in range(10000):
    q = N//26
    r = N%26
    if r == 0:
        r = 26
        q -= 1
    anslist.append(alplha[r-1])
    N = q
    if q ==0:
        break

anslist.reverse()
ans = ''
for k in range(len(anslist)):
    ans += anslist[k]
print(ans)

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

using namespace std;

int N, M;
int dp[1 << 20];
int ruisekiwa[100001][20];
int in[100000];
int kindtonum[20];

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> in[i];
		kindtonum[in[i] - 1]++;

	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < M; j++) {
			if (in[i - 1] - 1 == j)ruisekiwa[i][j]++;
			ruisekiwa[i][j] += ruisekiwa[i - 1][j];

		}

	}
	for (int i = 1; i < (1 << M); i++) dp[i] = 1000000007;
	for (int i = 0; i < (1 << M); i++) {
		for (int j = 0; j < M; j++) {
			if (i & (1 << j))continue;

			int cost = 0;
			int totalnum = 0;
			for (int k = 0; k < M; k++)if (i & (1 << k))totalnum += kindtonum[k];

			//cout << i << " " << j << " " << totalnum << endl;

			for (int k = 0; k < M; k++)if (k != j)cost +=
				(ruisekiwa[totalnum + kindtonum[j]][k] - ruisekiwa[totalnum][k]);

			dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + cost);

		}

	}

	cout << dp[(1 << M) - 1] << endl;
	return 0;

}

Measured memory_bytes: 15368
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define mod 10e9+7
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  ll a,b=0,c;
  string s,t;
  cin >> a ;
  cin >> s;
  for(int i=0;i<a-2;i++){
     if(s.at(i)=='A' && s.at(i+1)=='B'&&s.at(i+2)=='C')
     b++;
  }
  cout << b << endl;
}
   



Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    S = input()
    nw = S[0]
    ret = 1
    for i in range(1,N):
        if nw == S[i]:
            continue
        else:
            nw = S[i]
            ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9184