akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;



int main(){
ll N;
cin >> N;
string S;
cin >> S;
ll ans=0;
vector<ll> ikour(N,0);
vector<ll> ikoug(N,0);
vector<ll> ikoub(N,0);
ll rsum=0,gsum=0,bsum=0;
for(ll i=N-1;i>=0;i--){
  if(S[i]=='R')rsum++;
  else if(S[i]=='G')gsum++;
  else if(S[i]=='B')bsum++;
  ikour[i]=rsum;
  ikoug[i]=gsum;
  ikoub[i]=bsum;
;}
for(ll i=0;i<N-2;i++){
 for(ll j=i+1;j<N-1;j++){
   if(S[i]!=S[j]){
     if(S[i]!='R'&&S[j]!='R'){
       ans+=ikour[j+1];
       if(2*j-i<N&&S[2*j-i]=='R')ans--;
     }
     else if(S[i]!='G'&&S[j]!='G'){
       ans+=ikoug[j+1];
       if(2*j-i<N&&S[2*j-i]=='G')ans--;
     }
     else if(S[i]!='B'&&S[j]!='B'){
       ans+=ikoub[j+1];
       if(2*j-i<N&&S[2*j-i]=='B')ans--;
     }
   }
 ;}
;}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 3660
import sys
N, M = map(int, input().split())
REL = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    REL[a-1].add(b-1)
    REL[b-1].add(a-1)
REL = [list(s) for s in REL]

ans = 0
todo = []
done = set()
pdone = set()
for s in range(N):
    if s in done:
        continue
    pdone.clear()
    todo.append(s)
    while todo:
        p = todo.pop()
        pdone.add(p)
        done.add(p)
        for np in REL[p]:
            if np in pdone:
                continue
            todo.append(np)
    ans = max(ans, len(pdone))
print(ans)

Measured memory_bytes: 188704
import sys
input = sys.stdin.readline

from heapq import heappop,heappush

n = int(input())
p = []
for i in range(n):
    x,y = map(int,input().split())
    p.append((i,x,y))

e = [[] for _ in range(n)]

p = sorted(p,key=lambda x:x[1])
n0,x0,y0 = p[0]
for i in range(n-1):
    n1,x1,y1 = p[i+1]
    e[n0].append([min(abs(x1-x0),abs(y1-y0)),n1])
    e[n1].append([min(abs(x1-x0),abs(y1-y0)),n0])
    n0,x0,y0 = n1,x1,y1

p = sorted(p,key=lambda x:x[2])
n0,x0,y0 = p[0]
for i in range(n-1):
    n1,x1,y1 = p[i+1]
    e[n0].append([min(abs(x1-x0),abs(y1-y0)),n1])
    e[n1].append([min(abs(x1-x0),abs(y1-y0)),n0])
    n0,x0,y0 = n1,x1,y1

def Prim(n,edge):
    #edge[source] = [[cost_1,target_1],[cost_2,target_2],...]
    used = [False] * n
    q = []
    #e = [cost,target]
    for e in edge[0]:
        heappush(q,e)
    used[0] = True
    res = 0
    while q:
        c,v = heappop(q)
        if used[v]:
            continue
        used[v] = True
        for e in edge[v]:
            if not used[e[1]]:
                heappush(q,e)
        res += c
    return res

print(Prim(n,e))

Measured memory_bytes: 124192
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;
 
 
 int lis( int arr[], int n )  
{  
    int lis[n]; 
   
    lis[0] = 1;    
  
    /* Compute optimized LIS values in bottom up manner */
    for (int i = 1; i < n; i++ )  
    { 
        lis[i] = 1; 
        for (int j = 0; j < i; j++ )   
            if ( arr[i] > arr[j] && lis[i] < lis[j] + 1)  
                lis[i] = lis[j] + 1;  
    } 
  
    // Return maximum value in lis[] 
    return *max_element(lis, lis+n); 
}  
void computeLPSArray(char* pat, int M, int* lps) 
{ 
    // length of the previous longest prefix suffix 
    int len = 0; 
  
    lps[0] = 0; // lps[0] is always 0 
  
    // the loop calculates lps[i] for i = 1 to M-1 
    int i = 1; 
    while (i < M) { 
        if (pat[i] == pat[len]) { 
            len++; 
            lps[i] = len; 
            i++; 
        } 
        else // (pat[i] != pat[len]) 
        { 
            // This is tricky. Consider the example. 
            // AAACAAAA and i = 7. The idea is similar 
            // to search step. 
            if (len != 0) { 
                len = lps[len - 1]; 
  
                // Also, note that we do not increment 
                // i here 
            } 
            else // if (len == 0) 
            { 
                lps[i] = 0; 
                i++; 
            } 
        } 
    } 
} 
string longestCommonPrefix(string ar[], int n) 
{ 
  
    // If size is 0, return empty string 
    if (n == 0) 
        return ""; 
  
    if (n == 1) 
        return ar[0]; 
  
    // Sort the given array 
    sort(ar, ar + n); 
  
    // Find the minimum length from  
    // first and last string 
    int en = min(ar[0].size(),  
                 ar[n - 1].size()); 
  
    // Now the common prefix in first and  
    // last string is the longest common prefix 
    string first = ar[0], last = ar[n - 1]; 
    int i = 0; 
    while (i < en && first[i] == last[i]) 
        i++; 
  
    string pre = first.substr(0, i); 
    return pre; 
} 
bool isvalid(ll int x, ll int y, ll int m, ll int n)
{
    if(x<0||y<0||x>=m||y>=n)return 0;
    else return 1;
}
bool iscor(ll int x, ll int y, ll int m, ll int n)
{
    if(x==0||y==0||x==m-1||y==n-1)return 1;
    else return 0;
}

    
int main()
{
  fastio();
 
ll int T;
//cin>>T;
T=1;
ll int anscount=1;
while(T--)
{
 ll int n,m,count=0,i;
 cin>>n>>m;ll int a[n];
 double sum=0;
 for(i=0;i<n;i++){cin>>a[i];sum+=a[i];}
 sort(a,a+n);
 sum/=4*m;
 for(i=n-1;i>=0;i--)
 {
     if(a[i]>=sum)
     {
         count++;
     }
     else
     {
         break;
     }
     if(count==m)break;
 }
 if(count==m)cout<<"Yes"<<endl;
 else
 cout<<"No"<<endl;
  
  
  
}
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;
long long int t[55][55][2504];

int main()
{
    int n, a;
    cin >> n >> a;

    vector<int>p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];

    }

    t[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= 2500; k++) {
                t[j][i + 1][k] += t[j][i][k];
                if (k + p[i] <= 2500)t[j + 1][i + 1][k + p[i]] += t[j][i][k];
            }
        }
    }
    long long int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += t[i][n][i * a];
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 57472
/**
  @file d.cpp
  @title D - Cake 123
  @url https://atcoder.jp/contests/abc123/tasks/abc123_d
**/

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

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

template <class T>
void show(vector<T>& v) {
  for (uint i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<LL> A(X, 0);
  vector<LL> B(Y, 0);
  vector<LL> C(Z, 0);

  REP(i, X) { cin >> A[i]; }
  REP(i, Y) { cin >> B[i]; }
  REP(i, Z) { cin >> C[i]; }

  // sort(ALL(A), std::greater<LL>());
  // sort(ALL(B), std::greater<LL>());
  // sort(ALL(C), std::greater<LL>());

  vector<LL> AB;

  REP(i, X) {
    REP(j, Y) {
      AB.push_back(A[i] + B[j]);
    }
  }

  sort(ALL(AB), std::greater<LL>());
  AB.resize(K);

  vector<LL> ABC;
  REP(i, K) {
    REP(j, Z) {
      ABC.push_back(AB[i] + C[j]);
    }
  }
  sort(ALL(ABC), std::greater<LL>());

  REP(i, K) { cout << ABC[i] << "\n"; }

  return 0;
}


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

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

Measured memory_bytes: 1152
import sys

input = sys.stdin.readline

N = int(input())
S = input().strip()

if N%2==1:
	ans = 'No'
else:
	former = S[0:N//2]
	latter = S[N//2::]
	if former==latter:
		ans = 'Yes'
	else:
		ans = 'No'


print(ans)

Measured memory_bytes: 38256
a,b,c,k = map(int,input().split())

d={}

d[1]=a
d[0]=b
d[-1]=c

ans = 0
cnt=0

cnt+=a
ans+=a
if cnt>k:
    ans-=(cnt-k)
    print(ans)
    exit(0)

cnt+=b
if cnt>k:
    print(ans)
    exit(0)

cnt+=c
ans-=c
if cnt>k:
    ans+=(cnt-k)
    print(ans)
    exit(0)

if cnt==k:
    print(ans)

Measured memory_bytes: 9212
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;

/*
  let's try computer shogi!!!
 */


int main(){
  vector<ll> p;
  vector<bool> q,r;
  ll n;
  cin >> n;
  p.resize(n);
  q.resize(n+1);
  r.resize(n);
  for(ll i=0;i<n;++i){
    cin >> p[i];
    q[i+1] = false;
    r[i] = false;
  }
  q[0] = false;
  
  for(ll i=0;i<n;++i){
    q[p[i]] = true;
    if(q[p[i]-1]){
      r[p[i]-1] = true;
    }
  }
  ll cnt = 0;
  ll cmax = 0;
  for(ll i=0;i<n;++i){
    cerr << r[i]<<endl;
    if(r[i]){
      cnt++;
    }else{
      if(cnt > cmax){
	cmax = cnt;
      }
      cnt = 0;
    }
  }
  if(cnt > cmax){
    cmax = cnt;
  }
  cerr<<"ans"<<endl;
  cout<<n-cmax-1<<endl;
  return 0;
}

Measured memory_bytes: 1920
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
//string str;
int N,K;
int X[101];
int S[101];
int main(){
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>X[i];
		S[i]=min(X[i]*2,(K-X[i])*2);
	}
	int T=0;
	for(int i=0;i<N;i++){
		T+=S[i];
	}

	cout<<T<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static int[][] dp;




	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] map = new char[h][w];
		long pow = 1000000007;
		for(int i = 0;i < h;i++){
			String a = sc.next();
			for(int j = 0;j < w;j++){
				map[i][j] = a.charAt(j);
			}
		}
		//		for(int i = 0;i < h;i++){
		//			for(int j = 0;j < w;j++){
		//				System.out.print(map[i][j]);
		//			}
		//			System.out.println();
		//		}
		//		
		long[][] dp  = new long[h][w];		//dp[i][j] = i,jにくる道の総数
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++){
				if(i == 0){
					if(j == 0){
						dp[i][j] = 1%pow;
					}else{
						if(map[i][j-1] != '#'){
							dp[i][j] = dp[i][j-1]%pow;
						}
					}

				}else{
					if(j == 0){
						if(map[i-1][j] != '#')
							dp[i][j] =dp[i-1][j]%pow; 
					}else{
						if(map[i-1][j] != '#'){
							dp[i][j] += dp[i-1][j]%pow; 
						}
						if(map[i][j-1] != '#'){
							dp[i][j] += dp[i][j-1]%pow; 
						}

					}
				}
			}
		}
		//		for(int i = 0;i < h;i++){
		//					for(int j = 0;j < w;j++){
		//						System.out.print(dp[i][j]);
		//					}
		//					System.out.println();
		//				}



		System.out.println(dp[h-1][w-1]%pow);


	}

}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 40688
#include <stdio.h>

int t[1000000];
int main(void)
{
	int n, i, j, sum, c;	
	
	for (i = 2; i * i <= 1000000; i++){
		if (t[i] == 0){
			for (j = 2 * i; j <= 1000000; j++){
				if (j % i == 0){
					t[j] = 1;
				}
			}
		}
	}
	
	while (scanf("%d", &n), n != 0){
		sum = c = 0;
		
		for (i = 2; i <= 1000000; i++){
			if (t[i] == 0){
				sum += i;
				c++;
			}
			if (n == c){
				break;
			}
		}
		printf("%d\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 4504
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=1000000+5;
const int INF=0x7fffffff;
const int inf=100000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
int main()
{
    char c;
    cin>>c;
    if(c>='a'&&c<='z')
        cout<<'a'<<endl;
    else
        cout<<'A'<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int par[100009];
void init(int n){for(int i=0;i<n;++i) par[i]=-1;}
int root(int x){
  if(par[x]<0) return x;
  else return par[x]=root(par[x]);
}
bool same(int x,int y){return root(x)==root(y);}
bool comb(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y) return false;
  if(-par[x]<-par[y]) swap(x,y);
  par[x]+=par[y];
  par[y]=x;
  return true;
}
int size(int x) {return -par[root(x)];}

// 解説あり
int main() {
  int n,m,k;
  cin>>n>>m>>k;
  init(n);
  vector<int> ans(n,0);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    comb(a-1,b-1);
    ans[a-1]--;
    ans[b-1]--;
  }
  Graph Bro(n);
  rep(i,k){
    int a,b;
    cin>>a>>b;
    Bro[a-1].push_back(b-1);
    Bro[b-1].push_back(a-1);
  }
  
  rep(i,n){
    ans[i]+=size(i)-1;// sizeとらないと遅い
    for(auto j:Bro[i])
      if(same(i,j)) ans[i]--;
  }
  rep(i,n){
    if(i!=n-1) cout<<ans[i]<<" ";
    else cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
int len;
string s[62];
int step;
int ask(string s){
	cout << "? " << s << endl;
	int x;
	cin >> x;
	return x;
}
string solve(int l,int r){
	if(l==r)return s[l];
	int m=l+r>>1;
	string L=solve(l,m),R=solve(m+1,r);
	if(L.empty())return R;
	if(R.empty())return L;
	string ret;int i=0,j=0;
	for(;i<L.size()||j<R.size();)
		if(i<L.size() && (j==R.size() || ask(ret+L[i]+string(R.begin()+j,R.end()))
				==len-ret.size()-1-(R.size()-j))) ret = ret + L[i++];
		else	ret = ret + R[j++];
	return ret;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int p=0;char c;
	for(c='a';c<='z';++c)s[p++]=string(128-ask(string(128,c)),c);
	for(c='A';c<='Z';++c)s[p++]=string(128-ask(string(128,c)),c);
	for(c='0';c<='9';++c)s[p++]=string(128-ask(string(128,c)),c);
	for(auto u:s)len+=u.size();
auto zz=solve(0,61);
assert(zz.size()<=128 && zz.size()==len);
	cout<<"! "<<zz<<endl;
}


Measured memory_bytes: 3820
#-------最強ライブラリSCC(Python) ver25252------
import sys
sys.setrecursionlimit(1000000)

class scc_graph:
  # n 頂点数
  def __init__(s, n): 
    s._n = n
    s.g = {}
  def num_vertices(s): return s._n
  # 辺を追加 frm 矢元 to 矢先
  # O(1)
  def add_edge(s, frm, to): 
    if frm in s.g: s.g[frm].append(to)
    else: s.g[frm] = [to]

  # グループの個数と各頂点のグループidを返す
  def scc_ids(s):
    now_ord = group_num = 0
    visited = []
    low = [0] * s._n
    ord = [-1] * s._n
    ids = [0] * s._n
    # 再帰関数 
    def dfs(self, v, now_ord, group_num):
      low[v] = ord[v] = now_ord
      now_ord += 1
      visited.append(v)
      if v in s.g:
        for to in s.g[v]:
          if ord[to] == -1:
            now_ord, group_num = self(self, to, now_ord, group_num)
            low[v] = min(low[v], low[to])
          else:
            low[v] = min(low[v], ord[to])
      if low[v] == ord[v]:
        while True:
          u = visited.pop()
          ord[u] = s._n
          ids[u] = group_num
          if u == v: break
        group_num += 1
      return now_ord, group_num

    for i in range(s._n):
      if ord[i] == -1: now_ord, group_num = dfs(dfs, i, now_ord, group_num)
    for i in range(s._n):
      ids[i] = group_num - 1 - ids[i]
    return [group_num, ids]

  # 強連結成分となっている頂点のリストのリスト トポロジカルソート済み
  # O(n + m)
  def scc(s):
    ids = s.scc_ids()
    group_num = ids[0]
    counts = [0] * group_num
    for x in ids[1]: counts[x] += 1
    groups = [[] for _ in range(group_num)]
    for i in range(s._n):
      groups[ids[1][i]].append(i)
    return groups

  class edge:
    def __init__(s, frm, to):
      s.frm = frm
      s.to = to


#-------最強ライブラリここまで------

def main():
  input = sys.stdin.readline

  n, m = list(map(int, input().split()))
  ab = [list(map(int, input().split())) for _ in range(m)]

  g = scc_graph(n)

  for i in range(m):
    u, v = ab[i]
    g.add_edge(u, v)

  scc = g.scc()

  print(len(scc))

  for v in scc:
    print(len(v), end = " ")
    for x in v:
      print(x, end = " ")
    print("")

main()


Measured memory_bytes: 265496
N = int(input())
*V, = map(int, input().split())
def calc(V):
    A = {-1: 0}
    for c in V:
        A[c] = A.get(c, 0) + 1
    return sorted(A.items(), key=lambda x:(x[1],x[0]), reverse=1)
P = calc(V[::2])
Q = calc(V[1::2])
if P[0][0] == Q[0][0]:
    print(N-max(P[0][1]+Q[1][1], P[1][1]+Q[0][1]))
else:
    print(N-P[0][1]-Q[0][1])

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll L, R;
    cin >> L >> R;

    vector<bool> v(2019, false);
    FOR(i, L, R+1){
        if(v[i%2019]) break;
        v[i%2019] = true;
    }

    int ans = inf;

    REP(i, 2019){
        FOR(j, i+1, 2019){
            if(!v[i] || !v[j]) continue;
            chmin(ans, i*j % 2019);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// AOJ 1190: Anchored Balloon
// 2017.12.8 bal4u@uu

#include <stdio.h>
#include <math.h>

#define N 75
int n;
int x[10], y[10], l[10];

double sach(double xx, double yy)
{
	int i;
    double t, ans = 1e10;

    for (i = 0; i < n; i++) {
        t = l[i]*l[i] - (xx-x[i])*(xx-x[i]) - (yy-y[i])*(yy-y[i]);
        if (t < ans) ans = t;
    }
    return ans;
}

double ysach(double xx)
{
	int i;
    double l = -100.0, r = 100.0, m1, m2;

    i = N; while(i--) {
        m1 = (2*l + r) / 3;
        m2 = (l + 2*r) / 3;
        if (sach(xx, m1) > sach(xx, m2)) r = m2; else l = m1;
    }
    return sach(xx, l);
}

double xysach()
{
	int i;
    double l = -100.0, r = 100.0, m1, m2;

    i = N; while (i--) {
        m1 = (2*l + r) / 3;
        m2 = (l + 2*r) / 3;
        if (ysach(m1) > ysach(m2)) r = m2; else l = m1;
    }
    return sqrt(ysach(l));
}

int main()
{
	int i;

    while (scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++) scanf("%d%d%d", x+i, y+i, l+i);
        printf("%.07f\n", xysach());
    }
}

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

typedef long long ll;

int ar[200005];


int main()
{
    ll n , i, ans=0;

    cin>>n;

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

    sort(ar,ar+n);
    reverse(ar,ar+n);

    for(i=1; i<n; i++)
    {
        ans+=ar[i/2];
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define int long long

const int N = 5005, mod = 1e9 + 7;
int n, m, dp[N][N];
string s;

int binpow(int _a, int _m) {
    int res = 1, now = _a;
    for (; _m; _m >>= 1, now = (now * now) % mod) if(_m & 1) res = (res * now) % mod;
    return res;
}

signed main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> s; m = s.size();
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if(j) dp[i][j - 1] += dp[i - 1][j], dp[i][j - 1] %= mod;
            else dp[i][j] += dp[i - 1][j], dp[i][j] %= mod;
            dp[i][j + 1] += dp[i - 1][j] * 2; dp[i][j + 1] %= mod;
        }
    }

    cout << (dp[n][m] * binpow( binpow(2, m), mod - 2 )) % mod;

    return 0;
}


Measured memory_bytes: 195840
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := make([]int, n)
	ans := 0
	c := map[pair]int{}

	for i := 0; i < n; i++ {
		a[i] = int(scanFloat64()*1e9 + 0.5)

		c2, c5 := 0, 0
		for a[i]%2 == 0 && c2 < 20 {
			a[i] /= 2
			c2++
		}
		for a[i]%5 == 0 {
			a[i] /= 5
			c5++
		}
		for p, e := range c {
			if p.a+c2 >= 18 && p.b+c5 >= 18 {
				ans += e
			}
		}

		c[pair{c2, c5}]++
	}
	fmt.Fprintln(wr, ans)

}

type pair struct{ a, b int }


Measured memory_bytes: 5864
from itertools import accumulate
import bisect
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()

OK = 0
NG = max(A)*2+1
c = 0
# 幸福度がmid点以上上がる握手をM回できるか
while NG-OK > 1:
    mid = (OK+NG)//2
    cnt = 0

    for a in A:
        cnt += N-bisect.bisect_left(A, mid-a)

    if cnt >= M:
        OK = mid
    else:
        NG = mid

S = list(accumulate(A))

ans = 0
c = 0
for a in A:
    idx = bisect.bisect_right(A, OK-a)
    if idx >= 1:
        ans += a*(N-idx)+S[-1]-S[idx-1]
    else:
        ans += a*(N-idx)+S[-1]

    c += N-idx
ans += OK*(M-c)
print(ans)


Measured memory_bytes: 59916
A=int(input())
B=list(map(int,input().split()))
B=[i for i in B if i%2==0]
num=0
for i in range(len(B)):
  if B[i]%3!=0 and B[i]%5!=0:
    num=1
if num==1:
  print("DENIED")
else:
  print("APPROVED")
   

Measured memory_bytes: 38256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
//---------------------------

int max(std::vector<int> v){
  int maxVal = INT_MIN;       // 整数最小値
  for(int i = 0; i < (int)v.size(); ++i) {
    if( v[i] > maxVal )
    maxVal = v[i];
  }
  return maxVal;
}
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N;cin >> N;
  vector<string> v(N);
  REP(i,N){
    cin >> v[i];
  }
  int M;cin>> M;
  vector<string> w(M);
  REP(i,M){
    cin>>w[i];
  }
  vector<int> count(N,0);

  REP(i,N){
    REP(j,N){
      if (v[i] == v[j]) {
        count[i]++;
      }
    }
    REP(k,M) {
      if(v[i] == w[k]){
        count[i]--;
      }
    }
  }
  int ans = 0;
  if(max(count) > 0)ans = max(count);
  P(ans);
  return 0;
}


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

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

    int cnt = 0;
    while(true){
        string s;
        cin >> s;
        if(s == "END_OF_TEXT") break;
        
        rep(i,s.size()){
            if(isupper(s[i])) s[i] = tolower(s[i]);
        }
        
        if(s == w) cnt++;
    }
    cout << cnt << endl;
}





Measured memory_bytes: 3204
# -*- coding: utf-8 -*-

import sys
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

X, Y, N, M, L = MAP()
A = LIST()
B = LIST()
C = LIST()

A.sort(reverse=1)
B.sort(reverse=1)

que = []
que += A[:X]
que += B[:Y]
heapify(que)

for c in C:
    if c > que[0]:
        heappop(que)
        heappush(que, c)
ans = sum(que)
print(ans)


Measured memory_bytes: 23216
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
  ll n;
  cin >> n;

  ll total = 0;
  for(ll i = 1; i <= n; i++){
    for(ll j = 1; j <= n; j++){
      ll a = gcd(i, j);
      for(ll k = 1; k <= n; k++){
        ll b = gcd(a, k);
        total += b;
      }
    }
  }

  cout << total << endl;
}     



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  char x;
  cin >> a >> x >> b;
  if (a < 2019 || (a == 2019 && b < 5)) {
    cout << "Heisei";
  } else {
    cout << "TBD";
  }
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int md = (int)1e9+7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main(){
	int n,m;
	cin >>n >>m;
	vector<ll>  x(n),y(n),z(n); 
	rep(i,n) cin >>x[i] >>y[i] >>z[i];
	
	ll ans = -1LL<<60;
	rep(a,2) rep(b,2) rep(c,2){
		vector<ll> sma(n);
		rep(j,n){
			ll sm =0;
			sm += a? x[j]: -x[j];
			sm += b? y[j]: -y[j];
			sm += c? z[j]: -z[j];
			sma[j] = sm;
		}
		sort(sma.rbegin(), sma.rend());
		ll w =0;
		rep(j,m) w += sma[j];
		ans = max(ans, w);
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    cnt = [0] * 4
    for i in range(3):
        a, b = map(int, readline().split())
        a -= 1
        b -= 1
        cnt[a] += 1
        cnt[b] += 1

    if cnt.count(1) == 2 and cnt.count(2) == 2:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61956
// Submitted By Subhash Yadav
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) throws IOException {

		FastScanner sc = new FastScanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=sc.nextInt();
		int ans=0;
		for(int i=1;i<n;i++) {
			
				double d1=1.0*n/i-1;
				ans+=Math.ceil(d1);
			
		}
		out.println(ans);
		out.close();
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

}

Measured memory_bytes: 33700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
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; }
typedef long long ll;
using namespace std;
const ll mod=1e+9+7;
int main(void){
    string s;cin>>s;
    ll dp[s.size()+3][13];
    rep(i,s.size()+3)rep(j,13)dp[i][j]=0;
    dp[0][0]=1;
    rep(i,s.size()){
        char c=s[i];
        rep(j,13){
            if(c=='?'){
                rep(k,10){
                    int buf=j*10+k;
                    buf%=13;
                    dp[i+1][buf]+=dp[i][j];
                    dp[i+1][buf]%=mod;
                }
            }else{
                int k=c-'0';
                int buf=j*10+k;
                buf%=13;
                dp[i+1][buf]+=dp[i][j];
                dp[i+1][buf]%=mod;
            }
        }
    }
    ll res=dp[s.size()][5];
    cout<<res<<endl;
}

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

int main() {
  ll x, m = 100, ans = 0;
  cin >> x;
  while(true){
    m = m * 1.01;
    ++ans;
    if(m >= x) break;
  }
  cout << ans << endl;
}


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

#define LINE_SIZE 12

int
main(int argc, char **argv) {
  char *buf;
  int n, price, min, profit, lost;

  buf = (char *) malloc(LINE_SIZE);
  if (buf == NULL) exit(1);

  buf = fgets(buf, LINE_SIZE, stdin);
  if (buf == NULL) exit(1);

  n = atoi(buf);
  price = min = profit = lost = -1;

  while (1) {
    buf = fgets(buf, LINE_SIZE, stdin);
    if (buf == NULL || n < 1) break;

    --n;
    price = atoi(buf);

    if (min == -1) {
      min = price;
    } else if (price < min) {
      if (lost == -1 || lost > (min - price)) {
        lost = min - price;
      }
      min = price;
    } else if (profit < (price - min)) {
      profit = price - min;
    }
  }

  fprintf(stdout, "%d\n", profit > -1 ? profit : -lost);

  free(buf);
  buf = NULL;
  exit(0);
}


Measured memory_bytes: 2092
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int N;
    string s;
    cin >> N >> s;

    vs32 L(N + 1, 0);
    L[0] = 0;
    rep (i, N)
    {
        L[i + 1] = L[i];
        if (s[i] == 'W') ++L[i + 1];
    }

    int ans = N;
    rep (i, N)
    {
        ans = MIN(N - i - 1 - L[N] + L[i + 1] + L[i], ans);
    }

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



Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t


int main(void){
    string s;
    cin >> s;
    vector<int> a;
    int can_p = 0;
    
    a.push_back(0);
    for(int i = 0 ; i < s.size() ; i++ ){
        if( s[i] == 'g' ){
            can_p++;
        }else if( s[i] == 'p'){
            can_p--;
        }
        a.push_back(can_p);
    }
    
    int count = 0;
    int pm = INT_MAX;
    int gm = a[s.size()];
    for(int i = s.size() - 1 ; i >= 0 ; i-- ){
        bool is_g = s[i] == 'g';
        
        if( s[i] == 'g' ){/*
            cout << "::::" << i << "::::" << endl;
            cout << gm << endl;
            cout << pm << endl;
            cout << a[i] << endl;
            cout << "::::" << i << "::::" << endl;
            */
            if( gm - 2>= 0 && pm - 2> 0 &&a[i] > 0){
                count ++;
                gm-=2;
                pm-=2;
                is_g = false;
            }
        }
        
        if( !is_g )pm = min(a[i],pm);
        if( is_g )gm = min(a[i],gm);
    }
    cout << count << endl;
    
    return 0;
}

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

int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  while(1) {
    c -= b;
    if(c <= 0) {
      cout << "Yes";
      break;
    }
    a -= d;
    if(a <= 0) {
      cout << "No";
      break;
    }
  } 
}

Measured memory_bytes: 3772
#include <iostream>
#include <vector> //可変長配列
#include <queue> //キュー
#include <unordered_map> //ハッシュ連想配列
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int R,G; cin>>R>>G;
    cout<<2.0*G-R<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define loop(i,a,b) for(i=a;i<b;i++)
#define mod   998244353
#define INF 1000000000000
#define pb push_back
#define lim 200001
using namespace std;

int main()
{
  ll h,w,i,j;
  cin>>h>>w;
  char s[h+1][w+1];
  ll dp[h+1][w+1];
  loop(i,0,h)
    cin>>s[i];
  dp[0][0]=0;
  
  
  loop(i,0,h)
    loop(j,0,w)
  {if(!i && !j) 
  { if(s[0][0]=='#')
    dp[0][0]=1;
   continue;}
   dp[i][j]=INF;
  if(i>0)
    {dp[i][j]=dp[i-1][j];
     if(s[i-1][j]=='.' && s[i][j]=='#') dp[i][j]++;
    }
    if(j>0)
    {if(s[i][j-1]=='.' && s[i][j]=='#') 
      dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
     else
       dp[i][j]=min(dp[i][j],dp[i][j-1]);}
  }
  
  cout<<dp[h-1][w-1]<<endl;
       return 0;}
  

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

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

using namespace std;

int main(){
	int a, b, c;
	cin>>a>>b>>c;
	
	if( ( a <= c && c <= b ) || ( b <= c && c <= a ) ){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    LL a, b;
    int c, d;
    cin >> a >> b >> c >> d;
    --a;

    LL x = b / c - a / c;
    LL y = b / d - a / d;
    LL lc = c / __gcd( c, d ) * (LL)d;
    LL z = b / lc - a / lc;

    cout << b - a - ( x + y - z ) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a1,a2,a3;
  scanf("%d %d %d\n",&a1,&a2,&a3);
  if (a1 + a2 + a3 >= 22) {
    printf("bust\n");
  } else {
    printf("win\n");
  }
  return 0;
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

vector<pair<int, int>> cop;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, a; cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> a;
        cop.push_back(make_pair(a, i));
    }

    sort(cop.begin(), cop.end());

    int swaps = 0;

    for(int i = 0; i < n; ++i)
        if(cop[i].second % 2 != i % 2)
            ++swaps;

    cout << swaps / 2 << "\n";

    return 0;

}


Measured memory_bytes: 1400
#include<stdio.h>
#define N 100


int main(){

  int n,l,i,p[N+1],m[N+1][N+1],k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      int j=i+l-1;
      m[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
	if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
	  m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }
    }
  }

  printf("%d\n",m[1][n]);
  return 0;

}



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

using namespace std;

#define N 1000005

int n, a[N];

string s;

int get()
{
	int res = 0;
	for(int i = 0; i <= n; i++)
	{
		int now = a[i] % 2;
		if(now && ((n & i) == i)) res ^= 1;
	}
	return res;
}

int main()
{
	cin >> n >> s;
	n--;
	for(int i = 0; i <= n; i++)
		a[i] = s[i] - '1';
	if(get()) cout << 1 << endl;
	else
	{
		for(int i = 0; i <= n; i++)
			if(a[i] == 1) 
			{
				cout << 0 << endl;
				return 0;
			}
		for(int i = 0; i <= n; i++)
			a[i] /= 2;
		if(get()) cout << 2 << endl;
		else cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 5252
import math
n = int(input())
T = [int(input()) for _ in range(n)]

#最小公倍数
def lcm(x, y):
    return (x*y)//math.gcd(x, y)

ans = T[0]
for t in T[1:]:
    ans = lcm(ans, t)
print(ans)

Measured memory_bytes: 9180
#include<cstdio>
int n;
int tab[100005], dp[100005];

inline int mini(int a, int b){
	return a<b?a:b;
}
inline int abs(int x){
	return x<0?-x:x;
}

int main(){

	scanf("%d", &n);
	for(int i=0;i<n;i++){
		scanf("%d", &tab[i]);
	}
	for(int i=1;i<n;i++){
		dp[i]=dp[i-1]+abs(tab[i]-tab[i-1]);
		if(i!=1)dp[i]=mini(dp[i], dp[i-2]+abs(tab[i]-tab[i-2]));
	}
	printf("%d\n", dp[n-1]);
}


Measured memory_bytes: 896
n = int(input())
li = [input() for i in range(n)]

print("AC x " + str(li.count("AC"))) 
print("WA x " + str(li.count("WA"))) 
print("TLE x " + str(li.count("TLE"))) 
print("RE x " + str(li.count("RE"))) 

Measured memory_bytes: 79156
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

// Z_p
// cin以外の大体のことはできる
template <int p>
struct int_p {
    long long int val;
    template <typename T>
    int_p(T x) {
        val = x % p;
    }
    // [0,p)の範囲の代表元
    long long int repr() const {
        if (val < 0) return val + p;
        return val;
    }
    //環演算
    int_p<p> operator+(int_p<p>& b) const {
        return int_p<p>(val + b.repr());
    }
    int_p<p> operator+(int& b) const {
        return int_p<p>(val + b);
    }
    int_p<p> operator-(int_p<p>& b) const {
        return int_p<p>(val - b.repr());
    }
    int_p<p> operator-(int& b) const {
        return int_p<p>(val - b);
    }
    int_p<p> operator*(int_p<p>& b) const {
        return int_p<p>(val * b.repr());
    }
    int_p<p> operator*(int& b) const {
        return int_p<p>(val * b);
    }
    //代入
    template <typename T>
    int_p<p> operator=(T x) {
        val = x;
    }
};
// coutとかできるようにする
template <int p>
ostream& operator<<(ostream& os, const int_p<p>& x) {
    os << x.repr();
    return os;
};

int main() {
    int n;
    const int mod = 1e+9 + 7;
    cin >> n;
    int_p<mod> ans = 1;
    for (int i = 1; i <= n; i++) {
        ans = ans * i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n;
int a[maxn];
int flag;
ll ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		ans+=abs(a[i]);
		if(a[i]<0) flag^=1;	
	}
	for(int i=1;i<=n;i++) a[i]=abs(a[i]);
	sort(a+1,a+1+n);
	if(!flag) printf("%lld\n",ans);
	else printf("%lld\n",ans-2*abs(a[1]));
	return 0;
}

Measured memory_bytes: 640
N = int(input())
*B, = map(int, input().split())
now = max(B)
ops = []
while N > 0:
    temp = (-1, -1)
    for i, b in enumerate(B):
        if b <= N and b == i + 1:
            temp = max(temp, (b, i))
    if temp != (-1, -1):
        _, i = temp
        ops.append(B.pop(i))
    N -= 1
if B: print(-1)
else: print(*list(reversed(ops)), sep='\n')

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

using namespace std;

int a[101];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int mn = 1001, mx = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        mn = min(mn, a[i]);
        mx = max(mx,a[i]);
    }
    cout << mx - mn << endl;
    return 0;
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int k, n; cin >> k >> n;

	vector <int> a(n);

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

	int record = 0;

	for(int i = 1; i < n; i++){
		int dif = a[i] - a[i - 1];
		record = max(record, min(dif, k - dif));
	}

	record = max(record, min(a.back() - a[0], k - a.back() + a[0]));

	cout << k - record << endl;
	
	
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
int n;
ll sect[100005];
ll ans=0,tmpans=0;
ll tmpmin=1e12;
typedef long long ll;
typedef vector<ll> vll;

int main(int argc,char const* argv[])
{
  string flag[55];
  int n,m;
  cin >> n >> m;
  for(int i=0;i<n;i++)
    {
      cin >> flag[i];
    }
  int ans=1000000;
  for(int i=0;i<n-2;i++)
    {
      for(int j=i+1;j<n-1;j++)
	{
	  int tmpans=0;
	  int k=j+1;
	  for(int w=0;w<=i;w++)
	    {
	      for(int yoko=0;yoko<m;yoko++)
		{
		  if(flag[w][yoko]!='W') tmpans++;
		}
	    }
	  for(int w=i+1;w<=j;w++)
	    {
	      for(int yoko=0;yoko<m;yoko++)
		{
		  if(flag[w][yoko]!='B') tmpans++;
		}
	    }
	  for(int w=k;w<n;w++)
	    {
	      for(int yoko=0;yoko<m;yoko++)
		{
		  if(flag[w][yoko]!='R') tmpans++;
		}
	    }
	  ans=min(ans,tmpans);
	}
    }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

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

    int res = 1;
    while (res <= k && n > 0) {
        res *= 2;
        n--;
    }
    while (n > 0) {
        res += k;
        n--;
    }

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


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int C = sc.nextInt();
    	int d =0;

    	for(int i =0;i<C;i++){

    		if(A<=B){
    			B -=A;
    			d++;
    		}

    	}


    	System.out.println(d);

}


}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

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

const int MAX_N = 200000;
int n;
string s[MAX_N+1];
map<string, int> mp;
int max_v = 0;

int main() {
    
    cin >> n;
    rep(i, n) cin >> s[i];

    rep(i, n) {
        if (mp.find(s[i]) == mp.end()) {
            mp[s[i]] = 1;
        } else {
            mp[s[i]]++;
        }
        if (mp[s[i]] > max_v) max_v = mp[s[i]];
    }

    for (map<string, int>::iterator i = mp.begin(); i != mp.end(); ++i) {
        if (i->second == max_v) cout << i->first << endl;
    }

    return 0;
}

Measured memory_bytes: 28288
// One-stroke Path

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int n, m;

typedef struct NODE {
    vector<int> adj;
} Node;

Node *nodes;
// 3: src, 2: dst, 1: 到達済, 0: 未到達
char *node_map;

void init_node_map() {
    for (int i = 0; i <= n; i++) {
        node_map[i] = 0;
    }
}

bool is_bridge(int dst) {

    for (int i = 0; i < nodes[dst].adj.size(); i++) {
        int next = nodes[dst].adj[i];

        if (node_map[dst] == 2 && node_map[next] == 3) {
            continue;
        }

        // 既に訪れていた
        if (node_map[next] == 1 || node_map[next] == 2) {
            if (nodes[dst].adj.size() == 1) {
                break;
            }
            continue;
        }

        // loopが見つかった
        if (node_map[next] == 3) {
            return false;
        }

        node_map[next] = 1;

        if (is_bridge(next)) {
            continue;
        } else {
            return false;
        }
    }
    return true;
}

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

    nodes = (Node *)malloc(sizeof(Node) * (n+1));
    node_map = (char *)malloc(sizeof(char) * (n+1));
    init_node_map();

    vector<int> srcs;
    vector<int> dsts;

    int a, b;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        srcs.push_back(a);
        dsts.push_back(b);

        nodes[a].adj.push_back(b);
        nodes[b].adj.push_back(a);
    }

    int cnt = 0;

    for (int i = 0; i < m; i++) {
        int s = srcs[i];
        int d = dsts[i];

        node_map[s] = 3;
        node_map[d] = 2;

        if (is_bridge(d)) {
            cnt++;
        }
        init_node_map();
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256