akhauriyash/Code-Regression huggingface dataset:
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = 1e5;

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

	vl ans(N);
	for (int i = 0;i < N;++i) {
		ll temp = 0;
		for (int j = 0;j < N;++j) {
			if (i == j) continue;
			temp ^= a[j];
		}

		ans[i] = temp;
		break;
	}

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

	for (auto const& x : ans) {
		cout<<x<<" ";
	}

	cout<<endl;
	return 0;
}


Measured memory_bytes: 6312
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  long int n , m , ans=0 , x ;
  cin>>n>>m;
  for(int i=0 ; i<m;i++){
    cin>>x;
    ans+=x;

  }
  if(ans>n)
    cout<<-1;
    else
    cout<<n-ans;
}



Measured memory_bytes: 3592
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int dish[5];
    for(int i=0; i<5; i++){
        cin >> dish[i];
    }
    int ans=1000000;
    int m=100000;
    for(int a=0; a<5; a++){
        for(int b=0; b<5; b++){
            if(a==b){
                continue;
            }
            for(int c=0; c<5; c++){
                if(a==c || b==c){
                    continue;
                }
                for(int d=0; d<5; d++){
                    if(d==a || d==b || d==c){
                        continue;
                    }
                    for(int e=0; e<5; e++){
                        if(e==a || e==b || e==c || e==d){
                            continue;
                        }
                        int tmp1=dish[a]+(m-dish[a])%10+dish[b];
                        int tmp2=tmp1+(m-tmp1)%10+dish[c];
                        int tmp3=tmp2+(m-tmp2)%10+dish[d];
                        int tmp4=tmp3+(m-tmp3)%10+dish[e];
                        ans=min(ans, tmp4);
                    }
                }
            }
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
=begin
N
L1 ... Ln
=end

n  = gets.chomp.to_i
ls = gets.chomp.split(" ").map(&:to_i)

ls.sort!
max = ls.pop
sum = ls.reduce(0) {|acc, l| acc + l}

if sum > max
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1916
/* 
1e4个a_i, 求最小公倍数乘1/a_i
 */
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
typedef long long ll;
const ll MOD=1e9+7;
inline ll qpow(ll a, ll b) {return b? ((b&1)? a*qpow(a*a%MOD,b>>1)%MOD: qpow(a*a%MOD,b>>1))%MOD: 1;}
inline ll gcd(ll a, ll b) {return b? gcd(b, a%b): a;}
//inline ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
int p[maxn];
void trial_division1(long long n) {//The smallest divisor has to be a prime number.
    for (long long d = 2; d * d <= n; d++)if(n % d == 0) {
        int cnt=0;
        while (n % d == 0) {
            //factorization.push_back(d);
            cnt++;
            n /= d;
        }
        p[d]=max(p[d],cnt);
    }
    if (n > 1)
        //factorization.push_back(n);
        p[n]=max(p[n],1);
    
}

int a[maxn];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
    }
    rep(i,1,n){
       trial_division1(a[i]);        
    }
    ll lcm=1;
    rep(i,1,1000000)if(p[i]){
        lcm*=qpow(i,p[i]);
        lcm%=MOD;
    }
    ll ans=0;
    rep(i,1,n)ans+=qpow(a[i],MOD-2);ans%=MOD;
    debug(lcm);
    rep(i,1,5)debug(p[i]);
    ans=ans*lcm%MOD;
    
    cout<<ans<<endl;
}

Measured memory_bytes: 5120
#include<stdio.h>
int main(){
  int N,x,i,a;
  x=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a);
    if(a%2==0){
      if(a%3!=0 && a%5!=0){
        x=1;
        break;
      }
    }
  }
  if(x==0)
    printf("APPROVED\n");
  else
    printf("DENIED\n");
  return 0;
}

Measured memory_bytes: 128
def main():
    N = int(input())
    A = list(map(int, input().split()))

    m = max(A) + 1
    dp = [0] * m

    for a in sorted(A):
        if dp[a] != 0:
            dp[a] = 2
            continue
        for i in range(a, m, a):
            dp[i] += 1

    print(sum(dp[i] == 1 for i in A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 32200
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	private static final boolean TEST = true;

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			char[] t = in.next().toCharArray();
			Arrays.sort(t);
			s[i] = String.valueOf(t);
		}
		System.out.println(solve(n, s));
		in.close();
	}

	private static long solve(int n, String[] s) {
		long ans = 0;
		Arrays.sort(s);
		int p = 0;
		for (int i = 1; i < n; i++)
			if (!s[p].equals(s[i])) {
				long l = i - p;
				if (l > 1)
					ans += l * (l - 1) / 2;
				p = i;
			}
		long l = n - p;
		if (l > 1)
			ans += l * (l - 1) / 2;
		return ans;
	}
}


Measured memory_bytes: 52256
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a, b] <- getInts
  ; putInts [a*b, 2*(a+b)]
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

Measured memory_bytes: 3660
#include<bits/stdc++.h>
    using namespace std;
   // #define bug printf("bug\n");
   // #define bug2(var) cout<<#var<<" "<<var<<endl;
   // #define co(q) cout<<q<<endl;
  //  #define all(q) (q).begin(),(q).end()
    typedef long long int ll;
    typedef unsigned long long int ull;
    const int MOD = (int)1e9+7;
    const int MAX = 1e6;
   // #define pi acos(-1)
   // #define inf 1000000000000000LL
   // #define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll arr[120];
    ll nCr(ll n, ll r)
    {
        ll C[r+1];
        memset(C, 0, sizeof(C));
        C[0] = 1;
        for (ll i = 1; i <= n; i++)
        {
            for (ll j = min(i, r); j > 0; j--)
                C[j] = (C[j] + C[j-1]);
        }
        return C[r];
    }
    int main()
    {
    	//cout<<nCr(5,2)<<"\\\\\\\\\\\\\\\\\\\\"<<endl;
        ll tot=0;
        long double ans=0,sum=0,cnt=0;
        map<ll,int>N,R;
        int n,a,b;
        cin>>n>>a>>b;
        for(int i=0; i<n; i++){
        	cin>>arr[i];
			N[arr[i]]++;
		}
        sort(arr,arr+n);
        ll last ;
        for(int i=n-1; i>=0; i--)
        {
            sum+=arr[i];
            R[arr[i]]++;
            cnt++;
            if(cnt>b)
                break;
            if(cnt==a)
            {
                last = arr[n-1];
                ans=sum/cnt;
            }
            if(cnt>=a)
            {
                long double cur=(sum/cnt);
                if(cnt==a)
                    {tot+=nCr(N[arr[i]],R[arr[i]]);
                    }
                else if(arr[i]==last)
                {
                 tot+=nCr(N[arr[i]],R[arr[i]]);
                }
            }
        }
        cout<<setprecision(18)<<fixed<<ans<<endl;
        cout<<tot<<endl;
        return 0;
    }

Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    int d, a, pa = 0;
    double x = 0, y = 0;
    while (true){
        scanf("%d,%d", &d, &a);
        if (d == 0 && a == 0) break;
        x += d * sin(pa*M_PI/180);
        y += d * cos(pa*M_PI/180);
        pa += a;
    }
    int ax = x, ay = y;
    printf("%d\n%d\n", ax, ay);
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

string s;

int main()
{
    cin >> s;
    int sz = s.size();
    int ans1 = sz;
    _for(i,0,sz-1){
        if(s[i] != s[i+1]) ans1 = min(ans1,max(sz-(i+1),i+1));
    }

    cout << ans1 << endl;
    return 0;
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a, b, c;
    cin >> a >> b >> c;

    // 処理
    int  i   = 0;
    bool flg = false;
    for (int i = 1; i <= b; i++) {
        if ((a * i) % b == c) {
            flg = true;
            break;
        }
    }
    // 出力
    if (flg) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll f,n;
    string s;
    cin>>f;
    cin>>s;
    n=s.length();
    for(int i=0;i<n;i++)
    {
        int a=s[i]-'A';
        a+=f;
        a=a%26;
        char c='A'+a;
        //char c=('A'+s[i]+f-'A');
        cout<<c;
    }
}
return 0;
}

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

a = [0] * (N + 1)
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for k in range(len(A)):
        a[A[k]] += 1


ans = 0
for i in range(1, N + 1):
    if a[i] == 0:
        ans += 1


print(ans)


Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

static const double eps = 1e-10;
typedef complex<double> point;
struct circle { point p; double r; };
inline double sq(double x) { return x * x; }

pair<point, point> cross(const circle& c1, const circle& c2)
{
    double d = abs(c1.p - c2.p);
    double rc = (sq(d) + sq(c1.r) - sq(c2.r)) / (2*d);
    double rs = sqrt(sq(c1.r) - sq(rc));
    point diff = (c2.p - c1.p) / d;
    return make_pair(c1.p + diff * point(rc, rs),
                     c1.p + diff * point(rc, -rs));
}

bool check_point(const vector<circle>& circles, point p)
{
    return all_of(begin(circles), end(circles),
            [p](const circle& c){ return sq(c.r + eps) > norm(c.p - p); });
}

bool check(const vector<circle>& ropes, double h)
{
    vector<circle> circles;
    for (const auto& c : ropes) {
        double r = sqrt(sq(c.r) - sq(h));
        circles.push_back({ c.p, r });
    }

    for (int i = 0; i < (int)circles.size(); ++i) {
        const circle& c1 = circles[i];
        if (check_point(circles, c1.p))
            return true;

        for (int j = i + 1; j < (int)circles.size(); ++j) {
            const circle& c2 = circles[j];
            double sqd = norm(c1.p - c2.p);
            if (sq(c1.r + c2.r) <= sqd)
                return false;
        }

        for (int j = i + 1; j < (int)circles.size(); ++j) {
            const circle& c2 = circles[j];
            auto cp = cross(c1, c2);
            if (check_point(circles, cp.first))
                return true;
            if (check_point(circles, cp.second))
                return true;
        }
    }

    return false;
}

int main()
{
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n, n) {
        double lo = 0, hi = 1e10;
        vector<circle> ropes;

        for (int i = 0; i < n; ++i) {
            double x, y, r;
            cin >> x >> y >> r;
            ropes.push_back({ point(x, y), r });
            hi = min(hi, r);
        }

        for (int i = 0; i < 100; ++i) {
            double mid = (lo + hi) / 2;
            bool b = check(ropes, mid);
            if (b)
                lo = mid;
            else
                hi = mid;
        }

        cout.precision(15);
        cout << hi << endl;
    }
}

Measured memory_bytes: 1328
def calc2(time,i):
    c1,s1,f1 = Data[i]

    t = max(time,s1)
    if t % f1 == 0:
        pass
    else:
        t = (t//f1+1)*f1
    return t+c1;

def calc(n,N):
    time = 0
    for i in range(n,N-1):
        time = calc2(time,i)
    return time

N = int(input())
Data = []
Ans = []
for _ in range(N-1):
    c,s,f = map(int,input().split())
    Data.append([c,s,f])
for i in range(N-1):
    print(calc(i,N))
print(0)



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int flag=false;
    for(int i=0;i<s.size();i++)
    {
        if(s[2]==s[3]&&s[4]==s[5])
        {
            flag=true;
        }
    }
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

def solve(N, A):
    MOD = 10**9 + 7
    S = [0] * N
    for i in range(N-1)[::-1]:
        S[i] = (S[i+1]+A[i+1]) % MOD

    # N : 2 * 10 ** 5
    # A[i] * A[j] foreach i, j : i < j
    answer = 0
    for i in range(N):
        #print(A[i], S[i])
        answer += (A[i] * S[i]) % MOD

    return answer % MOD

print(solve(N, A))


Measured memory_bytes: 31432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  set<int> st;
  rep(i, n) {
    int a;
    cin >> a;
    st.insert(a);
  }
  cout << (st.size() == n ? "YES" : "NO") << endl;
}

Measured memory_bytes: 9600
n = int(input())
s = list(int(input()) for _ in range(n))
s2 = sorted(list(x for x in s if x % 10 != 0))#10で割ると余りが出る
ss = sum(s)

ans = -1
if ss % 10 != 0:
    ans = ss
else:
    if len(s2) > 0:
        ans = ss - s2[0]
    else:
        ans = 0
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long

int main() {
	ll n;
	cin>>n;
	ll a[n],h[n]={0};
	rep(i,n){
		cin>>a[i];
	}
	ll max = 0,m=0;
	for(ll i=1;i<n;++i){
		if(a[i]>a[i-1]){
			max=0;
		}
		else max++;
		if(max>m){
			m=max;
		}
	}

	// rep(i,n) cout<<h[i]<<endl;
	cout<<m;
}

Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val h = readLine()!!.split(" ").map { it.toInt() }

    val dp = Array(N + 100) { Int.MAX_VALUE }

    dp[0] = 0

    for (i in 0 until N) {
        for (k in 1..K) {
            if (i - k < 0) continue
            val c = dp[i - k] + Math.abs(h[i] - h[i - k])
            if (dp[i] > c) dp[i] = c
        }
    }

    println(dp[N - 1])
}


Measured memory_bytes: 59320
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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;
}

int main(){
  cout << fixed << setprecision(15);
  int n; cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  
  ll ans = 0;
  sort(all(v));
  for (int i = 0; i < n; i++){
    for (int j = 0; j < i; j++){
      if (i == j) continue;
      for (int k = 0; k < j; k++){
        if (i == k || j == k) continue;
        if (v[k] + v[j] > v[i]) ans++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
N,Y = map(int, input().split())
for i in range(Y//10000+1):
    for j in range((Y-10000*i)//5000+1):
        k = N-i-j
        if 10000*i+5000*j+1000*k==Y and k>=0:
            print(i, j, k)
            break
    else: 
        continue
    break
else:
    print(-1,-1,-1)

Measured memory_bytes: 9100
main = do
  li <- getLine
  let [k,x] = map read $ words li
  let ans = compute k x
  putStrLn $ unwords $ map show ans

compute :: Int -> Int -> [Int]
compute k x = [a..b]
  where
    a = max (-1000000) (x-k+1)
    b = min   1000000  (x+k-1)


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

int main(){
	int N,minA = 0,minB,hito;
	int A[100010],B[100010];
	cin >> N;

	for(int i=1;i<=N;++i){
		cin >> A[i] >> B[i];
	}

	for(int j=1;j<=N;++j){
		if(A[j] > minA){
			minA = A[j];
			minB = B[j];
		} 
	}
	hito = minA + minB;
	cout << hito << endl;
}

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

int main (){
	int x,n,a[100005],b[100005];
	long long cnt=0;
	cin>>n;
	for(int i=1;i<=n+1;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<=n;i++){
		x=a[i]+a[i+1];
		if(x<=b[i]){
		    a[i+1]=0;
		    cnt+=x;
		}
		else if(x>b[i]&&b[i]>=a[i]){
			a[i+1]-=b[i]-a[i];
			cnt+=b[i];
		}
		else{
			cnt+=b[i];
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
static const double eps = 1e-5;

#define for(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define rep(i,n) for(i,0,n)

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    int ans=0,t;
    rep(i,n/4){
      cin>>t;
      ans+=t;
    }
    cout<<ans<<endl;
  }
  return 0;
}

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


def solve(N: int):
    cnt = 0
    for i in range(1, N):
        div = math.floor((N-1) / i) - (i-1)
        if div <= 0:
            break
        cnt += 2 * div - 1
    return cnt


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

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))


if __name__ == '__main__':
    main()
    # print(solve(3))


Measured memory_bytes: 9208
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static int[] rsp;
        static void Main(string[] args)
        {
            int[] nk = ReadLine().Split(' ').Select(int.Parse).ToArray();
            rsp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            string s = ReadLine();
            long ans = 0;
            for (int i = 0; i < nk[0]; i++)
            {
                ans += Func(s[i]);
            }
            var sb = new StringBuilder();
            sb.Append(s);
            for (int i = 0; i < nk[0]-nk[1]; i++)
            {
                char target = sb[i + nk[1]];
                if (sb[i] == sb[i+nk[1]])
                {
                    ans -= Func(sb[i]);
                    sb[i + nk[1]] = 'A';
                }
            }
            WriteLine(ans);
        }

        static int Func(char c)
        {
            switch (c)
            {
                case 's':
                    return rsp[0];
                case 'p':
                    return rsp[1];
                case 'r':
                    return rsp[2];
            }
            return 0;
        }
    }
}


Measured memory_bytes: 13664
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    rep(i, n){
        char s;
        cin >> s;
        if(s == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
 int x,y;
  cin >> x >> y;
  int num=0;
  REP(i,x+1){
    num = i *2 + (x-i)*4;
    if(num==y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#141_B
s = input()
flg = True
for i in range(len(s)):
    if i % 2 == 0 and s[i] == 'L':
        flg = False
        break
    if i % 2 == 1 and s[i] == 'R':
        flg = False
        break
print('Yes' if flg else 'No')

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

using namespace std;

//#define PRAGMA 448
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#ifdef LUCARIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif

typedef int intt;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
//#define int long long
#define pb push_back
#define bs binary_search
#define up upper_bound
#define fs first 
#define sd second 
#define mp make_pair    
#define endl "\n"

#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = a - 1; i >= b; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define ing(g,u,v)  g[u].pb(v); g[v].pb(u);
#define ingp(g,u,v,c) (g[u].pb({v,c});g[v].pb({u,c});)
#define mm(a,b) memset(a , b , sizeof a) 
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())
#define sfind(s,t) (s.find(t) != string::npos)

#define infll (ll)1e16
#define infi  (int)(1e9+1)
#define PI 3.14159265359 
#define mod (ll)(1e9+7)
#define eps  1e-6

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int n;
int a[100001];
int dp[100001];

int solve(int i){
    if(i >= n-1 )return 0;
    if(~dp[i])return dp[i];
    int &r = dp[i];


    if(i < n-1)r = abs(a[i]-a[i+1])+solve(i+1);
    if(i < n-2)r = min(r,abs(a[i]-a[i+2])+solve(i+2));

    return r; 
}


int32_t main(int32_t argc, char const *argv[]){
    FIN;
    mm(dp,-1);
    cin>>n;
    fore(i,0,n)cin>>a[i];

    cout<<solve(0);


    return 0;
}



















Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <vector>

int main()
{	
	int n; std::cin >> n;
	int k; std::cin >> k;
	int* T = new int[k];
	for (int i=0; i<k; i++) std::cin >> T[i];
	std::sort(T, T+k);

	for (long long int i=0; i<(1<<(n-k)); i++) {
		long long int index = 0;
		std::vector<int> output;
		long long int d = i;
		for (int j=0, t=0; j<n; j++) {
			if (k>0 && j==T[t]) {
				output.push_back(j);
				index += (1<<j);
				t++;
			}
			else {
				if ( (d&1) == 1 ) {
					output.push_back(j);
					index += (1<<j);
				}
				d >>= 1;
			}
		}
		std::cout << index << ":";
		for (std::vector<int>::iterator it = output.begin(); it != output.end(); ++it) std::cout << " " << *it;
		std::cout << std::endl;
	}
	
	delete[] T;
	
	return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <set>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    
    vector<bool> dp(120);
    dp[0]=true;
    REP(i,n){
        if(dp[i]){
            dp[i+4]=true;
            dp[i+7]=true;
            
        }
        
    }
    if(dp[n]){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
    return 0;
}


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



signed main(){

  int n,m;
  cin>>n>>m;
  vector<int> l(m),r(m);
  for(int i=0;i<m;++i){
    cin>>l[i]>>r[i];
  }
  int ml = *max_element(l.begin(),l.end());
  int mr = *min_element(r.begin(),r.end());
  if(mr<ml){
    cout<<0<<endl;
  }
  else{
    cout<<(mr-ml+1)<<endl;
  }

}

Measured memory_bytes: 1024
use proconio::input;

fn main() {

    input!{
        N:usize,
        mut A:[usize;N]
    }

    let mut ans = 0;
    for i in 0..N-1{
        if A[i]%2 == 1 && A[i+1]>0{
            ans += 1;
            A[i] -= 1;
            A[i+1] -= 1;
        }
        ans += A[i]/2;
    }
    ans += A[N-1]/2;
    println!("{}",ans);
}

Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	int a, b;

	cin >> a >> b;

	printf("%d %d %.10lf\n", a / b, a % b, (double)a / b);

	return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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 dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    VSORT(A);
    A.push_back(A.back());
    vector<ll> sum(N);
    sum[0]=A[0];
    for(int i=1;i<N;i++) sum[i] += sum[i-1] + A[i];
    int cnt=0;
    REP(i,N){
        if(2*sum[i]>=A[i+1]) cnt++;
        else cnt=0;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      final int n = in.nextInt();
      List<Pear> task = new ArrayList<>(n);
      for (int i = 0; i < n; i++) {
        task.add(new Pear(in.nextInt(), in.nextInt()));
      }

      Collections.sort(task);

      boolean isComp = true;
      int time = 0;
      for (Pear p : task) {
        time += p.c;
        if(time > p.l) {
          isComp = false;
          break;
        }
      }

      String ans = isComp ? "Yes" : "No";
      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
  

  private class Pear implements Comparable<Pear>{
    public int c,l;
    Pear(int c, int l) {
      this.c = c;
      this.l = l;
    }

    @Override
    public int compareTo(Pear o) {
      if(o == null) throw new NullPointerException();
      return l == o.l ? 0 : l - o.l;
    }
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 48740
#include <bits/stdc++.h>	
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)
#define int long long
 
// random_device rd; mt19937 g(rd());
 
using namespace std;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5;
 
int n, k;
int a[N];
map <int, int> d;
int pref[N];
int ans;

int Mod(int a)
{
	if(a >= k) a %= k;
	if(a < 0) a += k;
	return a;
}

main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i], pref[i] = pref[i - 1] + a[i];
	for(int i = 1; i <= n; i++) pref[i] -= i, pref[i] = Mod(pref[i]);
	d[0]++;
	for(int r = 1; r <= n; r++) if(r >= k) d[pref[r - k]]--, ans += d[pref[r]]++; else ans += d[pref[r]]++;
	cout << ans;
}    

Measured memory_bytes: 15872
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DStaticSushi solver = new DStaticSushi();
        solver.solve(1, in, out);
        out.close();
    }

    static class DStaticSushi {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            /* INPUT BEGIN */
            int n = in.nextInt();
            long c = in.nextLong();
            long[] x = new long[n];
            long[] v = new long[n];
            for (int i = 0; i < n; i++) {
                x[i] = in.nextLong();
                v[i] = in.nextLong();
            }
            /* INPUT END */

            /* PREPROCESS BEGIN */
            long c2 = c * 2;
            long[] r = new long[n + 1];//CALORIE INCOME(R)
            long[] mrd = new long[n + 1];//MAX  CALORIE(R)
            long[] mrd2 = new long[n + 1];//MAX CALORIE(R, CONSUMPTION DOUBLED)
            long[] l = new long[n + 1];//CALORIE INCOME(L)
            long[] mld = new long[n + 1];//MAX  CALORIE(L)
            long[] mld2 = new long[n + 1];//MAX CALORIE(L, CONSUMPTION DOUBLED)
            for (int i = 1; i <= n; i++) {//LETS CALC:3
                r[i] = r[i - 1] + v[i - 1];
                mrd[i] = Math.max(mrd[i - 1], r[i] - x[i - 1]);
                mrd2[i] = Math.max(mrd2[i - 1], r[i] - (x[i - 1] << 1));
                l[i] = l[i - 1] + v[n - i];
                mld[i] = Math.max(mld[i], l[i] - c + x[n - i]);
                mld2[i] = Math.max(mld2[i], l[i] - c2 + (x[n - i] << 1));
            }
            /* PREPROCESS END */

            /* DEBUG CODE START */
            //System.out.println(Arrays.toString(r));
            //System.out.println(Arrays.toString(mrd));
            //System.out.println(Arrays.toString(mrd2));
            //System.out.println(Arrays.toString(l));
            //System.out.println(Arrays.toString(mld));
            //System.out.println(Arrays.toString(mld2));
            /* DEBUG CODE END */

            long ans = 0;
            /* WE WANT TO MAXIMIZE mrd[i] + mld[n - i] */
            for (int i = 0; i <= n; i++) {
                ans = Math.max(ans, mrd[i] + mld2[n - i]);
                ans = Math.max(ans, mrd2[i] + mld[n - i]);
            }
            out.println(ans);/* OUTPUT */
        }

    }
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

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

int main() {
  int n;
  cin>>n;
  int exr = 0;
  map<pair<ll, ll>, pair<int, int>> sar;
  rep(i, n) {
    ll a,b;
    cin>>a>>b;
    if (a == 0 && b == 0) exr++;
    else {
      ll g = gcd(a,b);
      a /= g;
      b /= g;
      if (b < 0 || (b == 0 && a < 0)) {
        a *= -1;
        b *= -1;
      }
      if (a <= 0) {
        ll t = a;
        a = b;
        b = -t;
        sar[make_pair(a,b)].first++;
      } else {
        sar[make_pair(a,b)].second++;
      }
    }
  }
  ll ans = 1;
  for(auto x : sar) {
    ll a = x.second.first;
    ll b = x.second.second;
    ans *= (MOD + 1 + modpow(2, a) - 1 + modpow(2, b) - 1) % MOD;
    ans %= MOD;
  }
  ans = (MOD + ans - 1 + exr) % MOD;
  cout << ans;
}



Measured memory_bytes: 15968
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String A = sc.next();
        String B = sc.next();
        int la = A.length();
        int lb = B.length();

        if(la>lb){
            System.out.println("GREATER");
        }
        else if(la<lb){
            System.out.println("LESS");
        }
        else if(la==lb){
            if(A.equals(B)){
                System.out.println("EQUAL");
            }
            else{
                for(int i=0; i<la; i++){
                    if(A.charAt(i)>B.charAt(i)){
                        System.out.println("GREATER");
                        break;
                    }
                    if(A.charAt(i)<B.charAt(i)){
                        System.out.println("LESS");
                        break;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 22868
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define max(x) *max_element(all(x))
#define min(x) *min_element(all(x))

using namespace std;

ll fac[MAX], finv[MAX], inv[MAX];

//二項係数の計算
void comint()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; ++i)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll com(ll n, ll k)
{
    if (n > k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//Nが素数か判定する
bool is_prime(ll N)
{
    for (ll i = 2; i * i < N; ++i)
    {
        if (N % i == 0)
            return false;
    }
    return true;
}

//Nを素因数分解した結果のリストを返す
vector<ll> soinsubunkai(long long N)
{
    vector<ll> tmp;
    ll num = N;
    for (ll i = 2; i * i <= N; ++i)
    {
        if (N % i == 0)
        {
            ll j = N / i;
            if (is_prime(i))
            {
                while (num % i == 0)
                {
                    tmp.push_back(i);
                    num /= i;
                }
            }
            if (is_prime(j))
            {
                while (num % j == 0)
                {
                    tmp.push_back(j);
                    num /= j;
                }
            }
        }
    }
    return tmp;
}

//法mにおけるaの逆元を返す
ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

//法mにおけるa^bの値を返す
ll modpow(ll a, ll n, ll m)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<vector<char>> vec(N, vector<char>(N));
    rep(i, N)
    {
        rep(j, N) cin >> vec[i][j];
    }
    ll ans = 0;
    rep(a, N)
    {
        vector<vector<char>> tmp(N, vector<char>(N));
        rep(b, N)
        {
            rep(c, N)
                tmp[b][c] = vec[(a + b) % N][c];
        }
        ll counta = 0;
        for (ll i = 0; i < N; ++i)
        {
            for (ll j = i + 1; j < N; ++j)
            {
                if (tmp[j][i] == tmp[i][j])
                    counta++;
            }
        }
        if (counta == (N * (N - 1) / 2))
            ans++;
    }
    cout << ans * N << endl;
}


Measured memory_bytes: 512
def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def f(x):
    N = 2
    while 1:
        A = N * (N + 1) / 2
        if x < A:
            return N - 1
        N += 1

N = int(input())

div = pf(N)
exp = []

begin =-1
for i in range(len(div)):
    A = div[i]

    if i == len(div) - 1:
        exp.append(i - begin)
        break

    if div[i + 1] != A:
        exp.append(i - begin)
        begin = i

ans = 0

for i in exp:
    ans += f(i)

print(ans)


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

long long N,M;
long long ans;
int main(){
	while(cin>>N>>M){
		
	if(M>N) swap(N,M); //N>M
	if(M==1){
		if(N==1)
			cout<<1<<endl;
		else
			cout<<N-2<<endl;
	}
	else if(M==2){
		cout<<0<<endl;
	}
	else{
		ans=(N-2)*(M-2);
		cout<<ans<<endl;
	}
	break;
}
	return 0;
}

Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, X = sc.nextInt()
    val L = Array.fill(N)(sc.nextInt())
    var D = 0L
    var i = 0
    while (D <= X && i < N) {
      D += L(i)
      if (D <= X) {
        i += 1
      }
    }
    println(i+1)
  }

}

Measured memory_bytes: 27076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var sides = Console.ReadLine()
                .Split(' ')
                .Select(int.Parse);

            var sortedSides = sides.OrderBy(side => side);

            // 実装1（愚直に。遅いと思ったらこっちのほうが速かった。）
            if (sortedSides.Last() < sortedSides.Sum() - sortedSides.Last())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            // 実装2（こっちのほうが効率がいいかも？実際はこっちのほうが遅かった。範囲を足し合わせる処理があるから？）
            //if (sortedSides.Last() < sortedSides.Take(sortedSides.Count() - 1).Sum())
            //{
            //    Console.WriteLine("Yes");
            //}
            //else
            //{
            //    Console.WriteLine("No");
            //}
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define inf (int)(3e18)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}


signed main() {
	string s;cin>>s;
	rep(i,s.size()){
		if(s[i]!=s[s.size()-1-i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	int N=s.size();
	string t=s.substr(0,(N-1)/2);
	string u=s.substr((N+3)/2-1);
	rep(i,t.size()){
		if(t[i]!=t[t.size()-1-i]){
			cout<<"No"<<endl;return 0;
		}
	}
	rep(i,u.size()){
		if(u[i]!=u[u.size()-1-i]){
			cout<<"No"<<endl;return 0;
		}
	}
	cout<<"Yes"<<endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

vector<int> solve(int N){
    vector<int> res(100,0);
    for(int i = 1; i < N+1; i++){
        int now = i;
        for(int j = 2; j < N+1; j++){
            if(now % j != 0) continue;
            int cnt = 0;
            while(now % j == 0){
                cnt++;
                now /= j;
            }
            res[j] += cnt;
        }
        if(now != 1) res[now] += 1;
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    vector<int> res(100);
    res = solve(N);
    int ans = 0;
    int cnt_25 = 0;
    int cnt_15 = 0;
    int cnt_5 = 0;
    int cnt_3 = 0;
    rep(i,100){
        if(res[i] >= 74) ans++;
        if(res[i] >= 24){
            cnt_25++;
            cnt_15++;
            cnt_5++;
            cnt_3++;
        }
        else if(res[i] >= 14){
            cnt_15++;
            cnt_5++;
            cnt_3++;
        }
        else if(res[i] >= 4){
            cnt_5++;
            cnt_3++;
        }
        else if(res[i] >= 2) cnt_3++;
    }
    ans += cnt_25*(cnt_3-1);
    ans += cnt_15*(cnt_5-1);
    ans += cnt_5*(cnt_5-1)/2*(cnt_3-2);
    cout << ans << endl;
}

Measured memory_bytes: 3592