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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
int types[4];
// 0: XA
// 1: BA
// 2: BX
// 3: XXo

int count(const string& s) {
  int ret = 0;
  for (int i=0; i<int(s.size())-1; i++) {
    if (s[i] == 'A' && s[i+1] == 'B') {
      ret++;
    }
  }
  return ret;
}

int main(int argc, char** argv) {
  int N;
  cin >> N;

  ll ret = 0;

  for (int i=0; i<N; i++) {
    string s;
    cin >> s;

    ret += count(s);

    int t = 3;
    if (s[0] == 'B' && s[s.size()-1] == 'A') {
      t = 1;
    } else if (s[0] == 'B') {
      t = 2;
    } else if (s[s.size()-1] == 'A') {
      t = 0;
    }
    types[t]++;
  }

  // 1: BA
  if (types[1] >= 2) {
    ret += types[1]-1;
    types[1] = 1;
  }

  if (types[1] > 0 && types[0] > 0) {
    ret++;
    types[1]--;
  } else if (types[1] > 0 && types[2] > 0) {
    ret++;
    types[1]--;
  }

  while (types[0] > 0 && types[2] > 0) {
    ret++;
    types[0]--;
    types[2]--;
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
n,l=map(int,input().split())
aji_lis=[int(l+i-1) for i in range(1,n+1)]

N_sum=sum(aji_lis)
ap=min([abs(i) for i in aji_lis])

if N_sum >=0:
    print(N_sum-ap)
else:
    print(N_sum+ap)



Measured memory_bytes: 2940
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = sum(a)
for i in range(n):
    if a[i]>=b[i]:
        a[i] -= b[i]
    else:
        a[i+1] = max(0,a[i+1]-b[i]+a[i])
        a[i] = 0
print(ans-sum(a))


Measured memory_bytes: 24048
enemmyCountN,killerTimeK = map(int,input().split())
enemyHp = list(map(int,input().split()))

enemyHp.sort()

resultEnemyCount = enemmyCountN - killerTimeK
countNormal = 0

if killerTimeK >= enemmyCountN:
    print(0)

else:
    for i in range(resultEnemyCount):
        countNormal += enemyHp[i]
    print(countNormal)

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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


void Main()
{
    int n,x;cin>>n>>x;
    
    int result = 1;
    int now=0;
    REP(i, n){
        int l;cin >> l;
        now += l;
        if(now <= x){
            result++;
        }
    }
    cout<<result << endl;

    
    

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m, a, b;
int ans[1 << 17];

vi solve(int n, int x) {
    vi v1, v2;
    int f = -1;
    REP(i, 1 << n) {
        int y = i ^ (i >> 1);
        if (f != -1 && i % 2 == 1) f = !f;
        if (x == y) {
            f = 1;
        }
        (f != 1 ? v1 : v2).push_back(y);
    }
    RREP(i, v2.size()) v1.push_back(v2[i]);
    return v1;
}


int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n >> a >> b){
        if (__builtin_popcount(a ^ b) % 2 == 0) {
            puts("NO");
        } else {
            puts("YES");
            int j = -1, k = (1 << n);
            int p = -1;
            REP(i, 1 << n) {
                int y = i ^ (i >> 1) ^ a;
                if (y == b) {
                    j = i;
                    p = 0;
                }
                if (p == -1) {
                    ans[i] = y;
                } else {
                    if (p & 2) ans[j ++] = y;
                    else ans[-- k] = y;
                    p ++;
                }
            };
            REP(i, 1 << n) printf("%d ", ans[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n = getInt();
  int k = getInt();

  while(k --> 0){
    int x = getInt() - 1;
    int y = getInt() - 1;
    
    x = min(x, n - x - 1);
    y = min(y, n - y - 1);

    print(1 + (min(x, y) % 3));
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  vector<ll> B(n); rep(i, n) cin >> B[i];
  ll sumA = accumulate(all(A), 0LL);
  ll sumB = accumulate(all(B), 0LL);
  ll m = sumB-sumA;
  ll two=0, one=0;
  rep(i, n) {
    if(A[i] > B[i]) {
      one += A[i]-B[i];
    } else if(A[i] < B[i]) {
      two += (B[i]-A[i]+1)/2;
    }
  }
  cout << (two<=m ? "Yes" : "No") << "\n";
  return 0;
}


Measured memory_bytes: 3764
#!/usr/bin/env python3
import sys
import math

def check1(k):
    return math.floor(k*0.08) == math.floor(k*0.1)

def check2(k, A , B):
    return math.floor(k*0.08) == A and math.floor(k*0.1) == B

def solve(A: int, B: int):
    k1 = A / .08
    k2 = B / .1

    min_k = math.floor(min(k1 - k1*0.08, k2 - k2 * 0.1))
    max_k = math.floor(max(k1 + k1*0.08, k2 + k2 * 0.1))

    # min_k = math.floor(min(k1 - k1*0.08, k2 - k2 * 0.1))
    # max_k = math.floor(max(k1 + k1*0.08, k2 + k2 * 0.1))

    ans = -1
    for k in range(min_k, max_k+1):
        c1 = check1(k)
        c2 = check2(k, A, B)
        if c2:
            ans = k
            break

    print(ans)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
private val scanner = java.util.Scanner(System.`in`)

private fun readInts(n: Int) = Array(n) { scanner.nextInt() }
private fun readLongs(n: Int) = Array(n) { scanner.nextLong() }
private fun readLineInts() = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()
private fun readLineLongs() = readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

fun main(args: Array<String>) {
    val (N, K) = readLineInts()
    val h = Array(N) { readLine()!!.toInt() }

    val sorted = h.sorted()
    var min = Int.MAX_VALUE
    for (n in 0 .. N - K) {
        val diff = sorted[n + (K - 1)] - sorted[n]
        if (diff < min) min = diff
    }

    println(min)
}

Measured memory_bytes: 42428
import sys

# from itertools import chain, accumulate

n, m, *abcdef = map(int, sys.stdin.buffer.read().split())

ver_lines = []
hor_lines = []
x_list = set()
y_list = set()
n3 = n * 3
for a, b, c in zip(abcdef[0:n3:3], abcdef[1:n3:3], abcdef[2:n3:3]):
    y_list.add(a)
    y_list.add(b)
    x_list.add(c)
    ver_lines.append((a, b, c))

for d, e, f in zip(abcdef[n3 + 0::3], abcdef[n3 + 1::3], abcdef[n3 + 2::3]):
    y_list.add(d)
    x_list.add(e)
    x_list.add(f)
    hor_lines.append((d, e, f))
x_list.add(0)
y_list.add(0)

x_list = sorted(x_list)
y_list = sorted(y_list)
x_dict = {x: i for i, x in enumerate(x_list, start=1)}
y_dict = {y: i for i, y in enumerate(y_list, start=1)}
row_real = len(x_list)
col_real = len(y_list)
row = row_real + 2
col = col_real + 2

banned_up = [0] * (row * col)
banned_down = [0] * (row * col)
banned_left = [0] * (row * col)
banned_right = [0] * (row * col)
for a, b, c in ver_lines:
    if a > b:
        a, b = b, a
    ai = y_dict[a] * row
    bi = y_dict[b] * row
    j = x_dict[c]
    banned_left[ai + j] += 1
    banned_left[bi + j] -= 1
    banned_right[ai + j - 1] += 1
    banned_right[bi + j - 1] -= 1
for d, e, f in hor_lines:
    if e > f:
        e, f = f, e
    ri = y_dict[d] * row
    ej = x_dict[e]
    fj = x_dict[f]
    banned_up[ri + ej] += 1
    banned_up[ri + fj] -= 1
    banned_down[ri - row + ej] += 1
    banned_down[ri - row + fj] -= 1

for i in range(1, col):
    ri0 = row * (i - 1)
    ri1 = row * i
    for j in range(1, row):
        banned_up[ri1 + j] += banned_up[ri1 + j - 1]
        banned_down[ri1 + j] += banned_down[ri1 + j - 1]
        banned_left[ri1 + j] += banned_left[ri0 + j]
        banned_right[ri1 + j] += banned_right[ri0 + j]

# banned_up = list(chain.from_iterable(map(accumulate, banned_up_ij)))
# banned_down = list(chain.from_iterable(map(accumulate, banned_down_ij)))
# banned_left = list(chain.from_iterable(zip(*map(accumulate, banned_left_ij))))
# banned_right = list(chain.from_iterable(zip(*map(accumulate, banned_right_ij))))

# for i in range(col):
#     print(walls[i * row:(i + 1) * row])

s = row * y_dict[0] + x_dict[0]
enable = [-1] * row + ([-1] + [0] * (row - 2) + [-1]) * (col - 2) + [-1] * row

# for i in range(col):
#     print(enable[i * row:(i + 1) * row])

q = [s]
moves = [(-row, banned_up), (-1, banned_left), (1, banned_right), (row, banned_down)]
while q:
    c = q.pop()
    if enable[c] == 1:
        continue
    elif enable[c] == -1:
        print('INF')
        exit()
    enable[c] = 1
    for dc, banned in moves:
        if banned[c]:
            continue
        nc = c + dc
        if enable[nc] == 1:
            continue
        q.append(nc)
# for i in range(col):
#     print(enable[i * row:(i + 1) * row])


ans = 0
for i in range(col):
    ri = i * row
    for j in range(row):
        if enable[ri + j] != 1:
            continue
        t = y_list[i - 1]
        b = y_list[i]
        l = x_list[j - 1]
        r = x_list[j]
        ans += (b - t) * (r - l)
print(ans)


Measured memory_bytes: 915508
#include<stdio.h>
int main(void)
{
  int white,black,square;
  char str[16];
  
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d",&square);
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d",&white);
  
  black = square * square - white;
  
  printf("%d",black);
  return 0;
}

Measured memory_bytes: 128
// -*- compile-command: "g++ -g -Wno-return-type -Wall -Wextra -DLOCAL -std=c++11 -D_GLIBCXX_DEBUG e.cpp -oe && ./e " -*-
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define int LL
#define vc vector
#define pb push_back
#define pr pair
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define f(i,n) for(int i=0;i<(n);i++)
#define fr(i,n) for(int i=(n);i--;)
#define fv(i,v) f(i,sz(v))

int n,m;

struct Linfun{
	int a,b;
	Linfun(int a,int b):a(a),b(b){}
	int eval(int x){ return a*x+b; }
	void operator+=(Linfun r){
		a+=r.a;
		b+=r.b;
	}
	void operator-=(Linfun r){
		a-=r.a;
		b-=r.b;
	}
};

struct Event{
	int i,x;
	Event(int i,int x):i(i),x(x){}
	bool operator<(Event r)const{
		return x<r.x;
	}
};

struct Step{
	int i;
	int a,b;
	int dist;
	Step(){}
	Step(int i,int a,int b):i(i),a(a),b(b){
		dist = a<=b?b-a:m-a+b;
	}
	bool operator<(Step r)const{
		return b<r.b;
	}
	vc<Event> getEvents(){
		vc<Event> r;
		if(1+b-dist>=0) r.pb(Event(i,1+b-dist));
		r.pb(Event(i,b+1));
		r.pb(Event(i,max(b,m-dist+b)+1));
		return r;
	}
	Linfun cost(int x){
		//int odist = x<=b?1+b-x:1+m-x+b;
		// odist <= dist:
		// (x<=b?1+b-x:1+m-x+b)<=dist
		// (x<=b && 1+b-x <= dist || x>b && 1+m-x+b<=dist
		// 1+b-dist <= x && x<=b || max(1+b,1+m-dist+b) <= x
		// r = 1+b-dist <= x && x<b+1 ? 1+b-x : max(b,m-dist+b)+1 <= x ? 1+m-x+b : dist
		//return min(dist,odist);
		return 1+b-dist <= x && x<b+1 ? Linfun(-1,1+b) : max(b,m-dist+b)+1 <= x ? Linfun(-1,1+m+b) : Linfun(0,dist);
	}
};

main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>m;
	vc<int> a(n);
	f(i,n) cin>>a[i],a[i]--;
	vc<Step> steps(n-1);
	f(i,n-1) steps[i]=Step(i,a[i],a[i+1]);
	vc<Event> events;
	f(i,n-1) for(auto e:steps[i].getEvents()) events.pb(e);
	sort(all(events));
	auto lf=Linfun(0,0);
	f(i,n-1) lf+=steps[i].cost(0);
	int j=0;
	while(events[j].x==0) j++;
	int best=2e18;
	f(x,m){
		for(;j<sz(events)&&events[j].x==x;j++){
			int i=events[j].i;
			lf-=steps[i].cost(x-1);
			lf+=steps[i].cost(x);
		}
		int cand=lf.eval(x);
		if(cand<best) best=cand;
	}
	cout<<best<<'\n';
}


// cost(a,b) = min(dist(a,b),1+dist(x,b))
// dist(a,b) = a < b ? b-a : a+m-b;



Measured memory_bytes: 9840
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
int h,w;
char c[51][51];
map<char,int> m;
int lmin[7],lmax[7],umin[7],umax[7];

bool rect(int index){
  for(int y=umin[index];y<=umax[index];y++){
    for(int x=lmin[index];x<=lmax[index];x++){
      if(m[c[y][x]]!=index&&c[y][x]!='?')
	return false;
    }
  }
  return true;
}
void replaceToAny(int index){
  for(int y=umin[index];y<=umax[index];y++){
    for(int x=lmin[index];x<=lmax[index];x++){
      c[y][x]='?';
    }
  }
}
void solve(){
  m.clear();
  REP(i,7){
    lmin[i]=umin[i]=999;
    lmax[i]=umax[i]=0;
  }
  cin>>h>>w;
  REP(y,h){
    REP(x,w){
      cin>>c[y][x];
      if(c[y][x]=='.')continue;
      if(m.find(c[y][x])==m.end()){
	int sz=m.size();
	m[c[y][x]]=sz;
      }
      lmin[m[c[y][x]]]=min(lmin[m[c[y][x]]],x);
      lmax[m[c[y][x]]]=max(lmax[m[c[y][x]]],x);
      umin[m[c[y][x]]]=min(umin[m[c[y][x]]],y);
      umax[m[c[y][x]]]=max(umax[m[c[y][x]]],y);
      //      cout<<lmin[0]<<" "<<lmax[0]<<" "<<umin[0]<<" "<<umax[0];
    }
  }
  while(m.size()>0){
    for(auto i=m.begin();i!=m.end();i++){
      if(rect((*i).second)){
	replaceToAny((*i).second);
	m.erase(i);
	goto NEXT;
      }
    }
    cout<<"SUSPICIOUS"<<endl;
    return;
  NEXT:;
  }
  cout<<"SAFE"<<endl;
}
int main(){ _;
  int n;cin>>n;
  REP(i,n){
    solve();
  }
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int main(){
  string S, T;
  int ans = 0;
  cin >> S >> T;
  rep(i, 3){
    if (S[i] == T[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3568
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

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

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ld a, b, x; cin >> a >> b >> x;
  ld half = a * a * b / 2;
  ld ans;

  if (x < half) ans = atan(a * b * b / (2 * x));
  else ans = atan((2 * b - 2 * x / (a * a)) / a);

  outl(ans / M_PI * 180);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
  
        System.out.println(Math.max(Math.max(A+B,A-B),A*B));
    }
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

struct UF
{
	vector<int> par; // 親
	vector<int> sz; // 数
	// 初期化
	UF(int n):par(n),sz(n) {
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;
		}
	}
	// 木の根を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		par[x] = y;
		sz[y] += sz[x];
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int n){return sz[find(n)];}
};

vector<pair<ll,pair<ll,ll>>> v;
vector<pair<ll,ll>> h;
ll n,m;

int main(){
	while(cin >> n >> m,n|m){
		//初期化
		h.clear();
		v.clear();
		
		//入力
		REP(i,n){
			ll tmp;cin >> tmp;
			h.PB(MP(tmp,i));
		}
		REP(i,m){
			ll a,b,c;cin >> a >> b >> c;
			a--;b--;
			v.PB(MP(c,MP(a,b)));
		}
		sort(ALL(h));
		sort(ALL(v));
		
		//沈む順番を入れておく。
		vector<int> jun(n);
		REP(i,n)jun[h[i].SE] = i;

		//そもそも連結であるかどうかを見る
		UF seica(n);
		REP(i,m){
			int A = v[i].SE.FI;
			int B = v[i].SE.SE;
			if(!seica.same(A,B)){
				seica.unite(A,B);
			}
		}
		
		
		if(seica.size(0) != n){
			//連結でなかったら
			cout << 0 << endl;
		}
		else{
			//連結だったら
			vector<bool> sink(n);
			
			//順々に沈ませていってから、残った中で連結になるかどうかを見る。
			int cou = 0;
			while(1){
				int tmp = cou;
				while(cou < n-1 && h[cou].FI == h[cou+1].FI){
					cou++;
				}
				if(cou == n-1){
					cou = tmp - 1;
					break;
				}
				
				UF uf(n);
				REP(i,m){
					int A = v[i].SE.FI;
					int B = v[i].SE.SE;
					if(jun[A] > cou && jun[B] > cou && !uf.same(A,B)){
						uf.unite(A,B);
					}
				}
				int ma = 0;
				REP(i,n)ma = max(ma,uf.size(i));
				if(ma != n - cou -1){
					cou = tmp - 1;
					break;
				}
				cou++;
			}
			
			//逆に順々に復活させて、くっつけていく。
			ll ans = 0;
			UF uf(n);
			while(1){
				REP(i,m){
					int A = v[i].SE.FI;
					int B = v[i].SE.SE;
					if(jun[A] > cou && jun[B] > cou && !uf.same(A,B)){
						uf.unite(A,B);
						ans += v[i].FI;
					}
				}
				if(cou < 0)break;
				while(cou > 0 && h[cou].FI == h[cou-1].FI)cou--;
				cou--;
			}
			
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return 
#define en           "\n" 
#define endl         "\n" 

#define all(c)       c.begin(),c.end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2) 

#define fo(i,a,b)     for(int i = (int)(a); i <= (int)(b); i++)
#define rf(i,a,b)    for(int i = (int)(a); i >= (int)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
// template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
// template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***



long double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816;
void solve()
{
    long double  x;
    cin>>x;
    cout<<(2*pi*x)<<endl;
    
}


void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio;
cout<<setprecision(26)<<fixed;
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    cout<<"\n";
    return 0;
}

Measured memory_bytes: 3812
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int n = sc.nextInt();
		long min = Long.MAX_VALUE;
		for (int i = 1; i <= n; i++) {
		    if (b % i != 0) {
		        continue;
		    }
		    long x = b / i;
		    long y = a / x;
		    if (y > n || y == 0) {
		        min = Math.min(min, Math.abs(n * x - a));
		    } else {
		        min = Math.min(min, Math.abs(y * x - a));
		    }
		    if (y + 1 > n) {
		        min = Math.min(min, Math.abs(n * x - a));
		    } else {
		        min = Math.min(min, Math.abs((y + 1) * x - a));
		    }
		    if (y - 1 == 0 || y - 1 > n) {
		        min = Math.min(min, Math.abs(n * x - a));
		    } else {
		        min = Math.min(min, Math.abs((y - 1) * x - a));
		    }
		}
		System.out.println(min);
	}
}



Measured memory_bytes: 26376
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 105
using namespace std;
typedef unsigned long long ll;
int n,m;
int a[200005];
//ll c[maxn][maxn];
int myabs(int now)
{
	return now>0 ? now : -now;
}
int main()
{
//	freopen("a.txt","r",stdin);
//	c[0][0]=1;
//	for(int i=1;i<=30;i++)
//	{
//		c[i][0]=c[i][i]=1;
//		for(int j=1;j<=i-1;j++)
//		{
//			c[i][j]=c[i-1][j-1]+c[i-1][j];
//		}
//	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);

//	ll ans1=0;
//	int pos1,pos2;
//	for(int i=1;i<=n;i++)
//		for(int j=1;j<=n;j++)
//		{
//			if(c[a[i]][a[j]]>ans1)
//			{
//				pos1=a[i];
//				pos2=a[j];
//				ans1=c[a[i]][a[j]];
//			}
//		}

//	printf("guess 1\n");
//	printf("%d %d\n",pos1,pos2);

//	ll ans2=0;
	sort(a+1,a+1+n);
	int dis=a[n]+1,pos=1;
	for(int i=1;i<=n;i++)
	{
		if(myabs(a[n]-2*a[i])<dis)
		{
			pos=a[i];
			dis=myabs(a[n]-2*a[i]);
		}
	}

//	printf("guess 2\n");
	printf("%d %d\n",a[n],pos);
}


Measured memory_bytes: 640
n = int(input())
k = str(input())

k += '.'*n

R = [0] * (n*3)
G = [0] * (n*3)
B = [0] * (n*3)

dic = { 'R' : 0, 'G' : 0, 'B' : 0 };
for i in range(n-1, -1, -1):
    dic[k[i]] += 1
    R[i] = dic['R']
    G[i] = dic['G']
    B[i] = dic['B']

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if k[i] != k[j]:
            charset = ['R', 'G', 'B'];
            charset.remove(k[i]);
            charset.remove(k[j]);
            ##
            if charset[0] == 'R':
                ans += R[j + 1]
                ans -= (1 if k[j + (j - i)] == 'R' else 0)
            if charset[0] == 'G':
                ans += G[j + 1]
                ans -= (1 if k[j + (j - i)] == 'G' else 0)
            if charset[0] == 'B':
                ans += B[j + 1]
                ans -= (1 if k[j + (j - i)] == 'B' else 0)

print(ans)


Measured memory_bytes: 79980
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf ("%d %d", &a , &b);
    if (a > b)
    {
        printf("a > b\n", a, b);
    }
    else if (a < b)
    {
        printf("a < b\n", a, b);
    }
    else if (a == b)
    {
        printf("a == b\n", a, b);
    }
    return 0;
}



Measured memory_bytes: 2104
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	int a=0,b=0;
	cin>>n>>m;
	vi w(n);
	rep(i,m){
		int c;string s;cin>>c>>s;
		if(s=="AC"){
			if(w[c-1]>=0)b+=w[c-1],a++;
			w[c-1]=-inf;
		}else w[c-1]++;
	}
	cout<<a<<" "<<b<<endl;
}









Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

string s;
int n, k;
int dp[334][334][334];

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

    cin >> s >> k;
    n = s.size();
    rep(l, n) dp[l][l][0] = 1;
    FOR(bit, 1, n + 1) rep(l, n - bit + 1) {
        int r = l + bit - 1;
        rep(i, k + 1) {
            if(s[l] == s[r]) dp[l][r][i] = dp[l + 1][r - 1][i] + 2;
            if(i) chmax(dp[l][r][i], dp[l + 1][r - 1][i - 1] + 2);
            chmax(dp[l][r][i], dp[l + 1][r][i]);
            chmax(dp[l][r][i], dp[l][r - 1][i]);
            chmin<int>(dp[l][r][i], bit);
        }
    }
    cout << dp[0][n - 1][k] << endl;

    return 0;
}

Measured memory_bytes: 131200
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int a,b,x,y;

string s;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> a >> b >> s; x=1;
    for(int i=0;i<s.lg;i++){
        if(s[i]=='-' && i!=a) x=0;
        if(s[i]!='-' && i==a) x=0;
    }
    if(x) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		long K = long.Parse(str[1]);
		long[]A = new long[N];
		long sum = 0;
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str2[i]);
			sum += A[i];
		}
		var list = enum_div(sum);
		list.Sort((x,y)=>y.CompareTo(x));
		for(var j=0;j<list.Count;j++){
			long L = list[j];
			long k1 = 0;
			long k2 = 0;
			var lista = new List<long[]>();
			for(var k=0;k<N;k++){
				lista.Add(new long[2]{A[k]%L,(L-A[k]%L)%L});
			}
			lista.Sort((x,y)=>(Math.Min(x[0],x[1])).CompareTo(Math.Min(y[0],y[1])));
			for(var k=0;k<N;k++){
				if(lista[k][0]<lista[k][1]){
					if(k1+lista[k][0]>K){
						k2 += lista[k][1];
					} else {
						k1 += lista[k][0];
					}
				} else {
					if(k2+lista[k][1]>K){
						k1 += lista[k][0];
					} else {
						k2 += lista[k][1];
					}
				}
			}
			if(k1<=K && k2<=K){
				Console.WriteLine(L);
				break;
			}
		}
	}
	
	public static List<long> enum_div(long n){
		long tmp = n;
		var list = new List<long>();
		for(var i=1;i*i<=n;i++){
			if(n%i==0){
				list.Add(i);
				if(i*i!=n){
					list.Add(n/i);
				}
			}
		}
		return list;
	}
}

Measured memory_bytes: 18040
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007LL;
const double INF=1000000000;
const int MAX=100001;
int h,w;
char c[60][60];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
bool visited[2][60][60];
bool field(int x,int y,int f){
    if(x>=0&&x<w&&y>=0&&y<h&&(!visited[f][y][x])&&(c[y][x]=='.')){
        return true;
    }
    return false;
}
void dfs(int x,int y,char s){
    if(s=='W'){
        if(!field(x,y,0)) return;
        visited[0][y][x]=true;
    }
    else{
        if(!field(x,y,1)) return;
        visited[1][y][x]=true;
    }

    for(int i=0;i<4;i++){
        dfs(x+dx[i],y+dy[i],s);
    }
}
int main(){
    while(cin>>w>>h,w+h){
        for(int i=0;i<h;i++){
            cin>>c[i];
            for(int j=0;j<w;j++){
                visited[0][i][j]=false;visited[1][i][j]=false;
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                
                if(c[i][j]=='B'||c[i][j]=='W'){
                    for(int k=0;k<4;k++){
                        dfs(j+dx[k],i+dy[k],c[i][j]);
                    }
                }
            }
        }
        int br=0;int wh=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(visited[0][i][j]&&(!visited[1][i][j])){
                    wh++;
                }else if(visited[1][i][j]&&(!visited[0][i][j])){
                    br++;
                }
            }
        }
        cout<<br<<" "<<wh<<endl;
    }
    return 0;
}

                           



Measured memory_bytes: 3132
#include<stdio.h>

int main(void) {
  long int n, a[10000], i, min = 0, max = 0, sum;
  
  scanf("%ld", &n);
  for (i = 0; i < n; i++)
  {
    scanf("%ld", &a[i]);
  }
  
  sum = a[0];
  
  for (i = 1; i < n; i++)
  {
    if (a[min] > a[i])
    {
      min = i;
    }
    if (a[max] < a[i])
    {
      max = i;
    }
    sum = sum + a[i];
  }
  printf("%ld %ld %ld\n", a[min], a[max], sum);
  
  return 0;
}

Measured memory_bytes: 2784
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 3000

using namespace std;

string v;
int d[maxn+5][maxn+5];///d[i][j]=nr de permutari de lg i care se termina in j
int s[maxn+5][maxn+5];///s[i][j]=s[i][1]+s[i][2]+..+s[i][j]
const int mod = 1000000007;

int main () {
  int n; cin >> n >> v; v = " " + v;
  int i, j, z;
  d[1][1] = 1;
  for (j = 1; j <= n; j++) s[1][j] = (s[1][j-1] + d[1][j]) % mod;
  for (i = 2; i <= n; i++) {
    for (j = 1; j <= i; j++) {
      if (v[i-1] == '>') d[i][j] = (s[i-1][i-1] - s[i-1][j-1] + mod) % mod;
      else d[i][j] = s[i-1][j-1];
    }
    for (j = 1; j <= n; j++) s[i][j] = (s[i][j-1] + d[i][j]) % mod;
  }
  cout << s[n][n];
  return 0;
}


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

const int mn=15005,Log=14;
int n,k,m,tmp_k;
int c[mn],p[mn],vis[mn];
long long ans=-2e18,sum[mn];
vector<int> a;

void dfs(int x)
{
    if(vis[x]) return ;
    vis[x]=1;
    a.push_back(x);
    dfs(p[x]);
}

int main()
{
    scanf("%d%d",&n,&k);
    tmp_k=k;
    for(int i=1;i<=n;++i) scanf("%d",p+i);
    for(int i=1;i<=n;++i) scanf("%d",c+i);
    int f=0;
    for(int i=1;i<=n;++i) if(c[i]>0) f=1;
    if(!f) {
        for(int i=1;i<=n;++i) ans=max(ans,1ll*c[i]);
        cout<<ans;
        return 0;
    }
    for(int _i=1;_i<=n;++_i) {
        if(!vis[_i]) {
            k=tmp_k;
            a.clear();
            memset(sum,0,sizeof sum);
            a.push_back(0);
            dfs(_i);
            m=a.size()-1;
            for(int i=1;i<=m;++i) a.push_back(a[i]);
            for(int i=1;i<=m;++i) a.push_back(a[i]);
            m*=3;
            for(int i=1;i<=m;++i) sum[i]=sum[i-1]+1ll*c[a[i]];
            m/=3;
            long long tmp_ans=0,tmp=-2e18;
            if(sum[m]>0) {
                int b=max(k/m-1,0);
                tmp_ans+=sum[m]*b,k-=m*b;
            }
            else if(k>=2*m) k=2*m;
            for(int i=1;i<=m;++i) {
                long long t=sum[i-1];
                for(int j=1;j<=k;++j) {
                    t=max(t,sum[i+j-1]);
                }
                tmp=max(tmp,t-sum[i-1]);
            }
            tmp_ans+=tmp;
            ans=max(ans,tmp_ans);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <queue>
using namespace std;
long long int ans[3000] = {}; 
long long int P; 
long long int Pow(long long int a, long long int n, long long int m) {
	long long int powa[65];
  	powa[0] = a; 
  	for(int j = 0; j < 64; ++j){
     		powa[j+1] = (powa[j] * powa[j]) % m; 
  	}
	long long int c = n; 
  	long long int Q = 1; int k = 0; 
	while(c > 0){
  		if(c & 1) Q = (Q * powa[k]) % m; 
		c = c >> 1; k++; 
	}
	return Q;
}
long long int Inv(long long int a, long long int m) {
	return Pow(a, m-2, m); 
}
void add(long long int D){
    if(D == 0LL){
        ans[0] += P - 1; ans[0] %= P; 
        ans[P-1] ++; ans[P-1] %= P; 
	}
	else{
    	long long int tmp[3000] = {}; 
	    tmp[P-1] = 1; 
	    long long int I = Inv(D, P); 
    	for(int i = P-2; i > 0; i--){
	    	tmp[i] =  D * tmp[i+1] % P; 
	    }
	    for(int i = 0; i < P; i++){
		    ans[i] += tmp[i]; ans[i] %= P; 
	    }
	}
}
int main(){
	cin >> P; 
	for(int i = 0; i < P; i++){
		long long int a; cin >> a; 
		if(a == 1) add(i); 
	}
	for(int i = 0; i < P; i++){
		if(ans[i] == 0) cout << 0 << " "; 
		else cout << P - ans[i] << " "; 
	}
	cout << endl; 
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

al = "abcdefghijklmnopqrstuvwxyz"

def solve(N: int):
    i = 1
    n = ""
    while(N>0):
        m = N % 26 -1
        n = al[m] + n
        N = N // 26 - (m==-1)*1

    print(n)

    

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9036
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, m;
    cin >> n >> m;
    vvint d(m, vint(m));
    vvint c(n, vint(n));
    rep(i, m) rep(j, m) cin >> d[i][j];
    rep(i, n) rep(j, n) cin >> c[i][j];

    map<int, int> c1;
    map<int, int> c2;
    map<int, int> c3;

    rep(i, n) rep(j, n) {
        int id = (i+j+2)%3;
        if (id == 0) c1[c[i][j]-1]++;
        if (id == 1) c2[c[i][j]-1]++;
        if (id == 2) c3[c[i][j]-1]++;
    }

    int ans = INF;
    rep(i, m) {
        rep(j, m) {
            if (i == j) continue;
            rep(k, m) {
                if (i == k || j == k) continue;
                int tmp = 0;
                for (auto x : c1) tmp += d[x.fi][i] * x.se;
                for (auto x : c2) tmp += d[x.fi][j] * x.se;
                for (auto x : c3) tmp += d[x.fi][k] * x.se;
                ans = min(ans, tmp);
            }
        }
    }

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

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-8

int main() {
    int n, m; cin >> n >> m;
    vector<int> e[n];
    vector<double> d(n, 0), p(n, 0);
    for (int i = 0; i < m; i++) {
        int s, t; cin >> s >> t;
        e[s-1].emplace_back(t-1);
    }
    for (int i = n-1; i >= 0; i--) {
        if (e[i].size() == 0) continue;
        double x = 1.0 / e[i].size();
        for (auto &to: e[i]) {
            d[i] += (d[to] + 1) * x;
        }
    }
    p[0] = 1;
    for (int i = 0; i < n; i++) {
        if (e[i].size() == 0) continue;
        double x = 1.0 / e[i].size();
        for (auto &to: e[i]) {
            p[to] += p[i] * x;
        }
    }
    double ans = d[0];
    for (int i = 0; i < n; i++) {
        for (auto &j: e[i]) {
            // {i, j}
            double ij = 1.0 / e[i].size();
            double diff = -(1 + d[j]) * ij;
            if (e[i].size() > 1) {
                double ik = 1.0 / (e[i].size() - 1) - ij;
                for (auto &k: e[i]) {
                    if (j == k) continue;
                    diff += (1 + d[k]) * ik;
                }
                if (ans+diff > eps) ans = min(ans, d[0]+diff*p[i]);
            }    
        }
    }
    printf("%.12f\n", ans);
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

const ll NUM = 1000000007;
int main() {
    ll n, k; cin >> n>> k;
    vector<int> Q;
    ll count = 0;
    int a; cin >> a;
    Q.push_back(a);
    rep(i,n-1){
        int num; cin >> num;
        auto Iter = lower_bound(ALL(Q),num+1);
        int bigger = Iter-Q.begin();
        count += Q.size() - bigger;
        Q.insert(Q.begin()+bigger,num);
    }

    ll count2 = 0;
    rep(i,n){
        auto Iter2 = upper_bound(ALL(Q),Q[i]);
        count2 += Q.end()-Iter2;
    }
    ll ans = 0;
    for(ll i = 1; i < k; i++){
        ans += (count2*i)%NUM;
    }
    cout << (ans+count*k)%NUM << endl;
    


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	long n, num;
  long max, min;
	long sum=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> num;
		sum += num;
		if(i==0){max = num;min = num;}
		else if(max < num) max = num;
		else if(min > num) min = num;
	}
	cout << min << " " << max << " " << sum << endl;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll mod = 1000000007;
 
int main() {
    int n;
    cin >> n;
    vector<ll>a(n);
    vector<bool>b(n, true);
    rep(i, 0, n)cin >> a[i];
    sort(a.begin(),a.end(),greater<ll>());
    vector<ll>l;
    rep(i, 1, n){
        if(a[i] == a[i-1] && b[i] && b[i-1]){
            b[i] = false;
            b[i-1] = false;
            l.push_back(a[i]);
            if(l.size()==2){
                cout << l[0] * l[1] << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 1024
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long

#define INF 999999999

using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
// input
int n,z,w;
int a[2000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> z >>w;
    REP(i,n) cin >> a[i];

    if (n == 1) cout << abs(a[0]-w) << "\n";
    else cout << max(abs(a[n-2]-a[n-1]),abs(a[n-1]-w)) << "\n";
    
}

Measured memory_bytes: 256