akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline

s = input().strip()

aa = int(s[:2])
bb = int(s[2:])

if 0 < aa and aa <= 12 and 0 < bb and bb <= 12:
    print("AMBIGUOUS")
elif 0 < aa and aa <= 12:
    print("MMYY")
elif 0 < bb and bb <= 12:
    print("YYMM")
else:
    print("NA")


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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll n;
    cin>>n;
    ll ans=0;
    repA(i,1,n)
    {
        if(i%3==0 || i%5==0) continue;
        ans+=i;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3652
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1].to!int;
    auto T = readln.chomp;
    auto S = T.to!(dchar[]);
    S.reverse;

    Tuple!(bool, int)[] A;
    bool tmp = false;

    foreach (i; 0..N) {
        if (S[i] != S[i+1]) {
            A ~= tuple(tmp, i);
            tmp ^= 1;
        }
    }
    A ~= tuple(false, N);

    int ans = 0;
    int pos = 0;
    int idx = 0;
    int mov = M;
    int[] hoge;

    while (pos < N) {
        if (idx == A.length.to!int - 1) {
            if (mov < M) {
                pos += mov;
                hoge.back += mov;
                mov = M;
            } else {
                pos += M;
                ans += 1;
                hoge ~= M;
            }
        } else if (pos + mov <= A[idx][1]) {
            if (mov < M) {
                pos += mov;
                hoge.back += mov;
                mov = M;
            } else {
                pos += M;
                ans += 1;
                hoge ~= M;
            }
        } else if (pos == A[idx][1]) {
            if (pos + mov > A[idx+1][1]) {
                if (mov == M) {
                    ans += 1;
                    hoge ~= A[idx+1][1] + 1 - pos;
                } else {
                    hoge.back += A[idx+1][1] + 1 - pos;
                }
                mov -= A[idx+1][1] + 1 - pos;
                pos = A[idx+1][1] + 1;
                idx += 2;
            } else if (mov == M) {
                writeln(-1);
                return;
            } else {
                mov = M;
            }
        } else {
            int d = min(A[idx][1] - pos, mov);
            if (mov == M) {
                hoge ~= d;
                ans += 1;
            } else {
                hoge.back += d;
            }
            pos += d;
            mov -= d;
        }
    }

    hoge.back -= hoge.sum - N;
    hoge.reverse;
    hoge.map!(to!string).join(" ").writeln;
}

Measured memory_bytes: 3964
from heapq import heappop, heappush, heapify
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))

N, M = inpl()
LRC = sorted([(lambda L,R,C:(L-1,R-1,C))(*inpl()) for _ in range(M)])
m = 0
dq = [(0,0)]
for i in range(N):
    while dq and dq[0][1] < i:
        heappop(dq)
    if not dq:
        print(-1)
        break
    d = dq[0][0]
    while m < M and LRC[m][0] == i:
        heappush(dq, (d+LRC[m][2], LRC[m][1]))
        m += 1
else:
    print(d)


Measured memory_bytes: 76124
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
    scanf("%d",&n);
    long long ans=0;
    int h=0;
    while(n--)
    {
        int x;scanf("%d",&x);
        if(x<=h) ans+=h-x;
        h=max(h,x);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3808
import sys
def main():
    for line in sys.stdin:
        a = list(line)
        del a[-1]
        for x in range(len(a)):
            a[x] = int(a[x])


        for x in range(9):
            b = []
            for y in range(len(a) - 1):
                hoge = a[y] + a[y + 1]
                if hoge > 9:
                    hoge -= 10
                else:
                    pass
                b.append(hoge)
            else:
                a = b

        print(a[0])


if __name__ == "__main__":
    main()

Measured memory_bytes: 7696
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt();
		String s=stdIn.next();
		if(a<3200)
			System.out.println("red");
		else
			System.out.println(s);
	}
}

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


int main(){
 int N=0;
 int count=0;
 cin >> N;
 vector<string> F(N);

 for(int i=0;i<N;i++){
     cin >> F[i];
 }
 sort(F.begin(),F.end());
 
 for(int i=0;i<N;i++){
if(F[i]!=F[i+1]){
count++;
}
 }
 cout << count <<endl;
}

Measured memory_bytes: 9528
import sys
n = int(input())
s = input()
t = []

if (len(s)==1):
    print(3)
    sys.exit()
if (len(s)==2):
    print(6)
    sys.exit()

for i in range(len(s)-1):
    if (i>0):
        if(s[i-1]==s[i]):
            if (i == len(s)-2):
                t.append(1)
                continue
            else:
                continue
        elif (i == len(s)-2 and s[i]!=s[i+1]):
            t.append(1)
            
    
    if (s[i]==s[i+1]):
        t.append(2)
    else:
        t.append(1)

if (t[0]==1):
    ans = 3
else:
    ans = 6

for i in range(len(t)-1):
    
    if (t[i]==1):
        if (t[i+1]==1):
            ans *= 2
        else:
            ans *= 2
    else:
        if (t[i+1]==1):
            ans *= 1
        else:
            ans *= 3
print(ans % 1000000007)

Measured memory_bytes: 3064
<?php

$A = trim(fgets(STDIN));//10
$B = trim(fgets(STDIN));//2
$C = trim(fgets(STDIN));//1
$X = trim(fgets(STDIN));
$count=0;
//10 2 1
for($i=0;$i<=$A;$i++){
    for($j=0;$j<=$B;$j++){
        for($k=0;$k<=$C;$k++){
            if($i*500+$j*100+$k*50 == $X){
                $count++;
            }
        }
    }
}

echo $count;
?>

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int res[110][110];
int main() {
	int n, h, w;
	cin >> h >> w >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int cur = 1;
	for (int i = 1; i <= h; i++) {
		if (i % 2 == 1) {
			for (int j = 1; j <= w; j++) {
				res[i][j] = cur;
				a[cur]--;
				if (a[cur] == 0) {
					cur++;
				}
			}
		}
		else {
			for (int j = w; j >= 1; j--) {
				res[i][j] = cur;
				a[cur]--;
				if (a[cur] == 0) {
					cur++;
				}
			}
		}
	}

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cout << res[i][j] << ' ';
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

int main() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];

    sort(ALL(a), greater<ll>());

    ll d = INF, r = 1;
    rep(i, 1, n){
        if(d > abs(a[0]-2*a[i])) r = a[i], d = abs(a[0]-2*a[i]);
    }
    co(a[0] << " " << r);

    return 0;
}


Measured memory_bytes: 1152
n = int(input())
s = input()
mod = 10**9+7

dp = [0] * (n+1)
dp[0] = 1

for i in range(n):
    next = [0] * (n+1)
    for j in range(n):
        if(j==0):
            next[0] += dp[0]
            next[0] %= mod
            next[1] += dp[0]*2
            next[1] %= mod
        else:
            next[j-1] += dp[j]
            next[j-1] %= mod
            next[j+1] += dp[j]*2
            next[j+1] %= mod
    dp = next[::]

ans = dp[len(s)] * pow(pow(2,mod-2,mod),len(s),mod)
ans %= mod
print(ans)

Measured memory_bytes: 76436
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, K = gets_i_list
p_list = gets_i_list

e_list = p_list.map do |p|
  (p + 1) * 0.5
end

sum_list = [0]
(0...N).each do |i|
  sum_list[i+1] = sum_list[i] + e_list[i]
end

max = 0
0.upto(N - K) do |i|
  total = sum_list[i+K] - sum_list[i]
  max  = [max, total].max
end
puts sprintf("%.12f", max)


Measured memory_bytes: 23108
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	while (true) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0)
			break;
		if (x > y)
			swap(x, y);
		cout << x << " " << y << endl;
	}
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;

void solve()
{	
	int n; cin >> n;
	vector<int> l(2*n);
	rep(i, 2*n) cin >> l[i];
	sort(all(l),greater<int>());
	int ans = 0;
	rep(i, n)ans += l[2*i+1];
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);++i)
#include <algorithm>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    int l;
    l = s.length();
    //cout << l << endl;
    int ans = 0;
    rep(i,l){
        if(s[i] != t[i]) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
const int maxx=1e5+2;
typedef long long ll;
int main(){
    string str; cin>>str;
    int ans=0,f=0;
    for(int i=0;i<str.size();i++){
        if(i>0){
            if(str[i]==str[i-1]&&(!f)){
                if(i+1<str.size()){
                    ans++;
                    i++;
                    f=1;
                }
            }else{
                ans++;
                f=0;
            }
        }else{
            ans++;
            f=0;
        }
        //cout<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
a, b, c, d = map(int, input().split())
if c% b == 0:
    aoMake = (c//b)*2-1
else:
    aoMake = ((c//b)+1)*2-1

if a%d == 0:
    takaMake = (a//d)*2
else:
    takaMake = ((a//d)+1)*2

if takaMake > aoMake:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    map<char, int> ans;
    for(char c = 'a'; c <= 'z'; c++){
        ans[c] = 50;
    }

    rep(i, n){
        string s;
        cin >> s;
        map<char, int> cnt;
        for(char c = 'a'; c <= 'z'; c++){
            cnt[c] = 0;
        }
        rep(j, (int)s.size()){
            cnt[s[j]]++;
        }
        for(auto itr = cnt.begin(); itr != cnt.end(); itr++){
            ans[itr->first] = min(ans[itr->first], itr->second);
        }
    }

    for(auto itr = ans.begin(); itr != ans.end(); itr++){
        rep(i, itr->second) cout << itr->first;
    }
    cout << endl;
    
}

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

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


int main(){
 
  int N ;
  cin >> N ;
  
  vector<int> W(N) ;
  
  rep (i,N){
   cin >> W.at(i) ;
  }//ここまで入力
  
  int a = 1000 ;//最終値
  
  int s = accumulate(W.begin() , W.end() , 0);
 
  
  rep (i,N){
   int p = 0;
   int j = 0;
    
    while (j <= i){
     p = p + W.at(j); 
      
      j++;
    }
    
    int q = s - p;
     
    
    if (p <= q){
      a = min (a, q-p);
     }else{
      a = min (a, p-q) ;
    }
 
  }
  
  cout << a << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int m=scanner.nextInt();
        int l=scanner.nextInt();
        long a[][]=new long[n][m];
        long b[][]=new long[m][l];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                a[i][j]=scanner.nextInt();
            }
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<l;j++){
                b[i][j]=scanner.nextInt();
            }
        }
        long c[][]=new long[n][l];
        for(int i=0;i<n;i++){
            for(int j=0;j<l;j++){
                long result=0;
                for(int k=0;k<m;k++){
                    result+=a[i][k]*b[k][j];
                }
                c[i][j]=result;
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<l;j++){
                System.out.print(c[i][j]);
                if(j!=l-1){
                    System.out.print(" ");
                }else{
                    System.out.println();
                }
            }
        }

    }

}



Measured memory_bytes: 53656
s=input()
t=input()
b=list()
for x in range(len(s)-len(t)+1):
    a=0
    for y in range(len(t)):
        #print(s[x+y],t[y],s[x+y]==t[y])
        if s[x+y]==t[y]:
            a+=1
    b.append(a)
print(len(t)-max(b))

Measured memory_bytes: 9016
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

	ll N , A , B;
	cin >> N >> A >> B ;

	cout << min(A,B) << " " << max(A+B-N, 0LL) << endl;

	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/**
 *    author:  [itmo] enot.1.10
 *    created: 01.10.2016 14:59:57       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

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

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 2e5 + 10;

char s[N];

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    scanf("%s", s);
    int res =0;
    int n = strlen(s);
    int bal =0;
    forn(i, n)
    {
        if (s[i] == 'T') bal++;
        else bal--;
        res = max(res, bal * 2);
    }
    printf("%d\n", res);
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


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

int main() {
	long long h,w;
	cin >> h >> w;
	long long k1 = (h * w) / 2;
	long long k2 = (h * w) % 2;
	long long k = k1 + k2;
	if(h == 1 || w == 1)
	{
		k = 1;
	}
	cout << k << endl;
	return 0;
}

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

int N;
char S[100000];

int main() {
    string str;
    cin >> str;
    N = str.size();
    for (int i = 0; i < N; ++i) {
        if (str[i] == '0') {
            S[i] = 0;
        }
        else {
            S[i] = 1;
        }
    }
    int L2R;
    {
        int contL2R[100000];
        int prv = -1;
        int streak;
        for (int i = N - 1; i >= 0; --i) {
            if (S[i] == prv) {
                ++streak;
                contL2R[i] = streak;
            }
            else {
                contL2R[i] = streak = 1;
                prv = S[i];
            }
        }
        int a = 0;
        bool even = false;
        for (int i = 0; i < N; ) {
            a += contL2R[i] / 2;
            if (contL2R[i] % 2 != 0) {
                if (even) {
                    ++a;
                }
            }
            else {
                even = !even;
            }
            i += contL2R[i];
        }
        L2R = a;
    }
    int R2L;
    {
        int contR2L[100000];
        int prv = -1;
        int streak;
        for (int i = 0; i < N; ++i) {
            if (S[i] == prv) {
                ++streak;
                contR2L[i] = streak;
            }
            else {
                contR2L[i] = streak = 1;
                prv = S[i];
            }
        }
        int a = 0;
        bool even = false;
        for (int i = N-1; i >= 0; ) {
            a += contR2L[i] / 2;
            if (contR2L[i] % 2 != 0) {
                if (even) {
                    ++a;
                }
            }
            else {
                even = !even;
            }
            i -= contR2L[i];
        }
        R2L = a;
    }
    int ans = min(L2R, R2L);
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
// #define MULTIPLE_TEST_CASE
void solution() {
  int n;
  cin >> n;
  int v[n];
  int x = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    x ^= v[i];
  }
  for (int i = 0; i < n; i++) {
    cout << (x ^ v[i]) << " ";
  }
  cout << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 5216
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

ll a, b, k;

int main() {
    fastio();

    cin >> a >> b >> k;

    if (a >= k) {
        cout << a - k << " " << b << endl;
    } else {
        cout << 0 << " " << max(0LL, b - (k - a)) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define INF 1e18
using namespace std;
int n,a[3001],dp[3001][3001];
int Dp_Rec(int L, int R)
{
    if(dp[L][R]) return dp[L][R];
    if(L == R) return dp[L][R] = a[L];
    if(L > R) return dp[L][R] = INF;
    return dp[L][R] = max(a[R] - Dp_Rec(L,R-1),a[L] - Dp_Rec(L+1,R));
}
main()
{
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> a[i];
    cout << Dp_Rec(1,n);
}

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

int N,M;
vector<int> a;

int main() {
    cin>>N>>M;
    a.resize(N);
    int sum=0;
    for (int i=0; i<N; i++) {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    string ans;
    if ((double)a[M-1]>=(double)sum/(4*M)) ans="Yes";
    else ans="No";
    cout<<ans<<endl;
    return 0;
}
//next_permutation


Measured memory_bytes: 256
n = int(input())
ss = []
cnt = 0

# for _ in range(n):
#     ss.append(input())

# for i, s1 in enumerate(ss[0:n-2+1]):
#     for s2 in ss[i + 1:n-1+1]:
#         # print(s1, s2)
#         if sorted(s1) == sorted(s2):
#             cnt += 1

for _ in range(n):
    ss.append(input())

map = {}
for s in ss:
    sorted_s = ''.join(sorted(s))
    if sorted_s in map.keys():
        map[sorted_s] += 1
    else:
        map[sorted_s] = 1


# map = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
# map = {'a': 10 ** 5}  # maxテスト
# print(map)

# あとはxC2の組み合わせの総数を求めれば良い


for n in map.values():
    if n > 1:
        # cnt += factorial(n) // (2 * factorial(n-2))
        cnt += (n * (n - 1)) // 2
    # print(n)
    # print(cnt)

print(cnt)

Measured memory_bytes: 24988
#include <stdio.h>
#include <math.h>

int main(void)
{
  int i, k, count = 0;
  char s[101];
  
  scanf("%d", &k);
  
  scanf("%s", s);
  
  for( i = 0; i < 100; i++ ){
      if( s[i] == '\0' ){
          break;
      }
      count++;
  }
  
  if( count <= k ){
      printf("%s\n", s);
      return 0;
  }
  
  //printf("count = %d\n", count);
  for( i = 0; i < k; i++ ){
    printf("%c", s[i]);
  }
  
  printf("...");
  return 0;
}

Measured memory_bytes: 1712
//Gvs Akhil (Vicennial)
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ld(a) while(a--)
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define tcf(v,i) for(auto i : v)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator
#define INF 		0x3f3f3f3f
#define LLINF       1000111000111000111LL
#define PI 			3.14159265358979323
#define endl '\n'
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N=1000006;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<ii,vii,greater<ii> > spq;
const ll MOD=1000000007LL;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
int32_t main(){
	int a,b; cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0){
		cout<<"Possible";
	}
	else cout<<"Impossible";
}



Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>

using namespace::std;

int main(){

	int w;
	int n;
	int i;
	int a;
	int b;
	int number[32] = {};

	scanf("%d", &w);
	scanf("%d", &n);

	for (i = 1; i <= w; i++){
		number[i] = i;
	}

	for (i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);
		swap(number[a], number[b]);
	}
	for (i = 1; i <= w; i++){
		cout << number[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
inline int in() {int x; cin>>x; return x;}
const int MX = 2005;

int main() {
  int n = in(), x = in()-1, y = in()-1;
  vector<int> ans(n);
  FOR(j,0,n) {
    vector<int> dist(n, MX);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != MX) return;
      dist[v] = d;
      q.push(v);
    };
    push(j, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist[v] + 1;
      if (v-1 >= 0) push(v-1, d);
      if (v+1 < n) push(v+1, d);
      if (v==x || v==y) push(x+y-v, d);
    }
    FOR(i,0,n) ans[dist[i]]++;
  }
  FOR(i,1,n) cout << ans[i]/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

int main() {
    string s;
    cin >> s;
    if(s == "A") {
        cout << "T" << endl;
    } else if(s == "T") {
        cout << "A" << endl;
    } else if(s == "C") {
        cout << "G" << endl;
    } else {
        cout << "C" << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 200000
#define N 262144
#define INF 0x3FFFFFFF
#define mp make_pair
#define tp pq.top()
#define F first
#define S second 
int t[N*2+5],t1[N*2+5],t2[N*2+5],p[MN+5];
priority_queue< pair< pair<int,int>,pair<int,int> > > pq;
void build(int*t){for(int i=N;--i;)t[i]=min(t[i<<1],t[i<<1|1]);}
int query(int*t,int l,int r)
{
	int res=INF;
	for(l+=N-1,r+=N+1;l^r^1;l>>=1,r>>=1)
	{
		if(~l&1)res=min(res,t[l+1]);
		if( r&1)res=min(res,t[r-1]);
	}
	return res;
}
void push(int l,int r)
{
	if(l>r)return;
	int x=query(l&1?t1:t2,l,r),y=query(l&1?t2:t1,p[x]+1,r);
	pq.push(mp(mp(-x,y),mp(l,r)));
}
int main()
{
	int n=read(),i,x,y,l,r;
	for(i=1;i<=n;++i)
	{
		p[x=read()]=i;
		t[i+N]=x;t1[i+N]=i&1?x:INF;t2[i+N]=i&1?INF:x;
	}
	build(t);build(t1);build(t2);push(1,n);
	while(!pq.empty())
	{
		x=-tp.F.F;y=tp.F.S;l=tp.S.F;r=tp.S.S;
		printf("%d %d ",x,y);pq.pop();
		push(l,p[x]-1);push(p[x]+1,p[y]-1);push(p[y]+1,r);
	}
}

Measured memory_bytes: 8948
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <sstream>
#pragma comment(linker, "/STACK:256000000")
using namespace std;

#define in(s) freopen(s, "r", stdin)
#define out(s) freopen(s, "w", stdout)
#define forn(i, n) for (int i = 0; i < n; i++)
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef long double ld;

const int MAXN = 55;
ll dp[MAXN][(1 << 20) + 5];
int path[MAXN];


vector < vector< pair<int, int> > > g;

vector <int> cp, cab;

void dfs(int v, int p, int t) {
	if (v == t) {
		cab = cp;
		return;
	}
	forn(i, (int)g[v].size()) {
		int to = g[v][i].first, num = g[v][i].second;
		if (to == p)
			continue;
		cp.push_back(num);
		dfs(to, v, t);
		cp.pop_back();
	}
}

int main()
{
	//in("input.txt");
	//out("output.txt");
	srand(1373737);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, a, b;
	cin >> n;

	g.resize(n);
	forn(i, n - 1) {
		cin >> a >> b;
		a--; b--;
		g[a].push_back(mp(b, i));
		g[b].push_back(mp(a, i));
	}

	int m;
	cin >> m;

	forn(i, m) {
		cin >> a >> b;
		a--; b--;
		dfs(a, -1, b);

		forn(j, (int)cab.size())
			path[cab[j]] |= (1 << i);
	}

	dp[0][0] = 1ll;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (1 << m); j++) {
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j | path[i]] += dp[i][j];
		}
	}
	cout << dp[n - 1][(1 << m) - 1];

	return 0;
}

Measured memory_bytes: 411904
#!/usr/bin/env pypy3

import itertools


def summarize_dists(n, x, y):
    if x > y:
        x, y = y, x
    # notice: ignore table[0]
    table = [0 for _ in range(n)]
    for i, j in itertools.combinations(range(n), 2):
        if i <= x and y <= j:
            dist = x - i + 1 + j - y
        elif i <= x:
            dist = x - i + min(j - x, 1 + y - j)
        elif y <= j:
            dist = min(i - x + 1, y - i) + j - y
        else:
            dist = min(j - i, i - x + 1 + y - j)
        table[dist] += 1
    return table


def main():
    n, x0, y0 = (int(z) for z in input().split())
    x = x0 - 1
    y = y0 - 1
    table = summarize_dists(n, x, y)
    print(*table[1:], sep="\n")


if __name__ == "__main__":
    main()


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

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

    int n;
    cin >> n;

    if (n == 1) {
        cout << 1 << '\n';
        return 0;
    }

    int ans[6] = {2, 4, 8, 16, 32, 64};
    int index = lower_bound(ans, ans + 6, n + 1) - ans;
    cout << ans[index - 1] << '\n';
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;
import std.algorithm, std.container, std.datetime, std.typecons;

class LowLink {
	int n;
	int[][] g;
	int[] ord, low, root, cmp, used;
	this(int nn) {
		n = nn;
		g.length = ord.length = low.length = used.length = n;
		cmp.length = root.length = n;
	}

	void addEdge(int x, int y) {
		g[x] ~= y;
		g[y] ~= x;
	}

	int k;
	void dfs(int u, int b) {
		used[u] = 1;
		low[u] = ord[u] = k;
		k++;
		foreach (v; g[u]) {
			if (v == b) continue;
			if (!used[v]) {
				dfs(v, u);
				low[u] = min(low[u], low[v]);
			} else {
				low[u] = min(low[u], ord[v]);
			}
		}
	}

	int mc;
	void dfs2(int u, int d) {
		used[u] = 2;
		cmp[u] = d;
		//mc = max(mc, d);
		foreach (v; g[u]) {
			if (used[v] == 2) continue;
			if (ord[u] < low[v]) {
				mc++;
				dfs2(v, mc-1);
			} else {
				dfs2(v, d);
			}
		}
	}

	void exec() {
		k = mc = 0;
		//int c = 0;
		foreach (i; 0..n) {
			if (!used[i]) {
				dfs(i, -1);
				mc++;
				dfs2(i, mc-1);
				//c = mc+1;
			}
		}
	}
}

int main() {
	int v, e;
	readf("%d %d\n", &v, &e);
	auto ll = new LowLink(v);
	alias Tuple!(int, int) P;
	P[] g;
	foreach (i; 0..e) {
		int a, b;
		readf("%d %d\n", &a, &b);
		if (a > b) swap(a, b);
		ll.addEdge(a, b);
		g ~= P(a, b);
	}
	ll.exec();
	P[] res;
	foreach (p; g) {
		if (ll.cmp[p[0]] != ll.cmp[p[1]]) {
			res ~= p;
		}
	}
	res.sort!((a, b) => a[0] != b[0] ? a[0] < b[0] : a[1] < b[1]);
	foreach (p; res) {
		writeln(p[0], " ", p[1]);
	}
    return 0;
}

Measured memory_bytes: 4760
// Problem : E - Coprime
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
#define MAXN 1000001
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
int spf[1000001];
unordered_map<int,int>s;
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
bool chk(int x) 
{ 
    set<int> ret; 
    while (x != 1) 
    { 
	    ret.insert(spf[x]);
        x = x / spf[x]; 
    } 
    for(auto v:ret){
    	if(s.find(v)!=s.end())return false;
        s[v]=1; 
    }
    return true; 
    
} 
void solve(){
	// pp(prime.size());
	int n;
	rd(n);
	vint arr(n);
	int tot;
	FOR(i,n){
		rd(arr[i]);
		if(i==0)tot=arr[i];
		else tot=__gcd(tot,arr[i]);
	}
	// set<int>s;
	bool flag=true;
	for(int i=0;i<n;i++){
		// if(!flag)break;
		if(!chk(arr[i])){
			flag=false;
			break;
		}
		// if(!flag)break;
	}
	// for(auto v:s)pp(v);	
	if(flag)pp("pairwise coprime");
	else if(tot==1)pp("setwise coprime");
	else pp("not coprime");
	return;	
}


int32_t main() {
    // fint{
    	sieve();
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 18732
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int W,H,n;
vector<int> number;

int solve = 0;

struct Rect{
	int x1,y1,x2,y2; 
	Rect(int a,int b,int c,int d){x1 = a , y1 = b , x2 = c, y2 = d;};
};
vector< vector<Rect> > data(15);
vector< vector<int> > output(10,vector<int>(10));
vector< vector<int> > bt(10,vector<int>(10));

void dfs(int pos){
	if(solve > 2)return;

	if(pos == n){
		output = bt;
		solve++;
		return;
	}
	vector< vector<int> > prev = bt;
	
	rep(i,data[pos].size()){
		Rect t = data[pos][i];
		bool flag = true;
		for(int i=t.y1;i<=t.y2;i++){
			for(int j=t.x1;j<=t.x2;j++){
				if(bt[i][j] != -1){
					flag = false;
				}
				bt[i][j] = pos;
			}
		}
		if(flag){
			dfs(pos+1);
		}
		bt = prev;
	}
	return;
}
int main(){
	while(cin >> W >> H >> n , n){
		rep(i,10)rep(j,10)bt[i][j] = -1;
		rep(i,15)data[i].clear();
		vector<int> k(n);
		number.resize(n);
		rep(i,n)cin >> number[i] >> k[i];
		vector< vector<int> > map(H,vector<int>(W,0));
		rep(i,H)rep(j,W)cin >> map[i][j];
		rep(i,H)rep(j,W){
			for(int x=j;x<W;x++){
				for(int y=i;y<H;y++){
					int num = -1 , cnt = 0;
					bool flag = true;
					for(int X=j;X<=x;X++){
						for(int Y=i;Y<=y;Y++){
							if(map[Y][X] != 0){
								cnt++;
								num = find(number.begin(),number.end(),map[Y][X])-number.begin();
							}
						}
					}
					int tx = x-j+1, ty = y-i+1;
					if(cnt != 1 || tx * ty != k[num])continue;
					data[num].push_back(Rect(j,i,x,y));
				}
			}
		}
		solve = 0;
		dfs(0);
		if(solve == 1){
			//cout << W << " " << H << endl;
			rep(i,H){
					rep(j,W)
						cout << (j?" ":"") << number[output[i][j]];
					cout << endl;
			}
		}else{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 924
#import time
count=0
def merge(A,left,mid,right):
    global count
    L=A[left:mid]+[2**30]
    R=A[mid:right]+[2**30]

    i=0
    j=0
    for k in range(left,right):
        count+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1


def mergeSort(A,left,right):
    if left+1 < right:
        mid = int((left+right)/2)
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)


#start = time.time()

n=int(input())
s=list(map(int,input().split()))
count=0
mergeSort(s,0,n)

print(s[0],end='',sep='')
for i in range(1,n):
    print(" ",s[i],end='',sep='')
print()

print(count)

#end=time.time()-start
#end*=1000
#print ("Time:{0}".format(end) + "[m_sec]")



Measured memory_bytes: 61648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<ll,ll>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  int h,w,ans=-1;
  cin>>h>>w;
  field.resize(h);
  rep(i,h)cin>>field[i];
  vector<vector<int>> dist(h,vector<int>(w,-1));

  rep(i,h)rep(j,w){
    if(field[i][j]=='#'){
      q.push(make_pair(i,j));
    }
  }
  int dx[4]={0,0,-1,1};
  int dy[4]={1,-1,0,0};
  while(!q.empty()){
    P ab=q.front();
    int x=ab.first;
    int y=ab.second;
    q.pop();
    rep(i,4){
      int nx=x+dx[i];
      int ny=y+dy[i];
      if(nx<0||ny<0||nx>=h||ny>=w)continue;
      if(field[nx][ny]!='.')continue;
      if(field[nx][ny]!='#'&&dist[nx][ny]==-1){
      dist[nx][ny]=dist[x][y]+1;
      q.push(make_pair(nx,ny));
      ans=max(dist[nx][ny],ans);
      }
    }
  }
  cout<<ans+1<<endl;
}


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

int main() {
  int cnts[100001] = {};
  int n, q, b, c;
  long long s(0);
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    cnts[a[i]]++;
    s += a[i];
  }cin >> q;
  while (q--) {
    cin >> b >> c;
    s += (long long ) (c - b) * cnts[b];
    cnts[c] += cnts[b];
    cnts[b] = 0;
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 4364
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;
const ll inf = 1e9;

int main(){
  ll N , K; cin >> N >> K;
  vector<ll> a(N); rep(i,N) cin >> a[i];

  vector<P> b(N);
  // 初期状態
  rep(i,N){
    b[i].fi = max( ll(0) , i - a[i] );
    b[i].sc = min( N , i + a[i] + 1 );
  }
  SORT(b);
  vector<ll> t(N + 1);
  rep(i,N) t[b[i].sc]++;
  vector<ll> ans(N);
  rep(loop, K){
    if(ans[0] == N and ans[N - 1] == N){
      break;
    }
    else{
      ll cnt = 0;
      rep(i,N) ans[i] = 0;
      // ansの更新
      rep(i,N){
        cnt += POSU(b , mp(i , inf)) - POSL(b , mp(i , -inf));
        cnt -= t[i];
        ans[i] += cnt;
      }
      // 範囲の更新
      rep(i,N){
        b[i].fi = max( ll(0) , i - ans[i] );
        b[i].sc = min( N , i + ans[i] + 1 );
      }
      SORT(b);
      rep(i,N + 1) t[i] = 0;
      rep(i,N) t[b[i].sc]++;
    }
  }
  rep(i,N){
    cout << ans[i] << " ";
  }
  cout << endl;
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> bool chmax(T& t, const U& u) { if (t < u) { t = u; return 1; } return 0; }
template<class T, class U> bool chmin(T& t, const U& u) { if (t > u) { t = u; return 1; } return 0; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 200010;

V<int> g[maxn];
V<int> vs[2];

void dfs(int v, int p, int d) {
	vs[d].pb(v);
	for (int to : g[v]) {
		if (to != p) {
			dfs(to, v, d^1);
		}
	}
}

int main() {
	int N; cin >> N;
	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(0, -1, 0);

	int n1 = (N + 2) / 3;
	int n2 = (N + 1) / 3;
	int n3 = N / 3;

	if (vs[0].size() < vs[1].size()) {
		swap(vs[0], vs[1]);
	} 

	V<int> ans(N, -1);
	V<int> use(N + 1);

	if (vs[1].size() >= n2) {
		int now = 0;
		for (int i = 1; i <= N; i += 3) {
			ans[vs[0][now]] = i;
			use[i] = 1;
			now++;
		}
		now = 0;
		for (int i = 2; i <= N; i += 3) {
			ans[vs[1][now]] = i;
			use[i] = 1;
			now++;
		}
		now = 1;
		rep(i, N) {
			if (ans[i] == -1) {
				while (use[now]) {
					++now;
				}
				ans[i] = now++;
			}
		}
	} else {
		int now = 3;
		for (int v : vs[1]) {
			ans[v] = now;
			use[now] = 1;
			now += 3;
		}
		now = 1;
		rep(i, N) {
			if (ans[i] == -1) {
				while (use[now]) {
					++now;
				}
				ans[i] = now++;
			}
		}
	}

	rep(i, N) printf("%d%c", ans[i], i == N-1 ? '\n' : ' ');

	return 0;
}

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

int main(){
  string str;
  
  //空白も含めて1行まるごとを文字列として受け取るためにはgetline関数を使う
  getline(cin,str);

  
  for(int i=0;i<(int)str.size();i++){
    if( islower(str[i]) ){
      str[i]=toupper(str[i]);
    }else if( isupper(str[i]) ){
      str[i]=tolower(str[i]);
    }
  }
  cout<<str<<endl;
  
  /*
    以下は文字コードの引き算と足し算を使う例
  for(int i=0;i<(int)str.size();i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]=str[i]-'a'+'A';
    }else if('A'<=str[i]&&str[i]<='Z'){
      str[i]=str[i]-'A'+'a';
    }
  }
  */

  return 0;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(),(x).end()
#define lowbit(x) x&-x
#define pb push_back
#define ls (id<<1)
#define rs (id<<1|1)
#define Rint register int
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const int MAXN=4e5+10,MAXM=4e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int MOD=1e9+7,mod=998244353;
const int inv2=5e8+4;

int n,m;
struct Node
{
    int l,r;
    bool operator < (const Node &rhs)const
    {
        return l^rhs.l?l<rhs.l:r>rhs.r;
    }
}e[MAXN];

int ans=0;
priority_queue<int,vector<int>,greater<int> >pq;
vector<int> v;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d%d",&e[i].l,&e[i].r);
    int l=1,r=m;
    sort(e+1,e+n+1);
    for(int i=1;i<=n;i++)
    {
        pq.push(e[i].r);
        if(l<=r&&l<=e[i].l)l++;
        else v.push_back(pq.top()),pq.pop();
    }
    sort(ALL(v),greater<int>());
    for(auto j:v)if(l<=r&&r>=j)r--;
                    else ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3320
n,m=map(int,input().split())
x=sorted(list(map(int,input().split())));#print(x)

if n>=m:
  print(0)
  exit(0)
else:
  x_distance=[]
  for i in range(m-1):
    x_distance.append(x[i+1]-x[i])
  x_distance.sort();print(sum(x_distance[:m-n]))
  exit(0)

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

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//?????§??¬?´???°??¨????°???¬?????°
//O(1)?????????
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

#define NUM_MAX   1000010
bool flag[NUM_MAX];
vector< int >prm;

int N;
int ans = 0;
int K;

void eratosthenes(){
	if( N < 2 ) return;
	fill( flag, flag+NUM_MAX, 0 );
	int idx = 2;
	while( idx <= K ){
		while( flag[idx] ) idx++;
		if( idx > N ) break;
		//prm.push_back( idx );
		for( int i = idx; i <= N; i += idx ) flag[i] = 1;
		ans++;
	}
	while( idx < N ){
		idx++;
		if( !flag[idx] ){
			//prm.push_back( idx );
			ans++;
		}
	}
}


int main(){
	
	while( scanf("%d", &N) != EOF ){
		K = sqrt( N );
		K++;
		
		eratosthenes();
		
		cout<<ans<<endl;
		/*
		REP( i, prm.size() ){
			cout<<prm[i]<<endl;
		}*/
		//prm.clear();
		ans = 0;
	}	
	return 0;
	
}

Measured memory_bytes: 4200