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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<double, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}


bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

struct Circle {
    double x, y, r;
};

std::istream &operator>>(std::istream &in, Circle &o) {
    in >> o.x >> o.y >> o.r;
    return in;
}

struct Edge {
    ll to;
    double cost;
};


class Dijkstra {
    ll vector_count;

    vector<double> distances;
    vector<vector<Edge>> edges;

public:
    Dijkstra(ll n) {
        vector_count = n;
        distances.resize(n, INF);
        edges.resize(n);
    }

    void insertTowWay(ll from, ll to, double cost) {
        edges[from].push_back({to, cost});
        edges[to].push_back({from, cost});
    }

    void insert(ll from, ll to, double cost) {
        edges[from].push_back({to, cost});
    }

    void dijkstra(ll k) {
        distances[k] = 0;  // 始点sへの最短距離は0

        priority_queue<P, vector<P>, greater<P>> que;  // 距離が小さい順に取り出せるようgreater<P>を指定
        que.push(P(0, k));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
            if (distances[v] < p.first) {
                continue;
            }
            for (auto e : edges[v]) {  // 頂点vから出る辺eを走査
                if (distances[e.to] > distances[v] + e.cost) {
                    distances[e.to] = distances[v] + e.cost;
                    que.push(P(distances[e.to], e.to));
                }
            }
        }
    }

    double distance(ll to) {
        return distances[to];
    }

};


int main() {

    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;


    int n;
    cin >> n;

    vector<Circle> v(n);
    rep(i, n) cin >> v[i];

    n += 2;
    v.push_back({x1, y1, 0});
    v.push_back({x2, y2, 0});

    Dijkstra dijkstra(n);

    rep(i, n) {
        rep(j, n) {
            if (i >= j) continue;

            Circle a = v[i], b = v[j];

            double x = a.x - b.x;
            double y = a.y - b.y;
            double xx = x * x;
            double yy = y * y;
            double sq = sqrt(xx + yy);

            double d = max<double>(sq - a.r - b.r, 0);

            dijkstra.insertTowWay(i, j, d);
        }
    }
    dijkstra.dijkstra(n - 1);
    double ans = dijkstra.distance(n - 2);
    cout << setprecision(20) << ans << endl;


}

Measured memory_bytes: 23888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
using G = vector<vector<int>>;
const long long INF = 1LL << 60;

int main(){
int n,r;
cin >> n >> r;
if(n <10){
  r+=100*(10-n);
}
cout << r << endl;

}  

Measured memory_bytes: 768
a,b,c,d=input()
a,b,c,d=int(a),int(b),int(c),int(d)
for op1 in ['+','-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if op1=='+':
                if op2=='+':
                    if op3=='+':
                        num = a+b+c+d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                    else:
                        num = a+b+c-d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                else:
                    if op3=='+':
                        num = a+b-c+d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                    else:
                        num = a+b-c-d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
            else:
                if op2=='+':
                    if op3=='+':
                        num = a-b+c+d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                    else:
                        num = a-b+c-d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                else:
                    if op3=='+':
                        num = a-b-c+d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()
                    else:
                        num = a-b-c-d
                        if num==7:
                            print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+'='+'7')
                            exit()

Measured memory_bytes: 3192
//ABC 153 E kmjp
#include <bits/stdc++.h>
using namespace std;

typedef signed long long ll;

int H,N;
int A[10101],B[101010];
ll dp[20100];

void solve() {
	int i,j,k,l,r,x,y; 
	
	cin>>H>>N;
	
	for(i=0; i<20001; ++i) 
	   dp[i]=1LL<<60;
	
	dp[0]=0;
	
	for(i=0; i<N; ++i) {
		cin>>x>>y;    //Ai, Bi 
		for(j=0; j<H; ++j) 
		   dp[j+x] = min(dp[j+x],dp[j]+y);
	}
	
	ll mi=1LL<<60;
	
	for(i=H;i<=20000;i++) 
	   mi=min(mi,dp[i]);
	
	cout<<mi<<endl;	
}

int main(){
	int i;
	
	ios::sync_with_stdio(false), cin.tie(0);
	
	solve(); 
    
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
int n, m;
char p[101000], q[101000];
int gcd(int a, int b) {
	return b ? gcd(b, a%b) : a;
}
int main() {
	int i;
	scanf("%d%d", &n, &m);
	scanf("%s%s", p, q);
	int g = gcd(n, m);
	for (i = 0; i < n; i++) {
		if (i % (n / g) == 0) {
			if (p[i] != q[i / (n / g) * (m / g)]) {
				puts("-1");
				return 0;
			}
		}
	}
	printf("%lld\n", 1ll * n*m / g);
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

int f(int n2, int n1, int m2, int m1,bool flag){
//    cout<<n2<<" "<<n1<<" "<<m2<<" "<<m1<<endl;
    if( (2*m2+m1)-(n2+n1)<=0 )return 0;
    
    if(flag){
        int atkm2 = min(m2,(n2+n1));
        m2 = max<ll>(0,m2-(n2+n1));
        m1 += atkm2;
        m1 = m1-(n2+n1-atkm2);
        assert(m1>0);
        return f(m2,m1,n2,n1,!flag)+1;
    }else{
        int atkm1 = min(m1,(n2+n1));
        m1 = max<ll>(0,m1-(n2+n1));
        int less = n2+n1-atkm1;
        m2 -= less/2;
        m2 -=less%2;
        m1 += less%2;
        assert(m1+m2>0);
        return f(m2,m1,n2,n1,!flag)+1;
    }
}


//int f(int n, int nd, int m, int md){
//    //    cout<<nd<<" "<<md<<endl;
//    int ndd = md-min(nd,n);
//    int mdd = nd;
//    if(ndd>0)return f(m,ndd,n,mdd)+1;
//    else return 0;
//}


signed main(){
    int n,m;
    cin>>n>>m;
    cout<<min(f(n,0,m,0,0),f(n,0,m,0,1))<<endl;
}




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

int main(int argc, char* pArgv[])
{
  int n = 0;
  std::cin >> n;

  auto result = (n % 2 == 0) ? n / 2 : n / 2 + 1;
  std::cout << result << std::endl;

  return 0;
}



Measured memory_bytes: 256
x,n = map(int, input().split())
p = [False] * 110
line = list(map(int, input().split()))
for i in range(n):
    p[line[i]] = True

ans = 0
a = 10000
for i in range(110):
    if p[i]:
        continue

    ai = abs(i - x)
    if ai < a:
        a = ai
        ans = i

print(ans)


Measured memory_bytes: 9188
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0]);
    var K = Number(lines[0].split(" ")[1]);
    lines.shift();

    var h = lines.map(value => Number(value));

    // 昇順ソート
    h.sort((a, b) => a - b);

    var result = Infinity;

    for (var i = 0; i < h.length; i++) {
        if (result > h[i + K - 1] - h[i]) { result = h[i + K - 1] - h[i]; }
    }
    console.log(result);
});

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

using namespace std;

const int len = 100010;
char s[len];

int main() {
	ios :: sync_with_stdio(0);
	cin >> s;
	for (int i=0;i<strlen(s);i++) {
		if (i%2 == 0) cout << s[i];
	}
	return 0;
}

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

int main(){
	int str[30];
	int w, n, i;
	int a, b;
	int t;

	cin >> w;
	cin >> n;

	for (i = 0; i < 30; i++){
		str[i] = i + 1;
	}

	for (i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);
		
		t = str[a - 1];
		str[a - 1] = str[b - 1];
		str[b - 1] = t;
	}
	for (i = 0; i < w; i++){
		cout << str[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 1240
from collections import deque
def myAnswer(S:deque,Q:int,querys:list) -> str:
   setF = {1,2}
   reverse = False
   for query in querys:
      command = int(query[0])
      if(command == 1):
         reverse = not reverse
      else:
         F = int(query[1])
         C = query[2]
         if(reverse):
            F = set(setF - {F}).pop()
         S.appendleft(C) if(F == 1) else S.append(C)

   if(reverse):S.reverse()
   return "".join(S)

def modelAnswer():
   return
def main():
   S = deque(input())
   Q = int(input())
   querys = [list(map(str,input().split())) for _ in range(Q)]
   print(myAnswer(S,Q,querys))



if __name__ == '__main__':
   main()

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n;
    cin >> n;
    cout << (n-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

int main(){
    int n,r=0,rta=0;
    string s;
    cin >> n;
    cin >> s;
    for(int i=0;i<n;i++){
        if(s[i]=='R') r++;
    }
    for(int i=0;i<r;i++){
        if(s[i]!='R') rta++;
    }
    cout << rta << endl;
    return 0;
}


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

//最大値を求める関数 //templateで宣言しているので，渡す値はどんな型でもOK
//aよりbが大きかったらaにbを代入
template<class T> inline bool chmax(T& a, T b){//アドレスで渡しているので，aだけ値が変わる?
if (a < b) { a = b; return 1; }
return 0;
}

//最大公約数を求める関数 //入れ子になっているので，ユークリッドの互除法．//大小が逆でも一回増えるだけ
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main() {
  // input
  int N; cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i<N; ++i) cin >> a[i];

  //方法1 //解説通りの定義とやり方．
  // 累積 GCD (左と右両方)
  vector<int> left(N+1, 0), right(N+1, 0);
  for (int i = 0; i < N; ++i) left[i+1] = GCD(left[i], a[i]);
  for (int i = N-1; i >= 0; --i) right[i] = GCD(right[i+1], a[i]);
  
  // 集計
  int res = 0;
  for (int i = 0; i < N; ++i) {
    // 左側
    int l = left[i]; 
    // 右側
    int r = right[i+1]; 
    // 更新
    chmax(res, GCD(l, r));
  }
  cout << res << endl;

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int l[N], r[N], f[N][3];
char s[N];
int solve(vector<int> a) {
	int i = 0;
	f[0][0] = -1e9;
	for (int x : a) {
		i ++;
		if (x == 1) {
			f[i][0] = f[i - 1][1];
			f[i][1] = max(f[i][0], f[i - 1][2]);
			f[i][2] = max(max(f[i][1], f[i][0]), f[i - 1][1] + 1);
		}
		else {
			f[i][0] = max(f[i - 1][2], f[i - 1][0] + x - 1);
			f[i][1] = max(max(f[i][0], f[i - 1][2]), f[i - 1][0] + x);
			f[i][2] = max(max(max(f[i][0], f[i][1]), f[i - 1][1] + x), f[i - 1][2] + x - 1);
		}
	}
	return f[i][1];
}
int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; ++ i) l[i] = s[i] == '1' ? l[i - 1] + 1 : 0;
	for (int i = n; i >= 1; -- i) r[i] = s[i] == '1' ? r[i + 1] + 1 : 0;
	vector<int> a;
	int ans = 0;
	for (int i = 2; i < n; ++ i) {
		if (s[i] == '0' && s[i - 1] == '1' && s[i + 1] == '1') {
			if (a.empty()) a.push_back(l[i - 1]);
			a.push_back(r[i + 1]);
		}
		else if (s[i] == '0') {
			if (!a.empty()) ans += solve(a);
			a.clear();
		}
	}
	if (!a.empty()) ans += solve(a);
	printf("%d\n", ans);
}


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

int N;
int A[101];

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

	int cont1 = 0;
	int ans = 0;
	for(int i = 0; i < N; i++){
		if(A[i] == 1){
			cont1++;
		}
		else{
			ans = max(ans,cont1);
			cont1 = 0;
		}
	}
	ans = max(ans,cont1);

	cout << ans + 1 << endl;

	return 0;
}



Measured memory_bytes: 3108
#include "bits/stdc++.h"

using namespace std;

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

    int ans = X;
    for (int i = 0; i < N; ++i) {
        // A_i * x + 1 <= D
        ans += (D - 1) / A[i] + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
N, M = map(int,input().split())
graph = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a) #双方向

visited = [False]*N
visited[0] = True
ans = [0]*N
D = deque([0])
while D:
    v = D.popleft()
    for i in graph[v]:
        if visited[i]:
            continue
        visited[i] = True #一度通ったことを伝える
        ans[i] = v+1
        D.append(i)

print('Yes')
for i in range(1,N):
    print(ans[i])


Measured memory_bytes: 37852
#include <iostream>
using namespace std;
int main(void){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    while (A >= B) {
        B *= 2;
        K--;
    }
    while (B >= C) {
        C *= 2;
        K--;
    }
    if (K >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3556
from bisect import bisect_right
import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
a_to_i = [[] for _ in range(max(A)+1)]
for i in range(N):
    a_to_i[A[i]].append(i)
next_index = [-1]*N
for i in range(N):
    a = A[i]
    j = bisect_right(a_to_i[a], i)
    if j == len(a_to_i[a]):
        next_index[i] = a_to_i[a][0]+N
    else: next_index[i] = a_to_i[a][j]
now = 0
cnt = 0
while True:
    i = next_index[now]
    if i>=N:
        i%=N
        cnt+=1
    else: now = i
    i+=1
    if i>=N:
        cnt+=1
        i%=N
    now = i
    if now == 0:
        break
K%=cnt
if K==0:
    print()
    sys.exit()
ans = [A[0]]
K*=N
K-=1
now = 0
while now<K:
    ni = next_index[now%N]+1
    if(now//N)*N+ni-1 == K:
        ans.pop()
        break
    if (now//N)*N+ni>K:
        now+=1
        ans.append(A[now%N])
    else:
        now = (now//N)*N+ni
        ans[-1] = A[now%N]




print(*ans, sep = ' ')







    


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

void solve(int a, int b, int c){
	if(a <= 30){
		cout << "HEISEI " << a << " " << b << " " << c << "\n";
	}else if(a == 31){
		if(b <= 4){
			cout << "HEISEI " << a << " " << b << " " << c << "\n";
		}else{
			cout << "? " << 1 << " " << b << " " << c << "\n";
		}
	}else{
		cout << "? " << a-30 << " " << b << " " << c << "\n";
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		string s;
		cin >> s;
		if(s == "#") return 0;
		int a, b, c;
		cin >> a >> b >> c;
		solve(a, b, c);
	}
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define N 60
#define MOD 1000000007
using namespace std;

int n,dp[N][5][5];
char s[2][N];

int dfs(int now,int bust,int balt) {

  int salt=-1,sust=-1;
  int ret=0;
  if(now>n) return 1;
  if(~dp[now][bust][balt]) return dp[now][bust][balt];
  if(s[0][now]==s[0][now-1]) sust=bust;
  if(s[1][now]==s[1][now-1]) salt=balt;
  if(s[0][now]!=s[1][now] && ~salt && ~sust && salt==sust) return dp[now][bust][balt]=0;
  for(int i=0;i<3;i++) {
    for(int j=0;j<3;j++) {
      if((~salt && i!=salt) || (~sust && j!=sust)) continue ;
      if(s[0][now]==s[1][now] && i!=j) continue ;
      if(s[0][now]!=s[1][now] && i==j) continue ;
      if(s[0][now-1]!=s[0][now] && bust==i) continue ;
      if(s[1][now-1]!=s[1][now] && balt==j) continue ;
      ret=(ret+dfs(now+1,i,j))%MOD;
    }
  }
  return dp[now][bust][balt]=ret;

}

int main() {

  memset(dp,-1,sizeof(dp));
  scanf("%d",&n);
  scanf("%s %s",s[0]+1,s[1]+1);
  int res=0;
  for(int i=0;i<3;i++) {
    for(int j=0;j<3;j++) {
      if(s[0][1]==s[1][1] && i!=j) continue ;
      if(s[0][1]!=s[1][1] && i==j) continue ;
      res=(res+dfs(2,i,j))%MOD;
    }
  }
  printf("%d",res);

}


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


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

    vector<long long> s(N);
    for (int i = 0; i < N; ++i) cin >> s[i];
  
    sort(s.begin(), s.end());
    reverse(s.begin(), s.end());

    long long sum = 0;
    for (int i = 0; i < N; ++i) sum += s[i];
    if (sum % 10 != 0) cout << sum << endl;
    else {
        for (int i = N - 1; i >= 0; --i) {
            sum -= s[i];
            if (sum % 10 != 0) {cout << sum << endl; return 0;}
            else if (sum == 0) {cout << 0 << endl; return 0;}
            else if (i == 0) {cout << 0 << endl; return 0;} 
            else {sum += s[i]; continue;}
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=1e5;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if (a+b==15) printf("+");else 
	if (a*b==15) printf("*");else printf("x");
	 
	return 0;
} 

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

int main()
{
	int n;
	int i = 1;
	int x;

	cin >> n;

	while (i <= n) {
		x = i;

		if (x % 3 == 0) {
			cout << " " << i;
		} else if (x % 10 == 3) {
			cout << " " << i;
		} else {
			x /= 10;
			while (x) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
		i++;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<cctype>

using namespace std;

int main(int argc, char* argv[])
{
  char a;
  vector<int> count(26,0);
  while(cin>>a){a=tolower(a);int num=a-'a';if(num>=0 and num<=25) count[num]++;}
  for(int i=0;i<26;i++) {char b = i+'a';cout << b << " : " <<count[i] << endl;}
}

Measured memory_bytes: 3096
x,y,z,k=map(int,input().split())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
cl=[int(i) for i in input().split()]
lst=[i+j for i in al for j in bl]
lst.sort(reverse=True)
num=min(x*y,k)
lst=lst[:num]
L=[i+j for i in cl for j in lst]
L.sort(reverse=True)
for i in range(k):
  print(L[i])

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

using namespace std;
typedef long long ll;

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>

int main(){
	int n, w;
	std::vector<int> wList;
	std::vector<int> vList;

	std::vector<std::vector<std::vector<long long>>> dpList;

	std::cin>>n>>w;

	wList.resize(n);
	vList.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>wList[i]>>vList[i];

	long long baseW= wList[0];

	dpList.resize(n+1);

	for(int i=0; i<n+1; i++){
		dpList[i].resize(n+1);

		for(int j=0; j<n+1; j++)
			dpList[i][j].resize(3*(n+1), -1);
	}

	dpList[0][0][0]= 0;

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			for(int k=0; k<3*n; k++){
				if(dpList[i][j][k]<0)
					continue;

				dpList[i+1][j][k]= std::max(dpList[i+1][j][k], dpList[i][j][k]);

				if((long long)j*baseW + (long long)k + (long long)wList[i] <=w)
					dpList[i+1][j+1][wList[i]-baseW +k]= 
						std::max(dpList[i+1][j+1][wList[i]-baseW +k], dpList[i][j][k]+ vList[i]);
			}
		}
	}

	long long ans=0;

	for(int i=0; i<n+1; i++)
		for(int j=0; j<3*(n+1); j++)
			ans= std::max(ans, dpList[n][i][j]);
	
	std::cout<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 24704
w,h,n=map(int,input().split())
x1,x2=0,w
y1,y2=0,h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x1 = max(x1,x)
    elif a==2:
        x2 = min(x2,x)
    elif a==3:
        y1 = max(y1,y)
    elif a==4:
        y2 = min(y2,y)
print(max((x2-x1)*(y2-y1),0) if x2-x1>0 else 0)

Measured memory_bytes: 38384
#include<stdio.h>
int main(void)
{
  while(1){
    int n,p=0;
    scanf("%d",&n);
    if(n==0)
      break;
    n=1000-n;
    p+=n/500;
    n=n%500;
    p+=n/100;
    n=n%100;
    p+=n/50;
    n=n%50;
    p+=n/10;
    n=n%10;
    p+=n/5;
    n=n%5;
    p+=n;
    printf("%d\n",p);
  }
  return 0;
}

Measured memory_bytes: 600
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
p=list(map(int,input().split()))
def root(x):
	if x!=parent[x]:
		x=root(parent[x])
	return x
def same (x,y):
	return root(x)==root(y)
def unite(x,y):
	rx=root(x)
	ry=root(y)
	if rank[rx]<rank[ry]:
		parent[rx]=ry
	else:
		parent[ry]=rx
		if rank[rx]==rank[ry]:
			rank[rx]+=1
parent=list(range(n))
rank=[0]*n
for i in range(m):
	x,y=map(int,input().split())
	unite(x-1,y-1)
ans=0
for i in range(n):
	if same(p[i]-1,i):
		ans+=1
print(ans)

Measured memory_bytes: 13876
import numpy as np
n = int(input())
a = list(map(int, input().split()))

mynas=0
for i in range(n):
    if a[i]<0:
        mynas += 1

a=np.array(a)
a=np.abs(a)
a=np.sort(a)
goukei=0

if mynas % 2 ==0:
    for j in range(n):
        goukei += a[j]
else:
    for k in range(n):
        goukei+=a[k]
    goukei-=a[0]*2

print(goukei)


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


//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
using ll = long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define Test int T;cin>>T;while(T--)
#define REP(i,j,k) for(int i=(j);(i)<(k);(i)++)
#define Time()	cerr <<'\n' << clock() * 1000 / CLOCKS_PER_SEC << "ms\n"
#define SZ(x) (int)x.size();
#define all(x) x.begin,x.end()
// no change 

//const int MxN = 1e9+5;

int main() {
	int n,k;
	cin>>n>>k;
	vi v(n+1,1);
	for(int i=0;i<k;i++)
	{
		int d;
		cin>>d;
		while(d--){
			int x;
			cin>>x;
			if(v[x] == 0)continue;
			else v[x]--;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(v[i] == 1)ans++;
	}
	cout<<ans;
	
	
}


Measured memory_bytes: 3604
A, B, C, K = list(map(int, input().split()))

ans = 0

if A > K:
    ans = 1 * K
else:
    ans = A
    K -= A
    if B > K:
        ans += 0 * B
    else:
        K -= B
        if C >= K:
            ans -= 1 * K
print(ans)

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

int main()
{
  int a,b;
  cin>> a;
  cin >> b;
   if (a<b)
   {
   cout << "0"<< endl;
   }
     else 
     {
     cout << "10"<< endl;
   }
 
 return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

 

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    mint ans = 2;
    mint comb_a = 1,comb_b = 1;


    rep(i,0,a){
        mint m = i+1;
        comb_a *= (n-i);
        comb_a *= m.inv();
    }

    rep(i,0,b){
        mint m = i+1;
        comb_b *= (n-i);
        comb_b *= m.inv();
    }
    

    ans = ans.pow(n) - 1;
    ans -= comb_a;
    ans -= comb_b;

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

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

int main(void) {
  int N, D, X;

  cin >> N >> D >> X;

  int tmp_ans = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;

    int ate_day = 1;
    while (ate_day * a + 1 <= D) {
      tmp_ans++;
      ate_day++;
    }
  }

  int ans = tmp_ans + N + X;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(lambda x: -int(x) ,input().split()))
import heapq
heapq.heapify(a)
for _ in range(m):
  tmp = -heapq.heappop(a)
  tmp //= 2
  heapq.heappush(a,-tmp)
print(-sum(a))

Measured memory_bytes: 14252
import sys
import numpy as np

N, M = map( int, input().split() )
X_list = np.array( sorted( list( map( int, input().split() ) ) ) )

diff=np.diff(X_list, n=1)

if N>=M:
	print(0)
	sys.exit()

sorted_diff=np.sort(diff)

cnt=np.sum(sorted_diff[:M-N])

print(cnt)

Measured memory_bytes: 22992
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
#define all(v) (v).begin(),(v).end()

int main(){
  	int N, X;
  	cin >> N >> X;
  	vector<int> m(N);
  	for (int i=0;i<N;i++) cin >> m[i];
  	int m_min = *min_element(all(m));
  	int m_sum = accumulate(all(m), 0);
  	cout << (X - m_sum) / m_min + N << endl;
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main{
	static int[] w; 
	static int[] v;
	static int W;
	static int  N;
	static long[][] memo;
	public static long solve(int i, int weight)
	{
		if(i==N)
			return 0;
		if(memo[i][weight]!=-1)
			return memo[i][weight];
		if(weight+w[i]>W)
		return solve(i+1, weight);
		return memo[i][weight]=Math.max(v[i] + solve(i+1, weight + w[i]), solve(i+1, weight));
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw =new PrintWriter(System.out);
		StringTokenizer st= new StringTokenizer(br.readLine());
		N=Integer.parseInt(st.nextToken());
		W=Integer.parseInt(st.nextToken());
		w= new int[N];
		v=new int[N];
		for (int i = 0; i < N; i++) {
			st=new StringTokenizer(br.readLine());
			w[i]=Integer.parseInt(st.nextToken());
			v[i]=Integer.parseInt(st.nextToken());
		}
		memo=new long[N][W+1];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < W+1; j++) {
				memo[i][j]=-1;
			}
		}
		pw.print(solve(0, 0));
		pw.close();
	}
}


Measured memory_bytes: 124500
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a;
  cin>>a;
  string s;
  cin>>s;
  if(a>=3200) cout<<s<<endl;
  else cout<<"red"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from operator import itemgetter
from heapq import heapify, heappop, heappush
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, T = IL()
ab = [IL() for i in range(N)]
ab.sort(key=itemgetter(0))
#print(ab)

dp = [[0]*(T+1+3000+1) for _ in range(N+1)]
ans = 0
for i in range(N):
  for j in range(T+1+3000+1):
    time, deli = ab[i]
    if 0 <= j-time < T:
      dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)
    else:
      dp[i + 1][j] = dp[i][j]
    ans = max(ans, dp[i + 1][j])
print(ans)

#print(dp)


Measured memory_bytes: 183896
#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

char t[N];
int n;
int dp[300005][2];

int solve(int i,int c) {
	if (i == n)
		return (c == 1 ? 0 : oo);
	int &ret = dp[i][c];
	if (ret != -1) return ret;
	ret = 0;
	if (c == 1)
		ret = (t[i] != 'W') + solve(i + 1, c);
	if (c == 0) {
		ret = min((t[i] != 'E') + solve(i + 1, c), solve(i+1,1));
	}
	return ret;
}

int main() {
	scanf("%d",&n);
	scanf("%s",t);
	memset(dp, -1, sizeof dp);
	cout << solve(0, 0);
}

Measured memory_bytes: 16896
#!/usr/bin/env python
# coding: utf-8

# In[4]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        l[i+1]=1+l[i]
    else:
        l[i+1]=l[i]
for i in range(Q):
    print(l[lr[i][1]-1]-l[lr[i][0]-1])


# In[ ]:






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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; ++i)cin >> s[i];
  int cntab = 0;
  int a = 0;
  int b = 0;
  int ba = 0;
  for(int i = 0; i < n; ++i){
    if(s[i].front() == 'B')b++;
    if(s[i].back() == 'A')a++;
    if(s[i].front() == 'B' && s[i].back() == 'A')ba++;
    for(int j = 0; j < (int)s[i].size()-1; ++j){
      if(s[i][j] == 'A' && s[i][j+1] == 'B')cntab++;
    }
  }
  cntab += min(a,b);
  if(a > 0 && a == b && a == ba)cntab--;
  cout << cntab << endl;
}


Measured memory_bytes: 3728
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,k;
    long long sum = 0,i;
    cin>>n>>k;


    int a[n];
    for(i = 0;i < n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }if(n<=k)
    {
        cout<<"0"<<endl;
        return 0;

    }
    sort(a,a+n);
    for(i = n-1;i>n-k-1;i--)
    {
        sum-=a[i];
    }
    cout<<sum<<endl;

}


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

int main() {
    vector<int> a(3);
    for (int i=0;i<3;i++)cin >> a[i];
    if (a[0]==a[1] && a[1]==a[2]){
        cout << "1";
    }
    else if (a[0]==a[1] || a[1]==a[2] || a[0]==a[2]){
        cout << "2";
    }
    else {
        cout << "3";
    }
    
}


Measured memory_bytes: 3544
#include<iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int L[m];
	int R[m];
	int i;
	for(i=0;i<m;i++){
		cin >> L[i] >> R[i];
	}
	int Lmax = 0;
	int Rmin = n;
	for(i=0;i<m;i++){
		if(Lmax < L[i]) Lmax = L[i];
		if(Rmin > R[i]) Rmin = R[i];
	}
	int ans = 0;
	if(Rmin - Lmax + 1 > 0) ans = Rmin - Lmax + 1;
	cout << ans;
	
}

Measured memory_bytes: 1024
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
//--Container
//
typedef long long ll;
typedef pair<int,int> pi;

char cz[110];
void cl(){
	scanf("%s",cz);cz[3]='8';
	printf("%s\n",cz);
};

int main(){
	cl();
	return 0;
};

Measured memory_bytes: 128
#include<bits/stdc++.h>
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 ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  string s; cin >> s;
  int c = 0;
  rep(i,s.size()-1) if(s[i] != s[i+1]) c++;
  cout << c << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[3005][3005];

int main() {
  ll mod = 998244353;
  int N, S;
  cin>>N>>S;
  int A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  DP[0][0] = 1;
  DP[0][A[0]] = 1;
  for(int i=0;i<N-1;++i) {
    DP[i+1][0] = 1;
    DP[i+1][A[i+1]] = 1;
    for(int j=0;j<=S;++j) {
      DP[i+1][j] += DP[i][j];
      DP[i+1][j] %= mod;
      if(j+A[i+1]<=S) {
        DP[i+1][j+A[i+1]] += DP[i][j];
        DP[i+1][j+A[i+1]] %= mod;
      }
    }
  }
  ll ans = 0;
  for(int i=0;i<N;++i) {
    ans += DP[i][S];
    ans %= mod;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 73980
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;



int main(int argc, char *args[]) {
	int a, b;
	char s[12];
	cin >> a >> b;
	cin >> s;
	for (int i = 0; i < a; i++) {
		if (!('0' <= s[i] && s[i] <= '9')) { 
			cout << "No" << endl; return 0; 
		}
	}
	if (!(s[a] == '-')) { 
		cout << "No" << endl; return 0; 
	}
	for (int i = a + 1; i < a + b; i++) {
		if (!('0' <= s[i] && s[i] <= '9')) {
			cout << "No" << endl; return 0;
		}
	}
	cout << "Yes" << endl;
}


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

int main(){
  int A,B;
  int count;
  cin>>A>>B;
  if(B==1){cout<<"0"<<endl;
           return 0;
          }
  
  while((B-A+1)>1){
    count++;
    B=B-A+1;
  }
  cout<<count+1<<endl;

  
  return 0;
}

  


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

long long Dijkstra(const WGraph &G, const int s, const int t) {
    int n = (int)G.size();
    std::vector<long long> dis(n, LINF);
    dis[s] = 0;
    using P = std::pair<long long, int>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> que;
    que.push(std::make_pair(0, s));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        if (dis[v] < p.first) continue;
        for (auto e : G[v]) {
            if (dis[e.first] > dis[v] + e.second) {
                dis[e.first] = dis[v] + e.second;
                que.push(std::make_pair(dis[e.first], e.first));
            }
        }
    }
    return dis[t] == LINF ? -1 : dis[t];
}

void solve() {
    int H, W, cx, cy, dx, dy;
    cin >> H >> W >> cx >> cy >> dx >> dy;
    --cx, --cy, --dx, --dy;
    vector<string> S(H);
    for (int i=0; i<H; ++i) cin >> S[i];

    WGraph G(H*W);
    for (int i=0; i<H; ++i) {
        for (int j=0; j<W; ++j) {
            int cur = i*W + j;
            for (int xx=-2; xx<=2; ++xx) {
                for (int yy=-2; yy<=2; ++yy) {
                    if (xx == 0 && yy == 0) continue;
                    int nx = i + xx, ny = j + yy;
                    if (nx < 0 || H <= nx || ny < 0 || W <= ny) continue;
                    if (S[nx][ny] == '#') continue;
                    int next = nx*W + ny;
                    if (abs(xx) + abs(yy) == 1) G[cur].push_back({next, 0});
                    else G[cur].push_back({next, 1});
                }
            }
        }
    }

    cout << Dijkstra(G, cx*W+cy, dx*W+dy) << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 299460
#include <stdio.h>

int main(void)
{
	unsigned short a[4], b[4], hit, blow, i, j;

	while(scanf("%u%u%u%u%u%u%u%u",
		&a[0], &a[1], &a[2], &a[3],
		&b[0], &b[1], &b[2], &b[3]) != EOF){
			hit = 0;
			blow = 0;
			for(i=0; i<4; i++){
				if(a[i] == b[i]){ hit++; }
				for(j=0; j<4; j++){
					if(a[i] == b[j]){ blow++; }
				}
			}
			printf("%d %d\n", hit, blow-hit);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

vector<int> x(11, 1);
vector<int> a(51), b(51), c(51);
vector<ll> d(51);
ll ans = 0LL;
int n, m, q;

void dfs(int i) {
    if(i > n) {
        ll tmp = 0LL;
        for(int j=0;j<q;++j) {
            if(x[b[j]] - x[a[j]] == c[j]) {
                tmp += d[j];
            }
        }
        ans = max(ans, tmp);
        return;
    }
    for(int j=x[i-1];j<=m;++j) {
        x[i] = j;
        dfs(i+1);
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> m >> q;
    for(int i=0;i<q;++i) cin >> a[i] >> b[i] >> c[i] >> d[i];

    dfs(1);
    cout << ans << endl;

}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

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

	vector<int> w( N+1 ), e( N+1 );
	for( int i = 1; i <= N; ++i ) {
		w[i] = w[i-1] + (S[i-1] == 'W');
		e[i] = e[i-1] + (S[i-1] == 'E');
	}

	int ans = N;
	for( int i = 1; i <= N; ++i ) {
		ans = min( ans, w[i-1] + e[N] - e[i] );
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)




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

 ll a,b;
  cin >> a >> b;
  cout << 6-a-b << endl;
  
  
  
} // main

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N;
    char S[N], T[N];
    scanf("%d", &N);
    scanf("%s %s", S, T);

    for (int i = 0; i < N - 1; i++){
        printf("%c%c", S[i], T[i]);
    }
    printf("%c%c\n",S[N - 1], T[N - 1]);

    return 0;
}


Measured memory_bytes: 128
a, b = map(int, input().split())
c = input()
d = list("1234567890")
for i in range(a):
    if c[i] not in d:
        print("No")
        exit()
for i in range(b):
    if c[-i-1] not in d:
        print("No")
        exit()
if c[a] == "-":
    print("Yes")
else:
    print("No")


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

long N, P, i, j, n;

int main(void) {
    cin >> N >> P;
    if (N == 1) {
        cout << P << endl;
        return 0;
    }

    long ans = 1;
    //Pを素因数分解
    for (i=2; i*i<=P; i++) {
        n = 0;
        while (P % i == 0) {
            P /= i;
            n++;
        }
        if (n >= N) {
            ans *= pow(i, n / N);
        }
    }
    
    cout << ans << endl;
    return 0;
}




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

int main(){
    long long n, a[1000000],ans=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            long long d=a[i]-a[i+1];
            a[i+1]=a[i];
            ans=ans+d;
            
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5152
import java.util.Scanner;

public class Main {

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

		int mod = 2019;

		int l = in.nextInt();
		int r = in.nextInt();
		
		// 2019の倍数が必ずある場合
		if(r-l >= mod) {
			System.out.println(0);
			return;
		}

		long IbyJ = 0;
		long min = Long.MAX_VALUE;

		for ( long i = l; i < r; i++ ) {
			for ( long j = i + 1; j <= r; j++ ) {
				IbyJ = i * j;
				min = (IbyJ % mod) < min ? (IbyJ % mod) : min;
			}
		}
		System.out.println(min);

		in.close();
	}
}

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

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());

    puts(accumulate(A.begin(), A.end(), 0) >= h ? "Yes" : "No");
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  int a = 0;
  for(int i = 0; i < n; i++){
    cin >> h.at(i);
    if(h.at(i) >= k) a++;
  }
  
  cout << a << endl;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    int n;
    long[] as;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    void read() {
        Scanner sc = new Scanner(System.in);
        n  =sc.nextInt();
        as = new long[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextLong();
        }
    }

    void solve() {
        long sum = Arrays.stream(as).sum();
        long[] subSum = new long[n];
        subSum[0] = as[0];
        for (int i = 1; i < n; i++) {
            subSum[i] = subSum[i-1] + as[i];
        }
        long ans = Long.MAX_VALUE, tmp;
        for (int i = 0; i < n - 1; i++) {
            tmp = sum - subSum[i];
            tmp = Math.abs(tmp - subSum[i]);
            ans = tmp < ans ? tmp : ans;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 92304
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections


class Node(object):

  def __init__(self):
    self.edges = []
    self.color = None


def main():
  nodes = [Node() for _ in range(int(input()))]

  for _ in range(len(nodes) - 1):
    u, v, w = map(int, input().split())

    nodes[u - 1].edges.append((nodes[v - 1], w))
    nodes[v - 1].edges.append((nodes[u - 1], w))

  queue = collections.deque()

  nodes[0].color = 0
  queue.append(nodes[0])

  while len(queue) != 0:
    node = queue.pop()

    for e, w in node.edges:
      if e.color is not None:
        continue

      if w % 2 == 0:
        e.color = node.color
      else:
        e.color = 1 - node.color

      queue.append(e)

  for node in nodes:
    print(node.color)


if __name__ == '__main__':
  main()



Measured memory_bytes: 48616