akhauriyash/Code-Regression huggingface dataset:
/* ***********************************************
Author        :yang12138
Created Time  :2017年12月11日 星期一 12时38分04秒
File Name     :C.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=2e5+10;

map<int,int>mp;
int cnt[N];

void solve(){
	int n,k;
	scanf("%d%d",&n,&k);
	int tot=0;
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(mp.count(x)) cnt[mp[x]]++;
		else cnt[++tot]=1,mp[x]=tot;
	}
	sort(cnt+1,cnt+tot+1);
	int ans=0;
	for(int i=1;i<=tot-k;i++) ans+=cnt[i];
	printf("%d\n",ans);
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	solve();
    
    return 0;
}


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

using namespace std;

int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
int seen[4][2000][2000];

int straight(vector<string> &v,int h,int w,int k,int y,int x){
  if(y < 0 || y >= h || x < 0 || x >= w)return 0;
  if(v[y][x] == '#')return 0;
  if(seen[k][y][x] != -1)return seen[k][y][x];
  int res = straight(v,h,w,k,y+dy[k],x+dx[k]) + 1;
  return seen[k][y][x] = res;
}

int search(vector<string> &v,int h,int w,int y,int x){
  if(v[y][x] == '#')return 0;
  int res = 0;
  res += straight(v,h,w,0,y,x);
  res += straight(v,h,w,1,y,x);
  res += straight(v,h,w,2,y,x);
  res += straight(v,h,w,3,y,x);
  return res-3;
}

int main(){
  int h,w,res = -1;
  cin >> h >> w;
  vector<string> v(h);
  for(int y = 0;y < h;y++)cin >> v[y];
  memset(seen,-1,sizeof(seen));
  for(int y = 0;y < h;y++){
    for(int x = 0;x < w;x++){
      res = max(search(v,h,w,y,x),res);
    }
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 67072
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	int n;
  	cin >> n;
  int dp[101];
 	memset(dp, 0, sizeof(dp));
  dp[4] = dp[7] = 1;
  for (int i = 8; i < n+1; i++){
  	dp[i] = max(dp[i-4],dp[i-7]);
  }
	(dp[n] == 1)? cout <<"Yes" <<'\n' : cout <<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one
}


int main() {

    int h, w;
    cin >> h >> w;
    vector<vector<char>> field = inpn<char>(h, w);

    vector<vector<int>> ans(h, vector<int>(w, -1));

    rep(i, h) {
        int prev = -1;
        rep(j, w) {
            if (field[i][j] == 'c') prev = j;
            if (prev == -1) continue;
            ans[i][j] = j - prev;
        }
    }

    rep(i, h) {
        rep(j, w) {
            cout << ans[i][j];
            if (j != w - 1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}


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

using namespace std;

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

typedef long long ll;
vector<bool> flag(100005,false);
vector<ll> d(100005,0);


void dfs(vector<vector<pair<ll,ll>>> &g, ll v){
 flag[v]=true;
 for(auto next_v:g[v]){
  if(flag[next_v.first]) continue;
   d[next_v.first]=d[v]+next_v.second;
  dfs(g,next_v.first);
}
}


int main(){
 ll n;
  cin >> n;
 vector<vector<pair<ll,ll>>> G(n);
  rep(i,0,n-1){
   ll u,v,w;
   cin >> u >> v >> w;
    u--;
    v--;
   G[u].push_back(make_pair(v,w));
   G[v].push_back(make_pair(u,w));
  }
  
  dfs(G,0);
  
  rep(i,0,n) {
    if(d[i]%2) cout << 1 << endl;
    else cout << 0 << endl;
  }
}


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

int main() {
  int x;
  cin >> x;
  if (x >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int MAX_N=262144;
vector<int64_t> seg(MAX_N*2-1);
int64_t qu(int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return 0;
  }
  else if(a<=l&&r<=b){
    return seg[k];
  }
  else{
    int64_t X=qu(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu(a,b,k*2+2,(l+r)/2,r);
    return X+Y;
  }
}
void pu(int64_t a,int b){
  int D=MAX_N-1+b;
  while(D>0){
    seg[D]+=a;
    D--;
    D/=2;
  }
  seg[0]+=a;
}

vector<int64_t> kazu(MAX_N*2-1);
int64_t cou(int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return 0;
  }
  else if(a<=l&&r<=b){
    return kazu[k];
  }
  else{
    int64_t X=cou(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=cou(a,b,k*2+2,(l+r)/2,r);
    return X+Y;
  }
}
void pu1(int64_t a,int b){
  int D=MAX_N-1+b;
  while(D>0){
    kazu[D]+=a;
    D--;
    D/=2;
  }
  kazu[0]+=a;
}
int64_t I=167167167167;

int main() {
  int Q,N=0;
  cin>>Q;
  vector<tuple<int64_t,int64_t,int64_t>> p(Q);
  vector<tuple<int64_t,int64_t,int64_t>> q;
  for(int64_t i=0;i<Q;i++){
    int64_t a;
    cin>>a;
    if(a==2){
      p[i]=make_tuple(I,I,I);
    }
    else{
      int64_t b,c;
      cin>>b>>c;
      q.push_back(make_tuple(b,i,c));
      N++;
    }
  }
  sort(q.begin(),q.end());
  for(int64_t i=0;i<N;i++){
    int64_t a,b,c;
    tie(a,b,c)=q[i];
    p[b]=make_tuple(a,i,c);
  }
  int64_t Z=0,X=0;
  for(int i=0;i<Q;i++){
    int64_t a,b,c;
    tie(a,b,c)=p[i];
    if(a!=I){
      Z+=c;
      pu1(1,b);
      pu(a,b);
      X++;
    }
    else{
      int64_t r=-1,l=Q;
      int64_t Y=(X+1)/2;
      while(l-r>1){
        int64_t D=(r+l)/2;
        if(Y<=cou(0,D+1,0,0,MAX_N)){
          l=D;
        }
        else{
          r=D;
        }
      }
      cout<<seg[l+MAX_N-1]<<" ";
      if(X%2==0){
        cout<<Z-qu(0,l+1,0,0,MAX_N)+qu(l+1,Q,0,0,MAX_N)<<endl;
      }
      else{
        cout<<Z-qu(0,l+1,0,0,MAX_N)+qu(l,Q,0,0,MAX_N)<<endl;
      }
    }
  }
}

Measured memory_bytes: 22376
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int INF = 1 << 30;
int dp[401][401];

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

    int N;
    while (cin >> N) {
        int ma, mb;
        cin >> ma >> mb;
        rep(i, 401)rep(j, 401)dp[i][j] = INF;
        dp[0][0] = 0;
        rep(ii, N) {
            int a, b, c;
            cin >> a >> b >> c;
            for (int i = 400; i >= 0; --i)for (int j = 400; j >= 0; --j)if (dp[i][j] != INF) {
                smin(dp[i + a][j + b], dp[i][j] + c);
            }
        }
        int ans = INF;
        int a = ma, b = mb;
        while (a < 401 && b < 401) {
            smin(ans, dp[a][b]);
            a += ma;
            b += mb;
        }
        if (ans == INF)ans = -1;
        cout << ans << endl;
    }
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int main()
{
    char s[1205];
    fgets(s, 1205,stdin);
    int ls=strlen(s)-1;
    s[ls]='\0';
    for (int i = 0; i < ls; ++i)
    {
        if (islower(s[i]))
            s[i] = toupper(s[i]);
        else if (isupper(s[i]))
            s[i] = tolower(s[i]);
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>

using namespace std;

int gcd(int n, int m) {
    if (n == 0) return m;
    return gcd(m % n, n);
}

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

    int max_l, min_r;
    cin >> max_l >> min_r;

    for (int i = 0; i < M-1; ++i) {
        int l, r;
        cin >> l >> r;
        if (l > max_l) max_l = l;
        if (r < min_r) min_r = r;
    }

    if (min_r - max_l + 1 > 0) {
        cout << min_r - max_l + 1 << endl;
    } else {
        cout << 0 << endl;
    }
}


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

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

bool isprime[60020];
//エラトステネス
void eratos(int m){
    for (int i = 0; i <= m; ++i) isprime[i] = true;
    isprime[0] = isprime[1] = false;
    //iを残してiの倍数を消していく
    for (int i = 2; i <= m; ++i){
        if(isprime[i]){
            for (int j = 2 * i; j <= m; j += i){
                isprime[j] = false;
            }
        }
    }
}

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

	eratos(60010);
	vector<int> ans;
	rep(i, 60001) {
		if (isprime[i] && i % 5 == 1) ans.push_back(i);
		if (ans.size() == n) break;
	}
	for(auto u : ans) printf("%d ", u);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

int main() {
  int n,k;
  cin>>n>>k;
  vector<ll> h(n);
  rep(i,n) cin>>h[i];
  sort(all(h));
  int hd=h[n-1]-h[0];
rep(i,n-k+1){
    if(h[i+k-1]-h[i]<hd){
      hd=h[i+k-1]-h[i];
    }
}
  cout<<hd<<endl;
return 0;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    println(problem103b(s, t))
}

fun problem103b(s: String, t: String): String {
    val s = s.toMutableList()
    val t = t.toList()
    var count = 0
    while (s != t) {
        s.add(0, s[s.size - 1])
        s.removeAt(s.size - 1)
        count++
        if (count > s.size) return "No"
    }
    return "Yes"
}

Measured memory_bytes: 31136
#include<bits/stdc++.h>
#define maxn ((int)1e5+10)
using namespace std;
int n,k,ans=maxn;
vector<int> v;
int a[maxn];
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
	{
		int tmp=0,strong=k-1,left=a[i],right=n-a[i]-1;
		tmp+=left/strong;
		if(left%strong)
			++tmp;
		tmp+=right/strong;
		if(right%strong)
			++tmp;
		ans=min(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int n;
  cin >> n;
  bool ok = false;
  for (int i = 0; i * 4 <= n; ++i) {
    int rest = n - i * 4;
    if (rest % 7 == 0) {
      ok = true;
      break;
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

int main()
{
    int n;
    cin >> n;
    int ans = ceil(n / 1.08);
    if ((int)(ans * 1.08) == n) {
        cout << ans << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint h,w;std::cin>>h>>w;
    std::vector<std::vector<lint>>g(h+2,std::vector<lint>(w+2));
    for(lint i=1;i<=h;i++){
        for(lint j=1;j<=w;j++){
            char c;std::cin>>c;
            g.at(i).at(j)=c=='#';
        }
    }
    for(lint i=1;i<=h;i++){
        for(lint j=1;j<=w;j++){
            if(g.at(i).at(j)
                &&!g.at(i-1).at(j)
                &&!g.at(i+1).at(j)
                &&!g.at(i).at(j-1)
                &&!g.at(i).at(j+1))
            {
                std::cout<<"No"<<'\n';
                return 0;
            }
        }
    }
    std::cout<<"Yes"<<'\n';
}



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

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

    rep(i,n){
        cin >> a[i];
    }

    int ans = inf;

rep(i,n){
    int x=a[i];
    int cunt=0;
    while(x%2!=1){
       x=x/2;
        cunt++;
    }
    ans=min(ans,cunt);
}

cout << ans << endl;

}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

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

    if (a <= b)
        cout << a << endl;
    else
        cout << a - 1 << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

const int mod = 1e9 + 7;

double dp[305][305][305];

int n;
int ile[4];

double rob(int a, int b, int c) {
	if (a < 0 || b < 0 || c < 0) return 0;
	if (dp[a][b][c] != -1) return dp[a][b][c];
	
	dp[a][b][c] = n*1./(a+b+c) + 
								a*1./(a+b+c) * rob(a-1,b,c) + 
								b*1./(a+b+c) * rob(a+1,b-1,c) + 
								c*1./(a+b+c) * rob(a,b+1,c-1); 
	
	return dp[a][b][c];
}

int main () {
	read(n);
	FOR(i,0,n+1) FOR(j,0,n+1) FOR(k,0,n+1) dp[i][j][k] = -1;
	dp[0][0][0] = 0;
	FOR(i,0,n) {
		make(a); ile[a]++;
	}
	printf("%.17lf\n", rob(ile[1], ile[2], ile[3]));
}	





Measured memory_bytes: 219392
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mk make_pair


int main()
{
  ll a,sum=0;
  cin>>a;
  ll c[a];
  unordered_map<ll,ll> mp;
  for(ll i=0;i<a;i++)
  {
    cin>>c[i];
    mp[c[i]]++;
    sum+=c[i];
  }
  ll b;
  cin>>b;
  while(b--)
  {
    ll d,e;
    cin>>d>>e;
    sum-=(d*(mp[d]));
    sum+=(e*(mp[d]));
    mp[e]+=mp[d];
    mp[d]=0;
    cout<<sum<<endl;
  }
}


Measured memory_bytes: 7816
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力
static long long slCnt;											// 個数
static long long slM;											// 積

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 最大公約数 - 取得
long long
fGetGCD(
)
{
	int i, j;

	// １つのみ
	if (slCnt == 1) {
		return slM;
	}

	// int以上
	if (slCnt > INT_MAX) {
		return 1;
	}

	// 上限
	int liLimit = (int)sqrt((double)slM);

	// 素因数分解・GCD - 取得
	long long llGCD = 1;
	for (i = 2; i <= liLimit; i++) {
		int liCnt = 0;
		while (slM % i == 0) {
			slM /= i;
			liCnt++;
		}

		// GCD
		liCnt /= (int)slCnt;
		for (j = 0; j < liCnt; j++) {
			llGCD *= i;
		}
	}

	return llGCD;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 個数・積 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld%lld", &slCnt, &slM);

	// 最大公約数 - 取得
	long long llGCD = fGetGCD();

	// 結果 - セット
	sprintf(lc1Out, "%lld\n", llGCD);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int a,b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
}

Measured memory_bytes: 256
import math
A,B,H,M=map(int,input().split())
a=30*H+M/2
b=6*M
c=abs(a-b)
c=min(c,360-c)
ans=A**2+B**2-2*A*B*math.cos(math.radians(c))
ans=math.sqrt(ans)
print(ans)

Measured memory_bytes: 9456
# coding: utf-8
# Your code here!

r, c = map(int, input().split())
# r, c = map(int, '4 5'.split())
arr = []
col_t = [0]*(c)

for _ in range(r):
    arr.append(list(map(int, input().split())))

for row in range(r):
    row_t = 0
    for col in range(c):
        row_t += arr[row][col]
        col_t[col] += arr[row][col]
    arr[row].append(row_t)

total = 0
for v in col_t:
    total += v
col_t.append(total)
arr.append(col_t)

for v in arr:
    print(' '.join(map(str, v)))



Measured memory_bytes: 5704
def findProductSum(A, n):

    array_sum = 0
    for i in range(0, n, 1):
        array_sum = array_sum + A[i]

    # calcualting square of array sum
    # (a1 + a2 + ... + an)^2
    array_sum_square = array_sum * array_sum

    # calcualting a1^2 + a2^2 + ... + an^2
    individual_square_sum = 0
    for i in range(0, n, 1):
        individual_square_sum += A[i] * A[i]


    return (array_sum_square - individual_square_sum) // 2


def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    # n = len(A)
    mod = (10**9) + 7
    print(int(findProductSum(A, n))%mod)

main()



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

int main() {
    ll n;cin >> n;
    n--;
    const char a = 'a';
    vector<char> name;
    while(n >= 0){
        name.push_back(a + n % 26);
        n = n / 26 - 1;
    }
    reverse(name.begin(), name.end());
    for(auto n :name)cout << n;
    cout << endl;
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001
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; }

int gcd(int a, int b) {
    if(a < b) swap(a, b);
    if (b==0) return a;
    return gcd(b, a%b);
}

int main() {
    int n;
    int h[MAXN];

    cin >> n;
    ll cost[MAXN];
    for(int i=0; i<n; i++) {
        cin >> h[i];
        cost[i] = ll(INF);
    }

    cost[0] = 0;
    cost[1] = abs(h[1] - h[0]);

    for(int i=2; i<n; i++) {
        chmin(cost[i], cost[i-1]+abs(h[i]-h[i-1]));
        chmin(cost[i], cost[i-2]+abs(h[i]-h[i-2])); 
//        cout << cost[i] << endl;
    }

    cout << cost[n-1] << endl;

    
}



Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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

int N,Ma,Mb,dp[50][500][500];

int main(){
    cin>>N>>Ma>>Mb;
    int a[N],b[N],c[N];
    rep(i,50){
        rep(j,500){
            rep(k,500){
                dp[i][j][k]=10000;
            }
        }
    }
    dp[0][0][0]=0;
    rep(i,N){
        cin>>a[i]>>b[i]>>c[i];
    }
    rep(i,N){
        rep(k,500){
            rep(j,500){
                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
                dp[i+1][a[i]+j][b[i]+k] = min(dp[i][j][k] + c[i], dp[i][a[i]+j][b[i]+k]);
            }
        }
    }

    int ans=10000000;
    repi(i,1,500)ans=min(dp[N][Ma*i][Mb*i],ans);
    if(ans<10000)out(ans);
    else out(-1);
    
    
}

Measured memory_bytes: 49024
#include <bits/stdc++.h>
#define MAXS 10007
#define INF 2147483647

#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define BZ freopen("input.txt", "r", stdin)
#define BX freopen("out.txt", "w", stdout)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n;
ll lista[MAXS];
int how[MAXS];

int main(){
  cin >> n;
  for(int i = 0 ;i < n; ++i){
    cin >> lista[i];
  }
  sort(lista, lista+n);
  int ans = 0;
  for(int i = 0; i < n; ++i){
    while(lista[i] % 2 == 0 && lista[i] > 0){
      lista[i] /= 2;
      how[i]++;
    }
		ans += how[i];
  }
  
  cout << ans;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = (int)2e5 + 77;
const int A    = 26;

string str;
int n, last[A];
int go[MAXN][A];
int dp[MAXN];

void solve() {
	cin >> str;
	n = len(str);
	
	for(int i = 0; i < A; ++i) {
		last[i] = n + 1;
	}

	for(int i = n; i >= 0; --i) {
		for(int code = 0; code < A; ++code) {
			go[i][code] = last[code];
		}

		if(i > 0) {
			last[str[i - 1] - 'a'] = i;
		}
	}

	for(int i = n; i >= 0; --i) {
		dp[i] = INT_INF;

		for(int code = 0; code < A; ++code) {
			dp[i] = min(dp[i], dp[go[i][code]] + 1);
		}
	}

	string answ;
	int cur = 0;

	while(cur <= n) {
		for(int code = 0; code < A; ++code) {
			if(dp[cur] == dp[go[cur][code]] + 1) {
				answ.push_back('a' + code);
				cur = go[cur][code];
				break;
			}
		}
	}

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 21652
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
#MOD = 10 ** 9 + 7
MOD = 998244353
def main():
    N = int(readline())
    D = list(map(int, readline().split()))
    if D[0]!=0:
        print(0)
        exit()
    node = [0]*(max(D)+1)
    for i in range(N):
        node[D[i]] += 1
    if node[0]>1:
        print(0)
        exit()
    ans = 1
    for i in range(len(node)-1):
        ans *= node[i]**node[i+1]
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12404
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for j in range(n):
    i=n-j-1
    #print("元の数")
    #print(i+1)
    sum=a[i]
    for k in range(2,n+1):
        if((i+1)*k>n):
            break
        #print(i*k+k)
        sum=sum^ans[i*k+k-1]
    ans[i]=sum

#print(ans)

kazu=0
for i in range(n):
    if(ans[i]==1):
        kazu+=1
print(kazu)
for i in range(n):
    if(ans[i]==1):
        print(i+1)

Measured memory_bytes: 7148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<complex>
using namespace std;
typedef long long LL;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
const int N=1000005;
int n,father[N],m,dist[N];
inline int getfather(int x){
	if(father[x]==x)return x;
	int t=getfather(father[x]);
	dist[x]+=dist[father[x]];
	return father[x]=t;
}
int main(){
	n=read(); m=read();
	for(int i=1;i<=n;i++)father[i]=i;
	for(int i=1;i<=m;i++){
		int l=read(),r=read(),d=read();
		int t1=getfather(l),t2=getfather(r);
		if(t1!=t2){
			dist[t2]=d-dist[r]+dist[l];
			father[t2]=t1;
		}else{
			if(dist[r]-dist[l]!=d){
				puts("No"); return 0;
			}
		}
	}
	puts("Yes");
}



Measured memory_bytes: 4864
use proconio::input;

fn main() {
  input! {
    n: usize,
    a: [isize; n],
  };
  let cond = |n| (n % 2 == 1 || (n % 3 == 0 || n % 5 == 0));
  if a.iter().map(cond).fold(true, |sum,a| sum & a) { 
    println!("APPROVED");
  } else {
    println!("DENIED");
  }
}


Measured memory_bytes: 2116
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int a,b,c,d=0;
	cin>>a>>b;
	for(int i=1;i<=b;i++){
		cin>>c;
		d+=c;
	}
	if(d<a) cout<<"No";
	else cout<<"Yes";
	return 0; 
 } 

Measured memory_bytes: 3568
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();

        for (int i=0;i<s.length();i++){
            System.out.print((char) ((s.charAt(i)-'A'+ n)%26 + 'A'));
        }
    }
}

Measured memory_bytes: 25044
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <set>

using namespace std;

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

	int N;
	cin >> N;

	set<string> count;

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

		count.insert(s);
	}

	cout << count.size();

	return 0;
}


Measured memory_bytes: 19200
import java.util.*

fun main(args: Array<String>){

    var (K,T) = readLine()!!.split(" ").map{it.toInt()}
    var a = readLine()!!.split(" ").map{it.toInt()}
    var max = 0
    for(i in a.indices){
        max = Math.max(a[i],max)
    }

    if(max > K/2){
        println(max- (K-max) -1)
    } else {
        println("0")

    }

}


Measured memory_bytes: 37484
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define sz(x) (int)(x.size())
#define pb push_back
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (long long)(1e9) + 123;
const int mod = 1000000007;
const double eps = 1e-9;


double getDist(int x, int y, int x1, int y1) {
    return sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
}

vector <pair <int, int>> v;

signed main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    int fact = 0;
    double sum = 0;
    for(int i = 1; i <= n; ++i) {
        int x, y; cin >> x >> y;
        v.pb({x, y});
    }
    sort(all(v));
    do {
        for(int i = 1; i < sz(v); ++i) {
            sum += getDist(v[i].first, v[i].second, v[i - 1].first, v[i - 1].second);
        }
        fact++;
    }while (next_permutation(all(v)));
    cout << setprecision(6) << fixed << sum / fact;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int num[100010];
vector<int> v[100010];
int mnum[100010];

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> X(N);
  for(int i=0;i<N;i++) cin>>X[i];

  for(int i=0;i<N;i++){
      num[X[i]]++;
  }

  for(int i=1;i<=100000;i++){
      if(num[i]==0) continue;
      if(num[i]%2){
          mnum[i%M]++;
          num[i]--;
      }
      v[i%M].push_back(num[i]);
  }

  int ans=0;
  ans=mnum[0]/2;
  mnum[0]%=2;
  for(int i=1;i<M;i++){
      if(M-i<i) break;
      else if(M-i==i){
          ans+=mnum[i]/2;
          mnum[i]%=2;
          continue;
      }
      int mi=min(mnum[i],mnum[M-i]);
      ans+=mi;
      mnum[i]-=mi;
      mnum[M-i]-=mi;
  }

  for(int i=1;i<M;i++){
      if(mnum[i]==0) continue;
      for(int j=0;j<v[M-i].size();j++){
          if(mnum[i]<=1) break;

          int mi=min(mnum[i]/2,v[M-i][j]/2);
          ans+=mi*2;
          mnum[i]-=mi*2;
          v[M-i][j]-=mi*2;
      }
  }

  for(int i=0;i<M;i++){
      for(int j=0;j<v[i].size();j++){
          ans+=v[i][j]/2;
      }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 6912
S = input()
flag = True

if S[0] != "A":
  flag = False
elif S[2:-1].count("C") != 1:
  flag = False
else:
  tmp = ""
  for s in S:
    if s != "A" and s != "C":
      tmp += s
  if not tmp.islower() or len(tmp) != len(S) - 2:
    flag = False
print("AC" if flag else "WA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, m, c; cin >> n >> m >> c;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> b(m);
    rep(i,m) cin >> b[i];
    rep(i,n)rep(j,m) cin >> a[i][j];
    int ans = 0;
    rep(i,n){
        int tmp = 0;
        rep(j,m){
            tmp += a[i][j] * b[j];
        }
        tmp += c;
        if(tmp > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

namespace _02_ABC081A
{
    class Program
    {
        static void Main(string[] args)
        {

            string s= Console.ReadLine(); ;

            int counter = 0;

            if (s[0] == '1') { counter++; }
            if (s[1] == '1') { counter++; }
            if (s[2] == '1') { counter++; }

            Console.WriteLine(counter);

            Console.Read();
                

        }
    }
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;

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

void Main()
{
    int n,d;
    cin >> n >> d;
	d = d*2+1;
	if(n%d == 0){
		cout << n/d << endl;
	}
	else{
		cout << n/d + 1 << endl;
	}

	return;
}

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

Measured memory_bytes: 256
a = 2, 3, 5
 
def f(n):
  m = memo.get(n)
  if m is None:
    m = d * n
    for p, c in zip(a, b):
      k, r = divmod(n, p);
      m = min(m, f(k) + r * d + c, f(k + 1) + (p - r) * d + c if r else m)
    memo[n] = m
  return m
 
t = int(input())
for _ in range(t):
  n, *b, d = map(int, input().split())
  memo = {0: 0, 1: d}
  print(f(n))


Measured memory_bytes: 10900
(* Vicfred
 * https://atcoder.jp/contests/abc140/tasks/abc140_b
 * implementation
 * *)

let f () = Scanf.scanf " %d" ( + ) 0
let n = f ()
let a = Array.init n @@ fun _ -> f ()
let b = Array.init n @@ fun _ -> f ()
let c = Array.init (n - 1) @@ fun _ -> f ()
let ans = ref @@ Array.fold_left ( + ) 0 b
let main =
    for i = 0 to (n - 2) do
        if a.(i + 1) = a.(i) + 1 then ans := !ans + c.(a.(i) - 1)
    done;
    Printf.printf "%d\n" !ans



Measured memory_bytes: 3800
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

int main(){
    int n,m ;
    cin >> n >> m ;
    vector<pair<pair<int,int>,int> > c(m,pair<pair<int,int>,int>()) ;
    for (size_t i = 0; i < m; i++)
    {
        cin >> c.at(i).first.first >> c.at(i).first.second ;
        c.at(i).second = i ;
    }
    sort(c.begin(), c.end()) ;
    map<int,string> id;
    string s,t,u ;
    int j = 1 ;
    for (size_t i = 0; i < m; i++)
    {
        if (i > 0)
        {
            if (c.at(i-1).first.first != c.at(i).first.first)
            {
                j = 1 ;
            }
            
        }
        
        t = to_string(c.at(i).first.first) ;
        while (t.size()<6)
        {
            t = '0' + t ;
        }
        u = to_string(j) ;
        while (u.size() < 6)
        {
            u = '0' + u ;
        }
        s = t + u ;
        id[c.at(i).second] = s ;
        j ++ ;
    }
    for (size_t i = 0; i < m; i++)
    {
        cout << id[i] << endl ;
    }
    
}

Measured memory_bytes: 13696
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().run();
        return 0;
    }

    void run()
    {
        Scanner cin = new Scanner();

        int n = cin.nextInt();

        int[] up = new int[n];
        int[] down = new int[n];

        for (int i = 0; i < n; i++)
        {
            up[i] = cin.nextInt();
            down[i] = cin.nextInt();
        }

        int[,] dp = new int[n, n];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                dp[i, j] = 999999999;
            }
        }

        for (int i = 0; i < n; i++)
        {
            dp[i, i] = 0;
        }

        for (int i = n - 1; i >= 0; i--)
        {
            for (int j = i; j < n; j++)
            {
                for (int k = i; k < j; k++)
                {
                    dp[i, j] = Math.Min(dp[i,j], dp[i, k] + dp[k + 1, j] + up[i] * down[k] * up[k + 1] * down[j]);
                }
            }
        }
        Console.WriteLine(dp[0, n - 1]);

    }

}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

}

Measured memory_bytes: 5656
#include<stdio.h>
#include<algorithm>
using namespace std;
int UF[110000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int c[110000];
int d[110000];
int e[110000];
int f[110000];
int mod=10007;
int m[110000];
int num[110000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)UF[i]=-1;
		for(int i=0;i<a;i++){
			scanf("%d%d%d%d",c+i,d+i,e+i,f+i);
			UNION(c[i],i);
			UNION(e[i],i);
		}
		for(int i=0;i<110000;i++)m[i]=num[i]=0;
		for(int i=0;i<a;i++){
			int at=FIND(i);
			if(m[at]<d[i]){
				m[at]=d[i];num[at]=1;
			}else if(m[at]==d[i])num[at]++;
			if(m[at]<f[i]){
				m[at]=f[i];num[at]=1;
			}else if(m[at]==f[i])num[at]++;
		}
		int ret=1;
		for(int i=0;i<a;i++){
			if(FIND(i)==i){
				ret=ret*(num[i]/2)%mod;
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 2176
#include <iostream>
using namespace std;
int appeared[1000001] = {};

int main() {
	int s;
	cin >> s;
	appeared[s]++;
	for(int i = 0; i < 1000000; i++) {
		s = (s%2==0)?(s/2):(s*3+1);
		//cout << s << endl;
		appeared[s]++;
		if(appeared[s]>1) {
			cout << (i+1+1) << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 20

int main()
{
  int i;
  char str[LEN + 1];

  while (scanf("%s", str) > 0) {
    for (i = strlen(str) - 1; i >= 0; i--) {
      printf("%c", str[i]);
    }
    putchar('\n');
  }

  return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60
const MAX = int(1e+5)

var fac [MAX]int
var finv [MAX]int
var inv [MAX]int

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	initComb()
	for i := 1; i <= K; i++ {
		ans := modComb(K-1, i-1) * modComb(N-K+1, i)
		fmt.Fprintln(wtr, ans%MOD)
	}
}

func initComb() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1
	for 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
	}
}

func modComb(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	ll n, a, b;
	cin >> n >> a >> b;

	vector<ll> x(n);
	rep (i, 0, n)
		cin >> x[i];

	ll res = 0;
	rep (i, 0, n - 1) {
		ll tmp = x[i + 1] - x[i];
		if (tmp * a < b) {
			res += tmp * a;
		} else {
			res += b;
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[110000];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<c;i++){
		int t;scanf("%d",&t);t--;
		p[t]++;
	}
	for(int i=0;i<a;i++){
		int d=c-p[i];
		if(d<b)printf("Yes\n");else printf("No\n");
	}
}

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

vector<int> frn[100005];
vector<int> visited(100005, 0);
int cnd[100005];
int grp[100005];

void dfs1(int x, int *s) {
  visited[x] = 1;
  (*s)++;
  rep(i, frn[x].size()) {
    int to = frn[x][i];
    if (visited[to] == 1) continue;
    dfs1(to, s);
  }
}

void dfs2(int x, int s, int g) {
  visited[x] = 2;
  cnd[x] = s;
  grp[x] = g;
  rep(i, frn[x].size()) {
    int to = frn[x][i];
    if (visited[to] == 2) continue;
    dfs2(to, s, g);
  }
}

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(m), b(m), c(k), d(k);
  rep(i, m) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
  }
  rep(i, k) {
    cin >> c[i] >> d[i];
    --c[i];
    --d[i];
  }

  rep(i, m) {
    frn[a[i]].push_back(b[i]);
    frn[b[i]].push_back(a[i]);
  }

  int g = 0;
  rep(x, n) {
    int s = 0;
    if (!visited[x]) {
      dfs1(x, &s);
      dfs2(x, s, g);
      g++;
    }
  }

  rep(i, n) --cnd[i];

  rep(i, m) {
    --cnd[a[i]];
    --cnd[b[i]];
  }
  rep(i, k) {
    if (grp[c[i]] == grp[d[i]]) {
      --cnd[c[i]];
      --cnd[d[i]];
    }
  }

  rep(i, n-1) printf("%d ", cnd[i]);
  printf("%d\n", cnd[n-1]);
  
  return 0;
}

Measured memory_bytes: 12308
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a == 5 && b == 7 && c == 5) printf("YES\n");
	else if(a == 5 && b == 5 && c == 7) printf("YES\n");
	else if(a == 7 && b == 5 && c == 5) printf("YES\n");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 128