akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <complex>
#define pb push_back
#define pll pair <ll, ll>
#define MOMI using namespace std;
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")

//#pragma GCC optimize("unroll-loops")
//#define double long double

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 3e5;

ll n, m, k;

vector <ll> ID;

void vivod(vector <ll> V){
    ll q;
    for (q = 0; q < V.size(); q++){
        cout << V[q] << " ";
    }
    cout << endl << endl;
}

vector <ll> mul(vector <ll> A, vector <ll> B){
    vector <ll> ANS;
    ANS.resize(A.size());
    ll q;
    for (q = 0; q < A.size(); q++){
        ANS[q] = A[B[q]];
    }
    return ANS;
}

vector <ll> rev(vector <ll> A){
    vector <ll> ANS;
    ANS.resize(A.size());
    ll q;
    for (q = 0; q < A.size(); q++){
        ANS[A[q]] = q;
    }
    return ANS;
}

vector <ll> step(vector <ll> A, ll x){
    if (x == 0){
        return ID;
    }
    if (x % 2 == 1){
        return mul(step(A, x - 1), A);
    }
    vector <ll> T = step(A, x / 2);
    return mul(T, T);
}

int main(){
    ll q, w, e, t, a, b, c;
    cin >> n >> k;
    vector <ll> P, Q;
    ID.resize(n);
    for (q = 0; q < n; q++){
        ID[q] = q;
    }
    P.resize(n); Q.resize(n);
    for (q = 0; q < n; q++){
        cin >> P[q];
        P[q]--;
    }
    for (q = 0; q < n; q++){
        cin >> Q[q];
        Q[q]--;
    }
    k--;
//    vivod(P);vivod(Q);
    vector <ll> W = mul(mul(Q, rev(P)), mul(rev(Q), P));
//    vivod(W);
//    vector <ll> A = mul(mul(P, step(W, (k) / 6)), rev(P)); /// 0, 6, 12, 18, 24
//    vector <ll> B = mul(mul(Q, step(W, (k) / 6)), rev(Q)); /// 1, 7, 13, 19, 25;
    vector <ll> A = mul(step(W, (k) / 6), mul(P, rev(step(W, k / 6))));
    vector <ll> B = mul(step(W, (k) / 6), mul(Q, rev(step(W, k / 6))));
//    cout << "A " << endl; vivod(A);
//    cout << "B " << endl; vivod(B);
    if (k % 6 == 0){
        for (q = 0; q < n; q++){
            cout << A[q] + 1 << " ";
        }
        return 0;
    }
    ll i = (k / 6) * 6 + 1;
    for (;i < k; i++){
        vector <ll> C;
        C.resize(n);
        for (q = 0; q < n; q++){
            C[A[q]] = B[q];
        }
//        vivod(C);
        A = B;
        B = C;
    }
    for (q = 0; q < n; q++){
        cout << B[q] + 1 << " ";
    }
    return 0;
}


Measured memory_bytes: 56776
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    unordered_map<string, int> m;

    rep(i, n) {
        string s;
        cin >> s;
        sort(all(s));
        m[s] += 1;
    }

    int64 ans = 0;
    for (auto it = m.begin(); it != m.end(); ++it) {
        int64 x = it->second;
        ans += x * (x - 1) / 2;
    }

    print(ans);

    return 0;
}



Measured memory_bytes: 10660
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define pii pair<int, int>
#define pt(xx) cout << "\n" \
                    << xx << "\n"
#define debugv(x)               \
    cout << "\n"                   \
         << #x << ": ";            \
    rep(i, x.size()) cout << x[i] << " "; \
    cout << endl
#define debug2d(x)            \
    cout << "\n"                    \
         << #x << " is: \n";        \
    rep(i,x.size())     \
    {                               \
        rep(j,x[0].size()) \
        {                           \
            cout << x[i][j] << " "; \
        }                           \
        cout << endl;               \
    }
#define nl cout << endl

#define MOD 1000000007
using namespace std;

int N, M, K;
int Q;
int ans = 0;

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

    vector<int> p(n);
    rep(i,n)cin>>p[i];


int    cnt = 0;
    int a,b;
    for (int i = 1; i<n-1;++i){
        a = p[i-1];
        b = p[i+1];
        if (min(a,b)<p[i] && max(a,b)>p[i])
        cnt++;
    }

cout<<cnt<<endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main(void)
{
    std::vector<int> primes = {2};
    int k, max_prime = 2;

    std::cin >> k;

    for (int i = 3; max_prime < k; i+=2)
    {
        primes.emplace_back(i);

        for (int p : primes)
        {
            if (p * p > i) break;

            if (i % p == 0)
            {
                primes.pop_back();
                break;
            }
        }

        max_prime = primes.back();
    }

    std::cout << max_prime << '\n';

    return 0;
}


Measured memory_bytes: 384
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.toLowerCase().split( "\n" );
  var w = data[0];
  
  var cnt = 0;
  for( var i=1; i<data.length; i++ ) {
    var t = data[i].split( ' ' );
    for( var j=0; j<t.length; j++ ) {
      if( w == t[j] ) {
        cnt++;  
      }
    }
  }
  console.log( cnt );
});

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

int main()
{
    int A, B;
    cin >> A >> B;

    int a, b, c;
    a = A + B;
    b = A - B;
    c = A * B;
    int min = a;

    if (a <= b || a <= c)
    {
        min = b;
        if (b <= c)
        {
            min = c;
        }
    }

    cout << min << endl;
    return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
int a[maxn];
int b[maxn];
void run_case()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i];
    }
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    int ans = 0;
    if (n & 1)
    {
        int l = a[n / 2 + 1];
        int r = b[n / 2 + 1];
        ans = r - l + 1;
    }
    else
    {
        int l = a[n / 2] + a[n / 2 + 1];
        int r = b[n / 2] + b[n / 2 + 1];
        ans = r - l + 1;
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 5200
// https://kenkoooo.com/atcoder/#/contest/show/a9a7a4e2-047d-4784-8e13-668951991a1d からきました
// ふたつ先までのdfsでいいので間に合いそう
// 1をスタートにして隣接してるノードから更にひとつだけ伸ばし、Nかどうかみるだけ
package main
import "fmt"
var n, m int
var graph [][]int
func main(){
	fmt.Scan(&n, &m)
	graph = make([][]int, n)
	for i:=0; i<n; i++{
		graph[i] = []int{}
	}
	for i:=0; i<m; i++{
		var a, b int
		fmt.Scan(&a, &b)
		graph[a-1] = append(graph[a-1], b-1)
		graph[b-1] = append(graph[b-1], a-1)
	}
	for _, relayPoint := range graph[0]{
		for _, goal := range graph[relayPoint]{
			if goal == n-1{
				fmt.Println("POSSIBLE")
				return
			}
		}
	}
	fmt.Println("IMPOSSIBLE")
}

Measured memory_bytes: 16768
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
//#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int n, m, k;
int a[15][1055];

int getCount(int x1, int y1, int x2, int y2){
	int ans = a[x2][y2];
	if(x1)
		ans -= a[x1-1][y2];
	if(y1)
		ans -= a[x2][y1-1];
	if(x1 && y1)
		ans += a[x1-1][y1-1];
	return ans;
}


int32_t main(){
	cin >> n >> m >> k;
	char c;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> c;
			if(c == '1')
				a[i][j] = 1;
			else
				a[i][j] = 0;
		}
	}
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(i)
				a[i][j] += a[i-1][j];
			if(j)
				a[i][j] += a[i][j-1];
			if(i && j){
				a[i][j] -= a[i-1][j-1];
			}
		}
	}
	if(getCount(0,0,n-1,m-1) <= k){
		cout << 0;
		return 0;
	}
	int ans = 1e9;
	for(int i = 0; i < (1<<(n-1)); i++){
		vector<int> v;
		v.push_back(0);
		for(int j = 0; j < (n-1); j++){
			if(i&(1<<j))
				v.push_back(j+1);
		}
		v.push_back(n);
		int prev = -1;
		int cnt = 0;
		int flag = 0;
		for(int j = 0; j < m; j++){
			for(int l = 0; l < (int)v.size()-1; l++){
				if(getCount(v[l],prev+1,v[l+1]-1,j) > k){
					if(j == prev+1)
						flag = 1;
					cnt++;
					prev = j-1;
					break;
				}
			}
		}
		if(flag)
			continue;
		ans = min(ans,(int)v.size() - 2 + cnt);
		
	}
	cout << ans << endl;
	

	return 0;
}



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

int main(void){
	int A;
	cin >> A;
	int B;
	cin >> B;
	int C;
	cin >> C;
	int X;
	cin >> X;	
	int ans;
	for(int i = A;i>=0;i--){
	for(int j = B;j>=0;j--){
	for(int k = C;k>=0;k--){
	if(i*500+j*100+k*50==X){ans++;}
	}
	}
	}
	cout << ans<< endl;	
 return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, M; double sum = 0;
  cin >> N >> M;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a+N, greater<int>());
  if(a[M-1] < sum / (4*M)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//



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

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    ll n, k, s;
    cin >> n >> k >> s;
    ll s_size = n - (k-1);
    vector<ll> a(s_size);
    if(s_size <= s && k != 0){
        rep(i, s_size){
            if(i == s_size-1){
                a[i] = s / s_size + s % s_size;
            }else{
                a[i] = s / s_size;
            }
        }
    }else{
        rep(i, k){
            if(i)cout << " ";
            cout << s;
        }
        rep(i, n-k){
            cout << " ";
            if(s < 1e9)
                cout << s+1;
            else
                cout << s-1;
        }
        cout << endl;
        return 0;
    }
 
    int now = 0;
    rep(i, n){
        if(i) cout << " ";
        cout << a[now];
        now++;
        if(now == s_size) now = 0;
    }
    cout << endl;
    
    
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main(){
  int n,a;
  cin >> n;
  cin >> a;
  bool s=false;
  n%=500;
  for(int i=0;i<=a;i++){
    if(i==n){
      s=true;
    }
  }

  if(s==true){
    cout << "Yes";
  }else{
    cout << "No";
  }


}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void) {
	long long n, a, b, sum=0;
	scanf("%lld %lld %lld", &n, &a, &b);
	sum+=(n/(a+b))*a;
	n%=a+b;
	if(n<a)
		sum+=n;
	else
		sum+=a;
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as C
f s
  | even n && t == u = n
  | otherwise = f (C.init s) 
  where 
    n = C.length s
    (t,u) = C.splitAt (n`div`2) s
main = do
  s <- getLine
  print $ f (C.init $ C.pack s)

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

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

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

int n;
const int maxn = 2e5 + 5;
ll a[maxn];

map<ll, int> cnt;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    cnt[0] = 1;
    ll sum = 0;
    ll ans = 0;
    for(int i = 1;i <= n;i++){
        sum += a[i];
        ans += cnt[sum];
        cnt[sum]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14336
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

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

int func(int N)
{
        if (N < 10)
                return N;
        return func(N / 10) + N % 10;
}

int main()
{
        int N, A, B, ans = 0;
        cin >> N;
        int tmp = func(N);

        if (N % tmp == 0)
                puts("Yes");
        else
        {
                puts("No");
        }

        return 0;
}


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


int main() {
    int N; cin >> N;
    int max = 0;
    int sec_max = 0;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (max < A[i]) {
            max = A[i];
        } else if (sec_max < A[i]) {
            sec_max = A[i];
        }
    }

    for (int i = 0; i < N; i++) {
        if (max == A[i]) {
            cout << sec_max << endl;
        } else {
            cout << max << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007



int main(){
  ll k,a,b;
  cin >> k >> a >>b;
  ll res =0,ans=0,div=0;
  if(a+1>=b){
    ans=k+1;
  }else if(k<=a){
    ans=k+1;
  }else{
    div=(k-a+1)/2;
    ans=b+(div-1)*(b-a)+(k-(a-1)-div*2);
  }
  cout << ans <<endl;
}


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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<unordered_map<char, vector<int>>> dict(n);

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            dict[i][s[j]].push_back(j - i);
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (s[i] == s[j]) continue;
            int dist = j - i;
            int r = (int)'R' + (int)'G' + (int)'B' - (int)s[i] - (int)s[j];
            auto it = lower_bound(dict[j][r].begin(), dict[j][r].end(), dist);
            if (it != dict[j][r].end() && *it == dist) {
                ans += dict[j][r].size() - 1;
            } else {
                ans += dict[j][r].size();
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 51904
//https://atcoder.jp/contests/aising2019/tasks/aising2019_a
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main(){
    int R,C,N;
    cin>>N>>R>>C;
    cout<<(N-R+1)*(N-C+1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
const int N = 2e6 + 5 ;
int a[N] ;
signed main(){
	int n; 
	cin >> n; 
	n = 2*n ;
	f(n) cin >> a[i] ; 
	sort(a+1 , a+n+1) ;
	int ans = 0 ; 
	for ( int i =1 ;i<=n ;i++){
		if( i & 1) ans += a[i] ; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

int main() {
	ll N;cin >> N;ll p;
	vector<ll>a(N);
	for (int i = 0;i < N;i++) cin >> a[i];
	ll sum = 0;
	sort(all(a));
	ll poi = 1;
	for (int i = 1;i < N;i++) {
		if (a[i] == a[i - 1]) {
			poi++;
		}
		else {
			if (a[i - 1] <= poi)sum += (poi - a[i - 1]);
			else sum += poi;
			poi = 1;
		}
	}
	if (a[N - 1] <= poi)sum += (poi- a[N - 1]);
	else sum += poi;
	poi = 0;
	cout << sum << endl;
}

Measured memory_bytes: 1024
/*****And nothing else matters!******/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.1415926535
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define llu unsigned long long
#define setbits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define tc int test_case; cin >> test_case; while(test_case--)
#define f(i,a,n) for(int i = a ; i < n ; i++)
#define rf(i,n,a) for(int i = n-1 ; i >= a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define sp(x) fixed << setprecision(10) << x
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
const int N = 2e5 + 10;

int main()
{
    fast;
    int n;
    cin >> n;
    bool ok = false;
    while(n)
    {
        if(n % 10 == 7)
            ok = true;
        n /= 10;
    }
    ok ? cout << "Yes" : cout << "No";
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a+b+c-maxValue(a,b,c)==maxValue(a,b,c)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
  public static int maxValue(int a,int b,int c){
    int max = a;
    if(max<b) max = b;
    if(max<c) max = c;
    return max;
  }
}

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

int main(){
    char s[3][3];
    int i,j;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            cin >> s[i][j];
        }
    }
    for(i=0;i<3;i++){
        cout << s[i][i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

using namespace std;

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

int main(){
    int N;
    cin>>N;
    long long x[50],y[50];
    map<pair<int,int>,long long> m;
    rep(i,0,N)cin>>x[i]>>y[i];

    long long ans=0;
    rep(i,0,N){
        rep(j,0,N){
            if(i==j)continue;
            m[MP(x[i]-x[j],y[i]-y[j])]++;
            ans=max(ans,m[MP(x[i]-x[j],y[i]-y[j])]);
        }
    }

    cout<<N-ans;

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto& e : a) cin >> e;
	int counter = -1;
	bool isDividable = true;
	while(isDividable){
		for(auto& e : a){
			if( e == 0 ) isDividable = false;
			if( e%2 == 0 ){
				e /= 2;
			}else{
				isDividable = false;
			}
		}
		counter++;
	}
	cout << counter << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC117C - Streamline
  // Xをソートして、次の値までの差分（差の絶対値）の数列を求めておく
  // 10, 12, 1, 2, 14　→　1, 2, 10, 12, 14（ソート）
  // 1, 8, 2, 2（差分：M-1個ある）
  // この中からN-1個分の移動はしなくてもよい（コマが2個なら1個分は移動不要）
  // 移動の最小値を求めるので、プライオリティキューで最小値を((M-1)-(N-1))個分popして足す
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  REP(i, M){
    cin >> X.at(i);
  }
  sort(X.begin(), X.end());
  priority_queue<int, vector<int>, greater<int> > D;
  REP(i, M-1){
    D.push(X.at(i+1)-X.at(i));
  }
  int ans = 0;
  REP(i, (M-1)-(N-1)){
    ans += D.top();
    D.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 1276
from collections import deque

h, w = map(int, input().split())
white = 0
s = []
for i in range(h):
    line = list(input())
    white += len([j for j in line if j == '.'])
    s.append(line)

Q = deque([[0, 0]])
stamp = [[0]*w for _ in range(h)]

while Q:
    row, col = Q.popleft()
    for i, j in [[0, -1], [1, 0], [0, 1], [-1, 0]]:
        new_row, new_col = row+i, col+j
        if new_row < 0 or new_row >= h or new_col < 0 or new_col >= w:
            continue
        if s[new_row][new_col] == '#' or stamp[new_row][new_col] > 0:
            continue
        stamp[new_row][new_col] = stamp[row][col] + 1
        Q.append([new_row, new_col])

if stamp[-1][-1] == 0:
    print(-1)
else:
    print(white - stamp[-1][-1] - 1)

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

int main(void) {
  int n;
  cin >> n;
  int a[n];
  rep (i, n) cin >> a[i];

  sort(a, a + n);

  int _max = a[n - 1];

  int gole = (a[n - 1] % 2 == 0 ? a[n - 1] / 2 : a[n - 1] / 2 + 1);

  int nowId = a[0], nowD = 1001001001;
  for (int i = 0; i < n - 1; i++) {
    
    if (abs(gole - a[i]) < nowD) {
      nowD = abs(gole - a[i]);
      nowId = a[i];
    }
    
  }
  cout << _max << " " << nowId << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

    int a, min, max;
    long long sum = 0;

    for (int i = 0; i < n; i++) {
        cin >> a;
        if (i == 0) {
            min = a;
            max = a;
        }
        if (a > max) {
            max = a;
        }
        if (a < min) {
            min = a;
        }
        sum += a;
    }

    cout << min << " " << max << " " << sum << endl;

    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s;
ll ans;
int main(void){
	cin>>s;
	for(int i=1;i<s.size();i++){
		if(s[i-1]!=s[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 512
class C
	attr_reader :x,:y
	def initialize(x,y)
		@x, @y = x,y
	end
end

def func(x,y,goal,list,count)
	cost1 = 0
	cost2 = 0
	if x==goal.x&&y==goal.y
		return count
	else
		if x+1<=goal.x && list[x+1][y]==0 
		    cost1 = func(x+1,y,goal,list,1)
		end
		if y+1<=goal.y && list[x][y+1]==0 
			cost2 = func(x,y+1,goal,list,1)
		end
		return (cost1+cost2)
	end
end

ans = Array.new
loop do
	n = gets.split.map(&:to_i)
	if n[0]==0&&n[1]==0
		break
	end
	goal = C.new(n[0],n[1])
	list = Array.new(goal.x+1)
	(goal.x).times do |l|
		list[l+1] = Array.new(goal.y+1){0}
	end
	t = gets.to_i
	t.times do
		x,y = gets.split.map(&:to_i)
		list[x][y] = 1
	end
	ans.push(func(1,1,goal,list,0))
end

ans.each do |v|
	puts v
end

Measured memory_bytes: 8736
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
int main()
{
	int a,b,c,x,ans=0;cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(500*i+100*j+50*k==x)ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#ifdef __LOCAL_DEBUG__
# define _debug(fmt, ...) fprintf(stderr, "\033[94m%s: " fmt "\n\033[0m", \
    __func__, ##__VA_ARGS__)
#else 
# define _debug(...) ((void) 0)
#endif
#define rep(i, n) for (int i=0; i<(n); i++)
#define Rep(i, n) for (int i=1; i<=(n); i++)
#define range(x) (x).begin(), (x).end()
typedef long long LL;
typedef unsigned long long ULL;


vector<string> val;

bool check(string lhs, string rhs) {
  LL sl = accumulate(range(lhs), 0) - lhs.size() * '0';
  LL sr = accumulate(range(rhs), 0) - rhs.size() * '0';
  LL vl = stoll(lhs), vr = stoll(rhs);
  return vl * sr <= sl * vr;
}

int main() {
  vector<string> arr;
  for (int i = 1; i <= 1000; i++) {
    arr.push_back(to_string(i));
  }
  for (int i = 0; i < 16; i++) {
    for (string& str : arr)  {
      val.push_back(str);
      str+="9";
    }
  }
  sort(range(val), [] (string& lhs, string& rhs) -> bool {
        if (lhs.size() != rhs.size()) return lhs.size() < rhs.size();
        return lhs < rhs;
      });
  while (val.rbegin()->size() >= 16) val.pop_back();
  val.resize(unique(range(val)) - val.begin());


  int k; k = val.size();
  vector<string> ok;
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      if (!check(val[i], val[j])) goto cont;
    }
    ok.push_back(val[i]);
cont:;
  } 
  
  cin >> k;
  rep (i, k) cout << ok[i] << endl; 
  return 0;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

int K,A,B;
int main(){
	// debug;
	ios;

	cin>>K>>A>>B;
	if(B/K - (A-1)/K > 0) cout<<"OK\n";
	else cout<<"NG\n";

	return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 2e5 + 10;

int a[N];

long long ans;

void solve(int l, int r)
{
	if (l == r)
	{
		ans += a[l];
		return;
	}
	long long res = 0;
	int mid = (l + r) >> 1;
	vector<int> L, R;
	for (int i = mid; i >= l; --i)
	{
		if (!SZ(L) || a[L[SZ(L) - 1]] > a[i])
			L.pb(i);
	}
	for (int i = mid + 1; i <= r; ++i)
	{
		if (!SZ(R) || a[R[SZ(R) - 1]] > a[i])
			R.pb(i);
	}
	L.pb(l - 1);
	R.pb(r + 1);
	for (int i = 0, j = 0; i < SZ(L) - 1; ++i)
	{
		while (a[R[j]] > a[L[i]] && j < SZ(R) - 1) ++j;
		res += 1LL * (R[j] - mid - 1) * (L[i] - L[i + 1]) * a[L[i]];
	}
	for (int i = 0, j = 0; i < SZ(R) - 1; ++i)
	{
		while (a[R[i]] < a[L[j]] && j < SZ(L) - 1) ++j;
		res += 1LL * (mid - L[j]) * (R[i + 1] - R[i]) * a[R[i]];
	}
	ans += res;
	solve(l, mid);
	solve(mid + 1, r);
}

int n;

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]);
	solve(1, n);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2424
#include<stdio.h>
#define N 100001
int rec(int,int);
void print(int);
struct Node{
  int p;
  int l;
  int r;
};
struct Node T[N];
int n,D[N];
int main(){
  int i,k,m,j,o,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) 
    T[i].p=T[i].l=T[i].r= -1;
  for(i=0;i<n;i++){
    scanf("%d%d",&k,&m);
    for(j=0;j<m;j++){
      scanf("%d",&o);
      if(j==0)T[k].l=o;
      else T[l].r=o;
      l=o;
      T[o].p=k;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==-1)r=i;
  }
  rec(r,0);
  for(i=0;i<n;i++)
    print(i);
  return 0;
}

int rec(int a,int b){
  D[a]=b;
  if(T[a].r!=-1)rec(T[a].r,b);
  if(T[a].l!=-1)rec(T[a].l,b+1);
}

void print(int a){
  int i,c;
  printf("node %d:",a);
  printf(" parent = %d,",T[a].p);
  printf(" depth = %d,",D[a]);
  if(T[a].p==-1){
    printf(" root, ");
  }
  else if(T[a].l==-1){
    printf(" leaf, ");
  }
  else printf(" internal node, ");
  printf("[");
  for(i=0,c=T[a].l;c!=-1;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
      }
  printf("]");
  printf("\n");
}
  
 

Measured memory_bytes: 5288
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int dp[100][2][4]; //! [digit from left 0based][1: less than N for sure][non-0 count]

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

    string N;
    int K;
    cin >> N >> K;

    dp[0][0][0] = 1;
    rep(i, N.length()) {
        int nd = N[i]-'0';
        rep(j, 2) rep(k, 4) rep(d, 10) {
            if (K < k) continue;
            if (!j && nd < d) continue;
            int nextJ = ((j || d < nd) ? 1 : 0);
            //! smaller than N guaranteed
            if (k < K) {
                //! any number is allowed
                if (d) {
                    dp[i+1][nextJ][k+1] += dp[i][j][k];
                } else {
                    dp[i+1][nextJ][k] += dp[i][j][k];
                }
            } else {
                //! only 0 is allowed
                if (d == 0) {
                    dp[i+1][nextJ][k] += dp[i][j][k];
                }
            }
        }
    }

    LL ans = 0;
    rep(j, 2) {
        ans += dp[N.length()][j][K];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

struct Vec{
	int ind;
	int val;
};
bool valAsc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val < right.val: left.val < right.val;
}
bool valDesc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val> right.val: left.val > right.val;
}

int main(void){
	int ans,N,n1=1,n2=1,tmp;
	vector <Vec> p;
	scanf("%d",&N);
	for (int i=0;i<N;i++){
		scanf("%d",&tmp);
		Vec vtmp = {i,tmp};
		p.push_back(vtmp);
	}

	sort(p.begin(), p.end(),valAsc);
	for (int i=0;i<N-1;i++){
		if(p[i+1].ind > p[i].ind){
			n2++;
 		}else{
 			n2=1;
 		}
 		if(n2>n1){
 			n1 = n2;
 		}
	}	
	ans = N -n1;
	
	printf("%d\n",ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;

const int INF = 1 << 29;

struct Edge{
    int to, cost;
};
typedef pair<int, int> P;

int d[10001];

int main()
{
    int n,u,k,v,c;
    
    cin >> n;
    fill(d, d + n, INF);
    vector<Edge> G[10001];
    for(int i = 0; i < n; ++i){
        cin >> u >> k;
        for(int j = 0; j < k; ++j){
            cin >> v >> c;
            Edge e = {v, c};
            G[u].push_back(e);
        }
    }
    
    priority_queue<P, vector<P>, greater<P>> que;
    d[0] = 0;
    que.push(P(0,0));
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); ++i){
            Edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    
    for(int i = 0; i < n; ++i){
        cout << i << ' ' << d[i] << endl;
    }
    
}

Measured memory_bytes: 6312
s = input()

stack = []
for c in s:
    if c == 'S':
        stack.append(c)
    else:
        if not stack:
            stack.append(c)
        elif stack[-1] == 'T':
            stack.append(c)
        else:
            stack.pop()

print(len(stack))
# print(*stack, sep='')

Measured memory_bytes: 5096
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    S = Scanner.string()
    c1, c2 = 0, 0
    for i in range(N):
        if S[i] == ")":
            c1 -= 1
        else:
            c1 += 1
        if S[N-i-1] == ")":
            c2 += 1
        else:
            c2 -= 1
        c1 = max(0, c1)
        c2 = max(0, c2)
    ans = "(" * c2 + S + ")" * c1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38512
import sys
l,r = map(int,input().split())
if r-l >= 2018:
    print(0)
    sys.exit()
elif (l%2019 > r%2019) or (l%2019 == 0) or (r%2019 == 0):
    print(0)
    sys.exit()
else:
    l = l%2019
    r = r%2019
p = 2018**2
for i in range(l,r):
    for j in range(i+1,r+1):
        q = (i*j) % 2019
        if q < p:
            p = q
print(p%2019)

    

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

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

    int N;
    cin >> N;

    vector<int> a(N);
    vector<int> b(N + 1);

    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }

    for(int i = 1; i <= N; i++) {
        cin >> b[i];
    }

    for(int i = 1; i < N; i++) {
        a[i] += a[i - 1];
        b[i + 1] += b[i];
    }

    int ans = 0;

    for(int i = 0; i < N; i++) {
        cerr << a[i] << " " << b[N] - b[i] << endl;
        ans = max(ans, a[i] + (b[N] - b[i]));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
def Q3(x):
    def gcd(a, b):
        if b > a:
            a, b = b, a
        while b > 0:
            a, b = b, a % b
        return a

    def lcm(a, b):
        return (a * b) // gcd(a, b)

    N = x[0]
    lst = x[1:]
    if N == 1:
        return lst[0]
    else:
        l = lcm(lst[0], lst[1])
        for x in lst:
            l = lcm(l, x)
        return l

n = int(input())
t = [int(input()) for i in range(n)]
t.insert(0,n)
print(Q3(t))

Measured memory_bytes: 3064
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int m, f, r;
    int s;
 
    while (1) {
        scanf("%d%d%d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1) break;
 
        if (m < 0 || f < 0) puts("F");
        else {
            s = m + f;
            if (s >= 80) puts("A");
            else if (s >= 65) puts("B");
            else if (s >= 50) puts("C");
            else if (s < 30) puts("F");
            else puts(r >= 50 ? "C" : "D");
        }
    }
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;
	cin>>n;
	int cnt=0;
	
	rep(i,n){
		int a;cin>>a;
		if(a==cnt+1) cnt++;

	}
	cout<<(cnt>0?n-cnt:-1)<<endl;

	return 0;
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const string D_blue    = "\x1b[36m";
const string D_green   = "\x1b[32m";
const string D_red     = "\x1b[31m";
const string D_yellow  = "\x1b[33m";
const string Db_red    = "\x1b[41m";
const string Db_yellow = "\x1b[43m";
const string D_end     = "\x1b[39m";
const string Db_end    = "\x1b[49m";

int main (){
  int N,D,X;;
  while (cin >> N >> D >> X){
    D--;
    int ans = X;
    REP(i,N){
      int a;
      cin >> a;
      ans += D / a + 1;
    }

    cout << ans << endl;
  }
  return 0;
}


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

int main()
{
    char b,c[128];
    c['A'] = 'T';
    c['T'] = 'A';
    c['C'] = 'G';
    c['G'] = 'C';
    cin >> b;
    cout << c[b] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define re register
using namespace std;
struct ios{
	template <typename ty> inline ios& operator >> (ty &x)
	{
		register int f=1;x=0;register char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
		for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
		x*=f;return *this;
	}
	template <typename ty>  inline ios& operator << (ty x)
	{
		if(x<0) x=-x,putchar('-');
		if(x>9) *this << x/10;
		putchar(x%10+48);
		return *this;
	}
	inline ios& operator << (char c){putchar(c);return *this;}
}io;
const int mod = 10007;
int a,b,c;
int main()
{
	io >> a>>b>>c;
	if(b+c-a<0) io<<0;
	else io << b+c-a;
	
}

Measured memory_bytes: 256
def binary_search(a, n, query):
    start = 0
    end = n - 1
    while start <= end:
        mean = (start + end) // 2
        if a[mean] == query:
            return True
        elif a[mean] > query:
            end = mean - 1 
        else:
            start = mean + 1
    
    return False


n = int(input())
s = [int(i) for i in input().split()]
q = int(input())
t = [int(i) for i in input().split()]

count = 0
for i in t:
    if binary_search(s, n, i):
        count += 1

print(count)


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

int main() {
  int K, N, ans;
  cin >> N >> K;
  ans =0;
  vector<int>p(N);
  
  for(int i=0; i<N; i++){
    cin >> p.at(i);
  }
  
  sort(p.begin(), p.end());
  
  for(int i=0; i<K; i++){
    ans += p.at(i);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

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

	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);

    if (a == b && a== c) {
			
		printf("1\n");

	}
	else if(a!=b && a!=c &&b!=c){
		printf("3\n");
	}
	else {
		printf("2\n");
	}


}




Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int ans = 0;
  for(int i = 0; i < n; i++)
  {
    if(s[i] == t[i]) ans++;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int H,W;
	int i,j;
	
	while(1){
	scanf("%d %d",&H,&W);
	if((H==0)&&(W==0)) break;
	for(i=0 ;i<H ;i++){
		for(j=0 ;j<W ;j++){
			printf("#");
		}
		printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n; cin >> n;
  vector<ll> a(n,0);
  for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);

  deque<ll> deq;
  sorti(a);
  deq.push_front(a[0]);

  ll i = 1, j = n-1, judge = 0;
  while (true) {
    if (i <= j) deq.push_front(a[j--]); else break;
    if (i <= j) deq.push_back(a[j--]); else break;
    if (i <= j) deq.push_front(a[i++]); else break;
    if (i <= j) deq.push_back(a[i++]); else break;
  }

  ll res = 0;
  for (int i = 0; i < deq.size()-1; ++i) {
    res += abs(deq[i] - deq[i+1]);
  }

  ll tmp = deq.back(); deq.pop_back();
  deq.push_front(tmp);

  ll rest = 0;
  for (int i = 0; i < deq.size()-1; ++i) rest += abs(deq[i] - deq[i+1]);

  cout << max(res,rest) << endl;
}


Measured memory_bytes: 1920