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

using namespace std;

const int MAX_N = 1e6 + 10;

int N, A[MAX_N];

int main() {
    scanf("%d", &N);
    static char S[MAX_N]; scanf("%s", S + 1);
    for (int i = 1; i <= N; i++) A[i] = S[i] - '1';
    bool any_1 = false;
    for (int i = 1; i <= N; i++) if (A[i] == 1) any_1 = true;
    if (any_1)
        for (int i = 1; i <= N; i++) A[i] &= 1;
    else
        for (int i = 1; i <= N; i++) A[i] /= 2;
    int ans = 0;
    N--;
    for (int i = 0; i <= N; i++)
        if ((i & N) == i) ans ^= A[i + 1];
    printf("%d\n", ans * (any_1 ? 1 : 2));
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l;
  cin >> n >> l;
  vector<string>s(n);
  int i;
  for(i=0;i<n;i++)cin>>s[i];
  priority_queue<string,vector<string>,greater<string> >que;
  for(i=0;i<n;i++)que.push(s[i]);
  string ans = "";
  while(!que.empty()){
    ans += que.top();
    que.pop();
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = 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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    if (a+b <= 2*c){
        PRINT(x*a+y*b);
    }
    else{
        if (x > y){
            if (a > 2*c) a = 2*c;
            PRINT(y*2*c+abs(x-y)*a);
        }
        else{
            if (b > 2*c) b = 2*c;
            PRINT(x*2*c+abs(x-y)*b);
        }
    }
}


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

int main()
{
	int N, X;
	cin >> N >> X;

	int total = 0;
	vector<int> M;
	for (int i = 0; i < N; i++) {
		int m;
		cin >> m;
		total += m;
		M.push_back(m);
	}

	sort(M.begin(), M.end());

	int minSize = M[0];

	int n = (X - total) / minSize;

	cout << N + n << endl;
}




Measured memory_bytes: 256
require 'set'

n, m = gets.chomp.split(' ').map(&:to_i)

v = (0...n).map { nil }
g = (0...n).map { Set.new }
m.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  a -= 1
  b -= 1
  g[a].add(b)
  g[b].add(a)
end

(0...n).each do |i|
  next if v[i]

  c = 1

  s = [i]
  v[i] = c
  while !(s.empty?)
    j = s.pop
    g[j].each do |k|
      next if v[k]
      s.push(k)
      c += 1
      v[k] = c
    end
  end
end

puts v.max


Measured memory_bytes: 83376
#include <iostream>
using namespace std;
#define ll long long
int main(){
    ll n, a, b, sum=0, maxi=0, mini=0;
    cin >> n >> a >> b;
    if(a>b){
        cout << sum << endl;
    }
    else if(n==1){
        if(a!=b){
            cout << sum << endl;
        }
        else{
            sum =1;
            cout << sum << endl;
        }
    }
    else{
        maxi = a+b+(n-2)*b;
        mini = a+b+(n-2)*a;
        sum = maxi - mini + 1;
        cout << sum << endl;
    }
    return 0;
}

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


int main(){
int N ;
cin >> N;
vector<int>High(100000000);
for (int i =0;i<N;i++){
  cin >> High.at(i);
}
bool can = true;
int max_cou = High.at(0);
for( int i =1;i<N;i++){
  
  int num = High.at(i);
  if(max_cou - num > 1 && max_cou > num)
    can =false;
  max_cou = max(num,max_cou);

}
if(can){
  cout << "Yes" <<endl;
}
else{
  cout << "No" << endl;
}
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] arr = br.readLine().split("");

        int startWithZeroCount = 0;
        int startWithOneCount = 0;
        for (int i = 0; i < arr.length; i++) {
            String s = arr[i];
            if (i % 2 == 0) {
                if (s.equals("0")) {
                    startWithOneCount++;
                } else {
                    startWithZeroCount++;
                }
            } else {
                if (s.equals("0")) {
                    startWithZeroCount++;
                } else {
                    startWithOneCount++;
                }
            }
        }
        out.println(Math.min(startWithOneCount, startWithZeroCount));
        out.close();
    }
}


Measured memory_bytes: 29396
#include<bits/stdc++.h>
#define all(vc) vc.begin(),vc.end()
#define ll long long
#define MIN(a,b) ((a)<(b)) ? (a) : (b)
#define EVEN(a) (a)%2==0 ? 1 : 0
#define fi first
#define se second
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
long long int MOD = 1e9+7;
long long int ji[300005], ou[300005];
long long int brut = 100000000000000000;
int fDig(int i)
{
   int k;
   do
   {
      k=i;
      i/=10;
   }while(i);
   return k;
}
int main()
{
  cin.tie(0);cout.tie(0);
  int n=1 ,m ,tmp ;
	cin>>tmp ;
	if(tmp==1)
		{
		cout<<"Yes"<<endl ;
		return 0 ;
		}
	m=tmp ;
	while(n<m)
		{
		m=tmp/n ;
		if(n*m==tmp&&m<=9)
			{
			cout<<"Yes"<<endl ;
			return 0 ;
			}
		n++ ;
		}
	cout<<"No"<<endl;
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}


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

int gcd(int x, int y){
  return (x % y)? gcd(y, x % y): y; 
}

int func(int a, int b, int c){
  int tmpNum;
  tmpNum = gcd(a, b);
  return gcd(tmpNum,c);
}

int main() {
  int num;
  long long kekka = 0;
  cin >> num;
  
  for(int i = 1; i <= num; i++){
    for(int j = 1; j <= num; j++){
      for(int k = 1; k <= num; k++){
        kekka += func(i,j,k);
      }
    }
  }
  
  cout << kekka;
}


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

int main(){
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  int ans = 0;
  sort(A.begin(),A.end());
  ans += (A[2]-A[0])/2;
  A[0] += ((A[2]-A[0])/2)*2;
  ans += (A[2]-A[1])/2;
  A[1] += ((A[2]-A[1])/2)*2;
  //cout << A[0] << " " << A[1] << " " << A[2] << endl;
  int r = A[2]*2-A[1]-A[0];
  if(r==0){
    cout << ans << endl;
  }else if(r==1){
    cout << ans+2 << endl;
  }else{
    cout << ans+1 << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = INT_MAX;
const int MAX = 300000;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------
int N,M,Q;
vector<int> a,b,c,d;
vector<int> A;
int ans;
void func(int n){
    if(n == N + 1){
        int t = 0;
        for(int i = 0; i < Q; i++) {
            if(A[b[i]] - A[a[i]] == c[i]){
                t += d[i];
            }
        }
        ans = max(ans,t);
        return;
    }
    for(int i = A[n-1]; i <= M; i++) {
        A[n] = i;
        func(n+1);
    }
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>M>>Q;
    a.resize(Q);b.resize(Q);c.resize(Q);d.resize(Q);
    A.push_back(1);
    for(int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    ans = 0;
    func(1);
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i,s,t ) for(int i = s; i< t ; i++)
using VL = vector<LL>;
#define SZ(a) (int)a.size()

void change(string&s, int a, int b, int c) {
	FOR(i, 0, SZ(s)) {
		if (s[i] == 'P') {
			s[i] = a + '0';
		}
		if (s[i] == 'Q') {
			s[i] = b + '0';
		}
		if (s[i] == 'R') {
			s[i] = c + '0';
		}
	}
}
string expr1(string&, int&);
string expr2(string&, int&);

// (だったらFを再度評価
// -だったらFを再度評価
// numだったらおちまい
// ()内でしか*,+をやらない

string expr2(string &s, int &i) { // とるとこ,(だったらexpr1へ
	if (isdigit(s[i])) {
		string num = string(1, s[i]);
		i++;
		return num;
	}
	if (s[i] == '-') {
		i++;
		string num = expr2(s, i);
		if ("2" == num)return "0";
		if ("0" == num)return "2";
		assert(num == "1");
		return num;
	}
	if (s[i] == '(') {
		i++;
		string num = expr1(s, i);
		// とってきたので、今見てるのは)
		assert(s[i] == ')');
		i++;
		return num;
	}
	// -

	return "";
}


string expr1(string &s,int &i) { 
	string A = expr2(s, i);
	string B = "";
	// いっことった
	int mode = 0;
	while(i < SZ(s) &&(s[i] == '+' || s[i] =='*')) {
		char op = s[i];
		i++;
		if (op == '+') {
			B = expr1(s, i);
			mode = 1;
		}
		else if (op == '*') {
			B = expr1(s, i);
			mode = 2;
		}
	}
	string OP = " +*";

	//cout << "A:" << A << ", "<<OP[mode] <<" B:" << B << endl;
	if (mode == 1) {
		if (A == "2" || B == "2")return "2";
		if (A == "1" || B == "1")return "1";
		return "0";
	}
	else if (mode == 2) {
		if (A == "0" || B == "0")return "0";
		if (A == "1" || B == "1")return "1";
		return "2";
	}

	return A;
}


void solve() {
	string s;
	while (cin >> s,s!=".") {
		// p,q,r:0,1,2
		int ans = 0;
		FOR(a, 0, 2 + 1) {
			FOR(b, 0, 2 + 1) {
				FOR(c, 0, 2 + 1) {
					string t = s;
					change(t, a, b, c);
					int i = 0;
					string res = expr1(t, i);
					//ut << "res:" << res << endl;
					if ("2" == res) {
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
}


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(int argc, char* argv[]) {
  string s, t;
  cin >> s >> t;

  map<char, char> s_to_t;
  map<char, char> t_to_s;
  for (int i = 0; i < s.size(); ++i) {
    if (s_to_t.find(s[i]) == s_to_t.end() && t_to_s.find(t[i]) == t_to_s.end()) {
      s_to_t[s[i]] = t[i];
      t_to_s[t[i]] = s[i];
    } else if (!(s_to_t[s[i]] == t[i] && t_to_s[t[i]] == s[i])) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 776
S = input()
T = input()
answer = 0
for i in range(len(S)-len(T)+1):
    samecnt = 0
    for j in range(len(T)):
        if S[j+i] == T[j]:
            samecnt += 1
    answer = max(answer, samecnt)

print(len(T)-answer)

Measured memory_bytes: 67472
n = input()
user = [""] * n
for i in range(n):
  user[i] = raw_input()
m = input()
st = 0
for i in range(m):
  t = raw_input()
  if t in user:
    print ("Closed" if st else "Opened") + " by " + t
    st = not st
  else:
    print "Unknown " + t

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    vector<LL> sum(100005, 0LL);
    int n;LL k;cin >> n >> k;
    for(int i=0;i<n;i++){
        int a, b;cin >> a >> b;
        sum[a] += LL(b);
    }
    LL now = 0;
    for(int i=0;i<100005;i++){
        if(now < k && k <= now+sum[i]){
            cout << i << endl;
            return 0;
        }
        now += sum[i];
    }
    return 0;
}


Measured memory_bytes: 1024
<?php
$in = [];
fscanf(STDIN, "%d", $in[]);
fscanf(STDIN, "%d", $in[]);
fscanf(STDIN, "%d", $in[]);
fscanf(STDIN, "%d", $in[]);
fscanf(STDIN, "%d", $in[]);
fscanf(STDIN, "%d", $k);

$ans = "Yay!";

for ($i = 0; $i < count($in) - 1; $i++) {
    for ($j = $i + 1; $j < count($in); $j++) {
        if ($in[$j] - $in[$i] > $k) {
            $ans = ":(";
            break;
        }
    }
}

echo $ans;


Measured memory_bytes: 4728
#include <cstdio>
#include <cstring>

using namespace std;

char sir[8010];
int d[8010],d1[8010],vx[8010],vy[8010];

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int x,y;
    scanf("%s\n",sir+1);
    scanf("%d%d",&x,&y);
    int l=strlen(sir+1);
    int poz=1,lx=0,ly=0;
    while(poz<=l && sir[poz]!='T') {x--;poz++;}
    int c=0,nr=0;
    sir[l+1]='T';
    for(int i=poz;i<=l+1;i++)
    {
        if(sir[i]=='T')
        {
            if(nr>0 && c%2==0) vx[++lx]=nr;
            if(nr>0 && c%2==1) vy[++ly]=nr;
            nr=0;
            c++;
            continue;
        }
        nr++;
    }
    int s=0;
    for(int i=1;i<=lx;i++) s+=vx[i];
    if((s+x)<0 or (s+x)%2==1) {printf("No");return 0;}
    int a=(s+x)/2;
    d[0]=1;
    for(int i=1;i<=lx;i++)
    {
        for(int j=a-vx[i];j>=0;j--)
            if(d[j]==1) d[j+vx[i]]=1;
    }
    s=0;
    for(int i=1;i<=ly;i++) s+=vy[i];
    if((s+y)<0 or (s+y)%2==1) {printf("No");return 0;}
    int a1=(s+y)/2;
    d1[0]=1;
    for(int i=1;i<=ly;i++)
        for(int j=a1-vy[i];j>=0;j--)
            if(d1[j]==1) d1[j+vy[i]]=1;
    if(d[a]==1 && d1[a1]==1) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int k, x;
	cin >> k >> x;
	int n = 1000000;
	for (int i = max(-n, x - k + 1); i <= min(n, x + k - 1); i++) {
		cout << i << " ";
	}
	cout << endl;
}


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

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split(" ");

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		long ans = 0;
		for (int i = 0; i < n; i++) {
			ans += a[i] - 1;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#prag\
ma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long
using namespace std;

vector<set<pair<int,int> > > g;
vector<int> gv[100001];
set<pair<int,int> > s,s2;
bool vis[100001];
int a[100001];

inline void dfs(int x){
	for(int i=0;i<gv[x].size();i++){
		if(!vis[gv[x][i]]){
			vis[gv[x][i]]=1;
			s.insert(make_pair(a[gv[x][i]],gv[x][i]));
			dfs(gv[x][i]);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	int n,m;
	
	cin>>n>>m;
	
	if(n-1==m){
		cout<<0;
		return 0;
	}
	
	if((n-1-m)*2>n){
		cout<<"Impossible";
		return 0;
	}
	
	for(int i=1;i<=n;i++) cin>>a[i];
	
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		++u,++v;
		gv[u].push_back(v);
		gv[v].push_back(u);
	}
	
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			vis[i]=1;
			s.insert(make_pair(a[i],i));
			dfs(i);
			g.push_back(s);
			s.clear();
		}
		
	for(int i=1;i<=n;i++) s2.insert(make_pair(a[i],i));
	
	ll ans=0;
	for(int i=0;i<n-m;i++){
		s=g[i];
		ans+=(ll)(*s.begin()).first;
		s2.erase(*s.begin());
	}
	
	for(int i=1;i<=2*(n-m-1)-(n-m);i++){
		ans+=(ll)(*s2.begin()).first;
		s2.erase(s2.begin());
	}
	
	cout<<ans;
}

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

int main(){
  int N, A, count, ans=1000000000;
  bool Even;
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> A;
    Even = true;
    count = 0;
    while (Even==true){
      if (A % 2 == 0){
        A = A / 2;
        count++;
      }
      else {
        Even = false;
      }
    }
    if (count < ans){
      ans = count;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*
I am not somebody you can put inside a box
And I am not somebody who will let you take my spot
It's written on my face I'm somebody who never stop
I do it because I gotta I don't do it for you props
Nah, you can keep those
I'm aiming way higher than planes in Heathrow
And I'm sorry to say but my game can't be sold
And look to be honest either you got it or don't
But if you got a dream and a vision
Put it in your mind that you gotta go out and get it
People try to stop you it's so hard in the beginning
But you said that you a winner so keep going ain't no quiting
I'm giving you the words that out me in this posotion
Some people hear and some people listen
Wanna be the best then you gotta learn the difference
*/
#include <bits/stdc++.h>                                           
 
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
//#define int long long	
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define ll long long
#define vi vector < int >
#define pii pair < int, int > 
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()                                                                    
#define pb push_back   
#define ppb pop_back
#define mp make_pair
#define s second
#define f first                                               
	
   
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;   
   
const int N = 2e5 + 13, inf = 1e9, mod = 1e9 + 7, block = 444;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
const ll INF = 1e18;
//fucking constants

int n, m, v, u, p[N], cnt[N];

int get (int v) {
	return v == p[v] ? v : p[v] = get(p[v]);
}                                


void merge (int v, int u) {
	v = get(v), u = get(u);
	if (v == u)	
		return;

	if (cnt[v] < cnt[u])
		swap(v, u);

	p[u] = v;
	cnt[v] += cnt[u];
}

main () {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		p[i] = i;
		cnt[i] = 1;
	}


	while (m--) {
		cin >> v >> u;
		merge(v, u);
	}

	cout << *max_element(cnt + 1, cnt + 1 + n);
}

Measured memory_bytes: 5152
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


ll modpow(ll x, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2);
        return h * h % MOD;
    } else {
        return x * modpow(x, n - 1) % MOD;
    }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N)  cin >> a[i];

    int ans = 0;

    vector<int> g1(N-1);
    auto g2 = g1;
    g1[0] = a[0], g2[0] = a[N-1];

    reps(i,N-1)  {
      g1[i] = gcd(g1[i-1], a[i]);
      g2[i] = gcd(g2[i-1], a[N-1-i]);
    }

    // rep(i,N)  {
    //   cout << g1[i] << ' ' ;
    //   if (i == N-1) cout << endl;
    // }
    // rep(i,N)  {
    //   cout << g2[i] << ' ' ;
    //   if (i == N-1) cout << endl;
    // }

    rep(i,N-2)  {
      // cout << gcd(g1[i],g2[N-3-i]) << endl;
      ans = max(ans, gcd(g1[i],g2[N-3-i]));
    }
    cout << max(ans,max(g1[N-2],g2[N-2])) << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
ll INF=pow(10,9);

struct LazySegment{
    vector<P> dat;
    //要素数
    int n;

    LazySegment(int n_){
        n=1;
        while(n<n_)n*=2;
        dat.resize(2*n);

        for(int i=0;i<2*n-1;i++)
            dat[i]={INF,i-n+1};
    }

    //k番目の値をaに変更
    void update(int k,ll a){
        k+=n-1;
        dat[k].first=a;
        while(k>0){
            k=(k-1)/2;
            if(dat[2*k+1].first<=dat[2*k+2].first) dat[k]=dat[2*k+1];
            else                                   dat[k]=dat[2*k+2];
        }
    }

    //[a,b)の最小値を求める
    //kは節点の番号、[l,r)はその区間
    P query(int a,int b,int k,int l,int r){
        if(r<=a || b<=l)return {INF,INF};
        if(a<=l && r<=b)return dat[k];
        else{
            P vl=query(a,b,2*k+1,l,(l+r)/2);
            P vr=query(a,b,2*k+2,(l+r)/2,r);
            if(vl.first<=vr.first) return vl;
            else                   return vr;
        }
    }
};

int main(){
    int N,M;cin>>N>>M;
    string S;cin>>S;
    vec dp(N);
    LazySegment LS(N+1);LS.update(N,0);
    for(int i=N-1;i>=0;i--){
        if(S[i]=='1') continue;
        P p=LS.query(i+1,min(i+M,N)+1,0,0,LS.n);
        if(p.first==INF){
            cout<<-1<<endl;
            return 0;
        }
        dp[i]=p.second-i;
        LS.update(i,1+p.first);
    }
    int i=0;
    while(i<N){
        cout<<dp[i]<<" ";
        i+=dp[i];
    }
    return 0;
}

Measured memory_bytes: 5504
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int n = s.nextInt();
		BigInteger array[] = new BigInteger[n * 3];
		for (int i = 0; i < array.length; i++) {
			array[i] = BigInteger.valueOf(s.nextInt());
		}
		s.close();
		System.out.println(Main.calc(n, array));
	}

	private static BigInteger calc(int n, BigInteger[] array) {
		BigInteger res = BigInteger.ZERO;
		java.util.Arrays.sort(array, java.util.Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			res = res.add(array[1+i * 2]);
		}
		return res;
	}
}

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

#if 0
この問題では、全ての価格の候補に対して税込価格を調べ、各税込価格が最大値かを比較する、という風にforループを2回回す解法がまず考えられる。この場合、計算量はO(n^2)程度となることが予想される。
O(n^2) < S^2 = 1000^2 = 10^6であり、C++ならば十分演算可能であると分かる。
#endif

int X, Y, S;

int tax(int rate, int price_without_tax){
  return  (int)price_without_tax*(100+rate) / 100;
}

int solve(){
  int maximum=0;
  for(int i=1;i<S;++i)
    for(int j = i; j < S; ++j)
      if(tax(X,i)+tax(X,j)==S)
        maximum = max(maximum,tax(Y,i)+tax(Y,j));

  return maximum;
}

int main() {
  while(cin >> X >> Y >> S && X>0){
    cout << solve() << endl;
  }
 }



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    ll ans = 0, tmp;
    vector<P> A(n);
    for (int i = 0; i < n; i++) sc(A[i].first)
    for (int i = 0; i < n; i++) sc(A[i].second)
    for (int i = 0; i < n; i++){
        tmp = 0;
        for (int j = 0; j <= i; j++) tmp += A[j].first;
        for (int j = i; j < n; j++) tmp += A[j].second;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
ll arr[200010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll k,n,hi=0,sum=0;
    cin>>n>>k;
    for(ll i=1;i<=n;i++)
    cin>>arr[i];
    for(ll i=0;i<k;i++)
    sum+=arr[i];
    hi=sum;
    for(ll i=1;i<=n-k+1;i++){
        sum+=arr[i+k-1]-arr[i-1];
        hi=max(hi,sum);
    }
    cout<<setprecision(100)<<(hi+k)/2.0;
}


Measured memory_bytes: 1792
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*
*   创 建 者： badcw
*   创建日期： 2019/12/22
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 15;
const int mod = 1e9+7;
ll qp(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n;
int x[maxn], y[maxn];

int main(int argc, char* argv[]) {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int sz;
        scanf("%d", &sz);
        int u, v;
//        y[i] |= 1 << i;
        for (int j = 0; j < sz; ++j) {
            scanf("%d%d", &u, &v);
            u --;
            if (v == 0) x[i] |= 1 << u;
            else y[i] |= 1 << u;
        }
    }
    int res = 0;
    for (int stat = 0; stat < (1 << n); ++stat) {
        int flag = 1;
        for (int i = 0; i < n; ++i) {
            if (stat >> i & 1) {
                int flag1 = x[i] & stat;
                int flag2 = y[i] & stat;
                if (!(flag1 == 0 && flag2 == y[i])) {
                    flag = 0;
                    break;
                }
            }
        }
        if (flag) res = max(res, __builtin_popcount(stat));
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];

int freq[5];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int x, y;

    for (int i = 0; i < 3; i++) {

        cin >> x >> y;
        a[x]++;
        a[y]++;
    }

    sort(a, a+5);

    if (a[4] > 2) cout << "NO";
    else cout << "YES";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int N, D;
	cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(D));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> X[i][j];
		}
	}
	int count = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			double dist;
			int sum = 0;
			for (int k = 0; k < D; k++) {
				sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
				dist = sqrt(sum);
			}
			if (floor(dist) == dist) count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {if(a < b) {a= b;return 1;}return 0;}
template <class T> inline bool chmin(T &a, T b) {if(a > b) {a= b;return 1;}return 0;}
ll mod= 1e9 + 7;



int main(){
  int h,w,m;
  cin >> h >> w >>m;
  ll a[h]={},b[w]={};
  ll c[m],d[m];
  rep(i,m){
    int q,w;
    cin >> q >> w;
    q--,w--;
    a[q]++;
    b[w]++;
    c[i]=q,d[i]=w;
  }

  ll hm=-1,wm=-1,counth=1,countw=1;
  rep(i,h){if(hm<a[i]){hm=a[i];counth=1;}else if(hm==a[i])counth++;}
  rep(i,w){if(wm<b[i]){wm=b[i];countw=1;}else if(wm==b[i])countw++;}
  ll ans=hm+wm;
  ll gg=0;
  rep(i,m){
    if(a[c[i]]==hm && b[d[i]]==wm){gg++;}
  }
  if(counth*countw>gg){cout << ans << endl;}else{cout << ans-1 << endl;}
}

Measured memory_bytes: 12988
import sys
from collections import deque

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


N, u, v = MI()
nl = [list() for _ in range(N)]
for _ in range(N - 1):
    a, b = MI()
    nl[a - 1].append(b - 1)
    nl[b - 1].append(a - 1)


def distance(v0):
    dist = [0] * N
    q = deque([(v0, -1, 0)])
    while len(q) > 0:
        v, p, d = q.popleft()
        dist[v] = d
        for next_v in nl[v]:
            if next_v != p:
                q.append((next_v, v, d + 1))
    return dist


t = distance(u - 1)
a = distance(v - 1)
initial_dist = t[v - 1]

ans = 0
for i in range(N):
    if a[i] > t[i]:
        ans = max(ans, a[i] - 1)
ans = max(ans, initial_dist - 1)
print(ans)


Measured memory_bytes: 71036
import java.util.Scanner

object Main extends App {

  def readALine(c:Int, ac:List[Int]=Nil):List[Int] =
    if (c > 0) readALine(c-1, sc.nextInt::ac) else ac.reverse
  // def readLines(r:Int, c:Int, ac:List[List[Int]]):List[List[Int]] =
  //   if (r > 0) readLines(r-1, c, readALine(c, Nil)::ac) else ac.reverse
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val Ai = readALine(N)
  val allXor = xor(Ai)

  def xor(l:List[Int], ac:Int = 0):Int = {
    if (l.isEmpty) ac else xor(l.tail, l.head ^ ac)
  } 
  def solver():List[Int] = {
    def iter(al:List[Int], ac:List[Int]):List[Int] = {
      if (al.isEmpty) ac.reverse else {
        iter(al.tail, (al.head ^ allXor)::ac)
      }
    }
    iter(Ai, Nil)
  }

  println(solver().mkString(" "))

}

Measured memory_bytes: 84368
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll max = a * c;

  if (a * d > max) {
    max = a * d;
  }
  if (b * c > max) {
    max = b * c;
  }
  if (b * d > max) {
    max = b * d;
  }

  cout << max << endl;

  return 0;
}


Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
char s[N];
int nxt[N], dp[N];
int pos[N][26], last[26];
char ret[N];
int A[26];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; i < 26; ++i) last[i] = n;
  for (int i = n - 1; i >= 0; --i) {
    last[s[i] - 'a'] = i;
    for (int k = 0; k < 26; ++k) {
      pos[i][k] = last[k];
    }
  }
  int cnt = 0;
  int i;
  for (i = 0; i < n; ++i) {
    if (++A[s[i] - 'a'] == 1) ++cnt;
    if (cnt == 26) break;
  }
  nxt[0] = i;
  for (int k = 1; k < n; ++k) {
    if (--A[s[k - 1] - 'a'] == 0) --cnt;
    if (cnt < 26) ++i;
    for (; i < n && cnt != 26; ++i) {
      if (++A[s[i] - 'a'] == 1) ++cnt;
      if (cnt == 26) break;
    }
    nxt[k] = min(n, i);
  }
  // for (int i = 0; i < n; ++i) trace(i, nxt[i]);
  dp[n] = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (nxt[i] < n) {
      dp[i] = 1 + dp[nxt[i] + 1];
    } else {
      dp[i] = 0;
    }
  }
  // for (int i = 0; i < n; ++i) {
  //   trace(i, nxt[i], dp[i]);
  // }
  int len = dp[0] + 1;
  // trace(len);
  int cur = 0;
  for (int k = 0; k < len; ++k) {
    for (int i = 0; i < 26; ++i) {
      if (pos[cur][i] == n || k + 1 + dp[pos[cur][i] + 1] < len) {
        ret[k] = 'a' + i;
        cur = pos[cur][i] + 1;
        break;
      }
    }
  }
  ret[len] = 0;
  puts(ret);
  return 0;
}


Measured memory_bytes: 22272
#!/usr/bin/env python3
import collections
import sys
sys.setrecursionlimit(int(1e7))

def dfs(n, pre, T, dist, d) :
	dist[n] = d
	for i in T[n] :
		if i[0] != pre :
			dfs(i[0], n, T, dist, d + i[1])


N = int(input())
T = collections.defaultdict(lambda : [])
for i in range(N-1) :
	a, b, c = map(int, input().split())
	T[a].append((b, c))
	T[b].append((a, c))
Q, K = map(int, input().split())

d = {}
dfs(K, -1, T, d, 0)

for i in range(Q) :
	x, y = map(int, input().split())
	print(d[x]+d[y])


Measured memory_bytes: 147616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    int ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if( i % 2 == 0){
            continue;
        }
        int counter = 0;
        for(int j = 1; j <= i; j++)
        if(i % j == 0){
            counter++;
        }
        if(counter == 8)
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define hell                         1000000007
#define __lcm(a,b)                   (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cerr << #x << " is " << x << endl;
#define endl                           '\n'

#define MAX 1005
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll n,t,A;
    cin >> n >> t >> A;
    ll a[n];
    rep(i,0,n) cin >> a[i];

    ll pos=0;
    double ans=hell*1.0;
    rep(i,0,n) {
        double ti = (t-a[i]*0.006);

        if(1.0*abs(ti-A) < 1.0*ans) {
            ans=abs(ti-A);
            pos=i;
        }
    }
    cout << pos+1 << endl;

}

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

int main(){
    int N;
    cin >> N;
    int cnt = 0;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec[i];
    }
    for (int j = 0; ; j++) {
        for (int i = 0; i < N; i++) {
        if (vec[i] % 2 > 0) {
            cout << cnt << endl;
            return 0;
        }
        vec[i] = vec[i] / 2;
        if (i == N - 1) {
            cnt++;
        }
      }
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

void solve()
{   
    ll ans = LLONG_MIN;
    ll a[2],b[2];
    for(int i =0;i<2;i++)
    cin>>a[i];
    for(int i =0;i<2;i++)
    cin>>b[i];
    if(a[0]*a[1]<=0 || b[0]*b[1]<=0){
        ans = 0;
    }
    for(int i =0;i<2;i++){
        for(int j = 0;j<2;j++){
            ans = max(ans,a[i]*b[j]); 
        }
    }
    cout<<ans<<'\n';
}
int main(){
    IOS;
    int tt;
    tt = 1;
    // cin>>tt;
    int i = 1;
    while(tt--){
        // cout<<"tc "<<i<<" ";
        solve();
        i++;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <complex>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i,n) for (int i=0; i < (n); i++)

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-9;    // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
D dot(P a, P b) {
  return (conj(a)*b).X;
}
// 外積　cross(a,b) = |a||b|sinθ
D cross(P a, P b) {
  return (conj(a)*b).Y;
}

// 多角形の符号付面積
D area(const VP& ps) {
  D a = 0;
  rep (i, ps.size()) a += cross(ps[i], ps[(i+1) % ps.size()]);
  return a / 2;
}

int main() {
  int n, m;
  while (cin >> m, m) {
    VP ps1(m);
    int curDeg = 0;
    rep(i,m-1) {
      ps1[i] = polar(1., curDeg * M_PI / 180);
      int v;
      cin >> v;
      curDeg += v;
    }
    ps1[m-1] = polar(1., curDeg * M_PI / 180);

    cin >> n;
    VP ps2(n);
    curDeg = 0;
    rep(i,n-1) {
      ps2[i] = polar(1., curDeg * M_PI / 180);
      int v;
      cin >> v;
      curDeg += v;
    }
    ps2[n-1] = polar(1., curDeg * M_PI / 180);

    D areaDiff = area(ps1) - area(ps2);
    if (EQ(areaDiff, 0)) cout << 0;
    else if (areaDiff > 0) cout << 1;
    else cout << 2;
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
n = int(input())
string_list=[input() for i in range(n)]

AC=string_list.count('AC')
WA=string_list.count('WA')
TLE=string_list.count('TLE')
RE=string_list.count('RE')
print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))

Measured memory_bytes: 79260
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main() {
	int n; scanf("%d",&n);
	int c=0;
	rep(i,1,n+1){
		int d; scanf("%d",&d);
		if((i&1) && (d&1)) ++c;
	} 
	printf("%d\n",c);
}


Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int n,d;
    cin >> n >> d;
    int s = d*2+1;
    if(n%s==0){
        cout << n/s<<endl;
    }else{
        cout<<n/s+1<<endl;
    }
}

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

int main(void){
	int N,K,ans=0;
	scanf("%d%d",&N,&K);
	int x[N];
	for(int i=0;i<N;i++)scanf("%d",&x[i]);
	for(int i=0;i<N;i++){
		if(abs(K-x[i]) < x[i]) ans += 2*abs(K-x[i]);
		else ans+=2*x[i];
	}
	
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import math
a, b, x = (int(x) for x in input().split())
if (a*b/2*a > x): print(math.degrees(math.atan(b/((2*x)/(a*b)))))
else:
    y = (2*x/a/a) - b
    print(math.degrees(math.atan((b-y)/a)))

Measured memory_bytes: 3060
X,K,D = [int(x) for x in input().split()]

if D * K < abs(X):
    print(abs(X) - D * K)
else:
    if (K - abs(X) // D) % 2 == 0:
        print(abs(X) % D)
    else:
        print(D - abs(X) % D)

Measured memory_bytes: 9108
from collections import deque


def get_next_node(node, discovery_time, adj_mat):
    for i, node in enumerate(adj_mat[node]):
        if discovery_time[i] == 0 and node == 1:
            return i
    return None

def bfs(node, adj_mat):
    distances = [-1] * len(adj_mat)

    distances[node] = 0
    q = deque(maxlen=len(adj_mat))
    q.append(0)
    while q:
        visit_node = q.popleft()
        for j in range(len(adj_mat)):
            if adj_mat[visit_node][j] and distances[j]==-1:
                distances[j] = distances[visit_node] + 1
                q.append(j)
    
    for i, d in enumerate(distances):
        print(i+1, d)


if __name__ == "__main__":
    n_node = int(input())
    # f = open('alds1_11_c-input.txt', 'r')
    # n_node = int(f.readline())

    adjacency_mat = [[0 for i in range(n_node)] for j in range(n_node)]
    for i in range(n_node):
        command = list(map(int, input().split()))
        # command = list(map(int, f.readline().split()))

        i = command.pop(0) - 1
        n_edge = command.pop(0)

        for j in command:
            adjacency_mat[i][j-1] = 1

    # f.close()
    discovery_time = [0] * n_node
    finish_time = [0] * n_node
    bfs(0, adjacency_mat)


Measured memory_bytes: 6108
package main

import "fmt"

func Check(ans int, d []int) bool {
	for ans > 0 {
		n := ans % 10
		for _, v := range d {
			if v == n {
				return true
			}
		}
		ans /= 10
	}
	return false
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	d := make([]int, k)
	for i := 0; i < k; i++ {
		fmt.Scan(&d[i])
	}

	for Check(n, d) {
		n++
	}

	fmt.Println(n)
}

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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 10){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input();
  int ans = inf;

  vector< int > s;
  s.push_back(1);
  for (int x = 6; x <= N; x *= 6) s.push_back(x);
  for (int x = 9; x <= N; x *= 9) s.push_back(x);

  bitset< 100001 > dp;
  dp.set(0);

  range(i, 0, N + 1) {
    if (dp[N]) {
      cout << i << endl;
      return;
    }

    bitset< 100001 > dp2;
    for (auto t : s) dp2 |= (dp << t);
    dp = dp2;
  }
}

signed main(int argc, char *argv[]) {
  solver();
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		int[] aa={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		System.out.println(aa[t-1]);
	}
}


Measured memory_bytes: 22100
//Spreadsheet

#include<stdio.h>


int main(void){
    int r, c;
    int i, j;
    int allsum = 0;
    int sheet[101][101] = {0};
    scanf("%d", &r);
    scanf("%d", &c);
    
    
    
    for(i = 0; i < r; i++)
        for(j = 0; j < c; j++)
            scanf("%d", &sheet[i][j]);

    //???????????±????????????????????????????¬??????????????????????
    for(i = 0; i < r; i++){
        int sum = 0;
        for(j = 0; j < c; j++){
            sum += sheet[i][j];
        }
        sheet[i][c] = sum;
        allsum += sum;
    }
    
    //???????????????????????±???????????????????????????????´?
    for(i = 0; i < c; i++){
        int sum = 0;
        for(j = 0; j < r; j++){
            sum += sheet[j][i];
        }
        sheet[r][i] = sum;
    }
    
    //  allsum to sheet[r][c]
    sheet[r][c] = allsum;
    
    //Print a new sheet
    for(i = 0; i < r + 1; i++){
        for(j = 0; j < c + 1; j++){
            if(j == 0) printf("%d", sheet[i][j]);
            else printf(" %d", sheet[i][j]);
        }
        putchar('\n');
    }
    return 0;
}

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

#define print2(a, b) cerr << "(" << a << "," << b << ")" << endl
#define print3(a, b, c) cerr << "(" << a << "," << b << "," << c << ")" << endl

const long long MOD = 2;

void solve(long long N, std::vector<long long> a){
    vector<ll> res(N);
    for (ll i = N - 1; i >= 0; i--) {
        ll n = i + 1;
        res[i] = a[i];
        for (ll j = 1; j * j <= n; j++) {
            if (n % j == 0) {
                a[j-1] ^= a[i];
                if (j * j != n && j != 1) {
                    a[n/j - 1] ^= a[i];
                }
            }
        }
    }

    int M = count(res.begin(), res.end(), 1LL);
    cout << M << endl;
    if (M > 0) {
        int c = 0;
        for (ll i = 0; i < N; i++) {
            if (res[i]) {
                if (c > 0)
                    cout << ' ';
                cout << i+1;
                c++;
            }
        }
        cout << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 3968
def main(s,t,a,b,u):
    if u == s:
        return "{0} {1}".format(a-1,b)
    else:
        return "{0} {1}".format(a,b-1)

s,t = input().split()
a,b = map(int, input().split())
u = input()
print(main(s,t,a,b,u))

Measured memory_bytes: 3060
// Let Go Your Earthly Tether , Enter The Void , Empty And Become Wind

#include<bits/stdc++.h>

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

#define PB push_back
#define F first
#define S second
#define _sz(x) (int)x.size()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pll = pair<ll , ll> ;

ll h , a ;

int main() {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
        cin >> h >> a ;
        ll ans = (h + a - 1) / a ;
        cout << ans ;
        return (0) ;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int t[100][100];
int sum[100][100];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<100;i++)
			for(int j=0;j<100;j++)
				sum[i][j]=t[i][j]=0;
		int b,c;
		scanf("%d%d",&b,&c);
		for(int i=0;i<a;i++){
			int d,e;
			scanf("%d%d",&d,&e);
			t[d-1][e-1]++;
		}
		int m=0;
		for(int i=0;i<c;i++)sum[0][i]=(m+=t[0][i]);
		m=0;
		for(int i=0;i<b;i++)sum[i][0]=(m+=t[i][0]);
		for(int i=1;i<b;i++){
			for(int j=1;j<c;j++){
				sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+t[i][j];
		//		printf("%d ",sum[i][j]);
			}
		//	printf("\n");
		}
		int f,g;
		scanf("%d%d",&f,&g);
		int ret=0;
		for(int i=0;i<=b-f;i++)
			for(int j=0;j<=c-g;j++){
				int p=sum[i+f-1][j+g-1];
				if(i)p-=sum[i-1][j+g-1];
				if(j)p-=sum[i+f-1][j-1];
				if(i&&j)p+=sum[i-1][j-1];
				ret=max(ret,p);
			}
	/*	for(int i=0;i<=b-g;i++)
			for(int j=0;j<=c-f;j++){
				int p=sum[i+g-1][j+f-1];
				if(i)p-=sum[i-1][j+f-1];
				if(j)p-=sum[i+g-1][j-1];
				if(i&j)p+=sum[i-1][j-1];
				ret=max(ret,p);
			}
	*/	printf("%d\n",ret);
	}
}

Measured memory_bytes: 0