akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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; }

int main()
{	
	string X;
	cin >> X;

	stack<char> st;

	rep(i, X.size())
	{
		if (X[i] == 'S')
		{
			st.push(X[i]);
		}
		else
		{
			if (st.empty() || st.top() == 'T')
			{
				st.push(X[i]);
			}
			else
			{
				st.pop();
			}
		}
	}

	cout << st.size() << endl;

	return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y;cin >> x >> y;
	int ans=0;
	for(ll i=x;i<=y;i+=i) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
K,N=map(int, input().split())
A=list(map(int, input().split()))

B=[0]*N

for i in range(N-1):
    B[i]=A[i+1]-A[i]

B[-1]=A[0]+K-A[-1]

B=sorted(B)

ans = sum(B[0:-1])
print(ans)

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

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

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

int main()
{
    string a,b,c;
    ll ans=0,n;
    cin >> n >> a >> b >> c;
    rep(i,n){
        vector<char> v;
        v.pb(a[i]);
        v.pb(b[i]);
        v.pb(c[i]);
        sort(all(v));
        Eunique(v);
        ans+=v.size()-1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String a = "AAA" , b = "BBB";
    if( s.equals(a) || s.equals(b) ){
        System.out.println("No");
    }else{
        System.out.println("Yes");
    }
    sc.close();
  }
}

Measured memory_bytes: 35564
#define _DEBUG 1

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

void solve(ll r, ll g, ll b) { yesOrNo((100 * r + 10 * g + b) % 4 == 0); }

// 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)
int main() {
  ll r;
  scanf("%lld", &r);
  ll g;
  scanf("%lld", &g);
  ll b;
  scanf("%lld", &b);
  solve(r, g, b);
  return 0;
}


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

int main(){
  int N, K, A, B, C;
  N = 0;
  string s;
  cin >> s;
/*
  vector<char> S(N);
  for(int i = 0; i < N; i++)
    cin >> S.at(i);
*/
  for(int i = 0; i < 4; i++){
    if(s.at(i)=='2') N++;
  }
  cout << N << endl;

}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			while (true) {
				int a = sc.nextInt();
				String op = sc.next();
				int b = sc.nextInt();

				if (op.equals("?")) {
					break;
				} else if (op.equals("+")) {
					System.out.println(a + b);
				} else if (op.equals("-")) {
					System.out.println(a - b);
				} else if (op.equals("*")) {
					System.out.println(a * b);
				} else if (op.equals("/")) {
					System.out.println(a / b);
				}

			}
		}
	}
}


Measured memory_bytes: 26304
#include <iostream>
#include <string>
#include <vector>
 
int main() {
  std::string s;
  std::getline(std::cin, s);
  int len = s.size();
  std::vector<int> up(len+1), down(len+1);
  int64_t sum = 0;
  int i = 0, t = 0, b0 = 0, b1 = 0;
  do {
    while (s[i] == '<' && i < len) i++;
    t = i;
    while (s[i] == '>' && i < len) i++;
    b1 = i;
    for (int j = b0; j < t; j++) {
      sum += j - b0;
    }
    sum += std::max(t - b0, b1 - t);
    for (int j = t + 1; j <= b1; j++) {
      sum += b1 - j;
    }
    b0 = b1;
  } while (i < len);
  
  std::cout << sum << std::endl;
}


Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,W,w,v;
    cin>>n>>W;
    int dp[W+1];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        cin>>w>>v;
        for(int j=W;j>=w;j--)
            dp[j] = max(dp[j],dp[j-w]+v);
    }
    cout<<dp[W];
    return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int ab , bc, ca;
    cin >> ab >> bc >> ca;

    if(ab * ab + bc * bc == ca * ca)
        cout << ab * bc / 2 << endl;
    else if( bc * bc + ca * ca == ab * ab)
        cout << bc * ca / 2 << endl;
    else if(  ca * ca + ab * ab == bc * bc )
        cout << ca * ab / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a,int b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}

int main() {
    int x;
    cin >> x;
	long long int sum = 0;
	for(int i=1;i<=x;i++){
	    for(int j=1;j<=x;j++){
	        for(int k=1;k<=x;k++)
	        sum+=gcd(i,gcd(j,k));
	    }
	}
	cout << sum;
	return 0;
}



Measured memory_bytes: 3592
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0 

using namespace std;
using ll = long long;

void testcase() {
    int h, w, n;
    cin >> h >> w >> n;
    int maxi = max(h, w);
    int res = n / maxi;
    if (n % maxi > 0) res++;
    cout << res << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(n):
    if x-A[i]>=0:
        x=x-A[i]
    else:
        print(i)
        exit()
if x==0:print(n)
else:print(n-1)

Measured memory_bytes: 3060
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=1e5+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

int main()
{
    ll n;
    cin>>n;
    ll a[n],pre[n],suf[n];
    for(ll i=0;i<n;i++){cin>>a[i];}
    for(ll i=0;i<n;i++)
    {
        if(i==0){pre[i]=a[i];}
        else{pre[i]=max(a[i],pre[i-1]);}
    }
    for(ll i=n-1;i>=0;i--)
    {
        if(i==n-1){suf[i]=a[i];}
        else{suf[i]=max(a[i],suf[i+1]);}
    }
    for(ll i=0;i<n;i++)
    {
        if(i==0){cout<<suf[i+1]<<endl;}
        else if(i==n-1){cout<<pre[i-1]<<endl;}
        else{cout<<max(pre[i-1],suf[i+1])<<endl;}
    }
}

Measured memory_bytes: 6272
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int max;
        int [] h = new int[n];
        for (int i = 0; i < n; ++i) {
            h[i] = scanner.nextInt();
        }
        max = h[0];
        int ans = 1;
        for (int i = 1; i < n; ++i) {
            if (max <= h[i]) {
                ++ans;
            }
            max = Math.max(max, h[i]);
        }
        System.out.println(ans);
    }
}


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

int main() {
    int ans = 0;
    for(int i = 0; i < 4; i++){
        char s;
        cin >> s;
        if (s == '+') {
            ans++;
        }
        else {
            ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,I=y+1;i<I;++i)
#define per(i,x,y) for(int i=x,I=y-1;i>I;--i)
using namespace std;
using ll=long long;
void cmax(int&x,const int&y){x=x>y?x:y;}
void cmin(int&x,const int&y){x=x<y?x:y;}
template<class T>istream&operator>>(istream&in,vector<T>&V){for(auto&x:V)in>>x;return in;}
template<class T>ostream&operator<<(ostream&out,const vector<T>&V){for(auto x:V)out<<x<<' ';return out;}
template<class T>void sort(vector<T>&V){sort(V.begin(),V.end());}
template<class T>void reverse(vector<T>&V){reverse(V.begin(),V.end());}
template<class T>int SZ(const vector<T>&V){return (int)V.size();}
void debug(){cerr<<"whxorz"<<'\n';}
int h,n;
const int N=262144;
int id[N];
const int mod=1e9+7;
int mul(const int&x,const int&y){return 1ll*x*y%mod;}
void upd(int&x,const int&y){x+=y;if(x>=mod)x-=mod;}
int tag[N];
int ans=0;
void trv2(int p,int prd,int op){
	if(p==1)return;prd=mul(prd,p);
	if(op)upd(tag[p],prd);
	else upd(ans,mul(mul(p>>1,tag[p^1]),prd));
	trv2(p>>1,prd,op);
}
int st[N],top=0;
void trv(int p,int prd,int op){prd=mul(prd,p);
	if(p>=n)return st[++top]=id[p],trv2(id[p],prd,op);
	trv(p<<1,prd,op);trv(p<<1|1,prd,op);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>h;
	n=1<<h-1;
	rep(i,1,n)cin>>id[i+n-1],id[i+n-1]+=n-1;
	//link i+n-1,id[i+n-1]
	rep(i,1,n-1){trv(i<<1,i,1);trv(i<<1|1,1,0);while(top)for(int x=st[top--];x;x>>=1)tag[x]=0;}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 5648
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n, tmp;
	string s;

	cin>> n;
	cin>> s;

	for (int i = 0;i < s.size();i++) {
		tmp = s[i] + n;
		if (tmp > 90) tmp -= 26;
		cout << (char)(tmp);
	}
	cout << endl;

}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



int main() {
    int n; cin >> n;
    deque<ll> a;
    rep(i, n) {
        ll t; cin >> t;
        if(i%2 == 0)a.push_back(t);
        else a.push_front(t);
    }

    if(n%2 == 0) {
        // 先頭から
        rep(i, n) {
            cout << a.front() << endl;
            a.pop_front();
        }
    } else {
        rep(i, n) {
            cout << a.back() << endl;
            a.pop_back();
        }
    }

    return 0;
}


Measured memory_bytes: 3840
#include<stdio.h>

int main(){
    while(1){
        int n,x,c=0;
        scanf(" %d %d\n",&n,&x);
        if(n==0&&x==0){
            break;
        }
        for(int i=1; i<=n-2; i++){
            for(int j=i+1; j<=n-1; j++){
                for(int k=j+1; k<=n; k++){
                    if(i+j+k==x) {
                        c++;
                        break;
                    }
                }
            }
        }
        printf("%d\n",c);
    }
    return 0;
}



Measured memory_bytes: 2624
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;

int main() {
	int a[8]= {0};
	int n;
	cin>>n;
	int *b=new int[n];
	for(int i=0; i<n; i++) {
		cin>>b[i];
	}
	int flag=0;
	int sum=0;
	for(int i=0; i<n; i++) {
		if(b[i]>=1&&b[i]<=399) {
			a[0]++;
		} else if(b[i]>=400&&b[i]<=799) {
			a[1]++;
		} else if(b[i]>=800&&b[i]<=1199) {
			a[2]++;
		} else if(b[i]>=1200&&b[i]<=1599) {
			a[3]++;
		} else if(b[i]>=1600&&b[i]<=1999) {
			a[4]++;
		} else if(b[i]>=2000&&b[i]<=2399) {
			a[5]++;
		} else if(b[i]>=2400&&b[i]<=2799) {
			a[6]++;
		} else if(b[i]>=2800&&b[i]<=3199) {
			a[7]++;
		} else if(b[i]>=3200) {
			flag++;
		}
	}
	for(int i=0; i<8; i++) {
		if(a[i]) {
			sum++;
		}
	}
	if(sum!=0) {
		flag+=sum;
		cout<<sum<<" "<<flag<<endl;
	} else {
		cout<<"1"<<" "<<flag<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool a[10];
int n,x,ans,temp;
int main()
  {
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
      {
        scanf("%d",&x);
        if (x<400&&!a[1]) a[1]=true,ans++;
        if (x>=400&&x<800&&!a[2]) a[2]=true,ans++;
        if (x>=800&&x<1200&&!a[3]) a[3]=true,ans++;
        if (x>=1200&&x<1600&&!a[4]) a[4]=true,ans++;
        if (x>=1600&&x<2000&&!a[5]) a[5]=true,ans++;
        if (x>=2000&&x<2400&&!a[6]) a[6]=true,ans++;
        if (x>=2400&&x<2800&&!a[7]) a[7]=true,ans++;
        if (x>=2800&&x<3200&&!a[8]) a[8]=true,ans++;
        if (x>=3200) temp++;
      }
    printf("%d %d\n",max(ans,1),ans+temp);
    return 0;
  }

Measured memory_bytes: 256
#include<stdio.h>
 #include<algorithm>
 using namespace std;
 int a[2000000];
 int H;
 void minitree(int i)
 {
     int l=i*2;
     int r=i*2+1;
     int bigest;
     if(a[i]<a[l]&&l<=H) bigest=l;
     else bigest=i;
     if(a[bigest]<a[r]&&r<=H) bigest=r;
     if(bigest!=i)
     {
         swap(a[bigest],a[i]);
         minitree(bigest);
     }
 }
 int main()
 {

     scanf("%d",&H);
     for (int i=1;i<=H;i++)
        scanf("%d",&a[i]);
     for (int i=H/2;i>=1;i--) minitree(i);
     for (int i=1;i<=H;i++) printf(" %d",a[i]);
     printf("\n");
     return 0;
 }

Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1001001001;
typedef unsigned long long ll;

#define N 8

bool row[N], col[N], dpos[2*N-1], dneg[2*N-1];
bool X[N][N];

void putQueen(int r, int c){
  X[r][c] = true;
  row[r] = true;
  col[c] = true;
  dpos[r+c] = true;
  dneg[r-c+N-1] = true;
}

void leaveQueen(int r, int c){
  X[r][c] = false;
  row[r] = false;
  col[c] = false;
  dpos[r+c] = false;
  dneg[r-c+N-1] = false;
}

void printBoard(){
  rep(i, N){
    rep(j, N){
      if(X[i][j]) cout << "Q";
      else cout << ".";
    }
    cout << endl;
  }
}

void recursive(int i){
  //printf("recursive(%d)\n", i);
  if(i == N){
   // printf("i == N\n");
    printBoard();
    return;
  }
  if(row[i] == true){
    //printf("row[%d] == true\n", i);
    recursive(i+1);
    return;
  }
  
    rep(j, N){
      //printf("(%d, %d)\n", i, j);
      if(col[j] || dpos[i+j] || dneg[i-j+N-1]) continue;
      //printf("put(%d, %d)\n", i, j);
      putQueen(i, j);
      recursive(i+1);
      //printf("leave(%d, %d)\n", i, j);
      leaveQueen(i, j);
    }
  
    //printf("fail\n");
}

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

  rep(i, k){
    int r, c;
    cin >> r >> c;
    putQueen(r, c);
  }

  recursive(0);

  return 0;
}






Measured memory_bytes: 3116
import numpy as np
def g(a,s,n):
    if len(s)<=n:
        return 0
    elif n==0:
        return a+int(s)
    elif n==len(s)-1:
        y=a
        for i in range(len(s)):
            y+=int(s[i:i+1])
        return y
    else:
        y=0
        for i in range(1,len(s)):
            y+=g(a+int(s[:i]),s[i:],n-1)
        return y
def f(s):
    a=0
    for i in range(len(s)):
        b=g(0,s,i)
        a+=b
    return a
def main():
    S=str(input())
    print(f(S))

if __name__=='__main__':
    main()


Measured memory_bytes: 12504
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; 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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    int n, k; cin >> n >> k;
    cout << (k==1 ? 0 : n-k) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

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

    int sum = 0;
    int max = 0;
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        if (max < p) {
            sum += max;
            max = p;
        } else {
            sum += p;
        }
    }

    cout << int(sum + max / 2) << endl;

    return 0;
}



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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL<<60);

int main(){

    ll n; cin >> n;
    vll x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    vll a(n);
    rep(i, n) a[i] = i;

    long double sum = 0;
    do{
        rep(i, n-1){
            ll xi = x[a[i]];
            ll yi = y[a[i]];
            ll xj = x[a[i+1]];
            ll yj = y[a[i+1]];
            sum += sqrt((long double)(pow(xi-xj, 2)+pow(yi-yj, 2)));
        }
    }while(next_permutation(all(a)));

    ll n_fac = 1;
    rep(i, n) n_fac *= i+1;

    cout << fixed << setprecision(10) << sum/n_fac << endl;

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

#[allow(unused_macros)]
macro_rules! chmax {
    ( $ x : expr , $ y : expr ) => { if $ x < $ y { $ x = $ y ; true } else { false } };
}

const MAX_DIGIT: usize = 50usize;

fn main() {
    input! {
        n: usize, k: u64,
        a: [u64; n]
    }

    let mut dp = vec_md![None;MAX_DIGIT+1;2];
    dp[0][0] = Some(0u64);

    for i in 0..MAX_DIGIT {
        let bit = 1u64 << (MAX_DIGIT - 1 - i);
        let mut stands = 0u64;
        for j in 0..n {
            if a[j] & bit != 0 {
                stands += 1;
            }
        }
        let cost1 = bit * stands;
        let cost0 = bit * (n as u64 - stands);

        if let Some(v) = dp[i][1] {
            chmax!(dp[i+1][1], Some(v + std::cmp::max(cost0, cost1)));
        }
        if let Some(v) = dp[i][0] {
            if k & bit != 0 {
                chmax!(dp[i+1][1], Some(v + cost1));
            }
        }
        if let Some(v) = dp[i][0] {
            if k & bit != 0 {
                chmax!(dp[i+1][0], Some(v + cost0));
            } else {
                chmax!(dp[i+1][0], Some(v + cost1));
            }
        }
    }
    println!("{}", (std::cmp::max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1])).unwrap());
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1e5+5;
int a[maxn];
signed main()
{
    int n, cnt = 0;
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> a[i];
    for(int i=1; i<n; i++)
        if(a[i]==i&&a[i+1]==i+1)
            swap(a[i], a[i+1]), cnt ++;
    if(a[1] == 1)
        swap(a[1], a[2]), cnt ++;
    for(int i=2; i<=n; i++)
        if(a[i] == i)
            swap(a[i], a[i-1]), cnt ++;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int sum0 = 0, sum2 = 0;
		
		for(int i = 0; i < N; i++) {
			int a = in.nextInt();
            if(a % 2 != 0) sum0++;
            else if(a % 4 == 0) sum2++;
		}
		
		System.out.println((sum2 >= sum0) || (sum0 - 1 == sum2 && sum0 + sum2 == N) ? "Yes" : "No");
	}
}


Measured memory_bytes: 48836
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

int persons[15];
int n;
vector<pair<int,int>> states[15];
int ans, h, a;
void solve(int d) {
    if (d == n) {
        rep(i, n) {
            if (persons[i]) {
                rep(j, states[i].size()) {
                    if (persons[states[i][j].first-1] != states[i][j].second) {
                        return;
                    }
                }
            }
        }
        h = 0;
        rep(i, n) {
            if (persons[i]) h++;
        }
        ans = max(ans, h);
        return;
    }
    persons[d] = 0;
    solve(d+1);
    persons[d] = 1;
    solve(d+1);
}

int main(void) {
    cin >> n;
    rep(i, n) {
        cin >> a;
        rep(j, a) {
            pair<int,int> p;
            cin >> p.first;
            cin >> p.second;
            states[i].push_back(p);
        }
    }
    persons[0] = 0;
    solve(1);
    persons[0] = 1;
    solve(1);
    cout << ans << endl;
    return 0;
}


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

  int N  ;
  cin >> N ;
  vector<int> A(N) ;
  ll sum = 0 ;
  ll sum2 = 0 ;
  rep(i,N){
    cin >> A.at(i) ;
    sum += A.at(i) ;
  }
  ll ans =1e18;
  //cout << ans << endl ;
  for(int i = 0 ; i < N-1 ; i++ ){
    sum  -= A[i] ;
    sum2 += A[i] ;
    //cout << sum2 <<  ' ' << sum << endl;
    ans = min( ans, abs(sum2-sum) ) ;
  }
  cout << ans << endl ;
}

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

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;
	cin >> n;
	vector<ll> h(n);
	for(auto &i: h) cin >> i;
	vector<int> dp(n);
	dp[0] = 0;
	if(n==1){
		cout<< 0;
		return 0;
	}
	dp[1] = labs(h[0]-h[1]);
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-1] + labs(h[i]-h[i-1]),dp[i-2]+labs(h[i]-h[i-2]));
	}
	cout << dp[n-1];
	
	return 0;
}

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

#define N 300

struct C
{
  int i;
  int u;
  int a;
  int p;
};
#define C(X) \
  ( *( (struct C *)(X) ) )

int
compare (
  const void  * a,
  const void  * b
  )
{
  int res;

  res = C( b ).a - C( a ).a;
  if ( res ) return ( res );

  res = C( a ).p - C( b ).p;
  if ( res ) return ( res );

  return ( C( a ).i - C( b ).i );
}

int
main (
  )
{
  int i, c;

  for ( ; ; )
  {
    struct C d[ N ];
    int u[ 1001 ] = { 0 };
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d%d%d%d", &d[ i ].i, &d[ i ].u, &d[ i ].a, &d[ i ].p );
    }
    qsort ( d, n, sizeof ( struct C ), compare );

    for ( c = 0; c < 26; ++c )
    {
      for ( i = 0; i < n; ++i )
      {
        if ( d[ i ].u < 0 ) continue ;

        if ( c < 10 )
        {
          if ( u[ d[ i ].u ] < 3 )
          {
            printf ( "%d\n", d[ i ].i );
            ++u[ d[ i ].u ];
            d[ i ].u = -1;
            break ;
          }
          continue ;
        }

        if ( c < 20 )
        {
          if ( u[ d[ i ].u ] < 2 )
          {
            printf ( "%d\n", d[ i ].i );
            ++u[ d[ i ].u ];
            d[ i ].u = -1;
            break ;
          }
        }

        if ( c < 26 )
        {
          if ( u[ d[ i ].u ] < 1 )
          {
            printf ( "%d\n", d[ i ].i );
            ++u[ d[ i ].u ];
            d[ i ].u = -1;
            break ;
          }
        }
      }
      if ( i >= n ) break ;
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
def prime(n):
  cnt = 0
  for i in range(1,n):
    if n % i == 0:
        cnt += 1
  if cnt == 1:
    return n
  else:
    return -1

x = int(input())
for i in range(x,2*10**5):
  if prime(i) != -1:
    print(prime(i))
    exit()

Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int a,b,c,i,d=0;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);

	for(i=a;i<b+1;i++)
	{
		if(c%i==0)
		{
			d=d+1;
		}
	}
		printf("%d\n",d);
		return 0;
}
		

Measured memory_bytes: 596
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;

  int cnt = 0;
  for(int i = 0; i <= a;i++){
   for(int j = 0;j <= b;j++){
     if((x - i * 500 - j * 100) >= 0 && (x - i * 500 - j * 100) % 50 == 0 && (x - i * 500 - j * 100)/50 <= c){
       cnt++;
     }
   }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x) -> int:
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y) -> None:
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x) -> int:
        return -self.parents[self.find(x)]

    def same(self, x, y) -> bool:
        return self.find(x) == self.find(y)

    def members(self, x) -> list:
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self) -> list:
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self) -> int:
        return len(self.roots())

    def all_group_members(self) -> dict:
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N: int
    M: int
    A: int
    B: int
    N, M = map(int, input().split())
    uni = UnionFind(N)
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        uni.union(A,B)
    
    print(uni.group_count() - 1)


if __name__ == "__main__":
    main()

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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const ll mod =1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int cur = 0;
    int last = 0;
    int ans = 0;
    f(n){
        int add;
        cin >> add;
        if(add<=last){
            cur++;
            ans = max(ans,cur);
        }
        else{
            cur = 0;
        }
        last = add;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <string>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    string S;
    cin >> N >> S;
    for (char& ch : S)
    {
        ch = (ch + N - 'A') % 26 + 'A';
    }
    cout << S;
    return 0;
}

Measured memory_bytes: 3132
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break

    c = 0
    for i in range(1, int(x/3)+2):
        for j in range(i+1, int(x/2)+2):
            k = x - i - j
            if k <= j:
                break
            elif k <= n:
                c += 1
    print(c)

Measured memory_bytes: 7628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;
  int i;
  vector<int> a(200010,0);
  map<int,int> mp;
  cin >> s;
  reverse(s.begin(),s.end());
  int tmp=1;
  for(i=0;i<s.size();i++){
    a[i+1]=a[i]+tmp*(s[i]-'0');
    a[i+1]=a[i+1]%2019;
    tmp=tmp*10%2019;
  }
  for(i=0;i<=s.size();i++){
    mp[a[i]]++;
  }
  ll ans=0;
  for(i=0;i<=s.size();i++){
    if(mp[a[i]]>=2){
      ans+=mp[a[i]]*(mp[a[i]]-1)/2;
      mp[a[i]]=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4356
#include<stdio.h>
#define MAX 10000

int parent(int i)
{
	return i / 2;
}

int left(int i)
{
	return 2 * i;
}
int right(int i)
{
	return 2 * i + 1;
}

int main()
{
	int h, i, a[MAX+1];
	
	scanf("%d", &h);
	for(i = 1; i <= h; i++)
	{
		scanf("%d", &a[i]);
	}
	
	for(i = 1; i <= h; i++)
	{
		printf("node %d: key = %d, ", i, a[i]);
		if(parent(i) >= 1) printf("parent key = %d, ", a[parent(i)]);
		if(left(i) <= h) printf("left key = %d, ", a[left(i)]);
		if(right(i) <= h) printf("right key = %d, ", a[right(i)]);
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,ans = 0;
    cin >> n;
    vector<ll> a(n),b(n);
    rep0(i, n)cin >> a[i] >> b[i];
    rrep0(i, n){
        if ((a[i] + ans) % b[i] != 0) {
            ans += b[i] - (a[i] + ans) % b[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
bool isPalin(string s){
    if (s==string(s.rbegin(),s.rend()))
        return true;
    return false;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ll t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        ll ans=0ll;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                for(int k=j+1;k<n;k++){
                    if(a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
                        ans++;
                }
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <exception>
#include <vector>
using namespace std;

int main(){
  int h, w;
  std::cin >> h >> w;

  vector<vector<char> > s(h, vector<char>(w));
  for(int row = 0; row < h; row++){
    for(int col = 0; col < w; col++){
      std::cin >> s[row][col];
    }
  }

  bool ans = true;
  vector<pair<int, int> > around;
  around.push_back(make_pair(-1, 0));
  around.push_back(make_pair(0, 1));
  around.push_back(make_pair(1, 0));
  around.push_back(make_pair(0, -1));
  vector<pair<int,int> > result;
  for(int row = 0; row < h; row++){
    for(int col = 0; col < w; col++){
      if(s[row][col] == '#'){
        bool ok = false;
        for(int idx = 0; idx < around.size(); idx++){
          try{
            if(s.at(around[idx].first + row).at(around[idx].second + col) == '#'){
              ok = true;
            }
          }catch(exception e){
            // 無視
          }
        }
        if(!ok) ans = false;
      }
    }
  }
  if(ans) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';

  return 0;
}


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

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
   int u, minv;
   int d[MAX], p[MAX], color[MAX];

   // 初期化
   rep(i, n) {
      d[i] = INFTY;
      p[i] = -1;
      color[i] = WHITE;
   }

   d[0] = 0;

   while(1) {
      minv = INFTY;
      u = -1;

      rep(i, n){
         if (minv > d[i] && color[i] != BLACK) {
            u = i;
            minv = d[i];
         }
      }
      if(u == -1) break;
      // uの決定
      color[u] = BLACK;

      rep(v, n) {
         if(color[v] != BLACK && M[u][v] != INFTY) {
            if(d[v] > M[u][v]) {
               d[v] = M[u][v];
               p[v] = u;
               color[v] = GRAY;
            }
         }
      }
   }
   int sum = 0;
   rep(i, n) {
      if(p[i] != -1) sum += M[i][p[i]];
   }
   return sum;
}

int main(){
   cin >> n;
   rep(i, n) {
      rep(j, n) {
         int e; cin >> e;
         M[i][j] = (e == -1) ? INFTY : e;
      }
   }

   cout << prim() << endl;
   return 0;
}



Measured memory_bytes: 3100
import numpy as np


def resolve():
    a_list = list(map(int,input().split()))
    b_list = list(map(int,input().split()))
    c_list = list(map(int,input().split()))
    arr = np.array([a_list, b_list, c_list])

    n = int(input())
    for _ in range(n):
        num = int(input())
        arr = np.where(arr == num, 0, arr)

    if True in np.all(arr == 0, axis=0):
        print('Yes')
        return

    elif True in np.all(arr == 0, axis=1):
        print('Yes')
        return

    elif arr[0, 0] == 0 and arr[1, 1] == 0 and arr[2, 2] == 0:
        print('Yes')
        return

    elif arr[2, 0] == 0 and arr[1, 1] == 0 and arr[0, 2] == 0:
        print('Yes')
        return

    else:
        print('No')
        return
      
resolve()

Measured memory_bytes: 12512
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]

using namespace std;

double EPS = 1e-10;
const double PI = acos(-1);

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
};

typedef point Vector;

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

double norm(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw( point p0, point p1, point p2 ){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if (cross(a,b)>EPS) return COUNTER_CLOCKWISE;
  if (cross(a,b)<-EPS) return CLOCKWISE;
  if (dot(a, b)<-EPS) return ONLINE_BACK;
  if (norm(a)<norm(b)) return ONLINE_FRONT;
  return ON_SEGMENT;
}

int main(void){
  point a,b,c;
  int q;
  cin >> a.x >> a.y >> b.x >> b.y;
  cin >> q;
  while(q--){
    cin >> c.x >> c.y;
    int res=ccw(a,b,c);
    if(res==COUNTER_CLOCKWISE)cout << "COUNTER_CLOCKWISE" << endl;
    else if(res==CLOCKWISE)cout << "CLOCKWISE" << endl;
    else if(res==ONLINE_BACK)cout << "ONLINE_BACK" << endl;
    else if(res==ONLINE_FRONT)cout << "ONLINE_FRONT" << endl;
    else if(res==ON_SEGMENT)cout << "ON_SEGMENT" << endl;
  }

  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int a,b,c; cin>>a>>b>>c;
    if(a==b and b==c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int main()
{
    ll n,l,i,last,temp=1,a[100005];
    cin>>n>>l;
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<n;i++)
    {
        if(a[i]+a[i+1]>=l)
        {
            temp=0;
            last=i;
        }
    }
    if(temp)
    {
        cout<<"Impossible\n";
        return 0;
    }
    cout<<"Possible\n";
    for(i=1;i<last;i++)
    cout<<i<<endl;
    for(i=n-1;i>=last;i--)
    cout<<i<<endl;
}


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

const int N = 405;
int n, a[N];
long long prefix[N], dp[N][N], INF = 1e18+5;

long long f(int l, int r) {
  assert(r >= l);
  if (dp[l][r] != -1) return dp[l][r];
  if (r == l) return 0;

  long long ans = INF;
  for (int i = l; i < r; i++) {
    long long cost = 0;
    cost += f(l, i);
    cost += f(i+1, r);
    cost += prefix[r] - prefix[l-1];
    ans = std::min(ans, cost);
  }

  return dp[l][r] = ans;
}

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

  for (int i = 1; i <= n; i++) {
    scanf("%d", a+i);
    prefix[i] = a[i] + prefix[i-1];
  }

  memset(dp, -1, sizeof dp);
  printf("%lld\n", f(1, n));
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  vector<int> words(26);
  rep(i, s[0].length()){
    int index = s[0][i] - 'a';
    words[index]++;
  }
  for(int i = 1; i < n; ++i){
    vector<int> tmp(26);
    rep(j, s[i].length()){
      int index = s[i][j] - 'a';
      tmp[index]++;
    }
    rep(j, 26){
      words[j] = min(words[j], tmp[j]);
    }
  }
  rep(i, 26){
    char c = 'a' + i;
    rep(j, words[i]){
      cout << c;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	char s[11];
	int count = 0,ans=0;
	bool flag = false;
	cin >> s;
	REP(i, (int)strlen(s)) {
		if ((s[i] == 'A') || (s[i] == 'C') || (s[i] == 'G') || (s[i] == 'T')) {
			count++;
			flag = true;
		//	cout << 1;
		}
		else {
		//	cout << 0;
			if (flag) {
				if (ans < count)ans = count;
				count = 0;
			//	cout << 9;
			}
			flag = false;
		}
	}
	if (ans < count)ans = count;
	cout << ans << endl;
	return		(0);
}


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

#define N 100000

int main(void){
    char s[N], c;
    int len=0, l, r;
    int ret = 0;

    while(isalnum(c = getchar()))
        s[len++] = c;

    l = 0; r = len -1;
    while(l <= r){
        if(s[l] == s[r]){
            l++; r--;
        }
        else{
            if(s[l] == 'x'){
                l++;
                ret++;
            }
            else if(s[r] == 'x'){
                r--;
                ret++;
            }
            else{
                ret = -1;
                break;
            }
        }
    }
    
    printf("%d\n", ret);

    return 0;
}


Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
string S = "";


int main() {
	scanf("%lld", &N);
	ll finalAns = 1e18;
	for(int i = 1; i <= sqrt(N); i++) {
		ll ans = 0;
		if(N % i == 0) {
			ans += abs(1 - i);
			ans += abs(1 - (N / i));
			finalAns = min(ans, finalAns);
		}
	}
	printf("%lld\n", finalAns);
	// cin >> S;
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256