akhauriyash/Code-Regression huggingface dataset:
from math import gcd
from functools import reduce
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))

g=reduce(gcd,a)
if g!=1:
  print("not coprime")
  exit()

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret
  
def primes(x):
  ret=[]
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      ret.append(i)
      if x//i!=i:
        ret.append(x//i)
  ret.sort()
  return ret[1:]
      
d=defaultdict(int)
for q in a:
  #p=primeFactor(q)
  p=primes(q)
  for j in p:
    if d[j]==1:
      print("setwise coprime")
      exit()
    d[j]+=1
print("pairwise coprime")

Measured memory_bytes: 182704
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <functional>
#include <time.h>
#include <math.h>

using namespace std;


int main() {

	int r;
	cin >> r;

	cout << r * r;


}

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

int main(){
    int a,b,cont=0;
    cin>>a>>b;

    for(int t=a;t<=b;t++){
        string num=to_string(t);
        bool flag=true;
        for(int i=0;i<=num.size()-1;i++){
            if(num[i]!=num[num.size()-1-i])flag=false;
        }
        if(flag)cont++;
    }

    cout<<cont<<"\n";

    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, K; cin >> N >> K;
    cout << N - K + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class c> struct rge { c b, e; };
template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; }
template <class c> auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c> char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
template <class c> typename enable_if<sizeof dud<c>(0)!=1, debug&>::type operator<<(c i) {cerr << boolalpha << i; return * this; }
template <class c> typename enable_if<sizeof dud<c>(0)==1, debug&>::type operator<<(c i) {return * this << range(begin(i), end(i)); }
template <class c, class b> debug & operator <<(pair < b, c > d) {
  return * this << "(" << d.first << ", " << d.second << ")";
}
template <class c> debug & operator <<(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  return * this << "]";
}
#else
template <class c> debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


typedef long long ll;
typedef long double ld;

#define ar array

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound 

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

const int maxn = 1e5+7;
vector<int> adj[maxn];
bool visited[maxn];
int parent[maxn];

int main() {
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		int a,b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	vector<pair<int,int>> q{{1,-1}};
	int curr = 0;
	while(curr < q.size()) {
		if (visited[q[curr].first]) {
			curr++;
			continue;
		}
		visited[q[curr].first] = true;
		parent[q[curr].first] = q[curr].second;
		for(int b:adj[q[curr].first]) {
			q.push_back({b,q[curr].first});
		}
		curr++;
	}

	for(int i=1;i<=n;i++) {
		if (!visited[i]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	for(int i=2;i<=n;i++) {
		cout << parent[i] << "\n";
	}
	
    return 0;    
}


Measured memory_bytes: 14172
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n,i,sum=0;
    cin>>n;
    int a[n],b[n],c[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n;i++)
        cin>>b[i];
    for(i=0;i<n-1;i++)
        cin>>c[i];
        
    for(i=0;i<n;i++)
    {
        sum+=b[a[i]-1];
        if((i!=0)&&(a[i]==a[i-1]+1))
            sum+=c[a[i-1]-1];
            
            //cout<<sum<<endl;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
l = len(str(N))
ans = 0

if l != 1:
    if l%2 == 0:
        for i in range(0, l, 2):
            ans += 9*(10**i)
    else:
        for i in range(0,l-2, 2):
            ans += 9*(10**i)
            #print(ans)
        ans += N - int('9'*(len(str(N))-1))
else:
    ans = N

print(ans)
#print(l)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int main(){
  int i,n,m,ans;
  scanf("%d",&n);
  ans=1;
  for(i=2;i<=n;i++){
    m=2;
    while(n>=pow(i,m)){
      if(ans<pow(i,m)){ans=pow(i,m);}
      m++;
    }
    if(m==2){break;}
  }
  printf("%d",ans); 
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,1,n){
        int in;
        cin>>in;
        a[in-1]++;
    }
    for(auto i:a) cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;
/*
vector<ll> G[500005];
vector<P> tree[500010];

//big priority queue
priority_queue <ll> pql;
priority_queue <P> pqp;

//small priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
*/
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj,n,m;
ll a,b,c,d,e,g,h,r,l,w,num,ans;
ll x[500005],y[500005],z[500005];
ll dp[205][300005];

int main(){    
    cin >> n >> w;
	for(i=0;i<n;i++){
		cin >> x[i+1] >> y[i+1];
		a += y[i+1];
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=a;j++){
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;
	for(i=1;i<=n;i++){
		//dp[i][j] := i番目まで使って価値jで重さの最小値
		for(j=0;j<=a;j++){
			if(j-y[i] < 0){
				dp[i][j] = dp[i-1][j];
				//pe(dp[i][j]);
			}else{
				dp[i][j] = min(dp[i-1][j],dp[i-1][j-y[i]] + x[i]);
				//pe(dp[i][j]);
			}
		}
		//el;
	}
	ans = 0;
	for(i=0;i<=a;i++){
		if(dp[n][i] <= w){
			ans = max(ans,i);
		}
	}
	p(ans);
	
    return 0;
}


Measured memory_bytes: 238592
#include <iostream>
using namespace std;
int parttion(int A[],int p,int r){
    int x=A[r];
    int i=p-1;
    for(int j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            int tmp=A[i];
            A[i]=A[j];
            A[j]=tmp;
        }
    }
    int tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;
    return i+1;
}
int main(){
    int n;
    int A[100000]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    int q=parttion(A,0,n-1);
    for(int i=0;i<q;i++){
        cout<<A[i]<<" ";
    }
    cout<<'['<<A[q]<<']';
    for(int i=q+1;i<n;i++){
        cout<<" "<<A[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3484
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int n,r;

  while(cin>>n>>r,n){
    int p,c;
    vector<int> cards;
    
    for(int i=n;i>0;--i){
      cards.push_back(i);
    }
    
    for(int i=0;i<r;++i){
      cin>>p>>c;
      vector<int> temp;
      for(int j=0;j<c;++j){
	temp.push_back(cards[p-1]);
	cards.erase(cards.begin()+p-1);
      }
      
      int j=0;
      for(auto i:temp){
	cards.insert(cards.begin()+j,i);
	j++;
      }
    }
    cout<<cards[0]<<endl;
  }
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 110

ll N;
ll F[MAX_N] = {};
ll P[MAX_N][20] = {};
int main()
{
    cin >> N;
    REP(i, N) {
        REP(j, 10) {
            int tmp;
            cin >> tmp;
            if(tmp == 1) { F[i] |= (1 << j); }
        }
    }
    REP(i, N) {
        REP(j, 11) {
            cin >> P[i][j];
        }
    }
    ll ans = -10000000000;
    for(ll work = 1; work < 1024; ++work) {
        ll cand = 0;
        REP(i, N) {
            ll overlap = (F[i] & work);
            ll cnt = 0;
            REP(j, 32) {
                if( ((overlap >> j) & 1) == 1) { cnt++; }
            }
            cand += P[i][cnt];
        }
        ans = max(ans, cand);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
import Data.List

main :: IO ()
main = do
    [n, y] <- map read . words <$> getLine :: IO [Int]

    let l = concatMap (\(a,b)->if y == 10000*(n-a)+5000*(a-b)+1000*b then [(n-a, a-b, b)] else [])
                [(a, b)|a <- [0..n], b <- [0..n], n-a>=0, a-b>=0, (n-a)+(a-b)+b <= n] 
    
    putStrLn $ ans l
    where
    ans [] = "-1 -1 -1"
    ans ((a,b,c):_) = show a++" "++show b++" "++show c


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
typedef unsigned int uint;
typedef long long llong;
using namespace std;

int main(void) {
    cin.tie(0); // cinéŤéĺ
    double T,X;

    cin >> T >> X;

    cout << T / X << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> p;
 
#define MOD 1000000007

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

    int H, W, M;
    cin >> H >> W >> M;

    map<p, bool> x;
    vector<int> ch(H);
    vector<int> cw(W);

    for(int i = 0; i < M; i++) {
        int h, w;
        cin >> h >> w;
        h--;
        w--;
        ch[h]++;
        cw[w]++;
        x[make_pair(h, w)] = true;
    }

    int mh = *max_element(ch.begin(), ch.end());
    int mw = *max_element(cw.begin(), cw.end());

    vector<int> mhs;
    vector<int> mws;

    for(int i = 0; i < H; i++) {
        if(ch[i] == mh) mhs.push_back(i);
    }

    for(int i = 0; i < W; i++) {
        if(cw[i] == mw) mws.push_back(i);
    }

    for(int i = 0; i < mhs.size(); i++) {
        for(int j = 0; j < mws.size(); j++) {
            if(x[make_pair(mhs[i], mws[j])]) continue;
            cout << mh + mw << endl;
            return 0;
        }
    }

    cout << mh + mw - 1 << endl;
}

Measured memory_bytes: 28508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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 MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int a, b, m; cin >> a >> b >> m;
	vector<int> as(a);
	int a_min = INF,b_min = INF;
	rep(i, a) 
	{cin >> as[i];chmin(a_min,as[i]);}
	vector<int> bs(b);
	rep(i, b)
	{cin >> bs[i];chmin(b_min,bs[i]);}
	vector<int> x(m), y(m), c(m);
	rep(i, m) cin >> x[i] >> y[i] >> c[i];
	int ans = a_min + b_min;
	rep(i, m)
	{
		int tmp = as[x[i]-1]+bs[y[i]-1]-c[i];
		chmin(ans,tmp);
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <map>

using namespace std;

vector<int> C(vector<int> v) {
	map<int, int> m;

	for (int i = 0; i < v.size(); ++i)
		++m[v[i]];

	vector<int> ret;
	for (int i = 0; i < v.size(); ++i)
		ret.push_back(m[v[i]]);

	return ret;
}

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> v;
		for (int i = 0; i < n; ++i) {
			int a; cin >> a;
			v.push_back(a);
		}

		int count = 0;
		vector<int> bv = v;
		while (1) {
			v = C(v);
			if (v == bv) break;
			bv = v;
			++count;
		}

		cout << count << endl;
		for (int i = 0; i < v.size(); ++i)
			if (i == v.size()-1) cout << v[i] << endl;
			else cout << v[i] << " ";
	}
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<double,int>;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  int a,b,c;
  int x,y;
  cin >> a >> b >> c >> x >> y;
  ll res = 0;
  if(2*c < a+b){
    int cnt = min(x,y);
    res += cnt * 2 * c;
    x -= cnt;
    y -= cnt;
  }
  if(2*c < a){
    res += x * 2 * c;
  }else{
    res += x * a;
  }
  if(2*c < b){
    res += y * 2 * c;
  }else{
    res += y * b;
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
def solve():
    S = list(input())

    ans = 1000000000
    # 0, 1
    for iro in range(2):
        cnt = 0
        for idx, s in enumerate(S):
            if idx % 2 == 0 and str(iro) != s: cnt += 1
            elif idx % 2 != 0 and str(iro) == s: cnt += 1
        # print(cnt)
        ans = min(ans, cnt)

    print(ans)
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		int count = 0;
		for (int i = 0; i < n; i++) {
			int min_j = i;
			for (int j = i; j < n; j++) {
				if (a[j] < a[min_j])
					min_j = j;
			}
			if (i != min_j)
				count++;
			int tmp = a[i];
			a[i] = a[min_j];
			a[min_j] = tmp;
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 26348
#include <stdio.h>          // printf(), scanf()
#define MAX_N 500000

typedef struct node_tbl
{
	int key;
	int parent;
	int left;
	int right;
} node;

const int nil = -1;
node t[MAX_N + 1];
int root;
int ix;

void
insert(int k)
{
	int y = nil;
	int x = root;
	int z = ix++;

	t[z].key = k;
	t[z].left = nil;
	t[z].right = nil;

	while (x != nil)
	{
		y = x;
		if (t[z].key < t[x].key)
			x = t[x].left;
		else
			x = t[x].right;
	}

	t[z].parent = y;
	if (y == nil)
		root = z;
	else
	{
		if (t[z].key < t[y].key)
			t[y].left = z;
		else
			t[y].right = z;
	}
}

void
inorder(int u)
{
	if (u == nil)
		return;

	inorder(t[u].left);
	printf(" %d", t[u].key);
	inorder(t[u].right);
}

void
preorder(int u)
{
	if (u == nil)
		return;

	printf(" %d", t[u].key);
	preorder(t[u].left);
	preorder(t[u].right);
}

int
main(int argc, char** argv)
{
	char command[8];
	int n;
	int x;
	int i;

	root = nil;
	ix = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%s", command);
		switch (command[0])
		{
		case 'i':
			scanf("%d", &x);
			insert(x);
			break;

		case 'p':
		default:
			inorder(root);
			printf("\n");

			preorder(root);
			printf("\n");
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 9576
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S, T;
    cin >> S >> T;
    ll ans = LINF;
    rep(i, S.size() - T.size() + 1) {
        string Ssub = S.substr(i, T.size());
        ll cnt = 0;
        rep(j, T.size()) {
            if (Ssub[j] != T[j]) cnt++;
        }
        ans = min(cnt, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
vector<ll> getNums(ll N) {
    vector<ll> num(N);
    REP(i, N) {
        cin >> num[i];
    }
    return num;
}

unordered_map<ll, ll> values;

void func(ll n) {
    for (ll i = 2; i * i <= n; ++i) {
        while ((n % i) == 0) {
            n /= i;
            values[i]++;
        }
    }
    if (n != 1) {
        values[n]++;
    }
}
int main() {
    ll N;
    cin >> N;
    values.clear();
    for (ll i = 1; i <= N; ++i) {
        func(i);
    }

    ll ans = 1;
    for (const auto& v : values) {
        ans *= v.second + 1;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int n;
vector<vector<int>> G;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	G.resize(n);
	rep(i,n-1){
		int a,b;cin >> a >> b;
		a--;
		b--;
		G.at(a).pb(b);
		G.at(b).pb(a);
	}
	int x=0,y=0;
	queue<int> q;
	q.push(x);
	vector<bool> used(n,true);
	used.at(0)=false;
	while(!q.empty()){
		x=q.front();
		q.pop();
		rep(i,G.at(x).size()){
			if(used.at(G.at(x).at(i))){
				q.push(G.at(x).at(i));
				used.at(G.at(x).at(i))=false;
			}
		}
	}
	rep(i,n) used.at(i)=true;
	queue<pii> q1;
	used.at(x)=false;
	q1.push(mp(x,1));
	int dist=1;
	while(!q1.empty()){
		pii cur=q1.front();y=cur.first;int k=cur.second;
		q1.pop();
		rep(i,G.at(y).size()){
			if(used.at(G.at(y).at(i))){
				q1.push(mp(G.at(y).at(i),k+1));
				dist=max(dist,k+1);
				used.at(G.at(y).at(i))=false;
			}
		}
	}
	if(dist%3==2) cout << "Second" << endl;
	else cout << "First" << endl;
}


Measured memory_bytes: 13684
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    vi a(3*N);
    rep(i, 3*N) cin >> a[i];
    int res = -1e18;
    priority_queue<int, vector<int>, greater<int>> lq;
    priority_queue<int> rq;
    vi lsum(3*N, 0), rsum(3*N, 0);
    rep(i, N) {
        lq.push(a[i]);
        lsum[N-1] += a[i];
    }
    FOR(i, 2*N, 3*N) {
        rq.push(a[i]);
        rsum[2*N-1] += a[i];
    }

    for(int k=N; k<2*N; k++) {
        lq.push(a[k]);
        lsum[k] = lsum[k-1] + a[k];
        lsum[k] -= lq.top();
        lq.pop();

        rq.push(a[3*N-1-k]);
        rsum[3*N-1-k-1] = rsum[3*N-1-k] + a[3*N-1-k];
        rsum[3*N-1-k-1] -= rq.top();
        rq.pop();
    }

    for(int i=N-1; i<2*N; i++) {
        res = max(res, lsum[i]-rsum[i]);
    }

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

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int W,H;
string s[500];
ll a[500][500];
ll b[500][500];
int dd[]={-1,0,1,0,-1};
int si,sj;
vector<P> ts;

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

  cin>>W>>H;
  rep(i,H)cin>>s[i];

  rep(i,H)rep(j,W){
    if(s[i][j]=='s'){
      si=i; sj=j;
    }
  }
  rep(i,H)rep(j,W)a[i][j]=b[i][j]=INF;
  {
    queue<P> que;
    rep(i,H)rep(j,W){
      if(s[i][j]=='g'){
        que.push(P(i,j));
        a[i][j]=0;
      }
    }
    while(que.size()){
      P p=que.front(); que.pop();
      rep(d,4){
        int ni=p.fi+dd[d],nj=p.se+dd[d+1];
        if(ni<0||ni>=H||nj<0||nj>=W||s[ni][nj]=='#'||s[ni][nj]=='*'||a[ni][nj]!=INF)continue;
        a[ni][nj]=a[p.fi][p.se]+1;
        que.push(P(ni,nj));
      }
    }
  }
  {
    queue<P> que;
    rep(i,H)rep(j,W){
      if(s[i][j]=='*'){
        que.push(P(i,j));
        b[i][j]=0;
      }
    }
    while(que.size()){
      P p=que.front(); que.pop();
      rep(d,4){
        int ni=p.fi+dd[d],nj=p.se+dd[d+1];
        if(ni<0||ni>=H||nj<0||nj>=W||s[ni][nj]=='#'||s[ni][nj]=='g'||b[ni][nj]!=INF)continue;
        b[ni][nj]=b[p.fi][p.se]+1;
        que.push(P(ni,nj));
      }
    }
  }

  rep(i,H)rep(j,W){
    if(s[i][j]=='s'||s[i][j]=='.')ts.push_back(P(i,j));
  }
  sort(all(ts),[=](const P& t1,const P& t2){ return a[t1.fi][t1.se]-b[t1.fi][t1.se] < a[t2.fi][t2.se]-b[t2.fi][t2.se]; });

  bool oc=true;
  long double res=a[si][sj];
  long double suma=0,sumb=0;
  ll T=ts.size();
  rep(i,T)sumb+=b[ts[i].fi][ts[i].se];
  repl(M,1,T+1){
    ll i=ts[M-1].fi,j=ts[M-1].se;
    suma+=a[i][j];
    sumb-=b[i][j];
    long double sumE=((long double)(T-M)*suma+(long double)T*sumb)/(long double)M;
    if(s[i][j]=='s')oc=false;
    if(oc)minch(res,suma/(long double)T+sumE/(long double)T+b[si][sj]);
  }
  printf("%.10Lf\n", res);

  return 0;
}



Measured memory_bytes: 11336
N = int(input())
A = list(map(int, input().split()))
forward = [0]*N
forward[0] = A[0]
total = sum(A)
m = 10**12
for i in range(1, N):
    forward[i] = forward[i-1] + A[i]
for i in range(N-1):
    tmp = total - forward[i]
    diff = abs(tmp - forward[i])
    m = min(diff, m)

print(m)


Measured memory_bytes: 26220
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

// dijkstra O(ElogV)
// verify : https://onlinejudge.u-aizu.ac.jp/problems/GRL_1_A
template<typename T>
struct Dijkstra {
private:
    int V;
    struct edge { int to; T cost; };
    vector<vector<edge>> G;
public:
    const T inf = numeric_limits<T>::max();

    // s から i の最小コスト
    // 経路がない場合は inf
    vector<T> d;

    Dijkstra(int V) : V(V) {
        G.resize(V);
    }

    // 辺の追加
    // 有向の場合　directed = true
    void add_edge(int from, int to, T weight, bool directed = false) {
        G[from].push_back({to,weight});
        if (!directed) G[to].push_back({from,weight});
    }

    void build(int s) {
        d.assign(V, inf);
        typedef pair<T, int> P; //(cost,v)
        priority_queue<P, vector<P>, greater<P>> pq;
        d[s] = 0;
        pq.push(P(d[s], s));

        while (!pq.empty()) {
            P p = pq.top(); pq.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (const edge &e : G[v])
            {
                // 最小値が更新されるとき push
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    pq.push({d[e.to], e.to});
                }
            }
        }
    }
};

int main() {
    int n, x, y; cin >> n >> x >> y;
    x--; y--;
    Dijkstra<ll> G(n);
    for (int i = 0; i < n - 1; i++) {
        G.add_edge(i, i + 1, 1);
    }
    G.add_edge(x, y, 1);
    vector<int> ans(n, 0);
    for (int i = 0; i < n; i++) {
        G.build(i);
        for (int j = i + 1; j < n; j++) {
            ans[G.d[j]]++;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main(){
  
  int n,m;//N種類の商品とM個の人気商品 //A
  int sum = 0;
  int count = 0;
  
  cin >> n >>m;
  vector<int> a(n);
  for(int i=0;i<n;i++){ //N個数分の商品
    cin >> a[i];
    sum += a[i];
  }
  
  for(int j=0;j<n;j++){
    if(a[j]*4*m >= sum){
      count++;
    }
  }
  
  if(count >= m){
    cout << "Yes" << endl;
  }else {
	cout << "No" << endl;
  }
  return 0;
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main()
{
  int n, m;
  
  cin >> n >> m;
  int ans = 0;
  if (n >= 2) {
    ans += n * (n - 1) / 2;
  }
  if (m >= 2) {
    ans += m * (m - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(a: int, b: int, x: int):
    ans = b // x
    if a > 0:
        ans -= (a - 1) // x
    else:
        ans += 1
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    solve(a, b, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9124
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 10
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on
int N;
double x[MAX_N];
char u[MAX_N][4];
const double btc = 380000.0;

void solve()
{
  double ans = 0.0;
  for (int i = 0; i < N; i++) {
    if (strcmp(u[i], "BTC") == 0) {
      ans += x[i] * btc;
    }
    else {
      ans += x[i];
    }
  }
  printf("%.6f\n", ans);
}

int main(void)
{
  cin >> N;
  REP(i, N) cin >> x[i] >> u[i];
  solve();
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    int n;
    char buf[30];

    //標準入力から一行をbufに格納
    fgets(buf, sizeof(buf), stdin);

    n = atoi(buf);
    
    if ((n>10) | (n<1))
    {
        return 0;
    }
    else
    {
        n = n + n * n + n * n * n;
    }
    
    

    //標準入力に書き出す
    printf("%d\n", n);
    return 0;
}

Measured memory_bytes: 1668
# Proglem https://atcoder.jp/contests/abc082/tasks/abc082_b
# Python 2nd Try


yes = "Yes"
no = "No"


def solver(sstr, tstr):
    result = True
    sfirst_str = ''.join(sorted(list(sstr)))
    tend_str = ''.join(reversed(sorted(list(tstr))))
    if sfirst_str < tend_str:
        result = True
    else:
        result = False
    return result


if __name__ == "__main__":
    s = input()
    t = input()
    if solver(s, t):
        print(yes)
    else:
        print(no)


Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [i64; n-1]
    };

    let mut buf = vec![0; n];

    for a in a {
        buf[(a - 1) as usize] += 1
    }

    for buf_iter in buf.iter() {
        println!("{}", buf_iter)
    }
}


Measured memory_bytes: 5544
//
// Created by 芹川武尊 on 2019/09/04.
//

#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

unsigned int H, W;

void dfs(int i, int j, vector<vector<char> >& m) {
    char tmp = m[i][j];
    m[i][j] = '.';
    if (j + 1 < W) {
        if (tmp == m[i][j+1]) dfs(i, j+1, m);
    }
    if (i + 1 < H) {
        if (tmp == m[i+1][j]) dfs(i+1, j, m);
    }
    if (j - 1 >= 0) {
        if (tmp == m[i][j-1]) dfs(i, j-1, m);
    }
    if (i - 1 >= 0) {
        if (tmp == m[i-1][j]) dfs(i-1, j, m);
    }
}

int solve() {
    vector<vector<char> > m(H, vector<char>(W, ' '));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> m[i][j];
        }
    }

    int tmp;
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (m[i][j] != '.') {
                ans++;
                dfs(i, j, m);
            }
        }
    }
    cout << ans << endl;
}

int main() {
    while(true) {
        cin >> H >> W;
        if (H == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

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

    ll x = n - 1;
    ll ans = 1;
    for (ll i = 2; i * i <= n; i++) {
        ll cnt = 0;
        while (x % i == 0) {
            cnt++;
            x /= i;
        }
        ans *= cnt + 1;
    }
    if (x != 1) ans *= 2;
    ans--;

    for (ll i = 2; i * i <= n; i++) {
        ll x = n;
        if (x % i == 0) {
            while (x % i == 0) {
                x /= i;
            }
            if (x % i == 1) ans++;
        }
    }
    ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nmr = readln.split.to!(int[]);
    auto N = nmr[0];
    auto M = nmr[1];
    auto R = nmr[2];
    auto rs = readln.split.to!(int[]).map!"a - 1"().array();
    sort(rs);
    auto MAP = new long[][](N, N);
    foreach (ref map; MAP) map[] = long.max/3;
    foreach (_; 0..M) {
        auto abc = readln.split.to!(int[]);
        auto A = abc[0]-1;
        auto B = abc[1]-1;
        long C = abc[2];
        MAP[A][B] = C;
        MAP[B][A] = C;
    }

    foreach (k; 0..N) foreach (i; 0..N) foreach (j; 0..N) if (MAP[i][j] > MAP[i][k] + MAP[k][j]) MAP[i][j] = MAP[i][k] + MAP[k][j];

    long res = long.max;
    do {
        long rr;
        foreach (i; 1..R) rr += MAP[rs[i-1]][rs[i]];
        res = min(res, rr);
    } while (nextPermutation(rs));

    writeln(res);
}

Measured memory_bytes: 1276
#!/usr/bin/python3
import itertools

def print_boad(boad):
    b = [['.' for i in range(8)] for j in range(8)]
    for q in boad:
        b[q[0]][q[1]] = 'Q'

    for i in range(8):
        print(''.join(b[i]))


def find_next(base, exist_r, exist_c, exist_lt, exist_rt, invalid):
    if len(base) == 8:
        print_boad(base)
        exit()
    all_set = set(range(8))
    rest_r = all_set - exist_r
    rest_c = all_set - exist_c
    for r, c in itertools.product(rest_r, rest_c):
        if r - c in exist_lt:
            continue
        if r - (7 - c) in exist_rt:
            continue

        find_next(
                base | {(r, c)},
                exist_r | {r},
                exist_c | {c},
                exist_lt | {r - c},
                exist_rt | {r - (7 - c)},
                invalid)
        invalid.add((r, c))

    return False



# main

k = int(input())
boad = set()
exist_r = set()
exist_c = set()
exist_lt = set()
exist_rt = set()
invalid = set()
for i in range(k):
    r, c = map(int, input().split())
    boad.add((r, c))
    exist_r.add(r)
    exist_c.add(c)
    exist_lt.add(r - c)
    exist_rt.add(r - (7 - c))


find_next(boad, exist_r, exist_c, exist_lt, exist_rt, invalid)

Measured memory_bytes: 7844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<vi> g(h + 2, vi(w + 2, -1));
  rep2(i, 1, h + 1) rep2(j, 1, w + 1) cin >> g[i][j];
  vector<vi> ans;
  rep2(i, 1, h + 1) rep2(j, 1, w + 1) {
    if(g[i][j] % 2 == 0 || (i == h && j == w)) continue;
    vi s(4);
    s[0] = i;
    s[1] = j;
    if(i < h) {
      g[i + 1][j]++;
      s[2] = i + 1;
      s[3] = j;
    } else {
      g[i][j + 1]++;
      s[2] = i;
      s[3] = j + 1;
    }
    ans.push_back(s);
  }
  cout << ans.size() << endl;
  rep(i, ans.size()) rep(j, 4) cout << ans[i][j] << (j == 3 ? '\n' : ' ');
}

Measured memory_bytes: 9904
#include<cstdio>

using namespace std;

int main(){
	int c[3][3];
	for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) scanf("%d", &c[i][j]);
	int b1 = c[0][0], b2 = c[0][1], b3 = c[0][2];
	if(c[1][0] - b1 == c[1][1] - b2 && c[1][1] - b2 == c[1][2] - b3 &&
	c[2][0] - b1 == c[2][1] - b2 && c[2][1] - b2 == c[2][2] - b3) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("avx,avx2,fma,sse,sse2")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
ll a,b;
typedef tree<int, null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> new_data;

int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    while(true)
    {
        ll x=1;
        while(x<=n)x*=2;
        ans=x-1;
        break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3652
s = int(input())
mod = 10**9+7

tmp = s
amari = tmp % 3
tmp //= 3
#print(tmp)

ans = 0


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = s
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

while tmp >= 1:
    #print(tmp,111,amari)
    ans += cmb(amari+tmp-1,tmp-1,mod)
    ans %= mod
    #print(ans,333,tmp,amari)
    amari += 3
    tmp -= 1
    #print(ans)
    
print(ans%mod)

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

using namespace std;

int main(){
	string str;
	cin >> str;
	sort(str.begin(),str.end());
	vector<bool> a(26,false);
	for(char i = 'a'; i <= 'z'; i++){
		char c = *lower_bound(str.begin(),str.end(),i);
		if(c == i)a[(int)i-'a']=true;
	}
	int ans = -1;
	for(int i = 0; i < 26; i++){
		if(!a[i]){
			ans = i;
			break;
		}
	}
	if(ans == -1)cout << "None" << endl;
	else{
		char ac = 'a' + ans;
		cout << ac << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<complex>
#define inf 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define pii pair<int,int> 
const int N=1e6+10;
const int mod=998244353;
using namespace std;
 

void solve(){
    string s; cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) puts("Yes");
    else puts("No");
}
int main() 
{
    int _=1;  //scanf("%d",&_);
    while(_--) solve();
return 0;
}
/*
*/
 

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b;
    char op;
    
    while(1){
        scanf("%d %c %d",&a, &op, &b);
        
        if(op=='+') printf("%d\n",a+b);
        else if(op=='-') printf("%d\n",a-b);
        else if(op=='*') printf("%d\n",a*b);
        else if(op=='/') printf("%d\n",a/b);
        else break;
    }
    
    return 0;
    
}


Measured memory_bytes: 2132
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int w, d;

	void run(){
		for(;;){
			w=sc.nextInt();
			d=sc.nextInt();
			if((w|d)==0){
				break;
			}
			int n=w+d;
			LinkedList<Integer> a=new LinkedList<Integer>();
			LinkedList<Integer> b=new LinkedList<Integer>();
			for(int i=0; i<w; i++){
				a.add(sc.nextInt());
			}
			for(int i=0; i<d; i++){
				b.add(sc.nextInt());
			}
			for(int e : a){
				if(b.contains(e)){
					b.remove((Integer)e);
				}
			}
			int ans=0;
			for(int e : a){
				ans+=e;
			}
			for(int e : b){
				ans+=e;
			}
			println(""+ans);
		}
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();

	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
//#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

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

const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N,K,Q;
    cin>>N>>K>>Q;
    vector<int> score(N,K-Q);
    for(int i=0;i<Q;i++){
        int a;
        cin>>a;
        score[a-1]++;
    }
    for(int i=0;i<N;i++){
        cout<<((score[i]>0)?"Yes":"No")<<endl;
    }
}

Measured memory_bytes: 1024
n = int(input())
list_B = list(map(int, input().split()))
list_A = [list_B[0]]
for i in range(len(list_B)-1):
  list_A.append(min(list_B[i], list_B[i+1]))
list_A.append(list_B[-1])
print(sum(list_A))

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

vec a(100010);
ll row = 0;
void line_s(ll bit){
    ll id = -1;
    reps(i,row,N) if((a[i]>>bit)&1) id = i;
    //cout<<bit<<' '<<id<<endl;
    if(id == -1) return;
    swap(a[row], a[id]);
    rep(i,N) if((i != row) && (((a[i]>>bit)&1))) a[i] ^= a[row];
    ++row;
    return;
}

int main() {
    cin>>N;
    M = 0;
    rep(i,N) {
        cin>>a[i];
        M ^= a[i];
    }
    for(ll i = 59; i >= 0; --i) if((((M>>i)&1) == 0) && (row < N)) line_s(i);
    ll ans = 0;
    rep(i,row) ans ^= a[i];
    cout<<(ans|M)*2 - M<<endl;
    //cout<<M<<' '<<ans<<endl;
}


Measured memory_bytes: 1024
#!/usr/bin/ruby

a = gets.chomp.to_i
b = gets.chomp.to_i

if [a,b].include?(1) and [a,b].include?(2)
 puts 3
elsif [a,b].include?(2) and [a,b].include?(3)
 puts 1
elsif [a,b].include?(1) and [a,b].include?(3)
 puts 2
end


Measured memory_bytes: 1788
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long int
#define mod 998244353
int power[200001];
int g;
void function2()
{
	power[0]=1;
	int j;
	for(j=1;j<=200000;j++)
	{
		power[j]=(10*power[j-1])%mod;
	}
}
int fast_power(int a,int b)
{
	if(b==0)
	  return 1;
	else
	{
		int r=fast_power(a,b/2);
		if(b%2==0)
		{
			return (r*r)%mod;
		}
		else
		{
			int x=(r*r)%mod;
			return (a*x)%mod;
		}
	}
}
int sum(int left,int right)
{
	int val1=power[left];
	int val2=power[right-left+1]-1;
	val1*=val2;
	val1%=mod;
	val1*=g;
	val1%=mod;
	return val1;
}
void build_tree(int tree[],int start,int end,int n,int index)
{
	if(start==end)
	{
		int here=power[n-1-start];
		tree[index]=here;
		return ;
	}
	else
	{
		int mid=(start+end)>>1;
		build_tree(tree,start,mid,n,2*index);
		build_tree(tree,mid+1,end,n,2*index+1);
		tree[index]=tree[2*index]+tree[2*index+1];
		tree[index]%=mod;
	}
}
void update(int tree[],int lazy[],int start,int end,int left,int right,int d,int n,int index)
{
	if(lazy[index]!=0)
	{
		tree[index]=lazy[index]*sum(n-1-end,n-1-start);
		tree[index]%=mod;
		if(start!=end)
		{
			lazy[2*index]=lazy[index];
			lazy[2*index+1]=lazy[index];
		}
		lazy[index]=0;
	}
	if(left>end||start>right)
	   return ;
	if(start>=left&&end<=right)
	{
		tree[index]=d*sum(n-1-end,n-1-start);
		tree[index]%=mod;
		if(start!=end)
		{
			lazy[2*index]=d;
			lazy[2*index+1]=d;
		}
		return ;
	}
	else
	{
		int mid=(start+end)>>1;
		update(tree,lazy,start,mid,left,right,d,n,2*index);
		update(tree,lazy,mid+1,end,left,right,d,n,2*index+1);
		tree[index]=tree[2*index]+tree[2*index+1];
		tree[index]%=mod;
	}
}
int sum_query(int tree[],int lazy[],int start,int end,int left,int right,int n,int index)
{
	if(lazy[index]!=0)
	{
		tree[index]=lazy[index]*sum(n-1-end,n-1-start);
		tree[index]%=mod;
		if(start!=end)
		{
			lazy[2*index]=lazy[index];
			lazy[2*index+1]=lazy[index];
		}
		lazy[index]=0;
	}
	if(left>end||start>right)
	  return 0;
	if(start>=left&&end<=right)
	   return tree[index];
	else
	{
		int mid=(start+end)>>1;
		int x=sum_query(tree,lazy,start,mid,left,right,n,2*index);
		int y=sum_query(tree,lazy,mid+1,end,left,right,n,2*index+1);
		return (x+y)%mod;
	}
}
int32_t main()
{
	function2();
	g=fast_power(9,mod-2);
	int n,q;
	scanf("%lld%lld",&n,&q);
	int tree[4*n+1]={0},lazy[4*n+1]={0};
	build_tree(tree,0,n-1,n,1);
	while(q--)
	{
		int l,r,d;
		scanf("%lld%lld%lld",&l,&r,&d);
		l--;
		r--;
		update(tree,lazy,0,n-1,l,r,d,n,1);
		int answer=sum_query(tree,lazy,0,n-1,0,n-1,n,1);
		printf("%lld\n",answer);
	}
}


Measured memory_bytes: 17844