akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

void solve(){
  ll n,K;
  cin>>n>>K;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  int l=-1,r=n;
  while(r-l>1){
    int i=(l+r)/2;
    vector<vector<bool>>dp(n+1,vector<bool>(5005));
    dp[0][0]=true;
    rep(k,n){
      rep(j,5001){
        if(k!=i&&j-a[k]>=0)dp[k+1][j]=dp[k][j]|dp[k][j-a[k]];
        else dp[k+1][j]=dp[k][j];
      }
    }
    bool ng=false;
    rep(j,5001){
      if(dp[n][j]==true&&j<K&&j+a[i]>=K)ng=true;//不必要ではない
    }
    if(ng)r=i;
    else l=i;
  }


  cout<<r;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 5708
module Main where

import Control.Monad (replicateM, forM_)
import Data.List (sortOn)

solve :: [Int] -> [Int]
solve as = let
    largest:secondLargest:n = sortOn negate as
    in
        fmap (\a -> if a == largest then secondLargest else largest) as


main :: IO ()
main = do
    n <- read <$> getLine 
    as <- replicateM n (read <$> getLine)
    let ans =  solve as
    forM_ ans  print

Measured memory_bytes: 120572
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a,b=0,c,k,p=0,q=0;
cin>>a>>b>>c>>k;
p=k-a;
q=k-a-b;
if(a>=k)
cout<<k<<endl;
else if(b+a>=k&&k>a)
cout<<a<<endl;
else if(c+a+b>=k&&k>a+b)
cout<<a+q*(-1)<<endl;
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int sum[5];
char c[21];
int main()
{
	int n,i;
    scanf("%d\n",&n); 
    for(i=1;i<=n;i++)
    {
    	scanf("%s",c);
    	if(c[0]=='A'&&c[1]=='C')sum[1]++;
    	else if(c[0]=='W'&&c[1]=='A')sum[2]++;
    	else if(c[0]=='T'&&c[1]=='L'&&c[2]=='E')sum[3]++;
    	else if(c[0]=='R'&&c[1]=='E')sum[4]++;
	}
	printf("AC x %d\n",sum[1]);
	printf("WA x %d\n",sum[2]);
	printf("TLE x %d\n",sum[3]);
	printf("RE x %d",sum[4]);
	
} 

Measured memory_bytes: 3812
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<30)


// 全点対間最短距離（ワーシャルフロイド）
const int MAX = 10;
int d[MAX][MAX];
void floyd(){
	int n = MAX;
	for (int k = 0; k < n; k++){
		for (int i = 0; i < n; i++){
			if (d[i][k] == INF) continue;
			for (int j = 0; j < n; j++){
				if (d[k][j] == INF) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int H, W;
int freq[10];

signed main(){
	cin >> H >> W;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++){
			cin >> d[i][j];
			if (d[i][j] == -1) d[i][j] = INF;
		}


	floyd();

	for (int i = 0; i < H*W; i++){
		int c;
		cin >> c;
		if (c >= 0) freq[c]++;
	}
	int result = 0;
	for (int i = 0; i < 10; i++){
		result += d[i][1] * freq[i];
	}

	cout << result << endl;


	return 0;
}





Measured memory_bytes: 256
from collections import defaultdict
counter = defaultdict(int)
n, k, q = map(int, input().split())
for _ in range(q):
    a = int(input()) - 1
    counter[a] += 1

for i in range(n):
    if k - q + counter[i] > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 16156
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int k; cin >> k;
    int n = 7;
    int ans = 0;
    int amari;
    rep(i,k) {
        ans++;
        amari = n%k;
        if (amari==0) break;
        n = n*10+7;
        n %= k;
    }
    if (amari==0) cout << ans << endl;
    else cout << -1 << endl;
}

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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector< pair<int,int> > edge;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    edge.emplace_back(u, v);
  }

  vector<long long> res(m);
  long long ans = (long long) n * (n - 1) / 2;

  vector<int> pa(n), num(n, 1);
  iota(pa.begin(), pa.end(), 0);

  function<int(int)> find = [&](int i) {
    if (i == pa[i]) return i;
    return pa[i] = find(pa[i]);
  };
  auto unite = [&](int i, int j) {
    i = find(i);
    j = find(j);
    if (i == j) return;
    ans -= (long long) num[i] * num[j];
    pa[j] = i;
    num[i] += num[j];
  };

  for (int i = m - 1; i >= 0; i--) {
    res[i] = ans;
    int u, v;
    tie(u, v) = edge[i];
    unite(u, v);
  }

  for (int i = 0; i < m; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,ans;
  cin>>n>>m;
  for(int i=m/n;i>=0;i--){
    if(m%i==0){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
const int N=55;
//Code beg....

char s[N][N];
int ans[N][N];

int main ()
{
    int n, m;
    scanf("%d%d",&n,&m);
    FOR(i,1,n) scanf("%s",s[i]+1);
    FOR(i,1,n) FOR(j,1,m) {
        if (s[i][j]=='#') {
            ++ans[i-1][j];
            ++ans[i-1][j-1];
            ++ans[i-1][j+1];
            ++ans[i][j-1];
            ++ans[i][j+1];
            ++ans[i+1][j-1];
            ++ans[i+1][j];
            ++ans[i+1][j+1];
        }
    }
    FOR(i,1,n) {
        FOR(j,1,m) {
            if (s[i][j]=='#') putchar(s[i][j]);
            else putchar(ans[i][j]+'0');
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N; cin >> N;
  
  map<int, int> data;
  for (int i = 1; i <= N; i++) {
    int n = i;
    for (int j = 2; j*j <= i; j++) {
      while (n % j == 0) {
        n /= j;
        data[j]++;
      }   
    }
    if (n != 1) data[n]++;
  }
  
  map<int, int> num;
  for (auto i : data) {
    if (i.second >= 74) num[75]++;
    if (i.second >= 24) num[25]++;
    if (i.second >= 14) num[15]++;
    if (i.second >= 4) num[5]++;
    if (i.second >= 2) num[3]++;
  }

  int ans = num[75] + max(0,num[25] * (num[3] - 1)) + max(0,num[15] * (num[5] - 1)) + max(0,num[5] * (num[5] - 1) * (num[3] - 2) / 2);
  
  cout << ans << endl;
}

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

int n, m, ans[50];
ll a[50][2], dis[50], x, y;

ll manhattan(ll x1, ll y1, ll x2, ll y2){
	return abs(x1-x2)+abs(y1-y2);
}

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

	for(int i=0; i<n; i++){
		cin >> a[i][0] >> a[i][1];
		dis[i] = 2e9;
		ans[i] = 60;
	}

	for(int i=0; i<m; i++){
		cin >> x >> y;
		for(int j=0, tempdis; j<n; j++){
			tempdis = manhattan(a[j][0], a[j][1], x, y);
			if(tempdis < dis[j]){
				dis[j] = tempdis;
				ans[j] = i+1;
			}
		}
	}

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

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

typedef long long ll;
const int inf = 1e9;

long long x, k, d, ans;

int main(){
	cin>>x>>k>>d;
	if(x < 0)x = -x;
	ans = numeric_limits<long long>::max() - 1;
	ll t = (x / d);
	if(t > k){ // only k steps available, so take them towards the origin.
		x -= k * d;
		cout<<abs(x)<<endl;
		return 0;
	}
	ll temp = x;
	temp -= (t * d); // +
	ll r = k;
	r -= t;
	if(r % 2 == 0){ // only end up back here, -ve, +ve
		ans = min(ans, abs(temp));
	}
	else{ // else we end up temp - d, at -ve location
		ans = min(ans, abs(temp - d));
	}
	temp = x; // try take one extra step to begin with 
	temp -= (t + 1) * d; // at negative location
	r = k;
	r -= t + 1;
	if(r % 2 == 0){ // if even number of steps, back to this location.
		ans = min(ans, abs(temp));
	}
	else{ // otherwise we can take one more, since we are negative to begin with, we'll be postive at the end.
		ans = min(abs(temp + d), ans);
	}
	cout<<ans<<endl;	
	return 0;
}


Measured memory_bytes: 3648
from itertools import combinations

n=int(input())
march=[0]*5

for _ in range(n):
    initial=input()[0]
    if initial in "MARCH":
        march["MARCH".index(initial)]+=1

count=0
for i, j, k in combinations(range(5),3):
    count+=march[i]*march[j]*march[k]
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define MOD (LL)pow(10,9) + 7

struct ST
{
    int a;
    char b;
};


int main(){
    int n,m;
    cin >> n >> m;
    vector<ST> s(m);
    for(int i = 0; i < m; ++i){
        cin >> s[i].a >> s[i].b;
    }

    for(int i = (n == 1 ? 0 : pow(10,n - 1)); i < pow(10,n); ++i){
        string t = to_string(i);
        bool ch = true;

        for(int j = 0; j < m; ++j){
            if(!(t[s[j].a - 1] == s[j].b)){
                ch = false;
            }
        }

        cerr << i << endl;

        if(ch){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;


    return 0;
}


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

int main() 
{
	int x, y;
	cin >> x >> y;
	while (x!=0||y!=0) {
		if (x < y) {
			cout << x << " " << y << endl;
		}
		else {
			cout << y << " " << x << endl;
		}
		cin >> x >> y;
	}
}




Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		//System.out.println("??\???>>");

		Scanner scan = new Scanner(System.in);

		int intTate = scan.nextInt();
		int intYoko = scan.nextInt();


		//System.out.println(intTate + " " + intYoko);

		int intArea = intTate * intYoko;

		int intOutLine = (intTate + intYoko) * 2;

		System.out.println(intArea + " " + intOutLine);

	}

}

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

int main()
{
    while (1) {
        int n, m;
        bool found = false;
        int sumt = 0, sumh = 0;
        cin >> n >> m;
        if (n == 0 && m == 0)
            break;
        int taro[100], hana[100];
        for (int i = 0; i < n; i++) {
            cin >> taro[i];
            sumt += taro[i];
        }
        for (int j = 0; j < m; j++) {
            cin >> hana[j];
            sumh += hana[j];
        }
        int ten = 201, a = 101, b = 101;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if ((sumt - taro[i] + hana[j]) == (sumh - hana[j] + taro[i])) {
                    if (ten > (taro[i] + hana[j])) {
                        found = true;
                        a = taro[i];
                        b = hana[j];
                        ten = taro[i] + hana[j];
                    }
                }
            }
        }
        if (found) {
            cout << a << " " << b << endl;
        }
        else {
            cout << -1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+5;
int a[N];
int main()
{
    int n;scanf("%d",&n);
    ll ans=0;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<n;i++)
    {
        ans+=a[i]/2;a[i]%=2;
        if(a[i]&&a[i+1])ans++,a[i]--,a[i+1]--;
    }
    printf("%lld\n",ans+a[n]/2);
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

int main(){
	char X[2], Y[2];
	scanf("%s %s",&X, &Y);
	if(strcmp(X,Y)==0) printf("=\n");
	if(strcmp(X,Y)>0) printf(">\n");
	if(strcmp(X,Y)<0) printf("<\n");
	return 0;
}

Measured memory_bytes: 128
n,w = map(int,input().split())
weight = [0 for i in range(n)]
value = [0 for i in range(n)]
for i in range(n):
    weight[i],value[i] = map(int,input().split())
    

#dp[i][j]: i番目の品物までの中から選び、重さがj以下になる時の、価値の総和の最大値
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(w+1):
        dp[i][j] = max(dp[i][j],dp[i-1][j])
        if(j - weight[i-1] >= 0):
            dp[i][j] = max(dp[i-1][j-weight[i-1]]+value[i-1],dp[i][j])
            
print(dp[n][w])

Measured memory_bytes: 171784
#include <iostream>

int main(){
   char b;
   std::cin >> b;

   if(b=='A') std::cout << 'T' << std::endl;
   else if(b=='C') std::cout << 'G' << std::endl;
   else if(b=='G') std::cout << 'C' << std::endl;
   else if(b=='T') std::cout << 'A' << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list>
#include <unordered_set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define _GLIBCXX_DEBUG
using namespace std;
struct __INIT { __INIT() {cin.tie(nullptr); ios::sync_with_stdio(false);} } __init;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
typedef pair<ll,ll> pair_t;
bool PSecComp(const pair_t& a, const pair_t& b) {
	if (a.second == b.second)return  a.first > b.first;
	else {
		return a.second > b.second;
	}
}

int main(){
	ll n;
	cin >> n;
	ll tmp = getDigit(n);
	cout << (tmp % 2 == 1 ? ( n - pow(10,tmp-1) +1) : 0) + (pow(100,ceil((tmp-1)/2.0))-1)/11 << endl;
}



Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	N, M := sc.nextInt(), sc.nextInt()
	even := (N*N - N) / 2
	var odd int
	if M >= 2 {
		odd = (M*M - M) / 2
	}
	fmt.Println(odd + even)
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
#define N 105
#define inf 1
typedef long long ll;


ll a,b,n,i;
ll s=0;
ll x,l=0;

int main(){
    cin>>a>>b>>n;
    if(floor(n*a/b)-floor(n/b)*a>s)
        s=floor(n*a/b)-floor(n/b)*a;
    for(i=1;;i++){
        if(i*b-1>n)
            break;
        if(floor(a*(i*b-1)/b)-a*(i-1)>s)
        s=floor(a*(i*b-1)/b)-a*(i-1);
        else
            l++;
        if(l>=5000)
            break;
        
        
        
    }
    cout<<s;
    
    return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]){

	bool all_visited = true;

	REP(i,N){
		if(visited[i] == false) all_visited = false;
	}

	if(all_visited) return 1;

	int ret = 0;

	REP(i,N){
		if(graph[v][i] == false) continue;
		if(visited[i]) continue;
		
		visited[i] = true;
		ret += dfs(i,N,visited);
		visited[i] = false;
	}

	return ret;

}


int main(void){

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

	REP(i,M){
		int A, B; cin >> A >> B; A--; B--;
		graph[A][B] = graph[B][A] = true;
	}

	bool visited[nmax];
	REP(i,N){
		visited[i] = false;
	}
	
	visited[0] = true;
	cout << dfs(0, N, visited) << endl;

	return 0;

}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const char letters[] = {'i', 'x', 'c', 'm'};

string to_mcxi(int n) {
    stringstream ss;
    int d = 0;
    while (n > 0) {
        int m = n % 10;
        n /= 10;
        if (m > 0) {
            ss << letters[d];
            if (m != 1) {
                ss << m;
            }
        }
        d++;
    }
    string s = ss.str();
    reverse(ALL(s));
    return s;
}

int from_mxci(string s) {
    int n = 0;
    int m = 1;
    REP(i, SZ(s)) {
        if (isdigit(s[i])) {
            m = s[i] - '0';
        } else {
            switch (s[i]) {
            case 'm':
                n += m * 1000;
                break;
            case 'c':
                n += m * 100;
                break;
            case 'x':
                n += m * 10;
                break;
            case 'i':
                n += m * 1;
                break;
            }
            m = 1;
        }
    }
    return n;
}

int main() {
    int n;
    cin >> n;
    REP(i, n) {
        string l, r;
        cin >> l >> r;
        cout << to_mcxi(from_mxci(l) + from_mxci(r)) << endl;
    }
}

Measured memory_bytes: 3088
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, K := getInt(), getInt()
	s := getString()
	cur := s[0]
	cnt := 0
	for i := 1; i < N; i++ {
		// out(cnt, K, string(s[i]), string(cur))
		if s[i] == cur {
			cnt++
			continue
		}
		if K > 0 {
			cnt++
			cur = s[i]
			for i < N {
				if s[i] != cur {
					break
				}
				i++
				cnt++
			}
			K--
		}
		if i < N {
			cur = s[i]
		}
	}
	cnt = min(N-1, cnt)
	out(cnt)
}


Measured memory_bytes: 2104
N = int(input())
B = list(map(int,input().split()))
A = [0 for i in range(N)]

for i in range(N-1):
	b = B[i]
	if i == 0:
		A[i] = b
	else:
		A[i] = min(b, B[i-1])

print(sum(A) + B[-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int main() {
    ll n, d;
    cin(n); cin(d);

    ll result = 0;
    rep2(i, n) {
        ll x, y;
        cin(x); cin(y);

        if (pow(x * x + y * y, 0.5) <= d) ++result;
    }

    print(result);
    return 0;
}

Measured memory_bytes: 4228
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  int N = readln.split[0].to!int;
  int[] A = new int[N];
  foreach(ref a; A) {
    a = readln.split[0].to!int;
  }

  int top = A.reduce!max;
  int second = 0;
  int maxcnt = 0;
  foreach(a; A) {
    if(a == top) { maxcnt++; continue; }
    second = max(second, a);
  }

  foreach(a; A) {
    writeln(a == top && maxcnt == 1 ? second : top);
  }
}


Measured memory_bytes: 4860
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int[] deg = new int[N];
		var M = new List<Tuple<int, int>>(N);
		List<int>[] adj = new List<int>[N];
		for(int i = 0; i < N; i++)
			adj[i] = new List<int>();

		for(int i = 0; i < N - 1; i++)
		{
			int a = GetInt();
			int b = GetInt();
			M.Add(Tuple.Create(a-1, b-1));
			deg[a-1]++;
			deg[b-1]++;
			adj[a-1].Add(b-1);
			adj[b-1].Add(a-1);
		}

		List<int> c = new List<int>(N);
		for(int i = 0; i < N; i++)
			c.Add(GetInt());
		c.Sort();

		int[] d = new int[N];
		bool[] visited = new bool[N];
		int numVisited = 0;
		while(numVisited < N)
		{
			List<int> leaf = new List<int>();
			for(int i = 0; i < N; i++)
			{
				if(visited[i])
					continue;
				
				if((deg[i] == 1) || (deg[i] == 0))
				{
					leaf.Add(i);
					visited[i] = true;
					d[i] = c[numVisited];
					numVisited++;
				}
			}

			foreach(int v in leaf)
				foreach(int u in adj[v])
					deg[u]--;					
		}

		int ans = 0;
		for(int i = 0; i < N - 1; i++)
			ans += Math.Min(d[M[i].Item1], d[M[i].Item2]);
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < N; i++)
			sb.AppendFormat($"{d[i]} ");

		Console.WriteLine(ans);
		Console.WriteLine(sb);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





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

bool check(int q) {
	for (int i = 3; i <= sqrt(q); i += 2)
		if (q % i == 0)
			return 0;

	return 1;
}

int main()
{	
	int n;

	cin >> n;

	while (n > 0) {
		if (n < 19 && n >= 13)
			cout << 13 << endl;
		else {
			int i = n - (n + 11) % 30;

			while (!(check(i) && check(i - 2) && check(i - 6) && check(i - 8)))
				i -= 30;

			cout << i << endl;
		}

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

bool isEdge(pll a, ll R, ll C) {
	return (a.fi == 0 || a.fi == R || a.se == 0 || a.se == C);
}

ll edgeOrd(pll a, ll R, ll C) {
	ll res = 0;
	if(a.se == 0) {
		res += a.fi;
		return res;
	}
	res += R;
	if(a.fi == R) {
		res += a.se;
		return res;
	}
	R += C;
	if(a.se == C) {
		res += R-a.fi;
		return res;
	}
	res += R;
	res += C-a.se;
	return res;
}

int main() {
	ll R, C, N;
	vector<pll> v;
	cin >> R >> C >> N;
	rep(i,N) {
		pll a, b;
		cin >> a.fi >> a.se >> b.fi >> b.se;
		if(isEdge(a,R,C) && isEdge(b,R,C)) {
			ll aa, bb;
			aa = edgeOrd(a,R,C);
			bb = edgeOrd(b,R,C);
			if(bb < aa) swap(aa,bb);
			v.push_back(pll(aa,bb));
		}
	}
	sort(all(v));
	bool flg = true;
	const ll mod = (C+R)*2;
	stack<ll> stk;
	if(v.size())
		stk.push(v[0].se);
	ll mx = -1;
	for(int i = 1; i < v.size(); i++) {
		while(stk.size() && stk.top() < v[i].fi)
			stk.pop();
		if(!stk.size() || v[i].se < stk.top()) {
			stk.push(v[i].se);
		}
		else {
			flg = false;
		}
	}
	if(flg)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>

int main( void){
    
    int a , b;
    int s , l;
    
    scanf( "%d %d" , &a , &b );
    
    s = a * b;
    l = 2 * ( a + b );
    
    printf( "%d %d\n" , s , l );
    
}


Measured memory_bytes: 2084
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    k = int(input())
    a = list(map(int,input().split()))
    
    mi = 2
    ma = 2

    if a[k-1] != 2:
        print(-1)
        exit()

    for i in range(k):
        if ma < a[k-1-i]:
            print(-1)
            exit()
        
        ma = a[k-1-i]*(ma // a[k-1-i]) + a[k-1-i] - 1
        
        if a[k-1-i]*(ma // a[k-1-i]) < mi:
            print(-1)
            exit() 
                    
        mi = a[k-1-i]* ((mi -1)  // a[k-1-i] + 1)

    print(mi,ma)

    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}


Measured memory_bytes: 124652
import heapq

n,m=map(int,input().split())
works=[[] for i in range(m+1)]
for i in range(n):
    day,pay=map(int,input().split())
    try:
        works[day].append(pay)
    except IndexError:
        pass
#print(works)

heapls=[]
day=1
ans=0

for i in range(m):
    day=i+1
    for j in works[day]:
        heapq.heappush(heapls,-j)
    if heapls!=[]:
        tmp=heapq.heappop(heapls)
        ans=ans+tmp
print(-ans)

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

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

const int max_n = 10e5;
int i2rl[max_n+1];
int rc2i[max_n+1];
int lc2i[max_n+1];
int rsum;
int lsum;
int i2c[max_n+1][2];

int n;
int panel[max_n];

int main(){
    cin >> n;

    int rsum = 0;
    int lsum = 0;
    string arrows;
    cin >> arrows;
    REP(i, n){
        char arrow;
        arrow = arrows[i];
        if(arrow == '>'){
            rsum += 1;
            rc2i[rsum] = i; // count -> idx
            i2rl[i] = 0; // idx -> rl;
        } else {
            lsum += 1;
            lc2i[lsum] = i;
            i2rl[i] = 1;
        }
        i2c[i][0] = rsum;
        i2c[i][1] = lsum;
    }

    int rcount = 0;
    int lcount = lsum;
    REP(i, n){
        if(i2rl[i] == 0){
            rcount += 1;
            if(rcount <= lcount){
                panel[i] = lc2i[i2c[i][1]+rcount] + 1;
            } else {
                panel[i] = n - rc2i[rcount-lcount];
            }
        } else {
            if(lcount <= rcount){
                panel[i] = n - rc2i[i2c[i][0] - lcount + 1];
            } else {
                panel[i] = lc2i[i2c[i][1]+rcount] + 1;
            }
            lcount -= 1;
        }
    }

    int output = 0;
    REP(i, n){
        // cout << panel[i] << " "; //
        output = max(output, panel[i]);
    }
    // cout << endl; //
    
    cout << output << endl;
}

Measured memory_bytes: 5192
#include"bits/stdc++.h"

using namespace std;

#define MAX 200002

int n;
vector<int> g[MAX];

int dist[MAX];
queue<int> q;

int bfs(int b) {
	memset(dist, -1, sizeof(dist));
	dist[b] = 1;
	q.push(b);
	while (!q.empty()) {
		b = q.front();
		q.pop();
		for (int go : g[b]) {
			if (dist[go] == -1) {
				q.push(go);
				dist[go] = dist[b] + 1;
			}
		}
	}
	return b;
}

int z[MAX];

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int mx=dist[bfs(bfs(0))];
	z[0] = 0;
	for (int i = 1; i <= mx; i++) {
		if (i <= 2) {
			if (z[i - 1] == 0) {
				z[i] = 1;
			}
			else {
				z[i] = 0;
			}
			continue;
		}
		if (z[i - 1] == 0) {
			z[i] = 1;
		}
		if (z[i - 2] == 0) {
			z[i] = 1;
		}
	}
	if (z[mx]) {
		puts("First");
	}
	else {
		puts("Second");
	}

	return 0;
}

Measured memory_bytes: 13556
N=int(input())
X=[]
for i in range(N):
    a,b=map(int,list(input().split(" ")))
    X.append([a+b,a-b])
X.sort()
D={}
D[0]=1
exe=[0]
for i in range(1,N):
    k=X[i][0]
    if X[i][1]<X[exe[-1]][0]:
        D[i]=D[exe[-1]]
    else:
        D[i]=D[exe[-1]]+1
        exe.append(i)
print(len(exe))

Measured memory_bytes: 35344
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

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

  int N , M;
  cin >> N >> M;
  priority_queue< int , vector<int> , greater<int> > Q;
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    Q.push(a);
  }
  vector<pair<int,int>> P(M);
  for(int i = 0; i < M; i++) {
    cin >> P[i].second >> P[i].first;
  }
  sort(P.rbegin() , P.rend());
  dg1(P);
  for(int i = 0; i < M; i++) {
    int n = P[i].second;
    while(n--) {
      int top = Q.top();
      dg4(i, n , top , P[i].first);
      if(P[i].first > top){
        Q.pop();
        Q.push(P[i].first);
      } else{
        break;
      }
    }
  }
  int ans = 0;
  while(!Q.empty()) {
    ans += Q.top();
    Q.pop();
  }
  cout << ans << '\n';
}


Measured memory_bytes: 5116
def main():
    n, d = [int(v) for v in input().split(' ')]
    cnt = 0

    for _ in range(n):
        x, y = [int(v) for v in input().split(' ')]
        if x**2 + y**2 <= d**2:
            cnt += 1
    print(int(cnt))


if __name__ == '__main__':
    main()


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

int main(){
    int n, i, j, k;
    cin>>n;
    //cout<<n<<endl;
    int nagasa=n;
    char s[n];
    int al[26];
    for(i=0; i<26; i++){
        al[i] = 0;
    }
    cin>>s;
    //cout<<s;
    int max = 0;
    int kosu = 0;
    for(i=1; i<n; i++){
        for(j=0; j<i; j++){
            for(k=i; k<n;k++){
                //cout<<s[j]<<s[k]<<endl;
                if(s[j] == s[k]){
                    al[int(s[j]-'a')]++;
                    //cout<<"true"<<endl;
                }
            }
        }
        for(j=0; j<26; j++){
            if(al[j]>0){
                kosu++;
                al[j] = 0;
            }
        }
        if(max<kosu){
            max = kosu;
        }
        kosu = 0;

    }
    cout<<max<<endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;
const int mod= 1e9 + 7;

struct edge { int to; int cost; 
edge(int a, int b):to(a),cost(b){}
};
typedef pair<int, int> P;//firstは最短距離、secondは頂点の番号

int V = 2001;//頂点の数
vector<edge> G[2001];//辺の情報！
int d[2001]; //sからnまでの最短コスト

void dijkstra(int s) {//sがゴール
	priority_queue<P, vector<P>, greater<P>> que;
	fill(d, d + V, INF);//最短距離の初期化
	d[s] = 0;//開始位置
	que.push(P(0, s));//始点は距離０と考える

	while (!que.empty()) {
		P p = que.top(); que.pop();//キューの視点からの最短距離の頂点を取り出す
		int v = p.second;
		if (d[v] < p.first)continue;//既に最短距離がd[v]に記録されていたら飛ばす
		for (int i = 0; i < int(G[v].size()); i++) {
			edge e = G[v][i];//頂点vを始点とした辺の構造体

			if (d[e.to] > d[v] + e.cost) {//辺の終点にある現時点での最短距離が今回追加するやつより大きいなら
				d[e.to] = d[v] + e.cost; //更新する
				que.push(P(d[e.to], e.to));
			}
		}

	}

}

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

	int X, Y, N;
	cin >>N>> X >> Y;


	vector<int> ans(N,0);
	edge s(Y-1,1), ss(X-1,1);
	G[X-1].emplace_back(s);
	G[Y-1].emplace_back(ss);
	FOR(i, 0, N-1) {
		edge q((i + 1) % N, 1),p(i% N, 1);
		G[i%N].emplace_back(q);
		G[(i+1)%N].emplace_back(p);
	}
	FOR(i, 0, N) {
		dijkstra(i);
		FOR(j, 0, N) {
			ans[d[j]]++;
		}
	}
	FOR(i, 1, N)cout << ans[i] / 2 << endl;

	return 0;
}

Measured memory_bytes: 384
/*input
13
strangeorange
*/

/* points of DP
1. representation
2. transition
3. direction
*/

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

int dp[2][5005];  // initialized by 0

int main() {
    int n;
    string s;
    cin >> n >> s;
    int *cur = dp[0], *nxt = dp[1]; // ex. cur[i] = *(cur+i)
    int ans = 0;
    for (int j = n-1; j >= 1; j--) {
        for (int i = j-1; i >= 0; i--) {
            if (s[i] == s[j]) {
                cur[i] = nxt[i+1]+1;
                ans = max(ans, min(j-i, cur[i]));
            }
            else {
                cur[i] = 0;
            }
        }
        swap(cur, nxt);
    }
    cout << ans << endl;
}

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

int main() {
  vector<int64_t> x(5);
  rep(i, 5) cin >> x.at(i);

  rep(i, 5) {
    if (x.at(i) == 0) {
      cout << i + 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<string>
using namespace std;
int main(){
  string x;
  cin>>x;
  if(x[0]==x[1] and  x[1]==x[2])
    cout<<"Yes"<<endl;
  else if(x[1]==x[2] and x[2]==x[3])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 888
A=[1]*51
for i in range(1,51):
    A[i]=2*A[i-1]+3

def T(N,x):
    if N==0:
        return 1
    elif x==1:
        return 0
    elif 2<=x<=A[N-1]+1:
        return T(N-1,x-1)
    elif x==A[N-1]+2:
        return T(N-1,A[N-1])+1
    elif A[N-1]+3<=x<=2*A[N-1]+2:
        return T(N-1,A[N-1])+1+T(N-1,x-(A[N-1]+2))
    else:
        return 2*T(N-1,A[N-1])+1

N,X=map(int,input().split())
print(T(N,X))

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

int main()
{
  fastio;
  int n; cin >> n; 
  n %= 1000; cout << (1000 - n) % 1000;
  return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define mt make_tuple

ll a[101010], b[101010], c[101010], ans=0;
int n;

int main(){
cin >> n;
rep(i, 0, n-1)cin >> a[i];
rep(i, 0, n-1)cin >> b[i];
rep(i, 0, n-1)cin >> c[i];
sort(a, a+n);
sort(b, b+n);
sort(c,c+n);

rep(i, 0, n-1){
int l = lower_bound(a, a+n, b[i])-a;
int r = upper_bound(c, c+n, b[i])-c;
ans+=1LL*l*(n-r);
}
cout << ans << endl;
return 0;}


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

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int h[2], m[2], s[2];

int main() {
    while (cin >> h[0] >> m[0] >> s[0] >> h[1] >> m[1] >> s[1]) {
        int A = h[0] * 3600 + m[0] * 60 + s[0];
        int B = h[1] * 3600 + m[1] * 60 + s[1];
        int be = B - A;
        
        int rh = be / 3600;
        int rm = (be % 3600) / 60;
        int rs = be % 60;
        cout << rh << " " << rm << " " << rs << endl;
    }
    return 0;
}


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

signed main() {
  int N;
  cin >> N;
  
  vector<string> S(N);
  int Acount = 0;
  int Bcount = 0;
  int ABcount = 0;
  int BAcount = 0; //先頭がB,末尾がA
  for( int i = 0; i < N; i++ ){
    cin >> S.at(i);
    if( S.at(i).at(0) == 'B' ) Bcount++;
    if( S.at(i).back() == 'A' ) Acount++;
    if( S.at(i).at(0) == 'B' && S.at(i).back() == 'A' ) BAcount++;
    for( int j = 1; j < S.at(i).size(); j++ ){
      if( S.at(i).at(j-1) == 'A' && S.at(i).at(j) == 'B' ) ABcount++;
    }
  }
  
  if( BAcount == 0 ){
    cout << ABcount + min( Acount, Bcount ) << endl;
    return 0;
  }else{
    if( (Acount-BAcount) + (Bcount-BAcount) > 0 ){
      cout << ABcount + min( Acount, Bcount ) << endl;
    }else{
      cout << ABcount + BAcount - 1 << endl;
    }
  }
}




Measured memory_bytes: 896