akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());

        // 主処理
        double waterH = (double) x / (a * a);

        double result = 0;
        if (b <= waterH * 2) {
            double h = b - waterH;
            result = Math.toDegrees(Math.atan(h / (a / 2.0)));
        } else {
            double bottom = x * 2.0 / a / b;
            result = Math.toDegrees(Math.atan((double) b / bottom));
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23764
from math import gcd
MOD = 10**9+7
n, k = map(int, input().split())
ans = [0 for _ in range(k+1)]
for i in range(k, 0, -1):
	tmp = pow(k//i, n, MOD)
	for j in range(2*i, k+1, i):
		tmp -= ans[j]
		tmp %= MOD
	ans[i] = tmp
#print(ans)
res = 0
for i, x in enumerate(ans):
	res += x * i
	res %= MOD
print(res)

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

int mid(int a,int b,int c){
  return a+b+c-max(max(a,b),c)-min(min(a,b),c);
}

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  cout << min(A*N,B) << endl;
}     
  

Measured memory_bytes: 256
from fractions import gcd
a,b = map(int, input().split())
m = gcd(a,b)

def fctr1(n):
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    return f

ans = 1 + len(fctr1(m))
print(ans)

Measured memory_bytes: 5340
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1 == 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        int a[n + 1];
        loop(1, n + 1)
        cin >> a[i];
        int vis[n + 1] = {0};
        vector<int> v;
        int curr = 1;
        while (true) {
            if (vis[curr] == 0) {
                vis[curr] = 1;
                v.pb(curr);
                curr = a[curr];
            }
            else {
                vis[curr]++;
                break;
            }
        }
        int pos = -1;
        int flag = 0;
        vector<int> lo;
        loop(0, v.size()) {
            if (vis[v[i]] == 2) {
                pos = i - 1;
                flag = 1;
            }
            if (flag == 1) {
                lo.pb(v[i]);
            }
        }

        /*for (auto it : v)
            cout << it << " ";
        cout << endl;
        for (auto it : lo)
            cout << it << " ";
        cout << endl;
        cout << pos << endl;    */

        if (k <= pos) {
            cout << v[k] << endl;
        }
        else {
            k -= (pos + 1);
            k = k % lo.size();
            cout << lo[k] << endl;
        }
        //cout << v[k] << endl;
    }
    return 0;
}


Measured memory_bytes: 10864
#include <cstdio>

const int MAXN = 6000;

int f[4][2*MAXN + 5], N, M;

int main() {
	scanf("%d%d", &N, &M);
	
	f[0][MAXN] = 1;
	for(int i=1;i<=3*N;i++) {
		int lb = MAXN - (i - 1), ub = MAXN + (i - 1);
		for(int j=lb;j<=ub;j++) {
			for(int o=3;o>=1;o--)
				f[o][j] = f[o-1][j];
			f[0][j] = 0;
		}
		for(int j=lb;j<=ub;j++) {
			f[0][j+1] = (f[0][j+1] + f[1][j]) % M;
			int del = (i - 1);
			f[0][j-1] = (f[0][j-1] + 1LL*f[2][j]*del%M) % M;
			del = 1LL*(i - 1)*(i - 2)%M;
			f[0][j] = (f[0][j] + 1LL*f[3][j]*del%M) % M;
		}
	}
	int ans = 0;
	for(int i=MAXN;i<=MAXN+3*N;i++)
		ans = (ans + f[0][i]) % M;
	printf("%d\n", ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

lld dist(lld ax, lld ay, lld bx, lld by)
{
    return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}

int main()
{
    lld a, b, h, m;
    cin >> a >> b >> h >> m;
    lld arad = (M_PI / 2 - h / 12.0 * 2 * M_PI) - 2 * M_PI / 12 * (m / 60);
    lld brad = (M_PI / 2 - m / 60.0 * 2 * M_PI);
    lld ax = a * cos(arad);
    lld ay = a * sin(arad);
    lld bx = b * cos(brad);
    lld by = b * sin(brad);
    cout << fixed << setprecision(18) << dist(ax, ay, bx, by) << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int n;
string s;
int w=0;
void wrongSolve(){

	ll i=0,j=n-1;
	while(s[i]=='.') i++;
	while(s[j]=='#') j--;
	ll k=i,count1=0,count2=0;
	while(k <=j){
		if(s[k]=='.') count1++;
		if(s[k]=='#') count2++;
		k++;
	}
	cout << min(count2,count1) << "\n";


}


void solve(){
	std::vector<int> white(n+1,0);   
	FOR(i,n){
		white[i]=(s[i]=='.') ? ((i > 0) ? (white[i-1]+1) : 1) : ((i > 0) ?white[i-1] : 0);
	}
	int w=white[n-1];
	int ans=w;
	FOR(i,n){                // last . lies in this position
		if(s[i]=='.') ans=min(ans, (i+1-white[i])+w-white[i] );
		else ans=min(ans,i+1-white[i]+ w-white[i]+1);
	}
	cout << ans;


}


int main(){
	startTime=clock();
	cin >> n;
	cin >> s;	
	solve();
	

	return 0;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
int n, i, j, a[85];
long long f[85];
int main()
{
    scanf("%d", &n);
    for (i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    f[0] = 1000;
    for (i = 1; i <= n; ++i)
    {
        f[i] = f[i - 1];
        for (j = 1; j < i; ++j)
            f[i] = max(f[i], f[j] / a[j] * a[i] + f[j] % a[j]);
    }
    printf("%lld", f[n]);
}

Measured memory_bytes: 3824
#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;

int main(){
    ll n;
    cin >> n;
    ll ans=0;
    ans=n*(n+1)-1;
    ll n2;
    rep(i,n/2-1){
        n2=n/(i+2);
        ans+=(i+2)*(n2*(n2+1)/2);
        ans-=(i+2);
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;



int main()
{
	vector<string>cypher2{
		"101",
		"000000",
		"000011",
		"10010001",
		"010001",
		"000001",
		"100101",
		"10011010",

		"0101",
		"0001",
		"110",
		"01001",
		"10011011",
		"010000",
		"0111",
		"10011000",

		"0110",
		"00100",
		"10011001",
		"10011110",
		"00101",
		"111",
		"10011111",
		"1000",

		"00110",
		"00111",
		"10011100",
		"10011101",
		"000010",
		"10010010",
		"10010011",
		"10010000",
	};


	map<char,int>ps{
		make_pair(' ',0),
		make_pair('\'',1),
		make_pair(',',2),
		make_pair('-',3),
		make_pair('.',4),
		make_pair('?',5)
	};
	string st;
	while (getline(cin,st)) {
		string nst;
		for (auto ch : st) {
			int k=0;
			if (ps.find(ch)!= ps.end()) {
				k=26+ps[ch];
				if (k == 27) {
					k=30;

				}
				else if (k == 28) {
					k=28;
				}
				else if (k == 29) {

				}
				else if (k == 30) {
					k=27;
				}
			}
			else {
				k=ch-'A';
			}
			for (int i = 0; i < 5; ++i) {
				nst.push_back('0'+((k&(1<<(4-i)))!=0));
			}

		}

		
		string ans;
		int l=0;
		while (true) {
			char next(0);
			for (int i = 0; i < 32; ++i) {
				if (nst.substr(l, cypher2[i].size())==cypher2[i]) {
					if (i <=5) {
						for (auto m : ps) {
							if (m.second == i) {
								next=m.first;
							}
						}
					}
					else {
						next='A'+i-6;
					}
					l+=cypher2[i].size();
					break;
				}
			}
			if (next) {
				ans.push_back(next);
			}
			else {
				break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

#define endl "\n"
#define int long long
#define vec(x) vector<x>
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
const int MOD = 1e9 + 7; 
const double pi = acos(-1);
int power(int a,int b,int m=MOD)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}
int dir[]={-1, 0, 1, 0, -1};
int dx[]={1,1,0,-1,-1,-1, 0, 1};
int dy[]={0,1,1, 1, 0,-1,-1,-1};

const int N = 1e18;

void solve()
{
	int i,n,ans=1,f=1,f1=1;
	cin>>n;
    vi a(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(!a[i])
        f=0;
        if(a[i]>N)
        f1=0;
    }
    if(f==0)
    {
        cout<<0<<endl;
        return;
    }
	if(f1==0)
    {
        cout<<-1<<endl;
        return;
    }
    for(i=0;i<n;i++)
    {
		if(a[i]>N/ans)
		{
			cout<<-1<<endl;
			return;
		}
		ans=ans*a[i];
	}
    cout<<ans<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	t=1;
	//cin>>t;
	while(t--)
		solve();
}


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

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

  vector<string> s(N),t(M);
  int balance = 0;

  for (int i=0; i<N; i++) {
    cin >> s[i];
  }

  cin >> M;
  for (int i=0; i<M; i++) {
    cin >> t[i];
  }

  int count;

  for (int i=0; i<N; i++) {
    string str = s[i];
    count = 0;

    for (int j=0; j<N; j++) {
      if (s[j] == str) {
        count += 1;
      }
    }

    for (int j=0; j<M; j++) {
      if (t[j] == str) {
        count -= 1;
      }
    }

    balance = max(count,balance);

  }

  for (int i=0; i<M; i++) {
    string str = t[i];
    count = 0;

    for (int j=0; j<N; j++) {
      if (s[j] == str) {
        count += 1;
      }
    }

    for (int j=0; j<M; j++) {
      if (t[j] == str) {
        count -= 1;
      }
    }

    balance = max(count,balance);

  }

  cout << balance << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
string s;vector<int>v;
ll cnt[N][20],ji=0;
ll dp[N][20];
void make(char a,char b,char c)
{
	for(int i=0;i<10;i++)
	{
		if(a!='?')i=a-'0';
		for(int j=0;j<10;j++)
		{
			if(b!='?')j=b-'0';
			for(int k=0;k<10;k++)
			{
				if(c!='?')k=c-'0';
				int num=i*100+j*10+k;
				cnt[ji][num%13]++;
				if(c!='?')break;
			}
			if(b!='?')break;
		}
		if(a!='?')break;
	}
	ji++;
}
int main()
{
	cin>>s;
	if(s.size()%3!=0)
	{
		int num=3-s.size()%3;
		while(num--)
		{
			s.insert(0,"0");
		}
	}
	for(int i=0;i<s.size();i+=3)
	{
		make(s[i],s[i+1],s[i+2]);
	}
	dp[ji][0]=1;
	for(int i=ji-1;i>=0;i--)
	{
		if((ji-i)%2==1)
		{
			for(int j=0;j<13;j++)
			{
				for(int k=0;k<13;k++)
				{
					dp[i][j]+=dp[i+1][(j-k+13)%13]*cnt[i][k]%mod;
					dp[i][j]%=mod;
				}
			}
		}
		else
		{
			for(int j=0;j<13;j++)
			{
				for(int k=0;k<13;k++)
				{
					dp[i][j]+=dp[i+1][(j+k)%13]*cnt[i][k]%mod;
					dp[i][j]%=mod;
				}
			}
		}
	}
	cout<<dp[0][5]<<endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;

  for (int i = 0; i < s.size(); ++i) {
    int d = (26 - (s[i] - 'a')) % 26;
    if (d == 0)
      continue;
    if (d <= k) {
      s[i] = 'a';
      k -= d;
    }
  }
  if (k > 0)
    s.back() = 'a' + (s.back() - 'a' + (k % 26)) % 26;

  cout << s << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5005;
// ll c[maxn], p[maxn], b[maxn], n, k, ans = -999999999999, t, cnt, vis[maxn], inf = 0;
int main()
{
    //freopen("input.in", "r", stdin);
    // cin >> n >> k;
    // for (int i = 1; i <= n; i++)
    //     cin >> p[i];
    // for (int i = 1; i <= n; i++)
    //     cin >> c[i];
    // ll temp;
    // for (int i = 1; i <= n; i++)
    // {
    //     memset(b, 0, sizeof(b));
    //     memset(vis, 0, sizeof(vis));
    //     cnt = 0, temp = 0, t = i, inf = 0;
    //     while (vis[p[t]] == 0)
    //         b[cnt + 1] = c[p[t]], inf += c[p[t]], cnt++, vis[p[t]] = 1, t = p[t];
    //     if (k <= cnt)
    //     {
    //         ll ab = 0;
    //         for (int j = 1; j <= k; j++)
    //         {
    //             ab += b[j];
    //             ans = max(ans, ab);
    //         }
    //         continue;
    //     }
    //     if (inf <= 0)
    //     {
    //         ll ab = 0;
    //         for (int j = 1; j <= cnt; j++)
    //         {
    //             ab += b[j];
    //             ans = max(ans, ab);
    //         }
    //     }
    //     {
    //         int kk = k / cnt;
    //         kk--;
    //         temp = (kk * inf);
    //         ans = max(temp, ans);
    //         for (int j = 1; j <= cnt; j++)
    //         {
    //             temp = temp + b[j];
    //             ans = max(temp, ans);
    //         }
    //         kk++;
    //         for (int j = 1; j <= k - kk * cnt; j++)
    //         {
    //             temp = temp + b[j];
    //             ans = max(temp, ans);
    //         }
    //     }
    // }
    // cout << ans << endl;
    ll n,ans=0,d;
    cin>>n>>d;
    while(n--)
    {
         ll a,b;
          cin>>a>>b;
        if( (a*a+b*b) <=d*d  )
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3568
from collections import defaultdict
N = int(input())

d = defaultdict(int)
A = list(map(int, input().split()))
Q = int(input())

ans = sum(A)
for a in A:
    d[a] += 1

for i in range(Q):
    b, c = map(int,input().split())
    tmp = d[b] #変動する個数を数える
    d[b] = 0
    d[c] += tmp
    if b >= c:
        ans -= (b-c)*tmp
    else:
        ans += (c-b)*tmp
    print(ans)


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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

template<ll Modulus>
class ModInt {
  ll value;
public:
  inline ModInt(ll val = 0) noexcept :
    value((val >= Modulus) ? (val % Modulus) : (val < 0) ? ((val + Modulus) % Modulus) : val) {}

  template<class Int>
  explicit inline operator Int() const noexcept { return static_cast<Int>(value); }

  inline ModInt inv() const noexcept {
    return ModInt<Modulus>::pow(value, Modulus-2);
  }

  inline ModInt& operator+=(ModInt x) noexcept {
    if ((value += x.value) >= Modulus) value -= Modulus;
    return *this;
  }
  inline ModInt& operator-=(ModInt x) noexcept {
    if ((value -= x.value) < 0) value += Modulus;
    return *this;
  }
  inline ModInt& operator*=(ModInt x) noexcept {
    value = (value * x.value) % Modulus; return *this;
  }
  inline ModInt& operator/=(ModInt x) noexcept {
    value = (value * x.inv().value) % Modulus; return *this;
  }

  inline ModInt operator+(ModInt x) const noexcept { return ModInt(*this) += x; }
  inline ModInt operator-(ModInt x) const noexcept { return ModInt(*this) -= x; }
  inline ModInt operator*(ModInt x) const noexcept { return ModInt(*this) *= x; }
  inline ModInt operator/(ModInt x) const noexcept { return ModInt(*this) /= x; }
  inline bool operator==(ModInt x) const noexcept { return value == x.value; }
  inline bool operator!=(ModInt x) const noexcept { return !(this->operator==(x)); }

  friend ostream& operator<<(ostream &os, ModInt x) noexcept { os << x.value; return os; }
  friend istream& operator>>(istream &is, ModInt &x) noexcept { is >> x.value; return is; }

  static constexpr inline ModInt pow(ll n, ll p) noexcept {
    ll ret = 1;
    for(; p > 0; p >>= 1) {
      if (p & 1) ret = (ret * n) % Modulus;
      n = (n * n) % Modulus;
    }
    return ret;
  }

  ModInt p(ll p){
	ll n = value;
    ll ret = 1;
    for(; p > 0; p >>= 1) {
      if (p & 1) ret = (ret * n) % Modulus;
      n = (n * n) % Modulus;
    }
    return value = ret;
  }
};

#define MOD 1000000007
using mint = ModInt<MOD>;

mint comb(ll n, ll k){
  mint ret = 1;
  rep(i, k){
    ret *= n - i;
    ret /= i + 1;
  }
  return ret;
}

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

  mint ans = mint::pow(2, n) - 1 - comb(n, a) - comb(n, b);
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import Data.Char
main=print.solve.(\[n,k]->(n,read k)).lines=<<getContents
solve(n,k)=(!!k).fst.foldr f((\a->(a,a))$1:replicate k 0)$map digitToInt n
f i(rs,as)=case i of
  0->(rs,bs)
  i->(mul(i-1)as`add`(0:rs)`add`as,bs)
  where bs=as`add`mul 9 as
add=zipWith(+)
mul k as=0:map(*k)as

Measured memory_bytes: 4032
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<stack>
#include<algorithm>
using namespace std;
struct Num{
	int x,y,index;
}num[200005];
int right[200005],sz[200005],par[200005],left[200005],ans[200005];
bool cmp(Num a,Num b){
	return a.x<b.x;
}
int find(int x){
	if(x==par[x])
		return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)
		return;
	if(sz[x]<sz[y]){
		sz[y]+=sz[x];
		sz[x]=0;
		par[x]=y;
	}
	else{
		sz[x]+=sz[y];
		sz[y]=0;
		par[y]=x;
	}
}
stack<int> st;
int main(){
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&num[i].x,&num[i].y);
		num[i].index=i;
		par[i]=i;
		sz[i]=1;
	}
	sort(num,num+n,cmp);
	st.push(0);
	for(i=1;i<n;i++){
		if(st.empty()||num[st.top()].y>num[i].y)
			st.push(i);
		else{
			auto x=st.top();
			while(st.size()&&num[i].y>num[st.top()].y){
				unite(i,st.top());
				st.pop();
			}
			st.push(x);
		}
	}
	for(i=0;i<n;i++)
		ans[num[i].index]=sz[find(i)];
	for(i=0;i<n;i++)
		printf("%d\n",ans[i]);
}

Measured memory_bytes: 7964
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;

long long a[(int)1e5+5];
long long b[(int)1e5+5];
long long c[(int)1e5+5];
long long dp[(int)1e5+5][3];

int main() {
	IOS
	int n;
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for(int i=1; i<n; i++) {
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
	}
	long long _ans = 0;
	_ans = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
	cout << _ans;
 	return 0;
}


Measured memory_bytes: 4992
import sys
import numpy as np

n, k = map(int, sys.stdin.readline().split())

dp = np.zeros((n+1, k+1))

for i in range(1,n+1):
    w, v = map(int, sys.stdin.readline().split())
    dp[i] = dp[i-1]
    dp[i][w:] = np.maximum(dp[i-1][:-w]+v, dp[i-1][w:])

print(int(np.max(dp[n])))

Measured memory_bytes: 92716
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rep(I, N) for (ll I = 0; I < (N); ++I)
#define repp(I, a, B) for (ll I = (a); I <= (B); ++I)
#define inn ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);srand(time(NULL));cout<<fixed<<setprecision(10);clock_t clk;clk = clock();
#define outt clk=clock()-clk;cerr<<fixed<<setprecision(6)<<"Time: "<<((double)clk)/CLOCKS_PER_SEC<<"\n";return 0;
using namespace std;
#define TRACE
#ifdef TRACE
#define t(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define t(...)
#endif
const int N = 2e5 + 5;
const int MAX = 2e6 + 5;
const int MOD = 1000000007;

int n;
ll h[N], dp[N], b[N];
ll tree1[4*N];

void buildmax(ll node,ll start,ll end)
{
    if(start == end)
    {
        tree1[node] = dp[start];
    }
    else
    {
        ll mid = (start+end)/2;
        buildmax( node*2 , start , mid );
        buildmax( node*2+1, mid+1, end );
        tree1[node] = max( tree1[node*2] , tree1[node*2 + 1] );
    }
}
void updatemax(int node, int start, int end, int idx)
{
    if(start == end)
    {
        tree1[node] = dp[idx];
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx && idx <= mid)
        {
            updatemax(2*node, start, mid, idx);
        }
        else
        {
            updatemax(2*node+1, mid+1, end, idx);
        }
        tree1[node] = max(tree1[2*node], tree1[2*node+1]);
    }
}  
ll querymax(ll node, ll start, ll end, ll l, ll r) 
{
    if (end < l || start > r) 
        return -1e18; 
    else if (l <= start && end <= r) 
        return tree1[node];
    ll mid=(start+end)/2;
    return max(querymax(2*node, start, mid, l, r), querymax(2*node+1, mid+1, end, l, r)); 
}

signed main()
{
    inn;

    cin >> n;
    repp(i,1,n) cin >> h[i];
    repp(i,1,n) cin >> b[i];
    repp(i,1,n) dp[i] = -1e18;
    buildmax(1,1,n);
    repp(i,1,n)
    {
        ll q = querymax(1,1,n,1,h[i]-1);
        dp[h[i]] = b[i] + (q == -1e18 ? 0 : q);
        updatemax(1,1,n,h[i]);
    }
    ll ans = 0;
    repp(i,1,n) ans = max(ans, dp[i]);
    cout << ans << "\n";

    outt;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long q,h,s,d,n;
  cin>>q>>h>>s>>d>>n;
  q*=4;
  h*=2;
  long long x=min(min(q,h),s);
  if(x*2<=d){
    cout<<n*x<<endl;
  }
  else{
    cout<<n/2*d+(n%2)*x<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int i = 1;
		int x = 0;
		List<Integer> list = new ArrayList<>();

		do {
			String str1 = br.readLine();
			x = Integer.parseInt(str1);
			if (x != 0) {
				list.add(x);
			}

		} while (x != 0);

		for (i = 0; i < list.size(); i++) {

			System.out.println("Case " + (i + 1) + ": " + list.get(i));
		}

	}

}



Measured memory_bytes: 32300
import numpy
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
c = 0
for x, y in combinations(X, 2):
  s = sum(p**2 for p in numpy.array(x)-numpy.array(y))**.5
  if s.is_integer():
    c += 1
print(c)

Measured memory_bytes: 27256
#include<iostream>
#include<vector>
#include<string>
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 31;

template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

int main() {
	int n;
	ll frog[500010];
	cin >> n;
	rep(i, n)cin >> frog[i];
	vector<ll>dp(500010, INF);
	dp[0] = 0;

	rep(i, n) {
		chmin(dp[i + 1], abs(frog[i + 1] - frog[i])+ dp[i]);
		if(i < n - 2)chmin(dp[i + 2], abs(frog[i + 2] - frog[i]) + dp[i]);
	}
	cout << dp[n - 1] << endl;

}

Measured memory_bytes: 6912
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int nx[120000];
int bf[120000];

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

	cin >> N >> K;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	for (int i = 1; i <= N; i++)nx[i] = nx[i] = -1;
	for (int i = 1; i < N; i++) {
		bf[v[i]] = v[i - 1];
	}
	for (int i = 0; i < N - 1; i++) {
		nx[v[i]] = v[i + 1];
	}
	int tp = v[0];
	int bk = v.back();
	while (K--) {
		cin >> M;
		if (M == tp && M == bk) {
			continue;
		}
		else if (M == tp) {
			bf[nx[M]] = -1;
			tp = nx[M];
			nx[bk] = M;
			nx[M] = -1;
			bf[M] = bk;
			bk = M;
		}
		else if (M == bk) {
			nx[bf[M]] = -1;
			bk = bf[M];
			bf[tp] = M;
			bf[M] = -1;
			nx[M] = tp;
			tp = M;
		}
		else {
			nx[bf[M]] = -1;
			bf[nx[M]] = -1;
			nx[bk] = M;
			bf[tp] = M;
			int ntp = nx[M];
			int nbk = bf[M];
			nx[M] = tp;
			bf[M] = bk;
			tp = ntp;
			bk = nbk;
		}
	}
	vector<int>ans;
	int cn = tp;
	ans.push_back(cn);
	while (cn!=bk) {
		cn = nx[cn];
		ans.push_back(cn);
	}
	for (int i = 0; i < N; i++) {
		if (i)cout << " ";
		cout << ans[i];
	}
	cout << endl;
}


Measured memory_bytes: 4680
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: Allen
 *
 * Created on January 12, 2019, 5:31 PM
 */

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    string a,b;
    cin>>a>>b;
    int dp[a.size()+1][b.size()+1];
    for(int i=0;i<=a.size();i++){
        dp[i][0]=0;
    }
    for(int i=0;i<=b.size();i++){
        dp[0][i]=0;
    }
    for(int i=1;i<=a.size();i++){
        for(int j=1;j<=b.size();j++){
            dp[i][j]=max(dp[i-1][j],max(dp[i][j-1],a[i-1]==b[j-1]?dp[i-1][j-1]+1:0));
        }
    }
    int x=a.size(),y=b.size();
    string ans="";
    while(dp[x][y]!=0){
        if(dp[x][y]==dp[x-1][y]){
            x-=1;
        }
        else if(dp[x][y]==dp[x][y-1]){
            y-=1;
        }
        else{
            x-=1;
            y-=1;
            ans=a[x]+ans;
        }
    }
    cout<<ans;
    return 0;
}



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

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


using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> in(n);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        in[i] = x;
    }
    whole(sort, in);
    int min = numeric_limits<int>::max();
    for (int j = in.front(); j <= in.back(); ++j) {
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            sum += pow(in[i] - j, 2);
        }
        min = std::min(min, sum);
    }
    cout << min << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 256
/*
Problem Source : arc-103D
Author : oier_hzy
Time : Nov 25 2019
*/

/*
check answer's existence by parity

we could reach all (x,y) which x+y < 2^k
proof : induction (the area we could reach is a Manhattan rectangle)

construct paths by bit -- reduce the maximum absolute values of coordinates
*/

#include <bits/stdc++.h>
using namespace std;

int X[1001], Y[1001];
int d[33], n;

int main() {
	scanf("%d", &n);
	bool exi[2] = {false, false};
	for(int i = 1; i <= n; ++ i) {
		scanf("%d%d", X+i, Y+i);
		exi[(X[i] + Y[i]) & 1] = true;
	}
	if(exi[0] and exi[1]) return puts("-1"), 0;
	
	int m = 0;
	if(exi[0]) d[++m] = 1;
	for(int i = 30; i >= 0; -- i) d[++m] = 1 << i;
	printf("%d\n", m);
	for(int i = 1; i <= m; ++ i) printf("%d ", d[i]);
	putchar(10);
	
	for(int c = 1; c <= n; ++ c) {
		int x = X[c], y = Y[c];
		for(int i = 1; i <= m; ++ i)
			if(abs(x) >= abs(y))
				if(x >= 0) x -= d[i], putchar('R');
				else x += d[i], putchar('L');
			else
				if(y >= 0) y -= d[i], putchar('U');
				else y += d[i], putchar('D');
		putchar(10);
	}
	return 0;
}

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

int main() {

  long long int N;
  cin >> N;
  if (N % 2 == 1) {
    cout << 0 << endl;
  }
  else {
    long long int ans = 0;
    for (long long int i = 5; i <= N; i *= 5) {
      ans += N / (2 * i);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

class Enumeration {
public:
  explicit Enumeration(int n, uint64_t m) : mod(m), fact(n), inv(n), finv(n) {
    fact[0] = finv[0] = inv[1] = 1;
    for (int i = 2; i < n; ++i) inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    for (int i = 1; i < n; ++i) {
      fact[i] = fact[i - 1] * i % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }
  uint64_t operator()(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fact[n] * finv[n - k] % mod * finv[k] % mod;
  }
  uint64_t modpow(uint64_t x, uint64_t e) {
    uint64_t res = 1;
    while (e > 0) {
      if (e & 1) res = res * x % mod;
      x = x * x % mod;
      e >>= 1;
    }
    return res;
  }

private:
  uint64_t mod;
  vector<uint64_t> fact, inv, finv;
};

int main() {

  ll n, m, k;
  cin >> n >> m >> k;

  Enumeration e(n * m, MOD);
  ll ans = 0;
  for (ll i = 1; i < m; ++i) {
    ll j = (m - i) * n * n % MOD;
    ans = (ans + i * j) % MOD;
  }
  for (ll i = 1; i < n; ++i) {
    ll j = (n - i) * m * m % MOD;
    ans = (ans + i * j) % MOD;
  }
  cout << ans * e(n * m - 2, k - 2) % MOD << '\n';

#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 8020
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int x[n],y[n],z[n];
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&x[i],&y[i],&z[i]);
    }
    int h;
    int e;
    int xx,yy;
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            e=1;
            h=1100000000;
            for(int k=0;k<n;k++){
                xx=x[k]-i;
                yy=y[k]-j;
                if(xx<0)xx*=-1;
                if(yy<0)yy*=-1;
                if(h>z[k]+xx+yy){
                    h=z[k]+xx+yy;
                }
            }
            for(int k=0;k<n;k++){
                xx=x[k]-i;
                yy=y[k]-j;
                if(xx<0)xx*=-1;
                if(yy<0)yy*=-1;
                if(h-xx-yy<0){
                    if(z[k]!=0)e=0;
                }
                else {
                    if(z[k]!=h-xx-yy)e=0;
                }
            }
            if(e)printf("%d %d %d\n",i,j,h);
        }
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	int ar[n];
	long long sum = 0;
	for(int i=0;i<n;++i) {
		cin >> ar[i];
		sum += ar[i];
	}
	int c = (int)ceil(sum/(4.0*k));
	int ans = 0;
	for(int i=0;i<n;i++) {
		if(ar[i]>=c) ++ans;
	}
	if(ans >= k) cout << "Yes";
	else cout << "No";
	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
const int N = 1e5 + 5;
 
int n, m, k;
int x11, y11, x2, y2;
int dx[4]={-1, +1, 0, 0};
int dy[4]={0, 0, +1, -1};
vector<vector<char> > a;
vector<vector<int> > vis, ways, dist;
 
void bfs(int x, int y)
{
	queue<pair<int, int> > q;
	q.push({x, y});
	vis[x][y] = 1;
	dist[x][y] = 0;
	while(!q.empty())
	{
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		for(int dir=0;dir<4;dir++)
		{
			for(int len = 1; len <= k; len++)
			{
				int nx=x+dx[dir] * len;
				int ny=y+dy[dir] * len;
				if(nx<1 || ny<1 || nx>n || ny>m)
					break;
				if(vis[nx][ny] && dist[x][y] + 1 > dist[nx][ny])
					break;
				if(a[nx][ny] == '@')
					break;
				if(vis[nx][ny])
					continue;
				dist[nx][ny]=dist[x][y]+1;
				vis[nx][ny]=1;
				q.push({nx, ny});
			}
		}
	}
}
 
int32_t main()
{
	IOS;
	cin >> n >> m >> k;
	cin >> x11 >> y11 >> x2 >> y2;
	a = vector<vector<char> > (n + 1, vector<char> (m + 1));
	vis = ways = dist = vector<vector<int> > (n + 1, vector<int> (m + 1, 0));
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	bfs(x11, y11);
	if(!vis[x2][y2])
		cout << -1;
	else
		cout << dist[x2][y2];
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, K, Q; cin >> N >> K >> Q;
    int F[N] = {0};
    FOR(i,0,Q-1){
        int A; cin >> A; --A;
        ++F[A];
    }

    FOR(i,0,N-1){
        cout << (K-Q+F[i] > 0 ? "Yes" : "No") << '\n';
    }
}



Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int x,y;
	scanf("%d %d", &x, &y);
	int a=x;
	x=0;
	for(int i=0; i<a; i++){
	x=x+i;	
	}
	int b=y;
	y=0;
	for(int i=0; i<b; i++){
		y=y+i;
	}
	printf("%d", x+y);
	return 0;
}

Measured memory_bytes: 3216
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long ans,bns,a[720000],n;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	if(n&1){
		for(int i=1;i<=n/2-1;i++)ans-=a[i]*2;
		for(int i=n/2+2;i<=n;i++)ans+=a[i]*2;
		ans-=a[n/2];
		ans-=a[n/2+1];
		for(int i=1;i<=n/2;i++)bns-=a[i]*2;
		for(int i=n/2+3;i<=n;i++)bns+=a[i]*2;
		bns+=a[n/2+1];
		bns+=a[n/2+2];
		printf("%lld\n",max(bns,ans));
	}else{
		for(int i=1;i<=n/2;i++)ans-=a[i]*2;
		for(int i=n/2+1;i<=n;i++)ans+=a[i]*2;
		ans+=a[n/2];
		ans-=a[n/2+1];
		printf("%lld\n",ans);
	}
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long n,a,b,sum,k,j;
string s;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>a>>b>>s;
for(int i=0;i<n;i++){
    if(s[i]=='a'){
        if(j<a+b){
            j++;
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else if(s[i]=='b'){
        if(k<b&&j<a+b){
                k++;
                j++;
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;
}

return 0;}



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

int main(){
  string s;
  cin>>s;
  
  bool b=true;
  for(int i=0;i<s.size()-1;i++){
    if(s.at(i)==s.at(i+1))
      b=false;
  }
  
  if(!b){
    cout<<"Bad"<<endl;
  }else{
    cout<<"Good"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, int(xs.size()) - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

ll solve(int n, int k, vector<ll> const & a) {
    vector<ll> b;
    REP (l, n) {
        ll acc = 0;
        REP3 (r, l + 1, n + 1) {
            acc += a[r - 1];
            b.push_back(acc);
        }
    }
    ll c = 0;
    REP_R (i, 60) {
        int cnt = 0;
        for (ll b_i : b) {
            if (b_i & (1ll << i)) {
                ++ cnt;
            }
        }
        if (k <= cnt) {
            c |= 1ll << i;
            b.erase(remove_if(ALL(b), [&](ll b_i) { return not (b_i & (1ll << i)); }), b.end());
        }
    }
    return c;
}

int main() {
    int n, k; cin >> n >> k;
    vector<ll> a(n);
    REP (i, n) cin >> a[i];
    cout << solve(n, k, a) << endl;
    return 0;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int b,c,n,m,x=0,y=0,i,j,k;
    int a[100005];
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a[i];
    }
    vector<int>v;
    for(i=n;;i++)
    {
        c=i;
        while(c!=0)
        {
            y=c%10;
            v.push_back(y);
            c=c/10;
        }
        for(j=0;j<v.size();j++)
        {
            x=0;
            for(k=0;k<m;k++)
            {
                if(v[j]==a[k])
                {
                    x=1;
                    break;
                }
            }
            if(x==1)
            {
                break;
            }
        }
        v.clear();
        if(x==0)
        {
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M, L = map(int, input().split())
dist = [[INF] * N for _ in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    if c > L:
        continue
    a -= 1
    b -= 1
    dist[a][b] = c
    dist[b][a] = c
Q = int(input())

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
fuel = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        fuel[i][j] = 1 if dist[i][j] <= L else INF
for k in range(N):
    for i in range(N):
        for j in range(N):
            fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j])
for i in range(Q):
    s,t = map(int, input().split())
    if fuel[s - 1][t - 1] != INF:
        print(fuel[s - 1][t - 1] - 1)
    else:
        print(-1)

Measured memory_bytes: 79032
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  
  vector<vector<int>> p(3,vector<int>(3));
  
  rep(i,3){
    rep(j,3){
    cin>>p[i][j];
    }
  }
  
  bool ok = true;
  
  rep(i,3){
    rep(j,3){
      rep(k,3){
        rep(l,3){
          if(p[i][j]+p[k][l]!=p[i][l]+p[k][j]) ok=false;
        }
      }
    }
  }
  
  cout << (ok?"Yes":"No") << endl;
  
}


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

using namespace std;

int main(){
	string weather[3] = {"Sunny", "Cloudy", "Rainy"};
	string s; cin >> s;
	int idx = 0;
	for(int i = 0; i < 3; ++i) if(s == weather[i]) idx = i;
	(idx += 1) %= 3;
	cout << weather[idx] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

ll n;
stack<int>b;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    if(n==0)cout<<0<<newl;
    else{
        while(n!=0){
            if(abs(n) % 2 == 0){b.push(0);}
            else {b.push(1); n--;}
            n/=(-2);
        }
        while(!b.empty()){
            cout<<b.top();b.pop();
        }
        cout<<newl;
    }

}


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

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	int ans = min(A, B);
	for (int i = 0; i < K; --ans) {
		if (A % ans == 0 && B % ans == 0) ++i;
	}
	cout << ans + 1;
}

Measured memory_bytes: 256
N,M=map(int,input().split())

import heapq
def dijkstra_heap(s):
  #始点sから各頂点への最短距離
  dist=[float("inf")]*size_v  
  used=[False]*size_v
  dist[s]=0
  used[s]=True

  hq_edge=[]
  for v,w,i in graph[s]:
    heapq.heappush(hq_edge,(w,v,i))

  while hq_edge:
    min_w,min_v,ei=heapq.heappop(hq_edge)
    if dist[min_v]>=min_w:
      answer_set.add(ei)
    #まだ使われてない頂点の中から最小の距離のものを探す
    if used[min_v]:
      continue

    dist[min_v]=min_w
    used[min_v]=True
    for v,w,ei2 in graph[min_v]:
      if not used[v]:
        heapq.heappush(hq_edge,(min_w+w,v,ei2))

  return dist

graph=[[] for _ in range(N+1)]
for i in range(M):
  a,b,c=map(int,input().split())
  graph[a].append((b,c,i))
  graph[b].append((a,c,i))
#print(graph)

size_v=N+1
answer_set=set()
for i in range(1,N+1):
  dist=dijkstra_heap(i)
  #print(dist)
    
#print(sorted(list(answer_set)))
print(M-len(answer_set))

Measured memory_bytes: 53212
#include<stdio.h>
#include<string.h>
int main()
{
    char str[100000];
    int i,l,c=0,d=0;
    scanf("%s",str);
    l=strlen(str);
    for(i=2;i<l;i++)
    {
        if(str[i]=='C')
        {
            c++;
        }
        if(str[i]>='a'&&str[i]<='z')
        {
            d++;
        }
    }
    if(str[1]>='a'&&str[1]<='z')
    {
        d=d+1;
    }
    if(str[l-1]=='C')
    {
        c=c-1;
    }
    if(str[0]=='A'&&c==1&&d==l-2)
    {
        printf("AC\n");
    }
    else
    {
        printf("WA\n");
    }

    return 0;
}


Measured memory_bytes: 128
N = int(input())
a = list(map(int,input().split(" ")))
ans = []
sumval = sum(a)
if N == 2:
	print(abs(a[0]-a[1]))
	exit(0)
	
for i in range(N-2):
	a[i+1] += a[i]
	ans.append(abs(sumval-2*a[i+1]))

print(min(ans))




Measured memory_bytes: 24832
if __name__ == "__main__":
    while True:
        n = int(input())
        if n ==0:break
        count = 0
        for i in range(1,n):
            for j in range(i+1,n):
                sum = (i+j)*(j-i+1)/2
                if sum> n:break
                if sum == n:count +=1

        print(count)

Measured memory_bytes: 7640