akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[argc])
{
  string S;

  cin >> S;

  char prev_c = '0';
  vector<int> flip_index;
  int ans = S.size();
  
  FOR(i, S.size()) {
    if (S[i] != prev_c &&
        MAX(i, S.size() - i) < ans)
      ans = MAX(i, S.size() - i);
    prev_c = S[i];
  }

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


Measured memory_bytes: 512
from collections import deque
H,W=map(int,input().split())
M=[list(input()) for _ in range(H)]

def bfs(i,j,d):
    d_max=0
    used=[[False for j in range(W)] for i in range(H)]
    Q=deque()
    Q.append((i,j,d))
    used[i][j]=True
    while Q:
        i,j,d=Q.popleft()
        for ni,nj in ((i+1,j),(i-1,j),(i,j+1),(i,j-1)):
            if ni<0 or nj<0 or ni>=H or nj>=W:
                continue
            if M[ni][nj]=='.' and not used[ni][nj]:
                d_max=max(d_max,d+1)
                used[ni][nj]=True
                Q.append((ni,nj,d+1))
    return d_max

ans=0
for i in range(H):
    for j in range(W):
        if M[i][j]=='.':
            ans=max(ans,bfs(i,j,0))

print(ans)


Measured memory_bytes: 3316
n, a, b, c, d = map(int, input().split())
s = input()
for i in range(a, max(c, d)):
    if s[i-1:i+1] == "##":
        print("No")
        exit()
if c < d:
    print("Yes")
    exit()
for i in range(b-1, d):
    if s[i-1:i+2] == "...":
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		long k = sc.nextLong();
		
		if (k % 2 == 0) {
			System.out.println(a-b);
		} else {
			System.out.println(-1 * (a-b));
		}
	}	
}

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

int main() {
    int A,B;
    std::cin >> A >> B;

    if(A < 10 && A > 0){
        if(B < 10 && B > 0){
            std::cout << A*B << std::endl;
            return 0;
        }
    }

    std::cout << "-1" << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

LL N, k, fl[55], f[55];

LL g(LL layer, int rank){
//  if(rank == 0){
//    return (layer > 0);
//  }

  if(layer == 0) return 0LL;

  assert(rank >= 0);
  if(layer == fl[rank]) return f[rank];

//  assert(layer >= 0);

  if(layer <= 1 + fl[rank - 1]) return g(layer - 1, rank - 1);

  layer -= (2 + fl[rank - 1]);

  return 1LL + f[rank - 1] + g(layer, rank - 1);
}

int main(){
  FAST_IO

  cin >> N >> k;

  fl[0] = f[0] = 1;

  for(int rep = 1; rep <= N; ++rep){
    fl[rep] = 3 + 2LL * fl[rep - 1];
    f[rep] = 1 + 2LL * f[rep - 1];
  }

//  for(int rep = 0; rep <= N; ++rep){
//    cout << f[rep] << " " << fl[rep] << '\n';
//  }
//
//  cout << "\n-------------------\n";
//  for(int layer = 0; layer < 30; ++layer){
//    cout << g(layer, 3) << '\n'; 
//  }

  cout << g(k, N) << '\n';
  return 0;
}


Measured memory_bytes: 256
'use strict';

function Main(INPUT) {
    const input = INPUT.split("\n")[0].split(" ");
    const sx = input[0];
    const sy = input[1];
    const tx = input[2];
    const ty = input[3];
    let ans = "";

    for (let i = 0; i < ty - sy; i++) {
        ans += "U";
    }
    for (let i = 0; i < tx - sx; i++) {
        ans += "R";
    }
    for (let i = 0; i < ty - sy; i++) {
        ans += "D";
    }
    for (let i = 0; i <= tx - sx; i++) {
        ans += "L";
    }

    for (let i = 0; i <= ty - sy; i++) {
        ans += "U";
    }
    for (let i = 0; i <= tx - sx; i++) {
        ans += "R";
    }
    ans += "DR"
    for (let i = 0; i <= ty - sy; i++) {
        ans += "D";
    }
    for (let i = 0; i <= tx - sx; i++) {
        ans += "L";
    }
    ans += "U";

    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int N;
int h;

int main() {
	std::cin >> N;
	int copy = N;
	for (int i = 8; i >= 0; i--) {
		int mod = 1;
		for (int j = 0; j < i; j++) {
			mod *= 10;
		}
		h += (copy / mod);
		copy %= mod;
	}
	std::cout << (N%h == 0 ? "Yes" : "No") << std::endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input()

    table = [0] * (N + 1)

    if len(set(S)) == 1:
        print(0)
        return
    # 赤の累積和

    for i in range(1, N + 1):
        if S[i - 1] == "R":
            table[i] = table[i - 1] + 1
        else:
            table[i] = table[i - 1]

    ans = float("inf")

    for i in range(N):
        left_red = table[i]
        left_white = i - table[i]
        right_red = table[N] - table[i]
        right_white = N - i - right_red
        # print(left_red, left_white, right_red, right_white)
        ans = min(ans, max(left_white, right_red))

    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 77376
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

bool isprime[1001];
vector<ll> primes;
ll N;
int main()
{
	fill(isprime,isprime+1000,1);
	isprime[0]=isprime[1]=0;
	for(ll i=2;i<1001;i++){
		if(!isprime[i]) continue;
		for(ll j=2*i;j<=1000;j+=i){
			isprime[j]=0;
		}
		primes.pb(i);
	}
	cin>>N;
	ll ans=1;
	rep(i,primes.size()){
		if(primes[i]>N) break;
		ll cnt=0;
		ll p=primes[i];
		while(p<=N){
			cnt+=N/p;
			p*=primes[i];
		}
		ans=(ans*(cnt+1))%1000000007;
	}
	cout<<ans<<endl;
}

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

const int N = 4010;
const int moder = 998244353;

int dp[N][N];
char s[N];
int a[N], idr[N], idb[N];

void add(int &a, int b){a += b; a -= a >= moder ? moder : 0;}

int main(){
    scanf("%s", s);
    int n = strlen(s);
    for (int i = 1; i <= n; ++ i){
        a[i] = s[i - 1] - '0';
    }
    int cntr = 0, cntb = 0;
    memset(idr, -1, sizeof(idr));
    memset(idb, -1, sizeof(idb));
    for (int i = 1; i <= n; ++ i){
        for (int j = 0; j < 2 - a[i]; ++ j){
            idr[++ cntr] = i;
        }
        for (int j = 0; j < a[i]; ++ j){
            idb[++ cntb] = i;
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= 2 * n; ++ i){
        for (int j = 0; j <= i - 1; ++ j){
            if (!dp[i - 1][j]) continue;
            int x = j + 1;
            if (idr[x] != -1 && idr[x] <= i){
                add(dp[i][j + 1], dp[i - 1][j]);
            }
            x = (i - 1 - j) + 1;
            if (idb[x] != -1 && idb[x] <= i){
                add(dp[i][j], dp[i - 1][j]);
            }
        }
    }
    printf("%d\n", dp[2 * n][cntr]);
    return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	rep(i, n){
		cin>>a[i];
		b[i] = a[i];
	}
	SORT(b);
	REV(b);
	bool usi = true;
	if(b[0] != b[1]){
		usi = false;
	}
	rep(i,n){
		if(usi){
			cout << b[0] << endl;
		} else {
			if(a[i] == b[0]){
				cout << b[1] << endl;
			} else {
				cout << b[0] << endl;
			}
		}
	}

}


Measured memory_bytes: 4744
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }
};

//--global--//



//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    ll n;
    cin >> n;
    ll dv=2;
    vector<int> ans;
    rep(i,60){
        //cout << dv << endl;
        if(n%dv!=0){
        ans.push_back(1);
        n += -pow(-2,i);
        }
        else ans.push_back(0);
        if(n==0) break;
        dv*=2;
        //    cout << n << endl;
    }

    reverse(ALL(ans));

    for(ll a : ans){
        cout << a;
    }
    cout << endl;
    


    //cout << bitset<100>(n) << endl;
    
    return 0;
}


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

int main(){

    while(true){
        std::string s;
        std::cin >> s;

        if(s == "0") break;

        size_t sum = 0;
        for(const auto& e : s){
            sum += e - '0';
        }

        std::cout << sum << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3216
#include <cstdio>
#include <stack>
using namespace std;

int main()
{
        int car;
        stack<int> st;
        while(scanf("%d", &car) != EOF) {
                if(car == 0) {
                        if(!st.empty()) {
                                printf("%d\n",st.top());
                                st.pop();
                        }
                } else {
                        st.push(car);
                }
        }
        return 0;
}

Measured memory_bytes: 1036
import sys
sys.setrecursionlimit(10**6)

readline = sys.stdin.readline

n,q = map(int,readline().split())
a=[[] for i in range(n)]
l=[0]*n
ans=[0]*n

def dfs(parent,current,value):
    value += l[current]
    ans[current] = value
    for i in a[current]:
        if i != parent:
            dfs(current,i,value)


for i in range(n-1):
    t1,t2 = map(int,readline().split())
    a[t1-1].append(t2-1)
    a[t2-1].append(t1-1)
    
for i in range(q):
    t1,t2 = map(int,readline().split())
    l[t1-1]+=t2
dfs(-1,0,0)

print(" ".join(map(str,ans)))

Measured memory_bytes: 237724
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    set<int> N;
    int a;
    rep(i, 3) {
        cin >> a;
        N.insert(a);
    }
    cout << (N.size() == 2 ? "Yes" : "No") << endl;
}


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

int main()
 {
     int i;
     int key;
     int final = 0;
     int n,m;
     scanf("%d", &n);
     int A[10000];
     for (i = 0; i != n; i++)
    {
        scanf("%d", &A[i]);
 }


 scanf("%d", &m);
 while (m--) 
 {
      scanf("%d", &key);
      for (i = 0; i != n; i++) 
   {
       if (A[i] == key) 
        {
            final++;
            break;
   }
  }
 }

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


}


Measured memory_bytes: 2100
// Created by Tanuj Jain
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll recurisve(vector<vector<ll>>&v , ll capacity ,ll no_of_items)
{
	//base case
	//if no capacity or no more items to check
	
	if(no_of_items==0 || capacity==0LL)
		return 0LL;
	//If the weight of my current item is more than the capacity then i cannot select this
	if(v[no_of_items-1][0]>capacity)
		return (recurisve(v,capacity,no_of_items-1LL));
	else
	{
		//i have two options 
		//1 choose this item and recurse on remaning items
		ll left_child=v[no_of_items-1][1]+recurisve(v,capacity-v[no_of_items-1][0],no_of_items-1LL);
		//2 do not choose this item and find the remaning items
		ll right_child=recurisve(v,capacity,no_of_items-1LL);
		ll ans=max(left_child,right_child);
		return ans;
	}
	
}

//bottom up
ll bottom_up(vector<vector<ll>>&v, int capacity)
{
	ll dp[v.size()+1][capacity+1]={};
	for(int i=1;i<=v.size();i++)
	{
		for(int j=1;j<=capacity;j++)
		{
			if(v[i-1][0]<=j)
			{
				//dp is max of taking that item or excluding that item
				dp[i][j]=max(v[i-1][1]+dp[i-1][j-v[i-1][0]], dp[i-1][j]);
			}
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	return dp[v.size()][capacity];

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

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	ll n,w;
	cin>>n>>w;
	vector<vector<ll>>v(n,vector<ll>(2));
	for(int i=0;i<n;i++)
		for(int j=0;j<2;j++)
			cin>>v[i][j];
	//cout<<recurisve(v,w,n);
		cout<<bottom_up(v,w);


	
}

Measured memory_bytes: 79232
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
char s[6];

int main() {
	scanf("%s", s);
	int ans = 700;
	for(int i = 0; i < 3; i++) {
		if(s[i] == 'o') ans += 100;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 1010100;
char tab[nax];
int f[nax][2];
int n;

int main() {
	ios_base::sync_with_stdio(false);
	scanf("%s", tab + 1);
	n = strlen(tab + 1);
	f[0][1] = 1;
	f[0][0] = 0;
	FOR(i, 1, n) {
		int currCyf = tab[i] - '0';
		f[i][0] = min(f[i - 1][0] + currCyf, f[i-1][1] + (10 - currCyf));
		f[i][1] = min(f[i-1][0] + currCyf + 1, f[i-1][1] + (10 - (currCyf + 1)));
	}
	cout << f[n][0] << endl;
}

Measured memory_bytes: 9088
h, w, n = gets.split.map(&:to_i)
a = $<.read.split.map(&:to_i)

ans = Hash.new(0)
mmap = Hash.new { |h,k| h[k] = Hash.new(0) }

a.each_slice(2) do |x, y|
	(x-1).upto(x+1) do |xx|
		(y-1).upto(y+1) do |yy|
			mmap[xx][yy] += 1
		end
	end
end

sum = 0
mmap.map { |x,tmp|
    tmp.map { |y, v|
    	next unless 1 < x && x < h && 1 < y && y < w
    	sum += 1
    	ans[v] += 1
    }
} if 0 < mmap.size 

puts (h-2) * (w-2) - sum

1.upto(9) do |i|
  puts ans[i]
end

Measured memory_bytes: 139488
#include<bits/stdc++.h>
#define eoi ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    eoi;
int a,b;
cin>>a>>b;
if(b*2<a){cout<<a-b*2;}
else{cout<<0;}
}


Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
       s: String,
    }
    let i = s.find("A").unwrap();
    let j = s.rfind("Z").unwrap();
    println!("{}", j - i + 1);
}


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

int main(){
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s.at(i);
  rep(i,n) sort(s.at(i).begin(),s.at(i).end());
  sort(s.begin(),s.end());
  ll cnt = 1;
  ll ans = 0;
  for(int i=1;i<n;i++){
    if( s.at(i) == s.at(i-1) ){
      cnt++;
    }else{
      ans += cnt*(cnt-1)/2;
      cnt = 1;
    }
  }
  ans += cnt*(cnt-1)/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7296
import numpy as np

N = int(input())

amari = N%10
hon_set = [2,4,5,7,9]
pon_set = [0,1,6,8]
bon_set = [3]

for x in hon_set:
    if amari == x:
        print('hon')

for x in pon_set:
    if amari == x:
        print('pon')

for x in bon_set:
    if amari == x:
        print('bon')

Measured memory_bytes: 26960
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> v(M);
    rep(i, M) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());

    int cnt = 0;
    int st = v[0].first, ed = v[0].second;
    for(int i = 1; i < M; i++){
        if(v[i].first < ed){
            st = max(st, v[i].first);
            ed = min(ed, v[i].second);
        }else{
            cnt++;
            st = v[i].first;
            ed = v[i].second;
        }
    }
    cnt++;
    cout << cnt << endl;
    return 0;
}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  n, k;
  cin >> n >> k;
  
  for(int i = 0; i < 35; i++){
    if(n < pow(k, i)){
      cout << i <<endl;
      break;
    } else if(n == pow(k, i)){
      cout << i + 1 <<endl;
      break;
    }
  }
}


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

string s,t;
int i,j;

int cmp(char x,char y){
	return x>y;
}

int main(){
	cin>>s>>t;
	
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);

	if(t>s) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main() {

	int n;
	cin >> n;

	int sum = 0;
	vector<int>d(n);

	for (int i = 0; i < n; i++) cin >> d[i];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j != i) {
				sum += d[i] * d[j];
			}
		}
	}

	cout << sum/2 << endl;

	return 0;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

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

    int t = 1900 * M + 100 * (N - M);

    int k = 1 << M;

    cout << t * k << '\n';

    return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
sum = 0
ans = 0
for i in range(len(a) - 1):
    sum += a[i]
    if sum > x:
        break
    else:
        ans += 1
sum += a[N-1]
if sum == x:
    ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n;
    int k;
    int r;
    int s;
    int p;
    char t[199999];
    long long ans=0;
    
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    
    for(int j=0; j<=k-1; j++){
    
    for(int i=j; i<=n-1; i+=k){
        
        if(i>=k){
            
            if(t[i]==t[i-k]){
                
                t[i] = 'x';
                
                continue;
                
            }
            
            if(t[i]=='r'){
                
                ans += p;
                
            } else if(t[i]=='s'){
                
                ans += r;
                
            } else {
                
                ans += s;
                
            }
            
        } else {
            
            if(t[i]=='r'){
                
                ans += p;
                
            } else if(t[i]=='s'){
                
                ans += r;
                
            } else {
                
                ans += s;
                
            }
            
        }
        
    }
    
    }
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979323846
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int a,b,c,d,diss,mass;
int tot,tots;
int fz,fm;
int w[4000],s[4000];

int main(void)
{
    fz=0,fm=1;
    a=read(),b=read(),c=read();
    d=read(),diss=read(),mass=read();
    for (int i=0;i<=3000;i++){
        for (int j=0;j<=3000;j++){
            if (i*a+j*b<=30)  w[100*(i*a+j*b)]=1;
            else break;
        }
    }
    for (int i=0;i<=3000;i++){
        for (int j=0;j<=3000;j++){
            if (i*c+j*d<=3000)  s[(i*c+j*d)]=1;
            else    break;
        }
    }
    for (int i=1;i<=3000;i++){
        for (int j=0;j<=3000;j++){
            if (w[i]&&s[j]&&j*100<=diss*i&&i+j<=mass){
                if (j*fm>=(i+j)*fz){
                    fz=j;fm=i+j;
                    tot=j+i;
                    tots=j;
                }
            }
        }
    }
    cout<<tot<<' '<<tots<<endl;
    return 0;
}

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


int main(){
  int N, T;
  cin >> N >> T;
  int ans = 1001;
  for(int ii=0; ii<N; ii++){
    int c, t;
    cin >> c >> t;
    if(t > T) continue;
    ans = min(ans, c);
  }
  if(ans == 1001){
    cout << "TLE" << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, res=0;
  vector<int> x(4);
  vector<string> operand(3);
  cin >> n;
  for(int i=0;i<4;i++){
    x[3-i] = n % 10;
    n /= 10;
  }
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
        res = x[0];
        if(i == 0){
          res -= x[1];
          operand[0] = "-";
        }else{
          res += x[1];
          operand[0] = "+";
        }
        if(j == 0){
          res -= x[2];
          operand[1] = "-";
        }else{
          res += x[2];
          operand[1] = "+";
        }
        if(k == 0){
          res -= x[3];
          operand[2] = "-";
        }else{
          res += x[3];
          operand[2] = "+";
        }
        if(res == 7){
          cout << x[0] << operand[0] << x[1] << operand[1] << x[2] << operand[2] << x[3] << "=7" << endl;
          return 0;
        }
      }
    }
  }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    string s;cin>>s;
    int n=s.size();
    int b=0,e=0;
    rep(i,n){
        if(s[i]=='A'){
            b=i;
            break;
        }
    }
    rep(i,n){
        if(s[i]=='Z'){
            e=i;
        }
    }
    cout<<e-b+1<<endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<set>

using namespace std;

int d, c[100], s[400][100];
int sat;
int m, t[400];
set<int> app[100];

int last(int d, int i) {
  return *(--app[i].upper_bound(d));
}

int next(int d, int i) {
  return *app[i].upper_bound(d);
}

int main() {
  scanf("%d", &d);
  for (int i = 1; i <= 26; i++) {
    scanf("%d", &c[i]);
    app[i].insert(0);
    app[i].insert(d+1);
  }
  for (int i = 1; i <= d; i++) {
    for (int j = 1; j <= 26; j++) {
      scanf("%d", &s[i][j]);
    }
  }
  for (int i = 1; i <= d; i++) {
    scanf("%d", &t[i]);
    sat += s[i][t[i]];
    app[t[i]].insert(i);
    for (int j = 1; j <= 26; j++) {
      sat -= c[j] * (i - last(i, j));
    }
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int d, q;
    scanf("%d %d", &d, &q);
    app[t[d]].erase(d);
    sat -= s[d][t[d]];
    sat -= c[t[d]] * (next(d, t[d]) - d) * (d - last(d, t[d]));

    sat += s[d][q];
    sat += c[q] * (next(d, q) - d) * (d - last(d, q));
    app[q].insert(d);
    
    t[d] = q;
    printf("%d\n", sat);
  }
}


Measured memory_bytes: 3480
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#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()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	vector<vector<int>> ans(h, vector<int>(w, 0));
	for (int i = 0; i < b; ++i) {
		for (int j = a; j < w; ++j) {
			ans[i][j] = 1;
		}
	}
	for (int i = b; i < h; ++i) {
		for (int j = 0; j < a; ++j) {
			ans[i][j] = 1;
		}
	}
	rep(i, h) {
		rep(j, w) {
			cout << ans[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 7580
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;

int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    freopen("task2-test-input.txt", "r", stdin);
//    freopen("task2-test-output.txt", "w", stdout);
    string s;
    cin>>s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout<<"Yes\n";
        return 0;
    }
    cout<<"No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main(void){
    int N;
    cin>>N;
    
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    
    sort(A.begin(),A.end(),greater<ll>());
    
    ll sum=1;
    bool check=false;
    for(int i=1;i<A.size();i++){
        if(A[i-1]==A[i]){
            if(check){sum*=A[i];break;}
            sum*=A[i];
            check=true;
            i++;
        }
    }
    
    if(check)cout<<sum<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
N, K = [int(_) for _ in input().split()]
S = str(input())

Nums = []
now, cnt = 1, 0
for i in range(N):
    if S[i] == str(now): cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0: Nums.append(cnt)
if len(Nums) % 2 == 0: Nums.append(0)


# add = 2 * K + 1
# ans = 0
# for i in range(0, len(Nums), 2):
#     tmp = 0
#     left = i
#     right = min(i+add, len(Nums))
#     j = left
#     while j < right:
#         tmp += Nums[j]
#         j += 1
#     ans = max(tmp, ans)
# print(ans)

#------------------------
# add = 2 * K + 1
# ans = 0
# left = 0
# right = 0
# tmp = 0
# for i in range(0, len(Nums), 2):
#     nextLeft = i 
#     nextRight = min(i + add, len(Nums))
#     while nextLeft > left:
#         tmp -= Nums[left]
#         left += 1
#     while nextRight > right:
#         tmp += Nums[right]
#         right += 1
#     #print('left, right:   ', left, right)
#     ans = max(tmp, ans)
        
# print(ans)
#------------------------
#print(Nums)
add = 2 * K + 1
sums = [0 for _ in range(len(Nums) + 1)]
for i in range(len(Nums)):
    sums[i+1] = sums[i] + Nums[i]
#print(sums)

ans = 0
for i in range(0, len(Nums), 2):
    left = i
    right = min(i+add, len(Nums))
    tmp = sums[right] - sums[left]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 7884
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;



int main(){
    int n;cin >> n;
    char c[n-1];
    int a[n];
    for (int i = 0; i < 2*n-1; i++) {
        if(i%2==0) cin >> a[i/2];
        else cin >> c[i/2];
    }
    LL dp[n+1][3];
    for (int i = 0; i < n+1; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j]=-LINF;
        }
    }
    dp[0][0]=a[0];
    for (int i = 0; i < n-1; i++) {
        if(c[i]=='+'){
            dp[i+1][0]=max(dp[i][0]+a[i+1],dp[i][1]+a[i+1]);
            dp[i+1][1]=dp[i][1]-a[i+1];
            dp[i+1][2]=dp[i][2]+a[i+1];
        }
        else{
            dp[i+1][1]=dp[i][0]-a[i+1];
            dp[i+1][2]=max(dp[i][2]+a[i+1],dp[i][1]+a[i+1]);
        }
    }
    cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;
    return 0;
}




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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

ll solve(ll N, ll P, string S)
{
    if (P == 2 || P == 5) {
        long long res = 0;
        for (int i = 0; i < N; ++i) if ((S[N-i-1]-'0') % P == 0) res += N-i;
        return res;
    }
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;
    return res;
}


int main()
{
    ll N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    ll cnt = 0;
    if(P == 2 || P == 5) {
        REP(i,0,N) {
            if((S[N-i-1] - '0') % P == 0) cnt += N - i;
        }
    }
    else {
        vec C(N+1, 0);
        ll d = 1;
        REP(i,0,N) {
            C[i+1] = (C[i] + (S[N-i-1] - '0') * d) % P;
            d = (d * 10) % P;
        }
        map<ll,ll> M;
        REP(i,0,N+1) ++M[C[i]];
        FORR(m,M) cnt += (m.second - 1) * m.second / 2;
    }

    PR(cnt);

    return 0;
}

/*


*/

Measured memory_bytes: 5484
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto &e: a) cin >> e;
  int last = 1e9 + 10;
  int ans = 0;
  int now = 0;
  for(int i = 0; i < n; i++) {
    if(last >= a[i]) {
      now++;
      ans = max(ans, now);
      last = a[i];
    } else last = 1e9 + 10, i--, now = 0;
  }
  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N;
    cin >> N;
    vector<int> A1(N), A2(N);
    for (int i = 0; i < N; i++) {
        cin >> A1.at(i);
    }
    for (int i = 0; i < N; i++) {
        cin >> A2.at(i);
    }
    int count = 0;
    for (int i = 0; i < N; i++) {
        count += A1.at(i);
        A1.at(i) = count;
    }
    count = 0;
    for (int i = 0; i < N; i++) {
        count += A2.at(N - i - 1);
        A2.at(N - i - 1) = count;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, A1.at(i) + A2.at(i));
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import defaultdict
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    a = defaultdict(int)
    for c in S:
        a[c]+=1
    for c in a:
        if a[c] != 2:
            print(NO)
            exit()
    print(YES)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main() {
	ll n; cin >> n;
	string s; cin >> s;
	
	ll l = 0, max_l = 0, loc = 0;
	rep(i, 0, n) {
		max_l = max(max_l, l);
		if (s[i] == 'E') l++;
		else l--;
		if (max_l < l) loc = i;
	}
	ll ans = 0;
	rep(i, 0, loc) {
		if (s[i] == 'W') ans++;
	}
	rem(i, n - 1, loc + 1) {
		if (s[i] == 'E') ans++;
	}
  	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 900
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }


void run() {
	int N; scanf("%d", &N);
	FORE(a, 1, 3500) FORE(b, 1, 3500) {
		// 4/N=1/a+1/b+1/c
		// c=N*a*b/(4*a*b-N*b-N*a)
		ll num = (ll)N*a*b, den = (ll)4 * a*b - (ll)N*b - (ll)N*a;
		if (den>0&&num%den == 0) { printf("%d %d %lld\n", a, b, num / den); return; }
	}
	assert(false);
}

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


Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[list(map(int,input().split())) for i in range(m)]
b=[[i] for i in h]
for i in a:
    b[i[0]-1].append(h[i[1]-1])
    b[i[1]-1].append(h[i[0]-1])
ans=0
for j in b:
    if max(j)==j[0] and j.count(max(j))==1:
        ans+=1
print(ans)

Measured memory_bytes: 111068
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64 = read();
    let mut vec: Vec<String> = (0..n).map(|_| read()).collect();
    let mut map: HashMap<char, i64> = HashMap::new();

    let march_vec = vec!['M', 'A', 'R', 'C', 'H'];

    map.insert('M', 0);
    map.insert('A', 0);
    map.insert('R', 0);
    map.insert('C', 0);
    map.insert('H', 0);

    for s in vec.iter() {
        let char_vec: Vec<char> = s.chars().collect();
        let first_letter = char_vec[0];

        *map.entry(first_letter).or_insert(0) += 1;
    }

    let mut count = 0;

    for i in 0..i64::pow(2, march_vec.len() as u32) {
        let mut each_vec: Vec<char> = Vec::new();
        for j in 0..march_vec.len() {
            if (1 & i >> j) == 1 {
                each_vec.push(march_vec[j].clone());
            }
        }

        let mut each_count = 1;

        if each_vec.len() == 3 {
            for s in each_vec.iter() {
                let val = map.get(s).unwrap().clone();
                each_count *= val;
            }
            count+=each_count;
        }
    }

    println!("{:?}", count);
}

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

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 8444
//In The Name Of Godd
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef pair<ll, ll> ii;
typedef pair<int, ii> iii;
typedef pair<double, double> dd;
typedef pair<dd, double> ddd;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<dd> vdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

#define forn(i, n) for (ll i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define inf 100000000000
#define eps 1e-9
const int maxw = 2e5, maxn = 101;
ll dp[2][maxw];
ll ww[maxn], v[maxn];

int main() {
  ll n, w; cin >> n >> w;
  forn(i, n) cin >> ww[i] >> v[i];
  // forn(i, maxn) forn(j, maxw) dp[i][j] = -inf;
  // forn(i, maxw) dp[0][i] = 0LL;
  forn(i, n + 1) if(i) {
    for(ll j = 0; j <= w; j++){
      ll ni = i % 2, oi = 1 - i % 2;
      dp[ni][j] = dp[oi][j];
      if(j >= ww[i - 1]) dp[ni][j] = max(dp[oi][j - ww[i - 1]] + v[i - 1], dp[ni][j]);
    }
  }
  ll ans = -inf;
  forn(i, maxw) ans = max(ans, dp[n % 2][i]);
  cout << ans << endl;

}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <memory>
using namespace std;

class DoublyLinkedList
{
private:
  struct Node
  {
    int key;
    shared_ptr<Node> prev_ptr;
    shared_ptr<Node> next_ptr;
  };
  shared_ptr<Node> first_ptr;
  shared_ptr<Node> last_ptr;

public:
  DoublyLinkedList():
    first_ptr(nullptr),
    last_ptr(nullptr)
  {}

  bool is_empty()
  {
    return first_ptr == nullptr;
  }

  shared_ptr<Node> find_node(int x)
  {
    if (is_empty()) return nullptr;

    shared_ptr<Node> cur_ptr = first_ptr;

    while (cur_ptr != nullptr)
    {
      // Found
      if (x == cur_ptr->key)
      {
        return cur_ptr;
      }

      // Check the next node
      cur_ptr = cur_ptr->next_ptr;
    }

    // Not found
    return nullptr;
  }

  void insert_node(int x)
  {
    shared_ptr<Node> new_ptr = make_shared<Node>(Node{x, nullptr, first_ptr});

    if (first_ptr == nullptr)
    {
      first_ptr = last_ptr = new_ptr;
      return;
    }
    else
    {
      first_ptr->prev_ptr = new_ptr;
      first_ptr = new_ptr;
      return;
    }
  }

  void delete_first()
  {
    if (is_empty()) return;

    if (first_ptr->next_ptr == nullptr)
    {
      first_ptr = nullptr;
      last_ptr = nullptr;
      return;
    }

    shared_ptr<Node> temp_ptr = first_ptr;
    temp_ptr->next_ptr->prev_ptr = nullptr;
    first_ptr = temp_ptr->next_ptr;
  }

  void delete_last()
  {
    if (is_empty()) return;

    if (last_ptr->prev_ptr == nullptr)
    {
      first_ptr = nullptr;
      last_ptr = nullptr;
      return;
    }

    shared_ptr<Node> temp_ptr = last_ptr;
    temp_ptr->prev_ptr->next_ptr = nullptr;
    last_ptr = temp_ptr->prev_ptr;
  }

  void delete_node(int x)
  {
    if (is_empty()) return;

    shared_ptr<Node> temp_ptr(find_node(x));

    if (temp_ptr == nullptr)
    {
      return;
    }
    if (temp_ptr == first_ptr)
    {
      delete_first();
      return;
    }
    if (temp_ptr == last_ptr)
    {
      delete_last();
      return;
    }

    temp_ptr->prev_ptr->next_ptr = temp_ptr->next_ptr;
    temp_ptr->next_ptr->prev_ptr = temp_ptr->prev_ptr;
  }

  void print()
  {
    if (is_empty())
    {
      printf("\n");
      return;
    }

    shared_ptr<Node> temp_ptr(first_ptr);
    printf("%d", temp_ptr->key);

    while (temp_ptr->next_ptr != nullptr)
    {
      temp_ptr = temp_ptr->next_ptr;
      printf(" %d", temp_ptr->key);
    }

    printf("\n");
  }
};

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

  DoublyLinkedList a_list;
  char command[11];
  int x;
  for (int i = 0; i < n; ++i)
  {
    scanf("%s %d", command, &x);

    if (strcmp(command, "insert") == 0)
    {
      a_list.insert_node(x);
      continue;
    }
    if (strcmp(command, "delete") == 0)
    {
      a_list.delete_node(x);
      continue;
    }
    if (strcmp(command, "deleteFirst") == 0)
    {
      a_list.delete_first();
      continue;
    }
    if (strcmp(command, "deleteLast") == 0)
    {
      a_list.delete_last();
      continue;
    }
  }

  a_list.print();

  return 0;
}


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

typedef long long i64;

const int NMAX = 2010;
vector <int> adia[NMAX];
bool has[NMAX];
int sumamin = 2e9;

pair <int, int> dfs(int nod, int tata, int& nr)
{ // first -> suma maxima, second -> de cate ori pot sa scad 2
	nr = 0;
	if (has[nod])
		nr = 1;

	int suma = 0;
	pair <int, int> pmax = { 0, 0 };

	for (auto i : adia[nod]) {
		if (i == tata)
			continue;
		int c;
		auto par = dfs(i, nod, c);
		nr += c;

		suma += par.first;
		pmax = max(pmax, par);
	}

	int pot_sa_scad = 0;

	if (2 * pmax.first <= suma)
		pot_sa_scad = suma / 2;
	else {
		int rest = 2 * pmax.first - suma;
		pot_sa_scad = suma - pmax.first;
		pot_sa_scad += min(rest / 2, pmax.second);
	}

	return make_pair(suma + nr, pot_sa_scad);
}

void verif(int centr)
{
	pair <int, int> pmax = { 0, 0 };
	int suma = 0;

	for (auto i : adia[centr]) {
		int a = 0;
		auto par = dfs(i, centr, a);
		pmax = max(pmax, par);
		suma += par.first;
	}

	if (suma % 2 != 0)
		return;

	pmax.first -= suma - pmax.first;
	if (pmax.first <= 2 * pmax.second)
		sumamin = min(sumamin, suma / 2);
}

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

	int n, a, b;
	string s;
	cin >> n >> s;
	assert(n <= 2000);

	for (int i = 1; i <= n; i++)
		has[i] = (s[i - 1] == '1');

	for (int i = 2; i <= n; i++) {
		cin >> a >> b;
		adia[a].push_back(b);
		adia[b].push_back(a);
	}

	for (int i = 1; i <= n; i++)
		verif(i);

	if (sumamin == 2e9)
		cout << "-1\n";
	else
		cout << sumamin << '\n';
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int i=0, array1[3000], array2[3000], a, b, tmp;
    while(1){
        scanf("%d %d", &array1[i], &array2[i]);
        if(array1[i] == 0 && array2[i] == 0)
            break;
        i++;
    }
    for(i = 0;; i++){
        if(array1[i] == 0 && array2[i] == 0)
            break;
        if(array1[i] > array2[i]){
            tmp = array1[i];
            array1[i] = array2[i];
            array2[i] = tmp;
        }
        printf("%d %d\n", array1[i], array2[i]);
    }
    
    return 0;
}

Measured memory_bytes: 620