akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef int64_t  ll;

int main () {
    int x, y;
    cin >> x >> y;
    vector<int> a(x, -1);
    rep(i, y) {
        int t;
        cin >> t;
        rep(i, t) {
            int tn;
            cin >> tn;
            a.at(tn-1) = 1;
        }
    }
    int ans = 0;
    rep(i, a.size()) {
        if (a.at(i) == -1) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
  int n,m,d,dy[4]={0,-1,0,1},dx[4]={-1,0,1,0},y,x;
  while(1){
    cin>>n;if(n==0)break;
    int mp[401][401];
    for(int i=0;i<401;i++)for(int j=0;j<401;j++)mp[i][j]=-1;
    mp[200][200]=0;
    for(int i=1;i<n;i++){
      cin>>m>>d;
      for(int j=0;j<401;j++)
	for(int k=0;k<401;k++)
	  if(mp[j][k]==m)mp[j+dy[d]][k+dx[d]]=i;
    }
    n=m=400,x=y=0;
    for(int i=0;i<401;i++)
      for(int j=0;j<401;j++)
	if(mp[i][j]!=-1){
	  if(i<m)m=i;
	  if(j<n)n=j;
	  if(i>y)y=i;
	  if(j>x)x=j;
	}
    cout<<x-n+1<<" "<<y-m+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1788
#include <stdio.h>

#define MAX 2000000

int H, A[MAX + 1];

void maxHeapify(int i) {
    int l, r, largest;
    l = 2 * i;
    r = l + 1;

    // 左の子、自分、右の子で値が最大のノードを選ぶ
    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;

    if (r <= H && A[r] > A[largest]) largest = r;

    if (largest != i) {
        int temp = A[i];
        A[i] = A[largest];
        A[largest] = temp;
        maxHeapify(largest);
    }
}

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

    for (int i = 1; i <= H; i++) scanf("%d", &A[i]);
    for (int i = H / 2; i >= 1; i--) maxHeapify(i);
    for (int i = 1; i <= H; i++) printf(" %d", A[i]);
    printf("\n");
}



Measured memory_bytes: 3640
/// You just can't beat the person who never gives up

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

int n ;
bool Never_give_up(){
    cin >> n ;
    cout << (n+999)/1000 * 1000 - n << endl ;
    return 0 ;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" ,"r" ,stdin);
    freopen("output.txt" ,"w" ,stdout);
#endif
    int t = 1 ;
    //scanf("%d",&t);
    while(t--) Never_give_up();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

int main(){
    int n;
    cin>>n;
    int ans=inf;
    vector<int> pow6;
    vector<int> pow9;
    int pos6=1;
    while(pos6<=n){
        pow6.push_back(pos6);
        pos6*=6;
    }
    int pos9=1;
    while(pos9<=n){
        pow9.push_back(pos9);
        pos9*=9;
    }
    reverse(pow6.begin(),pow6.end());
    reverse(pow9.begin(),pow9.end());
    for(int i=0;i<=n;i++){
        int pos6=i;
        int pos9=n-i;
        int pos=0;
        for(auto p:pow6){
            pos+=(pos6/p);
            pos6-=((pos6/p)*p);
        }
        for(auto p:pow9){
            pos+=(pos9/p);
            pos9-=((pos9/p)*p);
        }
        ans=min(pos,ans);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] d = new int[N];
        for(int i = 0; i < N; i++)
            d[i] = sc.nextInt();
        
        Arrays.sort(d);
        System.out.println(d[N/2] - d[N/2-1]);
        sc.close();
    }
}

Measured memory_bytes: 50812
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/*void bti(ll n)
{
ll k=1;
  while(n!=0)
    {
    bin[k++]=n%2;
    n/=2;
    }
}*/
/*void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}*/
int main()
{
  ll n,d;
  cin>>n;
  //cout<<n<<" "<<n/2<<" "<<(n-n/2)<<" "<<(n-n/2)/n<<endl;
  printf("%0.8f\n",(double)(n-n/2)/(double)n);
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,H,W,h,w,res=0;
  cin>>n>>H>>W;
  for(int i=0;i<n;++i){
    cin>>h>>w;
    if(h>=H&&w>=W)res++;
  }
  cout<<res;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,N,0);
  rep(i,0,N)cin >> P[i];
  sum=INF;
  rep(i,-100,200){
    num=0;
    rep(j,0,N)num+=pow((P[j]-i),2);
    sum=min(num,sum);
  }
  Out(sum);
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int ans = 0;
		
		ans = n % 1000;
		
		if(ans != 0) {
			ans = 1000 - ans;
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 35808
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        long K = scan.nextLong();
        long answer = 0;
        if (K == 0) {
            System.out.println(N * N);
            return;
        }
        for (int b = 1; b <= N; b++) {
            if (b <= K) {
                continue;
            }
            long remain = N % b;
            if (K - 1 <= remain) {
                answer += remain - (K - 1);
            }
            answer += (N / b) * (b - 1 - (K - 1));
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
#include<cstdio>
int n,i,k,x,sx,y,sy;
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int main(){
	for (n=read(),x=n,i=1;i<=n;i++){
		k=read();
		if (k<x) x=k,sx=0;if (k==x) sx++;
		if (k>y) y=k,sy=0;if (k==y) sy++;
	}
	if (y-x>1){puts("No");return 0;}
	if (x==y){
		puts(x==n-1||x<=n/2?"Yes":"No");
		return 0;
	}
	y-=sx;puts(y>=1&&y<=sy/2?"Yes":"No");
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    ll ans=0;
    if(n==1)
      ans=1;
    else if(n==2)
      ans=1;
    else{
      for(int i=n+1;i<=2*n;i++){
	bool flag=true;
	for(int j=2;j<=sqrt(i);j++){
	  if(i%j==0){
	    flag=false;
	    break;
	  }
	}
	if(flag){
	  //cout<<i<<endl;
	  ans++;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define mp(x,y) make_pair(x,y)
#define ALL(a) a.begin(),a.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int,int>
#define INF 1<<29
#define MAX 1010
using namespace std;

int m,n,k,J[MAX][MAX],O[MAX][MAX],I[MAX][MAX];
string s[MAX];

void solve(){
 cin>>n>>m;
 cin>>k;
 ZERO(J); ZERO(O); ZERO(I);
 FOR(i,n) cin>>s[i];
 FOR(i,n){
  FOR(j,m){
   J[i+1][j+1]=(s[i][j]=='J')+J[i][j+1]+J[i+1][j]-J[i][j];
   O[i+1][j+1]=(s[i][j]=='O')+O[i][j+1]+O[i+1][j]-O[i][j];
   I[i+1][j+1]=(s[i][j]=='I')+I[i][j+1]+I[i+1][j]-I[i][j];
  }
 }
 int a,b,c,d;
 FOR(i,k){
  cin>>a>>b>>c>>d;
  a--; b--;
  int jj=J[c][d]-J[c][b]-J[a][d]+J[a][b];
  int oo=O[c][d]-O[c][b]-O[a][d]+O[a][b];
  int ii=I[c][d]-I[c][b]-I[a][d]+I[a][b];
  cout<<jj<<" "<<oo<<" "<<ii<<endl;
 }
}

int main(){
 solve();
 return 0;
}

Measured memory_bytes: 16020
n,m = map(int,input().split())
data = []
count = 0
a = 0
for i in range(n):
    data.append(list(map(int,input().split())))
for i in range(m):
    for j in range(n):
        a += data[j][1:].count(i+1)
    if a == n:
        count += 1
    a = 0
print(count)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        // AOJ の Hint によると、こうやるらしい。
        // 1. 1番目と2番目の数を比べて、逆順ならば交換する。
        // 2. 2番目と3番目の数を比べて、逆順ならば交換する。
        // 3. 1番目と2番目の数を比べて、逆順ならば交換する。
        // いわゆるバブルソートである。
        // まず、一番大きな数を一番下に持っていく。
        // これで一番大きな数は決まったので、その上について同じ手順を繰り返していく。

        // a < b < c の順に並ぶようにする。
        int tmp;  // swap 用の補助の変数
        if (a > b) {
            tmp = b;
            b = a;
            a = tmp;
        }
        if (b > c) {
            tmp = c;
            c = b;
            b = tmp;
        }
        if (a > b) {
            tmp = b;
            b = a;
            a = tmp;
        }
        System.out.println(""+a+' '+b+' '+c);
    }
}


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

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

}




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

using namespace std;

int main(){
  string s,t;
  cin >> s >> t;
  int count = 0;
  if ( s.at(0) == t.at(0)) count++;
  if ( s.at(1) == t.at(1)) count++;
  if ( s.at(2) == t.at(2)) count++;
  cout << count << endl;
}



Measured memory_bytes: 3644
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int A, B; cin >> A >> B;
  int ans = 0, mouse = 1;
  while(mouse < B){
    ans++;
    mouse --;
    mouse += A;
  }
  cout << ans << endl;
}


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

using namespace std;

int main(){
    int t;
    int n, k;
    int x[100000];
    int dis[100000];
    cin >> t;

    for(int input=0; input<t; ++input){
        cin >> n >> k;
        for(int i=0; i<n; ++i) cin >> x[i];
        for(int i=0; i<n-1; ++i) dis[i] = x[i+1] - x[i];
        sort(dis, dis+n-1);
        int ans = 0;
        for(int i=0; i<n-k; ++i) ans += dis[i];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1952
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 1000000000
#define inf -100000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll int n;
    cin>>n;
    ll int a[n-1];
    ll int i,z,s=0;
    ll int f[200005]={0};
    for(i=0;i<n-1;i++)
    {
    	cin>>a[i];
    	f[a[i]]++;
    }
    for(i=1;i<=n;i++)
    {
    	cout<<f[i]<<endl;
    }
}
   

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n;cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    int l = 0,r = 0;
    int ans = 0;
    vector<int> cnt(22);
    rep(i,n){
        int nextl = i,nextr = n;
        while(l < nextl){
            rep(j,22)if(a[l]>>j&1)cnt[j] = 0;
            l++;
        }
        while(r < nextr){
            bool ok = true;
            rep(j,22){
                if(a[r]>>j&1){
                    if(cnt[j])ok = false;
                }
            }
            if(ok){
                rep(j,22)if(a[r]>>j&1)cnt[j] = 1;

            }
            else break;
            r++;
        }
        ans += r - l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <tuple>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder{
    void judge_outer(bool judge_exp,string ok = "Yes",string ng = "No"){
        if(judge_exp){
            cout << ok << endl;
        }else{
            cout << ng << endl;
        }
    }
    
    int ncr(int left,int right){
        right = min(left - right,right);
        int ans =1;
        for(int i=1;i<=right;i++){
            ans = ans * (left-right+i)/i;
        }
        return ans;
    }
    
    const int LIMIT = 1000000256;
    const int tenfive = 100000;
}

using namespace atcoder;

int main(void){
    int md=LIMIT,roop,moto,stk;
    int total=0;
    cin >> roop >> moto;
    for(int i=0;i<roop;i++){
        cin >> stk;
        moto -= stk;
        md = min(md,stk);
        total++;
    }
    cout<< total+moto/md << endl;
    return 0;
}


Measured memory_bytes: 256
//%std
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
char buf[100];
int main()
{
	int n=read();
	scanf("%s",buf);
	int ans=0;
	for(int i=0;i+2<n;++i)
		if(buf[i]=='A' && buf[i+1]=='B' && buf[i+2]=='C')
			++ans;
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  int q;
  cin >> q;
  string k;
  map<string, int> M;
  while (cin >> q >> k) {
    if (q == 0) {
      int x;
      cin >> x;
      M[k] = x;
    }
    if (q == 1) {
      if (M.count(k)) {
        cout << M[k] << endl;
      } else {
        cout << 0 << endl;
      }
    }
    if (q == 2)
      M.erase(k);
    if (q == 3) {
      string r;
      cin >> r;
      auto lo = M.lower_bound(k);
      auto hi = M.upper_bound(r);
      while (lo != hi) {
        auto p = *(lo++);
        cout << p.first << " " << p.second << endl;
      }
    }
  }
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
string s; cin>>s;//入力
ll count=0,ans=0;
rep(i,s.size()){
    if(s[i] == 'B') count++;
    else
    {
        ans += count;
    }//Wより右にあるBの数を数える
    
}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3728
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,K=get_i
ans=0
MOD=10**9+7
lsum=(0..K-1).to_a.inject(:+)
rsum=(N-K+1..N).to_a.inject(:+)
ans+=(rsum-lsum+1)%MOD
(K).upto(N) do|x|
  lsum+=x
  rsum+=N-x
  ans+=rsum-lsum+1
  ans%=MOD
end
puts ans

Measured memory_bytes: 17628
from collections import defaultdict
from bisect import bisect_left
s = input()
t = input()
ids = defaultdict(list)
for i, c in enumerate(s):
    ids[c].append(i)
i = 0
ans = 0
for c in t:
    if c not in ids:
        print(-1)
        exit()
    ls = ids[c]
    j = bisect_left(ls, i)
    if j == len(ls):
        ans += len(s)
        i = ls[0]+1
    else:
        i = ls[j]+1
print(ans+i)

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

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

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

  int a, b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  bool is_prime[100000];
 
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<100000;i++){
    is_prime[i] = true;
  }
 
  for(int i=2;i*i<100000;i++){
    if(is_prime[i]){
      for(int j=i*i;j<100000;j=j+i){
        is_prime[j] = false;
      }
    }
  }
 
  while(true){
    int n;
    cin >> n;
 
    if(cin.eof())
        break;
 
    int high = n;
    int low = n;
 
    while(1){
      high = high+1;
      if(is_prime[high]){
        break;
      }
    }
 
    while(1){
      low = low-1;
      if(is_prime[low]){
        break;
      }
    }
 
    cout << low << " " << high << endl;
  }
 
  return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long x){
    cout << (x == 0 ? 1 : 0) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long x;
    scanf("%lld",&x);
    solve(x);
    return 0;
}


Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    string s;
    cin>>s;
    s[3]='8';
    cout<<s<<endl;
}


Measured memory_bytes: 764
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(n)
	inpa(a,n)
	vector<int> count(1e5+1);
	int s=0;
	fo(i,n)
	{
		s+=a[i];
		count[a[i]]++;
	}
	inp(q)
	while(q--)
	{
		inp(b) inp(c)
		s+=(c-b)*count[b];
		count[c]+=count[b];
		count[b]=0;
		cout<<s<<'\n';
	}
	printclock;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		string S; cin >> S;
		string rS = S; reverse(rS.begin(), rS.end());
		ULL ans = 0;
		rep(i, (1 << N)) {
			string R, B;
			rep(j, N) { if (i & (1 << j)) R.push_back(S[j]); else B.push_back(S[j]); }
			R.push_back(' '); B.push_back(' ');
			UL dp[19][19] = {};
			dp[0][0] = 1;
			rep(b, B.size()) {
				rep(r, R.size()) {
					if (B[b] == rS[r + b]) dp[r][b + 1] += dp[r][b];
					if (R[r] == rS[r + b]) dp[r + 1][b] += dp[r][b];
				}
			}
			ans += dp[R.size() - 1][B.size() - 1];
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
n=int(input())
W=[]
for i in range(n):
    W.append(input())

ha=0
for i in range(n-1):
    if W[i][len(W[i])-1]!=W[i+1][0] :
        ha=1
for i in range(n):
    for j in range(i+1,n):
        if W[i]==W[j] :
            ha=1

if ha==0 :
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int q;
  int c,a,n;
  int team=0;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> c >> a >> n;
    while(1){
    if(c>0 && a>0 && n>0){
      team++;
      c--;
      a--;
      n--;
    }
    else if(c>1 && a>0){
      team++;
      c-=2;
      a--;
    }
    else if(c>2){
      team++;
      c-=3;
    }
    else{
      cout << team << endl;
      break;
    }
    }
    team=0;
  }
}

Measured memory_bytes: 1160
/*
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a < in.txt > out.txt
    */

//  io
#include <iostream>
//#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
    std::ifineam inFile("input.txt");
    std::ofineam outFile("output.txt");
    std::cin.rdbuf(inFile.rdbuf());
    std::cout.rdbuf(outFile.rdbuf());
    */

int main()
{
    int n;
    cin >> n;
    arri L(n);
    //arri suf(n);

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

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

    int sum = 0;

    for (int i = 0; i < n; i++)
    {
        int q = i + 1;
        for (int p = i + 1; p < n; p++)
        {
            if (q == p)
            {
                q++;
            }
            if (q >= n)
            {
                break;
            }
            while (L[q] < L[i] + L[p])
            {
                if (q >= n)
                {
                    break;
                }
                //sum++;
                q++;
            }
            q--;
            sum += q - p;
        }
    }
    cout << sum;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      long g = gcd(a,b);
      long cnt = 1;
      if(g%2==0){
      	while(g%2==0){g/=2;}
        cnt++;
      }
      long i = 3;
      while(i <= Math.sqrt(g)){
        if(g%i==0){
      		while(g%i==0){
        		g/=i;
        	}
            cnt++;
        }
        i+=2;
      }
      if(g!=1)cnt++;
      System.out.println(cnt);
    }
    
    public static long gcd(long x, long y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}


Measured memory_bytes: 23124
def main():
    import sys
    n=int(input())
    a=list(map(int, input().split()))
    ud=[]
    ans=1
    cnt=[0,0]
    if n==1:
        print(ans)
        sys.exit()
    for i in range(n-1):
        if a[i]==a[i+1]:
            ud.append('eq')
        elif a[i]<a[i+1]:
            ud.append('up')
        elif a[i]>a[i+1]:
            ud.append('down')
    if len(set(ud))==1 or (len(set(ud))==2 and 'eq' in set(ud)):
        print(ans)
        sys.exit()
    if ud[0]=='up':
        cnt[0]=1
    elif ud[0]=='down':
        cnt[1]=1
    for i in range(1,n-1):
        if (cnt[0]==cnt[1]==0 or cnt[0]!=0) and ud[i]=='up':
            cnt[0]+=1
        elif (cnt[0]==cnt[1]==0 or cnt[1]!=0) and ud[i]=='down':
            cnt[1]+=1
        elif cnt[0]!=0 and ud[i]=='down':
            ans+=1
            cnt[0]=0
        elif cnt[1]!=0 and ud[i]=='up':
            ans+=1
            cnt[1]=0
        elif cnt[0]!=0 and cnt[1]==0 and i==n-2:
            ans+=1
        elif cnt[1]!=0 and cnt[0]==0 and i==n-2:
            ans+=1
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 14252
from collections import Counter

S = input()
s_list = []
for i, s in enumerate(S):
  if s == 'W':
    s_list.append(i)
t_list = [i for i in range(len(s_list))]
answer = 0
for i in range(len(s_list)):
  answer += s_list[i] - t_list[i]
print(answer)



Measured memory_bytes: 97884
import java.io.*;
import java.util.*;

public class Main {

	static class Poly {
		int[] coef;
		int lead;

		public Poly(int[] coef, int lead) {
			this.coef = coef;
			this.lead = lead;
		}

		void trim() {
			while (lead >= 0 && coef[lead] == 0) {
				lead--;
			}
		}
	}

	Poly getPoly() {
		String s = nextToken();
		int[] coef = new int[s.length()];
		for (int i = 0; i < s.length(); i++) {
			coef[i] = s.charAt(s.length() - 1 - i) - '0';
		}
		return new Poly(coef, coef.length - 1);
	}

	void divideLeading(Poly a, Poly b) {
		// b.lead -> a.lead
		// b.lead-1 -> a.lead-1
		for (int i = 0; i <= b.lead; i++) {
			a.coef[i + a.lead - b.lead] ^= b.coef[i];
		}
		a.trim();
	}

	Poly gcd(Poly a, Poly b) {
		if (a.lead < b.lead) {
			Poly tmp = a;
			a = b;
			b = tmp;
		}
		if (b.lead == -1) {
			return a;
		}
		divideLeading(a, b);
		return gcd(b, a);
	}

	static final int P = 998244353;

	void submit() {
		int n = nextInt();
		Poly x = getPoly();

		Poly g = getPoly();
		for (int i = 1; i < n; i++) {
			Poly p = getPoly();
			g = gcd(g, p);
		}

		int[] gcd = Arrays.copyOf(g.coef, g.lead + 1);
		
//		System.err.println(Arrays.toString(gcd));

		int[] our = Arrays.copyOf(x.coef, Math.max(x.lead + 1, gcd.length));

		int valLess = 0;
//		for (int i = gcd.length - 1; i < our.length; i++) {
		for (int i = our.length - 1; i >= gcd.length - 1; i--) {
			valLess = (valLess * 2 + our[i]) % P;
		}

		Poly xx = new Poly(x.coef.clone(), x.lead);
		for (int i = 0; i < gcd.length - 1; i++) {
			if (i < xx.coef.length) {
				xx.coef[i] = 0;
			}
		}
		xx.trim();
		while (xx.lead >= g.lead) {
			divideLeading(xx, g);
		}
		
		int[] gMult = Arrays.copyOf(xx.coef, gcd.length - 1);
		
		if (compare(gMult, Arrays.copyOf(x.coef, gcd.length - 1)) <= 0) {
			valLess++;
			if (valLess >= P) {
				valLess -= P;
			}
		}
		
		out.println(valLess);
	}
	
	int compare(int[] a, int[] b){
		if (a.length != b.length) {
			throw new AssertionError();
		}
		
		for (int i = b.length - 1; i >= 0; i--) {
			if (a[i] != b[i]) {
				return a[i] < b[i] ? -1 : 1;
			}
		}
		return 0;
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


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

#define ll long long

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

    cin >> a;
    cin >> s;

    cout << (a >= 3200?s:"red") << endl;

    return 0;
}



Measured memory_bytes: 256
def main():
    N = int(input())
    A = [input() for i in range(N)]
    from itertools import combinations
    S = {"M": 0, "A": 1, "R": 2, "C": 3, "H": 4}
    ans = 0
    cnt = [0]*5
    for a in A:
        c = a[0]
        if c in S.keys():
            cnt[S[c]] += 1
    for comb in combinations(range(5), 3):
        ans += cnt[comb[0]]*cnt[comb[1]]*cnt[comb[2]]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 54616
n,m = map(int,input().split())
possible = [0]*n
kosuu = [1]*n
possible[0] = 1
L = []

for i in range(m):
    x,y = map(int,input().split())
    L.append((x,y))

for i in range(m):
    x,y = L[i][0],L[i][1]
    x,y = x-1,y-1
    if kosuu[x] >=2 and possible[x] == 1:
        possible[y] = 1
        kosuu[x] -=1
        kosuu[y] +=1
    elif kosuu[x] == 1 and possible[x] == 1:
        possible[x] = 0
        possible[y] = 1
        kosuu[x] = 0
        kosuu[y] +=1
    elif kosuu[x] >=2 and possible[x] == 0:
        kosuu[x] -=1
        kosuu[y] +=1
    elif kosuu[x] == 1 and possible[x] == 0:
        kosuu[x] = 0
        kosuu[y] +=1
print(sum(possible))

Measured memory_bytes: 23808
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
struct pnt{
  double x,y;
  bool operator>(const pnt &key)const{
      if(this->x==key.x)return this->y>key.y;
      return this->x>key.x;
  }
  pnt operator+(pnt key){
      pnt res;res.x=x+key.x,res.y=y+key.y;
      return res;
  } 
  pnt operator-(pnt key){
      pnt res;res.x=x-key.x,res.y=y-key.y;
      return res;
  }  
  pnt operator*(double key){
      pnt res;res.x=x*key,res.y=y*key;
      return res;
  }
  pnt operator/(double key){
      pnt res;res.x=x/key,res.y=y/key;
      return res;
  }
  double abs(){
      return sqrt(x*x+y*y);
  }
};
double dot(pnt a,pnt b){
    return a.x*b.x+a.y*b.y;
}
double dis(pnt a,pnt b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
pnt polar(double theta){
    pnt res;res.x=cos(theta);res.y=sin(theta);
    return res;
}
pair<pnt,pnt> koten(pnt c1,double r1,pnt c2,double r2){
    double di=dis(c1,c2);
    double theta=acos((-r2*r2+r1*r1+di*di)/(2*r1*di));
    double shita=atan2(c2.y-c1.y,c2.x-c1.x);
    pnt res1=c1+polar(shita+theta)*r1;
    pnt res2=c1+polar(shita-theta)*r1;
    //cout<<(-r2*r2+r1*r1+di*di/(2*r1*di))<<endl;
    //cout<<theta<<" "<<shita<<endl;
    return make_pair(res1,res2);
}
void inn(pnt & a){
    cin>>a.x>>a.y;
}
int main(){
    //ll q;cin>>q;
    //while(q--){
	pnt c1,c2;double r1,r2;
	inn(c1); cin>>r1;
	inn(c2); cin>>r2;
	pair<pnt,pnt> res=koten(c1,r1,c2,r2);
	if(res.first>res.second)swap(res.first,res.second);
	cout<<fixed<<setprecision(9)<<res.first.x<<" ";
	cout<<fixed<<setprecision(9)<<res.first.y<<" ";
	cout<<fixed<<setprecision(9)<<res.second.x<<" ";
	cout<<fixed<<setprecision(9)<<res.second.y<<endl;
    //}
    return 0;
}



Measured memory_bytes: 3680
def main():
	'''
	メイン関数
	'''
	# 文字列の長さN, 整数K
	N, K = map(int, input().split())

	# 文字列
	S = input()

	# 表示
	for i in range(0,N) :
		if i == K-1 :
			print(S[i].lower() , end="")
		else :
			print(S[i], end="")



if __name__ == '__main__':
	main()


Measured memory_bytes: 3060
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n,m;
int dp[6005][3005][2];
inline void add(int &x,int y){
	x+=y;if(x>=mod)x-=mod;
}
int main(){
	cin>>n>>m;
	for(int i=0;i<=n;i++){
		dp[0][i][i==0]=1;
	}
	for(int i=0;i<m*2;i++){
		for(int j=0;j<=n;j++){
			for(int p=0;p<2;p++){
				if(i%2==0){
					//first
					if(j)add(dp[i+1][j][p|(j-1==0)],dp[i][j][p]);
					if(j<n)add(dp[i+1][j+1][p],dp[i][j][p]);
				}else{
					//second
					if(j)add(dp[i+1][j-1][p|(j-1==0)],dp[i][j][p]);
					if(j<=n)add(dp[i+1][j][p],dp[i][j][p]);
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++){
		add(ans,dp[m*2][i][1]);
	}
	cout<<ans<<endl;
	return 0;
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int a[2000][2000];
int b[2000];
int upd[2000];

int main(){
	int n;cin>>n;
	rep(i,n)rep(j,n-1){
		scanf("%d",&a[i][j]);a[i][j]--;
	}
	queue<P>que;
	rep(i,n){
		for(int j=i+1;j<n;j++){
			if(a[i][0]==j&&a[j][0]==i){
				que.push(P(i,1));
				que.push(P(j,1));
				upd[i]=1;upd[j]=1;
				b[i]++;b[j]++;
			}
		}
	}
	int Max=0;
	while(!que.empty()){
		P p=que.front();que.pop();
		Max=max(Max,p.second);
		if(b[p.first]==n-1)continue;
		int nx=a[p.first][b[p.first]];
		if(a[nx][b[nx]]==p.first){
			b[p.first]++;
			b[nx]++;
			int tim=max(upd[p.first],upd[nx])+1;
			upd[p.first]=tim;
			upd[nx]=tim;
			que.push(P(p.first,tim));
			que.push(P(nx,tim));
		}
	}
	rep(i,n){
		if(b[i]!=n-1){
			puts("-1");return 0;
		}
	}
	cout<<Max<<endl;
}


Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <set>
#include <unordered_set>
#include <map>
#include <cmath>
#include <deque>
#include <queue>
#include <string>
#include <cstring>
#include <stack>

using namespace std;
typedef long long ll;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define V vector

V<ll> cache;
ll X;

void solve() {
    ll t, prev = 0;
    REP(i, 1, X+1){
        prev = t;
        t = ll(pow(i, 5));
        if(t == X) {
            cout << cache.size()+1 << " " << 0 << "\n";
            return;
        }
        if(t - prev > X) break;
        cache.PB(t);
    }

    int l = 0, r = cache.size()-1;
    while(l <= r) {
        t = cache[l] + cache[r];
        if (t == X) {cout << r+1 << " " << -l-1 << "\n"; return;}
        if (t < X) l += 1;
        else r -= 1;
    }
    l = 0;
    r = 0;
    int N = cache.size();
    while (r < N) {
        t = cache[r] - cache[l];
        if (t == X) {cout << r+1 << " " << l+1 << "\n"; return;}
        if (t < X) r += 1;
        else l += 1;
    }
    return;
}

int main() {
    cin >> X;
    solve();
    return 0;
}



Measured memory_bytes: 3596
def main():
    n = int(input())
    a, b = map(int, input().split())
    scores = list(map(int, input().split()))

    r1 = len(list(filter(lambda x: x <= a, scores)))
    r2 = len(list(filter(lambda x: a < x <= b, scores)))
    r3 = len(list(filter(lambda x: b < x, scores)))

    print(min(r1,r2,r3))


    return

main()

Measured memory_bytes: 3060
n = gets.to_i
arr = gets.split.map(&:to_i)
i = 1
res = 0
while i < n - 1
  res += 1 if (arr[i-1] < arr[i] && arr[i] < arr[i+1]) || (arr[i-1] > arr[i] && arr[i] > arr[i+1])
  i += 1
end
puts res

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

int main()
{
	int N, x;
	cin >> N >> x;
	int a[101];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N);
	int sum = 0;
	int max = 0;
	for (int i = 0; i < N; i++) {
		sum += a[i];
		if (sum > x) {
			break;
		}
        max = i + 1;
	}
	if (max == N && x > sum) {
		max = N - 1;
	}
	cout << max << endl;
}

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

int main(){
  int X,Y,a,count=0;
  cin>>X>>Y;
  for(int a=0; a<=X; a++){
    int b=X-a;
    if(2*a+4*b==Y){
      count++;
    }
  }
  if(count>0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
    

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

using namespace std;
const double PI=3.14159265358979323846;

int main() {

	int N, M;

	cin >> N >> M;

	int count = 0;

	int tmp;
	for (int i = 0; i < M; i++) {
		cin >> tmp;
		count += tmp;
	}

	int ans = N >= count ? N - count : -1;
	cout << ans << endl;
}

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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a;
  string s;
  cin>>a>>s;
  cout<<(a>=3200 ? s : "red")<<endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = nextInt()
    val XY = Array<Pair<Int, Int>>(N) { listOfIntToPair(listOfInt(0)) }
    val A = Array<Int>(N) { 0 }
    var F = 0
    fun D(n: Int, m: Int): Double = Math.sqrt(Math.pow((XY[n].first - XY[m].first).toDouble(), 2.0) + Math.pow((XY[n].second - XY[m].second).toDouble(), 2.0))
    var sum: Double = 0.0
    fun P(n: Int) {
        if (n == N) {
            F += 1
            for (m in 0 until N-1) {
                sum += D(A[m], A[m + 1])
            }
        } else {
            for (m in 0 until N) {
                var f = true
                for (x in 0 until n) if (A[x] == m) f = false
                if (f) {
                    A[n] = m
                    P(n + 1)
                }
            }
        }
    }
    P(0)
    var ans = sum / F.toDouble()
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun listOfIntToPair(p: List<Int>): Pair<Int, Int> = Pair(p[0], p[1])

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

// Contest: AtCoder Beginner Contest 142 (https://atcoder.jp/contests/abc142)
// Problem: D: Disjoint Set of Common Divisors (https://atcoder.jp/contests/abc142/tasks/abc142_d)

using namespace std;

using ll = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;

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

    set<int> fa, fb;
    ll a, b; cin >> a >> b;
    for (ll i = 2; i * i <= a; ++i) {
        if (a % i)
            continue;
        fa.emplace(i);
        while (a % i == 0)
            a /= i;
    }
    if (a > 1)
        fa.emplace(a);
    for (ll i = 2; i * i <= b; ++i) {
        if (b % i)
            continue;
        fb.emplace(i);
        while (b % i == 0)
            b /= i;
    }
    if (b > 1)
        fb.emplace(b);
    int c = 0;
    for (auto d : fa)
        if (fb.count(d))
            ++c;

    cout  << (c + 1) << '\n';
    return 0;
}


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

#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 103;
int n, g[N][N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			g[i][j] = 1;
		}
	}
	int k = n;
	if (n & 1) {
		k--;
	}
	for (int i = 1; i <= n / 2; i++) {
		g[i][k - i + 1] = 0;
	}
	vector <pii> vec;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (g[i][j]) {
				vec.pb({i, j});
			}
		}
	}
	cout << vec.size() << '\n';
	for (auto i : vec) {
		cout << i.F << ' ' << i.S << '\n';
	}
}


Measured memory_bytes: 384
#include <iostream>

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

using namespace std;

int main(){
	int n;
	cin >> n;
	if(n%10==9 || n/10==9){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;	
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    vector<int> a(n);
    for(int i=0;i<n;i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    int ans=1;
    for(int i=1;i<n;i++) {
        if(a.at(i-1)!=a.at(i)) {
            ans++;
        }
    }
    if(ans%2==0) ans--;

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


Measured memory_bytes: 640
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        set<string> st;
        while (n--) {
            string s;
            cin >> s;
            st.insert(s);
        }
        cout << st.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 19300
S = input()
T = input()
n = len(S)
m = len(T)
L = [0]*(n+1)
R = [0]*(m+1)
for i, s in enumerate(S):
  if s == "A":
    L[i+1] = (L[i]+1)%3
  else:
    L[i+1] = (L[i]-1)%3
for i, t in enumerate(T):
  if t == "A":
    R[i+1] = (R[i]+1)%3
  else:
    R[i+1] = (R[i]-1)%3
q = int(input())
for _ in range(q):
  a, b, c, d = map(int, input().split())
  if (L[b]-L[a-1])%3 == (R[d]-R[c-1])%3:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 5236
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,ans=0;
    cin>>n>>k;
    
    int freq[n];
    for(int i=0;i<n;i++)
        freq[i]=0;
    for(int i=0;i<k;i++)
    {
        int d;
        cin>>d;
        
        for(int i=0;i<d;i++)
        {
            int temp;
            cin>>temp;
            freq[temp-1]++;
        }
    }
    
    for(int i=0;i<n;i++)
    {
        if(freq[i]==0)
        {
            ans++;
        }
    }
    
    cout<<ans;
}

Measured memory_bytes: 3640
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
A = LIST()

B = [0] * N
for i, a in enumerate(A):
    if a > 0:
        B[i] = a

acc = [0] + list(accumulate(A))
acc2 = [0] + list(accumulate(B))
acc2rev = [0] + list(accumulate(B[::-1]))[::-1] + [0]

ans = -INF
for i in range(1, N-K+2):
    cnt = max(acc[i+K-1] - acc[i-1], 0)
    cnt += acc2[i-1] + acc2rev[i+K]
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 24128