akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int color = 0;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      color += 1;
    }
  }
  
  if (color == 0) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
  
}

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

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

    vector<double> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    double ans = (v[0] + v[1]) / 2;
    for (int i = 2; i < n; i++) {
        ans = (ans + v[i]) / 2.0;
    }

    cout << setprecision(16) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s;
    cin >> s;

    string akihabara = "AKIHABARA";

    int pos = 0;
    for (int i = 0; i < s.size();) {
        if (pos >= akihabara.size()) {
            cout << "NO\n";
            return 0;
        }

        if (s[i] == akihabara[pos]) {
            pos++;
            i++;
        } else if (akihabara[pos] == 'A') {
            pos++;
        } else {
            cout << "NO\n";
            return 0;
        }
    }

    if (pos < akihabara.size() - 1) {
        cout << "NO\n";
        return 0;
    }

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

Measured memory_bytes: 888
using System;

namespace _0109
{
	class Program
	{
		static string s;
		public static int pointer;
		static int number()
		{
			int ret = 0;
			while (pointer < s.Length && '0' <= s[pointer] && s[pointer] <= '9')
			{
				ret *= 10;
				ret += s[pointer] - '0';
				pointer++;
			}
			return ret;
		}
		static int term()
		{
			int ret = factor();
			while (pointer < s.Length)
			{
				if (s[pointer] == '*')
				{
					pointer++;
					ret *= factor();
				}
				else if (s[pointer] == '/')
				{
					pointer++;
					ret /= factor();
				}
				else break;
			}
			return ret;
		}
		static int expression()
		{
			int ret = term();
			while (pointer < s.Length)
			{
				if (s[pointer] == '+')
				{
					pointer++;
					ret += term();
				}
				else if (s[pointer] == '-')
				{
					pointer++;
					ret -= term();
				}
				else break;
			}
			return ret;
		}
		static int factor()
		{
			if (s[pointer] == '(')
			{
				pointer++;
				int ret = expression();
				pointer++;
				return ret;
			}
			else return number();
		}
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			for (int i = 0; i < n; i++)
			{
				s = Console.ReadLine();
				pointer = 0;
				Console.WriteLine(expression());
			}
		}
	}
}


Measured memory_bytes: 7804
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,popcnt,sse4.1,sse4.2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<17, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, q;
vi g[maxn];
vector<array<int, 3>> v;
int vis[maxn][11], col[maxn];
void dfs(int v, int p, int c, int d) {
	if(vis[v][d]++) return;
	if(!col[v]) col[v] = c;
	if(d)
		for(auto &i : g[v]) if(i != p) dfs(i, v, c, d-1);
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for(int f, t, i = 0; i < m; i++) {
		cin >> f >> t;
		g[f].pb(t);
		g[t].pb(f);
	}
	cin >> q;
	v.resize(q);
	for(auto &i : v) cin >> i[0] >> i[2] >> i[1];
	reverse(all(v));
	for(auto &i : v) {
		dfs(i[0], i[0], i[1], i[2]);
	}
	for(int i = 1; i <= n; i++) cout << col[i] << "\n";
}


Measured memory_bytes: 14836
#include<stdio.h>

void trace(int A[], int N){
	int i;
	for(i=0;i<N;i++){
		if(i>0)printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}
	
void insertionSort(int A[],int N){
		int i,j,v;
		for(i=1;i<N;i++){
			v=A[i];
			j=i-1;
			while(j>=0 && A[j]>v){
				A[j+1]=A[j];
				j--;
			}
			A[j+1]=v;
			trace(A,N);
		}
	}
	int main(){
		int N,i,j;
		int A[100];
		
		scanf("%d",&N);
		for(i=0;i<N;i++)scanf("%d",&A[i]);
		
		trace(A,N);
		insertionSort(A,N);
		
    return 0;
}
    

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

using namespace std;

int main(){
	int n, m;
	while(cin >> n >> m){
		if(!n) break;
		cin >> n;
		vector <int> count(m, 0);
		vector < vector< pair<int,int> > > rec(m);
		int t, p, s;
		for(int i=0;i<n;i++){
			cin >> t >> p >> p >> s;
			p--;
			if(s == 1){
				if(count[p] == 0)
					rec[p].push_back(make_pair(t,t));
				count[p]++;
			} else {
				count[p]--;
				if(count[p] == 0)
					rec[p][rec[p].size()-1].second = t;
			}
		}
		cin >> n;
		for(int i=0;i<n;i++){
			int ans = 0;
			cin >> s >> t >> p;
			p--;
			for(int j=0;j<rec[p].size();j++){
				ans += max(0, min(t, rec[p][j].second) - max(s, rec[p][j].first));
			}
			cout << ans << endl;
		}
	}
}

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

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

using ll = long long;
using ull = unsigned long long;

int main() {
  int n;
  string t, h;
  int a = 0, b = 0;
  cin >> n;
  rep(i, n) {
    cin >> t >> h;
    if (t > h) a += 3;
    if (t < h) b += 3;
    if (t == h) {a++; b++;}
  }
  cout << a << ' ' << b << endl;
  return 0;
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
const int N = 15;
int p[N];
int c[N][N];
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>p[i];
		for(int j=0;j<m;j++){
			cin>>c[i][j];
		} 
	}
	int cnt=1<<n,res=100000*15;
	for(int i=0;i<cnt;i++){
		int s=0;
		int v[N]={0};
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				s+=p[j];
				for(int k=0;k<m;k++){
					v[k]+=c[j][k];
				}
			} 
		}
		int t=0;
		for(int j=0;j<m;j++){
			t+=(v[j]>=k);
		}
		if(t==m)res=min(res,s);
	}
	if(res==100000*15)res=-1;
	cout<<res;
	
}

Measured memory_bytes: 3556
#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()
{
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;

    if (s == u)
    {
        a -= 1;
    }
    else
    {
        b -= 1;
    }

    cout<<a<<' '<<b<<endl;
    


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int dp1[3333][3333], dp2[3333][3333], a[3333], b[3333], n, T;
  void solve() {
    cin >> n >> T;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i] >> b[i];
      for (int j = 0; j <= T; ++j) {
        dp1[i][j] = dp1[i - 1][j];
        if (j - a[i] >= 0)
          dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - a[i]] + b[i]);
      }
    }
    for (int i = n; i >= 1; --i) {
      for (int j = 0; j <= T; ++j) {
        dp2[i][j] = dp2[i + 1][j];
        if (j - a[i] >= 0)
          dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - a[i]] + b[i]);
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j <= T - 1; ++j) {
        ans = max(ans, dp1[i - 1][j] + dp2[i + 1][T - 1 - j] + b[i]);
      }
    }
    cout << ans << "\n";
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 82176
arr = [ i for i in input().split(" ")]

# 1 2 +
operands = ["+", "-", "*", "/"]

s = []

for i in arr:
  if i not in operands:
    s.append(i)
  
  if i in operands:
    val2 = s.pop()
    val1 = s.pop()

    s.append(eval("{0} {1} {2}".format(val1, i, val2)))

print(s[-1])


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

int main() {
    string s;
    cin >> s;
    int cnt = 0;

    for (int i = 0; i < 4; i++) {
        if (s[i] == '+') {
            cnt++;
        } else {
            cnt--;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
#include <algorithm>

int main(int argc, char *argv[]){
    unsigned int N;
    std::cin >> N;
    std::string string[N];
    std::map<std::string, int>map;
    for(auto &s : string){
        std::cin >> s;
        std::sort(s.begin(),s.end());
        map[s]++;
    }

    long int anagrams = 0;
    long int count;
    for(auto &hist : map){
        count = hist.second;
        if(count==1){ continue; }
        anagrams += (count)*(count-1)/2;
    }
    std::cout << anagrams << std::endl;
    return 0;
}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	long long int ans = 0;
	vector <int> arr(3 * n);
	for(int i = 0;i < 3 * n; i++) {
		cin >> arr[i];
	}
	sort(arr.begin(), arr.end());

	for(int i = n; i < 3 * n; i += 2) {
		ans += arr[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(){
 int a,b,c,i,sum;
 sum = 0;
 scanf("%d%d%d", &a, &b, &c);
 for(i = a; i <= b; i++){
  if((c % i) == 0) {sum++;}
 }
 printf("%d\n", sum);
 return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 55;
typedef long long ll; 
using namespace std;

int n;
ll K, x, y, a[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int lowbit(int x) { return x & (-x); }

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	K = read <ll> (), n = 50, x = K % n, y = K / n; 
	for(int i = 1; i <= x; i++) a[i] = y + 2 * n - x; 
	for(int i = x + 1; i <= n; i++) a[i] = y + n - 1 - x; 
	printf("%d\n", n);
	for(int i = 1; i <= n; i++) printf("%lld%c", a[i], i == n ? '\n' : ' '); 
	return 0; 
}


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

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

	if(N == 2 || M == 2){
		cout << 0 << endl;
	} else if(N == 1 || M == 1){
		if(N == 1 && M == 1){
			cout << 1 << endl;
		} else {
			cout << max(N, M) - 2 << endl;
		}
	} else {
		long long ans = N*M - 2*(N+M) + 4;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <typeinfo>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define LEN 100005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main(void) {
    ll a, b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
    
    
    
    
    
}


Measured memory_bytes: 764
n = int(input())
s = []
for i in range(n):
    s.append(input())

ls1 = []
ls2 = []

for item in s:
    stk1 = []
    stk2 = []
    for ch in item:
        if ch == '(':
            stk2.append(ch)
        else:
            if len(stk2) > 0:
                stk2.pop()
            else:
                stk1.append(ch)
    l1 = len(stk1)
    l2 = len(stk2)
    if l2 >= l1:
        ls1.append((l1, l2))
    else:
        ls2.append((l1, l2))


ls1.sort()

cnt = 0

for item in ls1:
    cnt -= item[0]
    if cnt < 0:
        print('No')
        exit()
    else:
        cnt += item[1]

ls2.sort(key=lambda x: x[1])
ls2.reverse()

for item in ls2:
    cnt -= item[0]
    if cnt < 0:
        print('No')
        exit()
    else:
        cnt += item[1]

if cnt != 0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 92036
def sol():
    N = int(input())
    S = int(input())

    if N == S:
        print(N + 1)
        return

    def digitSum(n, b):
        if b < 2:
            return -1
        if n < b:
            return n
        return digitSum(n // b, b) + n % b

    for b in range(2, int(N**0.5) + 1):
        if digitSum(N, b) == S:
            print(b)
            return

    for p in range(int(N**0.5), 0, -1):
        b = (N - S) // p + 1
        if digitSum(N, b) == S:
            print(b)
            return
    print('-1')

sol()

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

namespace ABC045D{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var H = sr.Next<long>();
            var W = sr.Next<long>();
            var N = sr.Next<int>();
            var P = sr.Next<long>(N, 2);

            Func<long, long, long> hash = (s, t) => s * 10000000000L + t;
            Func<long, long, bool> isInside = (x, y) => 1 <= x && x < W - 1 && 1 <= y && y < H - 1;
            var dx = new[]{0, 1, 0, -1, 1, 1, -1, -1, 0};
            var dy = new[]{1, 0, -1, 0, 1, -1, 1, -1, 0};
            var area = new List<long>();

            foreach(var p in P){
                for(var i = 0; i < 9; i++){
                    var x = p[1] + dx[i] - 1;
                    var y = p[0] + dy[i] - 1;
                    if(isInside(x, y)){
                        area.Add(hash(x, y));
                    }
                }
            }

            var res = new long[10];
            foreach(var ag in area.GroupBy(x => x)){
                res[ag.Count()]++;
            }

            res[0] = (W - 2) * (H - 2) - res.Sum();
            Array.ForEach(res, Console.WriteLine);
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 112380
N = int(input())
A = [int(input()) for _ in range(N)]
Max = max(A)
x = A.count(Max)

for i in range(0 ,N) :
    if x >= 2 :
        print(Max)
    elif A[i] == Max :
        A[i] = 0
        print(max(A))
    else : print(Max)



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

class Node {
    public:
        int key;
        Node *parent, *left, *right;
};

Node *NIL;
Node *root = NIL;

void insert(int k) {
    Node *x = root;
    Node *y = NIL;
    Node *z = new Node;

    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    if (y == NIL) root = z;
    else {
        if (z->key < y->key) y->left = z;
        else y->right = z;
    }
}
void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    cout << ' ' << u->key;
    inorder(u->right);
}
void preorder(Node *u) {
    if (u == NIL) return;
    cout << ' ' << u->key;
    preorder(u->left);
    preorder(u->right);
}

Node *find(Node *r, int k) {
    while (r != NIL && r->key != k) {
        if (k < r->key) r = r->left;
        else r = r->right;
    }
    return r;
}

int main() {
    int n, value;
    string com;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            cin >> value;
            insert(value);
        } else if (com == "find") {
            cin >> value;
            Node *res = find(root, value);
            if (res != NIL) cout << "yes" << endl;
            else cout << "no" << endl;
        } else if (com == "print") {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 21884
import java.util.*;

public class Main {
	static long MOD = 998244353;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K = sc.nextInt();
		
		long[] pow = new long[K+1];
		long[] comb = new long[K+1];
		
		long temp = 1;
		for(int i=1; i<=N; i++) {
			temp = i==1 ? M : (temp * (M-1))%MOD;
			if(i>=N-K)
				pow[i-N+K] = temp;
		}
		
		comb[0] = 1;
		for(int i=0; i<K; i++) {
			comb[i+1] = (comb[i]*(N-1-i)) % MOD;
			comb[i+1] = (comb[i+1]*rev(i+1)) % MOD;
		}
		
		long ans = 0;
		for(int i=0; i<=K; i++) {
			ans = (ans + pow[i]*comb[K-i])%MOD;
		}
		System.out.println(ans);
		sc.close();
	}
	
	static long rev(long a) {
		return pow(a, MOD-2);
	}
	
	static long pow(long a, long b) {
		long ans = 1;
		while(b>0) {
			if((b&1)!=0)
				ans = (ans * a)%MOD;
			b>>=1;
			a = (a*a)%MOD;
		}
		return ans;
	}
	
}



Measured memory_bytes: 30380
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
auto cmx=[](auto&x,auto y){if(x<y){x=y;return true;}return false;};
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n;
    std::cin >> n;
    vec<vec<usize>> g(n);
    for (usize i=1; i<n; i++) {
        usize p;
        std::cin >> p;
        p--;
        g.at(p).push_back(i);
    }

    vec<usize> dp(n, -1);
    auto dfs = [&](auto&& f, usize x) -> void {
        dp.at(x) = 0;
        vec<usize> a;
        for (usize y: g.at(x)) if (dp.at(y)==-1) {
            f(f, y);
            a.push_back(dp.at(y));
        }
        std::sort(ALL(a), std::greater<>{});
        for (usize i=0; i<a.size(); i++) {
            cmx(dp.at(x), a.at(i) + i + 1);
        }
    };
    dfs(dfs, 0);

    std::cout << dp.at(0) << '\n';
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
typedef long long ll;
vector<ll>v[3];
ll ans=1;
int K;
ll solve(){
	reverse(v[2].begin(),v[2].end());
	int cnt1=0,cnt2=0;
	while(cnt1+1<(int)(v[0].size())&&cnt2+1<(int)(v[2].size())&&cnt1+cnt2+2<=K){
		if(1ll*v[2][cnt2]*v[2][cnt2+1]>1ll*v[0][cnt1]*v[0][cnt1+1])ans=(1ll*v[2][cnt2]*v[2][cnt2+1])%MOD*ans%MOD,cnt2+=2;
		else ans=(1ll*v[0][cnt1]*v[0][cnt1+1])%MOD*ans%MOD,cnt1+=2;
	}
	while(cnt2+1<(int)(v[2].size())&&cnt2+cnt1+2<=K){
        ans=ans*v[2][cnt2]%MOD*v[2][cnt2+1]%MOD;
        cnt2+=2;
    }
    while(cnt1+1<(int)(v[0].size())&&cnt2+cnt1+2<=K){
        ans=ans*v[0][cnt1]%MOD*v[0][cnt1+1]%MOD;
        cnt1+=2;
    }
    if(cnt2+cnt1<K)
        ans=ans*v[2][cnt2]%MOD;
    return (ans+MOD)%MOD;
}
bool can1(){
	int num=(int)(v[0].size())/2;
	for(int i=0;i<=num;i++)if(i*2<=K&&K-2*i<=(int)(v[2].size()))return 1;
	return 0;
}
bool can0(){
	return v[1].size()>0;
}
bool cmp(int x,int y){
	return abs(x)<abs(y);
}
int main(){
	int n;cin>>n>>K;
	for(int i=0;i<n;i++){
		int x;cin>>x;
		if(x<0)v[0].push_back(x);
		if(x>0)v[2].push_back(x);
		if(x==0)v[1].push_back(x);
	}
	sort(v[0].begin(),v[0].end());
	sort(v[2].begin(),v[2].end());
	if(can1()){
		cout<<solve();
	}else if(can0()){
		puts("0");
	}else{
		for(int i=0;i<v[0].size();i++)v[1].push_back(v[0][i]);
		for(int i=0;i<v[2].size();i++)v[1].push_back(v[2][i]);
		sort(v[1].begin(),v[1].end(),cmp);
		for(int i=0;i<K;i++)ans=ans*v[1][i]%MOD;
		cout<<(ans+MOD)%MOD;
	}
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    vector<P> lis(n);
    int x, y;
    rep(i, n){
        cin >> x >> y;
        lis[i] = make_pair(x, y);
    }
    if(n == 1) {
        cout << 1 << endl;
        return 0;
    }
    
    sort(all(lis));
    int ans = 1000000000;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            int dx = lis[j].first - lis[i].first;
            int dy = lis[j].second - lis[i].second;
            if(dx == 0 && dy == 0) continue;
            else{
                int cnt = n;
                for(int k = 0; k < n; k++){
                    for (int l = k; l < n; ++l) {
                        if(lis[l].first == lis[k].first + dx && lis[l].second == lis[k].second + dy){
                            cnt--;
                        }
                    }

                }
                ans = min(ans, cnt);
            }

        }
    }
    cout << ans << endl;
}

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

char color[105];
int main(void){
  int N; cin>>N;
  cin>>color;
  int cnt=0;
  for(int i=0;i<N;i++){
    if(color[i]=='R') cnt++;
  }
  if(cnt*2>N) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

const int maxn = 2100000;
const ll Mod = 1e9+7;

ll pw(ll x,int k)
{
	ll re=1ll;
	for(;k;k>>=1,x=x*x%Mod) if(k&1)
		re=re*x%Mod;
	return re;
}

ll s[maxn],pinv[maxn];
void pre()
{
	s[0]=1ll;
	for(ll i=1;i<maxn;i++) s[i]=s[i-1]*i%Mod;
	pinv[maxn-1]=pw(s[maxn-1],Mod-2);
	for(ll i=maxn-2;i>=0;i--) pinv[i]=pinv[i+1]*(i+1ll)%Mod;
}
ll C(const int i,const int j){return s[i]*pinv[j]%Mod*pinv[i-j]%Mod;}

int x[6],y[6];
struct node{int x,y;ll v;}a[4],b[4];
ll cal(const node x,const node y){return C(y.x+y.y-x.x-x.y,y.x-x.x);}

ll ans;

int main()
{
	pre();
	for(int i=0;i<6;i++) scanf("%d",&x[i]);
	for(int i=0;i<6;i++) scanf("%d",&y[i]);
	
	a[0]=(node){x[0]-1,y[0]-1,1ll};
	a[1]=(node){x[0]-1,y[1],-1ll};
	a[2]=(node){x[1],y[0]-1,-1ll};
	a[3]=(node){x[1],y[1],1ll};
	
	b[0]=(node){x[4],y[4],1ll};
	b[1]=(node){x[4],y[5]+1,-1ll};
	b[2]=(node){x[5]+1,y[4],-1ll};
	b[3]=(node){x[5]+1,y[5]+1,1ll};
	
	ans=0;
	for(int i=0;i<4;i++) for(int j=0;j<4;j++)
	{
		ll now=0;
		for(int k=y[2];k<=y[3];k++) 
			(now+=(ll)(-x[2]-k+1)*cal(a[i],(node){x[2]-1,k})%Mod*cal((node){x[2],k},b[j])%Mod)%=Mod;
		for(int k=x[2];k<=x[3];k++) 
			(now+=(ll)(-k-y[2]+1)*cal(a[i],(node){k,y[2]-1})%Mod*cal((node){k,y[2]},b[j])%Mod)%=Mod;
		for(int k=y[2];k<=y[3];k++) 
			(now+=(ll)(k+x[3])*cal(a[i],(node){x[3],k})%Mod*cal((node){x[3]+1,k},b[j])%Mod)%=Mod;
		for(int k=x[2];k<=x[3];k++) 
			(now+=(ll)(k+y[3])*cal(a[i],(node){k,y[3]})%Mod*cal((node){k,y[3]+1},b[j])%Mod)%=Mod;
		ans+=now*a[i].v*b[j].v%Mod;
	}
	printf("%lld\n",(ans%Mod+Mod)%Mod);
	
	return 0;
}


Measured memory_bytes: 33024
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int sum( int l, int r )
{
	l--;
	return r * ( r + 1 ) / 2 - l * ( l + 1 ) / 2;
}

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

	for ( int n; cin >> n, n; )
	{
		int res = 0;
		REP( i, 1, n + 1 )
		{
			REP( j, i + 1, n + 1 )
			{
				res += sum( i, j ) == n;
			}
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,dp[405][405],a[405];
int main(void){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",a+i);
        a[i]+=a[i-1];
    }
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)dp[i][j]=INF;
    for(int i=0;i<=n;i++)dp[i][i]=0;
    for(int l=1;l<n;l++){
        for(int i=1;i+l<=n;i++){
            int j=i+l;
            for(int k=i;k+1<=j;k++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+a[j]-a[i-1]);
            }
        }
    }
    printf("%lld\n",dp[1][n]);
}


Measured memory_bytes: 1536
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<bitset>
#include<deque>
#include<cstdlib>
#include<set>
#include<ctime>
#define ll long long
#define mp make_pair
using namespace std;
ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return f*x;
}
int n,top;
struct node{
	int from,to;
}as[10000];
bool flag;
int main()
{
	n=read();
	if(n&1)
	{
		flag=1;
		n--;
	}
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j) if(j!=i&&j+i!=n+1) as[++top]=(node){i,j};
	if(flag)
	{
		for(int i=1;i<=n;++i) as[++top]=(node){i,n+1};
	}
	cout<<top<<'\n';
	for(int i=1;i<=top;++i) cout<<as[i].from<<" "<<as[i].to<<'\n';
	return 0;
 }


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

int main() {
  int n, k;
  cin>>n>>k;
  vector<int> a(n+1);
  for (int i=0; i<n; i++) cin>>a[i+1];
  for (int _=0; _<k; _++) {
    vector<int> tmp(n+2);
    for (int i=1; i<n+1; i++) {
      ++tmp[max(i-a[i], 0)];
      --tmp[min(i+a[i]+1, n+1)];
    }
    a[0] = tmp[0];
    bool all_n = true;
    for (int i=1; i<n+1; i++) {
      a[i] = a[i-1] + tmp[i];
      if (a[i] != n) {
        all_n = false;
      }
    }
    if (all_n) {
      break;
    }
  }
  for (int i=0; i<n; i++) {
    cout<<a[i+1];
    if (i != n - 1) {
      cout<<" ";
    }
  }
  cout<<endl;
}

Measured memory_bytes: 4844
// abc135b: 0 or 1 Swap
#include <bits/stdc++.h>
using namespace std;

#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

int main(){
  int n;in(n);
  int c=0;
  upto(i,1,n+1,1){
    int k;in(k);
    if(i!=k)c++;
  }
  oute(c>2?"NO":"YES");
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int, C: int, D: int):
    print(max(0, min(B, D)-max(A, C)))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();

		ArrayList<Long> list = new ArrayList<>();
		for(int i = 0; i < 3 * N; i++) {
			list.add(scanner.nextLong());
		}

		//どうソートする？
		Collections.sort(list, Collections.reverseOrder());

		long sum = 0;
		for(int i = 0; i < N; i++) {
			sum += list.get(1 + (2 * i));
		}

		System.out.println(sum);
	}

}

Measured memory_bytes: 104640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    d=2*d+1;
    if(n%d!=0)
        cout<<(n/d)+1<<endl;
    else if(n%d==0)
    {
        cout<<n/d<<endl;
    }
}


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

int main() {
    int k;
    cin >> k;
    vector<vector<ll>> lun(12, vector<ll>(0));
    lun[0] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    if (1 <= k && k <= 9) {
        cout << k << endl;
        return 0;
    }
    int cnt = 9;
    for (int i = 1; i < 12; ++i) {
        vector<ll> base = lun[i - 1];
        for (ll j : base) {
            if (j % 10 != 0) {
                lun[i].emplace_back(10 * j + j % 10 - 1);
                cnt++;
                if (cnt == k) {
                    cout << lun[i][lun[i].size() - 1] << endl;
                    return 0;
                }
            }
            lun[i].emplace_back(10 * j + j % 10);
            cnt++;
            if (cnt == k) {
                cout << lun[i][lun[i].size() - 1] << endl;
                return 0;
            }
            if (j % 10 != 9) {
                lun[i].emplace_back(10 * j + j % 10 + 1);
                cnt++;
                if (cnt == k) {
                    cout << lun[i][lun[i].size() - 1] << endl;
                    return 0;
                }
            }
        }
    }
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

set<li> st[200200];

int main() {
    li n, m;
    cin >> n >> m;
    rep(i, m) {
        li a, b;
        cin >> a >> b;
        --a;
        --b;
        st[a].insert(b);
        st[b].insert(a);
    }
    repp(i, 1, n - 1) {
        if (st[i].find(0) != st[i].end() && st[i].find(n - 1) != st[i].end()) {
            puts("POSSIBLE");
            return 0;
        }
    }
    puts("IMPOSSIBLE");

    return 0;
}

Measured memory_bytes: 28416
import java.util.*;
import java.lang.*;

public class Main {
    static Set<Long> divisors(long N){
        Set<Long> ans = new HashSet<>();
        for(long n=1; n*n<=N; n++){
            if(N%n==0){
                ans.add(n);
                ans.add(N/n);
            }
        }
        return ans;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();

        // N := am+b
        // n/m==a, N%m == b
        // ans: a==b < m, N=a(m+1)
        long ans = 0;
        for(long a: divisors(N)) {
            long m = N/a-1;
            if(a<m){
                ans+=m;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
#include <iostream>
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <math.h>
using namespace std;

int main()
{
	
	int A, B, C, D;
	std::cin >> A >> B >> C >> D;
	int A_turn = 0;
	if (C%B == 0) {
		A_turn = C / B;
	}
	else {
		A_turn = (C / B) + 1;
	}
	int B_turn;
	if (A%D == 0) {
		B_turn = A / D;
	}
	else {
		B_turn = (A / D) + 1;
	}


	if (A_turn <= B_turn) {
		std::cout << "Yes";
	}
	else {
		std::cout << "No";
	}
	return 0;
}

	


Measured memory_bytes: 3608
#include<stdio.h>

int main(void){
    long long int n,a,b,sum=0,bc=0,rc=0,ans,f,d;

    scanf("%lld %lld %lld",&n,&a,&b);

    f=n/(a+b);

    d=f*(a+b);

    if(d==n){
        printf("%lld\n",f*a);
    }else{
        d=d+a;
        if(d>n){
            printf("%lld\n",f*a+(n-(a+b)*f));
        }else{
            printf("%lld\n",f*a+a);
        }
    }

    return 0;
}

Measured memory_bytes: 256
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))

q, h, s, d = rli()
n = ri()

m1 = min([q*4, h*2, s])

if(n == 1):
    print(m1)
else:
    m2 = min(m1*2, d)
    print(m2*(n//2) + m1*(n%2))

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll LL_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N;
    cin >> N;
    map<int, int> cnt;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        cnt[a]++;
    }
    vector<pair<ll,int>> A;
    for(auto p : cnt){
        if(p.se >= 4) A.emplace_back(p.fi, 4);
        else if(p.se >= 2) A.emplace_back(make_pair(p.fi, 2));
    }
    sort(all(A), greater<>());
    ll S;
    if(A.size() == 1){
        if(A[0].se >= 4) S = A[0].fi * A[0].fi;
        else S = 0;
    }else if(A.empty()) S = 0;
    else{
        if(A[0].se >= 4) S = A[0].fi * A[0].fi;
        else S = A[0].fi * A[1].fi;
    }
    cout << S << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define fi first
#define se second
#define ii pair<int, int>
#define int long long
using namespace std;

int n, m, k;
int a[3005][3005];
int f[3005][3005][4];

int attempt(int i, int j, int left)
{
    int val = 0;
    if (left != 0)
        val = a[i][j];
    if (i == n && j == m)
        return val;
    if (f[i][j][left] != -1)
        return f[i][j][left];
    int res = -1;

    if (i + 1 <= n)
        res = max(res, attempt(i+1, j, 3) + val);

    if (j + 1 <= m){
        if (left != 0)
            res = max(res, attempt(i, j+1, left - 1) + val);
        res = max(res, attempt(i, j+1, left));
    }
    return f[i][j][left] = res;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

//    freopen("in.inp", "r", stdin);
//    freopen("out.out", "w", stdout);

    cin >> n >> m >> k;
    memset(f, -1, sizeof(f));
    for (int i = 1; i <= k; i++)
    {
        int x, y, val;
        cin >> x >> y >> val;
        a[x][y] = val;
    }
    cout << attempt(1, 1,3);
}


Measured memory_bytes: 356616
from sys import stdin

n, x = (int(x) for x in stdin.readline().rstrip().split())
l = [int(i) for i in stdin.readline().rstrip().split()]

d = [0]
for i in range(1, n+1):
    d.append(d[i-1] + l[i-1])

print(len([i for i in d if i <= x]))


Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,i,j,k,n,m,x,y;
	string	s;
	string	ans = "No";

	cin >> s;

	for(i=0;i<3;i++) {
		if (s[i] =='7') ans = "Yes";
	}

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


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
    vector<string> S(N);
    vector<map<char, int>> cnt(N);
    rep(i, N)
    {
        cin >> S[i];
        rep(j, S[i].size())
        {
            cnt[i][S[i][j]]++;
        }
    }
    map<char, int> Ans;
    for (char str = 'a'; str <= 'z'; str++)
    {
        int Min = INT_MAX;
        rep(i, N)
        {
            Min = min(Min, cnt[i][str]);
        }
        Ans[str] = Min;
    }

    for (auto c : Ans)
    {
        while (c.second > 0)
        {
            cout << c.first;
            c.second--;
        }
    }
    return 0;
}

Measured memory_bytes: 384
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
   double x[3],y[3];
   rep(i,3) cin >> x[i] >> y[i];
   // double gx,gy;
   // gx = (x[0] + x[1] + x[2]) / (double)3;
   // gy = (y[0] + y[1] + y[2]) / (double)3;
   
   double d[3];
   d[0] = sqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]));
   d[1] = sqrt((x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]));
   d[2] = sqrt((x[2]-x[0])*(x[2]-x[0]) + (y[2]-y[0])*(y[2]-y[0]));
   
   double dmax = max({d[0],d[1],d[2]});
   // int dmax_num = 0;
   // rep(i,3){
      // if(dmax == d[i]){
         // dmax_num = i;
      // }
   // }
   double s = (d[0]+d[1]+d[2])/2;
   double S = sqrt(s*(s-d[0])*(s-d[1])*(s-d[2]));
   double r = (double)2*S/(d[0]+d[1]+d[2]);
   
   cout << fixed;
   cout << setprecision(20) << dmax*r/((double)2*r + dmax) << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	map<int, int> a, b;
	for (int i = 0; i < N; ++i) {
		int ai;
		cin >> ai;
		if (!a.count(ai)) a[ai] = i; else a[ai] = min(a[ai], i);
		++b[ai];
	}
	a[0] = 0;
	vector<long long> r(N);
	long long n = 0;
	int p = 1<<30;
	for (auto i = a.rbegin(); i->first > 0; ++i) {
		auto j = i; ++j;
		n += b[i->first];
		// bug : p = i->second;
		p = min(p, i->second);
		r[p] += n * (i->first - j->first);
	}
	for (auto x : r) {
		cout << x << endl;
	}
}


Measured memory_bytes: 11264
#include <iostream>

using namespace std;

int n;

int main() {
	cin >> n;
	int b = 1;
	while (b*2 <= n) b *= 2;
	if (n == b) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	cout << "1 2\n";
	cout << "2 3\n";
	cout << "3 " << n+1 << "\n";
	cout << n+3 << " " << 1 << "\n";
	cout << n+2 << " " << n+3 << "\n";
	for (int k = 4; k+1 <= n; k += 2) {
		cout << "1 " << k << "\n";
		cout << k << " " << k+1 << "\n";
		cout << "1 " << n+k+1 << "\n";
		cout << n+k+1 << " " << n+k << "\n";
	}
	if (n%2 == 0) {
		int x = 1^n^b;
		int y = 1;
		cout << x+n << " " << n << "\n";
		cout << b << " " << 2*n << "\n";
	}
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#define MAX_NUM 100
using namespace std;

int main()
{
	int* extBy2 = new int[MAX_NUM];
	int ans = 2;
	extBy2[0] = 1;
	for (int i = 1; i < MAX_NUM; i++) {
		if ((ans*2) > (i+1))
			extBy2[i] = ans;
		else {
			ans *= 2;
			extBy2[i] = ans;
		}
	}

	int N;
	cin >> N;
	cout << extBy2[N - 1];

	return 0;
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	int n;
	cin >> n;
	int a[n], ans = 0;
	for(int i = 0; i < n; i++)cin >> a[i];
	for(int i = 0; i < n; i++){
		int min_ = i;
		for(int j = i; j < n; j++){
			if(a[j] < a[min_]){
				min_ = j;
			}
		}
		if(min_ != i){
			swap(a[i], a[min_]);
			ans++;
		}
	}
	
	cout << a[0];
	for(int i = 1; i < n; i++)cout << ' ' << a[i];
	cout << '\n' << ans << '\n'; 
	return 0;
}



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


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

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


int main() 
{
  ll A,B,C,D; cin>>C>>D>>A>>B;
  ll kosuA_C=(C-1)/A;
  //cout<<kosuA_C<<endl;
  ll kosuA_D=D/A;
  //cout<<kosuA_D<<endl;
  ll kosuB_C=(C-1)/B;
  //cout<<kosuB_C<<endl;
  ll kosuB_D=D/B;
  //cout<<kosuB_D<<endl;
  ll kosuAB_C=(C-1)/(lcm(A,B));
  //cout<<kosuAB_C<<endl;
  ll kosuAB_D=D/(lcm(A,B));
  //cout<<kosuAB_D<<endl;
  cout<<(D-C+1)-((kosuA_D-kosuA_C)+(kosuB_D-kosuB_C)-(kosuAB_D-kosuAB_C))<<endl;
  return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A, B;
    cin >> A >> B;
    int res = max(A+B,max(A-B,A*B));
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

struct Node {
  int id = -1, parent = -1, left = -1, right = -1, sibling = -1, depth = 0, degree = 0, height = -1;
  string type = "";
  Node(int id = -1): id(id) {}
};

int get_height(map<int, Node> &tree, Node &nd, int height) {
  if (nd.left == -1 && nd.right == -1) return height;
  
  int l, r;
  if (nd.left == -1) l = 0;
  else {
    if (tree[nd.left].height == -1) tree[nd.left].height = get_height(tree, tree[nd.left], 0);
    l = tree[nd.left].height + 1;
  }

  if (nd.right == -1) r = 0;
  else {
    if (tree[nd.right].height == -1) tree[nd.right].height = get_height(tree, tree[nd.right], 0);
    r = tree[nd.right].height + 1;
  }
  
  return max(l, r); 
}

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

  map<int, Node> tree;
  rep(i, n) {
    int id, left, right;
    cin >> id >> left >> right;
    if (!tree.count(id)) tree[id] = Node(id);
    auto &nd = tree[id];
    nd.left = left;
    nd.right = right;
    
    if (nd.left != -1) {
      if (!tree.count(nd.left)) tree[nd.left] = Node(nd.left);
      tree[nd.left].parent = nd.id;
    }
    if (nd.right != -1) {
      if (!tree.count(nd.right)) tree[nd.right] = Node(nd.right);
      tree[nd.right].parent = nd.id;
    }
  }
  
  rep(i, n) {
    auto &nd = tree[i];
    
    if (nd.left != -1) nd.degree++;
    if (nd.right != -1) nd.degree++;

    if (nd.degree == 2) {
      tree[nd.left].sibling = nd.right;
      tree[nd.right].sibling = nd.left;
    }
    
    int parent = nd.parent;
    while (parent != -1) {
      nd.depth++;
      parent = tree[parent].parent;
    }

    if (nd.height == -1) nd.height = get_height(tree, nd, 0);
    
    if (nd.parent == -1) nd.type = "root";
    else if (!nd.degree) nd.type = "leaf";
    else nd.type = "internal node";
  }

  rep(i, n) {
    auto &nd = tree[i];
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", 
        nd.id, nd.parent, nd.sibling, nd.degree, nd.depth, nd.height, nd.type.c_str());
  }
}



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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int a=0;
    int arr[n],k=0;
    for(int x=0;x<n; x++)
    {
        if(s.at(x)=='I'){a=a+1;}
        if(s.at(x)=='D'){a=a-1;}
        arr[k++]={a};
    }
    int max=arr[0];
    for(int x=0; x<n; x++)
    {
        if(arr[x]>max)
            max=arr[x];
    }
  if(max>0)
    cout<<max<<endl;
    else
        cout<<"0";
    return 0;
}


Measured memory_bytes: 256