akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;
int hh, ww;

bool isin(int x, int y) {
    if (0 <= x && x < hh && 0 <= y && y < ww)
        return true;
    return false;
}

int main() {
    int h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    hh = h; ww = w;
    vector<vector<char>> s(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c ;
            cin >> c;
            s[i][j] = c;
        }
    }
    
    vector<vector<int>> d(h, vector<int>(w, INF));
    d[ch - 1][cw - 1] = 0;
    queue<P> qa, qb;
    qa.emplace(ch - 1, cw - 1);
    do {
        while (!qa.empty()) {
            auto p = qa.front();
            int x = p.first, y = p.second;
            qa.pop();
            int n = d[x][y];
            
            vector<int> dx = {0, 0, -1, 1}, dy = {1, -1, 0, 0};
            for (int i = 0; i < 4; i++) {
                int nx = x + dx[i], ny = y + dy[i];
                if (!isin(nx, ny))
                    continue;
                if (s[nx][ny] == '.' && d[nx][ny] == INF) {
                    d[nx][ny] = n;
                    qa.emplace(nx, ny);
                }
                if (s[nx][ny] == '#') {
                    qb.emplace(x, y);
                }
            }
        }
        
        while (!qb.empty()) {
            auto p = qb.front();
            int x = p.first, y = p.second;
            qb.pop();
            int n = d[x][y] + 1;
            
            vector<int> dx = {-2, -1, 0, 1, 2}, dy = {-2, -1, 0, 1, 2};
            for (int i = 0; i < 5; i++) {
                for (int j = 0; j < 5; j++) {
                    int nx = x + dx[i], ny = y + dy[j];
                    if (!isin(nx, ny))
                        continue;
                    if (s[nx][ny] == '.' && d[nx][ny] == INF) {
                        d[nx][ny] = n;
                        qa.emplace(nx, ny);
                    }
                }
            }
        }
    } while (!qa.empty());
    
/*     for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << setw(3) << d[i][j];
        }
        cout << endl;
    } */
    
    if (d[dh - 1][dw - 1] == INF)
        cout << -1 << endl;
    else
        cout << d[dh - 1][dw - 1] << endl;
        
    
    return 0;
}


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

#define INF 1e9

int main(){
  int e;
  while(true){
    cin >> e;
    if(e == 0)
      break;

    int y, sum, nmin = INF;
    for(int i=0; i*i*i<=e; i++){
      sum = e - i*i*i;
      y = sqrt(sum);
      sum -= y*y;
      nmin = min(nmin, sum + y + i);
    }
    cout << nmin << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3016
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int A = Integer.parseInt(values[1]);
        int B = Integer.parseInt(values[2]);

        if (N * A >= B) {
            System.out.println(B);
        } else {
            System.out.println(N * A);
        }

        scanner.close();

    }

}


Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#define endl '\n'
#define ll long long
using namespace std;

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] <= a[i + 1]) continue;
		ans += a[i] - a[i + 1];
		a[i + 1] += a[i] - a[i + 1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3960
A, B, C = map(int, input().split())

if A == 7:
    if B == C and B == 5:
        print('YES')
    else:
        print('NO')

elif B == 7:
    if A == C and A == 5:
        print('YES')
    else:
        print('NO')

elif C == 7:
    if A == B and A == 5:
        print('YES')
    else:
        print('NO')

else:
    print('NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int N, M;
const int MAXN = 200005;
vi to[MAXN];

int main () {
  cin >> N >> M;
  REP(i,M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
  }

  for (auto c : to[0]) {
    for (auto d : to[c]) {
      if (d == N-1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }

  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e,f,g,h;
  cin >> a >> b >> c >> d;
  e=c+b-d;
  f=d+c-a;
  g=e-c+a;
  h=f+b-d;
  cout << e << " " << f << " " << g << " " << h << endl;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    string s; cin >> s;
    int cnt = 0, ma = 0;
    REP(i, s.size()) {
        switch(s[i]) {
            case 'A':
            case 'C':
            case 'G':
            case 'T':
            cnt ++;
            ma = max(ma,cnt);
            break;
            default:
            cnt = 0;
        }
    }
    cout << ma << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2010;
bool mp[N][N],good[N][N];
int deep[N][N];
int L[N],R[N];
int s[N],top;
char ss[N];
int H,W,ans=0;
int main()
{
    scanf("%d%d",&H,&W);
    for(int i=1;i<=H;i++)
    {
        scanf("%s",ss+1);
        for(int j=1;j<=W;j++)
            mp[i][j]=(ss[j]=='#');
    }
    for(int i=1;i<H;i++)
        for(int j=1;j<W;j++)
        {
            int cnt=mp[i][j]+mp[i+1][j]+mp[i][j+1]+mp[i+1][j+1];
            good[i][j]=!(cnt&1);
        }
    for(int i=1;i<=H;i++)
        for(int j=1;j<=W;j++)
            deep[i][j]=good[i][j]?deep[i-1][j]+1:0;
    for(int i=1;i<=H;i++)
    {
        s[top=1]=0;
        for(int j=1;j<W;j++)
        {
            while(top&&deep[i-1][s[top]]>=deep[i-1][j]) top--;
            L[j]=s[top];s[++top]=j;
        }
        s[top=1]=W;
        for(int j=W-1;j>=1;j--)
        {
            while(top&&deep[i-1][s[top]]>=deep[i-1][j]) top--;
            R[j]=s[top];s[++top]=j;
        }
        for(int j=1;j<W;j++)
            ans=max(ans,(deep[i-1][j]+1)*(R[j]-L[j]));
    }
    ans=max(ans,max(H,W));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 23936
#include<stdio.h>
#include<cctype>
#include<string.h>
 
 
int main(void){
 
    char s[1200];
    int i;
 
    gets(s);
 
    for(i=0;i<strlen(s);i++){
        if(s[i] <= 'z' && s[i] >= 'a')
            printf("%c",toupper(s[i]));
        else
            printf("%c",tolower(s[i]));
    }
    puts("");
 
    return 0;
 
}

Measured memory_bytes: 928
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long t1 = sc.nextLong();
		long t2 = sc.nextLong();
		long a1 = sc.nextLong();
		long a2 = sc.nextLong();
		long b1 = sc.nextLong();
		long b2 = sc.nextLong();
		sc.close();

		if (a1 > b1) {
			long z = a1;
			a1 = b1;
			b1 = z;
			z = a2;
			a2 = b2;
			b2 = z;
		}

		long c1 = a1 * t1;
		long c2 = a2 * t2;
		long d1 = b1 * t1;
		long d2 = b2 * t2;
		long c = c1 + c2;
		long d = d1 + d2;
		if (c == d) {
			System.out.println("infinity");
			return;
		}
		if (c < d) {
			System.out.println(0);
			return;
		}

		long x1 = d1 - c1;
		long x = c - d;
		long ans = 1;
		ans += x1 / x * 2;
		if (x1 % x == 0) {
			ans--;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 1e6+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size()){
        cout<<"GREATER";
    }
    else if(a.size()<b.size()){
        cout<<"LESS";
    }
    else {
        for(int i=0;i<a.size();i++){
            if(a[i]==b[i])continue;
            else if(a[i]<b[i]){
                cout<<"LESS";
                return 0;
            }
            else {
                cout<<"GREATER";
                return 0;
            }
        }
        cout<<"EQUAL";
    }
}

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

int main()
{
  int N;
  cin >> N;
  set<string> s;
  for (int i = 0; i < N; i++)
  {
    string str;
    cin >> str;
    s.insert(str);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 19212
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

long long int INF = 1000000000000000000LL; // 10^18
using namespace std;

int W[400000] = {};
int E[400000] = {};

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

int main(){
	
	int N;
	cin >> N;
	
	string str;
	cin >> str;
	
	
	int cnt = 0;
	
	for(int i = 0; i < N; i++){
		if(str[i] == 'W'){
			cnt++;
		}
		W[i] = cnt;
	}
	
	cnt = 0;
	for(int i = N - 1; i >= 0; i--){
		if(str[i] == 'E'){
			cnt++;
		}
		E[i] = cnt;
	}
	
	int ans = E[1];
	
	for(int i = 0; i < N - 1; i++){
		ans = min(ans, W[i] + E[i + 2]);
		W[i] = cnt;
	}
	
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;


int main() {
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];

	bool pair1 = (a[0] == a[1]);
	bool pair2 = (a[0] == a[2]);
	bool pair3 = (a[1] == a[2]);

	if(pair1 + pair2 + pair3 == 3) cout << 1 << endl;
	if(pair1 + pair2 + pair3 == 1) cout << 2 << endl;
	if(pair1 + pair2 + pair3 == 0) cout << 3 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;

#define M 1000000007
#define N 0x100000
#define ll long long

#define lc(x) ((x) << 1)
#define rc(x) ((x) << 1 | 1)
#define fa(x) ((x) >> 1)

int h, p[N], l[N], r[N];
int flag[N];
int dep[N];

int main() {
	//freopen("A.in", "r", stdin);
	int h, n;
	scanf("%d", &h);
	n = 1 << (h - 1);
	for (int i = n; i < (n << 1); i++) {
		scanf("%d", p + i);
		p[i] += n - 1;
	}
	for (int i = 0; i < h; i++)
		for (int j = (1 << i); j < (2 << i); j++)
			dep[j] = i;
	for (int i = 1; i < (n << 1); i++) {
		l[i] = i << (h - dep[i] - 1);
		r[i] = l[i] + (1 << (h - dep[i] - 1)) - 1;
	}
	
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		for (int j = l[lc(i)]; j <= r[lc(i)]; j++) {
			ll prod = i;
			for (int k = j; k != i; k = fa(k))
				prod = prod * k % M;
			for (int k = p[j]; k; k = fa(k)) {
				prod = prod * k % M;
				flag[k] = (flag[k] + prod) % M;
			}
		}
		for (int j = l[rc(i)]; j <= r[rc(i)]; j++) {
			ll prod = 1, last = 0;
			for (int k = j; k != i; k = fa(k))
				prod = prod * k % M;
			for (int k = p[j]; k; k = fa(k)) {
				ans += prod * (M + flag[k] - last * k % M) % M;
				prod = prod * k % M;
				last = flag[k];
			}
			ans %= M;
		}
		for (int j = l[lc(i)]; j <= r[lc(i)]; j++)
			for (int k = p[j]; k; k = fa(k))
				flag[k] = 0;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 6360
for i in range(4):
    t,n=map(int,input().split())
    
    if t == 1:
        print(6000*n)
    elif t == 2:
        print(4000*n)
    elif t == 3:
        print(3000*n)
    elif t == 4:
        print(2000*n)


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

int  main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if (a+b+c < 22)
		cout << "win\n";
	else
		cout << "bust\n";
	return (0);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long sum = 0;

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

vector<pair<char, int>> strcompress(string S, int N){
    int count = 1;
    char c = S[0];
    vector<pair<char, int>> vec; 
	rep(i, N-1){
		if(c == S[i+1]){
			count++;
		}else{
			vec.push_back(make_pair(c, count));
			count = 1;
			c = S[i+1];
		}
	}
	vec.push_back(make_pair(c, count));
    return vec;
}


int main() {
    string s;
    cin >> s >> K;
    vector<pair<char, int>> prd = strcompress(s, s.length());
    ll count = 0, last = prd.size()-1;
    rep(i, last+1){
        count += prd[i].second/2;
    }
    count *= K;
    if(prd[0].first == prd[last].first && (prd[0].second+prd[last].second)%2 == 0 && prd.size() > 1){
        count += K;
        count--;
    }else if(prd.size() == 1 && prd[0].second%2 == 1) count = prd[0].second*K/2;
    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

ll MOD=1e9+7, fact[200010], inv[200010], dp[200010];
ii a[200010];

ll fpow(ll base, ll exp) {
  ll result = 1;
  while(exp){
    if(exp & 1) result = (result*base) % MOD;
    exp >>= 1;
    base = (base*base) % MOD;
  }
  return result;
}

bool cmp(ii &x, ii& y){
  return x.fst+x.snd<y.fst+y.snd;
}

ll comb(ll n, ll k){
  return fact[n]*inv[k]%MOD*inv[n-k]%MOD;
}

int main(){FIN;
  fact[0]=1; inv[0]=1;
  fore(i,1,200010) fact[i]=(fact[i-1]*i)%MOD, inv[i]=fpow(fact[i],MOD-2);
  ll h,w,n; cin >> h >> w >> n;
  fore(i,0,n) cin >> a[i].fst >> a[i].snd, a[i].fst--, a[i].snd--;
  a[n++] = {h-1, w-1};
  sort(a,a+n,cmp);
  fore(i,0,n){
    dp[i] = comb(a[i].fst+a[i].snd,a[i].fst);
    fore(j,0,i){
      if(a[j].fst <= a[i].fst && a[j].snd <= a[i].snd){
        ll r = abs(a[j].fst-a[i].fst), c=abs(a[j].snd-a[i].snd);
        ll rest = dp[j]*comb(r+c,r)%MOD;
        dp[i]=(dp[i]-rest+MOD)%MOD;
      }
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
using namespace std;
int n, d[100005]={1};
vector<int> vt;
int main() {
	int i, j;
	cin>>n;
	vt.push_back(1);
	for(i=6; i<=n; i*=6) vt.push_back(i);
	for(i=9; i<=n; i*=9) vt.push_back(i);
	for(i=1; i<=n; i++) {
		d[i] = 1e9;
		for(j=0; j<vt.size(); j++) {
			if(i>=vt[j]) d[i] = min(d[i], d[i-vt[j]] + 1);
		}
	}
	cout<<d[n]-1;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define re register
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define per(i,n,m) for(int i=m;i>=n;i--)
#define rrep(i,m,n) for(register int i=m;i<=n;i++)
#define rper(i,n,m) for(register int i=m;i>=n;i--)
const int N = 3e5 + 10;
const ll mod = 1e9 + 7;
ll a[N];
signed main(){
    string s;
    cin>>s;
    int ans=0,tmp=0;
    for(auto i:s){
        if(i=='g') {
            if (tmp > 0) {
                ans++;
                tmp--;
            } else {
                tmp++;
            }
        }else{
            if(tmp>0)tmp--;
            else {
                tmp++;
                ans--;
            }
        }
    }
    pi(ans);
   return 0;
}

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

using namespace std;

#define MAX_N 100005

int N;
vector<int> Edge[MAX_N];

int dfs(int pos, int pre)
{
  int ret = 0;
  for (int i = 0; i < Edge[pos].size(); i++) {
    int next = Edge[pos][i];
    if(next == pre){
      continue;
    }
    ret ^= (dfs(next, pos) + 1);
  }

  return ret;
}

int main()
{
  cin >> N;
  for (int i = 0; i < N-1; i++) {
    int x, y; cin >> x >> y; x--; y--;
    Edge[x].push_back(y);
    Edge[y].push_back(x);
  }

  if(dfs(0, -1) == 0){
    cout << "Bob" << endl;
  }
  else{
    cout << "Alice" << endl;
  }

  return 0;
}


Measured memory_bytes: 11904
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();


		int ans = Integer.MIN_VALUE;
		if(X < 4) {
			System.out.println(1);
			return;
		}else {
			for(int i = 2; i <= X; i++) {
				int j = 2;
				int tmp = (int) Math.pow(i, j);
				while(tmp <= X) {
					j++;
					tmp = (int) Math.pow(i, j);
				}
				tmp = (int) Math.pow(i, j - 1);
				if(ans < tmp && j > 2) {
					ans = tmp;
				}
			}
			System.out.println(ans);
		}

	}

}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
long long int n, m, q, maxi = -1;
long long int a[60], b[60], c[60], d[60], niz[20];
void pro(long long int niz[])
{
	long long int i, ans = 0;
	for(i=0;i<q;i++)
	{
 		if((niz[b[i]-1]-niz[a[i]-1]) == c[i])
		ans+=d[i];
	}
 	maxi = max(ans, maxi);
}
void dfs(long long int idx, long long int s)
{
	if(idx == n)
	{
	pro(niz);
    return;
	}
	for(long long int i = s;i<=m;i++)
	{
	niz[idx] = i;
	dfs(idx+1, i);
    }
	
}
main()
{
	 cin >> n >> m >> q;
 	for(long long int i=0;i<q;i++)
	cin >> a[i] >> b[i] >> c[i] >> d[i];
dfs(0, 1);	
 cout << maxi << endl;
	return 0;
}

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

int a[110];

int main(void)
{
    int n;
    cin >> n;

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

    int cnt = 0;

    sort(a, a + n);
    reverse(a, a + n);

    int tmp = 0;

    for(int i = 0; i < n; i++)
    {
        if(a[i] == tmp) continue;
        cnt++;
        tmp = a[i];
    }

    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
var main = (input: string) => {
    let a: string[] = input.split(" ");
    let d: number = parseInt(a[0]);
    let t: number = parseInt(a[1]);
    let s: number = parseInt(a[2]);

    if (t * s >= d) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29656
#!/usr/bin/env python3

def main():
    c0 = [int(s) for s in input().split(' ')]
    c1 = [int(s) for s in input().split(' ')]
    c2 = [int(s) for s in input().split(' ')]

    if c0[0] + c1[1] == c0[1] + c1[0] \
    and c0[0] + c2[1] == c0[1] + c2[0] \
    and c0[0] + c1[2] == c0[2] + c1[0] \
    and c0[0] + c2[2] == c0[2] + c2[0]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=510;
struct edge{
	int v,atrb,nxt;
}g[N*N*2];
int tot=0,head[N];
inline void add(int u,int v,int x){
	g[++tot]=edge{v,x,head[u]}; head[u]=tot;
}
int n,a[N],b[N];
inline void init(){
	for(int i=0; i<=50; ++i)
		for(int j=1; j<=50; ++j)
			add(i,i%j,j);
}
bool mark[N]; bool vis[N];
inline int bfs(int s,int t,int f){
	memset(vis,0,sizeof(vis));
	queue <int> q; q.push(s); vis[s]=1;
	while(!q.empty()){
		int u=q.front(); q.pop(); if(u==t)return 1;
		for(int i=head[u]; i; i=g[i].nxt){
			int v=g[i].v,limit=g[i].atrb;
			if(limit>=f&&!mark[limit])continue;
			if(vis[v])continue;
			vis[v]=1; q.push(v);
		}
	}
	return 0;
}
int main(){
	init(); scanf("%d",&n);
	for(int i=1; i<=n; ++i)scanf("%d",&a[i]);
	for(int i=1; i<=n; ++i)scanf("%d",&b[i]);
	for(int i=1; i<=n; ++i)if(!bfs(a[i],b[i],51))return puts("-1"),0;
	LL ans=0;
	for(int i=50; i>=1; --i){
		bool flag=1;
		for(int j=1; j<=n; ++j)
			if(!bfs(a[j],b[j],i)){
				flag=0; break;
			}
		if(!flag)ans+=(1ll<<i),mark[i]=1;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,M,K,B,res=0,L[2005]={},Lsum[4005]={};


int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    cout<<N/3<<endl;
}    


Measured memory_bytes: 256
// Monsters Battle Royale

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int n;

int gcd( int m, int n ){
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	// ユークリッドの方法
	while(m != n){
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}

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

    sort(a.begin(), a.end());

    for (int i = 1; i < n; i++) {
        long tmp = a[i] % a[0];
        if (tmp == 0) {
            a[i] = a[0];
        } else {
            a[i] = tmp;
        }
    }

    // for (int i = 0; i < n; i++) {
    //     cout << a[i] << " ";
    // }
    // cout << endl;


    int tmp = a[0];
    for (int i = 1; i < n; i++) {
        tmp = gcd(tmp, a[i]);
    }

    cout << tmp << endl;

    return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.close();

        int a = N % 10;

        switch (a) {
            case 3:
                System.out.println("bon");
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                System.out.println("pon");
                break;
            default:
                System.out.println("hon");
        }
        return;

    }
}


Measured memory_bytes: 35780
a, b = map(int, input().split())

i = abs(b - a) #東側の塔が西から何番目か

hb = (i + 1) * (i // 2) if i % 2 == 0 else (i + 1) * (i // 2) + (i + 1) // 2
print(hb - b)


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

using namespace std;
string str1,str2;
int main(){
    cin >> str1 >> str2;
    for(int d = 0; d < str1.length(); d++){
        cout << str1[d];
        if(d < str2.length()){
            cout << str2[d];
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[] array = new int[n];
		for(int i=0;i < n;i++) {
			array[i] = sc.nextInt();
		}
		long answer =0;
		for(int i=0;i < n;i++) {
			if(i == n-1) {
				answer+=t;
				break;
			}
			if(array[i+1]-array[i] >t) {
				answer+=t;
			}else {
				answer+= array[i+1]-array[i];
			}
		}
		System.out.println(answer);
	}
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int l, r = N;
    l = max(0, (int)count(A.begin(), A.end(), 1)-1);
    while (r-l > 1) {
        int c = (3*l+r+2)/4;
        map<int, int> mp;
        for (int i = 1; i < N; i++) {
            if (A[i-1] >= A[i]) {
                if (c == 1) {
                    mp[0] = 1;
                    break;
                }
                int t = A[i];
                mp[t]++;
                auto it = mp.upper_bound(t);
                mp.erase(it, mp.end());
                while (t > 0 && mp[t] == c) {
                    mp[t] = 0;
                    mp[t-1]++;
                    t--;
                }
            }
            if (mp[0] > 0) break;
        }
        if (mp[0] == 0) r = c;
        else l = c;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1024
use std::io::Read;
use std::collections::HashSet;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    if n == 1 {
        return "a".to_string();
    }

    let alphabets = vec!['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];

    let mut prev: Vec<String> = vec!["a".to_string()];
    for i in 2..=n {
        let mut next: Vec<String> = Vec::new();
        for s in prev {
            let dim = s.chars().collect::<HashSet<char>>().len();
            for j in 0..(dim + 1) {
                next.push(format!("{}{}", s, alphabets[j]));
            }
        }
        prev = next;
    }

    let mut result = String::new();
    for s in prev {
        result.push_str(&format!("{}\n", s));
    }
    result.trim().to_string()
}


Measured memory_bytes: 8964
# B - Foods Loved by Everyone(ABC118)
N,M=map(int, input().split())
D=set()

for i in range(1,M+1):
    D.add(i)
    
for i in range(N):
    A=list(map(int, input().split()))
    B=D
    C=set(A[1:])
    D=C&B
print(len(D))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL ans;
int main(){
    LL n;
    cin>>n;
    for(LL i = 1;i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0)ans += i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int vis[N];
vector<int>G[N];
void dfs(int n){
    vis[n]=1;
    for(auto i:G[n]) {
    if(!vis[i]) dfs(i);
    }
}

int main(){
    int n,M,ans=0;cin>>n>>M;
    while(M--){
        int u,v;cin>>u>>v;

    G[u].push_back(v);
    G[v].push_back(u);
    }
    for(int i=1;i<=n;i++) {
        if (!vis[i]) {
            ans++;
        dfs(i);
    }
    }
    cout<<ans-1;
    return 0;
}


Measured memory_bytes: 9960
package main

import "fmt"

func main() {
        var n, ai int
        fmt.Scan(&n)

        a := map[int]int{}
        for i := 0; i < n; i++ {
                fmt.Scan(&ai)
                v, ok := a[ai]
                if ok {
                        v = v + 1
                        a[ai] = v
                } else {
                        a[ai] = 1
                }
        }

        v1 := 0
        v2 := 0
        for k, v := range a {
                if v1 < k && 2 <= v {
                        if v2 < v1 {
                                v2 = v1
                        }
                        v1 = k
                        v = v - 2
                }
                if v2 < k && 2 <= v {
                        v2 = k
                }
        }

        fmt.Printf("%d\n", v1*v2)
}


Measured memory_bytes: 7936
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

ll modpow(ll a, int p) {
	if (p == 0) return 1;
	if (p % 2 == 0) { //偶数
		int halfp = p / 2;
		ll half = modpow(a, halfp); //a^(1/2)
		return half * half % MOD;   //a^(1/2) * a^(1/2)
	}
	else { //奇数
		return a * modpow(a, p - 1) % MOD; //a * a^(p-1)
	}
}

ll calcComb(int a, int b) {
	if (b > a - b) return calcComb(a, a - b);
	ll ansMul = 1;
	ll ansDiv = 1;
	for (int i = 0; i < b; i++) {
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}

	ll ans = ansMul * modpow(ansDiv, MOD - 2) % MOD;
	return ans;
}

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

	int Mnokori = m;
	ll ans = 1;
	for (int i = 2; i * i <= Mnokori; i++) {
		if (Mnokori % i == 0) {
			int cnt = 0;
			while (Mnokori % i == 0) {
				cnt++;
				Mnokori /= i;
			}
			
			ans *= calcComb(n + cnt - 1, n - 1);
			ans %= MOD;
		}
	}
	if (Mnokori != 1) {
		ans *= calcComb(n + 1 - 1, n - 1);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

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

long long gcd(long long x, long long y) {
    if(y == 0) return x;
    return gcd(y,x%y);
}

long long lcm(long long x, long long y) {
    if(x == 0 || y == 0) return 0;
    return x / gcd(x,y) * y;
}

int main(){
    int n;
    cin >> n;
    long long t;
    long long ans = 1;
    for(int i = 0; i < n; i++){
        cin >> t;
        ans = lcm(ans,t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	string s;
	cin >> s;
	int ans = 0;
	rep(i, s.size()-1) if(s[i] != s[i+1]) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//int cnt[100];
//int cnt1[100];
int main () {
//ll t; cin>>t; while(t--)
int n; cin>>n;
if(n==1) cout<<0<<endl;
else cout<<1<<endl;
 
return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int n,k;
    cin>>n>>k;
    if((n+1)/2>=k)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, X = MAP()
if (A <= X <= (A + B)):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 27200
#include<stdio.h>
int A[50],n;
int suuki(int i ,int m)
{
	if(m==0) return 1;
	if(i>=n) return 0;
	int L=suuki(i+1,m)||suuki(i+1,m-A[i]);
	return L;
}
int main(){
	int i,m,q;
	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);
		if(suuki(0,m)) 
		printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

Measured memory_bytes: 1008
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

long long const MOD = 1000000007LL;

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

    vector<vector<int> > neightbor(n);
    
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;

        neightbor[a].push_back(b);
    }

    for (int i = 0; i < neightbor[0].size(); i++) {
        int now = neightbor[0].at(i);
        for (int j = 0; j < neightbor[now].size(); j++) {
            if (neightbor[now].at(j) == n - 1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[250000];
  cin >> s;
  int a,b;
  for(int i=0;i<strlen(s);i++){
    if(s[i]=='A'){a=i;break;}
  }
  for(int i=strlen(s)-1;i>-1;i--){
    if(s[i]=='Z'){b=i;break;}
  }
  cout << b-a+1;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int c[3][3];
int a[3], b[3];;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i=0;i<3;i++) {
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    for(int i=0;i<101;i++){
        a[0]=i;
        b[0]=c[0][0]-a[0];
        b[1]=c[0][1]-a[0];
        b[2]=c[0][2]-a[0];
        a[1]=c[1][0]-b[0];
        a[2]=c[2][0]-b[0];
        if(c[1][1]==a[1]+b[1]&&c[1][2]==a[1]+b[2]&&c[2][1]==a[2]+b[1]&&c[2][2]==a[2]+b[2]){
            yes;
            return 0;
        }
    }
    no;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 199999;
const int MAX = 2e5 + 10;

void solve() {
    int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
    //cin>>_;
    while (_--) {
        solve();
    }
    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  int n, tmp;
  cin >> n;

  double bunbo = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    bunbo += 1.0 / tmp;
  }

  cout << setprecision(15) << 1.0 / bunbo << endl;
  return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b&&b!=c || a!=b&&b==c || a==c&&b!=c)
	cout << "Yes" << endl;
    else
	cout << "No" << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
        double x1, y1, x2, y2, xq, yq;
        double th, th2;
        double tmpx, tmpy, xp, yp;

        while ( scanf( "%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq ) != EOF ) {
                th = atan2( y2-y1, x2-x1 );
                tmpx = xq-x1; tmpy = yq-y1;
                th2 = atan2( tmpy, tmpx );
                xp = tmpx*cos( -2*(th2-th) ) - tmpy*sin( -2*(th2-th) );
                yp = tmpx*sin( -2*(th2-th) ) + tmpy*cos( -2*(th2-th) );

                printf( "%.6lf %.6lf\n", xp+x1, yp+y1 );
        }
        return 0;
}



Measured memory_bytes: 2140
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt = 0;
    rep(i, n)if(s[i]=='R')cnt++;
    if(cnt > n/2)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
def iscyclic(n):
    l = [int(x) for x in list(str(n))]
    N = len(l)
    if N % 2 == 0:
        return False
    else:
        n = N / 2
        for i in range(0, n):
            a = l[i]
            b = l[N - (i + 1)]
            if a != b:
                return False
        return True


def cyclicnum(a, b):
    res = []
    for i in range(a, b + 1):
        if iscyclic(i):
            res.append(i)
    return res

A, B = map(int, raw_input().split(" "))

print len(cyclicnum(A, B))

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


signed main()
{
    
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int n, k; cin >> n >> k;
    vector<int> v(n), w(n);
    vector<vector<int> > dp(n+1, vector<int> (k+1, 0));
    for (int i=0; i<n; i++) {
        cin >> w[i] >> v[i];
    }

    for (int i=0; i<=n; i++) {
        for (int j=0; j<k+1; j++) {
            if (i==0 or j==0)
                continue;
            if (w[i-1] <= j)
                dp[i][j] = max(v[i-1]+dp[i-1][j-w[i-1]], dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }

    cout << dp[n][k];
    return 0;
}

Measured memory_bytes: 80256
N = input()
i_N = 0
for i in range(len(N)):
    i_N += int(N[i])
if len(N) == 1:
    print(N)
    exit()
ans = (len(N) - 1) * 9
if N[0] != '9':
    ans += int(N[0]) - 1
else:
    for i in range(1, len(N)):
        if N[i] != '9':
            ans += int(N[i - 1]) - 1
            break
    else:
        ans += 9
if ans > i_N:
    print(ans)
else:
    print(i_N)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <math.h>


#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
	long long result = 1;
	long long mod = 1000000007;	
	int prime_count[170] = {}; //素数の数が170未満なのでこれくらい
	int N = 1000; //までの素数を作る
	int n; //入力
	gets(n)
	int arr[N];
	vector<int> prime; //各素因数の数をカウントしておく
	for(int i = 0; i < N; i++){
		arr[i] = 1;
	}

	for(int i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for(int i = 2; i < N; i++){
		if(arr[i]){
			prime.push_back(i); //素数表作成
		}
	}

	FOR(i, 2, n+1){ //与えられた数まで
		int j = 0;
		int target = i;
		while(true){
			if (target < prime[0]){
				break;
			}
			if (target%prime[j] == 0){
				// cout << target << prime[j] << j << endl;
				prime_count[j] +=1;
				target /= prime[j];
				j = 0;
				continue;
			}
			j++;
		}
	}
	rep(i, sizeof(prime_count) / sizeof(prime_count[0]) ){
		if (prime_count[i]){
			result *= prime_count[i]+1;
			result %= mod;
		}
	}
	puts(result)
}


Measured memory_bytes: 384
program sample
implicit none
integer A,B,C,D
READ(*,*)A,B,C,D
10 CONTINUE
DO WHILE (C>0.and.A>0)
C=C-B
If (C<=0) then
   WRITE(*,*) "Yes"
END IF
A=A-D
IF(A<=0.AND.C>0) then
   WRITE(*,*) "No"
END IF
END DO
stop
end program sample

Measured memory_bytes: 2796
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    v a(n);in(a,n);
   	int ans=0;
    for(int i=1;i<n;i++)
    {
    	if(a[i] < a[i-1])
    	{
    		ans+=a[i-1]-a[i];
    		a[i]=a[i-1];
    	}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4780
n = int(input())
fully_ab = 0
last_a = 0
head_b = 0
head_last_both = 0

for i in range(n):
    s = input().rstrip()
    fully_ab +=s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        head_last_both += 1
    elif s[0] == "B":
        head_b += 1
    elif s[-1] == "A":
        last_a += 1
    
assert (last_a+head_b+head_last_both <= n)
bigger = max(last_a,head_b)
lower  = min(last_a,head_b)
amari = bigger - lower

connected = max(0,head_last_both - 1)

ans1 = fully_ab
ans2 = lower + connected

if (amari>0 or lower > 0) and head_last_both > 0:
    ans2 += 1
print(ans1+ans2)

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

typedef long long ll;
using namespace std;

void solve(){
    ll n;
    cin >> n;

    int ans = 0;
    if (n == 1) {
        cout << 0 << endl;
        return;
    }
    int prv = 0;
    int cnt = 0;
    while (n % 2 == 0) {
        n = n/2;
        cnt++;
        if (cnt == prv + 1) {
            prv = cnt;
            cnt = 0;
            ans++;
        }
    }


    for (int i = 3; i <= sqrt(n); i = i + 2) {
        prv = 0;
        cnt = 0;
        while (n % i == 0) {
            n = n/i;
            cnt++;
            if (cnt == prv + 1) {
                prv = cnt;
                cnt = 0;
                ans++;
            }
        }
    }

    if (n > 2) {
        ans++;
    }
    cout << ans << endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3656