akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;
    
#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;


int main(){
    int n,x;
    int l[100];

    cin >> n >> x;
    rep(i,n){
        cin >> l[i];
    }

    int distance = 0;
    int ans = 0;
    while(distance <= x && ans < n){
        distance += l[ans];
        ans ++;
    }

    if(ans == n){
        if(distance <= x) ans ++;
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 256
import itertools
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
all_n = []
for i in itertools.permutations(a):
    all_n.append(int("".join(map(str, i))))
all_n = sorted(all_n)
a = int("".join(map(str, a)))
b = int("".join(map(str, b)))
num_a = 0
num_b = 0
for i in range(len(all_n)):
    if all_n[i] == a:
        num_a = i + 1
    if all_n[i] == b:
        num_b = i + 1
print(abs(num_a - num_b))

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define Fix( x ) setprecision( x ) << fixed
#define mem( a , x ) memset( a , x , sizeof( a ) )
#define bug( a , b ) cerr<< #a <<" = "<<a<<" , "<< #b <<" = "<<b<<"\n";
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define FOR( i , a , b ) for( int i = a; i <= b; i++ )
#define ROF( i , a , b ) for( int i = a; i >= b; i-- )
#define sz( V ) (int)V.size( )
#define all( V ) V.begin( ),V.end( )
#define Found( S , val ) S.find( val ) != S.end( )
#define Unique( V ) sort( all( V ) ), V.erase( unique( all( V ) ), V.end() )
typedef pair < int , int > ii;
typedef pair < int , ii > iii;
typedef long long int LL;
typedef unsigned long long uLL;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const int N = 100005;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos( -1.0 );


int main( int argc, char const *argv[] ) {
        fast_io;
        string s;
        cin >> s;
        int n;
        cin >> n;
        while( sz(s)%n != 0 ) s += 'X';
        vector < string > V;
        string ans = "";
        for( int i = 0; i < s.size(); i += n ) {
                ans += s[i];
        }
        cout << ans << endl;
        return 0;
}








Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>v and j>=0:
        a[j+1] = a[j]
        j -=1

    a[j+1] = v
    print(*a)
    


Measured memory_bytes: 5980
#b
n=int(input())
sp=[ [0,0,0] for i in range(n)]
for i in range(n):
    ss,pp = input().split()
    sp[i] = [ss,int(pp),i+1]
    
for ss in sorted( sorted(sp,key=lambda x:x[1], reverse=True) ,key=lambda x:x[0]):
    print(ss[2])

Measured memory_bytes: 40336
#include <stdio.h>
int main(void) {
    int a, b, answer;
    char op;
    while (scanf("%d %c %d", &a, &op, &b) == 3) {
        if (op == '?') break;
        if (op == '+') answer = a + b;
        if (op == '-') answer = a - b;
        if (op == '*') answer = a * b;
        if (op == '/') answer = a / b;
        printf("%d\n", answer);
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)     for(long long int i=a; i<n; i++)
#define loop(i,a,n)     for(long long int i=a; i>=n; i--)       

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	char d[a][b], e[a][b];
	int tot=0;
	forr(i,0,a)
	{
		forr(j,0,b)
		{
			cin>>d[i][j];
			e[i][j]=d[i][j];
			if(d[i][j]=='#')
				tot++;
		}
	}
	int row[a+1]={},col[b+1]={},ans=0;
	forr(i,0,(1<<a))
	{
		forr(j,0,a)
		{
			if(i&(1<<j))
				row[j]=0;
			else
				row[j]=1;
		}
		int ct=0, xx=0;
		forr(j,0,a)
		{
			if(row[j]==1)
			{
				forr(k,0,b)
				{	
					if(d[j][k]=='#')
						ct++;
					d[j][k]='.';
				}
			}
		}
		xx=ct;
		forr(j,0,(1<<b))
		{
			//cout<<xx<<'\n';
			forr(k,0,b)
			{
				if(j&(1<<k))
					col[k]=0;
				else
					col[k]=1;
			}
			forr(k,0,b)
			{
				if(col[k])
				{
					forr(l,0,a)
					{
						if(d[l][k]=='#')
						{
							ct++;
						}
					}
				}
			}	
			//cout<<ct-xx<<'\n';
			if(tot-ct==c)
			{
				/*cout<<'\n';
				forr(kk,0,b)
					cout<<col[kk]<<' ';
					cout<<'\n';
				forr(kk,0,a)
					cout<<row[kk]<<' ';
					cout<<'\n'<<'\n';
					//break;*/ans++;
			}
			ct=xx;
		}
		forr(j,0,a)
		{
			forr(k,0,b)
				d[j][k]=e[j][k];
		}
		//break;	
	}
	cout<<ans;
	
		
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
  	int n;
  	cin>>n;
  	bool ans = false;
  	while(n){
    	if(n%10==7){
        	ans = true;
          break;
        }
      n=n/10;
    }
  	if(ans){
    	cout<<"Yes"<<endl;
    } 
  	else{cout<<"No"<<endl;}
 	return 0; 
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
const long mod=1e9+7;
int N,K,A;
long dp[101][101][256];
main()
{
	cin>>N>>K;
	dp[0][0][0]=1;
	for(int i=0;i<N;i++)
	{
		cin>>A;
		for(int j=0;j<=i;j++)for(int k=0;k<256;k++)
		{
			(dp[i+1][j][k]+=dp[i][j][k])%=mod;
			(dp[i+1][j+1][k^A]+=dp[i][j][k]*(j+1))%=mod;
		}
	}
	long ans=0;
	for(int j=0;j<=N;j++)ans+=dp[N][j][K];
	cout<<ans%mod<<endl;
}


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

const int MAX = 500005;

struct Query
{
    int l, r, idx;
};
bool cmp(Query x, Query y)
{
    return x.r < y.r;
}
void update(int idx, int val, int bit[], int n)
{
    for (; idx <= n; idx += idx&-idx)
        bit[idx] += val;
}
int query(int idx, int bit[], int n)
{
    int sum = 0;
    for (; idx>0; idx-=idx&-idx)
        sum += bit[idx];
    return sum;
}

void answeringQueries(int arr[], int n, Query queries[], int q)
{
    int bit[n+1];
    memset(bit, 0, sizeof(bit));
    int last_visit[MAX];
    memset(last_visit, -1, sizeof(last_visit));
    int ans[q];
    int query_counter = 0;
    for (int i=0; i<n; i++)
    {
        if (last_visit[arr[i]] !=-1)
            update (last_visit[arr[i]] + 1, -1, bit, n);
        last_visit[arr[i]] = i;
        update(i + 1, 1, bit, n);
        while (query_counter < q && queries[query_counter].r == i)
        {  //cout<<"a";
            ans[queries[query_counter].idx] =
                     query(queries[query_counter].r + 1, bit, n)-
                     query(queries[query_counter].l, bit, n);
            query_counter++;
        }
    }
    for (int i=0; i<q; i++)
        cout << ans[i] << "\n";

 return ;
}

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

  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];

  Query queries[q];
    for(int i=0;i<q;i++){
      int l,r;
      cin>>l>>r;
      queries[i].l=l-1;
      queries[i].r=r-1;
      queries[i].idx=i;
    }
    sort(queries, queries+q, cmp);
   answeringQueries(arr, n, queries, q);
    }


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

int main() {
    int n, p; cin >> n >> p;
    string s; cin >> s;

    if(p == 2 || p == 5) {
        long long res = 0;
        for(int i=0; i<n; ++i) {
            if((int)(s[i] - '0') % p == 0) res += i + 1;
        }
        cout << res << '\n';
    } else {
        long long res = 0, cur = 0, p10 = 1;
        map<int, int> cnt;
        cnt[0] = 1;
        for(int i=n-1; i>=0; --i) {
            cur = (cur + (int)(s[i] - '0') * p10) % p;
            res += cnt[cur];
            cnt[cur] += 1;
            p10 = p10 * 10 % p;
        }
        cout << res << '\n';
    }
}

Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <tuple>
using namespace std;

long long N, M, A[1 << 18], B[1 << 18], cnt;
vector<pair<long long, long long>>vec;

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		vec.push_back(make_pair(A[i], B[i]));
	}
	sort(vec.begin(), vec.end());

	for (int i = 0; i < vec.size(); i++) {
		for (int j = 0; j < vec[i].second; j++) {
			if (M == 0) break;
			cnt += vec[i].first; M--;
		}
		if (M == 0) break;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 4980
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
int main(){
    int n, h;
    cin>>n>>h;
    vector<int> a, b;
    int c, d;
    rep(i, n){
        cin>>c>>d;
        a.push_back(c);
        b.push_back(d);
    }
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());
    int e=0;
    while(h>0){
        if(a[0]>=b[0]){
            e+=(h + a[0] - 1) / a[0];
            break;
        }
        h-=b[0];
        e++;
        b.erase(b.begin());
        if(b.size()==0){
            e+=(h + a[0] - 1) / a[0];
            break;
        }
    }
    cout<<e<<endl;
    return 0;
}

Measured memory_bytes: 1276
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;
    unordered_map<string, int> m;
    for (int i = 0; i < N; i++) {
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        m[str]++;
    }

    int ret = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
        ret += it->second * (it->second - 1) / 2;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 10660
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

  int N, M;
  cin >> N >> M;

  if (M == 0) {
    if (N == 1)
      cout << 0 << endl;
    else
      cout << pow(10, N - 1) << endl;
    return 0;
  }
  vector<pair<int, int> > P(M);
  REP(i, M) {
    int s, c;
    cin >> s >> c;
    P[i] = make_pair(s, c);
  }

  sort(P.begin(), P.end());
  P.erase(unique(P.begin(), P.end()), P.end());

  int len = P.size();
  if (N == 1) {
    if (len > 1)
      cout << -1 << endl;
    else
      cout << P[0].second << endl;
    return 0;
  }

  string ans[N];
  REP(i, N) ans[i] = "-1";
  REP(i, len) {
    if (P[i].first == 1 && P[i].second == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[P[i].first - 1] != "-1") {
      cout << -1 << endl;
      return 0;
    }
    ans[P[i].first - 1] = to_string(P[i].second);
  }

  if (ans[0] == "-1") ans[0] = "1";
  if (ans[0] == "") ans[0] = "1";

  for (int i = 1; i < N; i++) {
    if (ans[i] == "-1") ans[i] = "0";
  }

  // REP(i, N) cout << "ans[" << i << "] = " << ans[i] << endl;
  REP(i, N) { cout << ans[i]; }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 31/07/2020

from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

h, w = iia()
arr = []
for i in range(h):
    arr.append(list(is1()))
dp = [[0 for i in range(w)] for j in range(h)]
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if i > 0 and j > 0 and arr[i][j] == '.':
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
        elif i > 0 and arr[i][j] == '.':
            dp[i][j] = dp[i - 1][j]
        elif j > 0 and arr[i][j] == '.':
            dp[i][j] = dp[i][j - 1]
print(dp[-1][-1] % mod)

Measured memory_bytes: 289584
# include <iostream>

using namespace std;

int main(){

int a, b; 
cin >> a >> b;
    if(a!=1 && b!=1){
        if(a>b){
            cout << "Alice" << endl;
        }
        else if(a<b){
            cout << "Bob" << endl;
        }
        else{
            cout << "Draw" << endl;
        }
    }
    else if(a!=1 && b==1){
        cout << "Bob" << endl;
    }
    else if(a==1 && b!=1){
        cout << "Alice" << endl;
    }
    else{
        cout << "Draw" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(15);
  string s;
  cin >> s;
  rep(i,0,s.size()){
    if(s[i]=='R' && i%2==1) {cNo;return 0;}
    if(s[i]=='L' && i%2==0) {cNo;return 0;}
    
  }
  cYes;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using ll = long long int;
ll n, a[100003], b[100003], ans = 0;

int main(void) {

	scanf("%lld", &n);
	for (ll i = 0; i < n + 1; i++) scanf("%lld", &a[i]); for (ll j = 0; j < n; j++) scanf("%lld", &b[j]);
	
	for (int i = 0; i < n; i++) {

		if (b[i] <= a[i]) ans += b[i], b[i] = 0;
		else ans += a[i], b[i] -= a[i];

		if (b[i] <= a[i + 1]) ans += b[i], a[i + 1] -= b[i];
		else ans += a[i + 1], a[i + 1] = 0;

	}

	printf("%lld\n", ans);	
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int n,m;
int ans;
set<int> g[100];
int C[100];

int main(){
  scanf("%d %d", &n, &m);
  for(int i=0;i<n;i++){
    printf("lst %d\n",i);
    fflush(stdout);
    
    int k;
    scanf("%d",&k);
    C[i]=k;
    for(int j=0;j<k;j++){
      int v;
      scanf("%d",&v);
      if(v!=-1){
        g[i].insert(v);
        g[v].insert(i);
      }
    }
  }
  
  ans=0;
  for(int pos=0;pos<n;pos++){
    ans+= C[pos]*(C[pos]-1);
  }
  
  printf("ans %d\n",ans);
  fflush(stdout);
  return 0;
}

Measured memory_bytes: 1332
#include <stdio.h>

#define max(a, b) (a) < (b) ? (b) : (a)
int main() {
    int A;
    int B;

    scanf("%d", &A);
    scanf("%d", &B);

    printf("%d\n", max(A - 2 * B, 0));

    return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(void)
{
  int a[3];
  int fmax=0;
  int smax=0;
  
  cin>>a[0]>>a[1]>>a[2];
  
  for(int i=0;i<3;i++){
    if(a[i]==5){fmax++;}
    if(a[i]==7){smax++;}
  }
  
  if((fmax==2)&&(smax==1)){
    puts("YES");
  }else{
    puts("NO");
  }
  
  return 0;
}

Measured memory_bytes: 256
def cross_product(a,b):#a,bは複素数、だけどベクトル扱いしよう
    return (a.conjugate()*b).imag

def abs_area_vector(ax,ay,bx,by):#3点(0,0)(ax,ay)(bx,by)で構成される三角形の面積の絶対値
    return abs(0.5 * (cross_product(complex(ax,ay),complex(bx,by))))

def abs_area_3point(ax,ay,bx,by,cx,cy):#3点(ax,ay)(bx,by)(cx,cy)で構成される三角形の面積の絶対値
    return abs_area_vector(bx-ax,by-ay,cx-ax,cy-ay)

try:
    while True:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float,input().split())
        abc = abs_area_3point(x1,y1,x2,y2,x3,y3)
        pab = abs_area_3point(x1,y1,x2,y2,xp,yp)
        pbc = abs_area_3point(x2,y2,x3,y3,xp,yp)
        pca = abs_area_3point(x1,y1,x3,y3,xp,yp)
        #ここらへんで結構ミスあったから今度からはもっと簡潔に書けるように何か関数でも用意すべき
        print("NO" if pab * pbc * pca == 0 or abc != pab + pbc + pca else "YES")
except  (EOFError,ValueError):
    pass





Measured memory_bytes: 5596
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int h,w;
	bool ans=true;
	cin >>h>>w;
	vector<string> a(h);
	input(a);
	map<char, int> dis;
	rep(i, h) {
		rep(j, w) { dis[a[i][j]]++; }
	}
	int two = 0;
	int one = 0;
	repi(itr, dis) {
		if (itr->S % 2 == 1) {
			one++;
		} else if (itr->S % 4 != 0) {
			two++;
		}
	}
	if (h % 2 == 1 and w % 2 == 1) {
		ans &= (one == 1);
		ans &= (two <= h / 2 + w / 2);
	} else if (h % 2 == 0 and w % 2 == 0) {
		ans &= (one == 0 and two == 0);
	} else {
		ans &= (one == 0);
		if (h % 2 == 0) {
			ans &= (two <= h / 2);
		}else
		{
			ans &= (two <= w / 2);
		}
		
	    }

	cout<<solve(ans)<<endl;
}
/*
 5 4 
*/

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

signed main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    cout << a[n-1] << endl;
    rep(i,n){
        if(2*a[i]>a[n-1]){
            if(2*a[i]-a[n-1]<abs(2*a[i-1]-a[n-1])||i==0) cout << a[i] << endl;
            else cout << a[i-1] << endl;
            return 0;
        }
    }
}


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

int main() {
  int a, b, c, d, ans;
  cin >> a >> b >> c >> d;
  
  if (a <= c) {
    if (c < b) {
      if (b < d) ans = b - c;
      else  ans = d - c;
    } else {
      ans = 0;
    }
  } else {
    if (a < d) {
      if (d < b) ans = d - a;
      else  ans = b - a;
    } else {
      ans = 0;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3604
// C.

#include <iostream>
#include <cstdio>

using namespace std;

int cnt[256];

bool dec(int r) {
	for (int i = 'a'; r >= 1 && i <= 'z'; ++i) {
		if (cnt[i] > 0 && (cnt[i] % 4) != 0 && (cnt[i] % 2) == 0) {
			cnt[i] -= 2;
			--r;
		}
	}
	for (int i = 'a'; r >= 2 && i <= 'z'; ++i) {
		while (r >= 2 && cnt[i] > 0 && (cnt[i] % 4) == 0) {
			cnt[i] -= 4;
			r -= 2;
		}
	}
	return r == 0;
}

bool check(int h, int w) {
	if ((h % 2) == 0 && (w % 2) == 0) {

	} else if ((h % 2) != 0 && (w % 2) != 0) {
		int oc = 0;
		for (int i = 'a'; i <= 'z'; ++i) {
			if (cnt[i] % 2) {
				--cnt[i];
				++oc;
			}
		}
		if (oc != 1) {
			return false;
		}
		if (!dec((w - 1) / 2 + (h - 1) / 2)) {
			return false;
		}
	} else {
		if ((w % 2) != 0) {
			swap(h, w);
		}
		if (!dec(w / 2)) {
			return false;
		}
	}
	for (int i = 'a'; i <= 'z'; ++i) {
		if (cnt[i] % 4) {
			return false;
		}
	}
	return true;
}

int main(int argc, char *argv[]) {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < w; ++j) {
			cnt[s[j]] += 1;
		}
	}
	bool ans = check(h, w);
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int nu(char i){
  int A=i-'a';
  return A;
}
  
int main(){
  int N;
  string S;
  cin>>N>>S;
  int maxi=0;
  for(int i=1;i<N-1;i++){
    int count=0;
    vector<int>MAE(26);
    vector<int>ATO(26);
    for(int j=0;j<i;j++){
      int mark=nu(S.at(j));
      if(MAE.at(mark)==0){
        MAE.at(mark)=1;
      }
    }
    for(int j=i;j<N;j++){
      int mark=nu(S.at(j));
      if(ATO.at(mark)==0){
        ATO.at(mark)=1;
      }
    }
    for(int j=0;j<26;j++){
      if(MAE.at(j)==1&&ATO.at(j)==1){
        count=count+1;
      }
    }
    maxi=max(maxi,count);
  }
  cout<<maxi<<endl;
}

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

int main() {
	int w, a, b; cin >> w >> a >> b;
	if (abs(a-b) < w) cout << 0 << endl;
	else cout << min(abs(w + a - b), abs(w + b - a)) << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

public class Don
{
    public Don() { }
    private Reader r = new Reader();

    public void Solve()
    {
        var N = r.nextInt();
        var S = r.next();

        var p = 0;
        var max = 0;
        for(var i = 0; i < N; i++)
        {
            if (S[i] == 'I')
            {
                p++;
                max = Math.Max(max, p);
            } else
            {
                p--;
            }

        }

        Console.WriteLine(max);

    }

    public static void Main(string[] args)
    {
        new Don().Solve();
    }

}

class Reader
{
    string[] s;
    int i;
    char[] cs = new char[] { ' ' };

    public Reader()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length)
            return s[i++];
        var input = Console.ReadLine();
        while (input == "")
            input = Console.ReadLine();
        s = input.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

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

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

void rec(int d, ll val, vector<ll> &V){
    V.push_back(val);
    if(d == 10) return;

    for(int j = -1; j <= 1; j++){
        int add = (val % 10) + j;
        if(0 <= add && add <= 9 ) rec(d+1, val*10 + add, V);
    }
}

int main() {
    int k; cin >> k;
    vector<ll> V;
    for(int i = 1; i < 10; i++){
        rec(1,i,V);
    }
    sort(V.begin(),V.end());
    cout << V[k - 1] << endl;
}

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

int main(){
  int n;
  int tmp;
  long long int num;
  vector<int> a;
  vector<int> b;
  cin >> n;
  for(int i=0; i<n+1; i++){
    cin >> tmp;
    a.push_back(tmp);
  }
  for(int i=0; i<n; i++){
    cin >> tmp;
    b.push_back(tmp);
  }
  for(int i=0; i<n; i++){
    tmp = min(a.at(i), b.at(i));
    num += tmp;
    a.at(i) -= tmp;
    b.at(i) -= tmp;
    tmp = min(a.at(i+1), b.at(i));
    num += tmp;
    a.at(i+1) -= tmp;
    b.at(i) -= tmp;
  }
  cout << num << endl;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(){
	int h, w, i, j;
	while (1){
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0){
			return 0;
		}
		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>


using namespace std;



long long int maxi = 1e5 + 5;
long long int result;




void dfs(vector<long long int>arr[], vector<long long int>&visited, long long int start, vector<long long int>&indegree, vector<long long int>&distance)
{

	visited[start] = 1;

	for (auto i : arr[start])
	{	distance[i] = max(distance[i], distance[start] + 1);
		indegree[i]--;

		if (indegree[i] == 0)
		{
			dfs(arr, visited, i, indegree, distance);
		}

	}






}



int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long int n;
	cin >> n;
	long long int edge;
	cin >> edge;
	vector<long long int>arr[n + 1];
	vector<long long int>indegree(n + 1, 0);
	while (edge--)
	{
		long long int a, b;
		cin >> a >> b;
		arr[a].push_back(b);
		indegree[b]++;
	}
	vector<long long int>distance(100005);
	vector<long long int>visited(n + 1, -1);
	for (long long int i = 1; i < n + 1; i++)
	{	if (visited[i] == -1 && indegree[i] == 0)
			dfs(arr, visited, i, indegree, distance);
	}
	long long int r = 0;
	for (long long int i = 1; i < n + 1; i++)
	{
		r = max(r, distance[i]);
	}
	cout << r << endl;





	return 0;


}

Measured memory_bytes: 18724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#include<queue>
using namespace std;
int main() {
	int n;
	cin >> n;
	int sh[1000] = {};
	for (int i = 2; i <= n; i++) {
		for (int j = 2; j <= sqrt(i); j++) {
			if (i%j == 0)goto bre;
		}
		for (int j = 1; j <= n;) {
			int c = j;
			while (true) {
				if (c % i == 0) {
					sh[i]++;
					c /= i;
				}
				else break;
			}
			j++;
		}
	bre:;
	}
	long long ans = 1;
	for (int i = 2; i < 1000; i++) {
		if (sh[i]) {
			ans *= sh[i] + 1;
			ans %= 1000000007;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

using ull_t = unsigned long long;

int main()
{
    int S, W;
    cin >> S >> W;
    cout << (S <= W ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


//無向連結グラフ
//辺を取り除いたときに非連結になるかを調べる

ll N,M;
ll a[50];
ll b[50];

//初期値false
bool graph[50][50] = {};
bool visited[50] = {};

void dfs(ll v)
{
    visited[v] = true;

    for(ll v2 = 0; v2 < N; ++ v2)
    {
        //辺でないなら
        if(graph[v][v2] == false)continue;
        //すでに、到達していたら
        if(visited[v2] == true)continue;
        dfs(v2);
    }
}

int main() {

    cin >> N >> M;

    REP(i,M)
    {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
        //辺の情報を保存
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    ll ans = 0;

    REP(i,M)
    {
        //辺を削除
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        
        REP(j,N)visited[j] = false;

        //非連結か調べる 開始を0
        dfs(0);

        bool bridge = false;

        REP(j,N)
        {
            //到達できない地点がひとつでもあれば
            if(visited[j] == false)bridge = true;
        }
        if(bridge)++ans;

        //辺をもとに戻す
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

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

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, M = getNM()
A = getList()
que = [getList() for i in range(M)]

A.sort()
que.sort(key = lambda i:i[1])
time, alt = que.pop()

ans = 0
for i in range(N):
    # もし操作用カードがなくなったら
    if time == 0 and len(que) > 0:
        time, alt = que.pop()

    if A[i] < alt and time > 0:
        time -= 1
        ans += alt
    else:
        ans += A[i]
print(ans)

Measured memory_bytes: 109392
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
bool ex[1000005];
int main(){
	fastio;
	ll n; cin >> n;
	ll g = 0;
	bool pc = 1;
	for (ll i = 0; i < n; i++){
		ll ip; cin >> ip; g = __gcd(g, ip); 
		if (ex[ip] == 0) ex[ip] = 1;
		else if (ip != 1) pc = 0;
	}
	for (ll i = 2; i < 1000005; i++){
		ll cnt = 0;
		for (ll j = i; j < 1000005; j += i) cnt += ex[j];
		if (cnt >= 2) pc = 0; 
	}
	if (pc){
		cout << "pairwise coprime\n"; 
	}
	else if (g == 1){
		cout << "setwise coprime\n";
	}
	else{
		cout << "not coprime\n";
	}
}

Measured memory_bytes: 4600
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

struct Edge{
    ll from;ll to;ll cost;
};
using Edges = vector<Edge>;
bool bellman_ford(const Edges &Es,ll V,int s,vector<ll> &dis){
    dis[s] = 0;
    int cnt = 0;
    while(cnt < V){
        bool end = true;
        for(auto e:Es){
            if(dis[e.from] != INF && dis[e.from]+e.cost < dis[e.to]){
                dis[e.to] = dis[e.from] + e.cost;
                end = false;
                if(cnt==V-1&&e.to==V-1) return true;
            }
        }
        if(end) break;
        cnt++;
    }
    return false;
}

int main(){
    ll N, M;
    cin >> N >> M;
    Edges Es(M);
    rep(i,M){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;c*=-1;
        Es[i] = {a,b,c};
    }
    vector<ll> dis(N,INF);
    if(bellman_ford(Es,N,0,dis)) cout << "inf" << endl;
    else{
        cout << -dis[N-1] << endl;
    }
}

Measured memory_bytes: 3636
use proconio::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; n],
    }

    let sum: usize = a.iter().sum();
    let mut ans = 0;
    for i in 0..n {
        if a[i] >= (sum + 4 * m - 1) / (4 * m) {
            ans += 1;
        }
    }
    println!("{}", if ans >= m { "Yes" } else { "No" });
}


Measured memory_bytes: 2160
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  int n, res = INF;
  string s;
  cin >> n >> s;

  int W[n], E[n];
  rep(i, n) W[i] = 0, E[i] = 0;
  if(s[0] == 'W'){
    W[0] = 1;
  }else{
    E[0] = 1;
  }

  for(int i = 1; i < n; i++){
    if(s[i] == 'W'){
      W[i] = W[i-1] + 1;
      E[i] = E[i-1];
    }else if(s[i] == 'E'){
      W[i] = W[i-1];
      E[i] = E[i-1] + 1;
    }
    //cout << W[i] << ", " << E[i] << endl;
  }

  for(int i = 0; i < n; i++){
    if(i == 0){
      res = min(res, E[n-1]-E[0]);
    }else if(i == n-1){
      res = min(res, W[n-1]);
    }else{
      res = min(res, W[i-1]+(E[n-1]-E[i]));
    }
    //cout << "x: " << res << endl;
  }
  cout << res << endl;
}

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


Measured memory_bytes: 2964
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n-1],
    }

    let mut b = Vec::new();
    b.resize(n, 0);
    for x in a {
        b[x - 1] += 1;
    }
    for x in b {
        println!("{}", x);
    }
}


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// cf https://qiita.com/drken/items/cce6fc5c579051e64fab
template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight; //親との差分

    UnionFind(int n = 1, Abel SUM_UNITY = 0){
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0){
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for(int i=0; i<n; i++) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x){
        if(par[x] == x){
            return x;
        }
        else{
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x){
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    // weight[y] - weight[x] = w になるようにマージする（順番に注意）
    bool merge(int x, int y, Abel w){
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y), w = -w;
        if(rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y){
        return weight(y) - weight(x);
    }
};

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

    UnionFind<int> uni(N);
    for(int i=0; i<M; i++){
        int l, r, w; cin >> l >> r >> w;
        l--; r--;

        if(uni.issame(l, r)){
            if(uni.diff(l, r) != w){
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uni.merge(l, r, w);
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
n = int(input())
b = list(map(int,input().split()))
p = []

for i in range(n):
    nn = len(b)
    for j in range(nn-1,-1,-1):
        if b[j] == j+1:
            p.append(b[j])
            b = b[:j]+b[j+1:]
            break
            
if b == []:
    for i in range(n-1,-1,-1):
        print(p[i])
else:
    print(-1)

Measured memory_bytes: 38512
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;
	cin >> N;
	if (N <= 999) cout << "ABC" << endl;
	else cout << "ABD" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  int result = numeric_limits<int>::max();
  irep(i, s.size() - t.size()) {
    int cnt = 0;
    rep(j, t.size()) {
      if (t[j] != s[i + j]) {
        cnt++;
      }
    }
    chmin(result, cnt);
  }
  cout << result << endl;
  return 0;
}

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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int n, x, c=0, ans=0, maxRes, minRes ;
    vector<bool> color(8, false) ;
    cin>> n ;
    for(int i=0 ; i<n ; i++)
      {
        cin>> x ;
        if(x<=399) color[0]=true ;
        else if(x<=799) color[1]=true ;
        else if(x<=1199) color[2]=true ;
        else if(x<=1599) color[3]=true ;
        else if(x<=1999) color[4]=true ;
        else if(x<=2399) color[5]=true ;
        else if(x<=2799) color[6]=true ;
        else if(x<=3199) color[7]=true ;
        else if(x>=3200) c++ ;
      }
    for(int i=0 ; i<8 ; i++)
      if(color[i]) ans++ ;
    maxRes=ans+c ;
    minRes=ans ;
    if(!minRes) minRes=1 ;
    cout<< minRes << " " << maxRes ;
  }


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();

    static List<List<Integer>> edge;
    static int[] count;
    public static void main(String[]$) throws IOException {
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        count = new int[n];
        edge = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            edge.add(new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int a = scanner.nextInt() - 1;
            int b = scanner.nextInt() - 1;
            edge.get(a).add(b);
        }
        for (int i = 0; i < q; i++) {
            int p = scanner.nextInt() - 1;
            int x = scanner.nextInt();
            count[p] += x;
        }
        dfs(0);
        for (int i : count) {
            System.out.println(i);
        }
    }

    static void dfs(int v) {
        for (Integer i : edge.get(v)) {
            count[i] += count[v];
            dfs(i);
        }
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 119568
N = int(input())
txy = [[int(i) for i in input().split()] for _ in range(N)]

def solve() :
    pt, px, py = 0, 0, 0
    for t, x, y in txy :
        dd = abs(x-px) + abs(y-py)
        dt = t - pt
        if dd > dt or dd % 2 != dt % 2 :
            return 'No'
            
        pt, px, py = t, x, y
        
    return 'Yes'
    
print(solve())

Measured memory_bytes: 60376
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int>list;
  for(int i=1;i<32;i++){
    list.push_back(i*i);
  }
  for(int i=2;i<11;i++){
    list.push_back(i*i*i);
  }
  for(int i=2;i<6;i++){
    list.push_back(i*i*i*i);
  }
  for(int i=2;i<4;i++){
    list.push_back(i*i*i*i*i);
  }
  for(int i=2;i<4;i++){
    list.push_back(i*i*i*i*i*i);
  }
  list.push_back(128);
  list.push_back(256);
  list.push_back(512);
  sort(list.begin(),list.end());
  reverse(list.begin(),list.end());
  int X;
  cin>>X;
  for(int i=0;i<list.size();i++){
    if(list.at(i)<=X){
      cout<<list.at(i)<<endl;
      break;
    }
  }
}
  

    
    

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

template<typename T, typename Q>
istream &operator>>(istream &is, pair<T, Q> &p) {
	return is >> p.first >> p.second;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
	for (auto &x : v) is >> x;
	return is;
}

template<typename T, typename Q>
ostream &operator<<(ostream &os, pair<T, Q> p) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> v) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); it++)
		os << (it == v.begin() ? "" : ", ") << *it;
	return os << "]";
}

template<typename T, typename Q>
ostream &operator<<(ostream &os, map<T, Q> m) {
	os << "[";
	for (auto it = m.begin(); it != m.end(); it++) 
		os << (it == m.begin() ? "" : ", ") << *it;
	return os;
}
#define imie(...) " [" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b; cin >> a >> b;
	cout << max({a + b, a - b, a * b}) << '\n';
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  int ans = 0;
  int length = 0;
  cin >> S;
  for(int i = 0; i < S.size(); i++){
    if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
      length++;
      if(length > ans)ans=length;
    }
  else{
    length=0;
    }
}
cout << ans <<endl;
}



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 n,z; 
  cin >> n ;
  vector<int> t(n);
  vector<int> sum(n);
  z=0;
for(int i=0;i<n;i++){
  
  cin>>t.at(i);
}
  for(int i=0;i<n-1;i++){for(int j=i+1;j<n;j++)
  z+=t.at(i)*t.at(j);
  }
       cout<<z<<endl;
          }


Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

int n;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> n;


rep(i, 0, 100){

if(n - i*7 >=0){
    ll temp = (n- i*7);
    if(temp%4==0){
        cout << "Yes" << endl;
        return 0;
    }
}

}

cout << "No" << endl;






return 0;}
///....


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define f first
#define s second
#define endl "\n"
#define F(i,n) for(ll i=0;i<n;i++)
#define mem(x,val) memset(x,val,sizeof(x))
#define mod 1000000007
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cerr.tie(NULL)
 
int main()
{
    crap;
    ll T = 1;
    //cin>>T;
    while(T--){
        ll n; cin>>n;
        ll ans = 1;
        while(n){
        	n/=2;
        	ans*=2;
        }
        cout<<ans-1<<endl;
        //vector<ll> a(n); F(i,n) cin>>a[i];
    }
}

Measured memory_bytes: 256