akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

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


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#include<stack>
#include<vector>
#include<string>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int x,a;
	cin>>x>>a;
	if(x < a)
	{
		cout<<"0"<<endl;
	}
	else
	{
		cout<<"10"<<endl;
	}
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, K, X, Y, sum int
	fmt.Scan(&N)
	fmt.Scan(&K)
	fmt.Scan(&X)
	fmt.Scan(&Y)

	if K >= N {
		sum = N * X
	} else {
		sum = K*X + (N-K)*Y
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        WriteLine(48 - cin.nextint);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int data[128] = {};

int main()
{
    int x;
    int cnt = 0;

    for ( int i = 0; i < 12; ++i ) {
        scanf("%d", &x );
        data[x]++;
    }

    for ( int i = 1; i <= 100; ++i ) {
        if ( data[i] % 4 == 0 ) {
            cnt += data[i] / 4;
        }
    }

    if ( cnt == 3 ) {
        printf("yes\n");
    } else {
        printf("no\n");
    }

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}




Measured memory_bytes: 3168
#include <stdlib.h>
#include <stdio.h>

int main()
{
    long long i,k=0,j=0,n,odd[100001],even[100001];
    
    scanf("%lld",&n);
    if(n%2==0){
    for(i=0;i<n;i++){
        if(i%2==1){
            scanf("%lld",&even[k]);
            k++;
        }else{
            scanf("%lld",&odd[j]);
            j++;
        }
    }
    for(i=k-1;i>=0;i--){
        printf("%lld ",even[i]);
    }
    for(i=0;i<j;i++){
        printf("%lld ",odd[i]);
    }
    }else{
        for(i=0;i<n;i++){
        if(i%2==1){
            scanf("%lld",&even[k]);
            k++;
        }else{
            scanf("%lld",&odd[j]);
            j++;
        }    
        }
        for(i=j-1;i>=0;i--){
            printf("%lld ",odd[i]);
        }
        for(i=0;i<k;i++){
            printf("%lld ",even[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 3712
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-6
#define MOD (ll)1e15
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;
typedef pair<int, int> pr;
typedef pair<int, pair<int, int>> tup;

inline void sol()
{
	int n;
	cin >> n;
	map<string, int> mp;
	fore(i, 0, n)
	{
		string s;
		cin >> s;
		mp[s]++;
	}
	int mx = -inf;
	for (auto x : mp)
	{
		mx = max(mx, x.second);
	}

	set<string> otv;
	for (auto x : mp)
	{
		if (x.second == mx)
			otv.insert(x.first);
	}

	for (string x : otv)
		cout << x << '\n';
}

inline void solve()
{
	int q = 1;
	//cin >> q;
	while (q--)
	{
		sol();
		cout << '\n';
	}
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

Measured memory_bytes: 33280
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 1000000000;              // 10^9
// const ll  MAX_N = 1000000000000000000;     // 10^18
// const int BASE  = 1000000000 + 7;          // 10^9 + 7
// const int INFI  = 1000000000 + 7;          // 10^9 + 7
// const ll INFL  = 1000000000000000000 + 7; // 10^18 + 7

ll MOD(ll x, ll y) { return (x % y + y) % y; }
ll DIV(ll x, ll y) { return (x - MOD(x, y)) / y; }

string S;

int main() {
  cin >> S;

  cout << S.substr(0, S.size() - 8) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>

const int ms = 303;
const int MOD = 998244353;

std::bitset<ms> mat[ms];

struct Gauss {
	Gauss() {
		rank = 0;
		for(int i = 0; i < ms; i++) {
			eq[i].reset();
		}
	}
	int rank;
	std::bitset<ms> eq[ms];

	int add(std::bitset<ms> a) {
		for(int i = 0; i < ms; i++) {
			if(!eq[i][i] && !a[i]) continue;
			if(eq[i][i]) {
				if(a[i]) {
					a ^= eq[i];
				}
			} else {
				eq[i] = a;
				rank++;
				return i;
			}
		}
		return -1;
	}

	std::bitset<ms> reduce(std::bitset<ms> a) {
		for(int i = 0; i < ms; i++) {
			if(eq[i][i] && a[i]) {
				a ^= eq[i];
			}
		}
		return a;
	}
};

long long pot[ms + ms];

int main() {
	pot[0] = 1;
	for(int i = 1; i < ms + ms; i++) {
		pot[i] = pot[i-1] * 2 % MOD;
	}
	int n, m;
	std::cin >> n >> m;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			int v;
			std::cin >> v;
			if(v) {
				mat[i][j] = 1;
			}
		}
	}
	long long ans = 0;
	// count isolated
	for(int i = 0; i < n; i++) {
		long long cur = 0;
		for(int j = 0; j < m; j++) {
			if(mat[i][j]) cur = 1;
		}
		cur = cur * pot[m-1+n-1] % MOD;
		ans = (ans + cur) % MOD;
	}
	// uncount with previous
	Gauss tot;
	for(int i = 0; i < n; i++) {
		if(i) {
			mat[i-1][m] = 0;
			tot.add(mat[i-1]);
		}
		mat[i][m] = 1;
		int id = tot.add(mat[i]);
		if(id == m) {
			tot.eq[id].reset();
			tot.rank--;
			continue;
		}
		for(int j = i + 1; j < n; j++) {
			mat[j][m] = 1;
			auto b = tot.reduce(mat[j]);
			if(b[m] && b.count() == 1) {
				// contradiction
			} else {
				int rank = tot.rank;
				if(b.count()) rank++;
				//std::cout << "on pair " << i << ", " << j << " got rank " << rank << "\n";
				ans = (ans - pot[n-1+m-rank] + MOD) % MOD;
			}
		}
		if(id != -1) {
			tot.rank--;
			tot.eq[id].reset();
		}
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 256
//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int w, n;

int a[31], b[31];

int main() {
	cin >> w >> n;
	map<int, int> m;
	for (int i = 0; i < w; i++) {
		m[i + 1] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		int c, d;
		scanf("%d,%d", &c, &d);
		int temp = m[c];
		m[c] = m[d];
		m[d] = temp;
	}
	for (int i = 1; i <= w; i++) {
		cout << m[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
while True:
    H, W = [int(x) for x in input().split()]
    if H == 0 and W == 0:
        break
    line1 = ""
    line2 = ""
    for x in range(0, W):
        if x % 2 == 0:
            line1 += "#"
        else:
            line1 += "."
    for x in range(0, W):
        if x % 2 == 0:
            line2 += "."
        else:
            line2 += "#"
    for y in range(0, H):
        if y % 2 == 0:
            print(line1)
        else:
            print(line2)
    print("")



Measured memory_bytes: 5616
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      
      String[] Weather = {"Sunny", "Cloudy", "Rainy"};
      
      for( int l_i = 0; l_i < 3; l_i++){
        if(Weather[l_i].equals(s)){
          if(l_i < 2){
          	System.out.println(Weather[l_i + 1]);
          } else {
            System.out.println(Weather[0]);
          }
        }
      }
    }
}

Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int f(int x, int y, int z) {
    return x * x + y * y + z * z + x * y + y * z + z * x;
}

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

    vector<int> c(n + 1, 0);
    for (int x = 1; x < 100; x++) {
        for (int y = 1; y < 100; y++) {
            for (int z = 1; z < 100; z++) {
                int t = f(x, y, z);
                if (t <= n) c[f(x, y, z)]++;
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << c[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-


def check_solvable_recursively(number, is_solvable, candidate_numbers):
    """exhaustively search representable as summation of numbers in candidate_numbers

    Args:
        number: representable number
        is_solvable: is solvable list
        candidate_numbers: candidate numbers to be used

    Returns:
        None
    """
    is_solvable[number] = True
    if candidate_numbers:
        check_solvable_recursively(number + candidate_numbers[0], is_solvable, candidate_numbers[1:])
        check_solvable_recursively(number, is_solvable, candidate_numbers[1:])
    else:
        pass


def main():
    raw_input()  # pass length
    candidate_numbers = [int(x) for x in raw_input().strip().split(' ')]
    raw_input()  # pass length
    target_number_list = [int(x) for x in raw_input().strip().split(' ')]

    is_solvable_list = [False] * 2001

    check_solvable_recursively(0, is_solvable_list, candidate_numbers)

    for target_number in target_number_list:
        if is_solvable_list[target_number]:
            print "yes"
        else:
            print "no"

if __name__ == "__main__":
    main()

Measured memory_bytes: 6444
def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr

n,k=map(int,input().split())
a=list(map(int,input().split()))
sum_=sum(a)

fac=sorted(factor(sum_),reverse=True)
ans=1
for x in fac:
    li=sorted(z%x for z in a)
    res=0
    cum=[0]*(n+1)
    for i in range(n):
        cum[i+1]=cum[i]+li[i]
    for i in range(1,n):
        l,r=cum[i],x*(n-i)-(cum[n]-cum[i])
        if l==r and r<=k:
            ans=max(ans,x)
print(ans)

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

ll gcd(ll x, ll y) {
    while (y != 0) {
        ll r = x % y;
        x = y;
        y = r;
    }
    return x;
}

ll lcm(ll x, ll y) {
    return x * y / gcd(x, y);
}

ll A, B, C, D;

ll f(ll n) {
    ll d = gcd(C, D);
    ll m = lcm(C, D);
    ll x = n / C + n / D - n / m;
    return n - x;
}

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

    cin >> A >> B >> C >> D;
    ll result = f(B) - f(A - 1);
    cout << result << endl;

    return 0;
}



Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.conv;

void main() {
    foreach (i; 0 .. 50) {
        int[] tmp = readln.chomp.split.to!(int[]);
        int m = tmp[0], f = tmp[1], r = tmp[2];
        if (m == -1 && f == -1 && r == -1) break;
        if (m == -1 || f == -1) {
            "F".writeln;
        } else if (m + f >= 80) {
            "A".writeln;
        } else if (m + f >= 65) {
            "B".writeln;
        } else if (m + f >= 50) {
            "C".writeln;
        } else if (m + f >= 30) {
            if (r >= 50) {
                "C".writeln;
            } else {
                "D".writeln;
            }
        } else {
            "F".writeln;
        }
    }
}


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

int main() {
  uint32_t N = 0, M = 0;
  std::cin >> N >> M;

  std::vector<uint32_t> degree(N + 1, 0);
  for (size_t i = 0; i < M; i++) {
    uint32_t a = 0, b = 0;
    std::cin >> a >> b;

    degree[a]++;
    degree[b]++;
  }

  for (size_t i = 1; i < degree.size(); i++)
    std::cout << degree[i] << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int a,b;
  cin >> a >> b;
  
  cout <<(b-1+a-2)/(a-1) << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

H, W, K = map(int, input().split(" "))
#print(H, W, K)

list=[]
for i in range(H):
    li = input()
    list.append(li)
#print(list[0][1])

ans=0
y=0
for tate in range(2**H):
    for yoko in range(2**W):
        cnt = 0
        y=y+1
        for i in range(H):
            for k in range(W):
                #print(i, k)
                #print(list[i][k])
                if (tate>>i)&1 == 0 and (yoko>>k)&1 == 0:
                    if list[i][k] == "#":
                        cnt = cnt + 1
        #print(cnt)
        if cnt == K:
            ans = ans + 1
print(ans)
#print(y)

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N, p, q;
   cin >> N;
   vector<int> P(N), Q(N), perm(N);
   rep(i, N) cin >> P.at(i);
   rep(i, N) cin >> Q.at(i);
   rep(i, N) perm.at(i) = i + 1;

   if (P == Q) cout << 0 << endl;
   else {
     int count_p = 1, count_q = 1;
     do {
       if (perm == P) {
         p = count_p;
         count_q++;
       }
       else if (perm == Q) {
         q = count_q;
         count_p++;
       }
       else {
         count_p++;
         count_q++;
       }
     }while(next_permutation(perm.begin(), perm.end()));

     cout << abs(p - q) << endl;
   }
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int n , m , a , w=0;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> a;
        w += a;
    }
    
    if(w > n){
        cout << -1 << endl;
    } else {
        cout << n - w << endl;
    }
    return(0);
}


Measured memory_bytes: 3676
a = [list(map(int, input().split())) for _ in range(3)]
A = [[0, 0, 0] for i in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                A[j][k] = 1

ans = 0
for i in range(3):
    if sum(A[i]) == 3:
        ans = 1

for i in range(3):
    s = 0
    for j in range(3):
        s += A[j][i]
    if s == 3:
        ans = 1

s = 0
for i in range(3):
    s += A[i][i]
if s == 3:
    ans = 1

s = 0
for i in range(3):
    s += A[i][2 - i]
if s == 3:
    ans = 1

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] ls = new int[26];
            String s = in.nextLine();
            for (int i = 0; i < s.length(); i++) {
                ls[s.charAt(i) - 'a']++;
            }

            for (int i = 0; i < ls.length; i++) {
                if (ls[i] == 0) {
                    out.println((char) ('a' + i));
                    return;
                }
            }
            out.println("None");
        }

    }

    static class InputReader {
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String nextLine() {
            String str = null;
            try {
                str = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }

    }
}
 

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

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

    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;

    int japanese = 0;
    int overseas = 0;
    for(int i = 0; i < n; ++i) {
        if (s[i] == 'c') {
            cout << "No\n";
        } else if (s[i] == 'a') {
            if (a + b > japanese) {
                cout << "Yes\n";
                japanese++;
            } else {
                cout << "No\n";
            }
        } else {
            overseas++;
            if (a + b > japanese && overseas <= b) {
                japanese++;
                cout << "Yes\n";
            } else cout << "No\n";
        }
    }

    return 0;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N, cnt = 0;
    cin >> N;
    vector<int> dp;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        auto itr = lower_bound(dp.rbegin(), dp.rend(), A);
        if (itr == dp.rbegin()) {
            dp.push_back(A);
            cnt++;
        } else
            *(itr - 1) = A;
    }

    cout << cnt << '\n';
    return 0;
}


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

using namespace std;

int main(int argc, char* argv[])
{
  int N, M, C; cin >> N >> M >> C;
  
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int score = 0;
    for (int j = 0; j < M; j++) {
      int a; cin >> a;
      score += a*B[j];
    }
    score += C;
    if (score > 0) {
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	string s;
	cin>>s;
	if(s=="ARC"){
		cout<<"ABC"<<endl;
	}else{
		cout<<"ARC"<<endl;
	}
}

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


Measured memory_bytes: 3608
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);


        while(true){
        	int a=scan.nextInt();
        	int b=scan.nextInt();
        	int c=scan.nextInt();
        	if((a|b|c)==0)break;
        	int[] area ={a*a+b*b,a*a+c*c,c*c+b*b};
        	int n = scan.nextInt();
        	for(int i=0;i<n;i++){
        		boolean flag =false;
        		int r=scan.nextInt();
        		int d =4*r*r;
        	for(int l : area)
        		if(d>l)flag=true;
        		if(flag)System.out.println("OK");
        		else System.out.println("NA");
        	}
        }
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    VI a(3);
    rep(i,3) cin >> a[i];
    SORT(a);
    cout << a[0] + a[1] << endl;
    
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, k;
  string s;
  cin >> n >> s >> k;

  char a = s[k - 1];

  rep(i, 0, s.size()) {
    if (s[i] != a) {
      cout << '*';
    } else {
      cout << s[i];
    }
  }
  cout << '\n';
}

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

void solve(long long M, long long K)
{
    ll a_max = (ll)pow(2, M) - 1;

    if (K > a_max) {
        cout << -1 << endl;
        return;
    }
    if (M == 0) {
        cout << "0 0" << endl;
        return;
    }
    if (M == 1) {
        if (K == 0) {
            cout << "0 0 1 1" << endl;
            return;
        } else {
            cout << -1 << endl;
            return;
        }
    }
    if (M >= 2) {
        for (int i = 0; i <= a_max; i++ ) {
            if (i == K) {
                continue;
            }
            cout << i << " ";
        }
        cout << K << " ";
        for (int i = a_max; i >= 0; i--) {
            if (i == K) {
                continue;
            }
            cout << i << " ";
        }
        cout << K << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    solve(M, K);
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N,ma,mb;
  cin>>N>>ma>>mb;

  int dp[N+1][401][401]; //[i品まで][a g][b g]=いくらか

  rep(i,N+1){
    rep(j,401){
      rep(k,401){
        dp[i][j][k]=INF;
      }
    }
  }

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

  rep(i,N){
    int a,b,c;
    cin>>a>>b>>c;
    rep(j,401){
      rep(k,401){
        dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
        if(dp[i][j][k]!=INF){
          dp[i+1][j+a][k+b]=dp[i][j][k]+c;
        }
      }
    }
  }

  int ans=INF;

  reps(j,1,401){
    reps(k,1,401){
      if(j*mb==k*ma) {
        ans=min(ans,dp[N][j][k]);
      }
    }
  }

  if(ans==INF){
    cout << -1 <<"\n"; return;
  }

  cout << ans <<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

int main() {
    int N;
    cin>>N;
    map<string,int> vote;
    int max_vote=0;
    for (int i = 0; i < N; i++){
        string s;
        cin>>s;
        vote[s]++;
        max_vote=max(max_vote,vote[s]);
    }
    vector<string> ans;
    for(pair<string,int> p:vote){
        string key=p.first;
        int val=p.second;
        if(val==max_vote){
            ans.push_back(key);
        }
    }
    sort(ans.begin(), ans.end());
    for(auto name:ans){
        cout<<name<<endl;
    }
}

Measured memory_bytes: 27352
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<long long> arr(n);
    rep(i, n) cin >> arr[i];

    if (n <= k) {
        cout << 0<< endl;
        return 0;
    }

    sort(arr.begin(), arr.end(), greater<>());

    long long ans = 0;
    for (int i = k; i < n; i++) {
        ans += arr[i];
    }
    cout << ans << endl;
}


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

int main(){
    
    int n, m; cin >> n >> m;
    vector<int> products(n);
    int sum=0;
    for (int i=0; i<n; i++){
        cin >> products.at(i);
        sum+=products.at(i);
    }
    int count=0;
    for (int i=0; i<n; i++){
        if (products.at(i)>=sum/float(m*4)){
            count++;
        }
    }
    //cout << "count is " << count << endl;
    if (count>=m){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int d[303][303];
bool d_n[303][303];

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

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> d[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {

			if (i == j)continue;
			for (int k = 0; k < n; k++) {
				if (j == k)continue;
				if (i == k)continue;

				if (d[i][j] > d[i][k] + d[k][j]) {
					cout << "-1" << endl;
					return 0;
				}

				//if (d[i][j] == d[i][k] + d[k][j] && d[i][k] > 0 && d[k][j] > 0) {
				if (d[i][j] == d[i][k] + d[k][j]){
				    d_n[i][j] = true;
				}

			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {

			if (d_n[i][j] == false) {
				ans += d[i][j];
			}

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

Measured memory_bytes: 640
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>

using namespace std;
int abs(int a){
	if (a < 0) {
		return -a;
	} else {
		return a;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> costs = {0};
	vector<int> heights = {};
	int t;
	cin >> t;
	heights.push_back(t);
	cin >> t;
	heights.push_back(t);
	costs.push_back(abs(heights[0] - heights[1]));
	for (int i = 2; i < n; i++) {
		cin >> t;
		costs.push_back(min(costs[i - 2] + abs(heights[i - 2] - t),
			costs[i - 1] + abs(heights[i - 1] - t)));
		heights.push_back(t);
	}
	cout << costs.back();
	return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
    
int N,X;
cin >> N >>X;
int D[N+2]={};
int L[N+1]={};

for(int i=1;i<=N;i++){
    cin >> L[i];
}
int ans=-1;
for(int i=2;i<=N+1;i++){
    D[i]=D[i-1]+L[i-1];
    if(D[i]>X){
        ans=i-1;
        break;
    }

}
if(ans==-1){
    ans=N+1;
}
cout <<ans <<endl;
 return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i=0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int cnt = 0;
  for (int j = 0; j < N; j++) {
    if ((j != 0) && (vec.at(j) == vec.at(j-1))) {
      continue;
    }
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())

def bellman_ford(v, s, e):
    INF = 10**18
    # コストをINFで初期化
    d = [INF] * v
    # 開始頂点は0
    d[s] = 0
    # 負の閉路が無ければ更新はV-1回までで終わる
    for i in range(v):
        f = False
        for a, b, c in e:
            if d[a]==INF:continue
            # aまでのコスト+辺abのコストがbまでのコストより小さければ更新
            cost = d[a] + c
            if cost < d[b]:
                d[b] = cost
                f = True
                if i==v-1 and b==v-1:
                    return -1
        # 更新が無ければbreak
        if not f:
            break

    return d
e=[]
for i in range(m):
    a,b,c=[int(j) for j in input().split()]
    e.append((a-1,b-1,-c))

ans=bellman_ford(n,0,e)
if ans==-1:
    print("inf")
else:
    print(-ans[-1])






Measured memory_bytes: 3312
n = int(input())
a = list(map(int, input().split()))

a = sorted(a, reverse=True)

comb = -1
a_i = a[0]
if a_i % 2 == 0:
    mid = int(a_i/2)
    dif = 10**9
    for i in range(1, n):
        if dif > abs(a[i]-mid):
            dif = abs(a[i]-mid)
            a_j = a[i]
else:
    mid = int(a_i/2)
    dif = 10**9
    for i in range(1, n):
        if a[i] > mid:
            if dif > abs(a[i]-mid-1):
                dif = abs(a[i]-mid-1)
                a_j = a[i]
        else:
            if dif > abs(a[i]-mid):
                dif = abs(a[i]-mid)
                a_j = a[i]

print(a_i, a_j)


Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a,b,c,d;
map <ll,ll> mp;
ll solve(ll n){
    if(n==0)return 0;
    if(n==1)return d;
    if(mp.count(n))return mp[n];
    //cout<<n<<endl;
    ll l2=(n/2)*2;
    ll r2=((n+1)/2)*2;
    
    ll l3=(n/3)*3;
    ll r3=((n+2)/3)*3;
    
    ll l5=(n/5)*5;
    ll r5=((n+4)/5)*5;
    ll ans=1e18;
    //ll ans=min(n*d,(ll)1e18);
    if (n < ans/d) ans = n*d;
    ans=min(ans, llabs(l2-n)*d + a + solve(l2/2));
    ans=min(ans, llabs(r2-n)*d + a + solve(r2/2));
    
    ans=min(ans, llabs(l3-n)*d + b + solve(l3/3));
    ans=min(ans, llabs(r3-n)*d + b + solve(r3/3));
    
    ans=min(ans, llabs(l5-n)*d + c + solve(l5/5));
    ans=min(ans, llabs(r5-n)*d + c + solve(r5/5));
    
    mp[n]=ans;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin>>tt;
    while(tt--){
        ll n;
        cin>>n;
        cin>>a>>b>>c>>d;
        mp.clear();
        ll ans=solve(n);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 4464
#include<cstdio>
#include<iostream> 
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
const int maxn=3e5+50;
int N;
int p[maxn];
bool check(int l,int r) {
	for(int i=l;i<=r;++i) {
		if(p[i]<l||p[i]>r) {
			return false;
		}
	}
	int L=-1,R=-1;
	for(int i=l;i<=r;i+=2) {
		if(p[i]<i) {
			if(L>p[i]) return false;
			L=p[i];
		}
		else {
			if(R>p[i]) return false;
			R=p[i];
		}
	}
	return true;
} 
bool sol() {
	for(int i=2;i<N;++i) {
		if(p[i-1]!=i-1&&p[i]!=i&&p[i+1]!=i+1) {
			return false;
		} 
	}
	int l=1;
	while(l<=N) {
		while(l<=N&&p[l]==l) ++l;
		if(l>N) break;
		int r=l;
		while(r+2<=N&&p[r+1]==r+1&&p[r+2]!=r+2) r+=2;
		if(!check(l,r)) return false;
		l=r+1;
	}
	return true;
}
int main() {
	scanf("%d",&N);
	for(int i=1;i<=N;++i) {
		scanf("%d",&p[i]);
	}
	puts(sol()?"Yes":"No");
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	cout << (n - 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
d=list(map(int,input().split()))

m=int(input())
t=list(map(int,input().split()))

from collections import Counter

c =dict(Counter(d)) 

ans='YES'
for i in range(m):
    p = t[i]

    if p in c:
        if c[p]>=1:
            c[p]-=1
        else:
            ans='NO'
            break
    else:
        ans='NO'
        break

print(ans)



Measured memory_bytes: 49356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string s;
  
  cin >> s;
  
  int n = s.size();
  int nowSize = n;
  /*
  bool hasErased = false;
  bool erasedbefore = false;
  
  do
  {
    hasErased = false;
    
    for(int i = 0; i <= nowSize-2; i++)
    {
      // cout << "Looking at " << i << " " << s <<endl;
      if(s[i] != s[i+1])
      {
        s.erase(i, 2);
        hasErased = true;
        //erasedbefore = true;
        nowSize = s.size();
        //cout << i << " erased" << endl;
      }
    }
  } while (hasErased);
  */
  
  int zero = 0;
  int one = 0;
  
  for(auto itr = s.begin(); itr != s.end(); itr++)
  {
    if(*itr == '0') zero++;
    if(*itr == '1') one++;
  }
  
  cout << n - abs(zero - one) << endl;
  
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int i=0,f=0;
    string s;
        cin >> s;
    while(s[i]!='\0'){
        if(i%2==0 && s[i]!='h')f=1;
        if(i%2==1 && s[i]!='i')f=1;
        i++;
    }
    if(f==0 && i%2==0) cout << "Yes";
    else cout << "No";
    return 0;
}

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

int main()
{
  ll n;
  cin >> n;
  vector<ll> b(n-1);
  rep(n-1) cin >> b[i];
  ll tmp = b[0];
  for (ll i = 1; i < n-1; i++)
  {
    tmp += min(b[i-1],b[i]);
  }
  tmp += b[n-2];
  cout << tmp << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std;
const long long INF=200000000000000000LL;
typedef pair<long long,int> Pa;
int main(){
	long long Q,H,S,D,N,q,h,s,d=INF,ans;
	cin>>Q>>H>>S>>D>>N;
	q=Q*N*4;
	h=H*N*2;
	s=S*N;
	
	d=min(d,D*(N/2)+Q*4*(N%2));
	d=min(d,D*(N/2)+H*2*(N%2));
	d=min(d,D*(N/2)+S*(N%2));
	cout<<min(min(q,h),min(s,d))<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s,0, sizeof(s))
const int mod=100000007;
const int maxn=1000000;
const int inf = 0x3f3f3f3f;
int main()
{
    int a,b,now,ans=0;
    scanf("%d%d",&a,&b);
    now=1;
    while(now<b)
    {
        ans++;
        now--;
        now+=a;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int Q = Integer.parseInt(br.readLine());
    PriorityQueue<Integer> left = new PriorityQueue<>(Comparator.comparingInt(a -> -a));
    PriorityQueue<Integer> right = new PriorityQueue<>();
    long bsum = 0;
    long ymin = 0;
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < Q; i++) {
      String line = br.readLine();
      if (line.charAt(0) == '1') {
        String[] nums = line.split(" ");
        int a = Integer.parseInt(nums[1]);
        int b = Integer.parseInt(nums[2]);
        bsum += b;
        if (left.isEmpty()) left.add(a);
        else if (a < left.peek()) {
          left.add(a);
          ymin += left.peek() - a;
        } else {
          right.add(a);
          ymin += a - left.peek();
        }
        if (left.size() - right.size() > 1) {
          right.add(left.poll());
          int o = right.peek();
          int n = left.peek();
          ymin += (o - n) * (right.size() - left.size());
        } else if (right.size() > left.size()) {
          int o = left.peek();
          int n = right.peek();
          ymin += (n - o) * (left.size() - right.size());
          left.add(right.poll());
        }
      } else {
        sb.append(String.format("%d %d\n", left.peek(), bsum + ymin));
      }
    }
    System.out.print(sb.toString());
  }
}


Measured memory_bytes: 112180
(n, m) = list(map(int, input().split()))
bridge = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

for _ in range(m):
    ab = list(map(int, input().split()))
    bridge[ab[0]][ab[1]] = 1
    bridge[ab[1]][ab[0]] = 1

polygon = []
def search(before, nowi, route):
    global bridge
    for i in range(1, n + 1):
        if before == i or nowi == i :
            continue
        if bridge[nowi][i] == 1:
            if i in route:
                for j in range(len(route)):
                    if route[j] == i:
                        polygon.append(route[j:len(route) + 1])
                        break
                continue
            else:
                search(nowi, i, route + [i])
search(1, 1, [1])

for i in polygon:
    for j in range(1, len(i)):
        bridge[i[j-1]][i[j]] = 0
        bridge[i[j]][i[j-1]] = 0

print(sum(map(sum, bridge)) // 2)

Measured memory_bytes: 9460
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <bitset>
#include <functional>
#include <set>
#include <map>
#include <array>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
//#define int long long int
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

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

bool pairCompare(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, V[21], C[21];
  int ans = 0;
  cin >> N;
  REP(i, N){
    cin >> V[i];
  }
  REP(i, N){
    cin >> C[i];
  }
  REP(i, N){
    if(V[i] - C[i] > 0) ans += V[i] - C[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
"""
演算子は要素とセットでモノイドを形成するようなものでなければならない。
すなわち、結合律が成り立ち単位元が存在する必要がある。

equalityはsetを高速化するために使う。めんどい場合はNoneにしてもOK
"""
class SegmentTree:

    @classmethod
    def all_identity(cls, operator, equality, identity, size):
        return cls(operator, equality, identity, [identity]*(2 << (size-1).bit_length()))

    @classmethod
    def from_initial_data(cls, operator, equality, identity, data):
        size = 1 << (len(data)-1).bit_length()
        temp = [identity]*(2*size)
        temp[size:size+len(data)] = data
        data = temp

        for i in reversed(range(size)):
            data[i] = operator(data[2*i],data[2*i+1])
        return cls(operator, equality, identity, data)

    # これ使わずファクトリーメソッド使いましょうね
    def __init__(self, operator, equality, identity, data):
        if equality is None:
            equality = lambda a,b: False
        self.op = operator
        self.eq = equality
        self.id = identity
        self.data = data
        self.size = len(data)//2

    def _interval(self, a, b):
        a += self.size
        b += self.size
        ra = self.id
        rb = self.id

        data = self.data
        op = self.op
        while a < b:
            if a & 1:
                ra = op(ra,data[a])
                a += 1
            if b & 1:
                b -= 1
                rb = op(data[b],rb)
            a >>= 1
            b >>= 1
        return op(ra,rb)

    def __getitem__(self, i):
        if isinstance(i, slice):
            return self._interval(
                                    0 if i.start is None else i.start,
                                    self.size if i.stop is None else i.stop)
        elif isinstance(i, int):
            return self.data[i+self.size]

    def __setitem__(self, i, v):
        i += self.size
        data = self.data
        op = self.op
        eq = self.eq
        while i and not eq(data[i],v):
            data[i] = v
            v = op(data[i^1],v) if i & 1 else op(v,data[i^1])
            i >>= 1

    def __iter__(self):
        return iter(self.data[self.size:])

from operator import eq

N,M = map(int,input().split())
N += 1
S = tuple(map(lambda x: x == '0', input()))

dp = SegmentTree.all_identity(min, eq, float('inf'), N)
dp[N-1] = 0

for i in reversed(range(N-1)):
    if S[i]:
        dp[i] = dp[i+1:min(N,i+M+1)]+1
if dp[0] == float('inf'):
    print(-1)
    exit()

res = []
i = 0
while i < N-1:
    t = dp[i]
    k = 1
    while dp[i+k] != t-1:
        k += 1
    res.append(k)
    i += k
print(*res)

Measured memory_bytes: 71084