akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define ao(a)        \
    for (auto i : a) \
        cout << i << " ";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 1e6 + 6;
ll n, ans = 0;
bool check(ll num)
{
    ll a = 0, b = 0, c = 0;
    while (num > 0)
    {
        if (num % 10 == 3)
            a = 1;
        if (num % 10 == 5)
            b = 1;
        if (num % 10 == 7)
            c = 1;
        num /= 10;
    }
    if (a && b && c)
        return true;
    else
        return false;
}
void dfs(ll num)
{
    if (num > n)
        return;
    if (check(num))
    {
        ans++;
    }
    dfs(num * 10 + 3);
    dfs(num * 10 + 5);
    dfs(num * 10 + 7);
}
int main()
{

    cin >> n;
    dfs(0);
    c(ans) return 0;
}

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

int main(void) {
	int N,M,sum=0,min,k;
  cin >> N >> M;
  for(int i=0;i<N;++i){
    cin >> k;
    if(i==0)min=k;
  	sum += k;
    if(min > k) min = k;
  }
 cout << (M-sum)/min + N;
  
  
return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, m: usize, k: i64,
        a: [i64; n],
        b: [i64; m],
    }

    let mut read_b = 0;
    let mut time = 0;
    for i in 0..m {
        if time + b[i] > k {
            break;
        }
        time += b[i];
        read_b += 1;
    }

    let mut ans = read_b;
    let mut read_a = 0;
    for i in 0..n {
        time += a[i];
        read_a += 1;
        while time > k && read_b > 0{
            read_b -= 1;
            time -= b[read_b];
        }
        if time > k {
            break;
        }
        ans = max(ans, read_a + read_b);
    }
    println!("{}", ans);
}


Measured memory_bytes: 9324
def main():
    N = int(input())
    r = range(N)
    A = [list(map(int, input().split())) for _ in r]

    for i in r: A[i][i] = float('inf')
    possible = True
    ans = 0
    for i in r :
        for j in range(i+1,N):
            for k in r:
                if A[i][j] < A[i][k] + A[k][j]:
                    continue
                elif A[i][j] == A[i][k] + A[k][j]:
                    break
                else:
                    possible = False
                    break
            else:
                ans += A[i][j]
    print(ans if possible else -1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12628
using System;


namespace ALDS1_1_A_Insertion_Sort
{
	class Program
	{
		static int Main ( string[] args )
		{
			//??\???
			int inputCount = int.Parse (Console.ReadLine ());
			string[] inputStr = Console.ReadLine ().Trim ().Split (' ');
			int[] numArray = new int[inputCount];
			for (int lp = 0; lp < inputCount; lp++)
			{
				numArray[lp] = int.Parse (inputStr[lp]);
			}

			//??????
			InsertionSort (numArray, inputCount);

			return 0;
		}

		static void InsertionSort ( int[] numArray, int numCount )
		{
			Print (numArray);

			for (int lp = 1; lp < numCount; lp++)
			{
				int v = numArray[lp];
				int j = lp - 1;

				while (j >= 0 && numArray[j] > v)
				{
					numArray[j + 1] = numArray[j];
					j--;
				}
				numArray[j + 1] = v;

				Print (numArray);
			}
		}

		//????????¨
		static void Print ( int[] numArray )
		{
			for (int lp2 = 0; lp2 < numArray.Length; lp2++)
			{
				if (lp2 + 1 < numArray.Length)
				{
					Console.Write (numArray[lp2] + " ");
				}
				else
				{
					Console.WriteLine (numArray[lp2]);
				}
			}
		}
	}
}

Measured memory_bytes: 9296
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

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

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

    rep(i,s.size()) {
        if(s[i] == '1') { s[i] = '9'; continue; } 
        if(s[i] == '9') { s[i] = '1'; continue; } 
    }
    
    cout << s << endl;

    return 0;
}



Measured memory_bytes: 256
N, M = gets.strip.split(" ").map(&:to_i)
correct_cnt = 0
wrong_cnt = 0
flags = Array.new(N+1, false)
wrongs = Array.new(N+1, 0)
 
M.times do
  n, a = gets.strip.split(' ')
  flags[n.to_i] = true if a == 'AC' && flags[n.to_i] == false
  wrongs[n.to_i] += 1 if a == 'WA' && flags[n.to_i] == false
end
(1..N).each do |n|
  if flags[n] == true
    correct_cnt += 1
    wrong_cnt += wrongs[n]
  end
end
puts "#{correct_cnt} #{wrong_cnt}"

Measured memory_bytes: 3324
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iomanip>
#define ll long long int
#define add push_back

using namespace std; 

int main() {

    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);

    int T;  
    // cin >> T;
    T = 1;
    while(T--){
        ll n; cin >> n;
        if(n < 2){
            cout << 0 << endl;
            continue;
        }
        ll first = 1;
        ll mod = 1000000007;
        for(int i = 0; i < n; i++){
            first *= 10;
            first %= mod;
        }
        ll second = 1;
        for(int i = 0; i < n; i++){
            second *= 9;
            second %= mod;
        }
        ll last = 1;
        for(int i = 0; i < n; i++){
            last *= 8;
            last %= mod;
        }
        cout << ((first - 2*second + last) + (3 * mod)) % mod << endl;

    }
    return 0;
}

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

int n, q;
long long a, b, c, sum;
map < long long, long long > d;

signed main () {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &a);
		sum += a;
		++d[a];
	}
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		scanf("%lld %lld", &b, &c);
		if (d.find(b) != d.end()) {
			sum -= d[b] * b;
			sum += d[b] * c;
			d[c] += d[b];
			d.erase(b);
		}
		printf("%lld\n", sum);
	}
}


Measured memory_bytes: 7772
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  map<int,int> memo;
  rep(i,n){
    int buf;cin>>buf;
    memo[buf]+=1;
  }
  auto it=memo.end();
  int res=0;
  while(it!=memo.begin()){
    --it;
    
    int nxt=1;
    int hoge=it->first;
    while(hoge>0){
      hoge/=2;
      nxt*=2;
    }
    //printf("value = %lld, nxt = %lld\n",it->first,nxt);
    if(it->first*2==nxt){
      res+=it->second/2;
      it->second=0;
      continue;
    }
    auto it2=memo.find(nxt-it->first);
    if(it2!=memo.end()){
      res+=min(it->second,it2->second);
      it2->second-=min(it->second,it2->second);
    }
    it->second=0;
  }
  cout<<res<<"\n";
  return 0;
}

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

ll n,m,res=1,MOD=1000000007;

ll modpow(ll a, ll n){
	ll r=1;
	while(n)r=r*((n%2)?a:1)%MOD,a=a*a%MOD,n>>=1;
	return r;
}

ll comb(int n,int k){
	if(n<0||k<0||k>n)return 0;
	ll p=1,q=1;
	k=min(k,n-k);
	for(int i=1;i<=k;i++,n--)p=p*n%MOD,q=q*i%MOD;
	return p*modpow(q,MOD-2)%MOD;
}

ll hcomb(int n,int k){return (n==0&&k==0)?1:comb(n+k-1,k);}

map<ll,int> prime_decomp(ll n){
	map<ll,int> V;
	for(int i=2;i*i<=n;i++){
		while(n%i==0){
			V[i]++;
			n/=i;
		}
	}
	if(n>1)V[n]++;
	return V;
}

inline void solve(void){
	cin>>n>>m;
	for(auto v:prime_decomp(m))res=res*hcomb(n,v.second)%MOD;
	cout<<res<<endl;
}


int main(void){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  solve();
  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    A = inputList()
    
    Adict = {}
    for i in A:
        if i in Adict:
            Adict[i] += 1
        else:
            Adict[i] = 1
            
    if len(Adict) <= K:
        print(0)
        sys.exit()
        
    #print(Adict)
    i = 0
    ans = 0
    for k, v in sorted(Adict.items(), key=lambda x: -x[1]):
        #print("{} {}".format(k,v))
        if i < K:
            i += 1
            continue
        #print(k)
        ans += v
        
    print(ans)
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 97476
#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define F first
#define S second
#define var auto
using namespace std;
typedef long long ll;
const int Mod = 924844033;
const int Max = 4010;

ll dp[Max][Max];
ll numofway[Max][Max];
ll fact[Max];
void Solve(vector<int> A , int cntOfElem)
{
    int n = A.size() - 1;//there exists A[i] for every i from 1 to n

    numofway[0][0] = numofway[1][0] = numofway[1][1] = 1;

    for(int a = 2; a < Max; a++)
    {
        numofway[a][0] = 1;
        for(int cnt = 1; cnt <= a; cnt++)
        {
            numofway[a][cnt] = (numofway[a - 1][cnt] + numofway[a - 2][cnt - 1]) % Mod;
        }
    }
    for(int cnt = 0; cnt <= A[n]; cnt++)
    {
        dp[n][cnt] = numofway[A[n]][cnt];
    }
    for(int i = n - 1; i >= 1; i--)
    {
        dp[i][0] = 1;
        for(int cnt = 1; cnt <= cntOfElem; cnt++)
        {
            for(int j = 0; j <= A[i] && j <= cnt; j++)
            {
                dp[i][cnt] += (dp[i + 1][cnt - j] * numofway[A[i]][j]) % Mod;
            }
            dp[i][cnt] %= Mod;
        }
    }
fact[0] = 1;
    for(int i = 1; i < Max; i++)
        fact[i] = (fact[i - 1] * i) % Mod;
    ll ans = 0;
    int sign = 1;
    for(int i = 0; i <= cntOfElem; i++)
    {
        ans = (ans + sign * (dp[1][i] * fact[cntOfElem - i] % Mod) + Mod ) % Mod;
        sign = -sign;
    }

    cout << ans << '\n';;
}

int main()
{
    int n , k;cin >> n >> k;
    int badCnt = 2 * (n - k);
    int mn = badCnt / (2 * k);
    int bgcnt = badCnt % (2 * k);
    vector<int> A;A.pb(0);
    for(int i = 0 ; i < 2 * k ; i++)
        if(i < bgcnt)
            A.pb(mn + 1);
        else
            A.pb(mn);
    Solve(A , n);
}

Measured memory_bytes: 159744
import java.util.* ;
public class Main {
    public static void main(String[] args) {
        Main obj = new Main() ;
        Scanner S = new Scanner( System.in ) ;
        int l = S.nextInt() ;
        int r = S.nextInt() ;
        int k = S.nextInt() ;
        int result = 0 ;
        for( int i=l;i<=r;i++ ) {
            if( i%k==0 ) result++ ;
        }
        System.out.println( result ) ;
    }
}

Measured memory_bytes: 35700
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            List<int> lstA = new List<int>();
            sS = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < sS.Length; i++) { lstA.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int dAvg = (int)(lstA.Average() * (double)iN);
            List<ClsDev> lstD = new List<ClsDev>();
            for (int i = 0; i < lstA.Count; i++)
            {
                ClsDev oneUsr = new ClsDev();
                oneUsr.iX = i;
                oneUsr.iD = Math.Abs(lstA[i] * iN - dAvg);
                lstD.Add(oneUsr);
            }
            lstD.Sort(delegate (ClsDev mca1, ClsDev mca2) { return (int)(mca1.iD - mca2.iD == 0 ? mca1.iX - mca2.iX : mca1.iD - mca2.iD); }); // Dの昇順のXの昇順

            // 出力
            System.Console.WriteLine("{0}", lstD[0].iX.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        private class ClsDev
        {
            public int iX { get; set; } = 0;
            public int iD { get; set; } = 0;
        }

}


Measured memory_bytes: 13396
N, M = map(int, input().split())
E = [[int(x) - 1 for x in input().split()] for _ in range(M)]

def root(par, a):
    a_ = a
    while par[a] != a:
        a = par[a]
    par[a_] = a
    return a

def unite(par, a, b):
    ar = root(par, a)
    br = root(par, b)
    if ar != br:
        par[ar] = br

ans = 0
for i in range(M):
    par = list(range(N))
    for j in range(M):
        if i == j:
            continue
        a, b = E[j]
        unite(par, a, b)

    r0 = root(par, 0)
    for k in range(1, N):
        if root(par, k) != r0:
            ans += 1
            break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
typedef pair<int, int> ii;
int n, a[N];
bool check(int x) {
	priority_queue<ii> pq; //{position, character}
	fw (i, 1, n) {
		if (a[i] > a[i - 1]) continue;
		while (!pq.empty()) {
			ii tmp = pq.top(); pq.pop();
			if (tmp.fi <= a[i]) {
				pq.push(tmp);
				break;
			}
		}
		//Top of pq is now <= a[i]. We increment position a[i] by 1
		int cur = a[i], save = 1;
		while (save) {
//			cout << "cur = " << cur << " size = " << pq.size() << "\n";
			if (!pq.size()) {
				pq.push(ii(cur, 2));
//				cout << "Push in (" << cur << ", 2)\n";
				save = 0;
			} else {
				ii tmp = pq.top(); pq.pop();
				if (tmp.fi == cur) {
					if (tmp.se < x) {
						tmp.se++;
						pq.push(tmp);
						save = 0;
					} else {
						if (tmp.fi == 1) return 0;
						save = 1; //Position is reset to 'a', therefore don't need storage.
					}
				} else {
//					cout << "Push in (" << cur << ", 2)\n";
					pq.push(tmp);
					pq.push(ii(cur, 2)), save = 0;
				}
			}
			cur--;
		}
	}
	return 1;
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n) cin >> a[i];
	bool inc = 1;
	fw (i, 1, n) if (a[i] <= a[i - 1]) {
		inc = 0;
		break;
	}
	if (inc) {
		cout << "1";
		return 0;
	}
//	If a[i + 1] > a[i], it's just a[i] padded with as
//	a[i + 1] <= a[i], position a[i + 1] of a[i] will be incremented by 1.
//	Use priority queue.
	int l = 2, r = n;
	while (l < r) {
		int m = (l + r) >> 1;
		if (check(m)) r = m;
		else l = m + 1;
	}
	cout << l;
	return 0;
}

Measured memory_bytes: 1024
#B 81

N = int(input())
List = [1, 2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,72,81]

if 81 < N:
    print('No')
elif N in List:
    print('Yes')
else:
    print('No')

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  vector<int> cost(n,1000000001);
  cost[0] = 0;
  rep (i, n) {
    cin >> h[i];
  }
  for (int i = 0; i < n ;i++) {
    if (i + 1 < n) cost[i+1] = min(cost[i+1],cost[i]+abs(h[i+1]-h[i]));
    if (i + 2 < n) cost[i+2] = min(cost[i+2],cost[i]+abs(h[i+2]-h[i]));
  }
  cout << cost[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
  ll n;
  cin >>n;
  cout << n*(n-1)/2 << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                int coin = i*500+j*100+k*50;
                if (coin == d) ans++;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(s == u) a--;
    else if(t == u) b--;
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
X, Y = map(int, input().split())
ans = 0
if X == 3:
    ans += 100000
elif X == 2:
    ans += 200000
elif X == 1:
    ans += 300000
if Y == 3:
    ans += 100000
elif Y == 2:
    ans += 200000
elif Y == 1:
    ans += 300000
if X == Y == 1:
    ans += 400000
print(ans)

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

int main(void){
  string a, b, c;

  cin >> a >> b >> c;

  if(a.back() == b.front())
    if(b.back() == c.front())
      cout << "YES" << endl;
    else cout << "NO" << endl;
  else cout << "NO" << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(0);

    int n; cin >> n;
    cout << pow(n, 3);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// #define int long long
 
/* short */
#define pb push_back
#define print(x) cout << x << '\n'
 
/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

int H, W, N;
char field[1024][1024];

int bfs(int sx, int sy, int gx, int gy)
{
  int res[1024][1024];
  memset(res, -1, sizeof(res));
  queue<pii> Q;
  Q.push(pii(sx, sy));
  res[sy][sx] = 0;

  for (; !Q.empty();){
    int x = Q.front().first, y = Q.front().second; Q.pop();
    //cout << "debug: x " << x << " y " << y << endl;
    if (x == gx && y == gy)  break;
    REP(i, 4){
      int mx = x + dx[i], my = y + dy[i];
      if (mx < 0 || my < 0 || mx >= W || my >= H) continue;
      if (field[my][mx] != 'X' && res[my][mx] == -1){
        Q.push(pii(mx, my));
        res[my][mx] = res[y][x] + 1;
      }
    }
  }

  return (res[gy][gx]);
}

signed main()
{
  ios::sync_with_stdio(false);
  pii st;
  pii fac[10];

  cin >> H >> W >> N;
  REP(i, H){
    REP(j, W){
      cin >> field[i][j];
      if (field[i][j] == 'S') st = pii(j, i);
      if (isdigit(field[i][j])) fac[field[i][j] - '0'] = pii(j, i);
    }
  }

  int ans = bfs(st.first, st.second, fac[1].first, fac[1].second);
  REPS(i, 2, N + 1){
    ans += bfs(fac[i - 1].first, fac[i - 1].second, fac[i].first, fac[i].second);
  }
  print(ans);

  return (0);
}

Measured memory_bytes: 6320
<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
foreach($A as $k=>$v) {
  $to[0][$k]=$v-1;
}
$D=60;

for($i=0;$i<$D-1;$i++) {
  for($j=0;$j<$N;$j++) {
    $to[$i+1][$j] = $to[$i][$to[$i][$j]];
  }
}
$v=0;
for($i=$D-1;$i>=0;--$i) {
  $l = 1<<$i;
  if ($l <= $K) {
    $v = $to[$i][$v];
    $K -= $l;
  }
}
printf("%d\n",$v+1);


Measured memory_bytes: 406960
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=3*1e5+10;

int n;
int a[N];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=3*n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+3*n+1);
	long long Ans=0;
	int m=n*3;
	int now=0;
	for(int i=m-1;now<n;now++,i-=2)
		Ans+=a[i];
	cout<<Ans<<endl;
}

Measured memory_bytes: 1408
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = INT()
print(L[K-1])

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 111;
const int L = 500;

unsigned long long w = 1;
void mul(int x) {
    w *= x;
}

int n;
vector<int> e[N];
vector<int> st, lng;

void dfs(int v, int p = -1) {
    st.push_back(v);
    if (sz(st) > sz(lng))
        lng = st;
    for (int nv : e[v])
        if (nv != p)
            dfs(nv, v);
    st.pop_back();
}

int cc[N];
void dfs2(int v, int p, int cd = 0) {
    cc[cd] = max(cc[cd], sz(e[v]) - (p == -1 ? 0 : 1));
    for (int nv : e[v])
        if (nv != p)
            dfs2(nv, v, cd + 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    dfs(0);
    int v0 = lng.back();
    lng.pop_back();
    dfs(v0);

    int dep;
    if (sz(lng) % 2 == 1) {
        dep = sz(lng) / 2 + 1;
        cout << dep << " ";
        int v = lng[sz(lng) / 2];
        dfs2(v, -1);

        ull bw = 1;
        for (int i = 0; i < dep - 1; ++i) {
            bw *= cc[i];
        }
        for (int v2 : e[v]) {
            memset(cc, 0, sizeof(cc));
            dfs2(v, v2, 0);
            dfs2(v2, v, 0);
            ull cw = 2;
            for (int i = 0; i < dep - 1; ++i)
                cw *= cc[i];
            bw = min(bw, cw);
        }
        w = bw;
    } else {
        dep = sz(lng) / 2 + 1;
        cout << dep - 1 << " ";
        int v1 = lng[sz(lng) / 2 - 1];
        int v2 = lng[sz(lng) / 2];
        cc[0] = 2;
        dfs2(v1, v2, 1);
        dfs2(v2, v1, 1);
        for (int i = 0; i < dep - 1; ++i) {
            assert(cc[i]);
            mul(cc[i]);
        }
    }

    cout << w << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int a[100010][3];
int dp[100010][3];
 
int32_t main()
{
    int n;
    cin >> n;
 
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
            cin >> a[i][j];
    }
 
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j != k)
                    dp[i][j] = max(dp[i][j],dp[i-1][k]+a[i][j]);
            }
        }
    }
 
    cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;

int main() {
	int h, w;
	cin >> h >> w;
	vector< vector<char> > mp(h, vector<char>(w));
	int ans = h * w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> mp[i][j];
			if (mp[i][j] == '#') {
				ans--;
			}
		}
	}
	
	vector< vector<int> > mp2(h, vector<int>(w, 0));
	mp2[0][0] = 1;

	queue<Q> q;
	if (mp[0][0] != '#') {
		q.push(Q(1,P(0, 0)));
	}
	int dx[] = { 1,0,-1,0 };
	int dy[] = { 0,1,0,-1 };
	bool hh = false;
	long long int pqr = 0;
	while (!q.empty()) {
		Q qq = q.front();
		q.pop();
		P p = qq.second;
		for (int i = 0; i < 4; i++) {
			if (0 <= p.first + dx[i] && p.first + dx[i] < w && 0 <= p.second + dy[i] && p.second + dy[i] < h && mp2[p.second+dy[i]][p.first+dx[i]] == 0 && mp[p.second+dy[i]][p.first+dx[i]]=='.') {
				mp2[p.second + dy[i]][p.first + dx[i]] = 1;
				if (p.first + dx[i] == w - 1 && p.second + dy[i] == h - 1) {
					pqr = qq.first + 1;
					hh = true;
					break;
				}
				else {
					q.push(Q(qq.first+1, P(p.first + dx[i], p.second + dy[i])));
				}
			}
		}
		if (hh) {
			break;
		}
	}
	if (hh) {
		cout << ans-pqr << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main()
{
	int t;
     t=1;
	while(t--)
	{
       int a,b,c;
       cin>>a>>b>>c;
       int y=a/b;
       if(a%b!=0)
       {
       	y=y+1;
       }
       cout<<y*c<<endl;
	}
}

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

int main() {
    int N; cin >> N;
    unordered_map<int, int> m;
    REP(i, 0, N) {
        int a; cin >> a;
        m[a]++;
    }

    int ans = 0;
    for (auto elm : m) {
        if (elm.first > elm.second) ans += elm.second;
        else ans += elm.second - elm.first;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {

	int k,t;
	cin >> k >> t;
	vector<int> a(t);
	for (int i = 0; i < t; i++) {
		cin >> a[i];
	}

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

	int total = accumulate(a.begin(), a.end(), 0);
	int maxx = a[a.size() - 1];
	int nokori = total- maxx;

	if (nokori -1 >= maxx) {
		cout << 0 << endl;
		return 0;
	}
	else {
		cout << maxx - nokori - 1;
	}

	return 0;
}

Measured memory_bytes: 3628
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, m = M()
print((n-1)*(m-1))

Measured memory_bytes: 74592
seq=input()
N=seq.count("N")
S=seq.count("S")
E=seq.count("E")
W=seq.count("W")

if (N>0 and S==0) or (N==0 and S>0) or (E>0 and W==0) or (E==0 and W>0):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
   int n;
   cin >> n;
   int a[n],n2 = 0,n4=0;
   rep(i,n){
       cin >> a[i];
       if(a[i]%4==0) n4++;
       else if(a[i]%2==0) n2++;
   } 
   int n0 = n-n2-n4;
   if(n2==0){
       if(n0<=n4+1) cout << "Yes" << endl;
       else cout << "No" << endl;
       
   }
   else{
       if(n0<=n4) cout << "Yes" << endl;
       else cout << "No" << endl;
   }
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const double EPS = 1e-12;

class union_find {
	vector<int> data;
	
public:
	union_find(int size) {
		data.assign(size, -1);
	}
	
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	
	int find(int k) {
		if (data[k] <	0) return k;
		return data[k] = find(data[k]);
	}
	
	int size(int k) {
		return -data[find(k)];
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main(void) {
    i64 n, m, c;
    cin >> n >> m;
    c = n;
    union_find zohe(n);
    for (i64 i = 0; i < m; i++) {
        i64 x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        if (!zohe.same(x, y)) {
            c--;
            zohe.unite(x, y);
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args)throws IOException{
		int count;
		int n,p;//?????°????°????
		int i,j;
		int wan;
		int k=0;
		List<Human> list=new ArrayList<Human>();
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			count=0;
			list.clear();
			wan=0;
			k=0;
			
			String str=br.readLine();
			String[] a=str.split(" ");
			n=Integer.parseInt(a[0]);
			p=Integer.parseInt(a[1]);
			if(n==0&&p==0){
				break;
			}
			for(i=0;i<n;i++){
				Human e=new Human();
				list.add(i,e);
			}
			wan=p;
			
			while(true){
				if(wan>0){
					list.get(k).setStone(list.get(k).getStone()+1);
					wan--;
				}else if(wan==0){
					wan=list.get(k).getStone();
					list.get(k).setStone(0);
				}
				if(list.get(k).getStone()==p){
					System.out.println(k);
					break;
				}
				if(k<n-1){
					k++;
				}else{
					k=0;
				}
			}
		}
	}
	
}

class Human{
	int stone=0;

	public int getStone() {
		return stone;
	}

	public void setStone(int stone) {
		this.stone = stone;
	}
	
}

Measured memory_bytes: 25520
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int dp[3010][3010];
int main ()
{
    string s,t,res;
    cin>>s>>t;

    for (int i = 0; i <=s.size() ; ++i) {
        dp[0][i]=0;
    }
    for (int i = 0; i <=s.size() ; ++i) {
        dp[i][0]=0;
    }
    for (int k = 1; k <=s.length() ; ++k) {
        for (int l = 1; l <=t.size() ; ++l) {
            if (s[k-1]==t[l-1]) {
                dp[k][l]=dp[k-1][l-1]+1;
            } else  {
                dp[k][l]=max(dp[k-1][l],dp[k][l-1]);
            }

        }
    }
    int i=s.length(),j=t.length();
    res="";
    while (i>0&&j>0) {
        if (s[i-1]==t[j-1]) {
            res=res+s[i-1];
            i--;
            j--;
        } else if (dp[i-1][j]>dp[i][j-1]) {
            i--;
        } else {
            j--;
        }



    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;



}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
    ll t,n,item,temp=1,h,flag1=0,flag2=0,cost=100000000000,sum=0,k,avg=0;
    vector<ll>v1;
    vector<ll>v2;
    map<ll,ll>mp;
    ll L,R,d;
    cin>>L>>R>>d;
    if(L%d==0)
    {
        item=L/d;
        for(ll i=item;i*d<=R;i++)
        {
            sum++;
        }
    }
    else
    {
         item=L/d+1;
        for(ll i=item;i*d<=R;i++)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
int n,a,b,c,d;
string s;
bool dp1[222222],dp2[222222];
signed main(){
	cin>>n>>a>>b>>c>>d>>s;
	a--,b--,c--,d--;
	if(c>d){
		rep(i,n-2){
			if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'&&b-1<=i&&i+1<=d&&i!=d&&i+2!=b)goto ok;
		}
		puts("No");
		return 0;
	}
	ok:;
	dp1[a]=true;
	for(int i=a+1;i<=c;i++){
		if(s[i]=='.'){
			if(0<=i-2){
				if(dp1[i-1]||dp1[i-2])dp1[i]=true;
			}
			else if(dp1[i-1])dp1[i]=true;
		}
	}
	dp2[b]=true;
	for(int i=b+1;i<=d;i++){
		if(s[i]=='.'){
			if(0<=i-2){
				if(dp2[i-1]||dp2[i-2])dp2[i]=true;
			}
			else if(dp2[i-1])dp2[i]=true;
		}
	}
	if(dp1[c]&&dp2[d])puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 772
N = int(input())
ans = []
if N % 2 == 0:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if j <= i or i + j == N + 1:
                continue
            ans.append((i, j))
else:
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if j <= i or i + j == N:
                continue
            ans.append((i, j))

print(len(ans))
for i, j in ans:
    print(i, j)


Measured memory_bytes: 43504
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		String S = in.next();
		int[] east = new int[N+2];
		int[] west = new int[N+2];
		east[0] = 0;
		west[N+1] = 0;
		for(int i=1;i<=N;i++) {
			east[i] = (S.charAt(i-1)=='E')? east[i-1] : east[i-1] + 1;
			west[N+1-i] = (S.charAt(N-i)=='E')? west[N+2-i] + 1 : west[N+2-i];
		}
		int min = N;
		for(int i=1;i<=N;i++) {
			int sum = east[i-1] + west[i+1];
			min = Math.min(min, sum);
		}
		System.out.println(min);
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 30912
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int a[n];
		long int ans=0;
		for(int i=0;i<n;i++){
			cin>>a[i];
			ans+=a[i];
		}
		sort(a,a+n);
		cout<<a[0]<<' '<<a[n-1]<<' '<<ans<<endl;
	}
	return 0;
}


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

int main() {
  int n;cin >> n;
  vector<int>a(n);
  rep(i,n)cin >> a[i];
  
  vector<int> b1(0);
  vector<int> b2(0);
  
  rep(i,n){
    if(i%2==0)b2.push_back(a[i]);
    else b1.push_back(a[i]);
  }
  if(n%2==0){
    reverse(b1.begin(),b1.end());
    rep(i,n/2){
      cout << b1[i] << ' ' ;
    }rep(i,n/2){
      cout << b2[i];
      if(i!=n/2-1)cout << ' ';
      else cout << endl;
    }
  }
  else{
    reverse(b2.begin(),b2.end());
    rep(i,b2.size()){
      cout << b2[i] << ' ' ;
    }rep(i,b1.size()){
      cout << b1[i];
      if(i!=b1.size()-1)cout << ' ';
      else cout << endl;
    }
  }
}


Measured memory_bytes: 3956
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    if i in a: dp[i]=0
    else: dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
print(dp[n])

Measured memory_bytes: 13216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll n,k,ans=0;
string s;
void Main(){
    cin>>n>>k>>s;
    reverse(ALL(s));
    ll cnt=0;
    For(i,0,n+1){
        if(s[i]=='1') cnt++;
        else cnt=0;
        if(cnt>=k){
            cout<<-1<<endl;
            return;
        }
    }
    vector<int> vec;
    ll now=0;
    while(now<n){
        for(ll i=min(now+k,n);i>now;i--){
            if(s[i]=='0'){
                vec.push_back(i-now);
                now=i;
                break;
            }
        }
    }
    reverse(ALL(vec));
    For(i,0,vec.size()) cout<<vec.at(i)<<" ";
    cout<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 1144
N, L = map(int, input().split())
A = list(map(int, input().split()))

for i in range(1, N):
    if A[i-1] + A[i] >= L:
        X = i
        break
else:
    print("Impossible")
    exit()

print("Possible")
for i in range(1, X):
    print(i)
for i in range(N-1, X, -1):
    print(i)
print(X)


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

#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N; cin >> N;
    vector<int> a(N); cin >> a;
    int ans = 0;
    rep(i, N) {
        if (i < a[i]-1 && a[a[i]-1]-1 == i) ans++;
    }
    cout << ans << endl;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int a, b; cin >> a >> b;
  cout << max(a+b, max(a-b, a*b)) << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N + 1, 0);
  for (int i = 2; i <= N; i++) {
    int x = i;
    int j = 2;
    while (j <= x) {
      if (x % j == 0) {
        a.at(j)++;
        x /= j;
      } else {
        j++;
      }
    }
  }
  
  ll ans = 1;
  for (int i = 2; i <= N; i++) {
    ans = ans * ((a.at(i) + 1) % mod) % mod;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())

a = list(map(int,input().split()))

b = [0 for i in range(10**5+1)]

for i in range(n):
    if a[i] == 0:
        b[a[i]] += 1
        b[a[i]+1] += 1
    else:
        b[a[i]-1] += 1
        b[a[i]] += 1
        b[a[i]+1] += 1
print(max(b))

Measured memory_bytes: 13964
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	LL N;
	cin >> N;
	vector<LL> v(100001, 0);
	REP(i, N) {
		LL a, b;
		cin >> a >> b;
		a--; b--;
		for (LL j = a; j <= b; ++j) {
			v[j]++;
		}
	}

	for (LL j = N; j >= 0; --j) {
		if (v[j] >= j) {
			cout << j << endl;
			break;
		}
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using  namespace  std ;
 const  int N = 5005 , mod = 1e9 + 7 ;
 int n, f [N] [N], m; char s [N];
 int  main () {
  //freopen ( "pp.in" , "r" , stdin);
  //freopen ( "pp.out" , "w" , stdout);
   scanf ( "%d%s" , &n, s + 1 ); m = strlen (s + 1 );
  f [ 0 ] [ 0 ] = 1 ;
   for ( int i = 0 ; i <n; i ++)
       for ( int j = 0 ; j <= i; j ++) {
           if (j) f [i + 1 ] [j- 1 ] = (f [i + 1 ] [j- 1 ] + f [i] [j])% mod;
           else f [i + 1 ] [j] = (f [i + 1 ] [j] + f [i] [j])% mod;
          f [i + 1 ] [j + 1 ] = (f [i + 1 ] [j + 1 ] + 1ll * f [i] [j] * 2 )% mod;
      }
  for ( int i = 1 ; i <= m; i ++) f [n] [m] = 1ll * f [n] [m] * 500000004 % mod;
   printf ( "%d \n" , f [n] [m]);
   return  0 ;
}

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

int main(){
        int r, c;
        int arr[101][101] = {0};
        cin >> r >> c;
        for(int i = 0; i < r;i++){
                for(int j = 0; j < c; j++){
                        cin  >> arr[i][j];
                }
        }
        for(int i = 0; i < r; i++){
                for(int j = 0; j < c; j++){
                        arr[r][j] += arr[i][j];
                        arr[i][c] += arr[i][j];
                }
                arr[r][c] += arr[i][c];
        }
        for(int i = 0; i <= r; i++){
                for(int j = 0; j <= c; j++){
                cout << arr[i][j] ;
                if(j != c)cout << " ";
                }cout << endl;
        }
}


Measured memory_bytes: 3128
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)


def modinv2(x,r):
  return pow(x,r-2,r)

def perm(n,a,R):
    return (fact[n]*modinv2(fact[n-a],R))

def comb(n,a,R):
    return (fact[n]*modinv2(fact[n-a]*fact[a],R))

def factinit(n,R):
    global fact
    fact = [1]*(n+1)
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%R

s = inn()
x = 0
factinit(s,R)
for i in range(1,s//3+1):
    t = s-3*i
    c = comb(t+i-1,i-1,R)
    x = (x+c)%R
    #ddprint(f"{t=} {c=} {x=}")
print(x)


Measured memory_bytes: 63804
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
using namespace std;
typedef long long ll;
typedef double db;
int n, a[105], v[100], k;
int main()
{
	cin >> n;
	Rep(i, 1, n) scanf ("%d", &a[i]), v[min(8, a[i] / 400)] ++;
	Rep(i, 0, 7) k += (v[i] > 0);
	cout << k + (!k && v[8])<<" "<< k + v[8] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
   int x;
   cin>>x;
   for(int i=1;i<=x;i++){
       if(i%3==0||i%10==3||i%100/10==3||i%100==3||i/100==3||i/100%10==3||i/1000==3){cout<<" "<<i;}

    }
    cout<<endl;
}


Measured memory_bytes: 3096
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    vector<pair<int, int> > ab(n);
    rep(i,n) ab[i] = make_pair(a[i], b[i]);
    sort(ab.begin(), ab.end());
    ll cost = 0;
    rep(i,n){
        ll buy = min(m, ab[i].second);
        cost += (ll)ab[i].first * buy;
        m -= buy;
    }
    cout << cost << endl;
}

Measured memory_bytes: 1920