akhauriyash/Code-Regression huggingface dataset:
//お勉強中
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const ll mask30 = (1ll << 30) - 1;
const ll mask31 = (1ll << 31) - 1;
const ll RHmod = (1ll << 61) - 1;
const ll len = 5000;
ll POW[len + 1], RH[len + 1];
ll RHmul(ll A, ll B) {
	ll A1 = A >> 31;
	ll A2 = A & mask31;
	ll B1 = B >> 31;
	ll B2 = B & mask31;
	ll ret = 2 * A1 * B1 + A2 * B2 + ((A1 * B2 + A2 * B1 & mask30) << 31) + (A1 * B2 + A2 * B1 >> 30);
	return ret % RHmod;
}
ll RHcalc(int i, int j) {
	ll kari = (RH[j] - RH[i] + RHmod) % RHmod;
	return RHmul(kari, POW[len - i]);
}

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


	int N;
	cin >> N;
	string S;
	cin >> S;


	POW[0] = 1;
	rep(i, len) POW[i + 1] = RHmul(POW[i], 30);
	RH[0] = 0;
	rep(i, N) RH[i + 1] = (RH[i] + RHmul(POW[i], S[i] - 'a' + 1)) % RHmod;


	int L = 0;
	int R = N / 2 + 1;
	while (L + 1 < R) {
		int H = (L + R) / 2;

		int OK = 0;
		unordered_set<ll> ST;
		for (int i = 0; i <= N - 2 * H; i++) {
			ST.insert(RHcalc(i, i + H));
			if (ST.find(RHcalc(i + H, i + 2 * H)) != ST.end()) {
				OK = 1;
				break;
			}
		}

		if (OK) L = H;
		else R = H;
	}

	co(L);


	Would you please return 0;
}

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

const double eps = 1e-10;
typedef vector<vector<double>> mat;

vector<double> gauss_jordan(const mat& A, const vector<double> b) {
	int n = A.size();
	mat B(n, vector<double>(n + 1));
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
			B[i][j] = A[i][j];
	for(int i = 0; i < n; ++i)
		B[i][n] = b[i];
	
	for(int i = 0; i < n; ++i){
		int pivot = i;
		for(int j = i; j < n; ++j){
			if(abs(B[j][i]) > abs(B[pivot][i]))
				pivot = j;
		}
		swap(B[i], B[pivot]);
		
		if(abs(B[i][i]) < eps)
			return vector<double>();
		
		for(int j = i + 1; j <= n; ++j)
			B[i][j] /= B[i][i];
		for(int j = 0; j < n; ++j){
			if(i != j){
				for(int k = i + 1; k <= n; ++k)
					B[j][k] -= B[j][i] * B[i][k];
			}
		}
	}
	vector<double> x(n);
	
	for(int i = 0; i < n; ++i)
		x[i] = B[i][n];
	return x;
}

int main() {
	double a, b, c, d, e, f;
	while(cin >> a >> b >> c >> d >> e >> f){
		mat m;
		vector<double> l1, l2, r;
		l1.push_back(a); l1.push_back(b); r.push_back(c);
		l2.push_back(d); l2.push_back(e); r.push_back(f);
		m.push_back(l1); m.push_back(l2);
		vector<double> ans = gauss_jordan(m, r);
		printf("%.3f %.3f\n", ans[0], ans[1]);
	}
	return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
#endif

    string s;
    cin >> s;
    ll sum = 0;
    int p = 0, i = 0;
    char ch = '\0';
    for (char c : s) {
        if (ch != c) {
            if (ch == '>') sum += max(i, p), p = 0;
            else p = i;
            ch = c;
            i = 1;
        } else sum += i, i++;
    }

    sum += max(i, p);
    cout << sum;

    return 0;
}


Measured memory_bytes: 3912
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	string S; cin >> S;
	for (int i = 0; i < S.length() - 2; i++) {
		if (S[i] == S[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		if (S[i] == S[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	if (S[S.length() - 2] == S[S.length() - 1]) {
		cout << S.length() - 1 << " " << S.length() << endl;
		return 0;
	}
	cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
Main();
function Main(){
  var s = nextCharArray();
  var output = 0;
  var one = 0;
  var two = 0;
  for(var i = 0; i < s.length; i++){
    if(s[i] == "1"){
       one++;
    }else{
       two++;
    }
  }
  myout(Math.min(one,two) * 2);
}


Measured memory_bytes: 12364
#include <algorithm>
#include <cstdio>
#include <climits>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

ll dl[200][200], ds[200][200], dp[200], _dp[200];

int main() {
	for (;;) {
		int N, M; scanf("%d%d", &N, &M);
		if (N == 0 && M == 0) break;
		for (int u = 0; u < N; u++)
			for (int v = 0; v < N; v++)
				dl[u][v] = ds[u][v] = (u == v) ? 0 : INT_MAX;
		for (; M > 0; M--) {
			int x, y, t; char c; scanf("%d%d%d%*c%c", &x, &y, &t, &c);
			if (c == 'L') {
				dl[x - 1][y - 1] = min(dl[x - 1][y - 1], (ll)t);
				dl[y - 1][x - 1] = min(dl[y - 1][x - 1], (ll)t);
			}
			if (c == 'S') {
				ds[x - 1][y - 1] = min(ds[x - 1][y - 1], (ll)t);
				ds[y - 1][x - 1] = min(ds[y - 1][x - 1], (ll)t);
			}
		}
		for (int k = 0; k < N; k++)
			for (int u = 0; u < N; u++)
				for (int v = 0; v < N; v++) {
					dl[u][v] = min(dl[u][v], dl[u][k] + dl[k][v]);
					ds[u][v] = min(ds[u][v], ds[u][k] + ds[k][v]);
				}
		int R; scanf("%d", &R); R--;
		int _z; scanf("%d", &_z); _z--;
		fill(dp, dp + N, INT_MAX); dp[_z] = 0;
		for (; R > 0; R--) {
			swap(dp, _dp);
			int z; scanf("%d", &z); z--;
			for (int u = 0; u < N; u++) {
				dp[u] = min((ll)INT_MAX, _dp[u] + dl[_z][z]);
				for (int _u = 0; _u < N; _u++)
					dp[u] = min(dp[u], _dp[_u] + dl[_z][_u] + ds[_u][u] + dl[u][z]);
			}
			_z = z;
		}
		ll ans = INT_MAX;
		for (int u = 0; u < N; u++)
			ans = min(ans, dp[u]);
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;

int main(){

int n;
cin>>n;
set<ll>a;
rep(i,n){
    ll num;cin>>num;
    if(a.count(num)>0){
        cout<<"NO"<<endl;
        return 0;
    }
    else a.insert(num);
}
cout<<"YES";
return 0;
}

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define REP(i,n) for(ll i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1; 


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

  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  for(ll i = x; i <= y; i *= 2) ans ++;
  cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readIntBS = fst . fromJust . BS.readInt

main = do
  n <- readLn :: IO Int
  as <- reverse . sort . map (fromIntegral . readIntBS) . BS.words <$> BS.getLine :: IO [Integer]

  print $ sum $ solve $ take (2*n) as
  where
    solve [] = []
    solve (x:y:xs) = y : solve xs


Measured memory_bytes: 52604
#include<bits/stdc++.h>
using namespace std;
int dis[55][55];
int vis[55][55];
int dix[] = {0,0,1,-1};
int diy[] = {1,-1,0,0};
char a[55][55];
 int n,m;
int valid(int x, int y)
{
    if(x<1)return 0;
    if(x>n)return 0;
    if(y<1)return 0;
    if(y>m)return 0;
    if(a[x][y]!='.')return 0;
    if(vis[x][y])return 0;
    return 1;
}
void bfs(int x, int y)
{
    queue<pair<int,int> > q;
    q.push(make_pair(x,y));
    vis[x][y] = 1;
    dis[x][y] = 0;
    while(!q.empty())
    {
        pair<int,int> cur;
        cur = q.front();
        q.pop();
        x = cur.first;
        y = cur.second;
        int i;
        for(i=0;i<4;i++)
        {
            int nx = x + dix[i];
            int ny = y + diy[i];
            if(valid(nx,ny))
            {
                q.push(make_pair(nx,ny));
                vis[nx][ny] = 1;
                dis[nx][ny] = dis[x][y] + 1;
            }
        }
    }
}
int main()
{
   
    scanf("%d%d",&n,&m);
    int i,j;
    int cnt = 0;
    for(i=1; i<=n; i++){
        scanf("%s",&a[i][1]);
      //  printf("%s\n",&a[i][1]);
        for(j=1;j<=m;j++)if(a[i][j]=='.')cnt++;
    }
    
    for(i=1;i<=n;i++)for(j=1;j<=m;j++)dis[i][j] = 1000000007;
    if(a[1][1]=='.')bfs(1,1);
    if(dis[n][m]<1000000)printf("%d\n",cnt-1-dis[n][m]);
    else printf("-1\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int n;
    cin >> n;
    vector<int> l(n);
    REP(i, n)
    cin >> l[i];

    sort(l.begin(), l.end());
    auto sum = 0;
    REP(i, n - 1)
    sum += l[i];

    cout << (sum > l[n - 1] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
char x[128], y[128], z[256];
int n, m, i, j, k;

scanf("%s",&x);
scanf("%s",&y);

n = strlen(x);
m = strlen(y);

for(i = 0; i < 2 * n; i++){
z[i] = x[i % n];
}

for(i = 0; i < n; i++){
for(j = 0; j < m; j++){
if(z[i + j] == y[j])
	k++;
}
if(k == m){
	printf("Yes\n");
break;
}
k = 0;
}

if(k == 0)
	printf("No\n");

return 0;
}	

Measured memory_bytes: 524
from bisect import bisect_right
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a)
mod=10**9+7
ans=0
for i in range(n):
    for j in range(n):
        if i<j and a[i]>a[j]:
            ans+=1
ans*=k
#print(ans)
ans%=mod
r=0
for i in range(n):
    r+=(n-bisect_right(b,b[i]))
ans+=(r*(k-1)*k//2)
ans%=mod
print(ans)

Measured memory_bytes: 79280
#include<bits/stdc++.h>
using namespace std;
int a[10001];
int main()
{
	int n,ans;
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
	  scanf("%d",&a[i]);
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i+=2)
	  ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll a, b, x;
  cin >> a >> b >> x;
  ll kosu = b - a + 1;
  ll ans = kosu / x;
  ll amari = kosu % x;
  ll t = b % x - (amari - 1);
  if (t <= 0) ans++;
  ANS;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}

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

    vector<int> c(N+1, 0);
    int ans = 0;
    int ma = 1;
    rep(i, N) {
        int p = P[i];
        int l = c[p-1]+1;
        c[p] = l;
        chmax(ma, l);
    }
    ans = N - ma;

    cout << ans << endl;
}


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

int main() {

    int n, a;
    cin >> n >> a;
    if((n % 500) <= a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


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

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> l(2*n);
    for(int i = 0;i < 2*n;i ++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    for (int i = 2*n-2;i >= 0;i -= 2){
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
//ll const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

int H,W,N;
int a[10000];
int ans[100][100];

int main(){
    cin>>H>>W>>N;
    rep(i,N) cin>>a[i];

    int idx=0;
    rep(i,N){
        rep(j,a[i]){
            int r=idx/W;
            int c=idx%W;
            if(r&1) c=W-c-1;
            ans[r][c]=i+1;
            idx++;
        }
    }

    rep(i,H){
        rep(j,W) cout<<ans[i][j]<<' ';
        cout<<endl;
    }
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void)
{
	double hight;
	double max;
	double min;
	
	scanf("%lf", &hight);
	
	max = hight;
	min = hight;
	
	while (scanf("%lf", &hight) != EOF){
		if (max < hight){
			max = hight;
		}
		if (min > hight){
			min = hight;
		}
	}
	
	printf("%.1lf\n", max - min);
	
	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define pb push_back
#define mp make_pair
#define INF 2e9
#define mod 1000000007
#define eps 1e-6
#define abs(x) ((x)>=0?(x):-(x))
#define y1 solai
#define fi first
#define se second
typedef long long ll;
void read(ll &x)
{
	scanf("%lld",&x);
}
void read(ll &x, ll &y)
{
	scanf("%lld%lld",&x,&y);
}
void read(ll &x, ll &y, ll &z)
{
	scanf("%lld%lld%lld",&x,&y,&z);
}
void print(ll x)
{
	printf("%lld ",x);
}
void println(ll x)
{
	printf("%lld\n",x);
}
const ll N=100100;
ll n,m,a,b,cnt[N],ans,f[2*N],rf[2*N];
ll bin(ll a, ll n)
{
	ll ans=1;
	while(n)
	{
		if(n&1)
			(ans*=a)%=mod;
		(a*=a)%=mod;
		n/=2;
	}
	return ans;
}
ll c(ll n, ll k)
{
	if(k>n||k<0)
		return 0;
	return f[n]*rf[k]%mod*rf[n-k]%mod;
}
ll calc(ll n, ll m)
{
	return c(n+m-2,m-1);
}
int main()
{
	cin>>n>>m>>a>>b;
	f[0]=1;
	for(ll i=1;i<=n+m;i++)
		f[i]=f[i-1]*i%mod;
	rf[n+m]=bin(f[n+m],mod-2);
	for(ll i=n+m-1;i>=0;i--)
		rf[i]=rf[i+1]*(i+1)%mod;
	for(ll i=b+1;i<=m;i++)
		cnt[i]=calc(n-a,i),
		ans+=cnt[i]*calc(m-i+1,a),ans%=mod;
	println(ans);
}

Measured memory_bytes: 4096
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n,gg,p[11],c[11];
int dp[10010][11];

int main()
{
	scanf("%d%d",&n,&gg);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&p[i],&c[i]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int k=1000;k>=0;k--)
		{
			for(int j=1;j<p[i];j++)
			{
				dp[k+j][i]=max(dp[k+j][i-1],dp[k][i-1]+j*i*100);
			}
			dp[k+p[i]][i]=max(dp[k+p[i]][i-1],dp[k][i-1]+p[i]*i*100+c[i]);
		}
	}
	for(int i=1;i<=1000;i++)
	{
		if(dp[i][n]>=gg)
		{
			printf("%d\n",i);
			return 0;
		}
	}
}


Measured memory_bytes: 256
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))


n=int(input())
s=list(SR())

for i in range(len(s)):
    s[i] = ascii_uppercase2[ascii_uppercase2.index(s[i]) + n]
p2E(s)






Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		System.out.println((int)(A + B + C + Math.max(A,Math.max(B,C))*(Math.pow(2,K) -1)));
	}

}


Measured memory_bytes: 23764
n, m = map(int, input().split())
student = []
for _ in range(n):
    a = int(input())
    student.append(a)

for k in range(1, m+1):
    for i in range(n-1):
        if student[i] % k > student[i+1] % k:
            student[i], student[i+1] = student[i+1], student[i]

for s in student:
    print(s)



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

int main(){
  int N;
  cin >> N;
  int X = 100000000;
  for (int i = 0; i < N ; i ++){
    int A;
    int Z = 0;
    int w = 1;
    cin >> A;
    while (true){
      int Q;
      w *= 2 ;
      Q = A % w;
      if (Q == 0){
        Z ++;
      }
      else if (Q != 0){
        break;
      }      
    }
    if ( Z < X){
      X = Z;
    }
  }
  cout << X << endl;
}


Measured memory_bytes: 256
import sys
def resolve():
        input = sys.stdin.readline
        N,K=map(int,input().rstrip().split())

        print(K*pow(K-1,N-1))    




import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 2"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1 10"""
        output = """10"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """10 8"""
        output = """322828856"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.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; }

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	pair<pair<string, int>, int> p[n];
	rep(i, n){
		string s; int t;
		cin >> s >> t;
		p[i] = make_pair(make_pair(s, -t), i);
	}

	sort(p, p+n);

	rep(i, n) cout << p[i].second+1 << endl;
	return 0;
}

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

int n;
double a[300000];
ll s1[300000],s2[300000];

void calc(ll*s){
	stack<int>st;
	double p=a[0];
	ll cnt=0;
	for(int i=1;i<n;i++){
		while(p<a[i]){
			if(st.empty()){
				cnt+=i;
			}
			else{
				cnt+=i-st.top();
				st.pop();
			}
			p+=2;
		}
		double b=a[i];
		while(p>=b+2){
			b+=2;
			st.push(i);
		}
		s[i]=cnt;
		p=a[i];
	}
}
int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%lf",&a[i]);
		a[i]=log2(a[i]);
	}
	calc(s1);
	rep(i,n/2)swap(a[i],a[n-i-1]);
	calc(s2);
	ll Min=LLONG_MAX;
	rep(i,n+1){//最初に正になる場所
		ll A=(i>0?s1[i-1]*2:0);
		ll B=(i<n?s2[n-i-1]*2:0);
		Min=min(Min,A+B+i);
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 6016
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ld f(ld t, ld v, ld left, ld right) {
    if(v - left + v - right <= t) {
        return t * v - (v - left) * (v - left) / 2.0 - (v - right) * (v - right) / 2.0;
    }
    ld h = (t + left + right) / 2.0;
    return (left + h) * (h - left) / 2.0 + (right + h) * (h - right) / 2.0;
}

void solve() {
	int n; cin >> n;
    vector<ld> t(n + 2, 0), v(n + 2, 0);
    vector<ld> st(n + 4, 0);
    rep(i, n) {
        cin >> t[i + 1];
        st[i + 2] = st[i + 1] + t[i + 1];
    }
    rep(i, n) {
        cin >> v[i + 1];
    }
    ld ans = 0;
    rep(i, n + 1) {
        ld left = v[i], right = v[i];
        rep(j, n + 2) {
            if(j < i) {
                chmin(left, v[j] + st[i] - st[j + 1]);
                chmin(right, v[j] + st[i + 1] - st[j + 1]);
            } else if(i < j) {
                chmin(right, v[j] + st[j] - st[i + 1]);
                chmin(left, v[j] + st[j] - st[i]);
            }
        }
        //cerr << left << " " << right << endl;
        ans += f(t[i], v[i], left, right);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3868
//?????????????????????s[0]s[1]?????¨?????????
#include <iostream>
#include <string>
using namespace std;

int x[10][10];

char check_digit(string base_id) {
	int num = 0;
	for (int i = 0; i < 4; i++) {
		num = x[num][base_id[i] - '0'];
	}
	return (char)(num + '0');
}

bool is_correct(string id) {
	int num = 0;
	for (int i = 0; i < 5; i++) num = x[num][id[i] - '0'];
	return (num == 0);
}

bool is_detect_error(string id) {
	string eid;
	
	for (int i = 0; i < 5; i++) {
		eid = id;
		for (int j = 0; j < 10; j++) {
			eid[i] = (j + '0');
			if (eid != id && is_correct(eid)) { return false; }
		}
	}
	
	for (int i = 0; i < 4; i++) {
		eid = id;
		swap(eid[i], eid[i + 1]);
		if (eid != id && is_correct(eid)) { return false; }
	}
	return true;
}

int dfs(string base_id) {
	if (base_id.length() == 4) {
		return !is_detect_error( base_id + check_digit(base_id) );
	}
	
	int ret = 0;
	for (int i = 0; i < 10; i++) {
		ret += dfs(base_id + (char)('0' + i));
	}
	return ret;
}

int main() {
	int i, j;
	for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) cin >> x[i][j];
	cout << dfs("") << endl;
	return 0;
}

Measured memory_bytes: 3220
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 2e5 + 5;
int fact[N], ifact[N];
int path(int n,int m){
	int ans = (fact[n + m - 2] * ifact[n - 1]) % mod;
	ans = (ans * ifact[m - 1]) % mod;
	return ans;
}
void solve(){
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	fact[0] = 1;
	fr(i, 1, N - 1){
		fact[i] = (i * fact[i - 1]) % mod;
	}
	ifact[N - 1] = pwr(fact[N - 1], mod - 2, mod);
	for(int i = N - 2; i >= 0; i--){
		ifact[i] = (ifact[i + 1] * (i + 1)) % mod;
	}
	pii x = {h - a + 1, b};
	int ans = path(h, w);
	while(x.fi <= h && x.se > 0){
		int p = path(x.fi, x.se);
		p = (p * path(h - x.fi + 1, w - x.se + 1)) % mod;
		x.fi++, x.se--;
		ans = (ans - p + mod) % mod;
	}
	cout << ans;
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
using namespace std;
int h,w,n,a[11111],pos,k,x,y,ans[111][111];
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	pos=1;k=1;x=1;y=1;
	while(pos<=n)
	{
		ans[x][y]=pos;
		y+=k;
		a[pos]--;
		if (!a[pos]) pos++;
		if (y>w)
		{
			x++;y=w;k=-1;
		}
		if (y<=0) 
		{
			x++;y=1;k=1;
		}
		if (x>h) break;
	}
	for (int i=1;i<=h;i++)
	{
		for (int j=1;j<=w;j++)
		printf("%d ",ans[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cctype>
#include <utility>
#include <iostream>
#include <string>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, int &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	for (string s; getline(cin, s), s != "END OF INPUT";) {
		int w {};
		for (char c: s)
			if (c == ' ') {
				out(w);
				w = 0;
			} else
				w++;
		outl(w);
	}
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> st;
  for(int i=0; i<s.length(); i++){
    for(int j=1; j<=min(k, int(s.length())); j++){
      st.insert(s.substr(i,j));
    }
  }
  vector<string> v(st.begin(), st.end());
  cout << v[k-1] << endl;
  return 0;
}


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

void solve(){
	string str;
	cin >> str;
	int rain = 0;
	int flag = 0;
	for(int i = 0; i < 3; i++){
		if(str[i] == 'R'){
			flag++;
		}
		else{
			flag = 0;
		}
		rain = max(rain, flag);
	}
	cout << rain << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();	
}

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

using namespace std;
using LL=long long;

int R, C, K, a[3005][3005], x, y, z;
LL dp[3005][3005][4];

int main() {
    scanf("%d%d%d", &R, &C, &K);
    while (K--) {
        scanf("%d%d%d", &x, &y, &z);
        a[x][y] = z;
    }
    for (int i = 1; i <= R; i++)
        for (int j = 1; j <= C; j++)
            for (int k = 0; k <= 3; k++) {
                if (k > 1) {
                    if (a[i][j])
                        dp[i][j][k] = max(dp[i][j - 1][k], dp[i][j - 1][k - 1] + a[i][j]);
                    else
                        dp[i][j][k] = dp[i][j - 1][k];
                } else {
                    dp[i][j][0] = max(dp[i][j - 1][0], *max_element(dp[i - 1][j], dp[i - 1][j] + 4));
                    if (a[i][j]) {
                        dp[i][j][1] = max(max(*max_element(dp[i - 1][j], dp[i - 1][j] + 4), dp[i][j - 1][0]) + a[i][j],
                                          dp[i][j - 1][1]);
                    } else {
                        dp[i][j][1] = dp[i][j - 1][1];
                    }
                }
            }
    printf("%lld", *max_element(dp[R][C], dp[R][C] + 4));
    return 0;
}

Measured memory_bytes: 320348
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int c,int d){
    return d ? gcd(d, c % d) : c;
}



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

    int n,k; cin >> n >> k;
    int d,a;
    vector<int> ans(n+1);

    for(int i = 0;i < k;i ++){
        cin >> d;
        for(int j = 0;j < d;j ++){
            cin >> a;
            ans.at(a) = 1;
        }
    }

    int sum = 0;

    for(int i = 1;i < n+1;i ++){
        if(ans.at(i) == 0) sum ++;
    }

    cout << sum << endl;
}



Measured memory_bytes: 3652
inputNum = int(input())
shop = [0] * inputNum

for num in range(inputNum):
    city, score = input().split(" ")
    shop[num] = {'ID' : num + 1, 'City' : city, 'Score' : score}

sort_shop = sorted(shop, key = lambda x:-int(x['Score']))
sort_shop =sorted(sort_shop, key = lambda x:x['City']) 

for answer in sort_shop:
    print(answer['ID'])

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] strings = scan.nextLine().split("");
        int start = -1;
        int end = -1;
        for (int i = 0; i < strings.length - 1; i++) {
            if (strings[i].equals(strings[i + 1])) {
                start = i + 1;
                end = i + 2;
                break;
            }
            try{
            if (strings[i].equals(strings[i + 2])) {
                start = i + 1;
                end = i + 3;
                break;
            }
            }catch(Exception e){
                
            }

        }
        System.out.println(start + " " + end);
    }
}


Measured memory_bytes: 20276
n,m=map(int,input().split())
mod=10**9+7
import sys
sys.setrecursionlimit(100002)
def kaijou(x):
  if x==1:
    return 1
  else:
    return ((x%mod)*kaijou(x-1))%mod

if abs(m-n)==1:
  n2=kaijou(n)
  m2=kaijou(m)
  print((n2*m2)%mod)
elif abs(m-n)==0:
  n2=kaijou(n)
  m2=kaijou(m)
  print(2*(n2*m2)%mod)
else:
  print(0)

Measured memory_bytes: 83316
n,m,l=list(map(int,input().split()))
a=[[0]*m for i in range(n)]

for i in range(n):
    a[i]=list(map(int,input().split()))

b=[[0]*l for i in range(m)]

for i in range(m):
    b[i]=list(map(int,input().split()))

for i in range(n):
    for j in range(l):
        c=0
        for k in range(m):
            c+=a[i][k]*b[k][j]
        if j==0:
            print(c,end="")
        else:
            print(" "+str(c),end="")
    print()


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


template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}


int main(){
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long ma = max(max(max(a*c,b*d),a*d),b*c);
    cout<<ma<<endl;

    return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    if(n%k==0)cout << "0" << endl;
    else cout << "1" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include<utility>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

typedef pair<ll, ll> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int GCD(int x, int y) {
	return x ? GCD(y % x, x) : y;
}

int main()
{
	string s;
	cin>>s;
	int n=s.size();
	
	vector<bool>al(26,false);
	rep(i,n){
		al[s[i]-97]=true;
	}
	int ans=1e9;
	int only=0;
	rep(i,26){
		if(al[i]){
			only++;
			bool yet =true;
			int cnt=0;
			char a='a';
			a+=i;
			string tmp=s;
			int tmpn=n;
			while(yet){
				bool ok=true;
				rep(j,tmpn-1){
					if(tmp[j]==a or tmp[j+1]==a){
						tmp[j]=a;
					}else{
						ok=false;
					}
				}
				cnt++;
				tmpn--;
				if(ok){
					yet=false;
				}
			}	
		//	cout<<cnt<<" "<<a<<endl;
			ans=min(ans,cnt);		
		}
	}
	if(only==1){
		ans=0;
	}
	cout<<ans<<endl;



}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String res = s.charAt(0) == s.charAt(1) && s.charAt(0) == s.charAt(2)
                     || s.charAt(1) == s.charAt(2) && s.charAt(1) == s.charAt(3)
                     ? "Yes" : "No";
        System.out.println(res);
    }
}

Measured memory_bytes: 21716
package main

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

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func readInt(sc *bufio.Scanner) (res int) {
	res, _ =strconv.Atoi(readLine(sc))
	return
}

func readInts(sc *bufio.Scanner, n int) []int {
	ns := strings.Split(readLine(sc), " ")
	res := make([]int, n)

	for i, n := range ns {
		res[i], _ = strconv.Atoi(n)
	}
	return res
}

func readMatrix(sc *bufio.Scanner, rows, cols int) [][]int {
	res := make([][]int, rows)
	for i := 0; i < rows; i ++ {
		res[i] = readInts(sc, cols)
	}
	return res
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	n := readInt(sc)

	fmt.Println((800 * n) - (200 * (n / 15)))
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a[500005];
int main(){
	int n;
	long long ans=0;
	cin>>n;
	for(int i=1;i<=2*n;i++)
		cin>>a[i];
	sort(a+1,a+2*n+1);
	for(int i=1;i<=n;i++){
		ans+=a[i*2-1];
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

int main() {
   int a,b;
   cin >> a >> b;
   cout << (a==2 || b==2 ? "No" : "Yes") << endl;
}

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

int main() {
	int A , B;
  	cin >> A >> B;
    int kaibun_number = 0;
	for(int i = A; i <= B; i++){
    	if((i / 10000 == i % 10) && (i % 10000 / 1000 == i % 100 / 10)){
        	kaibun_number += 1;
        }
    }
  	cout << kaibun_number << endl;
}

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

int main(){
  string s;
  cin >> s;
  if(s == "AAA" || s == "BBB"){
    cout << "No" << endl;
  }else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cctype>

using namespace std;
using ll = long long;

constexpr ll INF = 1LL << 60;

ll scanll(){
    ll ret = 0;
    for(char c = getchar_unlocked(); isdigit(c); c = getchar_unlocked()){
        ret = 10 * ret + c - '0';
    }
    return ret;
}

void putll(ll x){
    if(!x){
        putchar_unlocked('0');
        return;
    }

    if(x < 0){
        putchar_unlocked('-');
        x = -x;
    }

    ll digits = 1;
    for(ll y = x; y /= 10; digits++);

    ll r = x % 10;
    for(x /= 10; x; r = 10 * r + x % 10, x /= 10);

    for(; r; r /= 10, digits--){
        putchar_unlocked(r % 10 + '0');
    }
    for(; digits; digits--){
        putchar_unlocked('0');
    }
}

ll f(ll b, ll n){
    ll ret = 0;
    for(; n; n /= b) ret += n % b;
    return ret;
}

int main(){
    ll n = scanll();
    ll s = scanll();
    ll d = n - s;

    if(d < 0) putll(-1);
    else if(!d) putll(n + 1);
    else{
        ll ans = INF;
        for(ll i = 1; i <= sqrt(d); i++){
            if(d % i) continue;

            ll b = i + 1;
            if(ans > b && f(b, n) == s) ans = b;

            b = d / i + 1;
            if(ans > b && f(b, n) == s) ans = b;
        }

        if(ans == INF) putll(-1);
        else putll(ans);
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
const ll MAX=110000;
const ll MOD=1000000007;
priority_queue<plll> tmp;
vector<pll> adj[MAX];
ll n,m,sd[MAX],td[MAX],sr[MAX],tr[MAX],S,T,fin;
int main(){
    scanf("%lld%lld%lld%lld",&n,&m,&S,&T);
    for(ll i=0;i<m;i++){
        ll t,t1,t2;
        scanf("%lld%lld%lld",&t1,&t2,&t);
        adj[t1].push_back(make_pair(t2,t));
        adj[t2].push_back(make_pair(t1,t));
    }
    tmp.push(make_pair(-1,make_pair(S,0)));
    while(!tmp.empty()){
        plll t=tmp.top();
        tmp.pop();
        t.first=-t.first;
        if(sd[t.second.first]==0ll){
            sd[t.second.first]=t.first;
            if(t.second.second==0) sr[t.second.first]=1;
            else sr[t.second.first]+=sr[t.second.second],sr[t.second.first]%=MOD;
            for(ll i=0;i<adj[t.second.first].size();i++) if(sd[adj[t.second.first][i].first]==0) {
                tmp.push(make_pair(-t.first-adj[t.second.first][i].second,make_pair(adj[t.second.first][i].first,t.second.first)));
            }
        }
        else if(sd[t.second.first]==t.first){
            sr[t.second.first]+=sr[t.second.second],sr[t.second.first]%=MOD;
        }
    }

    tmp.push(make_pair(-1,make_pair(T,0)));
    while(!tmp.empty()){
        plll t=tmp.top();
        tmp.pop();
        t.first=-t.first;
        if(td[t.second.first]==0ll){
            td[t.second.first]=t.first;
            if(t.second.second==0) tr[t.second.first]=1;
            else tr[t.second.first]+=tr[t.second.second],tr[t.second.first]%=MOD;
            for(ll i=0;i<adj[t.second.first].size();i++) if(td[adj[t.second.first][i].first]==0) {
                tmp.push(make_pair(-t.first-adj[t.second.first][i].second,make_pair(adj[t.second.first][i].first,t.second.first)));
            }
        }
        else if(td[t.second.first]==t.first){
            tr[t.second.first]+=tr[t.second.second],tr[t.second.first]%=MOD;
        }
    }
    for(ll i=1;i<=n;i++) sd[i]--,td[i]--;//printf("%lld %lld\n",sr[i],tr[i]);
    fin=sr[T]*tr[S],fin%=MOD;
    //printf("%lld\n",fin);
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<adj[i].size();j++){
            ll t=adj[i][j].second;
            ll t1=i,t2=adj[i][j].first;
            if(sd[t1]+t+td[t2]==sd[T]) if(sd[t1]*2<sd[T]&&td[t2]*2<sd[T]) fin-=(((sr[t1]*tr[t2])%MOD*sr[t1]%MOD)*tr[t2]%MOD),fin+=MOD,fin%=MOD;
        }
        if(sd[i]+td[i]==sd[T]) if(sd[i]*2==sd[T]) fin-=(((sr[i]*tr[i])%MOD*sr[i])%MOD*tr[i])%MOD,fin+=MOD,fin%=MOD;
    }
    printf("%lld\n",fin);
}


Measured memory_bytes: 20980
#include<bits/stdc++.h>
using namespace std;
# define ll long long
const int N = 1e5+1;
bool visited[N];
vector<ll>v[N];
vector<ll>p;
ll dis[N];



int main()
{
    ll n , m;
    cin >> n >> m;
    char g[n+1][m+1];
    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 1 ; j <= m ; j++)
        {
            cin >> g[i][j];
        }
    }
    ll dp[n+1][m+1];
    memset(dp , 0 , sizeof(dp));
    for(ll i = 2 ; i <=m; i++)
    {
        if(g[1][i] == '.' && g[1][i-1] == '.')
        dp[1][i] = 1;
        else
        break;
       // cout << i << endl;
    }

    for(ll i = 2 ; i <= n ; i++)
    {
        if(g[i][1] == '.' && g[i-1][1] == '.')
        dp[i][1] = 1;
        else
        break;
        
    }

    

     for(ll i = 2 ; i <= n ; i++)
    {
        //cout << "h" << endl;
        for(ll j = 2 ; j <= m ; j++)
        {
            if(g[i][j] == '.')
            dp[i][j]  = (dp[i-1][j] + dp[i][j-1])%(1000000007);
        }
    }

   /* for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j =1; j <= m ; j++)
        cout << dp[i][j] << " ";
        cout << endl;
    }*/

    cout << dp[n][m];
}


Measured memory_bytes: 11392
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    string s;
    char ch;
    int k;
    cin >> s >> k;
    bool f = 1;
    for (int i = 0; i < k;i++) {
        if (s[i] != '1') {
            f = 0;
            ch = s[i];
            break;
        }
    }
    if (f) cout << 1 << endl;
    else cout << ch << endl;
}

Measured memory_bytes: 256