akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N;
    cin >> N;
    map<char, int> m;
    REP(i, N) {
        string S;
        cin >> S;
        m[S[0]]++;
    }

    ll ans = 0;
    char list[] = { 'M','A','R','C','H' };
    FOR(i, 0, 5) {
        FOR(j, i + 1, 5) {
            FOR(k, j + 1, 5) {
                ans += (ll)m[list[i]] * m[list[j]] * m[list[k]];
            }
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

char g[505][505];

int vert(int N){
  int ret = 0;
  REP(j, 0, N){
    REP(i, 0, N){
      if(g[i][j] == '.'){
        ret++;
        break;
      }
    }
  }
  return ret;
}

int make_line(int N){
  int ret = N;
  REP(i, 0, N){
    int curr = N;
    int w = 0;
    bool p = false;
    REP(j, 0, N){
      if(g[j][i] == '#'){
        p = true;
      }
      if(g[i][j] == '.'){
        w++;
      }
    }
    if(p){
      curr = min(curr, w);
    } else {
      curr = min(curr, w+1);
    }
    ret = min(curr, ret);
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  bool f = false;
  int black = 0;
  REP(i, 0, N){
    REP(j, 0, N){
      cin >> g[i][j];
      if(g[i][j] == '#'){
        f = true;
        black++;
      }
    }
  }

  if(!f){
    cout << -1 << endl;
  } else if(black == N * N){
    cout << 0 << endl;
  } else {
    int ex = make_line(N);
    cout << ex + vert(N) << endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define io_optimized ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main(){
#define int int_fast32_t
	io_optimized
	int n;
	string s;
	while(cin>>n)
	{
		map<string,int> ma;
		set<string> se;
		int maxx=0;
		while(n--)
		{
			cin>>s;
			if(ma.find(s)==ma.end())
			{
				ma[s]=1;
			}
			else
			{
				ma[s]++;
			}
			if(ma[s]>maxx)
			{
				se.clear();
				se.insert(s);
				maxx=ma[s];
			}
			else if(ma[s]==maxx)
			{
				se.insert(s);
			}
		}
		for(auto it=se.begin();it!=se.end();it++)
		{
			cout<<*it<<"\n";
		}
	}

	return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n < 105)
    cout << 0 << endl;
  else {
    if (n == 105) {
      cout << 1 << endl;
    } else {
      int ans = 1;
      for (int i = 107; i <= n; i += 2) {
        int f = 0;
        for (int j = 1; j <= i; ++j) {
          if (i % j == 0) {
            f++;
          }
        }
        if (f == 8) {
          ans++;
        }
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long X;
    cin >> X;
    vector<long long> A;
    pair<int, int> ans;
    for (long long i = -4000; i <4000; ++i ){
        A.push_back(pow(i,5));
    }
    bool flag = true;
    for (int a = 0; a<8000 && flag; ++a){
        for (int b = 0;b<8000 && flag; ++b){
            if (A[a]-A[b]==X) {
                if(pow(a-4000,5)-pow(b-4000,5)) {
                ans.first = a;
                ans.second = b;
                flag = false;
                }
                
            }
        }
    }
    cout << (ans.first)-4000 << ' ' << (ans.second)-4000;
}


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

int main(){
  constexpr int64_t M0= 1000;
  int N;
  cin >> N;

  vector<int64_t> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  int64_t ans= M0;
  int right= 0;
  for(int left=0; left<N;){
    while(right+1 < N && data.at(right) <= data.at(right+1)){
      right++;
    }

    ans+= (ans/data.at(left))* (data.at(right)- data.at(left));

    right++;
    left= right;
  }
  
  cout << ans << endl;
}

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

int main(){
    int K,A,B,ans = 0;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++){
        if (i %K == 0)ans++;
    }
    if (ans >= 1){
        cout << "OK" << endl;
    }else cout << "NG" << endl;

return 0;
}
    
    

Measured memory_bytes: 3624
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430
import sys

input = sys.stdin.readline

MOD = 10 ** 6 + 3


def inv(n):
    return pow(n, MOD - 2, MOD)


fact = [1]
for n in range(1, MOD):
    fact.append((fact[-1] * n) % MOD)
    # d>1 の数列を d=1 となる数列に変換する
    # MODの倍数を含む数列の積は0になるので,
    # MODの倍数を含まない区間の積が計算できればよい
    # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい

inv_fact = [-1] * MOD
inv_fact[MOD - 1] = inv(fact[-1])
for n in range(MOD - 2, -1, -1):
    inv_fact[n] = ((inv_fact[n + 1] * (n + 1)) % MOD)
    # inv_factは,inv(n!)にn,n-1,...を掛けるイメージ

Q = int(input())
for _ in range(Q):
    x, d, n = map(int, input().split())

    if x == 0:
        print(0)
        continue

    if d == 0:
        print(pow(x, n, MOD))
        continue

    xd = (x * inv(d)) % MOD
    if xd == 0:
        print(0)
        continue

    if MOD - xd < n:
        print(0)
        continue

    dn = pow(d, n, MOD)
    print((((fact[xd + n - 1] * inv_fact[xd - 1]) % MOD) * dn) % MOD)


Measured memory_bytes: 93804
q, h, s, d = map(int,input().split())
n = int(input())
s = min(4*q, 2*h, s)
if 2*s > d:
    if n%2 == 0:
        ans = n//2 * d
    else:
        ans = n//2 * d + s
else:
    ans = n * s
print(ans)

Measured memory_bytes: 8980
import math

a,b,h,m = map(int,input().split())

h = h*30 + 0.5*m
m = m*6

rad = abs(h-m)
cosrad = math.cos(math.radians(rad))
c2 = a**2 + b**2 - 2*b*a*cosrad
c2 = c2 ** 0.5

print(c2)

Measured memory_bytes: 9508
//include---------------------------------------------------------------------------
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cctype>
#include<string>
#include<vector>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<algorithm>
#include<memory>

//using namespace-------------------------------------------------------------------
using namespace std;

//define,const----------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++)
const int INF = 1 << 25;
#define MAX_N 1000

//global----------------------------------------------------------------------------
bool menbar[MAX_N];
int n, m;

//function--------------------------------------------------------------------------
int solve(int check, int i, int alive){
	if(check == n)
		check = 0;
	if(i == m - 1 && menbar[check]){
		i = 0;
		menbar[check] = false;
		alive--;
		if(alive == 0)
			return check + 1;
	}
	if(menbar[check])
		return solve(check + 1, i + 1, alive);
	else 
		return solve(check + 1, i, alive);
}

int main(){
	while(scanf("%d %d", &n, &m)){
		if(n == 0 && m == 0) return 0;
		for(int i = 0; i < n; i++)
			menbar[i] = true;
		printf("%d\n", solve(0, 0, n));
	}
	return 0;
}

Measured memory_bytes: 1028
n = int(input())
s = list(map(int, input().split()))
answerL = []
for i in range(len(s)):
    ans = 'node '+str(i+1)+': '
    ans+= 'key = '+str(s[i])+', '
    if i!= 0:
        ans+='parent key = '+str(s[(i-1)//2])+', '
    if 2*i+1 < len(s):
        ans+='left key = '+str(s[2*i+1])+', '
    if 2*i+2 < len(s):
        ans+='right key = '+str(s[2*i+2])+', '
    answerL.append(ans)
for ans in answerL:
    print(ans)



Measured memory_bytes: 5628
#include <bits/stdc++.h>
//#define Akshay

using namespace std;

template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}

int main()
{
    #ifdef Akshay
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long int i,j,n,m,a,da,db,ans=10000000000000,b;
    
    cin>>n;
    
    for(i=1;i<=sqrt(n);i++)
    {
        da=0;
        db=0;
        if(n%i==0)
        {   b=i;
            a=n/b;
            
            while(a!=0)
            {
                da++;
                a/=10;
            }
            while(b!=0)
            {
                db++;
                b/=10;
            }
            
            if(ans>max(db,da))
            {
                ans=max(db,da);
            }
        }
    }
    
    cout<<ans;
    
    return 0;
    
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	static final int[] COUNTS = new int[]{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	static int[] dp;
	static int[] mCount;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[m];
		for (int i = 0; i < m; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		mCount = new int[m];
		for (int i = 0; i < m; i++) {
			mCount[i] = COUNTS[arr[i]];
		}
		dp = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			dp[i] = dfs(i);
		}
		int length = dp[n];
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < length; i++) {
			for (int j = 0; j < m; j++) {
				int a = mCount[m - 1 - j];
				if (dp[n] == dfs(n - a) + 1) {
					n -= a;
					sb.append(arr[m - 1 - j]);
					break;
				}
			}
		}
		System.out.println(sb);
	}
	
	static int dfs(int x) {
		if (x < 0) {
			return -1;
		} else if (x == 0) {
			return 0;
		}
		if (dp[x] != 0) {
			return dp[x];
		}
		int max = Integer.MIN_VALUE;
		for (int a : mCount) {
			int y = dfs(x - a);
			if (max < y + 1) {
				max = y + 1;
			}
		}
		if (max == 0) {
			max = -1;
		}
		return max;
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl0
 
ll modpow(ll x, ll y, ll m){
    if(y==0) return 1;
    ll res = modpow(x,y/2,m);
    return res * res % m * (y&1 ? x : 1) % m;
}
 
int h,w,n,k;
 
int ask(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c-1, d-1);
    fflush(stdout);
    int p;
    cin >> p;
    return p;
}
 
int ans[50][50];
 
void solve(int i1, int j1, int i2, int j2, int n){
    int h = i2 - i1;
    int w = j2 - j1;
    if(n == 0 || n == h*w){
        for(int i = i1; i < i2; ++i){
            for(int j = j1; j < j2; ++j){
                ans[i][j] = n == 0 ? 0 : 1;
            }
        }
    } else {
        if(w == 1 || rand()%2){
            int x = ask(i1, j1, i1 + h/2, j2);
            solve(i1, j1, i1 + h/2, j2, x);
            solve(i1 + h/2, j1, i2, j2, n - x);
        } else {
            int x = ask(i1, j1, i2, j1 + w/2);
            solve(i1, j1, i2, j1 + w/2, x);
            solve(i1, j1 + w/2, i2, j2, n - x);
        }
    }
}
 
int main(){
    srand(time(0));
    cin >> h >> w >> n >> k;
    memset(ans, -1, sizeof ans);
    solve(0, 0, h, w, n);
 
    // rep(i,h){
    //     rep(j,w){
    //         cerr << ans[i][j];
    //     }
    //     cerr << endl;
    // }
 
    ll sigma = 0;
    rep(i,h)rep(j,w){
        sigma += ans[i][j] * modpow(2, i*w + j, k);
        sigma %= k;
    }
    cout << "! " << sigma << endl;
}

Measured memory_bytes: 716
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var d = int.Parse(Console.ReadLine());
			if(d==0)break;
			Sol mySol=new Sol(d);
			mySol.writeAns();
		}
	}
}


class Sol{
	String ans_s;
	int cnt;
	
	public void writeAns(){
		Console.WriteLine(cnt);
		Console.WriteLine(ans_s);
	}
	
	public Sol(int n){
		var arr=Array.ConvertAll(Console.ReadLine().Split(' '),elem=>int.Parse(elem));
		int[] arr2=new int[n];
		for(int ii=0;ii<n;ii++)arr2[ii]=arr[ii];
		cnt=0;
		while(true){
			for(int i=0;i<n;i++){
				int k=0;
				for(int j=0;j<n;j++){
					if(arr[j]==arr[i])k++;
				}
				arr2[i]=k;
			}
			int chk=0;
			for(int i=0;i<n;i++)if(arr[i]!=arr2[i])chk++;
			if(chk!=0)cnt++;
			if(chk==0)break;
			for(int i=0;i<n;i++)arr[i]=arr2[i];

		}
		//ans_s=string.Join(" ",arr2);
		String[] sss = Array.ConvertAll(arr2,delegate(int elem){return elem.ToString();});
		ans_s=String.Join(" ",sss);
	}
}	

Measured memory_bytes: 5716
#include<iostream>
#include<cstdlib>
using namespace std;


int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (abs(a - c) <= d || abs(a - b) <= d&&abs(b - c) <= d) {
		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 System.Threading.Tasks;

namespace ABC113B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var TA = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var H = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var T = TA[0];
            var A = TA[1];

            double ansHeight = double.MaxValue;
            int ansNumber = -1;
            for(int i = 0; i < N; i++)
            {
                double d = Math.Abs(A - TempertureFromHeight(T, H[i]));
                if (ansHeight > d)
                {
                    ansHeight = d;
                    ansNumber = i + 1;
                }
            }
            Console.WriteLine(ansNumber);
            Console.ReadKey();
        }

        static double TempertureFromHeight(int T, int x)
        {
            return T - 0.006 * x;
        }
    }
}


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

int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    
    const LL MOD = 1000000007;
    
    string s;
    cin >> s;
    int n = s.size();
    vector<LL> num(n);
    for(int i = 0; i < n; i++){
        num[i] = s[i] - 'a' + 1;
    }
    vector<LL> dp(n+1, 0);
    dp[n] = 1;
    vector<LL> psums(n+1, 0);
    psums[0] = 0;
    set<LL> f[3];
    for(int i = 0; i < n; i++){
        psums[i+1] = (psums[i] + num[i]) % 3;
        f[psums[i]].insert(i);
    }
    set<LL> repeats;
    for(int i = 0; i < n; i++){
        if(i + 1 < n && num[i] == num[i+1]) repeats.insert(i+1);
    }
    
    f[psums[n]].insert(n);
    int stillbad = 1;
    for(LL r = n-1; r >= 0; r--){
        dp[r] = 0;
        if(r + 1 < n && num[r] == num[r+1]) stillbad = 0;
        if(stillbad){
            dp[r] = 1;
            continue;
        }
        for(LL b = 1; b <= 2; b++){
            int count_whole = 0;
            if(num[r] == b){
                dp[r] += dp[r+1];
                dp[r] %= MOD;
                if(r+1 == n) count_whole = 1;
                if(repeats.lower_bound(r+2) == repeats.end()){
                    LL q = n - (r+1);
                    dp[r] += q/2;
                    dp[r] %= MOD;
                    count_whole = 1;
                }
                // do something special; in weird case
            } else {
                auto z = repeats.lower_bound(r + 1);
                if(z == repeats.end()) continue;
                
                LL look_for = (psums[r] + b) % 3;
                auto it = f[look_for].lower_bound(*z);
                if(it == f[look_for].end()) continue;
                int idx = *it;
                dp[r] += dp[idx];
                dp[r] %= MOD;
                if(idx == n) count_whole = 1;
                if(repeats.lower_bound(idx + 1) == repeats.end()){
                    LL q = n - idx;
                    dp[r] += q/2;
                    dp[r] %= MOD;
                    count_whole = 1;
                }
            }
            if(!count_whole == 1 && (psums[r] + b) % 3 == psums[n] && !stillbad){
                dp[r] ++;
                dp[r] %= MOD;
            }
        }
    }
    cout << dp[0] << '\n';
}

Measured memory_bytes: 12240
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		int ans = 0;

		ans = (n * 800) - ((n / 15) * 200);

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

vector<int> C(10005);
void CountingSort(vector<int> A, vector<int> &B, int k) {
    for (int i = 0; i <= k; i++) {
        C[i] = 0;
    }
    for (int j = 0; j < A.size(); j++) {
        C[A[j]]++;
    }

    for (int i = 1; i <= k; i++) {
        C[i] = C[i] + C[i - 1];
    }

    for (int j = A.size() - 1; j > -1; j--) {
        B[C[A[j]] - 1] = A[j];
        C[A[j]]--;
    }
}

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

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N) { cin >> A[i]; }

    int k = *max_element(all(A));
    CountingSort(A, B, k);
    rep(i, N - 1) { cout << B[i] << " "; }
    cout << B[N - 1] << endl;
}


Measured memory_bytes: 26208
# -*- coding: utf-8 -*-
n = int(input())
rlist = []
for i in range(n):
    s, p= input().split()
    rlist.append({'i':i+1, 's':s, 'p':int(p)})

sorted_items = sorted(
  rlist,
  key = lambda x: (x['s'], -x['p'])
)

for r in sorted_items:
    print(r['i'])


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

int main() {
  string t, p; cin >> t >> p;
  int ans = -1;
  while (true) {
    ans = t.find(p, ans + 1);
    if (ans == -1) break;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3176
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>
#include <queue>
#include <assert.h>

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

#define int long long

using namespace std;

int N;
int a[300010];
int sum_arr[300010];
int min_sum_arr[300010];

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> N;
    rep(i,3*N) cin >> a[i];

    priority_queue<int, vector<int>, greater<int> > minpq;

    int sum = 0;
    rep(i,N) {
        minpq.push(a[i]);
        sum += a[i];
    }
    sum_arr[N-1] = sum;

    for (int i=N; i<2*N+1; i++) {
        minpq.push(a[i]);
        sum += a[i];
        sum -= minpq.top();
        minpq.pop();
        sum_arr[i] = sum;
    }

    priority_queue<int> maxpq;

    sum = 0;

    for (int i=3*N-1; i>=2*N; i--) {
        maxpq.push(a[i]);
        sum += a[i];
    }
    min_sum_arr[2*N] = sum;

    for (int i=2*N-1; i>=N-1; i--) {
        maxpq.push(a[i]);
        sum += a[i];
        sum -= maxpq.top();
        maxpq.pop();
        min_sum_arr[i] = sum;
    }

    //int ans = INT_MIN;
    int ans = -1000000000000000LL;
    for (int i=N-1; i<=2*N-1; i++) {
        ans = max(ans, sum_arr[i] - min_sum_arr[i+1]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 7668
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int mod = 1000000007;


int main(){
    ll N;
    cin>>N;
    ll p[N];
    ll cnt=0;
    for(ll i=0;i<N;i++){
        cin>>p[i];
    }
    for(ll i=0;i<N;i++){
        if(i!=N-1&&i+1==p[i]){
            swap(p[i+1],p[i]);
            cnt++;
        }
        if(i==N-1&&i+1==p[i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main() {
    int a, b;
    int s, r;
    
    scanf("%d", &a);
    scanf("%d", &b);
    
    s = a * b;
    r = (a + a) + (b + b);
    
    printf("%d %d\n", s, r);
    
    return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

//        int[] prices = new int[n];
//        for(int i=0;i<n;i++){
//            prices[i] = sc.nextInt();
//        }

        PriorityQueue<Integer> que = new PriorityQueue<>(new MyComparator());
        for(int i=0;i<n;i++){
            que.add(sc.nextInt());
        }

//        for(int i=0;i<n;i++){
//            System.out.println(
//              que.poll());
//        }

        if(n==1){
            int temp=que.poll();
            for(int i=0;i<m;i++){
                temp = temp/2;
            }
            System.out.println(temp);
            return;
        }


        for(int i=0;i<m;i++){
            //System.out.println(i);
            int a = que.poll();
            int b = que.poll();

            //System.out.println("a=" + a + " b=" + b);

            if(i==m-1) {
                que.add(a/2);
                que.add(b);
            }else {
                if (a / (2 * 2) > b) {
                    //System.out.println("a / 2 * 2 :" + a / (2 * 2));
                    que.add(a / (2 * 2));
                    que.add(b);
                    i++;
                } else {
                    //System.out.println("a / 2  :" + a / 2 );
                    que.add(a / 2);
                    que.add(b / 2);
                    i++;
                }
            }

        }

        long count =0;
        //System.out.println("size:" + que.size());
        int size = que.size();
        for(int i=0;i < size;i++){
            int temp = que.poll();
            //System.out.println("temp =" + temp);
            count += temp;
        }
        System.out.println(count);




    }
}
class MyComparator implements Comparator {

    public int compare(Object obj1, Object obj2) {

        int num1 = (int)obj1;
        int num2 = (int)obj2;

        if(num1 < num2) {
            return 1;
        } else if(num1 > num2) {
            return -1;
        } else{
            return 0;
        }
    }
}

Measured memory_bytes: 57052
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
const int N=200005;
 
inline int read(){
    int x=0; char ch=getchar();
    for(;!isdigit(ch);ch=getchar());
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
    return x;
}
 
int n,px,py;
ll a[N],ans=1e18,tot,now,mx,mn;
 
inline void update(){
    if(now<mn) mn=now;
    else if(now>mx) mx=now;
}
 
inline void solve(){
    for(int i=1;i<=n;i++){
        while(px<i&&a[px+1]*2ll<=a[i]) px++;
        while(py<n&&a[py+1]*2ll<=tot+a[i]) py++;
         
        for(int u=px+1;u>=px;u--)
            for(int v=py+1;v>=py;v--){
                mx=mn=a[u];
                 
                now=a[i]-a[u],update();
                now=a[v]-a[i],update();
                now=tot-a[v],update();
                 
                ans=min(ans,mx-mn);
            }
    }
}
 
int main(){
    n=read();
    for(int i=1;i<=n;i++) a[i]=a[i-1]+(ll)read();
    a[n+1]=a[n+2]=tot=a[n];
    solve(),printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 5336
h,w=map(int,input().split())
a=[0]*(w+2)
m=[a]
ans='Yes'
for i in range(h):
    s=input()
    m.append([0]+[1 if x=='#' else 0 for x in s]+[0])
m.append(a)
for i in range(1,h+1):
    for j in range(1,w+1):
        if m[i][j]==1 and sum(m[i][j-1:j+2],m[i-1][j]+m[i+1][j])==1:
            ans='No'
print(ans)


Measured memory_bytes: 40432
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		
		String str=input.next();
		char[] a = str.toCharArray();
		
		if((a[2]==a[3])&&(a[4]==a[5])) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}	
}


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

int conta(int x, int y, int d) {
	if(sqrt(pow(x, 2) + pow(y, 2)) > d)
		return 0;
	return 1;
}

int main() {
	int n, d, x, y, quant = 0;
	scanf("%d %d", &n, &d);

	for(int i = 0; i < n; ++i) {
		scanf("%d %d", &x, &y);
		if(conta(x, y, d))
			++quant;
	}

	printf("%d\n", quant);


}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;



int main(){
  ll n;
  cin >> n;
  cout<< (n/2)*((n+1)/2)<<endl;
  return 0;
}
  


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

int main(){
  string s,t;
  cin >> s >> t;
  int ans = 1001;
  rep(i,s.size()-t.size()+1){
    int res = 0;
    rep(j,t.size()){
      if (s[i+j] != t[j]) res++;
    }
    ans = min(ans,res);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

s =  list(sys.stdin.readline().rstrip())
k=['R', 'U', 'D']
g=['L', 'U', 'D']

flg = 1

for i in range(len(s)):
    if (i+1)%2 !=0:
        if s[i] not in k:
            flg = 0
    if (i+1)%2 ==0:
        if s[i] not in g:
            flg = 0
if flg == 0:
    print("No")
else:
    print("Yes")

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

int N, A[19], B[19];
int dp[1 << 19][19];

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

	for (int i = 0; i < (1 << N); i++) {
		for (int j = 0; j <= N; j++) dp[i][j] = (1 << 30);
	}

	dp[0][N] = 0;
	for (int i = 0; i < (1 << N); i++) {
		for (int j = 0; j <= N; j++) {
			if (dp[i][j] == (1 << 30)) continue;

			int bit[19], rui[19], cnts = 0;
			for (int k = 0; k < N; k++) { bit[k] = 0; if ((i & (1 << k)) != 0) bit[k] = 1; cnts += bit[k]; }
			for (int k = 0; k < N; k++) rui[k] = bit[k];
			for (int k = N - 2; k >= 0; k--) rui[k] += rui[k + 1];

			int preval = A[j];
			if (j == N) preval = -1000000000;
			else if (abs((cnts - j)) % 2 == 0) preval = B[j];

			// 次に何を取るか
			for (int k = 0; k < N; k++) {
				if (bit[k] == 1) continue;
				int r = A[k]; if (abs(cnts - k) % 2 == 1) r = B[k];
				if (preval <= r) {
					dp[i + (1 << k)][k] = min(dp[i + (1 << k)][k], dp[i][j] + rui[k]);
				}
			}
		}
	}
	
	int ans = (1 << 30);
	for (int i = 0; i < N; i++) ans = min(ans, dp[(1 << N) - 1][i]);

	if (ans == (1 << 30)) cout << "-1" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 20736
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}


//#########################################
char a[1000000];
int main() {

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

}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

int digit_sum(int x){
    if (x < 10) return x;
    return x % 10 + digit_sum(x / 10);
}

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

    int ans = n + 1;
    for (int i = 1; i < n; ++i) {
        ans = min(ans, digit_sum(i) + digit_sum(n - i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

int a[20],b[20],c[20],n;
pair<double,int> dp[1<<16][20];

double f(int bit,int now){
	if(bit==0)return 0;
	if(dp[bit][now].first>=0)return dp[bit][now].first;
	int weight=0;
	rep(i,n){
		if((bit&1<<i)>0)continue;
		weight+=c[i];
	}
	double res=-1;
	rep(i,n){
		if((bit&1<<i)==0)continue;
		double k=f(bit^1<<i,i)+abs(b[i]-b[now])/(2000./(70+weight*20));
		if(res<0||res>k){
			dp[bit][now].first=k;
			dp[bit][now].second=i;
			res=k;
		}
	}
	return res;
}

int main() {
	n=in();
	rep(i,n){
		cin>>a[i]>>b[i]>>c[i];
	}
	rep(i,1<<16)rep(j,20){
		dp[i][j].first=-1;
		dp[i][j].second=-1;
	}
	double res=-1;
	rep(i,n){
		double k=f(((1<<n)-1)^1<<i,i);
		if(res<0||res>k){
			res=k;
			dp[(1<<n)-1][0].second=i;
		}
	}
	int bit=(1<<n)-1,now=dp[(1<<n)-1][0].second;
	while(bit){
		if(bit<(1<<n)-1)cout<<" ";
		cout<<a[now];
		bit^=1<<now;
		now=dp[bit][now].second;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 15000
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int SURP = 1000000007;

int main(){
	int N;
	string s;
	cin >> N >> s;
	bool isWest[N] = {0};

	FOR(i,0,(int)s.length()){
		if(s[i] == 'W') isWest[i] = true;
	}

	int ret = 0;
	FOR(i,1,N){
		if (!isWest[i]) ret++;
	}

	int tmp = ret;
	FOR(i,1,N){
		if(!isWest[i]) tmp--;
		if(isWest[i-1]) tmp++;
		if(tmp < ret) ret = tmp;
	}

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
constexpr int INF = (numeric_limits<int>::max() == INT_MAX ? (int)1e9 : (long long)1e18);
constexpr long double eps = 1e-6;
const string el = "\n";
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;using pii = pair<int,int>;using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void fast_io(){ios::sync_with_stdio(false); cin.tie(nullptr);}
int out(int a){cout << a << el; return 0;}
int out(string s = "NO"){cout << s << el; return 0;}
template <class T>
inline int out(vector<T>&v,string c = " "){
    for(int i = 0; i < v.size(); ++i){
        if(i) cout << c; cout << v[i];
    } cout << el;return 0;
}
signed main(){
    fast_io();
    int N; cin >> N;
    vector<pii>input(N);
    for(auto& p : input)
        cin >> p.first >> p.second;
    sort(all(input));
    int ans = 0;
    rep(i,N - 1) ans += min(input[i + 1].first - input[i].first,input[i].second - input[i+1].second);
    ans += input.back().second + 1;
    ans += input.front().first - 1;
    cout << ans << endl;
    
    
}




Measured memory_bytes: 1920
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI
#include <numeric>	//gcd

using namespace std;

int main() {

	int K, X;
	cin >> K >> X;

	K = K * 500;

	if (K >= X) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;

}

Measured memory_bytes: 3684
#include <stdio.h>

int main(void){
    
    int n,m,i,j,k,l,flag;
    char a[51][51],b[51][51];
    
    scanf( "%d %d",&n,&m );
    
    for( i = 0; i < n; i++ ){
        scanf( "%s",a[i] );
    }
    
    for( i = 0; i < m; i++ ){
        scanf( "%s",b[i] );
    }
    
    for( i = 0; i < n-m+1; i++ ){
        for( j = 0; j < n-m+1; j++ ){
            flag = 1;
            for( k = 0; k < m; k++ ){
                for( l = 0; l < m; l++ ){
                    if( a[i+k][j+l] != b[k][l] ){
                        flag = 0;
                    }
                }
            }
            if( flag == 1 ){
                printf( "Yes" );
                return 0;
            }
        }
    }
    printf( "No" );
    return 0;
}

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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    string c1,c2,c3;
    cin >> c1 >> c2 >> c3;
    cout << c1[0] << c2[1] << c3[2] << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<map>
#include<algorithm>
#define mp(x,y) make_pair(x,y)
#define pi pair<int,int>
using namespace std;
inline int read(){int x=0,f=1,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;}
inline void write(int x){if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0');}
inline void writeln(int x){write(x); puts("");}
const int N=1e5+5;
set<int >se[N];
map<pi,int> ma;
pi q[N];
int n,h,t,fa[N];
inline int getfa(int x){
    return (fa[x]==x)?x:fa[x]=getfa(fa[x]);
}
inline void init(){
    n=read();
    for (int i=1;i<=n*2-2;i++){
        int u=read(),v=read();
        se[u].insert(v); se[v].insert(u);
        ma[mp(u,v)]++; ma[mp(v,u)]++;
        if (ma[mp(u,v)]==2) q[++t]=make_pair(u,v);
    }
}
inline void solve(){
    for (int i=1;i<=n;i++) fa[i]=i;
    set<int >::iterator it;
    while (h<t){
        int u=q[++h].first,v=q[h].second;
        u=getfa(u); v=getfa(v);
        se[u].erase(v); se[v].erase(u);
        if (se[u].size()<se[v].size()) swap(u,v);
        for (it=se[v].begin();it!=se[v].end();++it){
            int to=(*it);
            ma[mp(to,v)]=ma[mp(v,to)]=0;
            se[to].erase(v); se[to].insert(u);
            ma[mp(to,u)]++; ma[mp(u,to)]++;
            if (ma[mp(to,u)]==2) q[++t]=make_pair(to,u);
            se[u].insert(to);
        }
        fa[v]=u;
        se[v].clear();
    }
    int s=0;
    for (int i=1;i<=n;i++) s+=fa[i]==i;
    if (s==1) puts("YES"); else puts("NO");
}
int main(){
    init(); solve();
    return 0;
}

Measured memory_bytes: 57984
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<long long> s(n);
    for(int i=0;i<n;i++){
        if(i==0)s[i]=a[i];
        else s[i]=s[i-1]+a[i];
    }
    map<long long,int> m;
    long long ret=0;
    for(int i=n-1;i>0;i--){
        m[s[i]]++;
        ret+=m[s[i-1]];
    }
    m[s[0]]++;
    ret+=m[0];
    cout<<ret<<endl;
}

Measured memory_bytes: 15104
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define ret0 return 0;
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main() {
    map <ll, ll> pcnt;
    map <ll, bool> done;
 
    ll n, m, k;
    cin >> n >> m;
    string s;
    ll ac = 0, pen = 0;
    while (m--){
        cin >> k >> s;
        if (done[k]) {
            continue;
        }
            
        if (s == "WA") {
            pcnt[k]++;
        } else {
            pen += pcnt[k];
            ac++;
            done[k] = true;
        }
    }
    
    dmes (ac, pen);
}


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

bool cmp(const pair<long long, long long> &a, const pair<long long, long long> &b) {
	return (a.first + a.second) > (b.first + b.second);
}

int main(void) {
	int n;
	long long a = 0LL, b = 0LL;
	cin >> n;
	vector<pair<long long, long long> > d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i].first >> d[i].second;
	}
	sort(d.begin(), d.end(), cmp);
	for (int i = 0; i < n; i++) {
		if (!(i % 2)) a += d[i].first;
		else b += d[i].second;
	}
	
	cout << a - b << endl;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int n;
long long cnt, sum;

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		int d;
		long long c;
		read(d), read(c);
		cnt += c, sum += c * d;
	}
	print(cnt - 1 + (sum - 1) / 9);
}


Measured memory_bytes: 6044
#include <stdio.h>
#define N 100
int main()
{
  int i,v,j,num,A[N];
    scanf("%d",&num);
  
  for(i=0; i<num; i++){
    scanf("%d",&A[i]);
  }
  for(i=0; i<num-1; i++){
    printf("%d ", A[i]);
    }
    printf("%d\n",A[num-1]);
    
   for (i=1; i<=num-1; i++) {
    v  =  A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
       A[j+1]=A[j];
       j--;
       A[j+1]=v;
         }
       
       for(j=0; j<num-1; j++){
           printf("%d ", A[j]);
       }
     printf("%d\n", A[num-1]);
      }
    return 0;
}


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

using namespace std;

const long long MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> iii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef priority_queue<pii, vector<pii>, greater<pii>> fila_prioridade;
typedef priority_queue<iii, vector<iii>, greater<iii>> fila_prioridade_grids;

#define nl '\n'
#define INF 1000000000
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);


int n;

int main() {
        NeedForSpeed

	cin >> n;

	int numero = 1;

	int fatores_2 = 0;
	int maior = 0;
	int resposta = 1;

	while (numero <= n) {
		int pato = numero;
		fatores_2 = 0;
		while(pato != 1 || pato % 2 == 0) {
			pato /= 2;
			fatores_2++;
		}

		if (fatores_2 > maior) {
			maior = fatores_2;
			resposta = numero;
		}

		numero++;
	}


	cout << resposta << nl;



        return 0;
}



Measured memory_bytes: 3608
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int left=scan.nextInt();
        int right=scan.nextInt();
        int cnt=0;
        int temp;
        for(int i=0;i<n;i++){
            temp=scan.nextInt();
            if(temp<left || right<=temp)
                cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 9808
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const int mod = 1e9 + 7;

int main(){
    set<char> se;
    string s;
    cin >> s;

    for (int i=0; i<(int)s.size(); i++){
        se.insert(s[i]);
    }
    if (se.size() != 2 || s.size() != 4){
        cout << "No" << endl;
        return 0;
    }

    char v[2];
    int id=0, a = 0, b=0;
    for (auto it : se){
        v[id] = it;
    }
    for (int i=0; i<4; i++){
        if (s[i] == v[0]) a++;
        else b++;
    }
    if (b == a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
M=len(input())
O=10**9+7
D=[pow(-~O//2,M,O)]+[0]*-~N
for _ in'_'*N:D=[((2*D[i-1]if i else D[0])+D[i+1])%O for i in range(N+1)]+[0]
print(D[M])

Measured memory_bytes: 60508