akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


n = z()
v = zz()
a_lis = v[0::2]
b_lis = v[1::2]

a_all = [0]*(1 + 10**5)
b_all = [0]*(1 + 10**5)
for a in a_lis:
    a_all[a] += 1

for b in b_lis:
    b_all[b] += 1
nums = list(range(0, len(a_all)))
a_all = zip(a_all, nums)
b_all = zip(b_all, nums)
a_all = sorted(a_all, reverse=True)
b_all = sorted(b_all, reverse=True)

a_num_1, fixed_a_value = a_all[0]
b_num_1, fixed_b_value = b_all[0]
a_num_2 = a_num_1
b_num_2 = b_num_1
# print(a_num, b_num)
if (fixed_a_value == fixed_b_value):
    a_num_1, fixed_a_value = a_all[0]
    b_num_1, fixed_b_value = b_all[1]
    a_num_2, fixed_a_value = a_all[1]
    b_num_2, fixed_b_value = b_all[0]
# print(a_num, b_num)
ans = min(n-a_num_1-b_num_1, n-a_num_2-b_num_2)
print(ans)


Measured memory_bytes: 51696
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();

		char[] s = new char[S.length()];
		s = S.toCharArray();
		int count=0;
		int max=0;
		for(int i=0; i<=S.length()-1; i++){
			for(int j=S.length()-1; j>=0; j-- ){
				if(i>j){
					continue;
				}
				count = 0;
				for(int k=i; k<=j; k++){
					if(s[k]=='A' 
					|| s[k]=='T'
					|| s[k]=='C'
					|| s[k]=='G'){
						count ++;
					}else{
						break;
					}
				}
				if(max<count){
					max = count;
				}
			}
		}
		System.out.print(max);
	}	
}


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

ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}
ll min(ll a, ll b){ 
	if(a <= b) return a;
	else if(a > b) return b;
}
ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
ll fact(ll n){
	ll res = 1;
	rep(i, n){
		res *= i + 1;
		res =  res%((ll)(1e9 + 7));
	}
	return res;
}
ll digit(const ll n){
	ll res = 0;
	ll i = 1;
	while(n % i != n){
		res += 1;
		i *= 10;
	}
	return res;
}

int main(){
	ll n, t;
	cin >> n >> t;
	vector<ll> time(n, 0);
	rep(i, n)cin >> time[i];
	ll ans = time[time.size()-1] + t;
	rep(i, n-1){
		ans -= max(0, time[i+1] - (time[i]+t));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define _USE_MATH_DEFINES
#include <cmath>

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

using namespace std;
typedef long long ll;

struct Node {
   int   key;
   Node *l, *r, *p;
};

Node *root, *NIL;

void insert(int k) {
   Node *y = NIL;
   Node *x = root;
   Node *z;

   z = (Node *)malloc(sizeof(Node));
   z->key = k;
   z->l = NIL;
   z->r = NIL;

   while (x != NIL) {
      y = x;
      if (z->key < x->key) x = x->l;
      else x = x->r;
   }
   z->p = y;
   if (y == NIL)
      root = z;
   else{
      if (z->key < y->key)
         y->l = z;
      else
         y->r = z;
   }
}

bool find(int k) {
   Node *x = root;

   while (x != NIL) {
      if (k < x->key)
         x = x->l;
      else if (x->key < k)
         x = x->r;
      else
         return(true);
   }
   return(false);
}

Node *getmin(Node *x) {
   while (x->l != NIL) {
      x = x->l;
   }
   return(x);
}

void delete_key(int k) {
   Node *z = root;
   Node *x, *y;

   while (z != NIL) {
      if (k < z->key) z = z->l;
      else if (z->key < k) z = z->r;
      else break;
   }

   if (z->l == NIL || z->r == NIL) y = z;
   else y = getmin(z->r);

   if (y->l != NIL) x = y->l;
   else x = y->r;

   if (x != NIL)
      x->p = y->p;

   if (y->p == NIL)
      root = x;
   else if (y->p->l == y)
      y->p->l = x;
   else
      y->p->r = x;

   z->key = y->key;
   free(y);
}

void inorder(Node *u) {
   if (u == NIL) return;

   inorder(u->l);
   printf(" %d", u->key);
   inorder(u->r);
}

void preorder(Node *u) {
   if (u == NIL) return;

   printf(" %d", u->key);
   preorder(u->l);
   preorder(u->r);
}

int main() {
   int  n, x;
   char s[10];

   cin >> n;
   rep(i, n) {
      scanf("%s", s);
      if (s[0] == 'i') {
         scanf("%d", &x);
         insert(x);
      }
      else if (s[0] == 'f') {
         scanf("%d", &x);
         cout << (find(x) ? "yes" : "no") << endl;
      }
      else if (s[0] == 'd') {
         scanf("%d", &x);
         delete_key(x);
      }
      else{
         inorder(root);
         printf("\n");
         preorder(root);
         printf("\n");
      }
   }
   return(0);
}



Measured memory_bytes: 21964
//ABC145B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main(){
	int n;
	string s;
	cin >> n >> s;
	if(n%2 != 0){
		cout << "No" << endl;
		return 0;
	}
	for(int i=0;i<n/2;i++){
		if(s.at(i) != s.at(i+n/2)){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

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

	ll N;
	cin >> N;

	vector<pll> v(N);
	rep(i, N) cin >> v[i].first >> v[i].second;

	sort(v.begin(), v.end(), greater<pll>());
	cout << v[0].first + v[0].second << endl;	
}


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

#define LMIN -10000000000
#define LMAX 100000000000

int main() {
  int a, b, q;
  scanf("%d%d%d", &a, &b, &q);
  long int s[a+2], t[b+2], x[q];
  s[0] = LMIN;
  t[0] = LMIN;
  s[a+1] = LMAX;
  t[b+1] = LMAX;
  for (size_t i = 1; i <= a; i++) {
    scanf("%ld", s+i);
  }
  for (size_t i = 1; i <= b; i++) {
    scanf("%ld", t+i);
  }
  for (size_t i = 0; i < q; i++) {
    scanf("%ld", x+i);
  }
  for (size_t i = 0; i < q; i++) {
    int la = 0, lb = 0, ua = a+1, ub = b+1, ma, mb;
    while (ua-la > 1) {
      ma = (ua+la)/2;
      if (s[ma] < x[i]) {
        la = ma;
      } else {
        ua = ma;
      }
    }
    while (ub-lb > 1) {
      mb = (ub+lb)/2;
      if (t[mb] < x[i]) {
        lb = mb;
      } else {
        ub = mb;
      }
    }
    long int ans = LMAX;
    for (size_t j = 0; j < 2; j++) {
      for (size_t k = 0; k < 2; k++) {
        long int d1, d2;
        d1 = labs(s[la+j] - x[i]) + labs(t[lb+k] - s[la+j]);
        d2 = labs(t[lb+k] - x[i]) + labs(t[lb+k] - s[la+j]);
        if (d1 < d2) {
          if (d1 < ans) {
            ans = d1;
          }
        } else {
          if (d2 < ans) {
            ans = d2;
          }
        }
      }
    }
    printf("%ld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
   int n,i,j;
   cin>>n;
   double x[n],y[n];
   double f=1,sum=0,ans=0;
   for(i=0;i<n;i++)
   {
       cin>>x[i]>>y[i];
   }
    for(i=1;i<=n;i++)
    {
        f*=i;
    }//cout<<f<<e;

   for(i=0;i<n;i++)
   {
       for(j=0;j<n;j++)
       {
           sum=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
           //cout<<sum<<e;
           ans+=sqrt(sum);
       }
   }
  // cout<<ans<<e;
   double p=n;
   cout<<fixed<<setprecision(9)<<ans/p;



}


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

int M[101][101];
int d[101];
int n;
vector<int> q;

int check(int point){
    if(find(q.begin(), q.end(), point) != q.end()){
        //printf("%d in q\n",point);
        return 1;
    }
    else{
        //printf("%d not in q\n",point);
        return 0;
    }
}

void dijk(int point){
    q.push_back(point);
    int node, mini = INT_MAX;

    while(q.size()!=n){
        mini = INT_MAX;
        for(int i=1;i<n;++i){
            if(mini>d[i] && check(i)==0){
                node = i;
                mini = d[i];
            }
        }
        q.push_back(node);
        //printf("push node %d\n",node);
        for(int i=0;i<n;++i){
            if(d[node]+M[node][i]<d[i]){
                d[i] = d[node]+M[node][i];
            }
        }
    }
}

int main(){
    int id, pair_n, source, dis;
    int value;
    //FILE *fp=fopen("In3.txt","r");
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            M[i][j] = INT_MAX;
        }
    }
    for(int i=0;i<n;++i){
        scanf("%d %d",&id, &pair_n);
        //cin >> id >> pair_n;
        for(int j=0;j<pair_n;++j){
            scanf("%d %d",&source, &dis);
            //cin >> source >> dis;
            M[id][source] = dis;
        }
    }
    d[0] = 0;
    for(int i=1;i<n;++i){
        d[i] = M[0][i];
    }
    dijk(0);
    for(int i=0;i<n;++i){
        printf("%d %d\n",i,d[i]);
    }

    return 0;
}



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

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

  if ( A+B > C+D) {
    cout << "Left" << endl;
  } else if ( A+B == C+D ){
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
from bisect import bisect_right
while True:
    N = int(input())
    if N==0:
        break
    mem = []  # (l, r, id)
    for _ in range(N):
        command = input().split()
        if command[0]=="W":
            Id, S = map(int, command[1:])
            subS = S
            idx_mem = 0
            idx = 0
            while idx_mem < len(mem):
                l, r, _ = mem[idx_mem]
                if idx != l:
                    space = l - idx
                    assert space > 0, (mem, l, idx)
                    if subS <= space:
                        mem.insert(idx_mem, [idx, idx+subS, Id])
                        subS = 0
                        break
                    else:
                        mem.insert(idx_mem, [idx, idx+space, Id])
                        subS -= space
                        idx_mem += 1
                idx = r
                idx_mem += 1
            else:
                mem.append([idx, idx+subS, Id])

        elif command[0]=="D":
            Id = int(command[1])
            for idx_mem in range(len(mem)-1, -1, -1):
                if mem[idx_mem][2] == Id:
                    del mem[idx_mem]
        else:
            P = int(command[1])
            idx_mem = bisect_right(mem, [P, 100000000000000, -1]) - 1
            #print(mem, idx_mem)
            if idx_mem==-1:
                print(-1)
            else:
                l, r, id_ = mem[idx_mem]
                if P < r:
                    print(id_)
                else:
                    print(-1)
    print()



Measured memory_bytes: 5920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int sum = 0;
		if(y % 2 != 0) {
			System.out.println("No");
		} else {
			for(int i = 0; i <= x; i++) {
				sum = i * 2 + (x - i) * 4;
				if(sum == y) {
					System.out.println("Yes");
					return;
				}
			}
			System.out.println("No");
		}
	}
}


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

using ll=long long;


int main(){
    int tt=1;
    //cin>>tt;
    while(tt--){
        int n,i;
        cin>>n;
        if(n%1000 == 0)cout<<0;
        else
        cout<<1000 - (n%1000);
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define INF 1000000000
#define F first
#define S second

int dy[4] = { 0, 1, 0, -1 };
int dx[4] = { -1, 0, 1, 0 };
int main() {
	int N;
	while (cin >> N, N) {
		vector<pair<int, int>> vp;
		vp.emplace_back(200, 200);
		REP(i, 0, N - 1) {
			int n, d;
			cin >> n >> d;

			int ny = vp[n].F + dy[d];
			int nx = vp[n].S + dx[d];
			vp.emplace_back(ny, nx);
		}

		int ymin = INF, ymax = -INF, xmin = INF, xmax = -INF;
		REP(i, 0, vp.size()) {
			ymin = min(ymin, vp[i].F);
			ymax = max(ymax, vp[i].F);
			xmin = min(xmin, vp[i].S);
			xmax = max(xmax, vp[i].S);
		}

		cout << xmax - xmin + 1 << " " << ymax - ymin + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3076
/* AtCoder Beginner Contest 148. Task E - Double Factorial. */
#include <bits/stdc++.h>

using namespace std;

#define COUT_PRECISION 10

namespace abreto {

typedef long long int ll;

ll N;

ll answer(void) {
    if (N & 1) return 0;

    ll ans = 0;
    N /= 2;
    while (N > 4) {
        N /= 5;
        ans += N;
    }
    return ans;
}

void main(void) {
    cin >> N;
    cout << answer() << '\n';
}

}

int main(void) {
    cin.sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(COUT_PRECISION);
    abreto::main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; i++) // mからnまで

int main(){
    float D , T , S ;
    cin >> D >> T >> S;


    if ( D / T > S ){
      cout << "No" ;
    }else{
      cout << "Yes" ;
    }

    return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int a, b, k;
	cin >> a >> b >> k;

	bool which = 1;
	REP(i, k){
		if(which){
			b += a/2;
			a /= 2;
			which = 0;
		}else{
			a += b/2;
			b /= 2;
			which = 1;
		}
	}

	cout << a << ' ' << b << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import deque

h,w = map(int, input().split())
s = ["0" * (w+2)]  + ["0"+input()+"0" for i in range(h)] + ["0" * (w+2)] 
not_visited = [[0] * (w+2)] + [[0] + [1] * w + [0] for i in range(h)] + [[0] * (w+2)]
ans = 0
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j] == ".":
      continue
    black, white = 1,0
    queue = deque([(i,j,1)])
    not_visited[i][j] = 0
    while queue:
      H,W,color = queue.popleft()
      if not_visited[H-1][W]:
        if color and s[H-1][W] == ".":
          not_visited[H-1][W] = 0
          white += 1
          queue.append((H-1,W,0))
        elif color == 0 and s[H-1][W] == "#":
          not_visited[H-1][W] = 0
          black += 1
          queue.append((H-1,W,1))
      if not_visited[H+1][W]:
        if color and s[H+1][W] == ".":
          not_visited[H+1][W] = 0
          white += 1
          queue.append((H+1,W,0))
        elif color == 0 and s[H+1][W] == "#":
          not_visited[H+1][W] = 0
          black += 1
          queue.append((H+1,W,1))
      if not_visited[H][W-1]:
        if color and s[H][W-1] == ".":
          not_visited[H][W-1] = 0
          white += 1
          queue.append((H,W-1,0))
        elif color == 0 and s[H][W-1] == "#":
          not_visited[H][W-1] = 0
          black += 1
          queue.append((H,W-1,1))
      if not_visited[H][W+1]:
        if color and s[H][W+1] == ".":
          not_visited[H][W+1] = 0
          white += 1
          queue.append((H,W+1,0))
        elif color == 0 and s[H][W+1] == "#":
          not_visited[H][W+1] = 0
          black += 1
          queue.append((H,W+1,1))
    ans += black * white
print(ans)

Measured memory_bytes: 76784
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N;
int A[300], K[300];

int f(int n, int k) {
    while (n % k) {
        itn a = (n + k - 1) / k;
        n -= (n - k * (a - 1)) / a * a;
        if (n <= k * (a - 1))
            n += a;

        if ((n % k))
            n = n * (k - 1) / k;
    }
    return n / k;
    /*
    if (n == 0) {
        return 0;
    }
    if (n % k == 0) {
        return n / k;
    } else
        return f(n * (k - 1) / k, k);
    */
}

void solve() {
    int grn = 0;
    FOR(N) {
        grn ^= f(A[i], K[i]);
    }
    if (grn) {
        cout << "Takahashi" << endl;
    } else
        cout << "Aoki" << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(N)
    cin >> A[i] >> K[i];


    solve();
    return 0;
}


Measured memory_bytes: 384
fun main(args: Array<String>) {
        val inputs = read()
        if (isEven(inputs[0] * inputs[1]))
            println("Even")
        else
            println("Odd")
    }

    fun read(): List<Int> {
        val input = readLine()
        return input!!.split(" ").map { Integer.parseInt(it) }
    }

    fun isEven(arg: Int): Boolean {
        return (arg % 2) == 0
    }


Measured memory_bytes: 35948
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    i = 1
    flag = True
    for a in A:
        if a == i:
            flag = False
            i += 1
    if flag:
        print(-1)
    else:
        print(len(A) - i + 1)


if __name__ == "__main__":
    main()


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

int main(){
    string o, e;
    cin >> o >> e;
    int n = o.length()+e.length();
    for(int i=0; i<n; i++){
        if(i%2==0) cout << o[i/2];
        else cout << e[i/2];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define x first
#define y second
#define mp make_pair
#define pii pair<int,int>
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
int main(){
    char c[500005];
    scanf("%s",c+1);
    LL Min[500005];
    Min[0]=0;
    for(int i = 1;c[i]!=0;i++){
        if(c[i]=='>'){
            Min[i]=0;
        }
        else{
            Min[i]=Min[i-1]+1;
        }
    }
    LL sum=0;
    LL last=Min[strlen(c+1)];
    for(int i=strlen(c+1);i>=0;i--){
      //  printf("%lld ",last);
        sum+=last;
        if(c[i]=='>')last=max(last+1,Min[i-1]);
        else last=Min[i-1];//=max(Min[i-1],last-1);
     
    }
    printf("%lld\n",sum);
}

Measured memory_bytes: 4608
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	private void run_case() {
		HashMap<Integer, TreeMap<Integer, Integer>> adj = new HashMap<>();
		int n = reader.ni();
		int m = reader.ni();
		int[] hei = new int[n+5];
		for (int i=1; i<=n; i++) {
			int h = reader.ni();
			hei[i] = h;
			// adj.put(i, new TreeMap<>());
			// adj.get(i).put(i, h);
		}
		boolean[] bad = new boolean[n+1];
		for (int i=0; i<m; i++) {
			int a = reader.ni();
			int b = reader.ni();
			if (hei[a] > hei[b]) {
				bad[b] = true;
			} else if (hei[a] < hei[b]) {
				bad[a] = true;
			} else {
				bad[a] = bad[b] = true;
			}
			// adj.get(a).put(b, hei[b]);
			// adj.get(b).put(a, hei[a]);
		}
		int ans = 0;
		for (int i=1; i<=n; i++) {
			// if (adj.get(i).lastKey())
			if (!bad[i]) ans ++;
		}
		out.println(ans);
		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 53956
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;

string s;

int main()
{
    cin >> s;
    int n = s.size();
    string ans="";
    rep(i,n){
        if(s[i] == '0') ans += '0';
        else if(s[i] == '1') ans += '1';
        else{
            if(ans.size() != 0) ans.erase(ans.end()-1);
        }
    }
    cout << ans << endl;
}



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

using namespace std;

int main(){
 int n;
 while(1){
  cin >> n;
  if(n==0)break;
  long long a[n],i,ans=1e7;
  for(i=0;i<n;i++)cin >> a[i];
  sort(a,a+n);
  for(i=0;i<n-1;i++)ans=min(ans,a[i+1]-a[i]);
  cout << ans << endl;
 }
 return 0;
}


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

using namespace std;
using ll = long long;

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  ll n;
  cin >> n;
  vector<ll>a (n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  multiset<ll>s;
  s.insert (a[0]);
  for (ll i = 1; i < n; i++) {
    auto it = s.lower_bound (a[i]);
    if (it != s.begin() ) {
      it--;
      s.erase (it);
    }
    s.insert (a[i]);
  }
  cout << (ll) s.size() << '\n';
  return 0;

}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n,ans;
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	rep(i,1,n){
		rep(j,1,n){
			rep(k,1,n){
				ans += gcd(i,gcd(j,k));
			}
		}
	}	
	cout << ans << endl;
	return 0; 
}
//do smt instead of nothing! never give up!

Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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


int main(){
  ll h,w; cin >> h >> w;
  
  vector<vector<char>> table(h,vector<char>(w));
  vvl cnttable(h,vl(w,1e9));

  
  rep(i,h){
    rep(j,w) cin >> table[i][j];
  } 
  
  if(table[0][0] == '#') cnttable[0][0] = 1;
  else cnttable[0][0] = 0;
  
  rep(i,h){
    rep(j,w){

      if(i+1 < h){
        if(table[i][j] == '.' and table[i+1][j] == '#'){
          cnttable[i+1][j] = min(cnttable[i][j] + 1,
                                 cnttable[i+1][j]);
        }
        else cnttable[i+1][j] = min(cnttable[i+1][j],
                                    cnttable[i][j]);
      }
      if(j+1 < w){
        if(table[i][j] == '.' and table[i][j+1] == '#'){
          cnttable[i][j+1] = min(cnttable[i][j] + 1,
                                 cnttable[i][j+1]);
        }
        else cnttable[i][j+1] = min(cnttable[i][j],
                                    cnttable[i][j+1]);
      }
    }
  }
  
  /*for(auto array : cnttable){
    for(ll c : array){
      cout << c;
    }
    cout << endl;
  }
  */
  
  cout << cnttable[h-1][w-1] << endl;
  
  
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll countGreater(ll arr[], ll n, ll k) 
{ 
    ll l = 0; 
    ll r = n - 1; 
  
 
    ll leftGreater = n; 
  
 
    while (l <= r) { 
        ll m = l + (r - l) / 2; 
  
        if (arr[m] > k) { 
            leftGreater = m; 
            r = m - 1; 
        } 
  
 
        else
            l = m + 1; 
    } 
  
   
    return (n - leftGreater); 
}
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}

ll ans(ll A[],ll left,ll right,ll x)
{
    if(A[left]==x)return 1;

    else if(A[right==x])return 1;

   ll m=left+(right-left)/2;
   while(left<=right)
   {
    if(A[m]>x)right=m-1;
    else if(A[m]<x)left=m+1;
    else return 1;
   }
   return 0;
} 
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll n,a,b,a1,b1,temp1,temp2,i,ans=0,flag=0;
cin>>a>>b;
  

  b1=b*10;
  a1=a*(25)/2;

  temp1=min(a1,b1);
  temp2=max(a1,b1);

  for(i=temp1-100;i<=temp2+100;i++)
  {
    if(i*10/100==b&&i*8/100==a)
    {
        flag=1;
        ans=i;
        break;
    }
  }

  if(flag)cout<<ans<<endl;
  else cout<<-1<<endl;

    return 0;
    
}


 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        // その結果を push
        res.push_back({a, ex});
    }
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
/* vector<pair<ll,ll>>で受け取る！
例えば360=2^3*3^2*5は
{{2,3},{3,2},{5,1}}*/

int main() {
    vector<int> a(1001);
    int n;cin >> n;
    for(int i = 1; i <= n; i++) {
        vector<pair<ll,ll>> x=prime_factorize(i);
        for(int j = 0; j < x.size(); j++) {
            int s=x[j].first,t=x[j].second;
            a[s] += t;
        }
    }
    ll ans=1;
    for(int i = 0; i < 1001; i++) {
        ans *= (a[i]+1);
        ans %= INF;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

H, W, K = get_ints
MOD = 10 ** 9 + 7

if W == 1
  puts 1
else
  @W = W - 1
  @memo = {}

  @memo2 = {}

  def honsu_keisan(width, prev_exist)
    return @memo2[[width, prev_exist]] if @memo2[[width, prev_exist]]
    return 0 if width == 0
    if width == 1
      return prev_exist ? 1 : 2
    end

    result = if prev_exist
      honsu_keisan(width - 1, false)
    else
      honsu_keisan(width - 1, false) + honsu_keisan(width-1, true)
    end
    @memo2[[width, prev_exist]] = result
    result
  end

  def other_cases(start_w, end_w)
    res = []
    if start_w > 0
      res << honsu_keisan(start_w - 1, false)
    end
    if end_w < @W
      res << honsu_keisan(@W - (end_w + 1), false)
    end
    res = res.filter { |x| x != 0 }
    return 1 if res.empty?

    ans = 1
    res.each do |x|
      ans *= x
    end
    ans % MOD
  end

  def dfs(start_w, end_w, height)
    if @memo[[start_w, end_w, height]]
      return @memo[[start_w, end_w, height]]
    end

    if height == 0
      if start_w == end_w
        return 1
      else
        return 0
      end
    end

    res = [dfs(start_w, end_w, height - 1) * other_cases(start_w, start_w)]
    if start_w > 0
      res.push dfs(start_w - 1, end_w, height - 1) * other_cases(start_w - 1, start_w)
    end
    if start_w < @W
      res.push dfs(start_w + 1, end_w, height - 1) * other_cases(start_w, start_w + 1)
    end

    sum = res.sum % MOD
    sum.tap { |sum| @memo[[start_w, end_w, height]] = sum }
  end

  puts dfs(0, K-1, H)
end




Measured memory_bytes: 14364
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    h,w = map(int, input().split())
    a = [list(input().rstrip()) for _ in range(h)]
    
    s = 0
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                if s != j:
                    print('Impossible')
                    exit()
                s +=  1
        s -= 1

    if s == w-1:
        print('Possible')
    else:
        print('Impossible')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
def inverse(a, p):
    """逆元"""
    a_, p_ = a, p
    x, y = 1, 0
    while p_:
        t = a_ // p_
        a_ -= t * p_
        a_, p_ = p_, a_
        x -= t * y
        x, y = y, x
    x %= p
    return x


# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(n, k):
    mod = 10 ** 9 + 7
    ans = 0
    p_mod = [1, 1]
    for i in range(2, n + 1):
        p_mod.append((p_mod[-1] * i) % mod)

    for i in range(min(n, k + 1)):
        if i == 0:
            ans += 1
        elif i == 1:
            ans += n * (n - 1)
        else:
            nCi = p_mod[n] * inverse(p_mod[n - i], mod) % mod * inverse(p_mod[i], mod) % mod
            nmHi = (p_mod[n - 1] * inverse(p_mod[n - i - 1], mod) % mod) * inverse(p_mod[i], mod) % mod
            # ans += cmb2(n, i, mod) * cmb2(n - 1, i, mod)
            ans += nCi * nmHi % mod
        ans %= mod
    print(ans)


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    n, k = map(int, input().split())
    # Ai = [int(i) for i in input().split()]
    # Bi = [int(i) for i in input().split()]
    # ABi = [[int(i) for i in input().split()] for _ in range(N)]
    solve(n, k)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Measured memory_bytes: 87116
#include <stdio.h>

int main (void)
{
	
	char a,s;
	int i,j,n,m;
	int card[4][13]={0};
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf(" %c",&s);
		scanf("%d",&m);
		if(s == 'S' )
		card[0][m-1]=1;
		if(s == 'H' )
		card[1][m-1]=1;
		if(s == 'C' )
		card[2][m-1]=1;
		if(s == 'D' )
		card[3][m-1]=1;
	}
	
	for( i=0; i<4; i++){
		if(i == 0)
		a = 'S';
		if(i == 1)
		a = 'H';
		if(i == 2)
		a = 'C';
		if(i == 3)
		a = 'D';

		
		for( j=0; j<13; j++){
			if(card[i][j]==0)
			{
				printf("%c %d\n",a,j+1);
			}
			
		}
	}
	return 0;
}

Measured memory_bytes: 596
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  n :: Int <- readLn
  xs :: U.Vector Int64 <- U.fromListN n . map (read . BS.unpack) . BS.words <$> BS.getLine
  let negatives = U.filter (<= 0) xs
  if even (U.length negatives)
    then print $ U.sum $ U.map abs xs
    else let positives = U.filter (> 0) xs
             mn = U.maximum negatives
             mp = U.minimum positives
         in if U.null positives || abs mp > abs mn
            then print $ (U.sum $ U.map abs xs) + 2 * mn
            else print $ (U.sum $ U.map abs xs) - 2 * mp


Measured memory_bytes: 6908
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC086C solver = new ABC086C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC086C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 整数の入力
            int N = Integer.parseInt(in.next());
            int[] t = new int[N + 1];
            int[] x = new int[N + 1];
            int[] y = new int[N + 1];
            for (int i = 0; i < N; i++) {
                t[i + 1] = Integer.parseInt(in.next());
                x[i + 1] = Integer.parseInt(in.next());
                y[i + 1] = Integer.parseInt(in.next());
            }

            boolean ans = true;

            for (int i = 0; i < N; i++) {
                int dt = t[i + 1] - t[i];
                int dest = Math.abs(x[i + 1] - x[i]) + Math.abs(y[i + 1] - y[i]);

                if (dt < dest) ans = false;
                if (dest % 2 != dt % 2) ans = false;
            }

            // 出力
            if (ans) {
                out.println("Yes");
            } else {
                out.println("No");
            }

        }

    }
}



Measured memory_bytes: 62976
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arr[200005];
multiset<ll> S;
std::vector<ll> V;

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
		// S.insert(arr[i]);
		V.push_back(arr[i]);
	}
	sort(V.begin(), V.end());
	ll temp1 = V[V.size() / 2];
	ll temp2 = V[(V.size() / 2) - 1];
	

	for(int i = 0; i < N; i++) {
		if(arr[i] < temp1) {
			cout << temp1 << "\n";
		}
		else {
			cout << temp2 << "\n";
		}
	}



	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 5488
#include <iostream>

using namespace std;

int main()
{
  int p;
  int a,b,c,d;
  int x,y;
  int over;

  cin >> a >> b >> c >> d >> p;

  x = p*a;


  if(p <= c)
    {
      y = b;
    }
  else
    {
      over = p-c;
      y = b+over*d;
    }

  if(x <= y)
    {
      cout << x << endl;
    }
  else
    {
      cout << y << endl;
    }
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

struct state{
	int x, y, cx, cy, d;
	bool operator<(const state &r) const{
		return d > r.d;
	}
};

int field[10][10];

int dist[10][10][10][10];

inline int &f(state &s){
	return dist[s.x][s.y][s.cx][s.cy];
}

int w, h;
inline bool ng(int x, int y){
	if (x < 0 || x >= w || y < 0 || y >= h) return true;
	return field[y][x] == 1;
}

int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0, -1 };
int main(){
	while (cin >> w >> h, w|h){
		state init;
		int gx, gy;
		rep(i, h) rep(j, w){
			cin >> field[i][j];
			if (field[i][j] == 2) init.cx = j, init.cy = i;
			if (field[i][j] == 4) init.x = j, init.y = i;
			if (field[i][j] == 3) gx = j, gy = i;
		}

		MEMSET(dist, 0x7f);
		f(init) = 0;
		init.d = 0;
		priority_queue<state> q;
		q.push(init);
		bool ok = false;
		while (!q.empty()){
			state s = q.top();
			q.pop();

			if (f(s) < s.d) continue;
			if (s.cx == gx && s.cy == gy){
				ok = true;
				cout << s.d << endl;
				break;
			}

			rep(i, 4){
				int nx = s.x + dx[i], ny = s.y + dy[i];
				int ncx = s.cx, ncy = s.cy;
				int d = 0;
				if (nx == ncx && ny == ncy){
					ncx += dx[i];
					ncy += dy[i];
					++d;
				}
				if (ng(nx, ny) || ng(ncx, ncy)) continue;
				state nxt = {nx, ny, ncx, ncy, s.d+d};
				if (f(nxt) <= nxt.d) continue;
				f(nxt) = nxt.d;
				q.push(nxt);
			}
		}
		if (!ok) cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1260
#include<iostream>
using namespace std;
int main() {
	long long int A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K <= A) {
		cout << K << endl;
	}
	else if (K <= B ) {
		cout << K << endl;
	}
	else {
		cout << A - (K - A - B) << endl;
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  queue<string> Q;
  string s="a";
  Q.push(s);
  while(1){
    string temp;
    temp = Q.front();
    if(temp.size()>=n) break;
    Q.pop();

    for(char p='a';p<='j';++p){
      char max_c = 'a';
      rep(i,temp.size()){
        if(max_c<temp[i]) max_c=temp[i];
      }
      if(max_c+1>=p){
        string t;
        t = temp+p;
        Q.push(t);
      }
    }
  }

  while(!Q.empty()){
    string temp;
    temp = Q.front();
    Q.pop();
    cout << temp << endl;
  }
  
}


Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void) {
	string s;
	cin >> s;
	
	int n = s.size();
	vector<int> lr(n);
	for(int i = 0; i < n; ++i) {
		lr[i] = (s[i] == 'L' ? 1 : -1);
	}
	
	vector<int> n_child(n, 0);
	int num_odd = 0;
	int num_even = 1;
	for(int i = 1; i < n; ++i) {
		if(i % 2 == 0) ++num_even;
		else ++num_odd;
		if(lr[i] > lr[i-1]) {
			int j = i + 1;
			for(; lr[j] >= lr[j-1]; ++j) {
				if(j % 2 == 0) ++num_even;
				else ++num_odd;
			}
			n_child[i] += (i % 2 == 0 ? num_even : num_odd);
			n_child[i-1] += (i % 2 == 0 ? num_odd : num_even);
			num_odd = 0;
			num_even = 0;
			i = j - 1;
		}
	}

	for(int i = 0; i < n; ++i) {
		cout << n_child[i] << " ";
	}
	cout << endl;

	return 0;
}


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

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, x, y, z, w, h, ans = 0, cnt = 0, max = 0;
string s;

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

    cin >> a >> b;
    ll dif = b - a;
    while(dif--){
        cnt += dif;
    }
    cnt -= a;
    cout << cnt << endl;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int N, K, X, Y; cin >> N >> K >> X >> Y;

    int total = 0;
    if (N <= K) {
        total = N*X;
    } else {
        total = K*X+(N-K)*Y;
    }

    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}


int win[2][500][500];

bool rec(int X, int Y, bool alice) {
	if (X <= 1 && Y <= 1) return win[alice][X][Y] = (int)!alice;
	if (win[alice][X][Y] >= 0) return win[alice][X][Y];
	
	if (alice) {
		bool res = false;
		int mxi = X / 2 + 1;
		for_(i,1,mxi) res |= rec(X - 2 * i, Y + i, false);
		mxi = Y / 2 + 1;
		for_(i,1,mxi) res |= rec(X + i, Y - 2 * i, false);
		return win[1][X][Y] = (int)res;
	} else {
		bool res = true;
		int mxi = X / 2 + 1;
		for_(i,1,mxi) res &= rec(X - 2 * i, Y + i, true);
		mxi = Y / 2 + 1;
		for_(i,1,mxi) res &= rec(X + i, Y - 2 * i, true);
		return win[0][X][Y] = (int)res;
	}
}


int main() {
	/*
	memset(win, -1, sizeof(win));
	
	for_(X,0,10) {
		for_(Y,0,200) {
			cout << rec(X, Y, true);
		}
		cout << endl;
	}
	*/
	
	lint X, Y;
	cin >> X >> Y;
	
	lint yL = -1 + X, yR = 1 + X;
	puts(yL <= Y && Y <= yR ? "Brown" : "Alice");
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int test = 1;
		int currentHighestDivisible = 0;
		int currentWinner = 1;
		
		while (test <= x) {
			int testDividedByTwo = test;
			int testFactorsOfTwo = 0;
			while (testDividedByTwo % 2 == 0) {
				testFactorsOfTwo += 1;
				testDividedByTwo = testDividedByTwo/2;
			}
			if (testFactorsOfTwo > currentHighestDivisible) {
				currentWinner = test;
				currentHighestDivisible = testFactorsOfTwo;
				test += 1;
			} else {
				test += 1;
			}
		}
		System.out.println(currentWinner);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	long long a, b;
	cin >> a >> b;
	if(a * b < 0 || a * b == 0) {
		cout << "Zero" << endl;
		return 0;
	}
	if(a > 0) {
		cout << "Positive" << endl;
		return 0;
	}
	cout << (abs(a - b) % 2 == 1 ? "Positive" : "Negative") << endl;
	return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
vector<int>adj_list[200005];

void dfs(int u,vector<int>&flag,int *kitna)
{
  *kitna=*kitna+1;
  flag[u]=1;
  for(auto v:adj_list[u])
  {
    if(flag[v]==-1)
    {
      dfs(v,flag,kitna);
    }
  }
}
 
int32_t main()
{
  vector<int>arr;
  int n;int m;cin>>n>>m;
  vector<int>flag(n+1,-1);
  for(int i=1;i<=m;i++)
  {
    int u;int v;cin>>u>>v;
    adj_list[u].push_back(v);
    adj_list[v].push_back(u);
  }
  for(int i=1;i<=n;i++)
  {
    if(flag[i]==-1)
    {
      int kitna=0;
      dfs(i,flag,&kitna);
      arr.push_back(kitna);
    }
  }
  int ans=*max_element(arr.begin(),arr.end());
  cout<<ans<<endl;
}

Measured memory_bytes: 25072