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

using namespace std;

map<int,int> m;
int n;
int a, ans1, ans2, cnt;

int main() {
    scanf("%d", &n);
    for(int i = 0, t; i < n; i++) {
        scanf("%d", &t);
        m[t]++;
    }
    for(auto itr = m.rbegin(); itr != m.rend(); itr++) {
            int a = itr -> second;
            if(a <= 1) continue;
            if(a >= 4 && cnt == 0) {
                ans1 = itr -> first;
                ans2 = itr -> first;
                cnt += 2;
            }
            else if(a >= 2 && cnt != 2) {
                if(cnt == 1) ans2 = itr -> first;
                else if (cnt == 0) ans1 = itr -> first;
                cnt++;
            }
            if(cnt == 2) return (!printf("%lld", 1ll * ans1 * ans2));
    }
    printf("0");
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

ll mod = 1000000007;
string S;
vector<vector<ll>> dp(100005,vector<ll>(13,0));

int main(){
    cin >> S;
    int N = (int)S.size();

    for (int i = 0; i < N;i++){
        char c = (char)S[i];
        int t = c - '0';
        if(c == '?')
            t = -1;
        dp[0][0] = 1;
        for (int j = 0; j < 10;j++){
            if(t != -1 && t != j)
                continue;
            for (int k = 0; k < 13;k++){
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        for (int j = 0; j < 13;j++){
            dp[i + 1][j] %= mod;
        }
    }
    cout << dp[N][5] << endl;
    return 0;
}

Measured memory_bytes: 13824
#include <iostream>
#include <cmath>
using namespace std;
bool ip(long long n){
    if (n == 2)
        return true;
    else if (n < 2 || n % 2 == 0)
        return false;
    for (long long i = 3; i <= sqrt(n); i++)
        if (n % i == 0)
            return false;
    return true;
}
int main() {
    long long n, x, ans = 0;
    cin >> n;
    for (long long i = 0; i < n; i++) {
        cin >> x;
        if (ip(x))
            ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3056
s = input()[::-1]
l = len(s)
x = [0 for _ in range(2019)]
x[0] += 1
k = 0
p = 1
for si in s:
    k += int(si) * p % 2019
    k %= 2019
    x[k] += 1
    p *= 10
    p %= 2019

ans = 0
for xi in x:
    ans += max(0, xi * (xi - 1) // 2)
print(ans)


Measured memory_bytes: 9216
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		UnionFind uf = new UnionFind(num);
		int numEdge = sc.nextInt();
		int edge[][] = new int[numEdge][2];
		for(int i = 0; i < numEdge; i ++) {
			edge[i][0] = sc.nextInt() - 1;
			edge[i][1] = sc.nextInt() - 1;
		}

		long ans[] = new long[numEdge + 1];
		ans[numEdge] = (long) num * (num - 1) / 2;
		for(int i = numEdge - 1; i >= 0; i --) {
			ans[i] = ans[i + 1];
			if(!uf.same(edge[i][0], edge[i][1])) {
				ans[i] -= (long) uf.getSize(edge[i][0]) * uf.getSize(edge[i][1]);
				uf.unite(edge[i][0], edge[i][1]);
			}
		}

		for(int i = 1; i <= numEdge; i ++) {
			System.out.println(ans[i]);
		}
	}
}

class UnionFind {
	int parent[];
	int size[];

	public UnionFind(int num) {
		parent = new int[num];
		size = new int[num];
		for(int i = 0; i < num; i ++) {
			initNode(i);
		}
	}

	public void initNode(int i) {
		parent[i] = i;
		size[i] = 1;
	}

	public void unite(int x, int y) {
		int xRoot = getRoot(x);
		int yRoot = getRoot(y);
		if(size[yRoot] > size[xRoot]) {
			parent[xRoot] = yRoot;
			size[yRoot] += size[xRoot];
		}else {
			parent[yRoot] = xRoot;
			size[xRoot] += size[yRoot];
		}
	}

	public int getSize(int i) {
		return size[getRoot(i)];
	}

	public int getRoot(int i) {
		if(i != parent[i]) {
			parent[i] = getRoot(parent[i]);
		}
		return parent[i];
	}

	public boolean same(int x, int y) {
		return getRoot(x) == getRoot(y);
	}
}

Measured memory_bytes: 101332
#include <stdio.h>
#include <stdlib.h>
long int a[210000]={0};
int main()
{
    long int i,j,n,k=0,min;
    scanf("%ld",&n);
    for(i = 1;i <= n;i++)
        scanf("%ld",&a[i]);
    min = a[1];
    for(i = 1;i <= n;i++)
    {
        if(a[i] <= min)
            min = a[i],k++;
    }

    printf("%ld",k);
    return 0;
}

Measured memory_bytes: 1664
N = int(input())
p = [i for i in map(int,input().split())]
p_sorted = sorted(p)
count = 0
for i in range(len(p)):
    if p[i] != p_sorted[i]:
        count +=1
if (count == 0) or (count ==2):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long X = scan.nextLong();
        long[] x = new long[N+1];
        x[0] = X;
        for (int i = 1; i <= N; i++) {
            x[i] = scan.nextLong();
        }
        Arrays.sort(x);
        long[] dx = new long[N];
        for (int i = 0; i < N; i++) {
            dx[i] = x[i+1] - x[i];
        }
        System.out.println(gcd_list(dx));
    }
    public long gcd(long x, long y) {
        if (y == 0) {
            return x;
        }
        return gcd(y, x % y);
    }
    public long gcd_list(long [] x) {
        long answer = 0;
        for (int i = 0; i < x.length; i++) {
            answer = gcd(x[i], answer);
        }
        return answer;
    }
}


Measured memory_bytes: 51036
C = input().split()

A = int(C[0])
B = int(float(C[1])*100+0.5)



E = A*B



if E < 100:
    print(0)
elif E < 200:
    print(1)
elif E < 300:
    print(2)
else:
    F = str(E)
    print(F[0:len(F)-2])

Measured memory_bytes: 9192
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <algorithm>


typedef std::vector<int> liste;

bool solve(int i,int m,liste& list) {
    if(m==0) {
        return true;
    }
    if(m<0||i>=list.size()) {
        return false;
    }
    return (solve(i+1,m,list)||solve(i+1,m-list[i],list));
} 
    
int main(void){
        
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int value;
    int n;
    std::cin >> n;
    liste list(n);
    for(int i=0; i<n; i++) {
        std::cin >> list[i];
    } 
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        std::cout << (solve(0,value,list) ? "yes" : "no") << std::endl;
    } 
    
    return 0;
}

Measured memory_bytes: 1192
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
Asum = sum(A)
Bsum = sum(B)
yoy = []
mnu = []
test = []

if Asum < Bsum:
    flg = "NO"

else:
    flg = "YES"
    for n in range(N):
        a = A[n]
        b = B[n]
        if a >= b:
            test.append(a-b)
            yoy.append(a-b)
        else:
            test.append(a-b)
            mnu.append(a-b)
    min_num = len(mnu)#結果に足す
    min_sum = sum(mnu)#これより大きく

    yoy.sort(reverse=True)

    ynum = 0
    counter = 0
    if min_num != 0:
        for y in yoy:
            counter += 1
            ynum += y
            if ((ynum+min_sum) >= 0):
                break

if flg == "YES":
    print(min_num+counter)
else:
    print(-1)


Measured memory_bytes: 19964
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int main()
{
    set<int > s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int c,t;
        cin>>c;
        if(c==0)
        {
            cin>>t;
            s.insert(t);
            cout<<s.size()<<endl;
        }
        else
        {
            cin>>t;
            if(s.find(t)==s.end())
            {
                cout<<0<<endl;
            }
            else 
            cout <<1<<endl;
        }
    }
    
}


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

#define int long long
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define fs first
#define sc second
#define mpr make_pair
#define iter iterator
#define all(X) X.begin(),X.end()
#define sau(X) sort(all(X)),X.resize(unique(all(X))-X.begin())
#define exist(X,ele) binary_search(all(X),ele)
#define y0 I_love_Ryougi_Shiki_0
#define y1 I_love_Ryougi_Shiki_1

template<typename T1,typename T2>
ostream& operator << (ostream& out,const pair<T1,T2>& X)
{
	out<<"{"<<X.fs<<","<<X.sc<<"}";
	return out;
}

template<typename T>
ostream& operator << (ostream& out,const vector<T>& X)
{
	for(auto i:X) out<<i<<" ";
	return out;
}

template<typename T>
inline void cmin(T& x,T y)
{
	if(!(x<y)) x=y;
}

template<typename T>
inline void cmax(T& x,T y)
{
	if(x<y) x=y;
}

const int inf=5000000000000000ll;
const int mod=1000000007;

int dp[310][310][310]; // i edges | j points in total | k points can reach 1

main()
{
	ios::sync_with_stdio(false);
	
	int N,M; cin>>N>>M;
	dp[0][1][1]=1;
	for(int i=0;i<M;i++)
	{
		for(int j=1;j<=N && j<=i+1;j++)
		{
			for(int k=1;k<=j;k++)
			{
				if(dp[i][j][k]==0) continue;
				dp[i+1][j+1][k]+=dp[i][j][k]*(N-j)%mod;dp[i+1][j+1][k]%=mod; // nxt=white->grey
				dp[i+1][j][k]+=dp[i][j][k]*(j-k)%mod;dp[i+1][j][k]%=mod; // nxt=grey
				dp[i+1][j][j]+=dp[i][j][k]*k%mod;dp[i+1][j][j]%=mod; // nxt=black all grey->black
			}
		}
	}
	cout<<dp[M][N][N]<<endl;
	
	return 0;
}



















Measured memory_bytes: 225536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string ch,str;
    int flag;
    while(cin>>str>>ch)
    {
        flag=0;
        if(str.size()==ch.size()-1)
        {
            for(int i=0;i<str.size();i++)
            {
                if(str[i]==ch[i])
                {
                    continue;
                }
                else
                {
                    flag=1;
                    break;
                }
            }
            if(flag==1)
            {
                cout<<"No"<<endl;
            }
            else
            {
                cout<<"Yes"<<endl;
            }
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int k,n;
  cin>>k>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int ans=a[0]+k-a[n-1];
  rep(i,0,n-1){
    ans=max(ans,a[i+1]-a[i]);
  }
  cout<<k-ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

int main()
{
	lint X,Y;
	lint ans=0;
	
	cin >> X >> Y;
	for(lint i=1;;i*=2)
	{
		if(X*i<=Y)ans++;
		else break;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

  int n;
  int i, j, sum=0, ans;

  scanf("%d", &n);

  int x[n];

  for (i = 0; i < n; i++)
    scanf("%d", &x[i]);

  for (i = 0; i < n; i++)
    ans += x[i] * x[i];

  for (i = 1; i <= 100; i++) {
    sum = 0;
    for (j = 0; j < n; j++)
      sum += (i - x[j]) * (i - x[j]);
    if (ans > sum)
      ans = sum;
  }

  printf("%d", ans);


  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<pair<int,int>,ll> i_i_l;
typedef pair<int,ll> i_l;
int main(){
  int n;
  cin >> n;
  int i,j,k,b,c;
  while(n!=0){
    vector <i_l> date;
    i_l buf;
    int x,y;
    for(i=0;i<n;i++){
      cin >> c >> buf.second;
      buf.first=0;
      for(j=0;j<c;j++){
	cin >> x >> y;
        x-=6;
        y-=6;
	for(k=x;k<y;k++) buf.first+=1<<k;
	
      }
      date.push_back(buf);
    }
    
    ll dp[1<<16]={};
    for(i=0;i<n;i++){
      for(int S=0;S<1<<16;S++){
	if((S&date[i].first)==date[i].first){
	  dp[S-date[i].first]=max(dp[S-date[i].first],dp[S]+date[i].second);
	}
      }
    }
    ll o=0;
    for(int S=0;S<1<<16;S++){
      o=max(o,dp[S]);
    }
    cout << o << endl;

    cin >> n;
  }
}

Measured memory_bytes: 1724
n = int(input())
c = {s: 0 for s in 'MARCH'}
for i in range(n):
    s = input()[0]
    if s in 'MARCH':
        c[s]+=1

c = [v for k, v in c.items()]

ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans+=c[i]*c[j]*c[k]
print(ans)

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

#define ll long long 


ll gcd(ll a, ll b) {
  return a % b ? gcd(b, a % b) : b;
}


int main() {
  int N;
  cin >> N;
  
  vector<ll> time(N);
  for (int i = 0; i < N; i++) {
    cin >> time[i];
  }
  
  ll ans = time[0];
  for (int i = 0; i < N-1; i++) {
    ll LCM = time[i] * (time[i+1] / gcd(time[i], time[i+1]));
    ans = ans * (LCM / gcd(ans, LCM));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3616
import numpy as np

D=int(input())
C=np.array(list(map(int,input().split())))
S=[]
S_sa=[]
sa=[]
for i in range(D):
    s=np.array(list(map(int,input().split())))
    sa=s-C
    S_sa.append(sa)
    S.append(s)

minus=365*sum(C)

for i in range(D):
    A=S_sa[i].tolist()
    ma=max(S_sa[i])
    print(A.index(ma)+1)


Measured memory_bytes: 27504
a = gets.strip.split.map(&:to_i)

perms = [
    [a[0], a[1], a[2]],
    [a[0], a[2], a[1]],
    [a[1], a[0], a[2]],
    [a[1], a[2], a[0]],
    [a[2], a[0], a[1]],
    [a[2], a[1], a[0]],
]

def cost(p)
    (p[0] - p[1]).abs + (p[1] - p[2]).abs
end

puts perms.map { |p| cost(p) }.min

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n+2];
		array[0] = 0;
		array[n+1] = 0;
		for(int i = 1; i < n+1;i++) array[i] = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < n+1;i++) sum += Math.abs(array[i] - array[i+1]);
		for(int i = 1; i < n+1;i++) System.out.println(sum - Math.abs(array[i-1] - array[i]) - Math.abs(array[i] - array[i+1]) + Math.abs(array[i-1] - array[i+1]));
	}
}

Measured memory_bytes: 65280
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	vector<string> s(n);
	VI t(n);
	REP(i, n) { cin >> s[i] >> t[i]; }
	string x;
	cin >> x;
	int result = 0;
	bool is_sleep = false;
	REP(i, n) {
		if(is_sleep) {
			result += t[i];
		}
		if(s[i] == x) {
			is_sleep = true;
		}
	}
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int a[4], b[4];
int main()
{
    string L, R;
    while (cin >> L >> R) {
        int l = (L[0]-'0')*10 + L[2]-'0';
        int r = (R[0]-'0')*10 + R[2]-'0';
        if (l >= 11) a[0]++;
        else if (l >= 6) a[1]++;
        else if (l >= 2) a[2]++;
        else a[3]++;
        if (r >= 11) b[0]++;
        else if (r >= 6) b[1]++;
        else if (r >= 2) b[2]++;
        else b[3]++;
    }
    for (int i=0; i<4; ++i) cout << a[i] << " " << b[i] << endl;
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N; cin >> N;
  map<int, int> mp;
  rep(i, N) {
    int a; cin >> a;
    mp[a]++;
  }

  int ans = 0;

  for (auto e: mp) {
    if (e.second > e.first) {
      ans += e.second - e.first;
    }
    if (e.second < e.first) {
      ans += e.second;
    }
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4736
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();  
        int N = r.i();
        int[] X = r.ii(), 
              copy = X.clone();
        Arrays.sort(copy);  
        for(int i = 0; i < N; i++){
            if(X[i] < copy[N/2])
                print(copy[N/2]);
            else
                print(copy[N/2-1]);
        }
    }    

    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int Int(String s){
            return Integer.parseInt(s);
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 65460
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	int n,k; cin>>n>>k;
	deque<ll> d;
	for(int i=0; i<n; i++){
		int v; cin >> v;
		d.push_back(v);
	} 
	ll ans{};
	for(int l=0; l<=min(k,n); l++){
		for(int r=0; r+l<=min(k,n); r++){
			auto d1 = d;
			int rm = k-(r+l);
			vector<int> po, ne;
			for(int i=0; i<l; i++){
				if(d.front()>=0){
					po.push_back(d.front());
					d.pop_front();
				}
				else{
					ne.push_back(d.front());
					d.pop_front();
				}
			}
			for(int i=0; i<r; i++){
				if(d.back()>=0){
					po.push_back(d.back());
					d.pop_back();
				}
				else{
					ne.push_back(d.back());
					d.pop_back();
				}
			}
			if(ne.size())sort(ne.rbegin(),ne.rend());
			for(int i=0; i<rm; i++){
				if(ne.size()){
					ne.pop_back();
				}
			}
			ll sum{};
			for(auto i:po) sum += i;
			for(auto i:ne) sum += i;
			ans = max(sum,ans);
			d = d1;
		}
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 
#define ALL(a)  (a).begin(),(a).end()
#define INF 100000000


using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
  if(a>b){
    return gcd(b,a);
  }
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}


void chmin(int &a,int b){
  if(a>b){
    a=b;
  }
}
int N,A,B,C;
vector<int>L;
int rec(int i,int a,int b,int c){
  if(i==N){
    if(!a||!b||!c){
      return INF;
    }
    //増減コストはさいごにさんしゅつする
    return abs(a-A)+abs(b-B)+abs(c-C);
  }
  //そのたけを採用しない場合
  int res=rec(i+1,a,b,c);
  //0なのは最初の一本目は合体コストがないと考えられるため
  chmin(res,rec(i+1,a+L[i],b,c)+(a?10:0));
  chmin(res,rec(i+1,a,b+L[i],c)+(b?10:0));
  chmin(res,rec(i+1,a,b,c+L[i])+(c?10:0));
  return res;


}





int main(){
  cin>>N>>A>>B>>C;
  L.resize(N);
  for(int i=0;i<N;i++){
    cin>>L[i];
  }
  cout<<rec(0,0,0,0)<<endl;
  


}






Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	map<char,int> pre;
	int n;
	cin>>n;
	rep(i,n){
		map<char,int> now;
		string s;
		cin>>s;
		if(i==0){rep(j,s.size()) now[s[j]]++;}
		else{
			rep(j,s.size()){
				if(pre[s[j]]>now[s[j]]) now[s[j]]++;
			}
		}
		pre=now;
	}
	string ans;
	itr(i,pre){
		rep(j,i->second) ans.push_back(i->first);
	}
	sort(All(ans));
	cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
 
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    # divisors.sort()
    return divisors
 
n = sorted(make_divisors(N))

sum_yakusuu = N
for _n in n:
    if _n == 1:
        continue
    if _n+N/_n < sum_yakusuu:
        sum_yakusuu = int(_n+N/_n)
        bef_n = _n
    else:
        if len(n) == 2:
            print(int(_n-1))
        else:
            print(int(bef_n+N/bef_n-2))
        break
 

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

namespace AtcoderSubmit
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var A = int.Parse(line[0]);
            var B = int.Parse(line[1]);
            var C = int.Parse(line[2]);
            var K = int.Parse(line[3]);

            var k = K;
            var a = Math.Min(A, K);
            k -= a;
            k -= B;
            var c = Math.Max(0, k);
            Console.WriteLine(a - c);
        }
    }
}


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

long long s2i(string s) {
   istringstream ss;
   ss = istringstream(s);
   long long n;
   ss >> n;
   return n;
}

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   string a, b;
   cin >> a >> b;
   int c = s2i(a + b);
   if ((int) sqrt(c) == sqrt(c)) cout << "Yes" << '\n';
   else cout << "No" << '\n';
   return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
#define v_inputrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)

int main(){
    int k;
    cin >> k;
    vll a;
    
    for(int i = 1 ; i <= 9 ; i++){
        a.push_back(i);
    }

    while(1){
        if(k <= a.size()){
            cout << a[k-1] << endl;
            return 0;
        }
        k -= a.size();
        vll old;
        swap(a, old);
        for(ll x : old){
            for(int i = -1 ; i <= 1 ; i++){
                ll d = x%10 + i;
                if(d < 0 || d > 9){continue;}
                a.push_back(x*10 + d);
            }
        }
    }


}

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

using namespace std;
const int maxn = 2e5 + 4;
int cnt[maxn];

void _accepcted_by_one_hit_()
{
    #ifdef NTMA
        freopen("abc.inp", "r", stdin);
        freopen("abc.out", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
int main()
{	
	_accepcted_by_one_hit_();
    string s; cin >> s;
    if (s.size() % 2) return cout << "No", 0;
    for (int i=0; i+1<s.size(); i+=2) if (s[i] == 'h' && s[i+1] == 'i') continue;
    else {
        cout <<"No\n";
        return 0;
    } 
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************


int main(){

    int N;
    cin >> N;

    ll mx = 0;
    vll A(N);
    ll cnt1 = 0;
    REP(i, N){
        cin >> A[i];
        if (A[i] == 1) cnt1++;
        chmax(mx, A[i]);
    }

    if (cnt1 == 1) {
        cout << 1 << endl;
        return 0;
    } else if(cnt1 > 1){
        cout << 0 << endl;
        return 0;
    }

    vll B(mx + 1, 0);

    for(ll a: A){
        ll i = a;
        while (i <= mx){
            B[i]++;
            i += a;
        }
    }

    ll ans = 0;
    for(ll a: A){
        if(B[a] == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12728
N,X,Y = map(int, input().split())
from collections import defaultdict
edges = defaultdict(list)
for i in range(N-1):
    edges[i].append([i+1,1])
    edges[i+1].append([i,1])
edges[X-1].append([Y-1,1])
edges[Y-1].append([X-1,1])
# print(edges)

import heapq
INF = 10 ** 18
def dijkstra(n, edges, s):
    """
    input
        n : 頂点数
        edges : リスト(始点, 終点, コスト)
        s : 始点
    output
        d : 始点からの最短距離
    """
    d = [INF] * n
    used = [False] * n
    d[s] = 0
    used[s] = True
    edgelist = []
    # 初期のやつ
    for v, c in edges[s]:
        # print("v{},c{}".format(v,c))
        # コストを前にしてpushしておく(そこから最小値を取り出すので)
        heapq.heappush(edgelist, (c, v))
    # 空になるまで
    while len(edgelist):
        # コスト最小値を取り出す
        c_min, v_min = heapq.heappop(edgelist)
        # そのエッジがすでに確定していたら終わり
        if used[v_min]:
            continue
        # 確定していなければ、そこから派生するエッジをコスト付与して与える
        d[v_min] = c_min
        used[v_min] = True
        for v, c in edges[v_min]:
            if not used[v]:
                heapq.heappush(edgelist, (c+c_min, v))
    return d

ans = [0] * N
for i in range(N):
    d = dijkstra(N,edges,i)
    # print(d)
    for j in range(i+1,N):
        ans[d[j]] += 1
for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 77788
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>

using namespace std;

int main(){

int x;
int a=0;
string G;
cin>>x;
a=x;
while(1){
cin>>G;
if(G=="=")break;
cin>>x;


if(G=="+")a+=x;
if(G=="-")a-=x;
if(G=="/")a/=x;
if(G=="*")a*=x;
}
cout<<a<<endl;
return 0;
}

Measured memory_bytes: 1204
//============================================================================
// Author      : JCH
// Version     :
// Copyright   :
// Description : Contest ACM
//============================================================================

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int n, x, amount;

int main() {

	cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);

	while (cin >> n >> x) {
		if (!n && !x)
			return 0;

		amount = 0;

		for (int i = 1; i <= n; ++i)
			for (int j = i + 1; j <= n; ++j)
				for (int k = j + 1; k <= n ; ++k)
					if (i + j + k == x)
						amount++;

		cout << amount << endl;

	}
	return 0;
}



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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

vector<int>P(M);
vector<tuple<int, long long, int>> city(M);
for(int i = 0; i < M; i++){ 
     cin >> P.at(i);
     int x;
     cin >> x;

    city.at(i) = make_tuple(P.at(i), x , i);
    // cout << get<0>(city.at(i)) << endl; 
}

sort(all(city));

int cas = get<0>(city.at(0));
vector<int>cnt_v(M);
int cnt = 0;
for(int i = 0; i < M; i++){ 
     if(get<0>(city.at(i)) == cas) {
        cnt++;
     }
     else {
         cnt = 1;
         cas = get<0>(city.at(i));
     }
    cnt_v.at(get<2>(city.at(i))) = cnt;

}



for(int i = 0; i < M; i++){ 
     cout << setw(6) << setfill('0') << P.at(i);
     cout << setw(6) << setfill('0') << cnt_v.at(i) << endl;
}


}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int A,B;

int main() {
    cin >> A >> B;
    int K;
    cin >> K;

    set<int> st;

    rep(i,0,K - 1){
        if(A + i <= B){
            st.insert(A + i);
        }
        if(A <= B - i){
            st.insert(B - i);
        }
    }

    for(auto ite = st.begin();ite != st.end();++ite){
        cout << *ite << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;

int N;
int H[100000];

void Input()
{
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
}

int main()
{
	Input();
	int count = 0;
	int buf = H[0];
	int ans = 0;
	for (int i = 1; i < N; i++) {
		if (buf >= H[i]) count++;
		else {
			ans = max(ans, count);
			count = 0;
		}
		buf = H[i];
	}
	ans = max(count, ans);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;

namespace Triangular_Relationship
{
    class Program
    {
        public static void Main(string[] args)
        {
            var input = GetArrayIntInput();
            var count = (long)Math.Pow(input[0] / input[1], 3);
            if (input[1] % 2 == 0)
            {
                count += (long)Math.Pow((input[0] + (input[1] / 2)) / input[1], 3);
            }
            CWrite(count);
        }

        static string[] GetArrayCharInput() => Console.ReadLine().Split();
        static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray();
        static int GetIntInput() => Console.ReadLine().ToInt();
        static void CWrite<T>(T str) => Console.WriteLine(str);

    }

    static class ExtentionsLibrary
    {
        public static int[] StringToIntArray(this string str) =>
            str.Split().Select(int.Parse).ToArray();
        public static int ToInt(this string str) => int.Parse(str);
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<ll> A(N,0);
  vector<ll> R(N,0);
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(i%2==0){
      R[0] += A[i];
    }else{
      R[0] -= A[i];
    }
  }
  R[0] /= 2;
  for(int i=1;i<N;i++){
    R[i] = A[i-1] - R[i-1];
  }
  for(int i=0;i<N;i++){
    cout << R[i]*2 << " ";
  }
}

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

int main(){
    int n,l;
    cin >>n>>l;
    string a;
    vector<string> vec;
    for(int i=0;i<n;i++){
        cin >> a;
        vec.push_back(a);
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
        cout << vec[i];
    }
    return 0;
}

Measured memory_bytes: 256
x,y,z,k=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
a,b,c=0,0,0
AB=[]
for a in A:
  for b in B:
    AB.append(a+b)
AB.sort(reverse=True)
AB=AB[:k]
ABC=[]
for ab in AB:
  for c in C:
    ABC.append(ab+c)
ABC.sort(reverse=True)
print(*ABC[:k],sep="\n")

Measured memory_bytes: 151384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 1e5+500;
const int inf = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
#define X first
#define Y second

int a[20][20];
int n;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[i][j] = -1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		int cnt;
		scanf("%d",&cnt);
		for(int j=1;j<=cnt;j++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			a[i][x] = y;
		}
	}
	int m = 1<<n;
	int ans = 0;
	for(int i=0;i<m;i++)
	{
		vector<int> tmp(n+1);
		int flag = 0;
		for(int k=0;k<n;k++)
		{
			if(((i>>k)&1) == 1)
			{
				int x = k+1;
				tmp[x] = 1;
			}
		}
		for(int x=1;x<=n;x++)
		{
			if(tmp[x] == 1)
			{	for(int j=1;j<=n;j++)
				{
					if(a[x][j] == -1)continue;
					
					if(tmp[j] != a[x][j])
					{
						flag = 1;
						break;
					}		
				}
			} 
		}
		if(flag == 0)
		{
			ans = max(ans,__builtin_popcount(i));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    //long long int a,k;
    long double b,a,e;
    
    scanf("%Lf %Lf",&a,&b);
    
    e=a*b;
    printf("%lld",(long long int)e);
    return 0;
}

Measured memory_bytes: 1760
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string S; cin >> S;
    RREP(i,S.size()-1) {
        if (i % 2 != 0) continue;
        int h = i / 2;
        bool ok = true;
        REP(j,h) {
            if (S[j] != S[h+j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            OUT(i)
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

ll gcd(ll n, ll m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        ll r = n % m;
        n = m;
        m = r;
    }
    return n;
}

int f() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if (a < b) return 0;
    if (d < b) return 0;

    a -= b;
    if (a <= c) a += d;
    if (a < b) return 0;

    if (a > c) {
        a = (a - c) % b + c;
        if (a > c) a -= b;
    }
    //c以下になるまで削った
    if (a < 0) return 0;
    if (b == d) return 1;

    //以降d>bとしてよい

    //買えなくするにはc本より多い状態からマイナスまで削りきらないといけない
    //たとえば100本買いたいなら99本になったときに足してもらえればいい 98だとダメかも
    if (c >= b - 1) return 1;

    //以下、cはbより2本以上少ない bは3本以上
    //いつか、b本買ってもc以下にならないときがくる
    //逆にダメなaというのは、cより大きくbより小さいもの にbを足したもの（引いてないもの）
    
    ll t = gcd(b, d);
    //tで割ったあまりは変化しない
    ll r = a % t;
    //tで割ったあまりがrでその範囲に入るものがあるか
    int h = 0;
    if (b - (c + 1) >= t) {
        h = 1;
    } else {
        ll r0 = (c + 1) % t;
        ll r1 = b % t;
        if (r0 > r1) {
            r1 += t;
        }
        if (r < r0) r += t;
        h = (r0 <= r && t < r1);
    }
    return h ^ 1;

    //bとdが互いに素だと仮定できれば、いつか必ず買えなくなりそう？




    //c本以下には絶対いつかなる
    //cは大きいほどいい（本当か？）
}

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

    int t;
    cin >> t;

    for (int i = 0; i < t; i++) {
        cout << (f() ? "Yes" : "No") << '\n';
    }

    cout << flush;

    return 0;
}

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

#x,y = list(map(int,input().split()))	

S=input()
k=int(input())

c=0
l=0
for i in S:
    if i != "1":
        l=i
        break
    else:
        c+=1

#print(c,l)        
if c>=k:
    print(1)
else:
    print(l)
#if :
#    print("Yes")
#else:
#    print("No")

Measured memory_bytes: 2940
inp = list(map(int, input().split()))

#print(inp)
s = inp[0]
c = inp[1]

ans = 0
if s*2 <= c:
    ans += s
    c -= 2*s
    s = 0
    if c>=4:
        ans += c//4
elif c//2<=s:
        ans += c//2
        s -= c//2
        c -= 0
else:
    if c>=4:
        ans += c//4



print (ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    Arrays.sort(a);
    int sum=0;
    for(int i=1;i<k+1;i++){
      sum+=a[n-i];
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 22868
#include <iostream>
struct node{int k,p,l,r;};
node t[500010];
using namespace std;
void find(int now,int k,int ori){
  if(k<t[now].k){
    if(t[now].l) find(t[now].l,k,ori);
    else {
      t[ori].k=k;
      t[ori].p=now;
      t[now].l=ori;
      return;
    } 
  } else {
    if(t[now].r) find(t[now].r,k,ori);
    else {
      t[ori].k=k;
      t[ori].p=now;
      t[now].r=ori;      
      return;
    }
  }
}
void pr(int now){
  cout<<" "<<t[now].k;
  if(t[now].l) pr(t[now].l);
  if(t[now].r) pr(t[now].r);
}
void in(int now){
  if(t[now].l) in(t[now].l);
  cout<<" "<<t[now].k;
  if(t[now].r) in(t[now].r);
}
int main(){
  int tmp,n;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=="insert"){
      cin>>tmp;
      if(i) find(0,tmp,i);
      else t[i].k=tmp;
    } else {
      in(0);
      cout<<endl;
      pr(0);
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 10864
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(int argc, char const* argv[])
{
  string S;
  cin >> S;
  vector<int32_t> vec(S.length(), 0);
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '1') vec[i] = 1;
  }

  size_t sz = vec.size();
  int64_t cnt = 0;
  // for (int i = 0; i + 1 < sz; sz = vec.size()) {
  for (int i = 0; i + 1 < vec.size(); /**/) {
    if ((vec[i] != vec[i + 1])) {
      vec.erase(vec.begin() + i, vec.begin() + i + 2);
      cnt += 2;
      i = 0;
    } else {
      i++;
    }
  }

  printf("%ld\n", cnt);

  return 0;
}


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

using namespace std;


#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),v).end()

#define PB(a) push_back(a)
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  int n;cin>>n;
  ll mi=INF,ma=-INF,sum=0;
  for(int i=0;i<n;i++){
      ll k;cin>>k;
      mi=min(mi,k);
      ma=max(ma,k);
      sum+=k;
  }
  cout<<mi<<" "<<ma<<" "<<sum<<endl;
}

Measured memory_bytes: 3168
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, c := iScan(), iScan(), iScan()
	if a%2 == 0 || b%2 == 0 || c%2 == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(min([]int{a * b, b * c, c * a}))
	}
}


Measured memory_bytes: 1772
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> A(a), B(b);
    for (int i = 0; i < a; i++) cin >> A[i];
    for (int i = 0; i < b; i++) cin >> B[i];

    int ans = *min_element(A.begin(), A.end()) +
                *min_element(B.begin(), B.end());

    int x, y, c;
    int tmp = 0;
    for (int i = 0; i < m; i++) {
        tmp = 0;
        cin >> x >> y >> c;
        x--; y--;
        tmp += A[x] + B[y] - c;
        ans = min(tmp , ans);
    }
    cout << ans << '\n';

}


Measured memory_bytes: 1024
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    ll a; cin>>a;
    int k=0;
    for(int q=1; q<=a; q++){
        ll x; cin>>x;
        k+=q!=x;
    }
    if(k==0 || k==2) cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 256
#include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<climits>
    using namespace std;
    void File(){
        freopen("ARC97E.in","r",stdin);
        freopen("ARC97E.out","w",stdout);
    }
    #define REP(i,a,b) for(register int i = a;i <= b;++i)
    #define DREP(i,a,b) for(register int i = a;i >= b;--i)
    #define MREP(i,x) for(register int i = beg[x];i;i = E[i].last)
    #define mem(a) memset(a,0,sizeof(a))
    #define ll long long
    #define inf INT_MAX
    const int maxn = 2000 + 10;
    int n,c[maxn << 1],a[maxn << 1],pos0[maxn],pos1[maxn];
    int dp[maxn][maxn],cost0[maxn << 1][maxn],cost1[maxn << 1][maxn];
    int main(){
        //File();
        scanf("%d",&n);
        REP(i,1,n * 2){
            char s[5];
            scanf("%s%d",s,&a[i]);
            c[i]= s[0] == 'W' ? 0 : 1;
            if(c[i] == 0)pos0[a[i]] = i;
            else pos1[a[i]] = i;
        }
        REP(i,1,n * 2)
            REP(j,0,n){
                cost0[i][j] = cost0[i - 1][j] + (a[i - 1] > j && c[i - 1] == 0);
                cost1[i][j] = cost1[i - 1][j] + (a[i - 1] > j && c[i - 1] == 1);
            }
        REP(i,0,n)
            REP(j,0,n){
                if(i == 0 && j == 0)continue;
                int p0 = pos0[i],p1 = pos1[j];
                dp[i][j] = inf;
                if(i)dp[i][j] = min(dp[i][j],dp[i - 1][j] + cost0[p0][i - 1] + cost1[p0][j]);
                if(j)dp[i][j] = min(dp[i][j],dp[i][j - 1] + cost1[p1][j - 1] + cost0[p1][i]);
            }
        printf("%d\n",dp[n][n]);
        return 0;
    }

Measured memory_bytes: 79232
#include <stdio.h>

char grid[255][256];
char dir[4][2] = {
	{1, 0}, {0, 1}, {1, 1}, {1, -1}
};

int length(int x, int y, int n, int l, int k)
{
	int max;
	int t;
	
	if (x == n || y == n || x < 0 || y < 0 || grid[x][y] == '0'){
		return (l);
	}
	
	return (length(x + dir[k][0], y + dir[k][1], n, l + 1, k));
}	

int main(void)
{
	int i, j, k, n;
	int max, len;
	
	while (scanf("%d", &n), n != 0){
		max = 0;
		
		for (i = 0; i < n; i++){
			scanf("%s", grid[i]);
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				if (grid[i][j] == '1'){
					for (k = 0; k < 4; k++){
						len = length(i, j, n, 0, k);
						if (max < len){
							max = len;
						}
					}
				}
			}
		}
		
		printf("%d\n", max);
	}
	
	return (0);
}

Measured memory_bytes: 668