akhauriyash/Code-Regression huggingface dataset:
//__professor_
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define lld long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define ub upper_bound
#define lb lower_bound
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define test ll t;cin>>t;while(t--)
#define mod 1000000007
#define inf 1000000000000000001
const double pi  =3.141592653589793238463;
using namespace std;

int main()
{
	FAST;
	string s,t;
	cin>>s>>t;
	ll n=s.size();
	ll m=t.size();
	ll dp[n+1][m+1];
	for(ll i=0;i<=n;i++)
	{
		dp[i][0]=0;
	}
	for(ll i=0;i<=m;i++)
	{
		dp[0][i]=0;
	}

	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			if(s[i-1]==t[j-1])
			{
				
				dp[i][j]=1+dp[i-1][j-1];
			}
			else
			{

				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}

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

	vector<char> v;
	ll i=n,j=m;
	while(i>=1 && j>=1)
	{
		if(dp[i][j]>max(dp[i][j-1],dp[i-1][j]))
		{
			v.push_back(s[i-1]);
			//cout<<i<<" "<<j<<endl;
			i=i-1;
			j=j-1;
			continue;
			
		}
		if(dp[i-1][j]>dp[i][j-1])
		{
			i--;
		}
		else
		{
			j--;
		}
		
	}
	

	reverse(v.begin(),v.end());
	for(auto x:v)
		cout<<x;
	//cout<<dp[n][m]<<endl;
	return 0;
}



Measured memory_bytes: 70656
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define ll long long
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define eps 1e-7
#define zero(x) (((x) > 0? (x):(-x)) < eps)
using namespace std;
//https://codeforces.com/contest/1238/problems
//https://codeforces.com/contest/1238/submit

int c[10050];
int main(){
    for(int i = 0; i < 10005; i ++){
        c[i] = i*i;
    }
    string a,b;
    cin >> a >> b;
    string d = a+b;
    string e = b+a;
    int x = atoi(d.c_str());
    int y = atoi(e.c_str());
    int xx = lower_bound(c,c+10000,x)-c;
    int yy = lower_bound(c,c+10000,y)-c;
    if(c[xx] == x ||c[yy] == y){
        puts("Yes");
    }else{
        puts("No");
    }


    return 0;
}


Measured memory_bytes: 256
/*   Author : Rshs
 *   Data : 2019-10-05-19.57
 */
#include<bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define LL long long
#define MP make_pair
#define PII pair<int,int>
#define SZ(a) (int)a.size()
const double pai = acos(-1);
const double eps = 1e-10;
const LL mod = 1e9+7;
const int MXN = 1e6+5;

int main(){
    string s;LL k;
    cin>>s>>k;
    int le=s.length();
    LL l=0,r=le-1,d1=1,d2=1,d3=0;
    while(l<le-1&&s[l]==s[l+1]) l++,d1++;
    while(r>0&&s[r]==s[r-1]) r--,d2++;
    if(r==0) return cout<<(LL)le*k/2,0;
    for(int i=l+1;i<=r;i++){
        if(s[i]==s[i-1]) d3++,i++;
    }
    LL ans=d1/2+d2/2+d3*k;
    if(s[0]==s[le-1])ans=ans+(d1+d2)/2*(k-1);
    else ans=ans+(d1)/2*(k-1)+d2/2*(k-1);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int a, b; cin >> a >> b;
    int tmp = 1;
    int ans = 0;
    while(1) {
        if(tmp >= b) break;
        tmp =tmp-1+a;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#if defined(LOCAL)
#define PROBLEM_NAME "b"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) debug(x)
#else
#define L(x, ...) (x)
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)

#if defined(LOCAL)
#define L(x...) debug(x)
#else
#define L(x, ...) (x)
#endif

bool good(l x, l y, vvl& colors) {
  return (x > -1 and x < colors.size() and
          y > -1 and y < colors[0].size() and
          colors[x][y] == 0);
}

void solve(istream& cin, ostream& cout) {
  l rows, cols, n;
  cin >> rows >> cols >> n;
  vl v(n); F(i, 0, n) cin >> v[i];
  l x = 0, y = 0;
  vvl colors(rows, vl(cols));
  l k = 0;
  l dx[] = {0, 1, 0, -1};
  l dy[] = {1, 0, -1, 0};
  F(i, 0, rows * cols) {
    while (v[k] == 0) k++;
    colors[x][y] = k + 1;
    v[k]--;
    F(j, 0, 4) {
      if (good(x + dx[j], y + dy[j], colors)) {
        x = x + dx[j];
        y = y + dy[j];
        break;
      }
    }
  }
  F(i, 0, rows) {
    F(j, 0, cols) {
      if (j) cout << ' ';
      cout << colors[i][j];
    }
    cout << lf;
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


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

ll MOD = 1000000007;

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

  /*
  for (int a1 = 0; a1 <= 0; a1++) {
    for (int a2 = 0; a2 <= 4; a2++) {
      for (int a3 = 0; a3 <= 4; a3++) {
        for (int a4 = 0; a4 <= 4; a4++) {
          for (int a5 = 0; a5 <= 4; a5++) {
            A[0] = a1, A[1] = a2, A[2] = a3, A[3] = a4, A[4] = a5;
            ll ans = 3;
            map<ll, ll> m;
            m[0] = 1;
            for (int i = 1; i < N; i++) {
              if (A[i] == 0) {
                ans = ans * (3 - m[A[i]]) % MOD;
                m[A[i]]++;
              } else {
                ans = ans * (m[A[i] - 1] - m[A[i]]) % MOD;
                m[A[i]]++;
              }
            }
            if (ans > 0)
              cout << a1 << " " << a2 << " " << a3 << " " << a4 << " " << a5
                   << " " << ans % MOD << endl;
          }
        }
      }
    }
  }
  */
  if (A[0] > 0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 3;
  int m[100000] = {};
  m[0] = 1;
  for (int i = 1; i < N; i++) {
    if (A[i] == 0) {
      if (3 - m[A[i]] == 0) {
        cout << 0 << endl;
        return 0;
      }
      ans = ans * (3 - m[A[i]]) % MOD;
      m[A[i]]++;
    } else {
      if (m[A[i] - 1] - m[A[i]] <= 0) {
        cout << 0 << endl;
        return 0;
      }
      ans = ans * (m[A[i] - 1] - m[A[i]]) % MOD;
      m[A[i]]++;
      if (m[A[i]] == 4) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << ans % MOD << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

// #define int ll

const int maxn = 1e5+5;
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}

ll gcd(ll a, ll b){
	if (a==0) return b;
	if (b==0) return a;
	return gcd(b, a%b);
}

main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    vector<ll> a(n);
    vector<ll> a1(n), a2(n);
    REP(i,n) cin>>a[i];
    REP(i,n){
    	a1[i]=a[i]; if (i) a1[i]=gcd(a1[i],a1[i-1]);
    }
    RREP(i,n){
    	a2[i]=a[i]; if (i!=n-1) a2[i]=gcd(a2[i],a2[i+1]);
    }
    ll re = 0;
    REP(i,n){
    	MXTO(re, gcd(((i)?a1[i-1]:0),((i!=n-1)?a2[i+1]:0)));
    }
    cout<<re<<endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf 100000000
#define mod 1000000007
#define ld long double
#define point complex<double>
#define pi  acos(-1)
#define IO                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;

int main()
{
    IO
	int n;
	cin>>n;
	int arr[n];
	int arr2[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		arr2[i]=arr[i];
	}
	sort(arr2,arr2+n);
	int p1=-1,p2=-1,cnt=0;
	for(int i=0;i<n;i++)
	{
		if(arr2[i]!=arr[i])
		{
			cnt++;
			if(p1==-1)p1=i;
			else p2=i;
		}
	}
	if(cnt==0)
	{
		cout<<"YES"<<endl;
	}
	else if (cnt==2)
	{
		swap(arr[p1],arr[p2]);
		for(int i=0;i<n;i++)
	{
		if(arr2[i]!=arr[i])
		{
			cout<<"NO";
			return 0;
		}
		
	}
	cout<<"YES"<<endl;
	}
	else 
	{
		cout<<"NO"<<endl;
	}


    return 0;
}


Measured memory_bytes: 256
def init_d():
    d = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0, 'f': 0, 'g': 0,
         'h': 0, 'i': 0, 'j': 0, 'k': 0, 'l': 0, 'm': 0, 'n': 0,
         'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0,
         'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}
    return d

W = input()

d = init_d()
n = len(W)
for i in range(n):
    d[W[i]] += 1

for v in d.values():
    if v % 2 != 0:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H=0, W=0, count=0;
  cin >> H >> W;
  vector<string>s(H);
  for(int i=0;i<H;i++){
    cin >> s.at(i);
  }
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s.at(i).at(j) == '#'){
        cout << "#";
      }else{
      for(int k=-1;k<2;k++){
        for(int l=-1;l<2;l++){
          if(i+k<H && i+k>=0 && j+l<W  && j+l>=0){
            if(s.at(i+k).at(j+l)=='#'){
              count++;
              }//if
            }//if
          }//for l
        }//for k
        cout << count;
        count=0;
      }//else
    }//for j
    cout << endl;//for iの中
  }//for i
}//main

Measured memory_bytes: 3552
#include <cstdio>
#include <vector>

using namespace std;

int main() {
    int n, q, l, r;
    scanf("%d%d", &n, &q);
    vector<char> s(n + 1);
    vector<int> d(n + 1);
    scanf("%s", s.begin() + 1);
    for (int i = 1; i <= n; ++i) d.at(i) = d.at(i - 1) + (s.at(i) == 'C' && s.at(i - 1) == 'A');
    for (int i = 0; i < q; ++i) {
        scanf("%d%d", &l, &r);
        printf("%d\n", d.at(r) - d.at(l));
    }
    return 0;
}


Measured memory_bytes: 1280
def main():
    n=int(input())
    C=[[0]*10 for _ in range(10)]
    for i in range(1,n+1):
        s=str(i)
        C[int(s[0])][int(s[-1])]+=1
    ans=0
    for i in range(10):
        for j in range(10):
            ans+=C[i][j]*C[j][i]
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 40300
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[105],minn=2147483647,maxx=0;
inline int read(){
	char ch=getchar();
	int x=0,f=1;
	while(ch<'0' || ch>'9')	{if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main(){
    n=read();
    for(int i=1;i<=n;i++){
		a[i]=read();
		minn=min(a[i],minn);
		maxx=max(a[i],maxx);
    }
    printf("%d\n",maxx-minn);
	return 0;
}



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

using namespace std;
typedef long long ll;

const int MAX = 20000001;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
  COMinit();
  ll X, Y;
  cin >> X >> Y;

  if ((X + Y) % 3)
  {
    cout << 0 << endl;
    return 0;
  }

  const ll k = (X + Y) / 3;
  ll idx = -1;

  for (auto i = 0; i <= k; i++)
  {
    ll x = 2 * i + k - i;
    ll y = i + 2 * (k - i);
    if (x == X && y == Y)
    {
      idx = i;
      break;
    }
  }

  if (idx == -1)
  {
    cout << 0 << endl;
    return 0;
  }

  cout << COM(k, idx) << endl;

  return 0;
}


Measured memory_bytes: 469120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,l;
    cin>>n>>l;
    vector<string> s(n);
    for(int i=0;i<n;i++){
      cin>>s[i];
    }
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++){
      cout<<s[i];
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.* // Scanner

fun main(args: Array<String>) {

    val _s = Scanner(System.`in`)

    //
    val a_ = _s.nextInt()
    val b_ = _s.nextInt()

    //
    var ret = 
        if(
            a_ % 3 == 0 ||       
            b_ % 3 == 0 || 
            (a_ + b_) % 3 ==0) 
            
        {
            "Possible"
        } else {
            "Impossible"
        }

    println(ret)
}

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

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

int main(){
  int N;
  int p[100001];
  int dp[100001];

  cin >> N;
  rep(i,N) cin >> p[i];

  memset(dp, -1, sizeof(dp));

  queue<int> que;
  que.push(0);
  dp[0] = 0;

  while(!que.empty()){
    int now = que.front(); que.pop();

    if(now == N) break;

    rep(i,6){
      int next = now + i + 1;
      
      if(next >= N) next = 2*(N-1) - next;
      if(dp[next] != -1) continue;
      
      dp[next] = dp[now] + 1;
      
      while(p[next] != 0){
	int next2 = next + p[next];
	if(next2 >= N) next2 = 2*(N-1) - next2;
	if(dp[next2] != -1) goto next;
	dp[next2] = dp[next];
	next = next2;
      }
      que.push(next);
    next: ;
    }
  }

  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 2000
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x; cin>>n>>m>>x;
  int ans1=0,ans2=0;
  vector<int> a(m);
  for(int i=0; i<m; i++){
    cin>>a.at(i);
    if(a.at(i)<x) ans1++;
    else ans2++;
  }
  cout<<min(ans1,ans2)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int n;
int main()
{
	long long cnt[5];
	REP(i, 0, 5) cnt[i] = 0;

	cin >> n;
	REP(i, 0, n) {
		string s;
		cin >> s;
		if (s[0] == 'M') cnt[0]++;
		else if (s[0] == 'A') cnt[1]++;
		else if (s[0] == 'R') cnt[2]++;
		else if (s[0] == 'C') cnt[3]++;
		else if (s[0] == 'H') cnt[4]++;
	}

	long long ans = 0;
	REP(i, 0, 3) {
		REP(j, i + 1, 4) {
			REP(k, j + 1, 5) {
				ans += (cnt[i] * cnt[j] * cnt[k]);
			}
		}
	}

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

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

int main(){
    string s;
    cin>>s;
    int n = s.size();
    vector<ll> vec(n);
    vector<ll> ls(2020,0);
    vec[n-1] = s[n-1]-'0';
    ls[s[n-1]-'0']+=1;
    ll t = 1;
    for(int i=n-2;i>=0;i--){
        t=t*10%2019;
        vec[i]= (t*(s[i]-'0')+vec[i+1])%2019;
        ls[(t*(s[i]-'0')+vec[i+1])%2019]+=1;
    }
    ll ans=0;
    ls[0]++;
    rep(i,2019){
        ans += ls[i]*(ls[i]-1)/2;
    }
    cout<<ans<<endl;
    
    return 0;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n, k;
    cin >> n >> k;
    int x = 1;
    for(int i = 0; i < n; ++i){
        if(x < k)
            x *= 2;
        else
            x += k;
    }
    cout << x << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100005
#define EMPTY -1

typedef struct {
  int parent;
  int left;
  int rsib;
} Node;

int depth[N];
Node node[N];

int depthcount(int x, int d){
  depth[x] = d;
  if(node[x].rsib != EMPTY)  depthcount(node[x].rsib,d);
  if(node[x].left != EMPTY)  depthcount(node[x].left,d+1);
}

int main(){
  int i,j,n,l,r,p,child,root,id,deg;

  scanf("%d",&n);
  for(i=0; i<n; i++) {
    node[i].left = EMPTY;
    node[i].rsib = EMPTY;
    node[i].parent = EMPTY;
  }


  for(i=0; i<n; i++){
    scanf("%d%d",&id,&deg);
    for(j=0; j<deg; j++){
      scanf("%d",&child);
      if(j == 0) {
	node[id].left = child;
	l = child;
      }
      else {
	node[l].rsib = child;
      }
      l = child;
      node[child].parent = id;
    }
  }
  for(i=0; i<n; i++) if(node[i].parent == EMPTY) root = i;
  depthcount(root,0);  //根と深さの数がはいる

    for(i=0; i<n; i++){
      printf("node %d: parent = %d, depth = %d, ",i,node[i].parent,depth[i]);
      if(node[i].parent == EMPTY) printf("root, ");
      else if(node[i].left == EMPTY) printf("leaf, ");
      else printf("internal node, ");
    
      printf("[");
      for(j=0, child=node[i].left; child != EMPTY; j++, child = node[child].rsib){
	if(j != 0) printf(", ");
	 printf("%d",child);
      }
      printf("]\n");
    }

  return 0;
}

Measured memory_bytes: 5296
#include <stdio.h>

int main(int argc, char **argv) {
  int x, a, b, n;

  while (scanf("%d %d %d", &x, &a, &b) != EOF) {
    n = (x - a) / b;
    printf("%d\n", x - a - b * n);
  }

  return 0;
}


Measured memory_bytes: 128
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    // 速度区間の数は(N+2)
    int N;
    cin >> N;

    // 速度区間の境目の数は(N+1)
    int t[N+1];
    t[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> t[i];
        t[i] += t[i-1];
    }
    int T = t[N];

    // 速度区間の数は(N+2)
    int v[N+2];
    v[0] = 0;
    v[N+1] = 0;
    for (int i = 1; i <= N; i++) cin >> v[i];

    // table[i][j]: i番目の区間による最大値の束縛で, 時間インデックスj番目を表す
    double table[N + 2][2*T + 1];

    for (int i = -1; i <= N; i++) {
        double left = i < 0 ? -1 : t[i];
        double right = i == N ? T + 1 : t[i+1];
        left *= 2;
        right *= 2;

        for (int time = 0; time <= 2*T; time++) {
            if (time < left) {
                table[i+1][time] = v[i+1] + (left - time) * 0.5;
            } else if (time > right) {
                table[i+1][time] = v[i+1] + (time - right) * 0.5;
            } else {
                table[i+1][time] = v[i+1];
            }
        }
    }

    double min_vec[2*T + 1];
    for (int j = 0; j < 2*T + 1; j++) {
        min_vec[j] = table[0][j];
        for (int i = 1; i < N+2; i++) {
            min_vec[j] = min(min_vec[j], table[i][j]);
        }
    }

    double ret = 0;
    for (int i = 0; i < 2*T; i++) {
        ret += abs(min_vec[i] + min_vec[i+1]) * 0.5 * 0.5;
    }

    cout << fixed << setprecision(5) << ret << endl;
}

Measured memory_bytes: 32384
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int32_t main() {
	int n,k,q,ans=0;
	map<int ,int > mp;
	cin>>n>>k>>q;
	int tq=q,i;
	while(q--)
	{
		int v;
		cin>>v;
		mp[v]++;
	}
	for(i=1;i<=n;i++){
		if(k+mp[i]-tq>0)
			cout<<"Yes\n";
		else cout<<"No\n";
	}
}
						

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

#define pb push_back
#define pf push_front
#define st first
#define nd second
#define sz(x) ((int)x.size())
#define ins insert
#define fastio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define pi acos(-1.0)
using namespace std;

const int maxn=1e6+10;
const int maxe=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int gcd(int a,int b){
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
}

int a[maxn],num[maxn]={};
int main(){
    int n;
    scanf("%d",&n);
    int g=0;
    int f=0;
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        g=gcd(g,a[i]);
        for(int j=2;j*j<=a[i];++j){
            if(a[i]%j==0){
                num[j]++;
                if(num[j]>1)f=1;
                while(a[i]%j==0)a[i]/=j;
            }
        }
        num[a[i]]++;
        if(num[a[i]]>1&&a[i]!=1)f=1;
    }
    if(g>1)cout<<"not coprime"<<endl;
    else {
        if(f)cout<<"setwise coprime"<<endl;
        else cout<<"pairwise coprime"<<endl;
    }
}


Measured memory_bytes: 11400
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(x) cout << (x) << endl;
const int INF = 1e+8+7;
ll n,m;
string s,t;
int d[100],dp1[500][500],dp2[500][500];

int main(){
  int a[100000],b[100000],c[100000];
  m = 0;
  cin >> n;
  rep(i,0,n)cin >> a[i];
  rep(i,0,n)cin >> b[i];
  rep(i,0,n)cin >> c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  rep(i,0,n){
    ll mn = lower_bound(a,a+n,b[i])-a;
    ll mx = (c+n)-upper_bound(c,c+n,b[i]);
    m += mn * mx;
  }
  print(m);
  return 0;
}

Measured memory_bytes: 1408
import numpy as np

n,k = map(int,input().split())
p_list = np.fromstring(input(), np.int64, sep=' ')

Cumulative_sum = np.zeros(n+1, np.int64)
Cumulative_sum[1:] = p_list.cumsum()

length_k_sum_list = Cumulative_sum[k:] - Cumulative_sum[0:-k]

ans = (length_k_sum_list.max() + k) / 2

print(ans)

Measured memory_bytes: 18520
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

signed main()
{   
    int H,W; cin>>H>>W;
    vector<string> s(H+2);
    for(int i=1;i<=H;i++){
        cin>>s[i];
        s[i]='*'+s[i]+'*';
    }
    s[0]=s[H+1]=string(W+2,'*');

    bool ok=true;
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){ 
        if(s[i][j]=='.') continue;
        if(s[i-1][j]!='#' and s[i][j-1]!='#' and s[i][j+1]!='#' and s[i+1][j]!='#') 
            ok=false;
    }
    cout<<(ok? "Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

int main(){

  long ii,jj,kk;
  vector<int> a;
  int n;
  cin >> n;
  vector<int> tree;
  tree.resize(n);

  for(ii=0;ii<n;ii++){
    cin >> tree[ii];
  }

  for(ii=0;ii<n;ii++){
    cout << "node "  << (ii+1) << ": key = " << tree[ii] << ", ";
    if(ii!=0){
      cout << "parent key = " << tree[(ii-1)/2] << ", ";
    }
    if(ii*2+1<n){
      cout << "left key = " << tree[ii*2+1] << ", ";
    }
    if(ii*2+2<n){
      cout << "right key = " << tree[ii*2+2] << ", ";
    }
    cout << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, L;
  cin >> N >> L;
  
  vector<string> s(N);
  for (string &x:s)
    cin >> x;
  
  sort(s.begin(), s.end());
  string word;
  for (int i = 0; i < N; i++){
    word += s.at(i);
  }
  
  cout << word << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    
    if(A>K){
        cout << K;
        return 0;
    }
    if(A+B>K){
        cout << A;
        return 0;
    }else{
        cout << A-(K-A-B);
        return 0;
    }
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

LL mod = 1e9 + 7;


int m, n;
LL d[500005];
int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  scanf("%d%d", &n, &m);

  LL x = m - n;
  d[1] = x;
  d[2] = (x * x + x + 1) % mod;
  for (int i = 3; i <= n; i++) {
    d[i] = (x * d[i - 1] % mod + (i - 1) * (d[i - 2] + d[i - 1]) % mod) % mod;
  }
  LL ans = d[n];
  for (int i = m - n + 1; i <= m; i++) {
    ans = ans * i % mod;
  }
  cout << ans << endl;

#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 7412
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;

const int INF = 1e9 + 7;
const ll INFLL = 1e18;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bool IS_ONE_TEST = 1;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n + 1, 0), b(m + 1, 0);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= m; ++i) {
        cin >> b[i];
        b[i] += b[i - 1];
    }
    ll ans = 0, cur = 0;
    for (int i = 0; i <= n; ++i) {
        if (a[i] > k) {
            break;
        }
        auto it = upper_bound(all(b), k - a[i]);
        --it;
        cur = i;
        if ((k - a[i]) - *it >= 0) {
            cur += (it - b.begin());
        }
        ans = max(ans, cur);
    }
    cout << ans << en;
}

int main() {
    START_TIME = clock();
    fast_in_out();
    int TESTS = 1;
    if (!IS_ONE_TEST) cin >> TESTS;
    while (TESTS--) { solve(); }
#ifdef __APPLE__
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    cerr << en << TIME * 1000 << " ms." << en;
#endif
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 6352
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

int main()
{
	char s[10];
	int flag = 0;
	scanf("%s",s);
	for(int i = 0 ; i < strlen(s) - 1 ; i++){
		if(s[i] == 'A' && s[i + 1] == 'C') flag = 1;
	}
	if(flag) printf("Yes\n");
	else printf("No\n");
}

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

n, m = map(int,input().split())
a = list(map(int,input().split()))

bc = []
sum = 0

for i in range(m):
  b_c = list(map(int,input().split()))
  bc.append(b_c)
  
for i in a:
  bc.append([1,i])

sort_bc = sorted(bc, key=lambda x: x[1],reverse=True)

for i in sort_bc:
  if n < i[0]:
    sum += (n * i[1])
    break
  else:
    sum += (i[0] * i[1])
    n -= i[0]
    
print(sum)

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;

void debug_out() {
    cerr << endl;
}

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

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


int main() {
    FAST
    map<ll, bool> m;
    ll n, k;
    cin >> n >> k;
    ll arr[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    ll f = 1;
    vector<ll> v;
    ll reb;
    ll ans=0;
    while (!m[f]) {
        v.push_back(f);
        m[f] = 1;
        f = arr[f];
        k--;
        if(k==0)
            ans=f;

    }
    m.clear();
    vector<int> vv;
    while(!m[f])
    {
        vv.push_back(f);
        m[f]=1;
        f=arr[f];
    }
    if(k<=0)
        cout<<ans<<endl;
    else
        cout << vv[k%vv.size()] << endl;


    return 0;
}


Measured memory_bytes: 19128
#include "bits/stdc++.h"
using namespace std;
const int nmax = 1e6 + 10;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef double db;
int fa[nmax],a[nmax];
int n,m;
int findset(int x){
    int rt = x, temp;
    while(rt != fa[rt]) rt = fa[rt];
    while(x != rt ){
        temp = fa[x];
        fa[x] = rt;
        x = temp;
    }
    return rt;
}
int unionset(int x, int y){
    x = findset(x);
    y = findset(y);
    if(x == y) return -1;
    else {
        fa[x] = y;
        return 1;
    }
}
int main() {
    scanf("%d %d",&n,&m);
    for(int i = 1 ;i<=n; ++i) fa[i] = i;
    for(int i = 1 ;i<=n; ++i) scanf("%d",&a[i]);
    for(int i = 1 ;i<=m; ++i){
        int xx, yy;
        scanf("%d %d",&xx,&yy);
        unionset(xx, yy);
    }
    int ans  = 0;
    for(int i = 1;i<=n;++i){
        if(findset(i) == findset(a[i])) 
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>

int solve(int, int);

int a[2000];
int n;

int main(){
  int q;
  int m[2000];
  int i;
  int c;

  scanf("%d",&n);
  for(i=0; i < n; i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&q);
  for(i=0; i< q; i++){
    scanf("%d",&m[i]);
  }

  for(i=0; i < q; i++){

    if(solve(0,m[i])==1){
      printf("yes\n");
    }
      else{
	printf("no\n");
      }
  }

  return 0;
}


int solve(int i, int m){

  int res;
  if(m==0) return 1;
  if(i >= n) return 0;

  res=solve(i+1,m) || solve(i+1,m-a[i]);
  return res;
}

Measured memory_bytes: 588
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;


int main(){
    int n,i;
    cin>>n;
    int a[n];

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

    int m;
    cin>>m;
    int x[m],y[m],d,z=0,p=0;


    for(i=0;i<m;i++){
        cin>>x[i]>>y[i];
    }

    for(i=0;i<m;i++){
        z=0;
        d=x[i]-1;
        p=a[d];
        a[d]=y[i];
        for(int j=0;j<n;j++){
            z=z+a[j];
            //cout<<a[j]<<" ";
        }

        cout<<z<<endl;
        a[d]=p;
    }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

long long n, m;
pair<long long,long long> pd[1001000];




# if 0
int expectation2(int probability[], int distance[]){
  int S = 0;
  for (int i=0; i<n; ++i){
    S += probability[i] * distance[i];
  }
  // 予算0 の時の答えが，現在のS の値
  for (int i=0; i<n; ++i){
    if (m <= 0) break;
    int guarded = min(m, distance[i]);//Mと道[i]の長さの小さい方; // 雇う区間
    S -= probability[i]* guarded;
    m -= guarded;
  }
  return S;
}
#endif

int main(){
  while(cin >> n >> m && n ){
    long long d, p;
    for(int i = 0; i < n; ++i){
      cin >> d >> p;
      pd[i] = make_pair(p, d);
      
      // pd[i].first は道i の危険度
      // pd[i].second は道i の長さ
      //cout << pd[i].first << " " << pd[i].second <<  endl;
    }
    sort(pd, pd+n);
    
    int goal = 0;
    for(int i = 0; i < n; ++i){ 
      //cout << pd[i].first << " " << pd[i].second <<  endl;// 整列がうまく行ったか，PD を表示してみよう
      goal += pd[i].first * pd[i].second;
    }
    
    for(int i = n-1; i >=0; --i){
      if (m <= 0) break;
      int guarded = min(m, pd[i].second);//Mと道[i]の長さの小さい方; // 雇う区間
      goal -= pd[i].first * guarded;
      m -= guarded;
    }
    
    cout << goal << endl;
  }
}


Measured memory_bytes: 18752
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int n,m;
vector<int>vec[N];
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
		if(x)vec[x].push_back(y);else q.push(y);
	}
	for(int i=1;i<=m+1;i++)sort(vec[i].begin(),vec[i].end());
	int pos=-1;
	for(int i=1;i<=m;i++)
	if(vec[i].size()>1)
	for(int j=0;j<vec[i].size()-1;j++)q.push(vec[i][j]);
	else if(!vec[i].size())
	{
		if(!q.empty()&&q.top()<=i)q.pop();
		else{
			pos=max(pos,i);
			while(!vec[pos].size()&&pos<=m)pos++;
			if(vec[pos].size())vec[pos].pop_back();
		}
	}
	printf("%d",q.size());
}

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

int main(){
    ll n;
    cin >> n;
    ll a[n+1],b[n];
    for(ll i = 0;i < n+1;i++)cin >> a[i];
    for(ll i = 0;i < n;i++)cin >> b[i];
    ll ans = 0;
    ll y = min(b[n-1],a[n-1]+a[n]);
    ans += y;
    if(y>=a[n])a[n-1] = a[n]+a[n-1]-y;
    for(ll i = 0;i < n-1;i++){
        ll x = min(b[i],a[i]+a[i+1]);
        ans += x;
        if(x>=a[i])a[i+1] = a[i]+a[i+1]-x;
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
# input = sys.stdin.readline

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key=lambda x: x[1])

ans = 'No'
time = 0
for i, (Ai, Bi) in enumerate(AB):
    time += Ai
    if time > Bi: break
else:
    ans = 'Yes'

print(ans)


Measured memory_bytes: 53604
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;




int main(void) {
	int N,ans,num;
	num=0;
	cin >> N;
	vint A(N);
    for (int i = 0; i < N; i++)cin >> A[i];

	for (int i = 0;; i++) {
		for (int j = 0; j < N; j++) {
			if (A[j] % 2 == 1) {
				ans = i;
				num=1;
				break;
			}
			else A[j] /= 2;
			
		}
		if(num==1)break;
	}
	cout << ans << endl;
}

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

int main()
{
    int a,b,c,d;

    cin>>a>>b>>c>>d;

    while(a>0 || c>0)
    {
        c=c-b;
        a=a-d;

        if(c<=0)
        {
            cout<<"Yes";
            break;
        }
        else if(a<=0)
        {
            cout<<"No";
            break;
        }

    }

    return 0;
}


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

int main() {
    int n,k;
    int l[60];
    cin >> n >> k;
    for(int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    sort(l,l+n,greater<int>());
    int ans = 0;
    for(int i = 0; i < k; ++i) {
        ans += l[i];
    }
    cout << ans << endl;
}

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


int main(){
  ll n, k;
  cin >> n >> k;
  int count;
  double ans = 0.0;
  double a = 0.5;
  for(int i = 1; i <= n; i++){
    count = 0;
    double now = i;
    while(now <= k - 1){
      now *= 2.0;
      count++;
    }
    
    ans += pow(a, (double)count);
    
  }
  ans = ans / (double)n;
 printf("%.10lf", ans);

}


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

int main() {
    int64_t n; cin >> n;
    vector<int64_t> name;
    for (int i = 0; i < 20; i++) {
        n--;
        name.push_back(n % 26);
        n /= 26;
        if (n == 0) {
            break;
        }
    }
    reverse(name.begin(), name.end());
    for (auto x: name) {
        char y = 'a' + x;
        cout << y;
    }
    cout << endl;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s1 = br.readLine();
        for (int c : s1.toCharArray()) {
            System.out.print((char)(c >= 65 && c <= 90 ? c + 32 : c >= 97 && c <= 122 ? c - 32 : c));
        }
        System.out.println();
    }
}

Measured memory_bytes: 25028
def s():
 def b(M,x,y,n=0):
  if M[x][y]==0:return n
  M[x][y]=0
  a=max(b(M,x-1,y,n+1),b(M,x,y-1,n+1),b(M,x+1,y,n+1),b(M,x,y+1,n+1))
  M[x][y]=1
  return a
 for e in iter(input,'0'):
  n,m=int(e),int(input())
  P=[[0]*(n+2)for _ in[0]*(m+2)]
  for i in range(m):P[i+1][1:-1]=map(int,input().split())
  print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)))
if'__main__'==__name__:s()


Measured memory_bytes: 5724
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int k;
	int xyz[3];
	for(int i = 0; i < 3; i++){
		cin >> xyz[i];
	}
	cin >> k;
	long long int abc[3][1001];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < xyz[i]; j++){
			cin >> abc[i][j];
		}
		sort(abc[i], abc[i] + xyz[i]);
		reverse(abc[i], abc[i] + xyz[i]);
	}
	priority_queue<pair<long long int, vector<int> > > qu;
	long long int tmp = 0;
	vector<int> tmpv;
	for(int i = 0; i < 3; i++){
		tmp += abc[i][0];
		tmpv.push_back(0);
	}
	qu.push(make_pair(tmp, tmpv));
	set<vector<int> > used;
	used.insert(tmpv);
	for(int i = 0; i < k; i++){
		long long int ans = (qu.top()).first;
		vector<int> v = (qu.top()).second;
		qu.pop();
		cout << ans << endl;
		for(int j = 0; j < 3; j++){
			if(v[j] + 1 < xyz[j]){
				v[j]++;
				if(used.find(v) == used.end()){
					used.insert(v);
					long long int tmpans = ans - abc[j][v[j] - 1] + abc[j][v[j]];
					qu.push(make_pair(tmpans, v));
				}
				v[j]--;
			}
		}
	}
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> W(n);
        vector<vector<int>> dp(n, vector<int>(n, 0));
        for(int i = 0; i < n; i++) cin >> W[i];
    
        if(n == 1){
            cout << 0 << endl;
            return 0;
        }
    
        for(int w = 2; w <= n; w++){
            for(int r = 0; r <= n - w; r++){
                for(int k = r; k < r + w - 1; k++){
                    dp[r][r+w-1] = max(dp[r][r+w-1], dp[r][k]+dp[k+1][r+w-1]);
                }
                if(dp[r+1][r+w-2] == w-2 && abs(W[r]-W[r+w-1])<=1) dp[r][r+w-1] = max(dp[r][r+w-1], dp[r+1][r+w-2]+2);
            }
        }
    
        cout << dp[0][n-1] << endl;
    }
}


Measured memory_bytes: 3280
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	String[][] in = {
			{"wa","nn","wo","",""},
			{"a","u","o","i","e"},
			{"ka","ku","ko","ki","ke"},
			{"sa","su","so","si","se"},
			{"ta","tu","to","ti","te"},
			{"na","nu","no","ni","ne"},
			{"ha","hu","ho","hi","he"},
			{"ma","mu","mo","mi","me"},
			{"ya","yu","yo","",""},
			{"ra","ru","ro","ri","re"}
	};
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			char[] fl = scan.nextLine().toCharArray();
			for(int i = 0;i < fl.length;i+=2){
				int c = 0;
				switch(fl[i+1]){
				case 'T':c = 0;break;
				case 'L':c = 3;break;
				case 'U':c = 1;break;
				case 'R':c = 4;break;
				case 'D':c = 2;break;
				default:break;
				}
				System.out.print(in[fl[i]-'0'][c]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 17308
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> input(N);
    rep0(i, N)
    {
        cin >> input[i];
    }
    int D = 0;
    int res = 0;
    rep0(i, N)
    {
        res++;
        D += input[i];
        if (D > X)
        {
            break;
        }
    }
    if (D <= X)
    {
        res++;
    }
    cout << res;
}


Measured memory_bytes: 3596
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')
all = r * g * b

sub = 0
for i in range(N-1):
    for j in range(i, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            sub += 1
print(all - sub)

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

int main(){

    long long int a,b,c;

    cin >> a >> b >> c;

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

    return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 100;
bool flag;

bool cmp(int x,int y){
    return abs(0-x)<abs(0-y);
}

int main(){
    CIN(N);
    vi a(N+1),b(N+1);
    int sum=0;
    RepS(i,1,N){
        cin>>a[i];
        b[i]=b[i-1]+a[i];
    }
    int check=0;
    int ans=INF;
    Rep(i,1,N){
        ans=min(ans,abs(b[i]-(b[N]-b[i])));
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
s =int(input())
i=0
ans=[]
while i==0:
    
    if s in ans:
        i +=1
    ans.append(s) 
    if s%2 ==0:
        s = s/2
    elif s%2 ==1:
        s =3*s+1
  
print(len(ans))

Measured memory_bytes: 2940
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

string s, t;
ll ans;
int main(){
	cin >> s;
	t = s;
	reverse(t.begin(), t.end());
	REP(i,0,s.size()/ 2){
		if(s[i] != t[i]){
			ans ++;
		}
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
long long int dp[101][100001];
int main(){
  int n,cap;
  cin>>n>>cap;
  int wt[n],value[n];
  for(int i=0;i<n;i++){
    cin>>wt[i];
    cin>>value[i];
  }
  dp[0][0]=0;
  for(int i=1;i<100001;i++)
    dp[0][i]=INT_MAX;
  for(int j=0;j<=n;j++)
    dp[j][0]=0;
  for(int i=1;i<=n;i++){
    for(int val=1;val<100001;val++){
      if(val<value[i-1])
        dp[i][val]=min(dp[i-1][val],(long long int)wt[i-1]);
      else if(dp[i-1][val-value[i-1]]==INT_MAX)
        dp[i][val]=INT_MAX;
      else dp[i][val]=min(dp[i-1][val-value[i-1]]+wt[i-1],dp[i-1][val]);
    }
  }
  int ans=INT_MIN;
  for(int i=0;i<n+1;i++){
    for(int j=0;j<100001;j++){
      if(dp[i][j]<=cap)
        ans=max(ans,j);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 82500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

const ll INF = 1000000000000000000;

int main() {
    long double a; cin >> a;
    long double b; cin >> b;

    long double c = b*a;
    long double tmpans = floor(c);
    ll ans = tmpans;
    cout << ans << endl;

    return 0;
}

// 1000000000000000
// 9.99


Measured memory_bytes: 3680
n,a,b,c,d = map(int,input().split())
s = list(input())

a-=1
b-=1
c-=1
d-=1
if d>c:
    dp = [False]*(n+3)
    dp[d] = True
    for i in range(d-1,-1,-1):
        if s[i] == '#':
            continue
        if dp[i+1] or dp[i+2]:
            dp[i] = True
    
    cp = [False]*(n+3)
    cp[c] = True
    for i in range(c-1,-1,-1):
        if s[i] == '#':
            continue
        if cp[i+1] or cp[i+2]:
            cp[i] = True
    if cp[a] and dp[b]:
        print('Yes')
    else:
        print('No')
else:
    dp = [False]*(n+3)
    dp[d] = True
    for i in range(d-1,-1,-1):
        if s[i] == '#':
            continue
        if dp[i+1] or dp[i+2]:
            dp[i] = True
    
    cp = [False]*(n+3)
    cp[c] = True
    for i in range(c-1,-1,-1):
        if s[i] == '#':
            continue
        if cp[i+1] or cp[i+2]:
            cp[i] = True
    

    res = 0
    cnt = 0
    for i in range(b-1,d+2):
        if s[i] == '.':
            cnt += 1
        else:
            res = max(cnt,res)
            cnt = 0
    res = max(res,cnt)
    if cp[a] and dp[b] and res >= 3:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 7740