akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










vector<vector<ll>> g;
vector<ll> vec;
vector<bool> used;

void dfs(ll now){
    if(used[now]){
        ll idx;
        REP(i, vec.size()){
            if(vec[i] == now){
                idx = i;
                break;
            }
        }
        set<ll> st;
        for(ll i = idx; i < vec.size(); i++){
            st.insert(vec[i]);
        }
        map<ll, ll> cnt;
        for(auto &x : st){
            for(auto &y : g[x]){
                if(st.find(y) == st.end()) continue;
                cnt[y]++;
            }
        }
        for(auto &c : cnt){
            if(c.second >= 2){
                return;
            }
        }
        
        cout << vec.size() - idx << endl;
        for(ll i = idx; i < vec.size(); i++){
            cout << vec[i] + 1 << endl;
        }
        exit(0);
    }
    used[now] = true;
    vec.push_back(now);
    for(auto &v : g[now]){
        dfs(v);
    }
    used[now] = false;
    vec.pop_back();
}

 
int main(){
    ll n, m;
    cin >> n >> m;
    g.resize(n);
    used.resize(n);
    REP(i, m){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
    }
    REP(i, n){
        // cerr << "i: " << i << endl; 
        dfs(i);
    }
    cout << -1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

int n;
vector<int> G[1 << 17];
int ans;
int root;
bool r = true;
bool dfs(int v, int from) {
	if (G[v].size() == 1) {
		if (from < 0)dfs(G[v][0], v);
		else return false;
	}
	else if (G[v].size() == 2) {
		rep(j, G[v].size()) {
			int to = G[v][j];
			if (to == from)continue;
			return dfs(to, v);
		}
	}
	else {
		int num = 0;
		rep(j, G[v].size()) {
			int to = G[v][j];
			if (to == from)continue;
			if (!dfs(to, v)) {
				num++;
			}
		}
		r = (num>0);
		ans += max(0, num - 1);
		return true;
	}
}
void solve() {
	cin >> n;
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i, n)if (G[i].size() == 1)root = i;
	dfs(root, -1);
	//cout << r << endl;
	if (r)ans++;
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 7040
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#include<unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
#define fio ios_base::sync_with_stdio(false)
#define mod 998244353
#define mod1 mod
#define mod2 1000000007
#define li long long int
#define ll li
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%I64d",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 1000000000010000005
#define MINN -1000000000000000000
#define INTMAX 1000001000
#define pii pair<ll,ll>
#define pdd pair<double,double>
#define pic pair<int,char>
#define N 3000105
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 2*acos(0)
#define lgn 20
 
 
// #define INTMAX 200000000
 
// using namespace boost;
// #define si short int
 
using namespace std;
using namespace __gnu_pbds;
typedef priority_queue<pii, vector<pii > > max_pq;
typedef priority_queue<pii, vector<pii> , greater<pii>  > min_pq;
ll toint(const string &s) {stringstream ss; ss << s; ll x; ss >> x; return x;}
string tostring ( ll number ){stringstream ss; ss<< number; return ss.str();}
 
// using namespace __gnu_pbds;
// typedef priority_queue<pair<ll,char> , vector<pair<ll , char> > > max_pq;
// typedef priority_queue<pii , vector<pii > ,greater<pii > > min_pq;
typedef tree<pair<string,string> , null_type, less<pair<string,string> >, rb_tree_tag, tree_order_statistics_node_update> OST;
// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll , pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
#define nn 2000005
ll ar[ N ];
map < ll, ll > cnt;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin  >> n;
    ll sum = 0;
    for ( ll i = 1; i <= n; i ++){
        cin >> ar[i];
        cnt[ar[i]]++;
        sum += ar[i];
    }
    ll q;
    cin >> q;
    while ( q-- ){
        ll b,c;
        cin >> b >> c;
        sum += (c-b)*cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum <<"\n";
    }
    
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int A[N];
  int onep=0;
  for(int i=0; i<N; i++){
   cin >> A[i];
   if(A[i]==1) onep=i;
  }
  int ans=100000;
  for(int i=0; i<K; i++){
    ans = min(ans, (onep-i+K-2)/(K-1)+(N-onep-K+i+K-2)/(K-1)+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
N = int(input())
P_id = [0]*(N + 1) # P_id[i]は順列Pに置けるiのindex, P[0]は無視
for index, p in enumerate(map(int, input().split())):
    P_id[p] = index

left_next_index = list(range(- 1, N - 1)) + ['うんこ', - 1] # + [- 1]ではないことに注意, left_next_index[r1] = l1においてr1 = Nの場合があるから
right_next_index = list(range(1, N + 1)) + [N, 'うんこ']

res = 0
for p in range(1, N):
    l1 = left_next_index[P_id[p]]
    l2 = left_next_index[l1]
    r1 = right_next_index[P_id[p]]
    r2 = right_next_index[r1]
    
    res += p*((l1 - l2)*(r1 - P_id[p]) + (P_id[p] - l1)*(r2 - r1))
    
    left_next_index[r1] = l1
    right_next_index[l1] = r1
    
print(res)

Measured memory_bytes: 16212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    ll GCD = 1;
    for (int i = 1; i <= 100; i++) {
        if (A % i == 0 && B % i == 0) GCD = i;
    }

    if (C % GCD == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n; 

	int mn, cnt=0;
	cin >> mn;
	++cnt;
	for(int i=0; i<n-1; ++i){
		int p; cin >> p;
		if(mn>p) ++cnt;
		mn=min(mn,p);
	}
	cout << cnt << endl;
}

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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;


int main()
{
    int x, y, ans = 0;
    cin >> x >> y;

    if (x == 1) ans += 300000;
    if (y == 1) ans += 300000;
    if (x == 2) ans += 200000;
    if (y == 2) ans += 200000;
    if (x == 3) ans += 100000;
    if (y == 3) ans += 100000;

    if (x == 1 and y == 1) ans += 400000;

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



Measured memory_bytes: 256
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);

bool check(string s){
    int n = s.size(); 
    for (int i = 0; i < n/2; i++)
        if (s[i] != s[n - i - 1]) return false;
    return true;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    int n = sz(s);
    string pre = s.substr(0,n/2);
    string suf = s.substr((n + 1)/2,n/2);
    if (check(s) && check(pre) && check(suf)) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
 int height[10];
 int max[3]={0};
 int i;
 
 for(i = 0; i < 10; i++)
 {
  scanf("%d",&height[i]);
  if(height[i]>max[0]){
   max[2] = max[1];
   max[1] = max[0];
   max[0] = height[i];
  }else if((max[0] >= max[1])&&(height[i]) > max[1]){
   max[2] = max[1];
   max[1] = height[i];  
  }else if((max[1] >= max[2])&&(height[i]) > max[2]){
   max[2] = height[i];
  }
 }
 for(i = 0; i < 3; i++)
 printf("%d\n",max[i]);
 return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
const ll MOD = (ll)(1e9+7);

ll dp[63][8][2];

int main(void){
	int i,j,k,l,r,p,s,t;
	ll L,R,ans=0ll;
	dp[0][0][0] = 1ll;
	cin >> L >> R;
	for(i=0; i<60; ++i){
		l = (!!(L&(1ll<<(59-i)))); r = (!!(R&(1ll<<(59-i))));
		for(s=0; s<2; ++s){
			for(t=0; t<2; ++t){
					if(s==1 && t==0){
						continue;
					}
				for(j=0; j<8; ++j){
					for(p=0; p<2; ++p){
						if((!(j&1)) && (l > s)){
							continue;
						}
						if((!(j&2)) && (t > r)){
							continue;
						}
						if((!(j&4)) && (p > s)){
							continue;
						}
						k = 0;
						if((j&1) || (l < s)){
							k += 1;
						}
						if((j&2) || (t < r)){
							k += 2;
						}
						if((j&4) || (p < s)){
							k += 4;
						}
						dp[i+1][k][t] += dp[i][j][p];
						dp[i+1][k][t] %= MOD;
					}
				}
			}
		}
	}
	for(j=0; j<8; ++j){
		for(p=0; p<2; ++p){
			if(!(j&4)){
				continue;
			}
			ans += dp[60][j][p];
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

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

  ll ans = 0;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
      for(int k = 1; k <= n; k++) {
        ans += gcd(gcd(i, j), k);
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#define N 100001

char a[N];
char ha[128];

int main()
{	
	int i, l, j;
	
	scanf("%s", a);
	l = strlen(a);
	if(l & 1){
		puts("No");
		return 0;
	}
	ha['p'] = ha['q'] = 1, ha['d'] = ha['b'] = 2;
	
	for(i = 0, j = l - 1; i < j; i++, j--){
		if(ha[a[i]] != ha[a[j]] || a[i] == a[j]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
		
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
nxt = [[None]*(n+1) for _ in range(10)]

for i in reversed(range(n)):
    d = int(s[i])
    for j in range(10):
        nxt[j][i-1] = nxt[j][i]
    nxt[d][i-1] = i

res = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            try:
                i1 = nxt[a][-1]
                i2 = nxt[b][i1]
                i3 = nxt[c][i2]
                if i3:
                    res += 1
            except:
                pass
print(res)


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

using namespace std;

int main() {
	int H, N;
	cin >> N >> H;
	vector<pair<long, long>> a(N);
	vector<pair<long, long>> b(N);

	long c, d;
	for (int i=0; i<N; i++) {
		cin >> c >> d;
		a[i] = make_pair(c, d);
		b[i] = make_pair(d, c);
	}

	sort(a.begin(), a.end(), greater<pair<long,long>>());
	sort(b.begin(), b.end(), greater<pair<long,long>>());

	long res = H/a[0].first + 1;
	long res_v = res * a[0].first;
	int a_c = res;


	int m_c = 0;
	for (int i=0; i < b.size(); i++) {
		if (a[0].first > b[i].first) break;
		res_v += b[i].first;
		res++;
		m_c = i;
	}

	while(res_v >= H) {
		if (a_c > 0) {
			res_v -= a[0].first;
			res--;
			a_c--;
		} else {
			for (int i=m_c; res_v>=H; i--) {
				res--;
				res_v -= b[i].first;
			}

		}
	}


	cout << (res+1) << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll N ; cin >> N ;
  string S ; cin >> S;

  ll ans = 0 ;
  ll now = 0 ;
  rep(i,S.size()){
    if(S[i] == 'I') now++ ;
    else now--;

    ans = max(ans,now);
  }
  cout << ans << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x,l,d=0;
  cin>>n>>x;
  int cnt=1;
  while(n--){
    
    cin>>l;
    d+=l;
    if(d<=x){
      cnt++;
    }

  }
cout<<cnt<<endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
int KI[100][100];
int N;
int kans(){
  int a,b,i,j,k,min,count=0;
  int bango[100],A[100],B[100];

  for(i=0;i < N;i++){
    B[i]=-1;
    A[i]=2000000;
   bango[i]=0;
  }

  A[0]=0;

  while (1){
   
    a=-1;
    min=2000000;
    
    for(i=0;i < N;i++){
      if( A[i] < min && bango[i]!=2){
        min=A[i];
        a=i;
      }
    }

    if(a==-1){
      break;
    }
    bango[a]=2;
    
    for(b=0;b<N;b++){
      if(bango[b] !=2 && KI[a][b]!=2000000){
        if(KI[a][b] < A[b]){
          bango[b]=1;
          A[b]=KI[a][b];
          B[b]=a;
        }
      }
    }
  }

  
  for(i=0;i < N;i++){
    if(B[i] !=-1){
      count=count+KI[i][B[i]];
    }
  }

  return count;
}

int main(){
  int i,j,k,l;

  scanf("%d",&N);

  for(i=0;i < N;i++){
    for(j=0;j <  N;j++){
      scanf("%d",&k);
      KI[i][j] = (k==-1) ? 2000000 : k;
    }
  }
   l=kans();

  printf("%d",l);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2112
n,k=map(int,input().split())
s=list(map(int,input().split()))

m=sum(s[0:k])
r=[m,]
b=m

for i in range(n-k):
  b=b-s[i]+s[i+k]
  r.append(b)
r.sort()
print((r[-1]+k)/2)






Measured memory_bytes: 25188
/*
 Remember not to use arithmetic operation in double while comparision 

 priority of uses
 array > maps > unordered_maps
*/

#include<bits/stdc++.h>
#define lli long long int
#define vl vector<lli>
#define vi vector<int>
#define pb push_back
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	vl A(n),DP(n);
	for(auto &x:A)
		cin>>x;
	DP[0]=0;
	DP[1]=DP[0]+abs(A[1]-A[0]);
	for(int i=2;i<n;i++)
		DP[i]=min(DP[i-1]+abs(A[i]-A[i-1]),DP[i-2]+abs(A[i-2]-A[i]));
	cout<<DP[n-1];
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

int N;
bool prime[1005];
vector<int> vec;
int cnt[1000];

int main(void)
{
	cin >> N;
	for(int i = 2; i <= N; i++){
		if(prime[i]) continue;
		for(int j = i*2; j <= N; j+=i){
			prime[j] = true;
		}
		vec.push_back(i);
	}
	
	int n;
	for(int i = 2; i <= N; i++){
		n = i;
		for(int j = 0; j < vec.size(); j++){
			while(n % vec[j] == 0){
				cnt[j]++;
				n /= vec[j];
			}
		}
	}
	
	llint ans = 1;
	for(int j = 0; j < vec.size(); j++){
		ans *= cnt[j]+1;
		ans %= mod;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <functional>
#include <string>
#include <cstring>
#include <sstream>
#include <deque>
#define fir first
#define sec second
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> Q;

const int inf1=2e9+9;
const ll inf2=8e18+9;
const ll mol=1e4;//1e9+7;
const int maxn=1e5+9;
const ll maxx=1e12+9;

int n;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int m=sqrt(i+0.5),cnt=0;
        for(int x=1;x<=m;x++)
            for(int y=1;y<=m;y++)
            {
                int l=1,r=m,z,num;
                while(l<=r)
                {
                    z=(l+r)/2;
                    num=x*x+y*y+z*z+x*y+y*z+z*x;
                    if(num<i) l=z+1;
                    else if(num>i) r=z-1;
                    else
                    {
                        cnt++;
                        break;
                    }
                }
            }
        printf("%d\n",cnt);
    }
}


Measured memory_bytes: 3712
n,m=map(int,input().split())
ab=[]
for i in range(n):
  a,b=map(int,input().split())
  ab.append([a,b])
ab.sort()
ans=0
t=m
for i in range(n):
  if ab[i][1]<t:
    ans+=ab[i][0]*ab[i][1]
    t-=ab[i][1]
  else:
    ans+=ab[i][0]*t
    print(ans)
    exit()

Measured memory_bytes: 24044
#define _DEBUG
#ifdef _DEBUG
#define _GLIBCXX_DEBUG -Wall -Wextra -Wshadow -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -fmax-errors=2
#endif

#pragma warn +xxx
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define ln "\n"
#define forn(i,e) for( i=0; i<e; i++)
#define forsn(i,s,e) for( i=s; i<e; i++)
#define rforn(i,e) for( i=e; i>=0; i--)
#define vasort(v)         sort(v.begin(), v.end());
#define vdsort(v)         sort(v.begin(), v.end(),greater<int>());
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define out1(x1) cout << x1 << ln
#define out2(x1,x2) cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln


#define in1(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dr[] = {0,1,-1,0,1,-1,1,-1};
int dc[] = {1,0,0,-1,1,-1,-1,1};

ll exp(ll n, ll m, ll md){
        ll a = 1;
        while (m > 0){
                if (m&1) a = (a * n%md) % md;
                m /= 2;
                n = (n*n) % md;
        }
        return a % md;
}

void disp(vi v){
        for(auto u:v)
                cout<<u<<" ";
        cout<<"\n";
}

#define DEBUG
#ifdef DEBUG

#endif


void go1() {
        ll n;
        cin >> n;
        vi ans;
        while(n > 0) {
                ans.PB(n%26);
                n/=26;
        }
        reverse(ans.begin(), ans.end());
        int i;
        forn(i,ans.size()) {
                cout << (char)(ans[i] + 96);
        }

}
void go2() {
        char c;
        cin >> c;
        if ((int) c >= 97) {
                cout << 'a';
        } else cout << 'A';
}
int main(){
        fio;
        //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
        ll tt = 1;
/*

        cin >> tt;


        //*/
        while(tt--){
                go2();
        }

        return 0;
}

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

int main(){
  string S;
  int flag=0;
  cin>>S;
  for(int i=0;i<S.size();i++){
    if(i%2&&S[i]=='R'){
    flag++;
    }
    else if((i+1)%2&&S[i]=='L'){
      flag++;
    }
  }
  if(flag){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		String line = readLine();
		String[] str = line.split(" ");
		int[] array = new int[str.length];
		for(int i = 0; i < 3; i++) {
			array[i] = Integer.parseInt(str[i]);
		}
		Arrays.sort(array);
		System.out.println(array[0]+array[1]);
	}


	private static String readLine() throws Exception {
		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
		return br.readLine();
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

ll __lcm (ll a, ll b)
{
    return (a*b)/(__gcd(a,b));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    ll n,k;
    cin >> n >> k;

    ll input[n];
    ll cost[n];
    for (ll i=0;i<=n-1;i++)
    {
        cin >> input[i];
        cost[i]=input[i]/2;
    }

    ll lcm=1;
    for (ll i=0;i<=n-1;i++)
    {
        lcm=__lcm(cost[i],lcm);
    }

    for (ll i=0;i<=n-1;i++)
    {
        if (lcm%input[i]==0)
        {
            cout << "0" << endl;
            return 0;
        }
    }

    // k=k-lcm;
    // if (k>=0)
    // {
    //     cout << 1+(k/(2*lcm)) << endl;
    // }
    // else
    // {
    //     cout << "0" << endl;
    // }

    int ans=k/lcm;
    cout << (ans+1)/2 << endl;

    return 0;
}


Measured memory_bytes: 1792
n,b=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]

count=0
for i in range(n):
  for j in range(i+1,n):
    t=0
    for k in range(b):
      t += (x[i][k]-x[j][k])**2
    t = t**(1/2)
    if t.is_integer():
      count += 1
print(count)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
pair<int,int> a[123456],b[123456];
#define fi first
#define se second
int getans(int i,int j,int x,int y)
{
	return (x-a[i].fi)+(y-b[j].fi);
}
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=100000;i++)a[i].se=i,b[i].se=i;
	for (int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if (i&1)a[x].fi++;
		else b[x].fi++;
	}
	sort(a,a+100001,greater<pair<int,int>>());
	sort(b,b+100001,greater<pair<int,int>>() );
	int ans=n;
	for (int i=0;i<2;i++)for (int j=0;j<2;j++)if (a[i].se!=b[j].se)ans=min(ans,getans(i,j,n/2,n-n/2));
	printf("%d",ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define all(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

//
int main(void) {
    string s;
    cin >> s;
    if(s=="A") cout << "T" << endl;
    else if(s=="T") cout << "A" << endl;
    else if(s=="C") cout << "G" << endl; 
    else if(s=="G") cout << "C" << endl; 
    return 0;
}

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

int main(){
  int n, v[20], c[20], sum = 0;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for(int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for(int i = 0; i < n; i++) {
    if (v[i] > c[i])
      sum += v[i] - c[i];
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c == 17 && abs(a-b) + abs(b-c) + abs(c-a) == 4 && (a-b)*(b-c)*(c-a) == 0)cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    
    int N;
    while (cin >> N) {
        bool ok = true;
        set<int> se;
        for (int i = 0; i < N; ++i) {
            int a; cin >> a;
            if (se.count(a)) ok = false;
            se.insert(a);
        }
        if (ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}


















Measured memory_bytes: 9600
#!/usr/bin/env python
# coding: utf-8

# In[21]:


N, u, v = map(int, input().split())
u = u - 1
v = v - 1


# In[22]:


eda = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    eda[A-1].append(B-1)
    eda[B-1].append(A-1)


# In[25]:


par = [0] * N
# depth = [0] * N

stack = [v]
par[v] = -1

while stack:
    n1 = stack.pop()
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        par[n2] = n1
#         depth[n2] = depth[n1] + 1
        stack.append(n2)
        


# In[26]:


par


# In[27]:


dis = 0
n = u
while n != v:
    n = par[n]
    dis += 1


# In[28]:


n = u
for _ in range((dis - 1) // 2):
    n = par[n]


# In[29]:


y = (dis - 1) // 2
x = dis - y
# z = depth[n]


# In[38]:


stack = [n]
depth = [0] * N
maxd = 0

while stack:
    n1 = stack.pop()
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        depth[n2] = depth[n1] + 1
        maxd = max(maxd, depth[n2])
        stack.append(n2)
        


# In[41]:


z = maxd


# In[43]:


if dis % 2 == 0:
    print(y + z + 1)
else:
    print(y + z)


# In[ ]:






Measured memory_bytes: 63340
#include <iostream>

using namespace std;

int N;
int *a;
long long **DP;
long long ans;

long long calc(int i, int j) {
	if (i == j) return 0;
	else if (DP[i][j] != -1) return DP[i][j];
	else {
		long long min = calc(i,i) + calc(i + 1,j);
		for (int k = 1; k < j - i; k++) {
			if (min > calc(i, i + k) + calc(i + k + 1, j)) {
				min = calc(i, i + k) + calc(i + k + 1, j);
			}
		}
		long long sum = 0;
		for (int k = i; k <= j; k++)
			sum += a[k];
		return DP[i][j] = min + sum;
	}
}

 
int main() {
	int i, j;

	cin >> N;

	a = new int[N];
	for (i = 0; i < N; i++)
		cin >> a[i];

	DP = new long long*[N];
	for (i = 0; i < N; i++)
		DP[i] = new long long[N];

	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++)
			DP[i][j] = -1;
	}
	
	cout << calc(0, N - 1) << endl;

	for (i = 0; i < N; i++)
		delete[] DP[i];

	delete[] DP;
	delete[] a;

	return 0;
}

Measured memory_bytes: 1536
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve(){
    char a;
    cin>>a;
    cout<<(char)(a+1)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    solve();
}

Measured memory_bytes: 3596
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
Ts = nl()
M = n()

res = []
for i in range(M):
    P, X = nl()
    TD = Ts[:]
    TD[P-1] = X
    res.append(sum(TD))

for i in range(M):
    print(res[i])


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

int main() {
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  a--;
  b--;
  c--;
  d--;
  string s; 
  cin >> s;
  bool ex=true;
  if(c<d){
    rep2(i,a+1,c-1){
      if(s.at(i)=='#'&&s.at(i+1)=='#'){
        ex=false;
      }
    }
    rep2(i,b+1,d-1){
      if(s.at(i)=='#'&&s.at(i+1)=='#'){
        ex=false;
      }
    }
  }
  else{
    rep2(i,a+1,c-1){
      if(s.at(i)=='#'&&s.at(i+1)=='#'){
        ex=false;
      }
    }
    rep2(i,b+1,d-1){
      if(s.at(i)=='#'&&s.at(i+1)=='#'){
        ex=false;
      }
    }
    if(ex){
      ex=false;
      rep2(i,b-1,d){
        if(s.at(i)=='.'&&s.at(i+1)=='.'&&s.at(i+2)=='.'){
          ex=true;
        }
      }
    }
  }
  if(ex){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 640
using System;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            string line = null;
            while( (line = Console.ReadLine()) != null )
            {
                var inputStr = line.Split(' ');
                var input = new int[2];
                input[0] = int.Parse(inputStr[0]);
                input[1] = int.Parse(inputStr[1]);

                if ((input[0] == 0) && (input[1] == 0))
                    break;

                Array.Sort(input);
                Console.WriteLine(input[0] + " " + input[1]);
            }

        }
    }
}

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

using namespace std;

template< typename T >
struct PrioritySumStructure
{
  static const bool INCREASE = false;
  static const bool DECREASE = true;

  bool order;
  int k, sz;
  T sum;
  set< pair< T, int > > add, pend;
  unordered_map< int, T > adding, pending;

  PrioritySumStructure(int k, bool order = INCREASE) : k(k), sum(0), sz(0), order(order) {}

  void Sweep()
  {
    while(sz < k && !pend.empty()) {
      auto p = order ? --pend.end() : pend.begin();
      sum += p->first;
      ++sz;
      add.emplace(*p);
      adding.emplace(p->second, p->first);
      pending.erase(p->second);
      pend.erase(p);
    }
    while(sz > k) {
      auto p = order ? add.begin() : --add.end();
      sum -= p->first;
      --sz;
      pend.emplace(*p);
      pending.emplace(p->second, p->first);
      adding.erase(p->second);
      add.erase(p);
    }
  }

  T getSum()
  {
    if(sz < k) throw ("get Sum Exception");
    return (sum);
  }

  void addElement(int k, T x)
  {
    if(adding.count(k) || pending.count(k)) {
      throw ("Add Element Exception");
    }
    ++sz;
    add.emplace(x, k);
    adding[k] = x;
    sum += x;
    Sweep();
  }

  void deleteElement(int k)
  {
    if(pending.count(k)) {
      pend.erase({pending[k], k});
      pending.erase(k);
    } else if(adding.count(k)) {
      --sz;
      sum -= adding[k];
      add.erase({adding[k], k});
      adding.erase(k);
      Sweep();
    } else {
      throw ("delete Element Exception");
    }
  }

  void incrementSize()
  {
    ++k;
    Sweep();
  }

  void decrementSize()
  {
    if(k == 0) throw ("decrement Size Exception");
    --k;
    Sweep();
  }
};

typedef long long int64;

int main()
{
  int N, A[300000];

  scanf("%d", &N);
  for(int i = 0; i < 3 * N; i++) scanf("%d", &A[i]);

  PrioritySumStructure< int64 > sum1(N, PrioritySumStructure< int64 >::DECREASE);
  PrioritySumStructure< int64 > sum2(N, PrioritySumStructure< int64 >::INCREASE);
  for(int i = 0; i < N - 1; i++) sum1.addElement(i, A[i]);
  for(int i = N - 1; i < 3 * N; i++) sum2.addElement(i, A[i]);

  int64 ret = numeric_limits< int64 >::min();
  for(int i = N - 1; i < 2 * N; i++) {
    sum1.addElement(i, A[i]);
    sum2.deleteElement(i);
    ret = max(ret, sum1.getSum() - sum2.getSum());
  }
  printf("%lld\n", ret);
}

Measured memory_bytes: 34468
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end())
            cout << " ";
    }
    cout << endl;
}

int gcd(int x, int y) {
    int tmp;
    if(x > y)
        return gcd(y, x);
    int r;
    while((r = x % y)) {
        x = y;
        y = r;
    }
    return y;
}

bool isPrime(int n) {
    if(n < 2)
        return false;
    else if(n == 2)
        return true;
    else if(n % 2 == 0)
        return false;
    double sq = sqrt(n);
    for(int i = 3; i <= sq; i += 2) {
        if(n % i == 0)
            return false;
    }
    return true;
}

int main() {
    int N, co = 0;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    rep(i, N) {
        int min = i;
        rep(j, i, N) {
            if(A[j] < A[min])
                min = j;
        }
        if(i != min) {
            co++;
            swap(A[i], A[min]);
        }
    }

    vecout(A);
    cout << co << endl;
}


Measured memory_bytes: 3168
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(){
  int N; cin>>N;
  int L=0;
  int Ans=0;
  for(int i=1; i<N+1; i+=2){
   for(int j=1; j<i+1; j++){
     if(i%j==0)
       L++;
     else continue;
   }
    if(L==8)
      Ans++;
    L=0;
  }
  cout<<Ans<<endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

   class Main{
     public static void main(String[] args){
       Scanner stdIn = new Scanner(System.in);
       int a = stdIn.nextInt();
       int b = stdIn.nextInt();
       int c = stdIn.nextInt();
       if(b+c >= a){
         System.out.println(c-(a-b));
       }else{
         System.out.println(0);
       }
     }
   }

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}



int main() {
    long long n , b, ans = 0;
    cin >> n;
    if (n % 2 == 1){
        cout << 0 << endl;
        return 0;
    }
    for (int i = 1; i <= 25; i++){
        ans += (n / 2) / modpow(5, i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> A = {a, b, c};
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  cout << A.size() << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
H=list(map(int,input().split()))
ans=True
for i in range(n-1):
    if H[i]>H[i+1]:
        H[i+1]+=1
for j in range(n-1):
    if H[j]>H[j+1]:
     print("No")
     ans=False
     break
if ans:
    print("Yes")

Measured memory_bytes: 14224
#include <stdio.h>

int main(){
  int h,i;
  scanf("%d",&h);

  int a[h+1];

  for(i=1;i<=h;i++){
    scanf("%d",&a[i]);
  }

  for(i=1;i<=h;i++){
    printf("node %d: key = %d, ",i,a[i]);
    if(i==1){
      printf("left key = %d, right key = %d, ",a[i*2],a[i*2+1]);
    }
    else {
      printf("parent key = %d, ",a[i/2]);

      if(i*2<=h){
	printf("left key = %d, ",a[i*2]);
      }

      if(i*2+1<=h){
	printf("right key = %d, ",a[i*2+1]);
      }
    }
    printf("\n");
  }
      
	
  return 0;
}



Measured memory_bytes: 2056
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a,b,c,k,h;
    scanf("%d %d %d",&a,&b,&c);
    k=abs(a-b);
    h=abs(a-c);
    if(k<h)
    {
        printf("A");
    }
    else
    {
        printf("B");
    }
}


Measured memory_bytes: 128
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(usize);
    let A = get!(Vec<i64>);

    let ans: i64 = 3_i64.pow(N as u32) - A.iter().map(|a| 2 - a % 2).fold(1, |p, a| p * a);

    println!("{}", ans);

}


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

int main(){
  int x,y,a,b,c;
  cin >> a >> b >> c >> x >> y ;
  int price1 =0;//abピザ複数枚で用意する
  int price2 = x*a + y*b;//a,bそれぞれを枚数分買う
  int price3 = 0; //abピザだけで全部用意する。あまりもでる。
  if (x<y) price1+= 2*x*c + (y-x)*b;
  else if (x>y) price1 += 2*y*c + (x-y)*a;
  else if (x=y) price1 += 2*x*c;
  price3 += 2*max(x,y)*c;
  cout << min(min(price1,price2),price3) << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
void myInit();
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int MOD = 1000000007;
const int N = 3e5, M = N;
//=========TQR==============
vi g[N];
int a[N];

int main() {
	myInit();
	FIO;
	int n, i;
	unsigned ll  ans = 1;
	bool neg = false;
	cin >> n;
	fo(i, n) {
		unsigned ll x, tmp;
		cin >> x;
		if (x == 0) {
			ans = 0;
			neg = false;
		}
		if (ans > 0)	{
			tmp = 1000000000000000000 / ans;
			if (tmp < x)
				neg = true;
			else if (!neg)
				ans *= x;
		}
		// deb2(ans, tmp);

	}
	if (neg)
		cout << "-1\n";
	else
		cout << ans << endl;
	return 0;
}

void myInit() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mpow(int base, int exp) {
	base %= MOD;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % MOD;
		base = ((ll)base * base) % MOD;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m) {
	int i, u, v;
	while (m--) {
		cin >> u >> v;
		g[u - 1].pb(v - 1);
		g[v - 1].pb(u - 1);
	}
}

void dfs(int u, int par) {
	for (int v : g[u]) {
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10656
//#include <algorithm>
//#include <cassert>
//#include <cfloat>
//#include <cmath>
//#include <cstdio>
//#include <cstdlib>
//#include <deque>
#include <iostream>
//#include <limits>
//#include <map>
//#include <queue>
//#include <set>
//#include <stack>
//#include <string>
//#include <tuple>
//#include <unordered_map>
//#include <unordered_set>
//#include <vector>
using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

long getTotal(int *a, int n, int dir) {
  long total{0}, sum{0};
  for (int i{0}; i < n; ++i) {
    sum += a[i];
    if (dir > 0 && sum <= 0) {
      total += -sum + 1;
      sum = 1;
    } else if (dir < 0 && sum >= 0) {
      total += sum + 1;
      sum = -1;
    }
    dir *= -1;
  }
  return total;
}

int main() {
  int n; scanf("%d", &n);
  int a[n];
  for (int i{0}; i < n; ++i) scanf("%d", &a[i]);

  long try1 = getTotal(a, n, 1);
  long try2 = getTotal(a, n, -1);

  printf("%ld\n", MIN(try1, try2));
  return 0;
}


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

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = (int) 1e5 + 10;
int n; LL l;
char S[MAXN];

int TSize;
int nxt[MAXN][2];

void Insert() {
    int p = 0, len = strlen(S + 1);
    for (int i = 1; i <= len; ++i) {
        int c = S[i] - '0';
        if (nxt[p][c] == 0) nxt[p][c] = ++TSize;
        p = nxt[p][c];
    }
}

LL DFS(int u, int h = 0) {
    if (nxt[u][0] == 0 && nxt[u][1] == 0) return 0;
    LL cur = 0;
    if (nxt[u][0] != 0 && nxt[u][1] != 0) cur = 0; else
    cur = (l - h) & (h - l);
    if (nxt[u][0] != 0) cur ^= DFS(nxt[u][0], h + 1);
    if (nxt[u][1] != 0) cur ^= DFS(nxt[u][1], h + 1);
    return cur;
}

int main() {
    scanf("%d%lld", &n, &l);
    for (int i = 1; i <= n; ++i) {
        scanf("%s", S + 1);
        Insert();
    }

    puts(DFS(0) ? "Alice" : "Bob");
    return 0;
}

Measured memory_bytes: 4224
h, w, k = map(int, input().split())
# 長さ wの配列
dp = [1] + [0] * (w - 1)
 
# ????フィボナッチ数
facts = [1, 1, 2, 3, 5, 8, 13, 21, 34]
 
# h（高さ）だけ繰り返し 
for _ in range(h):
    # ndpは長さwの[0]の配列、ワークエリア
    ndp = [0] * w
    # w（縦線の数）だけ繰り返し
    for b in range(w):
        # bがゼロより大きいとき＝左端の縦線にいないとき
        if b > 0:
            # １つ左の縦線から移ってくるとき
            # ndpのb番目は、dpのb-1番目×フィボナッチ数のｂ－１番目×フィボナッチ数のw-b-1番目
            # フィボナッチ数の積なのは、通らない縦線の組み合わせ数であるため
            ndp[b] += dp[b - 1] * facts[b - 1] * facts[w - b - 1]
        # ndpのb番目にdpのb番目×フィボナッチ数のb番目×フィボナッチ数のw-b-1番目
        # そのまま下がってくるとき
        ndp[b] += dp[b] * facts[b] * facts[w - b - 1]
        # b が w-1より小さいとき＝右端の縦線にいないとき
        if b < w - 1:
            # １つ右の縦線から移ってくるパターンの数は
            ndp[b] += dp[b + 1] * facts[b] * facts[w - b - 2]
        ndp[b] %= 1000000007
    dp = ndp
 
print(dp[k - 1])


#疑問点：フィボナッチ数である理由

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
vector<int64_t> N(0);

void search(int64_t n) // nの末尾に追加
{
  if (n > 3234566667)
    return;
  for (int i = 0; i <= 9; i++)
  {
    int64_t scd = n % 10;        // 2桁目
    int64_t next_n = n * 10 + i; // iが1桁目
    if (abs(scd - i) <= 1)
    {
      N.push_back(next_n);
      search(next_n);
    }
  }
}

int main()
{
  int64_t K;
  cin >> K;
  for (int i = 1; i <= 9; i++)
  {
    int64_t copi = i;
    N.push_back(copi);
    search(copi);
  }
  sort(N.begin(), N.end());
  cout << N.at(K - 1) << endl;
}


Measured memory_bytes: 6512
def output_A(A):
    if len(A) == 1:
        print(A[0])
    else:
        for i in range(len(A)-1):
            print(f'{A[i]} ',end="")
        print(f'{A[i+1]}',)

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

output_A(A)
for i in range(1,len(A)):
    key = A[i]
    j = i-1
    while j>=0 and A[j] > key :
        A[j+1] = A[j]
        j -= 1
    A[j+1] = key
    output_A(A)


Measured memory_bytes: 5992
import java.util.*;

public class Main {
	static int R, C;
	public static class Terminal {
		int d;
		int idx;
		public Terminal(int d, int idx) {
			this.d = d;
			this.idx = idx;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		R = sc.nextInt();
		C = sc.nextInt();
		int N = sc.nextInt();
		ArrayList<Terminal> list = new ArrayList<>();
		
		for(int i=0; i<N; i++) {
			int x1 = sc.nextInt();
			int y1 = sc.nextInt();
			int x2 = sc.nextInt();
			int y2 = sc.nextInt();
			
			if(isOnEdge(x1, y1) && isOnEdge(x2, y2)) {
				list.add(new Terminal(convert(x1, y1), i));
				list.add(new Terminal(convert(x2, y2), i));
			}
		}
		Collections.sort(list, new Comparator<Terminal>() {
			public int compare(Terminal t1, Terminal t2) {
				return t1.d - t2.d;
			}
		});
		
		LinkedList<Terminal> stack = new LinkedList<>();
		
		for(Terminal t : list) {
			if(!stack.isEmpty() && stack.peek().idx == t.idx)
				stack.pop();
			else
				stack.push(t);
		}
		
		System.out.println(stack.isEmpty() ? "YES" : "NO");
		
		sc.close();
	}
	
	static boolean isOnEdge(int x, int y) {
		return x==0 || x==R || y==0 || y==C;
	}
	
	static int convert(int x, int y) {
		if(x==0)
			return y;
		else if(y==C)
			return C + x;
		else if(x==R)
			return C + R + (C-y);
		else
			return C + R + C + (R-x);
	}
}


Measured memory_bytes: 100380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mk make_pair
#define PII pair<ll,int>
#define PB push_back
const int maxn=2e5+9;
const int mod=1e9+7;
ll k,n,a[maxn],ans;
ll sum[maxn];
int main()
{
	ans=1;
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	int fh=1,l=1,r=n;
	if(k&1)
	{
		ans=a[n];if(a[n]<0)fh=-1;k--;r--;
	}
	while(k)
	{
		ll s1=a[l]*a[l+1],s2=a[r]*a[r-1];
		if(s1*fh>s2*fh)ans=(ans*(s1%mod))%mod,l+=2;
		else ans=(ans*(s2%mod))%mod,r-=2;
		k-=2;
	}
	ans=(ans+mod)%mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 5400