akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

void bubblesort(int A[],int N, int& count){
  bool flag = 1;

  while(flag){
    flag = 0;
    for(int j = N-1; j > 0; --j){
      if(A[j] < A[j-1]){
        count++;
        swap(A[j],A[j-1]);
        flag = 1;
      }
    }
  }
}

int main(){
  int A[100], N, count = 0;

  cin >> N;
  for(int i = 0; i < N; ++i) cin >> A[i];

  bubblesort(A, N, count);

  for(int i = 0; i < N; ++i){
    if (i == (N-1))
      cout<< A[i] << endl;
    else
      cout<< A[i] <<" ";
  }

  cout << count << endl;

  return 0;
}



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

int main()
{
    int n, c;
    cin >> n >> c;
    int d[40][40];
    for(int i = 0; i < c; i++){
        for(int j = 0; j < c; j++){
            cin >> d[i][j];
        }
    }
    int cnum[3][40];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < c; j++){
            cnum[i][j] = 0;
        }
    }
    int col[600][600];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> col[i][j];
            cnum[(i + j) % 3][col[i][j] - 1]++;
        }
    }
    int ans = 1000000007;
    for(int fir = 0; fir < c; fir++){
        for(int sec = 0; sec < c; sec++){
            for(int thi = 0; thi < c; thi++){
                int sum = 0;
                for(int i = 0; i < c; i++){
                    sum += d[i][fir] * cnum[0][i];
                }
                for(int i = 0; i < c; i++){
                    sum += d[i][sec] * cnum[1][i];
                }
                for(int i = 0; i < c; i++){
                    sum += d[i][thi] * cnum[2][i];
                }
                if(fir != sec && fir != thi && sec != thi){
                    ans = min(ans, sum);
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
/*===============================================================
*  Filename：c.cpp
*  Author：zhuyutian
*  Date：2017年08月06日
================================================================*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100005;

int n;
int a[maxn];
int cnt[4];

int main()
{
    //freopen("c.in","r",stdin);
    //freopen("c.out","w",stdout);
    scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		int x;
		scanf("%d",&x);
		cnt[x%4]++;
	}
	bool ok = true;
	if(cnt[1] + cnt[3] + (cnt[2] % 2) > cnt[0] + 1) ok = false;
	puts(ok ? "Yes":"No");
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args)throws IOException{
    //BufferedReader br = new BufferedReader(System.in);
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    
    int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int k = sc.nextInt()-1;
		
		for(int i=0; i<n; i++) {
			if(s[i] == s[k])
				out.print(s[i]);
			else
				out.print("*");
		}
		out.println();
    
    out.flush();
  }
}

Measured memory_bytes: 22736
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (B % A == 0) {
		cout << A + B << endl;
	}
	else {
		cout << B - A << endl;
	}


}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  vector<int> a;  
  int it = 1;
  rep(i, 0, n) {
    int t; cin >> t;
    if(t == it) {
      a.push_back(it);
      it++;
    }
  }
  
  if(a.size() == 0)
    cout << -1 << "\n";
  else
    cout << n - a.size() << "\n";

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
string S;
int n, k, ans;
const int N = 305;
int F[N][N][N];
int main()
{
    cin >> S; n = S.size(); cin >> k;
    for (int l = 0; l < n; ++ l)
        for (int r = n - 1; r >= l; -- r)
            for (int c = 0; c <= k; ++ c)
                if (S[l] == S[r])
                {
                    F[l + 1][r - 1][c] = max(F[l + 1][r - 1][c], F[l][r][c] + 1);
                    ans = max(ans, F[l][r][c] * 2 + (l == r ? 1 : 2));
                }
                else
                {
                    if (c != k)
                        F[l + 1][r - 1][c + 1] = max(F[l + 1][r - 1][c + 1], F[l][r][c] + 1),
                        ans = max(ans, F[l][r][c] * 2 + 2);
                    F[l][r - 1][c] = max(F[l][r - 1][c], F[l][r][c]);
                    F[l + 1][r][c] = max(F[l + 1][r][c], F[l][r][c]);
                }
    cout << ans << endl;
}


Measured memory_bytes: 110848
import os, sys, re, math

(S) = input()

max_len = 0
for i in range(0, len(S)):
    for j in range(i + 1, len(S) + 1):
        substr = S[i:j]
        if len(re.sub('[ATGC]', '', substr)) == 0:
            max_len = max(max_len, len(substr))

print (max_len)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
#define int ll
ll n;

void findDivisors(ll n) 
{ 
    vector<ll> div(n+5);  
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j * i <= n; j++) 
            div[i * j]++; 
    } 
	ll ans=0;
    for (ll i = 1; i <= n; i++) 
        ans += (ll)i*(ll)div[i];
    cout<<ans; 
} 
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	findDivisors(n);
	return 0;
}


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;

void dec(map<ll, ll> &m, ll a) {
    m[a]--;
    if (m[a] == 0) m.erase(a);
}

int main() {
    int N; cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];
    map<ll, ll> m;
    rep(i, N) m[-A[i]]++;

    ll ans = 0;
    int i = 0;
    while (!m.empty() && i < N) {
        ll x = - (m.begin()->first);
        dec(m, -x);
        ll p = 1;
        while (p <= x) p *= 2;
        ll y = p - x;
        if (m.count(-y)) {
            ans++;
            dec(m, -y);
        }
        i++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 14336
n = gets.to_i
arr = gets.chomp.split('')
w_sum = [0]
e_sum = [0]
arr.each_with_index do |v, i|
  if v == 'W'
    w_sum.push(w_sum[i] + 1)
  else
    w_sum.push(w_sum[i])
  end
end
w_sum.shift
arr.reverse.each do |v, _|
  if v == 'E'
    e_sum.unshift(e_sum[0] + 1)
  else
    e_sum.unshift(e_sum[0])
  end
end
e_sum.pop
min = 300001
(0...n).each do |i|
  min = [min, w_sum[i] + e_sum[i]].min
end
puts min - 1

Measured memory_bytes: 36304
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll X; cin >> X;
  
  FOR(i,-118,120){
    FOR(j,-119,119){
      if(i*i*i*i*i - j*j*j*j*j == X){
		cout << i << " " << j <<endl;
		return 0;
      }
    }
  }
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
C - Stones
https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

"""
import sys


def solve(N, S):
    black = 0
    white = S.count('.')
    ans = float('inf')

    for s in S + ' ':
        ans = min(ans, black+white)
        if s == '#':
            black += 1
        else:
            white -= 1
    return ans


def __solve(N, S):
    ans1 = 0
    prev = '@'
    for s in S:
        if prev == '#' and s == '.':
            ans1 += 1
            prev = '#'
        else:
            prev = s
    return ans1


def main(args):
    N = int(input())
    S = input()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

typedef long long ll;
using namespace std;

const int maxn = 1e5 + 7;
const int INF = 0x3f3f3f3f;

int f[1 << 17];
int a[maxn];

int DP(int x) {
    if(f[x] != INF) return f[x];
    for(int i = 1;i <= 15;i++) {
        if((x & (1 << i)) == 0) continue;
        for(int j = 1;j <= 15;j++) {
            if(i == j) continue;
            if((x & (1 << j)) == 0) continue;
            int num = 0;
            if(x & (1 << (i ^ j))) num = 1;
            f[x] = min(f[x],DP(x ^ (1 << i) ^ (1 << j) ^ (1 << (i ^ j))) + 1 + num);
        }
    }
    return f[x];
}

int main() {
    int n;scanf("%d",&n);
    for(int i = 1;i < n;i++) {
        int x,y,z;scanf("%d%d%d",&x,&y,&z);
        x++;y++;
        a[x] ^= z;a[y] ^= z;
    }
    int sta = 0;
    int num = 0;
    memset(f,0x3f,sizeof(f));
    f[0] = 0;
    for(int i = 1;i <= n;i++) {
        if(!a[i]) continue;
        if(sta & (1 << a[i])) {
            num++;
        }
        sta ^= (1 << a[i]);
    }
    
    printf("%d\n",DP(sta) + num);
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<ll> a(3*n);
    rep(i,n*3) cin>>a[i];
    sort(a.begin(),a.end(),greater<ll>());
    ll ans = 0;
    rep(i,n){
        ans+=a[2*i+1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

unsigned long long dp[50] = {0};

unsigned long long fib(int n){
  if(n == 0){
    return 1;
  } else if(n == 1){
    return 1;
  } else if(dp[n] != 0){
    return dp[n];
  } else {
    dp[n] = fib(n-1) + fib(n-2);
    return dp[n];
  }

}

int main(){
  int n;

  cin >> n;

  cout << fib(n) << endl;

  return 0;
}

Measured memory_bytes: 3084
using System;

namespace _5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string[] sss = Console.ReadLine().Split(' ');
                var a = int.Parse(sss[0]);
                var b = int.Parse(sss[1]);
                if (a == 0 && b == 0) break;
                for(var i=0;i<a;i++)
                {
                    for(var j=0;j<b;j++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 15940
#両端が違う文字abpipjarjob→奇数ならFirst,偶数ならSecond
#両端が同じ文字abaiaja→奇数ならSecond、偶数ならFirst
#abab→
a = gets.chomp.split("")
matsu = a.length - 1
if a[0] == a[matsu]
  if a.length%2 == 0
    print("First")
  else print("Second")
  end
else
  if a.length%2 == 0
    print("Second")
  else print("First")
  end
end

Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e;
string s;
bool cnt(int q, int w){
    for(int i=q; i<=w; i++){
        if(s[i]!=s[w-(i-q)]) return 0;
    }
    return 1;
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>s;
    a=s.size();
    s.insert(0,"0");
    if(cnt(1,a)==1&&cnt(1,(a-1)/2)==1&&cnt((a+3)/2,a)==1){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define MOD 1000000007

int n;
ll x[5252];
vi g[5252];

ll sum, a;

int cnt[5252];
ll subsum[5252];

void dfs1(int p, int bef){
  cnt[p] = 1;
  subsum[p] = x[p];
  for(int to : g[p])if(to != bef){
    dfs1(to, p);
    cnt[p] += cnt[to];
    subsum[p] += subsum[to];
  }
}

ll dp[5252][5252];  // dp[p][b] := b個がa+1, cnt[p]-b個がaになる時の最小コスト, b<=cnt[p]
ll tmp[5252];
void dfs2(int p, int bef){
  dp[p][0] = dp[p][1] = 0;
  int m = 2;
  for(int to : g[p])if(to != bef){
    dfs2(to, p);
    // merge
    REP(i,cnt[to]+m)tmp[i] = 1ll<<60;
    REP(i,cnt[to]+1)REP(j,m){
      CHMIN(tmp[i+j], dp[to][i]+dp[p][j]);
    }
    REP(i,cnt[to]+m)dp[p][i] = tmp[i];
    m += cnt[to];
  }
  REP(i,m){
    ll sm = a*cnt[p] + i;
    dp[p][i] += abs(sm-subsum[p]);
  }
}

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%lld",x+i);
  REP(i,n-1){
    int u,v;
    scanf("%d%d",&u,&v);
    --u;--v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  sum = accumulate(x,x+n,0ll);
  a = sum/n;
  dfs1(0,-1);
  dfs2(0,-1);
  printf("%lld\n",dp[0][sum%n]);
  return 0;
}



Measured memory_bytes: 121424
#include<vector>
#include<iostream>
using namespace std;
const int maxn=15;
int sum[maxn];
bool check(int i,vector<int> &left,vector<int> &right)
{
	int a=left.size()-1,b=right.size()-1;
	if(i==10&&left[a-1]<left[a]&&right[b-1]<right[b])
		return true;
	if(a>=1)
	{
		if(left[a-1]<left[a])
		{
	left.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
		}
		else
			return false;
	}
	else
	{
		left.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
	}
	left.pop_back();
	if(b>=1)
	{
		if(right[b-1]<right[b])
		{
			right.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
		}
		else
			return false;
	}
	else
	{
	right.push_back(sum[i]);
	if(check(i+1,left,right))
		return true;
	}
	right.pop_back();
	return false;
}
int main()
{
	int N;
	cin>>N;
	while(N--)
	{
		vector<int> left,right;
		for(int i=0;i<10;i++)
			cin>>sum[i];
		if(check(0,left,right))
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

ll n, s; 

bool check(ll b) {
	if(b < 2) return false;
	ll t = n, d = 0;
	while(t > 0) {
		d += t % b;
		t /= b;
	}
	if(s == d) return true;
	else return false;
}

int main(void){
	cin >> n >> s;
	if(s == n){
		printf("%lld\n", n + 1); return 0;
	}

	ll ans = INFF;

	for (ll b = 2; b * b <= n; ++b){
		if(check(b)) chmin(ans, b);
	}

	// (n - s) / p + 1 = b
	for (ll p = 1; p*p <= n - s; ++p) {
		if((n - s) % p) continue;
		ll b = (n - s) / p + 1;
		if(check(b)) chmin(ans, b);
	}
	
	if(ans != INFF) printf("%lld\n", ans);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
/*Problem Statement
There are 
N
 stones, numbered 
1
,
2
,
…
,
N
. For each 
i
 (
1
≤
i
≤
N
), the height of Stone 
i
 is 
h
i
.

There is a frog who is initially on Stone 
1
. He will repeat the following action some number of times to reach Stone 
N
:

If the frog is currently on Stone 
i
, jump to Stone 
i
+
1
 or Stone 
i
+
2
. Here, a cost of 
|
h
i
−
h
j
|
 is incurred, where 
j
 is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone 
N
.

Constraints
All values in input are integers.
2
≤
N
≤
10
5
1
≤
h
i
≤
10
4
*/
#include<vector>
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;

int jump_dp[100001];
int minjump(vector<int> & h, int n, int k);
int minjump(vector<int> & h, int n, int k) {

   // cout << " :n: :k: " << n <<" " << k;
    if (jump_dp[n] != -1)
      return jump_dp[n];
    if (k > n)
      k = n;
    int temp = 1;
    while (temp <= k) {
    int x = minjump(h, n-temp, k);
    if (temp == 1)
      jump_dp[n] = x + abs(h[n] - h[n-temp]);
    else
      jump_dp[n] = min(x + abs(h[n] - h[n-temp]), jump_dp[n]);
    temp++;
    }
    return jump_dp[n];
}
int main()
{
    int n;
    scanf("%d" , &n);
    int k;
    scanf("%d", &k);
    if (k > n)
     k = n-1;
    vector<int> heights(n);
    for(auto &x: heights)
      scanf("%d", &x);
    for(auto &x: jump_dp)
      x = -1;
    jump_dp[0] = 0;
    jump_dp[1] = abs(heights[0] - heights[1]);
    cout << minjump(heights, n-1, k) << endl;
    return 0;
}

Measured memory_bytes: 8832
use proconio::*;
use proconio::marker::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: Chars,
    }
    println!("{}",
        if N.iter().filter(|&c| *c == '7').count() >= 1 { "Yes" } else { "No" }
    )
}


Measured memory_bytes: 2092
#ABC123 A
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
mylist = [a,b,c,d,e]
ans = 0
for i in range(0, len(mylist)-1):
    for j in range(1, len(mylist)):
        if ((mylist[j] - mylist[i]) > k):
            ans += 1
print(":(" if ans >0 else "Yay!")

Measured memory_bytes: 3064
n = int(input())
A = [int(i) for i in input().split()]

q = int(input())
m = [int(i) for i in input().split()]

def dfs(idx, s, target):
    if s == target:
        return 1
    
    if s > target or idx == n:
        return 0
    if s + sum(A[idx:]) < target:
        return 0

    return dfs(idx+1, s, target) or dfs(idx+1, s + A[idx], target)

for target in m:
    ans = 'yes' if dfs(0, 0, target) else 'no'
    print(ans)


Measured memory_bytes: 5628
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main
{
	public static void main (String[] args)
	{
		Scanner sc=new Scanner(System.in); 
		int t,i;	
		int n=sc.nextInt();
		int a[][]=new int[n][3];
		for(i=0;i<n;i++)
		{
			a[i][0]=sc.nextInt();
			a[i][1]=sc.nextInt();
			a[i][2]=sc.nextInt();
		}
		long dp[][]=new long[n+1][3];
		for(i=1;i<=n;i++)
		{
			for(int j=0;j<3;j++)
			{
				for(int k=0;k<3;k++)
				{
					if(j!=k)
					{
						dp[i][j]=Math.max(dp[i][j], dp[i-1][k]+a[i-1][k]);
					}
				}
			}
		}
		System.out.println(Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2])));
	}
}

Measured memory_bytes: 64084
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


ll dp[60][205000];
int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,k;
    cin >> n >> k;
    rep(i, n){
        cin >> dp[0][i];
        dp[0][i]--;
    }
    rep(i, 59){
        rep(j, n){
            dp[i + 1][j] = dp[i][dp[i][j]];
        }
    }
    int v = 0;
    rep(i, 60){
        if(k & (1LL << i)) v = dp[i][v];
    }
    print(v + 1);


}



Measured memory_bytes: 97640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))


def main():
    n = int(input())
    a = list(sorted(map(int, input().split())))
    
    if a[0] == a[-1]:
        if (a[0] == n-1 or a[0]*2 <= n):
            print("Yes")
        else:
            print("No")
    elif a[-1] - a[0] > 1:
        print("No")
    else:
        minc = 0
        for _a in a:
            if _a == a[0]:
                minc += 1
            else:
                break
        if minc <= a[0] and n-minc>=2*(a[-1]-minc):
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14040
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    M = I()
    L = [LI() for i in range(M)]
    L = L[::-1]
    temp = 0
    ans = 0
    for a, b in L:
        temp += a*b
        ans += b
        while temp >= 10:
            temp2 = temp // 10
            ans += temp2
            temp = (temp % 10) + temp2

    print(ans-1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 102336
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef long long ll;

int N, M, Z;
int tt[200][200], t[200][200];
map<P,int> idx;
P ridx[200];

const int MOD = 10000;

mat mul(mat &A, mat &B){
  mat C(A.size(), vec(B[0].size()));
  for(int i = 0; i < A.size(); i++){
    for(int k = 0; k < B.size(); k++){
      for(int j = 0; j < B[0].size(); j++){
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
      }
    }
  }
  return C;
}

mat pow(mat A, ll n){
  mat B(A.size(), vec(A.size()));

  for(int i = 0; i < A.size(); i++){
    B[i][i] = 1;
  }
  while(n > 0){
    if(n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}

int main(){
  while(cin >> N >> M >> Z, N || M || Z){
    memset(tt, 0, sizeof(tt));
    idx.clear();

    for(int i = 1; i <= N; i++){
      int size = idx.size();
      idx[P(i, 0)] = size;
      ridx[size] = P(i, 0);
    }

    for(int i = 0; i < M; i++){
      int a, b;
      cin >> a >> b;
      tt[a][b] = tt[b][a] = true;

      int size = idx.size();
      idx[P(a, b)] = size;
      idx[P(b, a)] = size + 1;

      ridx[size] = P(a, b);
      ridx[size + 1] = P(b, a);
    }

    memset(t, 0, sizeof(t));

    for(int i = 1; i <= N; i++){ //今いる位置
      for(int j = 0; j <= N; j++){ //前いた位置
        if(j != 0 && !tt[i][j]) continue;
        if(idx.find(P(i, j)) == idx.end()) continue;

        int from = idx[P(i, j)];

        for(int k = 1; k <= N; k++){
          if(i == k || k == j) continue;
          if(!tt[i][k]) continue;
          if(idx.find(P(k, i)) == idx.end()) continue;

          int to = idx[P(k, i)];

          t[from][to] = true;
        }
      }
    }

    mat A;

    for(int i = 0; i < idx.size(); i++){
      vec v;
      for(int j = 0; j < idx.size(); j++){
        v.push_back(t[i][j]);
      }
      A.push_back(v);
    }

    mat ans = pow(A, Z);
    bool flg = false;

    for(int j = 0; j < idx.size(); j++){
      if(ans[0][j] > 0 && ridx[j].first == N){
        flg = true;
        break;
      }
    }

    cout << (flg ? "yes" : "no") << endl;
  }
}

Measured memory_bytes: 1896
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
const double PI = 3.14159265358979323846264338327950288;

vector<int> G[100010];
int ans[100010];
int visit[100010];
void bfs() {
	queue<int> que;
	visit[0] = true;
	que.push(0);
	while (!que.empty()) {
		int v = que.front();
		visit[v] = true;
		que.pop();
		for (int to : G[v]) {
			if (visit[to]) continue;
			else {
				visit[to] = true;
				ans[to] = v;
				que.push(to);
			}
		}
	}
}
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0;i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	bfs();
	cout << "Yes" << endl;
	for (int i = 1; i < N; i++) {
		cout << ans[i] + 1 << endl;
	}
}


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

ll lon(int n){
    if(n == 0) return 1;
    else return 2*lon(n-1)+3;
}

ll f(int n, ll x){
    if(n == 0 && x == 0) return 0;
    if(n == 0 && x == 1) return 1;
    if(x == 0 || x == 1) return 0;
    else if(x <= (lon(n)-1)/2) return f(n-1,x-1);
    else if(x == (lon(n)+1)/2) return f(n-1,x-2)+1;
    else if(x <= lon(n)-1) return f(n-1,lon(n-1))+f(n-1,x-lon(n-1)-2)+1;
    else return f(n-1,lon(n-1))*2+1;
}

int main(){
    int n; ll x; cin >> n >> x;
    cout << f(n,x) << endl;
}

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

using namespace std;

const long long INFTY = 1e20;

int main(){
    int N; cin >> N;
    vector<long long> A(N);
    long long sum = 0ll;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }

    long long x, y, ans;
    x = A[0];
    y = sum - x;
    ans = abs(x-y);
    for(int i=1;i<N-1;i++){
        x += A[i];
        y = sum - x;
        ans = min(ans, abs(x-y));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int S,W; cin >> S >> W;
  if(W>=S) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}


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

int main(){
    int n;
    while(cin>>n,n){
        vector<pair<int,int>> rw(n);
        for(int i=0;i<n;i++) cin>>rw[i].first>>rw[i].second;
        if(n==1){
            cout<<2*rw[0].first+rw[0].second<<endl;
            continue;
        }
        sort(rw.begin(),rw.end(),greater<pair<int,int>>());
        int rsum=accumulate(rw.begin(),rw.end(),0,[](int x,pair<int,int> y){return x+y.first;});
        int wsum=accumulate(rw.begin(),rw.end(),0,[](int x,pair<int,int> y){return x+y.second;});
        if(rsum<2*rw[0].first){
            int span=rw[0].first-(rsum-rw[0].first);
            vector<vector<int>> dp(n,vector<int>(span+1,0));
            dp[0][0]=true;
            for(int i=0;i<n-1;i++){
                for(int j=0;j<=span;j++){
                    dp[i+1][j]|=dp[i][j];
                    if(j-rw[i+1].second>=0) dp[i+1][j]|=dp[i][j-rw[i+1].second];
                }
            }
            int re=0;
            for(int i=0;i<=span;i++){
                if(dp[n-1][i]) re=i;
            }
            cout<<rw[0].first*2+wsum-re<<endl;
        }
        else{
            cout<<rsum+wsum<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3300
n = int(input())
arm = []
for i in range(n):
    x, l = map(int, input().split())
    arm.append([x-l, x+l])

arm.sort(key=lambda x: x[1])
ans = 0
lon = -(10 ** 9)
for i in range(n):
    if lon <= arm[i][0]:
        lon = arm[i][1]
        ans += 1

print(ans)


Measured memory_bytes: 21336
from collections import defaultdict

s = input()
memo = defaultdict(int)

def calc_sum(num, t):
  if len(t) == 1:
    return num + int(t)
  return num + int(t) + sum(calc_sum(num + int(t[:i]), t[i:]) for i in range(1, len(t)))

print(calc_sum(0, s))

Measured memory_bytes: 3316
import java.io.*;
import java.util.*;

public class Main {
  private static boolean solve(int n) {
    boolean[] dptable = new boolean[n + 1];
    dptable[0] = true;
    for (int v : new int[]{4, 7}) {
      for (int i = v; i <= n; i++) {
        dptable[i] |= dptable[i - v];
      }
    }
    return dptable[n];
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    out.println(solve(n) ? "Yes" : "No");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 23252
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] X = new int[N+1];
    X[0] = 0;
    for (int i = 1; i <= N; i++) {
      X[i] = sc.nextInt();
    }
    
    int hp = 2147483647;
    for (int P = 0; P <= N*3; P++) {
      int sum = 0;
      for (int j = 1; j <= N; j++) {
        sum += (X[j]-P) * (X[j]-P);
      }
      if (sum < hp) {
        hp = sum;
      }
    }
    
    System.out.println(hp);
  }
}

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

cands = [1]
for i in range(1, 10):
    if 6**i <= 100000:
        cands.append(6**i)
    if 9**i <= 100000:
        cands.append(9**i)
cands = sorted(cands)

ans = list(range(n+1))
for c in cands[1:]:
    for i in range(n+1):
        if i < c:
            pass
        else:
            ans[i] = min(ans[i], ans[i-c] + 1)
print(ans[-1])

Measured memory_bytes: 6900
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
 
 
int main() {
    int N, M;
    cin >> N >> M;
  
    vector<int>p(N);
    for (int i = 0; i < N; i++){
      cin >> p.at(i);
    }
 
    //友達集合を作る
    UnionFind UF(N);
    for (int i = 0; i < M; i++){
      int X, Y;
      cin >> X >> Y;
      X -= 1; 
      Y -= 1;
      UF.unite(X, Y);
    }
 
    //最大の友達集合を求める
    int count = 0;
    for (int i = 0; i < N; i++){
        if (UF.same(p.at(i)-1, i)){
          count++;
        }
    }
 
    cout << count << endl;
    return 0;
}



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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  ll W,H,x,y;
  cin>>W>>H>>x>>y;
  
  double ans;
  ans=(double)W*(double)H/2;
  bool A;
  if(x*2==W&&y*2==H)
    A=true;
  else
    A=false;
  cout<<fixed<<ans<<" "<<A<<endl;

  return 0;
}


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

int main(){

  int a=0;
  int b=0;
	
  int c=0;
  
  cin>>a>>b>>c;
  if(a+b+c>21)cout<<"bust";
  else cout<<"win";
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int four = 0;
		int two = 0;
		for(int i = 0;i <n;i++) {
			int number = sc.nextInt();
			if(number %4 ==0) {
				four++;;
			}else if(number %2 ==0) {
				two++;
			}
		}
		if(n % 2 ==0 ) {
			if(four >= n/2) {
				System.out.println("Yes");
				return;
			}else if(n-(four *2) <= two) {
				System.out.println("Yes");
				return;
			}else {
				System.out.println("No");
				return;
			}
		}else {
			if(four >= (n-1)/2) {
				System.out.println("Yes");
				return;
			}else if(n-(four *2) <= two) {
				System.out.println("Yes");
				return;
			}else {
				System.out.println("No");
				return;
			}
		}
	}
}

Measured memory_bytes: 48240
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	char mp[2][3];
	rep(i, 2)rep(j, 3)cin >> mp[i][j];
	string ans = "YES";
	rep(j, 3) {
		if (mp[0][j] != mp[1][2 - j])ans = "NO";
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  int digit[3];
  
  scanf("%lld",&n);
  scanf("%s",s);
  
  rep(i,1000){
    digit[0] = i/100;
    digit[1] = (i/10)%10;
    digit[2] = i%10;
    k=0;
    for(j=0;j<n;j++){
      if((int)(s[j]-'0')==digit[k]) k++;
      if(k>=3) break;
    }
    if(k==3) result++;
  }
  printf("%lld", result);
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
typedef struct{
  int boss;
  int sub;
}manage;
 
int main(void){
  
  int n, i;
  manage member[200002] = {{0,0}};
  
  scanf("%d", &n);
  
  for(i = 2; i <= n; i++){
    scanf("%d", &member[i].boss);
    member[member[i].boss].sub++;
  }
  
  for(i = 1; i <= n; i++){
    printf("%d\n",member[i].sub); 
  }
  
  return 0;
 
}

Measured memory_bytes: 3264
#include <iostream>

int main() {
  int input, hour, last;
  std::cin >> input;
  hour = input / (60 * 60);
  last = input % (60 * 60);

  std::cout << hour << ":" <<  last / 60 << ":" << 
    last % 60 << std::endl;

  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 10003
#define D 101
#define MOD 1000000007

string k;
int n, d;
ll dp[N][D][2];

int main() {
  cin >> k >> d;
  n = k.length();
  rep(i, n+1) rep(j, d) rep(k, 2) dp[i][j][k] = 0;
  dp[0][0][0] = 1;
  rep(i, n) {
    int v = k[i] - '0';
    rep(j, d) {
      rep(k, 2) {
        dp[i][j][k] %= MOD;
        rep(w, 10) {
          if(!k && v < w) continue;
          dp[i+1][(j+w) % d][k | (w < v)] += dp[i][j][k];
        }
      }
    }
  }
  cout << (dp[n][0][0] + dp[n][0][1] - 1) % MOD << endl;

  return 0;
}

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

int main(){
    string s;
    string ring;
    int n;
    int cnt=0;
    cin >> ring >> n;
    while(n--){
        cin >> s;
        s = s + s;
        if(s.find(ring) != string::npos) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1212
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        Long N = sc.nextLong();
        sc.close();
        Long min = N+1;

        for(long i = 1; i <= Math.sqrt(N); i++){
            if((N % i) == 0){
                long j = N / i;
                if(min > i+j){
                    min = i+j;
                }   
            }
        }

        System.out.println(min-2);

    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  int n, l; cin >> n >> l;
  vi32 a(n);
  rep(i, n) a[i] = l + i;
  int sum = 0;
  rep(i, n) sum += a[i];
  int ans = 1e9, cou = 1e9;
  rep(i, n) {
    int s = 0;
    rep(j, n) if (i != j) s += a[j];
    if (ans > abs(sum - s)) {
      ans = abs(sum - s);
      cou = s;
    }
  }
  cout << cou << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define po pop_front
#define mo(o) memset(o,-1,sizeof(o))
#define forn(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define mp make_pair
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
	int k;
	cin>>k;
	for(int i=0;i<k;i++)
		cout<<"ACL";
	cout<<endl; 
	return 0;
}

Measured memory_bytes: 3652