akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
int a[300000];
int main() {
    scanf("%d%d",&k,&n);
    if (k%2==0) {
        printf("%d",k/2);
        for (int i=1;i<n;++i) printf(" %d",k);
        printf("\n");
    } else {
        fill(a,a+n,(k+1)/2);
        int t=n-1;
        for (int i=0;i<n/2;++i) {
            if (a[t]!=0) a[t]--;
            else {
                a[t-1]--;
                a[t]=k;
                if (a[t-1]!=0) t=n-1;
                else t--;//下一步还会再处理的
            }
        }
        for (int i=0;i<n;++i) {
            printf("%d",a[i]);
            if (a[i+1]!=0) printf(" ");
            else break;
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 3456
import Control.Applicative((<$>))
import Control.Monad (forM_, unless)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Char (isSpace)
import Data.Vector (Vector)
import qualified Data.Vector as V
import Data.Vector.Mutable (IOVector)
import qualified Data.Vector.Mutable as VM

main :: IO ()
main = do
  n <- readLn
  ia <- getl (readiv B.readInt)
  ia' <- V.thaw ia
  insertionSort ia' n

insertionSort :: IOVector Int -> Int -> IO ()
insertionSort a n = do
  printa a n
  forM_ [1 .. n-1] $ \i -> do
    v <- VM.read a i
    let j = i - 1
    j' <- loop a j v
    VM.write a (j' + 1) v
    printa a n
  where
    loop :: IOVector Int -> Int -> Int -> IO Int
    loop a j v = do
      if j < 0 then return j
      else do
        u <- VM.read a j
        if u <= v then return j
        else do
          VM.write a (j+1) u
          loop a (j - 1) v

printa :: IOVector Int -> Int -> IO ()
printa a n = do
  forM_ [0 .. n-1] $ \i -> do
    unless (i == 0) $ putStr " "
    v <- VM.read a i
    putStr $ show v
  putStrLn ""

getl :: (ByteString -> a) -> IO a
getl f = f <$> B.getLine

readiv :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> Vector a
readiv f = V.unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')



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

using namespace std;

typedef long long ll;

int main() {
  ll a, b, k; cin >> a >> b >> k;
  ll aa = a - min(a, k);
  k -= min(a, k);
  ll bb = b - min(b, k);
  cout << aa << ' ' << bb;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

struct Node {
	Node *parent, *left, *right;
	int key;
};

Node *root, *nil;

void insert(int& a) {
	Node *b = (Node*)malloc(sizeof(Node)), *c = root, *d = nil;
	b->left = nil;
	b->right = nil;
	b->key = a;
	while (c != nil) {
		d = c;
		if (b->key < c->key) c = c->left;
		else c = c->right;
	}
	b->parent = d;
	if (b->parent == nil) root = b;
	else if (b->key < b->parent->key) b->parent->left = b;
	else b->parent->right = b;
}

Node* find(int& a) {
	Node* b = root;
	while (b != nil && a != b->key) {
		if (a < b->key) b = b->left;
		else b = b->right;
	}
	return b;
}

Node* getMinimum(Node* a) {
	while (a->left != nil) a = a->left;
	return a;
}

Node* getSuccessor(Node* a) {
	if (a->right != nil) return getMinimum(a->right);
	Node* b = a->parent;
	while (b != nil && a == b->right) {
		a = b;
		b = b->parent;
	}
	return b;
}

void erase(int& a) {
	Node *b = find(a), *c, *d;
	if (b->left == nil || b->right == nil) c = b;
	else c = getSuccessor(b);
	b->key = c->key;
	if (c->left != nil) d = c->left;
	else d = c->right;
	if (d != nil) d->parent = c->parent;
	if (c->parent == nil) root = d;
	else if (c == c->parent->left) c->parent->left = d;
	else c->parent->right = d;
	free(c);
}

void inorderTreeWalk(Node* a = root) {
	if (a != nil) {
		inorderTreeWalk(a->left);
		cout << ' ' << a->key;
		inorderTreeWalk(a->right);
	}
}

void preorderTreeWalk(Node* a = root) {
	if (a != nil) {
		cout << ' ' << a->key;
		preorderTreeWalk(a->left);
		preorderTreeWalk(a->right);
	}
}

int main() {
	int m, k;
	cin >> m;
	for (int i = 0; i < m; i++) {
		string a;
		cin >> a;
		if (a == "insert") {
			cin >> k;
			insert(k);
		}
		else if (a == "find") {
			cin >> k;
			if (find(k) == nil) cout << "no";
			else cout << "yes";
			cout << endl;
		}
		else if (a == "delete") {
			cin >> k;
			erase(k);
		}
		else {
			inorderTreeWalk();
			cout << endl;
			preorderTreeWalk();
			cout << endl;
		}
	}
}


Measured memory_bytes: 21904
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n;
cin>>n;
ll k;
cin>>k;
ll h;
ll ans=0;
for(int i=0;i<n;i++){
    cin>>h;
    if(h>=k){
        ans++;
    }
}
cout<<ans<<endl;
}










Measured memory_bytes: 256
/*************************************************************************
  >         File: A.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sat 01 Oct 2016 08:02:26 PM CST
*************************************************************************/
#include <bits/stdc++.h>

int main() {
  std::ios::sync_with_stdio(0);
  std::string s;
  std::cin >> s;
  int now = 0;
  int answer = 0;
  for (int i = 0; i < (int) s.size(); ++i) {
    if (s[i] == 'T') now--;
    else now++;
    if (now < 0) {
      answer++;
      now = 0;
    }
  }
  answer += now;
  std::cout << answer << std::endl;


  return 0;
}


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

struct UnionFind
{
  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1)
  {
    rep(i,n)
      par[i] = i;
  }

  int find(int x)
  {
    if (x == par[x])
      return x;
    return par[x] = find(par[x]);
  }

  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);

    if (x == y)
      return;

    if (sizes[x] < sizes[y])
      swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
  }

  bool same(int x, int y)
  {
    return find(x) == find(y);
  }

  int size(int x)
  {
    return sizes[find(x)];
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> e(m);
  rep(i, m)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[i] = make_pair(a, b);
  }
  int ans = 0;
  rep(i, m)
  {
    UnionFind u(n);
    rep(j, m)
      if (i != j)
        u.unite(e[j].first, e[j].second);
    if (u.size(0) != n)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	char cards[200+1];
	int n,m,h,p,i;

	while (1)
	{
		scanf("%200s",cards);

		if (!strcmp(cards,"-")) break;

		n = strlen(cards);
		scanf("%d",&m);
		p = 0;

		for (i = 0; i < m; i++)
		{
			scanf("%d",&h);
			p = (p + h) % n;
		}

		for (i = 0; i < n; i++)
			printf("%c",cards[(p + i) % n]);
		printf("\n");

	}

	return 0;
}

Measured memory_bytes: 1748
#include<stdio.h>
int main()
{
    int i,h,len,j,n,k;
    scanf("%d",&h);
    if(h<1200){
        printf("ABC\n");
    } else if(h<2800&&h>=1200){
        printf("ARC\n");
    } else{
        printf("AGC\n");
    }
    return 0;
}


Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0]){
        puts("YES");
    }else{
        puts("NO");
    }

    return 0;
}

Measured memory_bytes: 3556
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]
def SR(n):
    return [S() for _ in range(n)]
def LSR(n):
    return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 998244353

def solve():
    def add(i,x):
        while i < len(dp):
            dp[i] += x
            dp[i] %= mod
            i += i&-i
    def sum(i):
        res = 0
        while i:
            res += dp[i]
            res %= mod
            i -= i&-i
        return res

    n,k = LI()
    p = LIR(k)
    p.sort()
    dp = [0]*(n+2)
    add(1,1)
    add(2,-1)
    for i in range(1,n):
        dpi = sum(i)%mod
        for l,r in p:
            li = i+l
            if li > n:
                break
            ri = min(n,i+r)+1
            add(li,dpi)
            add(ri,-dpi)
    print(sum(n)%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 70944
(let* ((n (read))
       (m (read))
       (a (list (read) (read) (read)))
       (lst (sort (concatenate 'list
                               (loop :repeat (first a) :collect (cons (read) 1))
                               (loop :repeat (second a) :collect (cons (read) 2))
                               (loop :repeat (third a) :collect (cons (read) 0)))
                  #'> :key #'car))
       (stkcount 0)
       (ans 0))
  (loop :for (k . j) :in lst :if (= (+ n m) stkcount) :return 0 :end
        :do(cond ((= j 1) (if (not (= 0 n))
                              (progn (decf n) (incf ans k))))
                 ((= j 2) (if (not (= 0 m))
                              (progn (decf m) (incf ans k))))
                 ((= j 0) (incf stkcount) (incf ans k))))
  (princ ans))

Measured memory_bytes: 71976
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a, b, c;
    cin >> a >> b >> c;
    cout << char(a[0] - 'a' + 'A');
    cout << char(b[0] - 'a' + 'A');
    cout << char(c[0] - 'a' + 'A');
}


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

int main() {
  int n;
  cin >> n;
  unll p=1;
  for(int i=1;i<=n;i++){
    p *= i;
    p %= 1000000000 + 7;
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

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

    BigDecimal a = new BigDecimal(sc.next());
    BigDecimal b = new BigDecimal(sc.next());

    System.out.println(a.multiply(b).longValue());
  }
}


Measured memory_bytes: 35972
#include<iostream>
#include<cstdio>
#define INF 1<<30
#define MAX 1000000
using namespace std;


struct edge {
  int from,to,cost,k;
};

edge es[MAX];



int main(){
  int n,u,k,E,c,v;
  E = 0;
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);
   
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }

  
  int d[MAX];
  for(int i=0;i<n;i++)d[i] = INF;
  d[0] = 0;
  while(true){
    bool update = false;
    for(int i=0;i<E;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	update = true;
      }
    }
    if(!update)break;


  }

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

  return 0;
}

Measured memory_bytes: 8644
#include<stdio.h>

int main()
{
	int n,i;
	int ac = 0, wa = 0, tle = 0, re = 0;
	char str[100000][4];
	
	scanf("%d",&n);
	
	for (i = 0; i < n; i++) {
		scanf("%s",str[i]);
	}
	
	for (i = 0; i < n; i++) {
		if ((str[i][0] == 'A') && (str[i][1] == 'C'))
			ac++;
		else if ((str[i][0] == 'W') && (str[i][1] == 'A'))
			wa++;
		else if ((str[i][0] == 'T') && (str[i][1] == 'L') && (str[i][2] == 'E'))
			tle++;
		else if ((str[i][0] == 'R') && (str[i][1] == 'E'))
			re++;
	}
	
	printf("AC x %d\n",ac);
	printf("WA x %d\n",wa);
	printf("TLE x %d\n",tle);
	printf("RE x %d\n",re);
	
	return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll N, M;
ll A[305][305];
ll B[305];
ll C[305];
bool U[305];

bool solve(ll n)
{
    memset(B, 0, sizeof(B));
    memset(U, 0, sizeof(U));
    while (true)
    {
        memset(C, 0, sizeof(C));
        REP(i, N)
        {
            C[A[i][B[i]]]++;
        }
        bool e = true;
        REP(i, M)
        {
            if (C[i] > n)
            {
                U[i] = true;
                e = false;
            }
        }
        if (e)
            return true;
        REP(i, N)
        {
            while (B[i] < M && U[A[i][B[i]]])
                B[i]++;
            if (B[i] >= M)
                return false;
        }
    }
    return false;
}

int main()
{
    cin >> N >> M;
    REP(i, N)
    {
        REP(j, M)
        {
            cin >> A[i][j];
            A[i][j]--;
        }
    }

    ll ok = N, ng = 0;
    while (abs(ok - ng) > 1)
    {
        ll mid = (ok + ng) / 2;
        if (solve(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll A, B, M;
    cin >> A >> B >> M;
    ll ans = 1e18;

    vector<ll> a(A), b(B);

    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];

    rep(i, M){
        ll x, y, c;
        cin >> x >> y >> c;
        --x, --y;
        ans = min(ans, a[x] + b[y] - c);
    }

    ll tmp = *min_element(ALL(a)) + *min_element(ALL(b));

    ans = min(ans, tmp);

    print(ans);

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion



int main(void) {
  cin >> s;
  ans = 700;
  FOR(i, 0, 3) {
	if (s[i] == 'o') ans += 100;
  }
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	string S;
	cin >> S;
	cout << S.substr(0, 4) << " " << S.substr(4, 8) << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
G1 = defaultdict(list); G2 = defaultdict(list)
N, M, S, T = map(int, input().split())
S-=1; T-=1
for i in range(M):
    f, t , v1, v2 = map(int, input().split())
    G1[f-1].append((t-1, v1))
    G1[t-1].append((f-1, v1))
    G2[f-1].append((t-1, v2))
    G2[t-1].append((f-1, v2))

import queue
push = queue.heappush
pop = queue.heappop
INF = 10**16
d1 = [INF]*N; d2 = [INF]*N

def dijkstra(s, G, d):
    q = []
    d[s] = 0
    push(q, (0, s))

    while q:
        cost, v = pop(q)
        # print(f'd[{v}] = {cost}')
        # 既に q から取り出したものの方が低い
        if d[v] < cost:
            continue
        for to, tmpcost in G[v]:
            if d[to] > d[v] + tmpcost:
                d[to] = d[v] + tmpcost
                push(q, (d[to], to))

dijkstra(S, G1, d1)
dijkstra(T, G2, d2)
"""
for i in range(N):
    ans = 0
    for j in range(i, N):
        ans = max(ans, 10**15-d1[j]-d2[j])
    print(ans)
"""
anses = [0]*N
ans = 10**15
for i in range(N):
    ans = min(ans, d1[N-1-i]+d2[N-1-i])
    anses[N-1-i]=10**15-ans
for i in range(N):
    print(anses[i])

Measured memory_bytes: 104372
S = input()
N = len(S)

num = [0] * 2019
num[0] = 1
now, ans = 0, 0
_10 = 1

for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % 2019
    _10 *= 10
    _10 %= 2019
    ans += num[now]
    num[now] += 1
 
print(ans)


Measured memory_bytes: 9296
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

H,W = I()
maze = [list(s()) for _ in range(H)]
visited = [[0]*W for _ in range(H)]
def dfs(x,y):
    if x < 0 or y < 0 or x >= H or y >= W:
        return
    if maze[x][y] == '.':
        return
    visited[x][y] = 1
    dfs(x+1,y)
    dfs(x,y+1)
dfs(0,0)
if visited[H-1][W-1] == 1:
    cnt = 0
    for i in range(H):
        cnt += maze[i].count('#')
    if cnt == H+W-1:
        print('Possible')
    else:
        print('Impossible')
else:
    print('Impossible')

Measured memory_bytes: 27132
from collections import deque, defaultdict
from itertools import combinations
from itertools import product

def bipartite(V, E):
    '''
    Input:
    V = [0, 1, ..., N-1]: a list of vertices of the graph
    E: the adjacency list of the graph
    Output:
    If the graph is bipartite, return [(U_1, U_2) (the parts of the bipartite graph) for each component].
    Else, return None.
    '''
    color = {v: None for v in V}
    part = []
    for v in V:
        if color[v] is not None: continue
        stack = [(v, 0)] # color v with 0
        parts = {0: [], 1: []}
        while stack:
            v, c = stack.pop()
            if color[v] is not None: # consistent
                continue
            color[v] = c
            parts[c].append(v)
            for u in E[v].keys():
                if color[u] is None: # not visited yet
                    stack.append((u, c^1)) # paint u with different color from v's one
                elif color[u] != c: # consistent
                    continue
                else: # inconsistent
                    return None
        part.append(parts)
    return part

def floyd_warshall(V, E):
    '''
    Input:
        V = list(range(N))
        E = defaultdict(dict)
    Output:
        If there exists a negative cycle, return (None, prev), where prev is
        the table, whose (i, j)-element is the previous vertices in the shortest (i, j)-path
        Otherwise return (dist, prev), where dist is the table of the minimum cost
        between arbitrary vertex u, v in the given graph
    '''
    INF = float('inf')
    N = len(V)
    dist = {u: {v: INF for v in V} for u in V}
    prev = {u: {v: None for v in V} for u in V}
    for v in V:
        dist[v][v] = 0; prev[v][v] = -1
        for u, c in E[v].items(): dist[v][u] = c; prev[v][u] = v;
    for k in V:        
        for i, j in product(V, repeat=2):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j]
                prev[i][j] = prev[k][j]
    for v in V:
        if dist[v][v] < 0: return None, prev
    return dist, prev

N = int(input())
V = list(range(N))
E = defaultdict(dict)
for u in range(N):
    for v, s in enumerate(input()):
        if s == '1': E[u][v] = 1
if bipartite(V, E) is None:
    print(-1)
else:
    dist, _ = floyd_warshall(V, E)
    diameter = -1
    for u, v in combinations(V, 2):
        diameter = max(diameter, dist[u][v])
    print(diameter + 1)

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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;
	
	if(s.size()&1){
		cout << "No";
		exit(0);
	}
	
	bool yes=1;
	for(int i=0 ; i<s.size()-1 ; i+=2){
		if(s[i] != 'h' || s[i+1] != 'i'){
			yes=0;
			break;
		}
	}
	
	if(yes)cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	int n, t, e;
	cin >> n >> t >> e;
	t -= e;
	int num = -1;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;
		for (int j = 0; j < e * 2 + 1; j++){
			if ((t + j) % a == 0)num = i + 1;
		}
	}
	cout << num << endl;
	char c;
	cin >> c;
	return 0;
}

Measured memory_bytes: 3064
"use strict";
function main(input) {
    const line = input.split("\n");
    let arr = line[0].split(" ");
    const N = arr[0] * 1;
    const K = arr[1] * 1;
    let A = Array(N);
    A.fill(1);
    for (let i = 1; i < 2 * K; i++) {
        const d = line[i] * 1;
        arr = line[++i].split(" ").map(Number);
        for (let j = 0; j < arr.length; j++) {
            A[--arr[j]] = 0;
        }
    }
    console.log(A.reduce((Ai, x) => Ai + x));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

typedef long long ll;

int main(){
  ll a,b,q;
  cin >> a >> b >> q;
  ll s[a+2],t[b+2],x[q];
  for(int i=1;i<a+1;i++){
    cin >> s[i];
  }
  for(int i=1;i<b+1;i++){
    cin >> t[i];
  }
  for(int i=0;i<q;i++){
    cin >> x[i];
  }
  s[0]=-1e15;
  s[a+1]=1e15;
  t[0]=-1e15;
  t[b+1]=1e15;
  for(int i=0;i<q;i++){
    ll lb=0,ub=a+1;
    while(ub-lb>1){
      ll mid=(lb+ub)/2;
      if(s[mid]>=x[i]){
        // これが条件を満たせば、解の存在範囲は(lb,mid]
        ub=mid;
      }
      else{
        // これが条件を満たせば、解の存在範囲は(mid,ub]
        lb=mid;
      }
    }
    // この時点でlb+1=ub
    
    ll ub_t=lower_bound(t,t+b+2,x[i])-t;
    ll lb_t=ub_t-1;
    
    ll ans=min({abs(s[lb]-x[i])+abs(t[lb_t]-s[lb]),abs(s[lb]-x[i])+abs(t[ub_t]-s[lb]),abs(s[ub]-x[i])+abs(t[lb_t]-s[ub]),abs(s[ub]-x[i])+abs(t[ub_t]-s[ub]),abs(t[lb_t]-x[i])+abs(s[lb]-t[lb_t]),abs(t[lb_t]-x[i])+abs(s[ub]-t[lb_t]),abs(t[ub_t]-x[i])+abs(s[lb]-t[ub_t]),abs(t[ub_t]-x[i])+abs(s[ub]-t[ub_t])});
    cout << ans << endl;
  }
}

Measured memory_bytes: 3712
#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(){
  string s;
  cin >> s;

  if(s=="SSS") printf("0");
  else if(s=="RSS") printf("1");
  else if(s=="SRS") printf("1");
  else if(s=="SSR") printf("1");
  else if(s=="RRS") printf("2");
  else if(s=="RSR") printf("1");
  else if(s=="SRR") printf("2");
  else if(s=="RRR") printf("3");

  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	long long a,b,c,r=1;
	scanf("%lli%lli",&a,&b);
	c=__gcd(a,b);
	for(long long i=2;i<=sqrt(c);i++)
	{
		if(c%i==0)
		{
			r++;
		}
		while(c%i==0)
		{
			c=c/i;
		}
	}
	if(c!=1)	printf("%lli",r+1);
	else
	{
		printf("%lli",r);
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=1e6+100;
int n,t;
int a[maxn],vis[maxn];
int isprime[maxn],p2[maxn];
int prime[maxn];
unordered_set<int> s;

void genep(){
    int cnt=1;
    for(int i=2;i<maxn;++i){
        if(!isprime[i]){prime[cnt++]=i;s.insert(i);   }
        for(int j=1;j<=cnt&&i*prime[j]<=maxn;++j){
            isprime[i*prime[j]]=1;
            if(i%prime[j]==0){
                break;
            }
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    genep();
    int fl=1;
    rep(i,1,n){
        cin>>a[i];++vis[a[i]];
        if(a[i]>1&&vis[a[i]]>1)fl=0;
    }
     
	
	if(fl){
    rep(uu,2,1000000){
        if(vis[uu]){
            int q=sqrt(uu)+2,j=1,v=uu;
            while(prime[j]<=uu){
                if(v%prime[j]==0){
                    while(v%prime[j]==0)v/=prime[j];
                    if(!p2[prime[j]])p2[prime[j]]=1;
                    else {fl=0;}
                }
                if(s.count(v)){
                    if(!p2[v])p2[v]=1;
	                else fl=0;
	                break;
                }
                if(v==1)break;
                ++j;
            }
        }
    }
	}
	
    if(fl){
        cout<<"pairwise coprime";
    }
    else{
        int rr=a[1];
        rep(i,2,n){
            rr=__gcd(a[i],rr);
            if(rr==1)break;
        }
        if(rr==1)cout<<"setwise coprime";
        else cout<<"not coprime";
    }



    return 0;
}


Measured memory_bytes: 22700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			if (op.equals("?"))
				break;
			else if (op.equals("+"))
				System.out.println(a + b);
			else if (op.equals("-"))
				System.out.println(a - b);
			else if (op.equals("*"))
				System.out.println(a * b);
			else
				System.out.println(a / b);
			
		}
	}
}	


Measured memory_bytes: 26352
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;


int main() {
	string s;
	cin >> s;
	string t = "AKIHABARA";
	vector<string> vs;
	int k = t.size();
	int d = (1<<1) + (1<<2) + (1<<3) + (1<<5) + (1<<7);
	for(int b=0; b<(1<<k); b++) {
		if((d & b) != d) continue;
		string p;
		for(int i=0; i<k ; i++) if( (b & (1<<i)) > 0){
			string q = " ";
			q[0] = t[i];
			p +=  q;
		}
		
		vs.push_back(p);
	}
	/*
	for(int i=0; i<vs.size(); i++)
		cout << vs[i] << endl;
	*/
	
	for(int i=0; i<vs.size(); i++) {
		if(s == vs[i]) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}



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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

const ll inf = 1e17;
vector<ii> vec[4];
map<int, ll> m;
int n, tot;

bool comp(ii a, ii b){
    if (a > b) return true;
    return false;
}

ll solve(int a, int b, int c, int d){
    //printf("%d %d %d %d\n", a, b, c, d);
    int sum = a*vec[0][0].fi+b*(vec[0][0].fi+1)+c*(vec[0][0].fi+2)+d*(vec[0][0].fi+3);
    int ha = ((100*d+c)*100+b)*100+a;
    if (sum > tot) return -inf;
    if (m.count(ha))
        return m[ha];


    //printf("bef ans\n");
    ll ans = 0;
    if (a != vec[0].size())
        ans = max(ans, solve(a+1, b, c, d)+vec[0][a].se);
    if (b != vec[1].size())
        ans = max(ans, solve(a, b+1, c, d)+vec[1][b].se);
    if (c != vec[2].size())
        ans = max(ans, solve(a, b, c+1, d)+vec[2][c].se);
    if (d != vec[3].size())
        ans = max(ans, solve(a, b, c, d+1)+vec[3][d].se);

    return m[ha] = ans;
}

int main(){
    int a, b;
    scanf("%d %d", &n, &tot);
    scanf("%d %d", &a, &b);
    vec[0].pb(mp(a, b));
    for (int i = 0; i < n-1; i++){
        scanf("%d %d", &a, &b);
        vec[a-vec[0][0].fi].pb(mp(a, b));
    }

    sort(vec[0].begin(), vec[0].end(), comp);
    sort(vec[1].begin(), vec[1].end(), comp);
    sort(vec[2].begin(), vec[2].end(), comp);
    sort(vec[3].begin(), vec[3].end(), comp);

    printf("%lld\n", solve(0, 0, 0, 0));
    return 0;
}


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

const int maxn(2e5 + 5);

int n, k, a[maxn], b[maxn], ql[maxn], qr[maxn], o[maxn], len, cov[maxn << 2];
ll f[maxn], ans = 1e18, sum;

void Modify(int x, int l, int r, int ql, int qr, int cv) {
	if (ql > qr) return;
	if (ql <= l && qr >= r) cov[x] = cv;
	else {
		int mid = (l + r) >> 1;
		if (cov[x]) cov[x << 1] = cov[x << 1 | 1] = cov[x], cov[x] = 0;
		if (ql <= mid) Modify(x << 1, l, mid, ql, qr, cv);
		if (qr > mid) Modify(x << 1 | 1, mid + 1, r, ql, qr, cv);
	}
}

int Query(int x, int l, int r, int p) {
	if (l == r) return cov[x];
	int mid = (l + r) >> 1;
	if (cov[x]) cov[x << 1] = cov[x << 1 | 1] = cov[x], cov[x] = 0;
	return p <= mid ? Query(x << 1, l, mid, p) : Query(x << 1 | 1, mid + 1, r, p);
}

inline int Cost(int p1, int p2) {
	return p1 <= p2 ? p2 - p1 : p2 + k - p1;
}

int main() {
	int i, v;
	scanf("%d%d", &n, &k);
	for (i = 1; i <= n; ++i) {
		scanf("%d%d", &a[i], &b[i]);
		if (b[i] == 1 && (a[i] << 1) > k) return puts("-1"), 0;
		sum += a[i], a[i] = (a[i] + a[i - 1]) % k;
	}
	o[++len] = 0, o[++len] = k - 1;
	for (i = 1; i <= n; ++i) {
		if (b[i] == 1) {
			ql[i] = ((-2 * a[i - 1]) % k + k) % k;
			qr[i] = ((-2 * a[i]) % k + k) % k;
		}
		else ql[i] = 0, qr[i] = k - 1;
		o[++len] = ql[i], o[++len] = qr[i];
	}
	sort(o + 1, o + len + 1), len = unique(o + 1, o + len + 1) - o - 1;
	for (i = 1; i <= n; ++i) {
		ql[i] = lower_bound(o + 1, o + len + 1, ql[i]) - o;
		qr[i] = lower_bound(o + 1, o + len + 1, qr[i]) - o;
	}
	Modify(1, 1, len, 1, len, n + 1);
	for (i = n; i; --i) {
		v = Query(1, 1, len, ql[i]), f[i] = f[v] + (v <= n ? Cost(o[ql[i]], o[ql[v]]) : 0);
		if (ql[i] <= qr[i]) Modify(1, 1, len, 1, ql[i] - 1, i), Modify(1, 1, len, qr[i] + 1, len, i);
		else Modify(1, 1, len, qr[i] + 1, ql[i] - 1, i);
	}
	for (i = 1; i <= len; ++i) v = Query(1, 1, len, i), ans = min(ans, f[v] + (v <= n ? Cost(o[i], o[ql[v]]) : 0));
	ans += sum + sum, printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7808
Bingocard = [list(map(int,input().split())) for i in range(3)]
N = int(input())
Draws = [int(input()) for i in range(N)]

Bingo=[Bingocard[0][0],Bingocard[0][1],Bingocard[0][2],Bingocard[1][0],Bingocard[1][1],Bingocard[1][2],Bingocard[2][0],Bingocard[2][1],Bingocard[2][2]]

# Number of draws
Num = len(Draws)

# take for loop for number of draws...
# Notice that since bingo card value at least 1,
# can change to 0....

for i in range (0, Num):
	if Bingo.count(Draws[i])>0:
		Bingo[Bingo.index(Draws[i])]= 0
	else:
		continue

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

Measured memory_bytes: 3188
{-# LANGUAGE CPP #-}
module Main where

import qualified Data.Vector as V 
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

dump :: (Show a) => a -> IO()
#if __GLASGOW_HASKELL__ >= 800
dump x = print x
#else
dump _ = pure ()
#endif

readint :: IO Int
readint = (fst . fromJust . BS.readInt) <$> BS.getLine

readvec :: IO [Int]
readvec = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

-- "101010" -> [1,0,1,0,1,0]
readToList :: String -> [Int]
readToList [] = []
readToList (x:xs) = read [x] : readToList xs

newtype UF a = UF (M.Map a a) deriving (Show) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [0..n] [0..n]
                in UF m

union :: (Eq a, Ord a) => a -> a -> UF a -> UF a
union l r uf@(UF m) = let lp = find l uf
                          rp = find r uf
                      in if lp == rp
                         then uf
                         else if size l uf < size r uf
                              then UF $ M.update (const $ Just rp) lp m
                              else UF $ M.update (const $ Just lp) rp m

find :: (Eq a, Ord a) => a -> UF a -> a
find x uf@(UF m) = let px = m M.! x
                in if px == x
                   then px
                   else find px uf

size :: (Eq a, Ord a) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par==x) m

main :: IO()
main = do
  s <-  readToList . BS.unpack <$> BS.getLine :: IO [Int]
  dump s
  let ones = length $ filter (==1) s
  let zeros = length $ filter (==0) s
  dump zeros
  dump ones
  print $ (* 2) $ min ones zeros



Measured memory_bytes: 4860
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

int N,K;

vector<vector<long long>> combination(int n, int r, int mod=0) {
    vector<vector<long long>> v(n + 1,vector<long long>(n + 1, 0));
    for (int i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < v.size(); j++) {
        for (int k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
            if(mod>0) v[j][k] %= mod;
        }
    }
    return v;
}
vector<vector<long long>> combi;

int main(){

    cin >> N >> K;

    ll ans;
    combi = combination(2010,2010,MOD);
    for( int sousa = 1 ; sousa <= K  ; sousa++ ){
        ans = 1;
        ans *= combi[N-K+1][sousa];
        ans *= combi[K-1][sousa-1];
        cout << ans % MOD << endl;
    }





}

Measured memory_bytes: 31872
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var H = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ans = 0;
        var count = 0;

        for (int i = 0; i < N - 1; i++)
        {
            if (H[i] - H[i + 1] >= 0)
                count++;
            else
                count = 0;
            ans = Math.Max(ans, count);
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 39812
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let mut s: Vec<char> = iterator.next().unwrap().chars().collect();
    let mut g = 0_usize;
    let mut p = 0_usize;
    for c in s {
        if c == 'g' {
            g += 1;
        } else {
            p += 1;
        }
    }

    let ans = (g - p) / 2;
    ans.to_string()
}


Measured memory_bytes: 2540
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=4e5+5;
const int MOD=1e9+7;
ll a[N],sum[N];

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;
    cin >> s;
    int c1=0,c2=0;
    for(auto ch:s){
        if(ch=='+') c1++;
        else    c2++;
    }
    cout << c1-c2<<endl;


    return 0;
}


Measured memory_bytes: 768
n = int(input())
x, y = [list(map(float,input().split()))for i in range(2)]
print("%.6f"%sum([abs(x[i]-y[i])for i in range(n)]))
print("%.6f"%pow(sum([abs(x[i]-y[i])**2 for i in range(n)]), 1/2))
print("%.6f"%pow(sum([abs(x[i]-y[i])**3 for i in range(n)]), 1/3))
print(*max([abs(x[i]-y[i])] for i in range(n)))



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

int main(void)
{
	int n,x;
	scanf("%d%d",&n,&x);
	if(x==1||x==2*n-1)puts("No");
	else {
		puts("Yes");
        if(x<=n){
		for(int i=n+x-1;i>=2*x;i--){
			printf("%d\n",i);
		}
		for(int i=1;i<2*x;i++){
			printf("%d\n",i);
		}
		for(int i=n+x;i<=2*n-1;i++){
			printf("%d\n",i);
		}
        }
        else{
			for(int i=1;i<=x-n;i++){
			printf("%d\n",i);
		}
		for(int i=2*x-2*n+1;i<=2*n-1;i++){
			printf("%d\n",i);
		}
		for(int i=2*x-2*n;i>x-n;i--){
			printf("%d\n",i);
		}
        }
	}
	return 0;
}


Measured memory_bytes: 1536
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;

int main() {
	string S, T, U;
	int A, B;
	cin >> S >> T >> A >> B >> U;
	if (U == S) {
		A--;
	}
	else {
		B--;
	}
	cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	int n,i,a,min,wa,t;

	scanf("%d",&n);
	while(n!=0){
		scanf("%d",&a);
		wa=a;
		t=a;
		if(a<0)
			min=a;
		else
			min=0;
		for(i=1;i<n;i++){
			scanf("%d",&a);
			wa+=a;
			if(wa-min>t)
				t=wa-min;
			if(wa<min)
				min=wa;
		}
		printf("%d\n",t);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 600
n = int(input())
s = [input() for _ in range(n)]

end_A = 0
start_B = 0
AB_count = 0
both = 0

for i in range(n):
    if 'AB' in s[i]:
        AB_count += s[i].count('AB')
    if s[i][0] == 'B':
        start_B += 1
    if s[i][len(s[i])-1] == 'A':
        end_A += 1
    if s[i][0] == 'B' and s[i][len(s[i])-1] == 'A':
        both += 1
start_B -= both
end_A -= both

if both == 0:
    print(AB_count + min(start_B, end_A))
elif end_A + start_B > 0:
    print(AB_count + both + min(start_B, end_A))
else:
    print(AB_count + both - 1)


Measured memory_bytes: 3828
while True:
    a, op ,b = input().split()
    a = int(a)
    b = int(b)
    if op == "?":
        break
    elif op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

struct edge{
    ll to;
    ll cost;
};

vector<vector<edge> > tree; 
vector<ll> dis;

void solve(ll k, ll d){
    if(dis[k] != -1){
        return;
    }
    dis[k] = d;
    REP(i, 0, tree[k].size()){
        edge next = tree[k][i];
        if(dis[next.to] == -1){
            solve(next.to, d+next.cost);
        }
    }
}

int main(){
    int n; cin >> n;
    tree = vector<vector<edge> >(n);
    dis = vector<ll>(n, -1);
    REP(i, 0, n-1){
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        edge e1 = {a, c}, e2 = {b, c};
        tree[b].pb(e1);
        tree[a].pb(e2);
    }
    ll q, k; cin >> q >> k;
    k--;
    solve(k, 0);
    REP(i, 0, q){
        ll a, b; cin >> a >> b;
        a--; b--;
        cout << dis[a] + dis[b] << endl;
    }
}

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

pair<long, long> divide(long h, long w) {
  long s = h * w;
  if (s % 2 == 0) return make_pair(s / 2, s / 2);
  if (h > w) swap(h, w);
  long s1 = h * (w / 2);
  return make_pair(s1, s - s1);
}

int main() {
  long h, w, ans = 1l << 62;
  cin >> h >> w;
  if (h % 3 == 0 || w % 3 == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (long i = 0; i <= h; i++) {
    long s = i * w, s1 = divide(h - i, w).first, s2 = divide(h - i, w).second;
    ans = min(ans, max(abs(s - s1), max(abs(s1 - s2), abs(s - s2))));
  }
  for (long i = 0; i <= w; i++) {
    long s = i * h, s1 = divide(w - i, h).first, s2 = divide(w - i, h).second;
    ans = min(ans, max(abs(s - s1), max(abs(s1 - s2), abs(s - s2))));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
num = []
t_sum = 0

for i in range(5):
    t = int(input())
    t_sum += t
    if t%10 == 0:
        num.append(0)
    else:
        num.append(10-t%10)
num = sorted(num)

ans = 0
for i in range(len(num)-1):
    ans += num[i]

print(ans + t_sum)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int N = 10004;
const int g[12] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int n, m;
int a[12];
int dp[N][12];
bool c[N];

bool mets(const int a[], const int b[])
{
    int ga = 0;
    for (int i = 0; i < m; ++i)
        ga += a[i];
    int gb = 0;
    for (int i = 0; i < m; ++i)
        gb += b[i];
    if (ga > gb)
        return true;
    if (gb > gb)
        return false;
    for (int i = m - 1; i >= 0; --i)
    {
        if (a[i] > b[i])
            return true;
        if (b[i] > a[i])
            return false;
    }
    return false;
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
        cin >> a[i];
    sort(a, a + m);
    c[0] = true;
    for (int i = 0; i < n; ++i)
    {
        if (!c[i])
            continue;
        int t[12];
        for (int k = 0; k < m; ++k)
            t[k] = dp[i][k];
        for (int j = 0; j < m; ++j)
        {
            t[j]++;
            if (i + g[a[j]] <= n)
            {
                if (mets(t, dp[i + g[a[j]]]))
                {
                    memcpy(dp[i + g[a[j]]], t, sizeof t);
                    c[i + g[a[j]]] = true;
                }
            }
            t[j]--;
        }
    }

    for (int j = m - 1; j >= 0; --j)
    {
        while (dp[n][j]--)
            cout << a[j];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 768
// ABC168B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

//#include "pch.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int K;
	cin >> K;
	string S;
	cin >> S;

	if (S.size()<=K)
	{
		cout << S << endl;
	}
	else {
		cout << S.substr(0,K)+"..." << endl;
	}
}


Measured memory_bytes: 3104
l = input()
mod = 10**9+7
L = len(l)

ans = pow(3,L,mod)
cnt = 0
for i,li in enumerate(l):
  if li == '0':
    ans -= pow(3,L-1-i,mod)*pow(2,cnt+1,mod)
    ans %= mod
  else:
    cnt += 1
    
print(ans%mod)

Measured memory_bytes: 39664
n = int(input())
As = list(map(int, input().split()))

Ev = list()
Od = list()

for i in range(n):
    if i % 2 == 1:
        Ev.append(As[i])
    else:
        Od.append(As[i])

# print(Ev)
# print(Od)
if n % 2 == 0:
    Ev = Ev[::-1]
    Ev.extend(Od)
    ans = Ev
else:
    Od = Od[::-1]
    Od.extend(Ev)
    ans = Od

print(*ans)

Measured memory_bytes: 26020