akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var diff = ab[0] - 2 * ab[1];
            Console.WriteLine(diff >= 0 ? diff : 0);
        }
    }
}


Measured memory_bytes: 13396
n, k = map(int, input().split())
ans = 0

for i in range(1, n+1):
    if i >= k:
        ans += 1/n
    else:
        count = 1
        while i * 2 ** count < k:
            count += 1
        ans += (1/n) * (0.5**count)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

int a[200007] = {};
int ans[200007] = {};

int main() {
    int i,j;
    int N;

    scanf("%d", &N);
    for( i=1; i<=N; i++) {
        scanf("%d", &a[i]);
    }
    int K = 0;
    for( i=1; i<=N; i++) {
        K ^= a[i];
    }

    for( i=1; i<=N; i++) {
        ans[i] = a[i] ^ K;
    }

    for( i=1; i<=N; i++) {
        printf("%d ", ans[i]);
    }
    printf("\n");


    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


Measured memory_bytes: 5268
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let vec_str: Vec<String> = s.trim().split_whitespace().map(|x| x.to_string()).collect();
    let a = vec_str[0].parse::<i32>().unwrap();
    
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let vec_str: Vec<String> = s.trim().split_whitespace().map(|x| x.to_string()).collect();
    let s = vec_str[0].parse::<String>().unwrap();

    if 3200 <= a {
        println!("{}", s);
    } else {
        println!("red");
    }
}


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

inline int readInt(){
  int ret = 0;
  char c;
  while((c=getchar()) && isdigit(c)){
    ret = ret * 10 + (c-'0');
  }
  return ret;
}

void outint(int a){
  if (a == 0)return;
  outint(a/10);
  putchar('0' + a%10);
}

void write(int &p,char *buf,int ans){
  if (ans == 0)return;
  write(p,buf,ans/10);
  buf[p++] = '0'+ans%10;
}

main(){
  int n,s;
  int p = 0;
  char buf[10000000];
  while(true){
    n = readInt();
    if (n==0)break;
    s = readInt();
    int r[101]={0};
    int sum[101];
    for(int i=0;i<n;i++){
      int tmp;tmp=readInt();r[tmp]++;
    }
    sum[0] = 0;
    for(int i=1;i<101;i++){
      sum[i] = sum[i-1] + r[i];
    }
    int ans = 0;
    for(int i=1;i != 101;i++){
      if (r[i] && i+i > s)ans += r[i]*(r[i]-1)/2;
      for(int j=i+1;j<101;j++){
	//if (i+j>s)ans += r[i]*r[j];
	if (i+j > s){
	  ans += r[i] * (sum[100] - sum[j-1]);
	  break;
	}
      }
    }
    //printf("%d\n",ans);
    if (ans == 0){
      buf[p++] = '0';
    }else     write(p,buf,ans);
    buf[p++] = '\n';
  }
  buf[p-1] = '\0';
  puts(buf);
}

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

using namespace std;

using ll = long long;

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

    string s;
    cin >> s;

    const int n = s.size();
    int cnt = 0, idx = 0;
    bool is_white = (s.front() == 'B');

    while (idx < n) {
        if ((s[idx] == 'W') && !is_white) {
            ++cnt;
            is_white = true;
        }
        else if ((s[idx] == 'B') && is_white){
            ++cnt;
            is_white = false;
        }
        ++idx;
    }

    cout << cnt -  1 << endl;

    return 0;
}


Measured memory_bytes: 512
#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()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	double tax;
	tax = 1.08;

	int q;
	q = ceil(n / tax);
	if (floor(q * tax) == n)
		cout << q << endl;
	else
		cout << ":(" << endl;
}


Measured memory_bytes: 256
e=[[int(i) for i in input().split()]for i in range(3)]
#print(e)
val=0
for j in range(3):
  for i in range(3):
    val+=e[j][i]
val0=val//3
#print(val0)
val1=e[0][0]+e[1][1]+e[2][2]
val2=e[1][0]+e[2][1]+e[0][2]
val3=e[2][0]+e[1][2]+e[0][1]
val4=e[2][0]+e[1][1]+e[0][2]
val5=e[2][2]+e[1][0]+e[0][1]
val6=e[0][0]+e[2][1]+e[1][2]
#print(val1,val2,val3,val4,val5,val6)
if val0==val1==val2==val3==val4==val5==val6:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#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(){
    string s;
    cin >> s;
    string s2;
    s2=s.substr(0,3);
    cout << s2 << endl;
    

    return 0;
}

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

int a[2010][2010];
int dp1[2010][2010], dp2[2010][2010], dp3[2010][2010], dp4[2010][2010];
char s[2010];

int main(){
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++){
		scanf("%s", s + 1);
		for (int j = 1; j <= m; j++){
			a[i][j] = s[j] == '#' ? 0 : 1;
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if (a[i][j] == 0) dp1[i][j] = 0, dp2[i][j] = 0;
			else dp1[i][j] = dp1[i - 1][j] + 1, dp2[i][j] = dp2[i][j - 1] + 1;
		}
	}
	for (int i = n; i >= 1; i--){
		for (int j = m; j >= 1; j--){
			if (a[i][j] == 0) dp3[i][j] = dp4[i][j] = 0;
			else dp3[i][j] = dp3[i + 1][j] + 1, dp4[i][j] = dp4[i][j + 1] + 1;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if (a[i][j] == 0) continue;
			ans = max(ans, dp1[i][j] + dp2[i][j] + dp3[i][j] + dp4[i][j] - 3);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<cstddef>
#include<cstdint>
#include<vector>
#include<algorithm>
using usize=std::size_t;
using i64 = std::int_fast64_t;

int main(){
static constexpr i64 Inf=std::numeric_limits<i64>::max()/2;
  static constexpr usize B=300;

std::ios::sync_with_stdio(false);
std::cin.tie(0);

  struct block_t{
    i64 x;
    std::vector<i64> a,b;
    std::vector<i64> bma,ra,rb;

    block_t():x(0),a(B,0),b(B,Inf),bma(B),ra(B+1),rb(B+1){}

    void build(){
      std::vector<usize> idx(B);
      for(usize i=0;i<B;++i)idx[i]=i;
      std::sort(idx.begin(),idx.end(),[&](usize l_,usize r_){
        return b[l_]-a[l_]<b[r_]-a[r_];
      });
      for(usize i=0;i<B;++i){
        bma[i]=b[idx[i]]-a[idx[i]];
      }
      ra[0]=Inf;
      for(usize i=0;i<B;++i){
        ra[i+1]=std::min(ra[i],a[idx[i]]);
      }
      rb[B]=Inf;
      for(usize i=B;i!=0;--i){
        rb[i-1]=std::min(rb[i],b[idx[i-1]]);
      }
    }

    void add_all(const i64 x_){
      x+=x_;
    }
    i64 get_all(){
      const usize i = std::lower_bound(bma.cbegin(),bma.cend(),x)-bma.cbegin();
      return std::min(ra[i]+x,rb[i]);
    }
    i64 get_part(const usize l,const usize r){
      i64 ret=Inf;
      for(usize i=l;i<r;++i){
        ret=std::min(ret,std::max(a[i]+x,b[i]));
      }
      return ret;
    }
    void add_part(const usize l,const usize r,const i64 x_){
      for(usize i=l;i<r;++i){
        a[i]+=x_;
      }
      build();
    }
  };


  usize n,q;
  std::cin>>n>>q;

  std::vector<block_t> sqd(n/B+1);

  for(usize i=0;i<n;++i){
    std::cin>>sqd[i/B].a[i%B]>>sqd[i/B].b[i%B];
  }
  for(auto &e:sqd)e.build();


  for(usize i=0;i<q;++i){
    usize t,l,r;
    std::cin>>t>>l>>r;
    l-=1;
    
    if(t==1){
      i64 x;
      std::cin>>x;
      if(l/B==r/B){
        sqd[l/B].add_part(l%B,r%B,x);
      }else{
        sqd[l/B].add_part(l%B,B,x);
        for(usize i=l/B+1;i<r/B;++i){
          sqd[i].add_all(x);
        }
        sqd[r/B].add_part(0,r%B,x);
      }
    }else{
      i64 ans=Inf;
      if(l/B==r/B){
        ans=sqd[l/B].get_part(l%B,r%B);
      }else{
        ans=std::min(ans,sqd[l/B].get_part(l%B,B));
        for(usize i=l/B+1;i<r/B;++i){
          ans=std::min(ans,sqd[i].get_all());
        }
        ans=std::min(ans,sqd[r/B].get_part(0,r%B));
      }
      std::cout<<ans<<std::endl;
    }
  }
}

/*

a+x>b    x > b-a
a+x <=b  x <= b-a

*/


Measured memory_bytes: 6720
#include <iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX + 1];

void maxHeapify(int i) // sink(int i) Algorithms 4th
{
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;

    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if (r <= H && A[r] > A[largest]) largest = r;

    if (largest != i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main(int argc, char const *argv[])
{
    cin >> H;

    for (int i = 1; i <= H; i++) {
        cin >> A[i];
    }
    for (int i = H / 2; i >= 1; i--) {
        maxHeapify(i);
    }
    for (int i = 1; i <= H; i++) {
        cout << " " << A[i];
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 5012
import numpy as np
import cmath
N = input()
N = int(N)
#nums = []
nu = input().split()
nui = [int(s) for s in nu]
nus = set(nui)
nul = list(nus)
if((len(nul)==1) and (nul[0]==0)):
    print("Yes")
else:
    if(N%3==0):
        if(len(nul)==2):
            if(nul[0] < nul[1]):
                a = nul[0]
                b = nul[1]
            else:
                a = nul[1]
                b = nul[0]
            a_c = nui.count(a)
            b_c = nui.count(b)
            if(a_c*2 == b_c):
                print("Yes")
            else:
                print("No")

        elif(len(nul)==3):
            a = nul[0]
            b = nul[1]
            c = nul[2]
            a_c = nui.count(a)
            b_c = nui.count(b)
            c_c = nui.count(c)
            if((a_c == b_c) and (b_c==c_c)):
                a_s = list(format(a,"040b"))
                b_s = list(format(b,"040b"))
                c_s = list(format(c,"040b"))
                
                a_si = [int(s) for s in a_s]
                b_si = [int(s) for s in b_s]
                c_si = [int(s) for s in c_s]
                
                a_np = np.array(a_si)
                b_np = np.array(b_si)
                c_np = np.array(c_si)
                
                sumnp = a_np + b_np + c_np
                
                amari = sumnp%2
                
                ind = np.where(amari==1)
                
                if(len(ind[0])==0):
                    print("Yes")
                else:
                    print("No")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 23328
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  int N,  ans = 0 ;
  cin >> N ;
  double answer = N * 3.141592 * 2 ;
  cout << answer << endl ;
  return 0 ;
}  

Measured memory_bytes: 3764
#include <stdio.h>

int main(void){

  int N;
  scanf("%d", &N);
  int i,j,k;
  long long c[5]={0,0,0,0,0};
  for(i=0; i<N; i++){
    char S[20];
    scanf("%s", S);
    
    if(S[0] == 'M'){
      c[0]++;
    }else if (S[0] == 'A'){
      c[1]++;
    }else if (S[0] == 'R'){
      c[2]++;
    }else if (S[0] == 'C'){
      c[3]++;
    }else if (S[0] == 'H'){
      c[4]++;
    }
  }

  unsigned long long count = 0;

  for(i=0; i<5; i++){
    for(j=i; j<5; j++){
      for(k=j; k<5; k++){
	
	if( i!=j && j!= k && k!= i){
	  count += c[i]*c[j]*c[k];
	}
      }
    }
  }
	  
  printf("%llu\n" , count);
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define mod 1000000007
typedef long long ll;
using namespace std;

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;


    UnionFind(ll N): par(N), siz(N, 1LL) {
        for (ll i = 0; i < N; ++i) par[i] = i;
    }

    void init(ll N) {
        par.resize(N);
        siz.assign(N, 1LL);
        for (ll i = 0; i < N; ++i) par[i] = i;
    }


    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }


    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int main(){
    ll N,M; cin >> N >> M;
    UnionFind tree(N);

    for(int i=0;i<M;i++){
        ll X,Y,Z; cin >> X >> Y >> Z;
        X--; Y--;
        tree.unite(X,Y);
    }

    set<ll> st;
    for(int i=0;i<N;i++){
        st.insert(tree.root(i));
    }

    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    long long A,B,C,K,ans=0;
    cin>>A>>B>>C>>K;
    if(A>=K){
        ans=K;
    }else if(A+B>=K){
        ans=A;
    }else{
        ans=A-(K-A-B);
    }
    
     cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 500;

int N, Mod;

vector<pair<int, int> > p;
ll f[Maxn + 5][Maxn + 5];

inline int F(int i) {
	static int ret = 2 * N - 1;
	while(ret >= 0 && i * i + ret * ret > 4 * N * N)
		ret--;
	return ret + 1;
}
inline int G(int i) {
	static int ret = 2 * N - 1;
	while(ret >= 0 && i * i + ret * ret >= N * N)
		ret--;
	return ret + 1;
}

int main()
{
	scanf("%d %d", &N, &Mod);
	for(int i = 0; i <= 2 * N - 1; i++) {
		if(i < N) p.push_back(make_pair(G(i), F(i)));
		else p.push_back(make_pair(F(i), 0));
	}
	sort(p.begin(), p.end());
	ll ans = 0;
	for(int k = 0; k <= N; k++) {
		memset(f, 0, sizeof f);
		f[0][0] = 1;
		int cnt1 = 0, cnt2 = 0;
		for(int i = 0; i < (int)p.size(); i++) {
			for(int j = 0; j <= k; j++)
				if(p[i].second == 0) {
					f[i + 1][j] = (f[i + 1][j] + f[i][j] * (p[i].first - j - cnt1) % Mod) % Mod;
				} else {
					if(j < k) f[i + 1][j + 1] = (f[i + 1][j + 1] + f[i][j] * (p[i].first - j - cnt1) % Mod) % Mod;
					f[i + 1][j] = (f[i + 1][j] + f[i][j] * (p[i].second - N - k - (cnt2 - j)) % Mod) % Mod;
				}
			if(p[i].second == 0) cnt1++;
			else cnt2++;
		}
		if(k % 2) ans = (ans - f[p.size()][k] + Mod) % Mod;
		else ans = (ans + f[p.size()][k]) % Mod;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 5260
ary=gets.chomp.split(" ").map{|x| x.to_i}
n=ary[0]
k=ary[1]
ts=gets.chomp.split(" ").map{|x| x.to_i}.sort{|a,b| b<=>a}
top=ts.shift
if ts.size==0
  puts top-1
else
sum=ts.inject(:+)
if top-sum-1>0
  puts top-sum-1
else
  puts 0
end
end

Measured memory_bytes: 1788
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int k; cin >> k;
	string s; cin >> s;
	vector<pii> v;
	v.emplace_back(1, s[0]);
	FOR(i, 1, n) {
		if (v.back().second == s[i])v.back().first++;
		else v.emplace_back(1, s[i]);
	}
	int ans = 0;
	REP(i, v.size())ans += v[i].first - 1;
	cout << min(n - 1, ans + 2 * k) << endl;
}

Measured memory_bytes: 1480
N=int(input())
Ins=[[] for _ in range(N)]
ans=0

#0-indexedにしておく
for i in range(N):
  A=int(input())
  for _ in range(A):
    x,y=map(int,input().split())
    Ins[i].append((x-1,y))

for i in range(2**N):
  flag=1
  honest=[]
  unkind=[]
  for j in range(N):
    if (i>>j)&1:
      honest.append(j)
    else:
      unkind.append(j)
      #ここまでは想定の組み合わせを作る作業
  for k in honest:
    #honestな人の証言を見ていく
    for l in Ins[k]:
      if l[1]==1 and l[0] in unkind:
        flag=0
        break
        #honestな人がある人物をhonestと答えたのにも関わらず
        #その人がunkindに入るような組み合わせは駄目...ケース1
      elif l[1]==0 and l[0] in honest:
        flag=0
        break
        #honestな人がある人物をunkindと答えたのにも関わらず
        #その人がhonestに入るような組み合わせは駄目...ケース2
  if flag==1:
    ans=max(ans,len(honest))
    #ケース1にもケース2にも該当しない場合
    #現在のhonestの人数をansと比較して大きい方を採用
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int a, b, c, d, e, f;
bool w[10100], s[10100];

void solve(){
    cin >> a >> b >> c >> d >> e >> f;

    w[0] = 1;
    for(int i = 0; i <= f; ++i){
        if(w[i]){
            w[i + 100 * a] = w[i + 100 * b] = 1;
        }
    }

    s[0] = 1;
    for(int i = 0; i <= f; ++i){
        if(s[i]){
            s[i + c] = s[i + d] = 1;
        }
    }

    double con = -inf;
    int W = 0, S = 0;
    for(int i = 100; i <= f; i += 100){
        for(int j = 0; j <= f - i; ++j){
            if(w[i] && s[j] && j <= i * e / 100){
                double cur = 100.0 * (double)j / double(i + j);
                if(cur > con){
                    con = cur;
                    W = i;
                    S = j;
                }
            }
        }
    }
    cout << W + S << " " << S << "\n";
}

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

    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if  (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    double n,a,sum=0;
    cin >> n;
    rep(i,n){
        cin >> a;
        sum+=1/a;
    }
    printf("%.10f\n",1/sum);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int l[3] = {};
int a[10];
void sort() {
	int b;
	if (l[2] < l[1]) {
		b = l[1];
		l[1] = l[2];
		l[2] = b;
	}
	if (l[1] < l[0]) {
		b = l[1];
		l[1] = l[0];
		l[0] = b;
	}
	if (l[2] < l[1]) {
		b = l[1];
		l[1] = l[2];
		l[2] = b;
	}
}
int main()
{
	for (int i = 0; i < 10; i++)cin >> a[i];
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 3; j++) {
			if (l[j] < a[i]) {
				l[j] = a[i];
				sort();
				break;
			}
		}
	}
	for (int j = 2; j >=0; j--) {
		cout << l[j] << endl;
	}
    return 0;
}




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

int main() {
    int num1, num2;
    char op;
    
    cin >> num1 >> op >> num2;
    
    if (op == '+')
      cout << num1 + num2 << endl;
    else
      cout << num1 - num2 << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 500002
mt19937 myrand(time(0));

ll fact[mx],inv[mx];

ll bigmod(ll a, ll p, ll m){
    ll res=1,x=a;
    while(p){
        if(p&1) res=(res*x)%m;
        x=(x*x)%m;
        p=p>>1;
    }
    return res;
}

void precalc(){
    fact[0]=1;
    for(int i=1;i<mx;i++) fact[i]=(i*fact[i-1])%mod;
    inv[mx-1]=bigmod(fact[mx-1],mod-2,mod);
    for(int i=mx-2;i>=0;i--) inv[i]=((i+1)*inv[i+1])%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    precalc();
    ll n,m;
    cin>>n>>m;
    ll ans=(fact[m]*inv[m-n])%mod;
    ll ways=0;
    for(int i=0;i<=n;i++){
        ll tmp=(fact[m-i]*inv[m-n])%mod;
        tmp=(tmp*fact[n])%mod;
        tmp=(tmp*inv[i])%mod;
        tmp=(tmp*inv[n-i])%mod;
        if(i&1) ways=(ways-tmp)%mod;
        else ways=(ways+tmp)%mod;
        ways=(ways+mod)%mod;
    }
    ans=(ans*ways)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11436
#include "bits/stdc++.h"
using namespace std;

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n,m;
int u,v;
LL s;

int visited[100000];
bool visited_fill[100000];

vector<vector<pair<int,LL>>> g;
vector<LL> v1,v2;
LL val[100000];
int n1,n2;
vector<int> m1,m2;

bool oddsearch(int x,int color){
  if(visited[x]!=-1 && visited[x]!=color)
    return true;
  if(visited[x]!=-1)
    return false;
  if(visited[x]==-1)
    visited[x]=color;
  bool ret=false;
  REP(i,g[x].size()){
    ret = ret | oddsearch(g[x][i].first,1-color);
  }
  return ret;
}

void fill(int x,LL l){
  if(visited_fill[x])
    return;
  visited_fill[x]=true;
  val[x]=l;
  if(visited[x]==0){
    m1.push_back(x);
    v1.push_back(l);
  }else{
    m2.push_back(x);
    v2.push_back(l);
  }
  REP(i,g[x].size()){
    fill(g[x][i].first,g[x][i].second-l);
  }
}

bool all_ok(){
  REP(i,n){
    REP(j,g[i].size()){
      if(val[i]+val[g[i][j].first]!=g[i][j].second){
	n1=i;
	n2=g[i][j].first;
	return false;
      }
    }
  }
  return true;
}
	      

int main(){
  cin>>n>>m;
  REP(i,n)
    visited[i]=-1;
  g.resize(n);
  REP(i,m){
    cin>>u>>v>>s;
    u--;
    v--;
    g[u].push_back(make_pair(v,s));
    g[v].push_back(make_pair(u,s));
  }
  bool odd=oddsearch(0,0);
  
  if(odd){
    REP(i,n)
      visited_fill[i]=false;
    fill(0,0);
    if(all_ok()){
      //min
      LL a =*min_element(v1.begin(), v1.end());
      LL b =*min_element(v2.begin(), v2.end());
      cout<<min((LL)1,max(a+b-1,(LL)0))<<endl;
    }else if(visited[n1] != visited[n2]){
      cout<<0<<endl;
    }else{
      LL tmp;
      REP(i,g[n1].size()){
	if(g[n1][i].first == n2){
	  tmp = g[n1][i].second;
	  break;
	}
      }
      LL diff = tmp - val[n1] - val[n2];
      //cerr<<"diff:"<<diff<<endl;
      if(diff % 2 != 0){
	cout<<0<<endl;
      }else{
	diff /= 2;
	REP(i,n){
	  if(visited[i]==visited[n1])
	    val[i]+=diff;
	  else
	    val[i]-=diff;
	}
	if(all_ok()){
	  //min
	  LL a =*min_element(v1.begin(), v1.end());
	  LL b =*min_element(v2.begin(), v2.end());
	  cout<<min((LL)1,max(a+b-1,(LL)0))<<endl;
	}else{
	  cout<<0<<endl;
	}
      }
    }
  }else{
    REP(i,n)
      visited_fill[i]=false;
    fill(0,0);
    LL a =*min_element(v1.begin(), v1.end());
    LL b =*min_element(v2.begin(), v2.end());
    if(all_ok())
      cout<<max(a+b-1,(LL)0)<<endl;
    else
      cout<<0<<endl;
  }
  return 0;
}


Measured memory_bytes: 15200
n = int(input())
a = input().split()
if(n==1):
    print(a[0])
    exit()

a_num = list( map(int, a[::2]))
a_op = a[1::2]

cumsum = a_num[::]
cumsum_op = [0] * n
cumsum_op[0] = a_num[0]
minus_ind = []
for i in range(1,n):
    cumsum[i] += cumsum[i-1]
    if(a_op[i-1] == '+'):
        cumsum_op[i] = cumsum_op[i-1] + a_num[i]
    else:
        cumsum_op[i] = cumsum_op[i-1] - a_num[i]
        minus_ind.append(i)

ans = cumsum_op[-1]
if(len(minus_ind)<2):
    print(ans)
    exit()

for l,r in zip(minus_ind[:-1],minus_ind[1:]):
    # lまでは符号通り、l,r-1までを減算、r以降を全て加算
    tmp = cumsum_op[l-1] - (cumsum[r-1] - cumsum[l-1]) + (cumsum[-1] - cumsum[r-1])
    ans = max(ans,tmp)

print(ans)

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int K;
    int A,B;
    cin >> K >> A >> B;
    FORq(i,A,B){
      if (i % K == 0){
        puts("OK");
        return 0;
      }
    }

    puts("NG");
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

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

		int k = 0;
		int i = 0;
		while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		}
		if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		}
		
	}

}


Measured memory_bytes: 52688
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int dp[][] = new int[N+1][W+1];
        for(int i = 0 ; i < W+1 ; i++)
            dp[0][i] = 0;
        Data data[] = new Data[N];
        for(int i = 0 ; i < N ; i++){
            int v = sc.nextInt();
            int w = sc.nextInt();
            data[i] = new Data(v,w);
        }
        for(int i = 0 ; i < N ; i++){
            for(int j = 0 ; j < W+1 ; j++){
                if(data[i].w <= j)
                    dp[i+1][j] = Math.max(dp[i+1][j-data[i].w] + data[i].v , dp[i][j]);
                else
                    dp[i+1][j] = dp[i][j];
            }
        }
        System.out.println(dp[N][W]);
    }
}
class Data{
    int v;
    int w;
    Data(int v, int w){
        this.v = v;
        this.w = w;
    }
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int a = Integer.parseInt(in.readLine());
    System.out.println(a + (int)Math.pow(a,2) + (int)Math.pow(a,3));
  }
}

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

int main() {
    int n,m,i;
    cin >> n >> m;
    int x[n];
    int h[n];
    for(i=0;i<n;i++){
        cin >> h[i];
            x[i]=0;
    }
    int a,b;
    for(i=0;i<m;i++){
        cin >> a >> b;
        if(h[a-1]>h[b-1]){
            if(x[a-1]!=-1){
            x[a-1]++;
            x[a-1]=1;
            }
            x[b-1]=-1;
        }
        else if(h[b-1]>h[a-1]){
            if(x[b-1]!=-1){
            x[b-1]++;
            }
            x[a-1]=-1;
        }
        else
        {
            x[a-1]=-1;
            x[b-1]=-1;
        }
    }
    int count=0;
    for(i=0;i<n;i++)
    {
        if((x[i]!=-1||x[i]==0)){
        //cout << i << "\n";
        count++;
        }
    }
    cout << count << "\n";
}

Measured memory_bytes: 4408
from sys import stdin, setrecursionlimit


def factorization(n):
    arr = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt

    if temp != 1:
        arr[temp] = 1

    if arr == []:
        arr[n] = 1

    return arr


def main():
    input = stdin.buffer.readline
    n, p = map(int, input().split())
    f = factorization(p)
    ans = 1
    for k in f:
        if f[k] >= n:
            ans *= k ** (f[k] // n)
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)
int main(){
    string s, t; cin>> s >> t;
    int n = t.size();
    int ans = 1e+9;
    int cnt = 0;
    for(int i=0; i<s.size() - n + 1; i++){
        for(int j=0; j<n; j++){
            if(t[j] != s[i+j]) cnt++;
        }
        ans = min(ans, cnt);
        cnt = 0;
    }
    cout<< ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  int n;
  cin >> n;
  int res = 0;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = n - 1; i >= 0; i--) {
    int x, y, z;
    x = a[i] + res;
    y = b[i];
    z = (x % y == 0) ? 0 : (y - x % y);
    res += z;
  }
  cout << res << endl;
}

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

int main(void) {
  ll N; cin >> N;
  vector<ll> A(N);
  ll A1 = 0;
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
    if ((i+1)%2 == 1) A1 += A.at(i);
    else A1 -= A.at(i);
  }
  cout << A1;
  for (ll i = 0; i < N-1; i++) {
    A1 = A.at(i)*2 - A1;
    cout << ' ' << A1;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = unsigned long long;
using namespace std;

int main(void) {
    int a,b;
    cin >> a >> b;

    for(int i = 1; i <= 3; ++i) {
        if ((a * b * i) & 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, x; cin>>n;
    bool ok = 1;
    loop(n){
        cin>>x;
        if(!(x&1) && (x%3!=0 && x%5!=0)) ok = 0;
    }
    cout<<(ok?"APPROVED\n":"DENIED\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n, m; cin >> n >> m;
  if(n==m) cout << "Yes\n";
  else cout << "No\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    b = [int(i) for i in input().split()]
    l = []
    b_len = len(b)

    for _ in range(b_len):
        for i in range(len(b)-1, -1, -1):
            if b[i] == i+1:
                l.append(b.pop(i))
                break
        else:
            print(-1)
            sys.exit()

    l.reverse()
    for i in l:
        print(i)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38612
#include<bits/stdc++.h>
#define ll  long long int
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
/*const int N = 2e6+5;
ll cnt[N];*/
/*bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
     return (a.f<b.f);
}*/
void solve()
{   ll n,m,k,y,x,res=0,l,r,cnt0=0,z,sum1=0,cnt1=0,h,res1,ans=1,sum=0;
    cin>>n;
   cout<<(n-2)*180;
}
int main()
{   speed_up
    ll t;
   //cin>>t;
    t=1;
    while(t--)
        solve();

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n;
  cin >> n;
  int sum = 0, m = 0, l;
  for (int i = 0; i < n; i++){
    cin >> l;
    sum += l;
    m = max(m, l);
  }

  if (sum - m > m)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
 
int main() {
vector<int> in_list;
vector<bool> isprime;
int m = 0, N, tmp, Nsqrt, cnt;
 
scanf("%d", &N);
for(int i=0; i<N; ++i) {
scanf("%d", &tmp);
if(m < tmp) m = tmp;
in_list.push_back(tmp);
}
 
isprime.resize(m, true);
isprime[0] = false;
Nsqrt = sqrt(m)+1;
 
for(int i=2; i<=Nsqrt; ++i) {
if(isprime[i-1] == false) continue;
for(int j=2*i; j<=m; j+=i) {
isprime[j-1] = false;
}
}
 
cnt = 0;
 
for(vector<int>::iterator itr=in_list.begin(); itr!=in_list.end(); ++itr) {
if(isprime[*itr-1]) ++cnt;
}
 
printf("%d\n", cnt);
return 0;
}

Measured memory_bytes: 13336
#include <iostream>
#include <cstdio>
#define N 3002
using namespace std;
int n,m,k,l,r,u,d,i,j,ans[N][N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			int x=i+j,y=i-j+m-1;
			l=min(l,y);r=max(r,y);
			u=min(u,x);d=max(d,x);
		}
	}
	for(i=u;i<=d;i++){
		for(j=l;j<=r;j++){
			int x=i+1,y=j+1;
			if(((x-1)/k)%2==0){
				if(((y-1)/k)%2==0) ans[i][j]=1;
				else ans[i][j]=2;
			}
			else{
				if(((y-1)/k)%2==0) ans[i][j]=3;
				else ans[i][j]=4;
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			int x=i+j,y=i-j+m-1;
			if(ans[x][y]==1) printf("R");
			else if(ans[x][y]==2) printf("Y");
			else if(ans[x][y]==3) printf("G");
			else printf("B");
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 11504
import java.util.*;
import java.io.*;
import java.math.*;


import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;


public class Main{ 


    static long mod=1000000007;
     // static int dx[]={1,-1,0,0};
     //  static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();


public  static void main(String[] args)   throws Exception, IOException{

    
    Reader sc = new Reader(System.in);
    PrintWriter out=new PrintWriter(System.out);

    //  int n=sc.nextInt();  
    int n=sc.nextInt();  
    // int d[]=new int[n];
    // long d[]=new long[n];
    int a=sc.nextInt();  
    int b=sc.nextInt();
    long ans=0,aa=a,bb=b,nn=n;  
    if(a==b)ans=1;
    else if(a<b && n>1){     
            ans=(nn-1)*bb+aa-( (nn-1)*aa+bb )+1;
    }

    out.println(ans);
    out.flush();
}

static void rep(int x, long d){

}

static void db(Object... os){

    System.err.println(Arrays.deepToString(os));

}

static boolean validpos(int x,int y,int r, int c){
    
    return x<r && 0<=x && y<c && 0<=y;
    
}
 
static boolean bit(long x,int k){
    // weather k-th bit (from right) be one or zero
    return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
}

}


class XY {
    int x,y,d;
    XY(int x, int y, int d) {
        this.x=x;
        this.y=y;
        this.d=d;
    } 
}

class P implements Comparable<P>{
    int x,y;
    P(int x, int y) {
        this.x=x;
        this.y=y;
    } 
      
    public int compareTo(P p){
        return x - p.x;
    } 
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}



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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;
int n;
int a[2005];
int dp[2005][2005];
pair<int,int> p[2005];

int recfun(int l,int r)
{
	if(l>r)return 0;

	if(dp[l][r]!=-1)return dp[l][r];

	int idx = n-(r-l+1);
	int leftval = abs(p[idx].ss-l)*(p[idx].ff)+recfun(l+1,r);
	int rightval = abs(p[idx].ss-r)*(p[idx].ff)+recfun(l,r-1);

	dp[l][r]=max(leftval,rightval);

	return dp[l][r];
}

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

	cin>>n;

	int x;
	for (int i = 0; i < n; ++i)
	{	
		cin>>x;
		p[i].ff=x;
		p[i].ss=i;
	}

	memset(dp,-1,sizeof(dp));

	sort(p,p+n);	

	reverse(p,p+n);
	cout<<recfun(0,n-1)<<'\n';

	return 0;
}	

Measured memory_bytes: 35180
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using vi = vector<int>; using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
typedef pair<ll,ll> Pair;
bool p_compare(const Pair& firstP, const Pair& secondP)
 { return firstP.first < secondP.first; }//sort(all(v),p_compare)で昇順ソート
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

ll n,m;
vector<Pair> v;

int main(){
	cin>>n>>m;ll aa,bb;
	rep(i,n){
		cin>>aa>>bb;
		v.pb(mp(aa,bb));
	}
	ll ans = 0;
	sort(all(v),p_compare);
	ll i=0;
	while(m>0){
		if(v[i].second<=m){
			m -= v[i].second;
			ans += v[i].first * v[i].second; 
		}else{
			ans += v[i].first * m;
			m -= m;
		}
		i++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<math.h>
#include<algorithm>

using namespace std;
int data[222];
int main(){

	int n;
	cin>>n;
	int A,B;
	cin>>A>>B;
	int C;
	cin>>C;
	for(int i=0;i<n;i++)cin>>data[i];
	sort(data,data+n,greater<int>());
	int cal=C;
	int mon=A;
	int num=0;
	while(1.*cal/mon<1.*(cal+data[num])/(mon+B)){
		cal+=data[num++];
		mon+=B;
	}
	cout<<cal/mon<<endl;
}

Measured memory_bytes: 1176
#include <cstdio>

int main() {
    int K,S,X,Y,count=0;
    scanf("%d %d",&K,&S);
    for (X=0; X<=K && X<=S; X++) {
        for (Y=0; Y<=K && Y<=S-X; Y++) {
            if (S-X-Y <= K) count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()

typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
//#define int long long
vector<int> dag[100005];
int dp[100005];
int dfs(int x) {
    if(dp[x]) return dp[x];
    for(int i = 0; i < dag[x].size(); i++) {
        chmax(dp[x],dfs(dag[x][i])+1);
    }
    return dp[x];
}
        
inline void solve(){

    int n, m;
    cin >> n >> m;
    int x, y;
    for(int i = 0; i < m; i++) {
        cin >> x >> y;
        dag[x].bash(y);
    }
    
    int maxi = 0;
    for(int i = 1; i <= n; i++) {
        chmax(maxi,dfs(i));
    }
    
    cout << maxi << endl;

}

struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}



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

void out(int*A, int N) {
	cout << A[0];
	for (int i = 1; i < N; i++) {
		cout << " " << A[i];
	}
	cout << endl;
}

void swap(int& x, int& y) {
	int temp;
	temp = x;
	x = y;
	y = temp;
}

void selectsort(int*A, int N) {
	int head = 0;
	int count = 0;
	while (head < N) {
		int minj = head;
		for (int j = head; j < N; j++) {
			if (A[minj] > A[j])
				minj = j;
		}
		if (A[head]>A[minj]){
			swap(A[head], A[minj]);
			count++;
		}	
		head++;
	}
	out(A, N);
	cout << count << endl;
}

int main() {
	int N;
	cin >> N;
	int* A = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	selectsort(A, N);
}


Measured memory_bytes: 3088
// C - Traveling Salesman around Lake
#include <bits/stdc++.h>
using namespace std;

int main(){
	int K,N; cin>>K>>N;
	int pre, now;
	cin>>pre;// first ai[0]
	int max_dist = 0;
	int last_dist = pre;
	while(--N){
		cin>>now;// ai[1~N-1]
		max_dist = max(max_dist, now - pre);
		pre = now;
	}
	last_dist += K - pre;//first + (K-last)
	max_dist = max(max_dist, last_dist);
	cout<< K - max_dist <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int d;
    while(cin>>d){
         long long s=0;
        for(int i=0;i<600/d;i++){
            s+=d*d*d*i*i;
        }
        cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long  N;
  cin >> N;
  for(long long h=1;h<=3500;h++){
    for(long long n=1;n<=3500;n++){
      if(0<(4*h*n-N*n-N*h) && N*h*n%(4*h*n-N*n-N*h)==0){
        long long a=4*h*n-N*n-N*h;
        cout << h << " " << n << " " << N*h*n/a << endl; return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
int main() {
	int t,n;
	while(scanf("%d",&t),t) {
		scanf("%d",&n);
		int sum=0;
		for(int i=0;i<n;i++) {
			int s,f;
			scanf("%d %d",&s,&f);
			sum+=(f-s);
		}
		if(sum>=t) printf("OK\n"); else printf("%d\n",t-sum);
	}
}

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

int n, w;
long long memo[101][100010];
long long c[101], ww[101];

long long dp(int i, int k) {
    if (i == n) return 0;
    if (memo[i][k] != -1) return memo[i][k];
    long long ans = - (1 << 30);
    if (ww[i] <= k) ans = max(ans, c[i] + dp(i + 1, k - ww[i]));
    ans = max(ans, dp(i + 1, k));
    return memo[i][k] = ans;
}

int main() {
    cin >> n >> w;
    for(int i = 0; i < n; i++) cin >> ww[i] >> c[i];
    memset(memo,-1,sizeof(memo));
    cout << dp(0,w) << "\n";
    return 0;
}

Measured memory_bytes: 79104