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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)


#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#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 REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int n;

    cin >> n;


    int a[n];

    ll sum = 0;


    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    int f = 0;

    for(int i=0; i<n-1; i++)
    {
        if(a[i]==a[i+1])
            continue;
        else
        {
            f = 1;
            break;
        }
    }


    if(f==0)
    {
        cout << 0 << endl;
    }
    else
    {

        sort(a,a+n);


        ll mini = a[0];
        ll maxi = a[n-1];


        vector<ll>v;

        for(int i=mini; i<=maxi; i++)
        {

            ll sum1 = 0;

            for(int j=0; j<n; j++)
            {
                ll b = abs(i-a[j]);
                sum1 += (b*b);
            }

            v.pb(sum1);
        }

        sort(v.begin(),v.end());

        cout << v[0] << endl;

    }




    return 0;
}


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

int main() {
	string s; cin >> s;
	vector<string> vec(s.size());
	for (int i = 0; i < s.size(); i++) vec[i] = s[i];
	string alphabet = { 'a','b','c','d','e','f','g','h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r','s','t','u','v','w','x','y','z' };
	vector<string> alpha_vec(alphabet.size());
	for (int i = 0; i < alphabet.size(); i++) alpha_vec[i] = alphabet[i];

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

	int count = alphabet.size();
	for (int i = 0; i < alpha_vec.size(); i++) {
		if (vec[i] == alpha_vec[i]) {
			count--;
		}
		else {
			cout << alpha_vec[i] << endl;
			break;
		}

		if (count == 0) {
			cout << "None" << endl;
			break;
		}
 	}

	return 0;
}

Measured memory_bytes: 5888
N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))

if x>sum(A):
    print(N-1)
    exit()

if x==sum(A):
    print(N)
    exit()

ans = 0
for i in range(N):
    if sum(A[:i]) <= x:
        ans = i
print(ans)

Measured memory_bytes: 3064
n = int(input())
s = [input() for i in range(n)]
ac = 0 
wa = 0
tle = 0
re = 0

for i in s:
    if i == "AC":
        ac += 1
    elif i == "WA":
        wa += 1
    elif i == "TLE":
        tle += 1
    elif i == "RE":
        re += 1


print('AC x ', end='') 
print(ac)
print('WA x ', end='') 
print(wa)
print('TLE x ', end='') 
print(tle)
print('RE x ', end='')
print(re)


Measured memory_bytes: 16244
unittest
{
	assert( [ "3 4 240", "60 90 120", "80 150 80 150" ].solve == 3 );
	assert( [ "3 4 730", "60 90 120", "80 150 80 150" ].solve == 7 );
	assert( [ "5 4 1", "1000000000 1000000000 1000000000 1000000000 1000000000", "1000000000 1000000000 1000000000 1000000000" ].solve == 0 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s %s"( n, m, k );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	
	auto at = 0L;
	auto ac = 0L;
	foreach( a; as )
	{
		if( k < at + a ) break;
		at += a;
		ac++;
	}
	
	auto ans = 0L;
	auto bt = 0L;
	auto bc = 0L;
	while( true )
	{
		while( bc < bs.length && at + bt + bs[ bc ] <= k )
		{
			bt += bs[ bc ];
			bc++;
		}
		ans = max( ans, ac + bc );
		if( ac == 0 ) break;
		at -= as[ ac - 1 ];
		ac--;
	}
	return ans;
}


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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	bool flag = false;
	if(a==b&&c!=a) flag=true;
	if(b==c&&a!=b) flag=true;
	if(c==a&&b!=a) flag=true;
	cout<<(flag?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>

using namespace std;
typedef pair<int, int> Pii;

int highestWorth(vector<Pii> item, int weight)
{
    int item_len = item.size();

    int dp[item_len][weight + 1];

    for (int i = 0; i < item_len; i++)
    {
        for (int j = 0; j <= weight; j++)
        {
            if (i == 0 || j == 0)
            {
                dp[i][j] = 0;
                continue;
            }

            // アイテムの重さが j 以内であるなら
            if (item[i].second <= j)
            {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - item[i].second] + item[i].first);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    return dp[item_len - 1][weight];
}

int main()
{
    int N, W;
    vector<Pii> item;
    cin >> N >> W;

    item.push_back(make_pair(0, 0));

    for (int i = 0; i < N; i++)
    {
        int v_i, w_i;
        cin >> v_i >> w_i;

        item.push_back(make_pair(v_i, w_i));
    }

    cout << highestWorth(item, W) << endl;
}


Measured memory_bytes: 7060
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    string s;
    cin >> s;
    REP(i, s.size()){
        cout << s[i];
        i++;
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
using namespace std;
int w,h;
int ans;
int mp[21][21];

void check() {
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++){
      cout << mp[i][j] << " ";
    }
    cout << endl;
  }

  cout <<"---------------------------"<<endl;

}

void saiki(int x,int y,int kai) {
  int dx[4] = {1,-1,0,0};
  int dy[4] = {0,0,1,-1};
  
  if(kai <10 && ans > kai+1) {
    for(int i=0;i<4;i++) {
      int nx = x+dx[i];
      int ny = y+dy[i];
      if(nx >= 0 && ny >=0 && nx < w && ny < h && mp[ny][nx] != 1) {
	nx = x,ny = y;
	while(1) {
	  nx += dx[i];
	  ny += dy[i];
	    if(nx < 0 || ny <0 || nx >= w || ny >= h) break;
	    else if(mp[ny][nx] == 1)  {
	      mp[ny][nx] = 0;
	      //cout << ny <<" "<<nx << endl;
	      //  cout << kai <<" "<<dy[i] <<" " << dx[i] <<endl;
	      saiki(nx-dx[i],ny-dy[i],kai+1);
	      mp[ny][nx] = 1;
	      break;
	    } else if(mp[ny][nx] == 3) {
	      //cout << "ok " <<kai <<" "<<ny <<" "<<nx <<  endl;
	      if (ans > kai+1) ans = kai+1;
	      break;
	    }
	  }
	
      }
    }
  }
}


int main() {
  
  while(1) {
    cin >> w >> h;
    if(w == 0 && h  ==0) break;
    
    int sx,sy;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++) {
	cin >> mp[i][j];
	if(mp[i][j]==2) sx = j , sy= i;
      }
    
    ans = 11;
    saiki(sx,sy,0);
    if(ans == 11) cout << -1 <<endl;
   else cout << ans << endl;
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;
const int N = (int) 1e5 + 7;
int n;
ll need, s[N], a[N];

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

  cin >> n >> need;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    if (a[i] + a[i + 1] >= need) {
      cout << "Possible\n";
      for (int j = 1; j < i; j++) {
        cout << j << "\n";
      }
      for (int j = n; j > i; j--) {
        cout << j - 1 << "\n";
      }
      return 0;
    }
  }
  cout << "Impossible\n";
}



Measured memory_bytes: 1664
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let a = Array.init n (fun _ ->
    Scanf.scanf " %d" @@ fun k ->
    Array.init k (fun _ -> Scanf.scanf " %d" ((+) 0)))
  in
  Array.init m (fun i ->
    let i = i+1 in
    let c = Array.fold_left (
      Array.fold_left (fun s v ->
        if v = i then s+1 else s)) 0 a
    in if c = n then 1 else 0)
  |> Array.fold_left (+) 0
  |> Printf.printf "%d\n"


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const ll MOD = (ll)1e9 + 7 ;
const int MAXN = 1e5 + 100;

void solve(){
    string s; cin >> s;
    if( s[2] == s[3] and s[4] == s[5])
        cout << "Yes\n";
    else 
        cout << "No\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
ll u18 = 1000000000000000000;
int main()
{
    
    int x, y; 
    cin >> x >> y ;
    if( y%2 == 0 ){
      if( (2*x-y/2) >= 0 && (y/2-x) >= 0 ){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
    else{
      cout << "No" << endl;
    }
   
    return 0;
}


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

int ans = 0;

void dfs(string s, ll n){
    if(atoll(s.c_str())>n)return;
    vector<bool> m(3, false);
    rep(i, s.size()){
        if(s[i] == '3') m[0] = true;
        if(s[i] == '5') m[1] = true;        
        if(s[i] == '7') m[2] = true;
        if(m[0]&&m[1]&&m[2]){
            ans++;
            break;
        }
    }
    dfs(s+'3', n);
    dfs(s+'5', n);
    dfs(s+'7', n);
    return;
}

int main(){
    ll n;
    cin >> n;
    dfs("0", n);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();
        int N, T;
        {int[] a = r.ii(); N = a[0]; T = a[1];}
        int[] t = r.ii();
        long sum = T;
        for(int i = 0; i < N-1; i++)
            sum += Math.min(T, t[i+1] - t[i]);  
        println(sum);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 48792
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = inp()
print(n**3)

Measured memory_bytes: 4196
#include <cstdio>

using namespace std;

#define rep(i, N) for (ll i = 0; i < N; ++i)
typedef long long int ll;
ll n, A[50];

int solve(ll i, ll m) {
    if (m == 0) return 1;
    if (i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    scanf("%d", &n);
    rep(i, n) scanf("%d", &A[i]);
    ll q, m;
    scanf("%d", &q);
    rep(j, q) {
        scanf("%d", &m);
        if (solve(0, m)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}



Measured memory_bytes: 2600
#include<stdio.h>

int isAsc(int arr[],int sz,int x,int y,int vX,int vY);


int main()
{
    int input[100],input2[100];
    int CASE,C,i,j;
    scanf("%d",&CASE);

    for(C=0; C<CASE; C++)
    {
        scanf("%d",&input[C]);
    }

    int isPossible=0;
    for(i=0; i<CASE; i++)
    {
        for(j=0; j<CASE; j++)
        {
            for(int k=0; k<CASE; k++)
            {
                //printf("%d ",input[k]);
                input2[k]=input[k];
            }
            //printf("\n");
            //printf("%d %d %d %d\n",i,j, input2[i], input2[j]);
            isPossible = isAsc(input2,CASE,i,j,input2[i],input2[j]);
            if(isPossible==1)
            {
                break;
            }
        }
        if(isPossible==1)
        {
            break;
        }
    }

    if(isPossible==0)
    {
        printf("NO\n");
    }
    else
    {
        printf("YES\n");
    }

    return 0;
}

int isAsc(int arr[],int sz,int x,int y,int vX,int vY)
{
    int i;

    arr[x]=vY;
    arr[y]=vX;

    /*
    for(i=0; i<sz; i++)
    {
        printf("%d ",arr[i]);
    }
    printf("\n");
    */

    for(i=0; i<sz-1; i++)
    {
        if(arr[i]>arr[i+1])
        {
            //printf("0\n\n");
            return 0;
        }
    }
    //printf("1\n\n");
    return 1;
}


Measured memory_bytes: 128
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let [n,l]=t.n(2)
  l--;
  let d=t.abs(1+l);
  let a=1;
  for(let i=2;i<=n;i++){
    if(d>t.abs(i+l)){
      d=t.abs(i+l)
      a=i;
    }
  }
  let ans=0;
  for(let i=1;i<=n;i++){
    if(i==a)continue
    ans+=i+l;
  }
  t.o(ans)
}
main()


Measured memory_bytes: 7500
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
mod = 7 + 10 ** 9
Atype = set(A)

mult = K * (K - 1)// 2
mult %= mod

count = dict()
for a in A:
    if a in count: count[a] += 1
    else: count[a] = 1

inside = 0
used = dict()
used[A[N-1]] = 1
for i in reversed(range(N-1)):
    for k in used:
        if A[i] > k: inside += used[k]
    if A[i] in used: used[A[i]] += 1
    else: used[A[i]] = 1
inside *= K
inside %= mod

after = 0
for a in A:
    for k in count:
        if a > k: after += count[k]
after *= mult
after %= mod

print((inside + after) % mod)


Measured memory_bytes: 42348
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){	
	
	int x;
	cin >> x;
	if(x>=30)cout << "Yes" << endl;
	else cout << "No" << endl;	
	
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){

int a, b;
cin>>a>>b;

if (a==b){
   cout<<"Draw";
}else if (a==1){
   cout<<"Alice";
}else if (b==1){
   cout<<"Bob";
}else if (a>b){
   cout<<"Alice";
}else{
   cout<<"Bob";
}

return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = 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; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;cin >> k;
    if(k%2==0||k%5==0){
        cout << -1 << endl;
        return 0;
    }
    ll t=7;
    int cnt=1;
    while(t%k!=0){
        t=(t*10+7)%k;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3656
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int, int> pii;
typedef double D;
typedef complex<D> P;

/* const */
const int INF = 999999999;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */


// 8?¨???????????????? N??\????????±?????\??????
int dp[8][1010];
const int mod = 1e4 + 7;

int getid(char c)
{
  if (c == 'J') return 0;
  if (c == 'O') return 1;
  return 2;
}

// ??¬??????????±?????????´????????????
void exclude(int now, int id)
{
  REP(i, 8) {
    if ((i & (1 << id)) == 0) {
      dp[i][now] = 0;
    }
  }
}

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

  REP(i, N) {
    // ?????\??????J??????????????????
    if (i == 0) {
      REP(j, 8) dp[j][i] = 1;
      exclude(i, 0);
    } else {
      REP(j, 8) {
        REP(k, 8) {
          // ?????\????±??????????????????§????±????????????°?£???°???
          if (j & k) {
            dp[k][i] = (dp[k][i] + dp[j][i - 1]) % mod;
          }
        }
      }
    }
    exclude(i, getid(s[i]));
  }
  int ans = 0;
  REP(i, 8) {
    ans += dp[i][N - 1] % mod;
    ans %= mod;
  }
  print(ans);

  return 0;
}

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

int a, b;

int main (){
    cin>>a>>b;
    if (a==b){
        cout<<"Draw"<<endl;
    }else if (a==1){
        cout<<"Alice"<<endl;
    }else if (b==1){
        cout<<"Bob"<<endl;
    }  else if (a>b || a==1){
        cout<<"Alice"<<endl;
    }else {
        cout<<"Bob"<<endl;
    }
}

Measured memory_bytes: 3532
#include <iostream>

using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  s += s;
  for(int i = 0; i < (int)s.length(); ++i){
    bool f = true;
    for(int j = 0; j < t.length(); ++j){
      if(s[i+j] != t[j]){
        f = false;
        break;
      }
    }
    if(f){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define  DESC std::greater<int>() //sort 3rd arg


int main()
{
	char x;
	cin >> x;

	

	if (isupper(x)) {
		cout << 'A' << endl;
	}
	else {
		cout << 'a' << endl;
	}

	

	return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

// テ」ツつーテ」ツδゥテ」ツδ陛ァツ板ィテ」ツδ佚」ツδε」ツδ?

typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
        src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

// テヲツ慊?・ツーツ湘・ツ?ィテ・ツ淞淌ヲツ慊ィ(Minimum Spanning Tree) by Prim Algorithm
/*
  g : テ」ツつーテ」ツδゥテ」ツδ?
  r : テヲツ慊?・ツ按敕」ツ?ォテ・ツ青ォテ」ツつ?ゥツ?づァツつケ
*/
pair<Weight, Edges> MST(const Graph &g, int r = 0) {
    int n = g.size(); Edges T; Weight total = 0;
    vector<bool> visited(n);
    priority_queue<Edge> q;
    q.push(Edge(-1, r, 0));
    while (q.size()) {
        Edge e = q.top(); q.pop();
        if (visited[e.dst]) continue;
        T.push_back(e);
        total += e.weight;
        visited[e.dst] = true;
        for(auto& f: g[e.dst]) if (!visited[f.dst]) q.push(f);
    }
    return pair<Weight, Edges>(total, T);
}

int main(){
    int n,m;
    while(cin>>n>>m && n){
        Graph g(n);
        rep(i,m){
            int a,b,c;
            cin>>a>>b>>c;
            g[a].emplace_back(a,b,c);
            g[b].emplace_back(b,a,c);
        }
        cout << MST(g).first << endl;
    }
}

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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int d1 = Math.abs((a+b)-(c+d));
        int d2 = Math.abs((a+c)-(b+d));
        int d3 = Math.abs((a+d)-(b+c));

        System.out.println(Math.min(Math.min(d1,d2), d3));
    }

}



Measured memory_bytes: 26300
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
int main(){
    int n;
    double students[1000] = {0},sum,m,div;
 
    while(true){
        scanf("%d",&n);
        if(n == 0) break;
        div = sum = 0;
        for(int i = 0; i < n; i++){
            scanf("%lf",&students[i]);
            sum += students[i];
        }
        m = sum/n;
        for(int i = 0; i < n;i++){
            div += (students[i] - m)*(students[i] - m);
            students[i] = 0;
        }
        printf("%.8lf\n",sqrt(div/n));
    }
}


Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int sum1[N+1], sum2[N+1];
    sum1[0] = 0;
    rep(i, N) sum1[i+1] = sum1[i]+(S[i] == 'W');
    sum2[N] = 0;
    rep3(i, N-1, 0) sum2[i] = sum2[i+1]+(S[i] == 'R');
    int ans = inf;
    rep(i, N+1){
        chmin(ans, max(sum1[i], sum2[i]));
    }
    cout << ans << endl;
}

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

struct RollingHash {
    private:
        ll N, base, mod;
        vector<ll> hash, power;
    public:
        RollingHash(string S) {
            N = S.size();
            base = 1007;
            mod = 1e9 + 7;
            hash.assign(N+1, 0);
            power.assign(N+1, 1);
            rep(i,0,N){
                hash[i+1] = (hash[i] * base + S[i]) % mod;
                power[i+1] = (power[i] * base) % mod;
            }

        }

        ll get(int lv, int rv){
            return (hash[rv] - hash[lv] * power[rv-lv] % mod + mod) % mod;
        }

};

int main(){
    string S,T;
    cin >> S >> T;
    RollingHash rh_s(S), rh_t(T);
    int ns = S.size(), nt = T.size();
    ll hash_T = rh_t.get(0, nt);
    rep(i,0,ns-nt+1){
        if(hash_T == rh_s.get(i, i+nt)){
            cout << i << "\n";
        }
    }

}


Measured memory_bytes: 20592
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	cout<<"ABC"<<n<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

k = INT()
s = input()

if len(s)<=k:
    print(s)
else:
    print(s[:k]+'...')

Measured memory_bytes: 72744
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[310][310];
bool ok[310];
ll ans = LINF;

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n) rep(j, m) cin >> a[i][j], a[i][j]--;

    rep(i, 310) ok[i] = 1;

    rep(i, m){
        int selected[310] = {};
        rep(j, n){
            rep(k, m){
                if (ok[a[j][k]]) {
                    selected[a[j][k]]++;
                    break;
                }
            }
        }
        ll mx = 0, idx = -1;
        rep(j, m){
            if(selected[j] == 0) continue;
            if(selected[j] > mx){
                mx = selected[j];
                idx = j;
            }
        }
        ans = min(ans, mx);
        ok[idx] = 0;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4324
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , m , cnt[N];

int main(){
    scanf("%d%d",&n,&m);
    rep(i,0,m){
        int a,b;
        scanf("%d%d",&a,&b);
        cnt[a]++;
        cnt[b]++;
    }
    bool ok = true;
    rep(i,1,n+1) ok &= ~cnt[i] & 1;
    puts(ok ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

int main(void) {
  string L;
  cin >> L;
  ll i, j;
  ll N=(ll)L.size();
  ll dp[MAX][2]={}; // dp[i][0]:Lより小さいことが確定
  
  dp[1][0]=1;
  dp[1][1]=2;
  for(i=1; i<N; i++) {
    
    moC(dp[i+1][0], +, (dp[i][0]*3)%MOD);
    
    if(L[i]=='1') {
      moC(dp[i+1][1], +, (dp[i][1]*2)%MOD);
      moC(dp[i+1][0], +, dp[i][1]);
    }else if(L[i]=='0') {
      moC(dp[i+1][1], +, dp[i][1]);
    }
    
  }
  
  ll ans=(dp[N][0]+dp[N][1])%MOD;
  pt(ans);
  
}
  
  


Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  int all = 0;
  REP(i,n) all += a[i];

  int cnt = 0;
  REP(i, n){
    if(a[i] * 4 * m >= all){
      cnt++;
    }
  }

  cout << (cnt >= m ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 3652
package main
import "fmt"
func main() {
  var s string
  var k int
  fmt.Scan(&s,&k)
  n := len(s)
  dp := make([][][]int,n)
  for l:=0;l<n;l++ {
    dp[l] = make([][]int,n)
    for r:=0;r<n;r++ {
      dp[l][r] = make([]int,k+1)
      for i:=0;i<k+1;i++ { dp[l][r][i] = -(1<<30) }
    }
  }
  dp[0][n-1][k] = 0
  ans := 0
  for l:=0;l<n;l++ {
    for r:=n-1;r>=max(0,l-1);r-- {
      for i:=0;i<k+1;i++ {
        if dp[l][r][i] < 0 { continue }
        f := 0
        if l <= r { f = 1 }
        ans = max(ans,dp[l][r][i]+f)
        if l < n-1 { dp[l+1][r][i] = max(dp[l+1][r][i],dp[l][r][i]) }
        if r > 0 { dp[l][r-1][i] = max(dp[l][r-1][i],dp[l][r][i]) }
        if l < r {
          f = 0
          if s[l:l+1] != s[r:r+1] { f = 1 }
          if i-f >= 0 { dp[l+1][r-1][i-f] = max(dp[l+1][r-1][i-f],dp[l][r][i]+2) }
        }
      }
    }
  }
  fmt.Println(ans)
}
func max(x,y int) int {
  if x > y { return x }
  return y 
}

Measured memory_bytes: 254684
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

int n, len, digits[10];

int main()
{
	cin >> n;

	while (n > 0){
		len++;
		digits[len] = n%10;
		n /= 10;
	}

	int res = 0;
	for (int i = len; i > 0; --i) {
		if (digits[i] == 1)
			digits[i] = 9;
		else
			if (digits[i] == 9)
				digits[i] = 1;

		res = 10*res + digits[i];
	}

	
	cout << res << endl;

	return 0;
}

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

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

int main(){
  int N;
  cin >> N;
  
  for(int i=0; i<=N/4; i++){
    for(int j=0; j<=N/7; j++){
      if(4*i + 7*j == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  
  /*if(N%7%4==0 || N%4%7==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }*/
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    for (int i = 1; i <= 10000;){
        int n;
        cin >> n;
        if(n!=0){
            cout << "Case " << i << ": " << n << endl;
            i++;
        }
    }
}


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

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

  for (int x=0; x<=N; x++){
    for(int y=0; y<=N; y++){
      if(N-x-y<0) break;
      if(Y == 10000*x + 5000*y + 1000*(N-x-y)) {
        cout << x << ' ' << y << ' ' << (N-x-y) <<endl;
        return 0;
      }

    }

  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << 9*max(a, max(b, c)) + a + b + c << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
using System;

namespace _0036
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string naiyo = "";
                string ans = "";
                string k = "1";
                string[,] a = new string[11, 11];
                for (int i = 0; i < 8; i++)
                {
                    string sd = Console.ReadLine();
                    if (sd == null)
                    {
                        naiyo = "qjsk";
                        break;
                    }
                    for (int y = 0; y < 8; y++)
                    {
                        a[i, y] =sd[y].ToString();
                    }

                }
                if (naiyo == "qjsk") { break; }
                for (int i = 0; i < 8; i++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        if (a[i, y] == k && a[i + 1, y] == k && a[i, y + 1] == k && a[i + 1, y + 1] == "1")
                        {
                            ans = "A";
                        }
                        if (a[i, y] == k && a[i + 1, y] == k && a[i + 2, y] == k && a[i + 3, y] == k) { ans = "B"; }
                        if (a[i, y + 1] == k && a[i, y + 2] == k && a[i, y] == k && k == a[i, y + 3]) { ans = "C"; }
                        if (a[i, y + 1] == k && a[i + 1, y + 1] == k && a[i + 2, y] == k && a[i + 1, y] == k) { ans = "D"; }
                        if (a[i, y] == k && a[i, y + 1] == k && a[i + 1, y + 1] == k && a[i + 1, 2 + y] == k) { ans = "E"; }

                        if (a[i, y] == k && a[i+1, y + 1] == k && a[i + 1, y ] == k && a[i + 2, 1 + y] == k) { ans = "F"; }
                        if (a[i+1, y] == k && a[i+1, y + 1] == k && a[i , y + 1] == k && a[i , 2 + y] == k) { ans = "G"; }
                    //    if (a[i, y] == k && a[i, y + 1] == k && a[i + 1, y + 1] == k && a[i + 1, 2 + y] == k) { ans = "E"; }
                    }
                }
                Console.WriteLine(ans);
               string asd=Console.ReadLine();
                asd = asd + " ";
            }
        }
    }
}

Measured memory_bytes: 8780
# coding : utf-8
lst = []
while True:
    h, w = map(int, input().split())
    lst.append([h, w])
    if h == 0 and w == 0:
        break
for l in lst:
    H = l[0]
    W = l[1]
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H-1:
                print ('#', end = '')
            else:
                if j == 0 or j == W-1:
                    print ('#', end = '')
                else:
                    print ('.', end = '')
        print ('')
    if i == H-1:
        print ('')


Measured memory_bytes: 7012
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;



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

	vector<int> p(n);
	vector<int> q(n);

	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> q[i];
	}

	vector<int> facto(n + 1);
	facto[0] = 1;
	for (int i = 1; i <= n; i++) {
		facto[i] = i * facto[i - 1];
	}

	int a = 0;
	for (int i = 0; i < n; i++) {
		int cnt = 0;
		for (int j = 0; j < i; j++) {
			if (p[j] < p[i]) {
				cnt++;
			}
		}

		a += facto[n - i - 1] * (p[i] - 1 - cnt);
	}
	int b = 0;
	for (int i = 0; i < n; i++) {
		int cnt = 0;
		for (int j = 0; j < i; j++) {
			if (q[j] < q[i]) {
				cnt++;
			}
		}

		b += facto[n - i - 1] * (q[i] - 1 - cnt);
	}
	cout << abs(a - b) << endl;

	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
//#define P pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    ll A, B, C; cin >> A >> B >> C;
    ll ans;
    if((A + B) >= C) {//C全部食える
        ans = C + B;
    }else {
        ans = (A + B) + B + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N = int(input())
    multi = {i*j for i in range(1, 10) for j in range(1, 10)}
    if N in multi:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < m; i++) {
			sum += sc.nextInt();
		}

		if(0 <= n - sum) {
			System.out.println(n - sum);
		}else {
			System.out.println(-1);
		}
		sc.close();
	}
	
}

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

vector<int> tree[1<<18];
int a[1<<18];
int ans[1<<18];
int nlow[1<<18];
int n;

void dfs(int v,int p)
{
    auto ptr=lower_bound(nlow, nlow+n+1, a[v]);
    const int plow=*ptr;
    *ptr=a[v];
    ans[v]=lower_bound(nlow, nlow+n+1, INT_MAX)-nlow-1;
    for(int u: tree[v]) if(p!=u) dfs(u,v);
    *ptr=plow;
}

main()
{
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>a[i];
    }
    for(int i=0; i<n-1; ++i)
    {
        int u,v; cin>>u>>v; --u,--v;
        tree[v].emplace_back(u);
        tree[u].emplace_back(v);
    }

    for(int i=1; i<=n; ++i)
    {
        nlow[i]=INT_MAX;
    }

    dfs(0,-1);

    for(int i=0; i<n; ++i)
    {
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 29720
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

ll Gcd(ll a,ll b){
    if(a < b)swap(a, b);

	if(a%b == 0)return(b);

	else return(Gcd(b, a%b));
}

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

    a--;

    ll same = c * d /Gcd(c, d);

    cout << b - a - (b/c - a/c) - (b/d - a/d) + (b/same - a/same) << endl;
}

Measured memory_bytes: 3584
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				begin(c), std::end(x)
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define V_TYPE				int
#define INF					1e4+1

using namespace std;
typedef long long ll;
typedef vector<V_TYPE> vdef;
typedef vector<vdef> vvdef;
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; }
template<typename T>inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T>inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


int main()
{
	int r, g, b, n;
	cin >> r >> g >> b >> n;

	int r_max = n / r;
	int g_max = n / g;
	int b_max = n / b;
	if (n%r != 0)
		r_max += 1;
	if (n%g != 0)
		g_max += 1;
	if (n%b != 0)
		b_max += 1;

	int subsum[3] = { 0,0,0 };

	int ans = 0;
	int comp = 0;

	for (int i = 0; i <= r_max; ++i)
	{
		subsum[0] = r * i;
		subsum[1] = 0;
		for (int j = 0; j <= g_max; ++j)
		{
			comp = n - (subsum[0] + subsum[1]);
			if (comp % b == 0)
			{
				if (comp / b >= 0)
					++ans;
			}
			subsum[1] += g;
		}
	}

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef unsigned long long ll;
struct node{
	int x,y;
}g[55];
int n,k;
inline bool calc(int x1,int y1,int x2,int y2)
{
	int res=0;
	for(int i=1;i<=n;i++)
	{
		if(g[i].x<x1||g[i].x>x2) continue;
		if(g[i].y<y1||g[i].y>y2) continue;
		++res;
	}
	return res>=k;
}
inline bool comp(const node &a,const node &b)
{
	return a.x<b.x;
}
long long ans=((ll)4*1e18);
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d%d",&g[i].x,&g[i].y);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int p=1;p<=n;p++)
			{
				for(int q=1;q<=n;q++)
				{
					int x1=g[i].x,x2=g[j].x,y1=g[p].y,y2=g[q].y;
					if(x1>x2) continue;
					if(y1>y2) continue;
					if(calc(x1,y1,x2,y2))
					{
						ll res=(ll)(x2-x1)*(y2-y1);
						if(ans>res)
						{
							ans=res;
						}
					}
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
	ll x , y , z , k ; 
	cin >> x >> y >> z >> k ; 
	priority_queue<ll> q ; 
	vector<ll> a(x) , b(y) , c(z) ; 
	for(ll &g: a){
		cin >> g ; 
	}
	for(ll &g: b){
		cin >> g ; 
	}
	for(ll &g: c){
		cin >> g ; 
	}
	vector<ll> ans ; 
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			ans.push_back(a[i]+b[j]);
		}
	}
	sort(ans.rbegin(),ans.rend());
	debug() << imie(ans) ; 
	sort(c.rbegin(),c.rend());
	debug() << imie(c) ; 
	vector<ll> res ; 
	for(int i=0;i<min(k,(ll)ans.size());i++){
		for(int j=0;j<z;j++){
			res.push_back(ans[i]+c[j]);
		}
	}
	debug() << imie(res) ; 
	sort(res.rbegin(),res.rend());

	for(int i=0;i<min(k,x*y*z);i++){
		cout << res[i] << endl;
	}
	return 0 ;
}


Measured memory_bytes: 43112