akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
d = []
for i in range(n - 1):
  d.append(abs(a[i + 1] - a[i]))
s = sum(d)
print(s - d[0] + abs(a[1]) + abs(a[-1]))
for i in range(n - 2):
  print(s - d[i] - d[i + 1] + abs(a[i + 2] - a[i]) + abs(a[0]) + abs(a[-1]))
print(s - d[-1] + abs(a[0]) + abs(a[-2]))

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

using namespace std;

int main()
{
    string s;
    int n, q;
    cin >> n >> q;
    cin >> s;
    int cnt[100010] = {};
    int ans[100010] = {};

    for (int i = 1; i < n; i++) {
        if (s[i] == 'C' && s[i-1] == 'A') {
            cnt[i]++;
        }
    }

    for (int i = 1; i < n; i++) {
        cnt[i] += cnt[i-1];
    }

    for (int i = 0; i < q; i++) {
        int r, l;
        cin >> r >> l;
        ans[i] = cnt[l-1]-cnt[r-1];
    }
    for (int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
lli r[100005] = {};
lli x, k;
struct f {
  lli t, a, b, c, up;
  f(lli a, lli b, lli c, lli up) : t(t), a(a), b(b), c(c), up(up) {}
  f(){};
  lli call(lli x) {
    if (x < a)
      return a + c;
    if (x < b)
      return c + x;
    return b + c;
  }
};
f func[100005] = {};
f calc(f f0, lli t) {
  int a = f0.a;
  int b = f0.b;
  int c = f0.c;
  if (f0.up) {
    if (a + c >= t) {
      f0.c = c - t;
    } else if (a + c < t && t < b + c) {
      f0.a = t - c;
      f0.c = c - t;
    } else {
      f0.a = 0;
      f0.b = 0;
      f0.c = 0;
    }
  } else {
    if (b + c + t <= x) {
      f0.c = c + t;
    } else if (a + c + t < x && x < b + c + t) {
      f0.a = a;
      f0.c = c + t;
      f0.b = x - (c + t);
    } else {
      f0.a = 0;
      f0.b = 0;
      f0.c = x;
    }
  }
  return f0;
}
int main() {
  cin >> x;
  cin >> k;
  rep(i, k) cin >> r[i + 1];
  k++;
  int q;
  cin >> q;
  lli t, a;
  func[0] = f(0, x, 0, true);
  rep(i, k - 1) {
    func[i + 1] = calc(func[i], r[i + 1] - r[i]);
    func[i + 1].up = !func[i].up;
  }

  rep(i, q) {
    cin >> t >> a;
    lli up = k, low = 0;
    while (up - low > 1) {
      lli mid = (up + low) >> 1;
      if (r[mid] > t) {
        up = mid;
      } else {
        low = mid;
      }
    }
    cout << calc(func[low], t - r[low]).call(a) << endl;
  }
}


Measured memory_bytes: 5888
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };



int main() {
	int a, b,k;
	cin >>k>> a >> b;
	int s = ((a + k - 1) / k) * k;
	if (s <= b)cout << "OK" << endl;
	else cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-

# input
N = int(input())
B = list(map(int, input().split()))

# solve
A = list()
for i in range(N):
    if i == 0:
        A.append(B[0])
    elif i == N - 1:
        A.append(B[-1])
    else:
        if B[i - 1] <= B[i]:
            A.append(B[i - 1])
        else:
            A.append(B[i])

# output
print(sum(A))


Measured memory_bytes: 3060
N = int(input())
H = list(map(int, input().split()))
Ans = 0
c = 0
h = H[0]
for i in H[1:]:
    if h - i >= 0:
        c += 1
    else:
        if c > Ans :
            Ans = c
        c = 0
    h = i
if c > Ans :
    Ans = c
print(Ans)

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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define F first;
#define S second;
#define MP make_pair;
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9 + 7;

int parent[N];

int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    ll n;
    cin >> n;
    ll x = n;
    int res = 0;
    for(ll i=2LL;i<=sqrt(n);i++) {
        int cnt = 0;
        while(x % i == 0) {
            x /= i;
            cnt++;
        }
        for(int j=1;j<=cnt;j++) {
            res++;
            cnt -= j;
        }
    }
    if(x != 1 && n != 1) res++;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int n,k;
long long T[100000];

int check(long long p)
{
    int i=0;

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

int solve()
{
   long long left=0;
   long long right=100000*10000;
   long long mid;
   while(right-left>1)
   {
       mid=(left+right)/2;
       int x=check(mid);
       if(x >=n) right=mid;
       else left=mid;
   }
   return right;
}



int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>T[i];
    }
    int tmp=solve();
    cout<<tmp<<endl;
    return 0;



}

Measured memory_bytes: 3848
// atcoder/abc144/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  double a, b, x;
  while (cin >> a >> b >> x) {
    if (x < (a * a * b) / 2.0) {
      double c = 2.0 * x / (a * b);
      // double r = asin(c / b) * 180 / M_PI;
      // printf("%.10lf\n", 90.0 - r);

      // double r = atan(b / c);
      // printf("%.10lf\n", r * 180.0 / M_PI);

      // printf("%.10lf\n", 90.0 - asin(c / b) * 180 / M_PI);
      printf("%.10lf\n", atan(b / c) * 180.0 / M_PI);
    } else {
      double c = 2.0 * (a * a * b - x) / (a * a);
      double r = atan(c / a);
      printf("%.10lf\n", r * 180.0 / M_PI);
    }
  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=0
for i in range(n):
    m=min(a[i], b[i])
    a[i]-=m
    b[i]-=m
    ans+=m
    m=min(a[i+1], b[i])
    if b[i] > 0:
        a[i+1]-=m
        ans+=m


print(ans)

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

int main() {
long n;
cin>>n;
long a[n];
int ans=0;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++){
  while(a[i]%2==0){
    if(a[i]%2==0){
      ans++;
      a[i]/=2;
    }
  }
}
cout<<ans<<endl;

}


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

int main() {
  int N;
  cin >> N;
  
  int total_member =0 ;
  
  for(int i=0; i<N ;i++){
    int l,r;
    cin >> l >> r;
    
    int member = r-l+1;
    
    total_member += member;
  }
  cout << total_member << endl;
  
}







Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
colors = [0]*9
for i in a:
    idx = i//400
    if(idx > 8):
        idx = 8
    colors[idx] += 1
ans = 0
for i in colors[0:8]:
    if i != 0:
        ans += 1
if ans == 0:
    print(1, colors[8])
else:
    print(ans, ans+colors[8])

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

typedef long long ll;
typedef struct pair<int,int> P;
int p[1001]={};
int x[1001]={};
int y[1001]={};

int dp[9][(1<<8)]={};
vector<int> v;
int n,m,s;
int d[201][201];
int r[201]={};


//int calc(int s1,int d1){
//	if(dp[s1][d1]>0)return dp[s1][d1];
//	if(d1==(1<<s1))return 0;
//	int d2=d1-(1<<s1);
//	dp[s1][d1]=200000001;
//	for(int i=0;i<s;++i){
//		int k=(1<<i);
//		if((d2&k)==k)dp[s1][d1]=min(dp[s1][d1],d[r[s1]][r[i]]+calc(i,d2));
//	}
//	return dp[s1][d1];
//}
int main() {
	int n;
	cin>>n;
	int p1;
	int t=0;
	int k=0;
	for(int i=1;i<n+1;++i){
		cin>>p1;
		if(p1==i){
			if(k==0){
				k++;
				t++;
			}else{
				k=0;
			}
		}else{
			k=0;
		}
	}
	cout<<t<<endl;
//	int a[100002]={};
//	int n;
//	cin>>n;
//	int a1;
//	for(int i=0;i<n;i++){
//		cin>>a1;
//		a[a1]++;
//		if(a1>0)a[a1-1]++;
//		a[a1+1]++;
//	}
//	int t=0;
//	int k=0;
//	for(int i=0;i<100002;i++){
//		if(t<a[i]){
//			t=a[i];
//			k=i;
//		}
//	}
//	cout<<t<<endl;
//
//	for(int i=0;i<201;++i){
//		for(int j=0;j<201;++j){
//			d[i][j]=200000001;
//		}
//	}
//	cin>>n>>m>>s;
//	bool flg=true;
//	int a,b,c;
//	int ct=0;;
//	for(int i=0;i<s;++i){
//		cin>>r[i];
//		ct+=(1<<i);
//	}
//	for(int i=0;i<m;++i){
//		cin>>a>>b>>c;
//		d[a][b]=c;
//		d[b][a]=c;
//	}
//	while(flg){
//		flg=false;
//		for(int i=1;i<n+1;++i){
//			for(int j=1;j<n+1;++j){
//				for(int k=1;k<n+1;++k){
//					if(d[i][j]>(d[i][k]+d[k][j])){
//						flg=true;
//						d[i][j]=d[i][k]+d[k][j];
//					}
//				}
//			}
//		}
//	}
//
//	int t=200000001;
//
//	for(int i=0;i<s;++i){
//		t=min(t,calc(i,ct));
//	}

//	cout<<max(x-t,0)<<endl;

	return 0;
}


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

int main(){
  long long N;
  cin>>N;
  
  long long ans=1;
  for(long long i=1;i<=N;i++){
    ans=ans*i%P;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 384
package main

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

func main() {
	var n int
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	set := make(map[string]bool)
	for i := 0; i < n; i++ {
		sc.Scan()
		set[sc.Text()] = true
	}

	fmt.Println(len(set))
}


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

const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};

int main() {
    ll h, w;
    cin >> h >> w;

    vector<string> board(h);
    rep(i, h) {
        cin >> board[i];
    }

    ll ans = 0;
    rep(sx, h) {
        rep(sy, w) {
            if(board[sx][sy] == '#') {
                continue;
            }
            vvl matrix(h, vl(w, -1));  // 数字を書き込むマス。-1で初期化
            queue<pair<ll, ll>> next;  // 次に探索するマスを入れるqueue
            next.push(make_pair(sx, sy));
            matrix[sx][sy] = 0;
            while(!next.empty()) {  // nextが空になるまで探索
                ll x = next.front().first;
                ll y = next.front().second;
                // 4方向調べる
                rep(i, 4) {
                    ll nx = x + dx[i];
                    ll ny = y + dy[i];
                    // 盤外または探索済みのところはダメ
                    if(nx < 0 || h <= nx || ny < 0 || w <= ny || 0 <= matrix[nx][ny]) {   
                        continue;
                    }
                    if(board[nx][ny] == '#') {
                        continue;
                    }
                    matrix[nx][ny] = matrix[x][y] + 1;  // 隣接マスに1足す
                    next.push(make_pair(nx, ny));  // 隣接マスをnextに入れる
                }
                next.pop();  // nextからいま探索したマスを削除
            }

            ll now = 0;
            rep(i, h) {
                rep(j, w) {
                    chmax(now, matrix[i][j]);
                }
            }

            chmax(ans, now);
        }
    }

    out(ans);
    re0;
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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 */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long

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

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    sort(rall(v));
    int sum = 0;
    rep(i, k)
    {
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MN 500
#define MX 5000
int u[MX+5],p[MX+5],pn;
ll a[MN+5][MN+5];
map<ll,int> mp;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
int main()
{
	int n,i,j,k,x,y;
	for(i=2;i<=MX;++i)
	{
		if(!u[i])p[++pn]=i;
		for(j=1;i*p[j]<=MX;++j)if(u[i*p[j]]=1,i%p[j]==0)break;
	}
	for(i=2;i<=MN+MN;i+=2)for(j=-MN;j<=MN;j+=2)
	{
		x=(i+j)/2;y=(i-j)/2;
		if(x<1||x>MN||y<1||y>MN)continue;
		for(k=1;mp[2*p[i/2]*p[(j+MN)/2]*k]++;++k);
		a[x][y]=2*p[i/2]*p[(j+MN)/2]*k;
	}
	for(i=1;i<=MN;++i)for(j=1;j<=MN;++j)if(!a[i][j])
	{
		ll x=1;
		if(i>1)x=x/gcd(x,a[i-1][j])*a[i-1][j];
		if(i<MN)x=x/gcd(x,a[i+1][j])*a[i+1][j];
		if(j>1)x=x/gcd(x,a[i][j-1])*a[i][j-1];
		if(j<MN)x=x/gcd(x,a[i][j+1])*a[i][j+1];
		for(k=1;mp[x*k+1]++;++k);
		a[i][j]=x*k+1;
	}
	scanf("%d",&n);
	for(i=1;i<=n;++i,puts(""))for(j=1;j<=n;++j)printf("%lld ",a[i][j]);
}

Measured memory_bytes: 20608
#include<bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);

vector<int>d(10,1);

bool isvalid(int ans)
{
    while(ans>0)
    {
        if(d[ans%10]==0) return false;

        ans/=10;
    }

    return true;
}

int main()
{
    speed;

    int n,k,x;
    cin>>n>>k;

    for(int i=0;i<k;i++) 
    {
        cin>>x;
        d[x]=0;
    }

    int ans=n;

    while(ans<=10*n && !isvalid(ans)) ans++;

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

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }



//---------- 1000000007 ----------
const int MOD = 1000000007;
int m_add(int a, int b)
{
	return (a + b) % MOD;
}
int m_sub(int a, int b)
{
	return (a + MOD - b) % MOD;
}
int m_mul(int a, int b)
{
	return (a * b) % MOD;
}
int m_pow(int x, int n)
{
	if (n == 0) return 1;
	ll res = m_pow((x * x) % MOD, n / 2);
	if (n & 1) res = (res * x) % MOD;
	return res;
}
int m_divide(int a, int b)
{
	return m_mul(a, m_pow(b, MOD - 2));
}

int m_comb(int n, int r)
{
	int i;
	int p = 1;
	for (i = 1; i <= r; i++)
	{
		p = m_mul(p, (n - i + 1));
		p = m_divide(p, i);
	}
	return p;
}

int m_comb_with_rep(int n, int r)
{
	return m_comb(n + r - 1, r);
}



int N, K;

signed main()
{
	cin >> N >> K;

	int ans = 0;

	int mi = 0;
	int ma = 0;

	for (int i = 0; i < K; i++)
	{
		mi = m_add(mi, i);
	}
	for (int i = 0; i < K; i++)
	{
		ma = m_add(ma, N - i);
	}
	ans = m_add(ans, m_sub(ma + 1, mi));

	for (int k = K; k <= N; k++)
	{
		mi = m_add(mi, k);
		ma = m_add(ma, N - k);
		ans = m_add(ans, m_sub(ma + 1, mi));
	}

	cout << ans << endl;
}




Measured memory_bytes: 3640
N,*A=map(int, open(0).read().split())
A=sorted(A)
i1=0
i2=N-1
cnt=1
l=1
r=N-2
ans=A[i2]-A[i1]
while cnt<N-1:
    cnt+=1
    j1=max((abs(A[i1]-A[l]),l),(abs(A[i1]-A[r]),r))
    j2=max((abs(A[i2]-A[l]),l),(abs(A[i2]-A[r]),r))
    (j,lr),d=max((j1,1),(j2,2))
    ans+=j
    if d==1:
        i1=lr
    else:
        i2=lr
    if lr==l:
        l+=1
    else:
        r-=1
print(ans)

Measured memory_bytes: 14452
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int A, B;
  cin >> A >> B;
  int result = (A + B) % 24;
  cout << result << endl;
}


Measured memory_bytes: 256
/*input
10 4
3 1
4 1
5 9
2 6
*/

#include <bits/stdc++.h>
using namespace std; 
#define int long long int
// #define max(x, y) ((x) > (y) ? (x) :(y))
#define pii pair< int , int> 
#define vi vector<int>
#define fore( i ,st) for ( int i= 0 ; i < (int)(st) ; i ++)
#define REP( i , st , en ) for ( int i =st; i < (int)en; i++)
#define REPD( i , en , st ) for ( int i =en; i >= (int)st; i--)
#define SZ(a) (int)a.size()
#define all(v) v.begin() , v.end()
#define pb push_back
#define F first
#define S second
#define bug(x) cout <<__LINE__ << ":"<<__FILE__ << " : " <<   #x  << " = " << x << "\n";
#define bitch_i_m_on_fiyaah_yeahhhh ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod = 1e9+7;
ostream& operator << ( ostream&  o, vector<int> s){for ( int i = 0;  i < (int)s.size() ; i++)o << s[i] << " ";o << "\n";return o;}
int  add( int a, int b){int c = a + b; if ( a> mod ) a-= mod; return c;}
void sub( int &a, int b){a = a - b;if ( a < 0) a += mod;}
int mul( int a , int b){return ((a %mod) * (b %mod) ) %mod;}
int exp( int a , int pow){ return (pow == 0 ? 1 : ( pow & 1  ? mul ( a ,exp( mul(a, a) , pow /2) ) : exp(mul(a ,a) , pow/2)));}
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
// void in( vector<int> &v){for (int i=0;i<(int)v.size();i++)cin>>v[i];}
// void in(int &n) {cin >> n; }

const int maxn = 2e5 +5;


vector<int> graph[maxn];

int cnt;
int vis[maxn];

void dfs( int n , int par=-1){

	for ( int c : graph[n]){
		if (c  == par) continue;
		if ( vis[c] ) continue;
		vis[c] =1;
		cnt++;
		dfs( c , n);
	}
}

void solve( int test){
	
	
	int n , m ; 
	cin >> n >> m ;
	fore( i , m){
		int u ,v;
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	int mx=0;
	for ( int i =1;  i <= n ; i++ ){
		if ( !vis[i]){
			cnt=1;
			vis[i] =1;
			dfs( i );
			mx = max( mx , cnt);
		}
	}

	cout << mx;





}
signed main(){
	bitch_i_m_on_fiyaah_yeahhhh
	int t =1; 
	// cin >> t;
	for ( int i = 0 ; i < t; i++)
		solve(i+1);
}

Measured memory_bytes: 25480
import java.util.*;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int t = sc.nextInt();

        int i = a;
        int j = 0;

        while(i <= t + 0.5){
            i += a;
            j += b;
        }
        System.out.println(j);

    }
}


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

#define rep(i, n) for(int i = 0; i < (int64_t)(n); i++)

int N;
string S;

void solve() {
    cin >> N >> S;
    int64_t count = 0;
    vector<int64_t> R(N + 1), G(N + 1), B(N + 1);
    R.at(0) = 0;
    G.at(0) = 0;
    B.at(0) = 0;

    rep(i, N) {
        if (S.at(i) == 'R') {
            R.at(i + 1) = R.at(i) + 1;
            G.at(i + 1) = G.at(i);
            B.at(i + 1) = B.at(i);
        }
        else if (S.at(i) == 'G') {
            R.at(i + 1) = R.at(i);
            G.at(i + 1) = G.at(i) + 1;
            B.at(i + 1) = B.at(i);
        }
        else {
            R.at(i + 1) = R.at(i);
            G.at(i + 1) = G.at(i);
            B.at(i + 1) = B.at(i) + 1;
        }
    }

    rep(i, N) {
        for (int j = i + 1; j < N; j++) {
            if (S.at(i) != S.at(j)) {
                if ((S.at(i) == 'R' && S.at(j) == 'G') || (S.at(i) == 'G' && S.at(j) == 'R')) {
                    count += (B.at(N) - B.at(j));
                }
                else if ((S.at(i) == 'R' && S.at(j) == 'B') || (S.at(i) == 'B' && S.at(j) == 'R')) {
                    count += (G.at(N) - G.at(j));
                }
                else {
                    count += (R.at(N) - R.at(j));
                }
                if (2 * j - i < N) {
                    if (S.at(2 * j - i) != S.at(i) && S.at(2 * j - i) != S.at(j)) {
                        count--;
                    }
                }
            }
        }
    }

    cout << count << endl;
    return;
}

int main() {
    solve();
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>adj[m+5];
    for(int i=0;i<m;i++)
    {
        int k;
        cin>>k;
        for(int j=0;j<k;j++)
        {
            int a;
            cin>>a;
            adj[i].push_back(a);
        }
    }
    int frr[m+5];
    for(int i=0;i<m;i++)cin>>frr[i];

    int flag=0;

    for(int i=1;i<=pow(2,n);i++)
    {
        map<int,int>mp;
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                mp[j+1]++;
            }
        }
        int kp=0;
           for(int j=0;j<m;j++)
           {
               int fl=0;
               for(int k=0;k<adj[j].size();k++)
               {
                   if(mp[adj[j][k]]>0)fl++;
               }
               if(fl%2==frr[j])
               {
                   kp++;
               }
             //  cout<<fl<<endl;
           }
           if(kp==m)flag++;
    }
cout<<flag<<endl;
}


Measured memory_bytes: 256
#include <iostream>
  
using namespace std;
  
int main()
{
    double tmp;
      
    while(cin >> tmp){
        if(tmp <= 48.0){
            cout << "light fly" << endl;
        } else if(tmp <= 51.0){
            cout << "fly" << endl;
        } else if(tmp <= 54.0){
            cout << "bantam" << endl;
        } else if(tmp <= 57.0){
            cout << "feather" << endl;
        } else if(tmp <= 60.0){
            cout << "light" << endl;
        } else if(tmp  <= 64.0){
            cout << "light welter" << endl;
        } else if(tmp <= 69.0){
            cout << "welter" << endl;
        } else if(tmp <= 75.0){
            cout << "light middle" << endl;
        } else if(tmp <= 81.0){
            cout << "middle" << endl;
        } else if(tmp <= 91.0){
            cout << "light heavy" << endl;
        } else {
            cout << "heavy" << endl;
        }
    }
      
    return 0;
}

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

a = []
for i in range(n):
    aa = int(input())
    a.append(aa)

t = a
a = sorted(a)
memo = a[n-1]

if a[n-2] == a[n-1]:
    for i in range(n):
        print(a[n-1])

else:
    for i in range(n):
        if t[i] == memo:
            print(a[n-2])
        else:
            print(a[n-1])



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

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll a, b, c;
    ll ans = 0;
    cin >> a >> b >> c;

    if (c <= a + b + 1) {
        ans += c + b;
    }
    else {
        ans += b + (b + a + 1);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n,k;
    set<int> st;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int i=0;i<d;i++){
            int x;
            cin>>x;
            st.insert(x);
        }
    }
    int x=n-st.size();
    cout<<abs(x)<<"\n";
    return 0;
}


Measured memory_bytes: 3604
N = gets.chomp.to_i
W = gets.chomp.split.map(&:to_i)

# p N
# p W 

min = 10000 # INF
0.upto(N-2).each do |i|  # N-1 is not need to be checked
  small = 0
  0.upto(i).each do |j|
    small += W[j]
  end
  large = 0
  (i+1).upto(N-1).each do |j|
    large += W[j]
  end

  diff = (small - large).abs
  if (min > diff)
    min = diff
  end
end

p min

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<stdio.h>
#include<string>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
#define INF 1e5

int main(){
	char s[4];
	cin>>s;
	sort(s,s+4);
	if((s[0]==s[1])&(s[2]==s[3])&(s[2]!=s[1])) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

int main() {
    ll N; cin >> N;
    ll ans = LLONG_MAX;
    for(ll i = 1; i <= sqrt(N); ++i) {
        if(N % i == 0) {
            ans = min(ans, i + N / i - 2);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
using namespace std;
int H,W,K,ans,black;

int main(){
    cin>>H>>W>>K;
    char c[H][W];
    for(int i=0;i<H*W;i++){cin>>c[i/W][i%W];black+=c[i/W][i%W]=='#';}
    //for(int i=0;i<H*W;i++)cout<<c[i/W][i%W]<<" \n"[i==W-1];

    for(int h_bit=0;h_bit<1<<H;h_bit++){
        bitset<32>hb(h_bit);
        //cout<<"h:"<<hb<<endl;
        for(int w_bit=0;w_bit<1<<W;w_bit++){
            bitset<32>wb(w_bit);
            //cout<<"w:"<<wb<<endl;
            if(wb.count()==W)continue;

            int cnt=0;

            for(int keta=0;keta<H;keta++){
                //cout<<(hb[keta])<<endl;
                if(hb[keta]){
                    for(int x=0;x<W;x++){
                        if(c[keta][x]=='#')cnt++;
                    }
                }
            }
            for(int keta=0;keta<W;keta++){
                //cout<<(wb[keta])<<endl;
                if(wb[keta]){
                    for(int x=0;x<H;x++){
                        if(!hb[x]&&c[x][keta]=='#')cnt++;
                    }
                }
            }
            // cout<<"cnt:"<<cnt<<endl;
            // if((black-cnt)==K)cout<<"ok"<<endl;
            ans+=((black-cnt)==K);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
// -*- coding:utf-8-unix -*-

#[macro_use]
extern crate lazy_static;
extern crate num_bigint; // 0.2.2
extern crate num_traits; // 0.2.8
use num_bigint::BigInt;
use num_traits::Pow;

// use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
use libm::*;
use std::cmp::*;
use std::collections::{BinaryHeap, HashMap, HashSet};
use std::io::*;
use std::ops::Range;
use std::str::FromStr;
use superslice::*;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//abc175-D
// #[fastout]
fn main() {
    input![h: i64, n: usize, ab: [(i64, i64); n]];

    let a: Vec<_> = ab.iter().map(|(a, _)| a).collect();
    let b: Vec<_> = ab.iter().map(|(_, b)| b).collect();

    let mut dp = vec![std::usize::MAX; h as usize + 1];

    for hh in 0..(h + 1) as usize {
        if hh == 0 {
            dp[hh] = 0;
        }

        for m_idx in 0..n as usize {
            dp[hh] = min(
                dp[hh],
                dp[max(hh as i64 - a[m_idx], 0) as usize] + *b[m_idx] as usize,
            );
        }
    }

    println!("{}", dp[h as usize]);
}

// use lazy_static::lazy_static;
// use std::sync::Mutex;

// lazy_static! {
//     static ref VALUES: Mutex<Vec<i32>> = Mutex::default();
// }

// let mut values = VALUES.lock().unwrap();
// values.extend_from_slice(&[1, 2, 3, 4]);
// assert_eq!(&*values, &[1, 2, 3, 4]);

// -100000000
//  1000000000


Measured memory_bytes: 2264
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int A,B;
  cin >> A >> B;
  bool ans = false;
  for(int i=0;i<1200;i++)
  {
    int e = i*0.08;
    int t = i*0.1;
    if(e==A)
    {
      if(t==B)
      {
        ans = true;
        cout << i << endl;
        break;
      }
    }
  }
  if(ans == false)
  {
    cout << -1 << endl;
  }
  return 0;
}


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

//#pragma GCC optimize("O3")

using namespace std;

struct point_t { int x; int y; };

const int maxH = 3e2, maxW = maxH;
const int maxA = 9e4;
const int maxQ = 10e5;
int H, W, D;
int Q;
point_t A[maxH * maxW + 1];
int L, R;
int precalc[maxH * maxW + 1];

inline int magic(int i, int j, int x, int y)
{
    return abs(x - i) + abs(y - j);
}

int main()
{
    int val;
    scanf("%d %d %d", &H, &W, &D);
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            scanf("%d", &val);
            A[val] = {i, j};
        }
    }

    for (int i = D, iend = H * W; i <= iend; ++i) {
        precalc[i] = precalc[i - D] + magic(A[i-D].x, A[i-D].y, A[i].x, A[i].y);
    }

    scanf("%d", &Q);
    for (int i = 1; i <= Q; ++i) {
        scanf("%d %d", &L, &R);
        cout << precalc[R] - precalc[L] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      string N;
      cin >> N;
      if ((N[0] == N[1]&& N[1] == N[2])||
          (N[1] == N[2] && N[2] == N[3])) 
          {cout << "Yes" << endl;}
      else  {cout << "No" << endl;}    
      
    }

Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  char s[n+1];
  scanf("%s", s);
  int ans = 0;
  for (int i=0; i<n-2; i++) {
    if (s[i] == 'A') {
      if (s[i+1] == 'B') {
        if (s[i+2] == 'C') {
          ans++;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int dp[1<<15][15];
bool done[1<<15][15];
int tb[1<<15];
int cs[15][15];
int main() {
	int N,M;
	cin >> N >> M;
	for(int i=0;i<M;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		cs[a][b]=cs[b][a]=c;
	}
	for(int u=0;u<(1<<N);u++)
	{
		for(int i=0;i<N;i++){
			dp[u][i]=-(1<<29);
			if(!(u&(1<<i)))continue;
			for(int j=i+1;j<N;j++){
				if(!(u&(1<<j)))continue;
				tb[u]+=cs[i][j];
			}
		}
		//cerr << u << ": " << tb[u] << endl;
	}
	dp[1][0]=0;
	for(int u=1;u<(1<<N);u+=2)
	{
		for(int i=1;i<N;i++){
			if(!(u&(1<<i)))continue;
			for(int j=0;j<N;j++){
				if(!(u^(1<<j))||!cs[i][j])continue;
				dp[u][i]=max(dp[u][i],dp[u^(1<<i)][j]+cs[j][i]);
			}
		}
		for(int v=u;v>0;v=(v-1)&u){
			for(int i=0;i<N;i++){
				if(!(v&(1<<i)))continue;
				dp[u][i]=max(dp[u][i],dp[u^v^(1<<i)][i]+tb[v]);
			}
		}
#if 0
		for(int i=0;i<N;i++){
			cerr << u << ", "  << i << ": " << dp[u][i]/100<< endl;
		}
#endif
	}
	//cerr << dp[(1<<N)-1][N-1]<<endl;
	cout << tb[(1<<N)-1]-dp[(1<<N)-1][N-1] << endl;



	return 0;
}



Measured memory_bytes: 2304
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const int MOD=(1e9)+7;
const int mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin >>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >>a[i];
  int low=0,high=MOD;
  while(high-low>1){
    int mid=(high+low)/2;
    int sum=0;
    for(int i=0;i<n;i++){
      sum+=(a[i]-1)/mid;
    }
    if(sum<=k) high=mid;
    else low=mid;
  }
  cout <<high<<'\n';
  return (0);
}

Measured memory_bytes: 3952
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
typedef long long ll;

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

int main() {
  double w, h, x, y = 0;
  cin >> w >> h >> x >> y;

  printf("%lf %d\n", w*h/2, 2*x == w && 2*y == h);
}


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

using namespace std;

typedef pair<int, int> pii;

int main()
{
    int N, q, a, v;
    cin >> N >> q;
    vector<int> p(N+1, 0);
    priority_queue<pii> Q;
    while (q--) {
        cin >> a >> v;
        p[a] += v;
        Q.push(pii(p[a], -a));
        while (1) {
            pii mp = Q.top();
            if (p[-mp.second] == mp.first) {
                cout << -mp.second << " " << mp.first << endl;
                break;                
            }
            Q.pop();
        }
    }
    return 0;
}

Measured memory_bytes: 7696
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

#define MOD 998244353

using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

typedef long long LL;
typedef vector<int> VI;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> rv;
  vector<int> gv;
  vector<int> bv;
  for (int i = 0; i < 3*N; i++) {
    if (S[i] == 'R') {
      rv.push_back(i);
    } else if (S[i] == 'G') {
      gv.push_back(i);
    } else {
      bv.push_back(i);
    }
  }
  vector<int> flags(3*N);
  for (int i = 0; i < N; i++) {
    vector<int> v = {rv[i], gv[i], bv[i]};
    sort(v.begin(), v.end());
    flags[v[0]] = 1;  // minimum
    flags[v[2]] = 2;  // maximum
  }
  int64_t ans = 1;
  for (int i = 1; i <= N; i++) {
    ans = (ans * i) % MOD;
  }
  int balance = 0;
  for (int i = 0; i < 3*N; i++) {
    if (!flags[i]) {
      ans = (ans * balance) % MOD;
      balance--;
    }
    if (flags[i] == 1) {
      balance++;
    }
  }
  balance = 0;
  for (int i = 3*N-1; i >= 0; i--) {
    if (!flags[i]) {
      ans = (ans * balance) % MOD;
      balance--;
    }
    if (flags[i] == 2) {
      balance++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3324
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
pair<char,int> fn(string s,int p){
  int i,j,k,l;
  int ln=s.length();
  for(i=0;i<ln;){
    if('A'<=s[i]&&s[i]<='Z'){
      if(p){
	p--;
	i++;
      }else{
	return make_pair(s[i],0);
      }
    }else{
      for(j=i;'0'<=s[j]&&s[j]<='9';j++);
      if(s[j]=='('){
	l=1;
	for(k=j+1;l;k++){
	  if(0){
	  }else if(s[k]=='('){
	    l++;
	  }else if(s[k]==')'){
	    l--;
	  }
	}
	string t=s.substr(j+1,k-j-2);
	l=atoi(s.substr(i,j-i).c_str());
	i=k;
	for(k=0;k<l;k++){
	  pair<char,int> r=fn(t,p);
	  if(r.first!='\0')
	    return make_pair(r.first,0);
	  p=r.second;
	}
      }else{
	if(p<atoi(s.substr(i,j-i).c_str())){
	  return make_pair(s[j],0);
	}else{
	  p-=atoi(s.substr(i,j-i).c_str());
	  i=j+1;
	}
      }
    }
  }
  return make_pair('\0',p);
}
int main(){
  int p;
  string s;
  while(cin>>s>>p&&(s!="0"||p!=0)){
    pair<char,int> r=fn(s,p);
    cout<<(r.first=='\0'?'0':r.first)<<endl;
  }
  return 0;
}

Measured memory_bytes: 932
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	As := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&As[i])
	}

	sort.Ints(As)

	var count int
	rest := len(As) - K
	count++

	if rest%(K-1) == 0 {
		count += rest / (K - 1)
	} else {
		count += rest / (K - 1)
		count++
	}

	fmt.Println(count)
}


Measured memory_bytes: 5504
#include <iostream>

#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

int N, K;
vector<vector<int>> V;
int MOD = 1e9 + 7;

int main() {
	cin >> N >> K;
	V.resize(N);
	for (int n = 0; n < N - 1; n++) {
		int a, b;
		cin >> a >> b;
		V[--a].push_back(--b);
		V[b].push_back(a);
	}
	vector<vector<int>> VV(N,vector<int>());
	queue<pair<int,int>> q;
	q.push(pair<int,int>(0,-1));
	vector<int> parent;
	parent.resize(N);
	long long ans = 1;
	while (!q.empty()) {
		int cur = q.front().first;
		int par = q.front().second;
		q.pop();
		parent[cur] = par;
		for (int c : V[cur]) {
			if (c != par)q.push(pair<int, int>(c, cur));
		}
	}
	q.push(pair<int, int>(0, 0));
	vector<int> check(N, 0);
	while (!q.empty()) {
		int cur = q.front().first;
		q.pop();
		int counter = 0;
		if (parent[cur] != -1) {
			//親は存在する
			if (parent[parent[cur]] != -1)counter += 2;//祖父まで含めた数
			else counter += 1;
			//うちチェック済みを除く
			counter += check[parent[cur]];
			check[parent[cur]]++;
		}
		ans *= (K-counter);
		ans %= MOD;
		for (int c : V[cur]) {
			if (c != parent[cur])q.push(pair<int, int>(c, 0));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10104
#!user/bin/env python
# coding:utf-8

n = int(input())
info = []

for i in range(n):
    # ai = int(input())
    # bi = int(input())
    abi = input()
    ai, bi = int(abi.split(' ')[0]), int(abi.split(' ')[1])
    
    info.append([ai, bi])

info = sorted(info, key=lambda inf: inf[1])

imp = info[0][0] + info[0][1]
print(imp)

Measured memory_bytes: 22092
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

ll dp[100][10];
ll dp2[100];
ll calc(ll i, ll j) {
	if(i==1) return 1;
	if(dp[i][j]!=-1) return dp[i][j];
	ll res=0;
	for(int x=max(0LL,j-1);x<=min(9LL,j+1);++x) {
		res+=calc(i-1, x);
	}
	return dp[i][j]=res;
}

string ans;
void gen2(ll k, ll len, bool start=true) {
	//~ LOG(len);
	if(len==0) return ;
	int L=start, R=10;
	if(!ans.empty()) {
		L=max(0, ans.back()-'0'-1);
		R=min(9, ans.back()-'0'+1)+1;
	}
	for(int i=L;i<R;++i) {
		k-=calc(len,i);
		//~ LOG(dp[len][i]);
		//~ LOG(k);
		if(k<=0) {
			//~ LOG("van");
			k+=calc(len,i);
			ans+=i+'0';
			gen2(k, len-1, false);
			break ;
		}
	}
}

void gen(ll k) {
	int len;
	for(int i=1;;i++) {
		k-=dp2[i];
		if(k<=0) {
			k+=dp2[i];
			len=i;
			break ;
		}
	}	
	//~ LOG(k);
	//~ LOG(dp[2][1]);
	gen2(k, len);
}



int main() {
	IO;
	memset(dp,-1,sizeof dp);
	for(int i=0;i<100;++i) {
		for(int j=0;j<10;++j) {
			calc(i,j);
		}
		for(int j=1;j<10;++j) dp2[i]+=calc(i,j);
	}
	//~ cerr<<dp2[1]<<"\n";
	//~ cerr<<dp2[2]<<"\n";
	//~ return 0;
	ll k;
	cin>>k;
	gen(k);
	cout<<ans<<"\n";

	return 0;
}


Measured memory_bytes: 256
#define DEBUG 0

/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-4-20 21:08:04
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
const ll M = 998244353;

int N;
int a[310];
int S = 0;
ll dp[310][90010];
ll DP[310][90010];

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> a[i];
    S += a[i];
  }
  fill(&dp[0][0], &dp[0][0] + 310 * 90010, 0);
  dp[0][0] = 1;
  for (auto i = 0; i < N; i++)
  {
    for (auto v = 0; v < 90010; v++)
    {
      if (dp[i][v] == 0)
      {
        continue;
      }
      dp[i + 1][v + a[i]] += dp[i][v];
      dp[i + 1][v + a[i]] %= M;
      dp[i + 1][v] += 2 * dp[i][v];
      dp[i + 1][v] %= M;
    }
  }
  ll K = 0;
  for (auto v = (S + 1) / 2; v <= S; v++)
  {
    K += dp[N][v];
  }
  fill(&DP[0][0], &DP[0][0] + 310 * 90010, 0);
  DP[0][0] = 1;
  for (auto i = 0; i < N; i++)
  {
    for (auto v = 0; v < 90010; v++)
    {
      if (DP[i][v] == 0)
      {
        continue;
      }
      DP[i + 1][v + a[i]] += DP[i][v];
      DP[i + 1][v + a[i]] %= M;
      DP[i + 1][v] += DP[i][v];
      DP[i + 1][v] %= M;
    }
  }
  ll L = 0;
  if (S % 2 == 0)
  {
    L = DP[N][S / 2];
  }
  ll ans = 1;
  for (auto i = 0; i < N; i++)
  {
    ans *= 3LL;
    ans %= M;
  }
  ans += M - (3 * K) % M;
  ans %= M;
  ans += 3 * L;
  ans %= M;
  cout << ans << endl;
}

Measured memory_bytes: 436352