akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9

vector<ll> daikus(vector<vector<mp> > &g, ll s){
	ll n = g.size();
	vector<bool> used(n,false);
	vector<ll> c(n,inf);
	priority_queue<mp,vector<mp>,greater<mp> > q;
	q.push(mp(0,s) );
	while(!q.empty()){
		mp now = q.top();
		q.pop();
		ll nn = now.second;
		ll cost = now.first;
		if(used[nn])continue;
		//cout<<s<<' '<<nn<<' '<<cost<<endl;
		used[nn] = true;
		c[nn] = cost;
		for(int i=0;i<g[nn].size();i++){
			ll next = g[nn][i].second;
			ll nc = g[nn][i].first;
			if(used[next])continue;
			q.push(mp(cost+nc,next) );
		}
	}

	return c;
}


int main(){
    while(1){
	int n;
	cin>>n;
	if(n==0)break;
	vector<ll> p(n-1);
	vector<ll> d(n-1);
	vector<ll> deg(n,0);
	ll sum = 0;
	for(int i=0;i<n-1;i++)cin>>p[i];
	for(int i=0;i<n-1;i++)cin>>d[i];
	vector<vector<mp> > g(n);
	for(int i=0;i<n-1;i++){
		p[i]--;
		deg[i+1]++;
		deg[p[i]]++;
		g[i+1].push_back(mp(d[i],p[i]) );
		g[p[i]].push_back(mp(d[i],i+1) );
		sum += d[i];
	}
	/*for(int i=0;i<n;i++)cout<<deg[i]<<endl;
	for(int i=0;i<n;i++){
		cout<<"index "<<i<<": ";
		for(int j=0;j<g[i].size();j++)cout<<g[i][j].second<<' ';
		cout<<endl;
	}*/
	for(int i=0;i<n;i++) if(deg[i]!= 1){
		for(int j=0;j<g[i].size();j++){
			if(deg[g[i][j].second] != 1){
			    //cout<<i<<' '<<j<<' '<<g[i][j].first<<endl;
			    sum += g[i][j].first;
			}
		}
	}
	//cout<<"OK"<<endl;
	vector<vector<ll> > A(n);
	for(int i=0;i<n;i++)A[i] = daikus(g,i);
	//cout<<"NONO"<<endl;
	ll m = 0;
	for(int i=0;i<n;i++){
	    	if(deg[i]==1)continue;
		for(int j=0;j<n;j++){
		    if(deg[j]==1)continue;
			m = max(m,A[i][j]);
		}
	}
	//cout<<sum<<endl;
	//cout<<m<<endl;
	cout<<sum-m<<endl;
    }
	return 0;
}



Measured memory_bytes: 7972
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
  int n;
	cin>>n;
	ll ans=0;
	vector<ll>a(n);
	rep(i,n)cin>>a[i],ans+=a[i];
	map<ll,ll>mp;
	rep(i,n)mp[a[i]]++;
	int q;
	cin>>q;
	while(q--){
		ll b,c;
		cin>>b>>c;
		ll x=mp[b];
		ans+=x*(c-b);
		mp[b]-=x;
		mp[c]+=x;
		cout<<ans<<"\n";
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

int main() {
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;

	if (s == u)
		--a;
	else
		--b;

	cout << a << " " << b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	auto city = vector<tuple<int, int, int>>(m);
	for(auto i = 0; i < m; ++i){
		cin >> get<1>(city[i]) >> get<0>(city[i]);
		get<2>(city[i]) = i;
	}
	sort(city.begin(), city.end());
	auto id = vector<int>(n + 1, 0);
	for(auto i = 0; i < m; ++i){
		get<0>(city[i]) = ++id[get<1>(city[i])];
	}
	sort(city.begin(), city.end(),
		[](tuple<int, int, int>& a, tuple<int, int, int>& b) -> bool{
			return get<2>(a) < get<2>(b);
		}
	);
	for(auto i = 0; i < m; ++i){
		cout << setfill('0') << setw(6) << right << get<1>(city[i]);
		cout << setfill('0') << setw(6) << right << get<0>(city[i]);
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 520000
using namespace std;
int Next[N],h[N],v[N];
int tot,p[N],siz[N],dep[N],flag;
int f[N];
int n,m;
long long k,o,ans,OO;
int add(int x,int y){
	tot++;
	Next[tot]=h[x];
	v[tot]=y;
	h[x]=tot;
}
int dfs(int x,int fa,int c){
	p[x]=c;
	siz[x]=1;
	dep[x]=dep[fa]+1;
	for(int i=h[x];i;i=Next[i]){
		if(v[i]==fa)continue;
		if(p[v[i]]&&((dep[x]-dep[v[i]])%2==0)){
			flag=1;
			continue;
		}
		if(p[v[i]])continue;
		dfs(v[i],x,c);
		siz[x]+=siz[v[i]];
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++){
		if(p[i]==0){
			flag=0;
			dfs(i,0,i);
			if(siz[i]==1)k++;
			else o++;
			f[i]=flag;
			OO+=flag;
		}
	}
	ans+=k*n;
	for(int i=1;i<=n;i++){
		if(p[i]==i)if(siz[i]!=1){
			if(f[i])ans+=o;
			else ans+=2*o-OO;
		}
		if(p[i]==i)if(siz[i]==1)ans+=n-k;
	}
	printf("%lld\n",ans);
} 

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,N;
  string s;  
  cin>>n>>s;
  N = s.length();
  rep(i,N){
  int ascii = int(s.at(i))+n;
  while(ascii>90){
    ascii = 64 + ascii % 90;
  }
  cout<<char(ascii);
  }
}


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

const int N = 100 * 1000 + 5;

int a[N];
int cnt[N];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] = -a[i];
	}
	sort(a, a + n);
	for (int i = n - 1; i >= 0; i--) {
		a[i] = -a[i];
		cnt[i] = cnt[i + 1] + 1;
		if (a[i] != a[i + 1]) {
			cnt[i] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		if (a[i + 1] < i + 1) {
		//	cout << i << endl;
			if ((a[i] ^ i ^ 1) & 1) {
				cout << "First";
			}
			else {
				cout << "Second";
			}
			return 0;
		}
		if (a[i + 1] == i + 1) {
			if ((a[i] ^ i ^ 1) & 1) {
				cout << "First";
				return 0;
			}
			if ((cnt[i + 1] ^ i ^ a[i + 1] ^ 1) & 1) {
				cout << "Second";
			}
			else {
				cout << "First";
			}
			return 0;
		}
	}
	
/*	if (a[n - 1] & 1) {
		cout << "Second";
	}
	else {
		cout << "First";
	}*/
	return 0; 
}

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

using namespace std;
using ll =long long;
using db = double;

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

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
const int mod = 1e9 + 7;

//ここから書き始める
int main()
{
	cout << setprecision(10);
	int n;
	cin >> n;
	int x ;
	cin >> x;
	vector<ll> m(n);
	rep(i,n) cin >> m[i];
	ll ans = 0 ;
	ll min = 10000;
	rep(i,n){
		ans ++;
		chmin(min,m[i]);
		x -= m[i];
	}
//	che(x,'x');
	ans += x / min ;
	cout << ans << endl;

	
}


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

int rel_c_c( double, double, double, double, double, double );

int main( void ) {
	int n;
	double xa, ya, ra, xb, yb, rb;

	for ( scanf( "%d", &n ); n--; printf( "%d\n", rel_c_c( xa, ya, ra, xb, yb, rb ) ) )
		scanf( "%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb );

	return 0;
}

int rel_c_c( double x1, double y1, double r1, double x2, double y2, double r2 ) {
	double d = hypot( x1 - x2, y1 - y2 );

	if ( d > r1 + r2 )
		return 0;
	if ( fabs( r1 - r2 ) <= d && d <= r1 + r2 )
		return 1;
	if ( d < fabs( r1 - r2 ) )
		return r1 >= r2 ? 2 : -2;
}

Measured memory_bytes: 652
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

vector<vector<P>> G(100005);
vector<ll> dist(100005,-1);
void dfs(int v){
  for(auto nv: G[v]){
    if(dist[nv.first] != -1) continue;
    dist[nv.first] = dist[v] + nv.second;
    dfs(nv.first);
  }
}

int main(){
  int N;
  cin >> N;
  for(int i=0; i<N-1; i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back(make_pair(b,c));
    G[b].push_back(make_pair(a,c));
  }
  int Q,K;
  cin >> Q >> K;
  K--;
  dist[K] = 0;
  dfs(K);
  for(int i=0; i<Q; i++){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    cout << dist[x] + dist[y] << endl;
  }
  return 0;
}


Measured memory_bytes: 11136
from bisect import bisect_left as bl
from bisect import bisect_right as br

n = int(input())

gpa = []
for _ in range(n):
    gpa.append(float(input()))

gpa_s = sorted(gpa)

for g in gpa:
    less = bl(gpa_s, g)
    more = br(gpa_s, g)
    print(less * 3 + (more-less-1))



Measured memory_bytes: 9600
#include <stdio.h>

int main(void){
	int prime[100001]={0};
	
	for(int i=2;i<=100001;i++){
		if(prime[i] == 0){
			prime[i] = 1;
			for(int j=i+i;j<=100001;j+=i){
				prime[j] = -1;
			}
		}
	}
	
	int c[100002]={0};
	for(int i=1;i<=100001;i+=2){
		if(prime[i]==1 && prime[(i+1)/2]==1)c[i]=1;
	}
	
	for(int i=1;i<=100002;i++){
		if(c[i]>=1)c[i] = c[i-1]+1;
		else c[i] = c[i-1];
	}
	
	int Q;
	scanf("%d",&Q);
	for(int i=0;i<Q;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		printf("%d\n",c[r]-c[l-1]);
	}
	return 0;
}

Measured memory_bytes: 1280
n = int(input())
N = list(map(int, input().split()))
cnt = 0
for i in range(0, len(N)-1):
    syou = N[i]
    syounum = i
    for j in range(i+1,len(N)):
      if syou > N[j]:
        syounum = j
        syou = N[j]
    if syounum != i:
      cnt+=1
      tmp = N[i]
      N[i] = N[syounum]
      N[syounum] = tmp
if cnt <= 1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll N;
    string a,b,c;
    cin >> N >> a >> b >> c;
    ll cnt = 0;

    
    for(ll i = 0; i < N; i++)
    {
        if(a[i] == b[i] && c[i] == b[i] && a[i] == c[i]){
            continue;
        }
        else if(a[i] == b[i] || c[i] == b[i] || a[i] == c[i]) {
            cnt++;
        }
        else{
            cnt += 2;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    map<char,int>m;
    rep(i,s.size()){
        m[s[i]]++;
        if(m[s[i]]==2)return cout<<"no"<<"\n",0;
    }
    cout<<"yes"<<"\n";
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int k;
std::string sss;

int min(int a,int b) {return a<b?a:b;}

int main() {
	read(k);
	std::cin>>sss;int len=sss.length();
	for(int i=0;i<=min(k-1,len-1);++i) {
		printf("%c",sss[i]);
	}
	if(len>k) puts("...");
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
bool is_prime(int n){
      if(n<=1)return false;
      for(int i=2;i*i<=n;i++){
            if(n%i==0)return false;
      }
      return true;
}
int main(){
      int ans=0;
      int n,a;
      cin>>n;
      REP(i,n){
            cin>>a;
            if(is_prime(a))ans++;
      }
      cout<<ans<<endl;
}

Measured memory_bytes: 1160
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
a = Counter(A)
b = list(a.keys())
B = [0]*(N+1)
for i in b:
  B[i] = int(a[i]*(a[i]-1)/2)
total = sum(B)

for i in range(N):
  k = A[i]
  change = (a[k]-1)*(a[k]-2)/2
  print(int(total-B[k]+change))

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

int main() {
	
	int N, T;
	cin >> N >> T;
	
	int minimo = 30000;
	
	for (int i = 0; i < N; i++) {
		
		int ci, ti;
		cin >> ci >> ti;
		
		if (ti <= T) minimo = min(minimo,ci);
		
	}
	
	if (minimo != 30000) cout << minimo << endl;
	else cout << "TLE" << endl;
	
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int mp[10][10];
int n , m , k;
int ans = 0;
void dfs(int isR , int step)
{
    if (isR){
        if (step == n + 1){
            dfs (0 , 1);
            return ;
        }
        int temp[10];
        for (int i = 1 ; i <= m ; i++) temp[i] = mp[step][i] , mp[step][i] = 0;
        dfs (isR,step + 1);
        for (int i = 1 ; i <= m ; i++) mp[step][i] = temp[i];
        dfs(isR, step + 1);
    }
    else {
        if (step == m + 1){
            int cnt = 0;
            for (int i = 1 ; i <= n ; i++)
                for (int j = 1 ; j <= m ; j++)
                    cnt += mp[i][j];
            ans += (cnt == k);
            return ;
        }
        int temp[10];
        for (int i = 1 ; i <= n ; i++) temp[i] = mp[i][step] , mp[i][step] = 0;
        dfs (isR,step + 1);
        for (int i = 1 ; i <= n ; i++) mp[i][step] = temp[i];
        dfs(isR, step + 1);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m >> k;
    for (int i = 1 ; i <= n ; i++){
        for (int j = 1 ; j <= m ; j++){
            char v; cin >> v;
            if (v == '#') mp[i][j] = 1;
        }
    }
    dfs(1 , 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<pair<int, int>> v(N);
    int X, L;
    for(int i = 0; i < N; i++){
        cin >> X >> L;
        v[i] = make_pair(X + L, X - L);
    }

    sort(v.begin(), v.end());

    int ans = 0;
    int end = -2e9;
    for(int i = 0; i < N; i++){
        auto temp = v[i];
        int tempStart = temp.second;
        int tempEnd = temp.first;
        if(tempStart >= end){
            ans++;
            end = tempEnd;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(){

	int a,b;

	int s = scanf("%d %d", &a,&b);
	if(s < 2){
		exit(1);
	}

	if(a * b % 2 == 0){
		printf("Even");
	}

	else{
		printf("Odd");
	}
	
  return 0;
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }

    int ans = 0;

    int flag = 0;

    rep(i,n){
        if(a[i] != i){
            flag = 0;
        }else{
            if(flag == 1){
                flag = 0;
            }else{
                ans++;
                flag = 1;
            }
        }
    }

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




Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
ll K,A,B;
ll k1;

int main() {
    cin >> K >> A >> B;
    if ((A+1 >= B) or ( K < A+1 )){
        cout << K + 1 << endl;
        return 0;
    }

    ll ans = 0;
    ll K2 = K - (A + 1);
    ans = B;
    ll count;
    if (K2 % 2 == 0){
        ans += (K2 / 2) * (B-A);
    }else{
        ans += (K2 / 2) * (B-A) + 1;
    }

    cout << ans << "\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M,K; cin >> N >> M >> K;
    vector<ll> A(N),B(M);
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];
    
    ll val = 0;
    int b = 0;
    rep(i,M) {
        if (val+B[i] <= K) {
            val += B[i];
            b++;
        } else break;
    }
    ll ans = b;
    rep(i,N) {
        val += A[i];
        while (b > 0 and val > K) {
            val -= B[b-1];
            b--;
        }
        if (val <= K) chmax(ans,i+1+b);
    }

    cout << ans << ln;
}


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

#define lli long long int
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define INF 1000000007
#define endl "\n"
#define max(aa, bb) (aa > bb ? aa : bb)
#define min(aa, bb) (aa < bb ? aa : bb)

int main(){
	lli n;
	string x;
	map <string ,lli> m;
	cin>>n;
	for (lli i = 0; i < n; i++){
		cin>>x;
		m[x]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;


}

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

using namespace std;

int N;

int A[25], B[25], C[25];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}
	for (int i = 1; i <= N; i++) {
		cin >> B[i];
	}
	for (int i = 1; i <= N - 1; i++) {
		cin >> C[i];
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		ans += B[A[i]];
	}

	for (int i = 1; i <= N - 1; i++) {
		if (A[i] + 1 == A[i + 1]) { ans += C[A[i]]; }
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a;
    cin >> a;
    cout << "ABC" << a;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)

S = 0
for i in range(len(A)-1):
    S+=abs(A[i+1]-A[i])
    
for i in range(1,N+1):
    ans = S + abs(A[i+1]-A[i-1]) - abs(A[i+1]-A[i]) - abs(A[i]-A[i-1])
    print(ans)

Measured memory_bytes: 14048
using System;

class Modulo
{
    private const int MOD = 1000000007;
    private readonly int[] m_facs;
    public int Mul(int a, int b) => (int)(Math.BigMul(a, b) % MOD);
    public Modulo(int n)
    {
        m_facs = new int[n + 1];
        m_facs[0] = 1;
        for (int i = 1; i <= n; ++i)
            m_facs[i] = Mul(m_facs[i - 1], i);
    }
    public int Fac(int n) => m_facs[n];
    public int Pow(int a, int m)
    {
        switch (m)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, m / 2);
                int p2 = Mul(p1, p1);
                return ((m % 2) == 0) ? p2 : Mul(p2, a);
        }
    }
    public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2));
    public int Ncr(int n, int r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        int res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var a = new Modulo(10);
        Console.WriteLine(a.Pow(k, n));
    }
}



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

void solve() {
    int a, b, c, d;
    long long n;
    cin >> a >> b >> c >> d;
    cin >> n;
    long long min_abc = min(c, min(4 * a, 2 * b));
    long long ans = 0;
    if (d < 2 * min_abc) {
        ans = d * (n / 2);
        if (n % 2 != 0) {
            ans += min_abc;
        }
    } else {
        ans = min_abc * n;
    }
    cout << ans << endl;
}

int main() {
//    freopen("/Users/simon/Downloads/test.in", "r", stdin);
    //    freopen("/Users/simon/Downloads/test.out", "w", stdout);
    solve();
}


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

int main() {
  string s;
  cin >> s;
  int s_length = 0;
  string word = "keyence";
  int i;
  if (s.length() >= word.length()) {
    for (i = 0; i < word.length(); i++) {
      if (s.at(i) != word.at(i)) {
        break;
      }
      s_length++;
    }
    if (s_length != word.length()) {
      int count = word.length() - s_length;
      int diff = s.length() - word.length();
      for (i = s.length() - 1; i > s.length() - count - 1; i--) {
        if (s.at(i) != word.at(i - diff)) {
          break;
        }
        s_length++;
      }
    }
  }
  cout << (s_length == word.length() ? "YES" : "NO") << endl;
  return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(100005);
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[x]++;
	}
	int even = 0, all = 0;
	for(int i = 1; i <= 100000; i++) {
		if(a[i] > 0) all++;
		if(a[i] % 2 == 0 && a[i] > 0) even++;
	}
	cout << (even % 2 == 0 ? all : all - 1) << endl;
	return 0;	
}

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

int main(){
    string s, abc="abcdefghijklmnopqrstuvwxyz";
    cin >> s;
    map<char, int> m;
    for(int i=0;i<s.length();i++){
        m[s[i]]++;
    }
    bool ans=false;
    for(int i=0;i<abc.length();i++){
        if(m[abc[i]]==0){
            cout << abc[i] << endl;
            ans = true;
            break;
        }
    }
    if(!ans){
        cout << "None" << endl;
    }
}

Measured memory_bytes: 512
N, K = map(int,input().split())
arr = list(map(int,input().split()))
ans = float('inf')
for i in range(N-K+1):
  if (arr[i+K-1]<=0)&(arr[i]<=0):
    path = abs(arr[i])
  elif (arr[i+K-1]>0)&(arr[i]<=0):
    path  = arr[i+K-1]-arr[i] + min(abs(arr[i+K-1]),abs(arr[i]))
  else:
    path  = abs(arr[i+K-1])
  
  ans = min(path,ans)

print(ans)

Measured memory_bytes: 14844
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define ll long long
using namespace std;

const int N=305;
const int M=200005;
const ll inf=1000000000000000ll;

struct E{
	int x,y,w;
	E(){}
	E(int x,int y,int w):x(x),y(y),w(w){}
}mem[M];
struct node{
	int to,w;
	node(){}
	node(int to,int w):to(to),w(w){}
};
int n,m,x,y,w,r1,r2;
ll ans;
int mp[N][N],f[N];
ll dis[N];
bool vis[N];
vector<node> lev[N];
queue<int> q;

bool cmp(E a,E b){
	return a.w<b.w;
}

int find(int k){
	if (f[k]!=k) f[k]=find(f[k]);
	return f[k];
}

void add(int x,int y,int w){
	lev[x].push_back(node(y,w));
	lev[y].push_back(node(x,w));
}

void bfs(){
	int j,k,u;
	memset(vis,0,sizeof(vis));
	for (j=1;j<=n;j++) dis[j]=inf;
	q.push(x); dis[x]=0;
	while (!q.empty()){
		k=q.front(); q.pop(); vis[k]=0;
		for (j=0;j<lev[k].size();j++){
			u=lev[k][j].to;
			if (dis[k]+lev[k][j].w<dis[u]){
				dis[u]=dis[k]+lev[k][j].w;
				if (!vis[u]){
					vis[u]=1; q.push(u);
				}
			}
		}
	}
}

int main(){
	int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++){
			scanf("%d",&mp[i][j]);
			if (i==j||i>j) continue;
			mem[++m]=E(i,j,mp[i][j]);
		}
	sort(mem+1,mem+1+m,cmp);
	for (i=1;i<=n;i++) f[i]=i;
	for (i=1;i<=m;i++){
		x=mem[i].x; y=mem[i].y; w=mem[i].w;
		r1=find(x); r2=find(y);
		if (r1!=r2){
			f[r2]=r1;
			add(x,y,w); ans+=1ll*w;
			continue;
		}
		bfs();
		if (dis[y]==1ll*w) continue;
		if (dis[y]<1ll*w){
			printf("-1\n");
			return 0;
		}
		add(x,y,w); ans+=1ll*w;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,string>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll n,m,k;
  cin>>n;
  string s[n];
  vector<string> ls,rs;
  vector<pii> bs;
  for (ll i = 0; i < n; ++i){
    cin >> s[i];
    stack<ll>st;
    x = 0;
    c = 0;
    for(auto it : s[i]){
       if(it=='('){
        st.push(it);
        c++;
       }
       else if(st.empty() and it==')'){
        x = 1;
        c--;
       }
       else {
        c--;
        st.pop();
       }
    }
    if(x==0 and st.size())
    ls.pb(s[i]);
    else if(x==1 and st.size()){
     bs.pb({c,s[i]});
    }
    else if(x==1)
     rs.pb(s[i]);
   
  }
  sort(bs.begin(), bs.end());
 
  string t;
  while(sz(ls)){
    t+=ls.back();
    ls.pop_back();
  }
  while(sz(bs)){
    t+=bs.back().S;
    bs.pop_back();
  }
  while(sz(rs)){
    t+=rs.back();
    rs.pop_back();
  }
   stack<char>st;

  for(auto &it : t){
       if(it=='('){
        st.push(it);
        
       }
       else if(st.empty() and it==')'){
        cr("No");
       }
       else st.pop();
    }
    
    if(st.size()){
         cr("No");
    }
    cr("Yes");


  
 
}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //int T;cin >> T;while (T--)
  solve();
  return 0;
}


Measured memory_bytes: 68632
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    int A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;
void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    unordered_map<ll,ll> ump;
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    vector<ll> sum(n+1,0);
    rep(i,n){
        sum[i+1] = (sum[i] + a[i]) % k;
    }
    // print(sum);
    // rep(i,n)sum[i]--;
    rep(i,min(n,k-1)){
        ump[sum[i+1]]++;
    }
    ll res = 0;
    rep(i,n){
        res += ump[sum[i]];
        if(i+k <= n)ump[sum[i+k]]++;
        ump[sum[i+1]]--;
        // print(i,res);
    }
    cout << res << endl;
}

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

int main(){
	int n;
	vector<int> num;
	cin >> n;
	for (int i = 0; i < n-1; i++){
		int a;
		cin >> a;
		num.push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < n-2; i++ )
	{
		ans += min(num[i],num[i+1]);
	}
	ans+=num[0]; ans+=num[n-2];
	cout << ans;
	
} 

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i,j=0,N,l[100000],c[100000],max_c=0;
	
	scanf("%d",&N);
	for(i=0;i<=N-1;i++)
	{
		scanf("%d",&l[i]);
	}
	c[0]=1;
	for(i=1;i<=N-1;i++)
	{
		if(l[i]!=l[i-1]) c[j]++;
		else
		{
			j++;
			c[j]=1;
		}
	}
	if(j>=2)
	{
	   for(i=0;i<=j-2;i++)
	   {
		   if(max_c<c[i]+c[i+1]+c[i+2]) max_c=c[i]+c[i+1]+c[i+2];
	   }
	}
	else if(j=1) max_c=c[0]+c[1];
	else max_c=c[0];
	printf("%d\n",max_c);
	return 0;
}

Measured memory_bytes: 2372
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <functional>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
//const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){cout << a << " " << b << " " << c << endl;}
#define INT_MAX 1<<30;
const int MAX = 1020000;
const double EPS = 1e-6;
const int mod = 1e9+7;

int main(){
    ll a,b; cin >> a >> b;
    cout << a/__gcd(a,b)*b << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
j = -1
res = 0
for  i in a:
    if i - 1 == j:
        res += c[j-1]
    j = i
print(res+sum(b))


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

int main() {

	    long long a,b,c,d;
	    cin>>a>>b>>c;
	    if((a+b+c)==17){cout<<"YES"<<endl;
	   
	    }
	    else cout<<"NO"<<endl;
	       
	  

	
	
}

Measured memory_bytes: 256
#UnionFind木
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n
    #parents属性は根でない場合は自分の親の番号だが、
    #根の場合は負の数で、絶対値がグループのメンバ数を表す

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
            x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def nums(self,x):
    return abs(self.parents[self.find(x)])

N, M = map(int, input().split())

A = [0]*M
B = [0]*M
for i in range(M-1,-1,-1):
  A[i],B[i] = map(int, input().split())
  A[i] -= 1
  B[i] -= 1

uf = UnionFind(N)
total = N*(N-1)//2
ans = [total]

for i in range(M):
  if uf.same(A[i],B[i]):
    ans.append(total)
    continue
  total -= uf.nums(A[i])*uf.nums(B[i])
  uf.union(A[i],B[i])
  ans.append(total)
  
#print(ans)   
print(*ans[-2::-1], sep='\n')


Measured memory_bytes: 18492
N,Q=[int(i) for i in input().split()]
S=input()

c=[0]
t = 0
for i in range(1,N):
   t += 1 if  (S[i-1]=='A' and S[i] == 'C') else 0
   c.append(t)

for _ in range(Q):
    l,r=[int(x)-1 for x in input().split()]
    print(c[r]-c[l])


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

int main(void) {
	double x,h,a;
	while(1){
	scanf("%lf%lf",&x,&h);
	a = sqrt(x * x / 4.00f + h * h);
	if (!a) return 0;
	printf("%lf\n" , x * a * 2.00f + x * x);
	}
}

Measured memory_bytes: 644
#include <iostream>

using namespace std;

int main(){
  int n,m,x,a[200],op[1000];
  cin>>n>>m;
  for(int i=0;i<m;++i) cin>>op[i];
  for(int i=0;i<2*n;++i){
    x=i;
    for(int j=0;j<m;++j){
      if(op[j]) x=(x+2*n-op[j])%(2*n);
      else x=(x<n)?(2*x):(2*x+1)%(2*n);
    }
    a[x]=i+1;
  }
  for(int i=0;i<2*n;++i) cout<<a[i]<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(void)
{
	double a,b,c,d,e,f;
    double b2,c2;
	double h,i,j;
	double x,y;
	
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) == 6){

		h = d / a;
		b2 = b * h;
		c2 = c * h;
		i = b2 - e;
		j = c2 - f;
		y = j / i;
		x = (c - y * b) / a;

		printf("%.3f %.3f\n",x, y);
    }

	return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define  int long long int
using namespace std;



int32_t main() {
int n,w,n1,v1;
cin >> n>>w;
int dp[w+1]={0};
for(int i=0;i<n;i++)
{
	cin >> n1 >> v1;
	for(int j=w-n1;j>=0;j--)
	{
		dp[j+n1]=max(dp[j+n1],dp[j]+v1);
	}
	

}	
int ans=0;	
for(int i=0;i<=w;i++)
{
	ans=max(ans,dp[i]);
}
cout << ans;
}	 
		 
		 
 



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

typedef struct rank{
  int num, ans, ranking;
}Rank;

typedef struct data{
  int score, ranking;
}Data;

int main(){
  int n,a,i=0;
  Rank r[100];
  while(scanf("%d,%d", &n, &a) != EOF){
    if( n==0 && a==0 ) break;
    r[i].num = n;
    r[i].ans = a;
    i++;
  }

  int count=1;
  vector<int> score;
  Data d[100];
  
  
  for(int j=0; j<i; j++)  score.push_back(r[j].ans);
  
  sort(score.begin(), score.end(),greater<int>() );
  int max=score[0];

  for(int j=0; j<i; j++){
    if(max == score[j]) continue;
    else{
      d[count-1].score = max;
      d[count-1].ranking = count;      
      max = score[j];
      count++;
    }
  }

  d[count-1].score = max;
  d[count-1].ranking = count;
  
  for(int j=0; j<count; j++){
    for(int k=0; k<i; k++){
      if(d[j].score == r[k].ans) r[k].ranking = d[j].ranking;
    }
  }
    
  int cheak;

  while(cin >> cheak){
    cout << r[cheak-1].ranking << endl;
  }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
int main()
{
long long int n;
cin >>n ;
long long int a[n],val[n+10];
for(long long int i=0;i<n;i++)
{
    cin >> a[i];
    val[i]=0;
    val[i+1]=0;
    val[i+2]=0;
}
for(long long int i=0;i<n;i++)
{
    val[a[i]]++;
}
long long int  ans=0;
for(long long int i=0;i<n+1;i++)
    {
        ans=ans+(val[i]*(val[i]-1))/2;
        // val[]
    }
    for(long long int i=0;i<n;i++)
    {
       long long int t=val[a[i]];
       long long int temp=ans- (t*(t-1) )/2;
       if(t-1>=2)
        temp=temp+((t-1)*(t-2))/2;

        printf("%lld\n",temp)  ;
    }
}



Measured memory_bytes: 5760
#include <iostream>
#include <utility>

using namespace std;

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

  int coin = 0;

  if (A>=B) {
    coin += A;
    A--;
  } else {
    coin += B;
    B--;
  }

  if (A>=B) {
    coin += A;
    A--;
  } else {
    coin += B;
    B--;
  }
  
  cout << coin << endl;

  return 0;
}


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

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

	if (b == 1)
	{
		cout << 0 << endl;
		return 0;
	}

	int ans = 1;

	for (int i = 1; i * a - (i - 1) < b; i++, ans++)
	{
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

    int big, small;
    if (A > B){
        big = A;
        small = B;
    }
    else
    {
        big = B;
        small = A;
    }

    int coin;
    if (big - small <= 1){
        coin = big + small;
    }else{
        coin = 2 * big - 1;
    }

    cout << coin << endl;
    

    return 0;
}

Measured memory_bytes: 256
from collections import deque

class Dice():
    def __init__(self, sequence):
        self.v = deque([seq[5], seq[4], seq[0], seq[1]])
        self.h = deque([seq[3], seq[0], seq[2], seq[5]])

    def lotate(self, direction):

        if   direction == "E":
            self.h.rotate()
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "W":
            self.h.rotate(-1)
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "N":
            self.v.rotate(-1)
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        elif direction == "S":
            self.v.rotate()
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        else:
            pass

    def disp_top_face(self):
        return self.v[2]

    def disp_front_face(self):
        return self.v[3]

    def disp_back_face(self):
        return self.v[1]

    def disp_right_face(self):
        return self.h[2]

    def disp_left_face(self):
        return self.h[0]

    def disp_bottom_face(self):
        return self.h[3]

if __name__ == "__main__":

    param = input().split(" ")
    seq = [int(a) for a in param]

    com = input()

    d = Dice(seq)
    for dir in com:
        d.lotate(dir)

    print(d.disp_top_face())



Measured memory_bytes: 6016
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
    input! {
        n:usize
    }
    let mut v = vec![];
    for _ in 0..n {
        input! {
            a:usize,b:usize,
        }
        v.push((a, b));
    }
    v.sort();
    if v.len() == 1 {
        println!("{}", v[0].1 + v[0].0);
    } else {
        let mut ans = v[0].0 - 1;
        ans += v.last().unwrap().1;
        ans += v.last().unwrap().0 - v[0].0 + 1;
        println!("{}", ans);
    }
}


Measured memory_bytes: 6164
H,W = map(int,input().split())
grid = [list(input()) for _ in range(H)]
#print(grid)
MOD = 10**9+7
dp = [[0]*W for i in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if i+1 < H and grid[i+1][j] == '.':
            dp[i+1][j] += dp[i][j]
            dp[i+1][j] %= MOD
        if j+1 < W and grid[i][j+1] == '.':
            dp[i][j+1] += dp[i][j]
            dp[i][j+1] %= MOD
print(dp[H-1][W-1])

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

int main(){
  int n;cin >> n;
  vector<int> s(n);for(int i=0;i<n;i++) cin >> s[i];
  int q;cin >> q;
  vector<int> t(q);for(int i=0;i<q;i++) cin >> t[i];
  int c=0;
  for(int i=0;i<q;i++){
    for(int j=0;j<n;j++){if(t[i]==s[j]){c+=1;break;}}
  }
  cout << c << endl;
}



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

class Program {
    static void Main() {
        int n = int.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        Console.WriteLine("{0} {1} {2}", a.Min(), a.Max(), a.Sum());
    }
}


Measured memory_bytes: 20480
S = input()

s = S[0]
for i in range(1, len(S)):
    if s[-1] != S[i]:
        s += S[i]

if len(S) == 1:
    print(0)
    exit(0)
elif len(S) == 2:
    print(1)
    exit(0)

print(len(s)-1)


Measured memory_bytes: 3188
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int h1,m1,s1,h2,m2,s2;
  for(int i=0;i<3;i++){
    scanf("%d %d %d %d %d %d",&h1,&m1,&s1,&h2,&m2,&s2);
    int sum1 = h2*3600+m2*60+s2;
    int sum2 = h1*3600+m1*60+s1;
    int res = sum1-sum2;
    printf("%d %d %d\n",res/3600,res%3600/60,res%60);
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, ll> pii;

int main() {
    int N;
    cin >> N;
    vector<ll> dist(N, -1);
    vector<vector<pii> > adj(N, vector<pii>(0));
    dist[0] = 0;
    for (int i = 0; i < N; i++) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        adj[u-1].push_back(make_pair(v-1, w));
        adj[v-1].push_back(make_pair(u-1, w));
    }
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int p = que.front(); que.pop();
        for (auto& t : adj[p]) {
            int q = t.first;
            ll w = t.second;
            if (dist[q] >= 0) {
                continue;
            } else {
                dist[q] = dist[p] + w;
                que.push(q);
            }
        }
    }
    for (int i = 0; i < N; i++) {
        // cout << dist[i] << " ";
        if (dist[i] & 1) cout << "1" << endl;
        else cout << "0" << endl;
    }
    return 0;
}


Measured memory_bytes: 8704