akhauriyash/Code-Regression huggingface dataset:
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
        int n=ni(),arr[]=new int[n+1],cnt=0;
        for(int i=1;i<=n;i++) arr[i]=ni();

        for(int i=1;i<=n;i++)
            if(arr[i]!=i)
                cnt++;
        pn((cnt==0 || cnt==2)?"YES":"NO");
    }


    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();

        long s = System.currentTimeMillis();
        int t=1;
        //t=ni();
        while(t-->0)
            process();

        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;
    static long mod=(long)1e9+7l;

    static<T> void r_sort(T arr[],int n){
        Random r = new Random(); 
        for (int i = n-1; i > 0; i--){ 
            int j = r.nextInt(i+1); 
                  
            T temp = arr[i]; 
            arr[i] = arr[j]; 
            arr[j] = temp; 
        } 
        Arrays.sort(arr); 
    }
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } 
            catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 21972
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;

bool calc(int i){
    if(i%10 == i/10%10 && i/10%10 == i/100%10)return true;
    return false;
}

int main(){
    INIT;
    cin >> n;
    while(true){
        if(calc(n)){
            cout << n << endl;
            return 0;
        }
        n++;
    }
}

Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
using namespace std;
typedef pair<double,double> P;
int b[19][19];


int main(){
	
	int n,m,a;
	while(cin>>n>>m>>a,n!=0||m!=0||a!=0){
		vector< vector<int> > kuji(1020,vector<int>(2*n+10));
		int h,p,q;
		for(int i=0;i<m;i++){
			cin>>h>>p>>q;
			kuji[h][2*max(p,q)-2]=1;
			
		}
		int now=2*a-1;
		for(int i=1000;i>=0;i--){
			if(kuji[i][now-1])
				now-=2;
			else if(kuji[i][now+1])
				now+=2;
			
		}
		cout<<now/2+1<<endl;
	}
	
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int e, y;
    cin >> e >> y;
    if(e == 0){
        if(1868 <= y && y <= 1911){
            cout << "M" << y - 1867 << endl;
        }
        else if(1912 <= y && y <= 1925){
            cout << "T" << y - 1911 << endl;
        }
        else if(1926 <= y && y <= 1988){
            cout << "S" << y - 1925 << endl;
        }
        else if(1989 <= y && y <= 2016){
            cout << "H" << y - 1988 << endl;
        }
    }
    else if(e == 1){
        cout << y + 1867 << endl;
    }
    else if(e == 2){
        cout << y + 1911 << endl;
    }
    else if(e == 3){
        cout << y + 1925 << endl;
    }
    else if(e == 4){
        cout << y + 1988 << endl;
    }

    return 0;
}

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

int main(void) {
  int A, B;
  cin >> A >> B;
  int ans = -1;
  for (int i = 100000; i >= 0; i--) {
    if ((int)(i * 0.08) == A && (int)(i * 0.1) == B) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    long a[200];
    cin>>n;
    for(int i=0; i<n; ++i) {
        cin>>a[i];
        if(a[i]%2==0) {
            a[i]/=2;
        } else {
            cout<<0<<'\n';
            return 0;
        }
    }
    int s=1;
    for(int i=2; i>0; ++i) {
        for(int j=0; j<n; ++j) {
            if(a[j]%2==1) {
                cout<<s<<'\n';
                return 0;
            } else {
                a[j]/=2;
            }
        }
        ++s;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string a,b;
  	cin>>a>>b;
  	int num =0;
  for(int i=0 ;i<3; ++i){
   	  
    if(a[i]==b[i])num++;
  }
  cout<<num;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin >> s;
    bool can = true;
    rep(i,s.size()){
        if(i%2==0 and s[i]=='L')can = false;
        if(i%2!=0 and s[i]=='R')can = false;
    }
    
    if(can)cout << "Yes";
    else cout << "No";
   
   
	return 0;
}

Measured memory_bytes: 3628
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:i32 = read();
    let a:i32 = read();
    let b:i32 = read();

    println!("{} {}", min(a,b), max(0,a+b-n));
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
int main() {
  int *a,n,j,i;
  int count=0,tmp=0;
  scanf("%d",&n);
  a=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
      scanf("%d",&a[i]);
  }
  for (i = 0; i < n; i++) {
    for (j = n-1 ; j >=1 ; j--) {
      if (a[j]<a[j-1]) {
        tmp=a[j-1];
        a[j-1]=a[j];
        a[j]=tmp;
        count++;
      }
    }
}
  for(i=0;i<n;i++){
    if (i!=n-1) printf("%d ",a[i]);
    else printf("%d\n",a[i]);
  }
  printf("%d\n",count);
  return 0;
}


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

typedef long long ll;
 
int main(){
  ll n, k;
  cin >> n >> k;

  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    a[i]--;
  }
  
  vector<ll> s(n, -1);
  vector<ll> m(n);
  s[0] = 0;
  m[0] = 0;
  int t = 0;
  ll i = 1, lp, bef;
  bool nreach = false;
  while(true){
    t = a[t];
    if(s[t]!=-1){
      lp = i - s[t];
      if(k < s[t]) nreach = true;
      else k -= s[t];
      break;
    }
    m[i] = t;
    s[t] = i;
    i++;
  }
  if(nreach){
    cout << ++m[k] << endl;
    return 0;
  }
  cout << ++m[s[t]+k%lp] << endl;
  return 0;
  
}


Measured memory_bytes: 7164
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int n;
	cin>>n;
	int a[10][10];
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			a[i][j]=0;
		}
	}
	int dg=1;
	for(int i=1;i<=n;i++)
	{
	    if(i==10)dg=2;
	    else if(i==100)dg=3;
	    else if(i==1000)dg=4;
	    else if(i==10000)dg=5;
	    else if(i==100000)dg=6;
		a[i/(int)pow(10,dg-1)][i%10]++;
	}
	ll sum=0;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			sum+=a[i][j]*a[j][i];
		}
	}
	cout<<sum;
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

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

int n, m, p[11], c[11], f[2004510];

int main()
{
	scanf("%d%d", &n, &m);
	m /= 100;
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &p[i], &c[i]), c[i] /= 100;
	memset(f, 63, sizeof(f));
	f[0] = 0;
	int s = 0;
	for (int i = 1; i <= n; i++)
	{
		s += p[i] * i + c[i];
		for (int j = s; j >= 0; j--)
		{
			for (int k = 1; k < p[i]; k++)
				if (j >= i * k)
					f[j] = min(f[j], f[j - i * k] + k);
			if (j >= p[i] * i + c[i])
				f[j] = min(f[j], f[j - i * p[i] - c[i]] + p[i]);
		}
	}
	int ans = 2147483647;
	for (int i = m; i <= s; i++) ans = min(ans, f[i]);
	printf("%d\n", ans);
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, K;
int A[100010], B[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if ((A[i]|K) == K) ans += B[i];
  }
  for (int i = 0; i < 30; i++) {
    if (!(K >> i & 1)) continue;
    int K2 = (1 << i) - 1;
    for (int j = i+1; j < 30; j++) {
      K2 += (K >> j & 1) << j;
    }
    ll sub = 0;
    for (int j = 0; j < N; j++) {
      if ((A[j]|K2) == K2) sub += B[j];
    }
    ans = max(ans, sub);
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  int count = 0;
  if (N > 1) {
    count += N * (N - 1) / 2.0;
  }
  
  if (M > 1) {
    count += M * (M - 1) / 2.0;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
n, m = map(int, input().split())
people =[]
food=[]
for i in range(n):
    people.append(list(map(int, input().split())))
common = {k for k in range(1, 31)}
for j in range(n):
    people[j].pop(0)
    common = common & set(people[j])
print(len(common))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

template <typename T>
struct BIT {
  int n;          // 配列の要素数(数列の要素数+1)
  vector<T> bit;  // データの格納先
  BIT(int n_) : n(n_+1), bit(n, 0) {}

  void add(int i, T x) {
    for (int idx=i; idx<n; idx+=(idx & -idx)){
      bit[idx] += x;
    }
  }

  T sum(int i) {
    T s(0);
    for (int idx=i; idx>0; idx -= (idx & -idx)){
      s += bit[idx];
    }
    return s;
  }

  T query(int l, int r) { return sum(r-1) - sum(l-1); }

  int lower_bound(T w) { 
    if (w <= 0) {
      return 0;
    }else{
      int x = 0, r = 1;
      while (r < n) r = r << 1;
      for (int len = r; len > 0; len = len >> 1) { // 長さlenは1段下るごとに半分に
        if (x + len < n && bit[x + len] < w) { // 採用するとき
          w -= bit[x + len];
          x += len;
        }
      }
      return x + 1;
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,q; cin >> n >> q;
  BIT<ll> bt(n);
  REP(i,n){
    ll a; cin >> a;
    bt.add(i+1, a);
  }

  while(q--){
    int t; cin >> t;
    if(t==0){
      int p,x; cin >> p >> x;
      p++;
      bt.add(p, x);
    }else{
      int l,r; cin >> l >> r;
      l++, r++;
      cout << bt.query(l, r) << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 8256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n,k; cin >> n >> k;
    int ans = k;
    for (int i = 1; i <= n-1; i++)
    {
        ans *= k-1;;
    }
    cout << ans << endl;
    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);
        
        double n = Double.parseDouble(sc.next());
        double k = Double.parseDouble(sc.next());
        
        int ans = (int)Math.ceil((n-1) / (k-1));
        System.out.println(ans);
    }
}

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rep2(i, j, N, M) rep(i, N) rep(j, M)
#define rep3(i, j, k, N, M, L) rep(i, N) rep(j, M) rep(k, L)
#define REP(i, init, N) for (int i = (init); i < (N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int N, M;

vector<pair<int, PII>> packets;

int solve() {
    VB bads(N);
    bads[0] = true;

    sort(ALL(packets));

    for (auto &p : packets) {
        bads[p.snd.snd] = bads[p.snd.snd] | bads[p.snd.fst];
    }

    return count(ALL(bads), true);
}

int main(void) {
    while (cin >> N >> M, N) {
        packets.clear();
        rep(i, M) {
            int t, s, d;
            cin >> t >> s >> d;
            --s; --d;
            packets.PB(MP(t, MP(s, d)));
        }

        cout << solve() << endl;
    }

	return 0;
}

Measured memory_bytes: 1680
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll N; cin >> N;
    ll ans = 0;
    for(ll i = 1; i * i < N; i++){
        if(N % i == 0){
            ll m = N / i - 1;
            if(m > i){
                ans += m;
                //cout << N << " " << i << " " << m << endl;
            }
            
        }
    }
    cout << ans << endl;
    
}

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

int INF = 1'000'000'000;

int main(){
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> max_a(n, 0);
    for (int i = n - 2; i >= 0; i--){
        max_a[i] = max(max_a[i + 1], a[i + 1]);
    }
    int max_num = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++){
        if (max_a[i] - a[i] > max_num){
            max_num = max_a[i] - a[i];
            cnt = 1;
        }
        else if (max_a[i] - a[i] == max_num) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    a, b = i_map()

    print((b-a)*(b-a+1)//2-b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10444
///============================================================================
/// Name        : Faisal.cpp
/// Author      : Faisal Ahmed
/// Version     :
/// Copyright   : Your copyright notice
/// Description : C++, Ansi-style
///============================================================================

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	string str;

	cin >> str;

	int len = str.size();
	int ans = 0;

	for(int i = len - 2; i >= 0; i--){
        if(str[i] != str[i + 1]){
            ans++;
        }
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,m,a[100005]={},b[100005]={},ans=0,x,y;
  cin >> n >> m;
  for(int i=0; i<=n; i++) {
    b[i]=1;
  }
  a[1]=1;
  for(int i=0; i<m; i++) {
    cin >> x >> y;
    if(a[x]==1) {
      a[y]=1;
      if(b[x]!=1) {
        a[x]=1;
      }
      else {
        a[x]=0;
      }
      b[x]--,b[y]++;
    }
    else {
      b[x]--,b[y]++;
    }
  }
  for(int i=1; i<=n; i++) {
    if(a[i]==1) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int k, x; cin >> k >> x;
    cout << (500*k >= x ? "Yes" : "No") <<'\n'; 
}

Measured memory_bytes: 256
#include <iostream> 
using namespace std;
int main(){
	int n,x,a;
    while(true){
        cin>>n>>x;
        if(n==0 && x==0){
			break;
			} 
        a=0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(x-i-j>j && x-i-j<=n){
                    a=a+1;
                }
            }
        }
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
ll n, s;
vector<ll> vec;
int main(void){
    // Your code here!
    cin >> n >> s;
    if (n <= s) {
        cout << (n == s ? n + 1 : -1) << endl;
        return 0;
    }
    for (ll i = 1; i <= sqrt(n - s); i++){
        if ((n - s) % i) continue;
        vec.push_back(i);
        vec.push_back((n - s) / i);
    }
    sort(vec.begin(), vec.end());
    for (ll i = 0; i < vec.size(); i++){
        ll b = vec[i] + 1, ketawa = 0, warareru = n;
        while(warareru){
            ketawa += warareru % b;
            warareru /= b;
        }
        if (ketawa == s){
            cout << b << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
// 2018/07/02 Tazoe

#include <iostream>
using namespace std;

// 最大公約数（ユークリッドの互除法）
int gcd(int x, int y)
{
	if(y==0)
		return x;

	return gcd(y, x%y);
}

int main()
{
	int x, y;
	cin >> x >> y;

	int g = gcd(x, y);

	// (横方向の交点数)+(縦方向の交点数)-(重なる交点数)
	cout << (x+1)+(y+1)-(g+1) << endl;

	return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
main() {
	int n=read();
	cout<<3*n*n;	
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

const int N = 51;
const int M = 2501;

typedef long long LL;

LL dp[N][M];
int n, m, x, sum, a[N];

int main(){
	scanf("%d %d", &n, &m);
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	sum = 0;
	for(int i=0; i<n; i++){
		scanf("%d", &x);
		sum += x;
        for(int j=i; j>=0; j--){
            for(int k=sum; k>=x; k--){
				dp[j+1][k] += dp[j][k-x];
            }
        }
	}
	LL ans = 0;
	for(int i=1; i<=n; i++){
		ans += dp[i][i*m];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {

	long long n, m;

	int ans = 0, cnt=0;
	cin >> n >>  m;
	string s;
	vector<int> w(100005);
	map<int, int> ac;
	long long p;
	rep(i, m) {
		cin >> p >> s;
		if (ac[p]==0&&s=="WA") {
			w[p]++;
		}else if(ac[p]==0 && s == "AC") {
			cnt += w[p];
			ac[p]++;
			ans++;
		}
	}
	cout << ans <<" "<< cnt;
}

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

#define llint long long int

using namespace std;

int main(){
    int N;

    cin >> N;

    vector<int> a(N);

    int all = 0;

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

        all ^= a[i];
    }
    for(int i = 0; i < N; i ++){
        cout << (int) (all ^ a[i]) << " ";
    }
    cout << endl;
}

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

int main() {
	long long N, ans, tmp;
	cin >> N;
	tmp = N;
	for (long long i = 1; i*i <= N; i++) {
		if (N%i) continue;
		long long j = N / i;
		ans = min(tmp, i + j - 2);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int tf[256];
	int n,m,i,j;
	char a,b,c;


	while( scanf("%d\n",&n) ){
		if(n == 0){
			return 0;
		}

		for(i = 0;i < 256;i++){
			tf[i] = i;
		}

		for(i = 0;i < n;i++){
			scanf("%c %c\n",&a,&b);
			tf[(int)a] = (int)b;
		}

		scanf("%d\n",&m);
		for(j = 0;j < m;j++){
			scanf("%c\n",&c);
			printf("%c",tf[(int)c]);
		}
		printf("\n");
	}

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
const int N=55;
ll fact[N],inv[N];

bool comp(PLL & a,PLL & b)
{
    if(a.S==b.S)
        return a.F<b.F;
    return a.S>b.S;
}
void solve()
{
    ll n;
    cin>>n;
    map<ll,ll> a,b;
    fr(i,0,n)
    {
        ll x;
        cin>>x;
        if(i%2==0)
        {
            a[x]+=1;
        }
        else
        {
            b[x]+=1;
        }
    }
    ll ans=inf,ans2=inf;
    vector<PLL> arr1,arr2;
    for(auto i: a)
    {
        arr1.pb(i);
    }
    for(auto j:b)
    {
        arr2.pb(j);
    }

    sort(ALL(arr1),comp);
    sort(ALL(arr2),comp);
    ll tmp=n/2;
    if(arr1[0].F!=arr2[0].F)
    {
        //cout<<"up\n";
        // cout<<SZ(<<" "<<arr1[0].S<<endl;
        // cout<<tmp<<" "<<arr2[0].S<<endl;
        ans2=(tmp-arr1[0].S)+(tmp-arr2[0].S);
    }
    else
    {
        if(SZ(arr2)==1)
            ans2=min(ans2,(tmp-arr1[0].S)+(tmp));
        else
            ans2=min(ans2,(tmp-arr1[0].S)+(tmp-arr2[1].S));
        if(SZ(arr1)==1)
            ans2=min(ans2,(tmp)+(tmp-arr2[0].S));
        else
            ans2=min(ans2,(tmp-arr1[1].S)+(tmp-arr2[0].S));
           
    }
    cout<<ans2<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 11800
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int K;
	string S;
	cin >> K >> S;
	int n = SZ(S);
	if (n > K) {
		S = S.substr(0, K) + "...";
	}
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 3616
while True:
    N=input()
    if N==0:break
    L=[]
    for i in range(N):
        a,b=raw_input().split()
        L.append((a,1))
        L.append((b,-1))
    L.sort()
    maxInt=temp=0
    for i in range(2*N):
        if L[i][1]==1:
            temp+=1
        else:
            temp-=1
        maxInt=max(maxInt,temp)
    print maxInt

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define S second
#define F first
const int  MOD = 1e9 + 7;
const int  N = 2e5 + 7;
ll n , h[N], a[N] , bit[N];
 
void update(int x, ll delta)
{
    for(; x <= n; x += x&-x)
        bit[x] = max(bit[x], delta);
}
ll query(int x)
{
    ll sum = 0;
    for(; x > 0; x -= x&-x)
        sum =max(sum,bit[x]);
    return sum;
}


//  a d f j k  l  ;
int main(){
    ios::sync_with_stdio(0);  cin.tie(0);
    cin>>n;
    for(int i = 1 ; i <= n ; i++) cin>>h[i];
    for(int i = 1 ; i <= n ; i++) cin>>a[i];

    ll ans = 0; 
    for(int i = 1 ; i <= n ; i++){
        ll up = a[i]+query(h[i]-1);
        ans = max(ans, up);
        update(h[i],up);
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int c[100005];
int main(){
    int n;
    cin >> n;
    int p[n];
    int ans=0;
    for(int i=0;i<n;i++){
        cin >> p[i];
        if(p[i]==(i+1))c[i]++;
    }
    for(int i=0;i<n;i++){
        if(c[i]==1){
            c[i]=0;
            if(i<n-1)c[i+1]=0;
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4420
def main():
    n = int(input())
    a = list(map(int,input(' ').split(' ')))
    l = int(bin(a[-1]^a[1]),2)
    r = a[0]
    for i in range(1,n):
        l = int(bin(l^(a[i-1]^a[(i+1)%n])),2)
        r = int(bin(r^a[i]),2)
    return r==l

if __name__ == '__main__':
    if main():
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 14116
#include<iostream>
#define n 39
using namespace std;

int main(){
	
	int c;
	while(cin>>c){
		int s=c%n;
	if(s==0)
		cout<<"3C39"<<endl;
	else if(s<=9)
		cout<<"3C0"<<s<<endl;
	else if(s<=38)
		cout<<"3C"<<s<<endl;
	
		}
	
	
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;

const lld M = 1000000007;
const int MAXN = 200002;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int arr[n+1];
  for (int i = 1; i <= n; ++i) 
    cin >> arr[i];

  bool can = true;
  int ans[n+1];
  for (int i = n; i; --i) {
    int idx = -1;
    for (int j = 1; j <= i; ++j) {
      if (arr[j] == j) idx = j;
    }
    if (idx == -1) {
      can = false;
      break;
    }
    ans[i] = idx;
    for (int j = idx; j < i; ++j) {
      arr[j] = arr[j+1];
    }
  }
  if (can) {
    for (int i = 1; i <= n; ++i)
      cout << ans[i] << "\n";
  } else {
    cout << "-1\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int ans[100100];

int main() {
  string s;
  cin >> s;
  int N = s.length();

  int ref = 0;
  int r_num = 0;
  int l_num = 0;
  int put_r = 0;

  while(ref<N-1){
    while(s[ref]=='R'){
      ++r_num;
      ++ref;
    }
    put_r = ref-1;

    while(s[ref]=='L'){
      ++l_num;
      ++ref;
    }

    if((r_num+l_num)%2==0){
      ans[put_r] = (r_num+l_num)/2;
      ans[put_r+1] = (r_num+l_num)/2;
    }
    else{
      if(r_num>l_num && max(r_num,l_num)%2==1){
        ans[put_r] = (r_num+l_num)/2+1;
        ans[put_r+1] = (r_num+l_num)/2;
      }
      else if(r_num<l_num && max(r_num,l_num)%2==0){
        ans[put_r] = (r_num+l_num)/2+1;
        ans[put_r+1] = (r_num+l_num)/2;
      }
      else{
        ans[put_r] = (r_num+l_num)/2;
        ans[put_r+1] = (r_num+l_num)/2+1;
      }
    }

    r_num=0;
    l_num=0;
  }

  FOR(i,0,N-1){
    cout << ans[i] << " ";
  }

  cout << endl;

}



Measured memory_bytes: 1024
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<29)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    string n;
    int ans = 0;
    cin >> n;
    for (int i = 0; i <= 3; i++) {
        if (n[i] == '2')ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n,m,x;
	cin >> n >> m >> x;
	map<int,int> a;
	for(int i = 1;i < n;i++)
	{
		a[i] = 0;
	}
	for(int i = 0;i < m;i++)
	{
		int b;
		cin >> b;
		a[b] = 1;
	}
	int mae=0,ato=0;
	for(int i = x - 1;i > 0;i--)
	{
		mae += a[i];
	}
	for(int i = x + 1;i < n;i++)
	{
		ato += a[i];
	}
    cout << min(mae,ato) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n[101];
  int i;
  int num;
  cin >> num;
  for(i=0;i<num;i++) cin >> n[i];
  cout << n[num-1];
  for(i=1;i<num;i++) cout <<" "<< n[num-i-1];
  cout << endl;
  return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define For(i, a, b)  for(int i = a, _b = b; i <= _b; ++i)
#define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i)
#define FileName      "test"
#define ll            long long
#define ld            long double
#define ull           unsigned long long
#define Print(x)      cerr << #x << "is " << x << '\n';
#define pb            push_back
#define X             first
#define Y             second
//#define Karma

using namespace std;

template<typename T> inline void Cin(T &x)
{
    char c;
    T sign = 1;
    x = 0;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        if (c == '-') sign = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
    x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}

typedef pair<int, int> pii;
typedef pair<ll, int> plli;
const int N = 1e6 + 7;
const int M = 1e5 + 7;
const ll oo = 1e18 + 7;
const ld pi = 3.1415926535897;

ll h[N], f[N], n, k;

void Enter()
{
     Cin(n, k);
     For(i, 1, n) Cin(h[i]);
}

void Solve()
{
     f[1] = 0;
     For(i, 2, k)
     {
         f[i] = oo;
         For(j, 1, i - 1)
             f[i] = min(f[i], f[j] + abs(h[i] - h[j]));
     }
     For(i, k + 1, n)
     {
         f[i] = oo;
         For(j, i - k, i - 1) f[i] = min(f[i], f[j] + abs(h[i] - h[j]));
     }
     cout << f[n];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef Karma
    freopen(FileName".inp", "r", stdin);
    freopen(FileName".out", "w", stdout);
#endif // Karma

    Enter();
    Solve();

    return 0;
}


Measured memory_bytes: 5120
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
  int n=sc.nextInt();
  int w=sc.nextInt();
  int a[]=new int[n];
  int b[]=new int[n];
  for(int i=0;i<n;i++)
  {
    b[i]=sc.nextInt();

    a[i]=sc.nextInt();

  }
  long dp[][]=new long[n+1][w+1];
  for(int i=1;i<=n;i++)
  {
   for(int j=1;j<=w;j++)
   {
    dp[i][j]=dp[i-1][j];
    if(b[i-1]<=j)
      dp[i][j]=Math.max(dp[i-1][j],a[i-1]+dp[i-1][j-b[i-1]]);
   }
  }
  System.out.println(dp[n][w]);
}
}

Measured memory_bytes: 126032
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    string S;
    int cnt = 0;
    int max = 0;

    cin >> S;
    for (int i = 0; i < 3; i++)
    {
        if (S[i] == 'R')
        {
            cnt++;
        }else
        {
            if (cnt > max)
            {
               max = cnt;
            }
            
            cnt = 0;
        }
        
    }

    if (cnt > max)
    {
        max = cnt;
    }
    

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 3192
def main():
    N = input().rstrip()
    ans = 0
    if N=="SUN":
        ans = 7
    elif N=="MON":
        ans = 6
    elif N=="TUE":
        ans = 5
    elif N == "WED":
        ans = 4
    elif N == "THU":
        ans = 3
    elif N == "FRI":
        ans = 2
    elif N == "SAT":
        ans = 1
    return ans

if __name__ == "__main__":
    ans = main()
    print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    string S, T, U;
    ll A, B;
    input(S, T, A, B, U);

    if (S == U)
    {
        cout << A - 1 << " " << B << endl;
    }
    else
    {
        cout << A << " " << B - 1 << endl;
    }

    return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
void solve(){
    int n;
    cin>>n;
    if(n==3){
        cout<<"2 5 63";
        return;
    }
    rep(y,1,n){
        int cur=(n-y)*(n-y+1)+3*y*y/2;
        if(cur%2==0 && cur%3==0){
            int mx=0;
            rep(i,1,n-y+1){
                mx=max(mx,2*i);
            }
            rep(i,1,y+1){
                mx=max(mx,3*(2*i-1));
            }
            if(mx>=30001) continue;
            rep(i,1,n-y+1){
                cout<<2*i<<" ";
            }
            rep(i,1,y+1){
                cout<<3*(2*i-1)<<" ";
            }
            return;
        }
    }
    assert(false);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<vector>
#define ll long long
#define maxn 105
#define p 1000000007
#define inf 0x3f3f3f3f
using namespace std;
int n,h[maxn],root,tot=1;
int si[maxn],a[maxn];
ll f[maxn][2];// f[maxn][0]表示非黑白相间的方案数
vector<int> c[maxn];

inline int read()
{
	int num,sign=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')sign=-1;
	num=c-'0';
	while((c=getchar())>='0'&&c<='9')
		num=(num<<1)+(num<<3)+c-'0';
	return num*sign;
}

void build(int l,int r,int id)
{
	int minheight=inf,top=0;
	int st[maxn];
	si[id]=r-l+1;
	for(register int i=l;i<=r;++i)
	{
		if(h[i]<=minheight)
		{
			if(h[i]<minheight)
			{
				top=0;
				minheight=h[i];
				st[++top]=i;
			}
			else
				st[++top]=i;
		}
	}
	st[++top]=r+1,a[id]=minheight;
	int lastgo=l;
	for(register int i=1;i<=top;++i)
	{
		if(st[i]==lastgo)
		{
			++lastgo;
			continue;
		}
		++tot;
		c[id].push_back(tot);
		build(lastgo,st[i]-1,tot);
		lastgo=st[i]+1;
	}
}

inline ll ksm(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%p;
		b>>=1;
		a=(a*a)%p;
	}
	return res;
}

void dfs(int u,int lasth)
{
	int sum=si[u];
	int H=a[u]-lasth;
	f[u][1]=1,f[u][0]=1;
	for(register int i=0;i<c[u].size();++i)
	{
		int v=c[u][i];
		dfs(v,a[u]);
		f[u][0]=(f[u][0]*((f[v][1]+f[v][0])%p)%p+(f[u][0]*f[v][1])%p)%p;
		f[u][1]=(f[v][1]*f[u][1])%p;
		sum-=si[v];
	}
	f[u][0]=((f[u][0]*ksm(2,sum))%p+(p-2*f[u][1]%p)%p)%p;
	f[u][1]=(f[u][1]*ksm(2,H))%p;
}

int main()
{
	n=read();
	for(register int i=1;i<=n;++i)h[i]=read();
	build(1,n,1);
	dfs(1,0);
	printf("%lld\n",(f[1][0]+f[1][1])%p);
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans = h[n-1]
for i in range(n-k+1):
  if ans > (h[i+k-1]-h[i]):
    ans = h[i+k-1]-h[i]
print(ans)
  

Measured memory_bytes: 7384
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *H = map(int, read().split())

    m = 0
    ans = 0
    for h in H:
        if h >= m:
            ans += 1
            m = h

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main(){
    string n;
    cin >> n;
    int sum = 0;
    for(int i = 0; i < n.length(); i++){
        sum += n[i]-'0';
    }

    if(sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int sosu(int);

int main(){
  int i,A,count=0;
  scanf("%d",&A);
  int kazu[A];
  

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

  for(i=0;i<A;i++){
    if(sosu(kazu[i])==1){
      count++;
  }
  }

  printf("%d\n",count);
  return 0;
}

int sosu(int x){
  int  i;
  if(x==2){
    return 1;
  }
  if(x<2 || x%2==0){
    return 0;
  }
  i = 3;
  while(i<=sqrt(x)){
    if(x%i==0){
      return 0;
    }
    i = i + 2;
  }
  return 1;
}



Measured memory_bytes: 2128
n,m,x=gets.chomp.split(" ").map(&:to_i);
tolls=gets.chomp.split(" ").map(&:to_i);

zero_to_x = 0
tolls.each do |toll|
    if (0..x).include?(toll)
        zero_to_x += 1
    end
end

x_to_n = 0
tolls.each do |toll|
    if (x..n).include?(toll)
        x_to_n += 1
    end
end

puts zero_to_x <= x_to_n ? zero_to_x : x_to_n

Measured memory_bytes: 14328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll pow2[33];
ll A[maxn];
ll B[maxn];
int oth[maxn];
vector<int> mch[maxn];
bool less2(int a,int b)
{
	return mch[a].size()<mch[b].size();
}
int I;
bool less3(int a,int b)
{
//	if(a==I)return 1;
//	if(b==I)return 0;
	return oth[a]>oth[b];
}
int ind[maxn];
bool usd[maxn];
int col[maxn];
int main()
{
	pow2[0]=1;
	for(int i=1;i<33;i++)
		pow2[i]=pow2[i-1]*2ll;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&A[i]);
	}
	sort(A,A+n);
	int m=0;
	B[0]=A[0];
	for(int i=0;i<n;i++)
	{
		if(A[i]==B[m])
		{
			oth[m]++;
		}
		else
		{
			B[++m]=A[i];
			oth[m]++;
		}
	}
	m++;
//	for(int i=0;i<m;i++)
//	{
//		cout<<B[i]<<" "<<oth[i]<<endl; 
//	}
	int cnt=0;
	for(int i=m-1;i>=0;i--)
	{
		for(int j=32;j>=0;j--)
		{
			if(pow2[j]<=B[i])break;
			ll dif=pow2[j]-B[i];
			int pos=lower_bound(B,B+m,dif)-B;
			if(B[pos]!=dif)continue;
			if(i!=pos)
			{
				int cur=min(oth[i],oth[pos]);
				oth[i]-=cur;
				oth[pos]-=cur;
				cnt+=cur;
			}
			else
			{
				int cur=oth[i]/2;
				oth[i]-=cur*2;
				cnt+=cur;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

int main(void) {
        int r;
        cin>>r;
        if(r<1200)
                cout<<"ABC";
        else if(r<2800)
                cout<<"ARC";
        else
                cout<<"AGC";
        return 0;
}


Measured memory_bytes: 256