akhauriyash/Code-Regression huggingface dataset:
use std::collections::BinaryHeap;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let mut a: Vec<(usize, usize)> = (0..n).map(|i| (sc.read::<usize>(), i)).collect();
    a.sort_by_key(|&(count, x)| (-(count as i32), x));

    let mut count = vec![0; n];

    // let mut heap = BinaryHeap::new();
    let mut head = 0;
    loop {
        let (head_count, x) = a[head];
        let mut tail = head;
        while tail + 1 < n {
            let (_, y) = a[tail + 1];
            if y > x {
                tail += 1;
            } else {
                break;
            }
        }

        if tail == n - 1 {
            for i in head..n {
                let (c, _) = a[i];
                count[x] += c;
            }
            count[x] += head * head_count;
            break;
        }

        let (tail_count, _) = a[tail + 1];

        let mut tmp = 0;
        for i in head..(tail + 1) {
            let (c, _) = a[i];
            tmp += c - tail_count;
        }
        tmp += head * (head_count - tail_count);
        count[x] = tmp;
        head = tail + 1;
    }

    for i in 0..n {
        println!("{}", count[i]);
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 9212
// AOJ Volume 0 Problem 0017

#include <stdio.h>
#include <string.h>

#define DIFF(c1, c2)    ((((c2)-(c1))>=0)?((c2)-(c1)+1):((c2)-(c1)+1+26))


void conv(char *str, char *str_diff)
{
    int i;
    
    i = 0;
    do {
        switch (str[i]){
          case ' ':
          case '.':
            str_diff[i] = -2;
            break;

          case '\0':
            str_diff[i] = 0;
            break;
          
          default:
            if (str_diff[i - 1] == -2){
                str_diff[i] = -1;
            }
            else {
                str_diff[i] = DIFF(str[i - 1], str[i]);
            }
            break;
        }
//        printf("[%d<%c>]", str_diff[i], str[i]);
    } while (str[i++] != '\0');
}

int search(char *str1, char *str2)
{
    int i;
    
    for (i = 0; i <= strlen(str1) - strlen(str2); i++){
        if (memcmp(str1 + i, str2, strlen(str2)) == 0){
            return (i);
        }
    }
    
    return (-1);
}

int main(void)
{
    char str[82];
    char str_diff[82];
    char diff_the[5];
    char diff_this[6];
    char diff_that[6];
    int pos;
    int diff;
    char c;
    int i;
    
    diff_the[0] = -1;
    diff_the[1] = DIFF('t', 'h');
    diff_the[2] = DIFF('h', 'e');
    diff_the[3] = -2;    
    diff_the[4] = 0;    
    
    diff_this[0] = -1;
    diff_this[1] = DIFF('t', 'h');
    diff_this[2] = DIFF('h', 'i');
    diff_this[3] = DIFF('i', 's');
    diff_this[4] = -2;    
    diff_this[5] = 0;    

    diff_that[0] = -1;
    diff_that[1] = DIFF('t', 'h');
    diff_that[2] = DIFF('h', 'a');
    diff_that[3] = DIFF('a', 't');
    diff_that[4] = -2;    
    diff_that[5] = 0;    

    
    str[0] = ' ';
//    gets(&str[1]);
	while (fgets(&str[1], 100, stdin) != 0){
	
	    conv(str, str_diff);
	
	    if ((pos = search(str_diff, diff_the)) == -1){
	        if ((pos = search(str_diff, diff_this)) == -1){
	            pos = search(str_diff, diff_that);
	        }
	    }
	    
	    diff = str[pos] - 't';
	    if (diff < 0){
	        diff += 26;
	    }
	    
	    for (i = 1; i < strlen(str); i++){
	        if ('a' <= str[i] && str[i] <= 'z'){
	            c = str[i] - 'a' - diff;
	            if (c < 0){
	                c += 26;
	            }
	            c += 'a';
	            
	            printf("%c", c);
	        }
	        else if (str[i] == '.' || str[i] == ' '){
	            printf("%c", str[i]);
	        }
	    }
		printf("\n");
	}
	
    return (0);
}

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

int main(){
  int n, count=0;
  string s;
  bool Pink=1,White=1,Green=1,Yellow=1;
  
  cin >> n;
  while(n>0){
    cin >> s;
    if(s == "P" && Pink == 1){
      count += 1;
      Pink = 0;
    }else if(s == "W" && White == 1){
      count += 1;
      White = 0;
    }else if(s == "G" && Green == 1){
      count += 1;
      Green = 0;
    }else if (s == "Y" && Yellow == 1){
      count += 1;
      Yellow = 0;
    }else if(count == 4){
      break;
    }
    
    n --;
  }
  
  if(count == 3){
    cout << "Three" <<endl;
  }else if(count == 4){
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
//file_name:ABC90_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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

    int l[100010] = {};
    
    srep(i,10000,100000){
        int ii = i;
        int a,b,c,d,e;
        a = ii%10;
        ii /= 10;
        b = ii%10;
        ii /= 10;
        c = ii%10;
        ii /= 10;
        d = ii%10;
        ii /= 10;
        e = ii%10;
        ii /= 10;
        if(a==e&&b==d)l[i]=1;
    }
    int nn = 0;
    int mm = 0;
    rep(i,n){
        nn += l[i];
    }
    rep(i,m+1){
        mm += l[i];
    }

    cout << mm - nn << endl;
    return 0;
}



Measured memory_bytes: 640
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
X = [0] * M
check = [[] for i in range(N)]

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    X[i] = [Y[i], P[i], i]

X.sort()
#print(X)

count = [0] * (N+1)
ans_list = [[] for _ in range(M)]

for i in range(len(X)):
    count[X[i][1]] += 1
    tmp = ('000000'+ str(X[i][1]))[-6:] + ('000000'+ str(count[X[i][1]]))[-6:]
    ans_list[X[i][2]] = tmp

for i in range(len(ans_list)):
    print(ans_list[i])

Measured memory_bytes: 41072
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	while(cin >> n){
		cout << stop[n] << endl;
		c++;
	}
	while(c>=20){};
	
}

Measured memory_bytes: 0
import math

def is_prime(n):
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def main():
    n = int(input())
    while True:
        result = is_prime(n)
        if result:
            print(n)
            exit()
        n += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
long long int prime(long long int n)
{
    if(n<=1){return prime(++n);}
    for(unsigned int i=2;i<=(n/2);i++)
    {
        if(n%i==0){return prime(++n);}
    }
    return n;
}
int main()
{
   long long int n;
   cin>>n;
   long long int x=prime(n);
   cout<<x;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	char a;
	cin >> a;
	//printf("%c%c%c\n", a[0]+'A'-'a',b[0]+'A'-'a',c[0]+'A'-'a');
	//cout << max(a*b,c*d) << endl;
	printf((a == 'a' || a == 'i' || a == 'u'||a=='e'||a=='o') ? "vowel\n" : "consonant\n");
}

Measured memory_bytes: 256
INF=float('inf')

def main():
    N,M,X=map(int,input().split())
    ans=INF
    CA=[[int(_) for _ in input().split()] for _ in range(N)]
    for bit in range(2**N):
        money=0
        tmp=[0]*M
        for i in range(N):
            if (bit >> i) & 1:
                money += CA[i][0]
                for j in range(1, M+1):
                    tmp[j-1] += CA[i][j]
        if min(tmp) >= X:
            ans=min(ans, money)
    print(-1 if ans == INF else ans)

main()

Measured memory_bytes: 9220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

struct P {
    int64_t x, y;

    bool operator<(const P& p) const {
        int64_t t1 = x + y;
        int64_t t2 = p.x + p.y;
        return t1 != t2 ? t1 < t2 : x < p.x;
    }
    void rot90() {
        y *= -1;
        swap(x, y);
    }
    void rot270() {
        swap(x, y);
        y *= -1;
    }
};

set<P> sp[2];
vector<P> vp[2];
int64_t d, m;

void dfs(P o) {
    int k[2][2] = { 1, 0, 2, 3, };
    for (int j = 0; j < 2; j++) {
        if (j == 1) o.rot90();
        P r[4] = {
            { o.x + d, o.y },
            { o.x, o.y + d },
            { o.x - d, o.y },
            { o.x, o.y - d },
        };
        if (j == 1) {
            for (int i = 0; i < 4; i++) {
                int s = i % 2 == 0 ? 1 : -1;
                r[k[0][i]].x += s;
                r[k[0][i]].y -= s;
            }
        }
        for (int h = 0; h < 2; h++) {
            auto i0 = lower_bound(vp[j].begin(), vp[j].end(), r[k[h][0]]);
            auto i1 = upper_bound(           i0, vp[j].end(), r[k[h][1]]);
            m += i1 - i0;

            auto i2 = sp[j].lower_bound(r[k[h][0]]);
            auto i3 = sp[j].upper_bound(r[k[h][1]]);
            vector<P> v;
            while (i2 != i3) {
                P p = *i2;
                sp[j].erase(i2++);
                if (j == 0) v.push_back(p), p.rot90();
                if (j == 1) p.rot270(), v.push_back(p);
                sp[j ^ 1].erase(p);
            }
            for (P& p : v) {
                dfs(p);
            }
        }
    }
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    a--;
    b--;

    vp[0] = vector<P>(n);
    for (int i = 0; i < n; i++) {
        cin >> vp[0][i].x >> vp[0][i].y;
    }
    vp[1] = vp[0];
    for (int i = 0; i < n; i++) {
        vp[1][i].rot90();
    }

    P pa[2];
    d = abs(vp[0][a].x - vp[0][b].x) + abs(vp[0][a].y - vp[0][b].y);

    for (int j = 0; j < 2; j++) {
        pa[j] = vp[j][a];
        sort(vp[j].begin(), vp[j].end());
        sp[j] = set<P>(vp[j].begin(), vp[j].end());
        sp[j].erase(pa[j]);
    }
    m = 0;
    dfs(pa[0]);

    cout << m / 2 << endl;

    return 0;
}


Measured memory_bytes: 27904
n,m,x = map(int,input().split())
books = []

for i in range(n):
    book = list(map(int,input().split()))
    books.append(book)

min_money = -1

#n冊あるとき、2**n通りの選び方
count = 0
for i in range(2**n):
    select = format(count, "0" + str(n) + "b")
    lst = []
    # print(select)
    while "1" in select:
        index = select.index("1")
        lst.append(books[index])
        select = "0"*(index+1) + select[index+1:]
    # print(lst)
    for j in range(1,m+1):
        skill = sum([lst[k][j] for k in range(len(lst))])
        if skill < x:
            # print("skill" + str(j) + "sum" + str(skill))
            break
    else:
        sum_money = sum([lst[j][0] for j in range(len(lst))])
        if min_money != -1:
            min_money = min(min_money, sum_money)
        else:
            min_money = sum_money

    count += 1

print(min_money)

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

int main(){
	int a[5],b[5],hi,bl;
	while(cin>>a[1]){
		cin>>a[2]>>a[3]>>a[4]>>b[1]>>b[2]>>b[3]>>b[4];
		hi=bl=0;
		for(int i=1;i<=4;i++){
			for(int j=1;j<=4;j++){
				if(a[i]==b[j]){
					if(i==j) hi++;
					else bl++;
				}
			}
		}
		cout<<hi<<" "<<bl<<endl;
	}
	return 0;
}

Measured memory_bytes: 3036
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	if (s.size() == 2) {
		if (s == "10") {
			cout << "1 2\n";
			return 0;
		}
		cout << -1 << endl;
		return 0;
	}
	if (s.size() == 3) {
		if (s == "110") {
			cout << "1 2\n";
			cout << "1 3\n";
			return 0;
		}
		cout << -1 << endl;
		return 0;
	}
	s = '0' + s;
	N = s.size();
	for (int i = 0; i < N; i++) {
		if (s[i] != s[N - i - 1]) {
			cout << -1 << endl;
			return 0;
		}
	}
	if (s[1] == '0') {
		cout << -1 << endl;
		return 0;
	}
	vector<pair<int, int>>ans;
	int box = 1;
	M = N - 1;
	for (int i = 2; i <= M / 2; i++) {
		if (s[i] == '1') {
			box = i;
		}
	}
	int cnt = 2;
	for (int i = 2; i <= M - box; i++) {
		ans.push_back({ 1,cnt });
		cnt++;
	}
	int bef = 1;
	for (int i = box; i >= 1; i--) {
		if (s[i] == '1') {
			ans.push_back({ bef,cnt });
			bef = cnt;
			cnt++;
		}
		else {
			ans.push_back({ bef,cnt });
			cnt++;
		}
	}
	for (auto i : ans)cout << i.first << " " << i.second << endl;
	return 0;
} 

Measured memory_bytes: 2276
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
    int n,m;
    map<int, bool> maps;
    map<int, int> error_maps;
    cin >> n >> m;
    int p;
    string r;
    int ans = 0;
    int error = 0;
    for(int i = 0 ; i < m;++i)
    {
        cin >> p >> r;
        if(maps.find(p) == maps.end())
        {
            if(r == "WA")
            {
                error_maps[p] = 1;
                maps[p] = false;
            }
            else{
                ans++;
                maps[p] = true;
            }
        }
        else
        {
            if(!maps[p] && r == "AC")
            {
                maps[p] = true;
                error += error_maps[p];
                ans++;
            }
            else if(!maps[p] && r == "WA")
            {
                error_maps[p]++;
            }
        }
    }
    cout << ans << " " << error << endl;
    return 0;
}


Measured memory_bytes: 6144
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int K; cin >> K;

    vector<ll> A;
    for (int i = 1; i < 1000; i++) {
        int p = i;
        int cnt = 0;
        while (p > 0) {
            cnt++;
            p /= 10;
        }
        ll val = i;
        rep(j,16-cnt) {
            A.emplace_back(val);
            val *= 10;
            val += 9;
        }
    }

    sort(all(A));
    A.erase(unique(begin(A), end(A)), end(A));
    int M = A.size();
    vector<ll> B(M);
    rep(i,M) {
        ll p = A[i];
        while (p > 0) {
            B[i] += p%10;
            p /= 10;
        }
    }
    rep(i,M) {
        bool ok = true;
        for (int j = i+1; j < M; j++) {
            if (A[i]*B[j] > A[j]*B[i]) ok = false;
        }
        if (ok) {
            cout << A[i] << ln;
            K--;
            if (!K) return 0;
        }
    }
}


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

using ll = long long;
const ll INF = 1e18 + 5;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,W,w,v;
    cin>>n>>W;
    vector<ll> dp(100001,INF);
    dp[0] = 0;
    for(int i=0;i<n;i++){
		cin>>w>>v;
		for(int j=100000;j>=v;j--){
			dp[j] = min(dp[j],dp[j-v] + w);
		}	
	}
	ll ans = 0;
	for(int i=0;i<=100000;i++){
		if(dp[i]<=W)
			ans = i;
	}
	cout<<ans;
    return 0;
}









Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N, K;
  cin >> N >> K;
  int ans = 0;
  rep(i, N)
  {
    int x;
    cin >> x;
    ans += 2 * min(x, abs(K - x));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    string a,b;cin>>a>>b;
    int m=a.length(),n=b.length(),t=m;
    for(int i=0;i+n<=m;i++)
    {
        int c=0;
        for(int j=0;j<n;j++)
        {
            if(a[i+j]!=b[j])
            c++;
        }
        t=min(t,c);
    }
    cout<<t<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,M,S;
    cin >>N>>M>>S;
    int res=0,tem;
    for(int i=0;i<S;i++){
    M = M-N;
    
    if(M>=0)res++;
}
   cout<<res<<endl;
   
}

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

int cnt[10][10] = {};

long long solve(int N) {
    for(int i=1; i<=N; ++i) {
        int k = i;
        int t = k % 10;
        while(k / 10) k /= 10;
        int h = k;
        cnt[h][t] += 1;
    }

    long long res = 0;
    for(int i=1; i<10; ++i) {
        for(int j=1; j<10; ++j) {
            res += cnt[i][j] * cnt[j][i];
        }
    }
    return res;
}

int main() {
    int N; cin >> N;
    cout << solve(N) << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 3
#define N 3
int main(void) {
    int i,j,flag;
    char board[SIZE*SIZE];
    while (scanf("%s\n",board)!=EOF) {
        flag =0;
        for(i=0;i<SIZE*SIZE;i++){
            if (i+(N-1)*SIZE<=i%SIZE+SIZE*(SIZE-1)) {
            	if (board[i]=='o'||board[i]=='x') {
                    for(j=0;j<N-1;j++) {
                        if (board[i+j*SIZE]!=board[i+(j+1)*SIZE]) break;
                        if (j==N-2) flag=1;
                    }
                }
            }
            if (i+N-1<=(i/SIZE)*SIZE+(SIZE-1)) {
                if (board[i]=='o'||board[i]=='x') {
                    for(j=0;j<N-1;j++) {
                        if (board[i+j]!=board[i+(j+1)]) break;
                        if (j==N-2) flag=1;
                    }
                }
            }
            if (i+(N-1)*(SIZE+1)<=SIZE*SIZE-1) {
                if (board[i]=='o'||board[i]=='x') {
                    for(j=0;j<N-1;j++) {
                        if (board[i+j*(SIZE+1)]!=board[i+(j+1)*(SIZE+1)]) break;
                        if (j==N-2) flag=1;
                    }
                }
            }
            if (i+(N-1)*(SIZE-1)<=SIZE*(SIZE-1)&&((i+(N-1)*(SIZE-1))/SIZE-i/SIZE==N-1)) {
                if (board[i]=='o'||board[i]=='x') {
                    for(j=0;j<N-1;j++) {
                        if (board[i+j*(SIZE-1)]!=board[i+(j+1)*(SIZE-1)]) break;
                        if (j==N-2) flag=1;
                    }
                }
            }
            if (flag==1) {
                printf("%c\n",board[i]);
                break;
            } else if (i==SIZE*SIZE-1) {
                printf("d\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 556
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a;
    cin >> a;
    if( a % 2 ) cout << 2 * a;
    else cout << a;
}


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

int main()
{
    int count = 0;
    cin >> count;
    list<int> inAry, outAry;
    for( int ii = 0; ii < count; ++ii){
        int buf;
        cin >> buf;
        inAry.push_back(buf);
    }
    
    bool isCntEven = count % 2 == 0;
    
    int i = 0;
    for(auto inVal : inAry){
        if((isCntEven && i % 2 == 0) || (!isCntEven && i % 2 != 0)){
            outAry.push_back(inVal);
        }else{
            outAry.push_front(inVal);
        }
        ++i;
    }
    
    i = 0;
    for(auto val : outAry){
        cout << val;
        if(i < outAry.size()-1){
            cout << " ";
        }
        ++i;
    }
    
    return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using ll = int64_t;

using namespace std;

ll n,m;
ll a[100010];

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

    cin >> n >> m;
    REP(i,n)cin >> a[i];

    int two = 0;
    REP(i,n){
        if(i == 0){
            ll x = a[i];
            while(x % 2 == 0){
                two++;
                x /= 2;
            }
        }else{
            ll x = a[i];
            int y = 0;
            while(x % 2 == 0){
                y++;
                x /= 2;
            }
            if(y != two){
                cout << 0 << '\n';
                return 0;
            }
        }
    }
    if(two != 0){
        REP(i,n) a[i] /= 2;
    }
    ll L = 1;
    REP(i,n){
        L = (L * a[i]) / gcd(L,a[i]);
    }
    
    cout << (1 + m/L)/2 << '\n';
    
}



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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll A(N);
  REP(i,N) IN(A[i]);

  ll tmp=1;
  REP(i,N){
    if(A[i]==tmp) tmp++;
  }

  if(tmp==1) OUT(-1);
  else  OUT(N-tmp+1);


  return 0;
}

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

int n, ans = -1;
char a[233];
bool cntl[26], cntr[26];

int solve(int pos) {
    int ret = 0;
    for(int i = 0; i < 26; ++i) cntl[i] = cntr[i] = 0;
    for(int i = 1; i <= pos; ++i) cntl[a[i] - 'a'] = 1;
    for(int i = pos + 1; i <= n; ++i) cntr[a[i] - 'a'] = 1;
    for(int i = 0; i < 26; ++i)
        if(cntl[i] && cntr[i]) ++ret;
    return ret;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i) ans = max(ans, solve(i));
    cout << ans << endl;
    return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = pow(10,9) + 100;

struct Card{ int number; char suit; };

int partition(vector<Card> &A, int p, int r){
    Card x = A[r];
    int i = p-1;
    for(int j=p; j<r; j++){
        if(A[j].number <= x.number){
            i++;
            swap(A[j], A[i]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

void quickSort(vector<Card> &A, int p, int r){
    if(p < r){
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q, r);
    }
}

void merge(vector<Card> &A, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<Card> L(n1+1);
    vector<Card> R(n2+1);
    rep(i,n1) L[i] = A[left+i];
    rep(i,n2) R[i] = A[mid+i];
    L[n1].number = INF;
    R[n2].number = INF;
    int i=0,j=0;
    for(int k=left; k<right; k++){
        if(L[i].number <= R[j].number){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(vector<Card> &A, int left, int right){
    if(left+1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main()
{
    int n; cin >> n;
    vector<Card> A(n);
    vector<Card> B(n);
    rep(i,n){
        cin >> A[i].suit >> A[i].number;
        B[i] = A[i];
    }
    quickSort(A, 0, n-1);
    mergeSort(B, 0, n);
    bool isStable = true;
    rep(i,n){
        if(A[i].number != B[i].number || A[i].suit != B[i].suit) isStable = false;
    }
    if(isStable) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    rep(i,n){
        printf("%c %d\n", A[i].suit, A[i].number);
    }
}


Measured memory_bytes: 5088
#include<stdio.h>
#include<string.h>
int a[128][128],H,W;
void U(int y,int w)
{
	for(int i=w;i<=W;i+=(i&-i))
		a[y][i]++;
}
int G(int y,int w)
{
	++y;
	int r=0,i;
	for(i=w;i;i^=(i&-i))
		r+=a[y][i];
	return r;
}
int main()
{
	int N,x,y,r,t,S,T;
	while(scanf("%d%d%d",&N,&W,&H)==3)
	{
		memset(a,0,sizeof(a));
		while(N--)scanf("%d%d",&x,&y),U(y,x);
		scanf("%d%d",&S,&T);
		for(r=x=0;x+S-1<W;++x)
		{
			for(t=y=0;y<T;++y)t+=G(y,x+S)-G(y,x);
			if(r<t)r=t;
			for(y=0;y+T<H;++y)
			{
				t+=G(y+T,x+S)-G(y+T,x)-G(y,x+S)+G(y,x);
				if(r<t)r=t;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
   int max=a,min=a;
  if(b>=a) max=b;
  else min=b;
  for(int i=0;i<max;i++) cout<<min;
 return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] a = new int[n];
         int all = 0;
         for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         }
         int mae = 0;
         int ushiro = all;
         int ans = 0;
         for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         }
         System.out.println(ans);
    }
}

Measured memory_bytes: 35836
<?php
  $n = trim(fgets(STDIN));
  for($i = 1; $i <= 9; $i++) {
    $res = $n / $i;
    $ama = $n % $i;
    if ($ama == 0 && $res <= 9) {
      echo 'Yes' . PHP_EOL;
      return;
    }
  }
  echo 'No' . PHP_EOL;


Measured memory_bytes: 4728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC115
{
    class Program
    {
        static void Main(string[] args)
        {
            int D;
            D = int.Parse(Console.ReadLine());

            if (D==25)
                Console.WriteLine("Christmas");

            else if (D==24)
                Console.WriteLine("Christmas Eve");

            else if (D==23)
                Console.WriteLine("Christmas Eve Eve");

            else if(D==22)
                Console.WriteLine("Christmas Eve Eve Eve");
            Console.ReadKey();
        }

    }
}


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

using str = string;
using ss = stringstream;

int a[26];

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

    str s;
    cin>>s;

    for(int i=0;i<s.size();i++)a[s[i]-'a']++;
    
    char ans=0;

    for(int i=0;i<26;i++)if(a[i]==0)
    {
        ans=i+'a';
        break;
    }

    if(ans==0)cout<<"None\n";
    else cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3756
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
char s[2010];
int n,m,l[2010][2010],r[2010][2010],h[2010][2010],a[2010][2010];
inline int read()
{
	char c=getchar();int x=0,flag=1;
	while(!isdigit(c)) flag*=c=='-'?-1:1,c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return x*flag;
}
void init(int x)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]==x) l[i][j]=0;
            else l[i][j]=l[i][j-1]+1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=m;j>=1;j--)
        {
            if(a[i][j]==x) r[i][j]=0;
            else r[i][j]=r[i][j+1]+1;
        }
    }
}
int main()
{
	n=read(),m=read();
	int ans=0;
	for(int i=1;i<=n;i++) 
	{
		scanf("%s",s+1);
		for(int j=1;j<=m;j++) a[i][j]=s[j]=='#';
	}
	for(int i=1;i<=n;i++)
		for(int j=m;j>=1;j--) a[i][j]=a[i][j]^a[i][j-1];
	for(int i=n;i>=1;i--)
		for(int j=1;j<=m;j++) a[i][j]=a[i][j]==a[i-1][j];
	init(0);
//	for(int i=1;i<=n;i++)
//	{
//		for(int j=1;j<=m;j++) cout<<a[i][j]<<' ';
//		cout<<endl;
//	}
	for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]) h[i][j]=h[i-1][j]+1;
            else h[i][j]=0;
            if(a[i-1][j]) l[i][j]=min(l[i-1][j],l[i][j]);
            if(a[i-1][j]) r[i][j]=min(r[i-1][j],r[i][j]);
        //    ans=max(ans,(h[i][j])*(l[i][j]+r[i][j]-1));
        	int x=i-h[i][j],y=j-l[i][j],xx=i,yy=j+r[i][j]-1;
        	x=max(x,1);
        	y=max(y,1);
        	ans=max(ans,(xx-x+1)*(yy-y+1));
        }
    }
    cout<<max(max(ans,n),m);
	return 0;
}


Measured memory_bytes: 63360
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main()
{


  int i;
  char ch;
  int count[26];



  for (i = 0;i<26;i++){
       count[i]=0;
  }

  while(scanf("%c",&ch) != EOF){
    ch = tolower(ch);
    if(isalpha(ch)){
  count[ch-'a']=count[ch-'a']+1;
}
}








  for (i=0; i<26;i++){
   printf("%c : %d\n",i+'a',count[i]);
  }


return(0);

}

Measured memory_bytes: 548
import java.util.Arrays;
import java.util.Scanner;

/**
 * B - 0 or 1 Swap
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 最大値
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        int replaceCnt = 0;
        String result = "YES";

        for( int i = 0; i < n; i++ ) {
            p[i] = sc.nextInt();
            q[i] = p[i];
        }

//        String beforeStr = Arrays.toString( p );
//        System.out.println( "beforeStr : " + beforeStr);
        Arrays.sort( q );
//        String sortStr = Arrays.toString( p );
//        System.out.println( "sortStr : " + sortStr);
        for( int i = 0; i < n; i++ ) {
//            System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
            if( p[i] != q[i] ) {
//                System.out.println( "replaceCnt++" );
                replaceCnt++;
//                System.out.println( "beforeStr - " + beforeStr.charAt( i ) + ": sortStr - " + sortStr.charAt( i ) + ": replaceCnt - " + replaceCnt);
                if( replaceCnt > 2 ) {
                    result = "NO";
                    break;
                }
            }
        }

        System.out.println( result );

        sc.close();
    }
}

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

using namespace std;

int main()
{
    vector<int> X(3);
    cin >> X[0] >> X[1] >> X[2];
    int m = 0;
    do { m = max(m, 10 * X[0] + X[1] + X[2]); } while (next_permutation(X.begin(), X.end()));
    cout << m << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2 * N -1],dneg[2 * N -1];
bool X[N][N];

void recursive(int);
void printBoard(void);
void initialize(void);

int main()
{
  int i,j,k,r,c;
  initialize();
  for(i=0;i<N;i++)
  {
    for(j=0;j<N;j++)
    {
      X[i][j]=false;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++)
  {
    scanf("%d %d",&r,&c);
    X[r][c]=true;
  }
  recursive(0);
  return 0;
}

void recursive(int i)
{
  int j;
  if(i == N)
  {
    printBoard();
    return;
  }
  for(j=0;j<N;j++)
  {
    if(NOT_FREE==col[j] ||
      NOT_FREE==dpos[i+j] ||
      NOT_FREE==dneg[i - j + N - 1])
      {
        continue;
      }
      row[i]=j;
      col[j]=dpos[i + j]=dneg[i - j + N - 1]=NOT_FREE;
      recursive(i+1);
      row[i]=col[j]=dpos[i + j]=dneg[i - j + N - 1]=FREE;
    }
}
void initialize()
{
  int i;
  for(i=0;i<N;i++)
  {
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<2*N-1;i++)
  {
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}
void printBoard()
{
  int i,j;
  for(i=0;i<N;i++)
  {
    for(j=0;j<N;j++)
    {
      if(X[i][j])
      {
        if(row[i]!=j)
        return;
      }
    }
  }
  for(i=0;i<N;i++)
  {
    for(j=0;j<N;j++)
    {
      if(row[i]==j)
      {
        printf("Q");
      }
      else
      {
        printf(".");
      }
    }
    printf("\n");
  }
}



Measured memory_bytes: 2108
#!/usr/bin/env python3

import array
import collections
import fractions
import math


def sieve_of_eratosthenes(end, typecode="Q"):
    assert end > 1
    is_prime = array.array("B", (True for i in range(end)))
    is_prime[0] = False
    is_prime[1] = False
    primes = array.array(typecode)
    for i in range(2, end):
        if is_prime[i]:
            primes.append(i)
            for j in range(2 * i, end, i):
                is_prime[j] = False
    return primes


def factorize_trial_division(n, typecode="Q"):
    factors = array.array(typecode)
    if n < 2:
        return factors
    for p in sieve_of_eratosthenes(math.ceil(math.sqrt(n)) + 1):
        if p * p > n:
            break
        while n % p == 0:
            factors.append(p)
            n //= p
    if n > 1:
        factors.append(n)
    return factors


def compute_max_size(a, b):
    g = fractions.gcd(a, b)
    fs = factorize_trial_division(g)
    ctr = collections.Counter(fs)
    res = len(ctr) + 1
    return res


def main():
    a, b = (int(c) for c in input().split())
    res = compute_max_size(a, b)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 6848
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int a[15];
    for(int i=0;i<15;i++){
        a[i]=10000000;
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            a[i] = 1;
        }else if(s[i]=='2'){
            a[i] = 2;
        }else if(s[i]=='3'){
            a[i] = 3;
        }else if(s[i]=='4'){
            a[i] = 4;
        }else if(s[i]=='5'){
            a[i] = 5;
        }else if(s[i]=='6'){
            a[i] = 6;
        }else if(s[i]=='7'){
            a[i] = 7;
        }else if(s[i]=='8'){
            a[i] = 8;
        }else if(s[i]=='9'){
            a[i] = 9;
        }
    }
    int ans=10000000,sa=0;
    for(int i=0;i<s.size();i++){
        sa = abs(100*a[i]+10*a[i+1]+a[i+2]-753);
        ans = min(sa,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
  string str;
  cin >> str;
  int kind=0;
  bool f=false;
  map<char,int>a;
  
  for(int i=0;i<str.size();i++){
    if(a.count(str[i])==0){
      kind++;
      a[str[i]]=0;
    }
    a[str[i]]++;
  }

  if((kind==2&&str.size()==2)||str.size()==1)
    f=true;
  
  if(a['a']==a['b']&&a['b']==a['c'])
    f=true;
  if(a['a']-1==a['b']&&a['b']==a['c'])
    f=true;
  if(a['a']==a['b']-1&&a['a']==a['c'])
    f=true;
  if(a['a']==a['b']&&a['b']-1==a['c'])
    f=true;
  if(a['a']==a['b']&&a['b']==a['c']-1)
    f=true;
  if(a['a']==a['b']-1&&a['b']==a['c'])
    f=true;
  if(a['a']-1==a['b']&&a['a']==a['c'])
    f=true;
  
  if(f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define MAX 3000
#define ll long long
ll fun(ll a[],ll dp[][MAX], int l,int r)
{
    if(dp[l][r]!=-1) return dp[l][r]; // means already calculated
    if(r==l+1) return max(a[l],a[r]);
    if(r==l) return a[l];
    if(l>r) return 0;
    ll option1 = a[l] + min(fun(a,dp, l+2,r), fun(a,dp,l+1,r-1));
    ll option2 = a[r] + min(fun(a,dp, l+1,r-1), fun(a,dp,l,r-2));
    dp[l][r] = max(option1, option2);
    return dp[l][r];
}
int main()
{
        int n;
        cin >> n;
        ll a[n];
      	ll dp[n][MAX];
        memset(dp, -1, sizeof(dp)); //set every element to -1
        int i;
      	ll sum = 0;
        for(i=0;i<n;i++)
        {
            cin >> a[i];
            sum+=a[i];
        }
        cout << 2*fun(a,dp,0,n-1)-sum << endl;

}


Measured memory_bytes: 70784
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
	int n;
	vector<int> v;//白:正,黒:負
	while(cin>>n,n){
		int c;
		v.clear();
		v.push_back(0);
		for(int i=1;i<=n;i++){
			cin>>c;
			if(c==0){//白
				if(i&1){
					if(0<v.back())++v.back();
					else v.push_back(1);
				}
				else{
					if(0<v.back())++v.back();
					else {
						int a=-v.back();v.pop_back();
						if(v.empty())v.push_back(a+1);
						else v.back() += a+1;
					}
				}
			}
			else{//黒
				if(i&1){
					if(0<=v.back())v.push_back(-1);
					else --v.back();
				}
				else{
					if(0<v.back()){
						int a= v.back();v.pop_back();
						if(v.empty())v.push_back(-(a+1));
						else v.back() -= a+1;
					}
					else {
						--v.back();
					}
				}
			}
		}
		int ans=0;
		rep(i,v.size()){
			if(0<v[i])ans+=v[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string a;
    cin>>a;
    for (int i = 6; i >= 0;i--){
        if(s[i]==a){
            cout << 7 - i << endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define r0 return 0;
#define f(k,i,n,j) for(ll k=i;k<=n;k=k+j)
#define cin(a) cin>>a;
#define loop while(t--)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
int main()
{
    ll h;
    cin>>h;
    ll ans=0,c=1;
    while(h>0)
    {
        ans+=c;
        h/=2;
        c=c*2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2e5+2;
vll dp(maxn,-1);

ll fun(vll &h, ll n, ll pos)
{
    if(pos==0) return 0;
    if(pos==1) return dp[pos]=fabs(h[0]-h[1]);
    if(dp[pos]!=-1)
    return dp[pos];

    if(pos>1)
    return dp[pos]=min(fabs(h[pos]-h[pos-1])+fun(h,n,pos-1),fabs(h[pos]-h[pos-2])+fun(h,n,pos-2));
}

int main()
{
    fastio; //remove for interactive
    ll i, j, k, n, m, t;
    vll h;

    cin>>n;
    for ( i = 0; i < n; i++)
    {
        cin>>j;
        h.pb(j);
    }

    cout<<fun(h,n,n-1)<<endl;
    
        
    return 0;
}

Measured memory_bytes: 8704
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& operator()(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) (*this)(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { ((*this)(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
// clang-format on





auto Main() {
	int n;
	cin>>n;
	unordered_map<string, int> M;
	FOR(ni,0,n) {
		string s;
		cin>>s;
		M[s]++;
	}
	for (auto x : {"AC", "WA", "TLE", "RE"}) {
		Cout(x, 'x', M[x]);
	}	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


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

int main(int argc, char const *argv[])
{
    int h, w;
    while(1) {
        cin >> h >> w;
        if(h==0 || w==0) break;
        for(int i=0; i<h; i++) {
            if(i==0 ||i==h-1){
                for(int j=0; j<w; j++) {
                    cout << '#';
                }
                cout << endl;
            }else{
                for(int j=0; j<w; j++) {
                    if(j==0 || j==w-1)
                        cout << '#';
                    else
                        cout << '.';
                }
                cout << endl;
            }
        }   
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3064