akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;

int a, b;
int main(void) {
	cin >> a >> b;
	cout << max({ a + b, a - b, a * b }) << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x=0 ,y=0;
      Scanner scanner = new Scanner(System.in);
      x = scanner.nextInt();
      y = scanner.nextInt();
      scanner.close();
      if ((x+y)%2 == 0) {
         int k1 = (x+y)/2;
         System.out.println(k1);
      }else if (x == y) {
         int k2 = x;
         System.out.println(k2);
      }else {
         System.out.println("IMPOSSIBLE");
      }

   }
}


Measured memory_bytes: 21844
A,B,C,X,Y = map(int,input().split())
ave_AB = (A+B)/2
if C >= ave_AB:
    print(X*A+Y*B)
else:
    if X >= Y:
        if 2*C >= A:
            print(2*C*Y+A*(X-Y))
        else:
            print(2*C*X)
    else:
        if 2*C >= B:
            print(2*C*X+B*(Y-X))
        else:
            print(2*C*Y)   

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	string arr[] = { "Sunny", "Cloudy", "Rainy"};
	map<string, int> m;
	m["Sunny"] = 0, m["Cloudy"] = 1, m["Rainy"] = 2;
	string str;
	cin>>str;
	cout<<arr[(m[str]+1)%3];

}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;
struct edge {
	int to, cost;
};
struct state {
	int pos, cost, used;
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost < s2.cost;
}
int n, m, t, a, b, c;
int main() {
	while (scanf("%d%d%d", &n, &m, &t), n) {
		vector<vector<edge> > G(n);
		for (int i = 0; i < m; i++) {
			scanf("%d%d%d", &a, &b, &c); a--, b--;
			G[a].push_back(edge{ b, c });
		}
		priority_queue<state> que; que.push(state{ 0, 0, 0 });
		vector<vector<int> > dist(n, vector<int>(n, 999999999)); dist[0][0] = 0;
		while (!que.empty()) {
			state st = que.top(); que.pop();
			for (edge e : G[st.pos]) {
				int cost1 = dist[st.pos][st.used] + e.cost;
				if (dist[e.to][st.used] > cost1) {
					dist[e.to][st.used] = cost1;
					que.push(state{ e.to, -cost1, st.used });
				}
				int cost2 = dist[st.pos][st.used];
				if (st.used != n - 1 && dist[e.to][st.used + 1] > cost2) {
					dist[e.to][st.used + 1] = cost2;
					que.push(state{ e.to, -cost2, st.used + 1 });
				}
			}
		}
		int ret = -1;
		for (int i = 0; i < n; i++) {
			if (dist[n - 1][i] <= t) {
				ret = i; break;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 2840
H, W = map(int, input().split())
G = [input() for _ in range(H)]
sy, sx, gy, gx = 0, 0, H - 1, W - 1
seen = [[-1] * W for _ in range(H)]

if G[sy][sx] == '#' or G[gy][gx] == '#':
    print(-1)
    exit()

from collections import deque
que = deque()
que.append([sy, sx])
seen[sy][sx] = 0
while que:
    y, x = que.popleft()
    for d in [-1, 0], [1, 0], [0, -1], [0, 1]:
        dy = y + d[0]
        dx = x + d[1]
        if dy < 0 or H <= dy or dx < 0 or W <= dx:
            continue
        if G[dy][dx] == '#':
            continue
        if seen[dy][dx] > -1:
            continue
        que.append([dy, dx])
        seen[dy][dx] = seen[y][x] + 1

count = 0
bunpu = [0] * (H * W + 1)
if seen[gy][gx] == -1:
    print(-1)
    exit()
else:
    all = H * W
    black = 0
    for i in range(H):
        for j in range(W):
            if G[i][j] == '#':
                black += 1
    #start point = 0,0 
    ans = all - black - seen[gy][gx] - 1
print(ans)

Measured memory_bytes: 74204
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
using namespace std;


void comb(int *indices, int s, int rest, std::function<void(int*)> f) {
	if (rest == 0) {
		f(indices);
	}
	else {
		if (s < 0) return;
		comb(indices, s - 1, rest, f);
		indices[rest - 1] = s;
		comb(indices, s - 1, rest - 1, f);
	}
}
void comb_apply(int n, int s, function<void(int*)> f) {
	vector<int> idx(n);
	comb(idx.data(), s - 1, n, f);
}

int main() {
	int N;
	cin >> N;
	vector<int> L(N);
	set<array<int, 3>> matched;
	for (int i = 0; i < N; ++i) {
		int n;
		cin >> L[i];
	}
	int count = 0;
	comb_apply(3, L.size(), [&](int *indices) {
		int a = L[indices[0]];
		int b = L[indices[1]];
		int c = L[indices[2]];
		if ( a != b && a != c && c != b &&
			a + b > c && b + c > a && c + a > b) {
			++count;
		}	
	});
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

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

		String s = sc.next();
		String t = sc.next();

		int cnt = 0;

		for (int i = 0 ; i < 3; i++) {
			String si = s.substring(i, i + 1);
			String ti = t.substring(i, i + 1);

			if (si.equals(ti)) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}

}



Measured memory_bytes: 21844
import java.util.*;

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

    int[] count = new int[ N ] ;

    for( int i = 0 ;i < N ; i ++ ){
      int A = sc.nextInt();
      count[ A ] ++ ;
    }

    boolean isReal = true;
    if( N % 2 == 0  ){
      for( int i = 1 ;  i < N ; i = i + 2 ){
        if( count[ i ] != 2 ){
          isReal = false;
          break;
        }
      }
    }else{
      for( int i = 0 ;  i < N ; i = i + 2 ){
        if(i == 0 && count[ i ] != 1 ){
          isReal = false;
          break;
        }
        if(i != 0 && count[ i ] != 2 ){
          isReal = false;
          break;
        }
      }
    }
    long result = 1L;
    if( !isReal ){
      result = 0L;
    }else{
      for( int i = 0 ;i < N / 2 ; i ++){
        result = result * 2;
        if(result > 1000000007L ){
          result = result - 1000000007L ;
        }
      }
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 48628
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
ll n,q;
string s;
ll cnt[1000006];
ll cnt2[1000006];
ll dpd[1000006];
ll gt(ll x)
{
        if(x < 0) return 0;
        return dpd[x];
}
ll gt2(ll x)
{
        if(x < 0) return cnt2[0];
        return cnt2[x];
}
int main()
{
        cin >> n >> s >> q;
        for(ll i=n-1;i>=0;i--){
                cnt[i] = cnt[i+1];
                cnt2[i] = cnt2[i+1];
                cnt2[i] += (s[i] == 'D');
                cnt[i] += (s[i] == 'M');
        }
        for(ll i=0;i<n;i++){
                dpd[i] += dpd[i-1];
                if(s[i] == 'D') dpd[i] += cnt[i+1];
        }
        while(q--){
                ll ans = 0;
                ll k;
                cin >> k;
                for(ll i=0;i<n;i++) {
                        if(s[i] != 'C') continue;
                        ans += gt(i-2) - gt(i-k) - cnt[i+1]*(gt2(i-k+1) - gt2(i-1));
                }
                cout << ans << "\n";
        }
        return 0;
}


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


int main(){
  ll a,c;
  double b;
  cin>>a>>b;
  int b_=b*100+0.5;
  c=a*b_/100;
  cout<<c<<endl;
}

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

using namespace std;
const int maxn = 1e5+10;
const int mod = 1e9+7;
typedef long long ll;
//kusucheng 1,2;
/*
ll fm(ll a, ll b,ll mod){
//	ll c = a*b - (ll)((long double)a*b/mod + 0.5)*mod;
//	return c<0?c+mod:c;
    return (a*b - (ll)((long double)a/mod*b)*mod+mod)%mod;
}*/
ll fm(ll a,ll b, ll mod){
	ll ans = 0;
	while(b > 0){
		if(b&1)  ans = (ans+a)%mod;
		a = (a+a)%mod;
		b >>= 1;
	}
	return ans;
}
int main()
{
	int n,k;
	cin >> n >> k;
	int a[maxn],b[maxn];
	for(int i = 0;i < n;i ++)
		cin >> a[i];
	int cnt1 = 0,cnt2 = 0;
	for(int i = 0;i < n-1;i ++){
		for(int j = i+1;j < n;j ++){
			if(a[i] > a[j]) cnt1 ++;
		}
	}
	sort(a,a+n,greater<int>());
	for(int i = 0;i < n-1;i ++){
		for(int j = i+1;j < n;j ++){
			if(a[i] > a[j]) cnt2 ++;
		}
	}
	int x,y;
	if(k%2 == 0) x = k/2,y = k-1;
	else x = k,y = (k-1)/2;
	cout << (fm(cnt1,k,mod)%mod + fm(x,y,mod)*cnt2%mod)%mod << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())
a1 = a*x + b*y
a2 = max(x,y) * 2*c
if y >= x:
    a3 = 2*c*x + (y-x)*b
else:
    a3 = 2*c*y + (x-y)*a
print(min(a1,a2,a3))

Measured memory_bytes: 3060
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
sum=0
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]==b[k][l]:
                    sum+=1
        if sum==m**2: break
        else: sum=0
    if sum==m**2: break
print("Yes" if sum==m**2 else "No")

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

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

    vector<int> a(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }

    vector<bool> chk(N, false);
    int cur = 0;
    int cnt = 0;
    while (!chk.at(cur) && cur != 1)
    {
        chk.at(cur) = true;
        cur = a.at(cur) - 1;
        cnt++;
    }
    if (cur == 1)
    {
        cout << cnt << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextLong();
        long M = sc.nextLong();
        
        long ans = 0;
        
        if (N > M / 2) {
        	ans += M / 2;
        	M = M % 2;
        } else if (N <= M / 2) {
        	ans += N;
        	M -= N*2;
        	N = 0;
        }
        
        ans += M / 4;

        
        System.out.println(ans);
        
        
    } 
        
}	

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

#define oo(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
  cout << name << ": " << arg1 << "\n";
}
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...);
}

unsigned lcm(int a, int b) { return (a / __gcd(a, b) * b); }
#define fri(i, n) for (int i = 0; i < n; ++i)
#define jri(j, k, n) for (int j = k; j >= n; j--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fa(x , n , v) fill(&(x)[0][0], &(x)[0][0] + (0 + n) *(0 + n) , (v))
#define ra(a) for(int &x : (a)) cin >> (x);
typedef long long int lli;
typedef unsigned long long int ulli;
const lli MOD = 1e9 + 7;
#define pb emplace_back
#define mp make_pair
#define vi vector<int>
#define vlli vector<lli>

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vi h(n);
  ra(h);
  vi dp(n , INT_MAX);
  dp[0] = 0;
  fri(i,n)
  for(int j : {i+1 , i+2}){
  	if(j < n){
    dp[j] = min(dp[j] , dp[i] + abs(h[i] - h[j]));
  }
  }
  cout << dp[n-1];
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;

int main() {
    double a, b, c, d;
    double t = 3.305785;
    cin >> a >> b;
    d = a * b;
    c = d / t;
    printf("%lf\n", c); 
}




Measured memory_bytes: 3196
#include<stdio.h>

int A[100000],n;

int partition(int,int);

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

  a = partition(0,n - 1);

  for(i = 0; i < n; i++){
    if(i) printf(" ");
    if(i == a) printf("[");
    printf("%d",A[i]);
    if(i == a) printf("]");
  }
  printf("\n");

  return 0;
}

int partition(int s,int t){
  int x,y,them,j;

  x = A[t];
  y = s - 1;
  for(j = s; j < t; j++){
    if(A[j] <= x){
      y++;
      them = A[y];
      A[y] = A[j];
      A[j] = them;
    }
  }
  them = A[y+1];
  A[y+1] = A[t];
  A[t] = them;
  return y+1;
}



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

using namespace std;
typedef long long ll;

const int N = 2e5;

int a[N + 5];
int tot[N + 5];
map < int , int > cnt;

int main(){
	tot[0] = 0;
	int n, m; scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	for(int i=1; i<=n; i++) tot[i] = (tot[i-1] + a[i]) % m;
	int idx = 0;
	for(int i=1; i<=n; i++){
		tot[i] = (tot[i] - i) % m;
		tot[i] = (tot[i] + m) % m;
	}
	ll ans = 0;
	cnt[0] = 1;
	for(int i=1; i<=n; i++){
		if(i >= m) cnt[tot[i-m]]--;
		ans += cnt[tot[i]];
		cnt[tot[i]]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,T,a;

int main(){
    cin >> n >> T >> a;
    vector<int> h(n);
    vector<double> t(n);
    REP(i,n){
        cin >> h[i];
        t[i] = T-0.006*h[i];
    }
    int res = 0;
    double ti = t[0];
    REP(i,n){
        if(abs(a-ti)>abs(a-t[i])){
            res = i;
            ti = t[i];
        }
    }
    put(res+1);
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#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()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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
}
 
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;
}
 
using namespace std;

//グラフのテンプレート
template<typename T>
struct edge {
	int from, to;
	T cost;

    edge(int to,T cost):from(0),to(to),cost(cost){}
	edge(int from, int to, T cost) :from(from), to(to), cost(cost) {}
};

template<typename T>
T prim(vector<vector<edge<T>>> &g){//プリム法(最小全域木)
    using P=pair<T,int>;//firstがcost,secondが行き先

    T sum=0;
    vector<bool>used(g.size(),false);
    priority_queue<P,vector<P>,greater<P>>pq;
    pq.emplace(0,0);
    while(!pq.empty()){
        auto p=pq.top();
        pq.pop();
        if(used[p.second])continue;
        used[p.second]=true;
        sum+=p.first;
        for(auto &x: g[p.second]){
            pq.emplace(x.cost,x.to);
        }
    }
    return sum;
}

void solve(){
    int v,e;
    cin>>v>>e;
    vector<vector<edge<int>>>g(v);
    rep(i,e){
        int a,b,w;
        cin>>a>>b>>w;
        g[a].eb(b,w);
        g[b].eb(a,w);
    }
    cout<<prim(g)<<endl;
}


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



Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 100010;
const int MOD = 1000000007;
const int INF = 1e8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
//

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

    vi delta(n+10, 0), acum(n+10, 0);
    forn(i, m) {
        int l, r;
        cin >> l >> r;
        delta[l]++;
        delta[r+1]--;
    }

    int val = 0, cnt = 0;
    forne(i, 1, n) {
        val += delta[i];
        if(val == m) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define N 10000
int isIncluded(int);
int arr[N];//first line
int n;//the number of first line
int main(void)
{
  int i;//counter
  int q;//the number of second line
  int x;//the element of second array
  int ans=0;//output
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&arr[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&x);
      ans+=isIncluded(x);
    }
  printf("%d\n",ans);
  return 0;
}
int isIncluded(int x)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      if(arr[i]==x) return 1;
    }
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll s[114514], n,ans = 1,now = 0;
int main(){
	cin >> n;
	REP(i, n)cin >> s[i];
	REPO(i, n - 1) {
		if (now == 0) {
			if (s[i] < s[i - 1])now = 1;
			else if (s[i] > s[i - 1])now = 2;
		}
		else {
			if ((now == 1 and s[i] > s[i - 1]) or (now == 2 and s[i] < s[i - 1])) {
				ans++;
				now = 0;
			}
		}
	}
	cout << ans << endl;
}

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

const int N = 100005;

int n, A, newA;
vector<int> G[N];
int lim;

int findA(int u, int p) {
    int rem = 0;
    for (int v : G[u]) if (v != p) {
        rem += findA(v, u);
    }
    A += rem / 2; rem %= 2;
    if (rem == 1) return rem;
    return (u == 1) ? 0 : 1;
}

int dfs(int u, int p) {
    multiset<int> s;
    for (int v : G[u]) if (v != p) {
        int cur = dfs(v, u) + 1;
        s.insert(cur);
    }

    vector<int> rem;
    while(s.size()) {
        multiset<int>::iterator it = s.end(); --it;
        int x = (*it);
        s.erase(it);
        it = s.upper_bound(lim - x);
        if (it == s.begin()) {
            rem.push_back(x);
        } else --it, s.erase(it), ++newA;
    }

    reverse(rem.begin(), rem.end());
    while(rem.size() && rem.back() == lim) ++newA, rem.pop_back();
    if (rem.empty()) return 0;
    else { newA += rem.size() - 1; return rem[0]; }
}

bool check() {
    newA = 0;
    newA += dfs(1, -1) != 0;
    return newA <= A;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v;
        G[u].push_back(v); G[v].push_back(u);
    }
    A += findA(1, -1);

    int l = 1, r = n;
    while(l < r) {
        lim = ((l + r) >> 1);
        if (check()) r = lim; else l = lim + 1;
    }
    cout << A << ' ' << l << endl;
}


Measured memory_bytes: 20352
#include <iostream>
#include <string>
#include <vector>

using namespace std;


int main() {
    int N, M; cin >> N >> M;

    vector<vector<int>> S;
    for(int i=0; i < M; i++) {
        int k; cin >> k;
        vector<int> s(k);
        for(int j=0; j < k; j++) {
            cin >> s[j];
        }
        S.push_back(s);
    }


    vector<int> p(M);
    for(int i=0; i < M; i++) {
        cin >> p[i];
    }

    int ans = 0;
    vector<int> denkyu_status(M, 0);
    for (int i=0; i<1 << N; i++) {
        for (int j = 0; j < N; j++) {
            if ((i >> j & 1) == 1) {
                for(int k=0; k < M; k++) {

                    bool flag2 = false;
                    for(int ind=0; ind < S[k].size(); ind++) {
                        if(S[k][ind] == j+1) {
                            flag2 = true;
                        }
                    }

                    if(flag2) {
                        denkyu_status[k]++;
                    }
                }
            }
        }


        bool flag = true;
        for(int j=0; j < M; j++) {
            if(denkyu_status[j] % 2 != p[j]) {
                flag = false;
            }
        }

        if(flag) {
            ans++;
        }

        for(int k=0; k < M; k++) {
            denkyu_status[k] = 0;
        }


    }

    cout << ans << endl;

    return 0;
}



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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

ll ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d, n;
int x, y;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;

    cin >> x >> a >> b;
    if (min(a, b) + x < max(a, b))
        pr(max(a, b) - (min(a, b) + x));
    else
        pr(0);

    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sum += s[i];
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    if (sum % 10 != 0) {
      break;
    }
    if (s[i] % 10 != 0) {
      sum -= s[i];
    }
  }
  if (sum % 10 == 0) {
    cout << 0 << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}


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

const int MOD = 1000 * 1000 * 1000 + 7;

bool isPrime(int x) {
    if(2 <= x && x <= 3)
        return true;
    int d = 2;
    while(d * d <= x && x % d != 0) d++;
    return x % d != 0;
}

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    vector<int> p;
    for(int i = 2; i <= n; i++)
        if(isPrime(i)) {
            //cout << i << endl;
            p.push_back(i);
        }
    vector<int> cnt;
    for(auto x: p) {
        int y = x, cur = 0;
        while(y <= n) {
            cur += n / y;
            y *= x;
        }
        cnt.push_back(cur);
    }
    int ans = 1;
    for(auto x: cnt) {
        ans = (1LL * ans * (x + 1)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	int n,table[100],count;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

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

		count = 0;

		for(int i=n-2; i >= 0; i--){
			for(int k=0; k <= i; k++){
				if(table[k] > table[k+1]){
					swap(table[k],table[k+1]);
					count++;
				}
			}
		}

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

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

int main() {
  double a,b,x;
  double n,ans=0;
  cin >> a >>b >> x;
  if(x*2>a*a*b) {
    n= ((x*2-a*a*b)/(a*a));
    ans = atan2((b-n),a);
  }else if(x*2<a*a*b) {
    n= ((a*a*b-x*2)/(a*b));
    ans= atan2(b,(a-n));
  }else{
    ans = atan2(b,a);
  }
  ans =ans*180/3.14159265;
  cout << setprecision(12) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const ll mod1 = 100000000007;
const int p = 233;
map<ll,int>has1;
ll hh[5015]={0};
ll pow1[5015]={0};
char s[5005]={0};
ll gethashcode(int i,int j){
    return hh[j]-hh[i-1]*pow1[j-i+1];
}
int n;
ll num;
int check(int m){
    has1.clear();
    for(int i=1;i+m-1<=n;i++){
        num=gethashcode(i,i+m-1);
        if(has1[num]){
            if(has1[num]+m<=i){
                return 1;
            }
        }
        else
            has1[num]=i;
    }
    return 0;
}
int main()
{
    pow1[0]=1;
    for(int i=1;i<5005;i++){
        pow1[i]=pow1[i-1]*p;
    }
    scanf("%d",&n);
    scanf("%s",s+1);
    hh[0]=0;
    for(int i=1;i<=n;i++)
        hh[i]=hh[i-1]*p+s[i]-'a';
    int ans = 0 ;
    int l=1,r=n;
    //cout << gethashcode(1,1)<<endl;
    //cout << check(1) << endl;
    while(l<r){
        int m=(l+r)/2;
        if(check(m)){
            ans=m;
            l=m+1;
        }
        else
            r=m;
    }
    printf("%d\n",ans);
    return 0;
}
//
//13
//orangerangeao




Measured memory_bytes: 640
import math
# A=[3,5,2,1,4]
# n=5
# A=[3,1,2]
# n=3
n=int(input())
A=list(map(int,input().split()))
def merge(A,left,mid,right):
    global count
    L=A[left:mid]+[math.inf]
    R=A[mid:right]+[math.inf]
    i,j=0,0
    for k in range(left,right):
        if L[i]<R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1
            count+=len(L)-1-i
#             print(len(L)-1-i)
#     print("A:",A[left:right])
    
            
def mergeSort(A,left,right):
    if left+1<right:
        
        mid=(left+right)//2
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)
count=0
mergeSort(A,0,n)
print(count)


Measured memory_bytes: 28952
#include<stdio.h>
int main(void) {
	int A ,B,X;
	scanf("%d%d%d", &A, &B,&X);
	

	if (A > X|| (A<X&&A+B<X)) {
		printf("NO");
	}
	else if (A <= X && A + B >= X) {
		printf("YES");
	}

	return 0;
}



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

const int N=500005;

int n,d;
char str[N],a[10]={'k','e','y','e','n','c','e'};

int main(){
	scanf("%s",str);
	n=strlen(str);
	for(int i=0;i<8;i++){
		int f=1;
		for(int j=0;j<i;j++)if(str[    j]!=a[j])f=0;
		for(int j=i;j<7;j++)if(str[n-7+j]!=a[j])f=0;
		if(f){printf("YES");return 0;}
	}printf("NO");
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	int n;
	string s;
	cin >> n >> s;
	rep(i, s.size()) {
		s[i] += n;
		if (s[i] > 65+25)s[i] -= 26;
	}
	c(s);
	ed;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;


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

	c -= a - b;

	cout << max(0, c) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 1e6+3;
#define LL long long
const LL mod = 998244353;
 
struct node
{
	int n,m;
	int id;
	int a,b;
}a[N];
 
 
bool cmp(node a,node b)
{
	if(a.n!=b.n){
		return a.n<b.n;
	}
	return a.m<b.m;
}
bool cmp1(node a,node b)
{
	return a.id<b.id;
}
 
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int k,f;
		scanf("%d%d",&k,&f);
		a[i].n=k;
		a[i].m=f;
		a[i].id=i;
	}
	sort(a+1,a+1+m,cmp);
	int p;
	for(int i=1;i<=m;i++){
		if(a[i].n==a[i-1].n){
			p++;
		}else{
			p=1;
		}
		a[i].a=a[i].n;
		a[i].b=p;
	}
	sort(a+1,a+1+m,cmp1);
	for(int i=1;i<=m;i++)
		printf("%06d%06d\n",a[i].a,a[i].b);
 
	return 0;
}

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 1e5+20;
const double EPS= 1e-10;

int h[MAXN];
int dp[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(2)<< fixed;
    int n, k;
    cin>> n>> k;
    forn(i,n){
        cin>> h[i];
    }

    memset(dp,1e6,sizeof dp );
    dp[0]=0;
    dp[1]= abs(h[0]-h[1]);
    fore(i,2,n-1){
        for1(j, min(k,i)){
            dp[i]= min(dp[i], dp[i-j] + abs(h[i]-h[i-j]) );
        }
    }
    cout<< dp[n-1]<<el;
}


Measured memory_bytes: 1024
#![allow(unused_imports)]

use std::cmp;
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

pub const MOD: usize = 1000000007;

fn main() {
    let (sx, sy, tx, ty): (i32, i32, i32, i32) = input_four();
    let dx = tx - sx;
    let dy = ty - sy;

    let mut ans = String::new();
    add(&mut ans, &'R', dx);
    add(&mut ans, &'U', dy);
    add(&mut ans, &'L', dx);
    add(&mut ans, &'D', dy+1);
    add(&mut ans, &'R', dx+1);
    add(&mut ans, &'U', dy+1);
    add(&mut ans, &'L', 1);
    add(&mut ans, &'U', 1);
    add(&mut ans, &'L', dx+1);
    add(&mut ans, &'D', dy+1);
    add(&mut ans, &'R', 1);

    println!("{}", ans);
    // dbg!(ans.len());
}

fn add(s: &mut String, c: &char, n: i32) {
    for i in 0..n {
        s.push(*c);
    }
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
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; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m ;
    cin >> n >> m ;
    cout << n*(n-1)/2 + m*(m-1)/2 <<endl ;
    

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<double> hight;
  for(double n;cin >>n;) hight.push_back(n);
  sort(hight.begin(),hight.end());
  cout <<hight[hight.size()-1]-hight[0]<<endl;
  return 0;
}

Measured memory_bytes: 1304
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) < 0) ? -(a) : (a))

#define FOR(var, to)          for (register int var = 0; var < to; var++)
#define FROMTO(var, from, to) for (register int var = from; var <= to; var++)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

static inline s64 rs64() {
	s64 a;
	scanf("%" SCNd64, &a);
	return a;
}

static inline void wi(int a) {
	printf("%d", a);
}

static inline void wu64(u64 a) {
	printf("%" PRIu64, a);
}

int main() {
	s64 s = rs64();
	s64 c = rs64();
	
	s64 res;
	if (s*2 < c) {
		s64 c_left = c-s*2;
		res = s+c_left/4;
	} else {
		res = c/2;
	}
	
	printf("%" PRId64, res);
	
	return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
# 明らかに背の高い人が前に存在しない
total = 0
now = A[0]  # 基準
for i in range(1, N):
    # 基準の方が高い場合
    if now >= A[i]:
        total += now - A[i]
        # この場合基準はそのまま
    else:
        # 基準の方が低いなら基準を更新
        now = A[i]
print(total)


Measured memory_bytes: 32060
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr int mod = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<ll> asum(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    asum[i] = asum[i + 1] + a[i];
  }
  // lb 以上の握手を行う時 m 回以下になる
  ll lb = inf, ub = 0;
  auto check = [&](ll x) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      auto itr = lower_bound(a.begin(), a.end(), x - a[i]);
      sum += distance(itr, a.end());
    }
    return sum;
  };
  while (lb - ub > 1) {
    ll mid = (lb + ub) / 2;
    if (check(mid) <= m) {
      lb = mid;
    } else {
      ub = mid;
    }
  }
  ll ret = 0, cnt = check(lb);
  for (int i = 0; i < n; i++) {
    auto itr = lower_bound(a.begin(), a.end(), lb - a[i]);
    int index = distance(a.begin(), itr), kosuu = distance(itr, a.end());
    ret += a[i] * kosuu + asum[index];
  }
  cout << ret + (lb - 1) * (m - cnt) << endl;
}


Measured memory_bytes: 1792
a = []
while True:
    b = map(int,raw_input().split())
    if b == [0, 0]:
        break
    a.append(b)
for list in a:
    h, w = list
    k = 0
    l = 0
    x = []
    y = []
    while k < w:
        if k % 2 == 0:
            x.append('#')
            y.append('.')
        else:
            x.append('.')
            y.append('#')
        k = k + 1
    while l < h:
        if l % 2 == 0:
            print ''.join(x)
        else:
            print ''.join(y)
        l += 1
    print 

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

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


  if(N%2==1){
    cout<<"0"<<endl;
  }
  else{
    
    cout << N/10+N/50+N/250+N/1250+N/6250+N/31250+N/156250+N/781250+N/3906250+N/19531250+N/97656250+N/488281250LL+N/2441406250LL+N/12207031250LL+N/61035156250LL+N/305175781250LL+N/1525878906250LL+N/7629394531250LL+N/38146972656250LL+N/190734863281250LL+N/953674316406250LL+N/4768371582031250LL+N/(4768371582031250LL*5)+N/(4768371582031250LL*25)+N/(4768371582031250LL*125)+N/(4768371582031250LL*625)<< endl;
  }
}




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


int main() {

    int x;
    cin >> x;
    if (x==3||x==5||x==7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> A(N+1);
  multiset<int> num;

  for(int i=1;i<=N;i++) {
    std::cin >> A[i];
  }
  num.insert(A[1]);
  for(int i=2;i<=N;i++){
    if(A[i]<=*num.begin()){
      num.insert(A[i]);
    }else{
      auto itr = num.lower_bound(A[i]);
      itr--;
      num.insert(A[i]);
      num.erase(itr);
    }
  }
  std::cout << num.size() << '\n';
  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    string s;
    cin >> s;
    int n = s.size();

    rep(i, n){
        if(s[i]!=s[n-1-i]){
            cout << "No" << endl;        
            return 0;
        }
    }

    rep(i, (n-1)/2){
        if(s[i]!=s[(n-3)/2-i]){
            cout << "No" << endl;        
            return 0;
        }
    }

    rep(i, (n-1)/2){
        if(s[i+(n+1)/2]!=s[n-1-i]){
            cout << "No" << endl;        
            return 0;
        }
    }

    cout << "Yes" << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
/*
 * ARC097_C.cpp
 *
 *  Created on: May 12, 2018
 *      Author: 13743
 */

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;

int seq[30000] = {0};
int seq2[30000];

int powI(int x, int n) {
	int ans = 1;
	while(n--) {
		ans *= x;
	}
	return ans;
}

void quickSort(int l, int r, int* a, int* b) {
	if(l >= r) return;
	int piv = a[r];
	int i = l - 1;
	for(int j=l; j<r; j++) {
		if(a[j] <= piv) {
			i++;
			swap(a[i], a[j]);
			swap(b[i], b[j]);
		}
	}
	swap(a[i+1], a[r]);
	swap(b[i+1], b[r]);
	quickSort(l, i, a, b);
	quickSort(i+2, r, a, b);
}

int main() {
	int k;
	char s[5010];
	cin >> s;
	cin >> k;

	int n=0;
	for(int i=0; s[i]!='\0'; i++) {
		n++;
	}
	for(int i=0; i<5; i++) {
		s[n+i] = 'a'-1;
	}

	for(int i=0; i<n; i++) {
		for(int j=0; j<5; j++) {
			for(int k=0; k<=j; k++) {
				seq[5*i+j] += (s[i+k]-'a'+1)*powI(50, 4-k);
			}
		}
	}

	for(int i=0; i<=29000; i++) {
		seq2[i] = i;
	}

	quickSort(0, 5*n-1, seq, seq2);

	int ii=0;
	int num = -1;
	while(k > 0) {
//		cout << seq[ii] << endl;
		if(num != seq[ii]) {
			k--;
			num = seq[ii];
		}
		ii++;
	}
	ii--;
	int he = seq2[ii] / 5;
	int rem = seq2[ii] - he*5;
	for(int i=0; i<=rem; i++) {
		if(he+i < n)
			cout << s[he + i];
	}
	cout << endl;
}




Measured memory_bytes: 768
#include<stdio.h>
#define WHITE 0
#define BLACK 1
#define GRAY -1
#define NUM 100
void dfs();
void visit(int);

int n,color[NUM+1],m[NUM+1][NUM+1],d[NUM+1],f[NUM+1],time;
int main(){
  int u,k,a,i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      m[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&a);
      m[u][a]=1;
    }
  }
  dfs();

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  
  return 0;
}

void dfs(){
  int i;
  for(i=1;i<=n;i++){
    color[i]=WHITE;
  }
  time = 0;
  for(i=1;i<=n;i++){
    if(color[i]==WHITE){
      visit(i);
    }
  }
}

void visit(int u){
  int j;
  color[u]=GRAY;
  d[u]=++time;
  for(j=1;j<=n;j++){
    if(m[u][j]==1){
      if(color[j]==WHITE){
	visit(j);
      }
    }
  }
  color[u]=BLACK;
  f[u]=++time;
}



Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int 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 MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll h; cin >> h;
		if(!h) break;
		ll w = 5;
		vvl a(h,vl(w));
		rep(i,h) rep(j,w) cin >> a[i][j];
		ll ans = 0;
		while(1){
			ll plus = 0;
			rep(i,h){
				rep(j,w){
					if(a[i][j] == -1) continue;
					ll t = j;
					while(t < w && a[i][t] == a[i][j]){
						t++;
					}
					if(t-j >= 3){
						REP(k,j,t) plus += a[i][k], a[i][k] = -1;
					}
				}
			}
			rep(j,w){
				ll modify = 0;
				for(ll i=h-1; i>=0; i--){
					if(a[i][j] == -1) modify++;
					else{
						if(modify){
							a[i+modify][j] = a[i][j];
							a[i][j] = -1;
						}
					}
				}
			}
			ans += plus;
			if(!plus) break;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3124