akhauriyash/Code-Regression huggingface dataset:
/*-- ILSH  --*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double ld;

#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll > 
#define pii pair< ll, ll > 
#define len length 
#define fi first
#define se second
#define dt cout<<"HEre\n";
#define sz(x) (ll)x.size()
const ll inf=1e18+1e17;
const ll mod = 1e9+7;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
const ll N=2e5+5;

void solve(){
	map<pair< ll, ll > ,ll > m;
	ll h,w,n;
	cin>>h>> w>>n;
	for ( ll i=0;i<n;i++){
		ll a, b;
		cin>>a>>b;
		for ( ll i=max(1ll,a-2);i<=min(h-2,a);i++){
			for ( ll j=max(1ll,b-2);j<=min(w-2,b);j++){
				m[mp(i,j)]++;
			}
		}
	}
	ll cnt=0,ans[10]={0};

	for ( auto i:m ){
		cnt++;
		ans[i.se]++;
	}
	ans[0]=(h-2)*(w-2)-cnt;
	for ( ll i=0;i<10;i++)
		cout<<ans[i]<<'\n';
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;
//	cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
    //	cout << clock() / double(CLOCKS_PER_SEC) << endl;
}


Measured memory_bytes: 59784
n,m,Q = list(map(int, input().split()))

l=[]
r=[]
for j in range(m):
    l_tmp, r_tmp = list(map(int, input().split()))
    l.append(l_tmp)
    r.append(r_tmp)

p=[]
q=[]
for k in range(Q):
    p_tmp, q_tmp = list(map(int, input().split()))
    p.append(p_tmp)
    q.append(q_tmp)
    
su = [[0 for _ in range(n+1)] for __ in range(n+1)]

def sumTable(L, R):
    for i in range(m):
        su[L[i]][R[i]] += 1
    
    for i in range(1,n+1):
        for j in range(1, n+1):
            su[i][j] += su[i-1][j]
            su[i][j] += su[i][j-1]
            su[i][j] -= su[i-1][j-1]

def getSum(ll,rr):
    ans = su[rr][rr] - su[rr][ll-1] -su[ll-1][rr] + su[ll-1][ll-1]
    return ans
  
sumTable(l,r)

import copy
ss = copy.copy(su)

for qi in range(Q):
    su = copy.copy(ss)
    print(getSum(p[qi], q[qi]))

Measured memory_bytes: 28292
from collections import Counter
n=int(input())
s=input()

count=0
max_count=0
for i in range(1,n):
    x=s[:i]
    y=s[i:]
    l=Counter(x)
    t=Counter(y)
    for j in l.keys():
        if(j in t.keys()):
            count+=1
    if(max_count < count):
        max_count=count
    count=0
print(max_count)
    

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

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

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);}

typedef pair<double, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to; double cost;};
struct edge3 {int from, to, cost;};

typedef pair<double, double> DBLP;

void dijkstra(const vector<vector<edge2> > &G, int s, vector<double> &dist/*, vector<int> &prev*/){
  int E = G.size();
  dist.assign(E, 1000000000000000.0); dist[s] = 0;
  // prev.assign(E, -1);
  priority_queue<INTP, vector<INTP>, greater<INTP> > que;
  que.push({0, s}); // {dist, index}
  while(!que.empty()){
    INTP p = que.top(); que.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;
    REP(i, G[v].size()){
      edge2 e = G[v][i];
      if(dist[e.to] > dist[v]+e.cost){
        dist[e.to] = dist[v]+e.cost;
        // prev[e.to] = v;
        que.push({dist[e.to], e.to});
      }
    }
  }
}

double DIST(DBLP A, DBLP B){
  return sqrt( pow(A.first-B.first, 2.0) + pow(A.second-B.second, 2.0) );
}

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

  DBLP S, T; int N;
  cin >> S.first >> S.second >> T.first >> T.second >> N;
  vector<DBLP> C(N+2); INTV R(N+2);
  C[0] = S; R[0] = 0; C[N+1] = T; R[N+1] = 0;
  REP(i, N) cin >> C[i+1].first >> C[i+1].second >> R[i+1];

  vector<vector<edge2> > G(N+2);
  vector<double> dist(N+2);
  REP(i, N+2) for(int j = i+1; j < N+2; j++){
    double D = max(0.0, DIST(C[i],C[j])-R[i]-R[j]);
    G[i].pb({j, D});
    G[j].pb({i, D});
  }
  dijkstra(G, 0, dist);

  coutdb << dist[N+1] << endl;
}

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    A = lmi()
    g = A[0]
    for i in range(1, n):
        g = gcd(g, A[i])
    print(g)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16356
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

void find_fac(int n, vector<int>& facs) {
    int n2 = n;
    for(int i = 2; i*i <= n2; i++) {
        while (n % i == 0) {
            facs[i] += 1;
            n /= i;
        }
    }
    if (n > 1)
        facs[n] += 1;
}

int main() {
    int n;
    cin >> n;
    vector<int> facs(n+1, 0);
    for(int i = 2; i <= n; i++) {
        find_fac(i, facs);
    }
    ll mod = 1e9 + 7;
    ll ans = 1;
    for(int i = 2; i <= n; i++) {
        ans *= (facs[i]+1);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,stack[200];
int isEmpty(){
  return top==0;
    }
void push(int x){
  stack[++top]=x;
}
int pop(){
  if(isEmpty())exit(1);
  else
  top--;
  return stack[top+1];
}
int main(){
  int a,b,x;
  char p;
  top=0;
  while((scanf("%c",&p))!=EOF&&p!='\n'){
     if(p=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(p=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(p=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else if(p<='9'&&'0'<=p){
      x=atoi(&p);
      while(scanf("%c",&p)!=EOF&&p!=' '){
	x*=10;
	x=x+atoi(&p);
      }
      push(x);
    }
  }
  printf("%d\n",pop());
  return 0;
}
      	



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		// 標準入力からデータを読み込む準備
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a = new int[N];

		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		 }		

		for (int i = a.length-1; i >= 0; i--) {
			if(i!=0)
				System.out.printf("%d ",a[i]);
			else
				System.out.printf("%d",a[i]);

		 }		

		System.out.println();

		sc.close();
	}

}



Measured memory_bytes: 26428
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
    long long nPk_modp(long long n, long long k, long long p);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

  string s;
  cin >> s;

  ll ans = 0;

  char bef = s[0];

  rep(i,sz(s))
  {
    if( i == 0) continue;
    if(s[i] != bef) ans++;

    bef = s[i];
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}

long long Combi::nPk_modp(long long n, long long k, long long p)
{
  ll ans = 1;
  for(long long i = k; i <= n; i++)
  {
    ans = (ans * i) % p;
  }

  return ans;
};

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A, B, x;
  cin >> N;
  B = N;
  x = 0;
  
  for (int i = 0; i < 8; i++) {
    A = B % 10;
    x += A;
    B /= 10;
  }
  if (N % x == 0) {
    cout << "Yes" << endl;
  }
  else {
      cout << "No" << endl;
  }
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int64_t const inf = 1LL<<60;

int64_t G[210][210];

int main() {
  int N, M, R; cin >> N >> M >> R;
  vector<int> r(R); cin >> r; rep(i, R) r[i]--;
  rep(i, N) rep(j, N) G[i][j] = (i == j ? 0 : inf);
  rep(i, M) {
    int a, b; int64_t c; cin >> a >> b >> c;
    a--, b--;
    G[a][b] = G[b][a] = c;
  }
  rep(k, N) rep(i, N) rep(j, N) {
    if (G[i][k] < inf && G[k][j] < inf) {
      minimize(G[i][j], G[i][k] + G[k][j]);
    }
  }

  sort(r.begin(), r.end());
  int64_t ans = inf;
  do {
    int64_t sum = 0;
    rep(i, R - 1) {
      sum += G[r[i]][r[i + 1]];
    }
    minimize(ans, sum);
  } while(next_permutation(r.begin(), r.end()));
  cout << ans << "\n";
}


Measured memory_bytes: 512
#include <stdio.h>

int main (int argc, char *argv[]) {
int a;
int b;

    do{
        scanf("%d",&a);
        scanf("%d",&b);
    }while(a < -1000 || a > 1000 || b < -1000 || b > 1000);
    int max = a+b;
    int min = a-b;
    int mul = a*b;

    int large = max;
    if(large < min){
        large = min;
    }
    if(large < mul){
        large = mul;
    }
    printf("%d \n",large);
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n;
	int k;
	cin >> n >> k;
	int i=0;
	int number =1;
	while(i<n){
		if(number < k) number*=2;
		else number+=k;
		i++;
	}
	cout << number;

	return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        const double RATE = 380000.0;
        // 解
        double ans = 0.0;

        // 入力
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            string[] tmp = Console.ReadLine().Split(' ');
            double a = double.Parse(tmp[0]);
            string b = tmp[1];

            if (b.Equals("JPY"))
            {
                ans += a;
            }
            else
            {
                ans += (a * RATE);
            }
        }
        
        //出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
n = int(input())
a = [ int(i) for i in input().split() ]
moves = 0
while max(a) != 0:
    i = -1
    j = -1
    for y in range(n):
        if a[y] > 0 and i == -1:
            i = y
        elif a[y] == 0 and i != -1:
            j = y
            break
    if j == -1:
        j = n
    if i == -1:
        break
    mn = 1e9
    for x in range(i,j):
        mn = min(a[x],mn)
    moves += mn
    for x in range(i,j):
        a[x] -= mn
print(moves)


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

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    if(k>=a){
        k=k-a;
        a=0;
        if(k>=b)
            b=0;
        else
            b=b-k;
    }
    else{
        a-=k;
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
long long int a[102][11][1100];

int main(){
	int n,s;
	a[0][0][0]=1;
	a[0][1][0]=1;
	for(int i=0;i<=100;i++){
		for(int j=0;j<=9;j++){
			for(int k=0;k<=1000;k++){
				a[i+1][j][k]+=a[i][j][k];
				a[i+1][j+1][k+i+1]+=a[i][j][k];
			}
		}
	}
	while(1){
		cin>>n>>s;
		if(n==0&& s==0)
		break;
		cout<<a[100][n][s]<<endl;
	}
	return 0;
}

Measured memory_bytes: 10712
n,x=map(int,input().split())
a=list(map(int,input().split()))
count=0
for i in range(1,n,1):
	if a[i]+a[i-1]>x:
		count+=a[i]-(x-a[i-1])
		if x<a[i-1]:
			a[i]=0
		else:
			a[i]=x-a[i-1]
print(count)

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

using namespace std;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

void sub()
{
    const auto N(cin2var<size_t>());
    const auto count = static_cast<uint64_t>(pow(N, 3));
    cout << count << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    sub();
    return 0;
}

Measured memory_bytes: 512
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	f = 0
	for i in 1:n
		if n<=i*1.08<n+1
			println(i)
			f = 1
			break
		end
	end
	if f == 0
		println(":(")
	end
end

main()

Measured memory_bytes: 165664
# 写経しましたが、何もわかっていません。

def floor_sum(n, m, a, b):
    "Return sum( floor( (A * i + B) / M ) for i in range(N) )"
    ret = 0
    while True:
        if a >= m:
            ret += ((n - 1) * n) // 2 * (a // m)
            a %= m
        if b >= m:
            ret += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        x_max = y_max * m - b
        if y_max == 0:
            return ret
        ret += (n + (-x_max) // a) * y_max
        n, m, a, b = y_max, a, m, -x_max % a
    
    return ret

def main():
    import sys
    input = sys.stdin.buffer.readline

    ans = []
    T = int(input())
    for _ in range(T):
        N, M, A, B = map(int, input().split())
        ans.append(floor_sum(N, M, A, B))

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


if __name__ == "__main__":
    main()

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "YES"
#define NO  "NO"
#define MOD 1000000000+7
#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int n; cin >> n;
  // vector<string> s(n);
  vector<string> v;

  int a = 0; // 最後がa
  int b = 0; // 最初がb
  int ab = 0; // 文字列中に含まれているab
  int ba = 0; // B****A
  for (int i = 0; i < n; ++i) {
    string s; cin >> s;
    string::size_type pos = s.find("AB");
    while (pos != string::npos) {
      ++ab;
      pos = s.find("AB", pos + 2);
    }
    if (s.front() == 'B' || s.back() == 'A') v.push_back(s);
  }

  for (auto it = v.begin(); it != v.end(); ++it) {
    if ((*it).back() == 'A') ++a;
    if ((*it).front() == 'B') ++b;
    // string::size_type pos = (*it).find("AB");
    // while (pos != string::npos) {
    //   ++ab;
    //   pos = (*it).find("AB", pos + 2);
    // }
  }
  

  num = ab + min(min(a, b), max((int)v.size() - 1, (int)0));
  
  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


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

int main(){
  
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  
  vector<int> dp(N,10000);
  
  dp[0] = 0;
  
  for(int i=1;i<N;i++){
    vector<int> ways(K,10000);
    for(int j=0;j<K;j++){
      if(i-j-1<0) break;
      ways[j] = dp[i-j-1] + abs(h[i] - h[i-j-1]);
    }
    sort(ways.begin(),ways.end());
    dp[i] = ways[0];
  }
  
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
N = int(input())
numbers = list(map(int,input().split()))
numbers.sort(reverse=True)
Bob = 0
Alice = 0
for i,number in enumerate(numbers):
  if i == 0:
    Alice += number
  elif i%2 == 0:
    Alice += number
  else:
    Bob += number
ans = Alice - Bob
print(ans)

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

int main() {
  string s;
  cin >> s;
  ll n = s.size()/2;
  ll itr_max = s.size()-1;
  ll ans = 0;
  for (ll i = 0; i < n; ++i) if (s[i] != s[itr_max-i]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(){
	string bottun[10] = { "0", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	queue<char> str;
	int n, i;
	cin >> n;
	while( n-- > 0 ){
		char s[1025];
		cin >> s;
		for( i = 0; s[i] != '\0'; i++ ){
			str.push(s[i]);
		}
		int t = 0, num = 0;
		while( !str.empty() ){
			if( str.front() == '0' && num != 0 ){
				cout << bottun[num][(t-1)%bottun[num].length()];
				t = 0;
			}
			num = (int)(str.front() - '0');
			str.pop();
			if( num != 0 ) t++;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1228
#include    <bits/stdc++.h>
#include    <ext/pb_ds/assoc_container.hpp>
#include    <ext/pb_ds/trie_policy.hpp>
#include    <ext/rope>

#pragma     03
#pragma     GCC             optimize("Ofast")
#pragma     GCC             optimization("unroll-loops, no-stack-protector")
#pragma     GCC             target("sse,sse2,sse3,ssse3,sse4.1,sse4.2")

#define     ll              long long
#define     ld              long double
#define     fi              first
#define     se              second
#define     sz(x)           x.size()
#define     mp              make_pair
#define     pb              push_back
#define     eb              emplace_back
#define     all(x)          begin(x), end(x)
#define     rall(x)         rbegin(x), rend(x)
#define     rep(i, x, n)    for (ll i = x; i < n; i++)
#define     fastio()        ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define     min(a, b)       (a < b) ? a : b
#define     max(a, b)       (a > b) ? a : b
#define     int             long long

using       namespace std;
using       namespace __gnu_pbds;
using       namespace __gnu_cxx;

mt19937     rng(chrono::steady_clock::now().time_since_epoch().count());

typedef     vector<int>     vi;
typedef     vector<vi>      vvi;
typedef     pair<int, int>  ii;
typedef     vector<ii>      vii;
typedef     vector<ll>      vl;
typedef     vector<vl>      vvl;
typedef     pair<ll, ll>    pll;
typedef     vector<pll>     vll;

inline void EXECUTE_TIME() {cout << endl << setprecision(10) << fixed << "CPU Time: " << clock() / double(CLOCKS_PER_SEC) << " sec(s)\n";}

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}
template <class T> inline T gcd(T a, T b) {if (b) return gcd(b, a % b); else return a;}
template <class T> inline T lcm(T a, T b) {return a / gcd(a,b) * b;}
template<typename T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;

const int N = 1e5 + 10;

int a[N];
priority_queue<ii> pq;

signed main() {
//    freopen("bubbletea.inp", "r", stdin);
//    freopen("bubbletea.out", "w", stdout);
    fastio();

    int n; cin >> n;
    int cnt[N], ans[N];
    fill(all(cnt), 1);
    fill(all(ans), 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pq.push(mp(a[i], i));
    }

    while (pq.size() > 1) {
        ii x = pq.top(); pq.pop();
        ii y = pq.top(); pq.pop();

        ans[x.se] += cnt[x.se] * (x.fi - y.fi);
        pq.push(mp(y.fi, min(x.se, y.se)));
        cnt[min(x.se, y.se)] += cnt[max(x.se, y.se)];
    }
    ans[0] += n * pq.top().fi;
    rep(i, 0, n) cout << ans[i] << endl;

//    EXECUTE_TIME();
}


Measured memory_bytes: 7476
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int N = stdIn.nextInt();
		
		if(N / 100 == N % 10)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35588
#include<iostream>
using namespace std;
long mod=1e9+7,dp[50][50][99],a[50][50],b[50][50],k;
int n;
main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>dp[i][j][0];
	for(int K=1;K<60;K++)
	{
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)
		{
			for(int l=0;l<n;l++)dp[i][j][K]=(dp[i][j][K]+dp[i][l][K-1]*dp[l][j][K-1])%mod;
		}
	}
	for(int i=0;i<n;i++)a[i][i]=1;
	for(int K=0;K<60;K++)
	{
		if(k&1LL<<K)
		{
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)
			{
				b[i][j]=0;
				for(int l=0;l<n;l++)b[i][j]=(b[i][j]+a[i][l]*dp[l][j][K])%mod;
			}
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)a[i][j]=b[i][j];
		}
	}
	long ans=0;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)ans=(ans+a[i][j])%mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 2176
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;

#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define vt vector
#define vll vt<ll>
#define pll pair<ll,ll>
#define vpll vt<pll>
#define vvll vt<vll>
#define all(v) v.begin(),v.end()
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define go_t int testcases; cin>>testcases; ffo(caseno,1,testcases)

#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"

#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

const ll mod = 1e9 + 7;
const ll N = 6e4 + 6;
const ll maxN = 1e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

int dx[4] = { -1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
// up, right, down, left

ll powerM(ll x, ll y, ll M = mod) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in4.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	FIO
	ll n, m, k, c, a, b, i, j;
	ll x, t;
	cin >> n >> x >> t;
	cout << ((n / x) + (n % x == 0 ? 0 : 1))*t;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	cin>>n;
	
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	
	int m=a[0];  long long sum=0;
	
	for( int i=0;i<n;i++)
	{  
	   
	
		if( m>a[i])
		{   
			sum= sum+ m- a[i];
		}
		else 
		{
			m= max(m,a[i]);
		}
	}
	
	cout<<sum<<endl;
	
	
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
if H == 1 or W == 1:
    ans = 1
elif H%2 == 1 and W%2 == 1:
    ans = H*(W//2) + (H+1)//2
else:
    ans = H*W//2
print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
	int n, total, tmp;

	while (cin >> n){
		total = 0;
		if (n == 0){
			break;
		}

		for (int i = 0; i < 9; i++){
			cin >> tmp;

			total += tmp;
		}

		cout << n - total << endl;
	}
}

Measured memory_bytes: 3072
//Bokann ga bokka--nn!!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define mod 100000
int main(){
	int n,m,s;
	while(1)
	{
		int dp[50][3005]={};
		cin >> n >> m >> s;
		if(!n) return 0;
		dp[0][0]=1;
		for(int i=1;i<=m;i++)
		{
			for(int j=n*n;j>=1;j--)
			{
				for(int k=s;k>=i;k--)
				{
					dp[j][k]+=dp[j-1][k-i];
					dp[j][k]%=mod;
				}
			}
		}
		cout << dp[n*n][s] << endl;
	}
}

Measured memory_bytes: 1752
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

const int mod = 1e9 + 7;

void solve(ll N) {
  ll res = 1;
  REP(i,N) res = (res * (i + 1)) % mod;
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	solve(N);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

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

int main(){
  int a,b;
  cin >> a >> b;
  cout << lcm(a,b) << ln;
  return 0;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

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

    int x = 2 * b - a;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    	Scanner sc = new Scanner(System.in);
	    	int a = sc.nextInt();
	    	int b = sc.nextInt();
	    	int c = sc.nextInt();
	    	int d = sc.nextInt();
	    	List<Integer> list = new ArrayList<>();
	    	list.add(a);
	    	list.add(b);
	    	list.add(c);
	    	list.add(d);
	    	Collections.sort(list);
	    	if (list.get(0) == 1 && list.get(1) == 4 && list.get(2) == 7 && list.get(3) == 9) {
	    		System.out.println("YES");
	    	} else {
	    		System.out.println("NO");
	    	}
	}
}


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

int main(){
  int N, Y; 
  int variables=scanf("%d %d\n", &N, &Y);
  
  int a  =Y/10000;
  int ans[3] = {-1, -1, -1};
  if(a==N){
    ans[0] = a;
    ans[1] = 0;
    ans[2] = 0;
  }else if(a<N){
    int frag=0;
    for(int i=a; i>=0; i--){
      int N_new = N-i;
      int resid = Y/1000-i*10;
      for(int j=0; j<=N_new; j++){
        if(5*j+N_new-j == resid){
          frag=1;
          ans[1] = j;
          ans[2] = N-i-j;
          break;
        }
      }
      if(frag){
        ans[0] = i;
        break;
      }
    }
  }
  printf("%d %d %d\n", ans[0], ans[1], ans[2]);
  return 0;
  
}

Measured memory_bytes: 128
#include <iostream>
#define MAX 1000000001

using namespace std;

int main() {
  
  int n;
  cin >> n; // number of entries

  int first, second;
  cin >> first >> second;

  int min = (first < second)? first:second;
  int max_diff = second - first;

  for (int i = 2; i < n; ++i) {
    int input;
    cin >> input;
    if ((input - min) > max_diff) max_diff = (input - min);
    if (input < min) min = input;
  }

  cout << max_diff << endl;
}

    
      

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1){
            res = res*x%mod;
        }
        x = x*x%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}

void pre(){
   
}

ll p[maxs];
ll r[maxs];

ll fn(ll x){
    if(p[x] == x){
        return x;
    }
    return p[x] = fn(p[x]);
}

bool add(ll x,ll y){
    x = fn(x);
    y = fn(y);
    if(x==y)
        return false;
    if(r[x] < r[y])
        swap(x,y);
    p[y] = x;
    if(r[x] == r[y])
        r[x]++;
    return true;
}

vector<ll> g[maxs];

void solve(){

    ll n,m;
    cin >> n >> m;
    
    for(ll i=1;i<n+1;i++){
        p[i] =i;
    }

    while(m--){
        ll s,d;
        cin >> s >> d;
        add(s,d);
        g[s].pb(d);
        g[d].pb(s);
    }

    set<ll> SET;
    for(ll i=1;i<n+1;i++){
        SET.I(fn(i));
    }

    if(SET.size() >1){
        cout << "No";
        return;
    }
    
    vll ans(n+1,-1);
    vll vis(n+1,0);
    queue<ll> q;
    q.push(1);

    while(q.size()){
        ll s = q.front();
        q.pop();
        vis[s] = 1;
        for(auto d : g[s]){
            if(!vis[d]){
                if(ans[d] == -1)
                    ans[d] = s;
                vis[d] = true;
                q.push(d);
            }
        }
    }

    cout << "Yes\n";
    for(ll i=2;i<=n;i++){
        cout << ans[i] << endl;
    }


}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    ll tt=1;
    while(T--){
        //cout << "Case #" << tt << ": ";
        tt++;
        solve();
    }
    return 0;
}

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

//1,000,000,007
//1000000007
int main(void)
{
	long int n, d;
	long int i, j, k;
	long int count = 0, sum;
	long int x[20][20];
	
	scanf("%ld%ld", &n, &d);
	
	for(i = 0; i < n; i++) {
		for(j = 0; j < d; j++) {
			scanf("%ld", &x[i][j]);
		}
	}
	
	for(i = 0; i < n - 1; i++) {
		for(j = i + 1; j < n; j++) {
			sum = 0;
			for(k = 0; k < d; k++) {
				sum += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
			}
			if((long int)(sqrt(sum) ) - sqrt(sum) == 0) {
				count++;
			}
		}
	}
	
	printf("%ld\n", count);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
    int x,y;
    for(int i = 1;i<3001;i++){
        cin>>x>>y;
        if(x == 0 && y == 0){
            break;
        }else{
            if(x > y){
                cout<<y<<" "<<x<<endl;
            }else{
                cout<<x<<" "<<y<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3044
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}


int main(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    ll ans;
    int maxv=0;
    rep(i,n){
        cin>>a[i];
        if(i)ans=gcd(a[i],ans);
        else ans=a[0];
        maxv=max(maxv,a[i]);
    }
    if(maxv<k){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    if(k%ans==0)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
    }


Measured memory_bytes: 640
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

n,q = imap()
g = adj(n+1)
for i in range(n-1):
    a,b = imap()
    g[a].append(b)
    g[b].append(a)

cnt = iarr(n+1)
for i in range(q):
    p,x = imap()
    cnt[p] += x

que = col.deque([1])
dep = col.defaultdict(int)
dep[1] = 1
while que:
    now = que.popleft()
    for next in g[now]:
        if dep[next]: continue
        # dep更新、que更新、そのほか　＝３点セット
        dep[next] = dep[now] + 1
        que.append(next)
        cnt[next] += cnt[now]

print(*cnt[1:])
    


Measured memory_bytes: 101236
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N,Y = map(int, input().split())

for sen in range(0, N+1):
  for gosen in range(0, N+1):
    man = N - sen - gosen
    if man < 0: break

    if 10000*man + 5000*gosen + 1000*sen == Y:
      print("{} {} {}".format(man, gosen, sen))
      exit(0)

print("-1 -1 -1")


Measured memory_bytes: 2940
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main(){


    string s;

    cin >> s;
    bool f = true;
    bool f2 = false;
    int i = 0;

    while(f){

        if(i == 0){
            if(s[i] < '2')f = false;

        }
        if(i == 2){

            if(s[i] < '1')f = false;

        }
        if(i == 3){
            if(s[i] < '9')f = false;
        }
        if(i == 5){

            if(s[i] == '1')f2 = true;

        }
        if(i == 6){

            if(s[i] < '5')f = false;
            if(f2)f = true;
            break;

        }
        ++i;

    }

    if(f)cout << "TBD\n";
    else cout << "Heisei\n";

    return 0;

}

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

int main(){
  ll n,m; cin >>n >>m;
  if(n==1 && m==1) cout << 1 << endl;
  else if(n==1) cout << m-2 << endl;
  else if(m==1) cout << n-2 << endl;
  else cout << (n-2)*(m-2) << endl;
  return 0; 
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int n;
	cin >> n;
	vector<int> h(n);
	for(int i = 0; i < n; ++i){
		cin >> h[i];
	}

	h[0]--;
	for(int i = 1; i < n; ++i){
		if(h[i] > h[i - 1]){
			h[i]--;
		}else if(h[i] < h[i - 1]){
			cout << "No";
			return 0;
		}
	}

	cout << "Yes";
    return 0;
}


Measured memory_bytes: 640
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long> a(3 * n);
    FOR(i, 0, 3 * n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    long long ans = 0;
    FOR(i, 0, n) {
        int idx = 3 * n - 2 - 2 * i;
        ans += a[idx];
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 99999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    int a,b,sum=1,ans;
    cin >> a >> b;
    for(ans=0;sum < b;ans++){
        sum += a-1;
    }
    cout << ans << endl;
}

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

using namespace std;

bool isMonth(int n){
	return (1 <= n && n <= 12);
}

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

	int first = (S[0] - '0') * 10 + (S[1] - '0');
	int second = (S[2] - '0') * 10 + (S[3] - '0');

	if(isMonth(first)){	// 前半がMMの可能性
		if(isMonth(second)){
			cout << "AMBIGUOUS" << endl;
		} else {
			cout << "MMYY" << endl;
		}
	} else {
		if(isMonth(second)){
			cout << "YYMM" << endl;
		} else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

using namespace std;
using ll = long long;

unsigned long long pow(long long base, long long power){  /// mod?
    if(power==0)
        return 1;
    if(power==1)
        return base;

    unsigned long long ans = pow(base, power/2); /// mod?
    ans *= ans; /// ((ans%mod)*(ans%mod))%mod;

    if(power&1)
        return ans*base; /// ((ans%mod)*(base%mod))%mod;
    return ans;
}

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

    int n; cin >> n;
    ll arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    sort(arr, arr+n);
    if(arr[0]==arr[n-1])
        return cout << 0, 0;


    ll mini = LLONG_MAX, cur;
    for(int i=-10000; i<=10000; i++){
        cur = 0;
        for(int j=0; j<n; j++)
            cur += pow((arr[j]-i), 2);
        mini = min(mini, cur);
    }
    cout << mini;

    return 0;
}


Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
const ll MAX_N = 1e5;
ll N, K;
ll h[MAX_N];
ll dp[MAX_N+1]; // メモ化テーブル
 
// i番目以降の品物から重さの総和がj以下になるように選ぶ
void rec(ll i){
	if (i==0) dp[i] = 0;
	else if (i<=K) dp[i] = abs(h[i]-h[0]);
	else{
		ll ans = 1e9;
		for (ll j = 1; j <= K; ++j){
			ll tmp = dp[i-j]+abs(h[i]-h[i-j]);
			if (tmp<ans) ans = tmp;
		}
		dp[i] = ans;
	} 
	return;
}

int main() {
	// 入力
	cin >> N>>K;
	for (ll i = 0; i < N; ++i) cin >> h[i];
 
	
	// 解法
	// まだ調べていないことを表す-1でメモ化テーブルを初期化
	memset(dp, -1, sizeof(dp));
	
	REP(i,N) rec(i);
	
	// REP(i,N) printf("%d\n", dp[i]);
	printf("%d\n", dp[N-1]);
}


Measured memory_bytes: 1792