akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int a[502];
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    vector<int> v;
    for(int i = 1; i * i <= sum; i++){
        if(sum % i == 0){
            v.push_back(i);
            v.push_back(sum / i);
        }
    }
    sort(v.begin(), v.end(), greater<int>());
    for(int x : v){
        int amari[506];
        for(int i = 0; i < n; i++){
            amari[i] = a[i] % x;
        }
        sort(amari, amari + n);
        int ssum = 0;
        for(int i = 0; i < n; i++){
            ssum += amari[i];
        }
        int mid = n - ssum / x;
        int cost = 0;
        for(int i = 0; i < mid; i++){
            cost += amari[i];
        }
        if(cost <= k){
            cout << x << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
H,W=map(int,input().split())

sq=[list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        if sq[i][j]=="#":
            temp=0
            if j!=0:
                if sq[i][j-1]=="#":
                    temp+=1
            if j!=W-1:
                if sq[i][j+1]=="#":
                    temp+=1
            if i!=0:
                if sq[i-1][j]=="#":
                    temp+=1
            if i!=H-1:
                if sq[i+1][j]=="#":
                    temp+=1
            if temp==0:
                print("No")
                exit()

print("Yes")


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 2e5 + 1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL0 {printf("0\n"); return 0;}
#define FAIL1 {printf("-1\n"); return 0;}
#define FAILNO {printf("NO\n"); return 0;}

int H,W;
char S[1001];
queue<pair<pair<int,int>, int> > qu;
set<pair<int,int> > seen;
int mx;

int exists(pair<int,int> p) {
    return seen.find(p) != seen.end();
}

void f(int i, int j, int d) {
    if (!exists({i,j})) {
        qu.push({{i,j}, d});
        seen.insert({i,j});
    }
}

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif

    scanf("%d%d", &H, &W);
    for (int i = 0; i < H; i++) {
        scanf("%s", S);
        for (int j = 0; j < W; j++) {
            if (S[j] == '#') {
                qu.push({{i,j},0});
                seen.insert({i,j});
            }
        }
    }

    while(qu.size()) {
        auto p = qu.front();
        qu.pop();
        
        int i = p.fi.fi;
        int j = p.fi.se;
        int d = p.se;

        mx = max(mx, d);

        if (i) f(i-1,j,d+1);
        if (i < H-1) f(i+1,j,d+1);
        if (j) f(i,j-1,d+1);
        if (j < W-1) f(i,j+1,d+1);
    }

    printf("%d\n", mx);
    return 0;
}


Measured memory_bytes: 59280
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	res := make(map[int]int)

	max := -1
	key := 0

	for i := 1; i <= n; i++ {

		nn := i
		for nn%2 == 0 {
			nn = nn / 2
			res[i] = res[i] + 1
		}

		if max < res[i] {
			max = res[i]
			key = i
		}

	}

	fmt.Println(key)
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,pll> ppll;
typedef vector <pll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

int main() {
    FAST;
    ll i, n, k, m, x = 0, y = 0, t, z = 0, ans = 0, j, c = 0;
    cin >> n;
    m = n + 1;
    for( i = 0 ; i < n ; i ++ ){
    	cin >> x;
    	if ( x < m ) ans ++;
    	m = min(x, m);
    }
    cout << ans;
}

Measured memory_bytes: 256
object Main{
	def main(args: Array[String]):Unit={
		val input =io.StdIn.readLine split " "
		if(input(0).toInt > input(1).toInt)
			println("a > b")
		else if(input(0).toInt < input(1).toInt)
			println("a < b")
		else
			println("a == b")

	}
}

Measured memory_bytes: 43684
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
 
int N, M;
vector<vector<int>> team(5001);
vector<int> order;
bitset<5001> used;
 
void rec(int i){
    if(used[i]) return;
    used[i] = true;
    for(auto t : team[i]){
        rec(t);
    }
    order.push_back(i);
    return;
}
 
int main(void){
    
    scanf("%d %d", &N, &M);
    for(int i = 0; i < M; ++i){
        int a, b; scanf("%d %d", &a, &b);
        team[b].push_back(a);
    }
    
    for(int i = 1; i <= N; ++i) rec(i);
    
    for(auto i : order) cout << i << endl;
    
    for(int i = 0; i < order.size() - 1; ++i){
        int a = order[i], b = order[i + 1];
        bool isthere = false;
        for(auto n : team[b]){
            if(a == n){
                isthere = true;
                break;
            }
        }
        if(!isthere){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    string S;
    cin >> S;
    vector<vector<int>> t((1 << (S.size() - 1)), vector<int>(1, 0));
    ll ans(0);
    for (int bit = 0; bit < (1 << (S.size() - 1)); ++bit)
    {
        rep(i, 0, S.size())
        {
            if (bit & (1 << i))
                t[bit].push_back(i + 1);
        }
        t[bit].push_back(S.size());
    }
    rep(i, 0, 1 << S.size() - 1)
    {
        rep(j, 1, t[i].size())
        {
            rep(x, t[i][j - 1], t[i][j])
                ans += (S[x] - '0') * powl(10, t[i][j] - x - 1);
        }
    }
    cout << ans << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 3676
#include <iostream>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if ( a == 1 )
    {
        a = 14;
    }
    if ( b == 1 )
    {
        b = 14;
    }
    if ( a > b )
    {
        cout << "Alice";
    }
    else if ( a < b )
    {
        cout << "Bob";
    }
    else
    {
        cout << "Draw";
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
struct edge { int to, cost; };

int n, p[1000], d[1000], ans;

bool used[1000], cused[1000];
vector<edge> G[1000];

int dfs(int s) {
  int ans = 0;
  used[s] = true;
  for (int i = 0; i < G[s].size(); i++) {
    if (used[G[s][i].to]) continue;
    ans = max(ans, G[s][i].cost + dfs(G[s][i].to));
  }
  return ans;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = 1; i < n; i++) scanf("%d", &p[i]), p[i]--;
    for (int i = 1; i < n; i++) scanf("%d", &d[i]);
    ans = 0;
    for (int i = 1; i < n; i++) {
      edge e1, e2;
      e1.to = p[i], e2.to = i;
      e1.cost = e2.cost = d[i];
      G[i].push_back(e1);
      G[p[i]].push_back(e2);
      ans += d[i] * 3;
    }
    for (int i = 0; i < n; i++) cused[i] = false;
    for (int i = 0; i < n; i++) if (G[i].size() == 1) cused[i] = true, ans -= G[i][0].cost * 2;
    int temp = 0;
    for (int i = 0; i < n; i++) used[i] = cused[i];
    for (int i = 0; i < n; i++) if (!used[i]) {
      temp = max(temp, dfs(i));
      for (int i = 0; i < n; i++) used[i] = cused[i];
    }
    printf("%d\n", ans - temp);
    for (int i = 0; i < n; i++) G[i].clear();
  }
}



Measured memory_bytes: 2884
#include <stdio.h>


int main() {


	char str[1001];
	int i;

	scanf("%s", str);

	i = 0;
	while (str[i] != '\0') {
		str[i] = (str[i] - 'A' + 23) % 26 + 'A';
		i++;
	}

	printf("%s\n", str);
	return 0;
}

Measured memory_bytes: 524
n=int(input())
ans=0
dp=[]
for i in range(10):
  dp.append(i)
l=len(str(n))
for i in range(10,n+1):
  num1=int(str(i)[0])
  num2=int(str(i)[-1])
  if num2==0:
    dp.append(dp[-1])
    pass
  else: 
    num=dp[-1]
    nums=0
    l=len(str(i))
    for j in range(2,l):
      nums+=10**(j-2)     
    if num2>num1:
      num4=0
    elif num1>num2:
      num4=10**(l-2)
    else:
      num4=(i-(num2*10**(l-1)+num1))//10
    nums+=num4
    #print(nums)
    num+=nums*2
    if num1==num2:
      num+=3
    dp.append(num)
print(dp[n])

Measured memory_bytes: 10408
N,K=map(int,input().split())
A=list(map(int,input().split()))
dp=[float("INF")]*(N+1)
dp[0]=0
for i in range(N):
  for j in range(1,K+1):
    if j+i>=N:
      break
    dp[i+j]=min(abs(A[i+j]-A[i])+dp[i],dp[i+j])
print(dp[N-1])

Measured memory_bytes: 56440
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;


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

        int gcd = ar[0];
        for (int i = 0; i < n; i++) {
            gcd = gcd(gcd, ar[i]);
        }
        System.out.println(gcd);
        sc.close();
    }
    private static int gcd(int m, int n) {
        if(m < n) {
            return gcd(n, m);
        }
        if(n == 0){
            return m;
        } 
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 51744
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

#define MAX 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1 << 30
int v,r;
vector<pair<int,int> > adj[MAX];

void dijkstra(){
    priority_queue<pair<int,int> > PQ;
    int color[MAX];
    int d[MAX];
    for(int i = 0; i < v; i++){
        color[i] = WHITE;
        d[i] = INFTY;
    }
    
    d[r] = 0;
    PQ.push(make_pair(0,r));
    color[r] = GRAY;

    while(!PQ.empty()){
        pair<int,int> m = PQ.top(); PQ.pop();
        int u = m.second;
        color[u] = BLACK;
        
        if(d[u] < m.first*(-1)) continue;

        for(int i = 0; i < adj[u].size(); i++){
            int v = adj[u][i].first;
            if(color[v] == BLACK) continue;
            if(d[u]+adj[u][i].second < d[v]){
                d[v] = d[u]+adj[u][i].second;
                PQ.push(make_pair(d[v]*(-1),v));
                color[v] = GRAY;
            }
        }
    }
        for(int i = 0; i < v; i++){
        if(d[i] < INFTY) printf("%d\n",d[i]);
        else printf("INF\n");
    }
}

int main(){
    int e,s,t,d;
    scanf("%d %d %d", &v, &e, &r);
    for(int i = 0; i < e; i++){
        scanf("%d %d %d", &s, &t, &d);
        adj[s].push_back(make_pair(t,d));
    }
    dijkstra();

    return 0;
}


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

int main(){
    vector<int> vec(3);
    cin >> vec[0] >> vec[1] >> vec[2];
    

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

    
    cout << vec[0] <<" "<< vec[1] <<" "<< vec[2] << endl;
    return 0;
}


Measured memory_bytes: 3148
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    import heapq
    N, Q = MI()
    event = []
    for _ in range(N):
        s, t, x = MI()
        event.append((s - x-0.5, 1, x))
        event.append((t - x-0.5, -1, x))

    for _ in range(Q):
        d = I()
        event.append((d, 0))

    # クエリも含めてソート
    event.sort(key=lambda x: x[0])

    # 工事現場が一番近いところを探すのにO(N)かけると死ぬのでlogNで調べることができるように優先度付きキューも使う
    occur = set()
    occur_priority = []

    for e in event:
        # 工事開始
        if e[1] == 1:
            occur.add(e[2])
            heapq.heappush(occur_priority, e[2])

        # 工事終了
        elif e[1] == -1:
            if e[2] in occur:
                occur.remove(e[2])

        # クエリ
        elif e[1] == 0:
            if occur:
                while 1:
                    if occur_priority[0] in occur:
                        min_occur = occur_priority[0]
                        break
                    else:
                        heapq.heappop(occur_priority)
                print(min_occur)
            else:
                print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 125660
def check_palindrome(s):
  n = len(s)
  return all([s[i] == s[n - 1 - i] for i in range(n // 2)])


def main():
  s = input()
  n = len(s)
  print('Yes' if check_palindrome(s) and check_palindrome(s[:n // 2]) else 'No')


main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    ll n;cin>>n;
    ll arr[n];
    ll ans = 0;
    for(int i=0;i<n;i++){cin>>arr[i]; ans^=arr[i];}
    for(int i=0;i<n;i++) cout<<(ans^arr[i])<<" ";
    cout<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}





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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl







using ll = long long;


const ll mod = 1e9+7;
const int maxn = 52;

void add(ll& x, ll y) {
    if (x>=mod) x%=mod;
    if (y>=mod) y%=mod;
    x += y;
    if (x>=mod) x%=mod;
}


int n,oddness;

ll dp[maxn][maxn][maxn*maxn]; // seen 1..i, holding j elems, have oddness k

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

    cin>>n>>oddness;
    if (oddness%2) out(0);


    dp[0][0][0] = 1;

    for (int i=0; i<n; i++) {
	for (int j=0; j<=n; j++) {
	    for (int k=0; k<=n*n; k++) {
		add(dp[i+1][j][k+j*2], dp[i][j][k]); //drop us here
		add(dp[i+1][j+1][k+(j+1)*2], dp[i][j][k]); // hold us
		
		if (j>0) add(dp[i+1][j][k+j*2], 1ll*j*dp[i][j][k]); //use us in past
		if (j>0) add(dp[i+1][j][k+j*2], 1ll*j*dp[i][j][k]); //place past here, hold us
		if (j>0) add(dp[i+1][j-1][k+(j-1)*2], 1ll*j*j%mod*dp[i][j][k]%mod); //place past here, place us in the past
	    }
	}
    }


    ll res = dp[n][0][oddness];
    res %= mod;
    res += mod;
    res %= mod;
    cout<<res<<endl;    
    return 0;
}


Measured memory_bytes: 58524
#include<stdio.h>
#include<string.h>
#define MAX 1000

char X[MAX+1],Y[MAX+1];
int Z[MAX+1][MAX+1];
void solve(int ,int);

int main()
{
  int n,i,j,lenx,leny;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",X);
    scanf("%s",Y);
    lenx=strlen(X)+1;
    leny=strlen(Y)+1;
    solve(lenx,leny);
    
    printf("%d\n",Z[lenx-1][leny-1]);
   }
  return 0;
}

void solve(int lenx,int leny)
{
  int i,j,cnt=0;
  for(i=1;i<lenx;i++)Z[i][0]=0;
  for(j=0;j<leny;j++)Z[0][j]=0;
  for(i=1;i<lenx;i++){
    for(j=1;j<leny;j++){
      if(X[i-1]==Y[j-1])Z[i][j]=Z[i-1][j-1]+1;
      else if(Z[i-1][j]>=Z[i][j-1])Z[i][j]=Z[i-1][j];
      else Z[i][j]=Z[i][j-1];
    }
  }
}


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

int main(void){
	int m[10];

	for(int i=0;i<10;i++){
		cin>>m[i];
	}
	sort(m,m+10);
	for(int i=9;i>6;i--){
		cout<<m[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> mp(200000, 0);

    rep(i, n)
    {
        cin >> a[i];
        a[i]--;
        mp[a[i]]++;
    }

    ll ans = 0;

    rep(i, n)
    {
        ans += max(0ll, mp[i] * (mp[i] - 1) / 2);
    }

    rep(i, n)
    {
        ll tmp = a[i];
        cout << ans -( (mp[tmp] * (mp[tmp] - 1) / 2)  -  (max((mp[tmp] - 2), 0ll) * (mp[tmp] - 1)/2) ) <<endl;
    }
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;

ll ca(int i) {
	return 1ll*i * i*i*i*i;
}
ll x;
int main() {
	cin >> x;
	for (int i = -1000; i <= 1000; i++) {
		for (int j = -1000; j < i; j++) {
			if (ca(i) - ca(j) == x) {
				cout << i << ' ' << j << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<vector>
#include<iostream>
#include<set>
#include<map>
#include<algorithm>
using namespace std;




int main() {
	int a,b;
	cin >> a >> b;
	int data[3] = {0};
	a--;b--;
	data[a] = 1;
	data[b] = 1;
	
	for(int i=0;i<3;++i){
		if(data[i]==0) cout << i+1 <<endl;
	}
	
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  int N,M,X;
  cin >> N >> M >> X;
  int ans = 1919810;
  vector<int> C(12);
  vector<vector<int>> A(12,vector<int>(M));
  for(int i=0;i<N;i++){
    cin >> C.at(i);
    for(int j=0;j<M;j++){
      cin >> A.at(i).at(j);
    }
  }
  
  for(int y1=0;y1<2;y1++){
    for(int y2=0;y2<2;y2++){
      for(int y3=0;y3<2;y3++){
    	for(int y4=0;y4<2;y4++){
          for(int y5=0;y5<2;y5++){
    		for(int y6=0;y6<2;y6++){
      		  for(int y7=0;y7<2;y7++){
    			for(int y8=0;y8<2;y8++){
          for(int y9=0;y9<2;y9++){
    		for(int y10=0;y10<2;y10++){
      		  for(int y11=0;y11<2;y11++){
    			for(int y12=0;y12<2;y12++){
                  
                  int count=0;
                  int cost = 0;
                  for(int d=0;d<M;d++){
if(A.at(0).at(d)*y1+A.at(1).at(d)*y2+A.at(2).at(d)*y3+A.at(3).at(d)*y4+
   A.at(4).at(d)*y5+A.at(5).at(d)*y6+
   A.at(6).at(d)*y7+A.at(7).at(d)*y8+A.at(8).at(d)*y9+A.at(9).at(d)*y10+
   A.at(10).at(d)*y11+A.at(11).at(d)*y12 >=X){
     count++;     
   }
                    
   if(count == M){
     cost = C.at(0)*y1+C.at(1)*y2+C.at(2)*y3+C.at(3)*y4+C.at(4)*y5+
            C.at(5)*y6+C.at(6)*y7+C.at(7)*y8+
            C.at(8)*y9+C.at(9)*y10+C.at(10)*y11+C.at(11)*y12;
     if(cost<ans){
       ans=cost;
     }
   }
                    
   }
                  
   }
   }
   }
   }
   }
   }
   }
   }
   }
   }
   }
   }
   
   if(ans==1919810){
     cout << -1 <<endl;
   }else{
     cout << ans << endl;
   }
  
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

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

bool z[8];

int main(){
	int n;
	scanf("%d", &n);
	int k = 0;
	f(i, 0, n){
		int t;
		scanf("%d", &t);
		if (t < 400)z[0] = true;
		else if (t < 800)z[1] = true;
		else if (t < 1200)z[2] = true;
		else if (t < 1600)z[3] = true;
		else if (t < 2000)z[4] = true;
		else if (t < 2400)z[5] = true;
		else if (t < 2800)z[6] = true;
		else if (t < 3200)z[7] = true;
		else ++k;
	}
	int an = 0;
	f(i, 0, 8)if (z[i])++an;
	printf("%d %d\n", max(1, an), an + k);
}

Measured memory_bytes: 256
N = gets.to_i
H = gets.split.map(&:to_i)

ans = 0
cnt = 0

H.each_with_index do |h, i|
    break if i == H.size - 1

    if H[i+1] <= h
        cnt += 1
        ans = cnt if cnt > ans
    else
        cnt = 0
    end
end

puts ans


Measured memory_bytes: 8580
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N; cin >> N;
	vector<int>p(N);
	for (int i = 0;i < N;i++) {
		cin >> p[i];
	}

	int cnt = 0;
	for (int i = 0;i < N;i++) {
		if (i + 1 != p[i])cnt++;
	}

	if (cnt > 2)cout << "NO" << endl;
	else cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N;
int x[MAX_N], y[MAX_N], h[MAX_N];

void solve()
{
  for (int j = 0; j <= 100; j++) {
    for (int k = 0; k <= 100; k++) {
      int nh = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          int tmp = abs(x[i] - j) + abs(y[i] - k) + h[i];
          if (nh == -1) {
            nh = tmp;
          }
          else {
            if (nh != tmp) {
              nh = -2;
              break;
            }
          }
        }
      }
      if (nh == -2) continue;

      for (int i = 0; i < N; i++) {
        if (h[i] == 0) {
          int dist = abs(j - x[i]) + abs(y[i] - k);
          if (nh > dist) {
            nh = -2;
            break;
          }
        }
      }
      if (nh == -2) continue;
      cout << j << " " << k << " " << nh << endl;
      return;
    }
  }
}

int main(void)
{
  cin >> N;
  REP(i, N) cin >> x[i] >> y[i] >> h[i];
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int> 

set<int> divs(int n){
  set<int> retset;
  for (int i=1;i<=(int)sqrt(n);i++){
    if (n%i==0){
      retset.insert(i);
      retset.insert(n/i);
    }
  }
  return retset;
}

int main(){
  int N; cin >> N;
  int X[N], Y[N];
  rep(i,N) {
    cin >> X[i];
    Y[i] = X[i];
  }

  sort(Y, Y+N);
  int mp = Y[N/2-1], mn = Y[N/2];
  rep(i,N){
    if (X[i]>=mn) cout << mp << endl;
    else cout << mn << endl;
  }

  

  return 0;
}

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

int digit(int n) {
  int i = 0;
  while (n > 0) {
    n = n/10;
    i++;
  }
  return i;
}


int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (digit(i) % 2 == 1) {ans++;}
  }
  cout << ans << endl;
  
  
  
}

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

int main() {

    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    if (S[K-1] == 'A') S[K-1] = 'a';
    if (S[K-1] == 'B') S[K-1] = 'b';
    if (S[K-1] == 'C') S[K-1] = 'c';

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast


    int n;
    cin>>n;


    unordered_map<string,ll> m;
    string str;
    for(int i = 0; i < n; i++)
    {
        cin>>str;
        sort(all(str));
        m[str]++;
    }

    ll total = 0;
    for(auto i : m)
    {
        total += (i.ss*(i.ss-1))/2;
    }

    cout<<total;

    return 0;
}

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

Measured memory_bytes: 256
#include<iostream>

int Min(int x, int y) {
	if (x > y) return y;
	else return x;
}


int main(void) {
	int a, b, c;
	std::cin >> a >> b >> c;
	int ans = Min(a + b, Min(b + c, c + a));
	std::cout << ans << std::endl;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
l_sort = sorted(l,reverse=True)
l_len = len(l)
if(l_len%2==0):
    ans = sum(l_sort[:(l_len//2)-1])+sum(l_sort[1:(l_len//2)])+l_sort[(l_len//2)-1]
else:
    ans = sum(l_sort[:(l_len//2)])+sum(l_sort[1:(l_len//2)+1])

print(ans)


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

int main() {
    ll A, B;
    cin >> A >> B;

    ll tmp1, tmp2, ret;
    bool exist = false;
    rep(i, 1250) {
        tmp1 = (ll)((float)i * 0.08F);
        tmp2 = (ll)((float)i * 0.1F);
        if (tmp1 == A && tmp2 == B) {
            exist = true;
            ret = i;
            break;
        }
    }

    if (exist) {
        cout << ret << endl;
    } else {
        cout << -1 << endl;
    }
}

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

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

  int s=0,w=a*100;
  for (int i = 0; 100*a*i <= f; i++)
  {
    for (int j = 0; 100*(a*i+b*j) <= f; j++)
    {
      for (int k = 0; 100*(a*i+b*j) + c*k <= f; k++)
      {
        for (int l = 0; 100*(a*i+b*j) + c*k + d*l <= f; l++)
        {
          int sumw = 100*a*i + 100*b*j;
          int sums = c*k+d*l;

          if(sumw+sums>f || sumw==0) break;
          if((double)sums/(sums+sumw) > (double)s/(s+w)){
            if(sumw*e/100 >= sums){
              s = sums;
              w = sumw;
            }
          }
        }
      }
    }
  }
  cout << s+w << " " << s << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
string s,eh,ss[202020];
int ans;
int main()
{
	cin>>s;
	if(s.size()==1)
	{
		cout<<1<<endl;
		return 0;
	}
	eh+=s[1];
	ss[0]=s[0];
	for(int i=1;i<s.size()-1;i++)
	{
		if(eh!=ss[ans])
		{
			ss[ans+1]=eh;
			ans++;
			eh=s[i+1];
		}
		else
		{
			eh+=s[i+1];
		}
	}
	if(eh==ss[ans])
	{
		ans--;
	}
	cout<<ans+2<<endl;
	return 0;
}

Measured memory_bytes: 11012
#include <bits/stdc++.h>
using namespace std;
int main(){
  char d='B'-'b';
  char a[10],b[10],c[10];
  cin>>a>>b>>c;
  printf("%c%c%c\n",a[0]+d,b[0]+d,c[0]+d);
  return(0);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int s;
  scanf("%d",&s);
  if(0<s%100 && s%100<=12){
    if(0<s/100 && s/100<=12)
      printf("AMBIGUOUS\n");
    else
      printf("YYMM\n");
  }
  else{
    if(0<s/100 && s/100<=12)
      printf("MMYY\n");
    else
      printf("NA\n");
  }
  return 0;
}


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

int main(void){
    string s;
    cin >> s;

    rep(i, s.size()){
        if(s[i] == 'A'){
            cout << "T";
        }else if(s[i] == 'T'){
            cout << "A";
        }else if(s[i] == 'C'){
            cout << "G";
        }else if(s[i] == 'G'){
            cout << "C";
        }
    }
    cout << endl;
    return 0;
}


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

using namespace std;

int main(){
  int n,m;
  cin >> n >> m ;
  vector<int > ar(n);

  int total = 0;
  for(int i=0; i<n; ++i){
    cin >> ar[i];
    total = total + ar[i];
  } 
  
  // cout << total << endl;

  // long double cutoff  = total/( 4 * m);

  // cout << cutoff << endl;
  int count = 0;

  for(int i=0 ; i< n; ++i){
    if((ar[i] *4)*m >= total){
      count++;
    }
  }

  if(count >= m){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }



  

  
}


Measured memory_bytes: 256
/*
* @Author: Samson
* @Date:   2018-05-07 20:48:15
* @Last Modified by:   Samson
* @Last Modified time: 2018-05-07 20:55:02
*/
//   @URL : 
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;

int a[255];

int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	int n;
	cin>>n;
	for(int i = 1; i <= n; ++i)
		cin>>a[i];
	for(int i = 1; i <= n; ++i)
	{
		printf("node %d: key = %d, ", i,a[i]);
		if(i != 1)
			printf("parent key = %d, ",a[i/2] );
		if(i*2 <= n)
			printf("left key = %d, ", a[i*2]);
		if(i*2+1 <= n)
			printf("right key = %d, ",a[i*2+1] );
		printf("\n");
	}
	return 0;
}


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

namespace ITP1_4_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int min, max;
            min = max = nums[0];
            long sum = nums[0];
            for(int i = 1; i < n; i++)
            {
                var num = nums[i];
                min = Math.Min(num, min);
                max = Math.Max(num, max);
                sum += num;
            }
            Console.WriteLine("{0} {1} {2}", min, max, sum);
        }
    }
}

Measured memory_bytes: 9888
L, R = list(map(int,input().split(" ")))
l = L % 2019
r = R % 2019

ans = 2019

if R - L >= 2018 or L > R:
    print("0")
else:
    array = list(range(l,r+1))
    for i in array:
        for j in array:
            if i == j:
                continue
            temp = i * j % 2019
            if ans > temp:
                ans = temp
    print(ans)
    

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int dp[31];
int dp1[3100];
int main()
{
	int a, b, c, d, e, f;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
	dp[0] = 1;
	for (int i = 0; i < 31; i++)
	{
		if (dp[i]&&i+a<31)
			dp[i + a] = 1;
	}
	for (int i = 0; i < 31; i++)
		if (dp[i]&&i+b<31)
			dp[i + b] = 1;
	dp1[0] = 1;
	for (int i = 0; i < 3100; i++)
		if (dp1[i]&&i+c<3100)
			dp1[i + c] = 1;
	for (int i = 0; i < 3100; i++)
		if (dp1[i] && i + d < 3100)
			dp1[i + d] = 1;
	int ch1 = 100*min(a,b);
	int ch2 = 0;
	for (int i = 1; i <= 30; i++)
	{
		if (!dp[i])continue;
		for (int y = 1; y <=min(e*i,3000); y++)
		{
			if (!dp1[y])continue;
			if (i * 100 + y > f)continue;
			if(!ch2){
				ch1 = i * 100 + y;
				ch2 = y;
			}
			else if ((i * 100 + y)*ch2 < ch1*y)
			{
				ch1 = i * 100 + y;
				ch2 = y;
			}
		}
	}
	printf("%d %d", ch1, ch2);
}

Measured memory_bytes: 128
### constant

NUMBERS = [
  ['#######', '#.....#', '#...|.#', '#.....#', '#...|.#', '#..-..#', '#######'],
  ['#######', '#..-..#', '#...|.#', '#..-..#', '#.|...#', '#..-..#', '#######'],
  ['#######', '#..-..#', '#...|.#', '#..-..#', '#...|.#', '#..-..#', '#######'],
  ['#######', '#.....#', '#.|.|.#', '#..-..#', '#...|.#', '#.....#', '#######'],
  ['#######', '#..-..#', '#.|...#', '#..-..#', '#...|.#', '#..-..#', '#######'],
  ['#######', '#..-..#', '#.|...#', '#..-..#', '#.|.|.#', '#..-..#', '#######'],
  ['#######', '#..-..#', '#...|.#', '#.....#', '#...|.#', '#.....#', '#######'],
  ['#######', '#..-..#', '#.|.|.#', '#..-..#', '#.|.|.#', '#..-..#', '#######'],
  ['#######', '#..-..#', '#.|.|.#', '#..-..#', '#...|.#', '#..-..#', '#######']
]

ROTCHS = {'#' => '#', '.' => '.', '-' => '|', '|' => '-'}

### subroutines

def rev_lr(num)
  num0 = 7.times.map{' ' * 7}
  for y in (0..6)
    for x in (0..6)
      num0[y][6 - x] = num[y][x]
    end
  end
  num0
end

def rev_td(num)
  num0 = 7.times.map{' ' * 7}
  for y in (0..6)
    num0[6 - y] = num[y].clone
  end
  num0
end

def rot_90(num)
  num0 = 7.times.map{' ' * 7}
  for y in (0..6)
    for x in (0..6)
      num0[6 - x][y] = ROTCHS[num[y][x]]
    end
  end
  num0
end

def rot_270(num)
  num0 = 7.times.map{' ' * 7}
  for y in (0..6)
    for x in (0..6)
      num0[x][6 - y] = ROTCHS[num[y][x]]
    end
  end
  num0
end

def cut_num(dice, y, x)
  num = []
  for y0 in (y..(y + 6))
    num << dice[y0][x..(x + 6)]
  end
  num
end

def find_num(num)
  #num.each{|n| puts n}
  NUMBERS.index(num) + 1
end

def parse_dice(dice)
  ds = []
  ds << find_num(rev_lr(cut_num(dice, 0, 7)))
  ds << find_num(rot_90(rev_lr(cut_num(dice, 7, 0))))
  ds << find_num(rev_lr(cut_num(dice, 7, 7)))
  ds << find_num(rot_270(rev_lr(cut_num(dice, 7, 14))))
  ds << find_num(rev_lr(cut_num(dice, 7, 21)))
  ds << find_num(rev_lr(rev_td(cut_num(dice, 14, 7))))
  ds
end

### main

loop do
  line = gets.strip
  break if line == '0'

  dice0 = [line[0..27]]
  dice1 = [line[29..56]]

  20.times do
    line = gets.strip
    dice0 << line[0..27]
    dice1 << line[29..56]
  end

  ds0 = parse_dice(dice0)
  ds1 = parse_dice(dice1)
  #p ds0
  #p ds1

  #exp0 = ds0.inject(0.0){|s, d| s + d} / 6
  #exp1 = ds1.inject(0.0){|s, d| s + d} / 6
  #p [exp0, exp1]

  win = lose = 0
  for d0 in ds0
    for d1 in ds1
      if d0 > d1
        win += 1
      elsif d0 < d1
        lose += 1
      end
    end
  end
  #p [win, lose]
  puts (win >= lose ? 'HIGH' : 'LOW')
end

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

#define PI 3.1415926535
#define MOD 1000000007
#define pb push_back
#define mp make_pair
//#define f first
//#define s second
#define FOR(i,x,y) for(int i=x;i<y;i++)
#define fill(a)  memset(a, 0, sizeof (a))
#define in(n) scanf("%d",&n)
#define out(n) printf("%d\n",n)
#define SORT(v)  sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout << (#x) << " is " << (x) << endl;
const long long int MAXX = 15e6;
const long long int MINN = 1e2;
const long long int inf = 1e7;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;


ll lcm(ll a, ll b) {
   return a / __gcd(a, b) * b;
}
int XOR(int x, int y){
  return (x | y) & (~x | ~y);
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
    return (a.second < b.second);
}
// __builtin_popcount(x)  - Returns the number of set bits in x
const long long int N = 4e6+5;
const int MAXN = 105;
int binsearch(int lo, int hi){
	while(lo<hi){
		int mid=(lo+hi)/2;
		if((mid))   // check(mid)
			hi=mid;
		else
			lo=mid+1;
	}
	return lo;
}
ll power(ll x,ll y){
    ll res=1;
    while(y>0){
      if(y&1) res=(res*x)%MOD;

      y/=2;
      x=(x*x)%MOD;
    }
    return res%MOD;
}

int main(){
      FAST
      int n,k;
      cin>>n>>k;
      if(k==1){
          cout<<0;
      }
      else{
          cout<<n-k;
      }

      return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int n;
int g[50][50];
int v[50];
int c,d;

void dfs(int i){
	int j;
	v[i]=1;
	rep(j,n){
		if(g[i][j]&&((i!=c||j!=d)&&(i!=d||j!=c))&&!v[j])
			dfs(j);
	}
}

int main(void){
	int m,a[50],b[50],i,j,f,ans=0;
	n=in();
	m=in();
	rep(i,m){
		a[i]=in();
		b[i]=in();
		a[i]--;
		b[i]--;
		g[a[i]][b[i]]=g[b[i]][a[i]]=1;
	}
	rep(i,m){
		f=1;
		MEMSET(v);
		c=a[i];
		d=b[i];
		dfs(0);
		rep(j,n)
			f&=v[j];
		if(!f)ans++;
	}
	print(ans);
	return 0;
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<double> t(n), v(n);
    for (auto& x: t) {
        cin >> x;
    }
    for (auto& x: v) {
        cin >> x;
    }
    t.emplace_back(0);
    v.emplace_back(0);
    double res = 0;
    double cur = 0;
    for (int i = 0; i < n; i++) {
        double out = v[i];
        double dt = 0;
        for (int j = i+1; j <= n; j++) {
            out = min(out, v[j] + dt);
            dt += t[j];
        }
        double inc = min({v[i]-cur, t[i], (out+t[i]-cur)/2.0});
        double dec = max(0.0, cur+inc - out);
        double cons = t[i] - inc - dec;
        res += (cur*2.+inc)*inc/2.;
        cur += inc;
        res += cur * cons;
        res += (cur*2.-dec)*dec/2.;
        cur -= dec;
    }
    cout << fixed << setprecision(5) << res;
}

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


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int h,w,a[501][501],i,j,k,hs[501],ws[501],x,flg;
	long long sum;
	scanf("%d %d",&h,&w);
	for(i=1;i<=h;i++)	{
		for(j=1;j<=w;j++)	{
			scanf("%d",&a[i][j]);
		}
	}
	if(h%2==1)	flg=1;
	else flg=0;
	for(i=1;i<=(h+1)/2;i++)	{
		hs[i]=0;	
		for(j=1;j<=(h+1)/2;j++)	{
			x=min(i,j);
			hs[i]+=x;
			if(!(flg==1 && j==h/2+1))	hs[i]+=x;
		}
		hs[h-i+1]=hs[i];
	}
	if(w%2==1)	flg=1;
	else flg=0;
	for(i=1;i<=(w+1)/2;i++)	{
		ws[i]=0;	
		for(j=1;j<=(w+1)/2;j++)	{
			x=min(i,j);
			ws[i]+=x;
			if(!(flg==1 && j==w/2+1))	ws[i]+=x;
		}
		ws[w-i+1]=ws[i];
	}	
//	for(i=1;i<=h;i++)	printf("hs=%d\n",hs[i]);
//	for(i=1;i<=w;i++)	printf("ws=%d\n",ws[i]);
	
	
	sum=0;
	for(i=1;i<=h;i++)	{
		for(j=1;j<=w;j++)	{
			sum+=(long long)a[i][j]*hs[i]*ws[j];
		}
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 3744
#include<stdio.h>

int main(){
	int n,x,ways,i,j,k;
	while(1){
		ways=0;
		scanf("%d %d",&n,&x);
		if((n==0)&&(x==0)){
			break;
		}
		for(i=1;i<=n;i++){
			for(j=2;j<=n;j++){
				for(k=3;k<=n;k++){
					if((i+j+k==x)&&(i!=j)&&(i!=k)&&(j!=k)&&(i<j)&&(j<k)){
						//printf("%d+%d+%d=%d\n",i,j,k,i+j+k);
						ways++;
						
					}
					
				}
				
			}
			
		}
		
		printf("%d\n",ways);
		
	}
	
	return 0;
	
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
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; }

int n;
vector< vector<long long> > cmap(4, vector<long long>(110, 0));
vector< vector<long long> > dp(4, vector<long long>(110, 0));

int main() {
    cin >> n;
    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> cmap.at(i).at(j);
        }
    }

    dp[0][0] = cmap.at(0).at(0);
    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < n; ++j) {
            chmax(dp[i+1][j], dp[i][j]+cmap.at(i+1).at(j));
            chmax(dp[i][j+1], dp[i][j]+cmap.at(i).at(j+1));
        }
    }

    cout << dp[1][n-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;

int main(){
    vector<ll> A(100010, 0);
    ll n;
    cin >> n;
    rep(i, n){
        ll num;
        cin >> num;
        num++;
        A[num-1]++;
        A[num]++;
        A[num+1]++;
    }
    ll c=0;
    rep(i, 100010) c = max(c, A[i]);
    out(c);
}

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 10000
#define NIL -1
typedef struct{
  int p,l,r;
}Node;
Node T[MAX];
int n;
 
void preParse(int u){
  if(u == NIL)return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}
 
void inParse(int u){
  if(u == NIL)return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);  
}
 
void postParse(int u){
  if(u == NIL)return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}
 
int main(){
  int i,v,l,r,root;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    T[i].p = NIL;
  }
  for(i = 0 ; i < n ; i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL)T[l].p = v;
    if(r != NIL)T[r].p = v;
  }
  for(i = 0 ; i < n ; i++){
    if(T[i].p == NIL)root = i;
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;
}


Measured memory_bytes: 2044
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int digits = N;
    int sum = 0;
    while (digits != 0) {
      sum += digits % 10;
      digits /= 10;
    }
    if (N % sum == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define N 300010
#define mod 1000000007
char s[N];
int f[N][3][3];
inline void add(int &a,int b) {
    a+=b;
    if (a>mod) a-=mod;
}
int main() {
    f[0][0][0]=1;
    scanf("%s",s+1);
    int n=strlen(s+1);
    for (int i=0;i<n;i++)
        for (int j=0;j<3;j++)
            for (int k=0;k<3;k++) {
                if (s[i+1]!='0') {
                    if (k) add(f[i+1][j][k - 1],f[i][j][k]);
                    else add(f[i+1][min(j+1,2)][k],f[i][j][k]);
                }
                if (s[i+1]!='1') {
                    if (k==2) add(f[i+1][j][1],f[i][j][k]);
                    else add(f[i+1][j][k+1],f[i][j][k]);
                }
            }
    int ans=0;
    for (int i=0;i<3;i++)
        for (int j=0;j<=i;j++) add(ans,f[n][i][j]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long l = sc.nextLong();
		int n = sc.nextInt();
		long[] dis = new long[n+1];
		long[] sum = new long[n+1];
		for(int i=1; i<=n; i++) {
			dis[i] = sc.nextLong();
			sum[i] = sum[i-1] + dis[i];
		}
		if(n == 1) {
			System.out.println(Math.max(dis[1], l-dis[1]));
			return;
		}
		long ans = 0;
		for(int i=1; i<=n; i++) { // i is the pivot
			// hitting pivot from right
			int right = Math.min(i-1, n-i);
			int left = Math.min(i, n-i);
			ans = Math.max(ans, dis[i] + (sum[i-1] - sum[i-1-right])*2 + left *2*l - 2*(sum[left+i] - sum[i]));
			// hitting pivot from left
			right = Math.min(i-1, n-i+1);
			left = Math.min(n-i, i-1);
			ans = Math.max(ans, l-dis[i] + (sum[i-1] - sum[i-1-right])*2 + left *2*l - 2*(sum[left+i] - sum[i]));
//			System.out.println(ans);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 92124
N,M = map(int,input().split())

A = []
for _ in range(N):
  A.append(input())
#print(A)

B = []
for _ in range(M):
  B.append(input())
#print(B)

ans = False
for y in range(N-M+1):
  for x in range(N-M+1):
    matched = True
    for v in range(M):
      for u in range(M):
        if A[y+v][x+u]!=B[v][u]:
          matched = False
    if matched:
      ans = True
print('Yes' if ans else 'No')


Measured memory_bytes: 40868
N, M = gets.chomp.split.map(&:to_i)
X = gets.chomp.split.map(&:to_i).sort

ans = 0
if M > N
  diffs = (1...X.length).to_a.map{|i| X[i] - X[i - 1]}.sort
  ans = diffs[0...(M - N)].inject(&:+)
end
puts ans

Measured memory_bytes: 12656
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
 
vector<int> Zalgo(const vector<int> &s){
    int N=s.size();
    vector<int> z(N,0);
    z[0]=N;
    int i=1,j=0;
    while(i<N){
        int c = s[i]^s[0]; 
        while(i+j<N && (s[i+j]^s[j])==c)j++;
        z[i]=j;
        if(j==0){i++;continue;}
        int k=1;
        while(i+k<N && z[k]+k < j){
            z[i+k]=z[k];
            k++;
        }
        i+=k;j-=k;
    }
    return z;
}
 
int main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> vec(3*N);
    REP(i,N) {
        int a; cin >> a;
        vec[i+N] = a;
        vec[i+2*N] = a;
    }
    REP(i,N) {
        int b; cin >> b;
        vec[i] = b;
    }
    vector<int> z = Zalgo(vec);
    FOR(i,N,2*N) {
        if(z[i]>=N) cout << i-N << ' ' << (vec[0]^vec[i]) << '\n';
    }
    return 0;
}

Measured memory_bytes: 8192
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]

    Inf = 10**9 + 1
    dp = [Inf] * N

    from bisect import bisect_left
    n = 0

    for a in A:
        i = bisect_left(dp, a, 0, n)

        if a < dp[i]:
            dp[i] = a
            n = max(n, i+1)
    print(n)

if __name__ == "__main__":
    resolve()



Measured memory_bytes: 10460