akhauriyash/Code-Regression huggingface dataset:
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define int LL
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
string s;
int k;
signed main(){
	fastio;
	cin>>s>>k;
	int len=s.length();
	s='*'+s;
	if(k==3){//while(1);
	LL res=0;
	rb(i,1,s.length()){
		rb(j,i+1,len)
			rb(k,j+1,len){
				res++;
			}
	}
	res*=9*9*9;//cout<<res<<endl;
	int ALL=0;
	rb(i,2,len){
		if(s[i]=='0'){
			ALL+=len-i;
		}
		else{
			break;
		}
	}
	ALL*=9*9;
	rb(i,2,len){
		if(s[i]=='0'){
		}
		else{
			ALL+=(len-i)*9*('9'-s[i]);
			rb(j,i+1,len){
				if(s[j]=='0') ALL+=9;
				else{
					ALL+='9'-s[j];
					break;
				}
			}
			break;
		}
	}
	int tt=0;
	rb(i,1,len-1){
		rb(j,i+1,len-1){
			tt++;
		}
	} 
	tt*=9*9;
	tt*='9'-s[1];
	ALL+=tt;
	res-=ALL;
	cout<<res<<endl;return 0;}
	if(k==2){
//		cout<<len<<endl;
		int res=0;
		rb(i,1,len){
			rb(j,i+1,len){
				rb(k,1,9)
					rb(l,1,9)
						{
							int ok=1;
							rb(m,1,len){char this_;
								if(m==i){
//									cout<<"!"<<endl;
									this_=char('0'+k);
								}else
								if(m==j){
									this_=char('0'+l);
								}
								else{
									this_='0';
								}
//								cout<<this_<<endl;
								if(s[m]<this_){
									ok=0;
									break;
								}
								if(s[m]==this_) continue;
								break;
							}//cout<<endl;
//							cout<<i<<" "<<j<<" "<<char('0'+k)<<endl;
							res+=ok;
						}
			}
		}
		cout<<res;
	}
	else{
		int res=0;
		rb(i,1,len){
			rb(j,1,9){
				int ok=1;
				rb(m,1,len){char this_;
					if(m==i){
						this_=char('0'+j);
					}
					else this_='0';
					if(s[m]<this_){
									ok=0;
									break;
					}
					if(s[m]==this_) continue;
					break;
				}
				res+=ok;
			}
		}
		cout<<res;
	}
	return 0;
}


Measured memory_bytes: 256
s = list(input())
k = int(input())
sl = len(s)

if len(set(s)) == 1:
    print(sl*k//2)
    exit()

d, l, r = s[0], 0, 0

if d == s[-1]:
    for i in range(1, sl):
        if s[i] != d:
            l = i
            break
    
    for i, c in enumerate(s[::-1]):
        if c != d:
            r = i
            break

ans = l//2 + r//2 + (l+r) // 2 * (k-1)
s = s[l:sl-r]
cnt = 0

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        s[i] = ""
        cnt += 1

ans += cnt * k

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
//A以上B以下の回文数の個数を出力せよ。入力は「A B」で与えられる。
int main() {
  int A,B,num;
  num=0; //numは求める個数
  cin >> A >> B;
  
  for(int j=A ; j<=B ; j++){
    int t=0;
    int J;//j自体を動かすと変なことが起きるっぽいので、以下変化させるのはjではなくJ
    J=j;
    for(int i=0 ; i<5 ; i++) { //このfor文でjを逆読みした自然数tを作っている(最後のt/=10に注意)
      t+=(J % 10);
      t*=10;
      J/=10;
    }
    t/=10;
    if(t==j)
     num+=1;
  }

  cout << num << endl;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    int N, A; cin >> N >> A;
    vi X(N+1); FOR(i, 1, N+1) cin >> X[i];
    
    const int XMAX = 50;
  
    vector<vvl> dp(N + MGN, vvl(N + MGN, vl(N * XMAX + MGN, 0)));

    dp[0][0][0] = 1;
    FOR(i, 1, N + 1) dp[i][0][0] = 1;

    for(int i=1; i<=N; i++) {
        for(int j=1; j<=i; j++) {
            for(int k=0; k <= j*XMAX; k++) {
                if (k + X[i] <= j*XMAX) {
                    dp[i][j][k + X[i]] += dp[i - 1][j - 1][k];
                }
                dp[i][j][k] += dp[i - 1][j][k];
            }
        }
    }

    ll ans = 0;
    FOR(j, 1, N+1) ans += dp[N][j][A*j];

    cout << ans << endl;

    return 0;
}

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


int main() {
  string s,t;
  cin >> s >>t;
  int n=s.size();
  vector<char> a(n);
  for(int i=0;i<n;i++){
    a.at(i)=s[i];
  }
  for(int w=0;w<n;w++){
    for(int i=n-1;i>0;i--){
     swap(a.at(i),a.at(i-1));
    }
    int ans=0;
    for(int p=0;p<n;p++){
      if(a.at(p)==t[p]){ans++;}
    }
    if(ans==n){cout << "Yes" << endl;
              return 0;}
  }
  cout << "No" <<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, T;
  cin >> n >> T;
  vector<int> c(n), t(n);
  llong ans = INF;
  REP(i,n){
    cin >> c[i] >> t[i];
    if(t[i] <= T && ans > c[i]){
      ans = c[i];
    }
  }

  if(ans == INF){
    cout << "TLE\n";
  }else{
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 256
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, 1, 0, -1 };

	public static void main(String[] args) {
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0) break;
			boolean[][] field = new boolean[H][W];
			int ar = 0;
			int ac = 0;
			int br = 0;
			int bc = 0;
			for (int i = 0; i < H; ++i) {
				String line = sc.next();
				for (int j = 0; j < W; ++j) {
					if (line.charAt(j) == '#') {
						field[i][j] = true;
					}
					if (line.charAt(j) == 'A') {
						ar = i;
						ac = j;
					}
					if (line.charAt(j) == 'B') {
						br = i;
						bc = j;
					}
				}
			}
			String pattern = sc.next();
			int[][] turn = new int[H][W];
			for (int[] a : turn) {
				Arrays.fill(a, -1);
			}
			ArrayList<Point> cur = new ArrayList<Point>();
			turn[ar][ac] = 0;
			cur.add(new Point(ar, ac));
			int t = 1;
			while (!cur.isEmpty()) {
				ArrayList<Point> next = new ArrayList<Point>();
				for (Point p : cur) {
					for (int i = 0; i < 4; ++i) {
						int nr = p.x + DR[i];
						int nc = p.y + DC[i];
						if (nr == -1 || nr == H || nc == -1 || nc == W || turn[nr][nc] != -1 || field[nr][nc]) continue;
						turn[nr][nc] = t;
						next.add(new Point(nr, nc));
					}
				}
				cur = next;
				++t;
			}
			int ans = Integer.MAX_VALUE;
			int ansR = -1;
			int ansC = -1;
			for (int i = 0; i < 10000; ++i) {
				if (turn[br][bc] != -1 && turn[br][bc] <= i) {
					ans = i;
					ansR = br;
					ansC = bc;
					break;
				}
				char q = pattern.charAt(i % pattern.length());
				if (q == '8') {
					if (br != 0) --br;
				} else if (q == '6') {
					if (bc != W - 1) ++bc;
				} else if (q == '4') {
					if (bc != 0) --bc;
				} else if (q == '2') {
					if (br != H - 1) ++br;
				}
			}
			if (ans == Integer.MAX_VALUE) {
				System.out.println("impossible");
			} else {
				System.out.println(ans + " " + ansR + " " + ansC);
			}
		}
	}
}

Measured memory_bytes: 12000
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / __gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m) - 1;i>=(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) n.begin(), n.end()
#define allr(n) n.rbegin(), n.rend()
#define sp(n) cout << fixed << setprecision(n)
#define pi 3.14159265358979323846
#define inf 1000000007
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  int a, b, c;
  ci(a, b, c);
  a == b && b == c ? co("Yes") : co("No");
}

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

int main(){
    int a[3][3];
    rep(i,3) rep(j,3) cin >> a[i][j];
    int n,b;
    cin >> n;
    rep(k,n){
        cin >> b;
        rep(i,3){
            rep(j,3){
                if(a[i][j]==b) a[i][j]=0;
            }
        }
    }
    string res="No";
    rep(i,3){
        int sum=0;
        rep(j,3) sum+=a[i][j];
        if(!sum) res="Yes";
        sum = 0;
        rep(j,3) sum+=a[j][i];
        if(!sum) res="Yes";
    }
    if(a[0][0]+a[1][1]+a[2][2]==0) res="Yes";
    if(a[0][2]+a[1][1]+a[2][0]==0) res="Yes";
    cout << res <<endl;

}

Measured memory_bytes: 256
#include<iostream>
using ll = long long;
using namespace std;

int main()
{
    ll a, b;
    cin >> a >> b;
    if(a == 0){
        switch(b % 4){
            case 0:
                cout << b << endl;
                break;
            case 1:
                cout << 1 << endl;
                break;
            case 2:
                cout << b+1 << endl;
                break;
            case 3:
                cout << 0 << endl;
                break;
        }
    } else{
        switch(b % 4){
            case 0:
                switch((a-1) % 4){
                    case 0:
                        cout << ((a-1) ^ b) <<  endl;
                        break;
                    case 1:
                        cout << (1 ^ b) << endl;
                        break;
                    case 2:
                        cout << (a ^ b) << endl;
                        break;
                    case 3:
                        cout << b << endl;
                        break;
                }
                break;
            case 1:
                switch((a-1) % 4){
                    case 0:
                        cout << ((a-1) ^ 1) <<  endl;
                        break;
                    case 1:
                        cout << (1 ^ 1) << endl;
                        break;
                    case 2:
                        cout << (a ^ 1) << endl;
                        break;
                    case 3:
                        cout << 1 << endl;
                        break;
                }
                break;
            case 2:
                switch((a-1) % 4){
                    case 0:
                        cout << ((a-1) ^ (b+1)) <<  endl;
                        break;
                    case 1:
                        cout << (1 ^ (b+1)) << endl;
                        break;
                    case 2:
                        cout << (a ^ (b+1)) << endl;
                        break;
                    case 3:
                        cout << b+1 << endl;
                        break;
                }
                break;
            case 3:
                switch((a-1) % 4){
                    case 0:
                        cout << a-1 <<  endl;
                        break;
                    case 1:
                        cout << 1 << endl;
                        break;
                    case 2:
                        cout << a << endl;
                        break;
                    case 3:
                        cout << 0 << endl;
                        break;
                }
                break;
        }
    }
    return 0;
}
   

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int k;
  cin >> k;
  vector<int> v(k);
  int n=7%k;
  int ans=0;
  for(int i=1;i<k+10;i++){
    if(n==0){
      ans=i; break;
    }else{
      if(v[n]==1){
        ans=-1; break;
      }else{
        v[n]=1;
        n=(10*n+7)%k;
      }
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 7116
#include<stdio.h>
 int main(void){
  int i,x;
    int a[4];
  for(x=0,i=0;i<4;i++){
    scanf("%d",&a[i]);
    x+=a[i];
  }
  printf("%d\n%d\n", x/60,x%60);
  return 0;
}

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

using namespace std;

char s[30];
int i,v[30],ok;

int main()
{
    cin>>s;
    for (i=0;i<strlen(s);++i)
        v[s[i]-'a']++;

    ok=1;
    for (i=0;i<=26;++i)
        if (v[i]>1) {ok=0;break;}

    if (ok) cout<<"yes";
    else
        cout<<"no";

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
unordered_map<string,int>mp;
void init()
{
    mp["SUN"]=7;
    mp["MON"]=6;
    mp["TUE"]=5;
    mp["WED"]=4;
    mp["THU"]=3;
    mp["FRI"]=2;
    mp["SAT"]=1;
}
int main()
{
    init();
    string s;
    cin>>s;
    cout<<mp[s]<<endl;
}

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

int main(){

    string str;

    while(cin >> str){
        for(int i=0; i<str.size(); i++){
            if(str[i] == '@'){
                for(int j=0; j<str[i+1]-48; j++){
                    cout << str[i+2];
                }
                i += 2;
            }else{
                cout << str[i];
            }
        }
        cout << '\n';
    }

    return 0;
}

Measured memory_bytes: 1156
from bisect import bisect_right


a, b, q = map(int, input().split())
INF = 10 ** 18
J = [-INF] + [int(input()) for _ in range(a)] + [INF]
T = [-INF] + [int(input()) for _ in range(b)] + [INF]

for _ in range(q):
  s = int(input())
  b, d = bisect_right(J, s), bisect_right(T, s)
  res = INF
  for j in [J[b - 1], J[b]]:
    for t in [T[d - 1], T[d]]:
      d1, d2 = abs(j - s) + abs(t - j), abs(t - s) + abs(j - t)
      res = min(res, d1, d2)
  print(res)

Measured memory_bytes: 14228
#include<stdio.h>

int main() {
  int n;
  scanf("%d",&n);
  int j,k,l;
  j = n/100;
  n %= 100;
  k = n/10;
  n %= 10;
  l = n;
  if(j == 7 || k == 7 || l == 7) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}


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

typedef long long ll;

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

    ll A[n];
    for(int i = 0; i < n; i++){
        cin >> A[i];
        A[i] -= i+1;
    }  

    sort(A, A + n);

    ll pivot = A[n/2];

    ll ans = 0;
    for(int i = 0; i < n; i++)  ans += abs(A[i] - pivot);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] p = new int[m];
		int[] key = new int[m];
		for(int i = 0; i < m; i++){
		    p[i] = sc.nextInt();
		    int b = sc.nextInt();
		    for(int j = 0; j < b; j++){
		        key[i] |= 1<<(sc.nextInt() - 1);
		    }
		}
		// 計算
		int result = -1;
		int[] dp = new int[1<<n];
		int INF = 1001001001;
		Arrays.fill(dp, INF);
		dp[0] = 0;
		for(int i = 0; i < 1<<n; i++){
		    for(int j = 0; j < m; j++){
		        dp[i | key[j]] = min(dp[i | key[j]],  dp[i] + p[j]);
		    }
		}
		if(dp[(1<<n) - 1] != INF){
		    result = dp[(1<<n) - 1];
		}

		// 出力
		System.out.println(result);
        
	}
}

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

int main(){
    int A,B,C,sum;
    cin >> A >> B;
    for(int i = 0; i < B; i++){
        cin >> C;
        sum = sum + C;
    }
    if(sum >= A){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int 
signed main() {
int n,k;
    cin>>n>>k;            
    vector<int>v(n+1);
    v[0]=0;int c=0;
    for(int i=1;i<=n;i++){int d;cin>>d;v[i]=d;if(d==1){c++;}}
     
    vector<int>t(n+1,0);
    vector<int>l,var;
   // for(auto x:s){cout<<x<<" ";}cout<<endl;
    int i=1;
    t[i]=1;
    while(1){
        int  c = v[i];
        var.push_back(c);
        t[c]++;
        if(t[v[i]] == 2){
            t[v[i]]--;
            var.pop_back();
            while(1){
                int  c = v[i];
                t[c]++;
                if(t[v[i]] == 3) break;
                l.push_back(v[i]);
                i = v[i];
            }
            break;
        }
        i = v[i];
    
    }
    /* for(auto x:intial){cout<<x<<" ";}cout<<endl;
    for(auto x:loop){cout<<x<<" ";}cout<<endl;*/
     if(k<var.size()){
        cout<<var[k-1];
    } else{
        k -= var.size();
        k = k % l.size();
        if(k==0) cout<<l[l.size()-1];
        else cout<<l[k-1];
    }
    return 0;
    
}


Measured memory_bytes: 10768
#include <stdio.h>
#include <ctype.h>

int main() {
    char a[11], b[11], c[11];
    scanf("%s%s%s", a, b, c);
    printf("%c%c%c\n", toupper(a[0]), toupper(b[0]), toupper(c[0]));
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ll N;
  string s,t;
  cin >> N >> s >> t;
  ll cnt = N;
  rep(i,N){
    if(s.substr(i)  == t.substr(0,N-i) ) break;
    else cnt--;
  }
  cout << 2*N - cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#include <unordered_map>
using namespace std;
#define MAXSIZE 10005
typedef long long LL;
#define debug 0

int main() {
#if debug
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	int sum = 0;
	while (n--) {
		int tem;
		scanf("%d", &tem);
		sum += tem - 1;
	}
	printf("%d\n", sum);
	//printf("\n");
	system("pause");
	return 0;
}

Measured memory_bytes: 504
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from heapq import heapify, heappush, heappop
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map

    N = int(input())
    S = input()
    if 'W' not in S or 'R' not in S:
        print(0)
        exit()

    # RとWの位置
    locR = [-i for i in range(N) if S[i] == 'R']
    locW = [i for i in range(N) if S[i] == 'W']
    heapify(locR)
    heapify(locW)

    dS = deque(S)
    # print(N, dS)
    # print(locR, locW)
    count = 0
    while True:
        # print(locR, locW)
        # print(">?>", -locR[0], locW[0])
        if (-locR[0]) < locW[0]:
            break
        # 交換する
        right_most_R = heappop(locR)
        left_most_W = heappop(locW)
        heappush(locR, -left_most_W)
        heappush(locW, -right_most_R)
        count += 1
    print(count)

if __name__ == '__main__':
    main()

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

struct cost {
    i64 dest;
    i64 yen, snuuk;
};

void solve() {
    i64 n, m, s, t;
    cin >> n >> m >> s >> t, s--, t--;

    vector<vector<cost>> g(n);
    for (i64 i = 0; i < m; i++) {
        i64 u, v, a, b;
        cin >> u >> v >> a >> b, u--, v--;
        g[u].push_back({ v, a, b });
        g[v].push_back({ u, a, b });
    }

    vector<i64> minyen(n, INF), minsnuuk(n, INF);
    priority_queue<p64, vector<p64>, greater<>> pq;
    pq.emplace(0, s);
    while (!pq.empty()) {
        auto [ cost, to ] = pq.top(); pq.pop();
        if (minyen[to] != INF) continue;
        minyen[to] = cost;

        for (auto& [ dest, yen, snuuk ] : g[to]) {
            if (minyen[dest] != INF) continue;
            pq.emplace(cost + yen, dest);
        }
    }
    pq.emplace(0, t);
    while (!pq.empty()) {
        auto [ cost, to ] = pq.top(); pq.pop();
        if (minsnuuk[to] != INF) continue;
        minsnuuk[to] = cost;

        for (auto& [ dest, yen, snuuk ] : g[to]) {
            if (minsnuuk[dest] != INF) continue;
            pq.emplace(cost + snuuk, dest);
        }
    }

    for (i64 i = 0; i < n; i++) {
        pq.emplace(minyen[i] + minsnuuk[i], i);
    }

    for (i64 i = 0; i < n; i++) {
        while (pq.top().second < i) pq.pop();
        cout << (i64) 1e15 - pq.top().first << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

double DP[305][305][305];
bool vis[305][305][305];
int n;
double p;

double dp(int a, int b, int c){
	if(a<0 || b<0 || c<0) return 0;
	if(a==0 && b==0 && c==0) return 0;
	if(vis[a][b][c]) return DP[a][b][c];
	vis[a][b][c] = 1;
	double x1 = (double)a/n;
	double x2 = (double)b/n;
	double x3 = (double)c/n;
	double y = (double)(n-(a+b+c))/n;
	return DP[a][b][c] = (dp(a-1,b,c)*x1 + dp(a+1,b-1,c)*x2+ dp(a,b+1,c-1)*x3 +1)/(1-y);
}
int a[4];
int main(){
	scanf("%d",&n);
	p = (double)1/n;
	int x;
	
	for (int i = 0;i<n;i++){
		scanf("%d",&x);
		a[x]++;
	}
	double ans = dp(a[1],a[2],a[3]);
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 246016
import java.util.Scanner;

public class Main {

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

		int A = cin.nextInt();
		String text = cin.next();
		int left=0;
		int right=0;
		int left_l[] = new int[A];
		int right_l[] = new int[A];
		int countl=0;
		int countr=0;
		for(int i=0;i<A;i++){
			if(text.charAt(i)=='('){
				left++;
				left_l[countl] = i+1;
				countl++;
			}else{
				right++;
				right_l[countr] = i+1;
				countr++;
			}
		}

		int countc=0;

		for(int x=0;x<A;x++){
			if(left_l[x]>0){
				for(int y=0;y<A;y++){
					if(left_l[x]<right_l[y]){
						countc++;
						right_l[y]=0;
						break;
					}
				}
			}
		}

		left-=countc;
		right-=countc;


		for(int j=0;j<right;j++){
				System.out.print("(");
		}

		System.out.print(text);
		for(int k=0;k<left;k++){
				System.out.print(")");
		}
		System.out.println();
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

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

    std::vector<int> L(N);

    for (int i = 0; i < N; i++)
    {
        std::cin >> L[i];
    }

    std::sort(L.begin(), L.end());
    int maxLen = L[N - 1];
    int sum = 0;
    for (int i = 0; i < N-1; i++)
    {
        sum += L[i];
    }
    std::string out;
    if (maxLen < sum)
    {
        out = "Yes";
    }
    else
    {
        out = "No";
    }

    std::cout << out << std::endl;
    return 0;
}

Measured memory_bytes: 256
// Last Change: 08/26/2019 03:57:59.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

  vector<ll> a(N);
  ll sumAll = 0;
  for (auto &&e : a) {
    ll ipt;
    cin >> ipt;
    e = sumAll += ipt;
  }

  ll ans = numeric_limits<ll>::max();
  for (ll i = 0; i < N - 1; ++i) {
    ans = min(ans, abs(2 * a[i] - sumAll));
  }
  cout << ans << endl;
}


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

const int MAXN = 1e5 + 10;

long long n, ans, res;
long long a[MAXN], b[MAXN], c[MAXN];
long long sa, sb;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sa += a[i];
	}

	for (int i = 0; i < n; i++) {
		cin >> b[i];
		sb += b[i];
		if (a[i] < b[i]) {
			res += (b[i] - a[i]);
			ans++;
		}
		c[i] = (a[i] - b[i]);
	}
	
	sort(c, c + n);

	if (sa < sb)
		return cout << -1 << '\n', 0;

	for (int i = n - 1; i >= 0; i--) {
		if (res > 0) {
			ans++;
			res -= c[i];
		}
		else
			break;
	}
	cout << ans << '\n';
	return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 n;
	int64 num[5] = {5, 7, 5, 7, 7};
	while (cin >> n && n) {
		vector<int64> a(n);
		REP(i, n) {
			string s;
			cin >> s;
			a[i] = s.size();
		}
		int64 res = -1;
		REP(i, n) {
			int64 s = 0, idx = 0;
			FOR(j, i, n) {
				s += a[j];
				if (num[idx] == s) idx++, s = 0;
				if (idx == 5) break;
				if (num[idx] < s) break;
			}
			if (idx == 5) {
				res = i;
				break;
			}
		}
		cout << res+1 << endl;
	}
}



Measured memory_bytes: 3180
n = input()
s = input()

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

ans =0
for a in range(10):
  index_a = my_index(s, str(a))
  if index_a == -1:
    continue
  
  for b in range(10):
    index_b = my_index(s[index_a+1:], str(b))
    if index_b == -1:
      continue
      
    for c in range(10):
      index_c = my_index(s[index_a+1+index_b+1:], str(c))
      if index_c !=-1:
        ans += 1
print(ans)

Measured memory_bytes: 3064
n,m = map(int,input().split())
mod = 10**9+7
def mod_f(i):
    ans = 1
    for i in range(1,i+1):
        ans *= i
        ans %= mod
    return ans

if abs(n-m) > 1:
    print(0)
elif n == m:
    print((mod_f(n)*mod_f(m)*2)%mod)
else:
    print((mod_f(n)*mod_f(m))%mod)

Measured memory_bytes: 3064
while str=gets
    array=str.split(" ")
    a=array[0].to_i
    b=array[1].to_i
    if a==0 && b==0 then
        exit(0)
    elsif a<=b then
        print(a," ",b,"\n")
    else
        print(b," ",a,"\n")
    end
end

Measured memory_bytes: 8808
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, MX = 200000;
	cat K;
	cin >> N >> K;
	vector<int> A(N);
	vector< set<int> > pos(MX+1);
	for(int i = 0; i < N; i++) {
		cin >> A[i];
		pos[A[i]].insert(i);
	}
	vector<cat> skip[100];
	vector<int> nxt[100];
	for(int k = 0; k <= 60; k++) {
		skip[k].resize(N);
		nxt[k].resize(N);
	}
	for(int i = 0; i < N; i++) {
		set<int> & S = pos[A[i]];
		auto it = S.upper_bound(i);
		if(it == S.end()) {
			it = S.begin();
			skip[0][i] = N + *it - i + 1;
		}
		else skip[0][i] = *it - i + 1;
		nxt[0][i] = (*it + 1) % N;
	}
	for(int k = 0; k < 60; k++) for(int i = 0; i < N; i++) {
		skip[k+1][i] = min(N*K+1, skip[k][i] + skip[k][nxt[k][i]]);
		nxt[k+1][i] = nxt[k][nxt[k][i]];
	}
	int cur = 0, k = 60;
	cat l = 0;
	while(k >= 0) {
		if(skip[k][cur]+l > N*K) k--;
		else {
			l += skip[k][cur];
			cur = nxt[k][cur];
		}
	}
	vector<int> ans, occ(MX+1, -1);
	while(l < N*K) {
		int a = A[l%N];
		l++;
		if(occ[a] != -1) {
			while(ans.back() != a) {
				occ[ans.back()] = -1;
				ans.pop_back();
			}
			ans.pop_back();
			occ[a] = -1;
		}
		else {
			occ[a] = ans.size();
			ans.push_back(a);
		}
	}
	for(int i = 0; i < (int)ans.size(); i++)
		cout << ((i == 0) ? "" : " ") << ans[i];
	cout << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 166004
def main():
    N = int(input())
    freq = {}
    for i in range(1, N+1):
        pair = str(i)[0] + str(i)[-1]
        if pair in freq.keys():
            freq[pair] += 1
        else:
            freq[pair] = 1
    
    ans = 0
    for i in range(1, N+1):
        pair_rev = str(i)[-1] + str(i)[0]
        if pair_rev in freq.keys():
            ans += freq[pair_rev]
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
def main():
    n, *x = map(int, open(0).read().split())
    y = sorted(x)
    a, b = y[n // 2 - 1], y[n // 2]
    d = dict()
    for i, j in enumerate(y, 1):
        if i <= n // 2:
            d[j] = b
        else:
            d[j] = a

    for i in x:
        print(d[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 34064
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
#include<array>
#include<string>
#include<numeric>
#include<set>
#include<cstdio>
#include<cmath>
#include<unordered_map>
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    ld pi = acos(-1);
    ld a, b, h, m;
    cin>>a>>b>>h>>m;
    ld angle;
    angle = pi*2*(ld(h/12.0)+(ld)((m/60.0)/12.0)-(ld)(m/60.0));
    ld result = (ld)(a*a) + (ld)(b*b) - (ld)(2.0*a*b*cosl(angle));
    result = sqrt(result);
    cout<<fixed;
    cout<<setprecision(20)<<result<<"\n";
    return 0;
}


Measured memory_bytes: 4032
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int count(int x) {
  if (x % 100 != 0) return 0;
  return count(x / 100) + 1;
}

int main() {
  int d, n;
  cin >> d >> n;
  int cnt{};
  for (int i = 1;; ++i) {
    if (count(i) == d) {
      ++cnt;
      if (cnt == n) {
        cout << i << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int sec,h,m,s;
    cin >> sec;
    h = sec/(60*60);
    m = (sec - h*60*60)/(60);
    s = (sec - h*60*60 - m*60);
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int p=10e5+5;
int h[p], dp[p];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    int n, k;
    cin>>n>>k;
    for(int i=1; i<=n; i++) {cin>>h[i]; dp[i]=10e9+10; }
    dp[0]=0;
    dp[1]=0;
    
    for(int i=2; i<=n; i++)
    {
        for(int j=min(k, i-1); j>=1; j--)
        dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]), dp[i]);
        
    }
    cout<<dp[n];

    
    
    
    return 0;
}


Measured memory_bytes: 4736
use proconio::*;

fn run() {
    input! {
        mut n: usize,
    }
    n -= 1;
    let p = 26;
    let mut m = p;
    let mut len = 1;
    while n >= m {
        n -= m;
        m *= p;
        len += 1;
    }
    let mut ans = String::new();
    for _ in 0..len {
        m /= p;
        let x = n / m;
        ans.push((b'a' + x as u8) as char);
        n -= x * m;
    }
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 2176
#include<iostream>
#include<map>
using namespace std;
typedef long long LL;
const int N = 2e5;
LL a[N+1];
int main()
{
    LL n, x, m; cin >> n >> x >> m;
    LL todo = n;
    LL ans = 0;
    map<LL,int> first_saw;
    a[1] = x;
    int i;
    for(i = 1; i <= n && first_saw.find(a[i])==first_saw.end(); i++)
    {
        first_saw[a[i]] = i;
        ans += a[i];
        a[i+1] = (a[i]*a[i])%m; 
        todo--;
    }

    if(i <= n)
    {
        LL period = i-first_saw[a[i]];
        LL s = 0;
        for(int j = first_saw[a[i]]; j < i; j++)
            s += a[j];

        ans += (todo/period)*s;
        todo %= period;
        for(int k = 0; k < todo; k++)
            ans += a[first_saw[a[i]]+k];
    }
    cout<<ans<<endl;

    return 0;
}

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

main() {
    string S; cin >> S; int ans = 0;
    for(int i=0;i<(1<<(S.size()-1));i++){
        int pos=0; 
        for(int  j=0; j<S.size()-1; j++){
            if((i>>j)&1) {
                pos+=S[j]-'0';
                ans+=pos;
                pos=0;
            }
            else{
                pos+=S[j]-'0';
                pos*=10;
            }
        }
        ans+=pos;
        ans+=S[S.size()-1]-'0';
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=2*100000+10;

const ll nmax=100010;

class unionfind{
public:
    ll par[nmax];
    ll rank[nmax];

    unionfind(ll n){
        for(ll i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }

    ll root(ll x){
        if(par[x]==x)return x;
        else return par[x]=root(par[x]);
    }

    void unite(ll x,ll y){
        x=root(x);
        y=root(y);
        if(x==y) return;

        if(rank[x]<rank[y]) par[x]=y;
        else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(ll x,ll y){
        return root(x)==root(y);
    }
};

int main(){
  ll N,M,x,y;
  cin>>N>>M;
  ll pl[N];
  for(ll i=0;i<N;i++){
    cin>>pl[i];
    pl[i]--;
  }
  unionfind u(N);
  for(ll i=0;i<M;i++){
    cin>>x>>y;
    x--;y--;
    u.unite(x,y);
  }
  ll ans=0;
  for(ll i=0;i<N;i++){
    if(u.same(i,pl[i]))ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int r;
	cin >> r;
	cout << 3 * r * r;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3652
def main():
    (A,B,C,K) = list(map(int, input().split(' ')))

    if K <= A:
        print(K)
    elif K <= A+B:
        print(A)
    elif K <= A+B+C:
        print(A-(K-A-B))
    else:
        print(A-C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
int dp[200][200][2];
vector <int> num;
int k;
string s;
int solve(int pos, int cnt, int flag)
{
	if(cnt > k) return 0;
	if(pos == s.size())
	{
		if(cnt == k) return 1;
		else return 0;
	}
	if(dp[pos][cnt][flag] != -1) return dp[pos][cnt][flag];
	int res = 0;
	int limit;
	if(flag == 0) limit = s[pos]-'0';
	else limit = 9;
	for(int digit = 0; digit <= limit; digit++)
	{
		int nf = flag;
		int ncnt = cnt;
		if(digit != 0) ncnt++;
		if(flag == 0 && digit < limit) nf = 1;
		res += solve(pos+1,ncnt,nf);
	}
	return dp[pos][cnt][flag] = res;
}
int solve1(string s)
{
	memset(dp,-1,sizeof(dp));
	int result = solve(0,0,0);
	return result;
}
int32_t main()
{
	cin >> s >> k;
	cout << solve1(s) << "\n";
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define fast                            ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int                             long long
#define ff                              first
#define ss                              second
#define max3(a,b,c)                     max(a,max(b,c))
#define min3(a,b,c)                     min(a,min(b,c))
#define setbits(x)                      __builtin_popcountll(x)
#define zerobits(x)                      __builtin_ctzll(x)
#define pb                              push_back
#define mkp                             make_pair
#define all(v)                          (v).begin(),(v).end()
#define pii                             pair<int, int>
#define vi                              vector<int>
#define vpi                             vector<pair<int,int>>
#define rev(x)                          reverse(all(x))
#define gcd(m,n)                        __gcd(m, n)
#define negmod(x,m)                     ((x)%(m)+(m))%(m)
#define fr(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 repr(i, n)                      for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b)                    for (int i = (a), _b = (b); i >= _b; i--)
#define M                               1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ull countBits(ull n){ull count=0;while(n){count++;n>>=1;}return count;}
int updiv(int a,int b)
{
  if(a%b==0)
    return (a/b);
  else
    return (a/b)+1;
}
int mymod(int x,int m)
{
  if(x>0)
    return x%m;
  else
    return negmod(x,m);
}
int binpow(int a, int b)
{
    int res = 1;
    while(b>0)
    {
        if(b&1)
        res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}
bool second_sort(const pii & lhs , const pii & rhs)
{
    pii a,b;
    a.ff=lhs.ss;
    a.ss=lhs.ff;
    b.ff=rhs.ss;
    b.ss=rhs.ff;
    return a<b;
}
int32_t main()
{
fast
int t=1,n;
//cin>>t;
while(t--)
{
cin>>n;
int a[n+1],b[n+1],c[n+1];
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i]>>c[i];
}
int dp[n+1][3];
rep(i,n+1)
{
    rep(j,3)
    dp[i][j]=0;
}
dp[1][0]=a[1];
dp[1][1]=b[1];
dp[1][2]=c[1];
for(int i=2;i<=n;i++)
{
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
}
int s=max3(dp[n][0],dp[n][1],dp[n][2]);
cout<<s<<"\n";
}
return 0;
}


Measured memory_bytes: 8244
N = int(input())

A = list(map(int,input().split()))

stack = []
ans = 0

for a in A:
    if len(stack)==0:
        stack.append(a)
    elif stack[-1]!=a:
        stack.remove(stack[0])
        stack.append(a)
    else:
        ans += 1
        stack.clear()

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long 
#define f(j) for(ll i=0;i<j;i++)
#define pb(i) push_back(i)
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;    
typedef vector<vector<long long> > matrix; 
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	// faster
	ll n;
	cin>>n;
	ll a[n];
	f(n)	cin>>a[i];
	ll ans=0,dp[n]={0};
	dp[0]=a[0];
	for(ll i=1;i<n;i++)
		dp[i]=max(dp[i-1],a[i]);
	
	f(n)
		if(dp[i]>a[i])
			ans += dp[i]-a[i];
	cout<<ans<<"\n";
return 0;	
}

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
    
    scanf("%d", &N);
    vector<ll> a(N);
    for(int i = 0; i < N; ++i) scanf("%lld", &a[i]);
    
    vector<ll> up, down; up = down = a;
    sort(up.begin(), up.end()), sort(down.begin(), down.end(), greater<ll>());
    
    vector<ll> v1(N, 0), v2(N, 0);
    int cnt = 0, idx = 0, s = (N % 2) ? N / 2 : N / 2 - 1;
    for(int i = s; i >= 0 && i < N; i += (cnt % 2) ? cnt * 2 : -(cnt * 2)) ++cnt, v1[i] = up[idx], v2[i] = down[idx++];
    
    cnt = 0, idx = 0, s = (N % 2) ? N / 2 - 1 : N / 2;
    int n = (N % 2) ? 2 : -2, m = (N % 2) ? -2 : 2;
    for(int i = s; i >= 0 && i < N; i += (cnt % 2) ? cnt * n : cnt * m) ++cnt, v1[i] = down[idx], v2[i] = up[idx++];
    
    ll sum1 = 0, sum2 = 0;
    for(int i = 0; i < N - 1; ++i) sum1 += abs(v1[i] - v1[i + 1]), sum2 += abs(v2[i] - v2[i + 1]);
    printf("%lld\n", max(sum1, sum2));
    
    return 0;
}


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

string s;

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

    cin >> s;

    int ans = 101;
    int N = (int)s.size();
    for(int i = 0; i < 26; ++i){
        char c = char('a' + i);
        int prev = -1;
        int m = 0;
        for(int j = 0; j < N; ++j){
            m = max(m, j - prev - 1);
            if(s[j] == c){
                prev = j;
            }
        }
        m = max(m, N - prev - 1);
        ans = min(ans, m);
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
    int n, length;
    cin >> n >> length;
    vector<string> s(n);
    rep(i,n) {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    string ans;
    rep(i,n) {
        ans += s[i];
    }
    cout << ans << endl;
}

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

int main(){
	int a, b, c, x, d = 0;
	cin >> a >> b >> c;
	
	for(x = a; x <= b; x++){
		if(c % x == 0){
			d++;
		}
	}
	cout << d << endl;
    return 0;
}

Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int f[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
    int a,b;
    cin>>a>>b;
    int sum=a-1;
    if(b>=a) sum++;
    cout<<sum<<endl;
    return 0;
}


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

int main (){
int a,b;
cin >> a>>b;
int x=a+b;
int y=a-b;
int z=a*b;
if ( (x> y && x>z)||(x==y && x==z)||(x>y and x==z)||(x==y and x>z)) {
    cout<<x;
}
else if ((y >x && y >z)||(y==x and y==z ) || (y>x and y==z)||(y==x and y >z)){
    cout <<y ;
}
else if ((z>x && z>y)|| (z==y and z==x)||(z==y and z>x)||(z==x and z>y)){
    cout<< z;
}
}

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

int main(){
  	int k;	
  	string s;
  	cin >> k >> s;
  	if(s.length()<=k) cout << s << '\n';
  	else {
  		s = s.substr(0,k);
      	cout << s << "..." << '\n';
    }
  
	return 0;
}

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

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

  vector<int> v(n);
  vector<int> c(n);

  for(int i = 0; i < n; i++){
    cin >> v[i];
  }

  int totalx = 0;
  int totaly = 0;
  for(int i = 0; i < n; i++){
    cin >> c[i];

    if(v[i] > c[i]){
      totalx += v[i];
      totaly += c[i];
    }
  }

  cout << totalx - totaly << endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int i = a,n = 0;
    for(i=a;i<=b;i++){
        if(c%i == 0) n++;
    }
    cout << n <<endl;
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
#define endl '\n'

  
int calcAngle(long double h,long double m)  
{  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
    long double hour_angle = 0.5 * (h * 60.0 + m);  
    long double minute_angle = 6.0 * m;  
    long double angle = abs(hour_angle - minute_angle);  
    angle = min(360.0 - angle, angle);  
  
    return angle;  
}  
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  IOS
  long double a,b,h,m;
  cin>>a>>b>>h>>m;
  long double PI= acos(-1);
  long double ang=PI* 2 * ((long double)h/ 12.0 + ((long double)m/ 60.0) / 12.0 - (long double)m/ 60.0);
  long double c = -2.0*a*b*(cos(ang)) + a*a + b*b;
  c = sqrt(c);
  cout<<fixed<<setprecision(15)<<c<<endl;
}


Measured memory_bytes: 4176