akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

int extgcd(int a, int b, int &x, int &y) {
  int d = a;
  if (b != 0) {
    d = extgcd(b, a%b, y, x);
    y -= (a/b)*x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

// m is a large prime integer. Usually 1000000007 is used.
int mod_inverse(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x%m)%m;
}

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

  int n, x; cin >> n >> x;
  vector<int> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());

  vector<ll> fact(n+1);
  fact[0] = 1;
  for(int i=1; i<=n; i++) {
    fact[i] = fact[i-1]*i;
    fact[i] %= mod;
  }
  vector<ll> modinv(n+1);
  for(int i=1; i<=n; i++) {
    modinv[i] = mod_inverse(i, mod);
  }

  unordered_map<int, ll> mp;
  unordered_map<int, ll> mp2;

  rep(i, n) {
    int r = x%s[i];
    mp[r] += fact[n-1];
    mp[r] %= mod;
  }

  bool flag = true;
  while(flag) {
    flag = false;
    for(auto e: mp) {
      auto r = e.first;
      auto it = upper_bound(s.begin(), s.end(), r);
      auto k = distance(s.begin(), it);
      if (k==0) {
        mp2[e.first] += mp[e.first];
        mp2[e.first] %= mod;
      }
      for(int i=0; i<k; i++) {
        flag = true;
        auto pos = r%s[i];
        mp2[pos] += e.second * modinv[k];
        mp2[pos] %= mod;
      }
    }
    mp = mp2;
    mp2.clear();
  }

  ll ans = 0;
  for(auto e: mp) {
    ans += e.second*e.first;
    ans %= mod;
  }
  cout << ans << endl;
}


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

// APG4b-G
int main() {
  int N,A;
  cin >> N >> A;
  
  string answer = "No";
  for (int i = 0; i < 10000; i++) {
   if (A != 0 && N % 500 <= A) {
     answer = "Yes";
   } else if (N % 500 == 0) {
     answer = "Yes";
   }
    
  }
  cout << answer << endl;
  
}


Measured memory_bytes: 256
using System;

class Program{

    const int MOD =1000000007;
   
    static void Main(string[] args){
        int[] num = Program.ScanIntArray(2);
        int[,] CombMod = Program.CombModMake();
        /*
        for (int i = 1; i <= 5; i++)
        {
            for (int j = 1; j <= 5; j++)
            {
                Console.Write(CombMod[i,j] + " ");
            }
            Console.WriteLine("");
        }
        */
        int n = num[0];
        int k = num[1];
        long ans;
        for (int i = 1; i <= k; i++)
        {
            if(n == 1)
            {
                ans = 1;
            }
            else
            {
                ans = ((long)CombMod[n - k + 1, i] * (long)CombMod[k - 1, i - 1]) % MOD;
            }
            Console.WriteLine(ans);
        }
    }

    static int ScanOneInt()
    {
        return int.Parse(Console.ReadLine());
    }

    static int[] ScanIntArray(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] ar = new int[t];
        for (int i = 0; i < t; i++)
        {
            ar[i] = int.Parse(str[i]);
        }
        return ar;
    }

    static int[,] CombModMake()
    {
        int[,] res = new int[2005, 2005];
        for (int i = 0; i < 2005; i++)
        {
            for (int j = 0; j < 2005; j++)
            {
                if (i == 0 || i < j)
                {
                    res[i, j] = 0;
                }
                else if (j == 0 || i == j)
                {
                    res[i, j] = 1;
                }
                else
                {
                    res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % MOD;
                }
            }
        }
        return res;
    }
}

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

int main() {
    int N;
    cin >> N;
    map<ll, ll, greater<ll>> ma;
    rep(i, N) {
        int a;
        cin >> a;
        ma[a]++;
    }

    ll hen1 = 0, hen2 = 0;
    bool judge = false;
    for (auto p : ma) {
        if (p.second < 2)
            continue;
        ll n = p.second / 2;
        if (judge) {
            hen2 = p.first;
            break;
        }
        if (n == 1) {
            hen1 = p.first;
            judge = true;
        } else {
            hen1 = p.first;
            hen2 = p.first;
            break;
        }
    }

    cout << hen1 * hen2 << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1e18
int main(){
  ll n;
  cin>>n;
  ll a[n],b[n],c[n];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  vector<vector<ll>> dp(n,vector<ll>(3,0));
  dp[0][0]=a[0],dp[0][1]=b[0],dp[0][2]=c[0];
  for(int i=1;i<n;i++){
    dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
  }
  cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

Measured memory_bytes: 8064
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ", 3);
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);
        int k = Integer.parseInt(line[2]);

        int count = 0;
        for (int i = 100; i >= 1; i--) {
            if (a % i == 0 && b % i == 0) {
                count++;
                if (count == k) {
                    System.out.println(i);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 22868
n = gets.chomp.to_i
h = gets.chomp.split(' ').map(&:to_i)

combo = Array.new(n, 0)
(n - 1).times do |i|
  if h[i] >= h[i + 1]
    combo[i] = 1
    combo[i] += combo[i - 1] if i > 0
  end
end

puts combo.max


Measured memory_bytes: 10500
#include <iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < (int)s.size()-1; i++){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    for(int i=0;i<w+2;i++){
        cout << '#';
        //上辺
    }
    cout << endl;
    string s;
    for(int j=0;j<h;j++){
        cin >> s;
        cout << '#' << s << '#' << endl;
    }
    for(int k=0;k<w+2;k++){
        cout << '#';
        //下辺
    }
    cout << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
MOD = 998244353
l = []
r = []
for i in range(k):
  tmp1, tmp2 = map(int, input().split())
  l.append(tmp1)
  r.append(tmp2)

array = [0] * (n+1)

array[1] = 1

count = 0
for i in range(1, n+1):
  count += array[i]
  count %= MOD
  for j in range(k):
    if i + l[j] <= n:
      array[i+l[j]] += count
      array[i+l[j]] %= MOD
      
    if i + r[j] + 1 <= n:
      array[i+r[j]+1] -= count
      array[i+r[j]+1] %= MOD
      
print(array[-1])

Measured memory_bytes: 69844
#include <iostream>
#include <string>
using namespace std;

struct Node {
  int parent;
  int left;
  int right;
};
Node T[25];
const int NIL = -1;

void printPreorder(int id) {
  cout << " " << id;
  if (T[id].left != NIL) printPreorder(T[id].left);
  if (T[id].right != NIL) printPreorder(T[id].right);
}

void printInorder(int id) {
  if (T[id].left != NIL) printInorder(T[id].left);
  cout << " " << id;
  if (T[id].right != NIL) printInorder(T[id].right);
}

void printPostorder(int id) {
  if (T[id].left != NIL) printPostorder(T[id].left);
  if (T[id].right != NIL) printPostorder(T[id].right);
  cout << " " << id;
}

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

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    T[i].parent = T[i].left = T[i].right = NIL;
  }

  int id, left, right;
  for (int i = 0; i < n; i++) {
    cin >> id;
    cin >> left >> right;
    T[id].left = left;
    T[id].right = right;
    if (left != NIL) T[left].parent = id;
    if (right != NIL) T[right].parent = id;
  }

  int root = NIL;
  for (int i = 0; i < n; i++) {
    if (T[i].parent == NIL) {
      root = i;
      break;
    }
  }

  cout << "Preorder" << endl;
  printPreorder(root);
  cout << endl;
  cout << "Inorder" << endl;
  printInorder(root);
  cout << endl;
  cout << "Postorder" << endl;
  printPostorder(root);
  cout << endl;

  return 0;
}

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

int main() {
    int D, E;
    while(cin >> D >> E, D) {
        double ret = 1e9;
        for(int x=0; x<=D; ++x) {
            int y = D - x;
            ret = min(ret, abs(sqrt(x*x + y*y) - E));
        }
        cout << ret << endl;
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

int main(){
	ll N; cin>>N;
    vector<ll> h(N);
  rep(i,N) cin>>h[i];
  ll ma=0,cnt=0;
  rep(i,N){
  	if(ma<=h[i]){
    	cnt++;
    }
    ma=max(ma,h[i]);
  }
  cout<<cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main(){
    ll A , B , C;
    cin >> A >> B >> C;
    if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0){
        cout << 0 << endl;
    }
    else{
        cout << min({A * B , B * C , A * C}) << endl;
    }
}


Measured memory_bytes: 256
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  ps <- map read.words <$> getLine :: IO [Int]
  list <- forM [1..n-2] $ \i -> if ps !! i == (sort [(ps !! (i-1)),(ps !! i) ,(ps !! (i+1))]) !! 1
    then return (1 :: Int)
    else return (0 :: Int)

  putStrLn $ show $ sum (list :: [Int])


Measured memory_bytes: 508
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    for(int a=0;a<B;a++){
      if((A*a)%B==C){
        System.out.println("YES");
        return;
      }
    }
    System.out.println("NO");
  }
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3560
#include <ios>
#include <iostream>

bool isPalindromic(int N) {
  int n = N, d[5];
  for (int i = 0; i < 5; ++i) {
    d[i] = n % 10;
    n /= 10;
  }
  if (d[0] == d[4] && d[1] == d[3])
    return true;
  return false;
}

int main(int argc, char *argv[]) {
  int A, B;
  std::cin >> A >> B;

  int count = 0;
  for (int i = A; i <= B; ++i)
    if (isPalindromic(i))
      ++count;
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
y,m,d = map(str,input().split('/'))

y = int(y)

if int(m[0]) == 0:
    m = int(m[1])
else:
    m = int(m[0]+m[1])

if int(d[0]) == 0:
    d = int(d[1])
else:
    d = int(d[0]+d[1])
    
if y > 2019:
    print('TBD')
elif y == 2019:
    if m > 4:
        print('TBD')
    else:
        print('Heisei')
else:
    print('Heisei')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int x, n;
	cin >> x >> n;
	vector<int> nums(n);
	for(int i = 0; i < n; i++) cin >> nums[i];
	
	int diff = 10000;
	int ccc = 0;
	for(int i = 0; i <= 105; i++) {
		bool flag = false;
		for(int j = 0; j < n; j++) {
			if(nums[j] == i) 
				flag = true;
		}
		if(!flag) {
			if(abs(i - x) < diff) {
				diff = abs(i - x);
				ccc = i;
			}
		}
	}
	cout << ccc << "\n";
	return 0;
}

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

struct UnionFind
{
  vector<int> par;
  vector<int> rank;

  UnionFind(int n = 1)
  {
    init(n);
  }

  void init(int n = 1)
  {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; ++i)
      par[i] = i, rank[i] = 0;
  }

  int root(int x)
  {
    if (par[x] == x)
      return x;
    int r = root(par[x]);
    return par[x] = r;
  }

  bool same(int x, int y)
  {
    return root(x) == root(y);
  }

  bool unite(int x, int y)
  {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (rank[x] < rank[y])
      swap(x, y);
    if (rank[x] == rank[y])
      ++rank[x];
    par[y] = x;
    return true;
  }
};

int main()
{
  int64_t N, Q, c, x, y;
  cin >> N >> Q;
  UnionFind uf(N);
  vector<tuple<bool, int, int> > vt;
  for (int i = 0; i < Q; i++)
  {
    cin >> c >> x >> y;
    vt.push_back(make_tuple(c, x, y));
  }
  for (int i = 0; i < Q; i++)
  {
    tie(c, x, y) = vt.at(i);
    if (c)
      cout << uf.same(x, y) << endl;
    else
      uf.unite(x, y);
  }
}



Measured memory_bytes: 4484
N,K = map(int,input().split())
scores = list(map(int,input().split()))
for i in range(N-K):
  #print(scores[K-K+i:K+i+1],scores[K-K + i],scores[K+i])
  if scores[K-K + i ] >= scores[K+i]:
    print("No")
  else:
    print("Yes")

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    bool exist = false;
    for(int i = 1; i <= b; ++i) {
        if(a*i % b == c) exist = true;
    }
    
    if(exist) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

X = int(readline())

res = 0
if X < 600:
    res = 8
elif X < 800:
    res = 7
elif X <1000:
    res = 6
elif X < 1200:
    res = 5
elif X < 1400:
    res = 4
elif X < 1600:
    res = 3
elif X < 1800:
    res = 2
elif X < 2000:
    res = 1

print(res)

Measured memory_bytes: 61616
//知ってるか知らないかだと思ったので解答例を見た、受験の時にそういえばやった
#include<complex>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef complex<double> P;

//ベクトルa,bの張る三角形の面積(外戚の1/2)(符号つき)
double triangle_area_product(P a,P b){return (conj(a)*b).imag()/2;}

int main(){
  double x1,y1,x2,y2,x3,y3,xp,yp;
  while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
    P p1(x1-xp,y1-yp);P p2(x2-xp,y2-yp);P p3(x3-xp,y3-yp);
    double d1=triangle_area_product(p1,p2);
    double d2=triangle_area_product(p2,p3);
    double d3=triangle_area_product(p3,p1);
    bool ok=(d1>0 and d2>0 and d3>0) or (d1<0 and d2<0 and d3<0);
    //三項演算子積極的に使いたい
    cout << (ok ? "YES" : "NO") << endl;
  }
}



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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n,m;
    cin >> n >> m;
    vll a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    sort(all(a));
    sort(all(b));
    rep(i, n - 1) if (a[i] == a[i + 1]) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, m - 1) if (b[i] == b[i + 1]) {
        cout << 0 << endl;
        return 0;
    }

    const ll mod = 1e9 + 7;
    ll ans = 1;
    set<int> s;
    for (ll x = n * m; x > 0; x--) {
        auto ita = lower_bound(all(a), x);
        auto itb = lower_bound(all(b), x);
        if (*ita == x and *itb == x) {
            ans *= 1;
        } else if (*ita == x) {
            ans *= b.end() - itb;
        } else if (*itb == x) {
            ans *= a.end() - ita;
        } else {
            ans *= (a.end() - ita) * (b.end() - itb) - (n * m - x);
        }
        ans %= mod;
    }

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


Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var (
		a, t float32
		b    int
	)
	fmt.Scan(&a, &b, &t)

	sum := 0
	for i := 1; a*float32(i) < t+0.5; i++ {
		sum += b
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int a,b,c;

int main(){
	cin>>a>>b>>c;
	if((100*a+10*b+c)%4==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
using System;

public class Program{

	public static void Main(){
		
		var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
		
		var current = input[2];
		
		for(int i = 0; i < 10; i++){
			current = input[0] * current - input[1];
			Console.WriteLine(current);
		}
		
		
	
	}
		
	
	
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
//#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// age ye mosh dp ro baze dashti dp tedad baz shodeye baste nashode yadet nare !!
/// joooob zadam
const int N=2e5+100;
char c[N];
ll dp[(1<<26)];

int32_t main(){
    string s;
    cin >> s;
    ll n=s.size();
    for (int i=1;i<=n;i++){
        c[i]=s[i-1];
    }
    ll t=0;
    for (int i=0;i<(1<<26);i++)
        dp[i]=1e6;
    dp[0]=0;
    for (int i=0;i<26;i++){
   //     dp[(1<<i)]=0;
    }
    for (int i=1;i<=n;i++){
        //cout << i << endl;
        ll z=c[i]-'a';
        t ^= (1<<z);
        ll mi=dp[t];
        for (int j=0;j<26;j++){
            t ^= (1<<j);
            mi=min(dp[t],mi);
            t ^= (1<<j);
        }
        if (t==0){
            mi=-1;
        }
        dp[t]=mi+1;
        //cout << t << " " << dp[t]  << endl;
        if (i==n){
            cout << max((ll)1,dp[t]) << endl;
        }
    }


}


Measured memory_bytes: 263044
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,m,k,x,y,a[200001];
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
      cin>>n>>k;
      for(long long int i=0;i<n;i++)
      {
         cin>>a[i];
      }
      for(long long int i=k;i<n;i++)
      {
         if(a[i]>a[i-k])
            cout<<"Yes"<<endl;
         else
            cout<<"No"<<endl;
      }
   return 0;
}


Measured memory_bytes: 5192
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    double d = (double)(a[0]+a[1])/2;
    for(int i = 2;i<n;i++){
      d = (d + a[i])/2;
    }
    System.out.println(d);      
  } 
}

Measured memory_bytes: 21972
N = int(input())
A = list(map(int, input().split()))

if abs(A[0]) < abs(A[-1]):
    A = A[::-1]
B = list(map(abs, A))
B.sort()
C = [x for x in A if x < 0]
n = len(C)
if n % 2 == 0:
    print(sum(B))
else:
    print(sum(B[1:]) - B[0])


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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  int res;
  if (b == 1) res = 0;
  else {
    for (int i = 1; i < 20; ++i) {
      if (i*a-(i-1) >= b) {
        res = i;
        break;
      }
    }
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;
int main() {
	int a, b, c, n;
	int ans = 0;
	cin >> a >> b >> c >> n;
	for (int i = 0; i * a <= n; i++) {
		for (int j = 0; j * b <= n; j++) {
			int sum = a * i + b * j;
			if (sum > n)continue;
			if (!((n - sum) % c))ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
#define dvec vector<vector<int>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

int main()
{
  ll N; cin >> N;

  ll ans =  (N - 1) * N / 2;
  cout << ans << endl;

}


Measured memory_bytes: 3608
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

type Point struct {
	x, y float64
}

func main() {
	sc := NewScanner()
	n := sc.nextInt()
	p1 := Point{0, 0}
	p2 := Point{100, 0}
	fmt.Println(p1.x, p1.y)
	koch(n, p1, p2)
	fmt.Println(p2.x, p2.y)
}

func koch(d int, p1, p2 Point) {
	if d == 0 {
		return
	}
	s, t, u := Point{}, Point{}, Point{}
	s.x = (2*p1.x + p2.x) / 3
	s.y = (2*p1.y + p2.y) / 3
	t.x = (2*p2.x + p1.x) / 3
	t.y = (2*p2.y + p1.y) / 3
	u.x = (t.x-s.x)*math.Cos(math.Pi/3) - (t.y-s.y)*math.Sin(math.Pi/3) + s.x
	u.y = (t.x-s.x)*math.Sin(math.Pi/3) + (t.y-s.y)*math.Cos(math.Pi/3) + s.y

	koch(d-1, p1, s)
	fmt.Println(s.x, s.y)
	koch(d-1, s, u)
	fmt.Println(u.x, u.y)
	koch(d-1, u, t)
	fmt.Println(t.x, t.y)
	koch(d-1, t, p2)
}



Measured memory_bytes: 1156
n, k = map(int, input().split())
aa = list(map(int, input().split()))

ki = 0
while True:
    if 2 ** ki >= k:
        break
    else:
        ki += 1

mask = 0
for i in range(ki, -1, -1):
    b = 1 << i
    cnt = 0
    for a in aa:
        if a & b > 0:
            cnt += 1
    if len(aa) - cnt > cnt:
        if mask | b <= k:
            mask = mask | b

ans = 0
for a in aa:
    ans += a ^ mask
print(ans)


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

using namespace std;

#define debug(x) cout << #x << "::" << x << endl;
#define debug2(x, y) cout << #x << "::" << x << " " << #y << "::" << y << endl;
#define debug3(x, y, z) cout << #x << "::" << x << " " << #y << "::" << y <<" "<< #z << "::" << z << endl;

#define For(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
const ll mod = 1e9 + 7;
const int MAX = 5 * 1e3 + 5;
typedef pair<int, int> pii;

void add(ll &a, ll b)
{
    a = (a + b) % mod;
    if (a < 0) a += mod;
}

int main() {

    int n,w;
    cin>>n>>w;

    vector<vector<int>> v(n+1,vector<int>(2));

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

    vector<vector<ll>> dp(w+1,vector<ll>(n+1));

    for(int i=1;i<=w;i++){
        for(int j=1;j<=n;j++){
            if(v[j][0] <= i) dp[i][j] = max(v[j][1]+dp[i-v[j][0]][j-1],dp[i][j-1]);
            else dp[i][j] = dp[i][j-1];
            //if(i == 3) cout<<dp[i-v[j][0]][j-1]<<" ";
        }
    }

    /*For(i,1,w+1){
        For(j,1,n+1) cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/

    cout<<dp[w][n]<<endl;

    return 0;


}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
 
using namespace std;
 
const int N = (int) 1e5;
int n,k;
long long a[N+5],ans=(long long)2e15;
int main()
{
 
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    cin>>a[i];
     for(int i=1;i+k-1<=n;i++)
    {  
        int l=i,r=i+k-1;
        ans=min(ans,a[r]-a[l]+min(abs(a[l]),abs(a[r])));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
using namespace std;
const int N=100005;
const int INF=1e9;
int n,m;
int a[N];
int h[N],tot,dep[N];
struct Edge{
    int v,next;
}e[N*2];
int f[N],g[N],ans[N];
inline int max(int x,int y){
    return x>y?x:y;
}
inline int abs(int x){
    return x>=0?x:-x;
}
void addEdge(int u,int v){
    e[++tot]=(Edge){v,h[u]}; h[u]=tot;
    e[++tot]=(Edge){u,h[v]}; h[v]=tot;
}
void readData(){
    scanf("%d",&n);
    int u,v;
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        addEdge(u,v);
    }
    memset(a,-1,sizeof a);
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        a[u]=v; 
    }
}
void mark_dfs(int u,int fa){
    dep[u]=dep[fa]+1;
    for(int i=h[u],v;i;i=e[i].next)
        if((v=e[i].v)!=fa)
            mark_dfs(v,u);
}
bool firstCheck(){
    mark_dfs(1,0);
    int flag=-1;
    for(int u=1;u<=n;u++)
        if(a[u]!=-1){
            if(flag==-1)
                flag=(a[u]^dep[u])&1;
            else if(((a[u]^dep[u])&1)!=flag)
                return false;
        }
    return true;
}
void dp_dfs1(int u,int fa){
    f[u]=(a[u]!=-1)?a[u]:-INF;
    for(int i=h[u],v;i;i=e[i].next)
        if((v=e[i].v)!=fa){
            dp_dfs1(v,u);
            f[u]=max(f[u],f[v]-1);
        }
}
bool dp_dfs2(int u,int fa){
    if(a[u]!=-1)
        g[u]=a[u];
    ans[u]=(a[u]!=-1)?a[u]:max(f[u],g[u]);
    if(fa&&abs(ans[u]-ans[fa])!=1)
        return false;
    static int ch[N],cnt;           
    static int l[N],r[N];
    cnt=0;
    for(int i=h[u],v;i;i=e[i].next)
        if((v=e[i].v)!=fa)
            ch[++cnt]=v;
    l[0]=g[u]+1; r[cnt+1]=-INF;     
    for(int i=1;i<=cnt;i++)
        l[i]=max(l[i-1],f[ch[i]]);
    for(int i=cnt;i>=1;i--)
        r[i]=max(r[i+1],f[ch[i]]);
    for(int i=1;i<=cnt;i++)
        g[ch[i]]=max(l[i-1],r[i+1])-2;
    for(int i=h[u],v;i;i=e[i].next)
        if((v=e[i].v)!=fa){
            if(dp_dfs2(v,u)==false)
                return false;
            if(abs(ans[u]-ans[v])!=1)
                return false;
        }
    return true;
}
bool solve(){
    dp_dfs1(1,0);
    g[1]=-INF;
    if(dp_dfs2(1,0)==false)
        return false;
    puts("Yes");
    for(int i=1;i<=n;i++)
        printf("%d\n",ans[i]);
    return true;
}
int main(){
    readData();
    if(!firstCheck()||!solve()){
        puts("No");
        return 0;
    }
    return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

const int N=200005;
struct node{
	int a,b;
	node(int _a=0,int _b=0){
		if(!(_a&1))_a=0;
		if(_b&1)_b=0;
		a=_a,b=_b;
	}
	friend node operator + (node x,node y){
		return node(max(x.a,y.a),max(x.b,y.b));
	}
}T[N<<2];
int a[N],s[N],H[2],C[2];
char ans[N];
int n,mx;

#define lc (o<<1)
#define rc (o<<1|1)
#define mid ((l+r)>>1)
void upd(int o,int l,int r,int x,node y){
	if(l==r)return (void)(T[o]=y);
	if(x<=mid)upd(lc,l,mid,x,y);
	else upd(rc,mid+1,r,x,y);
	T[o]=T[lc]+T[rc];
}
node qry(int o,int l,int r,int x,int y){
	if(l==x&y==r)return T[o];
	if(y<=mid)return qry(lc,l,mid,x,y);
	if(mid<x)return qry(rc,mid+1,r,x,y);
	return qry(lc,l,mid,x,mid)+qry(rc,mid+1,r,mid+1,y);
}

int chk(int x,int val){
	node ret=qry(1,1,n,max(1,a[x]),n);
	int t[2]={ret.b,ret.a};
	return val>=0&&t[val&1]>=val;
}

int main(){
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%d",&a[i]);
		mx=max(mx,a[i]);
		s[i]=(a[i]==mx);
	}
	per(i,n,1){
		node ret=qry(1,1,n,a[i],n);
		if(s[i]==1)upd(1,1,n,a[i],node(ret.a+2,ret.b+2));
		else upd(1,1,n,a[i],node(ret.b+1,ret.a+1));
		s[i]+=s[i+1];
	}
	if(!chk(0,s[1]))return puts("-1"),0;
	rep(i,1,n){
		int nH=(a[i]>a[H[0]]?i:H[0]);
		int nC=C[0]+(i==nH);
		upd(1,1,n,a[i],node(0,0));
		if(chk(nH,C[1]-nC+s[i+1])||chk(H[1],nC-C[1]+s[i+1]))
			H[0]=nH,C[0]=nC,ans[i]='0';
		else
			H[1]=(a[i]>a[H[1]]?i:H[1]),C[1]+=(i==H[1]),ans[i]='1';
	}
	puts(ans+1);
	return 0;
}

Measured memory_bytes: 8448
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	ll A, B, N;
	cin >> A >> B >> N;
	if (B == 1)
		cout << 0 << endl;
	else {
		ll M = A / B;
		if (N >= B - 1)
			cout << (A - M - 1) << endl;
		else
			cout << (A * N / B - A * (N / B)) << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
/*
* @Author: hannibal_lecter
* @Date:   2018-09-23 20:18:39
* @Last Modified by:   hannibal_lecter
* @Last Modified time: 2018-09-23 20:23:12
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+9;
int Case = 1, n, m;
int cal(int a, int b) {return a*10+b;}
void solve(){
	int a[5];
   	for(int i = 1; i <= 3; i++) cin>>a[i];
    sort(a+1, a+4);
	cout<<cal(a[3],a[2])+a[1]<<endl;
    return;
}

int main() {
    //ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
    //freopen("/Users/hannibal_lecter/Desktop/code/in.txt", "r", stdin);
    //freopen("/Users/hannibal_lecter/Desktop/code/out.txt","w",stdout);
#endif
    while(Case--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ll long long
#define test(t) int t ; cin>>t ; while(t--)
ll mulmod(ll a, ll b, ll mod){ll res = 0;a = a % mod;while (b > 0){if (b % 2 == 1)res = (res + a) % mod;a = (a * 2) % mod;b /= 2;}return res % mod;}
int n;
int main(){
	BOOST;
	int m;
	cin >> n >> m;
	vector<pair<int,int> > v(m);
	for(int i = 0 ; i < m ; ++i){
		cin >> v[i].second >> v[i].first;
	}
 	sort(v.begin(),v.end());
 	int pos = -1;
 	int ans = 0;
 	for(int i = 0 ; i < m ; ++i){
 		if(v[i].second >= pos){
 			pos = v[i].first;
 			ans++;
 		}
 	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#define rep(i, n) for ( int i = 0; i < n; i++ )
using namespace std;
#define MAX 100
class Cube{
    public:
    string f[6];
    Cube(){}
    void roll_z(){ roll(1, 2, 4, 3);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_x(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
	string t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
};

Cube C[MAX];
int n;

bool eq( Cube c1, Cube c2 ){
    rep(i, 6) if ( c1.f[i] != c2.f[i] ) return false;
    return true;
}

bool equal( Cube c1, Cube c2 ){
    rep(i, 6){
	rep(j, 4){
	    if ( eq(c1, c2) ) return true;
	    c1.roll_z();
	}
	if ( i % 2 == 0 ) c1.roll_y();
	else c1.roll_x();
    }
    return false;
}

main(){
    while( cin >> n && n ){
	rep(i, n) rep(j, 6) cin >> C[i].f[j];
	int cnt = 0;
	rep(i,n) {
	    bool hasSame = false;
	    for(int j=i+1; j<=n-1;j++) if (equal(C[i],C[j])) {hasSame = true;break;}
	    if ( !hasSame ) cnt++;
	}
	cout << n - cnt << endl;
    }
}

Measured memory_bytes: 936
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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


vll calc(ll N) {
    vll ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            ll j = N / i;
            if (j != i) ret.push_back(j);
        }
    }
    sort(ALL(ret));
    
    return ret;
}


int main() {

    ll N;
    cin >> N;

    const auto vec1 = calc(N);
    const auto vec2 = calc(N - 1);

    ll ans = vec2.size() - 1;

    for (auto x : vec1) {
        if (x == 1) continue;
        auto NN = N;
        while (NN % x == 0) NN /= x;
        if ((NN - 1) % x == 0) ans++;
    }

    cout << ans << endl;

#ifdef _MSC_VER
    system("PAUSE");
#endif

    return 0;
}

Measured memory_bytes: 3656
H,W = map(int, input().split())

S=[]
a1="."*(W+2)
S.append(a1)
for i in range(H):
    a2="."
    a3=input()
    a4=a2+a3+a2
    S.append(a4)
S.append(a1)




for i in range(H):
    for j in range(W):
        count=0
        if S[i+1][j+1]=="#":
            count="#"
        else:
            if S[i][j]=="#":
                count+=1
            if S[i][j+1]=="#":
                count+=1
            if S[i][j+2]=="#":
                count+=1
            if S[i+1][j]=="#":
                count+=1
            if S[i+1][j+2]=="#":
                count+=1
            if S[i+2][j]=="#":
                count+=1
            if S[i+2][j+1]=="#":
                count+=1
            if S[i+2][j+2]=="#":
                count+=1
        print(count,end="")
    print("")



Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            int num1 = Convert.ToInt32(input);

            Console.WriteLine(48 - num1);
        }
    }
}


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

int main(){
  long long int m,a=0;
  cin >> m;
  while(m>4){
    if(m/500>0){
      a+=m/500*1000;
      m%=500;
    }
    else if(m/5>0){
      a+=m/5*5;
      m%=5;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll n;
    cin >> n;
    ll a[n], b[n];
    vector<ll> must;
    bool success = 0;
    const ll INF = 1145148931919810;
    for(ll i = 0; i < 2; i++) for(ll j = 0; j < n; j++) cin >> (i ? b : a)[j];
    for(ll k = 50; 0 <= k; k--){
        ll d[51][51];
        for(ll i = 0; i <= 50; i++) for(ll j = 0; j <= 50; j++) d[i][j] = INF * !(i == j);
        for(ll i = 0; i <= 50; i++) for(ll j = 1; j < k; j++) d[i][i % j] = 0;
        for(ll i = 0; i <= 50; i++) for(ll j : must) d[i][i % j] = 0;
        for(ll z = 0; z <= 50; z++) for(ll x = 0; x <= 50; x++) for(ll y = 0; y <= 50; y++) d[x][y] = min(d[x][y], d[x][z] + d[z][y]);
        bool f = 1;
        for(ll i = 0; i < n; i++){
            if(d[a[i]][b[i]]){
                f = 0;
                must.push_back(k);
                break;
            }
        }
        if(f) success = 1;
    }
    if(!success){
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    for(ll u : must) ans += (ll)pow(2, u);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

#define MAX 20

int solve(int,int);

  int A[MAX],n,result;
  
int main()
{
  int q,i;

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

  for(i=0;i<q;i++)
    {
      result=solve(0,M[i]);
      if(result==1)printf("yes\n");
      else printf("no\n");
    }
  return 0;
}

int solve(int i,int m)
{
  int result;
  if(m==0)return 1;
  if(i>=n)return 0;
  result=solve(i+1,m)||solve(i+1,m-A[i]);
  return result;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    ll n;
    cin >> n;
    ll ans=8;
    n-=400;
    
    cout << ans-(n/200) << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll mrk[M],red[M];

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

	ll n,m,i,j,p,tot = 0,ans = 0,cor = 0;
	string str;

	cin >> n >> m;

	for(i=1;i<=m;++i)
	{
		cin >> p >> str;
		if(str[0] == 'W')
		{
			tot++;
			red[p]++;
		}
		else
		{
			if(mrk[p] == 0)
			{
				cor++;
				mrk[p] = 1;
				red[p] = 0;
			}
		}
	}

	for(i=1;i<=n;++i)
		tot -= red[i];

	cout << min(n,cor) << " " << tot << "\n";
	return 0;
}

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

#define int long long

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

    int h,w, K;

    cin >> h >> w >> K;

    int dp[w+1][h+1];

    for(int i = 0; i < w+1 ; i++){
        for(int j = 0; j< h+1; j++){
            dp[i][j] = 0;
        }
    }

    dp[0][0] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < pow(2,w-1); k++){
                bool ok = true;
                for(int l = 0; l < w-2; l++){
                    if(((k >> l) & 1) && ((k >> (l+1)) & 1)){
                        ok = false;
                    }
                }
                if(ok){
                    if((j >= 1) && ((k >> (j-1)) &1)){
                        dp[j-1][i+1] += dp[j][i];
                        dp[j-1][i+1] %=1000000007;
                    }else if(j <= w-2 && (k >> j)&1){
                        dp[j+1][i+1] += dp[j][i];
                        dp[j+1][i+1]%=1000000007;
                    }else{
                        dp[j][i+1] += dp[j][i];
                        dp[j][i+1]%=1000000007;
                    }
                }
            }
        }
    }
    cout << dp[K-1][h] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
int main(){
string s;
cin>>s;
int sum =0;
for(int i=0;i<s.size();i++)
{
    s[i]=s[i]-'0';
    sum=sum+s[i];
}
if(sum%9==0)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;
}









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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1e9+7;

int main() {
	string s;
	cin >> s;
	ll dp[s.size()+100][4]={};
	dp[0][0] = 1;
	for (int i = 0;i < s.size();i++) {
		for (int j = 0;j < 4;j++) {
			if (s[i] != '?') {dp[i+1][j] = (dp[i+1][j]+dp[i][j])%inf;}
			else {dp[i+1][j] = (dp[i+1][j]+3*dp[i][j])%inf;}
		}
		if (s[i] == 'A'||s[i] == '?') {dp[i+1][1] = (dp[i+1][1] + dp[i][0])%inf;}
		if (s[i] == 'B'||s[i] == '?') {dp[i+1][2] = (dp[i+1][2] + dp[i][1])%inf;}
		if (s[i] == 'C'||s[i] == '?') {dp[i+1][3] = (dp[i+1][3] + dp[i][2])%inf;}
	}
	cout << dp[s.size()][3] << endl;
}

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

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,i,a,b,x,y;
    t = 1;
    while(t--) {
	 cin >> x >> y;
	 if(y == 1)
	  a = 0;
	 else
	  a = 1;
	 b = x;
	 if(x < y) {
	  while(b < y) {
	   a++;
	   b = b + x - 1;
	  }
     }
	 cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 256