akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
const int N = 10;
int p[N];
bool graph[N][N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < N; i++) {
        p[i] = i;
        for (int j = 0; j < N; j++) {
            graph[i][j] = false;
        }
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a][b] = true;
        graph[b][a] = true;
    }
    int res = 0;
    do {
        bool cur_ans = true;
        for (int i = 0; i < n - 1; i++) {
            if (!graph[p[i]][p[i + 1]]) {
                cur_ans = false;
                break;
            }
        }
        if (cur_ans) res++;
    } while (next_permutation(p + 1, p + n));
    cout << res << endl;
    return 0;
}


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

int main(void){
    string b;
    cin >> b;
    if(b=="A"){
        cout << "T\n";
    }else if(b=="T"){
        cout << "A\n";
    }else if(b=="C"){
        cout << "G\n";
    }else{
        cout << "C\n";
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int n;
    cin >> n;
    vector<int> h(n + 1);
    bool ans = true;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
        if (h[i - 1] - h[i] > 1) {
            ans = false;
            break;
        }
        h[i] = max(h[i], h[i - 1]);
    }

    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

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

namespace Algorithm
{
    class Program
    {
        const int N = 100;
        const int White = 0;
        const int Gray = 1;
        const int Black = 2;
        static int n, tt;
        static int[][] ans;
        static int[] color, d, f;
        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            color = new int[n];
            d = new int[n];
            f = new int[n];
            ans = new int[n][];

            for (var i = 0; i < n; i++)
            {
                var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
                ans[i] = new int[n];
                for (var j = 2; j < 2 + t[1]; j++)
                {
                    ans[t[0] - 1][t[j] - 1] = 1;
                }
            }

            Dfs();
        }

        static void DfsVisit(int u)
        {
            color[u] = Gray;
            d[u] = ++tt;
            for (var v = 0; v < n; v++)
            {
                if (ans[u][v] == 0) continue;
                if (color[v] == White)
                {
                    DfsVisit(v);
                }
            }
            color[u] = Black;
            f[u] = ++tt;
        }

        static void Dfs()
        {
            for (var u = 0; u < n; u++) color[u] = White;
            tt = 0;

            for (var u = 0; u < n; u++)
            {
                if (color[u] == White) DfsVisit(u);
            }
            for (var u = 0; u < n; u++)
            {
                Console.WriteLine($"{u+1} {d[u]} {f[u]}");
            }
        }
    }
}



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

using namespace std;

const int N = 200005;

int n;
int p[N];

int main() {

	int k;
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++) scanf("%d", p + i), p[i] += p[i - 1];

	int mx = 0;
	for(int i = k; i <= n; i++) {
		mx = max(mx, p[i] - p[i - k]);
	}

	mx += k;
	printf("%d.%d\n", mx / 2, mx % 2 ? 5 : 0);
}


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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> Number(200000,0);
  for(ll i=0;i<N;i++){
    cin >> A.at(i);
    Number.at(A.at(i)-1)++;
  }
  ll Sum;
  for(ll x:Number){
    if(x!=0){
      Sum+=x*(x-1)/2;
    }
  }
  for(ll k=0;k<N;k++){
    cout << Sum-(Number.at(A.at(k)-1)-1) <<endl;
  }
}


Measured memory_bytes: 6340
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, k, r, s, p, i, score=0;
    string t;
    char a[101000];
    cin >> n >> k >> r >> s >> p;
    cin >> t;
    for(i=0;i<n;i++){
        if(i<k){
            if(t[i]=='r'){
                score+=p;
                a[i]='p';
            }
            else if(t[i]=='s'){
                score+=r;
                a[i]='r';
            }
            else if(t[i]=='p'){
                score+=s;
                a[i]='s';
            }
        }
        else{
            if(t[i]=='r' && a[i-k]!='p'){
                score+=p;
                a[i]='p';
            }
            else if(t[i]=='s' && a[i-k]!='r'){
                score+=r;
                a[i]='r';
            }
            else if(t[i]=='p' && a[i-k]!='s') {
                score+=s;
                a[i]='s';
            }
            else a[i]='n';
        }
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iterator>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	string str;
	string str2;
	stringstream ss;
	int a,b,c,n,nn;
	char sum[10];
	while(1){
		cin >> n;
		if(n==0)break;
		cin >> str;
		for(a=0;a<n;a++){
			nn=1;
			for(b=1;b<str.size();b++){
				if(b==str.size()-1){
					if(str[b-1]==str[b]){
						nn++;
						while(nn>=0){
							if(nn>=10)str2+=nn/10+'0';
							else{
								str2+=nn%10+'0';
								nn=-1;
							}
							int nnn=10;
							while(nn>nnn*10){
								nnn*=10;
							}
							nn=nn-nnn;

						}
						back_inserter(str2)=str[b-1];
					}else{
						while(nn>=0){
							if(nn>=10)str2+=nn/10+'0';
							else{
								str2+=nn%10+'0';
								nn=-1;
							}
							int nnn=10;
							while(nn>nnn*10){
								nnn*=10;
							}
							nn=nn-nnn;
						}
						back_inserter(str2)=str[b-1];
						back_inserter(str2)='1';
						back_inserter(str2)=str[b];
					}
				}else{
					if(str[b-1]==str[b]){
						nn++;
					}else{
						while(nn>=0){
							if(nn>=10)str2+=nn/10+'0';
							else{
								str2+=nn%10+'0';
								nn=-1;
							}
							int nnn=10;
							while(nn>nnn*10){
								nnn*=10;
							}
							nn=nn-nnn;
						}
						back_inserter(str2)=str[b-1];
						nn=1;
					}
				}
			}
			str=str2;
			str2="";
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 0
S = input()
alpha = ['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',]
for i in alpha :
    if (i in S) == False :
        print(i)
        exit()
print('None')

Measured memory_bytes: 9228
n, m = map(int, input().split())
s = [0]*m
c = [0]*m
for i in range(m):
    s[i], c[i] = map(int, input().split())

ans = -1

for num in range(0, 1000):
    num_car = str(num)

    con1 = len(num_car) == n

    con2 = True
    for i in range(m):
        if con1 and num_car[s[i] - 1] != str(c[i]):
            con2 = False

    if con1 and con2:
        ans = num
        break

print(ans)

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

typedef unsigned long long int ULLI;

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

int N;
int Y;
int X;
int ls[114];
int rs[114];
int ts[114];
int bs[114];
ULLI field[1145][1419];
bool used[1145][1419];
vector<int> xs;
vector<int> ys;

bool WithinRange(int y, int x) {
  if (y < 0 || Y <= y) return false;
  if (x < 0 || X <= x) return false;
  return true;
}

void dfs(int y, int x) {
  used[y][x] = true;

  for (int i=0; i<4; i++) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (!WithinRange(ny, nx)) continue;
    if (used[ny][nx]) continue;
    if (field[y][x] != field[ny][nx]) continue;
    dfs(ny, nx);
  }
}

int main() {
  while (1) {
    scanf("%d", &N);
    if (N == 0) return 0;

    for (int i=0; i<N ; i++) {
      scanf("%d%d%d%d", &ls[i], &ts[i], &rs[i], &bs[i]);
      for (int j=-1; j<=1; j++) {
        xs.emplace_back(ls[i]+j);
        xs.emplace_back(rs[i]+j);
        ys.emplace_back(ts[i]+j);
        ys.emplace_back(bs[i]+j);
      }
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
  
    for (int i=0; i<N; i++) {
      ls[i] = lower_bound(xs.begin(), xs.end(), ls[i]) - xs.begin();
      rs[i] = lower_bound(xs.begin(), xs.end(), rs[i]) - xs.begin();
      ts[i] = lower_bound(ys.begin(), ys.end(), ts[i]) - ys.begin();
      bs[i] = lower_bound(ys.begin(), ys.end(), bs[i]) - ys.begin();
    }

    Y = ys.size()+1;
    X = xs.size()+1;
    xs.clear();
    ys.clear();

    fill(field[0], field[Y], 0);
    for (int i=0; i<N; i++) {
      for (int j=bs[i]; j<ts[i]; j++) {
        for (int k=ls[i]; k<rs[i]; k++) {
          field[j][k] |= ULLI(1) << ULLI(i);
        }
      }
    }
  
    fill(used[0], used[Y], false);

    int ans = 0;
    for (int i=0; i<Y; i++) {
      for (int j=0; j<X; j++) {
        if (!used[i][j]) {
          ans++;
          dfs(i, j);
        }
      }
    }
  
    printf("%d\n", ans);
  }
}



Measured memory_bytes: 8444
#include<iostream>
#include<string>

using namespace std;

int main(void){
    int i;
    int cnt[26]={0};
    string s;
    string abc="abcdefghijklmnopqrstuvwxyz";
    while(getline(cin,s)){
    for(i=0;i<s.size();i++){
        if(s[i]!=' ' && islower(s[i])) cnt[s[i]-'a']++;
        if(s[i]!=' ' && isupper(s[i])) cnt[s[i]-'A']++;
    }
    }
    for(i=0;i<26;i++){
        cout << abc[i] << " : " << cnt[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
//-----

var log = console.log;
if (typeof process != "undefined") {
	var input = "";
	process.stdin.resume();
	process.stdin.setEncoding('utf8');
	process.stdin.on('data', function (chunk) {
		input += chunk;
	});
	process.stdin.on('end', function () {
		before(input);
	});
}

function before(input) {
	var lines = input.split("\n");
	lines.shift();
	lines.pop();
	main(lines);
}

//-----

function main(lines) {
	var numbers = lines.pop().split(" ").map(function (e) {
		return Number(e);
	});
	var len = numbers.length;
	for (var i = 0; i < len; i++) {
		var part = numbers.slice(0, i + 1);
		var another = numbers.slice(i + 1, len);
		part = part.sort(function (a, b) {
			return a - b;
		});
		numbers = part.concat(another);
		log(numbers.join(" "));
	}
}

Measured memory_bytes: 17460
#include <algorithm>
#include <cstdio>
typedef std::pair<int,int> P;
const int N=100005;
int b[N],r,c,n,m=0;
P a[N];
int R(){
	int x,y;
	scanf("%d%d",&x,&y);
	if (!x || y==c) return x+y;
		else if (!y || x==r) return (r+c)*2-x-y;
	return -1;
}
int main(){
	scanf("%d%d%d\n",&r,&c,&n);
	for (int i=1;i<=n;i++){
		int x=R(),y=R();
		if (x>y) std::swap(x,y);
		if (x>=0) a[++m]=P(x,y);
	}
	std::sort(a+1,a+m+1);
	for (int i=1,top=0;i<=m;i++){
		for (;top && b[top]<a[i].first;top--);
		if (top && b[top]<a[i].second){
			printf("NO\n");
			return 0;
		}
		b[++top]=a[i].second;
	}
	printf("YES\n");
}

Measured memory_bytes: 1152
n,k=map(int,input().split())
a=list(map(int,input().split()))
def ok(l):
    cnt = 0
    for L in a:
        cnt += L//l
        if L%l != 0:
            cnt +=1
        cnt-=1
    return cnt<=k

bot,top=0,max(a)
while top - bot >1:
    mid = (top + bot) //2
    if ok(mid): top = mid
    else: bot = mid
print(top)

Measured memory_bytes: 104420
import sys
input = sys.stdin.readline
n = int(input())
b = list(map(int,input().split()))
count = b[0]
for i in range(n-2):
  if b[i] >= b[i+1]:
    count += b[i+1]
  else:
    count += b[i]
count += b[n-2]
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ios()                \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)


signed main()
{
    ios();
    int n;
    cin >> n;
    pair<int, int> task[n];
    for (int i = 0; i < n; i++) {
        cin >> task[i].first >> task[i].second;
    }
    sort(task, task + n, [](auto a, auto b){return a.second < b.second;});
    int t = 0;
    for (int i = 0; i < n; i++) {
        t += task[i].first;
        if (t > task[i].second) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3328
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,m,ans=0;cin>>n>>m;
  V<ll> v(n);
  rep(i,0,n){
    cin>>v[i];
    --v[i];
  }

  V<ll> dif(m,0),res(m);

  rep(i,0,n-1){
    ll a=v[i],b=v[i+1],c;
    if(a<b){
      dif[a+1]++;
      dif[b]--;
      c=b-a-1;
      ans+=b-a;
    }else if(b<a){
      if(a<m-1)dif[a+1]++;
      dif[0]++;
      dif[b]--;
      c=b+m-a-1;
      ans+=b+m-a;
      res[0]+=b+m-a-1-(b);
    }

    dif[b]-=c;
    if(b<m-1)dif[b+1]+=c;
  }

  rep(i,1,m)dif[i]+=dif[i-1];
  rep(i,1,m)res[i]=res[i-1]+dif[i-1];

  ll tmp=0;
  rep(i,0,m)chmax(tmp,res[i]);
  cout<<ans-tmp<<ENDL;

}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3;
const lli INF = 1e18;
const lli MOD = 1e9+7;

bool m[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7


int main(){_
	int n,k; cin>>n>>k;
	vi v(n); fore(i,0,n)cin>>v[i];
	sort(all(v));
	lli sum = 0;
	fore(i,0,k)sum+=v[i];cout<<sum<<ENDL;
}


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

using namespace std;
const int maxn = 2e5 + 5;

int a[maxn], b[maxn];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) scanf("%d", &a[i]), b[a[i]]++;
    for (int i = 1; i <= n; i++) printf("%d\n", b[i]);
    return 0;
}


Measured memory_bytes: 5312
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int N;
vector<int> G[100010];
int dist[100010];
vector<int> T;

void bfs() {
  queue<int> q;
  q.push(0);
  rep(i, N) dist[i] = inf;
  dist[0] = 0;
  while(!q.empty()) {
    auto p = q.front(); q.pop();
    T.push_back(p);
    for(auto e: G[p]) {
      if(dist[e] < inf) continue;
      dist[e] = dist[p] + 1;
      q.push(e);
    }
  }
}

int parent[22][100010];
int depth[100010];

void dfs(int v, int p, int d) {
  parent[0][v] = p;
  depth[v] = d;
  for(auto && e: G[v]) if(e != p) {
    dfs(e, v, d + 1);
  }
}

void init() {
  dfs(0, -1, 0);
  rep(k, 20) rep(v, N)
    if(parent[k][v] == -1)
      parent[k+1][v] = -1;
    else
      parent[k+1][v] = parent[k][parent[k][v]];
}

int lca(int u, int v) {
  if(depth[u] > depth[v])
    swap(u, v);
  rep(k, 22) if((depth[v] - depth[u]) >> k & 1) {
    v = parent[k][v];
  }
  if(u == v)
    return u;
  for(int k=21; k>=0; k--)
    if(parent[k][u] != parent[k][v])
      u = parent[k][u],
      v = parent[k][v];
  return parent[0][u];
}

int main() {

  cin >> N;

  rep(i, N - 1) {
    int x; cin >> x; x--;
    G[x].push_back(i+1);
  }

  init();
  bfs();

  ll ans = 0;
  REP(i, 1, T.size()) {
    int a = T[i - 1];
    int b = T[i];
    ans += dist[a] + dist[b] - 2 * dist[lca(a, b)];
  }

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

Measured memory_bytes: 22488
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    limit = 10 ** 18

    if 0 in a:
        print(0)
        exit()

    ans = 1
    for i in a:
        ans *= i
        if ans > limit:
            ans = -1
            break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21596
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define INF 2147483647
#define nINF -2147483648
struct point{
	int x,y,t;
}pts[100005];
bool cmp(point a,point b){
	return a.t<b.t;
}
int abs(int a){
	return a<0?-a:a;
}
int main(){
	int n;
	while(~getI(n)){
		F(i,0,n) getIII(pts[i].t,pts[i].x,pts[i].y);
		sort(pts,pts+n,cmp);
		bool ans=1;
		if(pts[0].x+pts[0].y!=pts[0].t) ans=0;
		for(int i=1;i<n;i++){
			if(pts[i].t-pts[i-1].t<abs(pts[i].x-pts[i-1].x)+abs(pts[i].y-pts[i-1].y)) ans=0;
			else if(pts[i].t-pts[i-1].t>abs(pts[i].x-pts[i-1].x)+abs(pts[i].y-pts[i-1].y)){
				if((pts[i].t-pts[i-1].t)%2!=abs(pts[i].x-pts[i-1].x)+abs(pts[i].y-pts[i-1].y)%2) ans=0;
			}
		}
		printf("%s\n",ans==1?"Yes":"No");
	}
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	multiset<int>s;
	multiset<int>::iterator it;
	for(int i=0; i<n; i++){
		if(s.empty()) s.insert(arr[i]);
		else{
			it = s.lower_bound(arr[i]);
			if(it==s.begin()) s.insert(arr[i]);
			else{
				it--;
				s.erase(it);
				s.insert(arr[i]);
			}
		}
	}
	cout<<s.size();
}

Measured memory_bytes: 8280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int f (int n) {
    int ret = 0;
    do ret++; while (n >>= 1);
    return ret;
}
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k = 0; cin >> n; k = f(n);
    vector<vector<int>> a(n, vector<int>(n));
    rep (i, n) {
        rep (j, i + 1, n) {
            rep (l, k) {
                if (!a[i][j] && ((i ^ j) & (1 << l))) a[i][j] = l + 1;
            }
            cout << a[i][j] << " \n"[j + 1 == j_len];
        }
    }
    return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

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

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

bool ABC(int n) {
	if (0 < n && n < 13) {
		return true;
	}
	else {
		return false;
	}
}

int main(void) {
	rapid_pleaseAC_fast;

	int a, b, c;
	cin >> a >> b >> c;
	cout << c <<" "<< a <<" "<< b << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1000000000+7)

int main() {
    int N, X;
    cin >> N >> X;
    int cnt = 1;
    int D = 0;
    REP(i, N) {
        int L;
        cin >> L;
        D += L;
        if (D <= X) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use std::collections::HashMap;

#[fastout]
fn main() {
  input! {
    n: usize,
    mut vals: [(isize, isize, isize);n]
  }
  
  vals = vals
          .into_iter()
          .filter(|(_,_,v)| v != &0)
          .collect::<Vec<(isize, isize, isize)>>();
  
  if vals.len() == 1 {
    println!("{} {} {}", vals[0].0, vals[0].1, vals[0].2);
    return
  }
  
  let mut succeed = true;
  for x in 0..=100 {
    let xx = x as isize;
    for y in 0..=100 {
      succeed = true;
      let yy = y as isize;
      let mut last = 0;
      let mut start = false;

      for i in 0..vals.len() {
        if start {
          let v = (xx - vals[i].0).abs() + (yy - vals[i].1).abs() + vals[i].2;
          if last != v {
            succeed = false;
            break
          }
        } else {
          last = (xx - vals[i].0).abs() + (yy - vals[i].1).abs() + vals[i].2;
          start = true;
        }
      }
      
      if succeed {
        println!("{} {} {}", x, y, last);
        return
      }
    }
  }
}

Measured memory_bytes: 2188
#include<stdio.h>

int main(){
  int H, W;
  scanf("%d %d", &H, &W);
  
  char S[H + 2][W + 2];
  int danger[H + 2][W + 2];
  for(int i = 0; i < H + 2; i++){
    for(int j = 0; j < W + 2; j++){
      danger[i][j] = 0;
      if(i == 0 || j == 0 || i == H + 1 || j == W + 1){
        S[i][j] == '.';
      }else{
        scanf(" %c", &S[i][j]);
      }
    }
  }
  
  for(int i = 1; i <= H; i++){
    for(int j = 1; j <= W; j++){
      if(S[i][j] == '#'){
        danger[i - 1][j - 1]++; danger[i - 1][j]++; danger[i - 1][j + 1]++;
                                /*     ||      */
                                /*     ||      */
        danger[i][j - 1]++;     /*=====@'======*/   danger[i][j + 1]++;
                                /*     ||      */
                                /*     ||      */
        danger[i + 1][j - 1]++; danger[i + 1][j]++; danger[i + 1][j + 1]++;
      }
    }
  }
  
  for(int i = 1; i <= H; i++){
    for(int j = 1; j <= W; j++){
      if(S[i][j] == '#') printf("#");
      else printf("%d", danger[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def bfs(src):
    from collections import deque

    que = deque()
    h, w = src
    que.append((dist[h][w], h, w))
    while que:
        cost, h, w = que.popleft()
        if h > 1:
            if dist[h-1][w] > cost:
                dist[h-1][w] = cost
                que.append((cost+seated[h-1][w], h-1, w))
        if h < N-1:
            if dist[h+1][w] > cost:
                dist[h+1][w] = cost
                que.append((cost+seated[h+1][w], h+1, w))
        if w > 1:
            if dist[h][w-1] > cost:
                dist[h][w-1] = cost
                que.append((cost+seated[h][w-1], h, w-1))
        if w < N-1:
            if dist[h][w+1] > cost:
                dist[h][w+1] = cost
                que.append((cost+seated[h][w+1], h, w+1))

N = INT()
P = [p-1 for p in LIST()]

dist = list2d(N, N, 0)
for i in range(N):
    for j in range(N):
        dist[i][j] = min(i, N-i-1, j, N-j-1)

ans = 0
seated = list2d(N, N, 1)
for p in P:
    h, w = divmod(p, N)
    ans += dist[h][w]
    bfs((h, w))
    seated[h][w] = 0
print(ans)


Measured memory_bytes: 173800
import numpy as np

a,b,x = map(int, input().split())

v = a*a*b

if v == x:
    print(0)
    exit(0)

t = None
if x >= v/2:
    pad = a*a*b - x
    h = (2*pad)/(a*a)
    t = np.arctan(h/a)
else:
    w = (2*x)/(a*b)
    t = np.arctan(b/w)
print(t*180/np.pi)



Measured memory_bytes: 13556
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count = 0;
        for (int i = 0; i < s.length() / 2; i++) {
            if (s.charAt(i) != s.charAt(s.length() - i - 1)) {
                count++;
            }
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 23252
import java.util.*;

public class Main {
		public static int N;
		public static long K;
		public static int A[];
		public static Integer F[];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextLong();// 修行回数
		A = new int[N];// 消化コスト
		F = new Integer[N];// 食べにくさ
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			F[i] = sc.nextInt();
		}
		// 消化コストが高い人と、食べにくさが低い食べ物をマッチングする。
		Arrays.sort(A);
		Arrays.sort(F, Collections.reverseOrder());
		for(int i=0;i<N;i++) {
			F[i]=F[i].intValue();
		}	//降順に並び替えるための手順
		
		//N個の組み合わせについて、それらの最大値がXを下回るようにする。
		//二分探索します。
		//調べたい範囲の一番左以下と、一番右以上の何かをleftとrightで定義する。
		long l = -1; long r = (long)Math.pow(10,12);
		while(l+1<r) {
			long c = l+(r-l)/2;//これがオーバーフローしないための書き方
			if(func(c)==true) r=c; else l=c;//if文を１行で書く	
		}
		System.out.println(r);
	}
	static boolean func(long c) {
		long sum=0;
		for(int i=0;i<N;i++) {
			sum += Math.max(A[i]-c/F[i],0);
		}
		return sum<=K;
	}
}

Measured memory_bytes: 107768
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  string s;
  cin >> s;
  if(s[1]==s[2] && s[0]==s[1]) cout << "Yes" << endl;
  else if(s[1]==s[2] && s[2]==s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;

  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

int main(){
    int N, M, cnt;
    cin >> N >> M;
    cnt = 0;
    if(N >= 2 || M >= 2){
        cnt += N*(N-1)/2;
        cnt += M*(M-1)/2;
    }

    cout << cnt << endl;
}

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

void printArray(int *array, int length) {
    for (int i = 0; i < length; i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, const char * argv[]) {
    // insert code here...
    int array[100];
    
    int count = 0;
    cin >> count;
    for (int i = 0; i < count; i++) {
        cin >> array[i];
    }
    
    printArray(array, count);
    for (int i = 1; i < count; i++) {
        int current = array[i];
        int j = i - 1;
        while (j >= 0 && array[j] > current) {
            array[j + 1] = array[j];
            j--;
        }
        array[j + 1] = current;
        printArray(array, count);
    }
    
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  string S;
  cin >> N >> S;

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int n;
    cin >> n;
    string s(n, '0');
    vector<Pii> vp;
    rep(i, n - 1) {
        s[i] = '1';
        if (i != 0) s[i - 1] = '0';
        rep2(j, i + 1, n) {
            s[j] = '1';
            cout << "? " << s << endl;
            s[j] = '0';
            int d;
            cin >> d;
            if (d != 0) vp.emplace_back(i, j);
        }
    }

    cout << "!";
    for (auto p : vp) {
        cout << " (" << p.first << "," << p.second << ")";
    }
    cout << endl;

}


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
const int IINF = 1 << 30;
const long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
// const int MOD = 998244353;

int main()
{
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    int score = 0;
    for (size_t i = 0; i < n; i++) {
        if (i >= k) {
            if (t[i] == t[i - k]) {
                t[i] = '#';
            }
        }
        if (t[i] == 'r')
            score += p;
        if (t[i] == 's')
            score += r;
        if (t[i] == 'p')
            score += s;
    }
    cout << score << "\n";
}

Measured memory_bytes: 512
flag = 1
keta,n = map(int,input().split())
sc = []
for i in range(n):
    sc.append(list(map(int,input().split())))

ans = [None]*keta

for j in sc:
    if j[0] == 1 and j[1] == 0 and keta != 1:
        flag = 0

    else:
        try:
            if ans[j[0]-1] == None:
                ans[j[0]-1] = j[1]
            elif ans[j[0]-1] != None and ans[j[0]-1] != j[1]:
                flag = 0
        except:
            flag = 0
        
        
for k in range(len(ans)):
    if k == 0 and ans[0] == None and keta != 1:
        ans[0] = 1
    elif ans[k] == None:
        ans[k] = 0
            
ans_s = ""
for l in ans:
    ans_s += str(l)
    
if flag == 0:
    print("-1")        
else:
    print(ans_s)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int parent;
  int left;
  int right;
} node;

int main(){
  node *ar,*t;
  int i,j,n,id,c,k,a,depth;

  scanf("%d",&n);
  ar=(node *)malloc(sizeof(node)*n);
  t=ar;
  for(i=0;i<n;i++){
    t[i].parent=-1;
    t[i].left=-1;
    t[i].right=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);    
    for(j=0;j<k;j++){
      scanf("%d",&c);
      t[c].parent=id;
      if(j==0)t[id].left=c;
      else t[a].right=c;
      a=c;
    }
  }
  for(i=0;i<n;i++){
    a=t[i].parent;
    depth=0;
    while(a!=-1){
      depth++;
      a=t[a].parent;
    }
    printf("node %d: parent = %d, depth = %d, ",i,t[i].parent,depth);
    if(t[i].parent==-1)printf("root, [");
    else if(t[i].left==-1)printf("leaf, [");
    else printf("internal node, [");
    a=t[i].left;
    if(a!=-1){
      printf("%d",t[i].left);
      while(t[a].right!=-1){
	printf(", %d",t[a].right);
	a=t[a].right;
      }
    }
    printf("]\n");
  }
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> s(n);
    {
        string buf;
        cin>>buf;
        for(int i=0;i<n;i++) s[i]=buf[i]-'0';
    }
    
    int iter10=-1;
    vector<int> dp(n+1);
    for(int i=1;i<n;i++){
        dp[i+1]=dp[i];
        if(s[i]==0){
            if(s[i-1]==1) iter10=i-1;
            else if(s[i-1]==0) iter10=-1;
        }
        else{
            if(s[i-1]==0){
                for(int j=i-2;j>=0;j--){
                    if(s[j]==0) break;
                    dp[i+1]=max(dp[i+1],i-1-j+dp[j]);
                }
            }
            else{
                if(iter10!=-1){
                    dp[i+1]=max(dp[i+1],i-iter10-1+dp[iter10]);
                }
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 4248
fun main(args : Array<String>) {
    val S = readLine()!!
    var index = 0
    var current = ""

    var answer = 0
    var before = ""
    while (index < S.length) {
        current += S[index]
        if (before == current) {
        } else {
            before = current
            current = ""
            answer++
        }
        index++
    }
    println(answer)
}

Measured memory_bytes: 41276
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n;
    cin>>n;
    string s;
    set<string> set;
    while(n--)
    {
    	cin>>s;
    	set.insert(s);
	}
	cout<<set.size()<<endl;
	
	return 0;
}

Measured memory_bytes: 19244
#include<stdio.h>

int n,k;
int T[100000];

int check(int p,int T[])
{
	int i=0,j;
	for(j=0;j<k;j++)
	{
		int s=0;
		while(s+T[i]<=p)
		{
			s+=T[i];
			i++;
			if(i==n)
			{
				return n;
			}
		}
	}
	return i;
}

int solve(int T[])
{
	int left=0,right=100000*10000,mid;
	
	while(right-left>1)
	{
		mid=(left+right)/2;
		int v=check(mid,T);
		if(v>=n)
		{
			right=mid;
		}
		else
		{
			left=mid;
		}
	}
	
	return right;
}

int main(void)
{
	int i;
	
	scanf("%d %d",&n,&k);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&T[i]);
	}
	
	int x=solve(T);
	
	printf("%d\n",x);
	
	return 0;
}


Measured memory_bytes: 2244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ld,P> P2;
P2 mk_P(ld a,ll b,ll c){
  return P2(a,P(b,c));
}
int main(){
  ll n;
  cin>>n;
  vector<P2> vec;
  for(int i=0;i<n;i++){
    ll x,y;
    ld angle;
    cin>>x>>y;
    if(y>0){
      angle=acos((ld)x/sqrt((ld)(x*x+y*y)));
    }
    else if(y==0){
      if(x>0) angle=0;
      else if(x<0) angle=M_PI;
      else continue;
    }
    else{
      angle=acos((ld)(-1*x)/sqrt((ld)(x*x+y*y)))+M_PI;
    }
    vec.push_back(mk_P(angle,x,y));
  }
  sort(vec.begin(),vec.end());
  int as=vec.size();
  for(int i=0;i<as;i++){
    P2 p=vec[i];
    p.first+=2*M_PI;
    vec.push_back(p);
  }
  ll ans=0;
  for(int i=0;i<as;i++){
    for(int j=i;j<i+as;j++){
      ll kx=0,ky=0;
      for(int k=i;k<=j;k++){
        kx+=vec[k].second.first;
        ky+=vec[k].second.second;
      }
      ll kans=kx*kx+ky*ky;
      ans=max(ans,kans);
    }
  }
  cout<<fixed;
  cout<<setprecision(20)<<sqrt((ld)ans)<<endl;
}


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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

template <typename T>
class Queue {
    struct node {
        node* next;
        node* prev;
        T value;
    };
    node* head_;
    node* tail_;
    int size_;

    public:
        Queue () : size_(0) {
            node* n = new node();
            n->next = nullptr;
            n->prev = nullptr;

            head_ = n;
            tail_ = n;
        };
        ~Queue () {
            node* next = tail_;
            REP(i, size_){
                node* tmp = next->next;
                free(next);
                next = tmp;
            }
        };

        void push(T v) {
            tail_->prev = new node();
            tail_->prev->next = tail_;
            tail_ = tail_->prev;
            tail_->value = v;
            ++size_;
        }

        T pop() {
            if (!head_->prev) {
                throw;
            }

            T v = head_->prev->value;
            head_ = head_->prev;
            free(head_->next);
            --size_;
            return v;
        }

        int get_size() {return size_;}
};


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

    int n, q;
    cin >> n >> q;

    Queue<pair<string, int>> Q;

    REP(i, n) {
        string name;
        int time;
        cin >> name >> time;
        Q.push(make_pair(name, time));
    }

    int time_sum = 0;

    while(Q.get_size() > 0) {
        auto exe = Q.pop();
        if(exe.second <= q) {
            time_sum += exe.second;
            cout << exe.first << " " << time_sum << endl;
        } else {
            time_sum += q;
            Q.push(make_pair(exe.first, exe.second - q));
        }
    }
}



Measured memory_bytes: 7860
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll n;



    vector<pair<ll,ll>>p;
void fs(ll a){
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        p.emplace_back(i,cnt);
    }
    return;
}


ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};
int main(){
   int n;
   cin>>n;
    long long int a[n],ans=0,i;
    int mod=1000000007;
    long long int sum=0;
 
    for( i = 0 ; i < n ; i++ ){
            cin>>a[i];
        sum = sum + a[i];
        sum%=mod;
    }
    for( i = 0 ; i < n ; i++ ){
        sum = sum - a[i];
        if(sum<0)sum+=mod;
 
        ans+=(a[i]%mod * sum%mod)%mod;
        ans%=mod;
    }
    cout<<ans%mod;
 
    return 0;
}
 




Measured memory_bytes: 5132
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define mCalc(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll mPow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) mCalc(res, *, x);
        mCalc(x, *, x);
        n>>=1;
    }
    return res;
}

ll dp[22][2100000];

int main(void) {
    ll N;
    cin >> N;
    ll i;
    ll s[MAX];
    ll fa[MAX];
    ll res=0;
    fa[0]=1;
    for(i=1; i<=N; i++) {
        fa[i]=i*fa[i-1]%MOD;
        s[i]=(s[i-1]+mPow(i, MOD-2))%MOD; //mPow(i, MOD-2):1/iの逆元、s[i]:1/1,1/2,...1/iの和
    }
    
    for(i=0; i<N; i++) {
        ll a;
        cin >> a;
        mCalc(res, +, (s[i+1]+s[N-i]-1)%MOD*a%MOD);
    }
    
    pt(res*fa[N]%MOD);
    
}










Measured memory_bytes: 1792