akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int const mxn = 1e3+10;
int const mod = 1e9+7;
int dp[mxn][mxn],mark[mxn][mxn];
string l[mxn];
int n,m;
long long ans = 0;
int memo (int i, int j){

	if (mark[i][j]){
	//	cout<<"("<<i+1<<","<<j+1<<") = "<<dp[i][j]<<endl;
		return dp[i][j];
	}
	if (l[i][j]=='#'){
	//	cout<<"("<<i+1<<","<<j+1<<") = "<<"#"<<endl;
		return 0;
	}
	if (i >=n or j>=m ){
	//	cout<<"("<<i+1<<","<<j+1<<") = "<<"failed"<<endl;
		return 0;
	}
	mark[i][j]=1;
	if (i==n-1 and j ==m-1){
	//	cout<<"("<<i+1<<","<<j+1<<") = "<<1<<endl;
		return 1;
	}
	dp[i][j] = (memo(i+1,j)%mod  + memo(i,j+1)%mod)%mod;
//	cout<<"("<<i+1<<","<<j+1<<") = "<<dp[i][j]<<endl;
	return dp[i][j];
}

int main(){
	cin>>n>>m;
	dp[n-1][m-1]=1;
	for (int i = 0;i<n;i++)
		cin>>l[i];
	ans = memo(0,0);
	cout<<ans;
}

Measured memory_bytes: 9344
n = readline.chomp.to_i
n.times do |i|
  (xa, ya, ra, xb, yb, rb) = readline.chomp.split(' ').map(&:to_f)
  l = Math.sqrt((xb - xa) ** 2 + (yb - ya) ** 2)
  r = ra + rb
  if r < l
    p 0
  elsif (ra - rb).abs <= l and l <= ra + rb
    p 1
  else
    if ra > rb
      p 2
    else
      p -2
    end
  end
end

Measured memory_bytes: 8648
def area_cal(input_fig):
    stack = []
    # area = [[面積計算が始まった位置, 面積],・・・]
    area = []
    total = 0
    for i in range(len(input_fig)):
        fig = input_fig[i]
        if fig == "\\":
            stack.append(i)
        elif fig == "/" and stack:
            j = stack.pop()
            width = i - j
            total += width
            while area and area[-1][0] > j:
                width += area[-1][1]
                area.pop()
            area.append([i,width])
    return area, total
            
input_fig = input()
area, total = area_cal(input_fig)
print(total)
if area:
    print(len(area),*list(zip(*area))[1])
else:
    print(0)


Measured memory_bytes: 6444
n, k = map(int,input().split())

l = [list(map(int,input().split())) for i in range(k*2)]

a = [[] for i in range(n)]

for i in range(0,k*2,2):
    n = l[i]
    for j in l[i+1]:
        a[j-1].append(i+1)


cnt = 0

for i in a:
    if len(i) == 0:
        cnt += 1

print(cnt)

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

#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int c[26];

int32_t main()
{
    IOS;
    string s;
    cin>>s;
    FOR(i,0,s.size()) c[(int)s[i] - 'a']++;
    FOR(i,0,26)
    {
        if(c[i]&1)
        {
        	cout<<"No\n";
        	return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

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

int main(){
  int n,may = 0;cin >> n;
  int x[n],y[n],h[n];rep(i,n)cin >> x[i] >> y[i] >> h[i];
  for(int i=0;i<n;++i){
    for(int cx=0;cx<=100;++cx){
      for(int cy=0;cy<=100;++cy){
        int H = max(h[i] + abs(x[i] - cx) + abs(y[i] - cy),0);
 		for(int t=0;t<n;++t){
		  if(h[t] == max(H - abs(x[t] - cx) - abs(y[t] - cy),0))may += 1;
        }
        if(may == n){
          cout << cx << " " << cy << " " << H << endl;
          return 0;
        }
        may = 0;
      }
    }
  }
  return 0;
}

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

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

    vector<int> count(9, 0);
    int a;
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        a /= 400;
        a = min(a, 8);
        count[a]++;
    }

    int minimum = 0;
    for (int i = 0; i < 8; i++)
    {
        if (count[i] > 0)
        {
            minimum++;
        }
    }

    int maximum = minimum + count.back();

    if (minimum == 0)
    {
        minimum = 1;
        maximum = count.back();
    }
    cout << minimum << " " << maximum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int n,i;
int max=1000;
int min=0;
scanf("%d",&n);
	int a[100];
for(i=1;i<=n;i=i+1){
	scanf("%d",&a[i]);
}
	for(i=n;i>=1;i--){
		printf("%d",a[i]);
		if(i!=1)printf(" ");
	}printf("\n");

	return 0;
}


Measured memory_bytes: 2104
//-----by LY02------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define M 1000000007
//------------------------------------------------

int b[4];
double dp[301][301][301];
//------------------------------------------------
int main() {
//------------------------------------------------
//	freopen("In.txt","r",stdin);
//	freopen("Out.txt","w",stdout);
//------------------------------------------------
	ios::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------

int n; cin>>n;
int a;
for(int i=0;i<n;i++)
{
	cin>>a;
	b[a]++;
}

for(int i=0;i<=n;i++)
	for(int j=0;j+i<=n;j++)
		for(int k=0;k+j+i<=n;k++)
		{
			if(!i&&!j&&!k) continue;
			double a1=0,a2=0,a3=0;
			if(k)
				a1=(double)k/n*dp[k-1][j][i];
			if(j)
				a2=(double)j/n*dp[k+1][j-1][i];
			if(i)
				a3=(double)i/n*dp[k][j+1][i-1];
			dp[k][j][i]=(double)n/(i+j+k)*(a1+a2+a3+1);
		}

cout<<fixed<<setprecision(10)<<dp[b[1]][b[2]][b[3]]<<endl;

//------------------------------------------------
	return 0;
}





//-----by LY02------------------------------------


Measured memory_bytes: 213248
// atcoder/abc134/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    cin >> a;

    map<int, int> m;
    for (int i = n; 1 <= i; --i) {
      int x = a[i-1];
      for (int j = i; j <= n; j += i) {
        x += m[j];
      }
      m[i] = x % 2;
    }

    vector<int> v;
    each (i, m) if (i.second) v.push_back(i.first);
    cout << v.size() << endl;
    each (i, v) cout << i << ' ';
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 11512
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[102][102];
string s;
int k;
int p[4]={1,9,81,729};
int cal(string s, int k) {
    //cout <<"s=" << s <<" k=" << k <<endl;
    if (s.size()<k)
        return 0;

    if (s.size()==0)
        return k==0;
    if (s[0]=='0')
        return cal(s.substr(1,s.size()-1),k);

    int ans = 0;
    string x(s.size()-1,'9');

    ans +=  cal(x,k);
    for (char c='1'; c<s[0];c++) {
        ans += dp[s.size()-1][k-1]*p[k-1];
    }
    ans += cal(s.substr(1,s.size()-1),k-1);
    return ans;
}
int main(){

    dp[0][0] = 1;
    for (int i=1;i<=101;i++){
        dp[i][i]=dp[i][0] = 1;
        for (int j=1;j<=3;j++)
            dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
        //for (int j=0;j<=3;j++)
        //    printf("%d ",dp[i][j]);
        //printf("\n");
    }

    while (cin>>s) {
        scanf("%d",&k);
        printf("%d\n",cal(s,k));
    }
    return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

vi x(50,0);

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

template <typename T>
inline std::string to_bin_str(T n, std::size_t digit_num) {
   std::string str;
   while (n > 0) {
       str.push_back('0' + (n & 1));
       n >>= 1;
   }
   str.resize(digit_num, '0');
   std::reverse(str.begin(), str.end());
   return str;
}

int main(){
  int n,tmp,ans=0;
  vi a,b;
  std::cin >> n;
  rep(i,n){
    std::cin >> tmp;
    if(tmp%10==0) a.pb(tmp);
    else b.pb(tmp);
  }
  if(b.size()==0){
    std::cout << 0 << std::endl;
    return 0;
  }
  sort(all(b));
  rep(i,a.size()){
    ans+=a[i];
  }rep(j,b.size()){
    ans+=b[j];
  }
  if(ans%10==0){
    std::cout << ans-b[0] << std::endl;
  }else{
    std::cout << ans << std::endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
void insert(vector<int>c,vector<int>&d){
	/*
	cout<<"insert debug\nc[i]\n";
	rep(i,c.size()) cout<<c[i]<<" ";
	cout<<endl;
	cout<<"d[i]\n";
	rep(i,d.size()) cout<<d[i]<<" ";
	cout<<endl;
*/
	rep(i,c.size()){
		int mid,ok=-1,ng=d.size();
		//cout<<"ok"<<ok<<"ng"<<ng<<endl;
		while(ng-ok>1){
			mid=(ok+ng)/2;
			//cout<<"mid"<<mid<<endl;
			if(d[mid]<c[i]) ok=mid;
			else ng=mid;
		}
		d.insert(d.begin()+ok+1,c[i]);
	}
	//rep(j,d.size())cout<<"#"<<d[j]<<endl;
}


int main(){
	int n,m;
	cin>>n>>m;
	vector<int>a(n),b(n);
	rep(i,n)cin>>a[i]>>b[i];
	vector<vector<int> >c(m+1);
	rep(i,n){
		if(a[i]<=m){
			c[a[i]].push_back(b[i]);
		}
	}
	/*
	rep(i,c.size()){
		rep(j,c[i].size()){
			cout<<c[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	/*
	rep(i,c.size()){
		sort(c[i].begin(),c[i].end());
	}
	*/
	vector<int>d;
	long long int sum=0;
	rep(i,m+1){
		insert(c[i],d);
		//rep(j,d.size())cout<<d[j]<<" ";
		//cout<<endl;
		if(d.size()>0){
			sum+=d[d.size()-1];
			d.pop_back();
		}
//		rep(j,d.size())cout<<d[j]<<" ";
//		cout<<endl;
	}
	cout<<sum<<endl;



	return 0;
}

Measured memory_bytes: 6400
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int> >in(n,vector<int>(m));
  rep(i,n)rep(j,m){
    char d;cin>>d;
    in[i][j]=d-'0';
  }
  loop(i,1,m)in[0][i]+=in[0][i-1];
  loop(i,1,n)rep(j,m){
    if(!j){
      in[i][j]+=in[i-1][j];
    }else{
      in[i][j]+=min(in[i][j-1],in[i-1][j]);
    }
  }
  cout<<in[n-1][m-1]<<endl;

  //rep(i,100000000)cout<<i<<" nibo"<<endl;
}

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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);


bool isPalindrome(string s) {
    int upper,lower,len;
    len=s.length();

    if(len==1) {
        return true;
    }

    if(len%2==0) {
        lower=(len/2)-1;
        upper=lower+1;
    }
    else {
        int mid=len/2;
        lower=mid-1;
        upper=mid+1;
    }

    while(s[lower]==s[upper]&&lower>0&&upper<len) {
        upper++;
        lower--;
    }

    if(upper==len-1&&lower==0&&(s[upper]==s[lower])) {
        return true;
    }
    else {
        //cout<<"this the the len: "<<len<<endl;
        //cout<<"this is upper "<<upper<<endl;
        //cout<<"this is lower "<<lower<<endl;

        return false;
    }

}
int main() {
    fast_io;

    string s;
    cin>>s;
    int len=s.length();

    int pt1=((len-1)/2);
    int pt2=((len+3)/2)-1;
   // cout<<"pt1: "<<pt1<<endl;
   // cout<<"pt2: "<<pt2<<endl;
    //cout<<s.substr(0,pt1)<<endl;
    //cout<<s.substr(pt2, len-pt2)<<endl;
    if(isPalindrome(s)&&isPalindrome(s.substr(0,pt1))&&isPalindrome(s.substr(pt2, len-pt2))) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }


}




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

int main(){
    int H, W, i, j;
    
    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3128
#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 Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n >> m;
	vll v(n),w(n),dp(m+1);
	rep(i,n) cin >> v[i] >> w[i];
	rep(i,m+1){
		rep(j,n){
			if(i<w[j]) continue;
			chmax(dp[i],dp[i-w[j]]+v[j]);
		}
	}
	cout << dp[m] << endl;
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    vector<int> a(n);rep(i,n)cin >> a[i];
    int i = 0;
    int ret = 0;
    auto f = [&](int x){
        //xkara
        //zouka
        int z = x;
        for(;z < n-1 && a[z] <= a[z+1];z++);
        int g = x;
        for(;g < n-1 && a[g] >= a[g+1];g++);
        return max(g,z)+1;

    };
    while(i < n){
        //trace(i);
        i = f(i);
        ret++;
    }
    cout << ret << endl;

    return 0;
}

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

int main() {
	const int SET = 3;
	const unsigned int hasABC = 0b0111;
	char str[32] = "";
	char check[4] = "abc";

	cin >> str;

	unsigned int findBit = 0x0000;
	for( int i = 0; i < SET; i++) {
		for(int j = 0; j < 3; j ++) {
			if(check[i] == str[j]) {
				unsigned int flg = 1 << i;
				findBit |= flg;
			}
		}
	}
	if(hasABC == findBit) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
package main
import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	rd := bufio.NewReader(os.Stdin)
	s, _ := rd.ReadString('\n')
	n := len(s)
	m := make(map[int]int)
	r := 0
	k := 1
	ans := 0
	for i := n-1; i >= 0; i-- {
		r += int(s[i] - '0') * k
		r %= 2019
		if m[r] > 0 {
			ans += m[r]
		}
		m[r]++
		k *= 10
		k %= 2019

	}
	fmt.Println(ans)
}

Measured memory_bytes: 2660
import copy


def resolve(L_input):
    L = copy.deepcopy(L_input)
    cnt = 0
    s = L[0]
    for i in range(1, len(L)):
        a = L[i]
        if s > 0 and s+a >= 0:
            L[i] = -s-1
            cnt += (s+a+1)
            s = -1
        elif s < 0 and s+a <= 0:
            L[i] = -s+1
            cnt += (-s-a+1)
            s = 1
        else:
            s += a

    return cnt


def solution(L):
    first_term = L[0]
    if first_term > 0:
        L_positive = L
        first_positibe_cnt = resolve(L_positive)
        # extract first_term+1 to first_term to be -1
        L_negative = [-1]+L[1:]
        first_negative_cnt = (first_term+1) + resolve(L_negative)
    elif first_term < 0:
        # add -first_term+1 to first_term to be 1
        L_positive = [1]+L[1:]
        first_positibe_cnt = (-first_term+1) + resolve(L_positive)
        L_negative = L
        first_negative_cnt = resolve(L_negative)
    else:
        # add 1 to first_term to be 1
        L_positive = [1]+L[1:]
        first_positibe_cnt = 1 + resolve(L_positive)
        # extract 1 to first_term to be -1
        L_negative = [-1]+L[1:]
        first_negative_cnt = 1 + resolve(L_negative)

    # print("first_positive, cnt: {}".format(first_positibe_cnt))
    # print(L_positive)
    # print("first_negative_cnt, cnt: {}".format(first_negative_cnt))
    # print(L_negative)

    return min(first_positibe_cnt, first_negative_cnt)


if __name__ == "__main__":
    N = int(input())
    L = list(map(int, input().split(' ')))
    print(solution(L))


Measured memory_bytes: 20608
import java.util.*;
 
public class Main {
    public static void main(String args[] ) throws Exception {
    	
    	Scanner sc = new Scanner(System.in);
    	Integer array[];
    	array = new Integer[10];	
    	
        for (int i=0; i<10; i++) {
            Integer mountain = sc.nextInt();
            array[i] = mountain;
        }
        
        Arrays.sort(array, Comparator.reverseOrder());
        for (int j=0; j<3; j++){
        System.out.println(array[j]);
        }
    }
}

Measured memory_bytes: 26312
#include <cstdio>
int n;
char s[100001],r[100001];
bool c(char a,char b)
{
    r[0]=a;
    r[1]=b;
    for (int i=2; i<n; ++i)
r[i]=r[i-1]=='S'?s[i-1]=='o'?r[i-2]:r[i-2]=='S'?'W':'S':s[i-1]=='x'?r[i-2]:r[i-2]=='S'?'W':'S';
    return !(r[n-1]=='S'&&((s[n-1]=='o'&&r[n-2]!=r[0])||(s[n-1]=='x'&&r[n-2]==r[0])))&&
           !(r[0]=='S'&&((s[0]=='o'&&r[1]!=r[n-1])||(s[0]=='x'&&r[1]==r[n-1])))&&
           !(r[n-1]=='W'&&((s[n-1]=='x'&&r[n-2]!=r[0])||(s[n-1]=='o'&&r[n-2]==r[0])))&&
           !(r[0]=='W'&&((s[0]=='x'&&r[1]!=r[n-1])||(s[0]=='o'&&r[1]==r[n-1])));
}
int main()
{
    scanf("%d%s",&n,s);
    puts(c('S','W')||c('W','S')||c('W','W')||c('S','S')?r:"-1");
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);

  long long a[n+1] , b[n+1] , c[n+1];
  long long ans = 0;
  for(int i = 1;i <= n;i ++){
    scanf("%lld %lld",&a[i] ,&b[i]);
    if(a[i]%b[i] != 0){
      c[i] = a[i] % b[i];
    }
    else{
      c[i] = 0;
    }
  }

  for(int i = n;i > 0;i --){
    if(c[i]%b[i] != 0){
      ans += b[i] - (c[i]%b[i]);
    }
    c[i-1] += ans;
  }

  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 4072
#include <stdio.h>
int main(void){
	int n[10000],m[10000];
	int h,i,j,k;
	h=0;
	do{
		h++;
		scanf("%d %d",&n[h],&m[h]);
	}while(n[h]!=0&&m[h]!=0);
	k=1;
	while(k<h){
		if(k==h)break;
		else 
		for(i=1;i<=n[k];i++){
			for(j=1;j<=m[k];j++)printf("#");
			printf("\n");
		}
		printf("\n");
		k++;
	}
	return 0;
}



Measured memory_bytes: 2020
#include <iostream>
#include <cstdio>

using namespace std;


class Rectangle{

private:
    int minx, maxx, miny, maxy;

public:
    Rectangle(int W, int H) : minx(0), miny(0), maxx(W), maxy(H){}

    void op(int x, int y, int a){

        if(a == 1) minx = max(minx, x);
        else if(a == 2) maxx = min(maxx, x);
        else if(a == 3) miny = max(miny, y);
        else maxy = min(maxy, y);
    }

    int area(){
        return max(0, (maxx - minx)) * max(0, (maxy - miny));
    }
};

int main() {

    int W, H, N;
    scanf("%d%d%d", &W, &H, &N);

    Rectangle rec(W, H);
    int x, y, a;
    while(N --){
        scanf("%d%d%d", &x, &y, &a);
        rec.op(x, y, a);
    }
    printf("%d\n", rec.area());

    return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    string o,b;
    cin >> o >> b  ;

    pri(o.size()==b.size()?o==b?"EQUAL":o>b?"GREATER":"LESS":o.size()>b.size()?"GREATER":"LESS");

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

long long n,k;
long long const inf=1LL<<60;
int main(){
    std::cin >> n>>k;
    std::vector<long long> h(n),dp(n,inf);
    for (int i = 0; i < n; i++) {
        /* code */
        std::cin >> h[i];
    }
    dp[0]=0;
    for (int i = 1; i < n; i++) {
        /* code */
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        
        
        for (int j = 2; j <= k; j++) {
            /* code */
            if(i>=j)chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    std::cout << dp[n-1] << std::endl;
}

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

int main(){
while(1){
	
	int n=0,d[103] = {0};
	scanf("%d",&n);
	if(n == 0)break;
	n+=1;
	
	for(int i = 1;i <= n;i++){
	scanf("%d",&d[i]);
	}
	
	for(int i = 1;i <= n;i++){ 
	int sa = 0;
	int nau;
	
	if(i == 1){
	sa = d[3] - d[2];
	nau = d[2];
	}else if(i == 2){
	sa = d[4] - d[3];
	nau = d[1];
	}else{
	sa = d[2] - d[1];
	nau = d[1];
	}
	
	
		for(int j = 1;j <= n;j++){
		if(i == j) continue;
		if(d[j] != nau) goto out;
		nau += sa;
		}
		printf("%d\n",d[i]);
		break;
		out:
		;
	}
	}
	return 0;
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;
static const int MAX_Q = 100000;
static const ll INF = 2000000000000000;

int N;
int a[MAX_N], b[MAX_N], c[MAX_N];
int Q, K;
int x[MAX_Q], y[MAX_Q];

struct edge{int to, cost;};
typedef pair<int, int> P;

vector<edge> G[MAX_N];
ll d[MAX_N];

void dijkstra(int s){
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + N, INF);
	d[s] = 0;
	que.push(P(0, s));

	while(!que.empty()){
		//printf("in loop\n");
		P p = que.top(); que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

void solve(){
	for(int i = 0; i < N; i++){
		G[a[i] - 1].push_back((edge){b[i] - 1, c[i]});
		G[b[i] - 1].push_back((edge){a[i] - 1, c[i]});
	}
	dijkstra(K - 1);
	//for(int i = 0; i < N; i++) printf("%lld\n", d[i]);
	for(int i = 0; i < Q; i++){
		printf("%lld\n", d[x[i] - 1] + d[y[i] - 1]);
	}
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N - 1; i++) scanf("%d %d %d", &a[i], &b[i], &c[i]);
	scanf("%d %d", &Q, &K);
	for(int i = 0; i < Q; i++){
		scanf("%d %d", &x[i], &y[i]);
	}
	solve();
	return 0;
}


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

template<typename T>
void print(std::vector<T> v){
    for(auto p:v){
        std::cout<<p<<" ";
    }
    std::cout<<std::endl;
}

/***********************/
//  during contest

void stupid(){
    int N;
    unsigned long long K;
    std::cin>>N>>K;
    std::vector<int>p(N);
    std::vector<long long> costs(N),sortedCosts(N);
    long long ans=0;
    long long loopCost=0;
    unsigned sumCost=0;

    for(int i=0;i<N;++i){
        std::cin>>p[i];
        p[i]-=1;
    }
    for(int i=0;i<N;++i){
        std::cin>>costs[i];
        sumCost+=costs[i];
    }
    int seed=0;
    for(int i=0;i<N;++i){
        sortedCosts[i]=costs[p[seed]];
        seed=p[seed];
    }
    print(sortedCosts);
    if(K>=N && sumCost>0){
        loopCost=sumCost*(K/N);
    }
    unsigned long long KN=K%N;
    for(int i=0;i<N;++i){
        long long s=0;
        for(int j=0;j<K && j<N;++j){
            s+=sortedCosts[(i+j)%N];
            long long buf=s;
            if(loopCost>0){
                if(j>KN){
                    buf+=(loopCost-sumCost);
                }else{
                    buf+=loopCost;
                }
            }
            if(ans<buf){
                ans=buf;
            }
        }
    }
    std::cout<<ans<<std::endl;
}

/************************/

void stupid2(){
    int N;
    unsigned long long K;
    std::cin>>N>>K;
    std::vector<int>p(N);
    std::vector<long long> costs(N),sums;
    std::vector<bool>flag(N,1);
    std::vector<std::vector<long long> > loops;
    long long ans=-1e10;
    for(int i=0;i<N;++i){
        std::cin>>p[i];
        p[i]-=1;
    }
    for(int i=0;i<N;++i){
        std::cin>>costs[i];
    }
    for(int i=0;i<N;++i){
        if(flag[i]==0){
            continue;
        }
        std::vector<long long>buf;
        long long sumBuf=0;
        for(int j=i;;j=p[j]){
            buf.push_back(costs[j]);
            sumBuf+=costs[j];
            flag[j]=0;
            if(p[j]==i){
                break;
            }
        }
        loops.push_back(buf);
        sums.push_back(sumBuf);
    }
    for(unsigned int i=0;i<loops.size();++i){
        long long loopCost=0;
        int loopLen=loops[i].size();
        int loopMod=K%loopLen;
        if((unsigned long long)loopLen<=K && sums[i]>0){
            loopCost=(K/loopLen)*sums[i];
        }
        for(int j=0;j<loopLen;++j){
            long long sum=0;
            for(int k=1;k<=loopLen && k<=K;++k){
                long long buf;
                sum+=loops[i][(j+k)%loopLen];
                buf=sum;
                if(loopCost>0){
                    if(k>loopMod){
                        buf+=(loopCost-sums[i]);
                    }else{
                        buf+=loopCost;
                    }
                }
                if(ans<buf){
                    ans=buf;
                }
            }
        }
    }
    std::cout<<ans<<std::endl;
}

int main(){
    stupid2();
}



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

using namespace std;

using ll = long long;
constexpr ll INF = 1e15;

constexpr int NMAX = 5000;
// https://img.atcoder.jp/aising2019/editorial.pdf
int N;
vector<ll> a(NMAX);
vector<vector<int>> g(NMAX);
// dp1[i][j] := i の部分木を条件を満たして j 個に分け,
//              i を含む成分の a が全て正となるようにするときの i が属する集合の和の最小値
vector<vector<ll>> dp1(NMAX);
// dp2[i][j] := i の部分木を j 個に分け,
//              i を含む成分以外は条件を満たすようにするときの i が属する集合の和の最小値
vector<vector<ll>> dp2(NMAX);

vector<ll> dfs2(vector<ll> &dp, vector<ll> &c1, vector<ll> &c2, bool flag)
{
    int sz0 = dp.size(), sz1 = c1.size(), sz2 = c2.size();
    vector<ll> ret(sz0 + sz2 - 1, INF);
    for (int i = 0; i < sz0; i++)
    {
        if (dp[i] == INF)
            continue;
        for (int j = 0; j < sz1; j++)
        {
            if (i + j - 1 >= 0)
            {
                if (c1[j] != INF)
                    ret[i + j - 1] = min(ret[i + j - 1], dp[i] + c1[j]);
                if (c2[j] != INF && !flag)
                    ret[i + j - 1] = min(ret[i + j - 1], dp[i] + c2[j]);
            }
            if (c1[j] != INF)
            {
                ret[i + j] = min(ret[i + j], dp[i]);
            }
            if (c2[j] < 0)
            {
                ret[i + j] = min(ret[i + j], dp[i]);
            }
        }
    }
    return ret;
}

void dfs(int cur, int pre)
{
    // dp1[cur][0] = INF;
    dp1[cur].push_back(INF);
    // dp1[cur][1] = a[cur] or INF
    dp1[cur].push_back(a[cur] > 0 ? a[cur] : INF);
    // dp2[cur][0] = INF;
    dp2[cur].push_back(INF);
    // dp2[cur][1] = a[cur];
    dp2[cur].push_back(a[cur]);

    // dp1'[i][j] := cur の i 番目の子迄からなる部分木を dp1 と同条件で
    //               j 個に分けたときの cur を含む成分の和の最小値
    for (const auto &u : g[cur])
    {
        if (u == pre)
            continue;
        dfs(u, cur);
        dp1[cur] = dfs2(dp1[cur], dp1[u], dp2[u], true);
        dp2[cur] = dfs2(dp2[cur], dp1[u], dp2[u], false);
    }
}

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

    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> a[i];
    for (int i = 0; i < N - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0, -1);
    for (ll k = 1; k <= N; k++)
    {
        if (dp1[0][k] != INF || dp2[0][k] < 0)
        {
            cout << k - 1 << endl;
            return 0;
        }
    }
    assert(false);
}


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int n, m;
vector<int> k;
vector<vector<int>> s;
vector<int> p;

int solve(int t, vector<bool>& sel) {
  if(t == n) {
    bool ok = true;
    for(int i=0;i<m;++i) {
      int su = 0;
      for(int j=0;j<k[i];++j) {
        if(sel[s[i][j]]) su++;
      }
      if(su%2 != p[i]) {
        ok = false;
        break;
      }
    }
    return (int)ok;
  } else {
    int res = solve(t+1, sel);
    sel[t] = 1;
    res += solve(t+1, sel);
    sel[t] = 0;
    return res;
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  cin >> n >> m;
  k.resize(m);
  s.resize(m);
  for(int i=0;i<m;++i) {
    cin >> k[i];
    s[i].resize(k[i]);
    for(int j=0;j<k[i];++j) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  p.resize(m);
  for(int i=0;i<m;++i) {
    cin >> p[i];
  }

  vector<bool> sel(m);
  cout << solve(0, sel) << endl;

}


Measured memory_bytes: 256
n,m = map(int,input().split())
 
if (n == 2 and m != 1) or (m == 2 and n != 1):
  print(0)
elif n ==1 and m != 1:
  print(m-2)
elif m == 1 and n != 1:
  print(n-2)
elif n == 1 and m == 1:
  print(1)
else:
  print(n*m-(n+m-2)*2)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は log(N);
 */
const int mod = 1e9 + 7;
// pie = M_PI
//ここから書き始める
#define MAX 200000
#define SENTINEL 2e9

int L[MAX / 2 + 2], R[MAX/2+2];

ll merge(int A[], int n, int left , int mid , int right){
	int i , j , k;
	ll cnt = 0;
	int n1 = mid - left ;
	int n2 = right - mid;
	rep(i,n1) L[i] = A[left + i];
	rep(i,n2) R[i]= A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for ( k = left ; k < right ; k++){
		if (L[i] <= R[j]){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

ll mergeSort(int A[],int n , int left, int right){
	int mid;
	ll v1,v2,v3;
	if(left + 1 < right){
		mid = (left + right ) / 2;
		v1 =mergeSort(A,n,left,mid);
		v2 = mergeSort(A,n,mid,right);
		v3 = merge(A,n,left,mid,right);
		return v1 + v2 + v3;
	}else return 0 ;
}

int main(){
	int A[MAX],n,i;

	cin >> n;
	rep(i,n) cin >> A[i];
	ll ans = mergeSort(A,n,0,n);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4612
#include <iostream>
#include <cmath>
#define NMAX 100000

using namespace std;

int n, dp[NMAX+10], v[NMAX+10];

int main()
{
    cin >> n;
    for(int i=1; i<=n; i++) cin >> v[i];
    dp[2] = abs(v[2] - v[1]);
    for(int i=3; i<=n; i++) dp[i] = min(dp[i-2] + abs(v[i-2] - v[i]), dp[i-1] + abs(v[i-1] - v[i]));
    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 1024
import numpy as np
from collections import Counter

n,m = map(int,input().split())

a = np.array([0]+list(map(int,input().split())),dtype=np.int64)
a = np.mod(a.cumsum(),m)

c = Counter(a)

ans = 0

for i in c.values():
    ans += i*(i-1)//2

print(ans)

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

using namespace std;

int main()
{
    long long n;
    cin >> n;

    long long ans=0;
    for(long long i=1;i<=n;i++){
        if(i%3==0 || i%5==0) continue;
        ans+=i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3548
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll mult (ll a, ll b) {
	return a * b % mod;
}

ll add (ll a, ll b) {
	int c = a + b;
	if (c >= mod) c -= mod;
	return c;
}

ll powmod (ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2) return mult (a, powmod (a, n - 1));
	ll b = powmod (a, n / 2);
	return mult (b, b);
}

ll inv (int a) {
	return powmod (a, mod - 2);
}

int f[maxn], rev[maxn];

int C (int n, int k) {
	if (k == 0 || n == k) return 1;
	return mult (f[n], mult (rev[k], rev[n - k]));
}



signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	f[0] = 1;
	fl (i, 1, maxn) {
		f[i] = mult (f[i - 1], i);
		rev[i] = inv (f[i]);
	}
	int n, k;
	cin >> n >> k;
	k = min (k, n - 1);
	int ans = 0;
	fr (i, k + 1) {
		ans = add (ans, mult (C (n, i), C (n - 1, n - i - 1)));
		dbg (ans);
	}
	cout << ans;







}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
ll po(ll n)
{
	ll k=0;
	while(n%2==0)
	{
		k++;
		n=n/2;
	}
	return k;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,k,n,w;
    	cin>>n>>w;
    	ll dp[n][w+1];
		pii a[n]; 
    	rep(i,0,n)
    	cin>>a[i].F>>a[i].S;
		rep(i,0,n)
		{
			repi(j,0,w)
			dp[i][j]=0;
		}
		rep(i,0,n)
		{
			rep(j,0,w+1)
			{
				if(j==0)
				dp[i][j]=0;
				else if(i>=1 && j>=a[i].F)
				dp[i][j]=max(dp[i-1][j],a[i].S+dp[i-1][j-a[i].F]);
				else if(i>=1)
				dp[i][j]=dp[i-1][j];
				else if(i==0 && j>=a[i].F)
				dp[i][j]=a[i].S;
				
			}
		}
		cout<<dp[n-1][w];
    } 
	return 0;
}

Measured memory_bytes: 78336
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
MOD = 10**9 + 7
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

r = ii()

print(3 * r * r)




Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
int x[100100];
vector<pair<int,int> > v;
int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>x[i];
    sort(x,x+n);
    ll b=x[0];
    for(int i=1;i<n-1;i++)
    {   if(x[i]>=0){
     v.pb(mp(b,x[i]));
     b-=x[i];}
     else
     {
         v.pb(mp(x[n-1],x[i]));
         x[n-1]-=x[i];
     }
    }
    v.pb(mp(x[n-1],b));
    x[n-1]-=b;
    cout<<x[n-1]<<endl;
    for(int i=0;i<n-1;i++)
        cout<<v[i].ff<<' '<<v[i].ss<<endl;
    return 0;
}


Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>

int compare(const void *a,const void *b){
	return *(int*)b-*(int*)a;
}

int main(){
	
	int N,K,l[60],i,max=0;
	
	scanf("%d",&N);
	scanf("%d",&K);
	for(i=0;i<N;i++){
		scanf("%d",&l[i]);
	}
	
	qsort(l,N,sizeof(int),compare);
	
	
	for(i=0;i<K;i++){
		max+=l[i];
		
	}
	
	printf("\n%d\n\n",max);
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define MP make_pair
#define ull unsigned long long int
#define F first
#define S second
#define put insert
#define pb push_back
#define rsortV(arr) sort(arr.begin(),arr.end(),greater<int>())
#define sortV(arr) sort(arr.begin(),arr.end())
#define sortA(arr,n) sort(arr,arr+n)
#define rsortA(arr,n) sort(arr,arr+n,greater<int>())
#define arrInput(arr,n) for(int i=0;i<n;i++) cin>>arr[i];
#define rev(arr) reverse(arr.begin(), arr.end())
#define all(x) (x).begin(), (x).end()
ll MOD = 1e9+7;
int numOfFactors(int N) {
    if(N == 0)
        return 0;
    if(N == 1)
        return 1;
    if(N <= 3)
        return 2;
    int ans = 0;
    for(int i=1;i*i<=N;i++) {
        if(N%i == 0) {
            ans ++;
            if(N/i != i)
                ans++;
        }
    }
    return ans;
}
int main() {
    fastio
    // int t;
    // cin>>t;
    // while(t--) {
    int N;
    cin>>N;
    int ans = 0;
    for(int C=1;C<=N;C++) {
        ans += numOfFactors(N-C);
    }
    cout<<ans;
    // }
    return 0;
}


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

int main() {

  string w;

  cin >> w;
  vector<int> vec(26);
  for(int i=0;i<w.size();++i){
    vec.at(w.at(i)-'a')++;
  }

  for(int i=0;i<26;++i){
    if(vec.at(i) % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3628
using System;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static int solver()
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var N = NK[0]; var K = NK[1];
            var A = new int[N + 1];
            var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            for (int i = 0; i < N; i++) A[i + 1] = read[i];
            var first = new long[N + 1];
            for (int i = 0; i < N + 1; i++) first[i] = -1;

            long move = 0;
            var position = 1;
            while (first[position] < 0)
            {
                first[position] = move;
                move++;
                position = A[position];
                if (move == K) return position;
            }
            var span = move - first[position];
            var reminder = (K - first[position]) % span;

            long move2 = 0;
            while (move2 < reminder)
            {
                position = A[position];
                move2++;
            }
            return position;
        }
    }
}


Measured memory_bytes: 44652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;

#define For(N,i) for(int i = 0; i < N; i++)


int main(){
	std::cout << std::fixed << std::setprecision(10);
	double a,b,x;
	cin>>a>>b>>x;
	double s = 0;
	double h = (double)x / ((double)a * (double)a);
	double m = (double)b - (double)h;
	double x_ = (double)x / (double)a;
	double u = (double)x_ / (double)b * 2.0;
	if(u >= a){
		double nh = b - h;
		double uh = h - nh;
		
		
		s = atan((double)(b - uh) / (double)a);
	}else{
		s = atan((double)b / (double)u);
	}
	cout<<s*180.0/M_PI<<endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
from heapq import heappop,heappush 

graph=[[] for _ in range(N)]
for _ in range(M):
    A,B=map(int,input().split())
    A,B=A-1,B-1
    graph[A].append(B)
    graph[B].append(A)

mark=[-1]*(N-1)

inf=float("inf")

di=[inf]*N
di[0]=0
hq=[(0,0)]

while hq:
    t,r=heappop(hq) #time room
    if t>di[r]:
        continue
    for x in graph[r]:
        t_new=t+1
        r_new=x
        if t_new<di[r_new]:
            di[r_new]=t_new
            heappush(hq,(t_new,r_new))
            if mark[r_new-1]==-1:
                mark[r_new-1]=r
            else:
                print("No")
                exit()
    
print("Yes")
for i in mark:
    print(i+1)

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

using namespace std;
using ll = long long;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N;
    cin >> N;

    ll c = 0;
    if(N % 2 == 0) {
        N /= 2;
        while(N > 0) {
            N /= 5;
            c += N;
        }
        _PR(c);
    }
    else _PR(0);

    return 0;
}

/*

    N!: [N/5^1] + [N/5^2] + ...

*/

Measured memory_bytes: 256