akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
   int N;
   cin >> N;
   vector<int> vec(N);
   for (int i = 0; i < N; i++)
   {
      cin >> vec.at(i);
   }
   
   sort(vec.begin(), vec.end());
   reverse(vec.begin(), vec.end());
   
   int count = 0;
   int tmp = 101;
   for (int i = 0; i < N; i++)
   {
      if (tmp > vec.at(i)) count++;
      tmp = vec.at(i);
   }
   
   cout << count << endl;
}

Measured memory_bytes: 256
n,q = map(int, input().split())
s=input()
a=[0]*n
for i in range(1,n):
    a[i]+=a[i-1]
    if s[i-1]=='A' and s[i]=='C':
        a[i]+=1
for i in range(q):
    l,r=map(int, input().split())
    print(a[r-1]-a[l-1])


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

using namespace std;

vector<int> to[200006];
bool visited[200006] = {false};
vector<int> ans;

void dfs(int node, int x){
  if(visited[node]) return;
  ans[node] += x;
  visited[node] = true;
  for(int i=0; i<to[node].size(); i++){
    dfs(to[node][i], ans[node]);
  }
}

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

  for(int i=0; i<N-1; i++){
    int a,b;
    cin >> a >> b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  ans.resize(200006);

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

  dfs(1, 0);

  for(int i=1; i<=N; i++){
    cout << ans[i] << ' ';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<pair<int,int>,ll> P;
const ll MOD = 1e9+7;

class segtree
{
  public:
  int depth;//セグ木の深さ(最上部が0）
  int size;
  vector<ll> node;//セグ木本体

  //コンストラクタ
  //初期値の代入もする
  segtree(int n)
  {
    depth=0;
    size=1;
    while(n>size)
    {
      size*=2;
      depth++;
    }
    size*=2;
    node.resize(size,1e14-1);
  }

  //値の更新
  //node[k]にaを加える
  void update(int k,ll a)
  {
    k+=(1<<depth);//セグ木上のインデックスに読み替え
    node[k]=min(a,node[k]);
    while(k>1)
    {
      k/=2;
      node[k]=min(node[k*2],node[k*2+1]);
    }
    return;
  }
  
  //値の取得
  //閉区間[a,b]に値はいくつあるか
  ll get(int a,int b)
  {
    a+=(1<<depth);
    b+=(1<<depth);
    if(a==b)
      return node[a];
    ll nowa=node[a];
    ll nowb=node[b];
    while(a/2<b/2)
    {
      //左側はより右側を見る
      if((a&1)==0)
        nowa=min(nowa,node[a+1]);
      //右側はより左側を見る
      if((b&1)==1)
        nowb=min(nowb,node[b-1]);
      a/=2;
      b/=2;
    }
    ll ret=min(nowa,nowb);
    return ret;
  }
};

P p[100000];
int main()
{
	int n,m;
	ll ans=0;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int l,r;ll c;
		cin>>l>>r>>c;
		l--;r--;
		p[i]=P(make_pair(l,r),c);
	}
	sort(p,p+m);
	segtree t=segtree(n);
	t.update(0,0);
	for(int i=0;i<m;i++)
	{
		//cerr<<p[i].first.first<<endl;
		ll s=t.get(p[i].first.first,p[i].first.second);
		if(s==1e14-1)
			continue;
		t.update(p[i].first.second,s+p[i].second);
	}
	ans=t.get(n-1,n-1);
	if(ans==1e14-1)
		ans=-1;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3840
while(True):
    i=0
    a=list(map(int,input().split()))
    if(a[0]==0 and a[1]==0):
        break
    for x in range(2,a[0]):
        sum=a[1]-x
        for y in range(1,x):
            if (sum-y<a[0]+1 and sum-y>x):
                i+=1
    print(i)    

Measured memory_bytes: 7668
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    ll a,co=0;
    cin >> a;
    for(int i = 1; i <= a; ++i){
        if(i % 3 == 0 && i % 5 == 0){
            continue;
        }else if(i % 3 == 0){
            continue;
        }else if(i % 5 == 0){
            continue;
        }else{
            co += i;
        }
    }

    cout << co << endl;
  

    return 0;
}



Measured memory_bytes: 3680
import math

def calc(n):
    global p
    q = 1
    lst = list(range(2, math.floor(math.sqrt(n))+1))

    for i in lst:
        if n%i ==0:
            q =0
            break

    if q==1:
        p = p+1

p =0
num = int(input())

for i in range(num):
    inputnum = int(input())
    if inputnum ==2:
        p =p+1
    else:
        calc(inputnum)

print(p)


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

int main() {
  int N;
  string S[100];
  cin >> N;

  for(int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  
  for(int i = 0; i < N; ++i) {
    if (S[i] == "Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 256
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n;
int store[5005];
string s;
int mul=41;
int mod=2016007997;
map<int,int>mp;
int check(int len)
{
    mp.clear();
    int mulpow=1;
    for(int i=0;i<len;i++)
        mulpow=(mulpow*mul)%mod;
    int val=0;
    for(int i=0;i<len;i++)
    {
        val=(val*mul+s[i])%mod;
        store[i]=val;
    }
    mp[val]=len-1;
    for(int i=len;i<n;i++)
    {
        val=(val*mul+s[i])%mod;
        store[i]=val;
        int get=(store[i]-((mulpow*store[i-len])%mod)+mod)%mod;
        if(!mp[get])
            mp[get]=i;
        else
        {
            if(i-mp[get]>=len && s[i]==s[mp[get]])
                return true;
        }
    }
    return false;
}
int32_t main() 
{
    IOS;
    cin>>n>>s;
    int low=0;
    int high=n/2;
    while(low<high)
    {
        int mid=(low+high+1)/2;
        if(!check(mid))
            high=mid-1;
        else
            low=mid;
    }
    print(low);
}

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

int main() {
	long long n, m, ans;
	cin >> n >> m;
	
	if(m >= n*2){
		ans += n;
		m = m-n*2;
		ans += m/4;
	}else{
		ans = m/2;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
const ll MOD = (ll)(1e9 + 7);
int C[MAX_N];
int L[MAX_N];
int B[MAX_N];
ll dp[MAX_N];

int main2() {
  CLR(L, -1);
  CLR(B, 0);
  CLR(dp, 0);

  int N = nextInt();
  REP(i, N) C[i] = nextInt();
  REP(i, N) {
    B[i] = L[C[i]];
    L[C[i]] = i;
  }

  dp[0] = 1;
  for (int i = 1; i < N; i++) {
    dp[i] = dp[i-1];
    int j = B[i];
    if (j != -1 && j != i-1) {
      dp[i] += dp[j];
    }
    dp[i] %= MOD;
  }
  ll ans = dp[N-1];
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

int main(){
	int n;
	bool flag = true;
	int count = 0;
	string s;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> s;
		if(s == "A"){
		count++;
		}
		else if(s == "Un"){
		count--;
		}
		if(count < 0)flag = false;
	}
	if(flag && count == 0){
	cout << "YES" <<endl;
	}
	else cout << "NO" <<endl;
	return 0;
}

Measured memory_bytes: 3136
N, M = map(int, input().split())
H = list(map(int, input().split()))
good = [True] * N

for i in range(M):
    a, b = map(int, input().split())
    a = a - 1
    b = b - 1
    if not H[a] > H[b]:
        good[a] = False
    if not H[a] < H[b]:
        good[b] = False

print(sum([1 if good[i] else 0 for i in range(N)]))

Measured memory_bytes: 19972
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 100005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';

ll abs1(ll x) {
  if (x < 0)
    return -x;
  return x;
}
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll dp[2][N];
ll pre[2][N];
ll arr[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  cin >> n >> k;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];

  memset(dp, 0, sizeof(dp));

  memset(pre, 0, sizeof(pre));
  dp[0][0] = 1;

  pre[0][0] = 1;
  for (ll i = 1; i <= k; i++)
    pre[0][i] = (pre[0][i - 1] + dp[0][i]) % mod;
  for (ll i = 1; i <= n; i++) {
    ll curr1 = i & 1;
    ll prev1 = (i - 1) & 1;

    for (ll j = 0; j < N; j++)
      pre[curr1][j] = 0;
    for (ll j = 0; j <= k; j++) {

      ll st = max(j - arr[i], 0ll);
      ll end1 = j;

      if (st)
        dp[curr1][j] = (pre[prev1][end1] - pre[prev1][st - 1] + mod) % mod;
      else
        dp[curr1][j] = pre[prev1][end1];

      if (j)
        pre[curr1][j] = pre[curr1][j - 1];

      pre[curr1][j] = (pre[curr1][j] + dp[curr1][j]) % mod;
    }
  }

  cout << dp[n & 1][k] << en;
  return 0;
}


Measured memory_bytes: 3328
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]


colors = []

#後ろから見ていく
for i,n in enumerate(list(reversed(A))):
    # 一つ目はとりあえずなんか一色ぬる
    if i == 0:
        colors.append(n)
    else:
        #二つ目以降は、各色の最小値のなかで、今見ているのより小さいものがあればそれを置き換える
        # 「各色の最小値集合の最小値と置き換える」を繰り返すので、最小値集合の最大より大きいなら最後に追加
        idx = bisect.bisect_right(colors, n)
        #if idx == len(colors):
        if colors[-1] <= n:
            colors.append(n)
        else:
            colors[idx] = n

print(len(colors))

Measured memory_bytes: 8604
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	M := sc.NextInt()
	A := make([][]byte, N)
	B := make([][]byte, M)

	for i := 0; i < N; i++ {
		A[i] = make([]byte, N)
		A[i] = []byte(sc.NextLine())
	}
	for i := 0; i < M; i++ {
		B[i] = make([]byte, M)
		B[i] = []byte(sc.NextLine())
	}

	check := func(i, j int) bool {
		for k := 0; k < M; k++ {
			for l := 0; l < M; l++ {
				if A[i+k][j+l] != B[k][l] {
					return false
				}
			}
		}
		return true
	}

	for i := 0; i <= N-M; i++ {
		for j := 0; j <= N-M; j++ {
			if check(i, j) {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().mainrun();
	}

	private Scanner scan;
	private int n,m;

	private void mainrun() {
		scan = new Scanner(System.in);

		while(true) {
			n = scan.nextInt();
			m = scan.nextInt();

			if(n != 0) {
				looprun();
			}else {
				break;
			}
		}

		scan.close();
	}

	private int[] a;
	private int ans;

	private void looprun() {
		ans = -1;
		a = new int[n];

		for(int i = 0;i < n;i++) {
			a[i] = scan.nextInt();
		}

		for(int i = 0;i < n;i++) {
			for(int j = 0;j < n;j++) {

				int num = a[i] + a[j];

				if(num <= m && i != j) {
					ans = Math.max(ans, num);
				}
			}
		}
		
		System.out.println((ans != -1 ? ans : "NONE"));
	}

}



Measured memory_bytes: 47296
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  string s;
  map<string, int> S;
  int maxs = 0;
  rep(i,N) {
    cin >> s;
    S[s]++;
    maxs = max(maxs, S[s]);
  }
  
  for (auto p : S) if (p.second==maxs) cout << p.first << endl;
  

  // cout << fixed << setprecision(6);
  return 0;
}



Measured memory_bytes: 25216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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

int n,seki;

cin >> n;

for (int i = 1; i < 10; i++)
{
   for (int j = 1; j < 10; j++)
   {
      seki = i*j;
      if (seki == n)
      {
         cout << "Yes" << endl;
         return 0;
      }
      
   }
      
}

cout << "No" << endl;







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

Measured memory_bytes: 256
import math

n = int(input())

def f(a, b):
  if len(str(a)) < len(str(b)):
    return len(str(b))
  else:
    return len(str(a))

ans = float('inf')
for i in range(1, int(math.sqrt(n)+1)):
  if n%i == 0:
    ans = min(ans, f(i, n//i))
print(ans)

Measured memory_bytes: 9188
//33
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> v[11];
  while(n--){
    int c,g;
    cin>>c>>g;
    v[g].push_back(c);
  }
  vector<int> r(k+1);
  for(int l=1;l<=10;l++){
    sort(v[l].rbegin(),v[l].rend());
    vector<vector<int> > dp(v[l].size()+1,r);
    int pp=0;
    for(int i=0;i<v[l].size();i++){
      pp+=v[l][i]+i*2;
      for(int j=k;j>=i+1;j--){
	dp[i+1][j]=max(dp[i+1][j],dp[0][j-i-1]+pp);
      }
    }
    for(int i=0;i<=k;i++){
      int m=0;
      for(int j=0;j<dp.size();j++){
	m=max(m,dp[j][i]);
      }
      r[i]=m;
    }
  }
  cout<<r[k]<<endl;
  return 0;
}
  
  

Measured memory_bytes: 15028
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d,e,f;
    cin>> a>>b>>c>>d;
    e= a+b;
    f= c+d;
    if(e>f){
        cout<< "Left";
    }
    else if(f>e){
        cout<< "Right";
    }
    else{
        cout<< "Balanced";
    }
    return 0;
}


Measured memory_bytes: 3636
s=input()
for i in range(len(s)):
    if i>=1:
        if s[i]==s[i-1]:
            print(i, i+1)
            exit()
    if i>=2:
        if s[i]==s[i-2]:
            print(i-1, i+1)
            exit()
print(-1, -1)

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

typedef long long ll;

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


int main () {
	int X;
	cin >> X;
	int k = 360 / gcd (360,X);
	cout << k << endl;
	return 0;
}

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

using namespace std;

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

  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> arr(n+1);
  
  int count = 0;
  rep (i, n-1){
    if(s.substr(i,2) == "AC")
      count++;
    arr[i+1] = count;
  }

  rep(i, q) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << arr[r] - arr[l] << endl;
  }
}

Measured memory_bytes: 1488
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        //入力準備
       Scanner sc = new Scanner(System.in);
       
       //入力値の受け取り
       int a = sc.nextInt();
       int b = sc.nextInt();
       int c = sc.nextInt();
       
       
       //計算して出力
        if (a < b && b < c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

using namespace std;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1') ans++;
    }   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<long long,long long> >st[200010];
vector<pair<int,int> >G[200010];
int n;
int up[200010];
long long ans;
bool dfs(int x,int p)
{
	int l=0,r=0;
	for(int i=0;i<(int)G[x].size();i++)
	{
		int y=G[x][i].first,w=G[x][i].second;
		if(y==p)continue;
		up[y]=w;
		if(!l)l=y;else r=y;
		if(!dfs(y,x))return false;
	}
	if(!l)st[x].push_back(make_pair(0,0));
	else
	{
		if((int)st[l].size()>(int)st[r].size())swap(l,r);
		long long mn=1e18;
		int p=0;
		for(int i=(int)st[l].size()-1;i>=0;i--)
		{
			while(p<(int)st[r].size() && st[l][i].first+st[r][p].first+up[l]+up[r]<=ans)mn=min(mn,st[r][p].second),p++;
			if(mn!=1e18)
			{
				st[x].push_back(make_pair(st[l][i].second+up[l],mn+up[r]));
				st[x].push_back(make_pair(mn+up[r],st[l][i].second+up[l]));
			}
		}
		sort(st[x].begin(),st[x].end());
		st[x].erase(unique(st[x].begin(),st[x].end()),st[x].end());
	}
	return ((int)st[x].size()>0);
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		G[x].push_back(make_pair(i,y));
	}
	long long l=0,r=1e11;
	while(l<=r)
	{
		ans=(l+r)>>1;
		for(int i=1;i<=n;i++)st[i].clear();
		if(dfs(1,0))r=ans-1;
		else l=ans+1;
	}
	printf("%lld",r+1);
	return 0; 
} 

Measured memory_bytes: 33784
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N int
	var K int
	fmt.Scan(&N)
	var S string
	fmt.Scan(&S)
	fmt.Scan(&K)

	a := S[K-1]

	var s = []string{}

	for i := 0; i < N; i++ {
		if S[i] != a {
			s = append(s, string('*'))
		} else {
			s = append(s, string(a))
		}
	}
	fmt.Println(strings.Join(s, ""))
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> a;
	cout << "Christmas";
	rep(i, 25 - a)
		cout << " Eve";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <cctype>
#include <cstdlib>
#include <string.h>
#include <utility>
#include <cstdio>
#include <set>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>
#include <assert.h>
using namespace std;
namespace mp = boost::multiprecision;

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

#define ll long long
#define LL long long

int main() {
	string s;
	map<string, int> n;
	int maxl = 0;
	string maxls;
	while (cin >> s) {
		transform(s.begin(), s.end(), s.begin(), (int (*)(int))tolower);
		if (s.length() > maxl) {
			maxl = s.length();
			maxls = s;
		}
		auto res = n.find(s);
		if (res == n.end()) n.insert(make_pair(s, 1));
		else res->second++;
	}
	int maxn = 0;
	string maxns;
	for_each(n.begin(), n.end(), [&](pair<string, int> p) {
			if (p.second > maxn) {
			maxn = p.second;
			maxns = p.first;
			}
			});
	cout << maxns << ' ' << maxls << endl;
	return 0;
}

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

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  vector<ll> sa(n+1);
  for(ll i=0;i<n;i++) {
    sa[i+1]=sa[i]+a[i];
  }
  vector<ll> aa((n+1)*n/2);
  ll temp=0;
  for(ll i=0;i<n;i++) {
    for(ll j=i+1;j<=n;j++) {
      aa[temp]=sa[j]-sa[i];
      if(j==i) {
        aa[temp]=a[i];
      }
      temp++;
    }
  }
  ll m=40;
  ll ans=0;
  temp=1;
  for(ll i=0;i<m-1;i++) {
    temp*=2;
  }
  while(m--) {
    ll count=0;
    for(ll i=0;i<aa.size();i++) {
      if((aa[i]&(ans+temp))==(ans+temp)) {
        count++;
      }
    }
    if(count>=k) {
      ans+=temp;
    }
    temp/=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int main()	{
  long long int freq[100001] = {0};
  long long n, k;
  cin >> n >> k;
  long long a, b;
  for (long long i = 0; i < n; i++)	{
    cin >> a >> b;
    freq[a] += b;
  }
  for (long long i = 1; i < 100001; i++)	{
    if (freq[i] >= k)	{
      cout << i << endl;
      break;
    }
    k -= freq[i];
  }
  return 0;
}

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

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

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

    int n, X;
    cin >> n >> X;

    vector<int> x(n);
    REP(i, n) cin >> x[i];

    if (n == 1) {
        cout << abs(X - x[0]) << '\n';
        return 0;
    }

    int g = gcd(abs(X - x[0]), abs(X - x[0]));
    REP(i, n) g = gcd(g, abs(X - x[i]));

    cout << g << '\n';
    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ;
  cin >> n ;
  int count = 0;
  map<string , int> map ;
  map["gray"] = 0;
  map["brown"] = 0;
  map["green"] = 0;
  map["skyblue"] = 0;
  map["blue"] = 0;
  map["yellow"] = 0;
  map["orange"] = 0;
  map["red"] = 0;
  map["over"] = 0;
  
  rep(i,n){
    int x ;
    cin >> x ;
    if(x<400)
      map["gray"] = 1 ;
    else if (x<800)
      map["brown"] = 1 ;
    else if (x<1200)
      map["green"] = 1 ;
    else if (x<1600)
      map["skyblue"] = 1 ;
    else if (x<2000)
      map["blue"] = 1 ;
    else if (x<2400)
      map["yellow"] = 1 ;
    else if (x<2800)
      map["orange"] = 1 ;
    else if (x<3200)
      map["red"] = 1 ;
    else 
      map["over"] ++ ;
  }
  
  count = map.at("gray") + map.at("brown") + map.at("green") + map.at("skyblue") + map.at("blue") + map.at("yellow") + map.at("orange") + map.at("red") ;
  int MIN = count;
  if( MIN == 0 )
    MIN = 1;
  int MAX = count + map.at("over");
  cout << MIN << " " << MAX << endl;
    
   

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, m, x, c[100], a[100][100], ans=10000000, buy[100]={0};
bool check(){
    int i, j, algo[10000]={0};
    for(i=0;i<n;i++){
        if(buy[i]==1){
            for(j=0;j<m;j++){
                algo[j]+=a[i][j];
            }
        }
    }
    for(i=0;i<m;i++){
        if(algo[i]<x){
            return false;
        }
    }
    return true;
}
int dfs(int cho, int money){
    if(cho==n){
        if(check()){
            ans=min(ans, money);
        }
        return 0;
    }
    cho++;
    buy[cho-1]=0;
    dfs(cho, money);
    money+=c[cho-1];
    buy[cho-1]=1;
    dfs(cho, money);
    return 0;
}
int main(){
    int i, j;
    cin >> n >> m >> x;
    for(i=0;i<n;i++){
        cin >> c[i];
        for(j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    dfs(0, 0);
    if(ans==10000000) cout << -1 <<endl;
    else cout << ans <<endl;
}

Measured memory_bytes: 3680
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from math import ceil

n=ni()
a=nl()

sa = sorted(a)[::-1]
aa = []
bb = []
for i in range(n):
  if i%2==0:
    aa.append(sa[i])
  else:
    bb.append(sa[i])

print(sum(aa)-sum(bb))


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string a, b, c;
	cin >> a >> b >> c;

	int i, j, k;
	i = j = k = 0;

	char now = a[0];
	i++;
	while(1){
		if(now == 'a'){
			if(i == a.size()){
				puts("A");
				break;
			}
			now = a[i++];
			//cout << now << endl;
		}else if(now == 'b'){
			if(j == b.size()){
				puts("B");
				break;
			}
			now = b[j++];
			//cout << now << endl;
		}else if(now == 'c'){
			if(k == c.size()){
				puts("C");
				break;
			}
			now = c[k++];
			//cout << now << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;

int main(){
	int x,y;
	cin >> x >> y;
	while(x != 0 || y != 0){
		if(x > y) swap(x,y);
		cout << x << " " << y << endl;
		cin >> x >> y;
	}
	return 0;
}


Measured memory_bytes: 3092
def bubble_sort(A, n):
	for i in range(n):
		for j in range(n-1, i, -1):
			if A[j][1] < A[j-1][1]:
				A[j], A[j-1] = A[j-1], A[j]

	print(' '.join(A))

def selection_sort(A, n):
	for i in range(n):
		minj = i
		for j in range(i, n):
			if A[j][1] < A[minj][1]:
				minj = j

		A[i], A[minj] = A[minj], A[i]

	print(' '.join(A))

if __name__ == '__main__':
	n = int(input())
	A = list(input().split())
	B = A[:]

	bubble_sort(A, n)
	print('Stable')

	selection_sort(B, n)
	print('Stable' if A == B else 'Not stable')

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

public class Hello
{
    public static void Main()
     {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var h = vars[0];
        var w = vars[1];
        var k = vars[2];

        var hCt = new List<List<int>>();

        for(int i = 0; i < h; i++)
        {
            var line = System.Console.ReadLine();
            hCt.Add(new List<int>());
            for(int j = 0; j < w; j++)
            {
                if(line[j] == '#')
                {
                    hCt[i].Add(j + 1);
                }
                
            }
        }
        var nums = Enumerable.Range(1, h).ToArray();

        List<int[]> lsth = new List<int[]>();

        for(int kumi = 1; kumi <=h; kumi++)
        {
            var combinations = Combination.Enumerate(nums, kumi, withRepetition: false);
            lsth.AddRange(combinations.ToArray());
        }

        nums = Enumerable.Range(1, w).ToArray();

        List<int[]> lstw = new List<int[]>();

        for (int kumi = 1; kumi <= w; kumi++)
        {
            var combinations = Combination.Enumerate(nums, kumi, withRepetition: false);
            lstw.AddRange(combinations.ToArray());
        }

        var ans = 0;

        for (int i = 0; i < lsth.Count; i++)
        {
            for(int j = 0; j < lstw.Count; j++)
            {
                var count = 0;
                var ct = new List<List<int>>();
                if(i != -1)
                {
                    foreach(var idx in lsth[i])
                    {
                        ct.Add(hCt[idx - 1]);
                    }
                }

                if(j != -1)
                {
                    ct.ForEach(lst => count += lst.Where(x => lstw[j].Contains(x)).Count());
                }

                if(count == k)
                {
                    ans++;
                }
            }
        }

        System.Console.WriteLine(ans);

    }

    public static class Combination
    {
        public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition)
        {
            if (k == 1)
            {
                foreach (var item in items)
                    yield return new T[] { item };
                yield break;
            }
            foreach (var item in items)
            {
                var leftside = new T[] { item };

                // item よりも前のものを除く （順列と組み合わせの違い)
                // 重複を許さないので、unusedから item そのものも取り除く
                var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

                foreach (var rightside in Enumerate(unused, k - 1, withRepetition))
                {
                    yield return leftside.Concat(rightside).ToArray();
                }
            }
        }
    }
}

Measured memory_bytes: 30220
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S;
  cin>>S;
  ll N=S.size();
  
  ll ans=0;
  for(ll i=0;i<N;i++) {
    ll count=0;
    if(S[i]=='A'||S[i]=='T'||S[i]=='G'||S[i]=='C') {
count++;
    for(ll j=i+1;j<N;j++) {
      if(S[j]=='A'||S[j]=='T'||S[j]=='G'||S[j]=='C') {
count++;
      }
      else {
break;
      }
    }
      ans=max(ans,count);
    }
  }
  
  
  
  cout<<ans<<endl;
}
      
      
      
      
      
      
      
      
      
      
      



Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e5 + 7;
int lst[Max];

int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)scanf("%d", &lst[i]);
	sort(lst + 1, lst + n + 1, greater<int>());
	ll res = 0;
	for (int i = 1; i <= k; i++)res += lst[i];
	cout << res;
}

Measured memory_bytes: 3216
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()

	if (a == b || b == c || c == a) && !(a == b && b == c) {
		_, _ = fmt.Fprintf(writer, "Yes")
	} else {
		_, _ = fmt.Fprintf(writer, "No")

	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define MOD 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail
    int n;
    cin >> n;
    int count = 0;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    count++;
    for (int i = 1; i < n; i++)
    {
        bool flag = true;
        for (int j = 0; j < i; j++)
        {
            if (arr[j] > arr[i])
                flag = false;
        }
        if (flag)
            count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//templete
int main() {
	int N;
	cin>>N;
	vll A,B;
	ll sa=0,sb=0;
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		A.pb(a);
		sa+=a;
	}
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		B.pb(a);
		sb+=a;
	}
	if(sa<sb){
		cout<<-1<<endl;
		return 0;
	}
	//あまりでソート
	vll C;
	ll lack=0,ans=0;
	for(int i=0;i<N;i++){
		C.pb(A[i]-B[i]);
		if(A[i]-B[i]<0){
			lack-=A[i]-B[i];
			ans++;
		}
	}
	sort(C.begin(),C.end(),greater<ll>());
	for(int i=0;i<N;i++){
		//cout<<lack<<endl;
		if(lack<=0)
			break;
		lack-=C[i];
		ans++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3316
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::BinaryHeap;        

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let line: Vec<i64> = read_as_vec();
    let (n, m) = (line[0], line[1]);
    let a: Vec<i64> = read_as_vec();

    let mut heap = BinaryHeap::new();

    for elem in a{
        heap.push(-elem);
    }
    let mut ops: Vec<(i64, i64)> = vec![];

    for _ in 0..m{
        let line: Vec<i64> = read_as_vec();
        ops.push((line[0], line[1]));
    }

    ops.sort_by_key(| x| -x.1);
    //println!("{:?}", ops);

    for &(b, c) in &ops{
        for _ in 0..b{
            if *heap.peek().unwrap() <= -c{
                break;
            }

            heap.pop();
            heap.push(-c);
        }
    }
    

    println!("{}", -heap.into_iter().sum::<i64>());

}


Measured memory_bytes: 11512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::string S)
{
    for (int i = 0; i < S.size(); i++)
    {
        if ((int)'Z' < (S[i] + N))
        {
            cout << (char)(S[i] + N - 26);
        }
        else
        {
            cout << (char)(S[i] + N);
        }
    }
    cout << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var  N = input[0];
  var D = input[1].split(" ").map(Number);
  var sum  = function(arr) {
      var sum = 0;
      for (var i=0,len=arr.length; i<len; ++i) {
          sum += arr[i];
      };
      return sum;
  };
var Dsum = sum(D);
var ans = 0;
for(var i= 0;i<N;i++){
  ans = ans + (D[i]*(Dsum-D[i]));
}
console.log(ans/2);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
nmx=list(map(int, input().split()))
N=nmx[0]
M=nmx[1]
X=nmx[2]
mylist=[]
for i in range(N):
    mylist.append(list(map(int, input().split())))
Ans=100000*12+1
for i in range(2**N):
    A=[0]*M
    C=0
    for j in range(N):
        if (i>>j) & 1:
            C+=mylist[j][0]
            for k in range(M):
                A[k]+=mylist[j][k+1]
    if min(A)>=X:
        Ans=min(Ans, C)
if Ans==100000*12+1:
    print(-1)
else:
    print(Ans)



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

namespace ITP1
{
    class ITP1_6_C
    {
        static void Main(string[] args)
        {
            int n;
            int b, f, r, v;

            List<List<int>> dataSet;
            // List<(int b, int f, int r, int v)> dataSet3 = new List<(int b, int f, int r, int v)>();

            int[,,] houseTable = new int[4,3,10];
            // List<int> house = new List<int>(8);

            n = int.Parse(Console.ReadLine());
            dataSet = new List<List<int>>(n);
            for (int i = 0; i < n; i++)
            {
                dataSet.Add(Console.ReadLine().Split().Select(int.Parse).ToList());
            }

            foreach (var data in dataSet)
            {
                b = data[0] - 1;
                f = data[1] - 1;
                r = data[2] - 1;
                v = data[3];
                houseTable[b, f, r] += v;
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int l = 0; l < 10; l++)
                    {
                        Console.Write($" {houseTable[i, j, l]}");
                    }
                    Console.WriteLine("");
                }
                if (!(i == 3))
                {
                    Console.WriteLine("####################");
                }
            }
            Console.ReadLine();
        }
    }
}



Measured memory_bytes: 18424
#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 n;
    cin >> n;
    if(n < 1200){
        cout << "ABC" << endl;
    }else{
        cout << "ARC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    ll N, M;

    cin >> N >> M;
    ll ans = 0ll;

    for (ll i = 1; i * i <= M; ++i) {
        if (M % i == 0) {
            ll K = i;
            ll L = M / i;

            if (L >= N) {
                chmax(ans, K);
            }

            if (K >= N) {
                chmax(ans, L);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<string> S(N);
	rep(i,N) cin >> S[i];
	int M; cin >> M;
	vector<string> T(M);
	rep(i,M) cin >> T[i];

	int key = 0;
	rep(i,M) {
		bool flag = false;
		rep(j,N) {
			if (T[i] == S[j]) {
				flag = true;
				key = 1 - key;
			}
		}
		if (flag) {
			if (key) cout << "Opened by " << T[i] << endl;
			else cout << "Closed by " << T[i] << endl;
		} else cout << "Unknown " << T[i] << endl;
	}
}


Measured memory_bytes: 3252
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>

using namespace std;

#define EPS (10e-11)

int solve() {
	
	int n;
	cin >> n;
	if( n == 0 ) return 1;

	vector< vector< long double > > src(4, vector< long double >( n ) );
	vector< vector< long double > > dist(n, vector< long double >( n, 0.0 ) );
	for( int i = 0; i < n; i++ ) {
		for( int j = 0; j < 4; j++ ) {
			cin >> src[j][i];
		}
	}

	for( int i = 0; i < n; i++ ) {
		for( int j = i + 1; j < n; j++ ) {
			long double d = sqrt( 
				(src[0][i] - src[0][j]) * (src[0][i] - src[0][j]) + 
				(src[1][i] - src[1][j]) * (src[1][i] - src[1][j]) +
				(src[2][i] - src[2][j]) * (src[2][i] - src[2][j]) );
			if( d > src[3][i] + src[3][j] + EPS ) {
				d -= src[3][i] + src[3][j];
				dist[j][i] = d;
				dist[i][j] = dist[j][i];
			}
		}
	}

	long double distsum = 0.0;
	bitset<100> flg(0);
	flg.set(0);
		
	while( flg.count() < n ) {
		long double mindist = 10e20;
		int p, q;
		for( int j = 0; j < n; j++ ) {
			if( !flg[j] ) continue;			//jは訪問済み頂点
			for( int k = 0; k < n; k++ ) {
				if( flg[k] ) continue;		//kは未訪問頂点
				if( j == k ) continue;
				if( dist[j][k] + EPS < mindist ) {
					p = j;
					q = k;
					mindist = dist[j][k];
				}
			}
		}
		distsum += mindist;
		flg.set(q);
	}

	printf("%.3llf\n",distsum);

	return 0;
}
     
int main(void){
	while(1){
		if( solve() ) break;
	}
    return 0;
}

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

using namespace std;

int main() {
	int N,K;
	cin >> N >> K;
	vector<int> P(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i];
	}
	sort(P.begin(), P.end());
	int a = 0;
	for (int i = 0; i < K; i++) {
		a += P[i];
	}
	cout << a;
}

Measured memory_bytes: 3628
N = int(input())
B = list(map(int, input().split()))
sum_A = 0

for i in range(N):
    if i == 0:
        sum_A += B[0]
    elif i == N-1:
        sum_A += B[N-2]
    else:
        sum_A += min(B[i-1], B[i])
print(sum_A)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 305;
const int INF = 2e9;
int G[N][N];
ll d[N][N];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m, L;
	cin >> n >> m >> L;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			G[i][j] = INF;
		}
		G[i][i] = 0;
	}
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		G[a][b] = G[b][a] = c;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			d[i][j] = G[i][j];
		}
	}
	
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (d[i][j] > L)
				d[i][j] = INF;
			else
				d[i][j] = 1;
		}
	}
	
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
	int q;
	cin >> q;
	while (q--) {
		int s, t;
		cin >> s >> t;
		if (d[s][t] != INF)
			cout << d[s][t] - 1 << "\n";
		else
			cout << "-1\n";
	}
	return 0;
}

Measured memory_bytes: 1664