akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 200000+5
#define eps 1e-8
#define mp make_pair
#define pb push_back
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<ll,ll> pll;
const ll MOD=998244353;
inline void read(ll &f){
    f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
ll n;
priority_queue<pair<pll,ll>,vector<pair<pll,ll> >,greater<pair<pll,ll> > > pq;
struct position{
    ll pos,dat;
    ll tar;
    bool operator <(const position &q){
        return pos<q.pos;
    }
};
position g[DMAX];
vector<ll> v[DMAX];
bool fa[DMAX];
ll cnt[DMAX];
ll DFS(ll now){
    cnt[now]=1;
    ll tot=1;
    for(int i=0;i<v[now].size();i++){
        tot=tot*DFS(v[now][i])%MOD;
    }
    cnt[now]+=tot;
    if(cnt[now]==MOD){
        cnt[now]--;
    }
    return cnt[now];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read(n);
    for(int i=1;i<=n;i++){
        read(g[i].pos),read(g[i].dat);
        g[i].tar=g[i].pos+g[i].dat;
    }
    sort(g+1,g+n+1);
    for(int i=n;i>=1;i--){
        while(!pq.empty() && g[i].tar>pq.top().first.first){
            v[i].pb(pq.top().second);
            fa[pq.top().second]=1;
            pq.pop();
        }
        pq.push(mp(mp(g[i].pos,g[i].dat),i));
    }
    ll ans=1;
    for(int i=1;i<=n;i++){
        if(!fa[i]){
            ans=ans*DFS(i)%MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 30080
N, M = map(int, input().split())
s2m = [[]for n in range(N)]
for m in range(M):
    line = list(map(int, input().split()))
    for s in line[1:]:
        s2m[s-1].append(m)
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    msc = [0 for m in range(M)]
    bit = str(bin(i))[2:].zfill(N)
    for j, b in enumerate(bit):
        if b == '1':
            for m in s2m[j]:
                msc[m] += 1
    count = 0
    for k, sc in enumerate(msc):
        if sc % 2 == p[k]:
            count += 1
    if count == M:
        ans += 1

print(ans)


Measured memory_bytes: 3064
class Heap
  attr_reader :size
  def initialize
    @heap = []
    @size = 0
  end
  def sum
    @heap.inject(:+)
  end
  def push(n)
    i = @size
    while i > 0
      pid = (i - 1) / 2
      break if n >= @heap[pid]
      @heap[i] = @heap[pid]
      i = pid
    end
    @heap[i] = n
    @size += 1
  end
  def pop
    top = @heap[0]
    @size -= 1
    n = @heap[@size]
    i = 0
    while i * 2 + 1 < @size
      cid1 = i * 2 + 1
      cid2 = cid1 + 1
      if cid2 < @size && @heap[cid2] < @heap[cid1]
        cid1 = cid2
      end
      break if @heap[cid1] >= n
      @heap[i] = @heap[cid1]
      i = cid1
    end
    @heap[i] = n
    top
  end
end

def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, m = input_a
a = input_a

q = Heap.new

a.each do |num|
  q.push(-num)
end

m.times do
  max = q.pop
  max = -(-max / 2)
  q.push(max)
end

sum = 0
while q.size != 0
  sum += -q.pop
end
puts sum

Measured memory_bytes: 11092
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
i64 x;
cin>>x;
string y;
cin>>y;
i64 n=0;
forn(i,y.size())
{
  if(y[i]!='.')
n=n*10+(y[i]-'0');
  }
  x=x*n;
  cout<<x/100;


    return 0;
  }


Measured memory_bytes: 3656
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    string s,t;
    cin >> s >> t;
    int n = s.length();
    int c=0;
    rep(i,0,n-1){
    	if(s[i]!=t[i]) c++;
    }
    cout<<c<<endl;
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
long long  n,m,s,sum=0,a,b;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a+b==0) puts("0");
	else
        printf("%lld\n",(n/(a+b))*a+min((n%(a+b)),a));
	return 0;
}


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

vector<long long> ans;
vector<long long> cnt;
vector<vector<int>> tree;

void dfs(int obj) {
    for (auto x : tree[obj]) {
        if (ans[x] == -1) {
            ans[x] = ans[obj] + cnt[x];
            dfs(x);
        }
    }
}

int main() {
    int N ,Q; cin >> N >> Q;
    tree.resize(N+1);
    ans.resize(N+1, -1);
    cnt.resize(N+1, 0);
    for (int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    for (int i = 0; i < Q; i++) {
        int p, x; cin >> p >> x;
        cnt[p] += x;
    }
    ans[1] = cnt[1];
    dfs(1);
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 22656
n = int(input())
s = [input() for _ in range(n)]
ac = str(s.count('AC'))
wa = str(s.count('WA'))
tle = str(s.count('TLE'))
re = str(s.count('RE'))
print('AC x '+ ac)
print('WA x ' + wa)
print('TLE x ' + tle)
print('RE x ' + re)

Measured memory_bytes: 16156
#include <stdio.h>
#include <stdint.h>
           
           
int        
main (void)
{          
  uint32_t  N, i, count = 0;
           
  scanf("%d", &N);
           
  for (i = 1; i < (N + 1)/2; i++) {
    if (i != N -i) {
      count++;
    }      
  }        
           
  printf("%u", count);
           
  return 0;                                                                        
} 

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

using namespace std;

// 別解
int main() {
    // 考え方メモ
    // 解説の部分文字列の考え方で解いてみる
    // 具体例：ATCODER
    // 1つ目から始まる場合、(A, AT, ATC, ATCO, ATCOD, ATCODE, ATCODER)  -> 7つ
    // 2つ目から始まる場合、(T, TC, TCO, TCOD, TCODE, TCODER)           -> 6つ
    // ・・・省略
    // 7つ目から始まる場合、(R)                                         -> 1つ
    //　合計すると、7 + 6 + 5 + 4 + 3 + 2 + 1 = 28 -> これに空文字列を1を加えて　-> 29つ
    // 抽象化
    // 長さをNとする。 N + (N - 1) + ... + 1 = N(N + 1) / 2
    // 計算量　NはMAXで10　10(10 + 1) / 2 = 55　最大で55個の文字列を調べればよい -> 個々の部分文字列操作にO(N)かかる -> 550くらいかな？

    string S;
    cin >> S;
    int N = S.size();

    string ACGT = "ACGT";
    int maxLength = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            bool found = true;
            string partialString = S.substr(i, j + 1 - i);  // 部分文字列を作成する
            for (auto ch : partialString) {                 // 一つずつ文字を検査する
                if (ACGT.find(ch) == string::npos) {
                    found = false;
                    break;
                }
            }
            maxLength = found ? max(maxLength, (int)partialString.size()) : maxLength;
        }
    }

    cout << maxLength << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
        import java.util.ArrayList;
        import java.util.Collections;
        import java.util.List;
        import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
        int int1 = Integer.parseInt(scan.next());
//        int int2 = Integer.parseInt(scan.next());
//        String str1 = scan.next();
//        String str2 = scan.next();
//        String str3 = scan.next();
        int ans_int = 0;
        String ans = "";
        ans_int = 24 + (24-int1);

        PrintWriter out = new PrintWriter(System.out);
        out.println(ans_int);
        out.flush();
        scan.close();
    }
}


Measured memory_bytes: 23764
N = int(input())
S = input()
D = 10**9+7

d = {}
for i,n in enumerate(S):
    if n in d.keys():
        d[n] += 1
    else:
        d[n] = 1

ans = 1
for i in d.values():
    ans *= i+1
print((ans-1)%D)

Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
    int i,x,y;

    for(i=1; i<=3000; i++){
        scanf("%d %d",&x,&y);

        if(x==0 && y==0){
            break;
        }else{
            if(x<y){
                printf("%d %d\n",x,y);
            }else{
                printf("%d %d\n",y,x);
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1932
using System;
class Vector2
{
    private double x, y;
    public Vector2() { x = 0.0; y = 0.0; }
    public Vector2(double i, double j) { x = i; y = j; }
    public static Vector2 operator +(Vector2 op1, Vector2 op2)
    {
        Vector2 result = new Vector2();
        result.x = op1.x + op2.x;
        result.y = op1.y + op2.y;
        return result;
    }
    public static Vector2 operator -(Vector2 op1, Vector2 op2)
    {
        Vector2 result = new Vector2();
        result.x = op1.x - op2.x;
        result.y = op1.y - op2.y;
        return result;
    }
    public double X { get { return x; } }
    public double Y { get { return y; } }
}
class _0035
{
    public static void Main()
    {
        string str;
        string[] data;
        double a, b, c, d, e, f, tA, tB, tC, tD;
        Vector2 A, B, C, D, AC, BD;
        while ((str = Console.ReadLine()) != null)
        {
            data = str.Split(',');
            A = new Vector2(double.Parse(data[0]), double.Parse(data[1]));
            B = new Vector2(double.Parse(data[2]), double.Parse(data[3]));
            C = new Vector2(double.Parse(data[4]), double.Parse(data[5]));
            D = new Vector2(double.Parse(data[6]), double.Parse(data[7]));
            AC = C - A; BD = D - B;
            a = AC.X; b = -AC.Y; c = C.X * A.Y - A.X * C.Y;
            d = BD.X; e = -BD.Y; f = D.X * B.Y - B.X * D.Y;
            tB = a * B.Y + b * B.X - c; tD = a * D.Y + b * D.X - c;
            tA = d * A.Y + e * A.X - f; tC = d * C.Y + e * C.X - f;
            Console.WriteLine((tB * tD < 0 && tA * tC < 0) ? "YES" : "NO");
        }
    }
}

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

ll N,v[100000],odd[100001],even[100001];
ll Mi[2],secondi[2],M[2],second[2];

int main(void){
    cin >> N;
    rep(i,N)cin >> v[i];
    rep(i,N){
        if(i%2)odd[v[i]]++;
        else even[v[i]]++;
    }
    
    
    for(ll i=1;i<=100000;i++){
        if(odd[i]>=M[1]){
            second[1] = M[1]; 
            M[1] = odd[i];
            secondi[1] = Mi[1];
            Mi[1] = i;
        }else if(odd[i]>=second[1]){
            second[1] = odd[i];
            secondi[1] = i;
        }
        
        if(even[i]>=M[0]){
            second[0] = M[0]; 
            M[0] = even[i];
            secondi[0] = Mi[0];
            Mi[0] = i;
        }else if(even[i]>=second[0]){
            second[0] = even[i];
            secondi[0] = i;
        }
    }
    ll ans=0;
    if(Mi[1] != Mi[0])ans =  N - M[0] -M[1];
    else{
        ans = min(N - second[0] - M[1],N-second[1]-M[0]);     
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
x,y,a,b,c=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))
al.sort(reverse=True)
bl.sort(reverse=True)
z=al[:x]+bl[:y]+cl
z.sort(reverse=True)
print(sum(z[:x+y]))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long gcd(long long x,long long y){
    //Euclidの互除法
    if(!(x%y)) return y;
    return gcd(y,x%y);
}
int main(){
    int n; cin>>n;
    int a[n]; rep(i,n) cin>>a[i];
    int ans=gcd(a[0],a[1]);
    for(int i=2;i<n;i++) ans=gcd(ans,a[i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
//#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int main()
{
	fastIO
	//inp_out();
	string s;
	cin>>s;
	ll a=count(all(s),'A');
	ll b=count(all(s),'B');
	if((a==0)||(b==0))
	{
		cout<<"No";
	}
	else
	{
		cout<<"Yes";
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define rep1(i,s,e) for(int i=s;i<e;i++)
#define rep2(i,s,e,c) for(int i=s;i>=e;i--)
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pfn() printf("\n")
#define pfs() printf(" ")
#define sfi(x) scanf("%d",&x)
#define sfi1(x,y) scanf("%d%d",&x,&y)
#define sff(x) scanf("%lf",&x)
#define sfl(x) scanf("%lld",&x)
#define memset1(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const int MAX = 1e4 + 50;
const int mod = 996873654;
int main(){
	string s,t="",pre="123";
	cin>>s;
	int count=0;
	for(int i=0;i<s.length();i++){
		t+=s[i];
		if(t!=pre){
			pre=t;
			t="";
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 1152
use proconio::input;

const M: usize = 300000;

fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut st = SegTree::new(M, std::cmp::max);
    let mut ans = 0;
    for _ in 0..n {
        input! {a: usize}
        let l = if a > k {a - k} else {0};
        let r = (a + k).min(M);
        let m = st.get(l, r + 1, None) + 1;
        st.set(a, m);
        ans = ans.max(m);
    }

    println!("{}", ans);
}


struct SegTree {
    tree: Vec<u64>,
    leaf_size: usize,
    op: fn(u64, u64) -> u64,
}

impl SegTree {
    fn new(n: usize, op: fn(u64, u64) -> u64) -> Self {
        let mut ls = 1;
        while ls < n {
            ls <<= 1;
        }
        Self {
            tree: vec![0; 2 * ls - 1],
            leaf_size: ls,
            op,
        }
    }

    fn set(&mut self, mut i: usize, v: u64) {
        i += self.leaf_size - 1;
        self.tree[i] = v;
        while i > 0 {
            i = (i - 1) / 2;
            self.tree[i] = (self.op)(self.tree[2 * i + 1], self.tree[2 * i + 2]);
        }
    }

    fn get(&self, s: usize, e: usize, rng: Option<(usize, usize, usize)>) -> u64 {
        let (i, l, r) = if let Some(rng) = rng { rng } else { (0, 0, self.leaf_size) };
        if l >= e || r <= s {
            0
        } else if l >= s && r <= e {
            self.tree[i]
        } else {
            let m = (l + r) / 2;
            let vl = self.get(s, e, Some((2 * i + 1, l, m)));
            let vr = self.get(s, e, Some((2 * i + 2, m, r)));
            (self.op)(vl, vr)
        }
    }
}


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

int main() {
	 int m, f, r;
    while(1){
        cin >> m >> f >> r;
        if(m + f + r == -3){
            break;
        }
        if(m == -1 || f == -1){
            cout << "F" << endl;
        }else if(m + f >= 80){
            cout << "A" << endl;
        }else if(m + f >= 65){
            cout << "B" << endl;
        }else if(m + f >= 50){
            cout << "C" << endl;
        }else if(m + f >= 30){
            if(r >= 50){
                cout << "C" << endl;
            }else{
                cout << "D" << endl;
            }
        }else{
            cout << "F" << endl;
        }
    }
	return 0;
}



Measured memory_bytes: 3080
N, M = gets.split.map(&:to_i)
edges = Array.new(N){[]}
M.times do
    a, b = gets.split.map(&:to_i)
    edges[a-1].push(b-1)
end
S, T = gets.split.map(&:to_i).map(&:pred)

dist = Array.new(N){Array.new(3)}
dist[S][0] = 0
que = [[S, 0]]
while que.size > 0
    i, x = que.shift
    y = (x+1) % 3
    edges[i].each do |j|
        unless dist[j][y]
            dist[j][y] = dist[i][x] + 1
            que.push([j, y])
        end
    end
end

ans = dist[T][0] || -3
puts ans/3

Measured memory_bytes: 18300
#include <iostream>
using namespace std;
int main()
{
int x,y;
while(cin>>x>>y){
  if(x==0&&y==0)
  return 0;
if(x<=y)
cout<<x<<" "<<y<<endl;
else if(y<=x)
cout<<y<<" "<<x<<endl;
}
return 0;
}

Measured memory_bytes: 3024
var input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/g);
var n = input[0] - 0;
var a = 1;
for (var i = 0; i < n; i++) {
    a = (a * (i + 1)) % 1000000007;
}
console.log(a);


Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<int> ivec;
typedef pair<int, int> ipair;

int main() {
    int a, b, c, d;
    cin >> a >> b>> c>>d;
    cout << min(a,b) + min(c,d) << endl;
    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<math.h>

#define N 200000

int main(void){
  int k, n, a[N], dis, maxDis=0;
  scanf("%d %d",&k,&n);
  for(int i=0; i<n; i++)
    scanf("%d",&a[i]);
  
  for(int i=0; i<n-1; i++){
    dis = a[i+1]-a[i];
    if(maxDis < dis)
      maxDis = dis;
  }
  dis = k - a[n-1] + a[0];
  if(maxDis < dis)
      maxDis = dis;
  
  printf("%d",k-maxDis);
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int MAX = 100001;

class TaskD {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int n;
		cin >> n;
		vector<int> vis(1000005, 0);
		vector<int> nums(n);
		for(int i = 0; i < n; i++){
			cin >> nums[i];
			vis[nums[i]]++;
		}
		int ans = 0;
		for(int i = 0; i < n; i++){
			vis[nums[i]]--;
			bool ok = true;
			for(int div = 1; div * div <= nums[i] and ok; div++){
				if(nums[i] % div == 0){
					if(vis[div] > 0){
						ok = false;
					}
					if(vis[nums[i]/div] > 0){
						ok = false;
					}
				}
			}
			vis[nums[i]]++;
			ans += ok;
		}
		cout << ans << endl;

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskD solver;
	solver.solve();
	return 0;
}


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

#define ll long long int

int main(){
	int n;  cin >> n;
    vector<int> p(n),srtd;
    for(auto &it:p)
        cin >> it;
    srtd = p;
    sort(srtd.begin(),srtd.end());

    int diff=0;
    for(int i=0;i<n;i++)
        diff += (srtd[i] != p[i]);
    
    if(diff == 0 || diff==2)
        cout << "YES\n";
    else 
        cout << "NO\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int power(ll x, ll y){
    ll res = 1; 
    while(y > 0){
        if (y & 1) res = res * x % MOD;
        x = x * x % MOD;
        y >>= 1;
    }
    return res;
}
int main(){
    ll m, n; cin >> m >> n;
    cout << power(m, n) << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;



int main() {
    int n; cin >> n;
    vector<ll> as(n);
    ll t = 0; 
    rep(i, n) {
        cin >> as[i];
        t ^= as[i];
    }
    rep(i, n) {
        ll a = t^as[i];
        cout << a << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4784
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
int main()
{
    int n; cin >> n;
    vector< int > v(n);
    long long int sum=0;
    map< int , int > mp;
 
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
        sum+=v[i];
        mp[v[i]]++;
    }
 
    int tt; cin >> tt;
 
    while(tt--)
    {
        int a,b; cin >> a >> b;
 
        sum-=(mp[a]*a);
        sum+=(mp[a]*b);
        mp[b]=mp[b]+mp[a];
        mp.erase(a);
        cout << sum << endl;
    }
 
 
 
 
    #ifdef TarekHasan
        main();
    #endif // TarekHasan
 
    return 0;
}

Measured memory_bytes: 6308
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            ans += temp - 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25428
// atcoder/abc171/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

const int N = 2 * 1e6 + 5;

namespace math {
  lli fact[N], finv[N], inv[N];

  void init()
  {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < N; i++){
      fact[i] = fact[i - 1] * i % mod;
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }

  lli mod_comb(int n, int k)
  {
    assert(n < N && k < N);
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fact[n] * (finv[k] * finv[n - k] % mod) % mod;
  }

  lli extgcd(lli a, lli b, lli& x, lli& y)
  {
    lli g = a;
    x = 1;
    y = 0;
    if (b != 0) {
      g = extgcd(b, a % b, y, x);
      y -= (a / b) * x;
    }
    return g;
  }

  lli mod_inverse(lli a, lli m)
  {
    lli x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
  }
  // nHm=n+m-1Cm

  lli mod_pow(lli n, lli p)
  {
    if (p == 0) return 1;
    if (p == 1) return n;
    lli m = mod_pow(n, p / 2);
    m *= m;
    m %= mod;
    if (p % 2) m = (m * n) % mod;
    return m;
  }
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  math::init();

  int k;
  str s;
  while (cin >> k >> s) {
    lli x = 0;
    for (int i = 0; i <= k; ++i) {
      lli a = math::mod_pow(25, k - i);
      lli b = math::mod_comb(s.size() + k - i - 1, s.size() - 1);
      lli c = math::mod_pow(26, i);
      x += (((a * b) % mod) * c) % mod;
      x %= mod;
    }
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 51136
parseInt(x) = parse(Int,x)

function f(p,q,r,k)
  if p > q > r
      k = k+1
  elseif r > q > p
      k = k+1
  end
  return(k)
end

function main()
  n = parseInt(readline())
  p = map(parseInt,split(readline()))
  k=0
  for i=2:(n-1)
    k = f(p[i-1],p[i],p[i+1],k)
  end
  println(k)
end

main()

Measured memory_bytes: 170888
#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 d;
  cin >> d;

  if (d == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  } else if (d == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else if (d == 24) {
    cout << "Christmas Eve" << endl;
  } else {
    cout << "Christmas" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	int n;
	cin >> n;

	vi num = vi(100001,0);
	ll ans = 0;
	REP(i, n) {
		int a;
		cin >> a;
		num[a]++;
		ans += a;
	}

	int q;
	cin >> q;
	REP(i, q) {
		int b, c;
		cin >> b >> c;
		ans += (c - b)*num[b];
		num[c] += num[b];
		num[b] = 0;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3724
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;

const int N=200005;
const int inf=1000000000;

struct node{
	int x,y;
	node(){}
	node(int x,int y):x(x),y(y){}
}a[N],b[N];
int p1,p2,n,m,s1,s2,mn,mx;
ll ans;
int c[N];

ll solve1(){
	int i;
	s1=a[p1].y-a[p2].y;
	s2=a[p1].x-a[p2].x;
	for (i=1;i<=n;i++) if (i!=p1&&i!=p2){
		s1=max(s1,a[p1].y-a[i].y);
		s2=max(s2,a[i].x-a[p2].x);
	}
	return 1ll*s1*s2;
}

bool cmp1(node a,node b){
	return a.x<b.x;
}

bool cmp2(node a,node b){
	return a.y<b.y;
}

void work(int mxl,int mnl,int id){
	int i,cnt=0;
	for (i=1;i<=m;i++) if (i!=id){
		if (b[i].y<=mxl){
			mnl=min(mnl,b[i].y);
			cnt++;
			continue;
		}
		if (b[i].x<=mxl) mnl=min(mnl,b[i].x);
		else return;
	}
	s2=min(s2,mxl-mnl);
}

void check(int mxl,int mnl){
	s2=min(s2,mxl-mnl);
}

ll solve2(){
	int i,j,mxx;
	mn=min(a[p1].x,a[p2].y);
	mx=max(a[p1].x,a[p2].y);
	s1=a[p1].y-a[p2].x;
	s2=inf;
	for (i=1;i<=n;i++)
		if (i!=p1&&i!=p2) b[++m]=a[i];
	sort(b+1,b+1+m,cmp1);
	work(max(mx,b[m].x),mn,m); mxx=b[m].x;
	sort(b+1,b+1+m,cmp2);
	c[m+1]=inf; j=0;
	for (i=m;i>=1;i--) c[i]=min(c[i+1],b[i].x);
	for (i=1;i<=m;i=j+1) if (b[i].y>=mxx){
		j=i;
		while (j<m&&b[j+1].y==b[j].y) j++;
		check(max(mx,b[i].y),min(mn,min(b[1].y,c[j+1])));
	}
	else j=i;
	return 1ll*s1*s2;
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
		if (a[i].x>a[i].y) swap(a[i].x,a[i].y);
	}
	p1=p2=1;
	for (i=1;i<=n;i++){
		if (a[i].y>a[p1].y) p1=i;
		if (a[i].x<a[p2].x) p2=i;
	}
	if (p1==p2){
		for (i=1;i<=n;i++){
			if (a[i].y==a[p1].y&&i!=p2){
				p1=i;
				break;
			}
			if (a[i].x==a[p2].x&&i!=p1){
				p2=i;
				break;
			}
		}
	}
	ans=solve1();
	if (p1!=p2) ans=min(ans,solve2());
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  vector<int> t(n), v(n);
  int sumt = 0;
  rep(i, n) {
    cin >> t[i];
    sumt += t[i];
  }
  vector<int> tt(n);
  tt[0] = t[0];
  for(int i=1; i<n; i++) {
    tt[i] = tt[i-1] + t[i];
  }
  rep(i, n) cin >> v[i];

  vector<int> vec(sumt+1);
  
  int pos = 1;
  int nowv = 0;
  for(int i=0; i<n; i++) {
    while(pos <= tt[i]) {
      if (nowv+1 <= v[i]) {
        nowv++;
      } else {
        nowv = v[i];
      }
      vec[pos] = nowv;
      pos++;
    }
  }

  vec[sumt] = 0;
  pos = sumt-1;
  nowv = 0;
  for(int i=n-1; i>=0; i--) {
    while(i == 0 || pos >= tt[i-1]) {
      if (pos == 0) break;
      if (nowv+1 <= v[i]) {
        nowv++;
      } else {
        nowv = v[i];
      }
      chmin(vec[pos], nowv);
      pos--;
    }
  }

  double ans = 0;
  for(int i=0; i<sumt; i++) {
    //debug(i);debugln(vec[i]);
    if (vec[i] != vec[i+1]) {
      ans += (vec[i]+vec[i+1])/(double)2.0;
    } else {
      ans += vec[i];
      auto p = distance(tt.begin(), upper_bound(tt.begin(), tt.end(), i));
      //debugln(p);
      if (v[p] > vec[i]) {
        ans += (double)1.0/4;
      }
    }
  }
  cout << setprecision(15) << ans << endl;
}


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


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

    if (s.at(0) != s.at(1) || s.at(1) != s.at(2) || s.at(2) != s.at(0))
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt, readLine}

object Main extends App {
  val n = readInt
  val numbers = readLine.split(" ").map(_.toInt) :+ 0
  val q = readInt
  var ans = 0
  readLine.split(" ").foreach( key => {
    ans += linerSearch(n, numbers, key.toInt)
  })
  println(ans)

  def linerSearch(n: Int, numbers: Array[Int], key: Int): Int = {
    numbers(n) = key
    var i = 0
    while (numbers(i) != key) {
      i += 1
    }
    if (i == n) 0 else 1
  }
}



Measured memory_bytes: 46520
MOD = 10 ** 9 + 7
INF = 10 ** 20
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n = int(input())
    a = list(map(int,input().split()))
    if n%2 == 0:
        ans1 = 0
        ans2 = 0
        for i in range(n):
            if i%2 == 0:
                ans1 += a[i]
            else:
                ans2 += a[i]
        ans = max(ans1,ans2)

        cuml = [0] * (n + 1)
        cumr = [0] * (n + 1)

        for i in range(n):
            if i == 0:
                cuml[i + 1] = a[i]
            else:
                cuml[i + 1] = cuml[i - 1] + a[i]
        
        for i in range(n - 1,-1,-1):
            if i == n - 1:
                cumr[i] = a[i]
            else:
                cumr[i] = cumr[i + 2] + a[i]
        
        for i in range(1,n - 2,2):
                ans = max(ans,cuml[i] + cumr[i + 2])
    
    else:
        cuml = [0] * (n + 1)
        cumr = [0] * (n + 1)
        cumr2 = [0] * (n + 1)

        for i in range(n):
            if i == 0:
                cuml[i + 1] = a[i]
            else:
                cuml[i + 1] = cuml[i - 1] + a[i]
        
        for i in range(n - 1,-1,-1):
            if i == n - 1:
                cumr[i] = a[i]
                cumr2[i] = a[i]
            else:
                cumr[i] = cumr[i + 2] + a[i]
                if i%2 == 1:
                    if i == n - 2:
                        continue
                    if i == n - 4:
                        cumr2[i] = cumr2[i + 3] + a[i]
                    else:
                        cumr2[i] = max(cumr2[i + 2],cumr[i + 3]) + a[i]

        cumr.append(0)
        ans = -INF
        for i in range(n):
            ans = max(ans,cuml[i] + cumr[i + 2])
            if i <= n - 6 and i%2 == 1:
                ans = max(ans,cuml[i] + cumr2[i + 2])
            if i <= n - 4 and i%2 == 1:
                ans = max(ans,cuml[i] + cumr[i + 3])
    
    print(ans)

if __name__ =='__main__':
    main()  


Measured memory_bytes: 94756
package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	bs := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		bs[i] = eGetInt(scanner)
	}
	as := make([]int, n)
	copy(as[1:], bs)
	as[0] = as[1]
	sum := 0
	for i := 0; i < len(as)-1; i++ {
		if max(as[i], as[i+1]) > bs[i] {
			as[i] = bs[i]
		}
		sum += as[i]
	}
	sum += as[len(as)-1]
	fmt.Println(sum)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
from sys import stdin

def read_matrix(n):
    A = []
    for _ in range(n):
        a = [ int(i) for i in stdin.readline().strip().split() ]
        A.append(a)
    return A

def prim(n, A):
    color = [ 'WHITE' for i in range(n) ]
    d = [ float('inf') for i in range(n) ]
    d[0] = 0
    p = [-1] * n

    while True:
        mincost = float('inf')
        for i in range(n):
            if color[i] != 'BLACK' and d[i] < mincost:
                mincost = d[i]
                u = i

        if mincost == float('inf'):
            break

        color[u] = 'BLACK'

        for v in range(n):
            if color[v] != 'BLACK' and A[u][v] != -1:
                if A[u][v] < d[v]:
                    d[v] = A[u][v]
                    p[v] = u
                    color[v] = 'GRAY'

    return sum(d)

n = int(input())
A = read_matrix(n)
print(prim(n, A))


Measured memory_bytes: 5904
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()

int n, m;
int h[(int)1e5+10];
set <int> g[(int)1e5+10];
int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) cin >> h[i];
	int ans = 0;
	while(m--) {
        int u, v;
        cin >> u >> v;
        g[u].insert(v);
        g[v].insert(u);
	}
	for(int i = 1; i <= n; ++i) {
        bool ch = 1;
        for(auto to : g[i]) ch &= (h[i] > h[to]);
        if(ch) ans++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 18076
#include <iostream>

using namespace std;

int main(void)
{
    int n;
    int p[11];
    int max;
    int max_index;

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        if (i == 1 || max < p[i]) {
            max = p[i];
            max_index = i;
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i == max_index) {
            ans += p[i] / 2;
        }
        else {
            ans += p[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c){
    stack<int> S;
    S.push(r);
    color[r] = c;
    while(!S.empty()){
        int u = S.top(); S.pop();
        for(int i=0;i<G[u].size();i++){
            int v = G[u][i];
            if(color[v]==NIL){
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assignColor(){
    int id = 1;
    for(int i=0;i<n;i++) color[i] = NIL;
    for(int u=0;u<n;u++){
        if(color[u] == NIL) dfs(u,id++);
    }
}

int main(){
    int s,t,m,q;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d %d",&s,&t);
        G[s].push_back(t);
        G[t].push_back(s);
    }
    
    assignColor();

    scanf("%d",&q);

    for(int i=0;i<q;i++){
        scanf("%d %d",&s,&t);
        if(color[s]==color[t]){
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }
}

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

int main() {
  int n,m;cin>>n>>m;
  vector<int> h(n);
  vector<bool> ans(n,true);
  rep(i,n)cin>>h[i];
  rep(i,m){
    int a,b;cin>>a>>b;
    a--;b--;
    if(h[a]<=h[b])ans[a]=false;
    if(h[b]<=h[a])ans[b]=false;
  }
  int cnt=0;
  rep(i,n){
    if(ans[i]==true)cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3788
#include <stdio.h>

int main(void){
	int a, b, r;
	scanf("%d %d",&a,&b);
	
	while(1){
		r = a%b;
		a = b;
		b = r;
		if(r==0)break;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  string s1,s2;
  cin>>s1>>s2;
  s1.pb('6');
  ll ans=1;
  ll cu=0;
  rep(i,n){
    if(s1[i]!=s1[i+1]){
      
      if(i==0) ans*=3;
      else if(cu) {
        cu=0;
        continue;
      }
      else{
        
        ans*=2;
      ans%=MOD;
      }
    }
    else{
      if(i==0){
        ans*=6;
      }
      else if(cu){
        ans*=3;
        ans%=MOD;
      }
      else{
        
        ans*=2;
        ans%=MOD;
      }
      i++;
      cu=1;
      
    }
  }
  COUT(ans);
}

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

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

    int pos = 0;
    if ((s[0] - '0') * 10 + (s[1] - '0') > 0 && (s[0] - '0') * 10 + (s[1] - '0') < 13)
        pos += 1;
    if ((s[2] - '0') * 10 + (s[3] - '0') > 0 && (s[2] - '0') * 10 + (s[3] - '0') < 13)
        pos += 2;
    if (pos == 0)
        cout << "NA" << endl;
    if (pos == 1)
        cout << "MMYY" << endl;
    if (pos == 2)
        cout << "YYMM" << endl;
    if (pos == 3)
        cout << "AMBIGUOUS" << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check


void solve(long long n, std::vector<long long> a){
    sort(ALL(a));
    ll B = a[n-1];
    auto it = lower_bound(ALL(a), B/2);
    
    if(it == a.begin()){
        cout << B << " " << *it << endl;
        return;
    }
    auto it1 = it--;
    if(abs((*it)*2-B)<= abs((*it1)*2-B)){
        cout << B << " " << *it << endl;
    }
    else{
        cout << B << " " << *it1 << endl;
    }
}

int main(){
    long long n;
    scanf("%lld",&n);
    std::vector<long long> a(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&a[i]);
    }
    solve(n, std::move(a));
    return 0;
}


Measured memory_bytes: 1024