akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

 class FS {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        return hasNextByte() ? buffer[ptr++] : -1;
    }

    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
        return (int) nextLong();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}
public class Main {
    static int[] pre;
    static int[] in;
static StringBuilder sb=new StringBuilder();
    public static void main(String[] args) {
        FS sc = new FS();
        int n = sc.nextInt();
        pre = new int[n];
        in = new int[n];
        for (int i = 0; i < n; i++) {
            pre[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            in[i] = sc.nextInt();
        }
        separate(0,n-1,0,n-1);
        sb.deleteCharAt(sb.length()-1);
        System.out.println(sb);
    }

    private static void separate(int i, int j,int i1,int j1) {
        if (i>j||i1>j1)return;
        sb.insert(0,pre[i]+" ");
        if (i==j||i1==j1)return;
        int start =i+1;
        int m=i1;
        while (in[m]!=pre[i]){
            m++;
        }
        int prelength =  m-i1;
        int postlength = j1 - m;
        separate(i+prelength+1,j,m+1,j1);
        separate(start,i+prelength,i1,m-1);
    }
}


Measured memory_bytes: 24416
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<algorithm>
using namespace std;

int main(){
	int x, y, z, b;
	float a;
	while(~scanf("%d %d %d", &x, &y, &z)){
		y + 2 * z <= x;
		a = (float)(x - z)/(y + z);
		b = a;
		printf("%d\n",b);
	}
	return 0;
}

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

using namespace std;
 
const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

struct poly {
    int P;
    vector<long long> a;
    poly(int P) : P(P), a(vector<long long>(P, 0ll)) { }

    int len() const {
        int res = 0;

        for (int i = 0; i < P; ++i)
            if (a[i] != 0)
                res = i + 1;

        return res;
    }

    long long& operator [](int i) { return a[i]; }
    const long long operator [](int i) const { return a[i]; }
};

poly operator *(const poly& a, const poly& b) {
    auto P = a.P;
    poly res(P);
    auto alen = a.len();
    auto blen = b.len();

    for (int i = 0; i < alen; ++i)
        for (int j = 0; j < blen; ++j)
            res[(i + j) % (P - 1)] += a[i] * b[j];

    for (int i = 0; i < P; ++i)
        if (res[i] >= P)
            res[i] %= P;

    return move(res);
}

int n;
int a[N];
vector<int> vec[2];

poly binpow(poly f, int n) {
    auto res = poly(f.P);
    res[0] = 1;

    for (; n > 0; n /= 2, f = f * f)
        if (n & 1)
            res = res * f;

    return move(res);
}
 
bool read() {
    if (!(cin >> n))
        return false;

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

    return true;
}

void solve() {
    for (int i = 1; i < n; ++i)
        vec[a[i] ^ a[0]].emplace_back(i);

    vector<poly> f(2, poly(n));

    for (int k = 0; k < 2; ++k) {
        f[k][0] = 1;

        for (auto x : vec[k]) {
            poly cur(n);
            cur[0] = (n - x) % n;
            cur[1] = 1;
            f[k] = f[k] * cur;
        }
    }

    ++f[1][0];
    auto res = binpow(f[0], n - 1) * f[1];
    res[n - 1] = res[0];
    res[0] = a[0];

    for (int i = 0; i < n; ++i)
        cout << (i > 0 && a[0] ? (n - res[i]) % n : res[i]) << ' ';

    cout << endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    while (read())
        solve();
 
    return 0;
}



Measured memory_bytes: 512
a = list(map(int,input().split()))
if a[0]>a[1]:
  X=a[0]
  a[0]-=1
else:
  X=a[1]
  a[1]-=1

if a[0]>a[1]:
  X+=a[0]
  a[0]-=1
else:
  X+=a[1]
  a[1]-=1

print(X)

Measured memory_bytes: 38384
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int main(){
    int N;cin>>N;
    int x[110],y[110],h[110];
    for(int i=0;i<N;i++)
        cin>>x[i]>>y[i]>>h[i];
    for(int Cx=0;Cx<=100;Cx++){
        for(int Cy=0;Cy<=100;Cy++){
            int n=0;
            while(h[n]==0)n++;
            int H=h[n]+abs(x[n]-Cx)+abs(y[n]-Cy);
            for(int k=0;k<n;k++){
                if(h[k]!=max(H-abs(x[k]-Cx)-abs(Cy-y[k]),0))
                    goto lol;
            }
            for(int k=n+1;k<N;k++){
                if(h[k]!=max(H-abs(x[k]-Cx)-abs(Cy-y[k]),0))
                    goto lol1;                
            }
            cout<<Cx<<" "<<Cy<<" "<<H<<endl;
            goto fin;
            
            lol:lol1:
            bool b;  
        }
    }
    fin:
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int p = sc.nextInt();
        int ans = (a * 3 + p) / 2;
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>

int main() {
  int A, B;
  std::cin >> A >> B;
  
  int cnt = 0;
  for (int num = A; num <= B; ++num) {
    std::stringstream ss;
    ss << num;
    
    std::string s = ss.str();
    std::string re = s;
    std::reverse(re.begin(), re.end());
    
    if (s == re) ++cnt;
  }
  std::cout << cnt << std::endl;
}

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

using namespace std;

typedef long long ll;
int main(void)
{
  ll X,Y;
  ll cnt =0;
  cin  >> X >>Y;
  for(;X<=Y;cnt++) {
    X*=2;
  }
  
  cout <<cnt<<endl;

    return 0;
}


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

#define all(a) (a).begin(), (a).end()

int main(){
	int a,b,c;
	cin>>a>>b>>c;

	if(a==b&&b==c){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


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

using namespace std;
const int N = 2e5+100;
struct node{
    long long a,b;
}s[N];
bool cmp(node a,node b){
    return a.a>b.a;
}
long long L[N],R[N];
long long minnore[N];//后缀最小的B
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>L[i]>>R[i];
    long long maxx=0;long long minn=1e18;
    int p,q;
    long long maxxlength=0;
    for(int i=1;i<=n;i++){
        if(L[i]>maxx){
            maxx=L[i];
            p=i;
        }
        if(R[i]<minn){
            q=i;
            minn=R[i];
        }
        maxxlength=max(maxxlength,R[i]-L[i]+1);
    }
    long long ans1=maxxlength+(minn>=maxx?minn-maxx+1:0);
    for(int i=1;i<=n;i++){
        s[i].a=max(R[i]-maxx+1,0LL);
        s[i].b=max(minn-L[i]+1,0LL);
    }
  //  for(int i=1;i<=n;i++) cout<<i<<' '<<s[i].a<<' '<<s[i].b<<endl;
    sort(s+1,s+n+1,cmp);
    minnore[n+1]=(1e18);
    for(int i=n;i>=1;i--) minnore[i]=min(minnore[i+1],s[i].b);
    long long ans2=0;
    for(int i=1;i<=n-1;i++){
        ans2=max(ans2,s[i].a+minnore[i+1]);
    }
    cout<<max(ans1,ans2)<<endl;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

ll conv(ll x,ll y) {
    ll n = y-x+1;
    if (n < 2) {
        return 1;
    } else {
        return n*(n-1) / 2;
    }
}

int main(void)
{
    IOS
    int n; cin >> n;
    vector<string> v(n);
    REP(i,n)  {
        cin >> v[i];
        sort(ALL(v[i]));
    }
    
    sort(ALL(v));
    ll ans = 0;
    int l = 0;
    int r = 0;

    FOR(i,1,n) {
        if (v[i-1] == v[i]) {
            r = i;
        } else {
            if (l != r) {
                ans += conv(l,r);
            }
            l = i;
            r = i;
        }
    }
    if (l != r) ans += conv(l,r);

    cout << ans << endl;


    return 0;
}

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


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
    //mint(2).pow(n); 2^n
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

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

double dp[305][305][305];  int n;


double f(int c1,int c2, int c3){
  if (dp[c1][c2][c3]!=double(-1))return dp[c1][c2][c3];
  double temp=0;
  double c0=n-c1-c2-c3;
  if (c1>0)temp+=f(c1-1,c2,c3)*c1/n;
  if (c2>0)temp+=f(c1+1,c2-1,c3)*c2/n;
  if (c3>0)temp+=f(c1,c2+1,c3-1)*c3/n;
  temp+=1;
  temp/=double(1-c0/n);
  dp[c1][c2][c3]=temp;
//  cout<<temp<<" "<<c1<<" "<<c2<<" "<<c3<<endl;
return dp[c1][c2][c3];

}


int main(){
  cin>>n;
  vector<ll> a(n);
  vector<ll> c(4,0);

  rep(i,n){
    cin>>a[i];
    c[a[i]]++;
  }
  rep(i,305)rep(j,305)rep(k,305)dp[i][j][k]=double(-1);
  dp[0][0][0]=double(0);

  f(c[1],c[2],c[3]);
  cout<<setprecision(10)<<dp[c[1]][c[2]][c[3]];

}


Measured memory_bytes: 225504
#include <iostream>
using namespace std;
int main(){
	int N, W;
	cin >> N >> W;
	int v[N], w[N], dp[N+1][W+1];
	for (int i = 0; i < N; ++i){
		cin >> v[i] >> w[i];
	}
	for (int i = 0; i < N+1; ++i){
		for (int j = 0; j < W+1; ++j){
			dp[i][j] = 0;
		}
	}
	for (int i = 0; i < N; ++i){
		for (int j = 0; j < W+1; ++j){
			dp[i+1][j] = dp[i][j];
			if (j) dp[i+1][j] = max(dp[i][j], dp[i+1][j-1]);
			else dp[i+1][j] = dp[i][j];
			if (j >= w[i]) dp[i+1][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

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

#define I cin
#define O cout
#define EN endl
#define ln cout<<endl
#define pb(a) push_back(a)

typedef long long int llint;

int n;
int i, j;
llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

int main()
{
  I >> n;

  map<int, bool> m;
  
  for(i = 0; i < n; i++) {
    int a;
    I >> a;

    if(!m[a]) {
      m[a] = true;
      cnt++;
    } else {
      m[a] = false;
      cnt--;
    }
  }

  O << cnt << EN;
  
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    ll n;cin>>n;
    string s;cin>>s;
    ll ans=0;
    rep(i,0,n-3){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            ans++;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main () {
    int cnt = 0;
    char A[3];

    cin >> A[0] >> A[1] >> A[2];

    for (int i = 0; i < 3; i++) {
        if (A[i] == 'o') cnt++;
    }

    cout << 700 + cnt * 100 << endl;
}

Measured memory_bytes: 256
# import fractions
# import sys
from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
a = [int(stdin.readline().rstrip()) for i in range(m)]
oks = []
mod = 1e+9 + 7
for i in range(n + 1):
    oks.append(True)
for ai in a:
    oks[ai] = False
dp = [0] * (n + 1)
dp[0] = 1
for now in range(n):
    for next in range(now + 1, min(n, now + 2) + 1):
        if oks[next]:
            dp[next] += dp[now]
            dp[next] %= mod

print(int(dp[n]))


Measured memory_bytes: 8604
require 'set'

def inputInts
    gets.chomp.split().map(&:to_i)
end

N, M = inputInts
from1 = Set.new
toN = Set.new

M.times do
    islands = inputInts
    islands.sort!
    if islands[0] == 1
        from1 << islands[1]
    elsif islands[1] == N
        toN << islands[0]
    end
end

if (from1 & toN).length > 0
    puts "POSSIBLE"
else
    puts "IMPOSSIBLE"
end

Measured memory_bytes: 14844
import java.util.*;
import java.math.*;
class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt();
        int arr[] =new int[n];
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
            long curr = 1000;
            int i=0;
            // int stock =0;
            long max = 1000;
            // boolean flag = false;
            for(i=0;i<n-1;i++)
            {
                if(arr[i+1]<=arr[i])
                {
                    continue;
                }
                else
                {
                    long stock = curr/arr[i];
                    curr %=arr[i];
                    curr +=arr[i+1]*stock ;
                }
            }
            System.out.println(curr);
    }
}

Measured memory_bytes: 36136
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()

# int(input())
# map(int, input().split())

n = int(input())
d = tuple(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += d[i] * d[j]
print(ans)


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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(red);
	get(green);
	get(blue);

	get(k);

	// k operations, and we have to make them greater
	int count = 0 ;

	while(green <= red)
	{
		
		green = 2*green;
		count++;
		if(count > k)
		{
			cout << "No" << endl;
			return 0;
		}
	}	

	// cout << green << " " << red << " " << count << endl;

	// now that we are here, we know that green more than red condidiotn worked

	while(blue <= green)
	{
		blue = 2*blue;
		count++;
		if(count > k)
		{
			cout << "No" << endl;
			return 0;
		}
	}


	// cout << blue << " " << green << " " << count << endl;

	// I reached ehre
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main(){

	int a, b, c;
	int A[10000] = { 0 };
	int M;
	int N = 0;

	cin >> a >> b >> c;

	for (int i = 0; i <= b - a; i++){
		A[i] = a + i;

		M = c%A[i];
		if (M == 0){
			N = N + 1;
		}
	}

	cout << N << endl;

	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
using namespace std;
 //for study
int n, a[100005];
string s;
int main() {
	int i, k;
	cin>>s;
	n = s.size();
	for(i=0; i<n; i++) {
		if(s[i]=='R') k = i;
		else a[k + (i-k)%2]++;
	}
	for(i=n-1; i>=0; i--) {
		if(s[i]=='L') k = i;
		else a[k - (k-i)%2]++;
	}
	for(i=0; i<n; i++) printf("%d ", a[i]);
	return 0;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdint>
using namespace std;
using i64 = int64_t;

int main(void){
    i64 x, k;
    cin >> x >> k;
    if(x>k) x = x-(x-1)/k*k;
    if(k-x<x) x = k-x;
    cout << x << '\n';
    return 0;
}

Measured memory_bytes: 3600
import sys
li = ["dream","dreamer","erase","eraser"]
li = [s[::-1] for s in li]
sen = input()[::-1]
while 1:
  ju = 0
  for i in range(4):
    le = len(li[i])
    if sen[:le] == li[i]:
      if len(sen) == le:
        print("YES")
        sys.exit()
      else:
        sen = sen[le:]
        ju = 1
  if not ju:
    print("NO")
    sys.exit()
	


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

int main() {
  int N, M, sum = 0;
  cin >> N;
  M = N;
  while (M >= 1){
    sum += M%10;
    M /= 10;
  }
  if (N%sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl; 
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    set<int> s;
    rep(i, n)
    {
        if (s.count(a[i]))
        {
            cout << "NO" << endl;
            return 0;
        }
        s.insert(a[i]);
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 13536
#include <bits/stdc++.h>
using namespace std;
int p[100005];
int sim[100005];
int sum[100005];
int q;
int main() {
	memset(p, 1, sizeof p);
	p[0] = p[1] = 0;
	for (int i = 2; i * i <= 100000; ++ i) {
		if (p[i])
		for (int j = i * i; j <= 100000; j += i) {
			p[j] = 0;
		}
	}
	for (int i = 3; i <= 100000; i += 2) {
		if (p[i] && p[(i + 1) / 2]) sim[i] = 1;
	}
	for (int i = 1; i <= 100000; ++ i) sum[i] = sum[i - 1] + sim[i];
	scanf("%d", &q);
	for (; q; -- q) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", sum[r] - sum[l - 1]);
	}
	return 0;
}


Measured memory_bytes: 1792
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = int.Parse(_[0]);
            var b = int.Parse(_[1]);
            var c = int.Parse(_[2]);
            var d = int.Parse(_[3]);

            if(Math.Abs(c - a) <= d){
                Console.WriteLine("Yes");
            }else if(Math.Abs(c- b) <= d && Math.Abs(b - a) <= d){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
/*
[abc103] A - Task Scheduling Problem
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 3;

int a[3];

ll solve() {
    sort(a, a + MAX_N);
    return a[2] - a[0];
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = INT()
ans = 0

for A in range(1, N):
    for B in range(1, N // A + 1):
        if N - A * B < 1:
            break
        ans += 1
    
print(ans)

Measured memory_bytes: 67584
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int main(){
  long long X;
  long long res = 0;
  rd(X);
  res += 1000 * (X / 500);
  X %= 500;
  res += 5 * (X / 5);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200322-1 [beta]

// --- original code ---
// {
//   ll X, res = 0;
//   rd(X);
//   res += 1000 * (X / 500);
//   X %= 500;
//   res += 5 * (X / 5);
//   wt(res);
// }


Measured memory_bytes: 256
x, n = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    a = [i for i in range(102)]
    for i in range(n):
        a[p[i]] = 1000
    minimum = 1000
    result = 1000
    for i in reversed(range(102)):
        if a[i] != 1000:
            if minimum >= abs(x - a[i]):
                minimum = abs(x - a[i])
                result = a[i]

    print(result)


Measured memory_bytes: 61956
object Main extends App {
	val N = scala.io.StdIn.readInt
	val K = scala.io.StdIn.readInt

	var t = 1

	for(i<-0 until N){
		if(2*t > t+K){
			t = t+K;
		}else{
			t = 2*t;
		}
	}

	println(t);
}


Measured memory_bytes: 25628
n = int(input())
s = input()
result = []
if len(set(s)) == 1:
  print(1)
else:
  for i in range(n):
    tmp = 0
    for k in set(s[:i]):
      if k in s[i:]:
        tmp += 1
    result.append(tmp)
  print(max(result))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=100005;
int n;
vector<pair<int,int> > v[MAXN];
int color[MAXN];

void dfs(int no,int father){
	for (int i=0;i<v[no].size();i++){
		int u=v[no][i].first;
		int w=v[no][i].second%2;
		if (u!=father){
			color[u]=color[no]^w;
			dfs(u,no);
		}
	}
}
int main()

{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<n;i++){
		int u,vv,c;
		cin>>u>>vv>>c;
		v[u].push_back({vv,c});
		v[vv].push_back({u,c});
	}

	dfs(1,-1);

	for (int i=1;i<=n;i++){
		cout<<color[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9216
#!/mnt/c/Users/moiki/bash/env/bin/python
N,H,W = list(map(int, input().split()))

hw = []
cnt = 0
for i in range(N):
    h,w = list(map(int, input().split()))
    # hw.append(tmp)
    # print("\nh, w: ", h, ", ", w)
    if h >= H and w >= W:
        # print("h, w:", h, w)
        # print("\thw: ", h,w)
        # print("\tcnt = ",  min(H//h, W//w))
        # print("\ta = ", H//h, W//w, "H: {}, W:{}, h:{}, w:{}".format(H,W,h,w))
        cnt += min(h//H, w//W)

# print(N,H,W)
# print(hw)
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


using pll = pair<long long, long long>;
int N;
vector<long long> x, y;
set<pll> se;

long long solve() {
    se.clear();
    for (int i = 0; i < N; ++i) se.insert(pll(x[i], y[i]));

    long long res = N;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (i == j) continue;
            long long dx = x[j] - x[i], dy = y[j] - y[i];

            long long tmp = N;
            for (int i = 0; i < N; ++i) {
                if (se.count(pll(x[i] + dx, y[i] + dy))) --tmp;
            }
            chmin(res, tmp);
        }
    }
    return res;
}

int main() {
    while (cin >> N) {
        x.resize(N); y.resize(N);
        for (int i = 0; i < N; ++i) cin >> x[i] >> y[i];
        cout << solve() << endl;
    }
}
                                        



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

int A[20][20];
int B[20];

int main(void) {
  int N, M, C;
  cin >> N >> M >> C;
  for(int i = 0; i < M; ++i){
  	cin >> B[i];
  }
  for(int i = 0; i < N; ++i){
  	for(int j = 0; j < M; ++j){
    	cin >> A[i][j];
    }
  }
  int ans = 0;
  for(int i = 0; i < N; ++i){
    	int sum = 0;
    for(int j = 0; j < M; ++j){
      	sum += A[i][j] * B[j];
    }
    if(sum + C > 0)++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define pb push_back
#define vi vector<int>
#define translow transform(s.begin(),s.end(),s.begin(),::tolower);
#define transup transform(s.begin(),s.end(),s.begin(),::toupper);
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;
double dist(ll x1,ll y1,ll x2,ll y2)
{
	double ans=0;
	ans=sqrt(pow(abs(x1-x2),2)+pow(abs(y1-y2),2));
	return ans;
}

int main() {
				fast
				ll n;
				cin>>n;
				ll x[n],y[n];
				for(ll i=0;i<n;i++)
				{
					cin>>x[i]>>y[i];
				}
				string s="";
				for(ll i=0;i<n;i++)
				s+=i+'0';
				double ans=0;
			//	cout<<dist(3,7,0,1)<<endl;
				//cout<<s<<endl;
				ll count=0;
				do { 
				
                    for(ll i=0;i<n-1;i++)
                    {
                    	//cout<<s<<endl;
                    	ans+=dist(x[s[i]-'0'],y[s[i]-'0'],x[s[(i+1)]-'0'],y[s[(i+1)]-'0']);
                    	//cout<<x[s[i]-'0']<<endl;
                    	//cout<<ans<<endl;
					}
                    //cout<<s<<endl;
                    
                    count++;
                    } while (next_permutation(s.begin(), s.end())); 
                    cout<<fixed<<setprecision(10)<<ans/count;
				
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

bool cmp(pii x, pii y) {
	return x.second < y.second;
}

int main() {
	ll x, y;
	cin >> x >> y;
	ll ans = 0;
	while (y >= x) {
		x *= 2;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main(){
 
    unsigned long long a,b,c,d;
 
    while(cin>>a>>b){
        c=a;
        d=b;
        while(1){
            if(c>d)c=c-d;
            if(c<d)d=d-c;
            if(c==d){
                cout<<c<<" "<<a*b/c<<endl;
                ;break;}
        }}
         
 
 
return 0;
}

Measured memory_bytes: 1152
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int H, W;
char board[510][510];
char ans_a[510][510], ans_b[510][510];

signed main() {
    cin >> H >> W;
    rep(i,0,H) rep(j,0,W) {
        cin >> board[i][j];
        ans_a[i][j] = ans_b[i][j] = '.';
    }

    rep(i,0,H) rep(j,0,W) {
        if(i == 0)   ans_a[i][j] = '#';
        if(i == H-1) ans_b[i][j] = '#';
        if(j%2 == 0 && i != H-1) ans_a[i][j] = '#';
        if(j%2 == 1 && i != 0  ) ans_b[i][j] = '#';
        if(board[i][j] == '#') ans_a[i][j] = '#', ans_b[i][j] = '#';
    }

    rep(i,0,H) {
        rep(j,0,W) cout << ans_a[i][j];
        cout << endl;
    }
    cout << endl;
    rep(i,0,H) {
        rep(j,0,W) cout << ans_b[i][j];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(10**6)

n=int(input())
g=[set() for _ in range(n*(n-1)//2+1)]
visit=[0]*(n*(n-1)//2+1)
d=[0]*(n*(n-1)//2+1)

for i in range(1,n+1):
    last=0
    for j in list(map(int,input().split())):
        mi,ma=(min(i-1,j-1),max(i-1,j-1))
        current=ma*(ma-1)//2+mi+1
        g[last].add(current)
        last=current

def dfs(u):
    if visit[u]==2:
        return d[u]
    
    ans=0
    visit[u]=1
    for v in g[u]:
        if visit[v]==1:
            print(-1)
            exit(0)
        
        d[u]=max(d[u],1+dfs(v))
    
    visit[u]=2
    return d[u]

print(dfs(0))

Measured memory_bytes: 261524
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

signed main()
{
	int ans = 0;
	REP(i, 5)
	{
		int x;
		cin >> x;
		if (x == 0)
		{
			ans = i + 1;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int MAXS = 114514;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n,k;
    cin>>n>>k;
    set<int> D;
    bool ban[11];
    for(int i=0;i<11;i++)ban[i]=false;
    for(int i=0;i<k;i++){
        int x;
        cin>>x;
        ban[x]=true;
    }
    for(int i=n;i<=MAXS;i++){
        string s = to_string(i);
        bool flag = true;
        for(int j=0;j<s.size();j++){
            int k = s[j]-'0';
            if(ban[k])flag=false;
        }
        if(flag){
            cout<<i<<endl;
            return 0;
        }
    }
}

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

typedef unsigned long long ull;
typedef long long ll;

double pi = 3.14159265358979323846;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	
	int r;
	cin >> r;
	
	cout << 2 * pi * r << endl;
	
	
	return 0;
}


Measured memory_bytes: 3828
import sys
 
def main():
    for line in iter(sys.stdin.readline, ""):
        a = line.rstrip("\n").split(" ")
        b = []
        b.append(int(a[0]))
        b.append(int(a[1]))
        if (b[0] == 0 and b[1] == 0):
            return
 
        print(str(min(b)) + " " + str(max(b)))
      
if __name__ == "__main__":
    main()

Measured memory_bytes: 7836
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

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

int n, m, N;
vector<string> fi;

pint pl[11];
int dist[1100][1100];

int solve(pint p, pint q) {
    memset(dist, -1, sizeof(dist));
    dist[p.first][p.second] = 0;
    queue<pint> que;
    que.push(p);
    
    while (!que.empty()) {
        pint now = que.front(); que.pop();
        if (now == q) break;
        for (int i = 0; i < 4; ++i) {
            int ni = now.first + dx[i], nj = now.second + dy[i];
            if (ni < 0 || ni >= n || nj < 0 || nj >= m) continue;
            if (fi[ni][nj] == 'X') continue;
            if (dist[ni][nj] == -1) {
                dist[ni][nj] = dist[now.first][now.second] + 1;
                que.push( pint(ni, nj) );
            }
        }
    }
    
    return dist[q.first][q.second];
}

int main() {
    while (cin >> n >> m >> N) {
        fi.resize(n);
        for (int i = 0; i < n; ++i) cin >> fi[i];
        
        for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
            if (fi[i][j] == 'S') pl[0] = pint(i, j);
            else if (fi[i][j] != '.' && fi[i][j] != 'X') pl[fi[i][j] - '0'] = pint(i, j);
        }
        
        int res = 0;
        for (int i = 0; i < N; ++i) res += solve(pl[i], pl[i+1]);
        
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 7008
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;cin >> N;
    int a=0,b=0,ab=0,res=0;
    rep(i,N){
        string s;
        cin >> s;
        int len = s.size();
        for(int i=0;i<len-2;i++){
            if(s.substr(i,2)=="AB")res++;
        }
        if(s[0]=='B'&&s[len-1]=='A')ab++;
        else if(s[len-1]=='A')a++;
        else if(s[0]=='B')b++;
    }
    if(ab>0){
        res+=ab-1;
        if(a>0){
            a--;
            res++;
        }
        if(b>0){
            b--;
            res++;
        }
    }
    res+=min(a,b);


    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 998244353

int main() {
	int n;
	cin >> n;
	int ret = 0;
	REP(i, n + 1) {
		if (i % 2 == 0)continue;
		int cnt = 0;
		FOR(j, 1,i + 1) {
			if (i%j == 0)cnt++;
		}
		if (cnt == 8)ret++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
l = m // n
ans = 0
for i in range(int(m**0.5),0,-1):
  if m % i == 0 and m // i >= n:
    if i > ans: ans = i
    d = m // i
    if  m // d >= n and d > ans: ans = d
print(ans)

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

int main() {
    char n;
    for (int i = 0; i < 2; i++){
        cin >> n;
        if (n == '9'){
            cout << "Yes" << endl;
            break;
        }
        else if (i == 1){
            cout << "No" <<endl;
        }
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//MIN

bool p_judge(ll p) {

	if (p == 1)return false;
	else if (p == 2)return true;
	else {

		bool flag = true;
		for (int i = 2; i <= sqrt(p); i++) {

			if (p%i == 0) {

				flag = false;
				break;

			}

		}
		return flag;

	}

}
//素数判定,素数=true,合成数=false

int main() {

	int N;
	vector<ll> A;

	cin >> N;
	for (int i = 0; i < N; i++) {

		int tmp;
		cin >> tmp;
		A.push_back(tmp);

	}
	sort(A.begin(), A.end());

	for (int i = 0; i < N; i++) {

		if (A[i] >= A[N - 1] / 2) {

			if (i == 0)cout << A[N - 1] << SPACE << A[0] << endl;
			else {

				if (abs(A[i - 1] * 2 - A[N - 1]) > abs(A[i] * 2 - A[N - 1])) {

					cout << A[N - 1] << SPACE << A[i] << endl;

				}
				else {
					cout << A[N - 1] << SPACE << A[i - 1] << endl;

				}

			}
			break;

		}

	}

	return 0;
}

Measured memory_bytes: 1400
from collections import defaultdict

H, W, N = map(int,input().split())
d = defaultdict(int)
ta = [1,1,0,-1,-1,-1,0,1,0]
tb = [0,1,1,1,0,-1,-1,-1,0]

for _ in range(N):
    a, b = map(int,input().split())
    for i in range(9):
        na = a + ta[i]
        nb = b + tb[i]
        if 1 <= na <= H and 1 <= nb <= W:
            d[(na, nb)] += 1

ans = [0] * 10

for i, v in d.items():
    if 2 <= i[0] <= H-1 and 2 <= i[1] <= W-1:
        ans[v] += 1

ans[0] = (H-2) * (W-2) - sum(ans)

for i in range(10):
    print(ans[i])

Measured memory_bytes: 166860
D,N = map(int,input().split())
T = [ int(input()) for i in range(D) ]
clothes = []
for _ in range(N):
  a,b,c = map(int,input().split())
  clothes.append([a,b,c])

# i日目に服jを来た時の、派手さの絶対値
dp = [ [-1]*(N) for _ in range(D+1) ]
dp[0][0] = 0

for j in range(N):
  a,b,c = clothes[j]
  if a <= T[0] <= b:
    dp[1][j] = c

for i in range(2, D+1):
  for j in range(N):
    a,b,c = clothes[j]
    if a <= T[i-1] <= b:
      for k in range(N):
        if dp[i-1][k] > -1:
          prev_c = clothes[k][2]
          if i > 2:
            dp[i][j] = max(dp[i][j], dp[i-1][k]+abs(prev_c-c))
          else:
            dp[i][j] = max(dp[i][j], abs(prev_c-c))

print(max(dp[-1]))


Measured memory_bytes: 6172