akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll W,N,dp[2][100001],w[100002],v[100001];
  cin >> N >> W;
  REP(i,N)cin >> w[i+1] >> v[i+1];
  REP(i,2)REP(j,100001)dp[i][j] = INF_INT;
  dp[0][0] = 0;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=100000;j++){
      if(j-v[i] >=0)
        dp[i%2][j] = min(dp[(i-1)%2][j],dp[(i-1)%2][j-v[i]]+w[i]);
      else
        dp[i%2][j] = dp[(i-1)%2][j];
    }
  }
  ll res=0;
  for(ll i=0;i<=100000;i++){
    if(dp[N%2][i] <= W)
      res = max(res,i);
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 3200
from collections import Counter
import numpy as np

s = input()
t = input()

l = list(set([(s[i], t[i]) for i in range(len(s))]))

l1 = []
l2 = []

for i in l:
    l1.append(i[0])
    l2.append(i[1])

c1 = Counter(l1)
_, counts1 = zip(*c1.most_common())
k1 = np.where(np.array(counts1)>1)[0]

c2 = Counter(l2)
_, counts2 = zip(*c2.most_common())
k2 = np.where(np.array(counts2)>1)[0]

if len(k1) >= 1 or len(k2) >= 1:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 26936
row = list(map(int, input().split()))
T = [input() for i in range(row[0])]
T = list(map(int, T))
T.sort()

sub = []
for i in range(row[0]-1):
    sub.append(T[i+1]-T[i])
i = 0
sum = 0
C_count = 0
count = 0
while i < len(sub):
    sum += sub[i]
    C_count += 1
    if sum > row[2] or C_count == row[1]:
        sum = 0
        C_count = 0
        count += 1
        i += 1
    else:
        i += 1
print(count+1)

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

using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string result = "No";
    int k = n / 2;
    if(n % 2 == 0 && s.substr(0, k) == s.substr(k, k)){
        result = "Yes";
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

int main()
{
    int n;
    cin >> n;
    vector<string> words(n);
    vector<string> a, b, ab, no;
    rep(i,0,n)
    {
        cin >> words[i];
        if(words[i].back() == 'A' && words[i].front() == 'B') ab.push_back(words[i]);
        else if(words[i].back() == 'A') a.push_back(words[i]);
        else if(words[i].front() == 'B') b.push_back(words[i]);
        else no.push_back(words[i]);
    }

    string res = "";
    int ata = 0;
    int atb = 0;
    bool flag = false;
    while(ata < a.size() || atb < b.size() || !flag)
    {
        if(ata < a.size()) res += a[ata++];
        if(!flag)
        {
            iter(it, ab) res += *it;
            flag = true;
        }
        if(atb < b.size()) res += b[atb++];
    }
    iter(it, no) res += *it;
    int cnt = 0;
    rep(i,0,(int)res.size()-1)
    {
        if(res[i] == 'A' && res[i+1] == 'B') cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
#define rep1(i,n) for(int i=1;i<=int(n);++i)

int main(void){
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i,n){
        cin >> v[i];
    }
    sort(all(v));
    double x = v[0];
    rep1(i,n-1){
        x = (x+v[i])/2.0;
    }
    printf("%.10f\n", x);
    return 0;
}


Measured memory_bytes: 256
<?php
$input = trim(fgets(STDIN));
$exploded = explode(" ", $input);
while($input){
  $arr[] = $exploded;
  $input = trim(fgets(STDIN));
  $exploded = explode(" ", $input);
}

  $n = $arr[0][0];
  $m = $arr[0][1];
  $sum_votes = array_sum($arr[1]);

$votes = $arr[1];
$populars = array_filter($votes, function($var){
  global $m;
  global $sum_votes;
  return $var >= $sum_votes/(4*$m);
});

$number = count($populars);

if($number >= $m){
  echo "Yes";
} else {
  echo "No";
}
?>

Measured memory_bytes: 15952
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int[] a = sc.nextIntArray(n);
		
		int res = 0;
		
		for(int i : a) {
			res+=i-1;
		}
		
		out.println(res);
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static int lcm(int a, int b) {
		return (a * b) / gcd(a, b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

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

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

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

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

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

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<pair<ll,ll> > vec(N);
    rep(i,N){
        cin >> vec[i].first >> vec[i].second;
    }
    sort(all(vec));
    ll cnt = 0;
    while(K > 0){
        K -= vec[cnt].second;
        if (K <= 0){
            break;
        }
        cnt++;
    }
    cout << vec[cnt].first << endl;
}


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

int main() {
    string a, b;
    cin>>a>>b;
    int x = stoi(a+b);
    for (int i=1; i*i<=x; i++) {
        if (i*i == x) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

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

int main()
{
    string word;
    cin>>word;
    string a = "dreamer";
    string b = "dream";
    string c = "eraser";
    string d = "erase";
    int flag = 1;
    while(flag)
    {
        flag = 0;
        int len = word.length();
        if(len < 5)break;

        if((word.compare(len-5,len,b)==0) || (word.compare(len-5,len,d)==0))
        {
            word.erase(len-5,len);
            flag = 1;
            continue;
        }
        if((word.compare(len-6,len,c)==0))
        {
            word.erase(len-6,len);
            flag = 1;
            continue;
        }
        if((word.compare(len-7,len,a)==0))
        {
            word.erase(len-7,len);
            flag = 1;
            continue;
        }
    }
    printf(word.length()?"NO\n":"YES\n");
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  long long int N,A,B;
  if(scanf("%lld%lld%lld",&N,&A,&B)<3) return 1;
  
  if((B-A)%2==0){
    printf("%lld",(B-A)/2);
  }
  else{
    if((A-1)<=(N-B)){
      printf("%lld",(A-1)+((B-A+1)/2));
    }
    else{
      printf("%lld",(N-B)+(B-A+1)/2);
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_V 100

//辺を表す構造体（行き先、容量、逆辺）
struct edge{ int to, cap, rev; };

vector<edge> G[MAX_V];//グラフの隣接リスト表現
bool used[MAX_V];//DFSですでに調べたかのフラグ

//fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size() - 1});
}

//増加パスをDFSで探す
int dfs(int v, int t, int f){
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

//sからtへの最大流を求める
int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0) return flow;
        flow += f;
    }
}

signed main(){
    int V,E;
    cin >> V >> E;
    int u,v,c;
    REP(i,E){
        cin >> u >> v >> c;
        add_edge(u, v, c);
    }
    cout << max_flow(0, V - 1) << endl;;
}


Measured memory_bytes: 3220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		int[] b = new int[m];
		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}
		int[] a = new int[m];
		int cnt = 0;
		int ans = c;
		for (int i = 0; i < n; i++) {
			ans = c;
			for (int j = 0; j < m; j++) {
				a[j] = sc.nextInt();
				ans += a[j] * b[j];
			}
			if (ans > 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 23508
#include <iostream>
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <climits>
#include <cmath>

int main(void) {
  int N, A, B;
  std::cin >> N >> A >> B;

  int between = B - A - 1;
  if (between % 2 == 0) {
    std::cout << "Borys" << std::endl;
  } else {
    std::cout << "Alice" << std::endl;
  }

  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;

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

  stack<int> left;
  stack<int> right;
  stack<int> pool;
  char c;
  int i = 0;
  while (cin >> c) {
    if (c == '/' and not left.empty()) {
      int l = left.top();
      left.pop();

      pool.push(i - l);

      while (not right.empty()) {
        int r_prev = right.top();
        if (l < r_prev) {
          // merge
          int pool_prev1 = pool.top();
          pool.pop();
          int pool_prev2 = pool.top();
          pool.pop();
          pool.push(pool_prev1 + pool_prev2);
          right.pop();
        } else {
          break;
        }
      }

      right.push(i);
    } else if (c == '\\') {
      left.push(i);
    }
    i++;
  }

  vector<int> vec;
  while (not pool.empty()) {
    vec.push_back(pool.top());
    pool.pop();
  }
  reverse(ALL(vec));
  int ans = 0;
  REP(i, SZ(vec)) { ans += vec.at(i); }
  cout << ans << endl;
  cout << SZ(vec);
  REP(i, SZ(vec)) { cout << " " << vec.at(i); }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3240
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> ans = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        while(true) {
            String d = sc.nextLine();
            if(d.equals("0")) {
                break;
            }

            int sum = 0;
            for(int i=0; i<d.length(); i++) {
                sum += Character.getNumericValue(d.charAt(i));
            }
            ans.add(sum);
        }

        for(int i: ans) {
            System.out.println(i);
        }
    }
}



Measured memory_bytes: 26188
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (n); ++i)	
//setprecision(16)

void outi(int x) { cout << x << endl; }
void outl(ll x) { cout << x << endl; }
void outs(string x) { cout << x << endl; }
ll max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
ll min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}
//---------------------------------------------------------------

int main() {
	int n;

	cin >> n;

	pair<pair<string, int>, int> p[110];

	rep(i, n) {
		string s;
		int k;
		cin >> s;
		cin >> k;
		p[i] = make_pair(make_pair(s, -k), i + 1);
	}

	sort(p, p + n);

	rep(i, n) {
		cout << p[i].second << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll k;
  cin >> k;
  mod = k;
  vb seen(k, false);
  ll cnt = 0;
  mint now = 0;
  while(true) {
    now *= 10;
    now += 7;
    cnt++;
    if(now.x == 0) {
      cout << cnt << endl;
      return 0;
    }
    if(seen[now.x]) break;
    seen[now.x] = true;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3700
package main
import . "fmt"
func main() {
  var a,b,c,x,y int
  var z,d,w,e int
  Scan(&a,&b,&c,&x,&y)
  z = min(x,y)
  d = min(a+b,2*c)
  if x > y {
    w = x - z
    e = min(a,2*c)
  } else {
    w = y - z
    e = min(b,2*c)
  }
  Println(z*d+w*e)
}
func min(n int,m int) int {
  if n < m {
    return n
  } else {
    return m
  }
}

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

LL mod = 1000000007;

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

	LL g[9][9] = {0};

	for (LL i = 1; i <= n; ++i) {
		LL st = i%10, en;

		if (st != 0) {
			LL t = i;
			while (t) {
				en = t;
				t/=10;
			}

			g[st-1][en-1]++;
		}

	}

	LL cnt = 0;
	for (LL i = 0; i < 9; ++i) {
		for (LL j = 0; j < 9; ++j) {
			cnt += g[i][j]*g[j][i];
		}
	}

	cout << cnt << "\n";
	
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int[] a = new int[n+2];
    for (int i=1;i<=n;i++){
      a[i] = scan.nextInt();
    }
    long sum = 0;
    for (int i=0;i<n+1;i++){
      sum += Math.abs(a[i+1]-a[i]);
    }

    for (int i=1;i<n+1;i++){
      System.out.println(find(a,i,sum));
    }

  }

  static long find(int[] a, int mid, long sum){
    if ((a[mid] >= a[mid-1]) && (a[mid] <= a[mid+1])){
      return sum;
    }
    if ((a[mid] <= a[mid-1]) && (a[mid] >= a[mid+1])){
      return sum;
    }

    if ((a[mid] == a[mid-1]) || (a[mid] == a[mid+1])){
      return sum;
    }

    sum += Math.abs(a[mid+1] - a[mid-1]);
    sum -= (Math.abs(a[mid-1] - a[mid]) + Math.abs(a[mid+1] - a[mid]));
    return sum;
  }
}


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

typedef long long int ll;
const ll INF = 1LL << 28;

ll N;
vector<ll> num;
map<ll,ll> memo;
queue<ll> q;
function<ll(ll)> seki;

int main() {
    cin >> N;
    q.push(2LL); q.push(8LL);
    while (q.size()) {
        ll n = q.front(); q.pop();
        num.push_back(n);
        if (n <= 1e18) {
            q.push(n * 10LL + 8LL);
            q.push(n * 10LL + 2LL);
        }
    }


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

    seki = [&](ll n) -> ll {
        if (memo.find(n) != memo.end()) return memo[n];

        int i = (int)(lower_bound(num.begin(), num.end(), n) - num.begin());
        memo[n] = -INF;
        if (num[i] == n) memo[n] = 1;
        for (; i > -1; i--) {
            if (n % num[i] == 0 ) {
                memo[n] = max(memo[n], seki(n / num[i]) + seki(num[i]));
            }
        }


        return memo[n];
    };

    int ans = seki(N);
    if (ans > 0) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 	string s;
 	cin>>s;
 	s='>'+s;
 	intl n=s.size();
 	intl index=0;
 	intl act=-1;
 	intl ans=0;
 	while(index<n){
 	
 		if(index<n-1&&s[index+1]=='>'){
 			index++;
 			intl count=0;
 			while(index<n&&s[index]=='>'){
 				count++;
 				index++;
			 }
			 if(act+1<count){
			 	act=count;
			 	ans+=act;
			 }
			 else{
			 	act++;
			 	ans+=act;
			 }
			 ans+=(count)*(count-1)/2;
			 act=0;
		}
		else{
			act++;
			ans+=act;
			index++;
		}
		
	 }
	 cout<<ans<<endl;
}


Measured memory_bytes: 1308
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
int a[100001];
int main()
{	int n,ans=0,num=0;
	cin>>n;
	for(rint i=1;i<=n;i++)
	{	cin>>a[i],ans+=(a[i]%4==0?1:0);
		if(a[i]%4==2) num++;
	}
	if(!num) num=1;
	if(ans>=(n-num+1)/2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
 	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> A(N), B(N);
  REP(i, N){
    cin >> A[i];
  }
  REP(i, N){
    cin >> B[i];
  }
  int ans = 0;
  REP(i, N){
    int res = 0;
    REP(j, N){
      if(i < j){
        res += B[j];
      }else if(i == j){
        res += A[j]+B[j];
      }else{
        res += A[j];
      }
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;

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

	ll N, W;

	cin >> N >> W;

	vector<ll> w(N);
	vector<ll> v(N);
	for (ll i = 0; i < N; ++i) cin >> w[i] >> v[i];

	ll Vmax = 0;
	for (ll i = 0; i < N; ++i) Vmax += v[i];

	vector<vector<ll>> dp(N + 1, vector<ll>(Vmax + 1, INF));

	dp[0][0] = 0;
	
	for (ll i = 0; i < N; ++i)
	{
		for (ll v_ub = 0; v_ub <= Vmax; ++v_ub)
		{
			if (v_ub - v[i] >= 0)
			{
				chmin(dp[i + 1][v_ub], dp[i][v_ub - v[i]] + w[i]);
			}
			chmin(dp[i + 1][v_ub], dp[i][v_ub]);
		}
	}

	ll ans = 0;
	for (ll v_ub = 0; v_ub <= Vmax; ++v_ub)
	{
		if (dp[N][v_ub] <= W)
		{
			chmax(ans, v_ub);
		}
	}

	cout << ans << endl;
	//system("pause");
}


Measured memory_bytes: 80256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

string s;
int a[12000];
int d;
ll dp[2][120];
ll dp2[2][120];
const ll MOD = 1e9 + 7;

void add(ll &a, ll b) {
	a = (a + b) % MOD;
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> s;
	reverse(ALL(s));
	for (int i = 0; i < s.size(); ++i)
		a[i] = s[i] - '0';
	int n = s.size();
	++a[0];
	int now = 0;
	while (a[now] == 10)
		a[now] = 0, ++now, ++a[now];
	n = max(n, now + 1);
	cin >> d;
	dp[0][0] = 1;
	for (int i = n - 1; i >= 0; --i) {
		memset(dp2, 0, sizeof(dp2));
		for (int fl = 0; fl < 2; ++fl)
			for (int j = 0; j < d; ++j)
				for (int k = 0; k < 10; ++k) {
					if (!fl && k > a[i])
						continue;
					int fl1 = fl || (k < a[i]);
					add(dp2[fl1][(j + k) % d], dp[fl][j]);
				}
		memcpy(dp, dp2, sizeof(dp));
	}
	cout << (dp[1][0] + MOD - 1) % MOD << "\n";
	return 0;
}




Measured memory_bytes: 384
fun main(args: Array<String>) {

    val (a, b, c, d) = readInts()

    if (Math.abs(c - a) <= d || (Math.abs(b - a) <= d && Math.abs(c - b) <= d))
        println("Yes")
    else
        println("No")
}

fun readInts(): List<Int> = readStrings().map { it.toInt() }
fun readStrings(): List<String> = readLine()!!.split(" ")

Measured memory_bytes: 37944
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int h, w;   cin >> h >> w;
    vector<vector<int> > a(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
            cin >> a[i][j];
    }
    vector<int> x, y, u, v;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w-1; j++) {
            if (a[i][j] % 2 == 0)
                continue;
            
            x.push_back(i);
            y.push_back(j);
            u.push_back(i);
            v.push_back(j+1);
            a[i][j]--;
            a[i][j+1]++;
        }
    }
    for (int j = 0; j < h-1; j++) {
        if (a[j][w-1] % 2 == 0)
            continue;

        x.push_back(j);
        y.push_back(w-1);
        u.push_back(j+1);
        v.push_back(w-1);
        a[j][w-1]--;
        a[j+1][w-1]++;
    }
    cout << x.size() << endl;
    for (int i = 0; i < x.size(); i++) 
        cout << x[i]+1 << " " << y[i]+1 << " " << u[i]+1 << " " << v[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 6380
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	int  s = 0, ma = 0;
	for(int i = 0; i < n; i++) {
		int a; scanf("%d", &a);
		
		s += a;
		ma = std::max(ma, a);
	}
	s -= ma;
	
	if(ma < s) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int x;
	cin >> x;
	cout << 1-x << endl;

}



Measured memory_bytes: 3648
/** 
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include<bits/stdc++.h>

using namespace std; 

#define start_cooking int main()
#define food_is_ready return 0;
#define main_ingredient_added ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

start_cooking
{
    main_ingredient_added
    //start with your recipe
    long long x;
    long long amt = 100;
    long long cnt = 0;
    cin>>x;
    while(amt < x)
    {
        ++cnt;
        amt += (0.01*amt);
    }
    cout<<cnt;
    food_is_ready
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
const int MAXN=10;
const ll MOD=1e9+7;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
void solve(){
    ll n;
    cin>>n;
    ll ans=qpow(10,n)-2*qpow(9,n)%MOD+MOD;
    ans=(ans+qpow(8,n))%MOD;
    cout<<ans<<"\n";
}
// #define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        ll a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        ll ans=a[n-1];
        int c=n-2;
        for(int i=n-2;i>=1;i-=2){
            if(i==1)
                ans+=a[c];
            else
                ans+=2*a[c];
            c--;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 5180
/*{{{*/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define mset(x,c) memset(x, c, sizeof(x))
#define mem0(x) mset(x,0)
#define mem1(x) mset(x,-1)
#define memc(x,y) memcpy(x, y, sizeof(x));
#define P(a,n) FOR(_,0,n) _W(a),printf("%c", " \n"[_==n-1])
#define print(a,n) cout << #a << " = ";FOR(_,0,n) _W(a),printf("%c", " \n"[_==n-1])
using namespace std;

template<class T> void _R(T &x) { cin >> x; }
void _R(signed &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const signed &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi); putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef LOCAL
 #define debug(...) {printf(" [" #__VA_ARGS__ "]: ");W(__VA_ARGS__);}
#else
 #define debug(...)
#endif

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
/*}}}*/
//#define int long long

const int N = 2e5+10;

int n, m;
int f[N], cnt[N];
int find(int x) { return f[x]?f[x]=find(f[x]):x; }

signed main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	R(n, m);
	FOR(i,0,m) {
		int u, v;
		R(u,v);
		if (find(u) != find(v)) f[find(u)] = v;
	}
	int ans = 0;
	FOR(i,1,n+1) {
		ans = max(ans, ++cnt[find(i)]);
	}
	W(ans);
}


Measured memory_bytes: 10704
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long

template <class T>
T mymax(T a,T b){
    if(a>=b) return a;
    return b;
}
template <class T>
T mymin(T a,T b){
    if(a<=b) return a;
    return b;
}

ll gcd(ll a, ll b){
    if(a<b){
        swap(a,b);
    }
    while(b){
        ll r = a%b;
        a=b;
        b=r;
    }
    return a;
}

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

struct XX{
    string name;
    ll v;
    ll cnt1;
    ll cnt2;
    ll cnt3;
    ll ten;
    ll q;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.q) == (riRight.q)){
            return riLeft.q < riRight.q;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.q) < (riRight.q);
    }
};


//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}

struct Tosi{
    ll ww;
    ll time;
};

int main(int argc, const char * argv[])
{
    //scanf("%s",S);
    //scanf("%d",&N);
    //scanf("%lld %lld",&target1,&target2);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //ifstream ifs( "1_06.txt" );//テスト用
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,M;
    cin >> N >> M;
    if(N==2 || M==2){
        cout << 0 << endl;
        return 0;
    }
    if(N==1 || M==1){
        ll tmp=max(N,M);
        if(tmp>=2){
            cout << tmp-2 << endl;
            return 0;
        }else{
            cout << 1 << endl;
            return 0;
        }
    }
    
    ll ans=(N-2)*(M-2);
    
    cout << ans << endl;
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;

class Main {

	/*
	 * https://onlinejudge.u-aizu.ac.jp/#/problems/0029
	 */

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(br.readLine());
		HashMap<String, Integer> map = new HashMap<>();
		while (scanner.hasNext()) {
			String word = scanner.next();
			Integer frequency = map.get(word);
			if(frequency==null) {
				map.put(word, 1);
			}else {
				map.put(word, frequency+1);
			}
		}
		scanner.close();

		String[] wordArray = map.keySet().toArray(new String[0]);
		String mostFreq = wordArray[0];
		for(int i=1; i<wordArray.length; i++) {
			int freq = map.get(wordArray[i]);
			if(freq > map.get(mostFreq)) {
				mostFreq = wordArray[i];
			}
		}
		String maxLength = wordArray[0];
		for(String word : wordArray) {
			if(word.length() > maxLength.length()) {
				maxLength = word;
			}
		}

		System.out.printf("%s %s\n", mostFreq, maxLength);
	}

}



Measured memory_bytes: 25888
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    double t,x;
    cin>>t>>x;
    printf("%.15f\n",t/x);
    return 0;
}


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

class MinCostFlow {
public:
  struct edge { int to, cap, cost, rev; };

  const int INF = 1 << 28;
  int N;
  vector<vector<edge>> E;
  vector<int> h, dist, prevv, preve;

  MinCostFlow(int N): N(N), E(N), h(N, 0), dist(N), prevv(N), preve(N) {}

  void add_directed_edge(int from, int to, int cap, int cost) {
    E[from].push_back((edge) { to, cap, cost, (int) E[to].size() });
    E[to].push_back((edge) { from, 0, -cost, (int) E[from].size() - 1 });
  }

  int min_cost_flow(int s, int t, int f) {
    int ret = 0;
    while (f > 0) {
      priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
      for (int i = 0; i < N; i++) dist[i] = INF;
      dist[s] = 0;
      q.push(make_pair(0, s));
      while (!q.empty()) {
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < E[v].size(); i++) {
          edge &e = E[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
            dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            q.push(make_pair(dist[e.to], e.to));
          }
        }
      }
      if (dist[t] == INF) return -1;
      for (int v = 0; v < N; v++) h[v] += dist[v];
      int d = f;
      for (int v = t; v != s; v = prevv[v]) d = min(d, E[prevv[v]][preve[v]].cap);
      f -= d;
      ret += d * h[t];
      for (int v = t; v != s; v = prevv[v]) {
        edge &e = E[prevv[v]][preve[v]];
        e.cap -= d;
        E[v][e.rev].cap += d;
      }
    }
    return ret;
  }
};

int main(void) {
  ll N;
  cin >> N;
  vector<vector<ll>> W(N, vector<ll>(N)), E(N, vector<ll>(N));
  vector<string> F(N);
  REP(i, 0, N) REP(j, 0, N) cin >> W[i][j];
  REP(i, 0, N) REP(j, 0, N) cin >> E[i][j];
  REP(i, 0, N) cin >> F[i];

  MinCostFlow mcf(N * 2 + 2);

  ll s = N * 2, t = N * 2 + 1;
  vector<ll> row(N), col(N);
  REP(i, 0, N) row[i] = i;
  REP(i, 0, N) col[i] = N + i;

  REP(i, 0, N) mcf.add_directed_edge(s, row[i], 1, 0);
  REP(i, 0, N) mcf.add_directed_edge(col[i], t, 1, 0);

  REP(i, 0, N) {
    REP(j, 0, N) {
      ll cost = 0;
      REP(k, 0, N) {
        if (k == j) {
          if (F[i][k] == '.') cost += W[i][k];
        } else {
          if (F[i][k] == 'o') cost += E[i][k];
        }
      }
      mcf.add_directed_edge(row[i], col[j], 1, cost);
    }
  }

  ll min_cost = mcf.min_cost_flow(s, t, N);

  struct operation {
    ll row, col;
    bool circle;
  };
  vector<operation> op;
  REP(i, 0, N) {
    REP(j, 0, N) {
      if (mcf.E[i][j + 1].cap != 0) continue;
      REP(k, 0, N) {
        if (k == j) {
          if (F[i][k] == '.') op.push_back({ i, k, true });
        } else {
          if (F[i][k] == 'o') op.push_back({ i, k, false });
        }
      }
    }
  }

  cout << min_cost << endl;
  cout << op.size() << endl;
  REP(i, 0, op.size()) {
    cout << op[i].row + 1 << " " << op[i].col + 1 << " " << (op[i].circle ? "write" : "erase") << endl;
  }
}


Measured memory_bytes: 3768
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    for(int i=0; i<S.size(); i++){
        int num=(int)S[i]+N;
        num=(num-'A')%26;
        cout << (char)(num+'A');
    }
    cout << endl;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

long table[200000][3];

int main()
{
    long N,K;
    std::cin >> N >> K;
    std::vector<long> p;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        p.push_back(temp);
    }

    long tempsum=0;
    long max=0;
    for(long i=0; i<K; i++){
        tempsum+=p[i];
    }
    max=tempsum;

    for(long i=K; i<N;i++){
        tempsum-=p[i-K];
        tempsum+=p[i];
        if(tempsum>max){
            max=tempsum;
        }
    }

    double result=(double)(max+K)/(double)2;
    std::cout << std::setprecision(9) << result << std::endl;
    return 0;
}

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

int main(){
    int N, M, Q; cin >> N >> M >> Q;
    vector<int> l(M), r(M);
    vector<vector<int>> num(N+1, vector<int>(N+1));
    for(int i = 0; i < M; i++){
        cin >> l[i] >> r[i];
        num[l[i]][r[i]]++;
    }
    vector<vector<int>> ans(N+1, vector<int>(N+1));
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            ans[i][j] = ans[i][j-1] + num[i][j];
        }
    }
    while(Q--){
        int p, q; cin >> p >> q;
        int FA = 0;
        for(int i = p; i <= q; i++){
            FA += ans[i][q];
        }
        cout << FA << endl;
    }
}

Measured memory_bytes: 6968
import sys
import bisect
input = sys.stdin.readline
 
def main():
    w,h,n = map(int,input().split())
    l=0
    b=0
    x=[0 for i in range(n)]
    y=[0 for i in range(n)]
    a=[0 for i in range(n)]
    for i in range(n):
        x[i],y[i],a[i] = map(int,input().split())
    for i in range(n):
        if(a[i]==1):
            l=max(l,x[i])
        elif(a[i]==2):
            w=min(w,x[i])
        elif(a[i]==3):
            b=max(b,y[i])
        else:
            h=min(h,y[i])
    wi=w-l
    he=h-b
    if(wi<0):
        wi=0
    if(he<0):
        he=0
    ans=he*wi
    print(ans)
    
main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

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

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

template <class T>
T pow_ (T x, T n, T M){
    uint64_t u = 1, xx = x;
    while (n > 0){
        if (n&1) u = u * xx % M;
        xx = xx * xx % M;
        n >>= 1;
    }
    return static_cast<T>(u);
};

template <class T> class Factorial {
    T mod;
    vector<uint64_t> facts, factinv;

public:
    Factorial(int n, T mod) : facts(static_cast<u32>(n+1)), factinv(static_cast<u32>(n+1)), mod(mod) {
        facts[0] = 1;
        for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1]*i % mod;
        factinv[n] = pow_(facts[n], static_cast<uint64_t>(mod - 2), static_cast<uint64_t>(mod));
        for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * (i+1) % mod;
    }

    T fact(int k) const {
        if(k >= 0) return static_cast<T>(facts[k]);
        else return static_cast<T>(factinv[-k]);
    }

    T operator[](const int &k) const {
        if(k >= 0) return static_cast<T>(facts[k]);
        else return static_cast<T>(factinv[-k]);
    }

    T C(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return static_cast<T>(facts[p]*  factinv[q] % mod * factinv[p-q] % mod);
    }

    T P(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return static_cast<T>((facts[p] * factinv[p-q]) % mod);
    }

    T H(int p, int q) const {
        if(p < 0 || q < 0) return 0;
        return static_cast<T>(q == 0 ? 1 : C(p+q-1, q));
    }
};


int main() {
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(), v.end(), greater<>());
    auto dp = make_v(n+1, x+1, (ll)0);
    dp[0][x] = 1;
    Factorial<int> f(n, MOD);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= x; ++j) {
            (dp[i+1][j] += (dp[i][j]*(n-i-1))) %= MOD;
            (dp[i+1][j%v[i]] += dp[i][j]) %= MOD;
        }
    }
    ll ans = 0;
    for (int i = 0; i < x; ++i) {
        (ans += dp[n][i]*i) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 158592
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		char[] a = scn.nextLine().toCharArray();
		char[] b = scn.nextLine().toCharArray();
		char[] c = scn.nextLine().toCharArray();
		String ans = "";
		ans += a[0];
		ans += b[1];
		ans += c[2];
		System.out.println(ans);
	}

}


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

using namespace std;

int n, m;
bool edge[8][8];
bool vis[8];

int dfs(int now)
{
  bool ok = true;
  for (int i = 0; i < n; i++)
    if (!vis[i])
      ok = false;
  if (ok)
    return 1;
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (edge[now][i] && !vis[i])
    {
      vis[i] = true;
      ans += dfs(i);
      vis[i] = false;
    }
  return ans;
}

int main()
{
  cin >> n >> m;
  while (m--)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a][b] = edge[b][a] = true;
  }
  vis[0] = true;
  cout << dfs(0) << endl;

  return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
#define int long long
int32_t main()
{
  int t,n,i,j,k,l;
  string s1,s2;
  cin>>s1>>s2;
  s1+=s2[s2.size()-1];
  if(s1==s2)
   cout<<"Yes";
  else
   cout<<"No";
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int k,q;cin>>k>>q;
    vector<int> d(k);
    REP(i, k) cin >> d[i];
    vector<ll> conv(k);
    REP(_,q){
        int n,x,m;cin>>n>>x>>m;
        REP(i,k) conv[i]=d[i]%m;
        ll y=x;
        ll res=n-1;
        REP(i,k){
            ll cnt=((n-i-1)+k-1)/k;
            if(n-1<=i) cnt=0;
            if(conv[i]==0) res-=cnt;
            y+=cnt*conv[i];
        }
        res-=y/m-x/m;
        cout<<res<<endl;
    }
}


Measured memory_bytes: 384
n = gets.to_i
t, a = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

min = 10 ** 6
ans = 0
h.each_with_index do |x, i|
  o = ((t - x * 0.006) - a).abs
  if o < min
    min = o
    ans = i
  end
end

puts ans + 1


Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = (a); i <= (b); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 200005;
int n, a[MX];
map<int, ll> mp;
ll res = 0;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		res += mp[a[i]]++;
	}

	for (int i = 0; i < n; i++) {
		cout << res - mp[a[i]] + 1;
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 10368