akhauriyash/Code-Regression huggingface dataset:
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      csf: [(usize, usize, usize); n-1],
   }
   for i in 0..n-1 {
      let (c0, s0, _) = csf[i].clone();
      let mut now = s0 + c0;
      for j in i+1..n-1 {
         let (c, s, f) = csf[j].clone();
         if now < s {
            now = s;
         } else if now % f != 0 {
            now += f - now % f;
         }
         now += c;
      }
      println!("{}", now);
   }
   println!("0");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;


//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  return ((x * y) / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  lol sum = 0;
  int a;
  rep(i, m){
    cin >> a;
    sum += a;
  }
  if(sum > n){
    cout << "-1\n";
  }
  else {
    cout << n - sum << '\n';
  }
  return 0;
}


Measured memory_bytes: 3648
S = int(input())
 
if S <= 10**9:
  print(0,0,S,0,0,1)
elif S == 10*18:
  print(0,0,10**9,0,0,10**9)
  end
else:
  q,r = divmod(S,10**9)
  if r == 0:
    print(0,0,0,10**9,q,0)
  else:
    print(0,0,1,10**9,q+1,10**9-r)



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

int main(){
  int a, b;
  cin >> a >> b;
  char grid[101][101];
  cout << 100 << " " << 100 << endl;
  for(int i = 0; i < 100; i++){
    for(int j = 0; j < 100; j++){
      if(j < 50) grid[i][j] = '#';
      else grid[i][j] = '.';
    }
  }
  int sum = 1;
  for(int i = 0; i < 100; i += 2){
    for(int j = 0; j < 48; j += 2){
      if(sum == a) break;
      grid[i][j] = '.';
      sum++;
    }
    if(sum == a) break;
  }
  sum = 1;
  for(int i = 0; i < 100; i += 2){
    for(int j = 51; j < 98; j += 2){
      if(sum == b) break;
      grid[i][j] = '#';
      sum++;
    }
    if(sum == b) break;
  }
  for(int i = 0; i < 100; i++){
    for(int j = 0; j < 100; j++){
      cout << grid[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


map<int,int> kyori;

int main(){
	int n;
	
	while(cin>>n){
		if(n==0)break;
		
		kyori.clear();
		int max,maxno;
		for(int i=0;i<n;i++){
			int p,d1,d2;
			cin>>p>>d1>>d2;
			kyori[p]=d1+d2;
			max=d1+d2;
			maxno=p;
		}
		
		for(map<int,int>::iterator p=kyori.begin();p!=kyori.end();++p){
			if(p->second>max){
				max=p->second;
				maxno=p->first;
			}
		}
		cout<<maxno<<" "<<max<<endl;
	}
	return 0;
}

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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}



int main()
{
    double R;
    cin >> R;

    R = 2 * R * 3.141592;

    printf("%.4f\n",R);
   

 
    return 0;

}

Measured memory_bytes: 3808
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;


struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i, N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	int res = 0;
	REP(i, N) {
		chmax(res, ans);
		if (S[i] == 'I')ans++;
		else ans--;
	}
	cout << max(res, ans) << endl;
	return 0;
}



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

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

/*
int main() {
    int A, B, C;
    int x;
    std::cin >> A >> B >> C;
    x=min(A, B+C);
    std::cout << B+C-x << std::endl;

    return 0;
}
 */

int main(){
    int N;
    std::cin >> N;
    int count = 0;
    for(int i=1; i<=N; i++){
        if((0<i && i<10)||(100<=i && i<1000)||(10000<=i && i<100000)){
            count++;
        }
    }
    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 256
import sys
  
class Node():
    def __init__(self,key):
        self.key = key
        self.left = None
        self.right = None
  
def insert(t, z):
    y = None
    x = t
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
  
    if y is None:
        return z
    else:
        if z.key < y.key:
            y.left = z
        else:
            y.right = z
        return t
  
def inorder(t):
    s = ""
    l = []
    curr = t
    while True:
        while curr is not None:
            l.append(curr)
            curr = curr.left
        if curr is None and len(l) == 0:
            break
        else:
            curr = l.pop()
            s += " " + str(curr.key)
            curr = curr.right
    return s
  
def preorder(t):
    s = ""
    l = []
    curr = t
    while True:
        while curr is not None:
            s += " " + str(curr.key)
            l.append(curr)
            curr = curr.left
        if curr is None and len(l) == 0:
            break
        else:
            curr = l.pop()
            curr = curr.right
    return s
  
t = None
n = sys.stdin.readline()
lines = sys.stdin.readlines()
for line in lines:
    com = line.split()
    if com[0] == "insert":
        t = insert(t, Node(int(com[1])))
    else:
        print(inorder(t))
        print(preorder(t))

Measured memory_bytes: 152012
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		long A = scan.nextLong();
		long B = scan.nextLong();
		long K = scan.nextLong();
		scan.close();

		if(A+B>K) {
			if(A>=K) {
				A=A-K;
			}else{
				B=B+(A-K);
				A=0;
			}
		}else {
			A=0;
			B=0;
		}
		System.out.println(A+" "+B);
	}
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int MOD = 998244353;
const int N = (1e6)+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        vector<pii> plus,minus;
        int chk = 0;
        for(int ii=0;ii<n;ii++)
        {
            string s;
            cin>>s;
            stack<char> st;
            for(int i=0;i<s.length();i++)
            {
                if(!st.size())st.push(s[i]);
                else
                {
                    if(s[i] == ')' && st.top() == '(')st.pop();
                    else st.push(s[i]);
                }
            }
            int op=0,cl=0;
            while(st.size())
            {
                if(st.top() == '(')op++;
                else cl++;
                st.pop();
            }
            if(!cl && !op)continue;
            if(op-cl >= 0)plus.pb({-cl,op-cl});
            else minus.pb({-op,cl-op});
            chk+=op-cl;
        }
        if(chk)return cout<<"No",0;
        chk = 1;
        sort(all(plus));reverse(all(plus));
        sort(all(minus));reverse(all(minus));
        int curr = 0;
        for(auto p: plus)
        {
            int now = curr+p.ff;
            if(now < 0)chk = 0;
            curr += p.ss;
        }
        curr = 0;
        for(auto p: minus)
        {
            int now = curr+p.ff;
            if(now < 0)chk = 0;
            curr += p.ss;
        }
        cout<<(chk?"Yes":"No")<<endl;
    }
    return 0;
}


Measured memory_bytes: 19096
#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 <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#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 <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  a %= 500;
  if(a <= b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication32
{
    class Program
    {
		static long gcd(long a,long b){
			if(b==0)
				return a;
			return gcd(b,a%b);
		}
        static void Main(string[] args){
			while(true){
				string s;
			s=	Console.ReadLine();
			if(s==null)break;
			long[] ab=s.Split().Select(long.Parse).ToArray();
		    if(ab[0]<ab[1]){long c=ab[0];ab[0]=ab[1];ab[1]=c;}
	        long a=gcd(ab[0],ab[1]);
	        Console.WriteLine(a+" "+ab[0]*ab[1]/a);
				}
		}
	}
}

Measured memory_bytes: 9404
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n=inp()
    s=input()
    w=0
    for i in range(n):
        if s[i]=='.':
            w+=1
    b=n-w
    ans=n
    x=0
    y=w
    for i in range(n):
        ans=min(ans,x+y)
        if s[i]=='.':
            y-=1
        else:
            x+=1
        ans=min(ans,x+y)

    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;

int main(){
  string S;
  cin >> S;
  if (S[0] == S[1] && S[1] == S[2]){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*
  Contest 063
  C - Bugged
  Rakesh Kumar --> 28/08/2020
 */

#include <bits/stdc++.h>

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

    int n = 0, total = 0;
    std::cin >> n;
    std::vector<int> v;
    while (n--) {
        int s = 0;
        std::cin >> s;
        v.emplace_back(s);
        total += s;
    }
    std::sort(v.begin(), v.end());
    if (total % 10 == 0) {
        for (std::size_t i = 0; i < v.size(); ++i) {
            if ((total - v[i]) % 10) {
                std::cout << total - v[i] << std::endl;
                return 0;
            }
        }
        total = 0;
    }
    std::cout << total << std::endl;

    return 0;
}


Measured memory_bytes: 3592
N = int(input())
H = [int(i) for i in input().split()] 

count = 1

for i in range(1, N):
    nn = 0
    A = H[:i+1]
    for j in A[:-1]:
        if j > A[-1]:
            nn += 1
    if nn==0:
        count += 1

print(count)

Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class BMinorChange {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            String str1 = s.nextString();
            String str2 = s.nextString();
            int count = 0;
            for (int i = 0; i < str1.length(); i++) {
                if (str1.charAt(i) != str2.charAt(i)) {
                    count++;
                }
            }

            out.println(count);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 29952
N, K = map(int,input().split())
MOD = 10**9+7
ls = [0]*(K+1) #個数
for i in range(1, K+1)[::-1]:
  ls[i] =  pow(K // i, N, MOD)
  if K // i != 1:
    a = K // i
    for j in range(2, a+1):
      ls[i] -= ls[i*j]  
    
ans = 0
for i in range(1, K+1):
  ans += i * ls[i]
  ans %= MOD  
print(ans) 

Measured memory_bytes: 11140
import math
n=int(input())
a=list(map(int,input().split()))

ra=list(reversed(a))

left=[]
right=[]
right.append(ra[0])
left.append(a[0])

if n>2:
  k=math.gcd(a[0],a[1])
  left.append(k)
  for i in range(2,n-1):
    k=math.gcd(k,a[i])
    left.append(k)

  k=math.gcd(ra[0],ra[1])
  right.append(k)
  for i in range(2,n-1):
    k=math.gcd(k,ra[i])
    right.append(k)

  ans=[right[-1]]
  for i in range(1,n-1):
    ans.append(math.gcd(left[i-1],right[len(right)-i-1]))
  ans.append(left[-1])
  print(max(ans))
else:
  print(max(a[1],a[0]))

Measured memory_bytes: 25768
import sys

n = int(input())
x = [0]*n ; y = [0]*n
for i in range(n):
    x[i],y[i] = map(int, input().split())

if n == 1:
    print(1)
    sys.exit()

ans = []
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        p = x[i]-x[j]
        q = y[i]-y[j]
        count = 0
        for k in range(n):
            for l in range(n):
                if p == x[k]-x[l] and q == y[k]-y[l]:
                    count += 1
                ans.append(count)

print(n-max(ans))

Measured memory_bytes: 134084
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define prique priority_queue
signed main(){
    int n,a=0,b=0,ba=0,cnt=0;
    string s[20000];
    cin>>n;
    rep(i,n){
        cin>>s[i];
        int l=s[i].size();
        rep(j,l-1){
            if(s[i].substr(j,2)=="AB")cnt++;
        }
        if(s[i][0]=='B'&&s[i][l-1]=='A')ba++;
        else if(s[i][0]=='B')b++;
        else if(s[i][l-1]=='A')a++;
    }
    if(ba==0)cnt+=min(a,b);
    else if(ba==1&&a+b>0)cnt+=min(a,b)+1;
    else if(ba>1&&a+b==0)cnt+=ba-1;
    else if(ba>1&&a+b>0)cnt+=ba+min(a,b);
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int main(void)
{
	int i;
	char str[4];
	
	scanf("%s", str);
	
	i = 0;
	
	if(str[0] == '1'){
		i++;
	}
	if(str[1] == '1'){
		i++;
	}
	if(str[2] == '1'){
		i++;
	}
	
	printf("%d", i);
	
	return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int N, X, Y; cin >> N >> X >> Y;
    int dist[N]={0};

    for(int i=1; i<N; i++){
        for(int j=i+1; j<=N; j++){
            int res = min(min(abs(j-i), abs(X-j)+1+abs(Y-i)), abs(X-i)+1+abs(Y-j));
            dist[res]++;
        }
    }

    FOR(i,1,N) cout << dist[i] << endl;

    return 0;
}


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

/*
* int配列の要素をすべて0にする
*/
void all2zero(int *array, int num)
{
    for (int i = 0; i < num; i++)
    {
        array[i] = 0;
    }
}

int main()
{
    int N, sum = 0, now_num, pre_num = INT_MAX;

    cin >> N;
    for (int i = 0; i < N - 1; i++)
    {
        cin >> now_num;
        sum += (now_num < pre_num) ? now_num : pre_num;
        pre_num = now_num;
    }
    sum += now_num;
    cout << sum << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 764
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false INT_MAX INT_MIN insert erase clear pop push compare INT64_MAX INT64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const int mod = 1e9 + 7 ;
const int inf =
 1e9 + 5 ;
 //1e18L + 5;
const int nax = 2e5 + 5;
void min_self(int&a , int b){a=min(a,b);}
void max_self(int&a , int b){a=max(a,b);}
void add_self(int&a , int b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
int x,  y ;
cin >> x >> y ; 

for(int i = 0 ; i<1000 ;i++){
	for(int j = 0 ; j<1000 ;j++){
		if(i+j==x && 2*i +4*j == y){
			cout<<"Yes";
			return 0;
		}
	}
}
cout<<"No"<<endl;
	
}

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

int main() {
  int N, A;
  cin >> N;
  cin >> A;
  if(N >= 500){
   if(N % 500 == 0){
   cout << "Yes" <<endl;
   }else if(N % 500 < A){
     cout << "Yes" << endl;
   }else {
     cout << "No" << endl;
   }
  }else if(N < A){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().strip().split()))


m = 10 ** 9 + 7
def main():
    s = sum(a)
    ss = 0
    r = 0
    for nn in range(n):
        ss += a[nn]
        r += a[nn] * (s - ss)
    print(r % m)
    return

main()


Measured memory_bytes: 31488
#include <iostream>
using namespace std;
inline int bubblesort(int a[], int  n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}
int main() {
	const int n = 100;
	int ar[n];
	int num;
	cin >> num;
	for (int i = 0; i < num; i++) {
		cin >> ar[i];
	}
	int sum = bubblesort(ar, num);
	cout << ar[0];
	for (int i = 1; i < num; i++)
		cout << ' ' << ar[i];
	cout << endl;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
struct Node {
  ll x, y;
  Node() = default;
  Node(int a, int b) : x(a), y(b) {}
  friend bool operator<(const Node& n1, const Node& n2) {
    if (n1.x != n2.x) return n1.x < n2.x;
    return n1.y < n2.y;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  vector<Node> v(N);

  int vmin = INT_MAX;
  int imin = -1;
  int vmax = INT_MIN;
  int imax = -1;
  for (int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    v[i].x = x;
    v[i].y = y;
  }

  sort(v.begin(), v.end());

  for (int i = 0; i < N; ++i) {
    int x = v[i].x;
    int y = v[i].y;
    if (vmin > x) {
      vmin = x;
      imin = i;
    }

    if (vmax < y) {
      vmax = y;
      imax = i;
    }
  }

  ll ret = 1LL << 62;
  const ll rmin = vmin;
  // if bmax = vmax;
  ll bmax = vmax;

  ll rmax = rmin;
  ll bmin = bmax;

  for (auto& n : v) {
    rmax = max(rmax, n.x);
    bmin = min(bmin, n.y);
  }

  ret = min(ret, (rmax - rmin) * (bmax - bmin));
  // if rmax = vmax;
  rmax = vmax;

  multiset<int> st;
  vector<Node> bv;
  for (int i = 0; i < N; ++i) {
    if (i != imin && i != imax) {
      bv.push_back(v[i]);
      st.insert(v[i].x);
    }
  }
  st.insert(v[imin].y);
  st.insert(v[imax].x);

  bmin = *st.begin();
  bmax = *st.rbegin();
  ll nbmin = min(v[0].y, v[imax].x);
  ret = min(ret, (rmax - rmin) * (bmax - bmin));
  for (int i = 0; i + 1 < bv.size(); ++i) {
    auto const& c = bv[i];
    if (c.x > nbmin) break;
    bmin = min({c.y, bv[i+1].x, nbmin});
    bmax = max(c.y, bmax);
    nbmin = min(nbmin, c.y);
    ret = min(ret, (rmax - rmin) * (bmax - bmin));
  }

  bmin = v[0].y;
  bmax = v[imax].x;
  for (auto& n : bv) {
    bmin = min(bmin, n.y);
    bmax = max(bmax, n.y);
  }
  ret = min(ret, (rmax - rmin) * (bmax - bmin));
  cout << ret << endl;
}

Measured memory_bytes: 16876
n,x,y=map(int,raw_input().split())


a=[0]*n
m={}
for i in range(1,n+1):
	for j in range(i+1,n+1):
	    
	    d=min(j-i,abs(i-x)+1+abs(j-y))
	    if d in m:
	        m[d]+=1
	    else :
	        m[d]=1




for i in range(1,n):
    if i in m:
        print m[i]
    else:
        print 0

Measured memory_bytes: 2948
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, k = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

plus_zero = []
minus = []

for i in a:
    if i >= 0:
        plus_zero.append(i)
    if i < 0:
        minus.append(-i)

from collections import deque

plus_zero = deque(sorted(plus_zero, reverse=True))
minus = deque(sorted(minus, reverse=True))
absolute = deque(sorted(a, key=abs, reverse=True))

ans_lst = []
# 境界条件: k == n
if k == n:
    ans_lst.extend(a)
# 負
elif len(plus_zero) == 0 and (k % 2) != 0:
    for _ in range(k):
        ans_lst.append(-minus.pop())
# 正 or 0
else:
    minus_num = 0
    for _ in range(k):
        v = absolute.popleft()
        if v < 0:
            minus_num += 1
        ans_lst.append(v)
    if minus_num % 2 != 0:
        abs_min_plus_zero, abs_min_minus = None, None
        abs_max_plus_zero, abs_max_minus = None, None
        for i in ans_lst:
            if i >= 0:
                if abs_min_plus_zero is None:
                    abs_min_plus_zero = i
                else:
                    abs_min_plus_zero = min(i, abs_min_plus_zero)
            else:
                if abs_min_minus is None:
                    abs_min_minus = i
                else:
                    abs_min_minus = max(abs_min_minus, i)
        for i in absolute:
            if i >= 0:
                if abs_max_plus_zero is None:
                    abs_max_plus_zero = i
                else:
                    abs_max_plus_zero = max(i, abs_max_plus_zero)
            else:
                if abs_max_minus is None:
                    abs_max_minus = i
                else:
                    abs_max_minus = min(abs_max_minus, i)
        case1, case2 = False, False
        if abs_min_plus_zero is not None and abs_max_minus is not None:
            case1 = True
        if abs_min_minus is not None and abs_max_plus_zero is not None:
            case2 = True
        if case1 and case2:
            if abs_max_minus * abs_min_minus <= abs_max_plus_zero * abs_min_plus_zero:
                ans_lst.remove(abs_min_minus)
                ans_lst.append(abs_max_plus_zero)
            else:
                ans_lst.remove(abs_min_plus_zero)
                ans_lst.append(abs_max_minus)
        elif case1:
            ans_lst.remove(abs_min_plus_zero)
            ans_lst.append(abs_max_minus)
        elif case2:
            ans_lst.remove(abs_min_minus)
            ans_lst.append(abs_max_plus_zero)


# functools.reduceはTLEをくらう場合があるので気をつける
ans = 1
for i in ans_lst:
    ans = (ans * i) % MOD
print(ans)


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

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


Measured memory_bytes: 256
n,m=list(map(int,input().split()))
li=[[] for _ in range(n)]
for _ in range(m):
  a,b=list(map(int,input().split()))
  li[a-1].append(b)
  li[b-1].append(a)

for i in range(n):
  print(len(li[i]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
void pre(){}
long long int n,m,a,b;
vector<long long int>fov[100001];
long long int dp[100001]{0};
bool flag[100001]{0};
long long int dfs(long long int i){
    if(flag[i]){
        return dp[i];
    }
    if(fov[i].size()==0){
        dp[i]=-1;
        return dp[i];
    }
    flag[i]=1;
    dp[i]=0;
    for(auto j:fov[i]){
        dp[i]=max(dp[i],dfs(j)+1);
    }
    return dp[i];
}
void solve(){
    cin>>n>>m;
    for(long long int i=0;i<m;i++){
        cin>>a>>b;
        fov[a].push_back(b);
    }
    for(long long int i=1;i<=n;i++){
        fov[0].push_back(i);
    }
    cout<<dfs(0)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 8820
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

class UnionFind{
  public:
    //親の番号を格納．親の場合は-(その集合のサイズ)
    vector<int> Parent;
    //親との距離
    vector<int> Distance;
    //作るときはParentの値をすべて-1にする
    UnionFind(int N){
      Parent = vector<int>(N,-1);
      Distance = vector<int>(N,0);
    }

    //親を求める
    int find(int x){
      if(Parent[x] < 0) return x;
      //親の紐づけを変更
      if(Parent[x] != find(Parent[x])) Distance[x] += Distance[Parent[x]]; 
      return Parent[x] = find(Parent[x]);
    }

    //xの属する集合のサイズを取ってくる
    int size(int x){
      return -Parent[find(x)];
    }

    //2点間の距離を計算
    //xからみてy
    int getDistance(int x,int y){
      //find(x);
      //find(y);
      return  Distance[y] - Distance[x];
    }

    //xとyの属する集合を併合
    //併合できたらtrue，すでに併合していたらfalse 
    bool unite(int x, int y, int d){
      //xとyを直接つけない，親同士をつける
      d += Distance[x] - Distance[y];
      x = find(x);
      y = find(y);
      if(x==y) return false;

      //大きいほうに小さいほうをくっつける
      if(size(x) < size(y)){
        swap(x,y);
        d *= -1;
      }

      //xのサイズを更新
      Parent[x] += Parent[y];
      Parent[y] = x;
      Distance[y] = d;
      return true;
    }

    //xとyが同じ集合に属するか
    bool same(int x, int y){
      return find(x) == find(y);
    }
};
int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  UnionFind uni =  UnionFind(N);
  bool isExist = true;
  rep(i,M){
    int L,R,D;cin >> L >> R >> D;
    L--;R--;
    if(uni.same(L,R)){ 
      if(uni.getDistance(L,R) != D){
        isExist = false;
        break;
      }
    } else uni.unite(L,R,D);
  }
  YesNo(isExist);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int x;
    cin >> x;
    
    for(int i = x; i < 1e9; i++){
        int flag = 0;
        for(int j = 2; j < pow(i, 0.5); j++){
            if(i % j == 0){
                flag = 1;
            }
        }
        if(flag == 0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

typedef struct  circle{
    double x;
    double y;
    double r;
}CIRCLE;

int main(void){

    CIRCLE a,b;
    int n;
    double sum,diff1,diff2,len;

    cin >> n;

    while(n > 0){

        cin >> a.x >> a.y >> a.r >> b.x >> b.y >> b.r;

            sum = a.r + b.r;
            diff1 = a.r - b.r;
            diff2 = b.r - a.r;
            len = sqrt(pow(a.x - b.x,2.0) + pow(a.y - b.y,2.0));

            if(diff1 > len){
                cout << "2" << endl;
            }else if(diff2 > len){
                cout << "-2" << endl;
            }else if(fabs(diff1) <= len && len <= a.r + b.r){
                cout << "1" << endl;
            }else{
                cout << "0" << endl;
            }

        n--;
    }

    return 0;
}

Measured memory_bytes: 3180
#include <stdio.h>

typedef long long ll;
int main() {
	ll n, five = 0;
	scanf("%lld", &n);
	if(n & 1) {
		printf("0");
		return 0;
	}
	
	n /= 10;
	while(n) {
		five += n;
		n /= 5;
	}
	printf("%lld", five);
	return 0;
}

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

int main() {
  int a, b, c; cin >> a >> b >> c;
  bool ans=false;
  if (a == b && b != c){
    ans = true;
  }else if(b == c && b != a) {
    ans = true;
  }else if (a == c && a != b) {
    ans = true;
  }
  if (ans){
    cout << "Yes" << endl;
    return 0;
  }
  else
    cout << "No" << endl;
  return 0;
}


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

vector<int> list_of_possible_primes() {
  // 1381 is the 55th number which satisfies the requirements of this problem.
  const int SEIVE_SIZE = 1381; // 55555;
  vector<bool> seive(SEIVE_SIZE + 1, true);
  seive[0] = false;
  seive[1] = false;
  for (int i = 2; i * i <= SEIVE_SIZE; ++i) {
    for (int j = i + i; j <= SEIVE_SIZE; j += i) {
      seive[j] = false;
    }
  }
  vector<int> list;
  for (int i = 0; i <= SEIVE_SIZE; ++i) {
    if (seive[i] && i % 5 == 1) {
      list.push_back(i);
    }
  }
  return list;
}

int main() {
  int n;
  cin >> n;

  vector<int> ps = list_of_possible_primes();

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

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

int H, W;
char c[1024][1024];

int kitaeri[1024][2];

int main(void) {
	int i, j;
	int amamiyasora = 0;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%1023s", c[i]) != 1) return 1;
	}
	for (i = 0; i < H; i++) {
		int asumi = -1, iguti = -1;
		for (j = 0; j < W; j++) {
			if (c[i][j] == 'B') {
				iguti = j;
				if (asumi < 0) asumi = j;
			}
		}
		kitaeri[i][0] = asumi;
		kitaeri[i][1] = iguti;
	}
	for (i = 0; i < H; i++) {
		if (kitaeri[i][0] < 0) continue;
		for (j = i; j < H; j++) {
			if (kitaeri[j][0] >= 0) {
				int morikubosyoutarou = (j - i) + abs(kitaeri[j][1] - kitaeri[i][0]);
				int namikawadaisuke = (j - i) + abs(kitaeri[j][0] - kitaeri[i][1]);
				if (amamiyasora < morikubosyoutarou) amamiyasora = morikubosyoutarou;
				if (amamiyasora < namikawadaisuke) amamiyasora = namikawadaisuke;
			}
		}
	}
	printf("%d\n", amamiyasora);
	return 0;
}



Measured memory_bytes: 2804
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	heap := make([]int, 2000000)
	for i := 0; i < len(heap); i++ {
		heap[i] = -1
	}

	tailInd := 0

	for {
		command := nextText(sc)
		if command == "insert" {
			x, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			insert(tailInd, x, heap)
			tailInd++
		} else if command == "extract" {
			x := extract(tailInd, heap)
			fmt.Println(x)
			tailInd--
		} else if command == "end" {
			break
		}
	}
}

func insert(tailInd int, x int, heap []int) {
	heap[tailInd] = x
	nodeNumber := tailInd + 1
	for nodeNumber > 1 {
		if heap[nodeNumber-1] > heap[nodeNumber/2-1] {
			heap[nodeNumber-1], heap[nodeNumber/2-1] = heap[nodeNumber/2-1], heap[nodeNumber-1]
			nodeNumber = nodeNumber / 2
		} else {
			break
		}
	}
}

func extract(tailInd int, heap []int) int {
	extracted := heap[0]
	heap[0] = -1
	if tailInd <= 0 {
		return extracted
	}
	swap(0, tailInd-1, heap)
	nodeNumber := 1
	for {
		if nodeNumber*2-1 >= tailInd-1 {
			break
		} else if nodeNumber*2 >= tailInd-1 {
			if heap[nodeNumber-1] < heap[nodeNumber*2-1] {
				swap(nodeNumber-1, nodeNumber*2-1, heap)
			}
			break
		}
		if heap[nodeNumber-1] < heap[nodeNumber*2-1] || heap[nodeNumber-1] < heap[nodeNumber*2] {
			if heap[nodeNumber*2-1] > heap[nodeNumber*2] {
				swap(nodeNumber-1, nodeNumber*2-1, heap)
				nodeNumber = nodeNumber * 2
			} else {
				swap(nodeNumber-1, nodeNumber*2, heap)
				nodeNumber = nodeNumber*2 + 1
			}
		} else {
			break
		}
	}
	return extracted
}

func swap(x int, y int, heap []int) {
	heap[x], heap[y] = heap[y], heap[x]
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}



Measured memory_bytes: 29852
//???????????????
process.stdin.setEncoding('utf8');
//?¨??????\??????????????¨??\???????????????
process.stdin.on('data', function (input) {
    //60sec = 1min, 3600sec = 1h
    var inputNum = parseInt(input);
    var hour = Math.floor(inputNum / 3600);
    var min = Math.floor((inputNum % 3600) / 60);
    var sec = Math.floor(inputNum % 60);
    console.log(hour + ':' + min + ':' + sec);

})

Measured memory_bytes: 15644
def sub_k(string, I, K):
    temp = []
    for i in range(len(string)):
        if i-1+I == len(string):
            break
        temp.append(string[i:i+I])
    return sorted(set(temp))[0:K]

def main(string, K):
    result = []
    for i in range(K):
        result += sub_k(string, i+1, K-i)
    print(sorted(set(result))[K-1])

string = input()
K = int(input())
main(string, K)

Measured memory_bytes: 3528
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

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


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    int a[5];
    int k;

    rep(i, 5){
        cin >> a[i];
    }

    cin >> k;

    if (a[4] - a[0] <= k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<ll,ll> > A(N);
    REP(i,N){
        ll tmpa, tmpb;
        cin >> tmpa >> tmpb;
        A[i] = make_pair(tmpa, tmpb);
    }
    sort(all(A));
    ll ans = 0;
    ll num = 0;
    REP(i,N){
        if(num+A[i].second<=M){
            ans += A[i].first * A[i].second;
            num += A[i].second;
        } else {
            ans += A[i].first * (M - num);
            num += M - num;
        }
        if(num >= M) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;
#define pii pair <int , int>
#define F first
#define S second
const int N = 1e5 + 5, inf = 1e9 + 1;
int A[N], B[N], par[N], C, n, m;
long long W[N], Sum;
vector <int> g[N];
priority_queue <pii, vector<pii>, greater<pii>> pq[N];

void init() {
    C = n;
    for (int v = 1; v <= n; v++) {
        par[v] = v, W[v] = B[v];
        while (!pq[v].empty()) pq[v].pop();
        for (int u : g[v]) pq[v].push({A[u] - B[u], u});
    }
}
int getpar(int v) {return par[v] = (par[v] == v ? v : getpar(par[v]));}
void Union(int u, int v) {
    u = getpar(u);
    if (u == v) return ;
    par[u] = v, W[v] += W[u], C--;
    if (pq[u].size() > pq[v].size()) swap(pq[u], pq[v]);
    while (!pq[u].empty()) pq[v].push(pq[u].top()), pq[u].pop();
}
bool check(int w) {
    init();
    for (int v = 1; v <= n; v++) if (par[v] == v && w + W[v] >= A[v]) {
        while (!pq[v].empty()) {
            int u = pq[v].top().S;
            if (A[u] - B[u] > W[v] + w) break ;
            pq[v].pop(), Union(u, v);
        }
    }
    return C == 1;
}
int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> A[i] >> B[i], Sum += B[i];
    if (n == 1) return cout << max(A[1], B[1]) << "\n", 0;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    int dw = -1, up = inf;
    while (up - dw > 1) {
        int md = (up+dw)>>1;
        if (check(md)) up = md;
        else dw = md;
    }
    cout << Sum + up << "\n";


    return 0;
}


Measured memory_bytes: 19800
// In the name of Allah 
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define ld long double
#define mp make_pair

const ll MAX = 1e5 + 10, MAXL = 32, inf = 1e9+1, mod = 95542721;

ll n, k, a[MAX], b[MAX], res;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	ll sum = 0;
	for (int i = 0; i < n; i++)
		if ((a[i] | k) == k)
			res += b[i];
	for (int i = 0; i <= 30; i++)
	{
		if (!((k >> i) & 1)) continue;
		ll now = 0;
		for (int j = 0; j < i; j++) now |= (1 << j);
		for (int j = i+1; j <= 30; j++)
			if ((k >> j) & 1)
				now |= (1<<j);
		sum = 0;
		for (int j = 0; j < n; j++)
			if ((a[j] | now) == now)
				sum += b[j];
		res = max (res, sum);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    string s,t;cin >>s >>t;
    vvl alp(26);
    rep(i,s.size()){
        ll a=s[i]-'a';
        alp[a].pb(i);
    }
    ll ans=0;
    ll tmp=0;
    rep(i,t.size()){
        ll x=t[i]-'a';
        if(alp[x].size()==0){
            cout << -1 <<endl;
            return 0;
        }
        ll ind=lower_bound(all(alp[x]),tmp)-alp[x].begin();
        if(ind<alp[x].size())tmp=alp[x][ind]+1;
        else{
            ans+=s.size();
            tmp=alp[x][0]+1;
        }
    }
    cout <<ans+tmp <<endl;
}

Measured memory_bytes: 1724