akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, x;
    cin >> N >> x;

    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    ll ans = 0;
    REP(i, N - 1) {
        ll s = a[i] + a[i+1];
        if (s > x) {
            ans += s - x;
            a[i+1] = max(0LL, a[i+1] - s + x);
        }
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 1024
# writer解(c++)を写経した．answerのfor文のところ何やってるかさっぱりわかりませんが…
# https://atcoder.jp/contests/m-solutions2020/submissions/15122924
import sys
input = sys.stdin.readline
INF = 10**13


def main():
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    X_dist = [[0]*N for _ in range(1 << N)]
    Y_dist = [[0]*N for _ in range(1 << N)]

    # bitという道路群を建設したときの，各集落の評価距離
    # bit 001001 とかの1が立っている集落に道を作る
    for bit in range(1 << N):
        cur_x = [0]
        cur_y = [0]
        for i in range(N):
            if bit & (1 << i):
                cur_x.append(T[i][0])
                cur_y.append(T[i][1])
        for i in range(N):
            X_dist[bit][i] = T[i][2]*min(abs(cx - T[i][0]) for cx in cur_x)
            Y_dist[bit][i] = T[i][2]*min(abs(cy - T[i][1]) for cy in cur_y)

    # これはなに？
    answer = [INF] * (N+1)
    for i in range(1 << N):
        cnt = 0
        for j in range(N):
            if (i >> j) & 1:
                cnt += 1
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(N):
                if not((i >> k) & 1):
                    cost += min(X_dist[j][k], Y_dist[i - j][k])
            answer[cnt] = min(answer[cnt], cost)
            j -= 1

    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88580
#include <iostream>
#include <numeric>
#include <queue>
#include <cstring>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
const int inf=1000000005;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
int dp[105][10005];
string s1,s2;
int n,W;
int v[105],w[105];
int main(int argc,char const* argv[])
{
  cin >> n >> W;
  for(int i=0;i<n;i++)
    {
      cin >> v[i] >> w[i];
    }
  dp[0][0]=0;
  int ans=0;
  for(int i=1;i<=10000;i++)
    {
      dp[0][i]=inf;
    }
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<=10000;j++)
	{
	  if(j<v[i])
	    {
	      dp[i+1][j]=dp[i][j];
	    }
	  else
	    {
	      dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
	    }
	}
    }
  for(int i=0;i<=10000;i++)
    {
      if(dp[n][i]<=W)
	{
	  ans=i;
	}
    }
  cout << ans << endl;
  return 0;
}



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

int F[100][11], P[100][11];

int main()
{
    int n; cin>>n;
#define REP(i, a, b) for(int i=(a); i<(b); ++i)
    REP(i, 0, n) REP(j, 0, 10) cin>>F[i][j];
    REP(i, 0, n) REP(j, 0, 11) cin>>P[i][j];

    int res=INT_MIN;
    REP(i, 0, 1<<10) {
        bool ok=false;
        vector<int> period(n);
        REP(j, 0, 10) if ((i>>j)&1) {
            REP(k, 0, n) if (F[k][j]) {
                ok=true;
                period[k]++;
            }
        }
        if (!ok) continue;
        int profit=0;
        REP(k, 0, n) profit+=P[k][period[k]];
        res=max(res, profit);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,k,sum=0;
 cin>>n>>k;
 int p[n+2];
 for(int i=0;i<n;i++)
 {
     cin>>p[i];
 }
 sort(p,p+n);
 sum=0;
 for(int i=0;i<k;i++)
 {
    sum+=p[i];
 }
 cout<<sum<<endl;
}


Measured memory_bytes: 3520
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;

void solve() {
	double a; cin >> a;
	double b; cin >> b;
	cout << ceil((a + b) / 2) << endl;
	return;
}

int main() {
	solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){
        swap(a,b);
    }
    if(b>c){
        swap(b,c);
    }
    if(a>b){
        swap(a,b);
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int dx = x2 - x1;
    int dy = y2 - y1;
    
    printf("%d %d %d %d\n", x2 - dy, y2 + dx, x1 - dy, y1 + dx);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <list>
#include <algorithm>
using namespace std;

int
main (
  int   argc,
  char *argv[ ]
  )
{
  list<int>::iterator it;
  int i;

  for ( ; ; )
  {
    list<int> lis;
    int c;
    int n;

    scanf ( "%d", &n );
    if ( n == 0 ) break ;
    for ( i = 0; i < n; ++i )
    {
      int d;

      scanf ( "%d", &d );
      lis.push_back ( d );
    }

    for ( c = 0; c <= 10000; ++c )
    {
      for ( i = 1, it = lis.begin ( ); it != lis.end ( ); ++i, ++it )
        if ( *it != i ) break ;
      if ( it == lis.end ( ) ) break ;

      lis.push_back ( lis.size ( ) + 1 );
      for ( it = lis.begin ( ); it != lis.end (); ++it )
        --( *it );
      lis.remove ( 0 );
    }
    printf ( "%d\n", c <= 10000 ? c : -1 );
  }

  return ( EXIT_SUCCESS );
}

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

#define FOR(n) for(int i=0;i<n;i++)
#define ll long long

using namespace std;
int main()
{ int a;int k;int f=0;
 cin>>a;
 for(int i=a;;i++)
 {k=i;
   for(int j=2;j<=i/2;j++)
 {if(i%j==0)
    f=1;
 }
 if(f==1)
 {f=0;continue;}
  else
  {cout<<i;break;}
 
 }





return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  7 01:24:25 2020

@author: saito
"""

# %% import phase

# %% define phase

# %% input phase
x = int(input())

# %% process phase

# %%output phase
if x >= 30:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9100
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i := range S {
    S[i] = strconv.Itoa(A[i])
  }
  fmt.Fprintln(writer, strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func main() {
  N := NextInt()
  X := NextIntVec()
  A := make([]int, N * N + 1)
  B := make([]int, N * N + 1)
  ans := "Yes"
  for i, x := range X {
    if x < i + 1 {
      ans = "No"
      break
    }
    A[x] = i + 1
    B[x] = i + 1
  }
  C := make([]int, 0)
  for i := N * N; i > 0; i-- {
    if B[i] > 0 {
      for j := 0; j < B[i] - 1; j++ {
        C = append(C, B[i])
      }
    }
  }
  D := make([]int, 0)
  for i := 1; i < N * N + 1; i++ {
    if len(C) > 0 && C[len(C) - 1] == B[i] {
      ans = "No"
      break
    }
    if B[i] > 0 {
      for j := 0; j < N - B[i]; j++ {
        D = append(D, B[i])
      }
      continue
    }
    if len(C) == 0 { continue }
    A[i] = C[len(C) - 1]
    C = C[:len(C) - 1]
  }
  for i := N * N; i > 0; i-- {
    if len(D) == 0 { break }
    if D[len(D) - 1] == B[i] {
      ans = "No"
      break
    }
    if A[i] > 0 { continue }
    A[i] = D[len(D) - 1]
    D = D[:len(D) - 1]
  }
  Write(ans)
  if ans == "Yes" {
    WriteIntVec(A[1:])
  }
  Output()
}

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

class Node{
 public:
  Node* prev;
  Node* next;
  int data;
  Node(){prev = 0; next = 0; data = 0;}
};

class List{
 private:
  Node head;
 public:
  List(){head.prev = &head; head.next = &head;}
  int insert(int x){
   Node* p = new Node();
   if(p==0) return -1;
   Node* q = &head;
   Node* r = head.next;
   p->prev = q;
   p->next = r;
   p->data = x;
   q->next = p;
   r->prev = p;
   return 0;
  }
  int del(int x){
   Node* p;
   for(p=head.next; p!=&head; p=p->next){
    if(p->data==x) break;
   }
   if(p==&head) return -2;
   Node* q = p->prev;
   Node* r = p->next;
   q->next = r;
   r->prev = q;
   delete p;
   return 0;
  }
  int deleteFirst(){
   Node* p = head.next;
   if(p==&head) return -2;
   Node* q = p->prev;
   Node* r = p->next;
   q->next = r;
   r->prev = q;
   delete p;
   return 0;
  }
  int deleteLast(){
   Node* p = head.prev;
   if(p==&head) return -2;
   Node* q = p->prev;
   Node* r = p->next;
   q->next = r; 
   r->prev = q;
   delete p;
   return 0;
  }
  void print(){
   for(Node* p=head.next; p!=&head; p=p->next){
    cout << p->data;
    if(p->next!=&head){
     cout << ' ';
    }else{
     cout << endl;
    }
   } 
  }
};

int main(){
 List L;
 int n;
 cin >> n;
 for(int i=0; i<n; i++){
  char com[20];
  cin >> com;
  if(com[0]=='i'){
   int x;
   cin >> x;
   L.insert(x);
  }else if(com[6]=='F'){
   L.deleteFirst();
  }else if(com[6]=='L'){
   L.deleteLast();
  }else{
   int x;
   cin >> x;
   L.del(x);
  }
 }
 L.print();
 return 0;
}

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

int main(){
    long long A,B,c,a,b;
    cin>>A>>B;
    a=A;b=B;
    if(A<B){
        c=A;
        A=B;
        B=c;
    }
    c=A%B;
    while(c!=0){
        A=B;
        B=c;
        c=A%B;
    }
    cout<<a*b/B<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = [0] + list(map(int, input().split())) + [0]
    d = 0
    for a0, a1 in zip(aa, aa[1:]):
        d += abs(a0 - a1)
    for i in range(1, 1 + n):
        print(d - abs(aa[i - 1] - aa[i]) - abs(aa[i + 1] - aa[i]) + abs(aa[i - 1] - aa[i + 1]))

main()


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

signed main(void)
{
	int n;
	set<int> a;

	cin >> n;
	for(int i = 0; i < n; i++)
	{
		int b;
		cin >> b ;

		if (a.count(b))
		{
			cout << "NO" << endl;
			return 0;
		}
		a.insert(b);
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 9600
(* O(1) *)
let f1 n = if n mod 2 = 0 then 0 else 1

(* O(1) *)
let solve a b =
  let first, d1 = if a mod 2 = 0 then 0, 0 else a, 1 in
  let last, d2 = if b mod 2 = 0 then b, 1 else 0, 0 in
  first lxor last lxor f1 ((b - a + 1 - d1 - d2) / 2)

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  match read_ints () with
  | [a; b] -> solve a b |> string_of_int |> print_endline
  | _ -> ()

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    
    string s,t;
    cin>>s>>t;
    vi Scsum(1,0),Tcsum(1,0);
    rep(i,s.size()){
        if(s[i]=='A')Scsum.pb(*Scsum.rbegin()+1);
        else Scsum.pb(*Scsum.rbegin()+2);
    }
    rep(i,t.size()){
        if(t[i]=='A')Tcsum.pb(*Tcsum.rbegin()+1);
        else Tcsum.pb(*Tcsum.rbegin()+2);
    }
    int q;
    cin>>q;
    rep(i,q){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int sA=Scsum[b]-Scsum[a-1];
        int tA=Tcsum[d]-Tcsum[c-1];
        YN(sA%3==tA%3);
    }

}



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

#define ll long long int
#define pi 3.141592653589793238
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007

    ll mod_pow(ll a,ll b,ll m)
    {
        ll res=1;
        while(b)
        {
            if(b&1)
                res=(res*a)%m;

            a=(a*a)%m;
            b>>=1;
        }
        return res;
    }

void solve()
{
    ll n;
    cin>>n;
    vector<bool> vis(n,false);
    if(n<=2)
    {
        cout<<n-1;
        return;
    }
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
       
        for(ll j=1;i*j<n;j++)
        {
            // cout<<i<<" "<<j<<endl;
                ans++;
        }
    }
    cout<<ans;
    return;
}

int main()
{
    FAST;
    #ifndef ONLINE_JUDGE
        freopen("input1.txt","r",stdin);
        freopen("output1.txt","w",stdout);
    #endif
    ll q;
    q=1;
    // cin>>q;
    while(q--)
        solve();
    return 0;
}


Measured memory_bytes: 3740
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);String r;for(int n,a,b,c;(n=s.nextInt())>0;System.out.println(r+a+(a<c?"-"+c:"")))for(r="",a=c=s.nextInt();n-->1;){b=s.nextInt();if(b-c>1){r+=a+(a<c?"-"+c:"")+" ";a=b;}c=b;}}}

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

const int MOD = (int)1e9+7;

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

  if(C-1<=A+B)  cout << B+C << endl;
  else  cout << B*2+1+A << endl;
  
  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    int alice, bob;
    alice = 0;
    bob = 0;
    for (int i = N; i > 1;)
    {
        alice += a.at(i - 1);
        bob += a.at(i - 2);
        i -= 2;
    }
    if (N % 2 == 1)
    {
        alice += a.at(0);
    }
    cout << alice - bob << endl;
}


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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long c;
    if (n % (a + b) >= a) {
        c = a;
    } else {
        c = n % (a + b);
    }
    cout << n / (a + b) * a + c << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
n, d, a = map(int, input().split())
fox = [None]*n
for i in range(n):
  x, h = map(int, input().split())
  fox[i] = (x, h)

fox.sort()
x = [int(fox[i][0]) for i in range(n)]
h = [int(fox[i][1]) for i in range(n)]

ans = 0
bit = [0]*n
for i in range(n):
  if i != 0:
    bit[i] += bit[i-1]
  if bit[i] >= h[i]:
    continue
  sub = (h[i]-bit[i]-1)//a+1
  ans += sub
  bit[i] += sub*a
  index = bisect.bisect_right(x, x[i]+2*d)
  if index == n:
    continue
  bit[index] -= sub*a
print(ans)

Measured memory_bytes: 41748
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		String total = scanner.nextLine();
		if (total.contains("A") && total.contains("B")) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}	
	
	

}

Measured memory_bytes: 25684
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	ll N;
	ll num;
	ll time=0;
	ll i,j;
	//pair<ll,ll> H[50];
	ll H[50];
	cin>>N;
	for(ll i=0;i<N;i++){
		cin>>H[i];//=make_pair(num,i);
	}
	num=0;
	for(i=0;i<N;i++){
		for(j=0;j<i;j++){
			if(H[i]>=H[j]) num++;
		}
		if(num==i) time++;
		num=0;
	}
	cout<<time<<endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<double> x(N);
    vector<double> y(N);
    for (int i = 0; i < N; i++) {
        cin >> x.at(i);
        cin >> y.at(i);
    }

    double sum_l = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            sum_l += sqrt((x.at(i) - x.at(j)) * (x.at(i) - x.at(j)) + (y.at(i) - y.at(j)) * (y.at(i) - y.at(j)));
        }
    }
    sum_l *= 2;
    sum_l /= N;
    printf("%.10f\n", sum_l);
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

const n = 7

var (
	seq = []int{}
	flg bool
)

func dfs(left, i int, str string) {
	if i == len(seq) {
		if left == 0 && !flg {
			fmt.Printf("%s=%d\n", str, n)
			flg = true
		}
		return
	}
	for j := range make([]struct{}, 2) {
		if j == 1 || i != 0 {
			tmp := ""
			if i != 0 {
				tmp = []string{"-", "+"}[j]
			}
			tmp += string(seq[i] + '0')
			dfs(left-seq[i]*[]int{-1, 1}[j], i+1, str+tmp)
		}
	}
}

func main() {
	var abcd string
	fmt.Scan(&abcd)

	for _, c := range abcd {
		seq = append(seq, int(c)-'0')
	}
	dfs(n, 0, "")
}


Measured memory_bytes: 512
n = int(input())

l1 = []
l2 = []

for i in range(n):
    x1,y1 = map(int,input().split())
    l1.append(x1-y1)
    l2.append(x1+y1)

l1 = sorted(l1)
l2 = sorted(l2)
a = l1[-1]
b = l1[0]
c = l2[-1]
d = l2[0]
ans = max(a-b, c-d)
print(ans)


Measured memory_bytes: 27060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(void){
  int x,y;
  cin >> x >> y;
  int res = x == 1 && y == 1 ? 400000 : 0;
  res += max(0, 400000 - 100000 * x);
  res += max(0, 400000 - 100000 * y);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    int ct=0;
    for(int i=0;i<s.size();i++)if(s[i]==t[i])ct++;
    if(ct==s.size())cout<<"Yes\n";
    else cout<<"No\n";
    
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll n, m, q;
ll ans = 0;
vll a, b, c, d;
 
void dfs(vll A) {//再起全探索
    if (A.size() == n+1) {//(ai, bi, ci, di)の組で与えられるAの添え字は1オリジン
        ll now = 0;
        REP(i,q) {
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }
    A.push_back(A.back());//一番後ろに最後尾と同じ値をつける
    while (A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}


int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    a = b = c = d = vll(q);
    REP(i,q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vll(1,1));//使わない0番目を埋めて、+1番目は1で考えて十分
    cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define lP pair<ll,ll>
#define iP pair<int,int>

typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;


ll H, W, S, T, b, w;
int main(){
	cin >> H >> W >> S >> T;
	if (H % 2 == 1 && W % 2 == 1) {
		if (S % 2 == T % 2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (H == 1) {
			if (T == 1 || T == W) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (W == 1) {
			if (S == 1 || S == H) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			cout << "Yes" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
/********************************************************/


int main() {
    int n; cin >> n;
    ll ans = 0;
    repf(i,1,n+1) {
        ans += (ll)(i+n/i*i)*(n/i)/2;
        // cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	rep(i,0,b){
		rep(i,0,a) cout<<0;
		rep(i,a,m) cout<<1;
		cout<<endl;
	}  
	rep(i,b,n){
		rep(i,0,a) cout<<1;
		rep(i,a,m) cout<<0;
		cout<<endl;
	}
}

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

Measured memory_bytes: 1280
def main():
  n = int(input())
  MOD = int(1e9 + 7)
  dp = [0 for _ in range(n + 1)]
  dp[0] = 1
  for i in range(3 , n+1):
    dp[i] = 1
    for j in range(3,i - 2):
      if i - j < 3:
        break
      dp[i] = (dp[i] + dp[i - j])%MOD
  print(dp[n])
  

if __name__ == "__main__":
  main()

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a==1){
    a=14;
  }
  if(b==1){
    b=14;
  }
  if(a<b){
    cout << "Bob" << endl;
  }
  else if(a>b){
    cout << "Alice" << endl;
  }
  else{
    cout << "Draw" << endl;
  }
}

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

#define MEM(a, b) memset(a, b, sizeof a);
#define REP(i, k) for(int i = (0); i < (k); i++ )

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define debug puts("FANGO")
#define INF (int)INT_MAX
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007
#define endl "\n"

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef long long int32;
typedef unsigned long long uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

template <class T>
T sqr(T val) {
  return val * val;
}

void solve(__attribute__((unused)) int tc = 0) {
  int a, b, t;
  cin >> a >> b >> t;
  cout << (t / a) * b << endl;
  return;
}

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  /*int TC;
  cin >> TC;
  REP(tc, TC) {
    solve(tc);
  }*/
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s < t)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define mx 1000007
using namespace std;

ll F[mx], inv[mx];

ll Pow( ll x, ll y )
{
    ll res= 1;

    while(y>0)
    {
        if(y&1)
            res= (res*x)%mod;
        x= (x*x)%mod;
        y>>= 1;
    }

    return res;
}

void init()
{
    F[0]= F[1]= inv[0]= inv[1]= 1;

    for( ll i=2;i<mx;i++ )
        F[i]= ( F[i-1]*i )%mod,
        inv[i]= Pow( F[i], mod-2 );
}

int main()
{
    init();

    ll n;
    cin>>n;

    if(n<2)
        return cout<<"0\n", 0;
    
    ll zt= Pow( 9,n );
    ll nt= Pow( 9,n );
    ll kt= Pow( 8,n );
    ll tot= Pow( 10,n );
    ll baad= ( zt+nt-kt+mod )%mod;
    ll ans= ( tot-baad+mod )%mod;

    cout<< ans <<"\n";
}

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

#define MAX_HEAP_LENGTH 100

void swap(int array[], int i, int j) {
    int temp = array[i];
    array[i] = array[j];
    array[j] = temp;
}

typedef struct {
    int * array;
    int heap_size;
    int length;
} Heap;

Heap createHeap(int length) {
    Heap heap;
    
    heap.array = (int *)malloc((length+1) * sizeof(int));
    heap.array[0] = 0; // NOT USED
    heap.heap_size = heap.length = length;
    
    return heap;
}

int parentOfIndex(int index) {
    return index/2;
}
int leftOfIndex(int index) {
    return 2*index;
}
int rightOfIndex(int index) {
    return 2*index+1;
}

void maxHeapify(Heap heap, int iThis) {
    int iLeft = leftOfIndex(iThis);
    int iRight = rightOfIndex(iThis);
    int iLargest;
    
//    printf("HeapMaxify: L:%d,R:%d,This:%d\n", 
//            heap.array[iLeft],
//            heap.array[iRight],
//            heap.array[iThis]
//            );
    
    if (iLeft <= heap.heap_size && heap.array[iLeft] > heap.array[iThis]) 
        iLargest = iLeft;
    else
        iLargest = iThis;
    
    if (iRight <= heap.heap_size && heap.array[iRight] > heap.array[iLargest]) 
        iLargest = iRight;
    
    if (iLargest != iThis) {
        swap(heap.array, iThis, iLargest);
        // iLargest is no longer the index for largest value within the trinode.
        maxHeapify(heap, iLargest);
    }
}
void buildMaxHeap(Heap heap) {
    heap.heap_size = heap.length;
    
    for (int i = heap.length/2; i >= 1; i--)
        maxHeapify(heap, i);
}
void heapSort(Heap heap) {
    buildMaxHeap(heap);
    
    for (int i = heap.length; i >= 2; i--) {
        swap(heap.array, 1, i);
        heap.heap_size--;
        maxHeapify(heap, 1);
    }
}


int main(int argc, char** argv) {
    int nNode;
    scanf("%d", &nNode);
    
    Heap heap = createHeap(nNode);
    // 1-origin
    
    for (int i = 1; i <= nNode; i++)
        scanf("%d", &(heap.array[i]));
    
    buildMaxHeap(heap);
    
    for (int i = 1; i <= heap.length; i++) 
        printf(" %d", heap.array[i]);
    
    printf("\n");
    
//    for (int i = 1; i <= nNode; i++) {
//        printf("node %d: ", i);
//        printf("key = %d, ", heap.array[i]);
//        
//        if (i/2 > 0)
//            printf("parent key = %d, ", heap.array[i/2]);
//        
//        if (2*i <= heap.length)
//            printf("left key = %d, ", heap.array[2*i]);
//        
//        if (2*i+1 <= heap.length)
//            printf("right key = %d, ", heap.array[2*i+1]);
//        
//        printf("\n");
//    }

    return (EXIT_SUCCESS);
}




Measured memory_bytes: 3680
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    ll ans = 1;
    ll ng = 1000000000000000000;
    vl a(N);
    rep(i, N){
        cin >> a[i];
    }
    sort(all(a));
    rep(i, N){
        if(a[i] == 0){
            cout << 0;
            return 0;
        }
        ll c = ng % a[i];
        ll d = ng - c;
        ll e = d / a[i];
        if(e < ans){
            cout << -1;
            return 0;
        }
        ll tmp = ans * a[i];
        if(tmp > ng){
            cout << -1;
            return 0;
        }
        ans = tmp;
    }
    cout << ans;
}

Measured memory_bytes: 4108
#include<iostream>
#include<math.h>
using namespace std;

const int MAX = 81;
bool dp[MAX][MAX][(MAX+MAX) * MAX];
int A[MAX][MAX], B[MAX][MAX];

int main(){
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> B[i][j];
        }
    }
    dp[0][0][abs(A[0][0] - B[0][0])] = true;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            for (int k = 0; k < MAX * MAX; k++)
            {
                if (dp[i][j][k])
                {
                    dp[i+1][j][k+abs(A[i+1][j] - B[i+1][j])] = true;
                    dp[i+1][j][abs(k-abs(A[i+1][j] - B[i+1][j]))] = true;
                    dp[i][j+1][k+abs(A[i][j+1] - B[i][j+1])] = true;
                    dp[i][j+1][abs(k-abs(A[i][j+1] - B[i][j+1]))] = true;
                }
                
            }
            
        }
        
    }
    for (int k = 0; k < (MAX+MAX)*MAX; k++)
    {
        if (dp[h-1][w-1][k])
        {
            cout << k << endl;
            break;
        }
        
    }
    
    
}

Measured memory_bytes: 83456
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<String> arare = new HashSet<>();
		for (int i = 0; i < N; i++) {
			arare.add(sc.next());
		}
		System.out.println(arare.size() == 3 ? "Three" : "Four");

	}
}


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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m+1), b(m+1);
	for (int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= n; i++) {
		int sum = 0;
		for (int j = 1; j <= m; j++) {
			if (i == a[j] || i == b[j])sum++;
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class Comb:
    def __init__(self, n, mod=pow(10, 9)+7, f=True, i=False, version=False):
        self.n = n
        self.mod = mod
        self.mod_inv = mod-2 if version else -1
        self.factorial_table = None
        self.inverse_table = None
        if f: self.get_factorial()
        if i: self.get_inverse()
        
    def get_factorial(self):
        self.factorial_table = [1]*(self.n+1)
        for i in range(1, self.n+1):
            self.factorial_table[i] = self.factorial_table[i-1]*i%self.mod
        self.inverse_table = None
    
    def get_inverse(self):
        mod = self.mod
        mod_inv = self.mod_inv
        self.inverse_table = [1]*(self.n+1)
        for i in range(self.n+1):
            self.inverse_table[i] = pow(self.factorial_table[i], mod_inv, mod)
    
    def factorial(self, n):
        if self.factorial_table == None:
            return None
        return self.factorial_table[n]
    
    def inverse(self, n):
        if self.inverse_table == None:
            return None
        return self.inverse_table[n]   
    
    def permutation(self, n, k):
        if self.factorial_table == None:
            return None
        mod = self.mod
        mod_inv = self.mod_inv
        if self.inverse_table == None:
            return self.factorial_table[n]*pow(self.factorial_table[n-k], mod_inv, mod)%mod
        return self.factorial_table[n]*self.inverse_table[n-k]%mod
            
    def comb(self, n, k):
        if self.factorial_table == None:
            return None
        mod = self.mod
        mod_inv = self.mod_inv
        if self.inverse_table == None:
            res = self.factorial_table[n]*pow(self.factorial_table[n-k], mod_inv, mod)%mod\
                                    *pow(self.factorial_table[k], mod_inv, mod)%mod
        else:
            res = self.factorial_table[n]*self.inverse_table[n-k]%mod\
                                    *self.inverse_table[k]%mod
        return res
    
    def recomb(self, n, k):
        if n+k-1 > self.n:
            return None
        return self.comb(n+k-1, k)


def main():
    r1, c1, r2, c2 = map(int, input().split())
    comb = Comb(10**6*2+1, version=True)
    mod = pow(10, 9) + 7

    ans = 0
    comb1, comb2 = comb.comb(c1+r2+1, r2+1), comb.comb(c1+r1, r1)
    for key in range(c1, c2+1):
        sub = (((r2+1) * comb1 - r1 * comb2) * pow(key+1, mod-2, mod)) % mod
        ans = (ans + sub) % mod

        comb1 = comb1 * (key + r2 + 2) * pow(key+1, mod-2, mod) % mod
        comb2 = comb2 * (key + r1 + 1) * pow(key+1, mod-2, mod) % mod


    print(ans)


    
if __name__ == "__main__":
    main()




Measured memory_bytes: 89188
#include <bits/stdc++.h>
using namespace std;
int main(){
  map<string,int>a;
  string s,p,q;
  int k=0;
  while(cin>>s){
    a[s]++;
    if(p.size()<s.size())p=s;
    if(k<a[s]){
      k=a[s];
      q=s;
    }
  }
  cout<<q<<' '<<p<<endl;
}

Measured memory_bytes: 3168
//#include <bits/stdc++.h>
#include <iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector<long long>
#define  ii pair<int,int>
const long long mod = 1000000007LL, inf = 1e9, linf = 1e18, base = 10;
using namespace std;
#define pb push_back
#define mp make_pair
#define N 1002
using namespace std;


int main()
{
	string s;
	cin >> s;
	int d = 0;
	for (int i = 0; i < s.size(); i++)if (s[i] == 'o')d++;
	d += 15 - (int)s.size();
	if (d >= 8)cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

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

int w,h;
char in[100][100];

bool e[1000][1000];
int mnx[1000],mxx[1000];
int id[100][100];
int npc,sz[1000];
double xsum[1000];

void nul(int y,int x,int num,char bl)
{
	xsum[num]+=x+0.5;
	sz[num]++;
	
	rep(d,4)
	{
		int ny=y+dy[d],nx=x+dx[d];
		if(ny<0&&nx<0||ny>=h||nx>=w||in[ny][nx]!=bl)continue;
		if(id[ny][nx]>=0)continue;
		id[ny][nx]=num; nul(ny,nx,num,bl);
	}
}
void getsize(int num)
{
	rep(i,npc)if(e[num][i])
	{
		getsize(i);
		sz[num]+=sz[i];
		xsum[num]+=xsum[i];
	}
}

bool stable(int num)
{
	rep(i,npc)if(e[num][i])
	if(!stable(i))return 0;
	if(xsum[num]/sz[num]<=mnx[num]||mxx[num]<=xsum[num]/sz[num])return 0;
	
	return 1;
}

int main()
{
	while(cin>>w>>h,w){
		rep(i,h)cin>>in[i];
		
		npc=0;
		rep(i,h)rep(j,w)id[i][j]=-1;
		
		rep(i,h)rep(j,w)if(id[i][j]<0&&in[i][j]!='.')
		{
			id[i][j]=npc;
			sz[npc]=xsum[npc]=0;
			nul(i,j,npc,in[i][j]); npc++;
		}
		
		rep(i,npc)
		{
			rep(j,npc)e[i][j]=0;
			mnx[i]=inf,mxx[i]=-inf;
		}
		rep(i,h-1)rep(j,w)if(id[i+1][j]!=id[i][j])
		{
			int d=id[i+1][j],u=id[i][j];
			if(d<0||u<0)continue;
			
			e[d][u]=1;
			mnx[u]=min(mnx[u],j);
			mxx[u]=max(mxx[u],j+1);
		}
		rep(i,w)if(id[h-1][i]>=0)
		{
			int d=id[h-1][i];
			mnx[d]=min(mnx[d],i);
			mxx[d]=max(mxx[d],i+1);
		}
		
		int root=0;
		for(;root<npc;root++)
		{
			rep(i,npc)if(e[i][root])goto NEXT;
			break; NEXT:;
		}
		getsize(root);
		cout<<(stable(root)?"STABLE":"UNSTABLE")<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys

count = 0
N_list = []
M_list = []
for line in sys.stdin:
    line = line.rstrip("\n")
    if count == 0:
        line = line.split(" ")
        N = int(line[0])
        M = int(line[1])
    elif count <= N:
        N_list.append(line)
    else:
        M_list.append(line)
    count+=1
    
    
def judge_match(N_l, M_l):
    slide_count = len(N_l[0]) - len(M_l[0]) + 1
    count = 0
    for j in range(slide_count):
        count = 0
        for i in range(len(N_l)):
            if N_l[i][j:j+len(M_l[0])] == M_l[i]:
                count += 1
                if count == len(M_l):
                    return count
    return count

m_count = 0
for i in range(len(N_list)):
    m_count = judge_match(N_list[i:i+len(M_list)], M_list)
    if m_count == len(M_list):
        print("Yes")
        exit(0)
print("No")

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

using namespace std;

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

#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, a, b;

int main () {
    scanf("%d", &n);
    scanf("%d%d", &a, &b);

    int cnt0 = 0, cnt1 = 0, cnt2 = 0;
    fto(i, 1, n) {
        int x; scanf("%d", &x);
        if (x <= a) ++cnt0;
        else if (x <= b) ++cnt1;
        else ++cnt2;
    }

    printf("%d", min(cnt0, cnt1, cnt2));

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long ans = (long)N*(N+1)*(N+2)/6;
		for (int i=0;i<N-1;i++) {
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			if (u>v) {
				int tmp = u;
				u = v;
				v = tmp;
			}
			ans -= (long)(u+1)*(N-v);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 59496
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long modPow(long x, long k, long m) {
    if (k == 0) return 1;
    if (k % 2 == 0) return modPow(x * x % m, k / 2, m);
    return x * modPow(x, k - 1, m) % m;
}

const MOD = 10^^9 + 7;

long calc(string s) {
    long ans = 0;
    int one = 0; // 1 の個数
    for (int i = 0; i < s.length; i++) {
        if (s[i] == '1') {
            // s[i] = 0 とする
            // 範囲 [0, i) の各桁の 1 の組み合わせは (0, 1), (1, 0) の 2 通り
            // 範囲 [i + 1, $) の各桁の組み合わせは (0, 0), (0, 1), (1, 0) の 3 通り
            long a = modPow(2, one, MOD);
            long b = modPow(3, cast(int)s.length - i - 1, MOD);
            ans = (ans + (a * b)) % MOD;
            one++;
        }
    }

    // 上の for ループで i 番目を 0 にしたが、どの桁の 1 も 0 にしない場合
    ans = (ans + modPow(2, one, MOD)) % MOD;
    return ans;
}

// 桁 DP による解法
long calc2(string s) {
    void madd(T)(ref T a, in T b) { a = (a + b) % MOD; }

    int n = cast(int)s.length;
    auto dp = new long[][](100010, 2); // dp[見た桁数][L 以下か]
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            // L を維持: 選択肢は (0, 0) のみ
            madd(dp[i + 1][0], dp[i][0]);
            // L 未満: 選択肢は (0, 0), (1, 0), (0, 1) の 3 通り
            madd(dp[i + 1][1], dp[i][1] * 3);
        }
        else {
            // L を維持: 選択肢は (1, 0), (0, 1) の 2 通り
            madd(dp[i + 1][0], dp[i][0] * 2);
            // i 桁目を 0 にして L 未満へ遷移
            madd(dp[i + 1][1], dp[i][0]);
            // L 未満: 選択肢は (0, 0), (1, 0), (0, 1) の 3 通り
            madd(dp[i + 1][1], dp[i][1] * 3);
        }
    }

    return (dp[n][0] + dp[n][1]) % MOD;
}

void main() {
    string s = read!string;
    writeln(calc2(s));
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

#define muf(x) ((x)*(x)*(x)*(x)*(x))

signed main() {
#ifdef _DEBUG
  // freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int x; cin >> x;
  for (int a = -120; a <= 120; a++)
  for (int b = -120; b <= 120; b++) {
    if (muf(a) - muf(b) == x) {
      cout << fixed << setprecision(0);
      cout << a << ' ' << b << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    long long int n,x,m,ans=0,f=0,b=0,c=0,d=0,t=0;
    cin>>n>>x>>m;
    t=x;
    vector<long long int>a(1000000);
    for(long long int i=0;i<m;i++){
        if(a[x]==0){
            a[x]++;
            x=(x*x)%m;
        }
        else{
            d=i;
            break;
        }
        
    }
    for(long long int i=0;i<m;i++){
        if(t==x&&f==0){
            c=i;
            f=1;
            b+=t;
            t=(t*t)%m;
        }
        else if(f==0){
            ans+=t;
            t=(t*t)%m;
        }
        else if(f==1&&t==x){
            break;
        }
        else{
            b+=t;
            t=(t*t)%m;
        }
    }
    if(a[0]==0){
        ans+=((n-c)/(d-c))*b;
        for(long long int i=0; i<(n-c)%(d-c);i++ ){
            ans+=t;
            t=(t*t)%m;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

long long dp[100][100000];

long long max(long long a, long long b) {
	return a > b ? a : b;
}

long long ans(int index, long long value[], long long weight[], int n, int w) {

	// cout << "index " << index << " weight " << w << endl;

	if (index >= n || w == 0) {
		return 0;
	}

	if (dp[index][w] != -1) {
		return dp[index][w];
	}

	if (weight[index] > w) {
		// cout << "1index " << index << " weight " << w << endl;
		dp[index][w] = ans(index + 1, value, weight, n, w);
		return dp[index][w];
	}

	dp[index][w] = max(ans(index + 1, value, weight, n, w), value[index] + ans(index + 1, value, weight, n, w - weight[index]));
	return dp[index][w];
}

int main()
{
	ios::sync_with_stdio(false);

	int n, w;

	cin >> n >> w;

	long long value[n];
	long long weight[n];

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

	memset(dp, -1, sizeof(dp));
	// cout << n << " " << w << endl;
	long long a = ans(0, value, weight, n, w);

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 78336
#include<iostream>
#include<cstring>
using namespace std;
const int N = 310;
char s[N][N];
int id[N][N];
int spe[N][N];
bool check(int i,int j,int k){
	return spe[k][j]-spe[i-1][j];
}
int g(int i,int j){
	if(id[i-1][j-1]==id[i-1][j] && id[i-1][j]==id[i][j-1]){
		return id[i-1][j];
	}
	if(id[i-1][j+1]==id[i][j+1] && id[i][j+1]==id[i-1][j]){
		return id[i][j+1];
	}
	if(id[i+1][j+1]==id[i][j+1] && id[i][j+1]==id[i+1][j]){
		return id[i][j+1];
	}
	if(id[i+1][j-1]==id[i+1][j] && id[i+1][j]==id[i][j-1]){
		return id[i+1][j];
	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(id,0,sizeof(id));
	memset(spe,0,sizeof(spe));
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>s[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			spe[i][j]=spe[i-1][j];
			if(s[i][j]=='#'){
				spe[i][j]++;
			}
		}
	}

	int cnt=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='#'){
				int l,r,u,d;
				for(u=i-1;u>=1 && s[u][j]!='#' && !id[u][j];u--) ;
				u++;
				
				for(d=i+1;d<=n && s[d][j]!='#' && !id[d][j];d++) ;
				d--;
								
				for(l=j-1;l>=1 && spe[n][l]==0 && !id[i][l];l--) ;
				l++;
								
				for(r=j+1;r<=m && spe[n][r]==0 && !id[i][r];r++) ;
				r--;
				
				for(int x=u;x<=d;x++){
					for(int y=l; y<=r;y++)
					id[x][y] = cnt;
				}
				cnt++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<id[i][j]<<' ';
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 1664