akhauriyash/Code-Regression huggingface dataset:
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

ll h[maxn];
ll dp[maxn];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n, k;
    scanf("%d%d", &n, &k);

    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    dp[1] = 0;
    for(int i = 1; i <= n; i++) scanf("%lld", &h[i]);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= k; j++)
        {
            if(i + j > n)   break;
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    printf("%lld\n", dp[n]);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<vector<int>> a(N, vector<int>(M));
    for (auto &l: a)
        for (int &c: l)
            cin>>c;

    for (int i=0; i<N; i++)
    {
        int px = -1, py;
        for (int j=0; j<M && px==-1; j++)
            for (int k=i; k<N && px==-1; k++)
                if (a[k][j] != 0)
                    px = j,
                    py = k;
        if (px==-1)
            break;
        a[i].swap(a[py]);
        for (int j=i+1; j<N; j++)
            if (a[j][px] != 0)
                for (int k=0; k<M; k++)
                    a[j][k] ^= a[i][k];
    }
    int r = 0;
    for (int i=0; i<N; i++)
        for (int j=0; j<M; j++)
            if (a[i][j] != 0)
                r = i+1;

    long long MOD = 998244353;

    long long call = 1;
    for (int i=0; i<M; i++)
        call = call*2%MOD;
    long long czero = 1;
    for (int i=0; i<M-r; i++)
        czero = czero*2%MOD;
    long long rall = 1;
    for (int i=0; i<N-1; i++)
        rall = rall*2%MOD;
    cout<<(call-czero+MOD)%MOD*rall%MOD<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (1000L)
#define MAX_M (1000L)
#define NUM_MOD (1000000007L)

using namespace std;

int main() {
  // read inputs
  long N, M, as[MAX_N], bs[MAX_M];
  scanf("%ld %ld", &N, &M);
  for (long i = 0; i < N; i++) {
    scanf("%ld", &as[i]);
  }
  for (long j = 0; j < M; j++) {
    scanf("%ld", &bs[j]);
  }

  // sort as and bs
  sort(as, as + N);
  sort(bs, bs + M);

  // impossible if duplicates exist
  for (long i = 1; i < N; i++) {
    if (as[i] == as[i - 1]) {
      printf("0\n");
      exit(0);
    }
  }
  for (long j = 0; j < M; j++) {
    if (bs[j] == bs[j - 1]) {
      printf("0\n");
      exit(0);
    }
  }

  // solve
  long ans = 1;
  for (long x = N * M; x > 0; x--) {
    const long i = lower_bound(as, as + N, x) - as, a = as[i],
               j = lower_bound(bs, bs + M, x) - bs, b = bs[j];
    if (x == a && x == b) {
      ans = (ans * 1) % NUM_MOD;
    } else if (x == a) {
      ans = (ans * (M - j)) % NUM_MOD;
    } else if (x == b) {
      ans = (ans * (N - i)) % NUM_MOD;
    } else {
      const long num_places = (N - i) * (M - j) - (N * M - x);
      if (num_places <= 0) {
        printf("0\n");
        exit(0);
      }
      ans = (ans * num_places) % NUM_MOD;
    }
  }
  printf("%ld\n", ans);
}

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

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

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

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

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




int main(){
	int N,L;
	string a;
	vector<string> s;
	cin >> N >> L;
	FOR(i,N){
		cin >>a;
		s.PB(a);
	}
	sort(s.begin(),s.end());
	FOR(i,N) cout <<s[i];	
	
	return 0;
}

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

int main()
{
  int H,*A,i;
  
  scanf("%d",&H);

  A = (int *)malloc((H+1) * sizeof(int));

  for(i=0;i<H;i++){
    scanf("%d",&A[i+1]);
    
  }

  for(i=0;i<H;i++){
    printf("node %d: key = %d, ",i+1,A[i+1]);
    if(i!=0) printf("parent key = %d, ",A[(i+1)/2]);
    if((i+1)*2<=H && (i+1)*2+1<=H) printf("left key = %d, right key = %d, ",A[(i+1)*2],A[(i+1)*2+1]);
    else if((i+1)*2<=H) printf("left key = %d, ",A[(i+1)*2]);
    printf("\n");
  }

  free(A);
  return 0;
}
    



Measured memory_bytes: 2056
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] p = new int[m];
		int[] y = new int[m];
		String[] s = new String[m];
		HashMap<Integer, TreeMap<Integer, Integer>> map = new HashMap<>();
		for (int i = 0; i < m; i++) {
			p[i] = scan.nextInt();
			y[i] = scan.nextInt();
			map.computeIfAbsent(p[i], x -> new TreeMap<>()).put(y[i], i);
		}

		for (Entry<Integer, TreeMap<Integer, Integer>> e : map.entrySet()) {
			int cnt = 1;
			for (Entry<Integer, Integer> f : e.getValue().entrySet()) {
				s[f.getValue()] = String.format("%06d%06d", e.getKey(), cnt);
				cnt++;
			}
		}
		Arrays.stream(s).forEach(System.out::println);
	}
}


Measured memory_bytes: 186888
def all_digits_same(N, d):
    if N == d:
        return True
    elif N % 10 != d:
        return False
    return all_digits_same(N // 10, d)

N = int(input())

while True:
    if all_digits_same(N, N % 10):
        print(N)
        break
    N += 1

Measured memory_bytes: 2940
S = input()
N = len(S) + 1

vA = [0,] * N
vZ = []
p = ">"
for i,s in enumerate(S):
    if p+s == "><":
        vZ.append(i)
    p = s
if S[-1] == ">":
    vZ.append(N-1)

# print(vZ)##
####
for z in vZ:
    if z == N-1:
        break
    t = z
    while t<N-1 and S[t] == "<":
        vA[t+1] = vA[t] + 1
        t += 1

# print(vA)##

for z in vZ:
    if z == 0:
        continue
    t = z
    while t>0 and S[t-1] == ">":
        vA[t-1] = max(vA[t] + 1, vA[t-1])
        t -= 1

# print(vA)###
print(sum(vA))


Measured memory_bytes: 23348
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		City[] c = new City[m];
		for(int i = 0; i < m; i++) {
			c[i] = new City(sc.nextInt(), sc.nextInt(), i);
		}
		Arrays.sort(c, (c1, c2) -> c1.y - c2.y);
		int pnum[] = new int[n + 1];
		Arrays.fill(pnum, 1);
		for(int i = 0; i < m; i++) {
			c[i].setNum(pnum[c[i].p]);
			pnum[c[i].p]++;
		}
		City ans[] = new City[m];
		for(int i = 0; i < m; i++) {
			ans[c[i].i] = c[i];
		}
		//Arrays.sort(c, (c1, c2) -> c1.i - c2.i);
		//for(int i = 0; i < m; i++) c[i].printNumber();
		for(int i = 0; i < m; i++) ans[i].printNumber();
		
		
	}
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}
	public class City {
		int p, y, i, num;
		int getY() {
			return y;
		}
		void setNum(int num) {
			this.num = num;
		}
		City(int p, int y, int i){
			this.p = p; this.y = y;this.i = i;
		}
		void printNumber(){
			String s1 = "000000";
			String s2 = "000000";
			s1 = s1 + Integer.toString(p);
			s2 = s2 + Integer.toString(num);
			System.out.println(s1.substring(s1.length() - 6) + s2.substring(s2.length() - 6));
		}
	}
}



Measured memory_bytes: 116120
'use strict';

function main(input) {
  let AB = input.split("\n")[0].split(' ').map(x => Number(x));
  let s = input.split("\n")[1];

  if(s.length != AB[0] + AB[1] + 1 || s[AB[0]] != "-") {
  	console.log("No");
    return;
  }
  if(s.slice(0,AB[0]).match(/^[0-9]+$/) &&
	     s.slice(AB[0]+1).match(/^[0-9]+$/)){
    console.log("Yes");
    return;
  }
  console.log("No");

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import copy
N = int(input())
A_list = [int(input()) for _ in range(N)]
sort_list = copy.copy(A_list)
sort_list.sort()
for i in range(N):
    if A_list[i] == sort_list[-1]:
        print(sort_list[-2])
    else:
        print(sort_list[-1])

Measured memory_bytes: 14560
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int pos = 0;
  vector<char> o(s.size());
  for(auto& c : s){
    if(c=='B'){
      pos = max(0, pos-1);
    }else{
      o[pos] = c;
      pos++;
    }
  }
  for(int ii=0; ii<pos; ii++){
    cout << o[ii];
  }
  cout << endl;
  return 0;
}

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

int main()
{
  int x;
  cin>>x;
  if(x>=400&&x<=599)
    cout<<8<<endl;
  else
  {
    if(x>=600&&x<=799)
      cout<<7<<endl;
    else
    {
      if(x>=800&&x<=999)
    	cout<<6<<endl;
      else
      {
        if(x>=1000&&x<=1199)
    	cout<<5<<endl;
        else
        {
          if(x>=1200&&x<=1399)
    		cout<<4<<endl;
          else
          {
            if(x>=1400&&x<=1599)
    			cout<<3<<endl;
            else
            {
              if(x>=1600&&x<=1799)
    			cout<<2<<endl;
              else if(x>=1800&&x<=1999)
    			cout<<1<<endl;
            }
          }
        }
      }
      
    }
    
  }
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll>A(N);
  rep(i,N){cin>>A[i];}
  for(int i=K;i<N;i++){
    if(A[i-K]<A[i]){
      cout<<"Yes"<<endl;
    }
    else{
       cout<<"No"<<endl;
     }
  }
}

Measured memory_bytes: 4812
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define inf (int)(3e18)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N;
string s;
int a[1000005];
signed main() {
	cin>>N>>s;
	int sum1=0,sum2=0;
	bool flag=true;
	rep(i,N){
		a[i]=s[i]-'0';
		int now=N-1,sum=0;
		while(now)sum+=now/2,now/=2;
		now=N-i-1;
		while(now)sum-=now/2,now/=2;
		now=i;
		while(now)sum-=now/2,now/=2;
		if(!sum){
			sum1+=a[i]%2;
			sum2+=a[i]/2;
		}
		if(a[i]==2)flag=false;
	}
	if(sum1%2)cout<<1<<endl;
	else if(!flag)cout<<0<<endl;
	else if(sum2%2)cout<<2<<endl;
	else cout<<0<<endl;
}



Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
int main() {
    int tHp, tAt, aHp, aAt;
    cin >> tHp >> tAt >> aHp >> aAt;

    while(tHp>0&&aHp>0) {
        aHp -= tAt;
        tHp -= aAt;
    }
    if (aHp<=0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#define mxN 200005
using namespace std;

long n, a[mxN], dp[mxN];
map<long, long> nums;

int main() {
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> a[i];
		nums[a[i] + i]++;
	}
	long ans = 0;
	for (int i=1; i<=n; i++) {
		ans += nums[i - a[i]];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 27752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n,m;
  cin >> n >> m;
  deque<pair<ll,ll>> vp(n);
  for(ll i = 0; i < n; ++i) cin >> vp[i].first >> vp[i].second;
  sort(begin(vp),end(vp));
  ll ans = 0;
  priority_queue<ll> q;
  for(ll i = 1; i <= m; ++i){
    while(!vp.empty() and vp[0].first <= i){
      q.emplace(vp[0].second);
      vp.pop_front();
    }

    if(!q.empty()){
      ans += q.top();
      q.pop();
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 2684
n = int(input())
x = [int(i) for i in input().split()]
y = []
z =[]
for i in range(len(x)):
    y.append(x[i]+i)
    z.append(i-x[i])
count = 0 
dic = {}
for i in range(len(z)):
    if z[i] in dic :
        dic[z[i]]+= 1
    else :
        dic[z[i]] = 1
for i in range(len(y)) :
    dic[z[i]]-= 1 
    if y[i] in dic :
        count += dic[y[i]]
print(count)


Measured memory_bytes: 50800
#include <bits/stdc++.h>
using namespace std;
int main (){
  int n,l,i;
  cin>>n>>l;
  
  int a=1000,b=0,x,c=1;
  for(i=0;i<n;i++,l++){
    if(a>abs(l)){
      a=abs(l);
      if(a==0);
      else c=l/a;
    }
    b+=l;

  }
  
  b-=a*c;
  
  cout<<b;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<tuple>
#define INF  (int)1e8
#define EPS   1e-9
#define MOD 1000000007
#define Pi 3.14159
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define repk(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define IN(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printPI(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define ll long long
#define PI pair<int,int>
#define PL pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvvi vector<vvi>
#define vvvl vector<vvl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define dbg(x, y) cout << x << " = " << y << endl
using namespace std;

const int N = 1e5 + 5;
ll gcd(ll a, ll b) {ll temp; while (b > 0) {temp = a % b; a = b; b = temp;} return a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll fpow(ll  b, ll exp, ll mod) {if (exp == 0) return 1; ll t = fpow(b, exp / 2, mod); if (exp & 1) return t * t % mod * b % mod; return t * t % mod;}
ll divmod(ll i, ll j, ll mod) {i %= mod, j %= mod; return i * fpow(j, mod - 2, mod) % mod;}


void sol() {
	int n; cin >> n;
	int k; cin >> k;
	ll cnt = 0;
	rep(i, 1, n) {
		int a; cin >> a;
		if (a < k)
			cnt += (k - a);
		else
			k = a;

	}
	cout << cnt;
}

int main() {
	// fio
	int t = 1;
	// cin >> t;
	while (t--)
		sol();

	return 0;
}



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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n=s.length();
    int c=0;
    int ans=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            c++;
            ans=max(ans,c);
        }
        else{
            c=0;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using T = ll;
     
const int MOD = 998244353;
const ll ZER = 0;


int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll mn = a * (n - 1) + b, mx = a + b * (n - 1);
    cout << max(ZER, mx - mn + 1) << endl;
}



Measured memory_bytes: 3572
#ifndef LOCAL
#pragma GCC optimize("O2")
#endif
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

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

    sort(l.begin(), l.end());
    int count = 0;
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k< N; k++){
                if(l[k] < l[i] + l[j]){
                    count += 1;
                }
            }
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 256
#include<atcoder/string>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long Int;
string str;

int main(){
    cin >> str;
    auto sa = atcoder::suffix_array(str);
    auto lcp = atcoder::lcp_array(str, sa);
    Int l = str.size();
    Int ans = l * (l+1) / 2;
    for(auto l:lcp){
        ans -= l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15288
n,m=map(int,input().split())
ac=[0]*(n+1)
wa=0
for i in range(m):
  p,c=input().split()
  if c=='WA' and ac[int(p)]!=1:
    ac[int(p)]-=1
  elif c=='AC' and ac[int(p)]!=1:
    wa+=abs(ac[int(p)])
    ac[int(p)]=1
print(ac.count(1),wa)

Measured memory_bytes: 9348
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
#include<tuple>
#include<cstdio>
using namespace std;
#pragma warning(disable:4996)

//=========================================================================
//=========================================================================
//=========================================================================
template<typename Type> class RMQ {
private:
	unsigned size_; std::vector<Type> dat;
	inline Type query_(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return std::numeric_limits<Type>::max();
		if (a <= l && r <= b) return dat[k];
		Type lc = query_(a, b, (k << 1), l, (l + r) >> 1);
		Type rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
		return std::min(lc, rc);
	}
public:
	RMQ() : size_(0), dat(std::vector<Type>()) {};
	RMQ(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RMQ(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
		}
	}
	inline Type query(int l, int r) {
		return query_(l, r, 1, 0, size_);
	}
};
//=========================================================================
//=========================================================================
//=========================================================================

long long n, a[300000], b[300000]; vector<pair<long long, long long>>E;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) { scanf("%lld%lld", &a[i], &b[i]); if (a[i] > b[i])swap(a[i], b[i]); }

	//----------------------------パターン１：最大と最小それぞれを赤と青でカバーする---------------------------
	long long r1 = (1LL << 30), r2 = -(1LL << 30), r3 = (1LL << 30), r4 = -(1LL << 30);
	for (int i = 0; i < n; i++) {
		r1 = min(r1, a[i]); r2 = max(r2, a[i]); r3 = min(r3, b[i]); r4 = max(r4, b[i]);
	}
	long long ret1 = 1LL * (r2 - r1)*(r4 - r3);

	//-----------------パターン２：最大と最小両方を赤がカバーする：bmax-bminの最小値を求める-------------------

	//平面走査とＲＭＱでごり押し！！常勝！！！！
	RMQ<long long>X(n);
	for (int i = 0; i < n; i++) { E.push_back(make_pair(a[i], i)); E.push_back(make_pair(b[i], i)); }
	sort(E.begin(), E.end());

	long long ret2 = (1LL << 60);
	for (int i = 0; i < n; i++)X.update(i, -(1LL << 60));

	for (int i = 0; i < E.size(); i++) {
		long long p1 = E[i].first, p2 = E[i].second;
		X.update(p2, p1);
		ret2 = min(ret2, p1 - X.query(0, n));
	}
	ret2 *= (r4 - r1);

	cout << min(ret1, ret2) << endl;
	return 0;
}

Measured memory_bytes: 18284
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, long long M){
  std::cout << (N*(N-1))/2+(M*(M-1))/2 << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  solve(N, M);
  return 0;
}



Measured memory_bytes: 256
package main

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

type dice struct {
	t int64
	e int64
	w int64
	s int64
	n int64
	b int64
}

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

	d := &dice{
		t: nextInt(sc),
		s: nextInt(sc),
		e: nextInt(sc),
		w: nextInt(sc),
		n: nextInt(sc),
		b: nextInt(sc),
	}

	d.roll(nextString(sc))
	d.Print()
}

func (d *dice) Print() {
	fmt.Println(d.t)
}

func (d *dice) roll(s string) {
	for _, v := range s {
		switch v {
		case 'S':
			d.rollS()
		case 'W':
			d.rollW()
		case 'E':
			d.rollE()
		case 'N':
			d.rollN()
		}
	}
}

func (d *dice) rollS() {
	oldB := d.b
	d.b = d.s
	d.s = d.t
	d.t = d.n
	d.n = oldB
}

func (d *dice) rollN() {
	oldB := d.b
	d.b = d.n
	d.n = d.t
	d.t = d.s
	d.s = oldB
}

func (d *dice) rollE() {
	oldB := d.b
	d.b = d.e
	d.e = d.t
	d.t = d.w
	d.w = oldB
}

func (d *dice) rollW() {
	oldB := d.b
	d.b = d.w
	d.w = d.t
	d.t = d.e
	d.e = oldB
}

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

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 1124
n=int(input())
s=list(str(input()))
k=int(input())

for i in range(len(s)):
	if s[i]!=s[k-1]:
		s[i]='*'
for i in range(len(s)):
	if i==len(s):
		print(s[i])
	else:
		print(s[i],end='')

Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val i1 = sc.next()
    val i2 = sc.next()
    val i3 = sc.next()

    val sortValues = mutableListOf<String>(i1, i2, i3)
    sortValues.sort()
    println(sortValues[0] + " " + sortValues[1] + " " + sortValues[2])
}



Measured memory_bytes: 25756
# 確認

S = str(input())
words = ['dream', 'dreamer', 'erase', 'eraser']
dp = [0] * 100010

dp[0] = 1
for i in range(len(S)):
    if not dp[i]:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1

if dp[len(S)] == 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	ll a,b;
	cin >> a >> b;
	ll sum = (a + b) /2;
	if ((a + b) % 2 !=0) {
		cout << "IMPOSSIBLE" << endl;
	} else {
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <cmath>
#include <bitset>

constexpr int X = 20000;
const std::vector<int> dx{0, 1}, dy{1, 0};

int main() {
    int h, w;
    std::cin >> h >> w;

    std::vector<std::vector<int>>
        dss(h, std::vector<int>(w));

    for (auto& ds : dss) {
        for (auto& d : ds) {
            std::cin >> d;
        }
    }
    for (auto& ds : dss) {
        for (auto& d : ds) {
            int b;
            std::cin >> b;
            d = std::abs(d - b);
        }
    }

    std::vector<std::vector<std::bitset<X * 2 + 1>>>
        dp(h, std::vector<std::bitset<X * 2 + 1>>(w, 0));
    dp[0][0][X] = 1;

    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            dp[x][y] = (dp[x][y] << dss[x][y]) | (dp[x][y] >> dss[x][y]);

            for (int i = 0; i < 2; ++i) {
                int nx = x + dx[i],
                    ny = y + dy[i];

                if (h <= nx || w <= ny) continue;
                dp[nx][ny] |= dp[x][y];
            }
        }
    }

    int ans = X;
    for (int i = 0; i <= X * 2; ++i) {
        if (dp[h - 1][w - 1][i]) {
            ans = std::min(ans, std::abs(i - X));
        }
    }

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


Measured memory_bytes: 32000
n,k=map(int,input().split())
s=input()

cnt=0
lst=[]
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        cnt+=1
    else:
        lst.append(cnt)
        cnt=0

lst.append(cnt)

ans=n-sum(lst)-1

lst2=[]
for i in lst:
    for j in range(i//2):
        lst2.append(2)
    
    if i%2==1:
        lst2.append(1)

lst3=[]
xxxxx=lst2.count(1)

if xxxxx%2==1:
    lst3.append(1)

for i in range(xxxxx//2):
    lst3.append(2)

for i in range(lst2.count(2)):
    lst3.append(2)

lst3.sort()
lst3.reverse()

if len(lst3)>k:
    ans+=sum(lst3[:k])
else:
    ans+=sum(lst3)


print(ans)

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

using namespace std;

const int MAX_N = 1e2 + 10;
int numbers[MAX_N];

int main () {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int N;
    scanf("%d", &N);
    int maxNum = 0, minNum = INT_MAX;
    for(int i = 0; i < N; i += 1) {
        int number;
        scanf("%d", &number);
        minNum = min(minNum, number);
        maxNum = max(maxNum, number);
    }
    printf("%d\n", maxNum - minNum);
    return 0;
}

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

int main(){
	double a,b,c,d,e,f,x,y;
	while(true){
		cin>>a>>b>>c>>d>>e>>f;
		if(cin.eof()) break;
		x=(b*f-c*e)/(b*d-a*e);
		y=(c-a*x)/b;
		x=round(x*1000.0)/1000.0;
		y=round(y*1000.0)/1000.0;
		if(x-0.0<0.001&&x-0.0>-0.001) x=0.0;
		if(y-0.0<0.001&&y-0.0>-0.001) y=0.0;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 3260
def examC():
    ABC = LI(); ABC.sort()
    judge = ABC[2]*2-ABC[1]-ABC[0]
    ans = judge//2 + (judge%2)*2
    print(ans)
    return

def examD():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examC()


Measured memory_bytes: 3436
n = int(input())
from collections import defaultdict
dic = defaultdict(int)

for i in range(n+1):
    i = str(i)
    dic[(i[0], i[-1])] += 1


ans = 0
for i in range(1,10):
    for j in range(1,10):
        i = str(i)
        j = str(j)
        ans += dic[i,j] * dic[j,i]

print(ans)




Measured memory_bytes: 40428
#include <iostream>
#include<string.h>

using namespace std;

int main()
{
    char S[4];
    cin>>S;
    int flag=0;
    for(int i=0;i<strlen(S);i++)
    {
        if('0'<S[i]<'9')
        {


        if(S[i]==S[i+1])
        {
            flag=1;
        }
        }

    }
    if(flag==0)
    {
        cout<<"Good";
    }
    if(flag==1)
    {
        cout<<"Bad";
    }


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
  
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        for(int i=1;i<=x;i++){
            int num=i;
            if(num%3==0){
                System.out.print(" "+i);
            }else{
                while(true){
                    if(num%10==3){
                        System.out.print(" "+i);
                        break;
                    }
                    num=num/10;
                    if(num<3)
                        break;
                }
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 28604
#include <stdio.h>
#define N 500001
#define INFTY 1000000000
int A[N],l[N],r[N],count=0;

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++)l[i]=A[left+i];
  for(i=0;i<n2;i++)r[i]=A[mid+i];
  
  l[n1]=INFTY;
  r[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++,count++){
    if(l[i]<=r[j]){
      A[k]=l[i];
      i++;
    }
    else {
      A[k]=r[j];
      j++;
    }
  }
}

void mergesort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  mergesort(A,0,n);


  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n%d\n",count);
  
  return 0;
}



Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define pb              push_back
#define se              second
#define mp              make_pair
#define fi              first
#define del(a,vec)      vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v)   binary_search(f,l,v)
#define iter(a,b)       vector<int>::iterator a,b
#define lower(v,num)    lower_bound (v.begin(), v.end(), num);
#define upper(v,num)    upper_bound (v.begin(), v.end(), num); 
#define removecopy(a)   unique(a.begin(), a.end()); 
#define vi              vector<int> 
#define pi              pair<int,int>    
#define vpi             vector<pi>      
#define mlbb            ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)    
int mod =1000000007;
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    int pow (int x, int n,int mod) {//calculate x^n
    if (n == 0) return 1;

    int res = pow (x, n / 2,mod);

    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;

    return res;
    }
    int _gcd(int a,int b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};
using namespace Rahul;
int32_t main()
{
        
    mlbb;
    
    string s1,s2;
    cin>>s1>>s2;
    
    int num1 = s1[0] - '0';
    int num2 = s2[0] - '0';
    
    if(s1<s2){
        for(int i=0;i<num2;i++) cout<<s1;
    }
    else
    for(int i=0;i<num1;i++)  cout<<s2;
    
    
}


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

typedef long long ll;

int main() {
    while(true) {
        int n; cin >> n;
        if(n == 0)  break;
        vector<pair<int, int>> squares;
        int l = 0, r = 1, d = 0, u = 1;
        squares.push_back(pair<int, int>(0, 0));
        for(int i = 0; i < n-1; i++) {
            int m, p; cin >> m >> p;
            auto s = squares[m];
            switch(p) {
                case 0:
                squares.push_back(pair<int, int>(s.first-1, s.second));
                l = min(s.first-1, l);
                break;
                case 1:
                squares.push_back(pair<int, int>(s.first, s.second-1));
                d = min(s.second-1, d);
                break;
                case 2:
                squares.push_back(pair<int, int>(s.first+1, s.second));
                r = max(s.first+2, r);
                break;
                case 3:
                squares.push_back(pair<int, int>(s.first, s.second+1));
                u = max(s.second+2, u);
                break;
            }
        }
        cout << r - l << ' ' << u - d << endl;
    }
}


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

int main(void){
    int n, l;
    int result = 0;
    
    cin >> n >> l;
    
    rep(i, n){
        result += l+i;
    }
    
    if(l+n-1 <= 0){
        result -= l+n-1;
    } else if(l > 0){
        result -= l;
    }
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
int main(){
      ios::sync_with_stdio(false);
      int n,ans = INT_MIN,minnum = INT_MAX,tmp;
      cin >> n;
      for(int i= 0;i<n;i++){
            cin >> tmp;
            if(i!=0) ans = max(ans,tmp - minnum);
            minnum = min(tmp,minnum);
      }
      cout << ans << endl;
}

Measured memory_bytes: 1200
#import<bits/stdc++.h>
#define elif else if
using namespace std;


int a,b,c;
string s,t,r;


int main(void){
    cin>>s>>t>>r;
    if (s[s.size()-1]==t[0] and t[t.size()-1]==r[0]) puts("YES");
    else puts("NO");
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
#define SEND_HELP ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define BR cerr<<endl
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
	#ifndef ONLINE_JUDGE
        freopen("inputf.in", "r", stdin);
    #endif
    SEND_HELP

    int a, b;
    cin >> a >> b;
    cout << (((ll)a * b) / (ll)__gcd(a, b));

    return 0;
}

/*

*/

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int[] s = new int[100000];
			boolean ans = true;
			int N = sc.nextInt();
			int K = sc.nextInt();
			if(N == 0 && K == 0) break;
			for(int k = 0; k < K; k++){
				s[k] = sc.nextInt();
			}
			for(int n = 0; n < N; n++){
				for(int k = 0; k < K; k++){
					s[k] -= sc.nextInt();
				}
			}
			for(int k = 0; k < K; k++){
				if(s[k] < 0){
					ans = false;
					break;
				}
			}
			if(ans == true) System.out.println("Yes");
			else System.out.println("No");
		}
	}
}

Measured memory_bytes: 94892
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      mut aa: [usize; n],
    }
    use std::collections::HashMap;
    let mut map = HashMap::new();
    for &a in aa.iter() {
        *map.entry(a).or_insert(0) += 1;
    }
    aa.sort();
    aa.dedup();
    let mut ans = aa.len();
    let mut even = 0;
    for a in aa {
        let num = map.get(&a).unwrap();
        if num%2 == 0 {
            even += 1;
        }
    }
    if even%2 == 1 {
        ans -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
(let* ((n (read))
       (l1 (loop repeat n
                 collect (read-line)))
       (m (read))
       (l2 (loop repeat m
                 collect(read-line))))
  (format t "~A~%"
          (max 0
               (loop for i in l1
                     maximize (- (count i l1 :test #'string=) (count i l2 :test #'string=))))))


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

int main() {
  int64_t N;
  int64_t luca_1 = 2;
  int64_t luca_2 = 1;
  int64_t luca = 3;

  cin >> N;

  if (N == 0) {
    cout << 2 << endl;
  } else if (N == 1){
    cout << 1 << endl;
  } else {
    for (int64_t i = 2; i < N; i++) {
		luca_1 = luca_2;
        luca_2 = luca;
        luca = luca_1 + luca_2;
    }
    cout << luca << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define N 100
int min(int a,int b){
  if(a>b)return b;
  else return a;
}
int main(){
  int n,i,j,l,k,q;
  int p[N+1];
  int m[N+1][N+1];
  
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INT_MAX;//
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j]=min(m[i][j],q);
      }

    }
  }

  
  printf("%d\n",m[1][n]);


  
  return 0; 
}



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

bool is_prime(int n){
    for(int i=2; i*i<=n; i++){
        if(n % i == 0) return false;
    }
    return n != 1;  // n=1のときは例外となる
}

int main()
{
    int n; cin >> n;
    int count = 0;
    for(int i=0; i<n; i++){
        int x; cin >> x;
        if(is_prime(x)) count += 1;
    }
    cout << count << endl;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<string, string> P;

int main() {
	int n, f;
	cin >> n >> f;
	set<string> st;
	map<P, int> mp;
	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		vector<string> s(m);
		for (int j = 0; j < m; j++) {
			cin >> s[j];
			st.insert(s[j]);
		}
		for (int j = 0; j < m; j++) {
			for (int k = j + 1; k < m; k++) {
				mp[P(s[j], s[k])]++;
				mp[P(s[k], s[j])]++;
			}
		}
	}
	vector<string> ss;
	for (set<string>::iterator ite = st.begin(); ite != st.end(); ite++) {
		ss.push_back(*ite);
	}
	int ans = 0;
	sort(ss.begin(), ss.end());
	for (int i = 0; i < ss.size(); i++) {
		for (int j = i + 1; j < ss.size(); j++) {
			if (mp[P(ss[i], ss[j])] >= f) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	for (int i = 0; i < ss.size(); i++) {
		for (int j = i + 1; j < ss.size(); j++) {
			if (mp[P(ss[i], ss[j])] >= f) {
				cout << ss[i] << ' ' << ss[j] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 34820
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n,a,b;
    cin>>n>>a>>b;
    cout<<max(0ll,(n-1)*b+a-(n-1)*a-b+1)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cstdio>
using namespace std;
map<char,int>M;
int cnv(string str){
    str="."+str;
    int res=0;
    for(int i=0;i<str.length();i++){
        if(M.find(str[i])!=M.end()){
            int a;
            if(str[i-1]>='0'&&str[i-1]<='9'){
                a=str[i-1]-'0';
            }
            else a=1;
            res+=M[str[i]]*a;
        }
    }
    return res;
}
int main(){
    M['m']=1000;M['c']=100;M['x']=10;M['i']=1;
    int n;
    scanf("%d",&n);
    while(n--){
        string s1,s2;
        cin>>s1>>s2;
        int val=cnv(s1)+cnv(s2);
        if(val/1000){
            if(val/1000>1)printf("%d",val/1000);
            printf("m");
        }
        val%=1000;
        if(val/100){
            if(val/100>1)printf("%d",val/100);
            printf("c");
        }
        val%=100;
        if(val/10){
            if(val/10>1)printf("%d",val/10);
            printf("x");
        }
        val%=10;
        if(val){
            if(val>1)printf("%d",val);
            printf("i");
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define _USE_MATH_DEFINES
#include <cmath>

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

using namespace std;
typedef long long ll;

const int MAX = 100100;
int S[MAX];

int partition(int n) {
   int i = 0;
   int r = S[n];

   for (int j = 1; j < n; j++) {
      if (S[j] <= r) {
         i++;
         swap(S[i], S[j]);
      }
   }
   swap(S[i + 1], S[n]);
   return(i + 1);
}

int main() {
   int n;

   cin >> n;
   for (int i = 1; i <= n; i++) {
      scanf("%d", &S[i]);
   }
   int ans = partition(n);
   for (int i = 1; i <= n; i++) {
      if (i != 1) printf(" ");
      if (i == ans) printf("[%d]", S[i]);
      else printf("%d", S[i]);
   }
   printf("\n");
   return(0);
}



Measured memory_bytes: 3576
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

vector<pii> ans;

void doFor(int n) {
	for(int i=1; i<=n; i++) {
		for(int j=i+1; j<=n; j++) {
			if(i+j != n+1) {
				ans.pb(mp(i, j));
			}
		}
	}
}

int main() {

	boost;
	int n; cin>>n;
	if(n & 1) {
		doFor(n-1);
		for(int i=1; i<=n-1; i++) {
			ans.pb(mp(i, n));
		}
	}
	else {
		doFor(n);
	}
	cout<<ans.size()<<"\n";
	for(auto it : ans) {
		cout<<it.fi<<" "<<it.se<<"\n";
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,K;
    cin >> N >> K;
    int h;
    int c = 0;
    for(int i = 0; i < N ;i++){
        cin >> h;
        if(h >=K)c++;
    }
    
    cout << c << endl;
    
}


Measured memory_bytes: 256
l = list(map(int, input().split()))
a = l[0]
b = l[1]
c = l[2]

ss = []
mm = []
ll = []
def checkK(x,y,z):
    if y - x + 1 <= z *2:
        counter = int(x)
        while counter != y+1:
            ss.append(counter)
            counter = counter + 1
        for i in range(len(ss)):
            print(ss[i])
    
        
    else:
        for i in range(c):
            ll.append(a+i)
        for i in range(c):
            ll.append(b-c+i+1)
        for i in range(len(ll)):
            print(ll[i])
        
checkK(a,b,c)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define PB push_back

using namespace std;

int dp[110000];
vector<vector<int>> vv;
int dfs(int now)
{
  int &res = dp[now];
  if (res > 0) return res;
  res = 0;
  for (auto to : vv[now]) {
    res = max(res, dfs(to) + 1);
  }
  return res;
}

int main()
{
  int N, M; cin >> N >> M;
  vv = vector<vector<int>>(N);
  REP(i, M) {
    int x, y; cin >> x >> y;
    x--, y--;
    vv[x].PB(y);
  }

  REP(i, 110000) dp[i] = -1;
  int ans = -1;
  REP(i, N) {
    ans = max(ans, dfs(i));
  }
  cout << ans << endl;

  return 0;
}

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


#define ll long long
#define MOD 1000000007
#define PI 3.1415


int main(){
    ll n,d;
    cin>>n>>d;

    ll x,y,co=0;double dis;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        dis = pow(x*x+y*y,0.5);
        if(dis<=d)co++;
    }
    cout<<co<<endl;
}



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

ll n,x,y,q;
vector <ll> adj[200009];
ll an[200009];
ll vl[200009];

void btr(ll x,ll s,ll pr){
	an[x]=vl[x]+s;
	
	for(int i=0;i<adj[x].size();i++)
	if(adj[x][i]!=pr)
	btr(adj[x][i],s+vl[x],x);
}

int main(){
	cin>>n>>q;
	
	for(int i=1;i<n;i++)
	cin>>x>>y,adj[x].push_back(y),adj[y].push_back(x);
	
	for(int i=0;i<q;i++)
	cin>>x>>y,vl[x]+=y;
	
	btr(1,0,-1);
	
	for(int i=1;i<=n;i++)
	cout<<an[i]<<" ";
}

Measured memory_bytes: 28800
#include <stdio.h>
#include <math.h>
int main (void)
{
  int a,b;
  char op;
  for(;;){

  scanf("%d %c %d", &a, &op, &b);
  if( op == '?') break;
  switch( op ){
    case '+':
      printf("%d\n", a + b);
      break;
    case '-':
      printf("%d\n", a- b);
      break;
    case '/':
      printf("%d\n", a / b);
      break;
    case '*':
      printf("%d\n", a * b);
      break;

  }

  }

  return 0;
}

Measured memory_bytes: 1852