akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  db maxcon = 0;
  ll ans1 = 0, ans2 = 0;
  rep(i, 0, 31)rep(j, 0, 31){
    ll water = a * 100 * i + b * 100 * j;
    ll maxsugar = min(f - water, water * e / 100);
    for(ll k = 0; k * c <= maxsugar; k++){
      ll l = (maxsugar - k * c) / d;
      ll sugar = l * d + k * c;
      db con = (db)sugar / (db)(sugar + water);
      if(maxcon <= con){
        maxcon = con;
        ans1 = sugar + water;
        ans2 = sugar;
      }
    }
  }
  cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 256
use proconio::input;
fn main() {
    input!(x: usize, y: usize);
    for i in 0..=100 {
        for j in 0..=100 {
            if i + j == x && 2 * i + 4 * j == y {
                println!("Yes");
                return;
            }
        }
    }

    println!("No");
}


Measured memory_bytes: 2128
n=int(input())
a=sorted([int(input()) for i in range(n)])
a1=a[:n//2]
a2=a[n//2:]
a2.sort(reverse=True)
a2=[a2[-1]]+a2[:-1]
b=[]
for i in range(n):
  if i%2==0:
    b.append(a2[i//2])
  else:
    b.append(a1[i//2])
s=0
p=b[0]
for i in range(1,n):
  s+=abs(p-b[i])
  p=b[i]

if n%2==0:
  print(s)
  exit()
a1=a[:n//2+1]
a2=a[n//2+1:]
a2.sort(reverse=True)
a1=[a1[-1]]+a1[:-1]


b=[]
for i in range(n):
  if i%2==0:
    b.append(a1[i//2])
  else:
    b.append(a2[i//2])
t=0
p=b[0]
p
for i in range(1,n):
  t+=abs(p-b[i])
  p=b[i]
  
print(max(s,t))

Measured memory_bytes: 9432
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
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; }



int main() {
    int a[2];
    cin >> a[0] >> a[1];
    sort(a, a+2);
    int ans;
    if (a[0] == 1 && a[1] == 2) ans = 3;
    if (a[0] == 1 && a[1] == 3) ans = 2;
    if (a[0] == 2 && a[1] == 3) ans = 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public final class Main{
    public static void main(String[] args){
        FastScanner stdIn = new FastScanner(System.in);
        long n = stdIn.nextLong();
        long[] h = new long[(int)n];
        for(int i=0; i<n; i++){
            h[i] = stdIn.nextLong();
        }

        for(int i=(int)n-2; i>=0; i--){
            if(h[i]-h[i+1]>1){
                System.out.println("No");
                return;
            }else if(h[i]-h[i+1]==1){
                h[i] = h[i]-1;
            }
        }
        System.out.println("Yes");
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public long nextInt() {
        return Integer.parseInt(next());
    }

}


Measured memory_bytes: 40484
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

bool solve(){
    vector<int> cnt(15);
    vector<int> a(6);
    for (auto &&i : a) scanf("%d", &i), cnt[i]++;
    for (int i = 1; i <= 13; ++i) {
        if(i != 7 && !cnt[i]) cnt[i] = -1;
    }
    if(cnt[1] == cnt[13]){
        return cnt[1] != 1;
    }
    int l = 7, r = 7, cnt1 = 0, cnt2 = 0;
    if(cnt[1] == 1){
        while(true){
            if(cnt[l-1] == 1) l--, cnt[l] = 0, cnt1++;
            else if(cnt[r+1] == 1) r++, cnt[r] = 0, cnt1++;
            if(cnt1 == 6) return true;
            if(cnt[r+1] == -1) r++, cnt[r] = 0, cnt2++;
            else if(cnt[l-1] == -1) l--, cnt[l] = 0, cnt2++;
            if(cnt2 == 6) return false;
        }
    }else {
        while(true){
            if(cnt[r+1] == 1) r++, cnt[r] = 0, cnt1++;
            else if(cnt[l-1] == 1) l--, cnt[l] = 0, cnt1++;
            if(cnt1 == 6) return true;

            if(cnt[l-1] == -1) l--, cnt[l] = 0, cnt2++;
            else if(cnt[r+1] == -1) r++, cnt[r] = 0, cnt2++;
            if(cnt2 == 6) return false;
        }
    }
}

int main() {
    int n;
    cin >> n;
    while(n--) {
        puts(solve() ? "yes" : "no");
    }
    return 0;
}


Measured memory_bytes: 3156
#include<stdio.h>
#include<string.h>

int n,m,i,j;
char s[1000][9],x[9];

int main(){
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n*2;i++)scanf("%s",s[i]);
		//printf("\nAKB%d\n",n);
		scanf("%d",&m);
		for(i=0;i<m;i++){
			scanf("%s",x);
			for(j=0;j<=n;j++){
				if(x[0]==s[j*2][0]){
					//strcpy(x,s[i]);
					x[0]=s[j*2+1][0];
					break;
				}
			}
			printf("%c",x[0]);
		}
		printf("\n");
		scanf("%d",&n);
	}
	
	return 0;
}

Measured memory_bytes: 0
import re
n, q = map(int, input().split())
s = input()

def isAC(i):
    return s[i:i + 2] == "AC"

cs = [0] * n
for i, v in enumerate(s[:-1]):
    if isAC(i):
        cs[i] = 1

cs.insert(0, 0)
for i in range(1, len(cs)):
    cs[i] += cs[i - 1]

for query in range(q):
    left, right = map(int, input().split())
    result = cs[right] - cs[left - 1]
    if right < n and isAC(right - 1):
        result -= 1
    print(result)



Measured memory_bytes: 7924
#include<stdio.h>
int main(void)
{
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a>b) printf("a > b\n");
	else if(a<b) printf("a < b\n"); 
	if(a==b) printf("a == b\n");
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;

int ans = 0;
int N, M;
vector<vector<int> > V;
int walk(int x, bool visited[]){
    /* 閉路対策 */
    bool flag = true;
    for(int i = 0; i < N; i++) if(visited[i] == false) flag = false;
    
    if(flag) return 1;
    
    int ret = 0;
    for(int  i = 0; i < V[x].size(); i++){
        if(!visited[V[x][i]]) {
            visited[V[x][i]] = true;
            ret += walk(V[x][i], visited);
            visited[V[x][i]] = false;
        }
    }
    return ret;
}

int main(void){
    // Your code here!
    cin >> N >> M;
    V.resize(N);
    int a;
    int b;
    for(int i = 0; i < M; i++){
        cin >> a >> b;
        a--;
        b--;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    bool visited[N];
    for(int i=0; i < N; i++) visited[i] = false;
    visited[0] = true;
    cout << walk(0, visited) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int freq[100];

int main () {
  int n;
  int index_mode = 0;

  while(cin >> n)
    freq[n-1]++;

  for(int i = 0; i < 100; i++){
    if (freq[i] > freq[index_mode])
      index_mode = i;
  }

  for(int i = 0; i < 100; i++){
    if (freq[i] == freq[index_mode])
      cout << i+1 << endl;
  }
}

Measured memory_bytes: 1160
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
t = sum(B)
j = M
for i in range(N+1):
    while j > 0 and t > K:
        j -= 1
        t -= B[j]
    if t > K:
        break
    ans = max(ans, i+j)
    if i == N:
        break
    t += A[i]
print(ans)

Measured memory_bytes: 40604
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()

int main()
{
  int N, K; cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];

  map<int, int> mp;
  for (int i = 0; i < N; ++i) {
    mp[A[i]]++;
  }

  vector<pair<int, int>> pairs;
  for (auto v : mp) {
    pairs.push_back(make_pair(v.second, v.first));
  }

  sort(ALL(pairs));

  int i = pairs.size(), ans = 0;
  for (auto v : pairs) {
    if (i <= K) break;

    ans += v.first;
    i--;
  }

  cout << ans << endl;
}

Measured memory_bytes: 12536
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 105
using namespace std;
bool debug=false;

bool check(int n){
  int k=0,x=n;
  while(x){
    k++;
    x/=10;
  }
  if(k==1){
    return true;
  }else if(k==2){
    if(n%10==n/10)return true;
  }else if(k==3){
    if(n%10==n/100)return true;
  }else if(k==4){
    if((n%10==n/1000)&&(n/10%10==n/100%10))return true;
  }
  return false;
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<1000;i++){
    if(check(n-i)&&n-i>0){
      cout<<n-i<<endl;
      return 0;
    }
    if(check(n+i)&&n<=10000){
      cout<<n+i<<endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3104
/*
    author: Salam_35
    Created at :

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    string s;
  cin >> s;
  if(s=="ABC")cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;
}


Measured memory_bytes: 3620
#include<stdio.h>


int main(){

  int m, n, nma, nmi, max;
  int p[200];
  int i;

  while(scanf("%d %d %d", &m, &nmi, &nma),m){
    max=0;
    for(i=0;i<m;i++) scanf("%d", &p[i]);
    for(i=nmi;i<=nma;i++){
      if(max<=p[i-1]-p[i]){
        max=p[i-1]-p[i];
        n=i;
      }
    }
    printf("%d\n", n);
  }

  return 0;
}

Measured memory_bytes: 600
#line 1 "main.cpp"

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { ++i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const noexcept { return l; }
  constexpr iterator end() const noexcept { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { --i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const noexcept { return r; }
  constexpr iterator end() const noexcept { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  i64 L, R, D;
  std::cin >> L >> R >> D;
  std::cout << R / D - (L - 1) / D << '\n';
  return 0;
}

/**
 * @title Template
 */


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

void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
bool isprime(ll n)
{
    if(n%2==0)return false;
    for(int i=3;i<=sqrt(n);i+=2)
    {
        if(n%i==0)return false;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
  //  input();
    ll n,sum=0;
    cin>>n;
   	map<ll,int>m;
   	rep(i,0,n)
   	{
   		ll num;
   		cin>>num;
   		sum+=num;
   		m[num]++;
   	}
   	cin>>n;
   	rep(i,0,n)
   	{
   		ll n1,n2;
   		cin>>n1>>n2;
   		sum=sum-n1*m[n1];
   		sum=sum+n2*m[n1];
   		m[n2]+=m[n1];
   		m[n1]=0;
   		cout<<sum<<endl;
   	}
}




Measured memory_bytes: 9416
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::vector<int> bars(n); for (auto& b : bars) std::cin >> b;
	std::sort(bars.begin(), bars.end());
	int count = 0;
	for (auto i = 1; i < n; ++i) for (auto j = 0; j < i; ++j) {
		for (auto k = i + 1; k < n && bars[k] < bars[i] + bars[j]; ++k) ++count;
	}
	std::cout << count << '\n';
}


Measured memory_bytes: 256
s = str(input())
t = str(input())
d = dict()
f = dict()
for i in range(0,len(s)):
    if s[i] in d:
        if d[s[i]] != t[i]:
            print("No")
            break 
    else:
        d[s[i]] = t[i]
    if t[i] in f:
        if f[t[i]] != s[i]:
            print("No")
            break
    else:
        f[t[i]] = s[i]
else:
    print("Yes")

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int x,y;
  cin >> x >> y;
  x = x+y;
  cout << x%24 << endl;
  
  return 0;

}


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

void addEdge(vector<pair<int, int>> g[], int u, int v, int w) {
	// g[u].push_back({v, w});
	// g[v].push_back({u, w});
	g[u].push_back(make_pair(v, w));
	g[v].push_back(make_pair(u, w));
}

void dfs_util(vector<pair<int, int>> g[], int s, bool col[], int pcol, vector<bool>& visited) {
	visited[s] = true;
	for(int i=0; i<g[s].size(); ++i) {
		if(visited[g[s][i].first]) {continue;}

		if(g[s][i].second%2) col[g[s][i].first] = !pcol;
		else col[g[s][i].first] = pcol;
		dfs_util(g, g[s][i].first, col, col[g[s][i].first], visited);
	}

}

void dfs(vector<pair<int, int>> g[], int n, bool col[]) {
	col[1] = 0;
	vector<bool> visited(n+1, false);
	dfs_util(g, 1, col, col[1], visited);
	for(int i=1; i<=n; ++i)
		cout << col[i] << ' ';
}


int main() {

	// freopen("a.txt", "r", stdin);

	int N, u, v, w;
	cin >> N;
	vector<pair<int, int>> g[100100];
	for(int i=0; i<N-1; ++i) {
		cin >> u >> v >> w;
		addEdge(g, u, v, w);
	}


	bool col[100101];
	dfs(g, N, col);

	return 0;
}

Measured memory_bytes: 9728
#coding: utf-8
N = int(input())
a = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1] + abs(a[i] - a[i-1]))
    dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]))
print(dp[N-1])


Measured memory_bytes: 13980
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
X = int(input())
ans = 0
if X == 1:
    ans = 1
else:
    for i in range(2,33):
        j = i
        while j*i<=X:
            ans = max(j*i,ans)
            j = j*i
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

int main(){
	int t;
	scanf(" %d", &t);
	for(int tt=0; tt<t; ++tt){
		int n, h[100];
		scanf(" %d", &n);
		for(int i=0; i<n; ++i) scanf(" %d", &h[i]);
		
		int up=0, down=0;
		for(int i=1; i<n; ++i){
			int dif=h[i]-h[i-1];
			if(dif>0){
				if(up<dif) up=dif;
			}
			else{
				dif = -dif;
				if(down<dif) down=dif;
			}		
		}		
		
		printf("%d %d\n", up, down);
	}
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x, y;
	cin >> x >> y;
	int total = 0;
	if (x <= 3)
		total += 4 - x;
	if (y <= 3)
		total += 4 - y;
	if (x == 1 && x == y) {
		total += 4;
	}
	total *= int(1e5);
	cout << total;
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
constexpr int MOD = 1e9 + 7;

long L, R;
long dp[66][2][2][2];

// y % x = y ^ x and x <= y
// y % x is less than x. 
// when (y>>1) > x, MSB(y) == MSB(y^x) > x. so this doesnt fulfill the condition.
// then (x<<1) >= y >= x. In this case, y % x == y - x.
//
// On the other hand, xor is addition without carry-up.
// Digit that will carry when y + x and not when y ^ x, can be found by y & x.
// finally y ^ x is y + x - (y & x)<<1
// Requirement : y % x = y ^ x (y>=x) => y - x = y + x - (y & x)<<1 => x == y & x
//

int main() {
	cin >> L >> R;

	dp[0][0][0][0] = 1;
	
	// l = 1 : x is already more than L
	// r = 1 : y is already less than R
	// j = 1 : MSB of x and y is matched
	//
	// (x, y) = (1, 1), (0, 1), (0, 0) is required on each digit
	bool x[3] = {1, 0, 0}, y[3] = {1, 1, 0};

	for(int i = 0; i < 60; ++i) {
		bool lb = L>>(59-i)&1, rb = R>>(59-i)&1;

		for(int l = 0; l < 2; ++l) {
			for(int r = 0; r < 2; ++r) {
				for(int j = 0; j < 2; ++j) {

					// loop for updating
					for(int k = 0; k < 3; ++k) {
						if(!l && !x[k] && lb) continue;
						if(!r && y[k] && !rb) continue;
						if(!j && x[k] ^ y[k]) continue;
						
						int nl = (x[k] ^ lb   ? 1 : l);
						int nr = (y[k] ^ rb   ? 1 : r);
						int nj = (x[k] & y[k] ? 1 : j);

						(dp[i+1][nl][nr][nj] += dp[i][l][r][j]) %= MOD;
					}

				}
			}
		}
	}

	long ans = 0;
	for(int l=0;l<2;++l) for(int r=0;r<2;++r) ans = (ans + dp[60][l][r][1]) % MOD;

	cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <cstring>
#define INF 1000001
typedef long long llong;
using namespace std;



int main() {

	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i == 0 || i == H - 1 || j == 0 || j == W - 1)cout << '#';
				else cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3108
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			boolean[] stone = new boolean[n];
			stone[0] = (scan.nextInt() == 1)?true:false;
			for(int i = 2;i <= n;i++){
				if((i&1) == 0){
					boolean t = (scan.nextInt() == 1)?true:false;
					if(stone[i-2] != t){
						for(int j = i-2;j >= 0 && stone[j] != t;j--){
							stone[j] = t;
						}
					}
					stone[i-1] = t;
				}else{
					stone[i-1] = (scan.nextInt() == 1)?true:false;
				}
			}
			int count = 0;
			for(int i = 0;i < n;i++){
				if(!stone[i]){
					count++;
				}
			}
			System.out.println(count);
		}
	}
}

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

using namespace std;

typedef long long ll;
ll n, k, A[200050], fw[200050];
void update(ll p, ll v){
	for(;p<=n;p+=p&(-p)) fw[p]+=v;
}
ll query(ll p){
	ll ans = 0;
	for(;p;p-=p&(-p)) ans+=fw[p];
	return ans;
}
int main(){
	cin >> n >> k;
	vector<ll> v;
	for(ll i = 1; i<=n; i++){
		cin >> A[i];
		A[i]+=A[i-1];
		v.push_back(A[i]-k*i);
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	for(ll i = 0; i<=n; i++){
		ll val = lower_bound(v.begin(), v.end(), A[i]-k*i)-v.begin()+1;
		ans += query(val);
		update(val,1);
	}
	cout << ans;
	// A[i]-A[j] >= k*(i-(j)) -> A[i]-k*i >= A[j]-k*j for range [j+1,i]
}


Measured memory_bytes: 5104
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 15 , inf = 2e9;
int n , m;
int g[N][N] , cost[1<<N][N] , f[1<<N][N];
int sum[1<<N] , vis[1<<N] , del[1<<N] , times;

void Update(int &x,int d){
    x = min(x , d);
}

#define lb(x) (x&-(x))
int Cost(int mask){
    if(mask == 0) return 0;
    if(vis[mask] == times) return sum[mask];
    int &ret=sum[mask];
    vis[mask]=times;
    int y=lb(mask);
    return ret = del[y] + Cost(mask^y);
}

int main(){
    cin >> n >> m;
    rep(i,0,m){
        int u,v,c;
        cin>>u>>v>>c;
        --u;--v;
        g[u][v]=g[v][u]=c;
    }
    rep(i,0,1<<n) rep(j,0,n) rep(k,0,n) if(i>>k&1) cost[i][j]+=g[j][k];
    rep(i,0,1<<n) rep(j,0,n) f[i][j]=inf;
    f[1][0]=0;
    rep(i,0,1<<n) rep(j,0,n) if(f[i][j]!=inf){
        rep(k,0,n) if(!(i>>k&1)) del[1<<k] = cost[i^(1<<j)][k];
        rep(k,0,n) if(!(i>>k&1) && g[j][k]) Update(f[i|1<<k][k] , f[i][j] + del[1<<k]);
        int x=((1<<n)-1)^i;
        times++;
        for(int k=x;k;k=(k-1)&x) Update(f[i|k][j] , f[i][j] + Cost(k));
    }
    printf("%d\n",f[(1<<n)-1][n-1]);
    return 0;
}


Measured memory_bytes: 4480
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, q = sc.nextInt
  val ca = sc.next.toCharArray
  val acs = (0 until n - 1).scanLeft(0){(z, i) =>
    z + (if (ca(i) == 'A' && ca(i + 1) == 'C') 1 else 0)
  }
  println((1 to q).map{i =>
    val l, r = sc.nextInt
    acs(r - 1) - acs(l - 1)
  }.mkString("\n"))
}

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

int main() {
  long long n, k;
  cin >> n >> k;
  cout << (2 * k * k * k - 3 * k * k * n - 6 * k * k + 3 * k * n - 2 * k + 
           n * n * n + 3 * n * n + 8 * n + 12) / 6 % 1000000007 << endl;
  return 0;
}

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

using namespace std;

#define int long long

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }
template <typename T> T fact(T n) { return (n == 0 ? 1 : n * fact(n - 1)); }
template <typename T> T modpow(T a, T e, T m) { return (e == (T)0 ? 1 : ((a % m) * modpow((a % m), e - 1, m)) % m); }

constexpr int MOD = 1e9 + 7;

signed main(void) {
  int a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,A,B = map(int,read().split())

if A > B:
    answer = 0
elif N == 1:
    if A != B:
        answer = 0
    else:
        answer = 1
else:
    x = A * (N-1) + B
    y = A + B * (N-1)
    answer = y - x + 1

print(answer)

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin>>N;
	rep(i,0,N+1)
	{
		if((int)(i*1.08)==N)
		{
			cout<<i<<endl;
			return 0;
		}
	}

	cout<<":("<<endl;

	return 0;
}


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

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

ANS=0

for i in range(1,M+1):
    for j in range(1,D+1):

        if (j%10)>=2 and (j//10)>=2 and (j%10)*(j//10)==i:

            ANS+=1

print(ANS)

Measured memory_bytes: 3064
//last edited at 26.8.2015 by charis

#include<iostream>
using namespace std;

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	int maxv=A[1]-A[0];
	int min=A[0];
	for(int i=1; i<N; i++){
		maxv=(maxv>A[i]-min)?maxv:A[i]-min;
		min=(A[i]<min)?A[i]:min;
	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 1940
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};
    static long pl,mi;

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

//        int n=sc.nextInt();
        char a[]=sc.nextString().toCharArray();
        char b[]=sc.nextString().toCharArray();

        int dp[][] = new int[a.length+1][b.length+1];
        for (int i = 0; i < a.length; i++) {
			for (int t = 0; t < b.length; t++) {
				if(a[i]==b[t]) {
					dp[i+1][t+1] = dp[i][t] + 1; 
				}
				else {
					dp[i+1][t+1] = max(dp[i+1][t], dp[i][t+1]);
				}
			}
		}
        int i=a.length,t=b.length;
        String s="";
        while(i>0&&t>0) {
        	if(a[i-1]==b[t-1]) {
        		s=a[i-1]+s;
        		i--; t--;
        	}
        	else {
        		if(dp[i][t-1]<dp[i-1][t])i--;
        		else t--;
        	}
        }
        db(dp[a.length][b.length]);
	     
        out.println(s);
        out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//    public int compareTo(P p){
//        return d-p.d; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 83412
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#include<cstring>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))

using namespace std;



int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}


bool vis1[100010], visN[100010];
int dist1[100010], distN[100010];
vector<int> tree1[100010];

void dfs1(int pos) {
	for (auto i : tree1[pos]) {
		if (!vis1[i]) {
			vis1[i] = true;
			dist1[i] = dist1[pos] + 1;
			dfs1(i);
		}
	}
	return;
}
void dfsN(int pos) {
	for (auto i : tree1[pos]) {
		if (!visN[i]) {
			visN[i] = true;
			distN[i] = distN[pos] + 1;
			dfsN(i);
		}
	}
	return;
}

int main() {
	int N; cin >> N;
	memset(vis1, 0, sizeof(vis1)); memset(visN, 0, sizeof(visN));
	vis1[0] = true; visN[N - 1] = true;
	dist1[0] = 0;
	distN[N-1] = 0;
	REP(i, N-1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		tree1[a].push_back(b);
		tree1[b].push_back(a);
	}
	dfs1(0);
	dfsN(N - 1);
	int Fen=0, Snu=0;
	FOR(i,0, N) {
		if (dist1[i] <= distN[i]) {
			Fen++;
		}
		else {
			Snu++;
		}
	}
	if (Fen > Snu) {
		cout << "Fennec" << endl;
	}
	else {
		cout << "Snuke" << endl;
	}
}


Measured memory_bytes: 9856
#include <iostream>
#include <cstring>

#define MAX 110
 
using namespace std;
 
int W, H, field[MAX][MAX];

int calc(int x,int y) {
  int count = 0;
  
  const int dx[2][6] = {{-1,0,-1,1,-1,0},{0,1,-1,1,0,1} };
  const int dy[2][6] = {{-1,-1,0,0,1,1} ,{-1,-1,0,0,1,1}};
  
  field[y][x] = -1;
  
  for(int i = 0 ; i < 6 ; i++) {
    int nx = x + dx[y%2][i], ny = y + dy[y%2][i];
    
    if(nx < 0 || nx > W+1) continue;
    if(ny < 0 || ny > H+1) continue;
    if(field[ny][nx] == 1) {
      count++;
      continue;
    }
    if(field[ny][nx] == 0) {
      count += calc(nx, ny);
    }
    
  }
  return count;
}

int main(void) {
  
  while(cin >> W >> H) {
    memset(field, 0, sizeof(field));
    int ans;     
    for(int i = 1 ; i <= H ; i++)
      for(int j = 1 ; j <= W ; j++) cin >> field[i][j];
    
    ans = calc(0,0);
 
    cout << ans << endl;
  } 
  return 0;
}

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

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

#define pb push_back

const int MOD = 1e9 + 7;

void dec(ll& x, ll y) {
	x -= y;
	if (x < 0)
		x += MOD;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   ll sum = 0;
   ll a[n + 1];
   for (int i = 1; i <= n; i++) {
   	cin >> a[i];
   	sum += a[i];
   }
   sum %= MOD;
   ll res = 0;
   for (int i = 1; i <= n; i++) {
   	dec(sum, a[i]);
   	res += (sum * a[i]) % MOD;
   	res %= MOD;
   }
   cout << res;
   return 0;
}

Measured memory_bytes: 5180
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RSLong;
            var ans = Calc(n[1]) ^ Calc(n[0] - 1);
            WriteLine(ans);
        }

        public static long Calc(long a)
        {
            //if (a < 0) return 0;
            // 10^3 <= 1024 = 2^10
            // 10^12 <= 2^40
            long ans = 0;
            for (int i = 1; i <= 45; i++)
            {
                long cnt;

                if (i == 1)
                {
                    cnt = ((a + 1) / 2) % 2;
                    ans += cnt << (i - 1);
                    continue;
                }
                long loop = (long)Pow(2, i);
                long amari = (a % loop) + 1;
                amari -= loop / 2;

                if (amari <= 0) cnt = 0;
                else cnt = amari % 2;
                ans += cnt << (i - 1);
            }
            return ans;
        }
    }
    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 13396
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	LL a, b;
	cin >> a >> b;
	int ans = INF;
	for (LL i = a; i <= b; i++)
	{
		for (LL j = i + 1; j <= b; j++)
		{
			if ((i*j) % 2019 < ans)
				ans = (i*j) % 2019;
			if (ans == 0)
				return cout << 0 << endl, 0;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

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

    string s;

    cin >> s;

    if(s.at(0) == s.at(1) && s.at(1) == s.at(2)) printf("No\n");
    else printf("Yes\n");

    return 0;
}

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

int main()
{
    int D;
    cin >> D;
    int c[26];
    int sd[D][26];
    for (int i = 0; i < 26;i++)
        cin >> c[i];
    for (int i = 0; i < D;i++){
        for (int k = 0; k < 26;k++){
            cin>>sd[i][k];
        }
    }
    int ans[D];
    ans[0] = 0;
    int lastDay[26];
    for (int i = 0; i < 26;i++){
        lastDay[i] = 0;
    }
    int tmp = 0;
    int diff = 0;
    for (int i = 0; i < D; i++){
        cin >> tmp;
        diff = sd[i][tmp - 1];
        lastDay[tmp - 1] = i+1;
        for (int j = 0; j < 26;j++){
            if(j==tmp-1)
                continue;
            diff -= c[j] * ((i+1) - lastDay[j]);
        }
        if(i==0)
            ans[i] = diff;
        else
            ans[i] = ans[i-1]+diff;
    }
    for (int i = 0; i <D;i++)
        cout << ans[i] << endl;
}



Measured memory_bytes: 3620
import java.util.Arrays;
import java.util.Scanner;

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

        int N = Integer.parseInt(sc.next());
        int[] L = new int[N];
        int max;
        int sum = 0;

        for (int i = 0; i < N; i++) {
            L[i] = Integer.parseInt(sc.next());
            sum += L[i];
        }
        Arrays.sort(L);

        max = L[L.length - 1];

        if (max < (sum - max)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

using namespace std;

int main() {
	int n;
	string aa = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<string> c(n);
		for (int i = 0; i < n; i++) {
			cin >> c[i];
		}
		int abc[26] = { 0 };
		bool h2 = true;
		for (int i = 0; i < n; i++) {
			//cout << c[i][0] - 'A' << endl;
			abc[c[i][0]-'A']++;
			int km = 0;
			int kn = 0;
			for (int j = 0; j < 26; j++) {
				//cout << j << endl;
				if (km < abc[j]) {
					km = abc[j];
					kn = j;
				}
			}
			//cout << i << endl;
			bool h = true;
			for (int j = 0; j < 26; j++) {
				if (j != kn && abc[j] + n - (i + 1) >= km) {
					h = false;
				}
			}
			if (h) {
				cout << aa[kn] << ' ' << i + 1 << endl;
				h2 = false;
				break;
			}
		}
		if (h2) {
			cout << "TIE" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3152
n = int(input())
l = list(map(int,input().split(" ")))
l.sort()
cnt = 0 
def search(arr,target,start,last):
    while last > start:
        mid = (last + start)//2
        if arr[mid] < target:
            start = mid + 1 
        else:
            last = mid 
    return start

for i in range(0,n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        target = a + b 
        f1 = search(l,target,j+1,n)
        cnt+= f1 - j -1
print(cnt)



Measured memory_bytes: 43740
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort()

s = p[:x] + q[:y]
s.sort(reverse=True)
ans = sum(s)

for _ in range(c):
    d, e = s.pop(), r.pop()
    if e > d:
        ans -= d
        ans += e
    else: break

print(ans)


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

#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++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const LL MOD = 1000000007;

void solve(long long N, std::vector<std::string> S){
    LL ans = S[0][0] == S[1][0] ? 3 : 6;
    int idx = S[0][0] == S[1][0] ? 1 : 2;
    bool prevI = S[0][0] == S[1][0];
    while(idx<N){
        if(S[0][idx] == S[1][idx]) {
            if(prevI) ans *= 2;
            idx++;
            prevI = true;
        } else {
            if(prevI) ans *= 2;
            else ans *= 3;
            idx += 2;
            prevI = false;
        }

        ans %= MOD;
    }

    cout << ans << endl;
}

// rg rg rb
// gr gb gr

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(2);
    for(int i = 0 ; i < 2 ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
  ll sum=0;
  ll N;
  cin >> N;
  for(ll i=1;i<=N;i++){
    if(i%3LL!=0&&i%5LL!=0){sum+=i;}
  ;}
  
  cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll int
using namespace std;

struct QAQ{
	int tw, fv;
};

bool operator <(QAQ a, QAQ b){
	return a.tw < b.tw;
} 

QAQ orz[200010];
int awa[200010][19];
int n;

int Q(int l, int k){
	int QAQ = 0;
	for (int i = k; i <= 18; i++){
		QAQ += awa[n][i] - awa[l - 1][i];
	}
	return QAQ;
}

int main(){
	cin >> n;
	for (int i = 1; i <= n; i++){
		char ch;
		ch = getchar();
		while (!isdigit(ch)) ch = getchar();
		long long zs = 0;
		long long qwq = 1000000000;
		while (isdigit(ch)){
			zs *= 10;
			zs += ch - '0';
			ch = getchar();
		}
		if (ch == '.'){
			ch = getchar();
			while (isdigit(ch)){
				zs *= 10;
				zs += ch - '0';
				qwq /= 10;
				ch = getchar();
			}
		} 
		long long qaq = qwq * zs;
		while (qaq % 2 == 0){
			orz[i].tw++;
			qaq >>= 1;
		} 
		while (qaq % 5 == 0){
			orz[i].fv++;
			qaq /= 5;
		}
	}
	sort(orz + 1, orz + 1 + n);
//	cout << awa[1][11] << endl;
	for (int i = 1; i <= n; i++){
		orz[i].tw = min(orz[i].tw, 18);
		orz[i].fv = min(orz[i].fv, 18);
		awa[i][orz[i].fv]++;
		for (int j = 0; j <= 18; j++){
			awa[i][j] += awa[i - 1][j];
		}
	}
	long long ANS = 0;
	for (int i = 1; i < n; i++){
		int L = i + 1, R = n;
		int ans = 0;
		while (L <= R){
			int mid = (L + R) >> 1;
			if (orz[mid].tw + orz[i].tw >= 18){
				R = mid - 1;
				ans = mid;
			}
			else{
				L = mid + 1;
				ans = mid + 1;
			}
		}
//		cout << Q(ans, 18 - orz[i].fv) << endl;
		if (orz[i].tw + orz[ans].tw >= 18){
			ANS += Q(ans, 18 - orz[i].fv);
		}
	}
	cout << ANS << endl;
	return 0;
	Mashu;
}

Measured memory_bytes: 19968
N,K = map(int,input().split())

# 普通に書いてよい。。？
probability = 0.0

for i in range(1,N+1) :
    toss_count = 0
    point = i
    while(K > point) :
        toss_count += 1
        point = point * 2
    
    probability += 1 / (N * pow(2,toss_count))

print(probability)

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>


#define INF 100000000
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; }

using namespace std;

int main(){
  int i,j,k,n,d,a,b;
  cin >> a>>b;

  if((a+b)%2==1)cout <<"IMPOSSIBLE"<<endl;
  else{
    cout << (a+b)/2;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;


int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	ll ans=0, sum=0, sqr=0;
	int N;
	cin >> N;
	vl v(N);
	for(auto&q : v) cin >> q, sum+=q, sum%=MOD, sqr+=(q%MOD)*(q%MOD), sqr%=MOD;

	ans=(sum*sum-sqr);
	if(ans%2!=0) ans+=MOD;
	ans/=2;
	ans%=MOD;
	
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 4776
#include<stdio.h>

int main()
{
	int i, j, k,sum, min;
	int arr[8][8] = {
		{ 1,2,1,2,1,4,1,4 },
		{ 1,2,1,4,1,4,1,2 },
		{ 1,4,1,2,1,2,1,4 },
		{ 1,4,1,4,1,2,1,2 },
		{ 2,1,2,1,4,1,4,1 },
		{ 2,1,4,1,4,1,2,1 },
		{ 4,1,2,1,2,1,4,1 },
		{ 4,1,4,1,2,1,2,1 },
	}, arr_p[8] = { 0 };

	while (scanf("%d %d %d %d %d %d %d %d", &arr_p[0], &arr_p[1], &arr_p[2], &arr_p[3], &arr_p[4], &arr_p[5], &arr_p[6], &arr_p[7]) != EOF)
	{
		min = -1;

		for (k = 0; k < 8; k++)
		{
			sum = 0;
			for (i = 0; i < 8; i++)
			{
				if (arr_p[i] > arr[k][i])
				{
					sum += arr_p[i] - arr[k][i];
				}
			}
			
			if (sum < min||min==-1)
			{
				min = sum;
				j = k;
			}
		}

		for (i = 0; i < 8; i++)
		{
			printf("%d",arr[j][i]);
			if (i != 7)
			{
				putchar(' ');
			}
			else
			{
				putchar('\n');
			}
		}

	}


	return 0;
}


Measured memory_bytes: 604