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


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

    string s;
    cin>>s;

    set<char> st;
    for (char c: s) st.insert(c);

    bool good = true;
    if (st.count('N') + st.count('S') == 1) good = false;
    if (st.count('E') + st.count('W') == 1) good = false;

    if (good)   cout<<"Yes\n";
    else        cout<<"No\n";
}


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

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

    int n,ans=0;
    cin >> n;

    vector<int> v(n);

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

    for(int i=1;i<n-1;i++){
        vector<int> aux;

        aux.push_back(v[i-1]);
        aux.push_back(v[i]);
        aux.push_back(v[i+1]);

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

        if(aux[1]==v[i]){
            ans++;
        }
    }    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
macro_rules! read_line {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}

fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line!().split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}

fn main() {
    let input: Vec<i32> = read_to_vec();
    let (w, h, n) = (input[0], input[1], input[2]);
    let mut input: Vec<Vec<i32>> = vec![Vec::new(); 4];
    let zero: i32 = 0;

    for _ in 0..n {
        let line: Vec<i32> = read_to_vec();
        
        input[(line[2]-1) as usize].push(line[(line[2]/3) as usize])
    }

    let (bottom, top, left, right) =
        (input[0].iter().max().unwrap_or(&zero),
        input[1].iter().min().unwrap_or(&w),
        input[2].iter().max().unwrap_or(&zero),
        input[3].iter().min().unwrap_or(&h));

    println!("{}",
        std::cmp::max(0, top - bottom) *
        std::cmp::max(0, right - left));
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B == C+D){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 3592
//author: clorf
//Think twice,Code once.
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=100010;
const double Pi=acos(-1.0);
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}
long long n,d,x,y,ans;
int main()
{
	scanf("%lld%lld",&n,&d);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x,&y);
		if(x*x+y*y<=d*d)
			ans++;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1732
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String[] v = br.readLine().split(" ");
			int w = Integer.parseInt(v[0]);
			int h = Integer.parseInt(v[1]);
			int x = Integer.parseInt(v[2]);
			int y = Integer.parseInt(v[3]);
			int r = Integer.parseInt(v[4]);

			if (x >= r && x <= w - r && y >= r && y <= h - r) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24352
#include <stdio.h>
/*ABC 139 A*/

int main (void)
{
  int i;
  int count = 0;
  char bef[4];
  char aft[4];

  scanf("%s", &bef);
  scanf(" %s", &aft);
  for ( i = 0; i < 3; i++) {
    if (bef[i] == aft[i]) {
      count++;
    }
  }

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


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int x, a;
  cin >> x >> a;
  if(x >= a) {
    cout << 10 << endl;
  }else {
    cout << 0 << endl;
  }
}

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

int main(){
    int k; cin >> k;
    queue<ll> que;
    for(int i = 1; i <= 9; i++){
        que.push(i);
    }
    rep(i, k-1){
        ll x = que.front();
        que.pop();
        for(int j = -1; j <= 1; j++){
            ll d = x%10;
            d += j;
            if(d < 0 || d > 9) continue;
            que.push(x*10+d);
        }
    }
    cout << que.front() << endl;
    // while(!que.empty()){
    //     cout << que.front() << " ";
    //     que.pop();
    // }
}


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

int main()
{
    int k, s;
    cin >> k >> s;
    int count = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= min(k, s - x); y++) {
            if (s - x - y <= k) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,k;
	cin>>n>>k;
	ll a,b;
	a=b=0;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		if(now%2){
			a++;
		}
		else{
			b++;
		}
	}
	ll c[51][51];
	c[0][0]=1;
	for(ll i=1;i<51;i++){
		for(ll j=0;j<=i;j++){
			if(j==0||j==i){
				c[i][j]=1;
			}
			else{
				c[i][j]=c[i-1][j-1]+c[i-1][j];
			}
		}
	}
//	cout << c[3][1];
	if(k==0){
		ll cnt=0;
		for(ll i=0;i<=b;i++){
			for(ll j=0;j<=a;j+=2){
				cnt+=c[b][i]*c[a][j];
				//cout <<cnt<<endl;
			}
		}
		cout <<cnt;
	}
	else{
		ll cnt=0;
		for(ll i=0;i<=b;i++){
			for(ll j=1;j<=a;j+=2){
				cnt+=c[b][i]*c[a][j];
				//cout <<cnt<<endl;
			}
		}
		cout <<cnt;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        n = n*(n-1)/2;
        m = m*(m-1)/2;
        
        System.out.println(n+m);
    }
}

Measured memory_bytes: 21844
using System;
using System.Linq;

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = h[0], m = h[1];
		var a = Console.ReadLine().Split().Select(double.Parse).ToArray();

		var v = First(0, 1 << 30, x =>
		{
			var c = 0;
			foreach (var _ in a)
			{
				var ai = _;
				while (ai > x) { ai /= 2; c++; }
			}
			return c <= m;
		});

		for (int i = 0; i < n; i++)
			while (a[i] > v) { a[i] /= 2; m--; }

		Array.Sort(a);
		for (int i = Math.Max(0, n - m); i < n; i++)
			a[i] /= 2;
		Console.WriteLine(a.Sum(x => (long)x));
	}

	static int First(int l, int r, Func<int, bool> f)
	{
		int m;
		while (l < r) if (f(m = l + (r - l - 1) / 2)) r = m; else l = m + 1;
		return r;
	}
}


Measured memory_bytes: 29532
/*
	ITP1-2-B: Range
*/
#include	<iostream>

using namespace std;

int main(void) {
	int a, b, c;
	
	cin >> a >> b >> c;
	if(a < b && b < c) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	
	return 0;
}

Measured memory_bytes: 1156
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

template<typename T>
class SWAG{
  private:

  std::function<T(T,T)> fn;

  std::stack<T> front,back;
  std::vector<T> front_fold,back_fold;

  T id;

  public:

  SWAG(T id_,std::function<T(T,T)> fn_):id(id_),fn(fn_),front_fold(1,id_),back_fold(1,id_){}

  void push(T val){
    back.push(val);
    back_fold.push_back(fn(back_fold.back(),val));
  }

  void pop(){
    if(front.empty()){
      assert(front_fold.size()==1);
      while(!back.empty()){
        T temp=back.top();
        back.pop();
        back_fold.pop_back();

        front.push(temp);
        front_fold.push_back(fn(temp,front_fold.back()));
      }
    }

    assert(!front.empty());

    front.pop();
    front_fold.pop_back();
    
  }

  T fold_all(){
    return fn(front_fold.back(),back_fold.back());
  }
};

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

  ll n,l;
  std::cin>>n>>l;

  SWAG<ll> swag(MOD,[](ll a,ll b){return std::min(a,b);});

  rep(i,0,l-1){
    ll a;
    std::cin>>a;
    swag.push(a);
  }

  rep(i,0,n+1-l){
    ll a;
    std::cin>>a;
    swag.push(a);
    std::cout<<swag.fold_all();
    if(i!=n-l)std::cout<<" ";
    swag.pop();
  }

  std::cout<<"\n";

  return 0;
}


Measured memory_bytes: 5904
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int n;
    cin >> n;
    int a[n+1], b[n+1], c[n];
    rep1(i,n+1) cin >> a[i];
    rep1(i,n+1) cin >> b[i];
    rep1(i,n) cin >> c[i];
    int ans = 0;
    rep1(i,n+1){
        ans += b[a[i]];
        if(i >= 2 && a[i] == a[i-1] + 1){
            ans += c[a[i-1]];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()


int main(void){
    ll h, w;
    cin >> h >> w;

    char map[h][w];
    rep(i, 0, h){
        rep(j, 0, w){
            cin >> map[i][j];
        }
    }

    ll dp[h][w];
    rep(i, 0, h){
        rep(j, 0, w){
            if(map[i][j] == '#'){
                dp[i][j] = 0;
            }else{
                if(i == 0 && j == 0){
                    dp[i][j] = 1;
                }else if(i == 0){
                    dp[i][j] = dp[i][j-1];
                }else if(j == 0){
                    dp[i][j] = dp[i-1][j];
                }else{
                    dp[i][j] = dp[i-1][j] + dp[i][j-1];
                    dp[i][j] %= 1000000007;
                }
            }
        }
    }

    cout << dp[h-1][w-1] << endl;
    return 0;
}


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

int main()
{
    int n, min = 1000000, max = -1000000;
    long sum = 0;

    std::cin >> n;

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

    std::cout << min << " "
              << max << " "
              << sum << std::endl;
}

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

using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const i64 INFL = (1LL << 62);
const i64 MOD = 1000000007;

template <class T>
i64 mod_pow(i64 a, i64 n, T mod) {
    mod = (i64)mod;
    i64 res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

template <int mod>
struct ModInt {
    using i64 = int64_t;
    i64 x;
    ModInt() : x(0) {}
    ModInt(i64 y) : x(y >= 0 ? y % mod : ((mod - (-y) % mod) % mod)) {}
    ModInt &operator+=(const ModInt &rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &rhs) {
        x = x * rhs.x % mod;
        return *this;
    }
    ModInt &operator/=(const ModInt &rhs) {
        *this *= rhs.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; }
    ModInt operator==(const ModInt &rhs) const { return x == rhs.x; }
    ModInt operator!=(const ModInt &rhs) const { return x != rhs.x; }
    friend ostream &operator<<(ostream &os, const ModInt &rhs) {
        return os << rhs.x;
    }
    friend istream &operator>>(istream &is, ModInt &rhs) {
        i64 t;
        is >> t;
        rhs = ModInt<mod>(t);
        return (is);
    }

   private:
    ModInt inverse() const {
        i64 a = x, u = 1LL, v = 0LL, t, b = (i64)mod;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
};
using mint = ModInt<1000000007>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    i64 n, a, b;
    cin >> n >> a >> b;
    mint ans = (mod_pow(2, n, MOD) - 1) % MOD;
    mint nca = 1;
    rep(k, a) { nca *= (n - k); }
    rep(k, a) { nca /= (k + 1); }
    mint ncb = 1;
    rep(k, b) { ncb *= (n - k); }
    rep(k, b) { ncb /= (k + 1); }

    ans -= nca;
    ans -= ncb;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

ac_list = [0]*n

for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac_list[i] = 1

ac_sum = list(accumulate(ac_list))

for l, r in lr:
    l -= 1
    r -= 1
    if l == 0:
        print(ac_sum[r-1])
        continue
    print(ac_sum[r-1] - ac_sum[l-1])


Measured memory_bytes: 32120
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<iomanip>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
typedef double D;
#define all(v) (v).begin(), (v).end()
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}

inline LL fastpo(LL x, LL n, LL mod) {
	LL res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }

inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}
const int _B = 131072;
char buf[_B];
int _bl = 0;
inline void flush() {
	fwrite(buf, 1, _bl, stdout);
	_bl = 0;
}
__inline void _putchar(char c) {
	if(_bl == _B) flush();
	buf[_bl++] = c;
}
inline void print(LL x, char c) {
	static char tmp[20];
	int l = 0;
	if(!x) tmp[l++] = '0';
	else {
		while(x) {
			tmp[l++] = x % 10 + '0';
			x /= 10;
		}
	}
	for(int i = l - 1; i >= 0; i--) _putchar(tmp[i]);
	_putchar(c);
}
struct P {
	D x, y;
};
const int N = 300033;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int pw[3][N], tot[3], f[N];
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	for(char c : s) {
		cnt +=  c == '1';
	}
	for(int d = 0; d <= 2; d++) {
		int mod = cnt + d - 1;
		if(mod <= 0) continue;
		tot[d] = 0;
		for(int i = 0; i < n; i++) {
			pw[d][i] = i == 0 ? 1 : pw[d][i - 1] * 2 % mod;
			if(s[n - i - 1] == '1') tot[d] = (tot[d] + pw[d][i])  %mod;
		}
		//cout << d << ' ' << tot[d] << ' ' << mod << endl;
	}
	for(int i = 0; i <= 200000; i++) {
		f[i] = i == 0 ? 0 : f[i % __builtin_popcount(i)] + 1;
	}
	for(int i = 0; i < n; i++) {
		int d = s[i] == '1' ? 0 : 2;
		if(cnt + d - 1 == 0) {
			cout << 0 << endl;
			continue;
		}
		//cout << d << endl;
		int mod = cnt + d - 1;
		int t = (tot[d] + (s[i] == '1' ? -pw[d][n - i - 1] : pw[d][n - i - 1])) % mod;
		t = (t + mod) % mod;
		//cout << t << endl;
		printf("%d%c", f[t] + 1, i == n - 1 ? '\n' : '\n');
	}
}






Measured memory_bytes: 6960
//Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
typedef long long LL;
const int MAXN = 1000000; 
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int k;

void init() {
  k = read();
}

LL a[MAXN + 5];
LL nine[MAXN + 5];
int tot = 0;

inline int getSum(LL x) {
  LL t = x, ret = 0;

  while (t) {
    ret += t % 10;
    t /= 10;
  }

  return ret;
}

bool cmp(LL x, LL y) {
  LL a = x * getSum(y), b = y * getSum(x);
  
  if (a != b) {
    return a < b;
  } else {
    return x < y;
  }
}

int main() {
  init();

  for (int i = 1; i <= 15; ++i) 
    nine[i] = nine[i - 1] * 10 + 9;

  for (int i = 1; i <= 999; ++i) {
    LL tmp = 1;
    a[++tot] = i;
    for (int j = 1; j <= 12; ++j) {
      tmp *= 10;
      a[++tot] = i * tmp + nine[j];
    }
  }
  
  sort(a + 1, a + 1 + tot, cmp);
  unique(a + 1, a + 1 + tot);
    
  LL mx = 0;
  int i = 1;

  while (k) {
    if (a[i] > mx) {
      mx = a[i];
      --k;
      printf("%lld\n", a[i]);
    }
    
    ++i;
  }

  return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
long long n,i,a,b=1000000000,k,h[100000];
int main(){
  for(cin>>n>>k;i<n;i++)cin>>h[i];
  sort(h,h+n);
  k--;
  for(i=0;i<n-k;i++){
    a=h[i+k]-h[i];
    b=min(b,a);
  }
  cout<<b;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
  int n;
	cin>>n; vector<int> a(n); rep(i, n) cin>>a[i]; sort(all(a));
  cout<<a[n-1]-a[0]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1000000007;

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

   double r;
   cin >> r;
   printf("%0.3f\n", 2*r*M_PI);
   return 0;
}

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

int main(){
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> v(N * 3);
  for (int i = 0; i < N * 3; i++) {
      cin >> v.at(i);
  }
  using vi = vector<int>;
  using vvi = vector<vi>;
  vvi vec(W, vi(H));
  for (int i = 0; i < N * 3 - 2; i += 3) {
    int x, y, a;
    x = v.at(i);
    y = v.at(i+1);
    a = v.at(i+2);
    if(a == 1){
    	for(int j = 0; j < x; j++){
          for(int k = 0; k < H; k++)
        	vec.at(j).at(k) = 1;
        }
    }
    else if(a == 2){
    	for(int j = x; j < W; j++){
          for(int k = 0; k < H; k++){
        	vec.at(j).at(k) = 1;
          }
        }
    }
    else if(a == 3){
    	for(int j = 0; j < W; j++){
          for(int k = 0; k < y; k++){
        	vec.at(j).at(k) = 1;
          }
        }
    }
    else if(a == 4){
    	for(int j = 0; j < W; j++){
          for(int k = y; k < H; k++){
        	vec.at(j).at(k) = 1;
          }
        }
    }
  }
  int area = 0;
  for(int j = 0; j < W; j++){
     for(int k = 0; k < H; k++){
        area += vec.at(j).at(k);
     }
   }
  cout << W*H - area << endl;
}


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

int main()
{
    long N, M;
    cin >> N >> M;
    priority_queue<long long> A;
    rep(i, N)
    {
        long long in;
        cin >> in;
        A.push(in);
    }
    rep(i, M)
    {
        long long discount = A.top() / 2;
        A.pop();
        A.push(discount);
    }

    long long ans = 0;
    rep(i, N)
    {
        ans += A.top();
        A.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main() {
  int h, w;
  while (scanf("%d%d", &h, &w), h | w) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int main(){
    ll H, N;
    vector<ll> A;
    cin >> H >> N;
    ll sum = 0;
    REP(i,0,N){
        ll a;
        cin >> a;
        sum += a;
    }
    if(sum >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vector<int> d{
    1, 0, 0,
    0, 1, 0,
    0, 0, 1,
    1, 1, 0,
    1, -1, 0,
    1, 0, 1,
    1, 0, -1,
    0, 1, 1,
    0, 1, -1,
    1, 1, 1,
    1, 1, -1,
    1, -1, 1,
    1, -1, -1
  };
  int n, m, p;
  while (cin >> n >> m >> p, n) {
    vector<int> xs(p), ys(p);
    for (int t = 0; t < p; ++t) {
      cin >> xs[t] >> ys[t];
      --xs[t], --ys[t];
    }
    auto in = [&](int x, int y, int z) {
      return 0 <= min({x, y, z}) and max({x, y, z}) < n;
    };
    vector<vector<vector<int>>> a(n, vector<vector<int>>(n, vector<int>(n)));
    auto chk = [&](int x, int y, int z, int dx, int dy, int dz) {
      vector<int> v;
      while (in(x, y, z) and (int)v.size() < m) {
        v.push_back(a[x][y][z]);
        x += dx, y += dy, z += dz;
      }
      for (int i : {-1, 1}) {
        if (count(begin(v), end(v), i) == m) {
          return i;
        }
      }
      return 0;
    };
    auto winner = [&] {
      for (int x = 0; x < n; ++x) {
        for (int y = 0; y < n; ++y) {
          for (int z = 0; z < n; ++z) {
            for (int i = 0; i < 13; ++i) {
              if (int c = chk(x, y, z, d[3 * i], d[3 * i + 1], d[3 * i + 2])) {
                return c;
              }
            }
          }
        }
      }
      return 0;
    };
    [&] {
      for (int t = 0; t < p; ++t) {
        auto &&v = a[xs[t]][ys[t]];
        *find(begin(v), end(v), 0) = t & 1 ? -1 : 1;
        if (int w = winner()) {
          cout << (w == 1 ? "Black" : "White") << ' ' << t + 1 << '\n';
          return;
        }
      }
      cout << "Draw\n";
    }();
  }
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int>par;
char s[105];
long long int ans=0;
int len;
void F(int now,long long int sig,long long int nw){
    if(now==len){
        ans+=sig+nw;
        return;}
    F(now+1,sig+nw,s[now]-'0');
    F(now+1,sig,nw*10+s[now]-'0');
    }
int main(){
    scanf("%s",s);
    len=strlen(s);
    F(1,0,s[0]-'0');
    printf("%lld\n",ans);
    }


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf

pf m = pfsub m (2:[3,5..])
  where
    pfsub n pl@(p:ps)
      | n == 1 = []
      | r == 0 = p : pfsub q pl
      | p * p > n = [n]
      | otherwise = pfsub n ps
      where
        (q, r) = divMod n p

solve [n, p] = product [head s ^ (length s `div` n)| s <- pfs]
  where
    pfs = group $ pf p
    
main = map read . words <$> getLine >>= print . solve

Measured memory_bytes: 1148
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 200005

using namespace std;

int main()
{
    ll x,a,b;

    scanf("%lld %lld %lld",&x,&a,&b);

    ll dif1=fabs(x-a);
    ll dif2=fabs(x-b);

    if(dif1<=dif2)
        printf("A\n");

    else
        printf("B\n");

    return (0);
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
while True:
    a = 0
    n,x = map(int,input().split())
    if n == 0:
        exit()
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i + j + k == x:
                    a += 1
    print(a)



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

int main(){
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, 0, n){
        cout << s[i] << t[i] ;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int c[6][6];
int main(){
    int h,w,K;
    cin>> h>> w>> K;
    rep(i,h){
        rep(j,w){
            char s;
            cin>>s;
            if(s=='.'){
                c[i][j]=0;
            }else{
                c[i][j]=1;
            }
        }
    }
    //cerr<<'O'<<endl;
    int ans=0;
    //cerr<<(1<<(h+w))<<endl;
    rep(k,1<<(h+w)){
        int temp=0;
        int d[h][w];
        rep(i,h){
            rep(j,w){
                d[i][j]=c[i][j];
                //cerr<<d[i][j];
            }
            //cerr<<endl;
        }
        rep(j,h+w){
            if((k>>j&1)==1){
                if(j<h){
                    rep(i,w){
                        d[j][i]=0;
                    }
                }else{
                    rep(i,h){
                        d[i][j-h]=0;
                    }
                }
            }
        }
        rep(i,h){
            rep(j,w){
                if(d[i][j]==1){
                    temp++;
                }
                //cerr<<d[i][j];
            }
            //cerr<<endl;
        }
        //cerr<<temp<<endl;
        if(temp==K){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	Info(){
		div = left = right = number = left_index = right_index = 0;
	}
	int div,left,right,left_index,right_index,number;
};

void func(int n){
	int table[n+1],index = 0,div;

	Info info[3];

	scanf("%d",&table[0]);
	scanf("%d",&table[1]);

	info[0].div = table[1] - table[0];
	info[0].left = table[0];
	info[0].left_index = 0;
	info[0].right = table[1];
	info[0].right_index = 1;
	info[0].number = 1;
	index++;

	bool Found;
	for(int i = 2;i < n+1; i++){
		scanf("%d",&table[i]);

		div = table[i] - table[i-1];

		Found = false;

		for(int k = 0; k < index; k++){
			if(info[k].div == div){
				info[k].number++;
				Found = true;
				break;
			}
		}
		if(!Found){
			info[index].div = table[i] - table[i-1];
			info[index].left = table[i-1];
			info[index].left_index = i-1;
			info[index].right = table[i];
			info[index].right_index = i;
			info[index].number = 1;
			index++;
		}
	}

	if(index == 2){ //case  9 1 2 3 4, 1 2 3 4 9,   2 3 4 6 8 10,   2 4 5 6 8,  2 4 6 7 8
		if(info[0].number < info[1].number){
			if(table[2] - table[1]  == info[0].div){ // 2 3 4 6 8 10
				printf("%d\n",info[0].right);
			}else{ // 9 1 2 3 4
				printf("%d\n",info[0].left);
			}
		}else if(info[1].number < info[0].number){ //1 2 3 4 9, 2 4 6 8 9 10
			printf("%d\n",info[1].right);
		}else{ //info[0].number == info[1].number && n == 4
			if(info[1].left_index == 1){ // 2 4 5 6 8
				printf("%d\n",table[2]);
			}else{
				if(table[2] - table[0] == info[1].div){ // 2 3 4 6 8
					printf("%d\n",table[1]);
				}else{	// 2 4 6 7 8
					printf("%d\n",table[3]);
				}
			}
		}

	}else{ //index == 3

		if(info[0].number == 1)printf("%d\n",info[0].right);
		else{
			printf("%d\n",info[1].right);
		}
	}

}

int main(){

	int n;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		func(n);
	}
    return 0;
}

Measured memory_bytes: 2708
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import static java.lang.Integer.parseInt;

/**
 * Rearranging a Sequence
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();

		int n, m;
		n = parseInt(line.substring(0, line.indexOf(' ')));
		m = parseInt(line.substring(line.indexOf(' ') + 1));

		List<Integer> list = new ArrayList<>(n + m);
		boolean[] dup = new boolean[n + 1];

		for (int i = n; i >= 1; i--) list.add(i);

		for (int i = 0; i < m; i++) list.add(parseInt(br.readLine()));

		StringBuilder sb = new StringBuilder();

		for (int i = list.size() - 1; i >= 0; i--) {
			int e = list.get(i);
			if (!dup[e]) {
				sb.append(e).append('\n');
				dup[e] = true;
			}
		}

		System.out.print(sb.toString());

	}
}

Measured memory_bytes: 55996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int sc[30][int(1e5+10)];

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N,C; cin >> N >> C;
    REP(i,30)
    {
        REP(j,1e5+10) sc[i][j] = 0;
    }

    REP(i,N)
    {
        int s,t,c; cin >> s >> t >> c;
        sc[c-1][s]++;
        sc[c-1][t+1]--;
    }
    REP(i,30) 
    {
        FOR(j,1,1e5+10)
        {
            sc[i][j] = sc[i][j-1] + sc[i][j];
            if(sc[i][j-1]) sc[i][j-1] = 1;
        }
    }
    LL ans = 0;
    REP(i,1e5+10)
    {
        int tmp = 0;
        REP(j,30)
        {
            tmp += sc[j][i];
        }
        if(tmp > ans) ans = tmp;
    }
    cout << ans << endl;

}


Measured memory_bytes: 12032
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(n):
    ans=0
    a=list(map(int,input().split()))
    for i in range(m):
        ans+=a[i]*b[i]
    if ans+c>0:
        count+=1
print(count)

Measured memory_bytes: 9096
#include<bits/stdc++.h>
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define YES cout<<"YES"<<endl
#define all(v) v.begin(),v.end()
#define NO cout<<"NO"<<endl
#define pb(x) emplace_back(x)
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define mi map<ll,ll>
#define pi pair<ll,ll>
#define what(x) cout<<#x<<" ="<<x<<endl;
using namespace std;
using ll =long long;

ll dp[105][100005];
vi w(100005),val(100005);
ll n;


int main()
{
    fastio;
        fr(j,0,100005)dp[0][j]=1e18;

        fr(i,0,105)dp[i][0]=0LL;
       // cout<<dp[0][0]<<endl;

        ll W;
        cin>>n>>W;

        ll s=0;
        fr(i,0,n)cin>>w[i]>>val[i],s+=val[i];


        fr(i,0,n)
        {
            fr(j,1,s+1)
            {
                if(j>=val[i])
                {
                    dp[i+1][j]=min(dp[i][j],w[i]+dp[i][j-val[i]]);
                }
                else dp[i+1][j]=dp[i][j];
            }
        }

            ll ans=0;
            fr(j,0,s+1)
            if(dp[n][j]<=W)ans=j;

            cout<<ans<<endl;














}




























Measured memory_bytes: 83600
n = int(input())
x = input()
original_pop_cnt = x.count("1")

pop_cnt_add = original_pop_cnt + 1
pop_cnt_sub = original_pop_cnt - 1

n_after_once_popcount_add = 0
n_after_once_popcount_sub = 0

for i in range(n):
    n_after_once_popcount_add = (n_after_once_popcount_add * 2 + int(x[i])) % pop_cnt_add
    if pop_cnt_sub != 0:
        n_after_once_popcount_sub = (n_after_once_popcount_sub * 2 + int(x[i])) % pop_cnt_sub

pow_add = [1] * 250000
pow_sub = [1] * 250000
for i in range(1, n + 100):
    pow_add[i] = (pow_add[i-1]*2) % pop_cnt_add
    if pop_cnt_sub != 0:
        pow_sub[i] = (pow_sub[i-1]*2) % pop_cnt_sub

def f(nex):
    ans = 0
    num = nex
    while num != 0:
        num = num % bin(num).count("1")
        ans += 1
    return ans

for i in range(n-1, -1, -1):
    if x[n - 1 - i] == "0":
        nxt = n_after_once_popcount_add
        nxt = nxt + pow_add[i]
        nxt = nxt % pop_cnt_add
        print(f(nxt) + 1)
    if x[n - 1 - i] == "1":
        if pop_cnt_sub != 0:
            nxt = n_after_once_popcount_sub
            nxt = nxt - pow_sub[i]
            nxt = nxt % pop_cnt_sub
            print(f(nxt) + 1)
        else:
            print(0)




Measured memory_bytes: 25708
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int k;
    cin >> k;
    ll ans = 0;
    for(int i=1;i<=k;i++)for(int j=1;j<=k;j++)for(int a=1;a<=k;a++){
        int t = __gcd(i,j);
        t = __gcd(t,a);
        ans += t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

struct Index {
  int x, y, z;
  Index(int a, int b, int c) : x(a), y(b), z(c) {}
  bool operator<(const auto &right) const {
    if (x != right.x) return x < right.x;
    if (y != right.y) return y < right.y;
    return z < right.z;
  }
};

struct Data {
  Index index;
  LL v = 0;
  Data(Index idx, LL w) : index(idx), v(w) {}
  bool operator<(const auto &right) const {
    return v < right.v;
  }
};

bool done[300][300][300] = {};

int main() {
  int X, Y, Z, K; std::cin >> X >> Y >> Z >> K;
  std::vector<LL> A(X), B(Y), C(Z);
  for (int i = 0; i < X; ++i) std::cin >> A[i];
  for (int i = 0; i < Y; ++i) std::cin >> B[i];
  for (int i = 0; i < Z; ++i) std::cin >> C[i];

  std::sort(A.rbegin(), A.rend());
  std::sort(B.rbegin(), B.rend());
  std::sort(C.rbegin(), C.rend());

  std::priority_queue<Data> que;
  std::map<Index, bool> done;

  Index idx(0, 0, 0);
  que.push(Data(idx, A[0] + B[0] + C[0]));
  done[idx] = true;
  for (int i = 0; i < K; ++i) {
    Data d = que.top();
    que.pop();

    int x = d.index.x;
    int y = d.index.y;
    int z = d.index.z;
    std::cout << d.v << std::endl;

    Index idx_x(x+1, y, z), idx_y(x, y+1, z), idx_z(x, y, z+1);
    if (!done[idx_x] && x + 1 < X) {
      que.push(Data(idx_x, A[x+1] + B[y] + C[z]));
      done[idx_x] = true;
    }
    if (!done[idx_y] && y + 1 < Y) {
      que.push(Data(idx_y, A[x] + B[y+1] + C[z]));
      done[idx_y] = true;
    }
    if (!done[idx_z] && z + 1 < Z) {
      que.push(Data(idx_z, A[x] + B[y] + C[z+1]));
      done[idx_z] = true;
    }
  }
}


Measured memory_bytes: 896
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

class UnionFindTree
    attr_accessor:par,:rank
    def initialize(n)
        @par=Array.new(n){|i| i}
        @rank=array(n,0)
    end

    def find(x)
        return x if @par[x]==x
        @par[x]=find(@par[x])
        return @par[x]
    end

    def union(x,y)
        x=find(x)
        y=find(y)
        return if x==y
        if @rank[x]<@rank[y]
            @par[x]=y
        else
            @par[y]=x
            @rank[x]+=1 if @rank[x]==@rank[y]
        end
    end

    def same?(x,y)
        return find(x)==find(y)
    end
end
N,M=get_i
P=get_i
idx=array(N)
N.times do|i|
  idx[P[i]-1]=i
end
uft=UnionFindTree.new(N)
M.times do
    x,y=get_i
    x-=1
    y-=1
    uft.union(x,y)
end
ans=0
N.times do|i|
  if uft.same?(i,idx[i])
    ans+=1
  end 
end
puts ans

Measured memory_bytes: 13596
def ringo(d,n):
    if (d == 0 and n < 100):
        return n
    elif(d == 0 and n == 100):
        return n + 1
    elif(d == 1 and n < 100):
        return 100 * n
    elif(d == 1 and n == 100):
        return 100 * n + 100
    elif(d == 2 and n < 100):
        return 10000 * n
    elif(d == 2 and n == 100):
        return 10000 * n + 10000
    else:
        return 0

l = input().split()
print(ringo(int(l[0]),int(l[1])))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define getMat(x, n, m, val) vector<vector<long long int>> x(n, vector<long long int> (m, val))
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,ans=0;
    string x;
    cin>>n;
    cin>>x;
    int found=x.find("ABC");
    if(found>=0){
        ans++;
        while(found != string::npos){
            found=x.find("ABC",found +1);
             if(found!=-1){
            ans++;
        }else break;
        }
    }else{
    cout<<0;
    return 0;
    }
  cout<<ans;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(){
   int n;
   long sum,i,j;
   double sumb,b;
   char d[20];
    
   scanf("%d",&n);
   sumb=sum=0;
   for (i=0;i<n;i++) {
      scanf("%lf %s",&b,d);
      if (strcmp(d,"JPY")==0) sum+=b;
      else                    sumb+=b;
   }
   printf("%lf\n",sum+sumb*380000.0);
   return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, char, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll mod = 1000000007;

static const ll INF = 1e15;

int main(void)
{
	int n, m;
	cin >> n >> m;
	vector<ll> cs(m);
	rep(i, m)cin >> cs[i];
	vector<ll> dp(n + 1, INF);
	dp[0] = 0;
	rep(i, m) {
		auto c = cs[i];
		rep(j, n + 1) {
			auto p = j - c;
			if (p >= 0) {
				if (dp[p] != INF) {
					dp[j] = min(dp[j], dp[p] + 1);
				}
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}




Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int x; scanf("%d", &x);
	int p = x / 100, q = x % 100;
	int r = q / 5 + (q%5 ? 1 : 0);
	DEBUG("%d %d %d\n", p, q, r);
	if(p >= r) printf("1\n");
	else printf("0\n");
}


Measured memory_bytes: 256
/* AOJ 0051
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0051
 *
 */

#include <stdio.h>
#include <stdlib.h>


int comp_char_asc(const void* a, const void* b){

    return *((char*)a) - *((char*)b);
}

int comp_char_dsc(const void* a, const void* b){

    return *((char*)b) - *((char*)a);
}

int main(){
    int n;
    int max, min;
    char buf[9];

    scanf("%d", &n);

    while(scanf("%s", buf)== 1){
        qsort(buf, 8, 1, comp_char_asc);
        sscanf(buf, "%d", &min);

        qsort(buf, 8, 1, comp_char_dsc);
        sscanf(buf, "%d", &max);
        printf("%d\n", max-min);

    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
#define Matrix vector<vector<int> >
// #define Matrix vector<vector<int> >
#define double long double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9+7;
const long long INF = 5e18;
const double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
 
inline long long mod(long long n, long long m){
    long long ret = n%m;
    if(ret < 0) ret += m;
    return ret;
}
 
double rad(double x){
    return x*pi/180.0;
}
 
bool isleft(pair<int,int> a, pair<int,int> b, pair<int,int> c){
    int det = (b.first-a.first)*(c.second-a.second) - (c.first-a.first)*(b.second-a.second);
    if(det>=0) return true;
    if(det<0) return false;
    return false;
}
 
int exp(int a, int b){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = mod(result*a,MOD);
 
        b >>= 1;
        a = mod(a*a,MOD);
    }
    return result;
}

void solve(){
    int q,w;
    cin>>q>>w;
    int v[123456];
    for(int i=0;i<123456;i++){
        v[i]=INF;
    }
    v[0]=0;
    while(q--){
        int n,p;
        cin>>n>>p;
        for(int i=123455;i>=p;i--){
            if(v[i-p]==INF) continue;
            v[i]=min(v[i],v[i-p]+n);
        }
    }
    int ans;
    for(int i=0;i<123456;i++){
        if(v[i]!=INF and v[i]<=w){
            ans=i;
        }
    }
    cout<<ans<<endl;
}
 
signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  string s;
  cin >> s;
  int ans = 0;
while(s.size()){
s.pop_back();
s.pop_back();
string t;
rep(i,SZ(s)/2) t.push_back(s[i]);
if(t+t == s) ans = max(ans,(int)t.size()*2);
}
cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
double ans=0;
void Main(){
    double r;cin>>r;
    ans = r * 6.2831853071795862320;
    cout<<fixed<<setprecision(10)<<ans<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3792
<?php
fscanf(STDIN, '%d %d %d', $height, $width, $remain);
$blacks = [];
$answer = 0;
for ($i = 0; $i < $height; $i++) {
    fscanf(STDIN, '%s', $line);
    $tmp = str_split($line);
    $bools = [];
    foreach ($tmp as $value) {
        $bools[] = $value === '#';
    }
    $blacks[] = $bools;
}

for ($maskR = 0; $maskR < (1 << $height); $maskR++) {
    for ($maskC=0; $maskC < (1 << $width); $maskC++) { 
        $cnt = 0;
        for ($i = 0; $i < $height; $i++) {
            for ($j = 0; $j < $width; $j++) {
                if ((($maskR >> $i) & 1) === 0 && (($maskC >> $j) & 1) === 0 && $blacks[$i][$j] === true) {
                    $cnt++;
                }
            }
        }
        if ($cnt === $remain) {
            $answer++;
        }
    }
}
echo $answer;


Measured memory_bytes: 16236