akhauriyash/Code-Regression huggingface dataset:
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        PriorityQueue<Integer> a = new PriorityQueue<>(n, Comparator.reverseOrder());
        for(int i=0; i<n; i++) {
            a.add(in.nextInt());
        }
        for(int i=0; i<m; i++) {
            int ai = a.poll();
            a.add((int)Math.floor(ai/2.0));
        }
        long s = 0;
        while(!a.isEmpty()) {
            s += a.poll();
        }
        System.out.println(s);
    }
}


Measured memory_bytes: 64832
#include <bits/stdc++.h>
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bn begin()
#define en end()
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007
#define pi 3.141592653589
#define INF 1000000000000
using namespace std;

int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie 
    string s, t; 
    cin >> s >> t ;
    int ans = 0 ;
    rep(i, 0, SZ(s)) {
        if(s[i] != t[i]) ans++ ;
    }
    cout << ans << "\n" ;
}

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

int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}


Measured memory_bytes: 3800
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine().toInt
    val strings = mutable.HashMap.empty[String, Int]

    for {
      _ <- 0 until n
    } {
      val s = in.readLine()
      strings(s) = if(strings.contains(s)) {
        strings(s) + 1
      } else {
        1
      }
    }

    val orderedStrings = strings.toSeq.sortWith {
      case ((_, count1), (_, count2)) => count1 > count2
    }

    val max = orderedStrings.head._2
    orderedStrings.collect {
      case (string, count) if count == max => string
    }.sorted.foreach(out.println)

    out.flush()
  }
}


Measured memory_bytes: 74812
from itertools import permutations
import sys
import os

def inini(_card):
    for i in range(len(_card)):
        _card[i] = 0


def main():
    for s in sys.stdin:
            card = 14*[0]
            inini(card)
            number = list(map(int,s.split(',')))
            for v in number:
                card[v] += 1
            one_pair = 0
            tree_card = 0
            four_card = 0
            for value in sorted(set(number),key=number.index):
                if card[value] == 2:
                    one_pair += 1
                elif card[value] == 3:
                    tree_card += 1
                elif card[value] == 4:
                    four_card += 1
            number.sort()
            if one_pair == 1 and tree_card ==1:
                print('full house')       
            elif one_pair == 1:
                print('one pair') 
            elif one_pair == 2:
                print('two pair')
            elif tree_card == 1:
                print('three card')   
            elif four_card == 1:
                print('four card')
            elif number[0] == number[1]-1 == number[2]-2 == number[3]-3 == number[4]-4:
                print('straight')
            elif number[0] == 1 and number[1] == 10 and number[2] == 11 and number[3] == 12 and number[4] == 13:
                print('straight')
            else:
                print('null')
                
            

       
if __name__ == '__main__':
    main()


Measured memory_bytes: 5640
ans = []
while 1:
    b = int(input())
    if b == 0:
        break
    x = 1
    res = (1, 1)
    while x*x <= b:
        if b % x == 0:
            y = b // x
            if x % 2 == 1:
                if y - x//2 >= 1:
                    res = max(res, (x, y - x//2))
                if x//2 - y + 1 >= 1:
                    res = max(res, (2*y, x//2 - y + 1))
            if y % 2 == 1:
                if x - y//2 >= 1:
                    res = max(res, (y, x - y//2))
                if y//2 - x + 1 >= 1:
                    res = max(res, (2*x, y//2 - x + 1))
        x += 1
    b, a = res
    ans.append("%d %d" % (a, b))
print(*ans, sep='\n')



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

const int MAXN = 312345;

long long v[MAXN];
long long s1[MAXN];
long long s2[MAXN];

int main () {

	int n;
	cin >> n;

	int m = 3 * n;

	memset (s1, -1, sizeof s1);
	memset (s2, -1, sizeof s2);

	priority_queue <long long> pq;
	long long sum = 0;
	for (int i = 0; i < m; ++i) {
		scanf ("%lld", v + i);
		pq.push (-v[i]);
		sum += v[i];

		if (pq.size() > n) {
			sum += pq.top();
			pq.pop();
		}

		if (pq.size() == n)
			s1[i] = sum;
	}

	while (!pq.empty()) pq.pop ();
	sum = 0;

	for (int i = m - 1; i >= 0; --i) {
		pq.push (v[i]);
		sum += v[i];

		if (pq.size() > n) {
			sum -= pq.top();
			pq.pop();
		}

		if (pq.size() == n)
			s2[i] = sum;
	}

	long long ans = -0x3F3F3F3F3F3F3F3F;
	for (int i = 0; i < m; ++i) {
		if (s1[i] != -1 && s2[i + 1] != -1)
			ans = max (ans, s1[i] - s2[i + 1]);
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;

int main() 
{
	ll A, B, K;
	cin >> A >> B >> K;
	if (K <= A) cout << A - K << " " << B;
	else if (K <= A + B) cout << 0 << " " << A+B-K;
	else cout << 0 << " " << 0;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include <string>
#include <cstring>
#include <cstdio>
#include<stack>
using namespace std;
int main()
{
    char s[100008]= {0};
    int i,j,n,t=0,x=0;
    scanf("%s",s);
    int l=strlen(s);
        for(i=0; i<l-1; i++)
        {
            if(s[i]!=s[i+1])t++;
        }
    printf("%d\n",t);
    return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cstring>
#include <functional>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define endl '\n'

using namespace std;

void push(vector<int> &seq, bool command)
{
    if (command)
    {
        if (!seq.empty() && seq.back())
            seq.pop_back();
        else
            seq.push_back(command);
    }
    else
    {
        seq.push_back(command);
    }
}

void rec(int start, int jump, int size, vector<int> sequence, vector<int> &res)
{
    if (jump == res.size())
    {
        return;
    }

    vector<vector<int>> new_seq(3);
    vector<int> digit = {0, 1, 2};

    for (auto command : sequence)
    {
        if (command)
        {
            for (int i = 0; i < 3; ++i)
            {
                push(new_seq[i], command);
                if (digit[i])
                    digit[i] = 3 - digit[i];
            }
        }
        else
        {
            for (int i = 0; i < 3; ++i)
            {
                digit[i]++;

                if (digit[i] == 3)
                {
                    digit[i] = 0;
                    push(new_seq[i], command);
                }
            }
        }
    }

    int finish = start + size * jump;
    int ix = 0;

    for (int i = start; i < finish; i += jump)
    {
        res[i] += digit[ix] * jump;
        if (++ix == 3)
            ix = 0;
    }

    for (int i = 0; i < 3; ++i)
    {
        rec(start + jump * i, jump * 3, size / 3, new_seq[i], res);
    }
}

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    vector<int> sequence;

    for (auto x : s)
        push(sequence, x == 'S');

    int size = 1;
    for (int i = 0; i < n; ++i)
    {
        size *= 3;
    }

    vector<int> res(size);

    rec(0, 1, size, sequence, res);

    for (auto x : res)
    {
        cout << x << " ";
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 9184
#include <stdio.h>
int Partition(int *,int,int);
int main()
{
  int A[100001];
  int i,n,key;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&A[i]);
      //printf("%d ",A[i]);
    }
  key=Partition(A,1,n);
  for(i=1;i<=n;i++)
    {
      if(i==key)printf("[%d] ",A[i]);
      else if(i==n)printf("%d\n",A[i]);
      else printf("%d ",A[i]);
    }
  return 0;
}

int Partition (int *A,int p,int r)
{
  int x,i,j,temp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j]<=x)
	{
	  i++;
	  temp=A[i];
	  A[i]=A[j];
	  A[j]=temp;
	}
    }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  return i+1;
}

Measured memory_bytes: 988
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <numeric>
#include <queue>
#include <stack>

using namespace std;
using ll = long long;

int main(){

	int X, t;
	int ans;

	cin >> X >> t;
	ans = X - t;
	if (ans < 0)ans = 0;
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int H,W;
	cin>>H>>W;
	rep(i,H) rep(j,W){
		string s;
		cin>>s;
		if(s=="snuke"){
			cout<<(char)('A'+j)<<i+1<<endl;
			return 0;
		}
	}
}


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

void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
do {\
std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
debug_impl(__VA_ARGS__);\
std::cerr << std::noboolalpha;\
} while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}


bool check(vector<ll>& A,  ll N, ll M, ll V, ll P, int pos)
{
    // first, make A[pos] high
    ll base = A[pos] + M;
    if (A[P-1]>base) return false;
 
    // get left votes
    if (V<=(N-pos)+(P-1)) return true;
    // queue<ll> que;
    // rep(i, 0, V-(N-pos)-(P-1))
    //     que.push(M);
 
    // voting with greedy
    ll sum = 0;
    for (int i=pos-1; P-1<=i; --i)
    {
        sum += base - A[i];
    }
    int k =  V-(N-pos)-(P-1);
    debug(pos, sum, M*k);
    debug(sum>=M*k);
    return sum >= M*k;
    // return que.size()==0;
}

int main()
{
    // read input
    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<ll> A(N);
    rep(i, 0, N)  cin >> A[i];
    
    // rsort
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    vector<ll> B(N+1, 0);
    rep(i, 0, N) B[i+1] = B[i] + A[i];
    debug(A, B);

    // binary search 
    ll low = 0;
    ll high = N-1;
    while (low<high)
    {
        ll mid = (low+high+1)/2;
        debug(low, mid, high);
        // check
        bool is_ok = check(A, N, M, V, P, mid);
        
        if (is_ok)
            low = mid;
        else
            high = mid-1;
    }
    debug(low);
    cout << low+1 << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;


constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
	template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
	template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
	template<typename T> void chadd(T& a, T b) { a = a + b; }

	void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }


	// 標準入出力
	struct inp {
		std::size_t sz;
		inp(std::size_t _sz = 1) : sz(_sz) {}
		template <typename T> operator T () const { T a; std::cin >> a; return a; }
		template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
		template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
	};

	inp inp1; // input one
}

int main() {

	int n = inp1;
	vector<int> a = inp(n);

	// 左から貪欲

	int ans = 0;
	int cnt = 1;
	rep(i, n) {
		if (a[i] != cnt) {
			// 壊す
			++ans;
			continue;
		}
		++cnt;
	}

	if (cnt == 1) Cout(-1);
	else Cout(ans);

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
 
int main()
{
	int h, w, i, j;
	scanf("%d %d", &h, &w);
	while (h && w)
	{
		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &h, &w);
	}
 
	return 0;
}


Measured memory_bytes: 2060
s=input()
s1=s[:2]
s2=s[2:]
a,b=0,0
if 1<=int(s1)<=12:
  a=1
if 1<=int(s2)<=12:
  b=1
print("AMBIGUOUS" if a*b==1 else "YYMM" if b==1 else "MMYY" if a==1 else "NA")

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

using namespace std;

#define LOCAL // sumbit source code
#define print_vec(v)          \
    for (auto row : v)        \
    {                         \
        for (auto d : v)      \
        {                     \
            cout << d << " "; \
        }                     \
        cout << endl;         \
    }
#define all(a) begin(a), end(a)
#define MOD 1000000007
#define PII pair<int, int>
typedef vector<int> VI;
typedef long long ll;


ll quick_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = a * res;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    a = abs(a), b = abs(b);
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

// TO-DO
// contest required
#ifdef LOCAL

bool cmp(const pair<string, int> &p1, const pair<string, int> &p2) {
    return p2.second < p1.second;
}

void solve() {
    int t;
    cin >> t;
    string s;
    int hash[4] = {0};
    while (t--) {
        cin >> s;
        if (s == "AC") {
            hash[0]++;
        }
        if (s == "WA") {
            hash[1]++;
        }
        if (s == "TLE") {
            hash[2]++;
        }
        if (s == "RE") {
            hash[3]++;
        }
    }
    cout << "AC x " << hash[0] << endl;
    cout << "WA x " << hash[1] << endl;
    cout << "TLE x " << hash[2] << endl;
    cout << "RE x " << hash[3] << endl;
}

int main() {
    // 加速输入和输出
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

#endif


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)


using namespace std;

ll Ha, Hb, Hc, Hx, Hy, Hz, Hmax, Hmin;
string ans;

int a[9];
int n;
int b[10];
bool temp[9];

int main() {
	rep(i, 9) {
		cin >> a[i];
	}
	cin >> n;
	rep(i, n) {
		cin >> b[i];
	}

	rep(k, n) {
		rep(i, 9) { 
				if (a[i] == b[k]) {
					temp[i] = 1;
			}
		}
	}



	if ((temp[0] && temp[1] && temp[2]) || (temp[3] && temp[4] && temp[5]) || (temp[6] && temp[7] && temp[8]) ||
		(temp[0] && temp[3] && temp[6]) || (temp[1] && temp[4] && temp[7]) || (temp[2] && temp[5] && temp[8]) ||
		(temp[0] && temp[4] && temp[8]) || (temp[2] && temp[4] && temp[6])) {
		ans = "Yes";
	}
	else ans = "No";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
 
#define hell                         1000000007
#define hell2                        998244353
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define all(v)                       v.begin(),v.end()
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'
 
const ll MAX=200005;
const ll SQN=330;
const ll LG=22;
const double PI=atan(1)*4;
using namespace std;

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

    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    
    ll x=0;
    while(b<=a) {
    	b=b*2;
    	x++;
    }

    while(c<=b) {
    	c=c*2;
    	x++;
    }
    if(x>k) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define PI 3.14159265
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 300000000000000001
#define infx 9223372036854775806
#define all(c) c.begin(),c.end()
#define mk(x,yy) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)           (x>y)?x:y
#define min2(x,y)           (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define ene cout<<"\n";

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll power(ll x,  ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
 
bool compr(std::vector<ll> a, std::vector<ll> b)
{
    if(a[0]==b[0])
        return a[1]<b[1];
    else
        return a[0]<b[0];
}

bool comp(std::vector<ll> a, std::vector<ll> b)
{
    if(a[1]==b[1]&&a[2]==b[2])
        return a[0]<b[0];
    else if(a[1]==b[1])
        return a[2]>b[2];
    else
        return a[1]<b[1];
}
ll bit[400005];

void update(ll x, ll val, ll n)
{
    for(;x<=n;x+=x&-x)
        bit[x] = max(bit[x],val);
}

ll query(ll x, ll n)
{
    ll tmp = 0;
    for(;x>0;x-=x&-x)
        tmp = max(tmp,bit[x]);
    return tmp;
}

int main()
{
    #ifdef SHIVANSH 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll h[n];
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>h[i];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=1;i<=n;i++)
    {
        update(i,0,n);
    }
    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
        ll lmx = query(h[i],n);
        lmx = a[i]+lmx;
        ans = max(lmx,ans);
        update(h[i],lmx,n);
    }
    cout<<ans<<endl;;
}

Measured memory_bytes: 8332
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long n, i, j, k, x, a, b, best;
	cin >> n;
	map<long long, long long> ct;
	for (i = 0; i < n; i++) {
		cin >> x;
		ct[x]++;
	}

	vector<long long> v;
	for (auto p : ct) {
		if (p.second >= 4) {
			v.push_back(p.first);
			v.push_back(p.first);
		}
		else if (p.second >= 2) v.push_back(p.first);
	}

	sort(v.rbegin(), v.rend());

	if (v.size() < 2) best = 0;
	else best = v[0] * v[1];
	cout << best << "\n";

	return 0;
}


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

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl cout<<'\n'
#define pb push_back
#define all(s) s.begin(),s.end()
#define bs binary_search

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a)*(b)/(__gcd((a),(b)))

const int Mod=1e9+7;
#define sum(a,b) (((a)%Mod)+((b)%Mod))%Mod
#define sub(a,b) (((a)%Mod)-((b)%Mod))%Mod
#define mul(a,b) (((a)%Mod)*((b)%Mod))%Mod
#define digit(x) floor((log10(x))+1)


#define count1(x) __builtin_popcount(x)

#define dbg(x) cout << #x <<":"<<x<<endl;

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
} 

ll pow(ll x, ll y, ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=(ans*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}

int main()
{
	fast;
	ll i,n,sum,j;
	cin >> n;
	vector<ll> ans(n+1);
	//ans[1]=1;
	for(i=0;i<=n;i++)
	{
		ans[i]=0;
	}
	//ans[1]=1;
	for(i=1;i<=n;i++)
	{
		ans[i]++;
		for(j=i+i;j<=n;j+=i)
		{
			ans[j]++;
		}
	}
	// for(i=1;i<=n;i++)
	// {
	// 	cout << ans[i] << " ";
	// }
	// cout<<endl;
	sum=0;
	for(i=1;i<=n;i++)
	{
		sum+=i*ans[i];
	}
	cout << sum << endl;
}

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

int main()
{
    int n,d;
    cin>>n>>d;
    int x[n][d];
    for(int i=0;i<n;i++)
        for(int j=0;j<d;j++)
            cin>>x[i][j];

    int count=0;
    double tmp;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++) {
            tmp=0;
            for(int k=0;k<d;k++)
                tmp+=pow(x[i][k]-x[j][k],2);
            tmp=sqrt(tmp);
            if(ceil(tmp)==floor(tmp)) count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <ctime>
#include <map>
#include <set>
#define fi first
#define se second
#define pii pair<int,int>
//#define ivorysi
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 100005
using namespace std;
typedef long long int64;
typedef double db;
typedef unsigned int u32;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9' ) {
		res = res * 10 - '0' + c;
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N;
pii f[(1 << 18) + 5];
int ans[(1 << 18) + 5];
pii Merge(pii a,pii b) {
	if(a.fi < b.fi) swap(a,b);
	return mp(a.fi,max(a.se,b.fi));
}
void Solve() {
	read(N);
	for(int i = 0 ; i < (1 << N) ; ++i) {
		read(f[i].fi);f[i].se = 0;
	}
	for(int i = 1 ; i < (1 << N) ; i <<= 1) {
		for(int j = 0 ; j < (1 << N) ; ++j) {
			if(j & i) {
				f[j] = Merge(f[j],f[j ^ i]);
			}
		}
	}
	for(int i = 1 ; i < (1 << N) ; ++i) {
		ans[i] = f[i].fi + f[i].se;
		ans[i] = max(ans[i - 1],ans[i]);
		out(ans[i]);enter;
	}
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}

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


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

int min(int a, int b){
  if(a>=b) return b;
  else return a;
}

int main(){
  int N;
  scanf("%d",&N);
  int *h;
  h=(int*)malloc((N+1)*sizeof(int));
  for(int i=1;i<=N;i++) scanf("%d",&h[i]);

  int *DP;
  DP=(int*)malloc((N+1)*sizeof(int));
  DP[1]=0;
  DP[2]=abs(h[1]-h[2]);
  for(int i=3;i<=N;i++){
    DP[i]=min(DP[i-1]+abs(h[i]-h[i-1]),DP[i-2]+abs(h[i]-h[i-2]));
  }

  printf("%d\n",DP[N]);
  return 0;
}

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

int main()
{
    int K, S;
    cin >> K >> S;

    ll ans = 0;
    for (int i = max(0, S - 2 * K); i <= min(S, K); i++)
    {
        for (int j = max(0, S - i - K); j <= min(S - i, K); j++)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n,m = 0;
    cin>>n;
    vector<int>a(n),b(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i] = a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++)    if(a[i]!=b[i])  m++;
    if(m<=2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n, k;

void read() {
  cin >> n >> k;
}

void solve() {
  double sol = 0;
  for(int i = 0; i < n; ++i) {
    double temp = i + 1;
    int nr = 0;
    while(temp < k)
      temp *= 2, ++nr;
    sol += (1.0 / n) * (1.0 / (1 << nr));
  }
  cout << fixed << setprecision(12) << sol;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int N; 
	cin >> N;
	if(N == 22){cout << "Christmas Eve Eve Eve" << endl;}
	else if(N == 23){cout << "Christmas Eve Eve" << endl;}
	else if(N == 24){cout << "Christmas Eve" << endl;}
	else if(N == 25){cout << "Christmas" << endl;}
}

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

using namespace std;

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

  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (K--) {
    vector<int> B(N + 1, 0);
    for (int i = 0; i < N; i++) {
      B[max(i - A[i], 0)]++;
      B[min(i + A[i] + 1, N)]--;
    }
    for (int i = 0; i < N; i++) {
      B[i + 1] += B[i];
    }
    for (int i = 0; i < N; i++) {
      A[i] = B[i];
    }
    if (count(A.begin(), A.end(), N) == N) {
      break;
    }
  }

  for (int i = 0; i < N; i++) {
    cout << A[i];
    cout << (i == N - 1 ? "\n" : " ");
  }

  return 0;
}

Measured memory_bytes: 4944
// ref: https://qiita.com/tubo28/items/e6076e9040da57368845
use std::io::{stdin, Read};
use std::str::FromStr;
use std::cmp;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let w = read();
    let h = read();
    let n = read();

    let mut xmin = 0;
    let mut xmax = w;
    let mut ymin = 0;
    let mut ymax = h;

    for _ in 0..n {
        let x = read();
        let y = read();
        let a = read();
        match a {
            1 => {
                xmin = cmp::max(xmin, x);
            }
            2 => {
                xmax = cmp::min(xmax, x);
            }
            3 => {
                ymin = cmp::max(ymin, y);
            }
            4 => {
                ymax = cmp::min(ymax, y);
            }
            _ => unreachable!()
        }
    }

    let ans = if (xmin < xmax) && (ymin < ymax) {
        (xmax - xmin) * (ymax - ymin)
    } else {
        0
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include "iostream"

using namespace std;

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

	int ans;
	ans = 1900 * m + 100 * (n - m);

	for (int i = 0; i < m; i++) {
		ans *= 2;
	}
	
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n;
  int k;
  cin >> n >> k;
  string s;
  cin >> s;
  if (s[k-1]=='A') s[k-1] = 'a';
  else if (s[k-1]=='B') s[k-1]='b'; else s[k-1]='c';
  cout << s;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

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

string P1[1100], P2[1100];
unsigned long long int rec[1100][1100];

int main(){
	
	int H, W;
	cin >> H >> W;
	
	for(int i = 0; i < H; i++){
		cin >> P1[i];
	}
	
	int R, C;
	cin >> R >> C;
	
	for(int i = 0; i < R; i++){
		cin >> P2[i];
	}
	
	if(H < R || W < C){
		return 0;
	}
	
	unsigned long long int B1 = 9973, B2 = 1e9 + 7, t1 = 1, t2 = 1;
	
	unsigned long long int ans = 0;
	
	for(int i = 0; i < C; i++){
		unsigned long long int val = 0;
		for(int j = 0; j < R; j++){
			val *= B1;
			val += P2[j][i];
		}
		ans *= B2;
		ans += val;
	}
	
	for(int i = 0; i < R; i++){
		t1 *= B1;
	}
	for(int i = 0; i < C; i++){
		t2 *= B2;
	}
	
	for(int i = 0; i < W; i++){
		unsigned long long int val = 0;
		for(int j = 0; j < R; j++){
			val *= B1;
			val += P1[j][i];
		}
		rec[0][i] = val;
		for(int j = R; j < H; j++){
			val *= B1;
			val += P1[j][i];
			val -= t1 * P1[j - R][i];
			rec[j - R + 1][i] = val;
		}
	}
	
	for(int i = 0; i <= H - R; i++){
		unsigned long long int val = 0;
		for(int j = 0; j < C; j++){
			val *= B2;
			val += rec[i][j];
		}
		if(val == ans){
			cout << i << " " << 0 << endl;
		}
		for(int j = C; j < W; j++){
			val *= B2;
			val += rec[i][j];
			val -= t2 * rec[i][j - C];
			if(val == ans){
				cout << i << " " << j - C + 1 << endl;
			}
		}
	}
	
	return 0;
}



Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1e9+7;

//ユークリッドの互除法
ll gcd(ll x,ll y){
    if(x>y)swap(x,y);
    if(y%x==0)return x;
    return gcd(x,y%x);
};

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

    int ans,tra,can;

    ans = max(a[0],a[1]); 
    tra = min(a[0],a[1]);
    can = gcd(a[0],a[1]);

    for(int i = 2; i < n; i++){
        int tmp1 = gcd(ans,a[i]);
        if(i == 2){
            int tmp2 = gcd(tra,a[i]);
            if(tmp1 > tmp2){
                if(tmp1 > can){
                    ans = tmp1;
                    can = gcd(can,a[i]);
                }
                else {
                    ans = can;
                    can = gcd(can,a[i]);
                }
            }
            else {
                if(tmp2 > can){
                    ans = tmp2;
                    can = gcd(can,a[i]);
                }
                else {
                    ans = can;
                    can = gcd(can,a[i]);
                }
            }
        }
        else {
            if(tmp1 > can){
                ans = tmp1;
                can = gcd(can,a[i]);
            }
            else {
                ans = can;
                can = gcd(can,a[i]);
            }
        }
    }
    cout << ans << endl;
}

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

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

using namespace std;

int dp[25][50005];

const int INF = 1 << 21;

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

  vector<int> c(m + 1);
  for (int i = 1; i <= m; ++i) { cin >> c[i]; }

  rep(i, n + 1) dp[0][i] = INF;
  rep(i, m + 1) dp[i][0] = 0;

  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (j - c[i] < 0) continue;
      dp[i][j] = min(dp[i][j], dp[i][j - c[i]] + 1);
    }
  }

  cout << dp[m][n] << '\n';

  return 0;
}



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

bool prime_check(long long int p){
    for(long long int i=2; i<=sqrt(p); i++){
        if(p%i == 0){
            return false;
        }
    }
    return true;
}

int main()
{
    long long int P;

    cin >> P;
    
    while(1){
        if(prime_check(P)){
            cout << P << endl;
            break;
        }
        else{
            P++;
        }
    }
    return 0;
}


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

using namespace std;

int main(){

  string S, T;
  char tmp;
  int flag = 1;

  cin >> S;
  cin >> T;

  for(int i = 0; i < S.size(); i++){
    tmp = S[S.size()-1];
    for(int j = S.size(); 0 < j; j--){
      S[j] = S[j-1];
    }
    S[0] = tmp;

    if(S == T){
      cout << "Yes" << endl;
      flag = 0;
      break;
    }
  }

  if(flag) cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
	int num, tmt, flag = 1, i, j, n = 0;
	int a[200];

	scanf("%d", &num);

	for (i = 0; i < num; i++) {
		scanf("%d", &a[i]);
	}

	for (i = 0; i < num; i++) {
		flag = 1;

		while (flag) {
			flag = 0;
			for (j = num - 1; j > 0; j--) {
				if (a[j] < a[j - 1]) {
					tmt = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmt;
					n++;
				}
			}
		}
	}


	
	for (i = 0; i < num; i++) {
		printf("%d", a[i]);

		if (i != num - 1) {
			putchar(' ');
		}
		else {
			putchar('\n');
		}
	}

	printf("%d\n", n);

	return 0;
}


Measured memory_bytes: 2080
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int MAXC = 6;
int coin[] = {500, 100, 50, 10, 5, 1};

int main()
{
    int n;
    while(cin >> n && n)
    {
        int ans = 0;
        n = 1000 - n;

        REP(MAXC)while(n >= coin[i]){ n-= coin[i]; ans++;}
        
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
	string str;
	while( cin >> str && str != "0" ){
		int ele[12] = {};
		ele[0] = 1;
		int s=0;
		long long ans = 0;
		for(int i = str.size() - 1 ; i >= 0 ; i--){
			int d = str[i] - '0';
			int c = i % 2 ? 10 : 1;
			s += c * d;
			s %= 11;
			if( d != 0 ){
				ans += ele[s];
			}
			ele[s]++;
		}
		cout << ans << endl;
	}
}

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


int main()
{
    int a, b;
    cin >> a >> b;
    int max = a + b;
    if ((a * b) > max)
        max = a * b;
    if ((a - b) > max)
        max = a - b;
    cout << max;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define ll long long
map<pair<ll,ll>,pair<ll,ll>>k;
const ll mod=1000000007;
ll qpow(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
int main()
{
    //cout<<3/__gcd(0,3)<<endl;
    int n;
    scanf("%d",&n);
    ll ans=mod-1;
    ll tmp=1;
    for(int i=1;i<=n;i++)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        if(a==0&&b==0)
        {
            ans=(ans+1)%mod;
        }
        else
        {
            if(a<0){a=-a,b=-b;}
            ll g = __gcd(abs(a),abs(b));
            a/=g;b/=g;
            if(a==0)
                k[{a,abs(b)}].first++;
            else if(b==0)
                k[{b,abs(a)}].second++;
            else if(b>0)
                k[{a,b}].first++;
            else
                k[{-b,a}].second++;
        }
    }
    for(auto it:k)
        tmp=tmp*((qpow(2,it.second.first)+qpow(2,it.second.second)-1)%mod)%mod;
    cout<<(ans+tmp)%mod<<endl;
}

Measured memory_bytes: 19264
#include <stdio.h>

int B[10000000];
int len;

void print(int x) {
	if(x > 0) B[len++]=x;
}

void yaru(int a, int islast) {
	int i;
	if (a%2==1) {
		for(i=1;i<a;i+=2) {
			print(2);
		}
		if(!islast) print(2); /* 最後以外で奇数が来るのは最初のみ */
	} else {
		if((a/2)%2==0) {
			if(islast) {
				print(1);
				print(a-2);
			} else {
				print(a);
			}
		} else {
			print(a/2-1);
			if(islast) {
				print(1);
				print(a/2-1);
			} else {
				print(a/2+1);
			}
		}
	}
}

int main(void) {
	int N,M;
	int A[200];
	int i;
	int kisuucount=0;
	int k1=0,k2=0;
	int tmp;
	if(scanf("%d%d",&N,&M)!=2)return 1;
	for(i=0;i<M;i++) {
		if(scanf("%d",&A[i])!=1)return 1;
	}
	for(i=0;i<M;i++) {
		if(A[i]%2!=0) {
			if(kisuucount==0)k1=i; else k2=i;
			kisuucount++;
		}
	}
	if(kisuucount>2) {
		puts("Impossible");
		return 0;
	}
	if(kisuucount==1) {
		tmp=A[k1];
		A[k1]=A[0];
		A[0]=tmp;
	} else if(kisuucount==2) {
		tmp=A[k1];
		A[k1]=A[0];
		A[0]=tmp;
		tmp=A[k2];
		A[k2]=A[M-1];
		A[M-1]=tmp;
	}
	printf("%d", A[0]);
	for(i=1;i<M;i++) printf(" %d",A[i]);
	putchar('\n');
	len=0;
	if(A[0]%2==1) {
		yaru(A[0], M==1);
		if(M==1) print(1);
	} else {
		print(1);
		yaru(A[0], M==1);
	}
	for(i=1;i<M;i++) {
		yaru(A[i],i+1>=M);
	}
	printf("%d\n", len);
	printf("%d", B[0]);
	for(i=1;i<len;i++) printf(" %d", B[i]);
	putchar('\n');
	return 0;
}

/*
sample 1
ABB
CDC

C: A=B

sample 2
ABCCBA
DEEFGF

E: B=C
F: C=A

----------

123214554
AABBCCDEE

1234321565
AABBCCDDEE

122343
AABBCC

Aの列: (N-奇数の数)/2個のペアについて同じだと言える
Bの列: 同様

全部同じだと言うのに必要なペアの数は(N-1)個
奇数が0個でも、高々N/2個のペアについてしか同じと言えない
Nが偶数の場合
  Aに奇数が0個 -> できる?
  Aに奇数が1個 -> ありえない
  Aに奇数が2個 -> できる?
  Aに奇数が3個 -> ありえない
  Aに奇数が4個以上 -> Impossible

Nが奇数の場合
  Aに奇数が0個 -> ありえない
  Aに奇数が1個 -> できる?
  Aに奇数が2個 -> ありえない
  Aに奇数が3個以上 -> Imposssible

123443215677658998
AABBxCCDDEEFGGFxHH

1122334455
xAABBCCDDx

1221345543
AAxBBCCxxx

1233214554
xAABCCBxDD

12345543216776
xABBACDEEDCxFF

123443215677658998
xABCDDCBAEEFGGFxHH

1221
xxAA

123456654321
xxABCDEEDCBA

1=3 2=4 5=3 6=4 5=6


Nが偶数の場合
  A/2が奇数の場合
    最初1個 -> 前のやつからの接続を受け入れる
    次(A/2-1)個 -> 回文としてマーク
    次1個 -> 次と接続する
    次(A/2-1)個 -> 回文としてマーク
  A/2が偶数の場合
    最初1個-> 前のやつからの接続を受け入れる
    次1個 -> 次と接続する
    次(A-2)個 -> 回文としてマーク

123214566547887
AABBCCDDEFFExGG

1234321
AABBCCx

123454321
AABBCCDDx

Nが奇数の場合
  Aが奇数のやつを最初に配置

*/


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>

int main() {
	int h, w, n, a[10001], point = 1;
	scanf("%d %d %d", &h, &w, &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", a + i);

	for (int i = 0; i < h; i++) {
		int masu[100];
		if (i & 1) {
			for (int j = 0; j < w; j++) {
				if (a[point] <= 0)
					point++;
				masu[w - 1 - j] = point;
				a[point]--;
			}
		} else {
			for (int j = 0; j < w; j++) {
				if (a[point] <= 0)
					point++;
				masu[j] = point;
				a[point]--;
			}
		}
		printf("%d", masu[0]);
		for (int j = 1; j < w; j++)
			printf(" %d", masu[j]);
		printf("\n");
	}
}

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

using namespace std;

int main(void){
    string S;
    cin >> S;
    int N ;
    N = S.length();
    int a[N];
    int sum = 0;
    for(int i = 0; i < N; i++)
    {
    a[i] = (int)(S[i] - '0');
    sum = sum + a[i];
    }
    sum = sum % 9;
    if(sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 4488
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  for(int i=1; i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cctype>
#include<stack>
using namespace std;
typedef long long ll;
ll nx[55],ny[55];
ll mx[55],my[55];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>nx[i]>>ny[i];
    for(int i=1;i<=m;i++)
        cin>>mx[i]>>my[i];
    for(int i=1;i<=n;i++)
    {
        int minLen=abs(nx[i]-mx[1])+abs(ny[i]-my[1]);
        int index=1;
        for(int j=1;j<=m;j++)
        {
            if(minLen>abs(nx[i]-mx[j])+abs(ny[i]-my[j]))
            {
                minLen=abs(nx[i]-mx[j])+abs(ny[i]-my[j]);
                index=j;
            }

        }
        cout<<index<<endl;

    }

    return 0;
}



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#D - Number of Amidakuji
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
H,W,K = map(int,readline().split())
facts = [1,1,2,3,5,8,13,21,34]
# a = [0]
# b = [1]
# for i in range(W):
#     a.append(b[i])
#     b.append(a[i]+b[i])

dp = [0] * W
dp[0] = 1
for _ in range(H):
    ndp = [0]*W
    for w in range(W):
        ndp[w] += dp[w] * facts[w] * facts[W-w-1]
        if w > 0:
            ndp[w] += dp[w-1] * facts[w-1] * facts[W-w-1] 
        if w < W-1:
            ndp[w] += dp[w+1] * facts[w] * facts[W-w-2]
        ndp[w] %= MOD
    dp = ndp
    
print(dp[K-1])

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  ll n,h,w;
  ll ans = 0;
  cin >> h >> w >> n;
  if ( n % max(h, w) == 0) {
    ans = n / max(h, w);
  } else {
    ans = n / max(h, w) + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const ll INF=10000000000LL;
ll r197(ll n){
	return n%1000000007;
}

typedef pair<int,int>P;

typedef pair<int,P>Pa;
vector<int> v[100001];
bool b[100005]={};
struct edge{
	int score;
	int num;
};
int n;
int k;
int p[103];
ll dp[101][100005]={};
ll reg(int m,int s){
	if(dp[s][m]!=-1)return dp[s][m];
	if(s==k)return 1;
	if(m==n)return 0;
	ll res=0;
	rep(i,0,p[m]+1){
		if(s+i>k)break;
		res=r197(res+(reg(m+1,s+i)));
	}

	return dp[s][m]=res;

}
int main() {
	cin>>n>>k;
	rep(i,0,n){
		cin>>p[i];
	}
	dp[0][0]=1;
	rep(i,0,n){
		rep(j,0,k+1){
			dp[i+1][j]=r197(dp[i+1][j]+dp[i][j]);
			dp[i+1][min(j+p[i],k)+1]=r197(dp[i+1][min(j+p[i],k)+1]-dp[i][j]);
		}
		rep(j,1,k+1){
			dp[i+1][j]=r197(dp[i+1][j]+dp[i+1][j-1]);
			if(dp[i+1][j]<0)dp[i+1][j]+=1000000007;
		}
	}
	cout<<dp[n][k]<<endl;

	return 0;
}


Measured memory_bytes: 80768
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	int a = n * (n - 1) / 2;
	int b = m * (m - 1) / 2;
	cout << a + b << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <utility>

using namespace std;

int w,h;
bool d[102][102];
bool flag[102][102];

int check(int x,int y){
	if(x < 0){ return -1; }
	if(x > w + 1){ return -1; }
	if(y < 0){ return -1; }
	if(y > h + 1){ return -1; }
	if(flag[x][y]){ return -1; }
	if(d[x][y]){ return 0; }
	return 1;
}
int check(pair<int,int> p){
	return check(p.first,p.second);
}

pair<int,int> add(pair<int,int> a,pair<int,int> b){
	return pair<int,int>( a.first+b.first , a.second+b.second );
}

int main(){
	int self;
	scanf("%d %d",&w,&h);
	for(int j=1;j<h+1;j++){
		for(int i=1;i<w+1;i++){
			scanf("%d",&self);
			d[i][j] = self;
		}
	}
	queue< pair<int,int> > que;
	que.push( pair<int,int>(0,0) );
	flag[0][0] = true;
	
	pair<int,int> v[2][6] = {
		{
			pair<int,int>(1,0),
			pair<int,int>(-1,0),
			pair<int,int>(0,1),
			pair<int,int>(0,-1),
			pair<int,int>(-1,1),
			pair<int,int>(-1,-1),
		},
		{
			pair<int,int>(1,0),
			pair<int,int>(-1,0),
			pair<int,int>(0,1),
			pair<int,int>(0,-1),
			pair<int,int>(1,1),
			pair<int,int>(1,-1),
		},
	};
	
	int ans = 0;
	int r;
	pair<int,int> p,pp;
	while(que.size() > 0){
		p = que.front();
		que.pop();
		for(int i=0;i<6;i++){
			pp = add(p,v[p.second % 2][i]);
			r = check(pp);
			if(r == 0){
				ans++;
			}
			if(r == 1){
				flag[pp.first][pp.second] = true;
				que.push(pp);
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 0