akhauriyash/Code-Regression huggingface dataset:
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}

template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){
    vector<pair<T,T>> out(input.size()-1);
    rep(i,input.size()-1){
        out[i].first =input[i  ];
        out[i].second=input[i+1];
    }
    return(out);
}
vector<char> String_to_vector_char(const string& input){
    vector<char> out(input.size());
    rep(i,input.size()){
        out[i]=input[i];
    }
    return out;
}

ll a,b,c,d;
void input(){
    cin>>a>>b>>c>>d;
}
void src(){
    ll e=lcm(c,d);a--;
    cout<<(b- (b/c+b/d-b/(lcm(c,d)))) - (a- (a/c+a/d-a/(lcm(c,d))));
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
sc = []
for i in range(M):
    temp = tuple(map(int, input().split()))
    sc.append(temp)

def check(num):
    d = []
    if num == 0:
        d.append(0)
    while (num > 0):
        n = num % 10
        d.append(n)
        num //= 10

    d = list(reversed(d))
    if len(d) != N:
        return False

    for s, c in sc:
        if d[s-1] != c:
            return False
    
    return True

for i in range(1000):
    if len(str(i)) != N:
        continue
    
    if check(i):
        print(i)
        break
else:
    print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
	//freopen("inp.in","r",stdin);
	int x;
	cin >> x;
	if(x<30)cout << "No\n";
	else cout << "Yes\n";
	
	
	return 0;
}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

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

int H, W, N, Sr, Sc;
char S[212345], T[212345];
bool SL[212345], SR[212345], SU[212345], SD[212345];
bool TL[212345], TR[212345], TU[212345], TD[212345];

int main() {

	scanf("%d%d%d%d%d%s%s", &H, &W, &N, &Sr, &Sc, S, T);

	rep(i, N) {
		switch (S[i])
		{
		case 'L':
			SL[i] = true;
			break;
		case 'R':
			SR[i] = true;
			break;
		case 'U':
			SU[i] = true;
			break;
		case 'D':
			SD[i] = true;
			break;
		}
		switch (T[i])
		{
		case 'L':
			TL[i] = true;
			break;
		case 'R':
			TR[i] = true;
			break;
		case 'U':
			TU[i] = true;
			break;
		case 'D':
			TD[i] = true;
			break;
		}
	}

	bool fall = false;

	auto isfallen = [](int r, int c) {
		if (r <= 0 || r > H || c <= 0 || c > W) return true;
		return false;
	};

	int R = Sr, C = Sc;
	rep(i, N) {
		if (SL[i]) C--;
		if (isfallen(R, C)) fall = true;
		if (TR[i] && !isfallen(R, C + 1)) C++;
	}R = Sr, C = Sc;
	rep(i, N) {
		if (SR[i]) C++;
		if (isfallen(R, C)) fall = true;
		if (TL[i] && !isfallen(R, C - 1)) C--;
	}R = Sr, C = Sc;
	rep(i, N) {
		if (SU[i]) R--;
		if (isfallen(R, C)) fall = true;
		if (TD[i] && !isfallen(R + 1, C)) R++;
	}R = Sr, C = Sc;
	rep(i, N) {
		if (SD[i]) R++;
		if (isfallen(R, C)) fall = true;
		if (TU[i] && !isfallen(R - 1, C)) R--;
	}

	if (fall) printf("NO\n");
	else printf("YES\n");

	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<tuple>
#include<stack>
#include<iomanip>
#include<map>
using namespace std;
//def lib
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define dRep(i,n0,n) for(int i=((int)n)-1;i>n0-1;i--)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define print(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007
//def end
typedef long long ll;
// lib
int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
int mfact(int x){int i=1;rep(j,x){i*=(j+1);} return i%mod;}
int modulo(int x){return x%mod;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
long long mfact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i%mod;}
long long modulo(long long x){return x%mod;}
int gcd(int x, int y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
ll gcd(ll x, ll y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
void say(bool x){if(x){cout<<"Yes"<<endl;}else {cout<<"No"<<endl;}return;}
//lib end
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1};
int main()
{
    ll n, m;
    cin >> n >> m;
    ll ans = 1;
    if(abs(n - m) > 1){
        cout << 0 << endl;
    }
    else if(n == m){
        ans = 2;
        rep(i, n){
            ans = (ans * (i + 1)) % mod;
        }
        rep(i, m){
            ans = (ans * (i + 1)) % mod;
        }
        cout << ans << endl;
    }
    else{
        rep(i, n){
            ans = (ans * (i + 1)) % mod;
        }
        rep(i, m){
            ans = (ans * (i + 1)) % mod;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# 数え上げで制約が 2 乗っぽいのでどうせ dp だろという気持ちになる
# なんで入力が数字で与えられるのかを考えるとちょっと視界が開ける

# よく考えると、できる列の制約は
# 「赤い/青いボールはできる列の i 個目までに A[i]/B[i] 個使える」
# と表せることがわかる
# これに気付けばあとは
#     dp[i][j] := i 個目まで並べたとき赤いボールを j 個使う場合の数
# とした dp が自然と思いつく

from itertools import accumulate

def main():
    mod = 998244353
    B = list(map(int, input()))
    N = len(B)
    A = [2-b for b in B] + [0]*N
    B += [0] * N
    a = b = 0
    for i in range(2*N):
        b += B[i]
        if b > 0:
            b -= 1
            B[i] = 1
        a += A[i]
        if a > 0:
            a -= 1
            A[i] = 1

    A = list(accumulate(A))
    B = list(accumulate(B))

    dp = [[0]*(2*N+2) for _ in range(2*N+1)]
    dp[0][0] = 1
    for i, (a, b) in enumerate(zip(A, B), 1):
        for j in range(2*N+1):
            if i - b <= j <= a:
                dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]) % mod

    print(sum(dp[2*N]) % mod)

main()


Measured memory_bytes: 166748
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


void solve()
{
	ll n, x;
	cin >> n >> x;
	ll a[n];
	for(int i = 0; i < n; ++i){
		cin >> a[i];	
	}
	sort(a, a + n);
	ll sum = x;
	for(int i = 1; i < n; ++i){
		ll d = a[i] - a[i - 1];
		sum += x;
		sum -= max(0ll, x - (a[i] - a[i - 1]));
	}	
	cout << sum;

}



 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 1792
// **** WHEN THE GOING GETS TOUGH, THE TOUGH GETS GOING. ****

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
typedef vector<ii> vii;
typedef vector<lii> lvii;

#define min_prq(t) priority_queue<t,vector<t>,greater<t>>
#define max_prq(t) priority_queue<t>
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

ll modpow(ll x,ll y,ll M=mod)
{
	ll ans=1;
	while(y>0){
		if(y&1) ans=(ans*x)%M;
		y=y>>1;
		x=(x*x)%M;
	}
	return ans;
}
ll ncr(ll n,ll r)
{
	ll nmr=1,dnm=1;
	for(int i=0;i<r;i++)
	{
		nmr=mod_product(nmr,n-i);
	}
	for(int i=1;i<=r;i++)
	{
		dnm=mod_product(dnm,i);
	}
	return mod_product(nmr,modpow(dnm,mod-2));
}

signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=modpow(2,n)-1;
	ans-=ncr(n,a);
	ans=mod_sum(ans,mod);
	ans-=ncr(n,b);
	ans=mod_sum(ans,mod);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import Data.List

f2::Int->[Int]->Int
f2 _ []=0
f2 0 xs=sum xs
f2 k (x:xs)
    |x>=0=sum (x:xs)
    |otherwise=f2 (k-1) xs

f::Int->[[Int]]->[Int]
f _ []=[]
f k (x:xs)=(f2 (k-(length x)) x):f k xs

main = do
       t1<-getLine
       t2<-getLine
       let n:k:[]=map read (words t1)::[Int]
           js=map read (words t2)::[Int]
           ps=[sort ((take e1 js)++(drop (n-e2) js))|e1<-[0..n],e2<-[0..n],e1+e2<k+1,e1+e2<n+1]
       print $ maximum $ f k ps

Measured memory_bytes: 1020
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
    int n, m;
    VVI a;
    VI b;
    cin >> n >> m;
    for(int i=0; i<n; i++) {
        VI vtemp;
        for(int j=0; j<m; j++) {
            int temp;
            cin >> temp;
            vtemp.push_back(temp);
        }
        a.push_back(vtemp);
    }
    for(int i=0; i<m; i++) {
        int temp;
        cin >> temp;
        b.push_back(temp);
    }
    
    for(int i=0; i<n; i++) {
        ll res = 0;
        for(int j=0; j<m; j++) {
            res += a[i][j] * b[j];
        }
        cout << res << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3200
#include <iostream>

using namespace std;

char num_a[102] = {}, num_b[102] = {};
void compare_a_b(char *, char *);

int main()
{
	int a_cnt = 0, b_cnt = 0;
	while (1)
	{
		char tmp;
		tmp = getchar();
		if (tmp == ' ' || tmp == '\n') break;
		num_a[a_cnt] = tmp;
		a_cnt++;
	}
	while (1)
	{
		char tmp;
		tmp = getchar();
		if (tmp == '\n') break;
		num_b[b_cnt] = tmp;
		b_cnt++;
	}
	if (a_cnt > b_cnt)
	{
		cout << "GREATER" << endl;
		return 0;
	}
	else if (a_cnt < b_cnt)
	{
		cout << "LESS" << endl;
		return 0;
	}
	else
	{
		compare_a_b(num_a, num_b);
	}
	return 0;
}

void compare_a_b(char *num_a, char *num_b)
{
	int cnt = 0;
	int ans = 0;
	while (1)
	{
		if (num_a[cnt] > num_b[cnt])
		{
			ans = 1;
			break;
		}
		else if (num_a[cnt] < num_b[cnt])
		{
			ans = 2;
			break;
		}
		else
		{
			if (cnt < 101) cnt++;
			else break;
		}
	}
	if (ans == 0)
	{
		cout << "EQUAL" << endl;
	}
	else if (ans == 1)
	{
		cout << "GREATER" << endl;
	}
	else
	{
		cout << "LESS" << endl;
	}
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);
    auto h = readln.split.to!(int[]);

    int ans;

    while (true) {
        if (h.all!"a == 0") {
            break;
        }
        auto s = h.split(0).filter!"!a.empty".count;
        ans += s;
        h = h.map!(hi => max(hi - 1, 0)).array;
    }

    writeln(ans);
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

string s;

int main () {
    cin >> s;
    int x = s.length();
    if (s[x-1]=='s') {
        s+="es";
    }
    else {
        s+="s";
    }
    cout << s;

}



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

struct node{
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};
typedef struct node * Tree;

Tree root, NIL;
int max;

void insert(int k){
  int H;
  Tree y = NIL;
  Tree x = root;
  Tree z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if (z->key < x->key){
      x = x->left;
    } else{
      x = x->right;
    }
  }

  z->parent = y;
  if (y == NIL){
    root = z;
  } else{
    if (z->key < y->key) {
      y->left = z;
    } else{
      y->right = z;
    }
  }
}

void inorder(Tree u){
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Tree u){
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int i, n, x;
  char com[20];
  scanf("%d", &n);
  max = 0;
  for (i = 0; i < n; i++){
    scanf("%s", com);
    if (strcmp(com, "insert") == 0){
      scanf("%d", &x);
      insert(x);
    } else if (strcmp(com, "print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 25148
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

class cCard
{
public:
	char suit;
	int value;
	cCard(string t)
	{
		istringstream iss(t);
		iss >> suit >> value;
	}
};

class cCards
{
	int m_n;

public:
	bool isStable;
	vector<cCard> cc;

	cCards(string c, int n)
	{
		m_n = n;

		vector<string> tc;
		istringstream iss(c);
		while (!iss.eof())
		{
			string t;
			iss >> t;
			cCard tc(t);
			cc.push_back(tc);
		}
	}

	bool BubbleSort();
	bool SelectionSort();
	string getStr();

};

bool cCards::BubbleSort()
{
	isStable = true;
	for (int i = 0; i < m_n; ++i)
	{
		for (int j = m_n - 1; j > i; --j)
		{
			if (cc[j].value < cc[j - 1].value)
			{
				swap(cc[j], cc[j - 1]);
				if (cc[j].value == cc[j - 1].value && cc[i].suit != cc[j - 1].suit)
				{
					isStable = false;
				}
				else
				{
					isStable = true;
				}
			}
		}
	}
	return isStable;
}

bool cCards::SelectionSort()
{
	isStable = true;
	for (int i = 0; i < m_n; ++i)
	{
		int minj = i;
		for (int j = i; j < m_n; ++j)
		{
			if (cc[j].value < cc[minj].value)
			{
				minj = j;
			}
		}
		swap(cc[i], cc[minj]);
		if(cc[i].value == cc[minj].value && cc[i].suit != cc[minj].suit)
		{
			isStable = false;
		}
		else
		{
			isStable = true;
		}
	}
	return isStable;
}

string cCards::getStr()
{
	ostringstream oss;
	for (int i = 0; i < cc.size() - 1; ++i)
	{
		oss << cc[i].suit << cc[i].value << " ";
	}
	oss << cc[cc.size() - 1].suit << cc[cc.size() - 1].value;
	return oss.str();
}

int main()
{
	int N;
	cin >> N;
	cin.ignore();

	string C;
	getline(cin, C);

	cCards ccd1(C,N);
	string ans1 = ccd1.BubbleSort() ? "Stable" : "Not stable";
	cout << ccd1.getStr() << endl;
	cout << ans1 << endl;
	cCards ccd2(C,N);
	ccd2.SelectionSort();
	cout << ccd2.getStr() << endl;
	string ans2 = (ccd1.getStr() == ccd2.getStr()) ? "Stable" : "Not stable";
	cout << ans2 << endl;

	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N; ll A[int(2e5+5)];

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N, greater<ll>());

  ll ans = A[0], rest = N - 2, now = 1;
  while (rest > 0){
    if (rest > 2){
      ans += A[now] * 2;
      now++; rest -= 2;
    }else{
      ans += A[now];
      rest--;
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define int long long
#define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll N, K;
ll dp[3000][3000];
ll a[3000];
ll Tarodp(ll), Jirodp(ll);

ll calcdp(ll l, ll r) {
    if(l > r) return 0;
    if(dp[l][r] != LINF) return dp[l][r];
    ll &res = dp[l][r];
    if((N - (r - l + 1)) % 2)
        res = min(calcdp(l, r - 1) - a[r], calcdp(l + 1, r) - a[l]);
    else {
        res = max(calcdp(l, r - 1) + a[r], calcdp(l + 1, r) + a[l]);
    }
    return res;
}

signed main() {
    cin >> N;
    REP(i, N) cin >> a[i];
    Fill(dp, LINF);
    cout << calcdp(0, N - 1) << "\n";
}


Measured memory_bytes: 70656
#include <cstdio>
#include <iostream>
const int MAXN = 1e5 + 5;
int ans[MAXN];
int main()
{
	int N;
	std::cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int val;
		scanf("%d", &val);
		ans[val] = i;
	}
	for (int i = 1; i <= N; i++)
		printf(i == 1 ? "%d" : " %d", ans[i]);
	std::cout << std::endl;
	return 0;
}

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

const int N = 3005, MOD = 1e9+7;
int n, dpprefix[N][N], dp[N][N];
//dp[i][j] = the number of ways to put numbers in prefix of size i such that
//the last number is j
char str[N];

void add_self(int& a, int b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
}

int32_t main() {
  scanf("%d%s", &n, str);

  dp[1][1] = 1;
  for (int j = 1; j <= n; j++)
    add_self(dpprefix[1][j], 1);

  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      int l = (str[i-2] == '<') ? 1 : j;
      int r = (str[i-2] == '<') ? j - 1 : i - 1;
      int sum = dpprefix[i-1][r] - dpprefix[i-1][l-1];
      if (sum < 0)
        sum += MOD;
      add_self(dp[i][j], sum);
      /*
      for (int k = l; k <= r; k++)
        add_self(dp[i][j], dp[i-1][k]);
        */
    }
    for (int j = 1; j <= n; j++) {
      add_self(dpprefix[i][j], dp[i][j]);
      add_self(dpprefix[i][j], dpprefix[i][j-1]);
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; i++)
    add_self(ans, dp[n][i]);

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 69504
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc086/tasks/arc089_a

"""
import sys
from sys import stdin
from collections import namedtuple
input = stdin.readline


def solve(points):
    cx, cy = 0, 0
    ct = 0
    for t, x, y in points:
        dt = t - ct
        dx = abs(x - cx)
        dy = abs(y - cy)
        if dx + dy > dt:
            return 'No'
        if dx + dy < dt:
            diff = dt - (dx + dy)
            if diff % 2 != 0:
                return 'No'
        ct = t
        cx = x
        cy = y
    return 'Yes'


P = namedtuple('P', ['t', 'x', 'y'])
def main(args):
    points = []
    N = int(input())
    for _ in range(N):
        t, x, y = map(int, input().split())
        points.append(P(t, x, y))
    ans = solve(points)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 18564
def main():
    n = int(input())
    s = input()
    ans = 0

    for i in range(1, n):
        cnt = 0
        x, y = set(s[:i]), set(s[i:])
        for j in x:
            if j in y:
                cnt += 1
        ans = max(ans, cnt)

    print(ans)


main()

Measured memory_bytes: 9036
N,Y = map(int, input().split())
"""
・10000x+5000y+1000z=Y
・x+y+z=N
・z=N-(x+y)>=0 x+y<=N
"""

for x in range(N + 1):
    for y in range(N + 1 - x):
        R = Y - 10000 * x - 5000 * y
        z = N - (x + y)
        if 1000 * z == R:
            print(x, y, z)
            exit()
print(-1, -1, -1)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string T; cin>>T;
    int N = T.size();
    rep(i,N){
        if (T[i]=='?') T[i]='D';
    }
    cout<<T<<"\n";
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a!=0){
		c-=b;
		if(c<=0){
			cout << "Yes";
			return 0;
		}
		a-=d;
		if(a<=0){
			cout << "No";
			return 0;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>

using namespace std;

const int MOD=1000000007;

long long dp[1003][1003];
char polje[1003][1003];


int main () {
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>polje[i][j];
		}
	}
	dp[1][1]=1;
	for(int i=2;i<=n;i++){
		dp[1][i]=dp[1][i-1]*bool(polje[1][i]=='.');
	}
	for(int i=2;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=(dp[i][j-1]+dp[i-1][j])*bool(polje[i][j]=='.')%MOD;
		}
	}
	cout<<dp[n][m];


return 0;
}



Measured memory_bytes: 9088
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 400001
#define MAX_V 400010
#define vec vector<int>
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};
main(){
    int p[50];
    p[0]=1;
    rep(i,30){
        p[i+1]=p[i]*2;
    }
    int n=in();
    int a[N];
    rep(i,n)a[i]=in();
    sort(a,a+n);
    int count[N]={};
    int temp=0;
    count[0]++;
    vec b;
    b.pb(a[0]);
    rep2(i,1,n-1){
        if(a[i]==a[i-1])count[temp]++;
        else {
            count[++temp]++;b.pb(a[i]);
        }
    }
    int ans=0;
    rep3(i,b.size()-1,0){
        rep3(j,30,1){
        int id=lower_bound(ALL(b),p[j]-b[i])-b.begin();
        if(b[id]!=p[j]-b[i])continue;
        if(i==id){
            ans+=count[i]/2;
            count[i]=count[i]%2;
        }
        else if(count[i]&&count[id]){
            if(count[i]>count[id]){
                count[i]-=count[id];
                ans+=count[id];
                count[id]=0;
            }
            else{
                count[id]-=count[i];
                ans+=count[i];
                count[i]=0;
                break;
            }
        }
    }
    }
    cout<<ans;
}

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

int main(){
	string s,c="No";
    int a=-1,b=-1;
    cin >> s;
    for(int i=0;i<s.size();i++){
      if(s.at(i)=='C'){
        a=i;
        break;
      }
    }
    for(int i=a;i<s.size();i++){
      if(s.at(i)=='F')
        c = "Yes";
    }
  cout << c << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			int a = in.nextInt();
			int b = in.nextInt();
			int n = a+b;
			int ans = 0;
			while(n!=0){
				n = n/10;
				ans++;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
   
if __FILE__ == $0
  while line = STDIN.gets
    tokens = line.chomp!.split.map!(&:to_i)
    sec = tokens[0]
    h = (sec/3600).to_i
    m = ((sec - h*3600)/60).to_i
    s = sec % 60
   
   
    puts "#{h}:#{m}:#{s}"
  end
end

Measured memory_bytes: 8612
#include <iostream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

string hidari = "qwertasdfgzxcvb";
string migi = "yuiophjklnm";

bool phidari(char c){
    return find(all(hidari),c)!=hidari.end();
}

int main(){
    while(true){
        string s;
        cin >> s;
        if(s=="#") break;
        bool fhidari = phidari(s[0]);
        int c = 0;
        for(int i=0;i<s.length();i++){
            bool ishidari = phidari(s[i]);
            if(ishidari != fhidari) c++;
            fhidari = ishidari;
        }
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

int main(){
    int N, K;
    while(cin >> N >> K){
        long long res = 0;
        for(int i=1;i<=N;i++){
            int m = (K - (i%K));
            if((2*m) % K != 0) continue;
            if(m > N) continue;
            long long a = (N - m)/K + 1;
            res += a * a;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
ll a[3];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 0, 3) cin >> a[i];
  sort(a, a+3);
  cout << ((a[0]%2*a[1]%2*a[2]%2) ? a[0] * a[1] : 0) << endl;
  return 0;
}

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

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

using namespace std;

int main(void){
  int n;
  string s, t;
  cin >> n >> s >> t;

  string ans = "";
  for(int i = 0; i < n; i++){
    ans += s[i];
    ans += t[i];
  }

  cout << ans << endl;
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    vector<string> vec(0);
    int len_s = s.size();
    rep(i,len_s){
        if (s[i] == '0'){
            vec.push_back("0");
        }
        else if (s[i] == '1'){
            vec.push_back("1");
        }
        else if (s[i] == 'B'){
            if (vec.size() == 0){
                continue;
            }
            vec.pop_back();
        }
    }
    int len_v = vec.size();
    rep(i,len_v){
        cout << vec[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 100010;

int n, a[MAXN], dp[MAXN], inc[MAXN], dc[MAXN];

int main(void) {
  scanf("%d",&n);
  REP(i, n) scanf("%d",&a[i]);

  for (int i = n - 1; i >= 0; --i) {
    inc[i] = dc[i] = i;
    if (i + 1 < n && a[i] <= a[i+1])
      inc[i] = max(inc[i], inc[i+1]);
    if (i + 1 < n && a[i] >= a[i+1])
      dc[i] = max(dc[i], dc[i+1]);
    dp[i] = MAXN;
    dp[i] = min(dp[i], dp[inc[i] + 1] + 1);
    dp[i] = min(dp[i], dp[dc[i] + 1] + 1);
  }

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


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

int main(){
	string o,e;
	cin>>o>>e;
	rep(i,e.size()){
		cout<<o[i]<<e[i];
	}
	if(o.size()>e.size())puts(o[(int)o.size()-1]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	int N;
	cin>>N;
	vector<ll> v(5,0);

	REP(i,N){
		string s; cin>>s;
		if(s[0]=='M')v[0]++;
		if(s[0]=='A')v[1]++;
		if(s[0]=='R')v[2]++;
		if(s[0]=='C')v[3]++;
		if(s[0]=='H')v[4]++;
	}
	ll sum=0;
	FOR(i,0,4)FOR(j,i+1,4)FOR(k,j+1,4)sum+=v[i]*v[j]*v[k];
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int cnt=0;
    int ans=0;
    for(int i=max(a,b);i>=1;i--){
        if(0==a%i&0==b%i){
            cnt++;
        }
        if(cnt==k){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N, Q = map(int, input().split())
    edge = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    cnt = [0]*N
    for i in range(Q):
        p, x = map(int, input().split())
        cnt[p-1] += x

    stk = []
    stk.append((0, -1))
    while len(stk):
        v, par = stk.pop()
        if v>0:
            cnt[v] += cnt[par]
        for i in edge[v]:
            if i!=par:
                stk.append((i, v))

    print(*cnt)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 56660
from bisect import*
from collections import*
n,k,*a=map(int,open(0).read().split())
b=defaultdict(list)
for i,v in enumerate(a):b[v]+=i,
s=a[0]
i=c=0
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  if i==n:break
  s=a[i]
k%=c+1
s=a[0]
i=c=0
while c<k-1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  c+=j==m
  i=t[j%m]+1
  s=a[i]
r=[]
while 1:
  t=b[s]
  m=len(t)
  j=bisect(t,i)
  if j==m:
    r+=s,
    i+=1
  else:
    i=t[j]+1
  if i==n:
    break
  s=a[i]
print(*r)

Measured memory_bytes: 58120
// D - Grid Components

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

bool grid[100][100];

void print_grid() {
	cout << 100 << " " << 100 << endl;
	for (int i=0; i<100; i++) {
		for (int j=0; j<100; j++) {
			if (grid[i][j]) cout << '#';
			else cout << '.';
		}
		cout << endl;
	}
}

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

	for (int i=0; i<50; i++) {
		for (int j=0; j<100; j++) {
			grid[i][j] = true;
		}
	}

	A--;
	for (int i=0; i<50; i+=2) {
		for (int j=0; j<100; j+=2) {
			if (A == 0) break;

			grid[i][j] = false;
			A--;
		}
	}

	B--;
	for (int i=99; i>=50; i-=2) {
		for (int j=0; j<100; j+=2) {
			if (B == 0) break;

			grid[i][j] = true;
			B--;
		}
	}

	print_grid();

	return 0;
}

Measured memory_bytes: 3616
import java.util.*; 
 
public class Main
{
	public static void main(String args[]) throws Exception{
		new Main().run();
	}
	

	int w,h;
	
	public void run()
	{
		int i,j,k,l;
		Scanner cin=new Scanner(System.in);
		while(true){
			//ツ陳シツ進ツ　ツ右ツ静慊　ツ板スツ転	 ツ債カツ静慊　ツ津「ツ止
			w = cin.nextInt();
			h = cin.nextInt();
			if(w==0 && h ==0) break;
			int board[][] = new int[h][w];
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					board[i][j] = cin.nextInt();
				}
			}
			int[] cost = new int[4];
			int MAXCOST = 99999999;
			int[][][] dp = new int[h][w][4];
			boolean[][][] flag = new boolean[h][w][4];
			flag[0][0][0] = true;
			for(i=0;i<4;i++) cost[i] = cin.nextInt();
			int vx[] = {1,0,-1,0};
			int vy[] = {0,1,0,-1};
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					for(k=0;k<4;k++){
						dp[i][j][k] = MAXCOST;
					}
				}
			}
			dp[0][0][0] = 0;
			while(true){
				boolean loopflag = false;
				for(i=0;i<h;i++){
					for(j=0;j<w;j++){
						for(k=0;k<4;k++){
							if(!flag[i][j][k]) continue;
							for(l=0;l<4;l++){
								int addcost = cost[l];
								int nextk = k;
								if(board[i][j] == l) addcost = 0;
								nextk = (k + l)%4;
								int nexty = i + vy[nextk];
								int nextx = j + vx[nextk];
								if(ok(nexty,nextx)){
									if(dp[nexty][nextx][nextk] > dp[i][j][k] + addcost){
										dp[nexty][nextx][nextk] = dp[i][j][k] + addcost;
										loopflag = flag[nexty][nextx][nextk] = true;
									}
								}
							}
						}
					}
				}
				if(!loopflag) break;
			}
			int res = MAXCOST; 
			for(k=0;k<4;k++) res = Math.min(res, dp[h-1][w-1][k]);
			System.out.println(res);
		}
	}
	
	boolean ok(int y, int x){
		return x>=0 && y>=0 && x<w && y<h;
	}
	
}

Measured memory_bytes: 12000
import sys


# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

# ===CODE===
def main():
    while True:
        n = int(input())
        if n == 0:
            exit(0)

        d = [[[0 for i in range(60)] for j in range(60)] for k in range(24)]

        for _ in range(n):
            a, b = input().split()
            a_h, a_m, a_s = a.split(":")
            b_h,b_m,b_s = b.split(":")
            d[int(a_h)][int(a_m)][int(a_s)] += 1
            d[int(b_h)][int(b_m)][int(b_s)] -= 1

        ans = 0
        tmp_ans = 0
        for i in range(24):
            for j in range(60):
                for k in range(60):
                    tmp_ans += d[i][j][k]
                    ans = max(ans, tmp_ans)

        print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7308
#include <cstdio>
using namespace std;

int data[5][4][11]={{{0}}};

int main (void)
{
	int b, f, r, v, n, i, j, p;
	scanf("%d", &n);

	for (i=1; i<=n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		data[b][f][r] += v;
	}

	for (i=1; i<=4; i++){
		for (j=1; j<=3; j++){
			for (p=1; p<=10; p++){
				printf(" %d", data[i][j][p]);
			}
			printf("\n");
		}
		if (i != 4)
			printf("####################\n");
	}
	return 0;
}

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

const ll INF = 1e18;

int n;
vector<string> s;
map<char,int> flags;

int main() {
    cin >> n;
    s.resize(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < n; i++) {
        map<char,int> tempflags;
        for (int j = 0; j < s[i].size(); j++) {
            for (char c = 'a'; c <= 'z'; c++) {
                if (s[i][j] == c) tempflags[c]++;
            }
        }
        if (i == 0) flags = tempflags;
        else {
            for (char c = 'a'; c <= 'z'; c++) {
                flags[c] = min(flags[c], tempflags[c]);
            }
        }
    }

    string ans;
    for (char c = 'a'; c <= 'z'; c++) {
        for (int i = 0; i < flags[c]; i++) {
            ans+=c;
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
T=int(input())
for case in range(T):
    N=int(input())
    KLR=[[],[]]
    ans=0
    for i in range(N):
        k,l,r=map(int,input().split())
        ans+=min(l,r)
        if l>=r:
            KLR[0].append((k,l,r))
        else:
            KLR[1].append((N-k,r,l))
    Len=[len(KLR[0]),len(KLR[1])]
    for i in range(2):
        KLR[i].sort()
        for j in range(Len[i]):
            k,l,r=KLR[i][j]
            KLR[i][j]=(min(k,Len[i]),l,r)
        q=[]
        index=0
        for j in range(Len[i]+1):
            while(index<Len[i]):
                k,l,r=KLR[i][index]
                if k==j:
                    heapq.heappush(q,(l-r,k,l,r))
                    index+=1
                else:
                    break
            while(len(q)>j):
                heapq.heappop(q)
        while(len(q)>0):
            ans+=heapq.heappop(q)[0]
    print(ans)


Measured memory_bytes: 161928
#include<stdio.h>
int a,b;
int main(){
  scanf("%d %d",&a,&b);
  if(b > 0){
    if(a > 0)printf("Positive\n");
    else if(a <= 0)printf("Zero\n");
  }
  else if(b == 0)printf("Zero\n");
  else if(b < 0){
    if(b == a)printf("Positive\n");
    else if((b-a)%2 == 0)printf("Negative\n");
    else printf("Positive\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



int main() {
    int N; 
    cin >> N;
    vector<long long> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (N % 2 == 0) {
        long long mi = A[N/2-1] + A[N/2];
        long long ma = B[N/2-1] + B[N/2];
        cout << ma - mi + 1 << endl;
    }
    else {
        long long mi = A[N/2], ma = B[N/2];
        cout << ma - mi + 1 << endl;
    }
}


Measured memory_bytes: 6328
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
long long mod=1e9+7;

int main()
{
	int n;
	cin>>n;
	int a[n];
	map<ll,ll>m;
	for(int i=0;i<n;i++)
		{
			cin>>a[i];
			m[a[i]]++;
		}
	
	  if(m.count(0))
	  {
    	if(n%2==0 || m[0] != 1){
     		 cout << 0 << endl;
      	return 0;
      	}
    	m.erase(0);
  	  }
  
  	  ll ans = 1;
  	for(auto ite:m){
    if(ite.second %2 != 0){
      cout << 0 << endl;
      return 0;
    }
    ans *= ite.second % mod;
    ans %= mod;
  }
  cout << ans%mod << endl;
  
  
	
	return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<string>
using namespace std;
int main(){
long l,i,k,f;
string s,t;
while(cin>>s){
l=s.size();t="";f=0;
for(i=0;i<l;i+=2){
if(49>s[i]||s[i]>54||49>s[i+1]||s[i+1]>53){f=1;break;}
k=(s[i]-48)*5+91+(s[i+1]-48);
/*cout<<"k="<<k<<endl;*/
if(s.substr(i,2)=="62")k=46;
else if(s.substr(i,2)=="63")k=63;
else if(s.substr(i,2)=="64")k=33;
else if(s.substr(i,2)=="65")k=32;
t+=k;
}
if(f==0)cout<<t<<endl;
else cout<<"NA"<<endl;
}
return 0;
}

Measured memory_bytes: 1200