akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    cout << n*n*n << endl;
    return 0;
}


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


int gcd(int a, int b)
{
	if (b > a) {
		int tmp = a;
		a = b;
		b = tmp;
	}

	int r = a % b;
	while (r) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

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

	int g = gcd(A, B);
	int cnt = 0;
	int ans;
	for (int i = 1; i <= g; ++i) {
		if (g % i == 0) {
			++cnt;
		}
		if (cnt == K) {
			ans = g / i;
			break;
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N, P;
string S;
int rest[200010];
ll cnt[10010];
ll sum[200010];
ll ans;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin >> N >> P >> S;
	reverse(S.begin(), S.end());
	if(P == 2){
		for(int i = 0; i < N; i++){
			if((S[i] - '0') % 2 == 0) ans += N - i;
		}
		cout << ans << endl;
		return 0;
	}
	if(P == 5){
		for(int i = 0; i < N; i++){
			if((S[i] - '0') == 0 || (S[i] - '0') == 5) ans += N - i;
		}
		cout << ans << endl;
		return 0;
	}
	rest[0] = 1;
	for(int i = 1; i < N; i++){
		rest[i] = rest[i - 1] * 10;
		rest[i] %= P;
	}
	for(int i = 0; i < N; i++){
		sum[i] += rest[i] * (S[i] - '0');
		sum[i] %= P;
		sum[i + 1] = sum[i];
		cnt[sum[i]]++;
	}
	ans += cnt[0];
	for(int i = 0; i < N - 1; i++){
		cnt[sum[i]]--;
		ans += cnt[(P + sum[i]) % P];
	}
	
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> w(n);
    int sumA = 0;
    int sumB = 0;
    rep(i, n)
    {
        cin >> w[i];
        sumA += w[i];
    }
    int min = sumA;
    rep(i, n)
    {
        sumA -= w[i];
        sumB += w[i];
        if (min > abs(sumA - sumB))
            min = abs(sumA - sumB);
    }
    cout << min << endl;
    return 0;
}


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

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

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

template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template <class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template <class T> inline T gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }
template <class T> inline T bigmod(T p, T e, T m) { T ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % m; p = (p * p) % m; } return (T)ret; }



void solve() {
	int a, b;
	cin >> a >> b;

	if (a <= 5)
	{
		cout << 0 << endl;
		return;
	}

	if (a <= 12)
	{
		cout << b/2 << endl;
		return;
	}

	cout << b  << endl;
}

int main()
{

	ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); cout.tie(nullptr); cin.tie(nullptr);

	int t = 1;
	while (t--) {

		solve();
	}



	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

num_list = [0] * (N + 1)
for a in A:
    num_list[a] += 1

ans = 0
for n in num_list:
    ans += n * (n - 1) // 2

for i in range(N):
    diff = num_list[A[i]] * (num_list[A[i]] - 1) // 2 - (num_list[A[i]] - 1) * (num_list[A[i]] - 2) // 2 if num_list[A[i]] >= 2 else 0
    print(ans - diff)


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

int main()
{
	int n,m;
	cin>>n;
	int t[n],sum=0;
	for(int i=0;i<n;i++)
		{
			cin>>t[i];
			sum+=t[i];
		}
	cin>>m;
	for(int i=0;i<m;i++)
		{
			int p,x;
			cin>>p>>x;
			cout<<sum-t[p-1]+x<<"\n";
		}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);
const int iINF = (1 << 31)-1;
const double dINF = 1000000000000000000.0;
const int MAX_N = 1 << 17;

int main(){
	int c[3][3];
	int a[3];
	int b[3];
	bool flg = true;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
			if (i == 0)a[j] = c[i][j];
			else if (j == 0) {
				b[i] = c[i][j] - a[j];
			}
			else {
				if (b[i] != c[i][j] - a[j])flg = false;
			}
		}
	}
	cout << (flg ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = (int(i) for i in input().split())
p = list(map(int, input().split()))

ans = 0
tmp = 0
for i in range(k):
    tmp += (p[i]+1)/2
ans = tmp
for i in range(1, n-k+1):
    tmp += -(p[i-1]+1)/2 + (p[i+k-1]+1)/2
    if(ans < tmp):
        ans = tmp

print(ans)


Measured memory_bytes: 25060
#include<stdio.h>
int main(void){
    int N, head;
    scanf("%d",&N);
  	if(N>99){
      	head = N/100;
          N = N-head*100;
      }
      if(N>9){
        head = N/10;
          N= N-head*10;
      }
    switch(N){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
        printf("hon\n");
		break;
        
        case 0:
        case 1:
        case 6:
        case 8:
        printf("pon\n");
        break;

        case 3:
        printf("bon\n");
        break;
    }
    return 0;
}

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

void same(char x1,char x2,char x3){
  if (x1==x2&&x2==x3){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  return;
}

int main(){
  string S;
  cin >> S;
  char x1,x2,x3;
  x1=S.at(0);
  x2=S.at(1);
  x3=S.at(2);
  same(x1,x2,x3);
}


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
   
	int N,wei[110];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> wei[i];
	}
	int total=0;
	for (int i = 0; i < N; i++) {
		total += wei[i];
	}
	//cout << total << endl;
	
	int forw=0, back=0;
	int sa = total;
	for (int i = 0; i < N;i++) {
		forw += wei[i];
		back = total - forw;
		if (forw > total / 2) {
			if (forw - back < sa) {
				sa = forw -back;
			}else break;
		}
		else if (back - forw < sa) {
			sa = back - forw;
		}
		else break;
	}

	cout << sa << endl;
}



Measured memory_bytes: 256
n=int(input())
a=sorted((list(map(int,input().split()))),reverse=True)
con=1
sta=a[0]
check=0
for i in range(1,n):
  if a[i]==sta:
    con+=1
    if con==2:
      check+=1
      x=sta
      a.remove(sta)
      a.remove(sta)
      break
  else:
    con=1
    sta=a[i]
sta=a[0]
con=1
for i in range(1,n-2):
  if a[i]==sta:
    con+=1
    if con==2:
      check+=1
      y=sta
      break
  else:
    con=1
    sta=a[i]
print(x*y if check==2 else "0")

Measured memory_bytes: 14672
def main():
  n, k = map(int, input().split())

  A = tuple(map(lambda a: int(a) - 1, input().split()))

  arrival = [None] * n
  arrival[0] = 0

  pos = 0
  for i in range(1, k + 1):
    next_pos = A[pos]

    if arrival[next_pos]:
      loop_len = i - arrival[next_pos]
      remaining = k - i
      kk = arrival[next_pos] + remaining % loop_len
      print(arrival.index(kk) + 1)
      return

    arrival[next_pos] = i
    pos = next_pos

  print(pos + 1)


main()


Measured memory_bytes: 32416
#include<bits/stdc++.h>
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14 
 
signed main(){
    int h, w;
    cin >> h >> w;
    int cost[10][10];
    rep(i, 10)rep(j, 10)
        cin >> cost[i][j];
    rep(k, 10)rep(i, 10)rep(j, 10)
        cost[i][j] = min(cost[i][k] + cost[k][j], cost[i][j]);

    long long ans = 0, in;
    rep(i, h)rep(j, w){
        cin >> in;
        if(in == -1 || in == 1)continue;
        ans += cost[in][1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
 
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
 
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
 
 
 
ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1e6 + 1389;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;
 

 
void solve(int tc = 0) {
	cin >> x;
	cout << !x;
}
 
int main() {
	#ifdef galen_colin_local
		auto begin = std::chrono::high_resolution_clock::now();
	#endif
	
	send help
 
	#ifndef galen_colin_local
		// usaco("moop");
	#endif
	
	// usaco("cowland");
	
	// freopen("tc.cpp", "r", stdin);
 
	int tc = 1;
	// cin >> tc;
	for (int t = 0; t < tc; t++) solve(t);
	
	#ifdef galen_colin_local
		auto end = std::chrono::high_resolution_clock::now();
		cout << setprecision(4) << fixed;
		// cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
	#endif
} 

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

typedef long long int ll;
ll powk(ll a, ll n){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
    }

    ll ans = abs(a[0]) + abs(a[0] - a[k - 1]);
    for(ll i = 0;i < n - k + 1;i++){
        ll r = abs(a[i]) + abs(a[i] - a[i + k - 1]);
        ll l = abs(a[i + k - 1]) + abs(a[i + k - 1] - a[i]);

        ans = min({ans, l, r});
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int a, b;//A, B, C, D;
    cin >>a >> b;//A >>B >>C >>D;
    int c = a + b;
    if(c%2 == 1 )
        c++;
    cout << c / 2 <<endl;
        return 0;
}

Measured memory_bytes: 256
use std::str;
use std::io;

struct Solver<'a> {
    a: usize,
    b: usize,
    n: usize,
    n_foreigner: usize,
    chars: str::Chars<'a>,
}

#[derive(Debug)]
#[derive(PartialEq)]
enum QR {
    Yes,
    No,
}

impl<'a> Solver<'a> {
    fn new<'b>(a: usize, b: usize, s: &'b String) -> Self
    where 'b: 'a {
        Solver { a: a, b: b, n: 0, n_foreigner: 0, chars: s.chars() }
    }

    fn domestic(&mut self) -> QR {
        if self.n < self.a + self.b {
            self.n += 1;
            QR::Yes
        } else {
            QR::No
        }
    }

    fn foreigner(&mut self) -> QR {
        if self.n < self.a + self.b && self.n_foreigner < self.b {
            self.n += 1;
            self.n_foreigner += 1;
            QR::Yes
        } else {
            QR::No
        }
    }

    fn other(&mut self) -> QR {
        QR::No
    }
}

impl<'a> Iterator for Solver<'a> {
    type Item = QR;

    fn next(&mut self) -> Option<Self::Item> {
        match self.chars.next() {
            None => None,
            Some(c) => match c {
                'a' => Some(self.domestic()),
                'b' => Some(self.foreigner()),
                'c' => Some(self.other()),
                _ => self.next(),
            }
        }
    }
}

#[test]
fn test_solver1() {
    let s = String::from("abccabaabb");
    let solver = Solver::new(2, 3, &s);
    assert_eq!(
        solver.collect::<Vec<QR>>(),
        vec![QR::Yes, QR::Yes, QR::No, QR::No, QR::Yes, QR::Yes, QR::Yes, QR::No, QR::No, QR::No]
    );
}

#[test]
fn test_solver2() {
    let s = String::from("cabbabaacaba\n");
    let solver = Solver::new(5, 2, &s);
    assert_eq!(
        solver.collect::<Vec<QR>>(),
        vec![QR::No, QR::Yes, QR::Yes, QR::Yes, QR::Yes, QR::No, QR::Yes, QR::Yes, QR::No, QR::Yes, QR::No, QR::No]
    );
}

#[test]
fn test_solver3() {
    let s = String::from("ccccc");
    let solver = Solver::new(2, 2, &s);
    assert_eq!(
        solver.collect::<Vec<QR>>(),
        vec![QR::No, QR::No, QR::No, QR::No, QR::No]
    )
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut iter = input.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    let mut input = String::with_capacity(n + 1);
    io::stdin().read_line(&mut input).unwrap();
    let solver = Solver::new(a, b, &input);
    for i in solver {
        match i {
            QR::Yes => println!("Yes"),
            QR::No => println!("No"),
        }
    }
}


Measured memory_bytes: 4732
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);
vector<string> fi;
int H, W;

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


int main() {

	cin >> H >> W;
	fi.resize(H);
	for (int i = 0; i < H; ++i) cin >> fi[i];


	vector<vector<int>> dist(H, vector<int>(W, -1));
	using pint = pair<int, int>;
	queue<pint> que;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (fi[i][j] == '#') {
				dist[i][j] = 0;
				que.push(pint(i, j));
			}
		}
	}

	while (!que.empty()) {
		auto cur = que.front();
		que.pop();
		for (int dir = 0; dir < 4; ++dir) {
			int nx = cur.first + dx[dir];
			int ny = cur.second + dy[dir];
			if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
			if (dist[nx][ny] == -1) {
				dist[nx][ny] = dist[cur.first][cur.second] + 1;
				que.push(pint(nx, ny));
			}
		}
	}

	int ans = 0;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans = max(ans, dist[i][j]);
		}
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
int MAX = 1000000;
int main(){
  vector<bool> prime(MAX + 1, true);
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i <= MAX; i++){
    if (prime[i]){
      for (int j = i * 2; j <= MAX; j += i){
        prime[j] = false;
      }
    }
  }
  vector<int> sum(MAX + 1, 0);
  for (int i = 0; i < MAX; i++){
    if (prime[i + 1]){
      sum[i + 1] = sum[i] + 1;
    } else {
      sum[i + 1] = sum[i];
    }
  }
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    cout << sum[n * 2] - sum[n] << endl;
  }
}


Measured memory_bytes: 6556
#include <stdio.h>
int main(void){
    int a, b, c, d;
    
    scanf("%d %d %d %d", &a, &b, &c, &d);
    
    if(b <= c || a >= b || a >= d){
        printf("0\n");
    }else if(b >= c && b <= d && a <= c){
        printf("%d\n", b - c);
    }else if(b >= d && a <= c){
        printf("%d\n", d - c);
    }else if(a >= c && b >= c && b <= d){
        printf("%d\n", b - a);
    }else if(b >= d && a >= c){
        printf("%d\n", d - a);
    }
}


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

int main(){
  int n,t,a,at[10000],mn=1000000000;
  cin>>n>>t>>a;
  int b=1000*a;
  vector<double>h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  for(int i=0;i<n;i++){
    at[i]=t*1000-h[i]*6;
  }
  int q=0;
  for(int i=0;i<n;i++){
    if(mn>abs(b-at[i])){
      mn=abs(b-at[i]);
      q=i;
    }
  }
  cout<<q+1<<endl;
}
    


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

int main() {
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
  	for(int j = 1; j < s.size(); j++) {
    	if(s[j-1] > s[j]) swap(s[j-1], s[j]);
    }
  }
  
  string t;
  cin >> t;
  for(int i = 0; i < t.size(); i++) {
  	for(int j = 1; j < t.size(); j++) {
    	if(t[j-1] > t[j]) swap(t[j-1], t[j]);
    }
  }
  string u = t;
  rep(i, t.size()) {
    t[i] = u[t.size()-1-i];
  }
  
  //cout << s << " " << t << endl;
  
  s < t ? cout << "Yes" << endl : cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()){
			String s = sc.nextLine();
      if(s.equals(".")) break;

			Stack<Character> count = new Stack<>(); 
			boolean flag = true;
			LABEL:
				for(int i = 0; i < s.length(); i++) {
					char c = s.charAt(i);
					switch(c) {
					case '(':
						count.push(')');
						break;
					case '[':
						count.push(']');
						break;
					case ')':
					case ']':
						if(count.isEmpty() || count.peek() != c) {
							flag = false;
							break LABEL;
						}else {
							count.pop();
						}
					}
				}

					if(count.isEmpty() && flag) {
						System.out.println("yes");
					}
					else {
						System.out.println("no");
					}
				}
		}	
	}


Measured memory_bytes: 45868
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  map<P, int> mp;
  vector<vector<int>> g(H + 1);
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y, X--, Y--;
    g[X].push_back(Y);
    mp[{X, Y}] = 1;
  }
  for (int x = 0; x <= H; x++) {
    mp[{x, W}] = 1;
  }
  for (int y = 0; y <= W; y++) {
    mp[{H, y}] = 1;
  }

  int ans = 1;
  int y = 0;
  for (int x = 1; x <= H; x++) {
    int cnt = 0;
    for (auto v : g[x]) {
      if (v < y) cnt++;
    }
    if (cnt > 0 || mp[{x, y}]) break;
    if (!mp[{x, y + 1}]) y++;
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 67456
n = gets.to_i
xs = gets.split.map &:to_i

xs_sort = xs.sort
l = xs_sort[n / 2]
s = xs_sort[n / 2 - 1]

if s == l then
	n.times{
		puts l
	}
else
	xs.each{ |x|
		if s < x then
			puts s
		else
			puts l
		end
	}
end


Measured memory_bytes: 23396
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();        
        long D = sc.nextInt();
        for(int i=0;i<N;i++){
            long x = sc.nextInt();
            long y = sc.nextInt();
            if( x*x + y*y <= D*D){
                ans++;
            }
        }
        System.out.println(ans);
    }

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


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

#define MAX_M 110

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

vector<edge> c[2][MAX_M];

int dijkstra(int s,int e,bool r){
	int d[MAX_M];
	bool use[MAX_M];
	for(int i=0;i<MAX_M;i++){
		d[i]=INT_MAX;
		use[i]=0;
	}
	priority_queue<P,vector<P>,greater< P > > que;
	
	d[s]=0;
	
	que.push(P(0,s));
	int ans;
	while(!que.empty()){
		P p=que.top();que.pop();
		//cout<<"pop "<<p.second<<" "<<p.first<<endl;
		int v=p.second;
		if(v==e){
			ans=p.first;
			break;
		}
		
		if(use[v]) continue;
		use[v]=1;
		//cout<<"use "<<p.second<<" "<<p.first<<endl;
		for(int i=0;i<c[r][v].size();i++){
			edge e=c[r][v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
	
	return d[e];
}

int main(){
	int n,m;
	while(cin>>n>>m,n!=0||m!=0){
		for(int r=0;r<2;r++){
			for(int i=0;i<MAX_M;i++){
				c[r][i].clear();
			}
		}
		for(int i=0;i<n;i++){
			int a,b,cos,tim;
			cin>>a>>b>>cos>>tim;
			edge co,t;
			co.to=b;co.cost=cos;
			t.to=b;t.cost=tim;
			c[0][a].push_back(co);
			c[1][a].push_back(t);
			co.to=a;t.to=a;
			c[0][b].push_back(co);
			c[1][b].push_back(t);
		}
		int k;
		cin>>k;
		for(int i=0;i<k;i++){
			int s,e;
			bool r;
			cin>>s>>e>>r;
			int ans=dijkstra(s,e,r);
			cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 1344
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define rep(i,a,b) for(register int i=(a);i<(b);++i)
#define pb push_back
#define mx(a,b) (a>b?a:b)
#define mn(a,b) (a<b?a:b)
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;
using namespace std;

namespace IO
{
	const uint32 Buffsize=1<<15,Output=1<<24;
	static char Ch[Buffsize],*S=Ch,*T=Ch;
	inline char getc()
	{
		return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
	}
	static char Out[Output],*nowps=Out;
	
	inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

	template<typename T>inline void read(T&x)
	{
		x=0;static char ch;T f=1;
		for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
		for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
		x*=f;
	}

	template<typename T>inline void write(T x,char ch='\n')
	{
		if(!x)*nowps++='0';
		if(x<0)*nowps++='-',x=-x;
		static uint32 sta[111],tp;
		for(tp=0;x;x/=10)sta[++tp]=x%10;
		for(;tp;*nowps++=sta[tp--]^48);
		*nowps++=ch;
	}

	inline void readmd(int&x)
	{
		x=0;static char ch;
		for(ch=getc();!isdigit(ch);ch=getc());
		for(;isdigit(ch);ch=getc())x=(x*10ll+(ch^48))%998244353;
	}
}
using namespace IO;

void file()
{
	FILE*DSD=freopen("water.in","r",stdin);
	FILE*CSC=freopen("water.out","w",stdout);
}

const int MAXN=1e5+7;

static ll N,A,B,C,D;

inline void init()
{
	read(N),read(A),read(B),read(C),read(D);
}

inline void solve()
{
	A-=B,--N;
	Rep(i,0,N)if(A>=i*C-(N-i)*D&&A<=i*D-(N-i)*C)
		return(void)puts("YES");
	puts("NO");
}

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

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

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

  int ki = 0, gu = 0;
  for(int i = 1;i <= k;i++){
    if(i % 2 == 1) ki++;
    else gu++;
  }

  cout << ki * gu << endl;

  return 0;
}


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

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

template <typename T>
inline void read(T &x)
{
    T data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    x = f * data;
}

const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e5 + 9;

signed main()
{
    //freopen("in.txt","r",stdin);
    //freopen("data.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    //std::cout.tie(0);
    ll n, x, t = 0, ans = 0;
    read(n);
    for (int i = 1; i <= n; ++i)
    {
        read(x);
        if (x < t)
            ans += t - x;
        else
            t = x;
    }
    cout << ans << endl;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <string>
#include <tuple>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#include <random>
#include <cmath>

using namespace std;
using lint = long long int;

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

	string* s = new string[n];
	int* t = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> s[i] >> t[i];
	}

	string x;
	cin >> x;

	int time = 0;
	bool count = false;
	for (int i = 0; i < n; i++) {
		if (count)
			time += t[i];
		if (s[i] == x)
			count = true;
	}

	cout << time;

	return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    val (n,m) = readLine()!!.split(" ").map{it.toInt()}
    var a = readLine()!!.split(" ").map{it.toLong()}.toMutableList()
    a.sort()
    val b = ArrayList<Pair<Long,Long>>()
    repeat(m){
        val (c, d) = readLine()!!.split(" ").map{it.toLong()}
        b.add(Pair(c, d))
    }
    b.sortBy{it.second}
    b.reverse()
    var j = 0
    for(i in 0 until m){
        for(k in 0 until b[i].first) {
            if (j == n || b[i].second <= a[j]) break
            a[j] = b[i].second
            j++
        }
        if(j == n) break
    }
    println(a.sum())
}


Measured memory_bytes: 103908
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		Set<String> first = new HashSet<>();
		Set<String> second = new HashSet<>();

		int max = 0;
		for (int i = 1; i < n; i++) {
			first.clear();
			second.clear();

			String firstStr = s.substring(0, i);
			String secondStr = s.substring(i, n);

			for (char c : firstStr.toCharArray()) {
				first.add(String.valueOf(c));
			}
			for (char c : secondStr.toCharArray()) {
				second.add(String.valueOf(c));
			}

			int cnt = 0;
			for (Iterator<String> iterator = first.iterator(); iterator.hasNext();) {
				String str = iterator.next();
				if (second.contains(str)) cnt++;
			}

			max = Math.max(max, cnt);

		}

		System.out.println(max);

		sc.close();

	}

}


Measured memory_bytes: 37632
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  long long count = 0;
  for (long long a = 1; a < N; a++)
  {
    for (long long b = a; a * b < N; b++)
    {
      if (a == b)
        count++;
      else
        count += 2;
    }
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define dump(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a >= 13) {
    cout << b << endl;
  } else if(a >= 6) {
    cout << b / 2 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  vector<ll> a(n+1);
  vector<ll> b(n+1);
  rep(i,n){
    cin>>a[i+1]>>b[i+1];
  }

  vector<vector<ll>> ans(n+1,vector<ll>(w+1,0));
  repo(i,n+1){
    rep(j,w+1){
      if(j-a[i]>=0) chmax(ans[i][j],ans[i-1][j-a[i]]+b[i]);
      chmax(ans[i][j],ans[i-1][j]);
    }
  }

  cout << ans[n][w] << endl;
}


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

int color[9];

int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        if(a<400)color[0]++;
        else if(a<800)color[1]++;
        else if(a<1200)color[2]++;
        else if(a<1600)color[3]++;
        else if(a<2000)color[4]++;
        else if(a<2400)color[5]++;
        else if(a<2800)color[6]++;
        else if(a<3200)color[7]++;
        else color[8]++;
    }
    int cnt=0;
    for(int i=0;i<8;i++){
        if(color[i]>0)cnt++;
    }
    if(cnt==0)cout<<1<<" ";
    else cout<<cnt<<" ";
    cnt+=color[8];
    cout<<cnt<<endl;
    return 0;
}

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 min = 0, max = 0;
		boolean[] flgs = new boolean[8];
		for(int i = 0; i < flgs.length; i++) {
			flgs[i] = false;
		}
		for(int i = 0; i < n; i++) {
			int score = scan.nextInt();
			if(3200 <= score) {
				max++;
			} else {
				for(int j=0; j<flgs.length; j++) {
					if(400*j <= score && score < 400*(j+1)) {
						flgs[j] = true;
					}
				}
			}
		}
		scan.close();
		for(int i=0; i<flgs.length; i++) {
			if(flgs[i]) {
				min++;
			}
		}
		max += min;
		if(max != 0 && min == 0) {
			min = 1;
		}
		System.out.println(min+" "+max);
	}

}

Measured memory_bytes: 21844
a, *bcd = gets.chomp.split("").map(&:to_i)

(1 << 3).times do |bit|
  ans = [a]
  sum = a

  bcd.each_with_index do |n, i|
    ans << (bit[i] == 0 ? "+" : "-") << n
    sum += (-1) ** bit[i] * n
  end

  if sum == 7
    puts [*ans, "=7"].join
    break
  end
end


Measured memory_bytes: 1788
from collections import deque

R, C = map(int, input().split())
masu = [list(input()) for _ in range(R)]
sr, sc = 0, 0
gr, gc = R - 1, C - 1

def bfs():
    d = [[float("inf")] * C for _ in range(R)]
    dr = [0, -1, 0, 1]
    dc = [1, 0, -1, 0]
    que = deque([])

    que.append((sr, sc))
    d[sr][sc] = 0
    while que:
        p = que.popleft()
        if p[0] == gr and p[1] == gc:
            break
        for i in range(4):
            nr = p[0] + dr[i]
            nc = p[1] + dc[i]
            if (0 <= nr < R) and (0 <= nc < C) and masu[nr][nc] != "#" and d[nr][nc] == float("inf"):
                que.append((nr, nc))
                d[nr][nc] = d[p[0]][p[1]] + 1
    
    return d[gr][gc]

white = 0
for i in range(R):
    for j in range(C):
        if masu[i][j] == ".":
            white += 1

res = bfs()
if 0 < res < float("inf"):
    print(white - res - 1)
else:
    print(-1)

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

using namespace std;

int main() {
	int n, m, q; cin >> n >> m >> q;
	vector<int> a(q), b(q), c(q), d(q);
	for (int i = 0; i < q; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i], --a[i], --b[i];
	vector<int> A(10);
	A[9] = m;
	int ans = 0;
	for (A[0] = 1; A[0] <= m; ++A[0]) {
		for (A[1] = A[0]; A[1] <= m; ++A[1]) {
			for (A[2] = A[1]; A[2] <= m; ++A[2]) {
				for (A[3] = A[2]; A[3] <= m; ++A[3]) {
					for (A[4] = A[3]; A[4] <= m; ++A[4]) {
						for (A[5] = A[4]; A[5] <= m; ++A[5]) {
							for (A[6] = A[5]; A[6] <= m; ++A[6]) {
								for (A[7] = A[6]; A[7] <= m; ++A[7]) {
									for (A[8] = A[7]; A[8] <= m; ++A[8]) {
										int tmp = 0;
										for (int i = 0; i < q; ++i) tmp += (A[b[i]] - A[a[i]] == c[i] ? d[i] : 0);
										ans = max(ans, tmp);
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  string n; cin >> n;
  if(n[0]=='1') n[0]='9';
  else if(n[0]=='9') n[0]='1';
  if(n[1]=='1') n[1]='9';
  else if(n[1]=='9') n[1]='1';
  if(n[2]=='1') n[2]='9';
  else if(n[2]=='9') n[2]='1';
  cout << n;
}

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

ll gcd(ll a, ll b){
    if(a < 0) a = -a;
    if(b < 0) b = -b;
    if(b == 0) return a;
    else return gcd(b, a%b);
}

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

void solve(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll l = lcm(c, d);
    ll dis = b - a + 1;
    cout << dis - ((b/c - (a-1)/c) + (b/d - (a-1)/d) - (b/l - (a-1)/l)) << endl;
}

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

Measured memory_bytes: 256
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
//using namespace boost;
//using namespace multiprecision;  

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

    int n,m;
    cin >> n >> m;

    vector<int> num(n+1,-1);

    rep(i,m){
        int s,c;
        cin >> s >> c;
        if(n != 1 && s == 1 && c == 0){
            return cout << "-1\n",0;
        }
        else if(num[s] == -1){
            num[s] = c;
        }else if(num[s] != c){
            return cout << "-1\n",0;
        }
    }

    string res;
    if(n == 1){
        if(num[1] == -1){
            return cout << "0\n",0;
        }else{
            return cout << num[1] << '\n',0;
        }
    }

    reps(i,n){
        if(i == 1){
            if(num[i] == -1){
                cout << 1;
            }else{
                cout << num[i];
            }
        }else{
            if(num[i] == -1){
                cout << 0;
            }else{
                cout << num[i];
            }
        }
    }

    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define reverse(s) reverse(s.begin(),s.end())

int main(){
    int n;
    cin >> n;
    int l(100),r(1);
    vector<int> x(n);
    rep(i,n){
        cin >> x[i];
        l = min(l,x[i]);
        r = max(r,x[i]);
    }
    int ans(100000000);

    for(int i=l;i<=r;i++){
        int t(0);
        rep(j,n){
            t += (x[j]-i)*(x[j]-i);
        }
        ans = min(ans,t);
    }
    put(ans);
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    string s; cin >>s;
    if(s == "AAA" or s=="BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

int main(){
	int n;
	cin>>n;
	map<int,int>m;
	map<int,int>::iterator it;
	while(n--){
		int a;
		cin>>a;
		it = m.find(a);
		if(it!=m.end()) it->second+=1;
		else m.insert(make_pair(a,1));
	}
	vector<long long>stick;
	for(it = m.begin(); it!=m.end(); it++){
		if(it->second>=2) stick.push_back(it->first);
		if(it->second>=4) stick.push_back(it->first);
		sort(stick.begin(),stick.end());
		while(stick.size()>=3) stick.erase(stick.begin()); 
	}
	if(stick.size()<=1) cout<<0;
	else cout<<stick[stick.size()-1]*stick[stick.size()-2];
}

Measured memory_bytes: 8288
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i,n,card;
        int array[] = new int[52];
        String s;
        for(i=0;i<52;i++){
            array[i] = 0;
        }
        n = scan.nextInt();
        for(i=0;i<n;i++){
            s = scan.next();
            card = scan.nextInt();
            switch(s){
                case"S":
                    card -= 1;
                    break;
                case"H":
                    card += 12;
                    break;
                case"C":
                    card += 25;
                    break;
                case"D":
                    card += 38;
                    break;
                default:
                    continue;
            }
            array[card] = 1;
        }
        for(i=0;i<52;i++){
            if(array[i]==0){
                if(i/13==0){
                    System.out.println("S "+ (i%13+1));
                }
                else if(i/13==1){
                    System.out.println("H "+ (i%13+1));
                }
                else if(i/13==2){
                    System.out.println("C "+ (i%13+1));
                }
                else if(i/13==3){
                    System.out.println("D "+ (i%13+1));
                }
            }
        }
    }
}



Measured memory_bytes: 26284
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using pii = pair<int,int>;
using ll = long long;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
static constexpr int INF = 0x3f3f3f3f;

bool isPrime(int n)
{
    if (n == 2) return true;
    if (n < 2 || (n&1) == 0) return false;
    for(int i=3; i*i <= n; i += 2)
        if (n % i == 0) return false;
    return true;
}

int cum[100010];

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

    for (int i=1; i <= 100005; i += 2) {
        if (isPrime(i) && isPrime((i+1) / 2)) ++cum[i];
    }

    for (int i=1; i <= 100005; ++i) {
        cum[i] += cum[i-1];
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int l, r;
        cin >> l >> r;
        outl(cum[r] - cum[l-1]);
    }

    return 0;
}



Measured memory_bytes: 1024
import java.io.*;
import java.math.BigInteger;
import java.util.*;

class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int test_cases = 1;
        Solver s = new Solver();
        for (int i = test_cases; i >= 1; i--) {
            s.solve(1, in, out);
        }
        out.close();
    }

    static class Solver {
        public void solve(int test_number, InputReader in, PrintWriter out) throws IOException {
            long n = in.nextLong();
            int k = in.nextInt();
            int[] a = new int[k];
            for (int i = 0; i < k; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            while (true) {
                if (check(a, n)) {
                    out.println(n);
                    return;
                }
                n++;
            }
        }

        private boolean check(int[] a, long n) {
            while (n > 0) {
                if (Arrays.binarySearch(a, (int) (n % 10)) > -1) return false;
                n /= 10;
            }
            return true;
        }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader()
        {
            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();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	int n=s.size();
	string ss=s;
	string s1=s.substr(0,(n-1)/2),s2=s.substr((n+3)/2-1);
	string s3=s1,s4=s2;
	reverse(ss.begin(),ss.end());
	reverse(s3.begin(),s3.end());
	reverse(s4.begin(),s4.end());
	if(ss==s && s3==s1 && s4==s2)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
int n;
int h[N],dp[N];
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  scanf("%d", &n);
  for(int i=0;i<n;++i)
    scanf("%d",&h[i]);
  dp[0]=0,dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<n;++i)
  {
    dp[i]=min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]);
  }
  printf("%d",dp[n-1]);


}






Measured memory_bytes: 1024
n = gets.chomp.to_i
a = readlines.map(&:to_i)
sorted = a.sort
h = {}
sorted.each.with_index do |d,i|
  h[d] = i
end
t = 0
a.each.with_index do |d,i|
  t += 1 if(h[d]%2 != i%2)
end
p t/2

Measured memory_bytes: 15600
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def make_divisors(n):
    # exclude itself
    divisors = [1]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors


def main():
    N = int(input())
    A = list(map(int, input().split()))
    S = [0] * (N)
    B = []
    for i in range(N - 1, -1, -1):
        S[i] %= 2
        if A[i] != S[i]:
            S[i] += 1
            B.append(i + 1)
            ds = make_divisors(i + 1)
            for d in ds:
                S[d - 1] += 1
        else:
            continue

    print(len(B))
    print(*B, sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 69608
/**
 *  author: nayakashutosh9
 *	[2020-09-19 17:25]
**/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define inf 1e18
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> pbds;
const int N = 300005;
/*******************************************************/


void solve() {
	int n; cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += (n / i);
		ans -= (n % i == 0);
	}
	cout << ans << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T = 1;
	// cin >> T; cin.ignore();
	for (int i = 1; i <= T; i++) {
		// cout << "Case #" << i << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int n, k;
  cin >> n >> k;
  if(n%k ==0 )cout << 0 << endl;
  else{cout << 1 << endl;}
}


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

int main(){
    string n;
    cin >> n;
    bool ans = false;

    rep(i, n.size()){
        if(n[i] == '7') ans = true;
    }
  
    if(ans) cout << "Yes" << endl;
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 3572