akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


deque<int> edge[24][4];
int n;
//int dp[24][1 << 23];
map<int, map<int, int> > dp;
int dfs(int p, int visit)
{
	if (dp[p].count(visit))
		return dp[p][visit];
	else if (!visit)
	{
		bool f = false;
		rep (i, 4)
			foreach (e, edge[p][i])
				f |= *e == n;
		return dp[p][visit] = f ? 1 : 0;
		//return f ? 1 : 0;
	}

	int res = 0;
	rep (i, 4)
	{
		foreach (e, edge[p][i])
		{
			if (*e == n)
				continue;

			if (visit & (1 << *e))
			{
				res += dfs(*e, visit ^ (1 << *e));
				break;
			}
		}
	}

	return dp[p][visit] = res;
	//return res;
}
int main()
{
	int w, h;
	while (scanf("%d%d", &w, &h), w | h)
	{
		rep (i, 24)
			rep (j, 4)
				edge[i][j].clear();

		pint church;
		vector<pint> pos;
		rep (i, h)
		{
			rep (j, w)
			{
				int t;
				scanf("%d", &t);
				if (t == 1)
					pos.push_back(pint(j, i));
				else if (t == 2)
					church = pint(j, i);
			}
		}
		n = pos.size();
		pos.push_back(church);

		rep (i, pos.size())
		{
			vector<pint> hor, ver;
			rep (j, pos.size())
			{
				if (pos[i].first == pos[j].first)
					ver.push_back(pint(pos[j].second, j));
				else if (pos[i].second == pos[j].second)
					hor.push_back(pint(pos[j].first, j));
			}
			sort(all(hor));
			sort(all(ver));

			foreach (it, hor)
			{
				if (it->first < pos[i].first)
					edge[i][3].push_front(it->second);
				else if (pos[i].first < it->first)
					edge[i][1].push_back(it->second);
			}
			foreach (it, ver)
			{
				if (it->first < pos[i].second)
					edge[i][2].push_front(it->second);
				else if (pos[i].second < it->first)
					edge[i][0].push_back(it->second);
			}
		}

		//rep (i, n + 1)
		//{
		//	printf(">%d: (%d, %d)\n", i, pos[i].first, pos[i].second);
		//	rep (j, 4)
		//	{
		//		printf("%d: ", j);
		//		foreach (t, edge[i][j])
		//			printf("(%d, %d) ", pos[*t].first, pos[*t].second);
		//		puts("");
		//	}
		//}

		//memset(dp, ~0, sizeof(dp));
		dp.clear();
		int all_visit = (1 << n) - 1;
		printf("%d\n", dfs(n, all_visit));

		//int s = 0;
		//rep (i, n)
		//	if (~dp[i][0])
		//		s += dp[i][0];
		//printf("%d\n", s);
	}
}

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

const int N = 1e5 + 10;

int cnt[N];

int main(){
	int n, m, u, v;
	scanf("%d %d",&n,&m);
	memset(cnt, 0, sizeof(cnt));
	for (int i = 1; i <= m; i++){
		scanf("%d %d",&u,&v);
		cnt[u]++; cnt[v]++;
	}
	for (int i = 1; i <= n; i++){
		if (cnt[i] & 1){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

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

int v[111111], c[111111];
vector<vector<pair<int, int>>> g;
int main() {
    int n, m = 0;
    cin >> n;
    g.resize(n + 1);
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    v[1] = -1;
    queue<int> q;
    q.push(1);
    while(!q.empty()) {
        int i = q.front();
        q.pop();
        int k = 1;
        for(auto p : g[i]) {
            if(v[p.first])
                continue;
            if(v[i] == k)
                k++;
            c[p.second] = v[p.first] = k++;
            q.push(p.first);
        }
        m = max(m, k);
    }
    cout << m - 1 << '\n';
    for(int i = 1; i < n; i++)
        cout << c[i] << '\n';
    cout << flush;
    return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<locale>
using namespace std;

int main(void){
  int n,k; cin>>n>>k;
  string s; cin>>s;
  locale l = locale::classic();
  s[k-1] = tolower(s[k-1], l);
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);

int main () {
  int n, d;
  cin >> n >> d;
  int x[15][15];
  rep(i,n)rep(j,d) cin >> x[i][j];

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      int d2 = 0;
      rep(k,d) {
        d2 += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      bool flag = false;
      for (int k = 0; k <= d2; ++k) {
        if (k*k == d2) flag = true;
      }
      if (flag) ans++;
    }
  }

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

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

int main() {
    ios_base::sync_with_stdio(false);
    int n,m,temp1,temp2;
    cin>>n>>m;
    std::vector<vector<int>>v(n+1);
    for(int i=0;i<m;i++)
    {
        cin>>temp1>>temp2;
        v[temp1].push_back(temp2);
        v[temp2].push_back(temp1);
        
    }
    std::vector<int>vis(n+1,n+1) ;
    std::vector<int>ans(n+1) ;
    vis[1]=0;
    std::queue<int>q ;
    q.push(1);
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for(int i=0;i<v[x].size();i++)
        {
            if(vis[x]+1<vis[v[x][i]])
            {
               vis[v[x][i]]=vis[x]+1;
               ans[v[x][i]]=x;
               q.push(v[x][i]);
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==n+1)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 10784
#include <iostream>
#define rep(i, n) for(int i=0; i<N; i++)

using namespace std;

int main(void){
  int N, K;
  cin >> N >> K;
  int x[N];
  rep(i, N)
    cin >> x[i];
  //入力終わり

  int ans = 0;
  rep(i, N){
    //距離が小さい方を選べばよい
    ans += min(x[i], K-x[i])*2;
  }

  //解答
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3604
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (w + 1) for _ in range(n + 1)]

for i in range(1, n + 1):
    wi, vi = wv[i - 1]
    for j in range(w + 1):
        if j < wi:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wi] + vi)
print(dp[n][w])


Measured memory_bytes: 119916
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int n, a;
    cin >> n >> a;
    if(n%1000 <= a) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;

public class Main {
	public static void main(String args[]) throws IOException{
		String str1,str2;
		int i,d = 0;
		BigInteger big1,big2,total;
		
		BufferedReader input =
				new BufferedReader(new InputStreamReader(System.in));
		i = Integer.parseInt(input.readLine());
		while(d++ < i){
			str1 = input.readLine();
			big1 = new BigInteger(str1);
			str2 = input.readLine();
			big2 = new BigInteger(str2);
			total = big1.add(big2);
			if(str1.length() > 80 || str2.length() > 80 ||
				total.toString().length() > 80){
				System.out.println("overflow");
			}else{
				System.out.println(total);
			}
		}
	}
}

Measured memory_bytes: 17792
#include <cstdlib>
#include <iostream>
 
using namespace std;
 
void insertion_sort(int arr[], int length);
void print_array(int array[],int size);
 
int main() {
     
     
    int l=0,i=0;
    cin>>l;
    int array[l];
    while(cin>>array[i] && i < l-1)
    {
         
        cout<<array[i]<<" ";
        i++;
    }
    cout<<array[l-1];
     
    cout<<endl;
    insertion_sort(array,l);
     
    return 0;
}
 
void insertion_sort(int arr[], int length) {
    int i, j ,tmp;
    for (i = 1; i < length; i++) {
        j = i;
        while (j > 0 && arr[j - 1] > arr[j]) {
            tmp = arr[j];
            arr[j] = arr[j - 1];
            arr[j - 1] = tmp;
            j--;
        }
        print_array(arr,length);
    }
}
 
void print_array(int array[], int size){
    int j;
    for (j=0; j<size;j++)
    {
        for (j=0; j<size-1;j++)
            cout<< array[j] <<" ";
        cout<< array[size-1] ;
    }
    cout << endl;
}

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

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();

            Console.WriteLine($"{arr[0] * arr[0] * Math.PI:0.000000000} {arr[0] * 2 * Math.PI:0.000000000}");
        }
    }
}



Measured memory_bytes: 20460
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


def main():
    k = int(input())
    i = 1
    x = 7 % k
    seen = {x}
    while x != 0:
        x = (x * 10 + 7) % k
        i += 1
        if x in seen:
            print(-1)
            break
        seen.add(x)
    else:
        print(i)
    


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

bool dp[5001][5001];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  sort(ALL(a));
  int ok = n, ng = -1;
  while (1 < abs(ok - ng)) {
    int mid = (ok + ng) / 2;
    vector<int> vc;
    REP(i, n) {
      if (i == mid) continue;
      vc.push_back(a[i]);
    }
    REP(i, n + 1) REP(j, k + 1) dp[i][j] = false;
    dp[0][0] = true;
    REP(i, n - 1) REP(j, k + 1) {
      if (dp[i][j]) {
        dp[i + 1][j] = true;
        if (j + vc[i] <= k) {
          dp[i + 1][j + vc[i]] = true;
        }
      }
    }
    bool flag = false;
    for (int i = 0; i < k; ++i) {
      if (k - a[mid] <= i && dp[n - 1][i]) {
        flag = true;
      }
    }
    if (flag) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 24704
import math
n, d = list(map(int, input().split()))
m=0
x=[]
for i  in range(n):
	 x.append(list(map(int ,input().split())))
for i  in range(n):
	for s in range (i+1,n):
		D=0
		for t in range (d):
			D += (x[i][t]-x[s][t])**2
			D2 =math.floor(D**(1/2))
		if D == D2**2:
			m+=1
print(m)




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

int main(){
  int n;
  cin >> n;
  vector<double> v1(n),v2(n);
  r(0,i,n)cin >> v1.at(i);
  double ave=accumulate(v1.begin(),v1.end(),0.0)/n;
  r(0,i,n){
    v2.at(i)=abs(v1.at(i)-ave);
  }
  auto it=min_element(v2.begin(),v2.end());
  cout << distance(v2.begin(),it) <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define All(x) (x).begin(), (x).end()
#define lowbit(x) ((x) & -(x))
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const ll mod = 1e9 + 7;
const int N = 4e6 + 10;
const db pi = acos(-1);
deque<int> v;
int main()
{
	int Q = read();
	while(Q --)
	{
		int op = read();
		if(op == 0)
		{
			int d = read();
			int x = read();
			if(d == 0) v.push_front(x);
			else v.push_back(x);
		}
		if(op == 1) cout << v[read()] << endl;
		if(op == 2)
		{
			int d = read();
			if(d == 0) v.pop_front();
			else v.pop_back();
		}
	}
	return 0;
}



Measured memory_bytes: 4636
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll n, i, ans = 0;
  scanf("%lld", &n);
  ll c, v[n];
  for(i = 0; i < n; ++i) scanf("%lld", &v[i]);
  for(i = 0; i < n; ++i) {
    scanf("%lld", &c);
    if(v[i] > c) ans += v[i] - c;
  }
  printf("%lld", ans);
  return 0;
}
  

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

int N;
int A[210];         // 最大 200 個なので余裕を持って 210 に --- 200 以上ならなんでもよいです

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

    int res = 0;

    // 操作が行える限り操作を繰り返す
    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  // 奇数があったらフラグを立てる
        }

        if (exist_odd) break;  // 奇数があったら break

        // 操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;  // 操作回数をインクリメント
    }

    cout << res << endl;
}

Measured memory_bytes: 3628
import sys


def roundup_div(a, b):
    return (a + b - 1) // b


def solve(S: str):
    pressed = []
    r = []
    rc = 0
    l = []
    lc = 0
    for c in S:
        if c == "R":
            rc += 1
            if lc > 0:
                l.append(lc)
                pressed.append(lc)
            lc = 0
        else:
            lc += 1
            if rc > 0:
                r.append(rc)
                pressed.append(rc)
            rc = 0
    l.append(lc)
    pressed.append(lc)

    rlim = []
    llim = []
    for rlen, llen in zip(r, l):
        llim.append(roundup_div(llen, 2) + rlen // 2)
        rlim.append(llen // 2 + roundup_div(rlen, 2))

    is_R = True
    ans = []
    ri, li = 0, 0
    for con in pressed:
        if is_R:
            for _ in range(con - 1):
                ans.append(0)
            ans.append(rlim[ri])
            ri += 1
        else:
            ans.append(llim[li])
            li += 1
            for _ in range(con - 1):
                ans.append(0)
        is_R = not is_R

    return " ".join(map(str, ans))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    ans = solve(S)
    if ans is not None:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13036
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,count=1; cin >>n;
  vector<int> d(n);
  for(int i=0;i<n;i++) {
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  for(int i=0;i<n-1;i++) {
    if (d.at(i)!=d.at(i+1))
      count++;
  }
cout << count << endl;
}

Measured memory_bytes: 256
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll a = h1 * 60 + m1;
    ll b = h2 * 60 + m2;
    cout << max(0L, b - k - a);
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

long long mypow(long long k, long long n) {
	long long temp = 1;

	k = k % DIV;
	while (n) {
		if (n % 2) temp = temp * k % DIV;
		k = k * k % DIV;
		n = n / 2;
	}
	return temp % DIV;
}


int main() {
	int S; cin >> S;
	vector<ll> f(S + 1), invf(S + 1);
	f[0] = 1, invf[0] = 1;
	for (int i = 1; i <= S; i++) {
		f[i] = f[i - 1] * i;
		f[i] %= DIV;
		invf[i] = mypow(f[i], DIV - 2);
	}

	ll ans = 0;
	for (int i = 1; S - 3 * i >= 0; i++) {
		ll temp = ((f[S - 2 * i - 1] * invf[S - 3 * i]) % DIV * invf[i - 1]) % DIV;
		ans += temp;
		ans %= DIV;
	}
	cout << ans << endl;
}




Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	
	int n, dummy1, dummy2, max, ans;
	
	int v[1000];
	
	cin >> n;
	
	for(int i = 1; i <= n; i++){
		v[i] = 0;
	}
	
	for(int i = 1; i <= n; i++){
		cin >> dummy1 >> dummy2;
		v[dummy1] = dummy2;
	}
	
	max = 0;
	
	for(int i = n; i > 0; i--){
		if(v[i] >= max){
			ans = i;
			max = v[i];
		}
	}
	
	printf("%d %d\n", ans, v[ans]);
	
	return 0;
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;

char A[55][55], B[55][55];
bool vis[55][55][55][55];
constexpr int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
bool solve() {
    int W, H;
    cin >> W >> H;
    if (W == 0) return false;
    int sxa, sya, sxb, syb, gxa, gya, gxb, gyb;
    REP(i, H) {
        REP(j, W) {
            cin >> A[i][j];
            if (A[i][j] == 'L') {
                sxa = i;
                sya = j;
            }
            if (A[i][j] == '%') {
                gxa = i;
                gya = j;
            }
        }
        REP(j, W) {
            cin >> B[i][j];
            if (B[i][j] == 'R') {
                sxb = i, syb = j;
            }
            if (B[i][j] == '%') {
                gxb = i, gyb = j;
            }
        }
    }
    REP(ia, H) REP(ja, W) REP(ib, H) REP(jb, W) { vis[ia][ja][ib][jb] = false; }
    using arr4 = array<int, 4>;
    queue<arr4> que;
    que.push({sxa, sya, sxb, syb});
    while (!que.empty()) {
        arr4 arr = que.front();
        que.pop();
        int i = arr[0], j = arr[1], x = arr[2], y = arr[3];
        vis[i][j][x][y] = true;
        // Aが動く
        REP(k, 4) {
            int ni = i + dx[k], nj = j + dy[k];
            int nx = x + dx[k], ny = y - dy[k];
            if (ni < 0 || ni >= H || nj < 0 || nj >= W || A[ni][nj] == '#') continue;
            if (nx < 0 || nx >= H || ny < 0 || ny >= W || B[nx][ny] == '#') {
                nx = x, ny = y;
            }
            if ((A[ni][nj] == '%' && B[nx][ny] != '%') || (A[ni][nj] != '%' && B[nx][ny] == '%')) continue;
            if (vis[ni][nj][nx][ny]) continue;
            vis[ni][nj][nx][ny] = true;
            que.push({ni, nj, nx, ny});
        }

        // Bが動く
        REP(k, 4) {
            int ni = i + dx[k], nj = j + dy[k];
            int nx = x + dx[k], ny = y - dy[k];
            if (ni < 0 || ni >= H || nj < 0 || nj >= W || A[ni][nj] == '#') {
                ni = i, nj = j;
            };
            if (nx < 0 || nx >= H || ny < 0 || ny >= W || B[nx][ny] == '#') continue;
            if ((A[ni][nj] == '%' && B[nx][ny] != '%') || (A[ni][nj] != '%' && B[nx][ny] == '%')) continue;
            if (vis[ni][nj][nx][ny]) continue;
            vis[ni][nj][nx][ny] = true;
            que.push({ni, nj, nx, ny});
        }
    }
    if (vis[gxa][gya][gxb][gyb])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return true;
}

signed main() {
    while (solve())
        ;
}


Measured memory_bytes: 12360
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int c[3][3];
  for (int i=0; i<3; ++i) {
    for (int j=0; j<3; ++j) cin >> c[i][j];
  }
  int a[3];
  a[0] = 0;
  a[1] = c[1][0]-c[0][0];
  a[2] = c[2][0]-c[0][0];
  for (int i=0; i<3; ++i) {
    for (int j=0; j<3; ++j) {
      if (a[i]+c[0][j] != c[i][j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n;
    int ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i += 2) {
        int count = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) {
                count++;
            }
        }
        if (count == 8) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())

lis=[1 for i in range(10**7)]


for i in range(2,10**7+1):
    for j in range(1,(10**7)//i+1):
        lis[i*j-1]+=1
s=0
for i in range(n):
    s+=lis[i]*(i+1)

print(s)

Measured memory_bytes: 219356
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    int N, T, A, ans = 0;
    cin >> N >> T >> A;
    vector<int> H(N);
    vector<double> t(N);
    for(int i = 0; i < N; i++){
        cin >> H[i];
        t[i] = abs(A - (T - H[i] * 0.006));
    }
    for(int i = 1; i < N; i++){
        if(t[ans] > t[i]){
            ans = i;
        }
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
#define REPLACE(x,y)    if(x > y)\
                        rep(x,y)

void rep(int& x, int& y){
    int temp;
    temp = x;
    x = y;
    y = temp;
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    
    REPLACE(a,b);
    REPLACE(a,c);
    REPLACE(b,c);
        
    cout << a << " " << b << " " << c << endl;
    
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
using namespace std;
int main()
{
	long n,i,j,ans;
	cin >> n;
	long a[n+1],h[100]={};

	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		j=0;
		while(a[i]!=0){
			if(a[i]%2==1){
				h[j]++;
			}
			a[i]/=2;
			j++;
		}
	} 
	for(i=0;i<100;i++){
		if(h[i]%2 != 0){
			cout << "No" << endl;
			return 0;
		}		
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
 
int main()
{
    double x1, x2, x3, y1, y2, y3, xp, yp;
    double s, s1, s2, s3;
     
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp) != EOF){
        //?????§????¢??????¢???
        s  = ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.0; 
        s1 = ((xp - x1) * (y2 - y1) - (yp - y1) * (x2 - x1)) / 2.0;
        s2 = ((xp - x1) * (y3 - y1) - (yp - y1) * (x3 - x1)) / 2.0;
        s3 = ((xp - x2) * (y3 - y2) - (yp - y2) * (x3 - x2)) / 2.0;
         
        s  = fabs(s);
        s1 = fabs(s1);
        s2 = fabs(s2);
        s3 = fabs(s3);
         
        if (fabs(s -fabs(s1 + s2 + s3))<1e-10) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

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

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

   if (b - a == c - b) {
       cout << "YES" << endl;
   } else {
       cout << "NO" << endl;
   }
}

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

const int MAXN = 112345;
const long long MOD = 1e9 + 7;

long long n, m;
vector <long long> x;
vector <long long> y;

long long solve () {
	long long ans = 0;
	for (long long i = 1; i < n; ++i) {
		long long temp = i * (n - i);
		temp %= MOD;
		
		ans += temp * (x[i] - x[i - 1]);
		ans %= MOD;
	}
	
	// ans *= ( ((m - 1LL) * m) / 2LL ) % MOD;
	return ans;
}

int main () {

	cin >> n >> m;
	x.resize (n);
	y.resize (m);
	
	for (int i = 0; i < n; ++i)
		scanf ("%lld", &x[i]);
		
	for (int i = 0; i < m; ++i)
		scanf ("%lld", &y[i]);

	long long ans = solve ();
	swap (n, m);
	swap (x, y);
	ans *= solve ();
	ans %= MOD;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    long a = 0, b = A.sum;
    long ans = 1L << 60;

    foreach (i; 0..N) {
        if (i != 0) {
            ans = min(ans, abs(a - b));
        }
        a += A[i], b -= A[i];
    }

    ans.writeln;
}


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

int main(){
	int r,g,b,num;
	cin >> r >>g>>b;
	
	num = g * 10 + b;

	if (num % 4 == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<19, mod = 1e9 + 7, i2 = (mod+1)/2;
int n, a[maxn], ind[maxn];
inline int get(int i) {
	i++;
	int r = ind[i];
	for(; i; i -= i&-i) r += a[i];
	return r;
}
inline void add(int i, int x) {
	i++;
	for(; i <= n; i += i&-i) a[i] += x;
}
void add(int l, int r, int x) {
	if(l == r) {
		ind[l+1] += x;
		return;
	}
	add(l, x);
	add(r+1, -x);
}

int f = 0;
void carry(int i) {
	if(i == 0) return;
	if(get(i)+1 == get(i-1)) {
		int p = 0, cur = 0, v = get(i)+1;
		//for(int z = 1<<19; z>>=1;)
		//	if(p-z >= 0 && get(p-z) == get(i)+1) p -= z;
		for(int z = 1<<19; z>>=1;)
			if(p+z <= i && cur+a[p|z]+ind[p|z] != v) {
				cur += a[p|z];
				p |= z;
			}
		add(p+1, i-1, 9);
		add(i, i, 10);
		add(p, p, -1);
	}
	while(get(i) < get(i-1)) {
		ll k = get(i-1)-get(i);
		k = (k+10)/11;
		add(i, i, 10*k);
		add(i-1, i-1, -k);
		carry(i-1);
	}
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	string s;
	
	cin >> s;
	
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	//for(int i = 0; i < 500000; i++) s.pb('0' + (rng()%10));
	
	n = s.size();
	for(int i = 0; i < n; i++) {
		add(i, i, s[i]-'0');
		//for(int j = 0; j <= i; j++) cout << get(j) << " ";cout << '\n';
		carry(i);
		//for(int j = 0; j <= i; j++) cout << get(j) << " ";cout << '\n';
	}
	cout << (get(n-1)+8)/9;
	return 0;
}


Measured memory_bytes: 7868
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);

		//ツエツδ可トツスツテツネツスツづ個づ督づゥツつ「ツ（ツ甘ッツ青板づ個づ敖）
		final int MAX = 1000000;
		boolean [] prime = new boolean[MAX + 1];
		for(int i=3; i <= MAX; i+= 2){
			prime[i] = true;
		}
		for(int i=3; i * i <= MAX; i+= 2){
			if(prime[i]){
				for(int j = i + i + i; j <= MAX; j += i + i){
					prime[j] = false;
				}
			}
		}

		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int count = 0;
			for(int i=3; i <= n/2; i += 2){
				if(prime[i] && prime[n-i]){
					count++;
				}
			}
			System.out.println(count);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}



///////////////////////////




int main() {

	ll N, X;

	ll m[MAX];
	
	cin >> N >> X;
	repn(i, N) cin >> m[i];

	ll ma = INF;
	repn(i, N) ma = min(ma, m[i]);

	repn(i, N) X -= m[i];

	ll ans = N + X / ma;

	cout << ans;
	
		
	system("PAUSE");

}


Measured memory_bytes: 504
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int n;
vector < int > A;
vector < int > B;

int getORD(vector < int > tmp){
    vector < int > me;
    for(int i= 1; i <= n; i++){
        me.push_back(i);
    }
    int ord = 1;
    do{
        if(me == tmp)
            return ord;
        ord++;
    }while(next_permutation(me.begin() , me.end()));
    return ord;
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        A.push_back(x);
    }
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        B.push_back(x);
    }
    int a = getORD(A);
    int b = getORD(B);
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int N, K;
  std::string S;
  std::cin >> N >> K;
  std::cin >> S;
  
  int flip = 0;
  int ans = 0;
  
  for (int i=0; i<N; ++i) {
    if (i != 0 && S[i] != S[i-1])
      ++flip;
    
    if (S[i] == 'L' && i > 0 && S[i-1] == 'L')
      ++ans;
    else if (S[i] == 'R' && i != N-1 && S[i+1] == 'R')
      ++ans;
  }
  
  while (K > 0 && flip > 0) {
    if (flip >= 2) {
      flip -= 2;
      ans += 2;
    } else {
      --flip;
      ++ans;
    }
    --K;
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

ll count(ll A, ll B, ll C, ll D){
  ll M = max(max(A, B), max(C, D));
  ll m = min(min(A, B), min(C, D));
  return M - m;
}

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

  vector <ll> sum(N);
  sum[0] = A[0];
  for (int i = 1; i < N; i++) sum[i] = sum[i - 1] + A[i];

  ll ans = 1e16;
  int L = 0, R = 2;
  for (int border = 1; border < N - 2; border++){
    ll L1 = sum[L], L2 = sum[border] - sum[L];
    for (int i = L + 1; i < border; i++){
      if (abs((L1 + A[i]) - (L2 - A[i])) < abs(L1 - L2)){
        L1 += A[i]; L2 -= A[i]; L++;
      }else{
        break;
      }
    }

    if (R == border) R++;
    ll R1 = sum[R] - sum[border], R2 = sum[N - 1] - sum[R];

    for (int i = R + 1; i < N - 1; i++){
      if (abs((R1 + A[i]) - (R2 - A[i])) < abs(R1 - R2)){
        R1 += A[i]; R2 -= A[i]; R++;
      }else{
        break;
      }
    }
    ll now = count(L1, L2, R1, R2);
    ans = min(ans, now);
  }

  cout << ans << endl;  

  return 0;
}

Measured memory_bytes: 3328
d,g = map(int,input().split())
g //= 100
P,C = [0]*d,[0]*d
for i in range(d):
    P[i],C[i] = map(int,input().split())
    C[i] //= 100
ans = 10**9
for bin in range(1, 1<<d):
    cnt = tot = 0
    for i in range(d):
        if bin & 1<<i:
            cnt += P[i]
            tot += P[i]*(i+1) + C[i]
    if tot < g: continue
    ans = min(ans, cnt)
    for i in range(d):
        if bin & 1<<i:
            rest_g = g - (tot - P[i]*(i+1) - C[i])
            p = max(0, (rest_g+i)//(i+1)) # round up
            ans = min(ans, cnt - (P[i] - p))
print(ans)


Measured memory_bytes: 3064
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


def main() -> None:
    input()
    arr = list(map(int, input().split()))

    cnt = [0] * (10 ** 5 + 10)
    for i in arr:
        cnt[i] += 1

    for i in range(len(cnt) - 2, -1, -1):
        cnt[i] += cnt[i+1]

    print(cnt.count(len(arr) // 2))

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, **kwargs):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 82836
#include<bits/stdc++.h>
#define ________ long long
using namespace std;
string ______;
int _____;
int ____;
int ___;
int main()
{
	cin>>______;
	________ _______=______.length();
	for(int i=0;i<_______;i++)
	if(______[i]=='C')
	{
		___=i;	
		_____=1;
		continue;
	}
	if(_____==0)
	{
		cout<<"No"<<endl;
		return 0;
	}
	else
	{
		for(int __=___;__<_______;__++)
		{
			if(______[__]=='F')
			{
				____=1;
				continue;
			}	
		}
	}
	if(____==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

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

struct data{
    int i;  string s;
    bool operator<(const data other) const{
        return i < other.i;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    vector<data> vp;
    vp.push_back({0, "kogakubu10gokan"});
    for(int i = 0; i< n; i++){
        int k;  string s;
        cin >> k >> s;
        vp.push_back(data({k,s}));
    }
    cout << (*(--upper_bound(vp.begin(), vp.end(),data({q, ""})))).s << endl;
    return 0;
}


Measured memory_bytes: 3244
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  string ans = (a+b+c >= 22) ? "bust" : "win";
  cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int A,B,M; cin >> A >> B >> M;
    vector<int> a(A),b(B);
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    int ans = 1000000;
    rep(i,M){
        int x,y,c; cin >> x >> y >> c;
        int sum = a[x-1] + b[y-1] - c;
        ans = min(ans,sum);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int MIN = a[0] + b[0];
    ans = min(ans,MIN);
    cout << ans << endl;
}

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

int main() {
  
  int a;
  int b;
  cin >> a >> b;
  
  if (a%2==1 && b%2==1) {
    cout << "Odd" << endl;
  } else {
    cout << "Even" << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
using namespace std;

int main (void) {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n)
    cin >> a[i];
  sort(ALL(a));
  int left = a[n - 1];
  int right = a[0];
  int mid = a[n - 1] / 2;
  int mid2 = a[n - 1] / 2 + 1;
  REP(i, n - 1) {
    int dist_now = max(abs(right - mid), abs(right - mid2));
    int dist_cand = max(abs(a[i] - mid), abs(a[i] - mid2));
    if (dist_now > dist_cand) {
      right = a[i];
    }
  }
  cout << left << " " << right << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X, A, B;
  double D;
  cin >> N;
  for (int i = 0; i < N; i++) {
    A++;
    X = A;
    B = A*1.08;
  if (N == B){
    break;
  }
  }
  if (N == B){
  cout << X << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
import java.util.function.Function;
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        int[] t = new int[5];
        int[] p = new int[5];
        int min = 700;
        for (int i = 0; i < 5; i++) {
            t[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i < 5; i++) {
            p[i] = i;
        }
        Function<Integer, Integer> order = (i) -> t[i] % 10 == 0 ? t[i] : t[i] + (10 - (t[i] % 10));
        
        do {
            int sum = 0;
            for (int i = 0; i < 4; i++) {
                sum += order.apply(p[i]);
            }
            sum += t[p[4]];
            min = Math.min(min, sum);
        } while (nextPermutation(p));
        
        out.println(min);
        
        out.flush();
    }
    
    public static boolean nextPermutation(int[] a) {
        for (int i = a.length - 1; 0 < i; i--) {
            if (a[i - 1] < a[i]) {
                int index = find(a[i - 1], a, i, a.length - 1);
                int temp = a[index];    a[index] = a[i - 1];   a[i - 1] = temp;
                Arrays.sort(a, i, a.length);
                return true;
            }
        }
        return false;
    }

    // destより大きい要素の中で最小のもののインデックスを二分探索で探す
    private static int find(int dest, int[] a, int s, int e) {
        if (s == e) {
            return s;
        }
        int m = (s + e + 1) / 2;
        return a[m] <= dest ? find(dest, a, s, m - 1) : find(dest, a, m, e);
    }
}

Measured memory_bytes: 28756
x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())))

A = sorted(P[:x] + Q[:y])
ans = sum(A)

for i in range(min(c, len(A))):
    if A[i] < R[-1]:
        ans = ans + R[-1] - A[i]
        R.pop(-1)

print(ans)


Measured memory_bytes: 23200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A+B>=C){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	static int P = (int)1e9+7;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] cnt = new int[1000000];
		for(int i=0;i<n;i++) {
			int num = sc.nextInt();
			a[i] = num;
			
			for(int j=2;j*j<=num;j++) {
				int c = 0;
				while(num%j==0){
					num/=j;
					c++;
				}
				
				cnt[j] = Math.max(cnt[j], c);
			}
			
			cnt[num] = Math.max(cnt[num], 1);
		}
		
		long lcm = 1;
		for(int i=2;i<cnt.length;i++) {
			for(int j=0;j<cnt[i];j++) {
				lcm = (lcm*i) % P;
			}
		}
 
		long ans = 0;
		for(int i=0;i<n;i++) {
			long ainv = fp(a[i], P-2);
			ans = (ans + ainv) % P;
		}
		
		ans = ans * lcm % P;
		
		System.out.println(ans);
	}
	static long fp(int a, int p) {
		if(p==0)
			return 1;
		long num = fp(a, p/2);
		if(p % 2 == 0)
			return num * num % P;
		else
			return num * num % P * a % P;
	}
}

Measured memory_bytes: 38116
n, m, l  = [int(_) for _ in input().split()]
matrix1 = []
for i in range(n):
    matrix1.append([int(_) for _ in input().split()])
matrix2 = []
for i in range(m):
    matrix2.append([int(_) for _ in input().split()])

for i in range(n):
    for j in range(l):
        x = 0
        for k in range(m):
            x += matrix1[i][k] * matrix2[k][j]
        print(x, end=" " if j < l - 1 else "\n")



Measured memory_bytes: 6568
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, m, ans;

	cin >> n >> m;
	ans = n * (n - 1) / 2 + m * (m - 1) / 2;
	cout << ans << "\n";

	return 0;
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int P,Q,R;
  cin >>P>>Q>>R;
  vector<int> time={P,Q,R};
  sort(time.begin(),time.end());
  cout<<P+Q+R-time.at(2)<<endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

bool isB(char c){
  return (c=='a' || c=='i' || c=='u' || c=='e' || c=='o');
}

string encode(string org){
  string ret="";
  ret += org[0];
  rep(i,org.size()-1) if(isB(org[i])) ret += org[i+1];
  return ret;
}

int main(){
  int n;
  while(cin>>n, n){
    vector<string> vec(n);
    rep(i,n) cin>>vec[i];
    rep(i,n) vec[i] = encode(vec[i]);
    sort(all(vec));
    vector<string> tmp(vec);
    tmp.erase(unique(all(tmp)), tmp.end());
    if(tmp.size() != vec.size()){
      cout << -1 << endl;
      continue;
    }
    repl(d,1,51){
      bool ok=true;
      rep(i,n-1){ //???????????????????????£????????????????????§??????
        if(vec[i].substr(0,d) == vec[i+1].substr(0,d)) {ok=false; break;}
      }
      if(ok){ cout<<d<<endl; break;}
    }
  }
  return 0;
}

Measured memory_bytes: 3156
import java.util.Scanner;

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

		if(a == b) {
			System.out.println(a + b);
		}else {
			System.out.println(Math.max(a, b) * 2 - 1);
		}
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;, i < n; i++)
using namespace std;
using ln = long long;

int main()
{
    ln n,m,sum=0;
    cin >> n >> m;



    for(int i=n-1;i>0;i--)
        sum += i; 

    for(int i=m-1;i>0;i--)
       sum += i;

    cout << sum << endl;
}

Measured memory_bytes: 3580
H = int(input())

if H == 1:
  print("1")
  quit()

bin_h = str(bin(H)[2:])
len_h = len(bin_h)
ans = 2 ** len_h - 1

if bin_h[1] == 1:
  ans += 2 ** (len_h - 1)
  
print(ans)
  

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define N 50
using namespace std;
int h,w,ans;
string s[N];

void update(int a,int b){
  int cnt=0;
  for(int i=0;i<=a;i++)
    for(int j=0;j<w;j++)
      if(s[i][j]!='W')cnt++;
  for(int i=a+1;i<=b;i++)
    for(int j=0;j<w;j++)
      if(s[i][j]!='B')cnt++;
  for(int i=b+1;i<h;i++)
    for(int j=0;j<w;j++)
      if(s[i][j]!='R')cnt++;
  ans=min(ans,cnt);
}

int main(){
  cin>>h>>w;
  ans=(1e9);
  for(int i=0;i<h;i++)cin>>s[i];
  for(int i=0;i<h-2;i++)
    for(int j=i+1;j<h-1;j++)update(i,j);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1208
from queue import Queue
n, m = map(int, input().split())
graph = {i:[] for i in range(n)}
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
ans = [None]*n
visited = [False]*n
visited[0] = True
q = Queue()
q.put(0)
while not q.empty():
    root = q.get()
    for r in graph[root]:
        if not visited[r]:
            ans[r] = root
            visited[r] = True
            q.put(r)
print('Yes')
for a in ans[1:]:
    print(a+1)


Measured memory_bytes: 43172