akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/python3
# -*- coding:utf-8 -*-


def main():
  n, k = map(int, input().strip().split())
  lp = list(map(lambda p:int(p)-1, input().strip().split()))
  lc = list(map(int, input().strip().split()))

  used = [0] * n
  loops = []
  for i in range(n):
    if used[i] == 1:
      continue
      
    ic = i
    loop = []
    while used[ic] == 0:
      loop.append(lc[ic])
      used[ic] = 1      
      ic = lp[ic]
      
    if len(loop) > 0:
      loops.append(loop)
    
  def loop_score(loop, k):
    return (k // len(loop)) * sum(loop)
  
  def path_score(loop, k):
    score = 0
    for i in range(len(loop)):
      cumsum = 0
      for j in range(k):
        cumsum += loop[(i+j) % len(loop)]
        score = max(score, cumsum)
    return score
  
  def calc_score(loop, k):
    if max(loop) < 0:
      return max(loop)
    
    if k < len(loop):
      return path_score(loop, k)
    if k >= len(loop):
      k -= len(loop)
      score = 0
      if sum(loop) > 0:
        score += loop_score(loop, k)
      k %= len(loop)
      k += len(loop)
      score += path_score(loop, k)

    return score
  
  print(max([calc_score(loop, k) for loop in loops]))

if __name__=='__main__':
  main()



Measured memory_bytes: 69100
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

x,a=MI()
print(max(x-a,0))

Measured memory_bytes: 3316
n, m = map(int, input().split())
if n % 2 != 0:
    for i in range(m):
        print(i + 1, n - i)
else:
    for i in range(m):
        if i < m / 2:
            print(i + 1, n - i)
        else:
            print(i + 1, n - i - 1)


Measured memory_bytes: 9172
#!/usr/bin/env python3
import sys, itertools


def solve(N: int, S: str):
    c = [0] * N
    counter = 0
    for i in range(N):
        if S[i] == '(':
            counter += 1
        else:
            counter -= 1
        c[i] = counter

    m = min(c)
    if m < 0:
        S = "("*abs(m) + S
        c = list(range(1, abs(m)+1)) + [cc+abs(m) for cc in c]
    
    S = "("*(c[0]-1) + S + ")"*c[-1]
    print(S)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>  
using namespace std;  
const int maxn=1e6+10;  
typedef long long ll;  
int dp[maxn];  
int main()  
{  
    for(int i=0;i<maxn;i++){  
        dp[i]=1e9;  
    }  
    dp[0]=0;  
    for(ll i=0;i<=maxn;i++){  
        dp[i+1]=min(dp[i+1],dp[i]+1);  
        for(ll j=6;i+j<=maxn;j*=6){  
            dp[i+j]=min(dp[i+j],dp[i]+1);  
        }  
        for(ll j=9;i+j<=maxn;j*=9){  
            dp[i+j]=min(dp[i+j],dp[i]+1);  
        }  
    }  
    int n;  
    cin>>n;  
    cout<<dp[n]<<endl;  
    return 0;  
}  

Measured memory_bytes: 4096
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
 //using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//マクロ
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define _GLIBCXX_DEBUG
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())       // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))    //最大値を求める
#define MIN(x) *min_element(ALL(x))    //最小値を求める
//定数
#define INF 1000000000000  // 10^12:極めて大きい値,∞
#define inf 2147483647     // int値の最大値
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back                             // vectorヘの挿入
#define MP make_pair                             // pairのコンストラクタ
#define F first                                  // pairの一つ目の要素
#define S second                                 // pairの二つ目の要素
#define CST(x) cout << fixed << setprecision(x)  //小数点以下の桁数指定
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
//各桁の和
int sumDight(int x) {
    int sum = 0;
    while (x > 0) {
        sum += (x % 10);
        x /= 10;
    }
    return sum;
}
//回文数
int divideReverse(int x) {
    int reverse = 0;
    int r;
    while (x > 0) {
        r = x % 10;
        reverse = reverse * 10 + r;
        x /= 10;
    }
    return reverse;
}

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

    ll n;

    cin>>n;
    vector<ll> t(110);
    rep(i, n) cin >> t[i];

    ll sum = 0;

    rep(i, n) { for (ll j = i + 1; j < n;j++){
            sum += t[i] * t[j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>

using namespace std;

int main() {
	int n;

	cin >> n;

	vector< int > num(n);
	vector< vector< long long int > > ans(n - 1, vector< long long int >(21, 0));

	for(int i = 0; i < n; i++) {
		cin >> num[i];
	}

	ans[0][num[0]]++;

	for(int i = 0; i < n - 2; i++) {
		for(int j = 0; j < 21; j++) {
			if(j + num[i + 1] <= 20) {
				ans[i + 1][j + num[i + 1]] += ans[i][j];
			}
			if(j - num[i + 1] >= 0) {
				ans[i + 1][j - num[i + 1]] += ans[i][j];
			}
		}
	}

	cout << ans[n - 2][num[n - 1]] << endl;
}

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

int main() {
	int n,rank;
	cin >> n;
	int A[4][14];
	char suit;

	for (int s = 0; s < 4; s++) {
		for (int r = 0; r < 14; r++) {
			A[s][r] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		cin >> suit >> rank;
		if (suit == 'S')A[0][rank] = 1;
		if (suit == 'H')A[1][rank] = 1;
		if (suit == 'C')A[2][rank] = 1;
		if (suit == 'D')A[3][rank] = 1;
	}

	for (int s = 0; s < 4; s++) {
		for (int r = 1; r < 14; r++) {
			if (A[s][r])continue;
			if (s == 0)suit = 'S';
			if (s == 1)suit = 'H';
			if (s == 2)suit = 'C';
			if (s == 3)suit = 'D';
			cout << suit << " " << r << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3068
#include <stdio.h>

int main(void){
	int m,f,r;

	while(scanf(" %d %d %d",&m,&f,&r) != EOF){
		if(m == -1 && f == -1 && r == -1) return 0;
		if(m == -1 || f == -1){
			printf("F\n");
		}else {
		int sum = m+f;
		if(sum >= 80) printf("A\n");
		if(sum < 80 && sum >= 65) printf("B\n");
		if(sum < 65 && sum >= 50) printf("C\n");
		if(sum < 50 && sum >= 30){
			if(r >= 50) {
				printf("C\n");
			}else{
				printf("D\n");	
			}
		}
		if(sum < 30) printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll a[100005], b[100005], c[100005];

int isOK_a(ll key, ll mid) { return a[mid] >= key ? 1 : 0; }
int isOK_c(ll key, ll mid) { return c[mid] <= key ? 1 : 0; }

ll binary_search(ll key, ll n, ll aORc) // a -> aORC=1, c -> aORC=0,
{
  ll ok = n, ng = -1;
  while (llabs(ok - ng) > 1)
  {
    ll mid = (ok + ng) / 2;
    if (aORc)
      isOK_a(key, mid) ? (ok = mid) : (ng = mid);
    else
      isOK_c(key, mid) ? (ok = mid) : (ng = mid);
  }
  return ok;
}

int main()
{
  ll n, ans = 0;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
    scanf("%lld", a + i);
  for (int i = 0; i < n; i++)
    scanf("%lld", b + i);
  for (int i = 0; i < n; i++)
    scanf("%lld", c + i);
  sortup(a, n);
  sortdown(c, n);
  for (int i = 0; i < n; i++)
    ans += binary_search(b[i], n, 1) * binary_search(b[i], n, 0);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3324
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ


	Scanner scan = new Scanner(System.in);

	int r = scan.nextInt();

	double re = 2*r*Math.PI;

	System.out.println(re);

	}

}


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

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if((x - r) < 0 || (x + r) > W){
		cout << "No" << endl;
	}
	else if((x - r) >= 0 && (x + r) <= W){
		if((y - r) < 0 || (y + r) > H){
			cout << "No" << endl;
		}
		else if((y - r) >= 0 && (y + r) <= H){
			cout << "Yes" << endl;
		}
	}
	return 0;
}

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

// 二項係数計算
long long COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  COMinit();
  ll n,m,ans=1;
  ll mod=1e9+7;
  cin>>n>>m;
  for(int i=2;i*i<=m;i++){
    if(m%i==0){
      int x=0;
      while(m%i==0){
        m/=i;
        x++;
      }
      ans*=COM(x+n-1,x);
      ans%=mod;
    }
  }
  if(m>1){
    ans*=n;
    ans%=mod;
  }
  cout<<ans<<endl;
}

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

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   int mx = 0;
   ll ans = 0;
   for(int i = 0 ; i < n ; i++){
      int x;
      cin >> x;
      mx = max(mx , x);
      ans += mx - x;
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 3632
f2=[0]*10**6
p2=2
while p2<10**6:
    for i in range(p2,10**6,p2):
        f2[i]+=1
    p2*=2
for i in range(1,10**6):
    f2[i]+=f2[i-1]

n=int(input())
s=input()

p = '2' if '2' in s else '3'

ans=0
for i,c in enumerate(s):
    if c==p:
        ans += 0 if f2[n-1]-f2[i]-f2[n-1-i] else 1
print(int(p)-1 if ans%2==1 else 0)


Measured memory_bytes: 60636
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;
#define cni cin

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int n,m,k,ans=0,ci;
string s;
bool flg;

main(){
	cin>>s;
	if(s[0]<3){
		s[0]=0;
		for(int i=1;i<s.size();i++){
			s[i]=7;
		}
	}/*else{
		rep(i,s.size()){
			//if(flg)break;
			if(s[i]=='3'||s[i]=='5'||s[i]=='7')continue;
			
		}
	}*/
	while(toInt(s)>=357){
		for(int i=s.size()-1;i>=0;i--){
			if(s[i]=='3'||s[i]=='5'||s[i]=='7')continue;
			if(i==0){
				if(s[i]<'3')s[i]='0';
				else if(s[i]<'5')s[i]='3';
				else if(s[i]<'7')s[i]='5';
				else s[i]='7';
			}else{
				if(s[i]<'3'){
					s[i]='7';
					s[i-1]--;
				}else if(s[i]<'5'){
					s[i]='3';
					//s[i-1]--;
				}else if(s[i]<'7'){
					s[i]='5';
					//s[i-1]--;
				}else{
					s[i]='7';
				}
			}
		}
		s=toString(toInt(s));
		//debug(toInt(s));
		int c3=0,c5=0,c7=0;
		rep(i,s.size()){
			if(c3&&c5&&c7)break;
			if(s[i]=='3')c3++;
			if(s[i]=='5')c5++;
			if(s[i]=='7')c7++;
		}
		if(c3&&c5&&c7)ans++;
		//debug(s,s.size(),c3);
		if(s.size()==c3){
			//debug("hi");
			string t;
			rep(i,c3-1){
				t+="7";
			}
			s=t;
			//debug(t);
		}else{
			s.back()--;
		}
	}
	dans;
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))

dp = [0]*n
dp[1] = abs(li[1]-li[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(li[i-1]-li[i]),dp[i-2]+abs(li[i]-li[i-2]))
print(dp[-1])

Measured memory_bytes: 85100
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    if (a <= 2 * b) {
      System.out.println(0);
    }
    else{
      System.out.println(a - 2 * b);
    }
  }
}

Measured memory_bytes: 35716
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn main() {
    let in_vec: Vec<i32> = read_line();
    let n = in_vec[0];

    let mut res: i64 = 0;
    for i in 1..n+1 {
        if (i % 3 != 0) && (i % 5 != 0) {
            res += i as i64;
        }
    }

    println!("{}", res);
}


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

using namespace std;
#define int long long
using int64 = long long;
const int64 INF = 1LL << 60;

signed main() {
  int N;
  cin >> N;
  set< int > st;
  for(int i = 1; i * i <= N; i++) {
    if(N % i == 0) {
      st.emplace(N / i);
      st.emplace(i);
    }
  }
  int64 ret = INF;
  for(auto &p : st) {
    int a = p;
    int b = N / a;
    ret = min< int64 >(ret, max(to_string(a).size(), to_string(b).size()));
  }
  cout << ret << endl;
}



Measured memory_bytes: 384
I, O, T, J, L, S, Z = map(int, input().split())

IJL = (I, J, L)

A = sum((e // 2) * 2 for e in IJL)
B = 0 if any(e <= 0 for e in IJL) else sum(((e - 1) // 2) * 2 for e in IJL) + 3

print(max(A, B) + O)


Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    var sum = 0
    val a = readLine()!!.split(' ').map {
        val num = it.toInt()
        sum += num
        num
    }
    val ave = sum/N
    var u = 0
    var o = 0
    repeat(N) {
        u += (a[it] - ave) * (a[it] - ave)
        o += (a[it] - (ave+1)) * (a[it] - (ave+1))
    }
    println(Math.min(u,o))
}


Measured memory_bytes: 37776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        long mod = 1000000000 + 7;

        int[] A = new int[N];

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

        long inversion = 0L;
        long inA = 0;
        long cA = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < i; j++) {
                if (A[j] > A[i]) {
                    inA++;
                }
            }

            for (int j = 0; j < N; j++) {
                if (A[j] > A[i]) {
                    cA++;
                }
            }
        }

        inversion = (((inA * K) % mod) + (cA % mod * ((K * (K - 1) / 2) % mod))) % mod;

        System.out.println(inversion);
    }
}

Measured memory_bytes: 25484
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge {
	int from,to;
	int cost;

	edge(int t,int c) : to(t),cost(c) {}
	edge(int f,int t,int c) : from(f),to(t),cost(c) {}

	bool operator<(const edge &e) const {
		return cost < e.cost;
	}
};

int n, m, k;
vector<edge> G[3005];
int d[3005], cost[3005][3005];
bool used[3005];

void dijkstra(int s,int n) {
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);

	d[s] = 0;
	que.push(P(0,s));

	while(que.size()) {
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v] < p.first) continue;

		rep(i,G[v].size()) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

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

	memset(used, 0, sizeof(used));
	memset(cost, 0, sizeof(cost));

	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;

		a--; 
		b--;

		G[a].push_back(edge(b, c));
		G[b].push_back(edge(a, c));

		cost[a][b] = c;
		cost[b][a] = c;
	}

	rep(i, k) {
		int x;
		cin >> x;
		used[x-1] = true;
	}

	vector<P> v(n);
	rep(i, n) {
		dijkstra(i, n);

		int res = INF, id = -1;
		rep(j, n) {
			if(used[j]) {
				if(res > d[j]) {
					res = d[j];
					id = j;
				}
			}
		}

		v[i] = mp(res, id); 
	}

	// rep(i, n) {
	// 	cout << "i:" << i << " " << v[i].first << " " << v[i].second << endl;
	// }

	int ans = 0;
	rep(i, n) {
		rep(j, n) {
			int res = v[i].first + v[j].first + cost[i][j];
			ans = max(ans, (res % 2 == 0 ? res / 2 : res / 2 + 1));
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int ans=0;
  string s;
  string t="CODEFESTIVAL2016";
  cin>>s;
  for(int i=0;i<16;i++)
    if(s[i]!=t[i])ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> list(9, vector<int>(9));
    rep(i, 9) rep(j, 9) list[i][j] = (i + 1) * (j + 1);
    rep(i, 9) rep(j, 9) if (list[i][j] == n) n = 0;
    if(n==0)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
}

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

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

    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N,x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
ans = 0
for i in range(N):
  if x-a[i] >=0:
    ans += 1
    x -= a[i]
  else:
    break

if x == 0 or ans == 0 or ans < N:
  print(ans)
else:
  print(ans-1)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);

		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > 0) {
				ans += a[i];
			}
		}

		long p = 0;
		long m = 0;
		for (int i = 0; i < k; i++) {
			if (a[i] > 0) {
				p += a[i];
			} else {
				m += a[i];
			}
		}

		long pMin = p;
		long mMax = m;
		for (int i = k; i < n; i++) {
			if (a[i - k] > 0) {
				p -= a[i - k];
			} else {
				m -= a[i - k];
			}
			if (a[i] > 0) {
				p += a[i];
			} else {
				m += a[i];
			}
			pMin = Math.min(pMin, p);
			mMax = Math.max(mMax, m);
		}
		ans = Math.max(ans - pMin, ans + mMax);
		System.out.println(ans);
	}
}


Measured memory_bytes: 44508
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,k,cc[50000][20],dd[500000],a,b;
char s[500000];
int main(){
	scanf("%d%d",&n,&a);
	if (a-n>=2018) printf("0\n");
	else{
		n%=2019;
		a%=2019;
		m=2019;
		if (n>a) printf("0\n");
		else{
			for (int i=n;i<=a;i++){
				for (int j=i+1;j<=a;j++) m=min(m,(i*j)%2019); 
			}
			printf("%d\n",m);
		}
	}
	return 0;
} 

Measured memory_bytes: 2304
/*
AizuOnline A1147
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int n,point[100];
//
int comp(void * x,void * y)
{
  return(*(int *)x- *(int *)y);
}
main()
{
  int i,m,sum;
  
  while(EOF!=scanf("%d ",&n) && n)
    {
      for(i=0;i<n;i++)
	scanf("%d",&(point[i]));

      qsort(point,n,sizeof(int),comp);

      sum=0;m=0;
      for(i=1;i<n-1;i++)
	  {
	    m++;
	    sum += point[i];
	  }
      printf("%d\n",sum/m);
    }
return(0);
}

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


int main()
{
  int n, l;
  cin >> n >> l;
  int s = l * (n - 1) + (n - 1) * n / 2;
  if (l < 0)
    s -= min(-l, n - 1);
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;

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

  int N; cin >> N;
  string S; cin >> S;

  int border = 0;
  REP(i,N-1) {
    if (S[i] != S[i+1]) border++;
  }

  int ans = border+1;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#endif

#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
struct edge { int to, cost; };
typedef std::pair<int, int> P;

int H, W;
char s, t;
std::string a[51];
std::vector<edge>G[51];
LL d[112345];

void dijkstra(int s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(d, d + 51, 114514810);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (d[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	in >> H >> W >> s >> t;
	rep(i, H) in >> a[i];
	for (int i = 1; i < H - 1; ++i)
	{
		for (int j = 1; j < W - 1; ++j)
		{
			if (a[i][j] != 'o'&&a[i][j] != '-'&&a[i][j] != '|'&&a[i][j] != '.')
			{
				// 右へ
				for (int k = j + 2; k < W - 1; ++k)
				{
					if (a[i][k] == 'o')
					{
						G[a[i][j] - 'A'].push_back({ a[i][k + 1] - 'A',1 });
						break;
					}
					if (a[i][k] != '-') break;
				}
				// 左へ
				for (int k = j - 2; k > 1; --k)
				{
					if (a[i][k] == 'o')
					{
						G[a[i][j] - 'A'].push_back({ a[i][k - 1] - 'A',1 });
						break;
					}
					if (a[i][k] != '-') break;
				}
				// 下へ
				for (int k = i + 2; k < H - 1; ++k)
				{
					if (a[k][j] == 'o')
					{
						G[a[i][j] - 'A'].push_back({ a[k + 1][j] - 'A',1 });
						break;
					}
					if (a[k][j] != '|') break;
				}
				// 上へ
				for (int k = i - 2; k > 1; --k)
				{
					if (a[k][j] == 'o')
					{
						G[a[i][j] - 'A'].push_back({ a[k - 1][j] - 'A',1 });
						break;
					}
					if (a[k][j] != '|') break;
				}
			}
		}
	}
	dijkstra(s - 'A');
	out << d[t - 'A'] << std::endl;
	return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()


int anyt(int n)
{
	 int l=1;
	 int r=2*sqrt(n);
	 int ans=1;
	 while(l<=r)
	 {
	 	 int m=(l+r)/2;
	 	 int t=m*(m+1);
	 	 t/=2;
	 	 if(t<=n)
	 	 {    
	 	 	 l=m+1;
	 	 	 ans=m;

	 	 }
	 	 else
	 	 {
	 	 	 r=m-1;
	 	 }
	 }

	 return ans;
}

void dit(map<int,int> &a,int n)
{
	 while(n%2==0)
	 {
	 	 a[2]++;
	 	 n/=2;
	 }

	 for(int i=3;i*i<=n;i++)
	 {
	 	 if(n%i==0)
	 	 {
	 	 	 while(n%i==0)
	 	 	 {
	 	 	 	 a[i]++;
	 	 	 	 n/=i;
	 	 	 }
	 	 }
	 }

	 if(n>1)
	 {
	 	 a[n]++;
	 }


}

void solve(){
    
   int n;
   cin>>n;
   if(n<=1)
   {
   	 cout<<0<<"\n";
   	 return;
   }
   map<int,int> g;
   dit(g,n);
   int ans=0;
   for(auto x:g)
   	 {
   	 	int p=anyt(x.second);
   	 	ans+=p;
   	 }

   	 cout<<ans<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST; return 0;
}

Measured memory_bytes: 3680
S = [len(x) for x in input().split('T')]

x,y = map(int,input().split(" "))
xstart = 0
dir = 0 # 0→ x方向 1 →y方向
first = True

temp = 0
spin_count = 0
x_array = []
y_array = []

xstart = S[0]
for c in S[1:]:
    if c != 0:
        dir += 1
        dir %= 2
        temp = c
        if dir == 0:
            x_array.append(temp)
        else:
            y_array.append(temp)
    else:
        dir += 1






dpx ={}
dpx[xstart] = 1


for i in x_array:
    temp = []
    remove = []
    for k,v  in dpx.items():
        if v != -1:
            temp.append(k + i)
            temp.append(k - i)
            remove.append(k)
    for k in remove:
        dpx[k] = -1
    for k in temp:
        dpx[k] = 1

dpy ={}
dpy[0] = 1
for i in y_array:
    temp = []
    remove = []

    for k,v  in dpy.items():
        if v != -1:
            temp.append(k + i)
            temp.append(k - i)
            remove.append(k)
    for k in remove:
        dpy[k] = -1
    for k in temp:
        dpy[k] = 1

if x in dpx and y in dpy and dpx[x] == 1 and dpy[y] == 1 :
    print("Yes")
else:
    print("No")

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

int main(){
  int a[3];
  rep(i,3) cin>>a[i];
  if (a[0]+a[1]==a[2] || a[1]+a[2]==a[0] || a[0]+a[2]==a[1]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

X = I()

if X >= 30:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9144
import java.util.Scanner;

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

		String s = sc.next();

		for (int i = 1; i < 4; i++) {
			if (s.charAt(i) == s.charAt(i - 1)) {
				System.out.println("Bad");
				return;
			}
		}
		
		System.out.println("Good");
	}
}


Measured memory_bytes: 21844
n,k,q=[int(i) for i in input().split()]
A=[int(input()) for i in range(q)]

points=[k-q]*n
for i in range(q):
  points[A[i]-1]+=1
for i in range(n):
  if points[i]>0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 10448
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define  st first
#define  nd second

/*DEBUGGER*/

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

/*ENDOFDEBUGGER*/

#define maxn 1000001
#define MOD   1000000007
#define int long long

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef gp_hash_table<int, int, hash<int > > ht;

vector<int> graph[maxn];

int to_map(pair<int,int> &p){
    return (min(p.st,p.nd)*1000 )+ max(p.st,p.nd);
}
int indeg[maxn];
int is_used[maxn];

//bool vis[maxn];
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int u;
    cin>>u;
    u--;
    for(int j=0;j<n-2;j++){
        int v;
        cin>>v;
        v--;
        pair<int,int> pu=make_pair(i,u);
        pair<int,int> pv=make_pair(i,v);
        int x=to_map(pu);
        int y=to_map(pv);
        //dbg(x,y);
        graph[x].push_back(y);

        indeg[y]++;
        is_used[x]=1;
        is_used[y]=1;

        u=v;

    }
  }

  vector<int> q;

  for(int i=0;i<maxn;i++){
    if(indeg[i]==0 and is_used[i]){
        q.push_back(i);
    }
  }
  int cnt=0;
  int days=0;
  while(q.size()){
    vector<int> p;
    cnt+=q.size();
    for(int i=0;i<q.size();i++){
        for(auto j : graph[q[i]]){
            indeg[j]--;
            if(!indeg[j])
                p.push_back(j);
        }
    }
    q=p;
    days++;
  }
  //dbg(cnt,days);
  if(cnt!=n*(n-1)/2)
    cout<<"-1";
  else
    cout<<days;

}


Measured memory_bytes: 54912
n = int(input())
a = list(map(int, input().split()))
m = 1145141919810
c = 0
ans = 0
for i in a:
    if i < 0:
        c += 1
        i = abs(i)
    if i < m:
        m = i
    ans += i
if c % 2 == 1:
    ans -= 2 * m
print(ans)

Measured memory_bytes: 14284
x, y = [int(w) for w in input().split()]

d = abs(abs(x) - abs(y))


if d == 0:
    if x - y == 0:
        ans = 0
    else:
        ans = 1
elif y == 0:
    if x < 0:
        ans = abs(x)
    else:
        ans = x + 1
else:
    ans = d

    if x * y > 0:
        if x > y:
            ans += 2
    else:
        if x > y:
            ans += 1
        elif x < 0:
            ans += 1

print(ans)


Measured memory_bytes: 9168
// A - キャンディーと2人の子供

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

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

	string ans;

	if (a + b == c || b + c == a || c + a == b) ans = "Yes";
	else ans = "No";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <stack>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

int main(){
	int n;
	cin>>n;
	vector<LL> a(n),b(n);
	LL sum=0,sum2=0;
	FOR(i,0,n){
		cin>>a[i];
		sum+=a[i];
	}
	FOR(i,0,n){
		cin>>b[i];
		sum2+=b[i];
	}
	if(sum2>sum){
		cout<<-1<<endl;
		return 0;
	}
	priority_queue<pll> pos;
	priority_queue<pll> neg;
	FOR(i,0,n){
		if(a[i]>b[i]){
			LL d=a[i]-b[i];
			pos.push(MP(d,i));
		}
	}
	LL rest=0,cnt=0;
	FOR(i,0,n){
		if(a[i]<b[i]){
			LL d=b[i]-a[i];
			cnt++;
			//cerr<<"change:"<<i<<endl;
			while(pos.size()&&rest<d){
				pll pr=pos.top();
				pos.pop();
				//cerr<<"change pos:"<<pr.ND<<endl;
				cnt++;
				rest+=pr.ST;
			}
			if(rest>=d){
				rest-=d;
			}else{
				cerr<<"Error"<<endl;
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 2936
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 4017

int n, i;
ll x, dif, aux, ans;
ll a[maxN];
deque< pair<int, int> > Q;


int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d%lld", &n, &x);
    for (i = 1; i <= n; i++) scanf("%lld", &a[i]), a[n + i] = a[i];

    ans = 1LL << 60;

    for (dif = 1; dif <= n; dif++) {
        while (!Q.empty()) Q.pop_back();

        aux = (dif - 1) * x;

        for (i = 1; i <= 2 * n; i++) {
            while (!Q.empty()) {
                if (Q.back().first < a[i]) break;
                Q.pop_back();
            }

            Q.push_back(mp(a[i], i));

            if (Q.front().second + dif <= i) Q.pop_front();

            if (i > n)
                aux += Q.front().first;
        }

        ans = min(ans, aux);
    }

    printf("%lld", ans);



    return 0;
}


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

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

int main() {
  int64_t N, M; cin >> N >> M;
  int64_t ans = 0;
  int64_t x = min(N, M / 2);
  ans += x;
  M -= x * 2;
  ans += M / 4;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
int main(void){
	ll i,j,k;
	ll n,m,s,g,b,e,pp,kou;
	ll ri[21][21];
	ll leng[21],v[21];
	ll min;
	
	PP p[100];
	
	cin>>n>>m;
	for(i=0;i<m;i++) scanf("%lld,%lld,%lld,%lld",&p[i].ff,&p[i].fs,&p[i].ss,&p[i].sf);
	scanf("%lld,%lld,%lld,%lld",&s,&g,&b,&e);
	
	//隣接行列
	sort(p,p+m);
	for(i=0;i<=n;i++) for(j=0;j<=n;j++) ri[i][j]=M;
	for(i=0;i<m;i++) ri[p[i].ff][p[i].fs]=p[i].sf,ri[p[i].fs][p[i].ff]=p[i].ss;
	
	//初期化
	for(k=0;k<=n;k++)leng[k]=M,v[k]=0;
	leng[s]=0;
	
	kou=0;
	//ダイクストラ法
	for(j=1;j<=n;j++){
		min=M;
		for(k=1;k<=n;k++) if(v[k]==0&&leng[k]<min) pp=k,min=leng[k];
		v[pp]=1;
		
		if(min==M)break;
		
		for(k=1;k<=n;k++){
			if((leng[pp]+ri[pp][k])<leng[k]) leng[k]=leng[pp]+ri[pp][k];
		}
	}
	kou+=leng[g];
//	cout<<leng[g]<<endl;
	
	//初期化
	for(k=0;k<=n;k++)leng[k]=M,v[k]=0;
	leng[g]=0;
	
	//ダイクストラ法
	for(j=1;j<=n;j++){
		min=M;
		for(k=1;k<=n;k++) if(v[k]==0&&leng[k]<min) pp=k,min=leng[k];
		v[pp]=1;
		
		if(min==M)break;
		
		for(k=1;k<=n;k++){
			if((leng[pp]+ri[pp][k])<leng[k]) leng[k]=leng[pp]+ri[pp][k];
		}
	}
	kou+=leng[s];
//	cout<<leng[s]<<endl;
	
	cout<<b-e-kou<<endl;
	return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h, w;
  cin >> h >> w;
  unordered_map<char,int> cnt;
  rep(i,h) rep(j,w) { //文字のカウント
    char a;
    cin >> a;
    if (cnt.count(a) == 0) cnt[a] = 0;
    cnt[a]++;
  }
  priority_queue<int> que;
  for (auto p : cnt) {
    que.push(p.second);
  }
  vector<int> num;
  rep(y,(h+1)/2) {
    rep(x,(w+1)/2) {
      vector<P> loc = {P(y,x), P(h-y-1,x), P(y,w-x-1), P(h-y-1,w-x-1)}; //対応する場所
      sort(all(loc));
      loc.erase(unique(all(loc)), loc.end());
      num.emplace_back(loc.size());
    }
  }
  sort(all(num), greater<int>());
  bool ok = true;
  for (auto n:num) {  
    int c = que.top(); que.pop();
    if (c < n) {
      ok = false; break;
    }
    else {
      c -= n;
      que.push(c);
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
typedef long long int ll;
typedef long double ld;
const ll N = 2e5+9;
const ll m = 1e9 + 7;
const ll MAXN = 2e3 + 9;

const ll inf= 1e14;
const ll mod =163577857;
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pld pair<ld,ld>
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
ll lo[MAXN+1];
ll st[MAXN][MAXN + 1],n;
ll qr(ll L,ll R){
    ll j = lo[R - L + 1];
    ll minimum = min(st[L][j], st[R - (1 << j) + 1][j]);
    return minimum;
}
ll mi(ll i,ll k){
    if((i-k)<0){
        ll ans = min(qr(0,i),qr(n-(k-i),n-1));
        return ans;
    }
    else{
        ll ans = qr(i-k,i);
        return ans;
    }
}
int main()
{   
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif     
    ll T= 1;
    // cin >> T;
    lo[1] = 0;
    for (int i = 2; i <= MAXN; i++)
        lo[i] = lo[i/2] + 1;
    while(T--){
        ll K,x;cin>>n>>x;
        ll a[n];
        for(int i = 0;i<n;i++){
            cin>>a[i];
        }
        K = lo[n];

        for (int i = 0; i < n; i++)
            st[i][0] = a[i];

        for (int j = 1; j <= K; j++)
            for (int i = 0; i + (1 << j) <= n; i++)
                st[i][j] = min(st[i][j-1], st[i + (1 << (j - 1))][j - 1]);

        ll ans = inf;
        for(int k = 0;k<=n;k++){
            ll te = k*x;
            for(int i = 0;i<n;i++){
                te+=mi(i,k);
            }
            ans = min(ans,te);
        }
        cout<<ans<<'\n';
    }
   
}   

Measured memory_bytes: 11816
N = int(input())

t = list(map(int,input().split()))
v = list(map(int,input().split()))

alltime = sum(t)
maxslis = []
rmaxslis = []



spd = 0
ans = 0

for i in range(N):

    for j in range(t[i]):
        maxslis.append(v[i])
        maxslis.append(v[i])
        rmaxslis.append(v[i])


maxslis.reverse()


for i in range(alltime * 2):

    if i == 0:
        able = 0.5
        maxslis[i] = 0

    elif able < maxslis[i]:
        maxslis[i] = able
        able += 0.5

    else:
        able = maxslis[i]

maxslis.reverse()
maxslis.append(0)

#print (maxslis)
dtflag = False

for i in range(alltime * 2 + 1):

    #print (i+1,maxslis[i],spd)

    if spd < maxslis[i]:

        ans += spd * 0.5 + 0.125
        spd += 0.5
        #if spd != maxslis[i]:
            #dtflag = True

    elif spd == maxslis[i]:

        #if dtflag and rmaxslis[i] != maxslis[i]:
            #ans += 0.25
            #print (i+1)
        ans += spd * 0.5
        dtflag = False

    else:
        ans += spd * 0.5 - 0.125
        spd -= 0.5
        dtflag = False

print (ans)


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

const int MAXN = 1e6 + 5, MOD = 924844033, g = 5;

int n, u, v, lim, cnt = 0;
int a[MAXN], b[MAXN], h[MAXN], siz[MAXN], fac[MAXN], r[MAXN];

struct edge
{
    int v, nxt;
}E[MAXN * 2];

void add_edge(int u, int v)
{
    E[cnt].v = v;
    E[cnt].nxt = h[u];
    h[u] = cnt++;
}

int fpow(int a, int n)
{
    int rtn = 1;
    for(; n; n >>= 1, a = 1ll * a * a % MOD)
        if(n & 1) rtn = 1ll * rtn * a % MOD;
    return rtn;
}

int inv(int x)
{
    return fpow(x, MOD - 2);
}

void dfs(int cur, int fa)
{
    for(int i = h[cur]; ~i; i = E[i].nxt)
    {
        int v = E[i].v;
        if(v == fa) continue;
        dfs(v, cur);
        siz[cur] += siz[v];
        a[siz[v]]--;
    }
    siz[cur]++;
    a[n - siz[cur]]--; a[n]++;
}

void init()
{
    fac[0] = 1;
    for(int i = 1; i <= n; i++)
        fac[i] = 1ll * fac[i - 1] * i % MOD;
    for(int i = 0; i <= n; i++)
        a[i] = 1ll * (a[i] % MOD + MOD) % MOD * fac[i] % MOD;
    for(int i = 0; i <= n; i++)
        b[n - i] = inv(fac[i]);
    lim = 1;
    while(lim <= n * 2) lim <<= 1;
    for(int i = 1; i < lim; i++)
        r[i] = (r[i >> 1] >> 1) | (i & 1 ? lim >> 1 : 0);
}

void ntt(int *f, bool p = 0)
{
    for(int i = 1; i < lim; i++)
        if(i < r[i]) swap(f[i], f[r[i]]);
    for(int i = 2; i <= lim; i <<= 1)
    {
        int len = i >> 1;
        int ur = fpow(g, (MOD - 1) / i);
        if(p) ur = inv(ur);
        for(int j = 0; j < lim; j += i)
        {
            int tmp = 1;
            for(int k = j; k < j + len; k++)
            {
                int t = 1ll * tmp * f[k + len] % MOD;
                f[k + len] = f[k] - t;
                f[k] = f[k] + t;
                if(f[k] >= MOD) f[k] -= MOD;
                if(f[k + len] < 0) f[k + len] += MOD;
                tmp = 1ll * tmp * ur % MOD;
            }
        }
    }
    if(p)
    {
        int tmp = inv(lim);
        for(int i = 0; i < lim; i++)
            f[i] = 1ll * f[i] * tmp % MOD;
    }
}

int main()
{
    cin>>n;
    memset(h, -1, sizeof(h));
    for(int i = 1; i < n; i++)
    {
        cin>>u>>v;
        add_edge(u, v); add_edge(v, u);
    }
    dfs(1, 0);
    init();
    ntt(a); ntt(b); 
    for(int i = 0; i < lim; i++)
        a[i] = 1ll * a[i] * b[i] % MOD;
    ntt(a, 1); 
    //for(int i = 0; i < lim; i++)
   //     cout<<a[i]<<' ';cout<<endl;
    for(int i = 1; i <= n; i++)
        cout<<1ll * inv(fac[i]) * a[i + n] % MOD<<endl;
    return 0;
}

Measured memory_bytes: 34688
use proconio::input;

fn main() {
    input! {
        a: f64,
        b: f64,
        h: i64,
        m: i64,
    };
    let a1 = (-h % 12) as f64 * 360_f64 / 12_f64
        + ((-m % 60) as f64 * 360_f64 / 60_f64 / 12_f64)
        + 90_f64;
    let b1 = (-m % 60) as f64 * 360_f64 / 60_f64 + 90_f64;
    let a2 = a1 * (2_f64 * std::f64::consts::PI) / 360_f64;
    let b2 = b1 * (2_f64 * std::f64::consts::PI) / 360_f64;
    let x = a2.cos() * a - b2.cos() * b;
    let y = a2.sin() * a - b2.sin() * b;
    let ans = (x * x + y * y).sqrt();
    println!("{}", ans);
}


Measured memory_bytes: 2964
#include <stdio.h>


#define N 100

int selectionSort(int *,int);

int main(){
  int s,t[N],i;
  scanf("%d",&s);

  for(i=0;i<s;i++)
    scanf("%d",&t[i]);

  printf("%d\n",selectionSort(t,s));

  return 0;
}
int selectionSort(int *t,int s){
  int swap,count=0,i,minj,j;
  for(i=0;i<s-1;i++){
    minj = i;
    for(j=i;j<s;j++){
      if(t[j]<t[minj]){
	minj = j;
     }
    }
    if(minj!=i){
      swap = t[minj];
      t[minj] = t[i];
      t[i] = swap;
      count++;  
    }
  }
  for(i=0;i<s-1;i++)
    printf("%d ",t[i]);
  printf("%d\n",t[s-1]);

  return count;
}




Measured memory_bytes: 2700
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

signed main(){
    llin(n);
    vll a(n);
    ll s=0;
    FOR(i,0,n-1){
        cin >>a[i];
        s+=a[i];
    }
    rSORT(a);
    sal(s-a[0]/2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const bool debug = 0;
//---------------------------------//

int main() {
	string S; cin >> S;
	
	string T;
	REP(i, S.size()) {
		if (S[i] == 'A') T += 'A';
		else if (i + 1 < S.size() && S.substr(i, 2) == "BC") {
			T += 'D';
			i++;
		}
		else T += 'R';
	}
	
	ll ans = 0, cnt = 0;
	REP(i, T.size()) {
		if (T[i] == 'A') cnt++;
		else if (T[i] == 'R') cnt = 0;
		else ans += cnt;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,x,c=0,flag=0;
    cin>>n>>k;
    int b[n+2];
    for(i=0; i<n; i++)
    {
        b[i]=i+1;
    }
    while(k--)
    {
        cin>>x;
        int a[x+2];
        for(i=0; i<x; i++)
        {
            cin>>a[i];
        }
        sort(a,a+x);
        for(i=0; i<x; i++)
        {for(j=i;j<n;j++)
        {
            if(a[i]==b[j])
            {
                b[j]=-1;
            }
        }

        }
    }
    for(i=0; i<n; i++)
    {
        if(b[i]!=-1)
        {
            c++;
        }
    }
     cout<<c<<endl;






}


Measured memory_bytes: 3636