akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	ll n, k;
	cin >> n >> k;
	vector<int> p(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	vector<ll> c(n);
	rep(i, n) cin >> c[i];
	ll ans = 0;
	rep(i, n) {
		ll use = k;
		int now = i;
		ll score = 0;
		ll r = 0;
		bool flag = true;
		vector<ll> s;
		while (now != i || flag) {
			score += c[p[now]];
			now = p[now];
			r++;
			flag = false;
			s.pb(score);
		}
		ll sz = s.size();
		ll x = 0;
		rep(j, min(sz, use)) {
			chmax(x, s[j]);
		}
		if (score > 0) {
			ll step = use / r;
			if (step > 0) {
				x += (step - 1) * score;
			}
		}
		ll res = 0;
		if (score > 0) {
			res += use / r * score;
			use %= r;
		}
		ll tmp = 0;
		rep(j, min(sz, use)) {
			chmax(tmp, s[j]);
		}
		chmax(ans, res + tmp);
		chmax(ans, x);
	}
	bool on = true;
	ll mi = -inf;
	rep(i, n) {
		if (c[i] >= 0) on = false;
		chmax(mi, c[i]);
	}
	if (on) cout << mi << '\n';
	else cout << ans << '\n';
}

Measured memory_bytes: 3816
// ABC170-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


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

    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    vector<bool> num(1000010,true);
    int bef=-1;
    rep(i,n){
        if(bef==a[i]) num[a[i]]=false; //被ってる
        else{
            bef=a[i];
            int cur=a[i]*2;
            while(cur<=1000000){
                if(num[cur]) num[cur]=false;
                cur+=a[i];
            }
        }
    }
    int ans=0;
    rep(i,n){
        if(num[a[i]]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4336
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N, L, T;
  cin >> N >> L >> T;
  vector<int> X(N), W(N);
  vector<int> Y(N);


  rep(i, N) {
    cin >> X[i] >> W[i];
    Y[i] = X[i] + T * (W[i] == 1 ? +1 : -1);
    Y[i] = ((Y[i] % L) + L) % L;
  }

  int Y0 = Y[0];
  sort(all(Y));

  int temp = 0;
  repp(i, 1, N - 1) {
    if (W[0] == W[i])
      continue;

    int diff;
    if (W[0] == 1) {
      diff = X[i] - X[0];
    } else {
      diff = L + X[0] - X[i];
    }

    if (T * 2 < diff)
      continue;

    temp++;

    int d = T * 2 - diff;
    temp += d / L;
  }

  if (W[0] == 2)
    temp = N - temp;
  temp = (temp % N + N) % N;

  vector<int> ans(N);

  int ind;
  rep(i, N) {
    if (Y[i] == Y0) {
      ind = i;
      if (Y[(i + 1) % N] == Y0 && W[0] == 1)
        ind++;
      break;
    }
  }

  rep(i, N) {
    ans[(temp + i) % N] = Y[(ind + i) % N];
  }

  rep(i, len(ans)) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 4352
import sys
H, W = [int(i) for i in input().split(' ')]


cou = 0
one_flag = False
result = []
sub_result = []
for line in sys.stdin:
    cou += 1
    xs = [1 if int(item) % 2 == 1 else 0 for item in line.strip().split(' ')]
    if cou % 2 == 0:
        xs = xs[::-1]
    for i, x in enumerate(xs):
        if one_flag:
            if i != 0:
                if cou % 2 == 0:
                    sub_result.append((cou, W-i+1, cou, W-i))
                else:
                    sub_result.append((cou, i, cou, i+1))
            else:
                if cou % 2 == 0:
                    sub_result.append((cou-1, W, cou, W))
                else:
                    sub_result.append((cou-1, 1, cou, 1))
        if x == 1:
            one_flag = not one_flag
            result.append(sub_result)
            sub_result = []
N = 0
for r in result:
    N += len(r)

print(N)
for r in result:
    for x in r:
        print(" ".join(map(str,x)))


Measured memory_bytes: 87904
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int H,W,h,w;
int res[505][505];
int main(){
  cin>>H>>W>>h>>w;
  if(H%h==0 && W%w==0){
    puts("No");
    return 0;
  }
  int M=1000000000-5;
  for(int i=h-1;i<H;i+=h) for(int j=w-1;j<W;j+=w){
    res[i][j]=-M-1;
  }
  for(int i=0;i<H;i+=h) for(int j=0;j<W;j+=w){
    res[i][j]+=M;
  }
  puts("Yes");
  REP(i,H) REP(j,W) printf("%d%c",res[i][j],j==W-1?'\n':' ');
  return 0;
}





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

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

    if(a % 2 == 1 && b % 2 == 1) {
        cout << "Yes";
    } 
    else {
        cout << "No";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  ll a;
  map<ll,ll> up;
  map<ll,ll> down;
  rep(i,n){
    cin >> a;
    up[a-(i+1)]++;
    down[-(i+1+a)]++;
  }
  ll ans = 0;
  for(auto x: up){
    ans += x.second*down[x.first];
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 37884
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

num =[i for i in range(X+1,Y+1) if i>max(x) and i<=min(y)]
if len(num)>=1:
  print('No War')
else:
  print('War')

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	vector<int> dp(3, 0), freq(3);
	scanf("%d %d %d", &freq[0], &freq[1], &freq[2]);
	--n;
	for(int k = 0; k < n; ++k) {
		scanf("%d %d %d", &dp[0], &dp[1], &dp[2]);
		for(int i = 0; i < 3; ++i) {
			int temp = dp[i];
			for(int j = 0; j < 3; ++j) {
				if(i == j)
					continue;
				dp[i] = max(dp[i], temp + freq[j]);
			}
		}
		freq = dp;
	}
	printf("%d", max(freq[0], max(freq[1], freq[2]) ));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int mod=10007,n;
	string s;
	cin>>n>>s;

	int c[1010]={-1};
	rep(i,0,s.size()){
		if(s[i]=='J') c[i]=0;
		if(s[i]=='O') c[i]=1;
		if(s[i]=='I') c[i]=2;
	}

	int dp[1010][1<<3]={};
	dp[0][1]=1;

	rep(i,0,n){
		rep(j,0,1<<3){
			if(dp[i][j]==0) continue;
			rep(k,0,1<<3){
				if((j&k)==0||(1<<c[i]&k)==0) continue;
				dp[i+1][k]=(dp[i+1][k]+dp[i][j])%mod;
			}
		}
	}

	int ans=0;
	rep(i,0,1<<3){
		ans=(ans+dp[n][i])%mod;
	}

	o(ans);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}




int main(){
    ll n;
    cin>>n;
    vector <ll> p(n);
    for(ll i = 0; i < n; i++){
        cin>>p[i];
    }
    ll miss = 0;
    for(ll i =0; i < n; i++){
        if(i+1 != p[i]){
            miss++;
        }
    }
    if(miss == 0 || miss == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Reopard on 2014/05/29.
 */
public class Main {

    static Scanner sc = new Scanner(System.in);
    static char[][] tile;
    static char black_tile = '.', red_tile = '#', player_tile = '@';
    static int W = 0, H = 0;

    public static void main(String args[]) {
        int x = 0, y = 0;
        while ((W = sc.nextInt()) != 0 && (H = sc.nextInt()) != 0) {
            tile = new char[H+2][W+2];
            for (int i = 0; i <= W + 1; i++) tile[0][i] = red_tile;
            for (int i = 1; i <= H; i++) tile[i] = (red_tile + sc.next() + red_tile).toCharArray();
            for (int i = 0; i <= W + 1; i++) tile[H + 1][i] = red_tile;
            outer:
            for (int i = 1; i <= H; i++) {
                for (int j = 1; j <= W; j++) {
                    if (tile[i][j] == player_tile) {
                        x = j;
                        y = i;
                        break outer;
                    }
                }
            }
            /*for (int i = 0; i <= H+1; i++){
                for(int j = 0; j <= W+1; j++){
                    System.out.print(tile[i][j]);
                }
                System.out.println();
            }
            System.out.println(tile[y][x]);*/
            System.out.println(countBlackTile(x, y));
        }
    }

    static int countBlackTile(int x, int y) {
        int[] dx = {0, 1, 0, -1};
        int[] dy = {-1, 0, 1, 0};
        int count = 1;
        if (tile[y][x] == red_tile) return 0;
        else {
            tile[y][x] = red_tile;
            for(int i = 0; i < 4; i++) {
                count += countBlackTile(x + dx[i], y + dy[i]);
            }
        }
        return count;
    }
}

Measured memory_bytes: 33376
Imports System.Collections
Imports System.Collections.Generic
Imports System.Linq
Imports System.xml
Imports System.xml.Linq

Module Module1
	public sub main()

		dim N as string = Console.ReadLine()
    dim L as new List(of string) 
    for i = 0 to convert.toint32(N) - 1
    	L.add(Console.ReadLine())
  	next    
    
  dim cnt as integer = L.groupBy(function(x) x).count
    console.writeLine(cnt)
    
	end sub 
End Module

Measured memory_bytes: 61360
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int n; cin>>n;
	set<string> s;
	fore(i,0,n){
		string ss;cin>>ss; s.insert(ss);
	}
	cout<<SZ(s)<<"\n";
}

Measured memory_bytes: 19188
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int t=1;

    while(t--)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);

        ll a,b,c,k,tempa,tempb,tempc;
        cin>>a>>b>>c>>k;
        tempa=a,tempb=b,tempc=c;
        ll res = 0;
        res += min(a,k);
        a -= min(a,k);
        k -= min(tempa,k);


        b -= min(b,k);
        k -= min(tempb,k);

        res += -1*min(c,k);
        c -= min(c,k);
        k -= min(tempc,k);

        cout<<res;
    }
}


Measured memory_bytes: 3608
a = int(input()) #500
b = int(input()) #100
c = int(input()) #50
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        if (x-500*i-100*j)%50 == 0 and 0<= x-500*i-100*j <= 50*c:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

int n;

int main() {
	while ( ~scanf( "%d", &n ) && ~n ) {
		if ( n == 0 ) {
			printf( "0\n" );
			continue;
		}
		LL ans = 0;
		int now_d = 0;
		while ( n != 0 ) {
			LL b = n % 4;
			for ( int i = 0; i < now_d; i++ ) {
				b *= 10;
			}
			ans += b;
			now_d++;
			n /= 4;
		}
		printf( "%lld\n", ans );

	}
	return 0;
}

Measured memory_bytes: 1196
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
LL N,X,Ans;
LL dz(LL a,LL b){
	if(a==0)return -b;
	LL ret=(b/a)*2*a;
	ret+=dz(b%a,a);
	return ret;
}
int main(){
	scanf("%lld%lld",&N,&X);
	printf("%lld\n",dz(X,N-X)+N);
}


Measured memory_bytes: 128
# N = gets.chomp.to_i
# A = gets.chomp.split.map(&:to_i)
S = gets.chomp.chars
N = S.size

diffs = 0
0.upto(N-1).each do |i|
  if S[i] != S[N-1-i]
    diffs += 1
  end
end

diffs /= 2

p diffs

Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int x,a;
    cin >> x >> a;
    if(x<a) cout << 0 << endl;
    if(x>=a) cout << 10 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ForATCODER
{
    public class Program
    {
        public static void Main(string[] args)
        {
            long[] nk = S2Larray(Console.ReadLine().Split(' '));
            long t = nk[0] - nk[1];
            long t2 = t / nk[1];
            nk[0] -= t2 * nk[1];
            long prev = nk[0];
            while (true)
            {
               long next = Math.Abs(nk[0] - nk[1]);
                if(prev<next)
                {
                    RESULT(prev);
                    return;
                }
                else
                {
                    nk[0] = next;
                    prev = next;
                }
            }
         

        }
        public static bool swap(int x, int y, ref int[] array)
        {

            // check for out of range
            if (array.Length <= y || array.Length <= x) return false;


            // swap index x and y
            var buffer = array[x];
            array[x] = array[y];
            array[y] = buffer;


            return true;
        }
        static int arser(int[] ar ,int search, int[] except)
        {
            for(int i  = 0;i < ar.Length;i++)
            {
                if(ar[i] == search)
                {
                    if (Array.IndexOf(except, i) >= 0) continue;
                    return i;
                }
            }
            return -1;
        }

        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static void RESULT(double res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(long res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(ulong res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] S2Iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
        static long[] S2Larray(String[] src)
        {
            int len = src.Length;
            long[] res = new long[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt64(src[i]);
            }
            return res;
        }
    }
}


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

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = min(b, d) - max(a, c);
	if(ans < 0) ans = 0;
	cout << ans << endl;
}

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>b;
    cout<<a+b/2<<endl;

    

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

ll dp[404][404];
int N;
ll A[404],sum[404];

ll solve(int l,int r){
  if(dp[l][r]<1e16) return dp[l][r];
  if(r-l<=1) return (dp[l][r]=A[l]+A[r]);
  ll res=1e16;
  for(int i=l;i<r;i++){
    ll tmp=solve(l,i)+solve(i+1,r);
    res=min(res,tmp+sum[r+1]-sum[l]);
  }
  return (dp[l][r]=res);
}

int main(){
  rep(i,404) rep(j,404) dp[i][j]=1e16;
  cin>>N;
  rep(i,N){
    cin>>A[i];
    sum[i+1]=sum[i]+A[i];
    dp[i][i]=0;
  }
  cout<<solve(0,N-1)<<endl;
  return 0;
}


Measured memory_bytes: 1536
n=int(input())
 
b=list(map(int,input().split()))
 
a=[0]*(n+1)
a[0]=b[0]
a[1]=b[0]
for i in range(1,n-1):
  a[i+1]=b[i]
  if a[i]>b[i]:
    a[i]=b[i]
 
print(sum(a))

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int a, b;bool ans[100][100];
int m = 100;
signed main(){
  cin>>a>>b;
  rep(i,m)repd(j,m/2+1,m)ans[i][j] = true;
  rep(i,m)ans[i][m/2] = true;
  a--;b--;
  int i = 1, j = 0;
  rep(_,a){
    ans[i][j] = true;
    j += 2;
    if(j == m/2){
      j = 0;i += 2;
    }
  }
  i = 1, j = m/2+1;
  rep(_,b){
    ans[i][j] = false;
    j += 2;
    if(j == m+1){
      j = m/2+1;i += 2;
    }
  }
  cout << "100 100" << endl;
  rep(i,m)rep(j,m)cout << (ans[j][i] ? '.' : '#') << (j == m-1 ? endn : "");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  ll N;
  cin >> N;
  vector<ll> A(5);
  REP(i, 5) { std::cin >> A.at(i); }
  ll min_ = A.at(4);
  REP(i, 4) {
    if (A.at(i) < min_) {
      min_ = A.at(i);
    }
  }
  ll time = 4;
  if (N % min_ > 0) {
    time += N / min_ + 1;
  } else {
    time += N / min_;
  }

  std::cout << time << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int32_t main()
{
	IO_OP;
	
	int n;
	cin >> n;
	cout << fixed << setprecision(10) << (double)(n-n/2)/n << endl;

}





Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

n = int(input())
ans = 0
A = list(input())
B = list(input())
C = list(input())

for i in range(n):
    a = A[i]
    b = B[i]
    c = C[i]
    if a == b and b != c:
        ans += 1
    elif a == c and b != c:
        ans += 1
    elif b == c and a != b:
        ans += 1
    elif a == b and b == c:
        ans += 0
    else:
        ans += 2

print(ans)

Measured memory_bytes: 3064
from sys import stdin
input = stdin.readline

from collections import deque, defaultdict
from copy import deepcopy

MAX = 100000
NIL = -1

# Gはdictで管理する、valueはdeque
G = defaultdict(lambda: deque())
color = [NIL]*MAX

def dfs(r, c):
    S = deque()
    S.append(r)
    color[r] = c
    while S:
        u = S.popleft()
        for v in G[u]:  # Gのvalueはdequeなので、それをvに一つずつ入れていく
            if color[v] == NIL:
                color[v] = c
                S.append(v)

def assign_color():
    id = 1
    for u in range(n):
        if color[u] == NIL:
            dfs(u, id)
            id += 1

n, m = map(int, input().split())

for _ in range(m):
    s, t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)

assign_color()

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    if color[s] == color[t]:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 83388
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int n;
int C[50];
bool used[50];
bool full[50];
set<ll> visited[101];

bool searchFrom();

void dump()
{
	rep(i, n){
		printf("%d", C[i]);
		if(full[i])
			printf("[o]");
		else if(used[i])
			printf("[ ]");
		else
			printf("[x]");
	}
	puts("");
}

bool searchTo(int v, int src)
{
	/*
	ll mask = 0;
	reps(i, src+1, n){
		if(C[i]<=v && !used[i])
			mask |= 1ll << i;
	}
	if(visited[v].find(mask) != visited[v].end())
		return false;
	visited[v].insert(mask);
	*/
	
	reps(i, src+1, n){
		if(!used[i]){
			full[i] = used[i] = true;
			if(C[i] == v){
				if(searchFrom())
					return true;
			}
			else if(C[i] < v && searchTo(v-C[i], i))
				return true;
			full[i] = used[i] = false;
		}
	}
	
	return false;
}

bool searchFrom()
{
	int unused = -1;
	rep(i, n){
		if(!used[i]){
			unused = i;
			break;
		}
	}
	if(unused == -1)
		return true;
	
	rep(i, unused){
		if(full[i]){
			full[i] = false;
			if(searchTo(C[i], i))
				return true;
			full[i] = true;
		}
	}
	return false;
}

int main()
{
	while(scanf("%d", &n), n){
		rep(i, n)
			scanf("%d", &C[i]);
		
		rep(i, 101)
			visited[i].clear();
		sort(C, C+n, greater<int>());
		fill(used, used+n, false);
		fill(full, full+n, false);
		used[0] = full[0] = true;
		puts(searchFrom() ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    cout << ((n >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<b; i++)

template<typename T>
void fillall(T& arr, const T& value) {
    arr = value;
}
template<typename T,typename ARR>
void fillall(ARR& arr, const T& value) {
    for(auto& i:arr) fillall(i,value);
}

char buf[1252];
char s[1252];

int it;
bool calc(){
    if(s[it]=='-'){
        it++;
        return !calc();
    }else if(s[it]=='('){
        it++;
        bool a = calc();
        char c = s[it];
        it++;
        if(c=='-')it++;
        bool b = calc();
        it++;
        if(c=='*')return a&&b;
        if(c=='+')return a||b;
        return (!a) || b;
    }else{
        char c = s[it++];
        return c=='T';
    }
}

int main(){
    while(true){
        fill(buf,buf+1252,'\0');
        scanf("%s",buf);
        if(buf[0]=='#')break;
        int l = strlen(buf);
        int eq = 0;
        REP(i,l)if(buf[i]=='=')eq=i;
        bool ok = true;
        REP(msk,1<<11){
            // f
            REP(i,eq){
                char c = buf[i];
                if('a' <= c && c <= 'k'){
                    int id = c-'a';
                    if(msk >> id & 1){
                        c = 'T';
                    }else{
                        c = 'F';
                    }
                }
                s[i] = c;
            }
            s[eq] = '\0';
            it = 0;
            bool f = calc();
            // g
            FOR(i,eq+1,l){
                char c = buf[i];
                if('a' <= c && c <= 'k'){
                    int id = c-'a';
                    if(msk >> id & 1){
                        c = 'T';
                    }else{
                        c = 'F';
                    }
                }
                s[i-(eq+1)] = c;
            }
            s[l-(eq+1)] = '\0';
            it = 0;
            bool g = calc();

            if(f!=g){
                ok = false; 
                break;
            }
        }
        puts(ok ? "YES" : "NO");
    }
    return 0;
}



Measured memory_bytes: 3080
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Io.ReadList<long>(devide: ' ');
            var N = NM[0];
            var M = NM[1];

            var min = Math.Min(N, M);
            var max = Math.Max(N, M);

            if (min == 1)
            {
                if (max == 1)
                {
                    Console.WriteLine(1);
                }
                else
                {
                    Console.WriteLine(max - 2);
                }
            }
            else
            {
                var output = (min - 2) * (max - 2);
                Console.WriteLine(output);
            }
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }

        class Io
        {
            public static string Read()
            {
                return Console.ReadLine();
            }

            public static IEnumerable<string> ReadRepeat(int count)
            {
                return Enumerable.Range(0, count).Select(_ => Read());
            }

            public static T Read<T>()
            {
                return (T)Convert.ChangeType(Read(), typeof(T));
            }

            public static IEnumerable<T> ReadRepeat<T>(int count)
            {
                return Enumerable.Range(0, count).Select(_ => Read<T>());
            }

            public static string[] ReadList(char devide = ' ')
            {
                return Read().Split(devide);
            }

            public static T[] ReadList<T>(char devide = ' ')
            {
                return ReadList(devide)
                    .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                    .ToArray();
            }

            public static IEnumerable<T[]> ReadListRepeat<T>(int count, char devide = ' ')
            {
                return Enumerable.Range(0, count).Select(_ => ReadList<T>(devide));
            }

            public static void Write(string value)
            {
                Console.WriteLine(value);
            }
        }
    }
}


Measured memory_bytes: 13396
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<string> S(N);
    rep(i,N) cin >> S[i];
    string T; cin >> T;

    vector<pair<string, int>> A(N,make_pair("",0));
    rep(i,N) {
        A[i].second = i;
        rep(j,S[i].size()) {
            if (S[i][j]=='?') A[i].first += 'a';
            else A[i].first += S[i][j];
        }
    }
    A.emplace_back(T,N);
    sort(all(A));
    int ansM;
    rep(i,N+1) if (A[i] == make_pair(T,N)) ansM = i+1;

    vector<pair<string, int>> B(N,make_pair("",0));
    rep(i,N) {
        B[i].second = i;
        rep(j,S[i].size()) {
            if (S[i][j]=='?') B[i].first += 'z';
            else B[i].first += S[i][j];
        }
    }
    B.emplace_back(T,-1);
    sort(all(B));
    int ansm;
    rep(i,N+1) if (B[i] == make_pair(T,-1)) ansm = i+1;

    for (int i = ansm; i <= ansM; i++) {
        if (i == ansm) cout << i;
        else cout << " " << i;
    }
    cout << endl;
}

Measured memory_bytes: 2408
N = int(input())
S = input()
data = set()
xd,yd = set(),set()
for i in range(N-2):
  x = S[i]
  if x in xd:
    continue
  else:
    xd.add(x)
    yd = set()
  for j in range(i+1,N-1):
    y = S[j]
    if y in yd:
      continue
    else:
      yd.add(y)
    for k in range(j+1,N):
      z = S[k]
      data.add(x+y+z)
print(len(data))

Measured memory_bytes: 41196
n=int(input())
a=[int(i) for i in input().split()]
a1={}
for i in range(n):
  a1[a[i]]=i+1
a2=sorted(a1.items(),key=lambda x:x[1])
a2.sort()
a3=[i[1] for i in a2]
print(*a3)


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

using namespace std;

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

	int n;
	cin >> n;
	int x = n, d = 0;
	while (x) {
		x /= 10;
		++d;
	}
	int ans = 0;
	for (int i = 1, mul = 1; i <= d; i += 2, mul *= 100) {
		if (i == d) {
			ans += n - mul + 1;
		}
		else {
			ans += 9 * mul;
		}
	}
	cout << ans;
			
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int a;
    rep1(i,6){
        int b;
        cin >> b;
        if(b == 0)a = i;
    }
    cout << a << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <set>
using namespace std;
string s;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cin>>s;
	if ((int)s.length()<26)
	{
		for (char c='a';c<='z';++c)
		{
			if (s.find(c)==-1)
			{
				cout<<s<<c<<endl;
				return 0;
			}
		}
	}
	else
	{
		set <char> x;
		while (!s.empty())
		{
			char c=s.back();
			x.insert(c);
			s.pop_back();
			if (c!=*x.rbegin())
			{
				cout<<s<<*x.upper_bound(c)<<endl;
				return 0;
			}
		}
		cout<<"-1\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

class Graph{
	private:
	int V;
	vvp List;
	vi DIJ(int s){
		priority_queue<P> que;
		vi d(V,inf);
		d[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(int i=0;i<List[v].size();i++){
				int F=List[v][i].first,S=List[v][i].second;
				if(d[F]>d[v]+S){
					d[F]=d[v]+S;
					que.push(P(-d[F],F));
				}
			}
		}
		return d;
	}
	public:
	Graph(int v){
		V=v;
		List=vvp(v);
	}
	void add_edge(int s,int t,int c){
		List[s].push_back(P(t,c));
		List[t].push_back(P(s,c));
	}
	int solve(vi a){
		vi d(V,inf);
		for(int i=0;i<a.size();i++){
			vi D=DIJ(a[i]-1);
			for(int j=0;j<V;j++) d[j]=min(d[j],D[j]);
		}
		double M=0;
		for(int i=0;i<V;i++) for(int j=0;j<List[i].size();j++){
			int v=List[i][j].first,l=List[i][j].second;
			M=max(M,d[i]+((double)d[v]-d[i]+l)/2);
		}
		return (int)(M+0.5+eps);
	}
};

int n,m,k;
vi a;

int main(){
	cin>>n>>m>>k;
	a=vi(k);
	Graph g(n);
	for(int i=0;i<m;i++){
		int s,t,c;
		cin>>s>>t>>c;
		g.add_edge(s-1,t-1,c);
	}
	for(int i=0;i<k;i++) cin>>a[i];
	cout<<g.solve(a)<<endl;
}

Measured memory_bytes: 6044
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,i;
	string str;
	set<string> S;
	cin >> n;
	for (i = 0;i < n;i++) {
		cin >> str;
		S.insert(str);
	}
	cout << S.size() << endl;
}

Measured memory_bytes: 19156
n,m=map(int,input().split())

li = [[0]*n for _ in range(n)]


for i in range(m):
    a,b=map(int,input().split())
    li[a-1][b-1]=1
    li[b-1][a-1]=1
  

def dfs(v,used):
    if not False in used:
        return 1


    ans=0
    for i in range(n):
        if not li[v][i]:
            continue
        elif used[i]:
            continue

        else:
            used[i]=True
            ans+=dfs(i,used)
            used[i]=False

    return ans

used=[False]*n
used[0]=True
print(dfs(0,used))

    



Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
char str[10];
int main()
{
	cin>>str;
	if((str[0]=='A'&&str[1]=='A'&&str[2]=='A')||
	(str[0]=='B'&&str[1]=='B'&&str[2]=='B'))
		puts("No");
	else
		puts("Yes");
    return 0;
}

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

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

using namespace std;

typedef pair<int, int> P;

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

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

    string s;
    cin >> s;

    int w, b;
    w = b = 0;
    for(char c : s){
        if(c == 'B'){
            b++;
        }else{
            w++;
        }
    }

    int ans = 0;
    int pos = 0;
    rep(i, SZ(s)){
        if(s[i] == 'B'){
            continue;
        }
        ans += i - pos;
        pos++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    string st;
    cin>>st;
    REP(i,st.size()-1){
        if(st[i]==st[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = str(input())
cnt = 0
for i in range(n):
    if s[i]=='R':
        cnt += 1
#print(cnt)
cnt_r = 0
for i in range(cnt):
    if s[i]=='R':
        cnt_r += 1
#print(cnt_r)
print(cnt - cnt_r)


Measured memory_bytes: 9352
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
string to_string_keta(const long long int l, const int keta) {
	ostringstream oss;

	oss << std::setw(keta) << std::setfill(' ') << l;

	return oss.str();
}

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<vector<int>>vs(N,vector<int>(N));
		int nx = N / 2-1;
		int ny = N / 2;
		for (int num = 1; num <= N*N; ++num) {
			nx += 1;
			ny += 1;
			nx %= N;
			ny %= N;
			while (1) {
				if (vs[ny][nx]) {

					nx += N - 1;
					ny += 1;
					nx %= N;
					ny %= N;
				}
				else {
					vs[ny][nx]=num;
					break;
				}
			}
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cout << to_string_keta(vs[i][j], 4);
				if (j == N - 1)cout << endl;
				
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <vector>

using namespace std;

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

    while (1)
    {
        C -= B;
        if (C <= 0)
        {
            cout << "Yes" << endl;
            exit(0);
        }
        A -= D;
        if (A <= 0)
        {
            cout << "No" << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 3636
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

n, m, v, p = map(int, readline().split())
a = np.array(read().split(), np.int64)
a.sort()


def check(i):
    if n - i <= p:
        return True
    x = a[i] + m
    y = np.zeros(n, np.int64)
    y = x - a
    y = np.minimum(y, m)
    y[n - p + 1:] = m
    if (y < 0).any():
        return False
    y[i] = 0
    next = y.sum()
    return next >= m * (v - 1)


low = -1
high = n - 1
while low + 1 < high:
    mid = (low + high) // 2
    if check(mid):
        high = mid
    else:
        low = mid
print(n - high)


Measured memory_bytes: 18560
parseInt(x) = parse(Int128, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
using Primes
function main()
  N = parseInt(readline())
  A = parseMap(split(readline()))

  ma = A[1] ; B = zeros(Int128,N)
  for i in 2:N
    if A[i] > ma
      ma = A[i]
      B[i] = 0
    else
      B[i] = ma - A[i]
    end
  end
  println(sum(B))
end
main()


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

/*
int main() {
    int N;
    std::cin >> N;
    std::cout << std::pow(N,3.0) << std::endl;
    return 0;
}


int main(){
    int N;
    int satis=0;
    std::cin >> N;
    int A[N], B[N], C[N-1];
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }
    for(int i=0; i<N; i++){
        std::cin >> B[i];
    }
    for(int i=0; i<N-1; i++){
        std::cin >> C[i];
    }

    for(int i=0; i<N-1; i++){
        satis+=B[i];
        if(A[i+1]==A[i]+1){
            satis+=C[A[i]-1];
        }
    }
    satis += B[N-1];
    std::cout << satis << std::endl;
    return 0;
}
 */

int main(){
    int N;
    std::cin >> N;
    int sum_A = 0;
    int A[N],B[N-1];
    for(int i=0; i<N-1; i++){
        std::cin >> B[i];
    }
    A[0]=B[0];
    A[1]=B[0];
    for(int i=1; i<N-1; i++){
        A[i]=std::min(A[i], B[i]);
        A[i+1]=B[i];
    }

    for(int i=0; i<N; i++){
        sum_A += A[i];
    }
    std::cout << sum_A << std::endl;
}

Measured memory_bytes: 256
n, l = gets.chomp.split(" ").map(&:to_i)

array = Array.new
n.times do |i|
  array << (l + (i+1) -1)
end

array_a = array.map do |a|
  a.abs
end

index = array_a.index(array_a.min)

array.delete_at(index)

result = array.inject(:+)

puts result

Measured memory_bytes: 1788