akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}

int main() {
	ll k;
	cin >> k;
	ll res = 0;
	queue<ll> que;
	for (ll i = 1; i < 10; i++) {
		que.push(i);
	}
	rep(i, k) {
		res = que.front();
		que.pop();
		if (res % 10 != 0) {
			que.push(10 * res + (res % 10) - 1);
		}
		que.push(10 * res + (res % 10));
		if (res % 10 != 9) {
			que.push(10 * res + (res % 10) + 1);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 5164
import bisect
import itertools
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, x = ril()
ls = sorted(ril())
acc = list(itertools.accumulate(ls))
i = bisect.bisect(acc, x)
if i == len(acc):
    if x > acc[-1]:
        i -= 1
print(i)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
using namespace std;
int main()
{
	IOS;
	int t=1;
	//cin >> t;
	while (t--) 
	{
		string s;
		cin>>s;
		int i,l=0,ans=0;
		for(i=0;i<3;i++)
		{
			if(s[i]=='R') {
				l++;
				if(i==2||s[i+1]=='S')
				{
					ans=max(ans,l);
					l=0;
				}
			}
			
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

A,B=LI()
res = A-B*2
print(res if res > 0 else 0)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
char a[105];int k,i,j;
int main()
{cin>>a;
k=strlen(a);
for(i=0;i<k;i++)
  {if(a[i]=='C')
    for(j=i+1;j<k;j++)
      if(a[j]=='F')
        {cout<<"Yes"<<endl; 
        return 0;
        }
  }
return cout<<"No"<<endl,0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {
	
	ll A, B, C;
	cin >> A >> B >> C;

	if (A + B + C <= 21) {
		cout << "win";
	}
	else {
		cout << "bust";
	}

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


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

using namespace std;
typedef pair<int ,int > P;

struct Node {
    int value;
    Node *next;
    Node *prev;
};
Node *nil;

void init() {
    nil = new Node();
    nil->next = nil;
    nil->prev = nil;
}

void insert_node(int x) {
    Node *p = new Node;
    p->value = x;

    p->next = nil->next;
    nil->next->prev=p;
    nil->next=p;
    p->prev=nil;
}

Node* search_node(int x) {
    Node *cur = nil->next;
    while(cur != nil && cur->value != x) cur = cur->next;
    return cur;
}

void delete_node(Node *p) {
    if(p == nil) return;
    p->prev->next=p->next;
    p->next->prev=p->prev;
    delete p;
}
void delete_first_node() {
    delete_node(nil->next);
}
void delete_last_node() {
    delete_node(nil->prev);
}
void delete_key_node(int x) {
    delete_node(search_node(x));
}

int main() {
    ios::sync_with_stdio(false);
    init();
    int n;
    string q;
    cin>>n;
    while(n--) {
        int x;
        cin>>q;
        if(q=="insert") {
            cin>>x;
            insert_node(x);
        }
        else if(q=="delete") {
            cin>>x;
            delete_key_node(x);
        }
        else if(q=="deleteFirst") {
            delete_first_node();
        }
        else if(q=="deleteLast") {
            delete_last_node();
        }
    }
    int t=0;
    Node *cur = nil->next;
    while(cur != nil) {
        if(t++) cout<<" ";
        cout<<cur->value;
        cur=cur->next;
    }
    cout<<endl;
    
    return 0;
}

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

int main(){
    int n;
    string s,t;
    cin >> n;
    cin >> s >> t;
    deque<char> sdeq,tdeq;
    rp(i,n){
        sdeq.push_back(s.at(i));
        tdeq.push_back(t.at(i));
    }
    rp(i,n){
        cout << sdeq.front() << tdeq.front();
        sdeq.pop_front();
        tdeq.pop_front();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
D = deque([])
for i in map(str,input().split()):
    if i.isdecimal():
        D.append(i)
    else:
        i1 = D.pop()
        i2 = D.pop()
        D.append(str(eval(i2+i+i1)))
else:
    print(D.pop())


Measured memory_bytes: 5968
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    fp((n == 3)||(n == 5)||(n == 7),"YES","NO");
    return 0;
}

Measured memory_bytes: 256
def solve(N, strX):
    def getNum1s(numD):
        num1s = [0] * (1<<numD)
        for S in range(1, 1<<numD):
            num1s[S] = num1s[S ^ (S & -S)] + 1
        return num1s
    num1s = getNum1s(20)

    fs = [0] * (N+1)
    for x in range(1, N+1):
        fs[x] = fs[x%num1s[x]] + 1

    M = strX.count('1')
    M1, M9 = M+1, M-1

    XmodM1 = 0
    for X in strX:
        XmodM1 *= 2
        XmodM1 += int(X)
        XmodM1 %= M1
    XmodM9 = 0
    for X in strX:
        XmodM9 *= 2
        XmodM9 += int(X)
        XmodM9 %= M9

    modM1s = []
    modM1 = 1
    for d in range(N+2):
        modM1s.append(modM1)
        modM1 *= 2
        modM1 %= M1

    modM9s = []
    modM9 = 1
    for d in range(N+2):
        modM9s.append(modM9)
        modM9 *= 2
        modM9 %= M9

    anss = []
    for X, modM1, modM9 in zip(strX[::-1], modM1s, modM9s):
        if X == '0':
            Y2 = (XmodM1 + modM1) % M1
        else:
            Y2 = (XmodM9 - modM9) % M9
        ans = fs[Y2] + 1
        anss.append(ans)

    return anss[::-1]


def solve2(N, strX):
    def getNum1s(numD):
        num1s = [0] * (1<<numD)
        for S in range(1, 1<<numD):
            num1s[S] = num1s[S ^ (S & -S)] + 1
        return num1s
    num1s = getNum1s(20)

    fs = [0] * (N+1)
    for x in range(1, N+1):
        fs[x] = fs[x%num1s[x]] + 1

    M = strX.count('1')
    M1, M9 = M+1, M-1

    XmodM1 = 0
    for X in strX:
        XmodM1 *= 2
        XmodM1 += int(X)
        XmodM1 %= M1

    modM1s = []
    modM1 = 1
    for d in range(N+2):
        modM1s.append(modM1)
        modM1 *= 2
        modM1 %= M1

    anss = []
    for X, modM1 in zip(strX[::-1], modM1s):
        if X == '0':
            Y2 = (XmodM1 + modM1) % M1
            ans = fs[Y2] + 1
        else:
            ans = 0
        anss.append(ans)

    return anss[::-1]


N = int(input())
strX = input().rstrip()

num1 = strX.count('1')

if num1 == 0:
    anss = [1] * N
elif num1 == 1:
    anss = solve2(N, strX)
else:
    anss = solve(N, strX)

print('\n'.join(map(str, anss)))


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

int main(){
  int n,m;
  cin >> n >> m;
  int a[m];
  int sum=0;
  for(int i=0;i<m;i++){
    cin>>a[i];
    sum+=a[i];
  }
  if(sum>n) cout << -1;
  else{
    if(sum==n) cout << 0;
    else cout << n-sum;
  }
  return 0;
}

Measured memory_bytes: 3636
object Main {
    def divisors(n: Int) =
        (1 to math.sqrt(n).toInt).flatMap(m =>
            if (n % m == 0 && m * m == n) List(m)
            else if (n % m == 0) List(m, n / m)
            else Nil
        )
    def main(args: Array[String]) = {
        val in = io.StdIn.readLine.split(" ").map(_.toInt)
        println((in(0) to in(1)).count(divisors(in(2)).contains))
    }
}

Measured memory_bytes: 45844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        //Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String firstLine = br.readLine();
        String[] firstSplit = firstLine.split(" ");
        int N = Integer.parseInt(firstSplit[0]);
        int Q = Integer.parseInt(firstSplit[1]);

        Box[] boxes = new Box[N];
        for(int i = 0; i<N; i++) boxes[i] = new Box();
        boxes[0].hasRed = true;

        for(int i = 0; i<Q; i++){
            String line = br.readLine();
            String[] split = line.split(" ");
            int a = Integer.parseInt(split[0]);
            int b = Integer.parseInt(split[1]);
            a--;
            b--;

            if(boxes[a].hasRed){
                if(boxes[a].balls == 1) boxes[a].hasRed = false;
                boxes[b].hasRed = true;
            }
            boxes[a].balls--;
            boxes[b].balls++;
        }

        //count
        int total = 0;
        for(Box b : boxes){
            if(b.hasRed) total++;
        }
        System.out.println(total);
    }
}

class Box{
    int balls;
    boolean hasRed;
    Box(){
        balls = 1;
        hasRed = false;
    }
}

Measured memory_bytes: 24300
#include <bits/stdc++.h>
using namespace std;
using pt = pair<double, double>; // x,y

void koch( int n, pt p1, pt p2 ) {
	if( n == 0 ) {
		return;
	}

	double cosine = cos( 60 * 3.141592653589793 / 180 );
	double sine = sin( 60 * 3.141592653589793 / 180 );

	pt s = { (2*p1.first + p2.first) / 3.0, (2*p1.second + p2.second) / 3.0 };
	pt t = { (p1.first + 2*p2.first) / 3.0, (p1.second + 2*p2.second) / 3.0 };
	pt u = {
		(t.first - s.first) * cosine - (t.second - s.second) * sine + s.first,
		(t.first - s.first) * sine + (t.second - s.second) * cosine + s.second
	};

	koch( n-1, p1, s );
	cout << s.first << ' ' << s.second << '\n';
	koch( n-1, s, u );
	cout << u.first << ' ' << u.second << '\n';
	koch( n-1, u, t );
	cout << t.first << ' ' << t.second << '\n';
	koch( n-1, t, p2 );
}

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

	int n;
	cin >> n;

	cout << fixed << setprecision( 8 );
	cout << 0.0 << ' ' << 0.0 << '\n';
	koch( n, { 0,0 }, { 100,0 } );
	cout << 100.0 << ' ' << 0.0 << '\n';
}



Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  string a,b;
  cin >> a >> b;
  if(a.at(0)==b.at(2)&&a.at(1)==b.at(1)&&a.at(2)==b.at(0))  cout << "YES" << endl;
  else  cout << "NO"  << endl;

  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

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

	vector<int> memo(n + 1);
	for (int i = 0; i < n; i++) {
		memo[i + 1] = memo[i] + (i + 1 < n && s[i] == 'A' && s[i + 1] == 'C');
	}

	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << memo[r] - memo[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 1488
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n=int(input())
a=sorted(list(map(int,input().split())))
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 0
for i in a[::-1]:
    find = twosum(i)
    if d[i] <= 0:
        continue
    d[i] -= 1
    if d[find] <= 0:
        d[i] += 1
    else:
        ans += 1
        d[find] -= 1
print(ans)

Measured memory_bytes: 113492
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = numeric_limits<ll>::max();


int main(){
    int N;
    string S;
    cin >> N >> S;

    ll R_cnt = 0, G_cnt = 0, B_cnt = 0;
    REP(i, 0, N){
        if (S[i] == 'R')
            ++R_cnt;
        else if (S[i] == 'G')
            ++G_cnt;
        else 
            ++B_cnt;
    }

    ll sum = R_cnt * G_cnt * B_cnt;

    REP(i, 0, N){
        REP(j, i + 1, N){
            int k = j + j - i;
            if (k >= N)
                break;
            if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i])
                --sum;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3620
/**
 * @author twason
 *
 * Problem A: Keitai Message
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2006
 *
 * Main.java
 * 2017/10/11
 *
 */ 

import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		// ???????????????????????°???????????????
		Scanner scanner = new Scanner(System.in);
		int caseCount;
		caseCount = Integer.parseInt(scanner.nextLine());

		Keitai keitai = new Keitai();	// ????????????????????????

		// ?????????????????????????????????
		// ??\??????????????????????????????????????????????????????????????°?????????
		for (int i = 0; i < caseCount; i++) {
			System.out.println(keitai.getMessage(scanner.nextLine()));
		}

		scanner.close();
	}
}

/**
 *  ???????????????
 *  ??\????????????????????????????????????????????????????????????...?
 *  ??????????????±??????????????£?????????????????????????????????????????§Main??§??¨??¨??????
 */
class Keitai {
	private static final int PATTERNLEN_MAX = 1024;		// ??\???????????????????????§???
	private static final int STRLEN_MAX = 75;		// ????????????????????????????????§??? 
	private static final String[] characters = {
		"",
		".,!? ",
		"abc",
		"def",
		"ghi",
		"jkl",
		"mno",
		"pqrs",
		"tuv",
		"wxyz"
	};	// ????????¨

	private static Scanner scanner;

	/**
	 *  ????????????????????????????????????????????????????????????????????????????????????
     *  @param pattern ???????????\???????????????
	 */ 
	public String getMessage(String pattern) {
		// ???????????????????????????????????????????????????
		String message = this.convertPatternToMessage(pattern);  
		return message;
	}

	/**
	 * ???????????\????????????????????????????????????????????????
	 * @param pattern ???????????\???????????????
	 */ 
	private String convertPatternToMessage(String pattern) {
		String result = "";	// ???????????????????????????

		char[] patternArray = pattern.toCharArray();	//??\???????????????(String)???char??????????????????

		char row;	// ????????¨??????
		int col;	// ????????¨??????

		int cursor = 0;	// ?????????????????°?????????????????????

		// 1??????????????????(?????????????????\??????????????????????????? or ????????????????????§???????¶????????????§?????????)
		while (cursor < patternArray.length && cursor < this.PATTERNLEN_MAX) {		
			// ???????????????????????????????????????
			if (patternArray[cursor] != '0') {
				row = patternArray[cursor];	// ??????????????? = ????????¨??????
				col = 0;					// ??°??????????????°???= ????????¨??????
				cursor++;			

				// ???????????????????????????????????????(?¢?????????????:0????????????????????§????????????)
				while (patternArray[cursor] != '0' &&  (cursor < patternArray.length && cursor < this.PATTERNLEN_MAX)) {
						col++;
						cursor++;
				}
				col = col % (characters[Character.getNumericValue(row)].toCharArray().length);	// ????????¨???row???????????°??§??°??????????????°???mod?????????
				result += characters[Character.getNumericValue(row)].toCharArray()[col];		// result += ????????¨[row][col]
			} else {
				// ??????????¢?????????????????????\???????????±???
				cursor++;
			}
		}
		return result;
	}
} 
	

Measured memory_bytes: 31512
def main():
    N = int(input())
    A = [input()]
    for i in range(1, N):
        W = input()
        if A[-1][-1] == W[0]:
            for j in range(i):
                if A[j] == W:
                    print("No")
                    return
            A.append(W)
        else:
            print("No")
            return
    print("Yes")

main()

Measured memory_bytes: 2940
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n = int(input().strip())
    a = list(map(int, input().strip().split()))
    for i in range(n):
        if a[i] % 2 == 0:
            if a[i] % 3 ==0 or a[i] %5==0:
                pass
            else:
                print("DENIED")
                return
    print("APPROVED")


if __name__ == '__main__':
    main()

Measured memory_bytes: 61420
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int xx[20][20],yy[20][20];


int b(int a,int b){
    int res=a;
    for(int i=1;i<b;i++){
        res*=a;
    }
    return res;
}

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

    int n;
    cin>>n;
    int a[n];
    int res=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            cin>>xx[i][j]>>yy[i][j];
        }
    }
    for(int x=0;x<b(2,n);x++){
        //cout<<x<<endl;
        int ar[n];
        int tmp=0;
        for(int i=0;i<n;i++){
            if(((x>>i)&1)==1){
                ar[i]=1;
                tmp++;
            }
            else{
                ar[i]=0;
            }
            //cout<<ar[i]<<" ";
        }
        //cout<<endl;
        bool is=true;
        for(int i=0;i<n;i++){
            if(ar[i]==0){
                continue;
            }
            int ai = a[i];
            //cout<<"ai "<<ai<<endl;
            for(int j=0;j<ai;j++){
                int xi=xx[i][j]-1,yi=yy[i][j];
                if(yi==0&&ar[xi]==1){
                    is=false;
                    break;
                }
                else if(yi==1&&ar[xi]==0){
                    is=false;
                    break;
                }
            }
        }
        if(is){
            res=max(res,tmp);
        }
        //cout<<"test"<<endl;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
const int maxn = 2e5 + 7;

int n, t[maxn], m, p[maxn], x[maxn], sum, ans = inf;

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> t[i], sum += t[i];
	cin >> m;
	for (int i = 1; i <= m; i++){
		cin >> p[i] >> x[i];
		int j = p[i], s = x[i], cur = sum;
		int cnt = cur - t[j] + s;
		cout << cnt << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

cnt = 0
max_cnt = 0

for i in range(len(H)-1):
    if H[i] >= H[i+1]:
        cnt += 1
        max_cnt = max(max_cnt, cnt)
    else:
        cnt = 0

print(max_cnt)

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

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

Measured memory_bytes: 256
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
A = [A11, A12, A13, A21, A22, A23, A31, A32, A33]
N = int(input())
for _ in range(N):
  b = int(input())
  if b in A:
    A[A.index(b)] = 0

if A[0]==0 and A[1]==0 and A[2]==0:
  print("Yes")
elif A[3]==0 and A[4]==0 and A[5]==0:
  print("Yes")
elif A[6]==0 and A[7]==0 and A[8]==0:
  print("Yes")
elif A[0]==0 and A[3]==0 and A[6]==0:
  print("Yes")
elif A[1]==0 and A[4]==0 and A[7]==0:
  print("Yes")
elif A[2]==0 and A[5]==0 and A[8]==0:
  print("Yes")
elif A[0]==0 and A[4]==0 and A[8]==0:
  print("Yes")
elif A[2]==0 and A[4]==0 and A[6]==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli n;
	cin>>n;
	string s[n];
	lli i,count0=0,count1=0,count2=0,count3=0;
	fr(i,n)
	{
		cin>>s[i];
		if(s[i]=="AC")
			count0++;
		else if(s[i]=="WA")
			count1++;
		else if(s[i]=="TLE")
			count2++;
		else
			count3++;
	}
	cout<<"AC x "<<count0<<"\n"<<"WA x "<<count1<<"\n"<<"TLE x "<<count2<<"\n"<<"RE x "<<count3;
	
	return 0;
}

Measured memory_bytes: 6784
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif 65 <= m + f:
        print('B')
    elif 50 <= m + f:
        print('C')
    elif 30 <= m + f:
        if r >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')


Measured memory_bytes: 5596
#include <stdio.h>
int main(){
 int a, b, c, i, cnt, k, u; cnt = 0;
 scanf("%d %d %d", &a, &b, &c);
 for(i = a; i <= b; i++){
  for(k = 1; k <= c; k++){
   if(c % k == 0 && i == k) cnt++;
  }
 }
 printf("%d\n", cnt);
 return 0;
}

Measured memory_bytes: 1852
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iterator>

typedef long long ll;
using namespace std;

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

    ll m = min(X, Y);
    ll d = max(X, Y) - m;

    ll money = 0;

    if (A+B >= 2*C) money += (2*C)*m;
    else money += (A+B)*m;

    if (X >= Y) {
        if (A >= 2*C) money += d*2*C;
        else money += d*A;
    }
    else {
        if (B >= 2*C) money += d*2*C;
        else money += d*B;
    }

    cout << money << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char s[50],sc[50];
  int sa,n,k,i;
  scanf("%d %d",&n,&k);
  scanf("%s",s);
  sa='A'-'a';
  for(i=0;i<n;i++){
    if(i==k-1){
      sc[i]=s[i]-sa;
    }
    else{
      sc[i]=s[i];
    }
  }
  sc[i]='\0';
  printf("%s",sc);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define pb push_back
#define int long long
#define debug(n) cerr << #n << " = " << n << '\n';
 
using namespace std;
const int MAXN = 3e3 + 10;
int dp[MAXN][MAXN];
int32_t main() {
    string s,t,ans;
    cin >> s >> t;    
    int n = s.size() , m = t.size();
    bool p1 = false , p2 = false;  
    for(int i = 0; i < n; i++) {
        if(t[0] == s[i])
            p1 = true;
        if(p1) 
            dp[i][0] = 1;
    }
    for(int j = 0; j < m; j++) {
        if(s[0] == t[j]) 
            p2 = true;
        if(p2)
            dp[0][j] = 1;
    }
    for(int i = 1; i < n; i++) 
        for(int j = 1; j < m; j++) {
            if(s[i] == t[j])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j] , dp[i][j - 1]);
        }
    int po1 = n - 1 , po2 = m - 1;
    if(n - 1 == 0)
        if(dp[n - 1][m - 1] != 0)
            return cout << s[0] , 0;
    if(m - 1 == 0)
        if(dp[n - 1][m - 1] != 0)
            return cout << t[0] , 0;
    while(true) {        
        if(dp[po1][po2] == 0)
            break;
        if(dp[po1][po2] == dp[po1 - 1][po2])
            po1--;
        else if(dp[po1][po2] == dp[po1][po2 - 1])
            po2--;
        else
           ans += s[po1] , po1-- , po2--; 
        if(dp[po1][po2] == 0)
            break;
        if(po1 <= 0) {
            ans += s[po1];
            break;
        }
        if(po2 <= 0) {
            ans += t[po2];
            break;
        }
    }
    reverse(ans.begin() , ans.end());
    cout << ans;
    return 0;
}


Measured memory_bytes: 74128
cards = {
	"S":[0]*13,
	"H":[0]*13,
	"C":[0]*13,
	"D":[0]*13
}

n = int(input())

for i in range(n):
	s, num = input().split()
	cards[s][int(num)-1] = 1
	
for i in ["S", "H", "C", "D"]:
	for j in range(13):
		if cards[i][j] == 0:
			print(i,j+1)

Measured memory_bytes: 7664
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

void solve()
{
    int r,g;
    scanf("%d%d", &r, &g);
    printf("%d\n", g+(g-r));


    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 128
N = int(input())
D = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for _ in range(N):
  D[input()] += 1
print("AC x {}".format(D["AC"]))
print("WA x {}".format(D["WA"]))
print("TLE x {}".format(D["TLE"]))
print("RE x {}".format(D["RE"]))

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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  ll sum[n];
  sum[0]=a[0];
  for(int i=1;i<n;i++){
    sum[i]=sum[i-1]+a[i];
  }
  int x=-1;
  for(int i=0;i<n-1;i++){
    if(2*sum[i]<a[i+1]){
      x=i;
    }
  }
  cout << n-x-1 << endl;
}


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

const int P = 998244353; int N , M , jc[2000003] , inv[2000003];
int poww(long long a , int b){
	int times = 1;
	while(b){if(b & 1) times = times * a % P; a = a * a % P; b >>= 1;}
	return times;
}

int C(int a , int b){return 1ll * jc[a] * inv[b] % P * inv[a - b] % P;}

signed main(){
	scanf("%d %d" , &N , &M); int ans = max(N , M); jc[0] = 1;
	for(int i = 1 ; i <= 2 * ans ; ++i) jc[i] = 1ll * jc[i - 1] * i % P;
	inv[2 * ans] = poww(jc[2 * ans] , P - 2);
	for(int i = 2 * ans - 1 ; i >= 0 ; --i) inv[i] = inv[i + 1] * (i + 1ll) % P;
	for(int i = 1 ; i <= min(N , M) ; ++i)
		ans = (ans + 1ll * C(N + M - 2 * i , N - i) * C(2 * i , i) % P * ((P + 1) / 2) % P * poww(C(N + M, N) , P - 2)) % P;
	cout << ans << endl; return 0;
}

Measured memory_bytes: 10496
# https://atcoder.jp/contests/abc140/tasks
import itertools
 
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

# 組み合わせ抽出
pattern = list(itertools.permutations(P))

# 順番
dct = sorted(pattern)

a = 0
b = 0

for i in range(len(pattern)):
    if list(dct[i]) == P:
        a = i
    if list(dct[i]) == Q:
        b = i

print(abs(a-b))

Measured memory_bytes: 8308
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void){
    int i, ANS=0, CNT=0;
    char S[15];
    scanf("%s", S);
    for(i=0; S[i]!='\0'; i++){
        if(S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T'){
            CNT++;
            if(CNT > ANS) ANS = CNT;
        }
        else CNT = 0;
    }
    printf("%d\n", ANS);
    return 0;
}


Measured memory_bytes: 128
def popcount(x):
    xb = bin(x)
    return xb.count("1")
def solve(x, count_1):
    temp = x %count_1
    if(temp == 0):
        return 1
    else:
        return 1 + solve(temp, popcount(temp))
n = int(input())
x = input()
x_b = int(x, 2)
mod = x.count("1")
xm1 = x_b %(mod+1)
if(mod != 1):
    xm2 = x_b %(mod-1)
for i in range(n):
    if(x[i] == "0"):
        mi = (((pow(2, n-1-i, mod+1) + xm1) % (mod+1)))
        if(mi == 0):
            print(1)
        else:
            print(1 + solve(mi, popcount(mi)))
    else:
        if(mod == 1):
            print(0)
        else:
            mi = ((xm2-pow(2, n-1-i, mod-1)) % (mod-1))
            if((x_b - xm2 == 0)):
                print(0)
            elif(mi == 0):
                print(1)
            else:
                print(1 + solve(mi, popcount(mi)))

Measured memory_bytes: 80240
#include <cstdio>
#include <vector>

using namespace std;

const int N = 100'009;

vector<int> g[N];
int pa[N];
int q[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    g[i].clear();
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; ++i) {
    pa[i] = -1;
  }
  pa[0] = 0;
  q[0] = 0;
  for (int qh = 0, qt = 1; qh < qt; ++qh) {
    int x = q[qh];
    for (int y : g[x]) {
      if (pa[y] == -1) {
        pa[y] = x;
        q[qt++] = y;
      }
    }
  }
  puts("Yes");
  for (int i = 1; i < n; ++i) {
    printf("%d\n", pa[i] + 1);
  }
}


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

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

enum Dir {
	TOP,
	BOTTOM,
	FRONT,
	BACK,
	LEFT,
	RIGHT
};

int trans[6] = { -1, -1, 3, 1, 2, 0 };
int memo[6][4] = { { 3,5,4,2 },{ 3,1,4,6 },{ 1,2,6,5 },{ 1,5,6,2 },{ 1,3,6,4 },{ 2,4,5,3 } };

class Dice {
public:
	Dice() { d.resize(6); }
	Dice(int top, int front) {
		d.resize(6);
		set(top, front);
	}
	int find(int num) const {
		for (int i = 0; i < 6; i++) if (num == d[i]) return i;
		assert(0);
		return -1;
	}
	int get(int dir) const {
		return d[dir];
	}
	void set(int top, int front) {
		d[TOP] = top;
		d[BOTTOM] = 7 - top;
		d[FRONT] = front;
		d[BACK] = 7 - front;
		int index = 0;
		for (; index < 4; index++) {
			if (memo[top - 1][index] == front) break;
		}
		d[RIGHT] = memo[top - 1][(index + 1) % 4];
		d[LEFT] = 7 - d[RIGHT];
	}
	void rotate(int dir) {
		vector<int> nd = d;
		if (dir == 0) {
			nd[TOP] = d[LEFT];
			nd[LEFT] = d[BOTTOM];
			nd[BOTTOM] = d[RIGHT];
			nd[RIGHT] = d[TOP];
		}
		if (dir == 1) {
			nd[TOP] = d[FRONT];
			nd[FRONT] = d[BOTTOM];
			nd[BOTTOM] = d[BACK];
			nd[BACK] = d[TOP];
		}
		if (dir == 2) {
			nd[TOP] = d[RIGHT];
			nd[RIGHT] = d[BOTTOM];
			nd[BOTTOM] = d[LEFT];
			nd[LEFT] = d[TOP];
		}
		if (dir == 3) {
			nd[TOP] = d[BACK];
			nd[BACK] = d[BOTTOM];
			nd[BOTTOM] = d[FRONT];
			nd[FRONT] = d[TOP];
		}
		d = nd;
	}
private:
	vector<int> d;
};

const int MAX = 110;
int field[MAX][MAX][MAX];

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n;
	while (cin >> n) {
		if (n == 0)break;
		memset(field, 0, sizeof(field));
		for (int i = 0; i < n; i++) {
			int t, f;
			cin >> t >> f;
			Dice dice(t, f);
			int y = MAX / 2, x = MAX / 2;
			for (int h = MAX - 1; h >= 0; ) {
				if (h == 0) {
					field[h][y][x] = dice.get(TOP);
					break;
				}
				if (field[h - 1][y][x] == 0) {
					h--;
					continue;
				}
				bool finish = true;
				for (int num = 6; num >= 4; num--) {
					int d = dice.find(num);
					if (d == BOTTOM || d == TOP) continue;
					int dir = trans[d];
					int ny = y + dy[dir], nx = x + dx[dir];
					if (field[h - 1][ny][nx] == 0) {
						dice.rotate(dir);
						h--;
						y = ny; x = nx;
						finish = false;
						break;
					}
				}
				if (finish) {
					field[h][y][x] = dice.get(TOP);
					break;
				}
			}
		}
		vector<int> ans(6);
		for (int y = 0; y < MAX; y++) for (int x = 0; x < MAX; x++) {
			for (int h = MAX - 1; h >= 0; h--) {
				if (field[h][y][x] > 0) {
					ans[field[h][y][x] - 1]++;
					break;
				}
			}
		}
		for (int i = 0; i < 6; i++) {
			cout << ans[i];
			if (i < 5) cout << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 8352
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI = 3.141592653589793;

void solve()
{
	int n,s;
	cin >> n >> s;
	string t[n];
	for(int i=0;i<n;i++)
	{
		cin >> t[i];
	}
	for(int i=0;i<n;i++)
	{
		cout << t[i] << nl << t[i] << nl;
	}
}

int32_t main()
{
	FastIO;
	Fast_D;
	solve();
	return 0;
}


Measured memory_bytes: 3636
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	
	nums := []int{a, b, c}
	sort.Ints(nums)
	
	if nums[0] % 2 == nums[1] % 2 && nums[1] % 2 == nums[2] % 2 {
		fmt.Println((nums[2] - nums[1]) / 2 + (nums[2] - nums[0]) / 2)
 	} else if nums[0] % 2 == nums[1] % 2 {
		nums[0]++
		nums[1]++
		fmt.Println((nums[2] - nums[1]) / 2 + (nums[2] - nums[0]) / 2 + 1)
	} else if nums[1] % 2 == nums[2] % 2 {
		nums[1]++
		nums[2]++
		fmt.Println((nums[2] - nums[1]) / 2 + (nums[2] - nums[0]) / 2 + 1)
	} else {
		nums[0]++
		nums[2]++
		fmt.Println((nums[2] - nums[1]) / 2 + (nums[2] - nums[0]) / 2 + 1)
	}
}

Measured memory_bytes: 1840
N, A, B, C, D = map(int, input().split())
A -= 1
B -= 1
C -= 1
D -= 1

s = input() + '.'

def solve():
    if C < D:
        cnt = 0
        for i in range(B, D):
            if s[i] == '#':
                cnt += 1
            else:
                cnt = 0
            if cnt > 1:
               return False 
        cnt = 0
        for i in range(A, C):
            if s[i] == '#':
                cnt += 1
            else:
                cnt = 0
            if cnt > 1:
               return False 
        return True
    else:
        cnt = 0
        flg = False
        for i in range(B, D+1):
            if s[i] == '#':
                cnt += 1
            else:
                if s[i-1] == '.' and s[i+1] == '.':
                    flg = True
                cnt = 0
            if cnt > 1:
               return False 

        if not flg:
            return False

        cnt = 0
        for i in range(A, C):
            if s[i] == '#':
                cnt += 1
            else:
                cnt = 0
            if cnt > 1:
               return False 
        return True

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

Measured memory_bytes: 41200
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n,m;
    cin>>n>>m;
    int ma=0;
    int sum=0;
    REP(i,m){
        int t;
        cin>>t;
        ma=max(ma,t);
        sum+=t;
    }
    cout<<max(0,ma-(sum-ma)-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

/**
 * @author Administrator
 * @date 2017/9/12
 */
public class Main {

    static class Node {
        int val;
        int num = 0;

        public int getVal() {
            return val;
        }

        public void setVal(int val) {
            this.val = val;
        }

        public int getNum() {
            return num;
        }

        public void setNum(int num) {
            this.num = num;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] arr = new int[n];
        Map map = new HashMap<>();
        for (int i = 0; i < n; i++) {

            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        HashSet<Object> set = new HashSet<>();
        for (int i = 0; i < arr.length; i++) {
            set.add(arr[i]);
        }
        if (set.size() <= k) {
            System.out.println(0);
            return;
        }
        Node[] nodes = new Node[set.size()];
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (i == 0) {
                nodes[count] = new Node();
                nodes[count].setVal(arr[i]);
                nodes[count].setNum(nodes[count].getNum() + 1);
            } else if (arr[i] == arr[i - 1]) {
                nodes[count].setNum(nodes[count].getNum() + 1);
            } else if (arr[i] != arr[i - 1]) {
                count += 1;
                nodes[count] = new Node();
                nodes[count].setVal(arr[i]);
                nodes[count].setNum(nodes[count].getNum() + 1);
            }
        }
        Arrays.sort(nodes, new Comparator<Node>() {

            @Override
            public int compare(Node o1, Node o2) {
                return o1.getNum() - o2.getNum();
            }
        });
        int sum = 0;
        for (int i = 0; i < set.size() - k; i++) {
            sum += nodes[i].num;
        }
        System.out.println(sum);
    }
}


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


void solve(long long N, std::vector<long long> A, long long Q, std::vector<long long> B, std::vector<long long> C){
    map<long long, long long> mp;
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        mp[A[i]]++;
        ans += A[i];
    }
    for (int i = 0; i < Q; i++) {
        long long b = B[i];
        long long c = C[i];
        mp[c] += mp[b];
        ans += (c - b) * mp[b];
        cout << ans << endl;
        mp.erase(b);
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> B(Q);
    std::vector<long long> C(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), Q, std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 9580
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;

int n, d, a[MAXN], ans[MAXN];

int main(){
	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; i++)	scanf("%d", &a[i]);
		
	int ind = -1;
	for (int i = 0; i + 1 < n; i++)
		if (a[i] + a[i + 1] >= d){
			ind = i;
			break;
		}
	if (ind == -1){
		printf("Impossible\n");
		return 0;
	}

	printf("Possible\n");
	for (int i = 0; i < ind; i++)
		printf("%d\n", i + 1);
	for (int i = n - 1; i >= ind + 2; i--)
		printf("%d\n", i);
	printf("%d\n", ind + 1);
	return 0;
}


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

using namespace std;
string table[66];

void solve()
{
	table[11] = "a";
	table[12] = "b";
	table[13] = "c";
	table[14] = "d";
	table[15] = "e";

	table[21] = "f";
	table[22] = "g";
	table[23] = "h";
	table[24] = "i";
	table[25] = "j";

	table[31] = "k";
	table[32] = "l";
	table[33] = "m";
	table[34] = "n";
	table[35] = "o";

	table[41] = "p";
	table[42] = "q";
	table[43] = "r";
	table[44] = "s";
	table[45] = "t";

	table[51] = "u";
	table[52] = "v";
	table[53] = "w";
	table[54] = "x";
	table[55] = "y";

	table[61] = "z";
	table[62] = ".";
	table[63] = "?";
	table[64] = "!";
	table[65] = " ";
	string s;
	while(cin >> s)
	{
		if(s.size() % 2 == 1)
		{
			cout << "NA" << endl;
			continue;
		}
		string ans = "";
		for(int i = 0; i < s.size() - 1; i += 2)
		{
			int a = (s[i] - '0') * 10 + (s[i + 1] - '0');
			if(!((11 <= a && a <= 15) || (21 <= a && a <= 25) || (31 <= a && a <= 35) ||(41 <= a && a <= 45) ||(51 <= a && a <= 55) ||(61 <= a && a <= 65)))
			{
				ans = "";
				break;
			}
			ans += table[a];
		}
		if(ans == "")
		{
			cout << "NA" << endl;
		}
		else
		{
			cout << ans << endl;
		}
	}
}

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

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    int ans = 0;
    for(int i = 1; i < n - 1; i++)
    {
        int check_cnt = 0;
        if(p[i] < p[i - 1]) check_cnt++;
        if(p[i] < p[i + 1]) check_cnt++;
        if(check_cnt == 1) ans++;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    ll n;
    char b[]=" abcdefghijklmnopqrstuvwxyz";
    cin>>n;
    ll a[20];
    ll m,p=0;
    while(n>26){
        m=n%26;
        if(m==0){
            m=26;
            n-=1;
        }
        a[p++]=m;
        n/=26;
    }
    a[p]=n;
    for(int i=p;i>=0;i--){
        cout<<b[a[i]];
    }
    return 0;
}


Measured memory_bytes: 3624