akhauriyash/Code-Regression huggingface dataset:
N,Time=map(int,input().split())
C=[]
T=[]
for _ in range(N):
    c,t=map(int,input().split())
    C.append(c)
    T.append(t)

tmp=[]
for i in range(N):
    if T[i]<=Time:
        tmp.append(C[i])
if tmp==[]:
    print('TLE')
else:
    print(min(tmp))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  
  for(int i = 1;i < 10;++i){
    for(int j = 1;j < 10;++j){
      if(i * j == n){
        print("Yes");
        return 0;
      }
    }
  }
  print("No");
  return 0;
} 


Measured memory_bytes: 256
Module Module1

    Sub Main()
        Dim tmp As String = Console.ReadLine()
        Dim s1 As Char = tmp(0)
        Dim s2 As Char = tmp(1)
        Dim s3 As Char = tmp(2)

        Dim s As String = String.Concat(s1, s2, s3)
        Dim ans As Long = 0

        For Each c As Char In s
            ans = ans + CLng(c & "")
        Next

        Console.WriteLine(ans)

    End Sub

End Module

Measured memory_bytes: 11220
n,k = map(int,input().split())
lst = [int(i) for i in input().split()]
ss = 0
for i in range(0,len(lst)):
    b,a = 0,0
    for ii in range(0,i):
        if lst[ii] < lst[i]:
            b += 1
    for ii in range(i,len(lst)):
        if lst[i] > lst[ii]:
            a += 1
    n1 = k
    tna = a*n1
    ta = a
    aa = n1*(tna+ta)//2
    n2 = k-1
    tnb = b*n2
    tb = b
    bb = n2*(tnb+tb)//2
    ss += aa+bb
print(ss%(10**9+7))


Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int o = 0;
		int point = 0;
		int stt[3] = { 0 };
		while (o < 3){
			string s;
			cin >> s;
			if (s.compare("HIT") == 0) {
				if (stt[2] == 1) {
					point++;
				}
				for (int j = 2; j > 0; j--) {
					stt[j] = stt[j - 1];
				}
				stt[0] = 1;
			} else if (s.compare("HOMERUN") == 0) {
				for (int j = 0; j < 3; j++) {
					if (stt[j] == 1) {
						point++;
					}
					stt[j] = 0;
				}
				point++;
			} else if (s.compare("OUT") == 0) {
				o = o++;
			}
		}
		cout << point << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a<=b)  cout << a << endl;
  else  cout << a-1 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str = sc.nextLine().split(" ");
		ap_change(str);
		sc.close();
	}

	private static void ap_change(String[] str) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < str.length; i++) {

			if (str[i].matches(".*apple.*")) {
				str[i] = str[i].replaceAll("apple", "peach");
			} else if (str[i].matches(".*peach.*")) {
				str[i] = str[i].replaceAll("peach" ,"apple");
			}

		sb.append(str[i]);

			if (i < str.length - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 26332
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int a,b,x;
  cin>>a>>b>>x;

  long long int c=a/x;
  long long int d=b/x;
  long long int ans=d-c;
  if(a%x==0){
    ans++;
  }
  cout<<ans<<endl;

}

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

int main(){
  string s;
  cin >> s;
  int l = s.length();
  vector<int> ans(l);
  vector<int> nr(l), nl(l);
  int pl = l, pr = 0;
  for(int i = l-1; i >= 0; i--) {
    if(s[i] == 'L') pl = i;
    else nl[i] = pl;
  }
  rep(i,l) {
    if(s[i] == 'R') pr = i;
    else nr[i] = pr;
  }
  rep(i,l) {
    if(s[i] == 'R') {
      int d = nl[i] - i;
      if(d % 2) ans[nl[i]-1]++;
      else ans[nl[i]]++;
    } else {
      int d = i - nr[i];
      if(d % 2) ans[nr[i]+1]++;
      else ans[nr[i]]++;
    }
  }
  rep(i,l) cout << ans[i] << " ";
  cout << endl;
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    for (int i=0;i<s.size();i++) {
        if (s[i]=='7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}



Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long


int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int N = S.size();
	vector<vector<int> > dp(N + 1, vector<int>(3, 0));
	int inv3 = (MOD + 1) / 3;

	for (int i = 0; i < N; i++) {
		if (S[i] == 'A') {
			dp[i][0] = 1;
		}
		else if (S[i] == '?') {
			dp[i][0] = inv3;
		}
	}
	//cerr << "ok" << endl;
	for (int i = 1; i < N; i++) {
		dp[i][0] += dp[i - 1][0];
		dp[i][0] %= MOD;
	}
	for (int i = 1; i < 3; i++) {
		for (int j = 1; j < N; j++) {
			dp[j][i] = dp[j - 1][i];
			if (S[j] == '?') {
				dp[j][i] += dp[j - 1][i - 1] * inv3;
				dp[j][i] %= MOD;
			}
			else if (S[j] == 'A' + i) {
				dp[j][i] += dp[j - 1][i - 1];
				dp[j][i] %= MOD;
			}
		}
	}
	int res = dp[N - 1][2];
	for (int i = 0; i < N; i++) {
		if (S[i] == '?') {
			res = (res * 3) % MOD;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 5840
A,B,C = map(int,input().split())
if A>C & C>B:
	print("Yes")
if B>C & C>A:
   	print("Yes")
if C>A & A>B:
	print("No")
if B>A & A>C:
	print("No")
if A>B & B>C:
	print("No")
if C>B & B>A:
	print("No")	
	

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

class DSU:
    def __init__(self, n):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a, b):
        x, y = self.leader(a), self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        stack = []
        while self.parent_or_size[a] >= 0:
            stack.append(a)
            a = self.parent_or_size[a]
        for i in stack:
            self.parent_or_size[i] = a
        return a

    def size(self, a):
        return -self.parent_or_size[self.leader(a)]

    def groups(self):
        leader_buf = [self.leader(i) for i in range(self._n)]
        group_size = [0] * self._n
        for i in leader_buf:
            group_size[i] += 1
        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)
        result = [i for i in result if i]
        return result



n, q = map(int, input().split())
dsu = DSU(n)

for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        dsu.merge(u, v)
    else:
        print(1 if dsu.same(u, v) else 0)


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

const int INF = 1e9 + 7;

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

  int mn = INF;
  int ans = 0;
  while ( n-- > 0 ) {
    int p;
    cin >> p;
    if ( p <= mn ) {
      mn = p;
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100
#define MAX 1000001
int main(){
  int i,j,ntop=0,otop=0, num[N],top=0;
  char str[MAX],c;
 
  while(1){
    scanf("%s",str);
    if(str[0]>='0'&&str[0]<='9')
      num[ntop++]=atoi(str);
    else{
      if(str[0]=='+')
	num[ntop-2]=num[ntop-2]+num[ntop-1];
      else if(str[0]=='-')
	num[ntop-2]=num[ntop-2]-num[ntop-1];
      else if(str[0]=='*')
	num[ntop-2]=num[ntop-2]*num[ntop-1];
      ntop--;
    }
    scanf("%c",&c);
    if(c=='\n')
      break;
  }
  printf("%d\n",num[0]);
  
  

  return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0) cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import product

def solve(n,a):
    testimony = product([0,1],repeat=n)
    ans = 0
    for l in testimony:
        flag = True
        for test in a:
            if l[test[0]] and l[test[1]] and (test[2] == 0):
                flag = False
            if l[test[0]] and l[test[1]]==0 and test[2]:
                flag = False
        if flag:
            ans = max(ans,sum(l))
    return ans



def main():
    N = int(input())
    a = []
    for i in range(N):
        tmp = int(input())
        for _ in range(tmp):
            x,y = map(int,input().split())
            a.append([i,x-1,y])
    print(solve(N,a))
    return

if __name__ == '__main__':
    main()


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

using Graph=vector<vector<int>>;

int main()
{
   int N,M; cin>>N>>M;
   Graph G(N);
   for(int i=0;i<M;i++){
      int a,b; cin>>a>>b;
      a--; b--;
      G[a].push_back(b);
   }

   vector<int> dp(N,-1);
   function<int(int)> rec=[&](int v)
   {
      if(dp[v]>=0) return dp[v];
      int res=0;
      for(int u:G[v]) res=max(res,rec(u)+1);
      return dp[v]=res;
   };

   for(int i=0;i<N;i++) if(dp[i]==-1){ rec(i); }
   cout<<*max_element(dp.begin(),dp.end())<<endl;
   return 0;
}


Measured memory_bytes: 8832
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
H_temp = [int(x) for x in range(N)]

for i in range(N):
  H_temp[i] = abs(float(A) - float(T - H[i] * 0.006))

print(H_temp.index(min(H_temp)) + 1)

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

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

	set<char> data;
	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		data.insert(c);
	}

	cout << (data.size() == 3 ? "Three" : "Four") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ld x,d;
    ll k;
    cin>>x>>k>>d;
    ll a=abs(x)/d,ans;
    if(a>=k) ans=abs(x)-k*d;
    else{
        k-=a;
        if(k%2==0) ans=abs(x)-a*d;
        else ans=abs(abs(x)-(a+1)*d);
    }
    cout<<ans;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b=1;
string d,f;
  char z;
  cin >>d ;
  a=d.size();
  for(int s=0;s<a;s+=2){
    z=d[s];
  if(z=='L'){
  f="No";
  break;}}
  
  for(int s=1;s<a;s+=2){
    z=d[s];
    //cout << z <<"\\";
  if(z=='R'){
  f="No";
  break;}}
  if(f=="No"){
  cout <<"No"<<endl;}
  else {cout <<"Yes" <<endl;}
}//奇数文字目がすべて R, U, D のいずれか。
//偶数文字目がすべて L, U, D のいずれか。

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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    for(auto &e : S) cin >> e;
    auto solve = [&](int bit) -> int {
        int res = __builtin_popcount(bit);
        int N = res + 1;
        vector<int> cnt(N);
        rep(j, W) {
            int now = 0, tmp = 0;
            rep(i, H) {
                cnt[now] += S[i][j] == '1';
                tmp += S[i][j] == '1';
                if(tmp > K) return H + W;
                if(bit & (1 << i)) now++, tmp = 0;
            }
            if(*max_element(cnt.begin(), cnt.end()) > K) {
                res++, j--;
                cnt.assign(N, 0);
            }
        }
        return res;
    };
    int ans = H + W;
    rep(i, 1 << (H - 1)) ans = min(ans, solve(i));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int X, Y, Z; cin >> X >> Y >> Z;
    int N = X + Y + Z;
    vec A(N), B(N), C(N);
    int ans = 0;
    REP(i, N){
        cin >> A[i] >> B[i] >> C[i];
        ans += C[i];
        A[i] -= C[i];
        B[i] -= C[i];
    }

    vector<Pii> D(N);
    REP(i, N) D[i] = Pii(A[i] - B[i], i);
    SORT(D);
    REVERSE(D);

    vec S1(N, 0), S2(N, 0);
    int tmp = 0;
    priority_queue<int> q1;
    REP(i, X){
        tmp += A[D[i].second];
        q1.push(-1 * A[D[i].second]);
    }
    S1[X - 1] += tmp;
    FOR(i, X, N){
        if(-1 * q1.top() < A[D[i].second]){
            tmp += A[D[i].second] + q1.top();
            q1.pop();
            q1.push(-1 * A[D[i].second]);
        }
        S1[i] += tmp;
    }

    tmp = 0;
    priority_queue<int> q2;
    REP(i, Y){
        tmp += B[D[N - 1 - i].second];
        q2.push(-1 * B[D[N - 1 - i].second]);
    }
    S2[N - Y] += tmp;
    FOR(i, Y, N){
        if(-1 * q2.top() < B[D[N - 1 - i].second]){
            tmp += B[D[N - 1 - i].second] + q2.top();
            q2.pop();
            q2.push(-1 * B[D[N - 1 - i].second]);
        }
        S2[N - 1 - i] += tmp;
    }

    //REP(i, N) cout << S1[i] << "," << S2[i] << endl;

    int ans2 = -1 * INF;
    FOR(i, X - 1, N - Y) ans2 = max(ans2, S1[i] + S2[i + 1]);
    cout << ans + ans2;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 6940
#include<iostream>
#include<string>

#define N 32
#define PLANE '.'
#define BLOCK '*'
#define STEEL '#'
#define WATER '-'
const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};
const char *tank_dir = "^>v<";
int conv[256]={0,};

using namespace std;

bool isinside(int i, int j, int h, int w){
  return 0<=i&&i<h&&0<=j&&j<w;
}

void simulate(char M[][N], int h, int w, const string &v)
{
  int ti;
  int tj;
  int dir;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      for(int k = 0; k < 4; ++k){
	if( tank_dir[k] == M[i][j] ){
	  ti = i;
	  tj = j;
	  dir = k;
	  M[i][j]=PLANE;
	}
      }
    }
  }
  conv['U']=0;
  conv['R']=1;
  conv['D']=2;
  conv['L']=3;

  for(int s=0;s<v.length();++s){
    switch(v[s]){
    case 'U':
    case 'D':
    case 'L':
    case 'R':
      {
	int ni = ti+di[conv[v[s]]];
	int nj = tj+dj[conv[v[s]]];
	dir = conv[v[s]];
	if( isinside(ni,nj,h,w) ){
	  if( M[ni][nj] == PLANE ){
	    ti = ni;
	    tj = nj;
	  }
	}
      }
      break;
    case 'S':
      {
	int ai=ti,aj=tj;
	while(true){
	  ai += di[dir];
	  aj += dj[dir];
	  
	  if( isinside(ai,aj,h,w) ){
	    if( M[ai][aj] == PLANE || M[ai][aj] == WATER ) continue;
	    else break;
	  }else break;
	  
	}
	if( M[ai][aj] == BLOCK ){
	  M[ai][aj] = PLANE;
	}
      }
      break;
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if( i == ti && j == tj ){
	putchar(tank_dir[ dir ]);
      }else{
	putchar(M[i][j]);
      }
    }
    putchar('\n');
  }
  return ;
}

int main()
{
  int T;
  cin >> T;
  for(int tc=1;tc<=T;++tc){
    int h,w;
    char M[N][N];
    string cmd;
    cin >> h >> w;
    if( tc > 1 )putchar('\n');
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
	cin >> M[i][j];
      }
    }
    int vlen;
    cin >> vlen;
    cin >> cmd;
    
    simulate( M, h, w, cmd );
  }
  return 0;
}

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

int main() {
int N;cin >> N;
vector<int> V(N);
vector<int> P(N);
vector<int> Q(N);
long int a = 0, b = 0;
bool A = 1, B = 1;

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

   V.at(i) = i + 1;

   }

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

   cin >> P.at(i);

   }

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

   cin >> Q.at(i);

   }

   do{

      if(A)a++;
      if(B)b++;
      int countA = 0;
      for(int i = 0; i < N; i++){
         if(V.at(i) == P.at(i))countA++;
      }
      
      if(countA == N)A = 0;
      int countB = 0;
      for(int i = 0; i < N; i++){
         if(V.at(i) == Q.at(i))countB++;
      }
      
      if(countB == N)B = 0;


   }while(next_permutation(V.begin(), V.end()));

cout << abs(a - b) << endl;

}

Measured memory_bytes: 256
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
ans.append(min(a) + min(b))
for i in range(M):
    x,y,c = list(map(int, input().split()))
    ans.append(a[x-1]+b[y-1]-c)
print(min(ans))

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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    int ans = 0;
    rep(i,n) cin >> d.at(i);
    for(int i = 0; i < n;i++){
        for(int j = i+1;j < n;j++){
            ans += d.at(i) * d.at(j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h,w;
    cin >> h >> w;
    string arx[2*h + 1];
    for(int i = 1; i <= 2*h; i+=2){
        string s;
        cin >> s;
        arx[i] = s;
        arx[i-1] = s;
    }
    forn(i,2*h){
        cout << arx[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from collections import deque
s=deque(list(input()))
q=int(input())
r = False
for i in range(q):
    tmp = list(input().split(' '))
    if tmp[0]=='1':
        r = not r
    elif (not r and tmp[1]=='1') or (r and tmp[1] =='2'):
        s.appendleft(tmp[2])
    else:
        s.append(tmp[2])
if not r:
    for i in s:
        print(i,end='')
else:
    for i in reversed(s):
        print(i,end='')

Measured memory_bytes: 7520
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <climits>
#include <functional>
#include <queue>
#include <cmath>
#include <utility>

using namespace std;

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

int N;
int a[300010];
int scoreL[100010], scoreR[100010];

signed main()
{
	cin >> N;

	rep(i, N*3) cin >> a[i];

	priority_queue<int, vector<int>, greater<int>> L;
	priority_queue<int> R;

	int sumL = 0, sumR = 0;
	for (int i = 0; i < N; ++i) {
		L.push(a[i]);
		sumL += a[i];
	}
	for (int i = N * 2; i < N * 3; ++i) {
		R.push(a[i]);
		sumR += a[i];
	}

	scoreL[0] = sumL;
	scoreR[0] = sumR;

	int l = N, r = N * 2 - 1;
	for (int i = 1; i <= N; ++i) {
		L.push(a[l]);
		sumL -= L.top(); L.pop();
		sumL += a[l];
		scoreL[i] = sumL;

		R.push(a[r]);
		sumR -= R.top(); R.pop();
		sumR += a[r];
		scoreR[i] = sumR;

		l++, r--;
	}

	int ans = -(LLONG_MAX/2);

	for (int i = 0; i <= N; ++i) {
		ans = max(ans, scoreL[i] - scoreR[N-i]);
	}

	cout << ans << endl;
}


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

#define PI acos(-1)
#define int long long int
#define pb push_back
#define mp make_pair
#define pi pair<string, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 1000001
#define MAXL 20
#define mod 998244353

signed main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  unordered_set<int> s;
  int maximum = INT_MIN;
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
    s.insert(v[i]);
    maximum = max(maximum, v[i]);
  }
  unordered_set<int> res;
  for (int i = 0; i < n; i++)
    if (v[i] != 0)
      for (int j = v[i] * 2; j <= maximum; j += v[i])
        if (s.find(j) != s.end())
          res.insert(j);
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++)
    mp[v[i]]++;
  int ans = n;
  for (auto it = mp.begin(); it != mp.end(); it++)
  {
    if (it->second >= 2)
    {
      if (res.find(it->first) == res.end())
      {
        int val = it->second;
        while (val--)
          ans--;
      }
    }
    if (res.find(it->first) != res.end())
    {
      int val = it->second;
      while (val--)
        ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 29548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e5+10;
ll x[M] , v[M] , s[M] ,r[M] , ans , n , m;
int main(){
	cin >> n >> m;
	for(int i = 1;i <= n;i ++) cin >> x[i] >> v[i];
	for(int i = 1;i <= n;i ++) s[i] = s[i-1] + v[i];
	for(int i = n;i >= 0;i --) r[i] = r[i+1] + v[i];
	for(int i = 1;i <= n;i ++) s[i] = max(max(0LL , s[i] - x[i]),s[i-1]);
	for(int i = n;i >= 0;i --) r[i] = max(max(0LL, r[i] - m + x[i] ),r[i+1]);
	for(int i = 1;i <= n;i ++) ans = max(ans,s[i] + max(0LL,r[i+1] - x[i]));
	for(int i = n;i >= 0;i --) ans = max(ans,r[i] + max(0LL,s[i-1] - m + x[i]));
	cout << ans << '\n';
	return 0;
}

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

int main() {
	int i = 0;
	int N;
	while (true) {
		cin >> N;
		if (N == 0) {
			break;
		}
		cout << "Case " << i + 1 << ": " << N << endl;
		i++;
	}
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define pinf LLONG_MAX
#define ninf LLONG_MIN
#define all(v) v.begin(),v.end()
#define endl '\n'
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define pi 3.1415926535897932384
using namespace std;
using namespace __gnu_pbds;

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
tree_order_statistics_node_update> ordered_multiset;

void pv(vector<auto> &v,ll start = 0, ll end = 0){
    if(end != v.size() - 1) end = v.size() - 1;
    for(ll i = start; i <= end; i++) cout << v[i] << " "; cout << endl;
}
void inline pp(pair<auto, auto> p) { cout << p.ff << " " << p.ss << endl; }
void inline in(vector<auto> &v, ll n) {
    v.resize(n); for(ll i = 0; i < n; i++) cin >> v[i];
}
void inline sortv(vector<auto> &v) { sort(all(v)); }
void inline sortvr(vector<auto> &v) { sort(v.rbegin(), v.rend()); }
bool inline isVowel (char c) {
    return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int solve();
int main(){
    fast();
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}
int solve(){
    ll n;
    cin >> n;
    vll a;
    in(a, n);
    sortv(a);
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            for(int k = j + 1; k < n; ++k){
                set<ll> st;
                st.insert(a[i]);st.insert(a[j]);st.insert(a[k]);
                if(a[i] + a[j] > a[k] && st.size() == 3)
                    ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
while True:
    # num of judges
    n = int(input())
    if n == 0:
        break

    scores = []
    for i in range(n):
        scores.append(int(input()))

    final_score = int( (sum(scores) - max(scores) - min(scores)) / (n - 2) )
    print(final_score)

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

map<int, bool> mp;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, k;
    cin >> a >> b >> k;
    FOR(i, a, a + k) {
        if(i > b) break;
        cout << i << endl;
        mp[i] = true;
    }
    for(int i = b - k + 1; i <= b; ++i) {
        if(i < a) break;
        if(!mp[i]) cout << i << endl;
        mp[i] = true;
    }
    return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
mas = [list(input()) for i in range(H)]
new_mas = []
new_mas2 = []
for row in mas:
    if "#" in row:
        new_mas.append(row)
    elif "#" not in row:
        continue

for column in list(zip(*new_mas)):
    if "#" in column:
        new_mas2.append(column)
    elif "#" not in column:
        continue

for i in list(zip(*new_mas2)):
    for j in i:
        print(j,end="")
    print()

Measured memory_bytes: 43224
import sys

H,W = 0,0
Data = []

def check(x,y):
    if x > 0:
        if Data[y][x-1] == '#':
            return True
    if x < W-1:
        if Data[y][x+1] == '#':
            return True
    if y > 0:
        if Data[y-1][x] == '#':
            return True
    if y < H-1:
        if Data[y+1][x] == '#':
            return True
    return False 

H,W = map(int,input().split())
for _ in range(H):
    data = list(input())
    Data.append(data)

for y in range(H):
    for x in range(W):
        c = Data[y][x]
        if c == '#':
            if check(x,y) == False:
                print('No')
                sys.exit()
print('Yes')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) ((a).begin(),(a).end())
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const int inf = 1e8;
int n;
int c[1010];
vector<pii> g[1010];
 
int rec(int v, int prv){
  if(c[v])return inf;
 
  int ans = 0;
  for(pii e : g[v]){
    int u = e.first, cost = e.second;
    if(u==prv)continue;
    ans += min(cost, rec(u,v));
  }
 
  return ans;
}
 
int main(){
  cin >> n;
  c[0] = 0;
  rep(i,n-1)cin >> c[i+1];
 
  rep(i,n-1){
    int u,v,p;
    cin >> u >> v >> p;
    g[u].push_back(pii(v,p));
    g[v].push_back(pii(u,p));
  }
 
  cout << rec(0,-1) << endl;
}

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

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int S, N,i;
            N = int.Parse(Console.ReadLine());

            S = 0;

            for (i=1; i<=N; i++)
            {
                S = S + i;                
            }

            Console.WriteLine(S);

            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];
    rep(i, H) rep(j, W) if (S[i][j] == '.') S[i][j] = '0';
    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '#') {
                if (i > 0 && j > 0 && S[i - 1][j - 1] != '#') S[i - 1][j - 1]++;
                if (i > 0 && S[i - 1][j] != '#') S[i - 1][j]++;
                if (i > 0 && j < W - 1 && S[i - 1][j + 1] != '#') S[i - 1][j + 1]++;

                if (j > 0 && S[i][j - 1] != '#') S[i][j - 1]++;
                if (j < W - 1 && S[i][j + 1] != '#') S[i][j + 1]++;

                if (i < H - 1 && j > 0 && S[i + 1][j - 1] != '#') S[i + 1][j - 1]++;
                if (i < H - 1 && S[i + 1][j] != '#') S[i + 1][j]++;
                if (i < H - 1 && j < W - 1 && S[i + 1][j + 1] != '#') S[i + 1][j + 1]++;
            }
        }
    }
    rep(i, H) cout << S[i] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int H, W, K;
char s[10][1000];

int solve() {
  int ans = INF;

  REP(bit, (1 << (H - 1))) {
    vector<int> ord(H, 0);
    int N = 0;
    REP(h, H - 1) {
      if(bit & (1 << h))ord[h + 1] = ord[h] + 1, N++;
      else ord[h + 1] = ord[h];
    }

    vector<int> sums(N + 1, 0);
    int vert = 0;
    bool sok = true;
    REP(w, W) {
      vector<int> one(N + 1, 0);
      bool ok = true;

      REP(h, H) {
        one[ord[h]] += s[h][w] - '0';
        sums[ord[h]] += s[h][w] - '0';

        if(one[ord[h]] > K) sok = false;
        if(sums[ord[h]] > K) ok = false;
      }
      if(!ok) vert++, sums = one;
    }
    if(sok) ans = min(N + vert, ans);

  }
  return ans;
}

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

  cin >> H >> W >> K;

  REP(i, H) REP(j, W) cin >> s[i][j];

  cout << solve() << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#include<random>
#pragma warning(disable:4996)
using namespace std;

bool check(const vector<int>&anss, const vector<vector<int>>&cards) {
	for (auto card : cards) {
		int sum=0;
		for (auto num : card) {
			sum+=anss[num];
		}
		if(sum<anss.size()/8||sum>anss.size()*3/8)return false;
	}
	return true;
}

int main() {
	int N,M;cin>>N>>M;
	vector<vector<int>>cards(M);
	for (int i = 0; i < M; ++i) {
		cards[i].resize(N/2);
		for(int j = 0; j < N / 2; ++j) {
			cin>>cards[i][j];
			cards[i][j]--;
		}
	}
	vector<int>anss(N,0);
	for (int i = 0; i < N / 2; ++i) {
		anss[i]=1;
	}
	random_device rnd;
	mt19937 mt(rnd());
	shuffle(anss.begin(),anss.end(),mt);
	while (true) {
		if (check(anss, cards)) {
			break;
		}
		else {
			for (auto card : cards) {
				int sum = 0;
				for (auto num : card) {
					sum += anss[num];
				}
				if (sum < anss.size() / 8) {
					int use;
					int unuse;
					while (true) {
						int n = mt() % (card.size() * 2);
						if (!binary_search(card.begin(), card.end(), n)&&anss[n]) {
							unuse = n;
							break;
						}
					}
					while (true) {
						int n = card[mt()%card.size()];
						if ( !anss[n]) {
							use = n;
							break;
						}
					}
					swap(anss[use],anss[unuse]);
				}
				else if (sum > 3*anss.size() / 8) {
					int use;
					int unuse;
					while (true) {
						int n = mt() % (card.size() * 2);
						if (!binary_search(card.begin(), card.end(), n) && !anss[n]) {
							use = n;
							break;
						}
					}
					while (true) {
						int n = card[mt() % card.size()];
						if (anss[n]) {
							unuse = n;
							break;
						}
					}
					swap(anss[use], anss[unuse]);
				}
			}
		}
	}
	for (int i = 0; i < anss.size(); ++i) {
		cout<<anss[i];
	}
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 3896
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    string T;
    cin >> T;
    REP(i,SZ(T)) {
        if (T[i] == '?') cout << 'D';
        else cout << T[i];
    }
    print();
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/nomura2020/nomura2020_b && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/nomura2020/nomura2020_b && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/nomura2020/nomura2020_b && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3748
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;
int main(){
	char s;
	cin >> s;
	char ans = s+1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<long long> vll, vLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18

ll combi(ll a, ll b){
    ll ret = 1;
    REP(i,b){
        ret *= (a-(ll)i);
        if(ret>=mod) ret %= mod;
    }
    for(int i=2;i<=b;i++){
        if(ret%i!=0){
            while(ret%(ll)i!=0){
                ret+=mod;
            }
        }
        ret /= (ll)i;
        if(ret>=mod) ret %= mod;
    }
    //cout << a << " " << b << " " << ret << endl;
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    ll ans = 1;
    vector<int> so;
    if(m==1){
        ans = 1;
    }else{
        for(int i=2;i<=2;i++){
            if(m%i==0){
                bool t = true;
                for(int j=0;j<so.size();j++){
                    if(i%so[j]==0){
                        t = false;
                        break;
                    }
                }
                if(t){
                    so.push_back(i);
                    int tmp = m;
                    int co = 0;
                    while(tmp%i==0){
                        tmp/=i;
                        co++;
                    }
                    ll x = combi((ll)n+co-1,(ll)co);
                   
                    ans *= x;
                    if(ans>=mod) ans %= mod;
                    //cout << ans << endl;
                }
            }
        }
        for(int i=3;i<=m;i+=2){
            
            if(m%i==0){
                bool t = true;
                for(int j=0;j<so.size();j++){
                    if(i%so[j]==0){
                        t = false;
                        break;
                    }
                }
                if(t){
                    so.push_back(i);
                    int tmp = m;
                    int co = 0;
                    while(tmp%i==0){
                        tmp/=i;
                        co++;
                    }
                    ll x = combi((ll)n+co-1,(ll)co);
                   
                    ans *= x;
                    if(ans>=mod) ans %= mod;
                    //cout << ans << endl;
                }
            }
                
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
int dc=100000;
#define MAX 100010
int count[9]={};

int main(){
  if(df)printf("*** debug mode ***\n");
  int n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    a/=400;
    if(a<=7)count[a]|=1;
    else count[8]++;
  }
  int s=0;
  for(i=0;i<8;i++){
    s+=count[i];
  }
  

  printf("%d %d",s+(count[8]&&(s==0)?1:0),s+count[8]);
  return 0;
}


/// confirm df==0 ///


Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	int N=0,K=0;
	int ans = 0;
	cin >> N  >>K;
	for (int i = 0; i < N; ans++) {
		if (i == 0)
			i += K;
		else
			i += K - 1;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}

struct Cmd {
  int y1, x1, y2, x2;
};

lli h, w;
vector<string> bd;
int main() {
  cin >> h >> w;
  bd = decltype(bd)(h+2, string(w+2, '.'));
  bd[0] = bd[h+1] = string(w+2, '#');
  for (int j=1; j<=h; ++j) {
    bd[j][0] = bd[j][w+1] = '#';
    for (int i=1; i<=w; ++i) {
      lli x; cin >> x;
      bd[j][i] = x % 2 == 0 ? '.' : '*';
    }
  }
  int x = 1, y = 1, px, py, vx = 1, vy = 0;
  bool hold = false;
  vector<Cmd> cmds;
  while (true) {
    if (hold) cmds.push_back({py, px, y, x});
    if (bd[y][x] == '*') {
      hold = !hold;
    }
    int failcnt = 0;
    while (bd[y+vy][x+vx] == '#') {
      int t = vx;
      vx = -vy;
      vy = t;
      if (failcnt >= 4) goto out;
      ++failcnt;
    }
    bd[y][x] = '#';
    px = x; py = y;
    x += vx; y += vy;
  }
out:
  
  cout << cmds.size() << endl;
  for (auto&& c : cmds) 
    cout << c.y1 << ' ' << c.x1 << ' ' << c.y2 << ' ' << c.x2 << endl;
  
  return 0;
}


Measured memory_bytes: 4596
//Created by Young Charlie
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s; cin>>s;
	for(int i = 0; i <int(s.size()) - 2; i++){
		if(s[i] == s[i + 1] && s[i + 1] == s[i + 2]){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define mod 1000000007
#define inf 1e17
using namespace std;

int main() 
{ 

   int n;
   cin>>n;
   // vector<int>vec;
   // for(int i=0;i<n;i++)
   // {
   //    int x;
   //    cin>>x;
   //    vec.pb(x);
   // }
   vector<vector<int> > dp( n+1 , vector<int> (3, 0));
   dp[0][0] = 0;
   dp[0][1] = 0;
   dp[0][2] = 0;
    int a,b,c;
   for(int i=1;i<n+1;i++)
   {
      cin>>a>>b>>c;
      dp[i][0] = a + max(dp[i-1][1],dp[i-1][2]);
      dp[i][1] = b + max(dp[i-1][0],dp[i-1][2]);
      dp[i][2] = c + max(dp[i-1][0],dp[i-1][1]);
   }
   cout<<max(dp[n][2],max(dp[n][0],dp[n][1]))<<endl;
} 

Measured memory_bytes: 5760
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

signed main() {
    vl vec;
    SS(ll,x,y,z,K);SV(ll,a,x);SV(ll,b,y);SV(ll,c,z);
    sort(a.rbegin(),a.rend());sort(b.rbegin(),b.rend());sort(c.rbegin(),c.rend());
    rep(i,x){
        rep(j,y){
            rep(k,z){
                if ((i + 1) * (j + 1) * (k + 1) <= K) vec.emplace_back(a[i] + b[j] + c[k]);
                else break;
            }
        }
    }
    sort(vec.rbegin(), vec.rend());
    rep(i,K)p(vec[i]);
}

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

int main(){
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	string s1,s2;
	for(int i = 0 ; i < w ; i += 1){
		if(i < a){
			s1 += '1';
			s2 += '0';
		}else{
			s1 += '0';
			s2 += '1';
		}
	}
	for(int i = 0 ; i < h ; i += 1){
		if(i < b){
			cout << s1 << endl;
		}else{
			cout << s2 << endl;
		}
	}
}

Measured memory_bytes: 1280