akhauriyash/Code-Regression huggingface dataset:
import math
n = int(input())
s = input().split(" ")
x = list(map(int,s))
s = input().split(" ")
y = list(map(int,s))
sa = []
for i in range(n):
    sa.append(math.fabs(x[i]-y[i]))
goukei = 0
for i in range(n):
    goukei += sa[i]
p1 = goukei
print(p1)
goukei = 0
for i in range(n):
    goukei += sa[i]**2
p2 = math.sqrt(goukei)
print(p2)
goukei = 0
for i in range(n):
    goukei += sa[i]**3
p3 = math.pow(goukei,1/3)
print(p3)
saidaisa = 0
for i in range(n):
    if sa[i] > saidaisa:
        saidaisa = sa[i]
print(saidaisa)

Measured memory_bytes: 7824
#include<stdio.h>

int nextInt();

int gcd(int a, int b){
	int t;
	if(a < b){t=a; a=b; b=t;}
	if(b < 1){return -1;}
	if(a%b == 0){return b;}
	return gcd(b, a%b);
}

int gcda(int *a, int length){
	if(length <= 0){return -1;}
	if(length == 1){return *a;}
	return gcd(*a, gcda(a+1, length-1));
}

int N, A[100000], ans, i;

int main(){
	N=nextInt();
	for(i=0; i<N; i++){
		A[i]=nextInt();
	}
	ans = gcda(A, N);
	printf("%d\n", ans);
	return 0;
}

int nextInt(){
	int f=0; char c=getchar();
	while((c<'0')||('9'<c)){c=getchar();}
	while((c>='0')&&(c<='9')){f=f*10+(c-'0'); c=getchar();}
	return f;
}


Measured memory_bytes: 2048
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,m,f[10005][4][2];
char ch[10005];
int dfs(int x,int y,int c){
    if(y>m)return 0;
    if(x>n)return y==m;
    if(f[x][y][c]!=-1)return f[x][y][c];
    int ok=c==1?ch[x]-'0':9;
    int sum=0;
    for(int i=0;i<=ok;i++)sum+=dfs(x+1,y+(i!=0),c&&i==ok);
    return f[x][y][c]=sum;
}
int main(){
    memset(f,-1,sizeof(f));
	scanf("%s",ch+1);
    in(m);
    n=strlen(ch+1);
    cout<<dfs(1,0,1)<<endl;
	return 0;
}
//法大师傅士大夫·1

Measured memory_bytes: 512
str = input()
N = int(str)

A = []
str = input().split()
for i in range(N):
    A.append(int(str[i]))

cnt = 0
flag = 0
while True:
    for i in range (N):
        if A[i] % 2 != 0:
            flag = 1
            break
        A[i] = A[i] / 2
    if flag ==1:
        break
    cnt = cnt+1

print(cnt)
    

Measured memory_bytes: 3060
require 'matrix'
loop do
  s = gets.chomp.chop
  break if s == ''

  #lookahead(?!  )
  s.gsub!(/([A-Z\)])(?![a-z\d])/, '\11')
  s.gsub!(/([A-Z][a-z])(?!\d)/, '\11')
  s.gsub!(/\((.+?)\)(\d*)/){
    as, n = $1, $2
    as.gsub(/([a-zA-Z])(\d+)/){"#{$1}#{$2.to_i * n.to_i}"}
  }
  atoms = s.scan(/[A-Z][a-z]?/).uniq
  l = s.split('->')[0].count('+') + 1
  molecules = s.split(/\->|\+/)
  m = molecules.size - 1
  n = atoms.size

  a = Matrix.build(n, m){|y, x|
    molecules[x].scan(/#{atoms[y]}(\d+)/).reduce(0){ |sum, a|
      x < l ? sum + a[0].to_i : sum - a[0].to_i
    }.to_r
  }.to_a

  b = [0] * n
  atoms.each do |atom|
    molecules[-1].scan(/(#{atom})(\d+)/).each{ |a, k|
      b[atoms.index(a)] = k.to_r
    }
  end

  # Gauss-Jordan elimination
  (0...[n,m].min).each do |i|
    pv = (i...n).max{|k| a[k][i].abs}
    a[i], a[pv] = a[pv], a[i]
    b[i], b[pv] = b[pv], b[i]
    (0...n).each do |j|
      next if i == j
      r = a[j][i] / a[i][i]
      (i...m).each do |k|
        a[j][k] -= r * a[i][k]
      end
      b[j] -= r * b[i]
    end
  end

  ans = (Matrix[*a[0,m]].inv * Vector[*b[0,m]]).to_a + [1.to_r]
  lcm = ans.map(&:denominator).reduce(&:lcm)
  puts ans.map{|x| (x * lcm).to_i} * ' '
end

Measured memory_bytes: 9944
c=[]
for i in range(3):
    c.append(list(int(i) for i in input().split()))
flag = True
tmp = [[],[],[]]
tmp2 = [[],[],[]]
for i in range(3):
    tmp[0].append(c[i][1]-c[i][0])
    tmp[1].append(c[i][2]-c[i][1])
    tmp[2].append(c[i][0]-c[i][2])
    tmp2[0].append(c[1][i]-c[0][i])
    tmp2[1].append(c[2][i]-c[1][i])
    tmp2[2].append(c[0][i]-c[2][i])
for i in range(3):
    if not tmp[i][0]==tmp[i][1]==tmp[i][2]:
        flag = False
        break
    if not tmp2[i][0]==tmp2[i][1]==tmp2[i][2]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
  char s[4];
  for(int i=0;i<4;i++){
    scanf("%s",&s[i]);
  }

  if(s[0]==s[1]){
    if(s[2]==s[3]&&(s[0]!=s[2])){
      puts("Yes");
      return 0;
    }
  }
  if(s[0]==s[2]){
    if((s[1]==s[3])&&(s[0]!=s[1])){
      puts("Yes");
      return 0;
    }
  }
  if(s[0]==s[3]){
    if(s[1]==s[2]&&(s[0]!=s[1])){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  string s;
  cin >> s;
  int sum=0,i;
  for(i=0;i<s.size();i++){
    sum+=(s[i]-'0');
  }
  if(sum%9==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3756
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int n;


lli As[1005];
lli* A;

int main(void){
	scanf("%d",&n);
	lli a=0,b=0;
	A=As;
	
	bool allf=true;
	rep(i,n){
		scanf("%lld",&A[i]);
		if(A[i]<=0)continue;
		allf=false;
		if(i%2)a+=A[i];
		else b+=A[i];
	}
	
	
	if(allf){
		lli ans=-(1LL<<40);
		int p=-1;
		rep(i,n){
			if(A[i]>ans){
				p=i; ans=A[i];
			}
		}
		printf("%lld\n%d\n",ans,n-1);
		ireg(i,p+1,n-1)printf("%d\n",i+1);
		reg(i,0,p-1)printf("%d\n",1);
		return 0;
	}
	
	int d=0;
	if(a>b){
		A++; d=1; n--;
	}
	
	lli ans=max(a,b);
	//printf("%lld %lld\n",a,b);
	
	vector<int> ss;
	bool ist=false;
	irep(i,n){
		if(i%2==1 || A[i]<=0){
			ss.push_back(i); n--;
		}
		else break;
	}
	
	while(n>0){
		if(A[0]<=0){
			ss.push_back(0); 
			ss.push_back(0); 
			A += 2; n-=2;
		}
		else break;
	}
	
	int p=2,i=2;
	while(i<n){
		if(A[i]<=0){
			ss.push_back(2);
		}
		else{
			ss.push_back(1);
		}
		i += 2;
	}
	
	printf("%lld\n",ans);
	printf("%d\n",ss.size()+d);
	if(d)printf("%d\n",1);
	rep(i,ss.size())printf("%d\n",ss[i]+1);
	
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<int> A(X), B(Y), C(Z);
    cin >> A >> B >> C;
    sort(all(C));

    vector<int> s;
    s.reserve(1000006);
    fore(x, A) {
        fore(y, B) {
            s.pb(x + y);
        }
    }
    sort(all(s));

    int ok = 0;
    int ng = 30000000000LL;

    while (abs(ok - ng) > 1) {
        int m = (ok + ng) / 2;
        int cnt = 0;
        fore(x, C) {
            cnt += end(s) - lower_bound(all(s), m - x);
        }
        if (cnt >= K) {
            ok = m;
        } else {
            ng = m;
        }
    }
    dump(ok);
    
    vector<int> ans;
    fore(x, s) {
        for (auto itr = lower_bound(all(C), ok - x); itr != end(C); itr++) {
            ans.pb(x + *itr);
        }
    }
    sort(rall(ans));
    rep(i, 0, K) {
        cout << ans[i] << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 140128
num = int(input())
input_line = input().split(" ")
num_line = [int(n) for n in input_line]

num_line.sort()

#print(num_line)
del_numlis=[num_line[0]]
item_numlis=[]
counter=1

for i in range(1,num):
    if(num_line[i-1]==num_line[i]):
        counter += 1
    
    else:
        item_numlis.append(counter)
        counter = 1
        del_numlis.append(num_line[i])
        
item_numlis.append(counter)

#print(del_numlis)
#print(item_numlis)

del_numlis_len = len(del_numlis)
result = 0

for i  in range(del_numlis_len - 2):
    tri_1 = del_numlis[i]
    for j in range(i+1,del_numlis_len - 1):
        tri_2 = del_numlis[j]
        for k in range(j+1,del_numlis_len):
            tri_3 = del_numlis[k]
            
            if(tri_1 + tri_2 > tri_3):
                result += item_numlis[i]*item_numlis[j]*item_numlis[k]
            
print(result)

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

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();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int n,m; cin >> n >> m;
    VI a(n); REP(i,n) cin >> a[i];
    VL s(m+1,0), e(m+1,0);
    REP(i,n-1) s[a[i]]++;
    REP(i,n-1){
        if(a[i]<a[i+1]) e[a[i+1]] += a[i+1]-a[i]-1;
        else{
            e[a[i+1]] += m-a[i];
            e[a[i+1]] += a[i+1]-1;
        }
    }

    VL p(m+1,0), q(m+1,0);
    REP(i,n-1){
        if(a[i]<m && a[i+1]<a[i]) p[m]++;
        if(a[i+1] == m) q[m] += e[m];
    }
    RFOR(i,m,1){
        p[i] = p[i+1] + s[i+1];
        if(i == a[n-1]-1) p[i]++;
        if(i == a[0]-1) p[i]--;
        p[i] -= s[i];
        q[i] = e[i];
    }

    ll ans = 0;
    REP(i,n-1){
        if(a[i+1] == m) ans += 1;
        else if(a[i]<a[i+1]) ans += a[i+1]-a[i];
        else if(a[i]==m) ans += a[i+1];
        else ans += a[i+1]+1;
    }

    ll tmp = ans;
    REP(i,m-1){
        tmp += p[m-1-i];
        tmp -= q[m-1-i];
        chmin(ans, tmp);
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 6548
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
map<int,int> m;
int fun(int n)
{
    int flag=0;
    m[n]--;
    for(int i=1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            int one=i;
            int two=n/i;
            //cout<<one<<" "<<two<<endl;
            if((m[one]>0))
                flag=1;
            if((m[two]>0))
                flag=1;
        }
    }
    m[n]++;
    if(flag)
    {
        //cout<<"hey"<<endl;
        return 0;
    }
    return 1;
}
int main()
{
    int  n,ar[200007];
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        int val;
        scanf("%d",&val);
        m[val]++;
        ar[i]=val;
    }
    int mh=0;
    for(int i=1; i<=n; i++)
    {
        mh=mh+fun(ar[i]);
    }
    printf("%d\n",mh);
    return 0;
}


Measured memory_bytes: 33380
#include<iostream> 
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    int flag=1,k=0;
    for(int i=0;i<l;i++)
        if(s[i]!='A'&&s[i]!='C')
    {
        if(s[i]<'a'||s[i]>'z')
        {
            flag=0;
        }
    }
    for(int i=2;i<l-1;i++)
    {
        if(s[i]=='C')
        {
            k++;
        }
    }
    if(k!=1)
        flag=0;
    if(s[0]!='A')
        flag=0;
    if(flag)
        cout<<"AC"<<endl;
    else
        cout<<"WA"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	long long N;
	vector<long long> NN;
	cin >> N;
	
	for (long long i = 1; i <= sqrt(N); i++) {
		if (N%i == 0) {
			NN.push_back(i + (N / i) - 2);
		}
	}
	sort(NN.begin(), NN.end());
	cout << NN[0] << endl;
}

Measured memory_bytes: 256
sx,sy,tx,ty=gets.split.map &:to_i
y=ty-sy
x=tx-sx
y.times{print("U")}
x.times{print("R")}
y.times{print("D")}
x.times{print("L")}
print("L")
(y+1).times{print("U")}
x.times{print("R")}
print("RDRD")
y.times{print("D")}
x.times{print("L")}
print("LU\n")


Measured memory_bytes: 1788
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
N = int(sys.stdin.readline())

for s in str(N):
    if s == "9":
        print("Yes")
        exit()

print("No")


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

int main(){
  char b;
  cin >> b;
  if(b == 'A') cout << "T" << endl;
  else if(b == 'T') cout << "A" << endl;
  else if(b == 'C') cout << "G" << endl;
  else cout << "C" << endl;
  return 0;
}

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

using namespace std;

int main() {
    int R, G, B;
    cin >> R >> G >> B;

    int x = R*100+G*10+B;
    if(x % 4){
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

vector<mint> prods(int x){
  vector<mint> res(x+1);
  res[0]=1;
  for(int i=1; i<=x; i++)res[i]=res[i-1]*i;
  return res;
}

vector<mint> p;//p=prods(MAX_n)
mint comb(int a,int b){
  if(b<0||b>a)return 0;
  return p[a]/p[b]/p[a-b];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
    p=prods(r2+c2+2);
    mint ans = comb(r2+c2+2,r2+1)-comb(r2+c1+1,c1)-comb(c2+r1+1,r1)+comb(r1+c1,r1);
    cout<<ans.x<<endl;
    return 0;
}

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

#define pb push_back
#define fst first
#define snd second
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
using namespace std;

const int MAXN = 1e5+10;
int a[MAXN];
ll dp[MAXN];
int n,k;

ll solve(int i){
    if(i == n-1) return 0;
    ll &r = dp[i];
    if(r != 1e16+10) return r;
    fore(j, 1, k+1){
        if(i+j<n){
            r = min(r, abs(a[i]-a[i+j])+solve(i+j));
        }
    }

    return r;
}

int main() {FIN;
    cin>>n>>k;
    fore(i,0,n){
        cin>>a[i];
        dp[i] = 1e16+10;
    }
    cout<<solve(0)<<"\n";
    return 0;
}



Measured memory_bytes: 6144
#include<stdio.h>
#include<string.h>
int main()
{
	int n,i,k;
	char s[100005];
	scanf("%s",&s);
	k=strlen(s);
	n=1;
	for(i=0;i<k-1;i++)
	{
		if(s[i]!=s[i+1])
		  n++;
	}
	printf("%d\n",n-1);
	return 0;
}

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

int main()
{
  ll H,N;cin>>H>>N;
  vector<ll> A(N+1);
  ll sum=0;
  for (ll i=1;i<=N;i++)
  {
    cin>>A[i];
    sum+=A[i];
  }
  if (sum >= H)
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b)print("Yes");
	else print("No");




	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)

using namespace std;

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




int main()
{
	int n; cin >> n;
	vector<int> v(n);

	REP(i, n)cin >> v[i];

	sort(ALL(v));
	if (v[0] == v[2])
	{
		cout << "Impossible" << endl;
		return 0;
	}

	int cou = 0;
	int now = v[0];
	REP(i, n)
	{
		if (now == v[i])
		{
			cou++;
		}
		else
		{
			if ((i > 1 && cou < 2) || now + 1 != v[i])
			{
				cout << "Impossible" << endl;
				return 0;
			}
			cou = 1;
			now = v[i];
		}
	}

	if (cou == 1)
	{
		cout << "Impossible" << endl;
		return 0;
	}
	else
	{
		if (v[0] == v[1])
		{
			if (v[0] * 2 - 1 == v[v.size() - 1])
			{
				cout << "Possible" << endl;
				return 0;
			}

		}
		else
		{
			if (v[0] * 2 == v[v.size() - 1])
			{
				cout << "Possible" << endl;
				return 0;
			}
		}
	}

	cout << "Impossible" << endl;



	return 0;
}


Measured memory_bytes: 256
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,dp[5][1<<15];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	rep(i,5)dp[i][0] = 1;
	rep2(s,1,INF){
		if(s*s >= 1<<15)break;
		rep(i,4)rep(j,1<<15){
			if(j+s*s >= 1<<15)break;
			dp[i+1][j+s*s] += dp[i][j];
		}
	}
	while(cin>>n && n)cout<<dp[4][n]<<endl;
}

Measured memory_bytes: 1704
n, m = map(int, input().split())
edges = [[] for i in range(n)]
# es=[]
for i in range(m):
    # es.append(tuple(map(int, input().split())))
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((b, i))
    edges[b].append((a, i))

def rec(now, i):
    seen[now] = True
    for e in edges[now]:
        if e[1] == i:
            continue
        if seen[e[0]]:
            continue
        rec(e[0], i)


ans = 0
for i in range(m):
    seen = [False for i in range(n)]
    rec(0, i)
    if False in seen:
        ans += 1

print(ans)


Measured memory_bytes: 3064
import numpy as np

N,Q = map(int, input().split())
S = input()
t = [0]* (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1]-t[l-1])

Measured memory_bytes: 18696
#include<iostream>
#include<algorithm>

int main() {
	int N, M, X, Y, xi{ -100 }, yi{100};
	std::cin >> N >> M >> X >> Y;
	
	for (int i{}; i < N; i++) {
		int x{}; std::cin >> x;
		xi = std::max(xi, x);
	}

	for (int i{}; i < M; i++) {
		int y{}; std::cin >> y;
		yi = std::min(yi, y);
	}

	auto b = xi <= yi && (std::min(Y, yi) - std::max(X, xi)) > 0;
	std::cout << (!b ? "War" : "No War") << "\n";

	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> h(n), dp(n);
  for(int i = 0; i < n; i++)
    cin >> h.at(i);
  dp[1] = abs(h[1] - h[0]);
  for(int i = 2; i < n; i++)
    dp[i] =
        min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  cout << dp[n - 1] << '\n';
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_149
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            long[] rsp = ReadLongs();
            string s = Read();
            long[,] dp = new long[n, 3];
            var dict = new Dictionary<char, int>();
            dict.Add('r', 0);
            dict.Add('s', 1);
            dict.Add('p', 2);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    long score = 0;
                    if ((j + 1) % 3 == dict[s[i]]) score += rsp[j];
                    if (i - k >= 0)
                    {
                        score += Max(dp[i - k, (j + 1) % 3], dp[i - k, (j + 2) % 3]);
                    }
                    dp[i, j] = score;
                }
            }
            long res = 0;
            for (int i = 0; i < k; i++)
            {
                res += Max(Max(dp[n - 1 - i, 0], dp[n - 1 - i, 1]), dp[n - 1 - i, 2]);
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  
  int ans = 0;
  
  while (true) {
    int M = 0;
    for (int i = 0; i < N; i++) M = max(M, H.at(i));
    if (M == 0) break;
    else {
      if (H.at(0) == M) ans++;
      for (int i = 0; i < N; i++) {
        if (H.at(i) == M) H.at(i) -= 1;
        else if (i < N - 1 && H.at(i + 1) == M) ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    string s;
    cin>>s;
    if(s == "ABC")cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   int N, K; cin >> N >> K;
   vector<int> p(N);
   rep(i, 0, N) cin >> p.at(i);

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

   int ans = 0;
   rep(i, 0, K) ans += p.at(i);

   cout << ans << endl;
 }


Measured memory_bytes: 3624
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
--import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Double
  as <- map read.words <$> getLine :: IO [Double]
  print $ product as / sum [ product as / a | a <- as]


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

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

using namespace std;
typedef int Weight;
Weight INF = 1000000000;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Weight weight) {
  g[src].push_back((Edge){src, dest, weight});
  g[dest].push_back((Edge){dest, src, weight});
}

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    Graph g(n);
    vector<int> to(n-1);
    REP(i,n-1) {
      cin>>to[i];
      --to[i];
    }
    REP(i,n-1){
      int c;
      cin>>c;
      add_edge(g,i+1,to[i],c);
    }
    int sum = 0;
    int lpath = 0;
    REP(i,n) {
      if (g[i].size() > 1) {
        for (auto e:g[i]) sum += 3*e.weight;
        Array a(n);
        dijkstra(g,a,i);
        REP(j,n) if (g[j].size() > 1) lpath = max(lpath, a[j]);
      } else {
        for (auto e:g[i]) sum -= e.weight;
      }
    }
    cout << (sum / 2 - lpath) << endl;
  }
  return 0;
}

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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main(){
    long x;
    cin >> x;
    long now=100;
    long cnt=0;
    while(now<x){
        cnt++;
        now += (long)(now * 0.01);
    }
    cout << cnt << endl;
    return 0;
}

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

int h1, m1, h2, m2, k;

int main(){
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	m1+=h1*60;
	m2+=h2*60;
	cout << (m2-m1)-k << "\n";
}

Measured memory_bytes: 3620
moji = input()
l = len(moji)
if moji.find('k') == 0 and moji.rfind("eyence") == l-6 :
    print("YES")
elif moji.find('ke') == 0 and moji.rfind("yence") == l-5 :
    print("YES")
elif moji.find('key') == 0 and moji.rfind("ence") == l-4 :
    print("YES")
elif moji.find('keye') == 0 and moji.rfind("nce") == l-3 :
    print("YES")
elif moji.find('keyen') == 0 and moji.rfind("ce") == l-2 :
    print("YES")
elif moji.find('keyenc') == 0 and moji.rfind("e") == l-1 :
    print("YES")
elif moji.find("keyence") == 0 or moji.find("keyence") == l-7:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define For(i,a,b) for(int i = a;i < b;i++)
#define all(n) n.begin(),n.end()

const int dx[6] = { 0,1,1,0,-1,-1 }, dy[6] = { 1,1,0,-1,-1,0 };

int main() {
	int t, n;
	while (cin >> t >> n && t) {
		map<int, map<int, int>> m;
		map<int, map<int, int>> a;
		rep(i, n) {
			int x, y;
			cin >> x >> y;
			m[x][y] = 1;
		}
		int sx, sy;
		cin >> sx >> sy;
		typedef pair<int, int> P;
		queue<P> q;
		q.push(P(sx, sy));
		a[sx][sy] = 1;

		while (q.size()) {
			int x = q.front().first;
			int y = q.front().second;
			q.pop();
			rep(i, 6) {
				int tx = x + dx[i], ty = y + dy[i];
				if (m[tx][ty] == 0 && a[tx][ty] == 0) {
					if (a[x][y] <= t) {
						a[tx][ty] = a[x][y] + 1;
						q.push(P(tx, ty));
					}
				}
			}
		}
		int ans = 0;
		for (auto vp : a) {
			for (auto p : vp.second) {
				if (p.second) {
					ans += 1;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3360
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int l = 1001;
		int r = -1;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			l = Math.min(l, a);
			r = Math.max(r, a);
		}
		
		System.out.println(r - l);
		sc.close();
	}
}




Measured memory_bytes: 27056
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef tuple<int, int, int> T;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string s;

int num[3][4010]; // 0->R, 1->G, 2->B

ll solve() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            num[j][i+1] = num[j][i];
        }
        switch(s[i]) {
        case 'R': num[0][i+1]++; break;
        case 'G': num[1][i+1]++; break;
        case 'B': num[2][i+1]++; break;
        }
    }

    ll res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (s[i] == s[j]) continue;
            if ((s[i] == 'R' && s[j] == 'G') || (s[j] == 'R' && s[i] == 'G')) {
                res += num[2][n] - num[2][j];
                if (j + j - i < n && s[j+j-i] == 'B') res--;
            } else if ((s[i] == 'B' && s[j] == 'G') || (s[j] == 'B' && s[i] == 'G')) {
                res += num[0][n] - num[0][j];
                if (j + j - i < n && s[j+j-i] == 'R') res--;
            } else {
                res += num[1][n] - num[1][j];
                if (j + j - i < n && s[j+j-i] == 'G') res--;
            }
        }
    }
    return res;
}

void input() {
    cin >> n >> s;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3188
#include <stdio.h>

int BinarySearch(int, int, int*);


int main(){

  int n,q,i,s;
  int S[1000000];
  int count = 0;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&s);
    if(BinarySearch(s,n,S) == 0){
      count++;
    }
  }

  printf("%d\n",count);

  return 0;
}


int BinarySearch(int key,int n,int S[]){

  int l=0,m,r;

  r = n;

  while(l < r){
    m = (r + l)/2;

    if(S[m] == key)return 0;

    else if(S[m] > key)r = m;

    else l = m+1;
  }

  return 1;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
const long double pi=acosl(-1);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    vector<int> x(2),y(2);
    for (int i=0;i<2;++i) cin >> x[i] >> y[i];
    bool flag=false;
    if (x[0]>x[1]) swap(x[0],x[1]),swap(y[0],y[1]);
    if (y[0]>y[1]){
        y[0]*=-1,y[1]*=-1;
        flag=true;
    }
    int N; cin >> N;
    vector<pair<int,int>> f;
    for (int i=0;i<N;++i){
        int X,Y; cin >> X >> Y;
        if (flag) Y*=-1;
        if (X<x[0]||x[1]<X||Y<y[0]||y[1]<Y) continue;
        f.emplace_back(X,Y);
    }
    sort(f.begin(),f.end());
    int n=f.size();
    vector<int> dp(n,INF);
    for (int i=0;i<n;++i){
        auto itr=lower_bound(dp.begin(),dp.end(),f[i].second);
        *itr=f[i].second;
    }
    int cnt=lower_bound(dp.begin(),dp.end(),INF)-dp.begin();
    long double ans=(long long)100*((x[1]-x[0])+(y[1]-y[0]))-20*cnt+5*pi*cnt;
    if (cnt==min(x[1]-x[0],y[1]-y[0])+1) ans+=5*pi;
    cout << ans << '\n';
}

Measured memory_bytes: 2672
n = int(input())
w = list(map(int,input().split()))
# print(w)

l = []
for i in range(n):
    t = i+1
    s1 = sum(w[:t])
    s2 = sum(w) - s1
    # print(t,s1,s2)
    l.append(abs(s1-s2))
print(min(l))



Measured memory_bytes: 38384
<?php

list($n) = explode(' ', trim(fgets(STDIN)));

$goods = [];
for ($i = 0; $i  < $n; ++$i) {
    list($s) = explode(' ', trim(fgets(STDIN))); 
    $goods[] = $s;
}

$goods = array_unique($goods);
echo count($goods);


Measured memory_bytes: 45328
# coding: utf-8
# Here your code !

def func():
    result=""
    try:
        line = input().rstrip()
        num = int(line)
    except:
        print("input error")
        return -1
        
    for i in range(1,num+1):
        if(i % 3 ==0):
            result += " "+str(i)
        else:
            devided=i
            while(True):
                if(devided % 10 == 3):
                    result += " "+str(i)
                    break
                elif(devided > 9):
                    devided = devided // 10
                else:
                    break
                
    print(result)

func()

Measured memory_bytes: 7692
import heapq
Q = int(input())

# 中央値の左側の値、右側の値を管理する
# heapqとする。rightは最小が興味あるが、leftは最大なので、-1をかけて扱う
left, right = [], []
# 両方のSUMも管理する必要がある。毎回SUMしてたら間に合わん
Lsum, Rsum = 0,0
Lcnt, Rcnt = 0,0
B = 0
for _ in range(Q):
  q = list(map(int, input().split()))
  if len(q) == 1:
    # 2
    # heapqってPeakできないの・・・？
    l = (-1) *left[0]
    #l = (-1) * heapq.heappop(left)
    #heapq.heappush(left,(-1)*l)
    # (l-l1) + (l-l2) + ... + (l-l) + (r-l) + ... + (r1 - l)
    print(l, Rsum//2 - Lsum//2 + B)
    #print(left,right, Lsum, Rsum)
  else:
    # 1
    _,a,b = q
    B += b
    # まず双方にaを突っ込む
    heapq.heappush(left,(-1)*a)
    heapq.heappush(right,a)
    Lsum += a
    Lcnt += 1
    Rsum += a
    Rcnt += 1
    # leftの最大値と、rightの最小値の関係が崩れていたら、交換する
    l = (-1)*left[0]
    r = right[0]
    #l = (-1) * heapq.heappop(left)
    #r = heapq.heappop(right)
    if l>=r:
      Lsum = Lsum - l + r
      Rsum = Rsum - r + l
      l,r = r,l
    _ = heapq.heappop(left)
    _ = heapq.heappop(right)
    heapq.heappush(left,(-1)*l)
    heapq.heappush(right,r)


Measured memory_bytes: 24920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;
typedef long long ll;
#define INF ((ll)1e18)

int N;
ll a[(int)3e5];
ll lmax[(int)(1e5+1)];
ll rmin[(int)(1e5+1)];

int main(){
    cin >> N;
    for(int n=0; n<3*N; n++){
        cin >> a[n];
    }
    
    priority_queue<ll,vector<ll>,greater<ll> > que;
    lmax[0]=0;
    for(int i=0; i<N; i++){
        lmax[0] += a[i];
        que.push(a[i]);
    }
    for(int i=1; i<=N; i++){
        que.push(a[N+i-1]);
        lmax[i] = lmax[i-1] - que.top() + a[N+i-1];
        que.pop();
    }
    for(int i=0; i<=N; i++){
        cerr << i << ": " << lmax[i] << endl;
    }
    
    priority_queue<ll> que2;
    rmin[0]=0;
    for(int i=0; i<N; i++){
        rmin[0] += a[3*N-1-i];
        que2.push(a[3*N-1-i]);
    }
    for(int i=1; i<=N; i++){
        que2.push(a[2*N-i]);
        rmin[i] = rmin[i-1] - que2.top() + a[2*N-i];
        que2.pop();
    }
    for(int i=0; i<=N; i++){
        cerr << i << ": " << rmin[i] << endl;
    }
    
    ll res = -INF;
    for(int i=0; i<=N; i++){
        ll tmp;
        tmp = lmax[i] - rmin[N-i];
        if(tmp>res) res=tmp;
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 5876
using System;
class atcoder
{
	public static void Main()
	{
		int s = 0;
		int x = int.Parse(Console.ReadLine());
		for (int i = 1; i < x + 1; i++)
		{
			s += i;
            if (s >= x)
			{
				Console.WriteLine(i);
				break;
			}
		}
	}
}

Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{
    public class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();
            var ls = s.Length;
            var lt = t.Length;

            var matchMax = 0;

            for (int ts = 0; ts < ls - lt + 1; ts++)
            {
                var cnt = 0;
                for (int n = 0; n < lt; n++)
                {
                    if (s[ts + n] == t[n])
                    {
                        cnt++;
                    }
                }
                matchMax = Math.Max(matchMax, cnt);
            }

            Console.WriteLine(lt - matchMax);



        }
    }
}



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

const int maxn = 1e6 + 1;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int tc = 1;
    // cin >> tc;
    while(tc--) {
        int n;
        cin >> n;
        vector<int> freq(maxn, 0);
        vector<int> a(n);
        for(int i=0; i<n; i++) {
            cin >> a[i];
            freq[a[i]]++;
        }
        
        int res = 0;
        for(int i=0; i<n; i++) {
            bool good = (freq[a[i]] == 1);
            for(int j=2; j*j <= a[i] && good; j++) {
                if(a[i] % j == 0) {
                    good = !(freq[j] || freq[a[i] / j]);
                }
            }
            if(good) res++;
        }
        
        if(freq[1] == 1) res = 1;
        else if(freq[1] > 1) res = 0;
        
        cout << res << endl;
    }
    
    return 0;
}

Measured memory_bytes: 7932
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

const int INF = 1e9 + 7;

struct Tree {
	int val, l, r;
	Tree *left = NULL, *right = NULL;
	
	Tree(vi &vec, int _l, int _r) {
		if(_l == _r) {
			val = vec[_l], l = _l, r = _r;
			return;
		}
		
		l = _l, r = _r;
		
		int mid = (l + r) / 2;
		
		left = new Tree(vec, l, mid);
		right = new Tree(vec, mid + 1, r);
		
		val = min(left->val, right->val);
	}
	
	int getVal(int _l, int _r) {
		if (_r < l || _l > r) 
			return INF;
			
		if(_l <= l && r <= _r)
			return val;
			
		return min(
			left->getVal(_l, _r), 
			right->getVal(_l, _r));
	}
	
};

int N, L; vi V;

int main() {
	scanf("%d %d", &N, &L);
	V.assign(N, 0);
	
	for(int i=0;i<N;i++)
		scanf("%d", &V[i]);
		
	Tree* t = new Tree(V, 0, N - 1);
	
	for(int i=L-1;i<N;i++) {
		int ans = t->getVal(i - L + 1, i);		
		printf("%d%s", ans, i < N - 1 ? " " : "\n");
	}
}



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

typedef long long ll;
typedef unsigned long long ull;
const int MOD=1000000007;

int main(){
    int N,K;
    cin >> N >> K;
    ll x[100001];
    for(int i=0;i<N;i++){
        cin >> x[i];
    }
    sort(x,x+N);
    ll ans=INT64_MAX;
    for(int i=0;i<N-K+1;i++){
        ll l=x[i],r=x[i+K-1];
        ll s;
        if(l*r>=0) s=max(abs(l),abs(r));
        else s=min(abs(l),abs(r))+(r-l);
        ans=min(ans,s);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int main(){
    char *v1 = malloc(5 * sizeof(char)), *v2 = malloc(7 * sizeof(char)), *v3 = malloc(5 * sizeof(char));
    scanf("%5[^,],%7[^,],%5[^,]", v1, v2, v3);
    printf("%s %s %s\n", v1, v2, v3);
    free(v1);
    free(v2);
    free(v3);
    return 0;
}

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

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

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

	int n; cin >> n;

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

	sort(a,a+n);
	cout << sum-a[n-1]/2 << endl;

	return 0;

}


Measured memory_bytes: 256
from collections import defaultdict
d = defaultdict(int)
H, W = map(int, input().split())
L = []
for i in range(H):
    L.append(input())
cl = L[:]

al = []
for i in cl:
    if ('#' in i):
        al.append(i)

if (len(al) == 0):
    print()
    exit()

for i in range(W):
    d[i] = True

for i, v in enumerate(al):
    for k, j in enumerate(v):
        if (j == '.'):
            continue
        else:
            d[k] = False
for i, v in d.items():
    if (v):
        for j, k in enumerate(al):
            if (i == 0):
                al[j] = ' ' + k[1:]
            elif ((i == W - 1) and (W != 1)):
                al[j] = k[:i] + ' '
            else:
                al[j] = k[:i] + ' ' + k[i + 1:]
for i in al:
    print(i.replace(' ', ''))


Measured memory_bytes: 3436
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		}
		int swapCount = 0;
		for(int index = 0; index < n; index++) {
			int minj = index;
			for(int j = index; j < n; j++) {
				if(nums[j] < nums[minj]) {
					minj = j;
				}
			}
			if(index != minj) {
				swapCount++;
			}
			int work = nums[index];
			nums[index] = nums[minj];
			nums[minj] = work;
		}
		printArray(nums);
		System.out.println(swapCount);
	}
	public static void printArray(int[] array) {
		int arrayLength = array.length;
		for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		}
		System.out.println(array[arrayLength - 1]);
	}
}

Measured memory_bytes: 26504
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int len[128];
int dp[2][1<<16];
char str[128][17];
int L[16][1<<16];
int R[16][1<<16];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%s",str[i]);
		len[i]=strlen(str[i]);
	}
	for(int i=0;i<b;i++){
		for(int j=0;j<(1<<b);j++){
			for(int k=0;k<b;k++)
				if(j&(1<<k)){
					if(k<i)L[i][j]++;
					else R[i][j]++;
				}
		}
	}
	int u=0;
	int mask=(1<<b)-1;
	int inf=99999999;
	for(int i=1;i<(1<<b);i++)dp[u][i]=-inf;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			for(int k=0;k<(1<<b);k++)dp[!u][k]=-inf;
			for(int k=0;k<(1<<b);k++){
				if(len[i]<L[j][k])continue;
				if(len[i]>L[j][k]+b-j)continue;
				if(len[i]>L[j][k]){
					int A=0;
					if(j&&(k&1)&&(str[i][L[j][k]]==str[i][L[j][k]-1]))A++;
					if(i&&(k&(1<<b-1))&&(str[i-1][len[i-1]-R[j][k]]==str[i][L[j][k]]))A++;
					dp[!u][(k*2+1)&mask]=max(dp[!u][(k*2+1)&mask],dp[u][k]+A);
				}
				if(len[i]<L[j][k]+b-j){
					dp[!u][(k*2)&mask]=max(dp[!u][(k*2)&mask],dp[u][k]);
				}
			}
			u=!u;
		}
	}
	int ret=0;
	for(int i=0;i<(1<<b);i++)
		ret=max(ret,dp[u][i]);
	printf("%d\n",ret*2);
}
/*
   INTERNATIONAL
C O LLEGIATE
PROGRAMMING
C O      NTEST
*/

Measured memory_bytes: 9740