akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 2e5 + 7;
const LL inf = 1e18;
int n;
int ch[N][2], c[N], val[N][2];
typedef pair<LL, LL> pii;
vector<pii> S[N];
void dfs(int u, LL mid) {
	if(!ch[u][0]) { S[u].pb(make_pair(0, 0)); return;}
	int &Ls = ch[u][0], &Rs = ch[u][1];
	dfs(Ls, mid);
	dfs(Rs, mid);
	
	if(S[Ls].size() > S[Rs].size()) swap(Ls, Rs), swap(val[u][0], val[u][1]);
	sort(S[Ls].begin(), S[Ls].end(), greater<pii>());
	sort(S[Rs].begin(), S[Rs].end());
//	printf("%d %d %d\n", u, S[Ls].size(), S[Rs].size());
	LL mi = inf;
	for(int i = 0, j = 0; i < S[Ls].size(); ++i) {
		for(; j < S[Rs].size() && S[Ls][i].first + S[Rs][j].first + val[u][0] + val[u][1] <= mid; ++j) {
			Min(mi, S[Rs][j].second);
		}
		if(mi != inf) {
			S[u].pb(make_pair(S[Ls][i].second + val[u][0], mi + val[u][1]));
			S[u].pb(make_pair(mi + val[u][1], S[Ls][i].second + val[u][0]));
		}
	}
}
bool check(LL mid) {
	rep(i, 1, n) S[i].clear();
	dfs(1, mid);
	return !S[1].empty();
}
int main() {
#ifdef fwat
//	freopen("data.in", "r", stdin);
#endif
	n = gi();
	rep(i, 2, n) {
		int x = gi(), v = gi();
		ch[x][c[x]] = i;
		val[x][c[x]++] = v;
	}
	LL l = 0, r = 1ll << 34, ret;
	while(l <= r) {
		LL mid = l + r >> 1;
		if(check(mid)) ret = mid, r = mid - 1;
		else l = mid + 1;
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 30452
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int h, n;
int a[1001], b[1001];

int dp[10001];

int solve() {
    for (int i = 1; i <= h; i++) {
        dp[i] = inf;
        for (int j = 0; j < n; j++) {
            int hp = max(0, i - a[j]);
            dp[i] = min(dp[i], dp[hp] + b[j]);
        }
    }
    return dp[h];
}

void input() {
    cin >> h >> n;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main(){
    unordered_map<string, int> mp;
    vector<vector<int>> index(1,vector<int>());
    string str;
    vector<string> what;
    int page, pages = 1;
    while(cin >> str >> page){
        if(mp[str] == 0){
            mp[str] = pages;
            vector<int> newin(1, page);
            index.push_back(newin);
            what.push_back(str);
            pages++;
        }
        else{
            index[mp[str]].push_back(page);
        }
    }
    sort(what.begin(), what.end());
    for(int i = 0;i<what.size();i++){
        str = what[i];
        sort(index[mp[str]].begin(), index[mp[str]].end());
        cout << str << endl;
        for (int i = 0; i < index[mp[str]].size();i++){
            if(i == index[mp[str]].size()-1){
                cout << index[mp[str]][i] << endl;
            }
            else{
                cout << index[mp[str]][i] << " ";
            }
        }
    }
    return 0;
}

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

using ll = long long;

// 再帰関数による最大公約数
ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a, b;
  cin >> a >> b;
  
  ll c = gcd(a, b);
  
  vector<ll> x;
  for (ll i = 1; i * i <= c; i++) {
    if (c % i == 0) {
      bool check = true;
      for (int j = 0; j < x.size(); j++) {
        if (gcd(i, x.at(j)) != 1) check = false;
      }
      if (check) x.emplace_back(i);
    }
  }
  
  for (ll i = sqrt<ll>(c); i > 0; i--) {
    if (c % i == 0) {
      ll k = c / i;
      bool check = true;
      for (int j = 0; j < x.size(); j++) {
        if (gcd(k, x.at(j)) != 1 || (k == x.at(j))) check = false;
      }
      if (check) x.emplace_back(k);
    }
  }
  
  cout << x.size() << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i=s; i<t; ++i)
#define pb push_back
using namespace std;
using P = pair<int,int>;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef tuple<int,int,int> T;
typedef vector<P> vp;
typedef vector<T> vt;

int main(void) {
  string s,t;
  cin >> s >> t;
  t.erase(t.end()-1);
  if(s==t){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3600
use std::io::stdin;

fn main(){
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let nm:Vec<i32> = st.split_whitespace().map(|x| x.parse().unwrap()).collect();

    let mut result:i32 = 0;

    let mut array:Vec<i32> = [-1; 5].to_vec();

    let mut s:Vec<i32> = Vec::with_capacity(nm[1] as usize);
    let mut t:Vec<i32> = Vec::with_capacity(nm[1] as usize);
    for _ in 0..*&nm[1] {
        let mut st = String::new();
        stdin().read_line(&mut st).unwrap();
        let st:Vec<i32> = st.split_whitespace().map(|x| x.parse().unwrap()).collect();   
        s.push(st[0]);
        t.push(st[1]);    
    };

    for i in 0..*&nm[1] {
        let i = i as usize;
        if nm[0] > 1 && s[i]==1 && t[i]==0 {
            result = -1;
            break;
        } else if array[s[i] as usize] < 0 {
            array[s[i] as usize] = t[i];
            result += t[i]*(10_i32.pow((nm[0]-s[i]) as u32));
        } else {
            if array[s[i] as usize] == t[i] {
                continue;
            } else {
                result = -1;
                break;
            };
        };
    };

    if result < 0 {
        println!("-1");
    } else if nm[0]==1 {
        println!("{}", result);
    } else if nm[1] == 0 {
        println!("{}", 10_i32.pow((nm[0]-1) as u32));
    } else {
        if array[1] < 0 {
            result += 10_i32.pow((nm[0]-1) as u32);
        };
        println!("{}", result);
    };
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int cnt=0;
  
  
  for(int i=0; i<s.size(); i++){
    if(s[i] != s[s.size() - i - 1]){
      cnt++;
    }
  }
  
  
    
  
  cout << cnt/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

using WG = map<int,map<int,ll>>; // weighted graph
// verified with https://beta.atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_d
const ll inf=1e15;
void dijkstra(int s, WG& g, vector<ll>& dist) {
  vector<bool> visited(dist.size());
  fill(dist.begin(),dist.end(),inf);
  using P = pair<ll,int>;
  priority_queue<P,vector<P>, greater<P>> pq;
  dist[s]=0;
  //visited[s]=true;
  pq.push(make_pair(0LL,s));
  while(!pq.empty()) {
    int v;
    ll d;
    tie(d,v)=pq.top();
    pq.pop();
    if(visited[v]) continue;
    visited[v]=true;
    for(auto& uw : g[v]) {
      int u;
      ll w;
      tie(u,w)=uw;
      if(visited[u]) continue;
      if(d+w<dist[u]) {
        dist[u]=d+w;
        pq.push(make_pair(dist[u],u));
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,m;
  cin>>n>>m;
  vector<int> p(m);
  vector<int> q(m);
  vector<int> c(m);
  rep(i,m) cin>>p[i]>>q[i]>>c[i];
  int id=0;
  vector<pair<int,int>> nodes;
  rep(i,n) {
    nodes.push_back(make_pair(i+1,0));
  }
  rep(i,m) {
    nodes.push_back(make_pair(p[i],c[i]));
    nodes.push_back(make_pair(q[i],c[i]));
  }
  map<pair<int,int>,int> ids;
  rep(i,nodes.size()) {
    ids[nodes[i]]=i;
  }
  // build graph
  WG g;
  rep(i,m) {
    g[ids[make_pair(p[i],c[i])]][ids[make_pair(q[i],c[i])]]=0;
    g[ids[make_pair(q[i],c[i])]][ids[make_pair(p[i],c[i])]]=0;
    g[ids[make_pair(p[i],c[i])]][ids[make_pair(p[i],0)]]=1;
    g[ids[make_pair(p[i],0)]][ids[make_pair(p[i],c[i])]]=1;
    g[ids[make_pair(q[i],c[i])]][ids[make_pair(q[i],0)]]=1;
    g[ids[make_pair(q[i],0)]][ids[make_pair(q[i],c[i])]]=1;
  }
  int N=nodes.size();
  vector<ll> dist(N);
  dijkstra(ids[make_pair(1,0)],g,dist);
  if(dist[ids[make_pair(n,0)]]!=inf) {
    cout << dist[ids[make_pair(n,0)]]/2 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 167148
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
int a=0,b=0;
string s;
signed main()
{
	cin>>s;
	rep(i,s.size()){
		if(s[i]=='0'){
			a++;
		}else{
			b++;
		}
	}
	cout<<min(a,b)*2;
}

Measured memory_bytes: 512
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	ans := 0
	for i := 0; i < N; i++ {
		a := nextInt()
		ok := true
		for ok {
			if a%2 == 0 {
				ans++
				a /= 2
			} else {
				ok = false
				break
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1944
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const ll mod = 1000000000 + 7; //10^9

int main() {
    vector<char> A(3);
    for (int i = 0; i < 3; i++)
    {
        cin >> A[i];
        
    }
    if (A[1] == 'R')
    {
        if(A[0] == 'R' && A[2] == 'R'){
            cout << 3 ;
            return 0;
        }
        if (A[0] == 'R' || A[2] == 'R')
        {
            cout << 2 ;
            return 0;
        }
        else{
        cout << 1;
        return 0;
        }
    }
    else {
        if (A[0] == 'R' || A[2] == 'R')
        {
            cout << 1 ;
            return 0;
        }
        else {
            cout << 0;
        }
    }


    
    
    
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long 
#define endl '\n'
#define debug(x)  cout<<x<<" ";
// #define for(i,n) for(i=0;i<n;i++)
#define fastInOut   ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
using namespace std;

int main() {
    fastInOut
    string s;
    cin>>s;
    int c=0;
    for(int i=0,j=s.size()-1;i<j;i++,j--)
       if(s[i]!=s[j])
          c++;
    cout<<c;
    return 0;
}

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

int main(){
    int n ,a ,b ,c, d;
    
    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >> a >> b >> c >>d;
        if(c>=5&&d>=2) cout << (a*c+b*d)*0.8 << endl;
        else if(c<5&&d>=2&&a*c+b*d>(a*5+b*d)*0.8) cout << (a*5+b*d)*0.8 << endl;
        else if(d<2&&c>=5&&a*c+b*d>(a*c+b*2)*0.8) cout << (a*c+b*2)*0.8 << endl;
        else if(d<2&&c<5&&a*c+b*d>(a*5+b*2)*0.8) cout << (a*5+b*2)*0.8 << endl;
        else cout<< a*c+b*d << endl;
    }
    
    return 0;
}

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


int main(){
    int a,b,k;cin >> a >> b >> k;
    for (int i = min(a,b); i >= 1; i--) {
        if(a%i==0&&b%i==0) k--;
        if(k==0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,H,W;
    cin >>N>>H>>W;
    cout << (N-H+1)*(N-W+1) <<endl;
    return (0);
}

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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        char[] data = S.toCharArray();
        int[] cnt = new int[26];
        for (int i = 0; i < data.length; i++) {
            cnt[data[i]-'a'] += 1;
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < 26; i++) {
            ans = Math.min(ans, solve(data, (char)(i + 'a')));
        }
        System.out.println(ans);
    }
    private int solve(char[] data, char target) {
        int count = 0;
        while (true) {
            boolean found_other = false;
            for(int i = 1; i < data.length; i++) {
                if (data[0] != data[i]) {
                    found_other = true;
                    break;
                }
            }
            if (!found_other) {
                break;
            }
            char[] new_data = new char[data.length-1];
            for (int i = 0; i < data.length-1; i++) {
                if (data[i+1] == target) {
                    new_data[i] = target;
                    continue;
                }
                new_data[i] = data[i];
            }
            count += 1;
            data = new_data;
        }
        return count;
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
 
using namespace std;

int main(){
    ll a, b, c; cin >> a >> b >> c;
    if(4*a*b < (c-a-b)*(c-a-b) && c > (a+b)) cout << "Yes";
    else    cout << "No";
}

Measured memory_bytes: 3616
h, w = map(int, input().split())

area = []

for i in range(h+2):
    if i == 0 or i == h+1:
        array = '.' * (w+2)
    else:
        array = input()
        array = '.' + array + '.'
    area.append(array)

def check(i, j):
    if area[i][j-1] == '#' or area[i][j+1] == '#' or area[i-1][j] == '#' or area[i+1][j] == '#':
        return True
    else:
        return False

for i in range(1, h+1):
    for j in range(1, w+1):
        if area[i][j] == '#':
            if not check(i, j):
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
N=int(input())
restaurants=[]
name=""
score=0
for i in range(N):
    name,score=input().split()
    score=int(score)
    restaurants.append([name,score,i+1])
restaurants=sorted(restaurants,key=lambda x:x[1],reverse=True)
restaurants.sort(key=lambda x:x[0])
for i in range(N):
    print(restaurants[i][2])



Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    ll a,b;
    
    ll ans = 0, y = 0;

    cin >> a >> b;

    ((a+b) % 2 == 0) ? (cout << (a+b)/2 << endl) : (cout << "IMPOSSIBLE" << endl);
}



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

int main(){
	int n, x;
	cin >> n >> x;
	if(x == 1 || x == 2 * n - 1){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	if(x <= n){
		for(int i = 1; i <= n; i++) if(i != x && i != x - 1) cout << i << endl;
		cout << x - 1 << endl << x << endl;
		for(int i = n + 1; i < 2 * n; i++) cout << i << endl;
	}else{
		x = 2 * n - x;
		for(int i = 1; i <= n; i++) if(i != x && i != x - 1) cout << 2 * n - i << endl;
		cout << 2 * n - x + 1 << endl << 2 * n - x << endl;
		for(int i = n + 1; i < 2 * n; i++) cout << 2 * n - i << endl;
	}
}

Measured memory_bytes: 1536
from functools import lru_cache
N = int(input())
S = input()
X = int(S, 2)

P = S.count('1')
if P == 0:
    for i in range(N):
        print(1)
    exit()

Rp = X % (P+1)
if P != 1:
    Rn = X % (P-1)

@lru_cache(None)
def popcnt(x):
    return bin(x).count('1')

for i in range(N):
    if S[i] == '1':
        if P == 1:
            print(0)
            continue
        p = P-1
        x = (Rn - pow(2, N-1-i, p)) % p
    else:
        p = P+1
        x = (Rp + pow(2, N-1-i, p)) % p

    cnt = 1
    while x:
        x %= popcnt(x)
        cnt += 1
    print(cnt)


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

namespace Lsk {
#define _auto_ template <typename T>

// fast io
#define writesp(x) (write(x), putchar(' '))
#define writeln(x) (write(x), putchar('\n'))
_auto_ inline void read(T &x) {
	x = 0; bool sgn = false; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (sgn = true), ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	if(sgn) x = -x;
}
_auto_ inline void write(T x) {
	if(x < 0) putchar('-'), x = -x;
	static char buf[40]; int o = 0;
	for(x; x > 9; x /= 10, ++o) buf[o] = x % 10 + '0'; buf[o] = x + '0';
	for(o; ~o; --o) putchar(buf[o]);
	return;
}

// cmin / cmax / swap
_auto_ inline void cmin(T &u, const T v) { if(u > v) u = v; }
_auto_ inline void cmax(T &u, const T v) { if(u < v) u = v; }
_auto_ inline T min(const T u, const T v) { return u < v ? u : v; }
_auto_ inline T max(const T u, const T v) { return u > v ? u : v; }
_auto_ inline void swap(T &u, T &v) { T tmp(u); u = v, v = tmp; }

// math
const int mod = 998244353, mod_2 = 1996488706;
//const int mod = 1000000007, mod_2 = 2000000014;
//const int mod = 1000000009, mod_2 = 2000000018;
_auto_ inline T abs(T x) { return x > 0 ? x : -x; }
_auto_ inline T gcd(T u, T v) {	return v ? gcd(v, u % v) : u; }
_auto_ inline T Mod(T u) { return u >= mod_2 ? u % mod : (u > mod ? u - mod : u); }
_auto_ inline T inmod(T u) { return u >= mod ? u - mod : (u < 0 ? u + mod : u); }
inline long long fpm(long long base, long long mi) {
	long long res = 1;
	while(mi) {
		if(mi & 1) res = Mod(res * base);
		base = Mod(base * base), mi >>= 1;
	}
	return res;
}

} using namespace Lsk;

int A, B;


int main() {
	read(A), read(B);
	if(A > 9 || B > 9) {
		puts("-1");
		return 0;
	}
	writeln(A * B);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long n = sc.nextLong();
		long k = sc.nextLong();
		
		// 計算
		long result = 0;
		while(true){
		    if(n >= k){
		        n = n%k;
		    }else{
		        if(n > abs(n-k)) n = abs(n-k);
		        break;
		    }
		}
		result = n;
		
		// 出力
		System.out.println(result);
	}
}



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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<vector<int> > edge;

	cin >> N;
	edge.resize(N+1);
	int a,b;
	for(int i = 0; i < N-1; i++){
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	vector<bool> use(N+1,false);
	queue<int> f,s;
	f.push(1), s.push(N);
	use[1] = true, use[N] = true;
	int fmasu = 1, smasu = 1;
	for(int i = 0; f.size() || s.size(); i++){
		queue<int> next, check = i&1 ? s : f;
		while(check.size()){
			int now = check.front();
			check.pop();
			for(int j = 0; j < edge[now].size(); j++)
				if(!use[edge[now][j]])
					next.push(edge[now][j]), use[edge[now][j]] = true;
		}

		if(i&1)
			s = next, smasu += next.size();
		else
			f = next, fmasu += next.size();
	}
	// cerr << fmasu << " " << smasu << endl;

	if(fmasu > smasu)
		cout << "Fennec" << endl;
	else
		cout << "Snuke" << endl;

	return 0;
}

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

using namespace std;

typedef pair<int, int> P;

int M, N;
char c[555][555];

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

int beatPanel()
{
  int ret = 0;
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < N; j++) {
      if(c[i][j] != '.') continue;
      vector<P> pos(30, P(-1, -1));
      for(int k = 0; k < 4; k++) {
	int nx = j + dx[k], ny = i + dy[k];
	while(0 <= nx && nx < N && 0 <= ny && ny < M && c[ny][nx] == '.') {
	  nx += dx[k], ny += dy[k];
	}
	if(0 <= nx && nx < N && 0 <= ny && ny < M) {
	  int idx = c[ny][nx] - 'A';
	  if(pos[idx].first != -1) {
	    int px = pos[idx].second, py = pos[idx].first;
	    c[ny][nx] = '.';
	    c[pos[idx].second][pos[idx].first] = '.';
	    ret += 2;	    
	  } else {
	    pos[idx] = P(nx, ny);
	  }
	}
      }
    }      
  }
  return ret;
}

int main()
{
  cin >> M >> N;
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < N; j++) cin >> c[i][j];
  }
  int ans = 0;
  while(int get = beatPanel()) ans += get;

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

Measured memory_bytes: 3376
#include <stdio.h>
#include <string.h>
 
int main()
{
    char s[100001];
    char s1[100001];
    scanf("%s",&s);
    long int i,cnt1=0,cnt2=0;
    long int l=strlen(s);
    strcpy(s1,s);
    for(i=0;i<l-1;++i)
      {
          if(s[i]==s[i+1])
             {
                 if(s[i]=='1') 
                   {
                       s[i+1]='0';
                       cnt1++;
                   }
                   
                 else
                   {
                       s[i+1]='1';
                       cnt1++;
                   }
             }
      }

      
   for(i=l-1;i>=0;--i)
      {
          if(s1[i]==s1[i-1])
             {
                 if(s1[i]=='1') 
                   {
                       s1[i-1]='0';
                       cnt2++;
                   }
                   
                 else
                   {
                       s1[i-1]='1';
                       cnt2++;
                   }
             }
      }
  
        
  
     if(cnt1<=cnt2)
       printf("%d",cnt1);
       
    else
       printf("%d",cnt2);
 
}


Measured memory_bytes: 384
#include<stdio.h>
#define N 100001
  
void Partition(int A[], int p, int q){
  int x, i, j;
  int temp;
  
  x = A[q];
  i = p-1;
  
  for(j = p; j <= q-1; j++){
    if(A[j] <= x){
      i = i + 1;
 
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
 
    }
  }
 
  temp = A[i + 1];
  A[i + 1] = A[q];
  A[q] = temp;

  for(j = 0; j <= q; j++){
    if(j == i + 1) printf("[%d]", A[j]);
    else printf("%d", A[j]);
    if(j != q) printf(" ");
  }
  printf("\n");
 
}
  
int main(){
  int n, i, p = 0, q;
  int A[N];
  
  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  q = n - 1;
  
  Partition(A, p, q);
  
  return 0;
}

Measured memory_bytes: 992
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using namespace chrono_literals;
  chrono::high_resolution_clock clock;
  auto be = clock.now();
  int D;
  cin >> D;
  array<int, 26> c;
  for (auto& e : c) cin >> e;
  vector<array<int, 26>> d(D);
  for (auto& r : d)
    for (auto& e : r) cin >> e;
  auto eval = [&](vector<int> t) {
    int S = 0;
    array<int, 26> last = {};
    for (int i = 0; i < D; ++i) {
      S += d[i][t[i]];
      last[t[i]] = i + 1;
      for (int j = 0; j < 26; ++j) S -= c[j] * (i + 1 - last[j]);
    }
    return S;
  };
  mt19937 mt(random_device{}());
  uniform_int_distribution<int> dist_type(0, 25), dist_day(0, D - 1);
  uniform_real_distribution<> dist(0, 1);
  double eps = 0.25;
  vector<int> t(D);
  for (int i = 0; i < D; ++i) t[i] = i % 26;
  int S = eval(t);
  int cnt = 0;
  while (clock.now() - be < 1950ms) {
    bool f = dist(mt) < eps / (cnt / 100);
    int day1 = dist_day(mt);
    int day2 = dist_day(mt);
    int prv = 0;
    if (f) {
      prv = t[day1];
      t[day1] = dist_type(mt);
    } else
      swap(t[day1], t[day2]);
    int score = eval(t);
    if (score > S) {
      S = score;
      continue;
    }
    if (f)
      t[day1] = prv;
    else
      swap(t[day1], t[day2]);
  }
  for (const auto& e : t) cout << (e + 1) << '\n';
}


Measured memory_bytes: 3740
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CMarks {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, K;
        cin >> N >> K;
        vector<int> A(N);
        REP(i, N) cin >> A[i];
        int sum = 0;
        REP(i, K) {
            sum += A[i];
        }
        vector<bool> res;
        FOR(i, K, N-1) {
            int prev = sum;
            sum -= A[i-K];
            sum += A[i];
            res.push_back(sum > prev);
        }
        for (auto val : res) cout << (val ? "Yes" : "No") << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CMarks solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 4772
from heapq import heappush, heappop

x,y,z,k = map(int,input().split())
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
c_ls = list(map(int, input().split()))
a_ls.sort(reverse=True)
b_ls.sort(reverse = True)
c_ls.sort(reverse = True)

hq = []
arg_hash = {}
val = a_ls[0] + b_ls[0] + c_ls[0]
# 第二引数は、(その要素の値、要素)
heappush(hq, (-val, 0,0,0))

for i in range(k):
    ans, a,b,c = heappop(hq)
    print(-ans)

    arg_a = (a+1,b,c)
    arg_b = (a,b+1,c)
    arg_c = (a,b,c+1)

    if a < x - 1 and arg_a not in arg_hash:
        arg_hash[arg_a] = 1
        # リストの足し算みたいな感じ
        heappush(hq, (-(a_ls[a+1] + b_ls[b] + c_ls[c]),) + arg_a)
    if b < y - 1 and arg_b not in arg_hash:
        arg_hash[arg_b] = 1
        heappush(hq, (-(a_ls[a] + b_ls[b+1] + c_ls[c]),) + arg_b)
    if c < z - 1 and arg_c not in arg_hash:
        arg_hash[arg_c] = 1
        heappush(hq, (-(a_ls[a] + b_ls[b] + c_ls[c+1]),) + arg_c)
    

Measured memory_bytes: 4768
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>

using namespace std;

int N;
int A, B, C;
int INF = 10000;
vector<int> ls;

int solve(int a, int b, int c, int current) {

    if (current == N) {
        if (min(min(a, b), c) > 0) {
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        } else {
            return INF;
        }
    }

    return min(
            solve(a + ls[current], b, c, current + 1) + 10,
            min(solve(a, b + ls[current], c, current + 1) + 10,
                min(solve(a, b, c + ls[current], current + 1) + 10,
                    solve(a, b, c, current + 1)))
    );


}

int main() {

    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) {
        int l;
        cin >> l;
        ls.push_back(l);
    }

    int result = solve(0, 0, 0, 0);

    cout << result << "\n";

    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll N;
vector<string> ans;
void dfs(ll cur, string s, ll num){
    if(cur == N-1){
        ans.push_back(s);
        return;
    }
    map<char,ll> mp;
    for(auto &c: s) mp[c]++;
    ll n = min(cur+2, num+1);

    rep(i,0,n){
        char c = (char)('a' + i);
        string t = s + c;
        if(mp[c] == 0){
            dfs(cur+1, t, num+1);
        }else{
            dfs(cur+1, t, num);
        }
    }
}

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

    cin >> N;
    dfs(0, "a", 1);
    sort(ans.begin(), ans.end());
    for(auto &e: ans) print(e);
}

Measured memory_bytes: 9716
from collections import Counter
import math
import sys
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result


arr_data = getinputdata()

x = int(arr_data[0][0])
y = int(arr_data[0][1])

cnt = 0

while x <= y:
    
    cnt += 1
    x = x * 2
    
    
    
print(cnt)    

Measured memory_bytes: 3316
def main():
    N = int(input())
    W = list(map(int, input().split()))
    ans = 10 ** 10

    for T in range(N - 1):
        S1 = sum(W[:T + 1])
        S2 = sum(W[T + 1:])
        diff = abs(S1 - S2)
        if diff < ans:
            ans = diff

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 63256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,D;
LL X[200000],Y[200000];

LL ans = 0;

void solve(){
  for(int i=0;i<N;i++){
    ans += ((X[i]*X[i]+Y[i]*Y[i])<=D*D);
  }
}

int main(){
    cin >> N >> D;
    for(int i=0;i<N;i++){
      cin >> X[i] >> Y[i];
    }

    solve();

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

Measured memory_bytes: 6316
#include <bits/stdc++.h>
#define rep(i,n) for ( int i = 0; i < (n); ++i )
using namespace std;
using ll = long long int;
const long long int INF = 1001001001001001LL;
const int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;


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

    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<int> dp(n, inf);
    dp[0] = 0;
    rep(i, n) {
        rep(j, 2) {
            int nj = i-(j+1);
            if(nj >= 0) dp[i] = min( dp[i], dp[nj] + abs(h[i] - h[nj]) );
        }
    }
    
    cout << dp[n-1] << endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n;
  cin>>n;
  FOR(i, 1, 10){
    FOR(j, 1, 10){
      if(i*j==n){
        cout<<"Yes"<<'\n';
        return 0;
      }
    }
  }
  cout<<"No"<<'\n';
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  int ans=0;

  if(S.at(0)=='1') ans++;
  if(S.at(1)=='1') ans++;
  if(S.at(2)=='1') ans++;

  cout << ans << endl;

return 0;  
}

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

int main() {

	int N,M;
	cin>>N>>M;
  if(N==0&&M<100){cout<<M<<endl;}
  else if(N==1&&M<100){cout<<100*M<<endl;}
  else if(N==2&&M<100){cout<<10000*M<<endl;}
  else if(N==0){cout<<101<<endl;}
    else if(N==1){cout<<10100<<endl;}
  else if(N==2){cout<<1010000<<endl;}

	
	//cout<< <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}


//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main() {
ll n;
cin>>n;
map<ll,ll>rensou;
ll a;
for(ll i=0;i<n;i++){
    cin>>a;
    rensou[a-1]++;
    rensou[a+1]++;
    rensou[a]++;
}
ll ans=0;
for(auto f:rensou){
    chmax(ans,f.second);
}
cout<<ans<<endl;
}








Measured memory_bytes: 6144
/* ----------------------- reclone_rk --------------------------------------------*/ 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;

#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define prq priority_queue<int>
#define prqp priority_queue<pair<int,int>>
#define vtr vector<int>
#define INF INT_MAX
#define NINF INT_MIN
#define endl "\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pvtr vector<pair<int,int>>
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)

int gcd(int a, int b){ if(a == 0) return b; return gcd(b%a, a);}
int MOD(int n){ return ((n%mod)+mod)%mod;}
int power(int a,int b){ if(b==0)return 1LL;int s=power(a,b/2LL);s*=s;s%=mod;if(b&1LL)return (s*a)%mod;return s;}
int inv(int a){return power(a,mod-2);}
int nCr(int n,int r){if(r>n)return 0LL;if(n-r<r)r=n-r;int ans=1;for(int i=0;i<r;i++){ans*=(n-i);ans=MOD(ans);ans*=inv(i+1);ans=MOD(ans);}return ans;}

int pi = 3.14159265358979323846;

bool check(int n, vector<int>d)
{
    while(n)
    {
        int rem = n%10;
        for(int j=0; j<d.size(); j++)
        {
            if(d[j] == rem)
                return false;
        }
        n = n/10;
    }
    return true;
}
signed main()
{   
    int n, k;
    cin>>n>>k;
    vector<int>d(k);
    for(int i=0; i<k; i++)
    {
        int dg;
        cin>>dg;
        d[i] = dg;
    }
    while(1)
    {
        if(check(n, d) == true)
        {
            cout<<n<<endl;
            break;
        }
        else
            n++;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 1e18;
const ll fact_table = 5000000;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
vector<ll> R[550010];
vector<pair<ll, double> > tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<"\n";
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 998244353;
//ll mod = 1000000007;
 
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);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,f,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];
char s[500005];
bool used[500005];
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> a >> b;
    if(abs(a - b) % 2 == 0){
        ans = abs(a - b) / 2;
    }else{
        ll ans1, ans2;
        ans1 = (a - 1) + 1 + (b - a - 1) / 2;
        ans2 = (n - b) + 1 + (b - a - 1) / 2;
        ans = min(ans1, ans2);
    }
    p(ans);
    

    

    
    return 0;
}















Measured memory_bytes: 38144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define MAX_C 1000000001

int main() {
  int n;
  cin >> n;
  vector<int> buka(n, 0);
  
  for (int i = 0; i < n-1; i++) {
    int t;
    cin >> t;
    t--;
    buka[t]++;
  }

  for (int i: buka) {
    cout << i << endl;
  }
}


Measured memory_bytes: 4056
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <bitset>

using namespace std;

#define NMAX 200


int n;
int blue[NMAX][NMAX], red[NMAX][NMAX];
int aux1, aux2;
vector<int> adj[2*NMAX];
//int index;

std::bitset<NMAX> vis;
array<int, NMAX> match;

bool augment(int u){
  if (vis[u])
    return(false);
  vis[u] = true;
  for (int v : adj[u]){
    if (match[v] == -1 || augment(match[v])){
      match[v] = u;
      return(true);
    }
  }
  return(false);
}


signed main(int argc, char *argv[]) {
  int index = 1;

  cin >> n;

  for(int i=0; i<n;++i){
    for(int j=0; j<n;++j){
      red[i][j] = blue[i][j] = 0;
    }
  }

  for(int i=0; i<n;++i){
    cin >> aux1 >> aux2;
    red[aux1][aux2] = index;
    index++;
  }
  for(int i=0; i<n;++i){
    cin >> aux1 >> aux2;
    blue[aux1][aux2] = index;

    for (int k=0;k<aux1; ++k){
      for (int l=0;l<aux2; ++l){
        if (red[k][l]){

          adj[red[k][l]-1].push_back(index-1);
          adj[blue[k][l]-1].push_back(index-1);
          //cout << k<<" "<<l<<"."<<aux1<<" "<<aux2<<endl;

        }

      }
    }

    index++;

  }


  // Computations
  // create adj
  /*
  for (int i=0; i<n; ++i){//blue
    for (int j=0; j<n; ++j){
      for (int k=0; k<i; ++k){// red
        for (int l=0; l<j; ++l){

          if (red[k][l] and blue[i][j]){
            adj[red[k][l]-1].push_back(blue[i][j]-1);
            adj[blue[k][l]-1].push_back(red[i][j]-1);
            cout << k<<" "<<l<<"."<<i<<" "<<j<<endl;
          }
        }
      }
    }
  }
  */

  // compute
  int mcbm = 0;
  std::vector<int> no_match;
  match.fill(-1);
  for(int u=0; u<n; u++){
    vis.reset();
    if (augment(u))
      mcbm++;
    else
      no_match.push_back(u);
  }

  cout << mcbm<<endl;

  return 0;
}


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

using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
using str = string;
using bl = bool;
using ch = char;

template<class T> using v = vector<T>;
template<class T> using uset = unordered_set<T>;
template<class T1, class T2> using umap = unordered_map<T1, T2>;

template<class T> void pd(T x)
{
    cout << x << " ";
}
template<class T> void pl(T x)
{
    cout << x << endl;
}

#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define sz(x) ((int)(x).size())
#define ph push_back
#define pp pop_back
#define mp make_pair
#define rep(i, a) for(int i = 0; i < (int)a; ++i)
#define repd(i, a) for(int i = (int)a; i >= 0; --i)
#define REP(i, a, b) for(int i = a; i < (int)b; ++i)
#define REPD(i, a, b) for(int i = (int)a; i >= b; --i)
#define fore(i, a) for(auto& i : a)
#define FORE(i, a) for(auto i : a)
#define PI 3.14159265358979323846264338327950L

// -----

int main()
{
    ll a, b;
    cin >> a >> b;
    pl(a * b);
}

Measured memory_bytes: 3620
A = int(input())
B = int(input())

if A == 1 and B == 2:
    print(3)

if A == 1 and B == 3:
    print(2)

if A == 2 and B == 1:
    print(3)

if A == 2 and B == 3:
    print(1)

if A == 3 and B == 1:
    print(2)

if A == 3 and B == 2:
    print(1)


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

int main(){
  ll a,b,c;
  cin >> a >> b;
  c = __gcd(a,b);
  
  int cnt = 1;
  for (int i=2; i <= sqrt(c); i++) {
    if (c%i==0) {
      cnt++;
      while (c%i==0) {
        c/=i;
      }
    }
  }
  
  if (c != 1) cnt++;
  
  cout << cnt << endl;
}

Measured memory_bytes: 256