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

int main() {
  // a,bの平均値を xの小数点以下を切り上げて得られる整数を出力する。
	int a, b;
	cin >> a >> b;
  
  	// a = 7, b = 4;
  
  	cout << (a + b) / 2 + (a + b) % 2 << endl;
}
  

Measured memory_bytes: 3568
#include <cstdio>
#include <algorithm>
#include <utility>
typedef long long int64;
static const int MAXN = 2e5 + 6;

int n, k;
int a[MAXN];
int64 s[MAXN];

inline int discretize(int n, int64 *arr)
{
    static std::pair<int64, int> p[MAXN];
    for (int i = 0; i < n; ++i) p[i] = std::make_pair(arr[i], i);
    std::sort(p, p + n);
    int rk = -1;
    for (int i = 0; i < n; ++i) {
        if (i == 0 || p[i].first != p[i - 1].first) ++rk;
        arr[p[i].second] = rk;
    }
    return rk + 1;
}

namespace fwk {
    int f[MAXN] = { 0 };
    inline void add(int pos, int inc) { for (++pos; pos < MAXN; pos += (pos & -pos)) f[pos] += inc; }
    inline int sum(int rg) { int ans = 0; for (++rg; rg; rg -= (rg & -rg)) ans += f[rg]; return ans; }
    inline int sum(int lf, int rg) { return sum(rg) - sum(lf - 1); }
}

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

    s[0] = 0;
    for (int i = 0; i < n; ++i) s[i + 1] = s[i] + a[i];
    //for (int i = 0; i <= n; ++i) printf("%lld%c", s[i], i == n ? '\n' : ' ');
    discretize(n + 1, s);
    //for (int i = 0; i <= n; ++i) printf("%lld%c", s[i], i == n ? '\n' : ' ');

    int64 ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans += fwk::sum(s[i]);
        fwk::add(s[i], +1);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 6400
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author aps
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HGrid1 solver = new HGrid1();
        solver.solve(1, in, out);
        out.close();
    }

    static class HGrid1 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int h = in.nextInt();
            int w = in.nextInt();

            int[][] a = new int[h + 1][w + 1];
            long[][] dp = new long[h + 1][w + 1];

            for (int i = 1; i <= h; i++) {
                char[] s = in.next().toCharArray();
                for (int j = 1; j <= w; j++) {
                    if (s[j - 1] == '.') a[i][j] = 1;
                    else a[i][j] = 0;
                }
            }

            dp[1][1] = 1;
            for (int i = 1; i <= h; i++) {
                for (int j = 1; j <= w; j++) {
                    if (a[i][j] == 1) {
                        dp[i][j] = Numbers.add(dp[i][j], dp[i - 1][j]);
                        dp[i][j] = Numbers.add(dp[i][j], dp[i][j - 1]);
                    }
                }
            }

            out.println(dp[h][w]);
        }

    }

    static class Numbers {
        public static final long mod = (long) 1e9 + 7;

        public static long add(long a, long b) {
            a += b;
            if (a >= mod) a -= mod;
            return a;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  string n;
  cin >> n;
  rep(i,(int)n.size()) {
    if(n[i] == '7') {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 3628
import sys
from collections import deque
# sys.setrecursionlimit(10**7)
 
def main():
    n, q = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n-1)]
    px = [list(map(int, input().split())) for i in range(q)]
    # indexがノード
    adj = [[] for _ in range(n+1)]
    for a, b in ab:
            adj[a].append(b)
            adj[b].append(a)
    # indexが直接初めにノードに加えられる得点
    v = [0] * (n+1)
    for p,x in px:
        v[p] += x
    # dequeを使ったキューによるBFS
    # 子をindexで、親ノードを要素で
    parent = [None] * (n+1)
    q = deque([1])
    while q:
        par = q.popleft()
        for chl in adj[par]:
            if chl == parent[par]:
                continue
            v[chl] += v[par]
            parent[chl] = par
            q.append(chl)
    # print(parent)
    # print(v)
    ans = ' '.join(map(str,v[1:]))
    print(ans)   
 
 
    # dequeを使ったスタックによるDFS
    # 子をindexで、親ノードを要素で
    # parent = [None] * (n+1)
    # q = deque([1])
    # while q:
    #     par = q.pop()
    #     for chl in adj[par]:
    #         if chl == parent[par]:
    #             continue
    #         v[chl] += v[par]
    #         parent[chl] = par
    #         q.append(chl)
    # # print(parent)
    # # print(v)
    # ans = ' '.join(map(str,v[1:]))
    # print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 129860
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int q,a,b,i,j;
    string str,order,p,s;
    cin >> str >> q;
    for(i=0;i<q;i++){
        cin >> order>>a>>b;
        if(order=="replace"){
            cin>>p;
            str.replace(a,b-a+1,p);
        }
        else if(order=="reverse"){
            s=str.substr(a,b-a+1);
            for(j=a;j<=b;j++) str[j]=s[b-j];
        }
        else if(order=="print"){
            cout << str.substr(a,b-a+1) << endl;
        }
    }
    
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int a[maxn], dp[maxn];
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	for(int i=1; i<=n; i++)
	{
		if(i<=k) dp[i] = abs(a[i] - a[1]);
		else {
			dp[i] = dp[i-1] + abs(a[i]-a[i-1]);
			for(int j=2; j<=k; j++)
				dp[i] = min(dp[i], dp[i-j] + abs(a[i]-a[i-j]));
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}

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

using namespace std;

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

    int n, x, y;

    cin >> n >> x >> y;

    vector<int> c(n - 1);

    for(int i = 1; i <= n - 1; ++i) {
        for(int j = i + 1; j <= n; ++j) {
            ++c.at(min(j - i, abs(x - i) + abs(y - j) + 1) - 1);
        }
    }

    for(int i = 1; i < n; ++i) {
        printf("%d\n", c.at(i - 1));
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#define DBL_MIN 0.000000000000001
using namespace std;

int main(void){
    vector<unsigned> datas;
    int N;
    cin >> N;
    unsigned tp;
    for(int i =0; i < N; i++){
        int tmp;
        cin >> tmp;
        datas.push_back(tmp);
        if(i == 0) tp = tmp;
        else tp ^= tmp;
    }

    for(int i =0; i < N; i++){
        if(i != 0) cout << " ";
        cout << (tp ^ datas[i]);
    }
    cout << endl;
}

Measured memory_bytes: 4324
#include <iostream>
#include <string>

using namespace std;

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

#define M 2000

bool ab[100000],ac[100000],bc[100000];

bool match(char c1, char c2){
return (c1 == '?' || c2 == '?' || c1 == c2);
}

int main(void){
int i,j;

string a,b,c;
cin >> a >> b >> c;

int A = a.length();
int B = b.length();
int C = c.length();

REP(i,A) REP(j,B) if(!match(a[i], b[j])) ab[i-j+50000] = true;
REP(i,A) REP(j,C) if(!match(a[i], c[j])) ac[i-j+50000] = true;
REP(i,B) REP(j,C) if(!match(b[i], c[j])) bc[i-j+50000] = true;

int ans = 3 * M;
for(i=-2*M;i<=2*M;i++) for(j=-2*M;j<=2*M;j++) if(!ab[i+50000] && !ac[j+50000] && !bc[j-i+50000]){
int L = min(0, min(i, j));
int R = max(A, max(B + i, C + j));
ans = min(ans, R - L);
}

cout << ans << endl;

return 0;
}


Measured memory_bytes: 256
l, r = map(int, input().split())
ans = 2018
if r - l >= 2019:
    for i in range(l, l + 2019 + 1):
        for n in range(l, i):
            ans = min(ans, (i * n) % 2019)
else:
    for i in range(l, r + 1):
        for n in range(l, i):
            ans = min(ans, (i * n) % 2019)
print(ans)

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


int main(int argc, char const *argv[])
{
    int n, m;
    scanf("%d", &n);
    scanf("%d", &m);
    int l[m], r[m];
    for (int i=0; i < m; i++){
        scanf("%d", &l[i]);
        scanf("%d", &r[i]);
    }

    int l_max = 0;
    for (int i=0; i < m; i++){
        if (l_max < l[i])
            l_max = l[i];
    }

    int r_min = 100000;
    for (int i=0; i < m; i++){
        if (r[i] < r_min)
            r_min = r[i];
    }

    int card = r_min - l_max + 1;
    if (card < 0)
        card = 0;

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



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

using namespace std;


int main(){
	int x, n, val;
	cin >> x >> n;
	set<int> st;
	for(int i=0;i<n;++i){
		cin >> val;
		st.insert(val);
	}
	int mini = INT_MAX, ans;
	for(int i=x;i >= -1000;--i){	
		if(st.count(i) == 0){
			if(mini > abs(x - i)){
				ans = i;
				mini = abs(x - i);
				break;
			}
		}
	}
	for(int i=x;i<= 1000;++i){
		if(st.count(i) == 0){
			if(mini > abs(x - i)){
				ans = i;
				mini = abs(x - i);
				break;
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
const int MX=100000;
int dp[MX+5];
int a[105];
int n,k;
void solve()
{
  dp[0]=0;
  for(int i=1;i<a[0];i++) dp[i]=0;
  for(int i=a[1];i<=k;i++)
  {
    int f=0;
    for(int j=1;j<=n&&i-a[j]>=0;j++)
    {
      if(!dp[i-a[j]])f=1;
    }
    dp[i]=f;
  }
}
int main()
{
  cin>>n>>k;
  for(int i=1;i<=n;i++)cin>>a[i];
  solve();
  if(dp[k])cout<<"First"<<endl;
  else cout<<"Second"<<endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		long N = Long.parseLong(st.nextToken());
		long K = Long.parseLong(st.nextToken());
		
		long res1 = N % K;
		long res2 = K - res1;
		
		System.out.println(Math.min(res1, res2));

	}

}

Measured memory_bytes: 32544
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int x,y,s,i,j,xs[10000][2];
    
    while (1) {
        
        int xs_count=0,max=-1;
        
        scanf("%d %d %d",&x,&y,&s);
        
        if (x==0&&y==0&&s==0) {
            break;
        }
        int xsx = (100.0+x);
        //?¨????x??§???????????????????¨????s?????????????????????????????¢???
        for (i = 1; i < s-1; i++) {
            for (j = 1; j < s-1; j++) {
                
                int xsxs = i*xsx/100 + j*xsx/100;
                
                if (s==(xsxs)) {
                    
                    xs[xs_count][0]=i;
                    xs[xs_count][1]=j;
                    xs_count++;
                    
                }
            }
        }
        
        //s????????£??????????????????????¨????????????§??????????????¨???
        
        for (i = 0; i < xs_count; i++) {
            int sy = (100.0+y);
            int xsy = xs[i][0]*sy/100 + (int)xs[i][1] * sy/100;
            
            if (xsy > max) {
                max = xsy;
            }
            
        }
        
        
        printf("%d\n",max);
    }
    return 0;
}

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

void SelectionSort(vector<int> A, int N){
  int min = A.at(0);
  int min_i;
  int count =0;
  bool flag;
  for(int i=0; i<N; i++){
    flag = 0;
    min = A.at(i);
    for(int j = i; j<N; j++){
      if(min > A.at(j)){
        min = A.at(j);
        flag = 1;
        min_i = j;
      }
    }
    if(flag){
      swap(A.at(i), A.at(min_i));
      count ++;
    }
  }
  for(int i=0;i<N;i++){
    if(i < N-1)
      cout << A.at(i) << ' ';
    else
      cout << A.at(i) << endl;
  }
  cout << count << endl;
}



int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N;i++)
    cin >> A.at(i);

  SelectionSort(A,N);
}



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

using namespace std;

int main(){
	long long int n, m;
	cin >> n>> m;
	long long int sum = n*m;
	if(n > 1 && m > 1)
		(sum % 2 == 0)?cout << sum/2:cout << sum/2 + 1;
	else cout << 1;
}




Measured memory_bytes: 3616
N, x = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
r = -1
s = 0
for i in range(N):
  s += As[i]
  if s > x:
    r = i
    break
if r == -1:
  if x == s:
    r = N
  else:
    r = N-1
print(r)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main () {
    char s;
    cin >> s;
    char ans;
    if ( s == 'A' ){
        ans = 'T';
    }else if( s == 'C' ){
        ans = 'G';
    }else if( s == 'T'){
        ans = 'A';
    }else if( s == 'G' ){
        ans = 'C';
    }
    cout << ans << endl;
        
}



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

typedef long long ll;

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

    int a,b,c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.size()==2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char c[3][3];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    for (int i = 0; i < 3; i++) {
        cout << c[i][i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>
#include <numeric>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

const string YES = "Yes";
const string NO = "No";
int a, b, c;
ll ans;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n; cin >> n;
  string s; cin >> s;
  vector<ll> cnt(3, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
        if (s[i] == "RGB"[j]) ++cnt[j];
      }
    }

  ll ans = cnt[0] * cnt[1] * cnt[2];
  for (int i = 0; i < n; ++i) {
    for (int l = 1; i + l * 2 < n; ++l) {
      int j = i + l * 1,
          k = i + l * 2;
      if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
          --ans;
        }
      }
    }
    cout << ans << endl;



  return 0;
}


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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long

const int upper = 1e5 + 20;
const int M = (int) 1e9 + 7;
const int inf = (int) 1e17;
const double eps =  1e-8;

vector<vi> adj;
int score[1001][1001];
vector<int> perm, position, indeg;

vector<int> status;

int n, k;

bool cycle = false;

void dfs (int current) {
	status[current] = 1;
	for (auto v: adj[current]) {
		if (status[v] == 2) continue;
		if (status[v] == 1) {
			cycle = true;
			return;
		}

		dfs(v);
	}
	status[current] = 2;
}

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif		

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int N, M, K, a = 0;

int main() {
	cin >> N >> M >> K;
	for (int i = 0; i <= M; i++) {
		a = N*i;
		if (a == K) {
			cout << "Yes" << endl;
			return 0;
		}
		for (int j = 1; j <= N; j++) {
			a += M - 2 * i;
			if (a == K) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#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;

int main() {
    vector<ll> dp(4001);
    dp[0] = 1;
    for (int i = 0; i < 4; ++i) {
        for (int j = 2999; j >= 0; --j) {
            dp[j+1001] -= dp[j];
        }
        for (int j = 0; j < 4000; ++j) {
            dp[j+1] += dp[j];
        }
    }
    ll n;
    while(cin >> n){
        cout << dp[n] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3136
N=int(input())
X= list(map(int, input().split())) 
K=max(X)
Y=0
for j in range(N):
    Y=Y+X[j]**2
for i in range(K+1):
    S=0
    for l in range(N):
        S=S+(X[l]-i)**2
    if S<Y:
        Y=S
print(Y)



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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	ll n , k ;
	cin >> n >> k ;
	vector<ll> h(n);
	rep(i,n) cin >> h[i]; 
	SORT(h);
	ll ans = INF ;
	rep(i,n-k+1){
		chmin(ans,h[i+k-1] - h[i]);
	}
	cout << ans << endl;
}


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

int main(){
	
	for(int n,l;cin>>n>>l,n;){
		int p[20],r[20];
		for(int i=0;i<n;i++){
			char c;
			cin>>c>>p[i];
			r[i]=(c=='R'?1:-1);
		}
		for(int ans=0;;ans++){
			int f=1,li=9999,ri=9999;
			for(int i=0;i<n;i++){
				if(0<p[i]&&p[i]<l)f=0;
				else if(p[i]==0)li=i;
				else if(p[i]==l)ri=i;
			}
			if(f){
				cout<<ans<<" "<<(li!=9999?li:ri)+1<<endl;
				break;
			}
			
			int flg[100]={};
			for(int i=0;i<n;i++){
				p[i]+=r[i];
				if(0<p[i] && p[i]<l)flg[p[i]]++;
			}
			for(int i=0;i<n;i++){
				if(0<p[i] && p[i]<l){
					if(flg[p[i]]>1)r[i]*=(-1);
				}
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 1160
# coding:utf-8
N,K=map(int,raw_input().split())
A=map(int,raw_input().split())

#dp[keta][こえるかも:1 こえない:0]
dp = [[-1, -1] for _ in range(51)]

dp[50][1]=0
for i in range(50):
    k = 49 - i
    mask = 1 << k
    num = 0
    for a in A:
        if (a&mask)!=0: num+=1
    

    if dp[k+1][0]>=0:
        #k+1がこえない => 0/1どっちでも
        dp[k][0] = max(dp[k+1][0] + mask*num, dp[k+1][0] + mask*(N-num))
    
    if dp[k+1][1]>=0:
        #k+1がこえるかも
        if K&mask!=0:
            #X[k]=1として選ぶ => まだこえるかも        
            dp[k][1] = dp[k+1][1] + mask*(N-num)

            #X[k]=0として選ぶ=>もう超えない
            dp[k][0] = max(dp[k][0], dp[k+1][1] + mask * num) # choose as X[k]=0
        else:
            #X[k]=1としては選べない

            #X[k]=0として選ぶ場合=>まだ超えるかも
            dp[k][1] = dp[k+1][1]+mask*num
print(max(dp[0]))



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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int n; cin >> n;
    vi a(n); REP(i, n) cin >> a[i];
    ll ans = 0;
    REP(i, n) FOR(j, i + 1, n) {
        ans += a[i] * a[j];
    }
    cout << ans << endl;
    

    return 0;
}

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

string S;
ll N, K;

ll com(ll N, ll R) {
    if (R < 0 || R > N) return 0;
    if (R == 1) return N;
    else if (R == 2) return N * (N-1) / 2;
    else return N * (N-1) * (N-2) / 6;
}

ll ctoi(char c) {
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5;
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
}

ll pow(ll n, ll k) {
  ll p = 1;
  for (ll i = 0; i < k; i++) {
    p *= n;
  }
  return p;
}

//左からn桁目までが決定している状況で、決定してないD-n桁に0でない数字がk個含まれている場合の数
ll res(int i, int k, bool smaller) {
  if (i == N) {
    if (k == 0) return 1;
    else return 0;
  } else if (k == 0) {
    return 1;
  } else if (smaller) {
    return com(N-i, k) * pow(9, k);
  } else {
    if (S.at(i) == '0') {
      return res(i+1, k, false);
    } else {
      ll ans = res(i+1, k, true);
      ans += (ctoi(S.at(i)) - 1) * res(i+1, k-1, true);
      ans += res(i+1, k-1, false);
      return ans;
    }
    
  }
}


int main() {
  cin >> S;
  N = S.size();
  cin >> K;
  
  cout << res(0, K, false) << endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

const Lmax int = 1e5
const SAVE_MAX int = 511 // 2^9 -1

var DV [SAVE_MAX + 1][Lmax + 1]int
var V []int
var W []int

func solve(v int, L int) int {
	if v <= SAVE_MAX {
		return DV[v][L]
	}

	var a int = solve(v/2, L)
	if W[v] <= L {
		a = max(solve(v/2, L-W[v])+V[v], a)
	}

	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	buf := make([]byte, 1024*1024*128)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N := nextInt()
	V = make([]int, N+1)
	W = make([]int, N+1)
	for i := 1; i <= N; i++ {
		V[i], W[i] = nextInt(), nextInt()
	}

	for v := 1; v <= min(N, SAVE_MAX); v++ {
		for w := 1; w <= Lmax; w++ {
			if W[v] <= w {
				DV[v][w] = max(DV[v/2][w-W[v]]+V[v], DV[v/2][w])
			} else {
				DV[v][w] = DV[v/2][w]
			}
		}
	}

	Q := nextInt()
	for i := 0; i < Q; i++ {
		v, L := nextInt(), nextInt()
		fmt.Fprintf(out, "%d\n", solve(v, L))
	}
}


Measured memory_bytes: 419704
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
l = inp.shift().split(' ')
N = l[0]
K = l[1]
A = inp.shift().split(' ')
o = {}
a = []
for (i=0; i<N; i++) {
    a[A[i]] = (a[A[i]] || 0) + 1
    o[A[i]] = 1
}
keys = Object.keys(o)
c = keys.length - K
if (c > 0) {
    a.sort((b,c) => b - c)
    cnt = 0
    for (k of a) {
        cnt += k
        c--
        if (c===0) {
            break;
        }
    }
    console.log(cnt)    
} else {
    console.log(0)
}


Measured memory_bytes: 53660
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int a[4], b[3];

void f(int d, int sum) {
	if (d == 3) {
		if (sum == 7) {
			for (int i = 0; i < 4; ++i) {
				cout << a[i];
				if (i < 3) {
					if (b[i] == 1)
						cout << "+";
					else
						cout << "-";
				}
			}
			cout << "=7" << endl;
			exit(0);
		}
		return;
	}

	b[d] = 1;
	f(d + 1, sum + a[d + 1]);
	b[d] = 0;

	b[d] = 2;
	f(d + 1, sum - a[d + 1]);
	b[d] = 0;
}

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 4; ++i) {
		a[i] = s[i] - '0';
	}

	f(0, a[0]);

	return 0;
}

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

using namespace std;

#define ll long long
#define Fastest ios_base:: sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"

int main()
{
	int n;
	cin >> n;
	cout << n*n*n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int MAX = 100000+5;
stack<int> S;
char c[MAX];
int main(int argc, char const *argv[])
{
	while(scanf("%s",c) != EOF){
		if(c[0] == '+'){
			int a = S.top();
			S.pop();
			int b = S.top();
			S.pop();
			S.push(a+b);
		}
		else if(c[0] == '*'){
			int a = S.top();
			S.pop();
			int b = S.top();
			S.pop();
			S.push(a*b);
		}
		else if(c[0] == '-'){
			int a = S.top();
			S.pop();
			int b = S.top();
			S.pop();
			S.push(b-a);
		}
		else{
			int a = atoi(c);
			S.push(a);
		}
	}
	printf("%d\n",S.top());
	return 0;
}


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

double dist(pair<double, double> a, pair<double, double> b)
{
	return sqrt((a.first - b.first) * (a.first - b.first) +
		(a.second - b.second) * (a.second - b.second));
}

int main()
{
	int N;
	cin >> N;
	vector<pair<double, double>> points(N);
	for (int i = 0; i < N; ++i)
	{
		double x, y;
		cin >> x >> y;
		points[i] = {x, y};
	}
	
	double sum = 0;
	for (int i = 0; i < N; ++i)
		for (int j = i + 1; j < N; ++j)
			sum += dist(points[i], points[j]);
	
	cout << fixed << setprecision(10) << sum * 2 / N << '\n';
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ull unsigned long long
#pragma comment(linker, "/STACK:64000000")
#define null NULL
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fornr(i, n) for (int i = (n); i >= 0; --i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) a.begin(), a.end()
#define vi vector<int>
#define v(a) vector<a>

typedef long double ld;
typedef pair<ld, ld> pldld;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;


typedef unsigned int ui;
typedef unsigned char uc;
const int infi = 1e9 + 7;
const ll infl = 2e18 + 7;

int ar[101];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
  //  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("suftree.in", "r", stdin); freopen("suftree.out", "w", stdout);
    int n;
    cin >> n;
    int x;
    cin >> x;
    forn(i, n)
        cin >> ar[i];
    sort(ar, ar + n);
    int sum = 0;
    int ans = 0;
    int i;
    for (i = 0; i < n; ++i) {
        if (sum + ar[i] > x)
            break;
        sum += ar[i];
        ++ans;
    }
    if (ans == n && sum < x) {
        --ans;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (int i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(int n, int k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  int n;
  cin>>n;
  cout<<n*n*n<<endl;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N,M;
int cnt [100001];

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

	cin >> N >> M;
	vector< vector<int> > A(M);
	vector<int> p(M);
	FOR(i,0,N){
		int X;
		cin >> X;
		if(++cnt [X] % 2 == 0){
			p [X % M]++;
		}
		A [X % M].push_back(X);
	}

	int ans = 0;
	for(int i = 0;i <= M / 2;i++){
		int j = (M - i) % M;
		if(i == j){
			ans += A [i].size() / 2;
		}
		else{
			int x = A [i].size(),y = A [j].size();
			if(x >= y){
				ans += min(x,y);
				ans += min((x - y) / 2,p [i]);
			}
			else{
				ans += min(x,y);
				ans += min((y - x) / 2,p [j]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6528
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;#include <stdio.h>
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int N, K;
	cin >> N >> K;

	vector<ll> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}

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

	ll ans = LLINF;
	for (int i = 0; i + K - 1 < N; i++) {
		ans = min(ans, H[i + K - 1] - H[i]);
	}

	cout << ans;

}



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

import numpy as np

N = int(readline())
S = np.array(read().split(),np.int64)

answer = 0
for d in range(1,N):
    n = (N-1)//d
    if (N-1)%d == 0:
        n = ((N-1)//d+1)//2
    if n <= 1:
        continue
    x = (S[d:d*n:d] + S[N-1-d:N-1-d*n:-d]).cumsum().max()
    if answer < x:
        answer = x

print(answer)

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

int main(){


int N1,N2;

cin>>N1;
while(N1--){
	int R;
cin>>N2>>R;
int hm=0;
int y,x=0;
int n[100003]={};
for(int i=0;i<N2;i++)
{	cin>>y;
	if(i>0)n[i]=y-x;
	x=y;
}
/*
for(int i=0;i<N2;i++)
	for(int j=N2-1;j>i;j--)
		if(n[j]>n[i]){int t=n[j];n[j]=n[i];n[i]=t;}
	*/
sort(n,n+N2);
long long int s=0;
int W=0;
for(int i=N2-1;i>=0;i--)
{if(W>=R-1)s+=n[i];W++;}//cout<<n[i]<<endl;W++;}
cout<<s<<endl;
}
return 0;
}

Measured memory_bytes: 1568
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	long a=sc.nextInt();	
      	long v=sc.nextInt();	
      	long b=sc.nextInt();	
      	long w=sc.nextInt();	
      	long t=sc.nextInt();	
      	String ans="NO";
      	if(Math.abs(a-b)<=((v-w)*t)){ans="YES";}
      System.out.println(""+ans);
}
}

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

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

	int comming[1001][1001] = {};
	map<P, vector<P>> e;
	rep(i, n) {
		int pre;
		cin >> pre;
		pre--;
		for(int j = 1; j < n - 1; j++) {
			int a;
			cin >> a;
			a--;
			auto p = pair<int, int>(min(i, a), max(i, a));
			e[{min(i, pre), max(i, pre)}].push_back(p);
			comming[min(i, a)][max(i, a)] += 1;
			pre = a;
		}
	}
	queue<P> q;
	rep(i, n) for(int j = i + 1; j < n; j++) {
		if (comming[i][j] == 0) {
			q.emplace(i, j);
		}
	}
	int ans = 0, acc = 0;
	while(!q.empty()) {
		acc += q.size();
		ans += 1;
		queue<P> nxt;
		while(!q.empty()) {
			auto p = q.front(); q.pop();
			for(auto dest: e[p]) {
				int x = dest.first, y = dest.second;
				if (comming[x][y] == 0) continue;
				comming[x][y]--;
				if (comming[x][y] == 0) {
					nxt.emplace(x, y);
				}
			}
		}
		swap(nxt, q);
	}
	if (acc != n * (n - 1) / 2) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}
}


Measured memory_bytes: 58752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){    
  ll A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K <= A) cout << K << endl;
  else if(K <= A + B) cout << A << endl;
  else cout << A - (K - A - B) << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

vector<int> e[MAXn];
int dep[MAXn],dp[MAXn];
void dfs(int x,int p){
    if (x != p) dep[x] = dep[p] + 1;
    for (auto i:e[x]) {
        if (i == p) continue;
        dfs(i,x);
    }
}
int main(){
    IOS();
    int n;
    cin >> n;
    REP (i,n-1) {
        int u,v;
        cin >> u >> v;
        u--, v--;
        e[u].eb(v);
        e[v].eb(u);
    }
    dep[0] = 1;
    dfs(0,0);
    int root = int(max_element(dep,dep+n) - dep);
    RST(dep,0);
    dep[root] = 1;
    dfs(root,root);
    int mxdep = *max_element(dep,dep+n);
    dp[1] = 1;
    dp[2] = 0;
    for (int i=3;i<MAXn;i++) dp[i] = !(dp[i-1]&dp[i-2]);
    debug(mxdep,root);
    if (dp[mxdep]) cout << "First" << endl;
    else cout << "Second" << endl;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int a, b, c;
    cin >> a >> b >> c;

    if((a <= c && c <= b) || (b <= c && c <= a)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

  ll a = 1, b = 1;

  for (int i = 0; i < n; ++i) {
    ll x, y;
    cin >> x >> y;

    ll c1 = (a + x - 1) / x;
    ll c2 = (b + y - 1) / y;
    ll c = max(c1, c2);
    a = x * c;
    b = y * c;
  }

  cout << a + b << endl;
}


Measured memory_bytes: 256
function Main(input) {
  const values = input.split(' ');

  const answer = values.map(Number).reduce((pv, v) => pv + v, 0) >= 22 ? 'bust' : 'win';

  //出力
  console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

cnt = 0

n.times do |i|
  if a[i] < b[i]
    cnt += a[i]
    b[i] -= a[i]

    if a[i + 1] < b[i]
      cnt += a[i + 1]
      a[i + 1] = 0
    else
      cnt += b[i]
      a[i + 1] -= b[i]
    end
  else
    cnt += b[i]
  end
end
puts cnt

Measured memory_bytes: 15380
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1e9+7)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

vector<ll> dijkstra(ll s, vector<vector<pll>>& cost_map){
    vector<ll> d(cost_map.size(), MAXINF);
    priority_queue<pll, vector<pll>, greater<pll>> q;
    q.push(pll(0, s));
    d[s] = 0;
    while(!q.empty()){
        pll f = q.top();q.pop();
        if(d[f.se] < f.fi) continue;
        for(auto v : cost_map[f.se]){
            ll value = f.fi + v.se;
            if(value < d[v.fi]) {
                // d[v.fi] = value;
                q.push(pll(d[v.fi] = value, v.fi));
            }
        }
    }
    return d;
}

int main(void)
{
    ll n,m;
    cin >> n >> m;
    ll s,t;
    cin >> s >> t;
    s--;t--;

    vector<vector<pll>>Y(n);
    vector<vector<pll>>S(n);
    REP(i, m){
        ll u,v;
        cin >> u >> v;
        ll a,b;
        cin >> a >> b;
        u--;v--;
        Y[u].pb(make_pair(v, a));
        Y[v].pb(make_pair(u, a));
        S[u].pb(make_pair(v, b));
        S[v].pb(make_pair(u, b));
    }

    auto yen = dijkstra(s, Y);
    auto snk = dijkstra(t, S);

    vector<ll> ans(n+1,MAXINF);
    RREP(i, n){
        ans[i]=min(ans[i+1], yen[i] + snk[i]);
    }

    // DEBUG_VEC(yen);
    // DEBUG_VEC(snk);
    // DEBUG_VEC(ans);

    REP(i, n){
        pr(1'000'000'000'000'000 - ans[i]);
    }
}

Measured memory_bytes: 19012
n,k=map(int,input().split())
if k>n:
    print(1)
else:
    r=0
    s=0
    sum=0
    for i in range(k):
        r=(r+i)%1000000007
  #      print(r)
        s=(s+n-i)%1000000007
   #     print(s)
    for j in range(k,n+2):
        sum=(sum+s-r+1)%1000000007
 #       print(sum)
        r=(r+j)%1000000007
 #       print(r)
        s=(s+n-j)%1000000007
 #       print(s)
    print(sum)
    
            
        

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

typedef long long ll;

const int mod = 1e9 + 7;

void solve() {
    int N;
    cin >> N;
    vector<int> T(N), A(N);
    rep(i, N) cin >> T[i];
    rep(i, N) cin >> A[i];
    int T_max = 0, T_max_i = 0;
    rep(i, N) if (T[i] > T_max) {
        T_max = T[i];
        T_max_i = i;
    }
    int A_max = 0, A_max_i = 0;
    rep(i, N) if (A[i] >= A_max) {
        A_max = A[i];
        A_max_i = i;
    }
    if (T_max != A_max || T_max_i > A_max_i) {
        cout << 0 << endl;
        return;
    }
    ll ans = 1, h = 0;
    rep(i, T_max_i + 1) {
        if (T[i] > h) {
            h = T[i];
        } else {
            ans = ans * h % mod;
        }
    }
    rep(i, A_max_i - T_max_i - 1) ans = ans * h % mod;
    for (int i = A_max_i + 1; i < N; i++) {
        if (A[i] < h) {
            h = A[i];
        } else {
            ans = ans * h % mod;
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 1024
n = int(input())
a = input()
b = input()
c = input()
res = 0

for i in range(n):
    if a[i] == b[i] == c[i]:
        pass
    elif a[i] != b[i] and b[i] != c[i] and c[i] != a[i]:
        res += 2
    else:
        res += 1
else:
    print(res)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
	int N;
	int A[200000];
	int max=0;
	long long total = 0LL;
	cin >> N;
	for (int a = 0;a < N;a++)
		cin >> A[a];
	max = A[0];
	for (int i = 0;i < N;i++) {
		if (max < A[i])
			max = A[i];
		
		total += max - A[i];
	}
	cout << total;

}

Measured memory_bytes: 4384
#include <stdio.h>
int main(void)
{
	int a;
  char s[3];
  for(int i=0;i<3;i++){
    scanf("%s",&s[i]);
  }
  if(s[0]=='a'){
    if(s[1]=='b'){
      if(s[2]=='c'){
        printf("Yes");
      }else{
        printf("No");
      }
    }else if(s[1]=='c'){
        if(s[2]=='b'){
          printf("Yes");
        }else{
          printf("No");
        }
    }else if(s[1]=='a'){
      printf("No");
    }
  }else if(s[0]=='b'){
    if(s[1]=='a'){
      if(s[2]=='c'){
        printf("Yes");
      }else{
        printf("No");
      }
    }else if(s[1]=='c'){
      if(s[2]=='a'){
        printf("Yes");
      }else{
        printf("No");
      }
    }else if(s[1]=='b'){
      printf("No");
    }
  }else if(s[0]=='c'){
    if(s[1]=='a'){
      if(s[2]=='b'){
        printf("Yes");
      }else{
        printf("No");
      }
    }else if(s[1]=='b'){
      if(s[2]=='a'){
        printf("Yes");
      }else{
        printf("No");
      }
    }else if(s[1]=='c'){
      printf("No");
    }
  }else{
    printf("No");
  }
  return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int s, x, y;

int main(){
	cin >> s >> x >> y;
	cout << min(x, y) << endl;
	cout << max(0, x + y - s)<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std ;
int main() {
	int n , x ,count;
	cin>> n >> x ;
	
	while( n !=0 || x!=0){
		count=0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				for (int k = 1; k <=n ; k++) {
					if ( i+j+k == x && j > i && k > j){
					    count++;
					}
				}
			}			
		}
		cout<< count << endl;
		cin >> n >> x;
		
	}
	return 0;
}


Measured memory_bytes: 3068
//package com.test.WYB;
import java.util.Scanner;
class Main {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
//		int[] arr = {1,2,3,4};
//		int[] arr2 = arr;
//		System.out.println(arr[3]);
//		System.out.println(arr2[3]);
//		int[] arr3;
//		arr3 = arr;
//		int[] arr4 = new int[4];
//		int[] arr5 = new int[] {1,2,4,8};
//		System.out.println(arr3[3]);
//		System.out.println(arr4[3]);
//		System.out.println(arr5[3]);
//		System.out.println(arr.length);
//		Scanner in = new Scanner(System.in);
//		int[] arr = new int[10];
//		
//		for(int i=0;i<arr.length;i++)
//		{
//			arr[i] = in.nextInt();
//		}
//		for(int i=0; i<arr.length;i++)
//		{
//			System.out.println(arr[i]);
//		}
		//System.out.println(arr);
		Scanner in = new Scanner(System.in);
		//int[] arr = new int[10];
		double a = in.nextInt();
		double b = in.nextInt();;
		System.out.println(a/b);
	}
}


Measured memory_bytes: 23124