akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, p[100000], q[100000];

int main() {
	cin >> n;
	inc(i, n) { cin >> p[i]; p[i]--; }
	
	inc(i, n) { q[p[i]] = i; }
	
	multiset<int> ms;
	ms.insert(-1);
	ms.insert(-1);
	ms.insert(n);
	ms.insert(n);
	
	LL ans = 0;
	dec(i, n) {
		ms.insert(q[i]);
		auto c = ms.lower_bound(q[i]);
		auto a = c;
		auto b = c;
		auto d = c;
		auto e = c;
		--a; --a;
		--b;
		++d;
		++e; ++e;
		LL A = * a;
		LL B = * b;
		LL C = * c;
		LL D = * d;
		LL E = * e;
		ans += ((D - C) * (B - A) + (E - D) * (C - B)) * (i + 1);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
  ll N,A,B; cin>>N>>A>>B;
  if(N<A+B-1||N>A*B){
    cout<<-1<<endl;
    return 0;
  }
  int s=1, rest=N,loop=B;
  rep(i,A){
    vector<int> tmp;
    rep(j,loop) tmp.push_back(s++);
    int n=tmp.size();
    rep(j,n) cout<<tmp[n-1-j]<<" ";
    rest-=loop;
    if(rest-(A-(i+1))<B){
      loop=rest-(A-(i+1))+1;
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 2492
#include <iostream>
#include <stack>
#include <cstdlib>
using namespace std;
int main() {
	const int  n =100;
	stack<int> i;
	char s[n];
	int a, b;
	while (cin >> s) {
		if (s[0] == '+') {
			a = i.top(); i.pop();
			b = i.top(); i.pop();
			i.push(a + b);
		}
		else if (s[0] == '-') {
			a = i.top(); i.pop();
			b = i.top(); i.pop();
			i.push(b - a);
		}
		else if (s[0] == '*') {
			a = i.top(); i.pop();
			b = i.top(); i.pop();
			i.push(a*b);
		}
		else i.push(atoi(s));

	}
	cout << i.top() << endl;
	return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  vector<vector<int>> s(m);
  rep(i,m){
    int k;cin>>k;
    rep(j,k){
      int a;cin>>a;
      a--;
      s[i].push_back(a);
    }
  }
  vector<int> p(m);
  rep(i,m)cin>>p[i];
  ll ans=0;
  rep(bit,1<<n){
    bool ok=true;
    rep(i,m){
      int cnt=0;
      for(auto x:s[i]){
        if(bit&(1<<x))cnt++;
      }
      if(cnt%2!=p[i])ok=false;
    }
    if(ok)ans++;
  }
  cout<<ans<<endl;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int i = 0, f = 0, p = 0;
    while(i < s.size()) {
        if (s[i] == '(') f++;
        else {
            f--;
            if (f < 0) {
                int j = i;
                string l = "";
                while(j < s.size() && s[j] == ')') l += "(", j++;
                s = l + s;
                i = j + l.size() - 1;
                f = 0;
            }
        }
        i++;
    }
    rep(j, f) s += ")";
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
    using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n" 
typedef long long ll;
typedef unsigned long long ull ;
typedef double dll ;
const ll inf = (ll)(1e5);
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
   ll n, W;
   cin >> n >> W;
   ll ans[n+1][W+1] = {{inf}};
   vector< ll > v(n+1, 0), w(n+1, 0); 
   for(ll i = 1; i <= n; i++) {
     cin >> w[i] >> v[i];
   }
   for(ll i = 0; i <=n; i++) {
   	for(ll j = 0; j <= W; j++) {
   		if( i == 0 or j == 0) ans[i][j] = 0;
   		else
   		if(w[i] <= j) {
   			ans[i][j] = max(v[i]+ans[i-1][j-w[i]], ans[i-1][j]);
   		}
   		else {
   			ans[i][j] = ans[i-1][j];
   		}
   	}
   }
   cout << ans[n][W] << endl;
  
  return 0;
} //good night.

Measured memory_bytes: 79232
fn concent(w: usize, s: usize) -> f64 {
    if w == 0 {
        0.0
    } else {
        s as f64 / w as f64
    }
}

fn main() {
    let (a, b, c, d, e, f) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        let v: Vec<usize> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
        (v[0], v[1], v[2], v[3], v[4], v[5])
    };

    let mut water = vec![false; f + 1];
    let mut sugar = vec![false; f + 1];

    for i in 0..f / (a * 100) + 1 {
        for j in 0..(f - a * i * 100) / (b * 100) + 1 {
            let x = a * i + b * j;
            water[x] = true;
        }
    }

    for i in 0..f / c + 1 {
        for j in 0..(f - c * i) / d + 1 {
            let x = c * i + d * j;
            sugar[x] = true;
        }
    }

    let mut ans_water = a;
    let mut ans_sugar = 0;
    for w in 0..f + 1 {
        if !water[w] {
            continue;
        }
        for s in 0..f - w + 1 {
            if !sugar[s] {
                continue;
            }
            if w * 100 + s > f {
                continue;
            }

            let c = concent(w, s);
            if c <= e as f64 && c > concent(ans_water, ans_sugar) {
                ans_water = w;
                ans_sugar = s;
            }
        }
    }

    println!("{} {}", ans_sugar + ans_water * 100, ans_sugar);
}


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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int a,b;
    cin>>a>>b;
    int ans = a+b;
    if (ans >= 10) cout << "error" << endl;
    else cout << ans <<endl;
    
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int rect[2], area, len;
    scanf("%d%d", &rect[0], &rect[1]);
    area = rect[0] * rect[1];
    len = rect[0] + rect[0] + rect[1] + rect[1];
    printf("%d %d\n", area, len);
    return 0;
}


Measured memory_bytes: 2036
#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! get_chars {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect::<Vec<_>>()
        }
    };
    ($n:expr) => {
        {
            (0..$n)
                .map(|_| get_chars!())
                .collect::<Vec<_>>()
        }
    };
}

fn main() {
    let s = get!(String);
    let t = get!(String);

    if s.len() + 1 == t.len() {
        if t.starts_with(&s) {
            println!("Yes");
            std::process::exit(0);
        }
    }
    println!("No");
}


Measured memory_bytes: 2084
#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>
 
 
using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;

typedef vector<ii> vii;
//#define int long long 


signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);

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

   	sort(a , a + n );

   	int ans =0 ;

   	for(int i=0;i<n;i++)
   	{
   		for(int j=i+1;j<n;j++)
   		{
   			int k = j+1;
   			while( k < n && a[i]+a[j] > a[k])
   				k++;
   			//cout<<k _ j<<endl;
   			ans += k - j -1;
   		}
   	}

   	cout<<ans;
    
}
    




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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    int a, b, c[13] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
    cin >> a >> b;
    cout << (c[a] == c[b] ? "Yes" : "No");
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3596
N = int(input())
SP = [[str(i) for i in input().split()]for j in range(N)]
for i in range(N):
    SP[i][1] = int(SP[i][1])

DP = sorted(SP, key=lambda x: (x[0], -x[1]), reverse=False)
for j in DP:
    for c, i in enumerate(SP):
        if i == j:
            print(c+1)

Measured memory_bytes: 3060
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    n = len(s)

    ans = 0
    for i in range(n // 2):
        if s[i] != s[n - i - 1]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include <vector>
#define INF (1<<30)
#define ll long long
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, M; cin >> N >> M;
	vector<ll> D(N), C(M);
	for (int i = 0; i < N;i++) cin >> D[i];
	for (int i = 0; i < M;i++) cin >> C[i];

	vector<vector<ll>> dp(M + 1, vector<ll>(N + 1, INF));
	dp[0][0] = 0;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			dp[i + 1][j + 1] = min(dp[i][j+1], dp[i][j] + C[i] * D[j]);
		}
	}

	cout << dp[M][N] << endl;
}

Measured memory_bytes: 9124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
//#include <stdio.h>

using namespace std;

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

    int A;
    int B;
    int C;

    cin >> A >> B >> C;

    if(B / A >= C){
        cout << C;
    }else{
        cout << B / A;
    }

}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <cstdint>
#include <cstring>

using namespace std;

//#define DEBUG

//2019-08-18 C
int main()
{
	long long int n;
	cin >> n;

#ifdef DEBUG
	cout << n << endl;
#endif

	long long int *v;
	v = new long long int[n];

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

#ifdef DEBUG
	for (int i = 0; i < n; i++){
		cout << v[i] << endl;
	}
#endif

	//if (n == 2){
	//	cout << (v[0] + v[1]) / 2 << endl;
	//}

	sort(v, v + n);

#ifdef DEBUG
	for (int i = 0; i < n; i++){
		cout << v[i] << endl;
	}
#endif

	double ans = v[0];

	for (int i = 1; i < n; i++){
		ans = (ans + v[i]) / 2.0;
	}

	cout << ans << endl;

#ifdef DEBUG
	system("pause");
#endif
	return 0;
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int h,w;
  int a,b;
  cin >> h >> w >> a >> b;
  cout << (h - a ) * (w - b);

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct Card{
    char suit;
    int val;
} Card;

void structCpy(Card A[], Card B[], int n){
    for(int i=0; i<n; i++){
        A[i].suit = B[i].suit;
        A[i].val = B[i].val;
    }
}

void structSwap(Card* A, Card* B){
    Card tmp = *A;
    *A = *B;
    *B = tmp;
}

void BubbleSort(Card A[], int n){
    for(int i=0; i<n-1; i++){
        for(int j=n-1; j>i; j--){
            if(A[j].val < A[j-1].val)
                structSwap(A+j-1,A+j);
        }
    }    
}

void SelectionSort(Card A[], int n){
    for(int i=0; i<n; i++){
        int min = i;
        for(int j=i; j<n; j++){
            if(A[min].val > A[j].val)
                min = j;
        }
        structSwap(A+i,A+min);
    }
}

// A is the sorted array 
// B is the original array
bool stableTest(Card A[], Card B[], int n){
    int countA = 0;
    while(countA < n-1){
        if(A[countA].val == A[countA+1].val){
            int countRan = countA;
            while(A[countRan].val == A[countRan+1].val && countRan < n-1)
                countRan++;
            int countB = 0;
            while(countRan - countA >= 0){
                if(B[countB].val == A[countA].val){
                    if(B[countB].suit != A[countA].suit)
                        return 0;
                    countA++;
                }
                countB++;
            }
            countA--;
        }
        countA++;
    }
    return 1;
}

void printCard(Card A[], int n){
    for(int i=0; i<n-1; i++)
        printf("%c%d ",A[i].suit,A[i].val);
    printf("%c%d\n",A[n-1].suit,A[n-1].val);
}

int main(){
    int n;
    scanf("%d",&n);
    Card card[n], card1[n], card2[n];
    for(int i=0; i<n; i++){
        char input[3];
        scanf("%s",input);
        card[i].suit = input[0];
        card[i].val = atoi(&input[1]);
    }

    structCpy(card1,card,n);
    structCpy(card2,card,n);

    // Bubble Sort result
    BubbleSort(card1,n);
    printCard(card1,n);
    if(stableTest(card1,card,n) == 1)
        printf("Stable\n");
    else
        printf("Not stable\n");

    // Selection sort result
    SelectionSort(card2,n);
    printCard(card2,n);
    if(stableTest(card2,card,n) == 1)
        printf("Stable\n");
    else
        printf("Not stable\n");

    return 0;
}


Measured memory_bytes: 2108
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        char tmp[10];
        scanf("%s", tmp);
        if (!strcmp(tmp, "AC"))
        {
            ac++;
        }
        if (!strcmp(tmp, "WA"))
        {
            wa++;
        }
        if (!strcmp(tmp, "TLE"))
        {
            tle++;
        }
        if (!strcmp(tmp, "RE"))
        {
            re++;
        }
    }
    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);

    return 0;
}


Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=998244353;
const LL LINF=1LL<<62;


int main(){
    int N;
    cin >> N;
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            if(i*4+j*7==N){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
map<int, int> cnt;
bool is_prime(long long x) {
	if (x == 1)
		return false;
	if (x == 2 || x == 3)
		return true;
	if (x % 6 != 1 && x % 6 != 5)
		return false;
	int s = sqrt(x);
	for (int i = 5; i <= s; i += 6)
		if (x%i == 0 || x % (i + 2) == 0)
			return false;
	return true;
}

void pfc(long long n, unordered_set<int> &st) {//快速质因数分解 
	
	long long i = 0;
	if (n == 1)
	{
		st.insert(1);
		return ;
	}
	while (i<n)
	{
		if (is_prime(n)) {
			st.insert(n);
			return ;
		}
		for (i = 2; i<n; i++)
		{
			if (n%i == 0)
			{
				st.insert(i);
				n /= i;
				break;
			}

		}
	}
	st.insert(n);
	
	return ;
}
int Gcd(int a, int b)
{
	if (0 == b) return a;
	else return Gcd(b, a % b);
}
void solve() {
	int n;
	cin >> n;
	VI a(n);
	rep(i, 0, n)cin >> a[i];
	int NG = a[0];
	for (int i = 1; i < n; i++) {
		NG = Gcd(NG, a[i]);
	}
	for (int i = n - 1; i >= 0; i--) {
		unordered_set<int> st;
		pfc(a[i], st);
		for (auto v : st) {
			if (v == 1)continue;
			if (cnt.count(v)) {
				if (NG == 1) {
					cout << "setwise coprime";
					return;
				}
				cout << "not coprime";
				return;
			}
			cnt[v]++;
		}
	}
	cout << "pairwise coprime";
//	return;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



Measured memory_bytes: 7308
S = input().split()
X = int(S[0])
Y = int(S[1])

Boo = False

tsuru = 0
kame = 0

for i in range(X+1):
    tsuru  = i*2
    kame = (X-i)*4
    if tsuru + kame == Y:
        Boo = True

if Boo:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61648
#include <iostream>

using namespace std;
using lint = long long;

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

inline bool chmax(lint& a, lint b) {
	if (a < b) {
		a = b; return true;
	}
	return false;
}

int r, c, k;
lint v[3003][3003];
lint dp[4][3003][3003];
int main() {
	cin >> r >> c >> k;
	rep(i, k) {
		int x, y, v1;
		cin >> x >> y >> v1;
		--x; --y;
		v[x][y] = v1;
	}

	dp[1][0][0] = v[0][0];

	rep(i, r) {
		rep(j, c) {
			const lint val = v[i][j];

			if (val != 0) {
				if (i != 0) {
					for (int k = 0; k <= 3; ++k) {
						chmax(dp[1][i][j], dp[k][i - 1][j] + val);
					}
				}
				if (j != 0) {
					for (int k = 0; k <= 2; ++k) {
						chmax(dp[k + 1][i][j], dp[k][i][j - 1] + val);
					}
				}
			}
			for (int k = 0; k <= 3; ++k) {
				if (i != 0) chmax(dp[0][i][j], dp[k][i - 1][j]);
				if (j != 0) chmax(dp[k][i][j], dp[k][i][j - 1]);
			}
		}
	}

	lint ans = 0;

	for (int i = 0; i <= 3; ++i) {
		ans = max(ans, dp[i][r - 1][c - 1]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 354784
def main():
  n = int(input())

  if n > 81: 
    print("No")
    return 0

  for i in range(1,10):
    for j in range(1,10):
      if i*j == n:
        print("Yes")
        return 1 
    
  print("No")
  return 0
       
main()

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll w,d;
  while(cin >> w >> d ,w + d){
    vector<ll> h(w),a(d);
    vector<ll> h2(w),a2(d);
    rep(i,w){
      cin >> h[i];
    }
    rep(i,d){
      cin >> a[i];
    }
    vector<vector<ll>> ans(w,vector<ll>(d));
    int i = 0;
    while(i < d){
      int j = 0;
      while(j < w){
        if(h[j] == a[i] && !h2[j] && !a2[i]){
          ans[j][i] = h[j];
          h2[j] = h[j];
          a2[i] = a[i];
          break;
        }
        ++j;
      }
      ++i;
    }
    i = 0;
    while(i < d){
      int j = 0;
      if(!a2[i]){
        while(j < w){
          if(a[i] <= h2[j]){
            ans[j][i] = a[i];
            a2[i] = a[i];
            break;
          }
          ++j;
        }
      }
      ++i;
    }
    i = 0;
    while(i < w){
      int j = 0;
      if(!h2[i]){
        while(j < d){
          if(h[i] <= a2[j]){
            ans[i][j] = h[i];
            h2[i] = h[i];
            break;
          }
          ++j;
        }
      }
      ++i;
    }
    ll res = 0;
    rep(i,d){
      rep(j,w){
        res += ans[j][i];
      }
    }
    std::cout << res << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3032
import java.util.Scanner;

public class Main {

    public static void main (String [] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans =0;
        if (B>=0){
            System.out.println(Math.max(A+B,A*B));
        }else{
            System.out.println(Math.max(A-B,A*B));
        }

    }
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		for(int i=0;i<n;i++){
			x[i] = sc.nextInt();
		}
		sc.close();
		int min = Integer.MAX_VALUE;
		for(int p=1;p<=100;p++){
			int wa = 0;
			for(int i=0;i<n;i++){
				wa += (x[i]-p)*(x[i]-p);
			}
			if(min>wa) min = wa;
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vi P(N);
	REP(i, N)cin >> P[i];
	int ans = 0;
	REP(i, N-2) {
		if (P[i] > P[i + 1] && P[i + 1] > P[i + 2])ans++;
		if (P[i] < P[i + 1] && P[i + 1] < P[i + 2])ans++;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

char a[3][4];


int main() {
    ios_base::sync_with_stdio(false);
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }
    if (a[0][0] == a[1][2] && a[0][1] == a[1][1] && a[0][2] == a[1][0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 768
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll n,a,b;
  cin >> n >> a >> b;

  string s;
  cin >> s;

  ll pass = 0;
  ll f_pass = 0;
  rep(i,sz(s))
  {
    if(s[i] == 'a')
    {
      if(pass < a + b)
      {
        pass++;
        cout << "Yes" << endl;
      }
      else
      {
        cout << "No" << endl;
      }
      
    }
    else if(s[i] == 'b')
    {
      if(pass < a + b && f_pass < b)
      {
        pass++;
        f_pass++;
        cout << "Yes" << endl;
      }
      else
      {
        cout << "No" << endl;
      }

    }
    else
    {
      cout << "No" << endl;
      
    }
  }

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main() {
	int N, Y;
	cin >> N >> Y;
	int s, t, u ;
	bool X=false;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N - i; j++) {
			int c;
			c = N - i - j;
			if ((10000 * i + 5000 * j + 1000 * c) == Y) {
				X = true;
				s = i;
				t = j;
				u = c;

			}
		}
	}
	if (X) {
		cout << s << " " << t << " " << u << endl;
	}
	else {
		cout << "-1 -1 -1" << endl;
	}

}

Measured memory_bytes: 256
n = int(input())
num = list(map(int, input().split()))
cnt = 0
for i in range(n):
    minj = i
    for j in range(i+1,n):
        if num[j] < num[minj]:
            minj = j
    if i != minj:
        num[i], num[minj] = num[minj], num[i]
        cnt+=1
print(" ".join(map(str, num)))
print(cnt)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k, arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
  cin >> k;
  cout << arr[k - 1];
  return 0;
}

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

# 最初にaが貯まるまで: はじめに1を持っているので、
x = a - 1

# 残りの回数
y = k - x

iteration, res = divmod(y, 2)

print(max(a + iteration*(b-a) + res, k+1))

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll long long
//#define mod 1000000007
#define NCONS 100001

using namespace std;
int N, Q, K;
vector<ll> adj[NCONS];
vector<ll> cost[NCONS];
bool visited[NCONS];
ll dist[NCONS];
int leaf_idx;

void set_dist(int cur, ll len)
{
	visited[cur] = true;
	dist[cur] = len;
	for (int i = 0; i < adj[cur].size(); i++)
	{
		auto next = adj[cur][i];
		auto next_cost = cost[cur][i];
		if (visited[next]) continue;
		set_dist(next, len + next_cost);
	}
}

ll get_dist(int x, int y)
{
	ll ret = dist[x] - dist[y];
	if (ret >= 0)
		return ret;
	else
		return -ret;
}


int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N - 1; i++)
	{
		ll a, b, c; cin >> a >> b >> c;
		adj[a].push_back(b);
		adj[b].push_back(a);
		cost[a].push_back(c);
		cost[b].push_back(c);
	}
	cin >> Q >> K;
	set_dist(K, 0);
	for (int i = 0; i < Q; i++)
	{
		int x, y; cin >> x >> y;
		cout << dist[x] + dist[y] << endl;
	}
	return 0;
}

Measured memory_bytes: 18304
#include <stdio.h>

int sum(int n){
    return n * (n + 1) / 2;
}
int main(void){
    int a, b;
    scanf("%d%d", &a, &b);
    int ans =  sum(b - a - 1) - a;
    printf("%d\n", ans);
    return 0; 
}

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

const int SIZE=100002;

class BIT{
    int N;
    vector<int> dat;
    public:
    BIT(int N):N(N),dat(N){}

    void add(int x){
        x++;
        while(x<=N){
            dat[x-1]++;
            x+=x&-x;
        }
    }
    int query(int r){
        int res=0;
        while(r>0){
            res+=dat[r-1];
            r-=r&-r;
        }
        return res;
    }
};
int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    auto l=a,r=b;

    auto solve1=[&](){
        vector<int> rids(n);
        iota(rids.begin(),rids.end(),0);
        sort(rids.begin(),rids.end(),[&](int lhs,int rhs){return r[lhs]<r[rhs];});

        int iter=0;
        vector<int> ls;
        for(auto lv:l) ls.push_back(lv);
        sort(ls.begin(),ls.end());
        int res=0;
        vector<int> rs;
        
        BIT bit(SIZE);
        for(int i=0;i<SIZE;i++){
            int ltmp=SIZE;
            while(iter<n && r[rids[iter]]==i){
                int id=rids[iter];
                ltmp=min(ltmp,l[id]);
                rs.push_back(r[id]);
                bit.add(l[id]);
                iter++;
            }
            if(ltmp!=SIZE){
                int cntl=lower_bound(ls.begin(),ls.end(),i)-lower_bound(ls.begin(),ls.end(),ltmp);
                int cntr=rs.end()-upper_bound(rs.begin(),rs.end(),ltmp);
                int cntlr=bit.query(SIZE)-bit.query(ltmp);
                int sc=cntl+cntr-cntlr;
                res=max(res,sc);
            }
            
        }
        return res;
    };

    auto solve2=[&](){
        vector<int> sum(SIZE);
        for(int i=0;i<n;i++){
            sum[a[i]]++;
            sum[b[i]]--;
        }
        for(int i=0;i+1<SIZE;i++){
            sum[i+1]+=sum[i];
        }
        return *max_element(sum.begin(),sum.end());
    };

    int res1=solve1();
    int res2=solve2();
    cout<<res1<<" "<<res2<<endl;
    return 0;
}


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


int main() {
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  int ans=0;
  for(int i=0;i<=A;i++){
  
    for(int j=0;j<=B;j++){
      
      for(int k=0;k<=C;k++){
        int total=i*500+j*100+k*50;
        if(total==X){
          ans++;
        }
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long double triple;
const int maxn=111111;
int f[maxn],g[111];
int main()
{
	g[0]=1;
	for(int i=1;i<=20;++i) g[i]=g[i-1]<<1;
	int n,m;scanf("%d%d",&n,&m);f[n+1]=0;
	for(int i=n;i;--i)
	{
		for(int j=f[i+1];!f[i];++j)if(g[j]*i>=m)
		{
			f[i]=j;break;
		}
	}
	triple ans=0;
	for(int i=1;i<=n;++i)
	{
		ans+=((triple)1.0/(1<<f[i]));
	}
	ans/=n;
 	printf("%.12f",(double)ans);
	return 0;
}

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

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  T res = e;
  while (n) {
    if (n & 1) res = op(res, a);
    if (n >>= 1) a = op(a, a);
  }
  return res;
}

template <unsigned Mod> struct Modular {
  using M = Modular;
  unsigned v;
  Modular(long long a = 0) : v((a %= Mod) < 0 ? a + Mod : a) {}
  M operator-() const { return M() -= *this; }
  M& operator+=(M r) { if ((v += r.v) >= Mod) v -= Mod; return *this; }
  M& operator-=(M r) { if ((v += Mod - r.v) >= Mod) v -= Mod; return *this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % Mod; return *this; }
  M& operator/=(M r) { return *this *= power(r, Mod - 2); }
  friend M operator+(M l, M r) { return l += r; }
  friend M operator-(M l, M r) { return l -= r; }
  friend M operator*(M l, M r) { return l *= r; }
  friend M operator/(M l, M r) { return l /= r; }
  friend bool operator==(M l, M r) { return l.v == r.v; }
};

constexpr long long mod = 1e9 + 7;
using Mint = Modular<mod>;

vector<Mint> fact, inv_fact, minv;
void prepare(int n) {
  fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1);
  for (int i = 0; i <= n; ++i) fact[i] = i ? i * fact[i - 1] : 1;
  inv_fact[n] = 1 / fact[n];
  for (int i = n; i; --i) inv_fact[i - 1] = i * inv_fact[i];
  for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1];
}
Mint binom(int n, int k) {
  if (k < 0 or k > n) return 0;
  return fact[n] * inv_fact[k] * inv_fact[n - k];
}
template<> Mint& Mint::operator/=(Mint r) {
  return *this *= r.v < minv.size() ? minv[r.v] : power(r, mod - 2);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> x(n);
  for (auto&& e : x) {
    cin >> e;
  }
  prepare(n);
  --n;
  Mint res, c = 1;
  for (int i = 0; i < n; ++i) {
    res += c * (x[i + 1] - x[i]);
    c += minv[i + 2];
  }
  res *= fact[n];
  cout << res.v << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#define int long long 
using namespace std;

typedef long long ll;

ll mod=1e9+7;

signed main(){
  ll n,m;
  cin >> n >> m;
  ll a[m+2];
  for(int i=1;i<=m;i++) cin >> a[i];
  a[0]=-1,a[m+1]=n+1;
  ll fib[100010];
  fib[0]=1,fib[1]=1;
  for(int i=2;i<100010;i++){
    fib[i]=(fib[i-1]+fib[i-2])%mod;
  }
  ll ans=1;
  for(int i=0;i<m+1;i++){
    ll t=a[i+1]-a[i];
    if(t==1) ans=0;
    else{
      ans=(ans*fib[t-2])%mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
/*⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄
⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄
⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄
⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄
⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰
⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤
⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗
⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄
⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄
⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄
⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄
⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄
⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴
⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=998244353;

int a,b,c,d;
ll memo[3005][3005];
ll memo2[3005][3005];

ll fix(ll i){
	i%=MOD;
	if (i<0) i+=MOD;
	return i;
}

long long qexp(long long b,long long p,int m){
    long long res=1;
    while (p){
        if (p&1) res=(res*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return res;
}

ll dp(int i,int j);
ll dp2(int i,int j);

ll dp(int i,int j){
	if (memo[i][j]!=-1) return memo[i][j];
	
	ll res;
	if (i<a || j<b) res=0;
	else if (i==a) res=qexp(a,j-b,MOD);
	else if (j==b) res=qexp(b,i-a,MOD);
	else res=fix(dp(i,j-1)*i+dp2(i,j));
	
	//cout<<i<<" "<<j<<" "<<res<<endl;
	
	return memo[i][j]=res;
}

ll dp2(int i,int j){
	if (memo2[i][j]!=-1) return memo2[i][j];
	
	int res;
	if (i<a || j<b) res=0;
	else res=fix(dp(i-1,j)+dp2(i-1,j)*(j-1));
	
	return memo2[i][j]=res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	memset(memo,-1,sizeof(memo));
	memset(memo2,-1,sizeof(memo2));
	
	cin>>a>>b>>c>>d;
	
	cout<<dp(c,d)<<endl;
}


Measured memory_bytes: 145172
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n-1];
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
		}
		for(int i = 0;i < n;i++){
			b[i] = saori.saori_hayami();
		}
		for(int i = 0;i < n-1;i++){
			c[i] = saori.saori_hayami();
		}
		int ans = 0;
		ans = b[a[0]-1];
		for(int i = 1;i < a.length;i++){
			ans += b[a[i]-1];
			if(a[i] - a[i-1] == 1){
				ans += c[a[i-1]-1];
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21076
#include<stdio.h>
#define MAX 10

int n , s , sum = 0;
int used[MAX] = {0};

void output() {
	int i;
	for(i = 0; i < MAX; i++) {
		printf("%2d" , used[i]);
	}
	puts("");
}

int getSum() {
	int i , usedSum = 0;
	for(i = 0; i < MAX; i++) {
		if(used[i]) {
			usedSum += i;
		}
	}
	return usedSum;
}

int use(int min , int num) {
	int i;
	if (num == n) {
		//output();
		if (getSum() == s) {
			//output();
			sum++;
		}
		return 1;
	}
	for(i = min; i < MAX; i++) {
		if (used[i] == 0) {
			used[i] = 1;
			use(i + 1 , num + 1);
			used[i] = 0;
		}
	}
	return 0;
}

int main () {
	
	while(1) {
	scanf("%d %d" , &n , &s);
		if (n == 0 && s == 0) break;
		use(0 , 0);
		printf("%d\n" , sum);
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	while(scanf("%lld",&n),n){
		ll M=0;
		ll m=1000;
		ll s=0;
		rep(i,0,n){
			ll t;
			scanf("%lld",&t);
			M=max(M,t);
			m=min(m,t);
			s+=t;
		}
		printf("%lld\n",(s-m-M)/(n-2));
	}
}


Measured memory_bytes: 2032
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i ++)
using ll = long long;
const ll INF = 1ll<<55;
int N, W;
int Ws[100];
int Vs[100];
ll dp[101][100001];

int main() {
    cin >> N >> W;
    rep(i, N) cin >> Ws[i] >> Vs[i];
    rep(v, 100001) dp[0][v] = INF;
    dp[0][0] = 0;
    rep(i, N) {
        rep(v, 100001) {
            dp[i+1][v] = min(v >= Vs[i] ? dp[i][v - Vs[i]] + Ws[i] : INF, dp[i][v]);
        }
    }
    ll ans = 0;
    rep(v, 100001) {
        if (dp[N][v] <= W) {
            ans = v;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;


typedef long long ll;

int n, m;
vector<int> K;
int S[10][10];
vector<int> P;

int SW[10] = {0};


int dfs(int i, int val_sw){
    if(i != 0) SW[i - 1] = val_sw;

    if(i == n){
        
        bool ret = true;
        for (int i = 0; i < m; i++)
        {
            int sum = 0;
            for (int j = 0; j < K[i]; j++)
            {
                if(SW[S[i][j]] == 1) sum ++;
            }
            if(sum % 2 != P[i]){
                ret = false;
                break;
            }
        }
        if(ret) return 1;
        else return 0;
    }

   return dfs(i+1, 1) + dfs(i+1, 0);

}

void solve(){
    int answer = 0;
   
    cout << dfs(0, 0) << endl;
}

int main(){
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int k;
        cin >> k;
        K.push_back(k);
        
        for (int j = 0; j < k; j++)
        {
            int s; cin >> s; s--;
           
            S[i][j] = s;
            
        }
    }
    for (int i = 0; i < m; i++){
        int p; cin >> p;
        P.push_back(p);
    }

    

    solve();

    return 0;

}

Measured memory_bytes: 256
N = int(input())

S = []

for _ in range(N):
    S.append(input())


# internal ab count
internal_ab = 0
for s in S:
    for i in range(1,len(s)):
        if s[i-1] == 'A' and s[i] == 'B':
            internal_ab += 1

# edge
a_pool = 0
b_pool = 0
ab_pool = 0
edge_ab = 0
for s in S:
    if s[0] == 'B' and s[-1] == 'A':
        ab_pool += 1 
    elif s[0] == 'B':
        b_pool += 1
    elif s[-1] == 'A':
        a_pool += 1

if ab_pool == 0:
    edge_ab = min(a_pool, b_pool)
elif a_pool + b_pool == 0:
    edge_ab = ab_pool - 1
else:
    edge_ab = ab_pool + min(a_pool, b_pool)
    
print(internal_ab+edge_ab)

Measured memory_bytes: 3700