akhauriyash/Code-Regression huggingface dataset:
// C++ code to find maximum possible product of 
// sub-sequence of size k from given array of n 
// integers 
#include <algorithm> // for sorting 
#include <iostream> 
#define M 1000000007
using namespace std; 

// Driver Code to test above function 
int main() 
{ 
	int n,m,k;
	cin>>n>>m>>k;
	string arr[n];
	for(int i=0;i<n;i++)
	    cin>>arr[i];
	int ans=0;
	for(int a=0;a<(1<<n);a++)
	{
	    for(int b=0;b<(1<<m);b++)
	    {
	        int black=0;
	        for(int i=0;i<n;i++)
	        {
	            for(int j=0;j<m;j++)
	            {
	                if((a & (1<<i)) || (b & (1<<j))) continue;
	                if(arr[i][j]=='#')  black++;
	            }
	        }
	        if(black==k)    ans++;
	    }
	}
    cout<<ans;
	return 0; 
} 


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

int f(int x);
int main()
{
  int n;
  scanf("%d",&n);
  int p[n],q[n];
  for(int i=0;i<n;i++) scanf("%d",&p[i]);
  for(int j=0;j<n;j++) scanf("%d",&q[j]);

  int a=0;
  int b=0;
  int c,d;
  for(int k=0;k<n;k++){
    c=0;
    d=0;
    for(int l=0;l<k;l++){
      if(p[l]<p[k])c=c+1;
      if(q[l]<q[k])d=d+1;
  }
    
    if(p[k]-(c+1)<=0) a=a;
    else a=a+(p[k]-(c+1))*f(n-k-1);
    if(q[k]-(d+1)<=0) b=b;
    else b=b+(q[k]-(d+1))*f(n-k-1);
}
  printf("%d\n",abs(a-b));
  return 0;
}

int f(int x){
  int s=1;
  for(int i=1;i<x+1;i++){
      s=s*i;
  }
  return s;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
int main()
{
    IO;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // #endif
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < 3; i++){
        if (s[i] == 'R')
        {
            ans++;
        }
    }
    if (ans == 2 and s[1] == 'S')
    {
        ans--;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3636
// 解説後
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

template <typename T>
struct Vector2 {
  Vector2& operator+=(const Vector2& other) noexcept {
    x += other.x;
    y += other.y;
    return *this;
  }

  friend Vector2 operator+(Vector2 lhs, Vector2 rhs) noexcept {
    return Vector2(lhs) += rhs;
  }

  template<typename U>
  auto dot(Vector2<U> rhs) const noexcept {
    return x * rhs.x + y * rhs.y;
  }

  auto norm2() const noexcept { return dot(*this); }

  auto norm() const noexcept { return sqrt(norm2()); }

  T x, y;
};

// L^2ノルムを最大化したいので、方向が同じベクトルを集める
int solve_F() {
  size_t N;
  std::cin >> N;

  std::vector<Vector2<double>> directions(360);
  for (size_t i = 0; i < directions.size(); ++i) {
    const double angle = 3.14159265358979 * 2 * i / directions.size();
    directions[i].x = cos(angle);
    directions[i].y = sin(angle);
  }


  std::vector<Vector2<int64_t>> summations(directions.size());
  for (size_t i = 0; i < N; ++i) {
    Vector2<int64_t> v;
    std::cin >> v.x >> v.y;

    for (size_t j = 0; j < directions.size(); ++j) {
      if (directions[j].dot(v) >= 0.0) {
        summations[j] += v;
      }
    }
  }

  double result = 0.0;
  for (const auto& v : summations) {
    result = std::max(result, v.norm());
  }

  std::cout << std::setprecision(20) << result;
  return 0;
}

int main() { return solve_F(); }


Measured memory_bytes: 384
#include <iostream>

class Node {
    public:
        const int value;
        Node* prev;
        Node* next;

        Node(int value): value(value) {}
        ~Node() {
            delete prev;
            delete next;
        }
};

class LinkedList {
    Node* guard;
    int _size;

    public:
        const int id;

        LinkedList(int id, Node* first): id(id) {
            guard = new Node(-1);
            guard->next = first;
            guard->prev = first;
            first->next = guard;
            first->prev = guard;
            _size = 1;
        }

        ~LinkedList() {
            delete guard;
        }

        void append_all(LinkedList* other) {
            last()->next = other->first();
            other->first()->prev = last();

            guard->prev  = other->last();
            other->last()->next  = guard;

            _size += other->size();
        }

        Node* first() {
            return guard->next;
        }

        Node* last() {
            return guard->prev;
        }

        bool is_end(Node* node) {
            return node == guard;
        }

        int size() {
            return _size;
        }
};

LinkedList **SETs;

void unite(int x, int y) {
    if ( SETs[x] == SETs[y] ) return;

    bool is_x_bigger = SETs[x]->size() >= SETs[y]->size();
    LinkedList* main = is_x_bigger ? SETs[x] : SETs[y];
    LinkedList* sub  = is_x_bigger ? SETs[y] : SETs[x];

    Node* node = sub->first();
    while(! sub->is_end(node)) {
        SETs[ node->value ] = main;
        node = node->next;
    }
    main->append_all(sub);
}

bool same(int x, int y) {
    return SETs[x]->id == SETs[y]->id;
}

void create_sets(int n) {
    for (int i = 0; i < n; i++) {
        Node *node = new Node(i);
        LinkedList *set = new LinkedList(i, node);
        SETs[i] = set;
    }
}

int main() {
    int n, q;
    std::cin >> n >> q;

    SETs = new LinkedList*[n];
    create_sets(n);

    int command, x, y;
    for (int i = 0; i < q; i++) {
        std::cin >> command >> x >> y;
        switch (command) {
            case 0:
                unite(x, y);
                break;
            case 1:
                std::cout << ( same(x, y) ? 1 : 0 ) << "\n";
                break;
        }
    }
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  string t;
  int sum = 0;
  while (true) {
    cin >> t;
    if (t == "END_OF_TEXT") break;

    if (s.size() != t.size()) continue;

    bool flag = true;
    for (int i = 0; i < s.size(); i ++) {
      if (s[i] == t[i] || s[i] == t[i] + 32 || s[i] + 32 == t[i]) continue;
      flag = false;
    }
    if (flag) sum ++;
  }

  cout << sum << endl;
}


Measured memory_bytes: 3184
/* Greatest Common Divisor */

#include <stdio.h>

unsigned gcd(unsigned, unsigned);

int main( void ) {
  unsigned a, b;
  scanf("%u", &a);
  scanf("%u", &b);

  printf("%u\n", gcd(a, b));

  return 0;
}

unsigned gcd(unsigned m, unsigned n) {
  unsigned tmp;
  if(n == 0) return m;
  if(n > m) {
    tmp = m;
    m = n;
    n = tmp;
  }
  gcd(n, m % n);
}

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

class Dice {
	array<int, 6> m_faces;

public:
	explicit Dice( const array<int, 6>& f ):
		m_faces( f )
	{}

	int top() const {
		return m_faces.at( 0 );
	}

	int right() const {
		return m_faces.at( 2 );
	}

	void roll( char dir ) {
		if( dir == 'N' ) {
			swapFace( 1, 5, 2, 3, 0, 4 );
		}
		else if( dir == 'S' ) {
			swapFace( 4, 0, 2, 3, 5, 1 );
		}
		else if( dir == 'W' ) {
			swapFace( 2, 1, 5, 0, 4, 3 );
		}
		else if( dir == 'E' ) {
			swapFace( 3, 1, 0, 5, 4, 2 );
		}
	}

	void swapFace( int i0, int i1, int i2, int i3, int i4, int i5 ) {
		array<int, 6> f = m_faces;

		m_faces.at( 0 ) = f.at( i0 );
		m_faces.at( 1 ) = f.at( i1 );
		m_faces.at( 2 ) = f.at( i2 );
		m_faces.at( 3 ) = f.at( i3 );
		m_faces.at( 4 ) = f.at( i4 );
		m_faces.at( 5 ) = f.at( i5 );
	}
};

int main() {
	array<int, 6> f;
	for( auto& v: f ) { cin >> v; }

	Dice dice( f );

	int q;
	cin >> q;

	for( int i = 0; i < q; ++i ) {
		int tp, fr;
		cin >> tp >> fr;

		for( auto ch: "NNNEEE" ) {
			if( dice.top() == fr ) { break; }

			dice.roll( ch );
		}

		dice.roll( 'S' );

		for( auto ch: "EEE" ) {
			if( dice.top() == tp ) { break; }

			dice.roll( ch );
		}

		cout << dice.right() << endl;
	}
}



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
ll v[3];
int n, x[maxn], y[maxn];
vector<int> id[3][3];
char res[maxn];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> v[0] >> v[1] >> v[2];
	for (int i = 0;i < n;++i) {
		string w;
		cin >> w;
		int a = w[0]-'A', b = w[1]-'A';
		id[a][b].pb(i);
		id[b][a].pb(i);
		x[i] = a, y[i] = b;
	}
	for (int i = 0;i < 3;++i) for (int j = 0;j < 3;++j)
		id[i][j].pb(n);
	for (int i = 0;i < n;++i) {
		int c = 3 - x[i] - y[i];
		if ( v[ x[i] ] == v[ y[i] ] && v[c] < v[x[i]]) {
			if (v[ x[i] ] + v[ y[i] ] == 0) return cout << "No\n", 0;
			int a = *upper_bound(id[x[i]][c].begin(), id[x[i]][c].end(), i),
				b = *upper_bound(id[y[i]][c].begin(), id[y[i]][c].end(), i);
			if (a < b) {
				res[i] = x[i];
				++v[x[i]], --v[y[i]];
			}
			else {
				res[i] = y[i];
				++v[y[i]], --v[x[i]];
			}
		}
		else if (v[ x[i] ] < v[ y[i] ]) {
			res[i] = x[i];
			++v[x[i]];
			--v[y[i]];
		}
		else {
			if (v[x[i]] + v[y[i]] == 0) return cout << "No\n", 0;
			res[i] = y[i];
			++v[y[i]];
			--v[x[i]];
		}
	}
	cout << "Yes\n";
	for (int i = 0;i < n;++i)
		cout << (char)('A' + res[i]) << '\n';
}



Measured memory_bytes: 5368
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let p = read_vec::<usize>()
        .iter()
        .map(|x| x - 1)
        .collect::<Vec<_>>();
    let mut uft = UnionFindTree::new(n);
    for i in 0..m {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        uft.unite(p[a], p[b]);
    }
    let mut ans = 0;
    for i in 0..n {
        if uft.same(i, p[i]) {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[derive(Debug, Clone)]
struct UnionFindTree {
    parent: Vec<isize>,
    size: Vec<usize>,
    height: Vec<u64>,
}

impl UnionFindTree {
    fn new(n: usize) -> UnionFindTree {
        UnionFindTree {
            parent: vec![-1; n],
            size: vec![1usize; n],
            height: vec![0u64; n],
        }
    }

    fn find(&mut self, index: usize) -> usize {
        if self.parent[index] == -1 {
            return index;
        }
        let idx = self.parent[index] as usize;
        let ret = self.find(idx);
        self.parent[index] = ret as isize;
        ret
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn get_size(&mut self, x: usize) -> usize {
        let idx = self.find(x);
        self.size[idx]
    }

    fn unite(&mut self, index0: usize, index1: usize) -> bool {
        let a = self.find(index0);
        let b = self.find(index1);
        if a == b {
            false
        } else {
            if self.height[a] > self.height[b] {
                self.parent[b] = a as isize;
                self.size[a] += self.size[b];
            } else if self.height[a] < self.height[b] {
                self.parent[a] = b as isize;
                self.size[b] += self.size[a];
            } else {
                self.parent[b] = a as isize;
                self.size[a] += self.size[b];
                self.height[a] += 1;
            }
            true
        }
    }
}


Measured memory_bytes: 8444
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			// int n = int.Parse(Console.ReadLine());
			// string s = Console.ReadLine();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int n = vs[0];
			int m = vs[1];
			int[][] bridges = new int[m][];
			for (int i = 0; i < m; i++) {
				bridges[i] = Console.ReadLine().Split().Select(p => int.Parse(p) - 1).ToArray();
			}
			Array.Reverse(bridges);
			UnionFind union = new UnionFind(n);
			long[] ans = new long[m];
			ans[0] = n * ((long)n - 1) / 2;
			for (int i = 0; i < m - 1; i++) {
				int a = bridges[i][0];
				int b = bridges[i][1];
				if (!union.Same(a, b)) {
					ans[i + 1] = ans[i] - union.Size(a) * union.Size(b);
				} else {
					ans[i + 1] = ans[i];
				}
				union.Unite(a, b);
			}
			Array.Reverse(ans);
			foreach (var item in ans) {
				Console.WriteLine(item);
			}


			Console.Out.Flush();
		}
	}



	public class UnionFind
	{
		private readonly UnionFindNode[] _Parent;

		public UnionFind(int n)
		{
			_Parent = new UnionFindNode[n];
			for (int i = 0; i < n; i++) {
				_Parent[i] = new UnionFindNode(i, 1);
			}
		}

		public int Find(int x)
		{
			if (_Parent[x].Parent == x) {
				return _Parent[x].Parent;
			}
			return _Parent[x].Parent = Find(_Parent[x].Parent);
		}

		public int Size(int x)
		{
			return _Parent[Find(x)].Size;
		}

		public void Unite(int x, int y)
		{
			int rx = Find(x);
			int ry = Find(y);
			if (rx != ry) {
				_Parent[ry].Parent = rx;
				_Parent[rx].Size += _Parent[ry].Size;
			}
		}

		public bool Same(int x, int y)
		{
			int rx = Find(x);
			int ry = Find(y);
			return rx == ry;
		}

		public override string ToString()
		{
			return string.Join(" ", _Parent.Select(p => $"({p.Parent},{p.Size})"));
		}
	}
	public class UnionFindNode
	{
		public int Parent;
		public int Size;
		public UnionFindNode(int parent, int size)
		{
			Parent = parent;
			Size = size;
		}
	}



}


Measured memory_bytes: 27060
Scanf.scanf "%d %d" (fun n m ->
    let s = Array.make 210000 0 in
    for i = 1 to m do
        Scanf.scanf " %d %d" (fun a b ->
            if a = 1 then s.(b) <- s.(b) lor 1;
            if b = 1 then s.(a) <- s.(a) lor 1;
            if a = n then s.(b) <- s.(b) lor 2;
            if b = n then s.(a) <- s.(a) lor 2;
        )
    done;
    let a = Array.fold_left (fun acc v -> if v = 3 then true else acc) false s in
    print_endline @@ if a then "POSSIBLE" else "IMPOSSIBLE"
)

Measured memory_bytes: 7456
#include<iostream>
using namespace std;
int main(){
    int H, W, i, j;
    cin >> H >> W;
    
    while(H != 0 && W != 0){
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if((i+j)%2==0){
                    cout << "#";
                }else{
                    cout <<".";
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include<vector>
#include<math.h>
using namespace std;

typedef pair<int,long long> p;

int main(){
    string S;
    long long K;
    cin >> S;
    cin >> K;
    for(int i=0;i<K;i++){
        if(S[i]!='1'){
            cout << S[i];
            exit(0);
        }
    }
    cout << '1';
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

typedef long long i64;
typedef pair<i64, i64> pii;

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

const int INF = 0x3f3f3f3f;
const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9) + 7;

int to_int(char c) {
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5;
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
}

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

  string a, b;
  cin >> a >> b;

  if (a.length() > b.length()) cout << "GREATER" << "\n";
  else if (a.length() < b.length()) cout << "LESS" << "\n";

  else if (a.length() == b.length()) {
    if (a == b) {
      cout << "EQUAL" << "\n";
      return 0;
    }
    for (int i = 0; i < a.length(); ++i) {
      int a_num = to_int(a[i]);
      int b_num = to_int(b[i]);
      if (a_num > b_num) {
        cout << "GREATER" << "\n";
        return 0;
      }
      else if (a_num < b_num) {
        cout << "LESS" << "\n";
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

int a,sum=0;
cin>>a;

sum=a+(a*a)+(a*a*a);
cout<<sum;





	return 0;
 }

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <map>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;


int main()
{
    std::string S;
    std::cin >> S;
    ll result = 0;

    ll length = S.size();
    ll candiadtes = length-1;
    for (auto bit=0; bit < (1<<candiadtes); ++bit)
    {
        bool separation[length];

        // 桁の終端は必ず区切る
        separation[length - 1] = true;

        for (auto i=0; i < candiadtes; ++i)
        {
            //仕切りを入れるか
            // bit: 00 のとき 125 /
            // bit: 01 のとき 1 / 25 /
            // bit: 10 のとき 12 / 5 /
            // bit: 11 のとき 1 / 2 / 5 /
            auto willSeparate = bit & (1 << i);
            separation[i] = willSeparate;
        }

        ll from = 0;
        ll sum = 0;
        for (auto i=0; i<length; ++i)
        {
            if (separation[i])
            {
                ll to = i+1;
//                std::cout << from << " " << to << " -> ";
//                std::cout << S.substr(from, to - from) << " / ";
                sum += std::stol(S.substr(from, to - from));
                from = to;
            }
        }
//        std::cout << sum << std::endl;
        result += sum;
    }

    std::cout << result << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int x[3];
    scanf( "%d %d %d",&x[0],&x[1],&x[2] );

    for( int i = 0;i < 2;i++ ){
        for( int k = 0;k < 2;k++ ){
            if( x[k] > x[k+1] ){
                int buf = x[k];
                x[k] = x[k+1];
                x[k+1] = buf;
            }
        }
    }
    for( int i = 0;i < 3;i++ ){
        printf( "%d",x[i] );
        if( i < 2 )printf( " " );
    }
    printf( "\n" );
    return 0;
} 

Measured memory_bytes: 1028
#include <string>
#include <iostream>
#include <algorithm>

int main()
{
    int n,l;
    std::string s[110];
    std::string backet[26][110];
    std::cin >> n>>l;
    for (int i = 0;i < n;i++) {
        std::cin >> s[i];
    }
    std::sort(s, s + n);
    for (int i = 1;i < n;i++) {
        s[0] += s[i];
    }
    std::cout << s[0] << std::endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){  
    long long int n, d, count = 0, a, b;
    cin >> n >> d;
    for(int i = 0; i < n; i++){
    	cin >> a >> b;
    	if(sqrt(a * a + b * b) <= d){
    		count++;
    	}
    }
    cout << count;
}

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

int is_prime(int);

int main(){
  int i,j;
  int a[10000];
  int con=0;
  scanf("%d",&i);
  for(j=0;j<i;j++){
    scanf("%d",&a[j]);
  }
  for(j=0;j<i;j++){
    if(is_prime(a[j])==1){
      con+=1;
    }
  }
  printf("%d\n",con);
  return 0;
}

int is_prime(int num){
  int i;
  if(num<2)return 0;
  else if(num==2)return 1;
  else if(num%2==0)return 0;

  else{
    for(i=3;i<=sqrt(num);i+=2){
    if(num%i==0){
      return 0;
    }
  }
  }
  return 1;
}



Measured memory_bytes: 2068
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		long ans  = 0;
		for(int i = 1; i < n; i++)
			ans += i;
		out.print(ans);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll cnt,ans,a,b,c,d,tmp,tmpp,m,h,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),ss;
bool fl;
struct edge{int to,cost;};
ll n,w,s,e;

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>ss;
    rep(i,Size(ss)){
        if(ss[i]=='N')n=1;
        else if(ss[i]=='W')w=1;
        else if(ss[i]=='S')s=1;
        else e=1;
    }
    if(n==s&&w==e)Cout("Yes");
    else Cout("No");
    return 0;
}


Measured memory_bytes: 764
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

res = 10 ** 9
for a in A:
    if a % 2 == 1:
        res = 0
        break
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1
    res = min(res, cnt)
print(res)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int a,b,h;
void init(){
	scanf("%d%d%d",&a,&b,&h);
	if(a%2&&b%2&&h%2){
		double ans1=(a+b+0.0)*h/2.0;
		printf("%.1lf\n",ans1);
	}
	else{
		int ans=(a+b)*h/2;
		printf("%d\n",ans);
	}
}
int main(void){
	init();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <vector>
    #include <algorithm>
     
    int main() {
      
      unsigned long long H, W;
      std::cin >> H >> W;
      if(W == 1 || H == 1)
        std::cout << 1 << std::endl;
      else
        std::cout << (W-W/2) * (H-H/2) + (W/2) * (H/2) << std::endl;
    }

Measured memory_bytes: 256
S = input()

if S == "SUN":
    print("7")
if S == "MON":
    print("6")
if S == "TUE":
    print("5")
if S == "WED":
    print("4")
if S == "THU":
    print("3")
if S == "FRI":
    print("2")
if S == "SAT":
    print("1")



Measured memory_bytes: 8992
#include <cstdio>
 
#define i64 long long
using namespace std;
int main(){
  i64 r,n;
  while(scanf("%lld",&n),n){
    r=0LL;
    for(i64 i=1LL;i*i<n;i++){
      if(!(n%i)){
        r+=i;if(i>1)r+=n/i;
      }
    }
    // printf("%d %d\n",n,r);
    if(r>n){
      puts("abundant number");
    }
    else if(r==n&&n!=1){
      puts("perfect number");
    }
    else{
      puts("deficient number");
    }
  }
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
bool fnc(char ch){
  return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
int main(){
  char ch;
  scanf("%c", &ch);
  printf("%s\n", fnc(ch) ? "vowel" : "consonant");
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  int d[b];
  for(int i=0; i<b; i++){
    scanf("%d",&d[i]);
  }
  int e=0,f;
  for(int i=0; i<a; i++){
    f=0;
    for(int j=0; j<b; j++){
      int g;
      scanf("%d",&g);
      f+=g*d[j];
    }
    if(f+c>0){e++;}
  }
  printf("%d",e);
  return 0;}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

bool include3(int n) {
    while (n) {
        if (n % 10 == 3) return true;
        n /= 10;
    }
    return false;
}

void call(int n) {
    for (int i = 1; i<= n; i++)
        if (i % 3 == 0 || include3(i)) cout << ' ' << i;
    cout << endl;
}

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


Measured memory_bytes: 3096
a=[]
while True:
 n=input()
 if n.find('?')>0:break
 a.append(n)
for s in a:
 t=s.split()
 if t[1]=='/':
  print(int(t[0])//int(t[2]))
 else:
  b=eval(''.join(t))
  print(b)

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;
  vector<string> s(n);
  REP(i, n)
    cin >> s[i];

  ll m;
  cin >> m;
  vector<string> t(m);
  REP(i, m)
    cin >> t[i];

  map<string, ll> num;
  set<string> key;
  REP(i, n){
    num[s[i]] += 1;
    key.insert(s[i]);
  }

  REP(i, m){
    num[t[i]] -= 1;
    key.insert(t[i]);
  }

  ll ans = 0;
  for(auto& it : key){
    //cout << it << ":" << num[it] << endl;
    ans = max(num[it], ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define fr first
#define sc second
using namespace std;
int main(){
  int n,N,cnt;
  while(cin >> N && N){
    n = N,cnt = 0;
    while(n > 0){
      cnt += n/5;
      n /= 5;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long
#define fu(a,b) for(int i=a;i<b;i++)
#define fv(a,b) for(int j=a;j<b;j++)
const int nax=1e5+5;
using namespace std;
vector<int> edge[nax];
bool vis[nax];
int dist[nax];
int ideg[nax];
void dfs(int a)
{
	vis[a]=1;
	//cout<<a<<"\n";
	for(int i: edge[a])
	{
		if(!vis[i])
		{
			dist[i]=max(dist[i],dist[a]+1);
			ideg[i]--;
			if(ideg[i]==0)
			dfs(i);
		}
	}
}

int main()
{
	int n,m;
	cin>>n>>m;
	
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		edge[a].push_back(b);
		ideg[b]++;
	}
	fu(1,n+1)
	{
		if(!vis[i] && ideg[i]==0)
		{
			dfs(i);
		}
	}
	int ans=0;
	fu(0,n+1)
	{
		//cout<<dist[i]<<" ";
		ans=max(ans,dist[i]);
	}
	//cout<<"\n";
	cout<<ans;
}

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

constexpr int INF = 1e9;

struct Card{
  char c;
  int num;
};

int N;
Card a[100010];
Card b[100010];

void swap( Card& a, Card& b ){
  Card tmp = a;
  a = b;
  b = tmp;
}

int Partition( int p, int r ){
  int x = a[r].num;
  int i = p - 1;
  for( int j = p; j < r; j++ ){
    if( a[j].num <= x ){
      i++;
      ::swap( a[i], a[j] ); 
    }
  }
  ::swap( a[i + 1], a[r] );

  return i + 1;
}

void QuickSort( int p, int r ){
  if( p < r ){
    int q = Partition( p, r );
    QuickSort( p, q - 1 );
    QuickSort( q + 1, r );
  }
}

void merge( Card* a, int left, int mid, int right ){
  int n1 = mid - left;
  int n2 = right - mid;
  Card* L = new Card[n1 + 1];
  Card* R = new Card[n2 + 1];
  for( int i = 0; i < n1; i++ ) L[i] = a[left + i];
  for( int i = 0; i < n2; i++ ) R[i] = a[mid + i];
  L[n1].num = INF;
  R[n2].num = INF;

  int i = 0, j = 0;
  for( int k = left; k < right; k++ ){
    if( L[i].num <= R[j].num ){
      a[k] = L[i++];
    }else{
      a[k] = R[j++];
    }
  }
}

void mergeSort( Card* a, int left, int right ){
  if( right - left > 1 ){
    int mid = ( right + left ) / 2;
    mergeSort( a, left, mid );
    mergeSort( a, mid, right );
    merge( a, left, mid, right );
  }
}


int main(){
  cin >> N;
  for( int i = 0; i < N; i++ ){
    cin >> a[i].c >> a[i].num;
    b[i] = a[i];
  }

  QuickSort( 0, N - 1 );
  mergeSort( b, 0, N );

  bool f = true;
  for( int i = 0; i < N; i++ ){
    if( a[i].c != b[i].c ){
      f = false;
      break;
    }
  }

  if( f ) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  
  for( int i = 0; i < N; i++ ){
    cout << a[i].c << " " << a[i].num << endl;
    // cout << b[i].c << " " << b[i].num << endl;
  }

  

    
}



Measured memory_bytes: 21924
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

template <typename T>
constexpr bool chmin(
    T a, T b, function<bool(T, T)> f = [](T a, T b) { return a > b; }) {
  // when f is true, b is more 'smaller'
  if (f(a, b)) {
    swap(a, b);
    return true;
  }
  return false;
}
template <typename T> constexpr bool chmax(T a, T b) {
  return chmin(a, b, [](T a, T b) { return a < b; });
}
template <typename ite> void print_ite(ite start, ite end, char c = ' ') {
  for (auto i = start; i != end; i++)
    cout << i << c;
  cout << endl;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  scan_ite(all(p));
  scan_ite(all(q));
  scan_ite(all(r));
  sort(all(p), greater<int>());
  sort(all(q), greater<int>());
  for (int i = 0; i < x; i++) {
    r.push_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    r.push_back(q[i]);
  }
  sort(all(r), greater<int>());
  ll ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += r[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 2552
#[int(i) for i in input().split()]
n = int(input())
dic = {}
for i in range(n):
    a = int(input())
    dic[i+1] = [a]
    for j in range(a):
        dic[i+1].append([int(k) for k in input().split()])
#print(dic)
#dic[i] = {[0,1]} i = 1 ~ n+1 ,   0は対象, 1は真偽
ls = []
#全員正直者から
#for i in range(1,n):
#    for j in range(i+1,n+1):
#        ls.append([i,j])
#print(ls)


ret = 2 ** n - 1

for i in range(ret,-1,-1):
    ls.append(format(i, '0'+str(len(format(ret,'b')))+'b'))
#print(ls)
ls_3 = []
ok = 1
ans = 0
for i in range(len(ls)):
    for j in range(len(format(ret,'b'))):
         if ls[i][j] == '1':
            ls_3.append(j+1)
    #print(dic)
    for j in ls_3:
        for k in range(1,dic[j][0]+1):
            if dic[j][k][1] == 1 and dic[j][k][0] not in ls_3:
                ok = 0
            if dic[j][k][1] == 0 and dic[j][k][0] in ls_3:
                ok = 0
    if ok == 1:
        ans = ls[i].count('1')
        break
    ls_3 = []
    ok = 1

print(ans)


Measured memory_bytes: 48604
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e6+5;
bool vis[maxn];
ll prime[maxn],cnt=0;
unordered_map<int,int> mp;
void getprime(ll maxn){
	for(ll i=2;i<maxn;i++){
		if(!vis[i]) prime[cnt++]=i,mp[i]=1;
		for(ll j=0;j<cnt&&prime[j]*i<maxn;j++){
			vis[prime[j]*i]=1;
			if(i%prime[j]==0) break; 
		}
	}
}

int n,a[maxn],ct[maxn];
int main(){
	scanf("%d",&n);getprime(maxn);
	rep(i,1,n) scanf("%d",&a[i]);
	int cur=a[1];
	rep(i,1,n){
		cur=__gcd(cur,a[i]);
	}
	if(cur!=1){puts("not coprime");return 0;}	
	rep(i,1,n){
		int x=a[i];
		if(mp[x]==1){
			ct[x]++;
			if(ct[x]>1){
				puts("setwise coprime");
				return 0;
			}			
			continue;
		}
		for(int j=0;j<cnt&&prime[j]<=x;j++){
			int flag=0;
			while(x%prime[j]==0){
				flag=1;
				x/=prime[j];
			}
			if(flag) ct[prime[j]]++;
			if(ct[prime[j]]>1){
				puts("setwise coprime");
				return 0;
			}
		}
	}
	puts("pairwise coprime");
}


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

#define f(i, q) for(int i = 0; i < q; i++)  

typedef long long ll;

int main() {
    int A, B, X;

    cin >> A >> B;

    X = max( A + (A - 1), B + (B - 1));

    X = max(X, A + B);
    
    cout << X<< endl;

    return 0;
}

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

int main(){
  int H,W,N;
  std::cin >> H >> W >> N;

  int hw_arr[100][100];
  int tmp_a = 0, c = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      int j2 = std::min(j+(i%2)*W, 2*W-1-(j+(i%2)*W));
      if(tmp_a == 0){
        std::cin >> tmp_a;
        c++;
      }
      tmp_a--;
      hw_arr[i][j2] = c;
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      std::cout << hw_arr[i][j] << (j==W-1?"\n":" ");
    }
  }

  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

struct UnionFind {
    vector<int> size, parents;
    UnionFind(int n){
        size.resize(n,0);
        parents.resize(n,0);
        for(int i = 0; i < n; i++){
            makeTree(i);
        }
    }
    void makeTree(int x){
        parents[x] = x;
        size[x] = 1;
    }
    bool isSame(int x, int y){return findRoot(x) == findRoot(y);}
    void unite(int x, int y){
        x = findRoot(x);
        y = findRoot(y);
        if(x == y) return;//二重辺を防ぐ
        if(size[x] > size[y]){
            parents[y] = x;
            size[x] += size[y];
        }else{
            parents[x] = y;
            size[y] += size[x];
        }
    }
    int findRoot(int x){
        if(x != parents[x]){
            parents[x] = findRoot(parents[x]);
        }
        return parents[x];
    }
    int treeSize(int x){return size[findRoot(x)];}
};

int main(){
    int n, m; cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i,m) cin >> a[i] >> b[i];
    UnionFind uf(n);
    rep(i,m) uf.unite(a[i], b[i]);
    int ans = 0;
    rep(i,n) ans = max(ans, uf.treeSize(i));
    cout << ans << endl;
}

Measured memory_bytes: 6276
m=10**9+7;f=max;r=range
for _ in r(int(input())):
	x,y=sorted(map(int,input().split()));s=-1;i=j=1
	while j<=x and i+j<=y:i,j,s=j,i+j,s+1
	if x<2 or y<3:print(1,x*y%m);continue
	a=f(0,(y-j)//i+1)+f(0,(x-j)//i+1);i=j=1
	for c in r(s):
		k,l=j,i+j*2
		for _ in r(s-c):k,l=l,k+l
		a+=(y>=k)*f(0,(x-l)//k+1)+(x>=k)*f(0,(y-l)//k+1)
		i,j=j,i+j
	print(s+1,a%m)

Measured memory_bytes: 82396
#include<bits/stdc++.h>
using namespace std;
int a[500010];
long long bg[500010],go[500010],ans[500010];
void add(int l,int r,int x)
{//cout<<l<<' '<<r<<' '<<x<<endl;
	bg[l]+=x;go[l]++;
	bg[r+1]-=x+(r+1-l);go[r+1]--;
}
int main()
{
	int n,m;long long all=0;scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<n;i++)
	{
		if (a[i]==a[i+1]) continue;
		if (a[i]<a[i+1])
		{
			all+=a[i+1]-a[i];
			add(a[i]+1,a[i+1],0);
		}
		else
		{
			all+=a[i+1]+m-a[i];
			if (a[i]!=m) add(a[i]+1,m,0);
			add(1,a[i+1],m-a[i]);
		}
	}
	long long ad=0,pt=0;
	for (int i=1;i<=m;i++)
	{
		ad+=pt+bg[i];
		ans[i]=ad;
		pt+=go[i];
		
	}
	/*for (int i=1;i<=m;i++) cout<<bg[i]<<' ';cout<<endl;
	for (int i=1;i<=m;i++) cout<<go[i]<<' ';cout<<endl;
	for (int i=1;i<=m;i++) cout<<ans[i]<<' ';cout<<endl;*/
	long long mx=-1;
	for (int i=1;i<=m;i++) mx=max(mx,ans[i]);
	cout<<all-mx<<endl;
}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

Measured memory_bytes: 11264
N,K=map(int,input().split())
MOD=10**9+7
X=[1]*(N+1)
for i in range(1,N+1):
  X[i]=(X[i-1]*i)
def Cb(i):
  return X[K-1]//(X[i]*X[K-1-i])
def Hr(n,groupnum):
  return X[n+groupnum]//(X[n]*X[groupnum])
for i in range(1,K+1):
  Nred=N-K-(i-1)
  if Nred<0:
    print(0)
    continue
  ans=Cb(i-1)*Hr(Nred,i)
  print(ans%MOD)
  

Measured memory_bytes: 5748
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        System.out.println((a.substring(0,1)+b.substring(0,1)+c.substring(0,1)).toUpperCase());
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  int h,n;
  int a;
  int po = 0;

  cin >> h >> n;

  for(int i=0; i<n; i++) {
    cin >> a;
    po += a;
  }

  if(po >= h) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._700problems
{
    class CodeFestival2017C_D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            string s = Read();

            var dict = new Dictionary<int, int>();
            dict.Add(0, 0);
            int[] dp = new int[s.Length + 1];
            for (int i = 0; i <= s.Length; i++)
            {
                dp[i] = int.MaxValue / 2;
            }
            dp[0] = 0;
            int now = 0;
            for (int i = 0; i < s.Length; i++)
            {
                int tmp = 1 << (s[i] - 'a');
                int next = now ^ tmp;
                if (dict.ContainsKey(next))
                {
                    if (dict[next] == 0)
                    {
                        dp[i + 1] = 1;
                    }
                    else
                    {
                        dp[i + 1] = dp[dict[next]];
                    }
                }
                for (int j = 0; j < 26; j++)
                {
                    int target = (1 << j) ^ next;
                    if (dict.ContainsKey(target))
                    {
                        dp[i + 1] = Min(dp[i + 1], dp[dict[target]] + 1);
                    }
                }

                now = next;
                if (dict.ContainsKey(now))
                {
                    if (dp[dict[now]] > dp[i + 1])
                    {
                        dict[now] = i + 1;
                    }
                }
                else
                {
                    dict.Add(now, i + 1);
                }
            }
            WriteLine(dp[s.Length]);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 25696
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <list>
#include <string>
#include <map>
#include <numeric>
#include<unordered_map>
#include<queue>
#include <set>
#include<unordered_set>
#include <bitset>
#include <cmath>
#include <functional>
using namespace std;
int main()
{
	ifstream fin("input.txt");
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i += 2)
	{
		cout << s[i];
	}
	cout << endl;
} 


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<char> s;
    for (int i = 0; i < n * 2; i++) {
        char x; cin >> x;
        s.push_back(x);
    }
    vector<int> op;
    op.push_back(0);
    int op_count = 0;
    long long res = 1;
    for (int i = 1; i < n * 2; i++) {
        int ops = 0;
        if (s[i-1] != s[i]) {
            ops = op[i-1];
            op.push_back(ops);
        } else {
            ops = (op[i-1] + 1) % 2;
            op.push_back(ops);
        }
        op_count += ops;
        if (ops == 1) {
            res *= i - 2 * (op_count - 1);
            res %= mod;
        }
    }
    if (s[0] != 'B' || s[2*n-1] != 'B') {
        cout << 0 << endl;
    } else if (op_count != n) {
        cout << 0 << endl;
    } else {
        for (int i = 1; i <= n; i++) {
            res *= i;
            res %= mod;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1656
#include <iostream>
#include <string>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <vector> 
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
    int a,b;
    int c;
    cin >> a;
    vector<int> data;
    
    for(int i = 0 ;i<a;i++){
        cin >> b;
        data.push_back(b);
    }
    sort( data.begin(), data.end() );
    c = data.back() - data.front();
    cout << c << endl;
}

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

int main() {
	int N; cin >> N;
	bool ok = false;
	for (int i = 0; i <= N / 4; i++) {
		for (int j = 0; j <= N / 7; j++) {
			if (4 * i + 7 * j == N) ok = true;
		}
	}
	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

int n;
int t[10000];
int dp[2][5001][2];
//[i][j][k] = i???????????§??§j??¬?????£???????????´????????¶???k(i - 1??????????£?????????£??????)?????¨??????????????????????°????

int main() {
	cin >> n;
	REP(i, n - 1) scanf("%d", &t[i]);
	t[n - 1] = 0;
	
	fill(dp[0][0], dp[2][0], INF);
	
	dp[0][0][0] = 0;
	REP(i, n) {
		int now = i % 2, next = (i + 1) % 2;
		REP(j, n / 2 + 1) {
			// ??????
			if (j < n / 2)
				dp[next][j + 1][1] = min(dp[now][j][1], dp[now][j][0] + t[i]);
			
			// ????????????
			dp[next][j][0] = min(dp[now][j][0], dp[now][j][1] + t[i]);
		}
	}
	
	cout << dp[n % 2][n / 2][0] << endl;
	
	return 0;
}

Measured memory_bytes: 3360
from collections import defaultdict


def main():
    N, M = [int(q) for q in input().split()]

    AB = [
        [int(q) for q in input().split()]
        for _ in range(N)
    ]
    AB = sorted(AB, key=lambda it: it[0])

    res = 0
    for ai, bi in AB:
        if bi >= M:
            res += ai * M
            print(res)
            return
        res += ai * bi
        M -= bi


if __name__ == '__main__':
    main()


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

int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(b<=c || d<=a){
		cout << 0;
	}else if(a<=c && b>=d){
		cout << d-c;
	}else if(c<=a && d>=b){
		cout << b-a;
	}else if(a<c){
		cout << b-c;
	}else{
		cout << d-a;
	}


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if(a == 0) cout << 1 << endl;
    if(b == 0) cout << 2 << endl;
    if(c == 0) cout << 3 << endl;
    if(d == 0) cout << 4 << endl;
    if(e == 0) cout << 5 << endl;
}


Measured memory_bytes: 3568
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[2];
            string[] s = Console.ReadLine().Split(' ');
            a[0] = int.Parse(s[0]);
            a[1] = int.Parse(s[1]);

            if (a[0] < a[1])Console.WriteLine("a" + " < " + "b");
            if (a[0] == a[1]) Console.WriteLine("a" + " == " + "b");
            if (a[0] > a[1]) Console.WriteLine("a" + " > " + "b");
        }
    }
}

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

namespace ABC102
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(A.Max() - A.Min());
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int weight[n];
  int sum = 0, mn = INT_MAX;
  for(int i = 0; i < n; i++) {cin >> weight[i]; sum += weight[i];}
  int cur = 0;
  for(int i = 0; i < n; i++) {cur += weight[i]; mn = min(mn, abs(cur - (sum - cur)));}
  cout << mn;
}

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

int main() {
	string w;
	cin >> w;
	int c[123] = { 0 };

	for (int i = 0; i < w.size(); i++) {
		for (char ch = 'a'; ch <= 'z'; ch++) {
			if (w[i] == ch) {
				c[ch]++;
			}
		}
	}
	bool flag = true;
	for (char ch = 'a'; ch <= 'z'; ch++) {
		if (c[ch] % 2 != 0) {
			flag = false;
			break;
		}
	}
	cout << ((flag) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256