akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int n; cin >> n;
   V<int> a(n);
   REP(i, n) cin >> a[i];

   REP(i, n) {
      if (a[i] > i) {
         cout << -1 << endl;
         return 0;
      }
   }

   int total = 0;
   priority_queue<int> que;
   que.push(-n+1);
   RREP(i, n) {
      if (que.top() + i > a[i]) {
         cout << -1 << endl;
         return 0;
      } else if (que.top() + i < a[i]) {
         total += a[i];
         que.push(a[i] - i);
      }
   }
   cout << total << endl;

   return 0;
}


Measured memory_bytes: 3956
#define MAX 2000001
#define VMAX 10001
#include <stdio.h>


int A[MAX], C[VMAX], B[MAX];

int main()//被排序的数至少有一个，所以B数组中的数统一向后移动一位 
{
	int n, i, j;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d", &A[i]);
	}
	for(i=0;i<n;i++)
	{
		C[A[i]]++;
	}
	for(i=1;i<=VMAX;i++)
	{
		C[i]=C[i]+C[i-1];
	}
	for(i=0;i<n;i++)
	{
		B[C[A[i]]]=A[i];
		C[A[i]]--;
	}
	for(i=1;i<=n;i++)
	{
		if(i>1)
		{
			printf(" ");
		}
		printf("%d", B[i]);
	}
	printf("\n");
	return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

int dp[110][110];
int S[110][110];

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

  int H, W;
  cin >> H >> W;
  
  string s;
  rep(i, H){
    cin >> s;
    rep(j, W){
      if(s[j] == '#'){
        S[i][j] = 1;
      }else{
        S[i][j] = 0;
      }
    }
  }

  rep(i, H){
    rep(j, W){
      dp[i][j] = 1000;
    }
  }

  if(S[0][0]==1){
    dp[0][0] = 1;
  }else{
    dp[0][0] = 0;
  }

  rep(i, H){
    rep(j, W){

      if(j < W-1){
        if(S[i][j+1]==1){
          if(S[i][j] == 1){
            chmin(dp[i][j+1], dp[i][j]);
          }else{
            chmin(dp[i][j+1], dp[i][j]+1);
          }
        }else{
          chmin(dp[i][j+1], dp[i][j]);
        }
      }

      if(i < H-1){
        if(S[i+1][j]==1){
          if(S[i][j] == 1){
            chmin(dp[i+1][j], dp[i][j]);
          }else{
            chmin(dp[i+1][j], dp[i][j]+1);
          }
        }else{
          chmin(dp[i+1][j], dp[i][j]);
        }
      }
    }
  }

  cout << dp[H-1][W-1] << endl;

  return 0;
}


Measured memory_bytes: 384
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 600000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000 大きいとワ―シャルフロイドでオーバーフローを起こす
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {

	string s;
	int n;
	cin >> n;
	int count[10] = {};
	int now = -1;
	char c;
	
	FOR(k, 1, n) {
		FOR(j, 0, 9) {
			count[j] = 0;
		}
		now = -1;

		cin >> s;

		FOR(i, 0, s.size() - 1) {
			if (s[i] == '0') {
				count[now]--;
				switch (now) {
				case 1:
					switch (count[now] % 5) {
					case 0:
						cout << ".";
						break;
					case 1:
						cout << ",";
						break;
					case 2:
						cout << "!";
						break;
					case 3:
						cout << "?";
						break;
					case 4:
						cout << " ";
						break;
					}
					break;
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
					c = 'a' + 3 * (now - 2) + (count[now] % 3);
					cout << c;
					break;
				case 7:
					c = 'p' + (count[now] % 4);
					cout << c;
					break;
				case 8:
					c = 't' + (count[now] % 3);
					cout << c;
					break;
				case 9:
					c = 'w' + (count[now] % 4);
					cout << c;
					break;
				}

				FOR(j, 0, 9) {
					count[j] = 0;
				}
				now = 0;
			}
			else {
				count[s[i] - '0']++;
				now = s[i] - '0';
			}

		}
		cout << endl;
	}

	
	

	return 0;
}


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

bool p[1000100];

void erato(){
	fill(p, p+1000100, true);

	p[0] = p[1] = false;

	for(int i=2; i*i < 1000100; i++){
		if(!p[i]) continue;
		for(int j= i+i; j < 1000100; j += i){
			p[j] = false;
		}
	}
}

int main(){
	erato();
	int a, d, n;

	while(cin >> a >> d >> n, a || d || n){
		while(true){
			if(p[a]) n--;
			if(n == 0) break;
			a += d;
		}

		cout << a << endl;
	}
}

Measured memory_bytes: 2136
#include <iostream>
#include<string>
using namespace std;
int main(void){
    // Here your code !
    int x,y;
    cin>>x>>y;
    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
            x=100;}
    if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
            y=100;}
    if(x==4||x==6||x==9||x==11){
        x=200;}
    if(y==4||y==6||y==9||y==11){
        y=200;}

    if(x==y){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    return 0;
}


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

const int maxn=1005;
int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    string s;
    while(cin>>n){
        set<string>vis;
        string temp;
        cin>>temp;
        vis.insert(temp);
        bool flag=1;
        for(int i=1;i<n;i++){
            cin>>s;
            if(s[0]!=temp[temp.size()-1]){
                flag=0;
            }
            if(vis.find(s)!=vis.end()){
                flag=0;
            }
            temp=s;
            vis.insert(s);
        }
        if(flag) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

template <class T>
T add(T x, T y) {
	return x + y;
}

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

	int N, K, R, S, P;

	string T;

	cin >> N >> K >> R >> S >> P >> T;

	for (int i = K; i < N; i++) {
		if (T[i] == T[i - K]) {
			T[i] = 'a';
		}
	}

	int sum = 0;
	for (int i = 0; i < N; i++) {
		switch (T[i]) {
		case 'r':
			sum += P;
			break;
		case 's':
			sum += R;
			break;
		case 'p':
			sum += S;
			break;

		default:
			break;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

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

        int x = scan.nextInt();
        scan.close();
        if (x == 3 || x == 5 || x == 7)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

Measured memory_bytes: 23764
local n,m,q=io.read("n","n","n")
local a,b,c,d={},{},{},{}
for i=1,q do
    a[i],b[i],c[i],d[i]=io.read("n","n","n","n")
end

local t={}
for i=1,10 do
    t[i]={}
end
for i=1,m do
    table.insert(t[1],{i})
end

for i=1,n-1 do
    for j,_ in pairs(t[i]) do
        local x=t[i][j]
        local p=x[#x]
        for k=p,m do
            local U={}
            for l=1,#x do
                U[l]=x[l]
            end
            table.insert(U,k)
            table.insert(t[i+1],U)
        end
    end
end

local answer=0
for _,T in pairs(t[n]) do
    local total=0
    for i=1,q do
        if T[b[i]]-T[a[i]]==c[i] then
            total=total+d[i]
        end
    end
    answer=math.max(answer,total)
end
print(answer)

Measured memory_bytes: 61460
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  


using namespace std;

typedef long long int ll;

const int precision = 16;
const int modulo =  1000000007; // 10^9 + 7
using ll = long long;
const double EPS = 1e-9;

// ll recV1(int ind, const vector<int> & stones) {
// 	if(ind >= (int)stones.size() - 1) return 0;

// 	int cost1 = ind + 1 < (int)stones.size() ? abs(stones[ind + 1] - stones[ind]) : INT_MAX;
// 	int cost2 = ind + 2 < (int) stones.size() ? abs(stones[ind + 2] - stones[ind]) : INT_MAX;

// 	//cout << ind << " cost1:" << cost1 << " cost2:" << cost2 <<endl;
// 	auto oneJump = recV1(ind + 1, stones) + cost1;
// 	auto twoJumps = recV1(ind + 2, stones) + cost2;
// 	//	cout << ind << " oneJump:" << oneJump <<  " twoJumps:" << twoJumps <<endl;
// 	return min(oneJump, twoJumps);
// }


ll recV2(int ind, const vector<int> & stones, unordered_map<int, ll> & memo) {
	if(ind >= (int)stones.size() - 1) return 0;
	if(memo.count(ind)) return memo[ind];

	int cost1 = ind + 1 < (int)stones.size() ? abs(stones[ind + 1] - stones[ind]) : INT_MAX;
	int cost2 = ind + 2 < (int) stones.size() ? abs(stones[ind + 2] - stones[ind]) : INT_MAX;

	//cout << ind << " cost1:" << cost1 << " cost2:" << cost2 <<endl;
	auto oneJump = recV2(ind + 1, stones, memo) + cost1;
	auto twoJumps = recV2(ind + 2, stones, memo) + cost2;
	//	cout << ind << " oneJump:" << oneJump <<  " twoJumps:" << twoJumps <<endl;
	memo[ind]  = min(oneJump, twoJumps);
	return memo[ind];
}


void solveFrog1() 
{
	int n; cin >> n;
	vector<int> stones(n);
	for(auto &it : stones) {
		cin >> it;
	}
	
	//cout <<  recV1(0, stones) <<endl; 
	unordered_map<int, ll> memo;
	cout <<  recV2(0, stones, memo) <<endl; 
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(precision);
	cout.setf(ios_base::fixed);

	solveFrog1();
	return 0;
}


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

int main() {
    int n;
    string s;
    cin>>n>>s;
    long long int r=0;
    long long int g=0;
    long long int b=0;
    rep(i,n){
        if(s[i]=='R') r++;
        if(s[i]=='G')g++;
        if(s[i]=='B')b++;
    }
    long long int ans =r*g*b;
    long long int ans2=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j]) continue;
            int k=j*2-i;
            if(k>=n||s[k]==s[i]||s[k]==s[j]) continue;
            ans2++;
            
        }
    }
    cout<<ans-ans2<<endl;



}

Measured memory_bytes: 3636
#include<stdio.h>
#include<queue>
using namespace std;
int head[131072],last[262144],to[262144],cnt=0;
int deg[131072];
void add(int u,int v)
{
	cnt++;
	last[cnt]=head[u];
	head[u]=cnt;
	to[cnt]=v;
	deg[u]++;
}
char s[131072];
queue<int> q;
int tp[131072];
int dis[131072];
void dfs(int u,int f,int d)
{
	d+=tp[u];
	dis[u]=d;
	for(int i=head[u];i;i=last[i])
	{
		int v=to[i];
		if(v==f)
		{
			continue;
		}
		if(deg[v]==0)
		{
			continue;
		}
		dfs(v,u,d);
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	scanf("%s",s+1);
	int numw=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='W')
		{
			numw++;
		}
	}
	if(numw<=1)
	{
		printf("%d\n",numw);
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='B'&&deg[i]==1)
		{
			q.push(i);
		}
	}
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		deg[u]=0;
		for(int i=head[u];i;i=last[i])
		{
			int v=to[i];
			if(deg[v])
			{
				deg[v]--;
				if(deg[v]==1&&s[v]=='B')
				{
					q.push(v);
				}
			}
		}
	}
	int ans=-2;
	for(int i=1;i<=n;i++)
	{
		if(deg[i])
		{
			ans+=2;
			tp[i]=((deg[i]+(s[i]=='W'))&1);
			ans+=tp[i];
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(deg[i]==1)
		{
			dfs(i,0,0);
			break;
		}
	}
	int u=0,d=-1;
	for(int i=1;i<=n;i++)
	{
		if(deg[i]==1)
		{
			if(dis[i]>d)
			{
				u=i;
				d=dis[i];
			}
		}
	}
	dfs(u,0,0);
	u=0,d=-1;
	for(int i=1;i<=n;i++)
	{
		if(deg[i]==1)
		{
			if(dis[i]>d)
			{
				u=i;
				d=dis[i];
			}
		}
	}
	printf("%d\n",ans-d-d);
	return 0;
}

Measured memory_bytes: 8576
using System;

public class a {
 static void Main(){
   var s = Console.ReadLine();
   var t = Console.ReadLine();
   int count = 0;
for(int i=0; i< 3;i++){
    if(s[i]==t[i]){
      count++;
    }
   }
   Console.WriteLine(count);
   
 }
}

Measured memory_bytes: 25912
import java.util.*;

public class Main {

    static int NOT_FOUND = 99999999;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] sArr = new int[n];
        for (int i = 0; i < n; i++) {
            sArr[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        int[] tArr = new int[q];
        int count = 0;
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            tArr[i] = x;
            if (linearSearch(sArr, x) != NOT_FOUND) count++;
        }
        System.out.println(count);
    }

    public static int linearSearch(int[] arr, int key) {
        for (int i = 0; i < arr.length; i++) {
            if (key == arr[i]) {
                return i;
            }
        }
        return NOT_FOUND;
    }
}



Measured memory_bytes: 40300
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int x,y;
  cin>>x>>y;
  
  int ans=0;
  if(x<=3){
    ans+=(4-x)*100000;}
  if(y<=3){
    ans+=(4-y)*100000;}
  if(x==1 && y==1){
    ans+=400000;}
  
  cout<<ans<<endl;
 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MOD = 1000000007;

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

  long long sum = 0, res = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    res = (res + sum * a) % MOD;
    sum = (sum + a) % MOD;
  }

  cout << res << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
 
using namespace std;

int n;
 
int main() {
  fast_io;

  cin >> n;

  cout << fixed << setprecision(20) << (double)(n * n * n) / 27 << endl;
 
  return 0;
}

Measured memory_bytes: 256
program aaa;
type mm=record s:string; v:longint; end;
var
  a:array[1..300]of mm;
  ans,now,i,j,n,m:longint;
  procedure qsort(l,r:longint);
  var i,j:longint; k:string;   t:mm;
  begin
    i:=l; j:=r; k:=a[(i+j)div 2].s;
    repeat
    while a[i].s<k do inc(i);
    while a[j].s>k do dec(j);
    if i<=j then begin t:=a[i];a[i]:=a[j];a[j]:=t; inc(i); dec(j); end;
    until i>j;
    if i<r then qsort(i,r);
    if j>l then qsort(l,j);
  end;
begin
  readln(n);
  for i:=1 to n do
  begin
    readln(a[i].s);
    a[i].v:=1;
  end;
  readln(m);
  for i:=1 to m do
  begin
    readln(a[n+i].s);
    a[n+i].v:=-1;
  end;
  qsort(1,n+m);
  ans:=0;
  now:=a[1].v;
  for i:=2 to n+m do
    if (a[i].s=a[i-1].s) then now:=now+a[i].v
       else
       begin
       if now>ans then ans:=now;
       now:=a[i].v;
       end;
  if now>ans then ans:=now;
  writeln(ans);
  readln;
  readln;
end.  

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

template<typename group>
struct fenwick_tree {
    using G = group;
    using T = typename group::value_type;

    size_t _size;
    std::vector<T> data;

    fenwick_tree(size_t n = 0) : _size(n), data(n+1, G::id()) { }

    int size() const { return size; }
    
    T sum(int r) const {
        T s = G::id();
        for(r=r-1; r>=0; r=(r&(r+1))-1) {
            s = G::op(data[r], s);
        }
        return s;
    }

    T sum(int l, int r) const {
        return G::op(G::inv(sum(l)), sum(r));
    }

    void add(int i, const T& x) {
        for(;i<=_size; i|=i+1) {
            data[i] = G::op(data[i], x);
        }
    }

    void set(int i, const T& x) {
        add(i, G::op(G::inv(*this[i]), x));
    }

    T operator[](int i) const {
        return sum(i, i+1);
    }


};

struct add_group {
    using value_type = int;
    static constexpr value_type id() { return 0; }
    static constexpr value_type op(const value_type& lhs, const value_type& rhs) { return lhs + rhs; }
    static constexpr value_type inv(const value_type& o) { return -o; }
};

int main() {
    int n, q;
    cin >> n >> q;
    fenwick_tree<add_group> bit(n);
    while(q--) {
        int c, x, y;
        cin >> c >> x >> y;
        if(c) {
            cout << bit.sum(x, y+1) << endl;
        } else {
            bit.add(x, y);
        }
    }
    return 0;
}


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

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        int H = cin.nextInt();
        int W = cin.nextInt();

        string[] A = new string[H];
        for (int i = 0; i < H; i++)
        {
            A[i] = cin.next();
        }

        int h = 0;
        int w = 0;

        for (int t = 1; t <= H + W - 1; t++)
        {
            char now = A[h][w];
            if (A[h + 1][w] == '#' && A[h][w + 1] == '#')
            {
                Console.WriteLine("Impossible");
                return;
            }
            if (A[h + 1][w] == '#')
            {
                for (int j = w + 1; j < W; j++)
                {
                    if (A[h][j] == '#')
                    {
                        Console.WriteLine("Impossible ");
                        return;
                    }
                }
                h++;
                if (h == H - 1)
                {
                    Console.WriteLine("Possible");
                    return;
                }
            }

            else if (A[h][w + 1] == '#')
            {
                for (int i = h + 1; i < H; i++)
                {
                    if (A[i][w] == '#')
                    {
                        Console.WriteLine("Impossible");
                        return;
                    }
                }
                w++;
                if (w == W - 1)
                {
                    Console.WriteLine("Possible");
                    return;
                }
            }
        }
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 2776
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int w,h,n;
  cin >> w >> h >> n;
  vector<int>x(n);
  vector<int>y(n);
  vector<int>a(n);
  rep(i,n) cin >> x.at(i) >> y.at(i) >> a.at(i);
  int num = w * h;
  int count = 0;
  vector<vector<int>> data(w, vector<int>(h));//int型の2次元配列(3×4要素の)の宣言  
  rep(i,n){
    if(a.at(i) == 1 ){
      for(int j = 0;j<x.at(i);j++){
        for(int k=0;k<h;k++){
          data.at(j).at(k)++;
        }
      }
    }
    else if(a.at(i)==2){
      for(int j = x.at(i);j<w;j++){
        for(int k=0;k<h;k++){
          data.at(j).at(k)++;
        }
      }
    }
    else if(a.at(i)==3){
      for(int j = 0;j<w;j++){
        for(int k=0;k<y.at(i);k++){
          data.at(j).at(k)++;
        }
      }
    }
    else{
      for(int j = 0;j<w;j++){
        for(int k=y.at(i);k<h;k++){
          data.at(j).at(k)++;
        }
      }
    }
  }//repend
  for(int i=0;i<w;i++){
    for(int j=0;j<h;j++){
      if(data.at(i).at(j) >=1){
        count ++;
//        cout<<data.at(i).at(j);
      }
//      else cout<<"0";
//      if(data.at(i).at(j) >= 1 )count++;
    }
//    cout << endl;
  }
  cout << num-count << endl;
}

Measured memory_bytes: 256
MAX = 2*10**5+1
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

dp = []*(n+1)
l = [-1]*MAX
dp[n] = -1
(n-1).downto(0) do |i|
  v = a[i]
  if l[v] == -1
    dp[i] = i
  else
    dp[i] = dp[l[v]+1]
  end
  l[v] = i
end

s = dp[0]
period = [-1]
while s != -1
  period << s
  s = dp[l[a[s]]+1]
end

t = period[k % period.length]
ans = []
pos = [-1]*MAX

exit if t == -1

t.upto(n-1) do |i|
  v = a[i]
  if pos[v] != -1
    (ans.length-pos[v]).times do
      pos[ans[-1]] = -1
      ans.pop
    end
  else
    pos[v] = ans.length
    ans << v
  end
end

puts ans.join(" ")

Measured memory_bytes: 29584
#coding:utf-8

def main():
    n, m = map(int, input().split())
    cases = []
    for _ in range(m):
        cases.append(list(map(int, input().split())))
    
    start = 10 ** (n-1)
    if n == 1:
        start = 0
    for i in range(start, 10 ** n):
        strnum = str(i)
        for case in cases:
            if case[1] != int(strnum[case[0] - 1]):
                break
        else:
            print(strnum)
            return
    else:
        print(-1)

if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b;
	cin>>a>>b;
	if(a*b<=0){cout<<"Zero"<<endl;return 0;}
	if((a>0&&b>0)||(b-a)%2==1){cout<<"Positive"<<endl;return 0;}
	cout<<"Negative"<<endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
s = []
out_list = []
for i in range(H):
    s.append(list(input()))

for i in range(H):
    for j in range(W):
        c = 0
        #「#」かどうか
        if s[i][j] == '#':
            continue
        #左上
        if 0 < i and 0 < j and s[i-1][j-1] == '#':
            c += 1
        #中上
        if 0 < i and s[i-1][j] == '#':
            c += 1
        #右上
        if 0 < i and j < W-1 and s[i-1][j+1] == '#':
            c += 1
        #左横
        if  0 < j and s[i][j-1] == '#':
            c += 1
        #右横
        if j < W-1 and s[i][j+1] == '#':
            c += 1
        #左下
        if  0 < j and i < H-1 and s[i+1][j-1] == '#':
            c += 1
        #中下
        if i < H-1 and s[i+1][j] == '#':
            c += 1
        #右下
        if i < H-1 and j < W-1 and s[i+1][j+1] == '#':
            c += 1
        s[i][j] = str(c)
for i in range(H):
    print(''.join(s[i]))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h[211111];
int main()
{
    ios::sync_with_stdio(false);
    int n,k;
    while(cin>>n>>k)
    {
        for(int i=1;i<=n;i++)
        {
            cin>>h[i];
        }
        sort(h+1,h+n+1);
        ll sum=0;
        for(int i=1;i<=n-k;i++)
            sum+=h[i];
        cout<<sum<<endl;
    }
    return 0;
}


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

const int MAXN=5e5+5;

int n;

char s[MAXN];
int f[MAXN],g[MAXN];

int main()
{
	int i;
	scanf("%d%s",&n,s+1);
	for(i=1;i<=n;i++)
		if(s[i]=='0') g[i]=i;
		else g[i]=g[i-1];
	for(i=3;i<=n;i++)
	{
		f[i]=f[i-1];
		if(s[i]=='0') continue;
		if(s[i-2]=='1'&&s[i-1]=='0')
		{
			f[i]=max(f[i],f[g[i-2]]+(i-2)-g[i-2]);
			f[i]=max(f[i],f[g[i-2]+1]+(i-2)-(g[i-2]+1));
		}else if(g[i]>1) if(s[g[i]-1]=='1')
			f[i]=max(f[i],f[g[i]-2]+i-g[i]);
	}
	printf("%d\n",f[n]);
	return 0;
}


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

int digits(long long x) {
    int ret = 0;
    while (x > 0) {
        ret++;
        x /= 10;
    }
    return ret;
}

int main() {
    long long n;
    cin >> n;
    int ans = 100000;
    for (long long a = 1; a <= sqrt(n); a++) {
        if (n % a != 0) {
            continue;
        }
        long long b = n / a;
        int f = max(digits(a), digits(b));
        ans = min(ans, f);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static int Solve(Scanner scan) {
        int A = scan.NextInt(), B = scan.NextInt();
        var max = 101 * 10 - 1;
        var min = B * 10;
        for (int i = min; i < max; i++) {
            if (Math.Floor(i * 0.08) == A && Math.Floor(i * 0.1) == B) return i;
        }
        return -1;
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
}

Measured memory_bytes: 27536
from collections import deque


n, k = map(int, input().split())
s = input()

tmp = deque()
cnt = 1
s += '-'
for i in range(n):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1

for i in range(k):
    if len(tmp) == 1:
        break
    elif len(tmp) == 2:
        tmp = [tmp[0] + tmp[1]]
    else:
        hoge = tmp[0] + tmp[1] + tmp[2]
        tmp.popleft()
        tmp.popleft()
        tmp.popleft()
        tmp.appendleft(hoge)

if len(tmp) == 1:
    print(tmp[0] - 1)
else:
    total = 0
    for j in tmp:
        if j > 1:
            total += j - 1
    print(total)


Measured memory_bytes: 4212
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        Set<Long> tmp = new HashSet<>();
        Integer n = sc.nextInt();
        for(int i=0;i<n;i++){
            tmp.add(sc.nextLong());
        }
        if(tmp.size()<n){
            System.out.println("NO");
        }
        else{
            System.out.println("YES");
        }
    }
}


Measured memory_bytes: 102392
// https://cses.fi/problemset/task/1734/
#include <bits/stdc++.h>

using namespace std;
using iii = tuple<int, int, int>;
using mii = map<int, int>;
using vi = vector<int>;
using viii = vector<iii>;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q, a, b;
  cin >> n >> q;
  vi x(n);
  mii m;
  for (int i = 0; i < n; i++) {
    int y;
    cin >> y;
    if (m.count(y)) x[i] = m[y];
    else x[i] = m.size(), m[y] = x[i];
  }
  viii y(q);
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    y[i] = {a-1, b, i};
  }
  int k = sqrt(n);
  sort(y.begin(), y.end(), [&](iii x, iii y) -> bool {
    int a1, b1, i1, a2, b2, i2;
    tie(a1, b1, i1) = x;
    tie(a2, b2, i2) = y;
    int a1q = a1/k, a2q = a2/k;
    if (a1q < a2q) return true;
    if (a1q > a2q) return false;
    return b1 < b2;
  });
  vi res(q);
  vi count(m.size());
  int l = 0, r = 0, ans = 0;
  for (iii z : y) {
    int i;
    tie(a, b, i) = z;
    while (r < b) if (++count[x[r++]] == 1) ans++;
    while (r > b) if (--count[x[--r]] == 0) ans--;
    while (l < a) if (--count[x[l++]] == 0) ans--;
    while (l > a) if (++count[x[--l]] == 1) ans++;
    res[i] = ans;
  }
  for (int z : res) cout << z << '\n';
}

Measured memory_bytes: 38904
#include <iostream>
using namespace std;
int main(void){
    int Ai,Am,As,Ae,Bi,Bm,Bs,Be;
    cin>>Ai>>Am>>As>>Ae>>Bi>>Bm>>Bs>>Be;
    cout<<(Ai+Am+As+Ae>Bi+Bm+Bs+Be?Ai+Am+As+Ae:Bi+Bm+Bs+Be)<<endl;
}

Measured memory_bytes: 3072
a, b, c, x, y = map(int, input().split())
if a + b <= c * 2:
    print(a * x + b * y)
else:
    if x <= y:
        print(c * min(x, y) * 2 + abs(x - y) * min(b, c * 2))
    else:
        print(c * min(x, y) * 2 + abs(x - y) * min(a, c * 2))


Measured memory_bytes: 3060
#!/usr/bin/env python
s = raw_input()
array_num = [ int(each_num) for each_num in s.split()]
first_area = array_num[0] * array_num[1]
second_area = array_num[2] * array_num[3] 
if first_area > second_area:
	print(first_area)
elif first_area < second_area:
	print(second_area)
else:
	print(first_area)
   

Measured memory_bytes: 2568
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"case #" << x << ": " << endl
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-15;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vector<ll> x(n);
	rep(i, n)	cin >> x[i];
	int l;	cin >> l;
	vector<vint> to(n, vint(20));
	rep(i, n)	to[i][0] = i;
	int tox = 0;
	while (tox + 1 < n && x[tox + 1] - x[0] <= l)	tox++;
	to[0][1] = tox;
	srep(i, 1, n) {
		while (tox + 1 < n && x[tox + 1] - x[i] <= l)	tox++;
		to[i][1] = tox;
	}
	srep(i, 2, 20)	rep(j, n) {
		to[j][i] = to[to[j][i - 1]][i - 1];
	}
	int q;	cin >> q;
	while (q--) {
		int a, b;	cin >> a >> b;
		a--;	b--;
		if (a > b)	swap(a, b);
		int ret = 0;
		while (a < b) {
			int add = 1;
			int days = 1;
			while (to[a][days + 1] < b) {
				days++;
				add *= 2;
			}
			ret += add;
			a = to[a][days];
		}
		cout << ret << endl;
	}
	return 0;
}

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

const int MOD = 1000000007;

int dp[100010][2];
//dp[i][0] L以下が確定
//dp[i][1] i桁目までLと一致

int main() {
    string s;
    cin >> s;

    int len = s.size();
    dp[0][1] = 1;
    for (int i = 0; i < len; i++)
    {   
        //a+bのi桁目が0
        if (s.at(i) == '0') {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1];
        }
        else {
            dp[i + 1][0] = (dp[i][0] + dp[i][1]) % MOD;
        }

        //a+bのi桁目が1
        if (s.at(i) == '0') {
            dp[i + 1][0] += dp[i][0] * 2 % MOD; dp[i + 1][0] %= MOD;
        }
        else {
            dp[i + 1][0] += dp[i][0] * 2 % MOD; dp[i + 1][0] %= MOD;
            dp[i + 1][1] += dp[i][1] * 2 % MOD; dp[i + 1][1] %= MOD;
        }
    }
    
    int ans = (dp[len][0] + dp[len][1]) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#define SENTINEL 1000000001
using namespace std;

struct Card{
  char suit;
  int num;
};

void merge(Card A[],int left, int mid,int right){
  int nl=mid-left;
  int nr=right-mid;
  Card L[nl+1];Card R[nr+1];
  L[nl].num = SENTINEL; R[nr].num = SENTINEL;
  for(int i=0;i<nl;i++) L[i] = A[left+i];
  for(int i=0;i<nr;i++) R[i] = A[mid +i];
  int il=0; int ir=0;
  for(int i=left;i<right;i++){
    if(L[il].num <= R[ir].num){
      A[i] = L[il];
      il++;
    }else{
      A[i] = R[ir];
      ir++;
    }
  }
}

void mergesort(Card A[],int left,int right){
  if(left + 1<right){
    int mid = (left + right)/ 2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int partition(Card A[],int p,int r){
  int x = A[r].num;
  int i = p-1;
  for(int j=p;j<r;j++){
    if(A[j].num<=x){
      i++;
      swap(A[j],A[i]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

void quicksort(Card A[],int p,int r){
  if(p<r){
    int q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}

bool is_stable(Card A[],Card B[],int n){
  for(int i=0;i<n;i++){
    if(A[i].suit != B[i].suit) return false;
  }
  return true;
}

int main(){
  int n;cin>>n;
  Card cards[n];
  Card cards2[n];
  for(int i=0;i<n;i++){
    cin>>cards[i].suit;
    cin>>cards[i].num;
  }
  memcpy(cards2,cards,sizeof(cards));
  quicksort(cards,0,n-1);
  mergesort(cards2,0,n);
  if(is_stable(cards,cards2,n)){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }
  for(int i=0;i<n;i++){
    printf("%c %d\n",cards[i].suit,cards[i].num);
  }
}

Measured memory_bytes: 5464
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
int main()
{
    char c;
    cin>>c;
    if(c=='A')
        cout<<'T'<<endl;
    else if(c=='T')
        cout<<'A'<<endl;
    else if(c=='C')
        cout<<'G'<<endl;
    else if(c=='G')
        cout<<'C'<<endl;
    return 0;

}


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

long long int gcd(long long int a,long long int b){
    if(a < b){
        long long int tmp;
        tmp=a;
        a=b;
        b=tmp;
    }
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}

long long int lcm(long long int a,long long int b){
    return a / gcd(a,b) * b;
}

int main(){
    long long int N,ans=1;
    cin>>N;
    vector<long long int> T(N);
    for(int i=0;i<N;i++){
        cin>>T[i];
        ans = lcm(ans,T[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
    int n;
    vector<ll> a;
    cin>>n;
    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        a.push_back(tmp);
    }
    ll quat=0,half=0;
    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            if(a[i]%4==0){
                quat++;
            }else{
                half++;
            }
        }
    }
    bool flag =false;
    if((n-quat*2) <= half){
        flag = true;
    }else{
        if(n%2==1 && n-quat*2==1){
            flag = true;
        }
    }
    if(flag) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 1400
x1, y1, x2, y2 = map(int, input().split())
print(x2-y2+y1, end=' ')
print(y2+x2-x1, end=' ')
print(x2-y2+y1-x2+x1, end=' ')
print(y2+x2-x1-y2+y1, end='')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, K;
vector<int> d;

int main() {
  cin >> N >> K;
  d.resize(N);

  rep(i, N) {
    char c;
    cin >> c;
    d[i] = (c == 'L' ? 0 : 1);
  }

  int ans = 0;
  rep(i, N - 1) {
    if (d[i + 1] == d[i]) ++ans;
  }

  int a = 0, b = 0;
  rep(i, N - 1) {
    if (d[i] == 0 && d[i + 1] == 1) ++a;
    if (d[i] == 1 && d[i + 1] == 0) ++b;
  }

  ans += 2 * min({a, b, K});
  if (K > min(a, b) && a != b) ans += 1;

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


Measured memory_bytes: 640
#include <stdio.h>
 
int main() {
    int n, cards[4][13], i, j, number;
    char card;
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 13; j++) {
            cards[i][j] = 0;
        }   
    }   
    scanf("%d", &n);
    getchar();
    for (i = 0; i < n; i++) {
        scanf("%c %d", &card, &number);
        getchar();
        int suit = 0;
        switch (card) {
            case 'S':
                suit = 0;
                break;
            case 'H':
                suit = 1;
                break;
            case 'C':
                suit = 2;
                break;
            case 'D':
                suit = 3;
                break;
        }   
        cards[suit][number - 1] = 1;
    }   
    for (i = 0; i < 4; i++) {
        switch (i) {
            case 0:
                card = 'S';
                break;
            case 1:
                card = 'H';
                break;
            case 2:
                card = 'C';
                break;
            case 3:
                card = 'D';
                break;
        }   
        for (j = 0; j < 13; j++) {
            if (!cards[i][j]) {
                printf("%c %d\n", card, j + 1); 
            }   
        }
    }
    return 0;
}

Measured memory_bytes: 600
def main():
    N = int(input())
    *H, = map(int, input().split())

    ans = 0
    cnt = 0
    prev = H[0] - 1
    for h in H:
        if h <= prev:
            cnt += 1
            ans = max(ans, cnt)
        else:
            cnt = 0
        prev = h

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20344
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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


    int A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << min(A,B) + min(C,D) << endl;

    return 0;
}


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

using namespace std;

using int64 = long long;

struct Element {
  int index;
  int value;
};

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<Element> elements;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x--;
    elements.push_back(Element({x, i + 1}));
  }
  sort(elements.begin(), elements.end(), [](Element e1, Element e2) {
    return e1.index < e2.index;
  });
  // for (const auto& e : elements) {
  //   cout << e.index << " " << e.value << endl;
  // }

  
  vector<int> output(n * n, -1);
  int current = 0;
  auto push_fn = [&](int x) {
    while (current < n * n && output[current] >= 0) current++;
    output[current] = x;
    while (current < n * n && output[current] >= 0) current++;
  };
  for (const auto& e : elements) {
    for (int i = 1; i <= e.value - 1; i++) {
      push_fn(e.value);
    }
    if (current > e.index) {
      if (DEBUG) cout << "DEBUG No 1" << endl;
      cout << "No" << endl;
      return 0;
    }
    output[e.index] = e.value;
    while (current < n * n && output[current] >= 0) current++;
  }
  for (const auto& e : elements) {
    if (e.value < n && current < e.index) {
      if (DEBUG) cout << e.value << endl;
      if (DEBUG) cout << "DEBUG No 2" << endl;
      cout << "No" << endl;
      return 0;
    }
    for (int j = 1; j <= n - e.value; j++) {
      push_fn(e.value);
    }
  }
  cout << "Yes" << endl;
  for (int x : output) cout << x << " ";
  cout << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,m,c,tmp,sum=0,cnt=0;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i,m)cin >> b.at(i);
    rep(i,n){
        rep(j,m){
            cin >> tmp;
            sum+=tmp*b.at(j);
        }
        if(sum+c>0)cnt++;
        sum=0;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807

signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y;
if(y>x)swap(x,y);
z = x*y;
w = x%y;
while(w!=0){
  x = y;
  y = w;
  w = x%y;
}
  std::cout <<z/y;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, h[110];
  while (cin >> n, n) {
    for (int i = 0; i < n + 1; i++) {
      cin >> h[i];
    }
    for (int i = 0; i < n + 1; i++) {
      vector<int> v;
      for (int j = 0; j < n + 1; j++) {
        if (j != i) v.emplace_back(h[j]);
      }
      bool yes = true;
      for (int j = 0; j + 1 < n; j++) {
        yes &= v[j + 1] - v[j] == v[1] - v[0];
      }
      if (!yes) continue;
      cout << h[i] << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3152