akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    sort(ALL(a), greater<int>());
    int ans = 0;
    REP(i, n)
    {
        if (i % 2 == 0)
        {
            ans += a[i];
        }
        else
        {
            ans -= a[i];
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int n,x,t,f=0,c=0;
  cin >> n >> x >> t ;
  int i=0;
  while(f==0){
    c += x;
    i++;
    if(n <= c) break;
  }
  cout << i * t;
}


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

int main(){
    int N;cin>>N;
    vector<string> S(N),ans;
    vector<int> ansc;
    REP(i,N)cin>>S[i];
    sort(S.begin(),S.end());
    int cnt=1;
    int m_cnt=0;
    REP(i,N-1){
        if(S[i]==S[i+1])cnt++;
        else{
            ans.push_back(S[i]);
            ansc.push_back(cnt);
            m_cnt=max(m_cnt,cnt);
            cnt=1;
        }
    }
    ans.push_back(S[N-1]);
    ansc.push_back(cnt);
    m_cnt=max(m_cnt,cnt);
    REP(i,ans.size()){
        if(ansc[i]==m_cnt)cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 17652
import Data.List (foldl')
import qualified Data.Map.Strict as Map

type WordCount = Map.Map String Int

main = input >>= return . solve >>= output

input :: IO [String]
input = words `fmap` getLine

output :: (String,String) -> IO ()
output (s1,s2) = putStrLn $ unwords [s1,s2]

solve :: [String] -> (String, String)
solve ws = wc `seq` (mostFrequent wc, longest wc)
    where
    wc = wordCount ws

wordCount :: [String] -> WordCount
wordCount = foldl' countUp Map.empty
    where
    countUp wc w = Map.insertWith (+) w 1 wc

mostFrequent :: WordCount -> String
mostFrequent wc = maxCount `seq` head [w|(w,c)<-Map.assocs wc, c == maxCount]
    where
    maxCount = maximum $ Map.elems wc

longest :: WordCount -> String
longest wc = maxLength `seq` head [w|w<-Map.keys wc, length w == maxLength]
    where
    maxLength = maximum $ map length $ Map.keys wc

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;
int a,b,c,d,ans;
str s1,s2,s;
int32_t main() {
    fast();
    cin >> a;
    cin >> s1 >> s2;
    int i1=0,i2=0;
    f(j,1,2*a+1){
        if(j&1){
            cout<<s1[i1];
            i1++;
        }
        else{
            cout<<s2[i2];
            i2++;
        }

    }

    return 0;
}
 

Measured memory_bytes: 256
K, S = map(int, input().split())

def solve(K,S):
    ans = 0
    for i in range(K+1):
        if i>S:
            continue
        for j in range(K+1):
            if i+j>S or i+j<S-K:
                continue
            # print(i,j,S-i-j)
            ans += 1
    return ans
print(solve(K,S))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  set<string> st;
  while(n--)
  {
    string s;
    cin>>s;
    st.insert(s);
  }
  cout<<st.size()<<endl;
  return 0;
}


Measured memory_bytes: 19112
from sys import stdin

# 無限大の定義
INF = 10 ** 9

N, A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
#N, *ABC = [int(x) for x in stdin.readline().rstrip().split()]

l_list = [int(stdin.readline().rstrip()) for _ in range(N)]


# DFS（深さ優先探索で解く）
# cur: カーソル
def dfs(cur, a, b, c):
    # カーソルが丈listの最後まで来たら
    if cur == N:
        # 「長さ Aの竹の材料」「長さ B の竹の材料」「長さ C の竹の材料」がそれぞれ一本以上必要で、
        # これを満たさない竹の扱い方は棄却
        if min(a, b, c) > 0:
            # 合成してから竹を伸ばしたり縮めるコストと、竹を伸ばしたり縮めたりして合成するコストは同じ
            # （足し算は順序を交換しても結果は変わらないから）
            # -30は、a, b, cについて材料選択の1回目にも合成とみなされていることから、その分を引いている
            # abs()は差の絶対値を求める標準関数
            # abs(a - A)は、今あるaに対して目標のAに対して伸ばすor縮めるコストを表している
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return INF
        
    # カーソルを進めながら全探索
    ret0 = dfs(cur+1, a, b, c) # どの竹の材料にもしない
    ret1 = dfs(cur+1, a+l_list[cur], b, c) + 10 # Aの材料にする
    ret2 = dfs(cur+1, a, b+l_list[cur], c) + 10 # Bの材料にする
    ret3 = dfs(cur+1, a, b, c+l_list[cur]) + 10 # Cの材料にする

    return min(ret0, ret1, ret2, ret3)

# cur=0, どの竹の材料も無い状態から
print(dfs(0, 0, 0, 0))

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

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    ll sum = 0, res = 0, right = 0;
    rep(left, 0, n)
    {
        while (right < n && ((sum ^ a[right]) == (sum + a[right])))
            sum += a[right], right++;
        res += right - left;
        if (left == right)
            ++right;
        else
            sum -= a[left];
    }
    cout << res << endl;
}


Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <deque>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    int n;
    cin >> n;
    multiset<int> st;

    int a1;
    cin >> a1;
    st.insert(a1);
    for(int i = 1;i < n;i++){
        int a;
        cin >> a;
        auto p = st.lower_bound(a);

        if(p == st.begin())st.insert(a);
        else{
            p--;
            st.erase(p);
            st.insert(a);
        }
    }

    cout << st.size() << endl;
}


Measured memory_bytes: 4992
#include<cstdio>
#define IN 150
using namespace std;

int n,u,f,y,x;
int h[300][300],d[300][300],res[7];
int dice[6],tmp[6];
int dy[] = {0,1,-1,0}, dx[] = {-1,0,0,1}; //w,s,n,e
 
int rot[4][6] = { {4,0,2,3,5,1},
		  {3,1,0,5,4,2},
		  {2,1,5,0,4,3},
		  {1,5,2,3,0,4} };

int die[6][6] = { {0,2,4,1,3,0},
		 {3,0,0,5,0,2},
		 {1,5,0,0,0,4},
		 {4,0,0,0,5,1},
		 {2,0,5,0,0,3},
		 {0,3,1,4,2,0} };

int main(){
  while(scanf("%d",&n),n){
    for(int i=0;i<300;i++)
      for(int j=0;j<300;j++)h[i][j] = d[i][j] = -1;

    while(n--){
      scanf("%d %d",&u,&f);
      u--; f--;
      dice[0] = u; dice[5] = 5-u;
      dice[1] = f; dice[4] = 5-f;
      dice[2] = die[u][f]; dice[3] = 5 - die[u][f];
      
      f = true;
      y = x = IN;
      while(f){
	f = false;
	for(int i=5;i>=3;i--){
	  for(int j=0;j<4;j++){
	    if(dice[j+1] == i){
	      if(h[y][x] > h[y+dy[j]][x+dx[j]]){
		y = y+dy[j]; x = x+dx[j];
		for(int k=0;k<6;k++)tmp[k] = dice[rot[j][k]];
		for(int k=0;k<6;k++)dice[k] = tmp[k];
		f = true;
		break;
	      }
	    }
	  }
	  if(f)break;
	}
      } 
      h[y][x]++; d[y][x] = dice[0];
    }
    
    for(int i=0;i<7;i++)res[i] = 0;
    for(int i=0;i<300;i++)
      for(int j=0;j<300;j++)res[d[i][j]+1]++;
    for(int i=1;i<6;i++)printf("%d ",res[i]);
    printf("%d\n",res[6]);
  }
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  if (n < 7) {
    cout << "No\n";
    return 0;
  }
  vector<int> deg(n);
  vector< vector<int> > g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    deg[u]++;
    deg[v]++;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) { return deg[i] > deg[j]; });

  bool ok = true;
  for (int i = 0; i < n; i++) {
    ok &= (deg[i] % 2 == 0);
    // cerr << deg[i] << ' ';
  }

  function<bool(int,int,int)> dfs = [&](int s, int v, int pa) {
    if (v == s && pa != -1) return true;
    if (deg[v] != 2 && pa != -1) return false;
    bool ret = false;
    for (auto u : g[v]) {
      if (u != pa) {
        ret |= dfs(s, u, v);
      }
    }
    return ret;
  };

  auto check = [&]() {
    if (deg[ord[0]] >= 6) return true;
    if (deg[ord[0]] == 2) return false;
    // max deg == 4
    if (deg[ord[1]] == 2) return false;
    if (deg[ord[2]] == 4) return true;
    // deg = [4, 4, 2, ..., 2]
    if (dfs(ord[0], ord[0], -1)) return true;
    if (dfs(ord[1], ord[1], -1)) return true;
    return false;
  };

  ok &= check();
  puts(ok ? "Yes" : "No");
  return 0;
}

/*
8 10
1 2
1 3
2 3
3 4
3 5
4 6
5 6
6 7
7 8
6 8

6 8
1 5
2 5
3 5
4 5
1 6
2 6
3 6
4 6

*/

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
#define pll pair<ll, ll>
#define vpl vector<pll>
#define vb vector<bool>
#define PB push_back
#define MP make_pair
#define ln "\n"
#define forn(i,e) for(ll i=0; i<e; i++)
#define forsn(i,s,e) for(ll i=s; i<e; i++)
#define rforn(i,e) for(ll i=e; i>=0; i--)
#define rforsn(i,s,e) for(ll i=s; i>=e; i--)
#define vasort(v) sort(v.begin(), v.end())
#define vdsort(v) sort(v.begin(), v.end(),greater<int>())
#define F first
#define S second

#define out1(x1) cout << x1 << ln
#define out2(x1,x2) cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define mz(a)   memset(a,0,sizeof(a))
#define arrin(a,n) forn(i,n) cin >> a[i];
#define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main() {
    zoom;
    ll n;
    in1(n);
    vl a(n);
    arrin(a,n);
    vasort(a);
    ll s=a[n-1];
    ll c=1;
    for(ll i=n-2;i>=0;i--){
        if (c==n-1) break;
        else{
            if (c+2<=n-1){
                c+=2;
                s+=2*a[i];
            }else if (c+1<=n-1){
                c+=1;
                s+=a[i];
            }
        }
    }
    out1(s);
    return 0;
}

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

int main(){
    while(1){
        ll n, x;
        cin >> n >> x;
        if(n == 0 && x == 0){
            break;
        }
        ll ans = 0;
        for(ll i = 1; i < min(x, n + 1); ++i){
            for(ll j = i + 1; j < min(x - i, n + 1); ++j){
                ll k = x - i - j;
                if(k <= j || k > n){ continue; }
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).OrderByDescending(x => x).ToArray();
		int ans = 0;
		for (int i = 0; i < n - 2; i++)
		{
			for (int j = i + 1; j < n - 1; j++)
			{
				if (a[i] == a[j]) continue;
				for (int k = j + 1; k < n; k++)
				{
					if (a[j] == a[k]) continue;
					if (a[i] < a[j] + a[k]) ans++;
				}
			}
		}
		Console.WriteLine(ans);
	}
}

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

struct node{
	int parent_id;
	int left_child_id;
	int right_child_id;
};

int get_root(node* b, int num);
void print_preorder(node* b, int root_id);
void print_inorder(node* b, int root_id);
void print_postorder(node* b, int root_id);

int main(){
	int n;
	scanf("%d", &n);
	node* b = (node*)calloc(n, sizeof(node));
	for(int i = 0; i < n; ++i){
		b[i].parent_id  = -1;
	}
	//input data
	for(int i = 0; i < n; ++i){
		int id;
		int left_child_id;
		int right_child_id;
		scanf("%d %d %d", &id, &left_child_id, &right_child_id);
		b[id].left_child_id  = left_child_id;
		b[id].right_child_id = right_child_id;
		if(left_child_id  != -1) b[left_child_id].parent_id  = id;
		if(right_child_id != -1) b[right_child_id].parent_id = id;
	}
	int root_id = get_root(b, n);
	printf("Preorder\n");
	print_preorder(b, root_id);
	putchar('\n');
	printf("Inorder\n");
	print_inorder(b, root_id);
	putchar('\n');
	printf("Postorder\n");
	print_postorder(b, root_id);
	putchar('\n');
	return 0;
}

void print_preorder(node* b, int root_id){
	printf(" %d", root_id);
	if(b[root_id].left_child_id  != -1) print_preorder(b, b[root_id].left_child_id);
	if(b[root_id].right_child_id != -1) print_preorder(b, b[root_id].right_child_id);
}

int get_root(node* b, int num){
	for(int i = 0; i < num; ++i){
		if(b[i].parent_id == -1) return i;
	}
	return -1;
}
void print_inorder(node* b, int root_id){
	if(b[root_id].left_child_id  != -1) print_inorder(b, b[root_id].left_child_id);
	printf(" %d", root_id);
	if(b[root_id].right_child_id != -1) print_inorder(b, b[root_id].right_child_id);
}
void print_postorder(node* b, int root_id){
	if(b[root_id].left_child_id  != -1) print_postorder(b, b[root_id].left_child_id);
	if(b[root_id].right_child_id != -1) print_postorder(b, b[root_id].right_child_id);
	printf(" %d", root_id);
}

Measured memory_bytes: 1056
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */			

void solve()
{  int a,n,m;
   cin >> n >> m;
   a=n*m;
   if(n==1 || m==1)
   {
      cout<<"1"<<endl;
      return ;
   }
   if(a%2!=0)a++;
   cout << (a/2);
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




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

int H,W;
int b = 1;

int main() {
  while(1) {
    b = 1;
    cin >> W >> H;
    if ( H == 0 && W == 0) {
      break;
    }
    for (int a = -1; a < H;) {
      ++a;
      if( a == H && b < W) {
        cout << endl;
        a = 0;
        b = b + 1;
      }else if ( a == H && b == W) {
        cout << endl << endl; // Two times new line.
        break;
      }
      cout << "#";
    }
  }
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main() {
    int N; cin >> N;
    int a,b,c,d;
    a = b = c = d = 0;
    for (int i = 0; i < N; i++)
    {
        string s; cin >> s;
        for (int j = 0; j < s.size()-1; j++)
        {
            if(s[j] == 'A' and s[j+1] == 'B') a++;
        }
        if(s[0] == 'B' and s[s.size()-1] == 'A') d++;
        else if(s[0] == 'B') c++;
        else if (s[s.size()-1] == 'A') b++;
    }

    int e = min(abs(b-c),d);
    int ans = a + min(b,c) + e + max(d-e,0);
    if(b+c>0) cout << ans << endl;
    else cout << a + max(d-1,0) << endl; 
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    int n,a,m=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        m += a - 1;
    }
    cout << m << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;

    int m = n / 2 + n % 2;

    cout << fixed << setprecision(10) << (double) m / (double) n << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
int n;
ll x;
struct node
{
    ll b,l,r;
    ll add;
    ll minn;
    ll total;
    int id;
} a[maxn+10];
int cmp(node aa,node bb)
{
    return aa.add + aa.total> bb.add + bb.total;
}
ll pre[maxn+10];
ll sum[maxn+10];
bool check(ll cnt)
{
    ll cc = cnt / x;
    ll mm = cnt % x;
    if(cc >= 1ll*n)
    {
        return true;
    }
    ll cur = sum[cc];
    ll diff = pre[n] - pre[cc];

    for(int i=1; i<=n; i++)
    {
        if(cc >= i)
        {
            if(cur - a[i].add + a[cc+1].add + a[i].l * mm >= diff - a[cc+1].total + a[i].l * a[i].b
               || cur - a[i].add + a[cc+1].add + a[i].r * mm >= diff - a[cc+1].total + a[i].r * a[i].b)
            {
                return true;
            }
        }
        else
        {
            if(cur + a[i].r*mm >= diff + (a[i].r - a[i].l) * a[i].b ||
               cur + a[i].l*mm >= diff)
            {
                return true;
            }
        }
    }
    //cout<<cnt <<" "<< cur <<"  "<< diff <<endl;
    return false;
}
int main()
{
    while(cin>>n>>x)
    {
        for(int i=1; i<=n; i++)
        {
            cin>>a[i].b>>a[i].l>>a[i].r;
            a[i].add = (x - a[i].b) * a[i].r;
            a[i].minn = (x - a[i].b) * a[i].l;
            a[i].total = a[i].b * a[i].l;
            a[i].id= i;
        }
        sort(a+1,a+1+n,cmp);
//        cout<<endl;
//        for(int i=1; i<=n; i++)
//        {
//            printf("%lld %lld %lld %lld\n",a[i].b,a[i].l,a[i].r,a[i].add);
//        }
        pre[0]=0;
        sum[0]=0;
        for(int i=1; i<=n; i++)
        {
            pre[i]=pre[i-1]+a[i].total;
            sum[i]=sum[i-1]+a[i].add;
        }

        ll ans = 0;
        ll L = 0,R = 1e10;
        while(L <= R)
        {
            ll mid = (L+R)>>1;
            if(check(mid))
            {
                ans = mid;
                R = mid - 1;
            }
            else
            {
                L = mid + 1;
            }
        }
        cout<<ans<<endl;

    }
    return 0;
}

Measured memory_bytes: 7296
S = input()
N = len(S) + 1
a = [0] * N
b = [0] * N
for i in range(0, N-1):
    if S[i] == '<':
        a[i+1] = a[i] + 1

for i in range(N-2, -1, -1):
    if S[i] == '>':
        b[i] = b[i+1] + 1

res = [max(x, y) for x, y in zip(a, b)]

print(sum(res))


Measured memory_bytes: 86092
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long ll;

int main()
{
	int k;
	scanf("%d", &k);
	int a,b;
	scanf("%d%d", &a,&b);
	int i = a;
	int ans = 0;
	while (i <= b)
	{
		if (i % k == 0)
			ans++;
		i++;
	}
	if (ans)
		printf("OK");
	else 
		printf("NG");
	return (0);
}

Measured memory_bytes: 2140
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#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 << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define memo(a,val) memset(a,val,sizeof(a))
#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	string s; cin >> s;
	if(s[0]==s[1] and s[1]==s[2] and s[0]=='R') cout << 3 << endl;
	else if((s[0]==s[1] or s[1]==s[2]) and s[1] == 'R') cout << 2 << endl;
	else if(s.find('R')!=string::npos) cout << 1 << endl;
	else cout << 0 << endl;
	
	return 0;
}

Measured memory_bytes: 3612
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
x = [[0]*2 for i in range(n)]
for i in range(n):
    x[i][0], x[i][1] = MAP()

x.sort()
tmp = -inf
ans = n
for i in range(n):
    if tmp > x[i][0] - x[i][1]:
        ans -= 1
        tmp = min(tmp, x[i][0] + x[i][1])
    else:
        tmp = x[i][0] + x[i][1]
print(ans)

Measured memory_bytes: 25460
#include<stdio.h>
#include<iostream>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string.h>
#include<functional>
#define INF 0x3f3f3f3f
using namespace std;
vector<int>q[4];
int main() {
	int n;
	long long w;
	while(~scanf("%d%lld",&n,&w)) {
		for(int j=0; j<4; j++)
			q[j].clear();
		int w1,v1;
		scanf("%d%d",&w1,&v1);
		q[0].push_back(v1);
		int x,y;
		for(int j=1; j<n; j++) {
			scanf("%d%d",&x,&y);
			x-=w1;
			q[x].push_back(y);
		}
		sort(q[0].begin(),q[0].end(),greater<int>());
		sort(q[1].begin(),q[1].end(),greater<int>());
		sort(q[2].begin(),q[2].end(),greater<int>());
		sort(q[3].begin(),q[3].end(),greater<int>());
		for(int j=0; j<4; j++)
			for(int k=1; k<q[j].size(); k++)
				q[j][k]+=q[j][k-1];
		int ans=0;
		for(int z=0; z<=q[0].size(); z++) {
			for(int e=0; e<=q[1].size(); e++) {
				for(int r=0; r<=q[2].size(); r++) {
					for(int t=0; t<=q[3].size(); t++) {
						long long sum=1LL*w1*z+1LL*(w1+1)*e+1LL*(w1+2)*r+1LL*(w1+3)*t;
						if(sum>w) continue;
						else {
							int sss=0;
							if(z!=0)sss+=q[0][z-1];
							if(e!=0)sss+=q[1][e-1];
							if(r!=0)sss+=q[2][r-1];
							if(t!=0)sss+=q[3][t-1];
							ans=max(ans,sss);
						}
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


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

int main(){
   
    int N,P;cin>>N>>P;
    int a=0,b=0;
    for(int i=0;i<N;i++){
        int c;cin>>c;
        if(c%2==0) a++;
        else b++;
    }
    long long int sum=1;
    if(b==0){
        if(P==1) cout<<0<<endl;
        else{
            for(int i=0;i<N;i++){
                sum*=2;
            }
            cout<<sum<<endl;
        }
    }
    else{
        for(int i=0;i<N-1;i++){
            sum*=2;
    }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream> 
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cmath>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

const int maxn = 100000 + 123;
int n, k;
vector<int> V[maxn];
int p[maxn];
int root;

void ReadData() {
	cin >> n;
	For(i,2,n) {
		int u, v; cin >> u >> v;
		V[u].push_back(v);
		V[v].push_back(u);
	}
	cin >> k;
	memset(p,-1,sizeof(p));
	For(i,1,k) {
		int pp, v; cin >> pp >> v;
		p[pp] = v;
		root = pp;
	}
}

void fail() {
	cout << "No" << endl;
	exit(0);
}

int stat[maxn];
void preDfs(const int u,const int prev, const int sign) {
	stat[u] = sign;
	for (int v : V[u]) if (v != prev) {
		if (p[v] != -1 && ((p[v] & 1) !=  (sign ^ 1)) ) return fail();
		preDfs(v, u, sign ^ 1);
	}
}

int upper[maxn], lower[maxn];
const int MX = 1000000;
void solveUpper(int p[], int upper[]) {
	priority_queue<pair<int,int> > qu;
	For(i,1,n) if (p[i] == -1) {
		upper[i] = MX;
		for (int j : V[i]) if (p[j] != -1) {
			upper[i] = min(upper[i], p[j] + 1);
		}
		if (upper[i] < MX) {
			qu.push(make_pair(-upper[i], i));
		}
	}

	while (!qu.empty()) {
		auto cur = qu.top(); qu.pop();
		int u = cur.second;
		if (upper[u] != -cur.first) {
			continue;
		}

		for (int v : V[u]) if (p[v] == -1) {
			int z = upper[u] + 1;
			if (z < upper[v]) {
				upper[v] = z;
				qu.push(make_pair(-upper[v], v));
			}
		}
	}
}

bool inrange(const int l, const int r, const int mid) {
	return mid >= l && mid <= r;
}
inline void dfsCal(const int u, const int prev) {
	for (int v : V[u]) if (v != prev) {
		if (p[v] == -1) {
			if (inrange(lower[v], upper[v], p[u] - 1)) {
				p[v] = p[u] - 1;
			} else p[v] = p[u] + 1;
		}
		dfsCal(v, u);
	}
}

bool was[maxn];
void bfsCal(int root) {
	queue<int> qu;
	qu.push(root);
	memset(was,false,sizeof(was));
	was[root] = true;
	while (!qu.empty()) {
		int u = qu.front(); qu.pop();
		for (int v : V[u]) if (!was[v]) {
			was[v] = true;
			if (p[v] == -1) {
				if (inrange(lower[v], upper[v], p[u] + 1)) {
					p[v] = p[u] + 1;
				} else p[v] = p[u] - 1;
			}
			qu.push(v);
		}
	}
}

void Process() {
	solveUpper(p,upper);
	For(i,1,n) if (p[i] != -1) p[i] = MX - p[i];
	solveUpper(p,lower);
	For(i,1,n) if (p[i] != -1) p[i] = MX - p[i];
	For(i,1,n) lower[i] = MX - lower[i];

	bfsCal(root);
	For(i,1,n) {
		for (int j : V[i]) {
			if (abs(p[i] - p[j]) != 1) {
				return fail();
			}
		}
	}

	cout << "Yes" << endl;
	For(i,1,n) cout << p[i] << "\n";
}

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

	//freopen("input.inp" , "r" , stdin);
	//freopen("out.out" , "w" , stdout);
	ReadData();
	Process();

	return 0;

}			

Measured memory_bytes: 9088
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
3
1
2 1
1
1 1
1
2 0
---+/
/+---test
3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0
---+/
/+---test
2
1
2 0
1
1 0
---+/
/+---test
15
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;

  long[][][] testimonies;
  testimonies.length = N;

  foreach (ref tests; testimonies) {
    const A = readln.chomp.to!long;
    tests.length = A;
    foreach (ref t; tests) {
      t.length = 2;
      readf(" %d %d ", &t[0], &t[1]);
      --t[0];
    }
  }

  long ans;
SKIP: foreach (ushort honest; 0..2.pow(N).to!ushort) {
    foreach (i; 0..N) {
      if ((honest >> i & 1) == 0) continue;
      foreach (test; testimonies[i]) {
        if ((honest >> test[0] & 1) != test[1]) continue SKIP;
      }
    }

    long cnt;
    foreach (i; 0..N) {
      if (honest >> i & 1) ++cnt;
    }
    ans.amax(cnt);
  }
  ans.writeln;
}


Measured memory_bytes: 340
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int table[256];

void init_table(){
  int idx = 0;
  for(int i=0;i<=9;i++){
    table[ i + '0'] = idx;
    idx++;
  }
  for(int i='A';i<='Z';i++){
    table[i] = idx;
    idx++;
  }
  for(int i='a';i<='z';i++){
    table[i] = idx;
    idx++;
  }
}

int fast_pow(int x, int n){
  int res = 1;
  while(n > 0) {
    if (n & 1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int conv(int type,const string& num){
  int res = 0;
  for(int i=num.size()-1,j=0;i>=0;i--,j++){
    res += table[num[i]] * fast_pow(type,j);
  }
  return res;
}

int main(){
  init_table();

  int total_initial_subsets;
  while(~scanf("%d",&total_initial_subsets)){
    int nim = 0;
    for(int subset_idx=0;subset_idx < total_initial_subsets;subset_idx++){
      int type;
      string num;
      cin >> type >> num;

      int pile = conv(type,num);
      
      nim ^= pile;
    }
    printf("%s\n",nim == 0 ? "lose" : "win");
  }
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <string.h>
#include <queue>
#include <utility>
#include <set>
#define lli long long int
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

int main() 
{
	fio;
	lli n,m;
	cin>>n>>m;
	lli arr[n];
	for (int i=0;i<n;i++)
	cin>>arr[i];
	lli dp[n],k,mini;
    dp[0]=0;
    for (int i=1;i<n;i++)
    {
        k=1;mini=1e9;
        while (k<=i&&k<=m)
        {
            mini=min(dp[i-k]+abs(arr[i]-arr[i-k]),mini);
            k++;
        }
        dp[i]=mini;
    }
    cout<<dp[n-1];
	return 0;
}	

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

int main(void) {
    while(1) {
        int a, b, i, j;
        cin >> a;
        cin >> b;

        if(a == 0 || b == 0) {
            break;
        }

        for(i=0; i<a; i++) {
            for(j=0; j< b; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}





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

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

	int ma = 0;
	int ans = 1;
	for( int i = 1; i <= N; i++ ) {
		int j = i;
		int k = 0;
		while( (j % 2) == 0 ) {
			k++;
			if( k > ma ) {
				ma = k;
				ans = i;
			}
			j /= 2;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
/*
  no pain, no gain
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define pii pair<int, int>
#define all(s) s.begin(), s.end()
#define prev myrza4321
#define y1 myrza1234
#define OK puts("OK")
using namespace std;

const int N = (int)1e5 + 5;
const int INF = 0x3f3f3f3f;

main() {
  int x, a;
  cin >> x >> a;
  if (x < a) {
    puts("0");
  } else {
    puts("10");
  }
}


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


int t;
int k[4][13];
int main(){
  cin>>t;
  int a;
  char b;
  
  for(int i;i<t;i++){
    cin>>b>>a;
  if(b=='S'){k[0][a-1]=1;}
  if(b=='H'){k[1][a-1]=1;}
  if(b=='C'){k[2][a-1]=1;}
  if(b=='D'){k[3][a-1]=1;}
  }
    for(int ushi;ushi<13;ushi++){
      if(k[0][ushi]==0){
	cout<<"S "<<ushi+1<<endl;}
    }
     for(int usha;usha<13;usha++){
      if(k[1][usha]==0){
	cout<<"H "<<usha+1<<endl;}
     }
      for(int ushu;ushu<13;ushu++){
      if(k[2][ushu]==0){
	cout<<"C "<<ushu+1<<endl;}
      }
       for(int ushe;ushe<13;ushe++){
	 if(k[3][ushe]==0){
	cout<<"D "<<ushe+1<<endl;}
       }
}

Measured memory_bytes: 1160
import math
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]

ans=0
for i in range(0,n):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=abs(X[i][k]-X[j][k])**2
    if math.sqrt(dis)==int(math.sqrt(dis)):
      ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

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

    string ans = "NO";
    repi(i, 1, B + 1) {
        if((A * i) % B == C) {
            ans = "YES";
            break;
        }
    }

    cout << ans << endl;
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int counter = 0;
  for(int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
      for(int k = 0; k <= C; k++){
        if(500 * i + 100 * j + 50 * k == X) counter++;
      }
    }
  }
  cout << counter << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef tuple<int, int,int> T;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int mod = 1000000007;
const int INF = 1e9;

const int M = 51;
char c[M][M];
char d[M][M];
int w, h;
bool f[M][M];

char dfs(int y, int x){
	if (c[y][x] != '.')return c[y][x];
	if (d[y][x])return 0;
	f[y][x] = true;

	char ret = -1;
	rep(i, 4){
		int tx = x + dx[i], ty = y + dy[i];
		if (cheak(tx, ty, w, h) && !f[ty][tx]){
			char t = dfs(ty, tx);
			if (ret == -1 || t == ret){
				ret = t;
			}
			else
			if(t != -1){
				ret = 0;
			}
		}
	}
	return ret;
}

void sdfs(int y, int x, char n){
	if (!(n == 'B' || n == 'W'))return;
	if (c[y][x] != '.')return;
	f[y][x] = false;
	d[y][x] = n;

	rep(i, 4){
		int tx = x + dx[i], ty = y + dy[i];
		if (cheak(tx, ty, w, h) && f[ty][tx]){
			sdfs(ty, tx, n);
		}
	}
}

int main()
{

	while (cin >> w >> h && w){
		clr(d);
		rep(y, h)rep(x, w){
			cin >> c[y][x];
		}

		rep(y, h)rep(x, w){
			clr(f);
			sdfs(y, x, dfs(y, x));
		}

		int ba = 0, wa = 0;
		rep(y, h)rep(x, w){
			if (c[y][x] == '.'){
				if (d[y][x] == 'B')ba++;
				if (d[y][x] == 'W')wa++;
			}
		}

		cout << ba << " " << wa << endl;
	}
	return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, mx;
string s;
int main() {
  cin >> n >> m >> s;
  for(int i = 1; i < n - 1; ++i)
    if(s[i] == 'R' && s[i + 1] == 'R')
      ++mx;
    else if(s[i] == 'L' && s[i - 1] == 'L')
      ++mx;  
  if(s[0] == 'R' && s[1] == 'R')
      ++mx;
  if(s[n - 1] == 'L' && s[n - 2] == 'L')
      ++mx;
  cout << min(n - 1, mx + m * 2) << endl;
}

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

int main(){
    int count = 0; string W,T;
    cin >> W;
    transform(W.begin(),W.end(), W.begin(),::tolower);
    while(1){
        cin >> T;
        if(T.find("END_OF_TEXT") != string::npos) break;
        transform(T.begin(),T.end(), T.begin(),::tolower);
        if(T == W) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int n;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 5e15;
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(auto &a : A) cin >> a;
    for(auto &a : A) a *= N;
    ll sum = 0;
    for(ll i = 0; i < N; i++) sum += A[i];
    sum /= N;
    ll dis = INF, ans = 0;
    for(ll i = 0; i < N; i++){
        if(dis > abs(A[i] - sum)){
            dis = abs(A[i] - sum);
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
Q = int(input())


cnt = defaultdict(int)
s = 0
for a in A:
  cnt[a] += 1
  s += a
 
for i in range(Q):
  b,c = map(int,input().split())
  s = s - b*cnt[b] + c*cnt[b]  
  cnt[c] += cnt[b]
  cnt[b] = 0
  #print(cnt)
  print(s)

Measured memory_bytes: 24008
#include<stdio.h>

int main(void)
{
	int H, W, i, j;

	for(;;){
		scanf("%d %d", &H, &W);
		if(H==0 && W==0) break;

		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2108
//ABC116-C
fun main(args: Array<String>) {
    val N = nextInt()
    val H = listOfInt().toIntArray()
    var ans = 0
    while (H.sum() > 0) {
        var l = 0
        while (l < N && H[l] == 0) l += 1
        var r = l
        while (r < N && H[r] > 0) r += 1
        var min = Int.MAX_VALUE
        for (n in l until r) if (H[n] < min) min = H[n]
        for (n in l until r) H[n] -= min
        ans += min
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

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

#define INF 1E18



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

    vector<int> a(n+1,-1);
    rep2(i,1,n+1) cin>>a[i];
    vector<int> check(n+1,-1);
    vector<int> root;

    int position = 1;
    int count1 = 0;
    while(check[position] == -1){
        check[position] = count1;
        root.push_back(position);
        count1++;
        position = a[position];
    }
    int period = root.size() - check[position];
    int l = check[position];

    if(k<l){
        cout<<root[k]<<endl;
    }else{
        k = (k-l)%period;
        cout<<root[l+k]<<endl;
    }



    return 0;
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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;
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N,K;
intvec V;
int ans=0;

void input() {
	cin>>N>>K;
	init(V,N);
}

void solve() {
	for(int l=0; l<N; l++) for(int r=N; N-(r-l)<=K && l<=r; r--) {
		intvec tmp=intvec(V.begin(),V.begin()+l);
		copy(V.begin()+r,V.end(),back_inserter(tmp));
		sort(all(tmp));
		int k=K-N+(r-l), tmpans=0;
		for(int i=0; i<tmp.size(); i++) {
			if(tmp[i]<0 && k>0) {
				k--;
				continue;
			}
			tmpans+=tmp[i];
		}
		chmax(ans,tmpans);
	}
	cout<<ans<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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

Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
int main()
 
{
char a,b;
cin>>a>>b;
 
if(a=='H'&&b=='H'){
    cout<<"H"<<endl;
}
else if(a=='D'&&b=='H'){
    cout<<"D"<<endl;
}
 
else if(a=='H'&&b=='D'){
    cout<<"D"<<endl;
}
 
else if(a=='D'&&b=='D'){
    cout<<"H"<<endl;
}
 
 
return 0;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
        return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    using Int =llong;
    Int n;
    cin>>n;
    vector<Int> a(n);
    for(Int i=0;i<n;i++) cin>>a[i];
    a.emplace(a.begin(),0);
    a.emplace_back(0);
    Int ans=0;
    for(Int i=1;i<(Int)a.size();i++)
        ans+=abs(a[i]-a[i-1]);
    for(Int i=1;i<=n;i++){
        cout<<ans-(abs(a[i]-a[i-1])+abs(a[i]-a[i+1]))+abs(a[i+1]-a[i-1])<<endl;
    }
    return 0;
}

Measured memory_bytes: 2032