akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define MAXN (100010)

int n, k;
int l[MAXN], r[MAXN];
bool has[MAXN];
std::vector<int> mat[MAXN];

bool union_seg(int &lu, int &ru, int lv, int rv, int odd, bool &mark){
	if(!mark){
		lu = lv;
		ru = rv;
		mark = true;
	}
	else{
		lu = std::max(lu, lv);
		ru = std::min(ru, rv);
	}
	if(lu > ru || lu == ru && (lu & 1) != odd) return false;
	return true;
}

bool dfs1(int u, int fa, int odd){
	if(has[u] && (l[u] & 1) != odd){
		return false;
	}
	for(auto v : mat[u]){
		if(v == fa) continue;
		if(!dfs1(v, u, !odd)){
			return false;
		}
		if(!union_seg(l[u], r[u], l[v] - 1, r[v] + 1, odd, has[u])){
			return false;
		}
	}
	if(!has[u]){
		l[u] = - 1e9;
		r[u] =   1e9;
	}
	return true;
}

bool inseg(int x, int l, int r){
	return l <= x && x <= r;
}

void dfs2(int u, int fa){
	for(auto v : mat[u]){
		if(v == fa) continue;
		if(inseg(l[u] + 1, l[v], r[v])){
			l[v] = l[u] + 1;
			dfs2(v, u);
		}
		else if(inseg(l[u] - 1, l[v], r[v])){
			l[v] = l[u] - 1;
			dfs2(v, u);
		}
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i < n; ++ i){
		int u, v;
		scanf("%d%d", &u, &v);
		mat[u].push_back(v);
		mat[v].push_back(u);
	}
	scanf("%d", &k);
	for(int i = 1; i <= k; ++ i){
		int v, p;
		scanf("%d%d", &v, &p);
		l[v] = r[v] = p;
		has[v] = true;
	}
	int root;
	for(root = 1; !has[root]; ++ root);
	if(!dfs1(root, 0, l[root] & 1)){
		return printf("No\n"), 0;
	}
	dfs2(root, 0);
	printf("Yes\n");
	for(int i = 1; i <= n; ++ i){
		printf("%d\n", l[i]);
	}
	return 0;
}

Measured memory_bytes: 15104
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cstring>
#include <functional>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <array>
#include <complex>

#define endl '\n'

using namespace std;

const int BITS = 60;

void solve()
{
    int n;
    cin >> n;

    vector<long long> A(n);

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

    string s;
    cin >> s;

    reverse(A.begin(), A.end());
    reverse(s.begin(), s.end());

    vector<long long> gauss(BITS);

    auto add = [&](long long cur) {
        for (int i = BITS - 1; i >= 0; --i)
        {
            if (cur >> i & 1)
            {
                if (gauss[i] == 0)
                {
                    gauss[i] = cur;
                    return true;
                }
                else
                {
                    cur ^= gauss[i];
                }
            }
        }

        return false;
    };

    for (int i = 0; i < n; ++i)
    {
        if (s[i] == '0')
        {
            add(A[i]);
        }
        else
        {
            if (add(A[i]))
            {
                cout << 1 << endl;
                return;
            }
        }
    }

    cout << 0 << endl;
}

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

    int t;
    cin >> t;

    for (int i = 0; i < t; ++i)
    {
        solve();
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
const int inf=1e9+1;
ll max(ll a, ll b)
 { return (a > b)? a : b; }

/*ll knapsack (ll n,ll k, ll w[], ll v[])
{
    ll ar[n+1][k+1];
    for (ll i=0;i<=n;i++)
   {
       for (ll j=0;j<=k;j++)
       {
          if (i==0 || j==0)
            ar[i][j]=0;
          else if (w[i-1]>j)
            ar[i][j]=ar[i-1][j];
              else
                ar[i][j]=max(v[i-1]+ar[i-1][j-w[i-1]],ar[i-1][j]);
         }
    }
    return ar[n][k];
}
*/

void lcs(ll n,ll m,string s,string t)
{
    ll ar[n+1][m+1],maxi=0;
    for (ll i=0;i<=n;i++)
    {
        for (ll j=0;j<=m;j++)
        {
            if (i==0 || j==0)
                ar[i][j]=0;
            else if (s[i-1]==t[j-1])
                {ar[i][j]=1+ar[i-1][j-1];
                }
            else
                ar[i][j]=max(ar[i-1][j],ar[i][j-1]);
        }
    }
    ll p=ar[n][m];
    char k[p+1];
    k[p] = '\0'; // Set the terminating character

   // Start from the right-most-bottom-most corner and
   // one by one store characters in lcs[]
   int i = n, j = m;
   while (i > 0 && j > 0)
   {

      if (s[i-1] == t[j-1])
      {
          k[p-1] = s[i-1];
          i--; j--; p--;
      }


      else if (ar[i-1][j] > ar[i][j-1])
         i--;
      else
         j--;
   }

   // Print the lcs
   cout << k;
}
int main(){

   string s,t;
   cin >> s >> t;
   ll n=s.size(),m=t.size();

   lcs(n,m,s,t);
    return 0;
}




Measured memory_bytes: 70656
import sys
input = sys.stdin.readline

n, m, q = map(int,input().split())
A = [list(map(int,input().split())) for i in range(q)]
# global ans0
ans0 = []


def c(L):
    if len(L) == n:
        ans = 0
        for i in range(q):
            if L[A[i][1]-1] - L[A[i][0]-1] == A[i][2]:
                ans += A[i][3]
        ans0.append(ans)
        
    elif len(L) == 0:
        for i in range(1, m+1):
            c([i])
    else:
        for i in range(L[-1], m+1):
            c(L + [i])

c([])
print(max(ans0))

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

int main()
{
    std::vector<int> times(5);
    for (int i = 0; i < 5; i++) {
        std::cin >> times[i];
    }

    std::vector<int> first_place(5);
    for (int i = 0; i < 5; i++) {
        first_place[i] = times[i] % 10;
    }

    int last_idx;
    for (int i = 0; i < 5; i++) {
        if (first_place[i]) {
            last_idx = i;
            break;
        }
    }

    for (int i = 0; i < 5; i++) {
        if (first_place[i] && first_place[i] < first_place[last_idx]) {
            last_idx = i;
        }
    }

    int ans = 0;
    for (int i = 0; i < 5; i++) {
        if (i != last_idx) {
            if (times[i] % 10) {

                ans += times[i] + 10 - times[i] % 10;
            } else {
                ans += times[i];
            }
        } else {
            ans += times[i];
        }
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n,m,ans,cnt;
struct data {
  int l,r;
} ordl[N],ordr[N];
bool cmpl(data a,data b) {
  return a.l < b.l;
}
bool cmpr(data a,data b) {
  return  a.r < b.r;
}
struct node {
  int mx,tag;
} t[N << 2];
void puttag(int x,int val) {
  t[x].mx += val;
  t[x].tag += val;
}
void push_down(int x) {
  puttag(x<<1,t[x].tag);
  puttag(x<<1|1,t[x].tag);
  t[x].tag = 0;
}
void push_up(int x) {
  t[x].mx = max(t[x<<1].mx,t[x<<1|1].mx);
}
void modify(int l,int r,int val,int x=1,int lp=1,int rp=m) {
  if (l > rp || r < lp) return;
  if (lp >= l && rp <= r) {
    puttag(x,val);
    return;
  }
  if (t[x].tag) push_down(x);
  int mid = (lp + rp) >> 1;
  modify(l,r,val,x<<1,lp,mid);
  modify(l,r,val,x<<1|1,mid+1,rp);
  push_up(x);
}
int query(int l,int r,int x=1,int lp=1,int rp=m) {
  if (l > rp || r < lp) return 0;
  if (lp >= l && rp <= r) return t[x].mx;
  if (t[x].tag) push_down(x);
  int mid = (lp + rp) >> 1;
  return max(query(l,r,x<<1,lp,mid),query(l,r,x<<1|1,mid+1,rp));
}
int main() {
  int a,b;
  scanf("%d%d",&n,&m);
  ans = max(0,n - m);
  cnt = n;
  for (int i = 1 ; i <= cnt ; ++ i) {
    scanf("%d%d",&a,&b);
    a ++;
    b --;
    if (a > b) {
      i --, cnt --;
      continue;
    }
    ordl[i] = (data) {a,b};
    ordr[i] = (data) {a,b};
  }
  sort(ordl+1,ordl+cnt+1,cmpl);
  sort(ordr+1,ordr+cnt+1,cmpr);
  int pl = 1, pr = 1;
  for (int i = 1 ; i <= m ; ++ i) {
    modify(1,i,1);
    for (; ordl[pl].l <= i && pl <= cnt ; ++ pl)
      modify(ordl[pl].l,m,1);
    ans = max(ans,query(1,i) - m);
    for (; ordr[pr].r <= i && pr <= cnt ; ++ pr)
      modify(ordr[pr].l,m,-1);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 9728
N, T = map(int, input().split())
# 美味しさのMAX
Tmax = 6000
dp = [[-1] * (Tmax) for i in range(N+1)]
dp[0][0] = 0

q = []
for i in range(N):
    q.append(list(map(int, input().split())))
q.sort()

for i in range(N):
    dp[i+1][:] = dp[i][:]
    a,b = q[i]
    for j in range(T):    
        if dp[i][j] >= 0:
            dp[i+1][a+j] = max(dp[i][a+j], dp[i][j] + b)
print(max(dp[N]))



Measured memory_bytes: 180316
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    repeat(i, N) cin >> A[i];
    long long B = 0;
    map<int, int> ModM;
    ModM[0]++;
    repeat(i, N) {
        B = (A[i] + B) % M;
        ModM[B]++;
    }
    long long res = 0;
    for (auto P : ModM) {
        long long num = P.second;
        res += num * (num - 1) / 2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6468
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	for(int n; cin >> n, n != 0; ) {
		string name[20];
		int times[20][30];
		int mi[20];
		rep(i, n) {
			cin >> name[i];
			cin >> mi[i];
			rep(j, mi[i]) cin >> times[i][j];
		}
		
		int ans[20] = {};
		rep(a, n) rep(b, mi[a]) {
			int cnt = 0;
			rep(c, n) if (a != c) rep(d, mi[c]) {
				if (times[a][b] == times[c][d]) cnt++;
			}
			ans[a] += n - cnt;
		}
		
		int t = ans[0];
		string s = name[0];
		rep(i, n) {
			if (t > ans[i]) {
				t = ans[i];
				s = name[i];
			}
			if (t == ans[i]) if (s > name[i]) s = name[i];
		}
		cout << t << ' ' << s << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	llint a, b, c;
	cin >> a >> b >> c;
	if (a > b)swap(a, b);
	if (b > c)swap(b, c);
	if (a > b)swap(a, b);
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << a*b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k <= a) {
    cout << k;
  }
  if (a < k and k <= a + b) {
    cout << a;
  }
  if (a + b < k and k <= a + b + c) {
    cout << a + ((k - a - b) * -1);
  }
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
void change(){

}
int main(){
    string S;
    string T;
    char s;
    cin >> S >> T;
    int count=0;
    int N,tmp;
    N=S.size();
    while(true){
        if(S==T){
            cout << "Yes" << endl;
            break;
        }
        else if(count>104){
            cout << "No" << endl;
            break;
        }
        tmp=S.at(0);
        for(int i=0; i<N-1; i++)
            S.at(i)=S.at(i+1);
        S.at(N-1)=tmp;
      count++;

    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
using namespace std;
int a[100010];
int b[100010];
int c[500010];
int x,y;
int A,B,C;
int cmp(int a,int b)
{
    return a>b;
}
int main()
{
    cin>>x>>y>>A>>B>>C;
    for(int i=0;i<A;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<B;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i<C;i++)
    {
        cin>>c[i];
    }
    sort(a,a+A,cmp);
    sort(b,b+B,cmp);
    for(int i=0;i<x;i++)
    {
        c[i+C]=a[i];
    }
    for(int i=0;i<y;i++)
    {
        c[i+C+x]=b[i];
    }
    sort(c,c+C+x+y,cmp);
    ll sum=0;
    for(int i=0;i<x+y;i++)
    {
        sum+=c[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 5520
#include <iostream>
#include <cassert>
//#define NDEBUG

/* 横線 #出力 */
void OutputWidthLine(int w){
	using namespace std;
	for (int j = 0; j < w; j++){			/* 横幅分の# */
		cout << "#";
	}
		cout << "\n";						/* 改行 */
}

/* 縦線 #出力 (内部の.含む) */
void OutputHeightLine(int h, int w){
	using namespace std;
	for (int i = 0; i < h-2; i++){			/* 高さ-2(上辺と下辺を除く) */
		cout << "#";						/* 左端の# */
		for (int j = 0; j < w-2; j++){		/* 横幅-2(左辺と右辺を除く) */
				cout << ".";
		}
		cout << "#\n";						/* 右端の# と 改行 */
	}
}

int main(void){
	using namespace std;
	static const int INPUT_H_MIN = 3;	/* 前提は3以上だが、入力終了時は0 */
	static const int INPUT_H_MAX = 300;
	static const int INPUT_W_MIN = 3;	/* 前提は3以上だが、入力終了時は0 */
	static const int INPUT_W_MAX = 300;
	int input_h = 0;
	int input_w = 0;
	
	while(1){
		/* 高さHと横幅Wを入力 */
		cin >> input_h >> input_w;
		
		/* 入力値が、  両方0(入力終了時) or 前提条件 最大・最小の制限内の入力 */
		assert ((input_h == 0 && input_w == 0 ) || (INPUT_H_MIN <= input_h && input_h <= INPUT_H_MAX));
		assert ((input_h == 0 && input_w == 0 ) || (INPUT_W_MIN <= input_w && input_w <= INPUT_W_MAX));

		if(input_h == 0 && input_w == 0 ){
			break;
		}
		else{
			/* 出力 */
			OutputWidthLine(input_w);				/* 横線 ##### */
			OutputHeightLine(input_h, input_w);		/* 縦線 #...# (高さ-2行分繰り返す)*/
			OutputWidthLine(input_w);				/* 横線 ##### */
			cout << "\n";					/* データセット間の空行 */
		}
	}
	
	return 0;
}



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

#define ll long long int

int main()
{
    int n;
    cin>>n;
    int t;
    t=n;

    int a=0, b=0, c=0, d=0;
    while(t--){
        string s;
        cin>>s;
        if(s=="AC"){
            a++;
        }
        if(s=="WA"){
            b++;
        }
        if(s=="TLE"){
            c++;
        }
        if(s=="RE"){
            d++;
        }

    }
    cout<<"AC"<<" " <<'x'<<" "<<a<<endl;
    cout<<"WA"<<" " <<'x'<<" "<<b<<endl;
    cout<<"TLE"<<" " <<'x'<<" "<<c<<endl;
    cout<<"RE"<<" " <<'x'<<" "<<d<<endl;
    return 0;
}



Measured memory_bytes: 3644
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b = rm()
print('Even' if a*b & 1 == 0 else 'Odd')















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

using namespace std;

int main() {
    string s;
    cin >> s;
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        string t;
        cin >> t;
        int tsize = t.size();
        t += t;
        bool flag = false;
        for (int j = 0; j < tsize; ++j) {
            if (t.substr(j, s.size()) == s) {
                flag = true;
                break;
            }
        }
        ans += (flag ? 1 : 0);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3144
N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
max = as.max
if max < K
  puts 'IMPOSSIBLE'
  exit 0
end

if as.include?(K)
  puts 'POSSIBLE'
  exit 0
end

n = as.reduce do |acc, a|
  acc.gcd(a)
end
puts(K % n == 0 ? 'POSSIBLE' : 'IMPOSSIBLE')


Measured memory_bytes: 8452
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_imports)]
use std::cmp;

fn main() {
    input!{
        n: u32,
        k: u32,
    }
    println!("{}", k * (k-1).pow(n-1));
}


Measured memory_bytes: 4352
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);


		String[] s = stdIn.next().split("");

		int[] a = new int[s.length+1];

		for(int i = 0; i < s.length; i++) {
			if(s[i].equals("<")) {
				a[i+1] = a[i]+1;
			}
		}

		for(int i = s.length-1; i>=0; i--) {
			if(s[i].equals(">")){
				a[i] = Math.max(a[i+1]+1, a[i]);
			}
		}

		long sum = 0;
		for(int i = 0; i < a.length; i++) {
			sum += a[i];
		}

		System.out.println(sum);
	}

}


Measured memory_bytes: 67032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		byte min, count = 0, arrayLength = Byte.parseByte(in.readLine());
		byte[] array = new byte[arrayLength];
		String[] strData = in.readLine().split(" ");
		for (int i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		}
		for (byte x = 0; x < arrayLength; x++) {
			min = x;
			for (byte y = (byte) (x + 1); y < arrayLength; y++) {
				if (array[min] > array[y]) {
					min = y;
				}
			}
			if (array[x] > array[min]) {
				byte temp = array[x];
				array[x] = array[min];
				array[min] = temp; 
				count++;
			}
		}
		for (int j = 0; j < arrayLength; j++) {
			if (j == arrayLength - 1) {
				sb.append(array[j]);
			} else {
				sb.append(array[j] + " ");
			}
		}
		System.out.println(sb);
		System.out.println(count);
	}
}

Measured memory_bytes: 17060
# -*- coding: utf-8 -*-
a = input()
b = input()
c = input()
x = input()

max_a = x / 500

count = 0
# print max_a
for i in range(0, min(a, max_a) + 1):
    rest = x - i * 500
    max_b = rest / 100
    # print rest, max_b
    for j in range(0, min(b, max_b) + 1):
        rest_c = rest - j * 100
        if rest_c <= c * 50:
            count += 1

print count


Measured memory_bytes: 2568
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int n,a[100],b;
    char c[1000];
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        scanf("%s",c);
        for(int i=0;i<n;i++)a[i]=0;
        b=0;
        for(int i=0;i<100;i++){
            if(c[i]=='S'){
                b+=a[i%n]+1;
                a[i%n]=0;
            }
            else if(c[i]=='L'){
                a[i%n]+=b+1;
                b=0;
            }
            else a[i%n]++;
        }
        sort(a,a+n);
        for(int i=0;i<n;i++)printf("%d ",a[i]);
        printf("%d\n",b);
    }
}


Measured memory_bytes: 2804
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
long long cycles[5001][5001]={0},nofcycles=0,cyclescore[5001]={0},used[5001]={0},lenofcycles[5001]={0};
int main(int argv,char* argc[]){
    long long n,k;
    scanf("%lld%lld",&n,&k);
    long long c[n];
    long long p[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&p[i]);
        p[i]--;
    }
    for(int i=0;i<n;i++){
        scanf("%lld",&c[i]);
    }
    for(int i=0;i<n;i++){
        if(used[i]==1){
            continue;
        }
        int z=0;
        long long tmp=i;
        while(used[tmp]==0){
            used[tmp]=1;
            cycles[nofcycles][z]=tmp;
            z++;
            cyclescore[nofcycles]+=c[tmp];
            tmp=p[tmp];
        }
        lenofcycles[nofcycles]=z;
        nofcycles++;
    }
    long long ans=-11451419198100000;
    for(int i=0;i<nofcycles;i++){
        long long tmp=0,res=k;
        if(cyclescore[i]>0){
            tmp=cyclescore[i]*(k/lenofcycles[i]-1);
            res=k%lenofcycles[i];
            res+=lenofcycles[i];
            
            for(int j=0;j<lenofcycles[i];j++){
                long long x=0;
                long long pos=cycles[i][j];
                for(int h=0;h<res;h++){
                    x+=c[pos];
                    pos=p[pos];
                    if(ans<x+tmp){
                        ans=(x+tmp);
                    }
                }
                
            }
        }else{
            for(int j=0;j<lenofcycles[i];j++){
                long long pos=cycles[i][j];
                long long x=0;
                for(int h=0;h<lenofcycles[i]&&h<k;h++){
                    x+=c[pos];
                    pos=p[pos];
                    if(ans<x+tmp){
                        ans=x+tmp;
                    }
                }
                
            }
        }
    }
    printf("%lld",ans);
    
    return 0;
}


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

int main() {
    int N, T, A; cin >> N >> T >> A;

    double best_temp = 1e9;
    int best_pos = -1;
    for (int i = 0; i < N; i++) {
        int h; cin >> h;
        double temp = T - h * 0.006;
        double diff = abs(temp - 1.0 * A);
        if (diff < best_temp) {
            best_temp = diff;
            best_pos = i + 1;
        }
    }
    cout << best_pos << endl;
}


Measured memory_bytes: 256
import           Control.Monad
import           Data.Maybe
import           Data.List
import qualified Data.ByteString.Char8         as BS

tuplify2 (x : y : _) = (x, y)
tuplify2 _           = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

main = do
    n    <- getInt
    nums <- map read . words <$> getLine
    print (solve nums)


solve xs = foldl1 (\x y -> (x + y) / 2) $ sort xs


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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

using namespace std;
int main(){
  string x;
  int a=0;
  cin>>x;
  for(int i=0;i<x.length();i++){
    a+=ctoi(x.at(i));
   // cout<<a<<endl;
  }
  if(a%9==0)
    cout<<"Yes";
  else if(x=="0")
    cout<<"Yes";
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3692
N, Q = map(int, input().split())

S = str(input())

L = []
for i in range(Q):
    l,r = map(int, input().split())
    L.append((l-1,r-1))
    
check = []
for i in range(N-1):
    if S[i:i+2] == "AC":
        check.append(i)
        
from bisect import bisect_left,bisect_right
for i in L:
    print(bisect_right(check, i[1]-1)-bisect_left(check, i[0]))

Measured memory_bytes: 19424
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =3001;
const int MOD =998244353;
int x[100000],y[100000],xr[100000],yr[100000],a[100000],mx,my;
vector<int> p[100000],q[100000];
bool used[100000];
bool dfs(int k){
  used[k]=true;
  for(auto&& i:p[x[k]]){
    if(used[i]){if(xr[i]!=xr[k]+a[i]-a[k]||yr[i]!=yr[k])return true;}
    else{
      xr[i]=xr[k]+a[i]-a[k];
      yr[i]=yr[k];
      mx=min(mx,xr[i]);
      my=min(my,yr[i]);
      if(dfs(i))return true;
    }
  }
  for(auto&& i:q[y[k]]){
    if(used[i]){if(yr[i]!=yr[k]+a[i]-a[k]||xr[i]!=xr[k])return true;}
    else{
      yr[i]=yr[k]+a[i]-a[k];
      xr[i]=xr[k];
      mx=min(mx,xr[i]);
      my=min(my,yr[i]);
      if(dfs(i))return true;
    }
  }
  return false;
}
  
  
signed main(){
  int R,C,n;
  cin>>R>>C>>n;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>a[i];x[i]--;y[i]--;
    p[x[i]].push_back(i);
    q[y[i]].push_back(i);
  }
  fill(used,used+n,false);
  for(int i=0;i<n;i++)if(!used[i]){
    mx=0;my=0;
    if(dfs(i)||-mx-my>a[i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

}

Measured memory_bytes: 23132
use itertools::iproduct;
use proconio::input;

fn main() {
    input! {
        k: usize,
    }
    let sum: usize = itertools::iproduct!(1..=k, 1..=k, 1..=k)
        .map(|(a, b, c)| num::integer::gcd(num::integer::gcd(a, b), c))
        .sum();
    println!("{}", sum);
}


Measured memory_bytes: 2160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int min = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (i == 0) {
                min = a[i];
                max = a[i];
                continue;
            }
            if (min > a[i]) {
                min = a[i];
            }
            if (max < a[i]) {
                max = a[i];
            }
        }

        double minCost = 0;
        for (int i = min; i < max; i++) {
            double cost = 0;
            for (int j = 0; j < n; j++) {
                cost += Math.pow(a[j] - i, 2);
            }
            if (i == min) {
                minCost = cost;
                continue;
            }
            if (cost < minCost) {
                minCost = cost;
            }
        }
        System.out.println((int) minCost);
    }

}


Measured memory_bytes: 21972
k = int(input())
kk = 0
ans = 0
for i in range(1, k+1):
    if i == 1:
        kk = 7
    else:
        kk = (kk * 10 + 7) % k
    if kk % k == 0:
        ans = i
        break
if ans:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9032
#include<bits/stdc++.h>
using namespace std;
#define Mod 1000000007
#define Maxn 2010

int n;
long long f[Maxn];

int main()
{
	scanf("%d", &n);
	if (n < 3) puts("0");
	else
	{
		for (int i=1; i<=n; i++) f[i]=1ll;
		for (int i=6; i<=n; i++)
			for (int j=3; j<=i-3; j++)
				f[i]=(f[i]+f[i-j])%Mod;
		// for (int i=1; i<=n; i++) printf("%d ", f[i]); puts("");
		printf("%lld\n", f[n]);
	}
}

Measured memory_bytes: 3816
#include <stdio.h>

int main(){
    int i,minj,j,k,N;
    int A[100];
    int count=0;
    
    scanf("%d",&N);

    
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
        }
         for(i=0;i<N-1;i++){
         minj = i;
         for(j=i;j<N;j++){
           if(A[j] < A[minj]){
             minj = j;
	 }
        
	 } if(i!=minj){
	 
	 k=A[i];
	 A[i]=A[minj];
	 A[minj]=k;
	count++;
	 }
	 }
	     for(i=0;i<N;i++){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
	     printf("\n");
	     printf("%d\n",count);
    
    return 0;
} 


Measured memory_bytes: 2108
#include<string>
#include<iostream>
#include<vector>

using namespace std;
int N,K;
string S;
int main(){
  cin >> N >> K;
  cin >> S;
  vector<int> data;
  if(S[0] == '0'){
    data.push_back(0);
  }
  for(int i=0;i<S.size();){
    int j = i;
    while(j < S.size() && S[j] == S[i]){
      j++;
    }
    data.push_back(j-i);
    i = j;
  }

  if(S.back() == '0'){
    data.push_back(0);
  }

  vector<int> sums((int)data.size() + 1,0);
  for(int i=0;i<data.size();i++){
    sums[i+1] = sums[i] + data[i];
  }

  int ret = 0;
  for(int left = 0; left < sums.size(); left += 2){
    int right = left + K * 2 + 1;
    if(right >= data.size()){
      right = (int) sums.size() - 1;
    }
    ret = max(ret,sums[right] - sums[left]);
  }

  cout << ret << endl;
}


Measured memory_bytes: 1272
def solve():
    H, W, A, B = map(int, input().split())
    if B <= H // 2 and A <= W // 2:
        for _ in range(B):
            print("0" * A + "1" * (W - A))
        for _ in range(H - B):
            print("1" * A + "0" * (W - A))
    else: print("No")
 
    return 0

if __name__ == "__main__":
    solve()

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;cin >>n;
    vector<int> a(n);
    REP(i,n)cin >> a[i];
    int ans = a[0];
    FOR(i,1,n){
        ans ^= a[i];
    }
    REP(i,n){
        cout << (ans^a[i]);
        if(i!=n-1)cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3948
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			
			HashMap<Integer, Integer> map = new HashMap<>();
			for(int i = 0; i < n; i++){
				if(!map.containsKey(data[i])){
					map.put(data[i], 1);
				}
				else{
					map.put(data[i], map.get(data[i]) + 1);
				}
			}
			
			ArrayList<Integer> list = new ArrayList<>();
			for(int i: map.keySet()){
				if(map.get(i) >= 2){
					list.add(i);
				}
			}
			Collections.sort(list);
			int temp = -1;
			boolean flg = false;
			for(int i = list.size() - 1; i >= 0; i--){
				if(map.get(list.get(i)) >= 4){
					if(temp != -1){
						System.out.println((long)list.get(i) * temp);
					}
					else{
						System.out.println((long)list.get(i) * list.get(i));
					}
					flg = true;
					break;
				}
				else if(map.get(list.get(i)) >= 2){
					if(temp == -1){
						temp = list.get(i);
					}
					else{
						System.out.println((long)temp * list.get(i));
						flg = true;
						break;
					}
				}
			}
			if(!flg){
				System.out.println(0);
			}
		}
	}



	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int x,y;
    cin >> x >> y;
    bool ok = true;
    if(y%2==1) ok = false;
    if(y<x*2) ok = false;
    if(y>x*4) ok = false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#include <chrono>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cstring>
#include <cassert>
#include <math.h>
using namespace std;

const int N = 3e3 + 10, mod = 998244353;

int n, s, arr[N];
int dp[N][N];
int inv, tot;

int fp(int a, int b) {
    int ret = 1;
    while(b) {
        if(b & 1) ret = 1ll * ret * a % mod;
        b >>= 1;
        a = 1ll * a * a % mod;
    }
    return ret;
}

int solve(int i, int sum) {
    if(sum == s) return tot;
    if(sum > s) return 0;
    if(i == n) return 0;
    if(dp[i][sum] != -1) return dp[i][sum];
    int ret = solve(i + 1, sum);
    ret = (ret + 1ll * inv * solve(i + 1, sum + arr[i]) % mod) % mod;
    return dp[i][sum] = ret;
}

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    inv = fp(2, mod - 2);
    int tc = 1;
    // scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        scanf("%d%d", &n, &s);
        tot = fp(2, n);
        for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
        memset(dp, -1, sizeof(dp));
        printf("%d\n", solve(0, 0));
    }
    return 0;
}

Measured memory_bytes: 39420
#include <stdio.h>

int selectionSort(int A[],int N){
    int i, j, t, sw = 0,minj;
    for(i = 0; i < N-1; i++){
        minj=i;
        for(j = i; j < N; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    if(i != minj){
        sw++;
    }
    }
    return sw;
}

int main(){
    int A[100],i,N,sw;

    scanf("%d",&N);
    for (i = 0; i < N; i++)
    {
        scanf("%d",&A[i]);
    }
    
    sw = selectionSort(A,N);

    for(i=0;i<N;i++){
        if(i>0){
            printf(" ");
        }
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long int lli;

//16進法
inline lli Reverse(lli n, int l, int r){
	lli ret = 0;
	for(int i=0; i<10; i++){
		lli num = n & 0b1111;
		n >>= 4;
		if(l<=i && i<=r){
			ret |= num << (4*(l+r-i));
		}else{
			ret |= num << (4*i);
		}
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	lli num[2] = {0, 0};
	for(int i=0; i<n; i++){
		lli a;
		cin >> a;
		num[0] |= a << (4*i);
		num[1] |= (lli)(i+1) << (4*i);
	}
	
	map<lli, int> step[2];
	for(int r=0; r<2; r++){
		set<lli> prev;
		prev.insert(num[r]);
		step[r][num[r]] = 0;
		for(int s=0; s<(n-1)/2; s++){
			set<lli> next;
			for(lli arr: prev){
				for(int i=0; i<n; i++){
					for(int j=i+1; j<n; j++){
						lli rev = Reverse(arr, i, j);
						if(step[r].count(rev) == 0){
							step[r][rev] = s+1;
							next.insert(rev);
						}
					}
				}
			}
			prev = next;
		}
	}
	
	int ans = n-1;
	for(auto itr: step[0]){
		if(step[1].count(itr.first) != 0){
			ans = min(ans, itr.second +step[1][itr.first]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 56356
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    そう甘くはないんだな〜w
*/

// from std...
use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, multinomial, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, Num, NumAssignOps, NumOps, One, Pow, Zero};
use permutohedron::Heap;
use proconio::{
    fastout, input, is_stdin_empty,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use rand::random;

pub const MOD10E9_7: usize = 1000000007;
pub const MOD99_: usize = 998244353;
pub const MAX: usize = std::usize::MAX;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 65;

// code...
// #[fastout]
fn main() {
    input! {
        s: Chars
    }

    let mut dp = vec![0];
    for (i, c) in s.into_iter().rev().map(|x| x.to_digit(10).unwrap() as usize).enumerate() {
        let p = *dp.last().unwrap_or(&0);
        dp.push((p + c * binary_powering(10, i, 2019)) % 2019);
    }

    // dbg!(&dp);

    let uc = unique_count(&dp);
    let ans = uc.into_iter().map(|x| x.1 * (x.1 - 1) / 2).sum::<usize>();
    println!("{}", ans);
}

/// 配列に含まれる要素(T: Ord + Copy)別にその個数を数えて
/// `BTreeMap<T, usize>`の形にして返す
pub fn unique_count<T: Ord + Copy>(v: &[T]) -> BTreeMap<T, usize> {
    let mut map = BTreeMap::new();
    for e in v {
        let h = map.entry(*e).or_insert(0);
        *h += 1;
    }
    map
}

/// 二分累乗法
/// `O(log n)`で累乗を求める
///
/// modを取らないときはmに0を指定
pub fn binary_powering(n: usize, r: usize, m: usize) -> usize {
    let mut a = n;
    let mut n = r;
    let mut res = 1usize;
    let m = if m != 0 { Some(m) } else { None };
    while n > 0 {
        if n & 1 != 0 {
            res *= a;
            if let Some(m) = m {
                res %= m
            }
        }
        a *= a;
        if let Some(m) = m {
            a %= m;
        }
        n >>= 1;
    }
    res
}


Measured memory_bytes: 4588
import math
import itertools

n, d = map(int, input().split())
x_list = [list(map(int, input().split())) for _ in range(n)]
count = 0
for y, z in itertools.combinations(x_list, 2):
    s = 0
    for i in range(d):
        s += (y[i] - z[i]) ** 2
    for i in range(1, int(math.sqrt(s)) + 1):
        if s == i ** 2:
            count += 1
            break
print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SMALLPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  int n;cin>>n;
  ll ans=1;
  string s;cin>>s;
  rep(i,n-1){
    if(s[i]!=s[i+1])ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
import math

K = int(input())

gcd2 = [[0 for i in range(K)] for i in range(K)]

for i in range(K):
  for j in range(K):
    gcd2[i][j] = math.gcd(i+1, j+1)
    
sum = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      sum += math.gcd(gcd2[i][j], k+1)
      
print(sum)

Measured memory_bytes: 9364
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>

using namespace std;

#define rip(i, n, s) for (long long i = (s);i < (long long)( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

int main(){
	ll n;
	cin >> n;
	ll ans = n-1;
	rip(i,1000001,1){
		if(n%i==0){
			ans =min(ans,n/i+i-2);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include<vector>
#include<cmath>

using namespace std;

int main(){
  int x;
  cin >> x;
  for(int k=x;k>0;k--){
    for(double i=1;i<100;i++){
      for(double j=2;j<10;j++){
        if(pow(i,j)==k){
          cout << k << "\n";
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 1148
adjacent = {"A" => ["A", "B", "D", "A"], "B" => ["B", "C", "E", "A"], "C" => ["C", "C", "F", "B"],
            "D" => ["A", "E", "G", "D"], "E" => ["B", "F", "H", "D"], "F" => ["C", "F", "I", "E"],
            "G" => ["D", "H", "G", "G"], "H" => ["E", "I", "H", "G"], "I" => ["F", "I", "I", "H"]}
while true
    n = gets.to_i
    break if n == 0
    s, t, b = gets.chomp.split
    arr = Array.new(n + 1){Hash.new(0)}
    arr[n][s] = 1
    n.downto(1){|i|
        arr[i].to_a.each{|k, v|
            adjacent[k].each{|x|
                case x
                when b then arr[i - 1][k] += v
                else arr[i - 1][x] += v
                end
            }
        }
    }
    puts arr[0][t] / arr[0].values.inject(:+).to_f
end


Measured memory_bytes: 6932
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=10005,M=1e9+7;
int n,A,B,C,ans,fac[N],inv[N];
inline int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)ans=ans*x%M;
	return ans;	
}
inline int c(int x,int y){
	if (x<y)return 0;
	if (x==y)return 1;
	return fac[x]*inv[y]%M*inv[x-y]%M;
}
signed main(){
	scanf("%lld%lld%lld%lld",&n,&A,&B,&C);
	fac[0]=inv[0]=1;
	if (B&1){
		puts("0");
		return 0;
	}
	B/=2;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*i%M;
	for (int i=1;i<N;i++)inv[i]=ksm(fac[i],M-2);
	for (int x=0;x<=C;x++)
		for (int p=0;p<=(C-x)/3;p++)
			(ans+=c(A,C-x-3*p)*c(A+p,p)%M*c(A+p+B,A+p)%M*c(B+x-1,B-1))%=M;
	printf("%lld\n",ans);	
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DPartition solver = new DPartition();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPartition {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long m = in.nextLong();
            long ans = 0;
            for (long i = 1; i * i <= m; i++) {
                if (m % i == 0) {
                    long a = m / i;
                    long b = i;
                    if (m / a >= n) {
                        ans = Math.max(ans, a);
                    }
                    if (m / b >= n) {
                        ans = Math.max(ans, b);
                    }
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 23376
def  spe(H,A):
    att_sum = sum(A) 
    if H -att_sum>0:
        print("No")
    else:
        print("Yes")
        



inp = input().split()
inp_ = input().split()
H = int(inp[0])
N = int(inp[1] )
A= [int(i) for i in inp_]
spe(H,A)

Measured memory_bytes: 14016
x = int(input())
ans = []
for i in range(10000):
	b = i**5 - x
	if b <0:
		B = -b
		s = int(pow(B,0.2))
		if s**5 == B:
			ans = [i, -s]
			break
	else:
		s = int(pow(b,0.2))
		if s**5 == b:
			ans = [i, s]
			break
print(ans[0], ans[1])


Measured memory_bytes: 9452
n,m=map(int,input().split())
G=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  G[a-1].append([b-1,1])
  G[b-1].append([a-1,1])
# print(G)
point=[-1]*n
dist=[-1]*n
from collections import deque
q=deque()
q.append(0)
dist[0]=0
while q:
  cur=q.popleft()
  for nx,nd in G[cur]:
    if dist[nx]!=-1:continue
    dist[nx]=dist[cur]+nd
    point[nx]=cur
    q.append(nx)
# print(dist)
# print(point)
for i in range(1,n):
  if point[i]==-1:
    print("No")
    exit(0)
print("Yes")
for i in range(1,n):
  print(point[i]+1)

Measured memory_bytes: 128632