akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdint>

using namespace std;

int solve(const string& s) {
    string ss = "CODEFESTIVAL2016";

    int n = 0;
    for (int i = 0; i < ss.size(); ++i) {
        if (s[i] != ss[i]) {
            ++n;
        }
    }

    return n;
}


int main() {
    string s;
    cin >> s;

    cout << solve(s) << endl;

    return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: a, b, i, res
  read (*, *) a, b
  res = -1
  do i = 1, 10000
    if (int(i * 0.08) == a .and. int(i * 0.1) == b) then
      res = i
      exit
    end if
  end do
  write (*, "(i0)") res
end program main


Measured memory_bytes: 768
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)

//  Increment Decrement.cpp
//
//  Created by WinnieJt on 2019/3/21.
//
//  Copyright © 2019 金天. All rights reserved.

#include<bits/stdc++.h>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
typedef double db;
typedef long long ll;
using namespace std;
char x[2333];
ll n,pre,hig;
ll cmp(ll a,ll b)
{
    if(a>=b) return a;
    else return b;
}
int main(void)
{
    ios::sync_with_stdio(false);
    cin >> n;
    for(ll i=0;i<n;i++) cin >> x[i];
    for(ll i=0;i<n;i++)
    {
        if(x[i]=='I') pre++;
        else if(x[i]=='D') pre--;
        hig=cmp(hig,pre);
    }
    cout << hig << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int digsum(int n){
	if(n==0)return 0;
	return n%10+digsum(n/10);
}
void solve(){
   int n,a,b;
   cin>>n>>a>>b;
   int cnt=0;
   for(int i=1;i<=n;i++){
	   int val=digsum(i);
	   cnt+=(val<a or val>b?0:i);  
	 }
	 cout<<cnt<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >>x;
  if(400<=x && x<=599)cout <<8;
  if(600<=x && x<=799)cout <<7;
  if(800<=x && x<=999)cout <<6;
  if(1000<=x && x<=1199)cout <<5;
  if(1200<=x && x<=1399)cout <<4;
  if(1400<=x && x<=1599)cout <<3;
  if(1600<=x && x<=1799)cout <<2;
  if(1800<=x && x<=1999)cout <<1;
  
    return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<iostream>
using namespace std;
const int maxn = 200000+5;
#define INF 1e9

struct HeapNode //Dijkstra算法用到的优先队列的节点
{
    int d,u;
    HeapNode(int d,int u):d(d),u(u){}
    bool operator < (const HeapNode &rhs)const  //这里重载小于号，是为了Q.top().能去除最小的边。如果不是很好理解的话可以画个图就明白了。
    {
        return d > rhs.d;
    }
};

struct Edge     //边
{
    int from,to,dist;
    Edge(int f,int t,int d):from(f),to(t),dist(d){}
};

struct Dijkstra
{
    int n,m;            //点数和边数,编号都从0开始
    vector<Edge> edges; //边列表
    vector<int> G[maxn];//每个节点出发的边编号(从0开始编号)
    bool done[maxn];    //是否已永久标号
    int d[maxn];        //s到各个点的距离
    int p[maxn];        //p[i]为从起点s到i的最短路中的最后一条边的编号

    void init(int n)
    {
        this->n=n;
        for(int i=0;i<n;i++) G[i].clear();//清空邻接表
        edges.clear();  //清空边列表
    }

    void AddEdge(int from,int to,int dist)
    {//如果是无向图，每条无向边调用两次AddEdge
        edges.push_back(Edge(from,to,dist) );
        m = edges.size();
        G[from].push_back(m-1);
    }

    void dijkstra(int s)//求s到所有点的距离
    {
        priority_queue<HeapNode> Q;
        for(int i=0;i<=n;i++) d[i]=INF;
        d[s]=0;
        memset(done,0,sizeof(done));
        Q.push(HeapNode(0,s) );

        while(!Q.empty())
        {
            HeapNode x=Q.top(); Q.pop();
            int u=x.u;
            if(done[u]) continue;
            done[u]= true;

            for(int i=0;i<G[u].size();i++)
            {
                Edge& e= edges[G[u][i]];
                if(d[e.to]> d[u]+e.dist)
                {
                    d[e.to] = d[u]+e.dist;
                    p[e.to] = G[u][i];
                    Q.push(HeapNode(d[e.to],e.to) );
                }
            }
        }
    }
}DJ;

int main()
{
   // return 0;
   int n,m;
   cin>>n>>m;
   DJ.init(n);
   int u,v;
   for(int i=1;i<=m;i++)
   {
       cin>>u>>v;
       DJ.AddEdge(u,v,1);
        DJ.AddEdge(v,u,1);
   }
   DJ.dijkstra(1);
   /*for(int i=1;i<=n;i++)
   {
       cout<<DJ.d[i]<<endl;
   }*/
   if(DJ.d[n]==2)
   {
       cout<<"POSSIBLE";
   }
   else
   {
       cout<<"IMPOSSIBLE";
   }
}


Measured memory_bytes: 21548
#include <bits/stdc++.h>
using namespace std;
int main() {
long long counter=0;
long long n,a,s,d,r;
cin>>n>>a>>s>>d>>r;
long long b[3]={};
b[0]=n*4;
b[1]=a*2;
b[2]=s;
sort(b,b+3);
if(b[0]*2<=d){
cout<<r*b[0]<<endl;}
else if(r%2==0){
cout<<r/2*d<<endl;}
else{
cout<<(r-1)/2*d+b[0]<<endl;}}


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

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, K;
  std::cin >> N >> K;
  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    if (ans * 2 < ans + K) {
      ans *= 2;
    } else {
      ans += K;
    }
  }

  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vi a(n);
    rep(i,0,n){
        cin>>a[i];
        if(a[i]==0){cout<<0;return 0;}
    }
    int ans = 1;
    rep(i,0,n){
        if(ans*a[i]>INF || ans*a[i] < ans){cout<<-1;return 0;}
        else{ans*=a[i];}
    }
    cout<<ans<<endl;
}

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

int main()
{
	int n; cin >> n ;
	int heights[n];

	for( int i = 0 ; i < n ; i ++ ) 
	   cin >> heights[i];

	/**

     dp[i] = min(dp[j] + abs(heights[i]-heights[j])) for j = i+1,i+2;

	*/

	int dp[n];
    dp[n-1] = 0 ;
    dp[n-2] = abs(heights[n-2]-heights[n-1]);

    for(int i = n-3 ; i >= 0; i --)
    {
    	dp[i] = dp[i+1] + abs(heights[i]-heights[i+1]);
    	dp[i] = min(dp[i+2] + abs(heights[i]-heights[i+2]),dp[i]);
    }

    cout << dp[0] << endl; 

}

Measured memory_bytes: 4408
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    if n == 1 {
        println!("Hello World");
    } else {
        let a: usize = read();
        let b: usize = read();
        println!("{}", a + b);
    }
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,N;
  cin >> X >> N;

  int p[N];

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

  sort(p,p+N);
  
  int check_p,minus_X,min_X,min_i;
  min_X = 100;
  min_i = X;

  for (int i = 0; i < 102 ; i++) {
    for (int j = 0; j < N ; j++) {
        if (p[j] == i){
            check_p = 0;
            break;
        }else{
            check_p = 1;
        }
    }
    if (check_p == 1){
         minus_X = abs(X - i);
         if (minus_X < min_X){
             min_X = minus_X;
             min_i = i;
         }
    }
    
    }
    cout << min_i <<endl;
  
}

Measured memory_bytes: 3648
#include<stdio.h>

int a[1000000],b;

int serch(int key){
  int l=0,r=b,mid;
  while(l<r){
    mid=(l+r)/2;
    if(key==a[mid]) return 1;
    if(key>a[mid]) l=mid+1;
    else if(key<a[mid])r=mid;
  }
  return 0;
}

int main(){
  int i,d,e,sum=0;
    scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&d);
  for(i=0;i<d;i++){
    scanf("%d",&e);
    if(serch(e)) sum++;
  }

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

    return 0;
}

Measured memory_bytes: 988
#include <stdio.h>

int main(void) {
	char str[1001];
	int i;
	
	scanf("%s", str);
	for (i = 0; str[i] != '\0'; i++) {
		if ('D' <= str[i])
			str[i] -= 3;
		else
			str[i] += 23;
	}
	
	printf("%s\n", str);
	
	return 0;
}

Measured memory_bytes: 524
program prob2
    implicit none
    integer::n, i
    integer(16)::l(0:86)
    l(0) = 2
    l(1) = 1
    do i = 2, 86
        l(i) = l(i-1) + l(i-2)
    end do
    read(*,*) n
    write(*,*) l(n)
    stop
end program

Measured memory_bytes: 2860
// AOJ ALDS1_12_C Single Source Shortest Path II
// 2018.5.1 bal4u
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define QMAX 35000
typedef struct { int t, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF   0x30303030
#define MAX_V 10002
int hi[MAX_V], *to[MAX_V], *dd[MAX_V];
int dist[MAX_V];

void dijkstra(int n, int start)
{
	int i, s, e, t, nt;

	memset(dist, INF, n << 2);
	qsize = 0;
	dist[start] = 0, enq(start, 0);
	while (qsize) {
		s = que[0].s, t = que[0].t, deq();
		if (dist[s] < t) continue;
		for (i = 0; i < hi[s]; i++) {
			e = to[s][i], nt = t + dd[s][i];
			if (dist[e] > nt) dist[e] = nt, enq(e, nt);
		}
	}
}

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
 
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) { pc('0'); return; }
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}

int main()
{
	int n, i, j, k, u;
 
	n = in();
	for (i = 0; i < n; i++) {
		u = in(), hi[u] = k = in();
		to[u] = malloc(k<<2);
		dd[u] = malloc(k<<2);
		for (j = 0; j < k; j++) {
			to[u][j] = in(), dd[u][j] = in();
		}
	}
	dijkstra(n, 0);
	for (i = 0; i < n; i++) {
		out(i), pc(' '), out(dist[i]), pc('\n');
	}
	return 0;
}


Measured memory_bytes: 5544
#include <stdio.h>
#include <math.h>
#define MAX 1000
 
int main(void){
 
    int i, n, temp[MAX];
    double sum, ave, sd;
 
    while(1){
        scanf("%d", &n);
 
        if(n == 0){
            break;
        }
 
        sum = 0.0;
        for(i = 0; i < n; i++){
            scanf("%d", &temp[i]);
            sum += (double)temp[i];
        }
 
        ave = sum / (double)n;
         
        sd = 0.0;
        for(i = 0; i < n; i++){
            sd += (ave - (double)temp[i]) * (ave - (double)temp[i]);
        }
        sd /= (double)n;
        printf("%f\n", sqrt(sd));
    }
 
 
    return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 20
using namespace std;
int n,m,a[szxb]={1};
signed main()
{
	scanf("%d%d",&n,&m);
	for(register int i(1);i<=n;i++){a[i]=(min((a[i-1]+m),(a[i-1]<<1)));}
	printf("%d",a[n]);
	return putchar(10),0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
int main(){
	int n;
	double o;
	cin>>n;
	if (n%2 == 0){
		o = n/2;
	}
	else{
		o = n/2 + 1;
	}
	cout<<o/n;
	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    int n, ans;
    double min, a, t, hi, tmp;
    cin >> n;
    cin >> t >> a;
    vector<double> h(n+1);
    h[0] = 0.0;
    for (int i=1; i<=n; ++i){
        cin >> hi;
        tmp = (t - hi * 0.006);
        h[i] = fabs(double(tmp) - double(a));
        //cout << i << ":" << h[i] << endl;
    }
    for (int i=1; i<=n; ++i){
        if(i == 1){
            min = h[i];
            ans = 1;
        }
        if(h[i] < min){
            min = h[i];
            ans = i;
        }
    }   
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    int sum = A[0] + A[1] + A[2];
    if (sum >= 22) {
        cout << "bust" << endl;
    }
    else {
        cout << "win" << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str = Console.ReadLine ().Split (' ');

            var A = long.Parse (str[0]);
            var B = long.Parse (str[1]);
            var H = long.Parse (str[2]);
            var M = long.Parse (str[3]);


            var a = H * 30 +0.5*M;
            var b = 6 * M;


            var c = Math.Abs (a - b);
                      if (c > 180) c = 360 - c;

          	var ans = Math.Sqrt (Math.Pow(A,2)+ Math.Pow(B,2) - 2 * A * B * Math.Cos (c * Math.PI / 180));
            Console.WriteLine (ans);
        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

Measured memory_bytes: 27936
import sys

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))

count = 0
current_min = P[0]
for i in range(N):
    Pi = P[i]
    if P[i] < current_min:
        current_min = P[i]
    if P[i] > current_min:
        count += 1

ans = N - count
print(ans)

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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";
 
using namespace std;

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

signed main(){
    io();   
    ll n; cin >> n;
    return cout << n*(n - 1)/2 << '\n', 0;
}


Measured memory_bytes: 3612
A = [int(i) for i in input().split(' ')]
if 2*A[2] < A[0] + A[1]:
  m = min(A[3], A[4])
  print(A[2] * m * 2 + (A[3] - m)*min(A[0],2*A[2]) + (A[4] - m)*min(A[1],2*A[2]) )
else:
  print(A[3] * A[0] + A[4] * A[1])

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int n;
  cin >> n;
  vt<pair<string, pi>> v(n);
  rep(i, 0, n) {
    string s;
    int p;
    cin >> s >> p;
    v[i] = {s, {-p, i + 1}};
  }
  sort(all(v));
  rep(i, 0, n) cout << v[i].second.second << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	int Sum = 0;
    int Hikakuyou = N;
	while (N != 0){
    Sum += N % 10;
    N = N / 10;
    }
    if(Hikakuyou % Sum == 0){
     cout << "Yes" << endl;
    }else{
     cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
#define int long long
double A, B, N;
int f(int x){
  return floor(A * x / B) - A * floor(x / B);
}
signed main(){
  cin >> A >> B >> N;
  cout << f(min(B-1,N));
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

f80 dp[3010][1510];

void solve() {
  int n; cin >> n;
  vf80 p(n); cin >> p;
  dp[0][0] = 1;
  rep(i, n) repc(j, 1500) {
    dp[i + 1][min(j + 1, 1500)] += dp[i][j] * p[i];
    dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
  }
  f80 ans = 0;
  for (int i = (n + 1) / 2; i <= min(n, 1500); i++) {
    ans += dp[n][i];
  }
  cout << ans << '\n';
}


Measured memory_bytes: 71040
#include <iostream>

#ifdef LOCAL
  #define debug_echo(expr) cout << expr << "\n";
#else
  #define debug_echo(expr)
#endif

using namespace std;

#define at ,<=,
#define to ,<,
#define in ,
#define forrange(...)  forrange1(forrange2, (__VA_ARGS__))
#define forrange1(X, A) X A
#define forrange2(i, s, op, e) for (int i = (s); i op (e); i++)

void split_half(string& s, string& left, string& right) {
  left = "";
  right = "";
  forrange (i in 0 to s.size() / 2) {
    left.push_back(s[i]);
  }
  forrange (i in s.size() / 2 to s.size()) {
    right.push_back(s[i]);
  }
}

int main() {
  string s;
  cin >> s;

  string left;
  string right;
  while (true) {
    s.pop_back();
    split_half(s, left, right);
    if (left == right) {
      break;
    }
  }

  cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <cstring>
#include <fstream>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int MAX_N = 12+1;
const double INF = 1e+100;
double dist[10+1][10+1]; // ツ板シツ径 a ツづ個ケツーツキツづ個陳心ツづ板シツ径 b ツづ個ケツーツキツづ個陳心ツづづ個仰猟猟」ツ。
double d[MAX_N][MAX_N];
double dp[1<<MAX_N][MAX_N];
int n, w;
int a[MAX_N];

// ツケツーツキツ甘板づ個仰猟猟」ツづーツ仰づ淞づゥ
int calc (void )
{
	for (int i = 3; i <= 10; i++ )
		for (int j = 3; j <= 10; j++ )
			dist[i][j] = 2.0*sqrt ((double)i*j );
}

// ツ経ツ路ツづ個静堋堕アツづーツ仰づ淞づゥ
void make (void )
{
	// ツ渉可甘コツ可サ
	rep (i, n+1 )
		rep (j, n+1 )
				d[i][j] = INF;

	rep (i, n )
		rep (j, n )
			d[i][j] = dist[a[i]][a[j]];

	rep (i, n ){
		d[n][i] = a[i]; d[i][n] = a[i];
	} // end rep
	n++;
}

// bitDP
double solve (){

	// ツ渉可甘コツ可サ
	rep (S, 1<<n ){
		fill (dp[S], dp[S]+n, INF );
	} // end rep

	dp[(1<<n)-1][0] = 0;
	for (int S = (1 << n ) - 2; S >= 0; S-- ){
		rep (v, n ){
			 rep (u, n ){
				if (!(S >> u & 1 ) ){
					dp[S][v] = min (dp[S][v], dp[S | 1 << u][u] + d[v][u] );
				} // end if
			} // end rep
		} // end rep
	} // end for

	return dp[0][0];
}

int main()
{
	calc ();
	string str = "";

	while (getline (cin, str ) ){
		vector <int> cake; 
		stringstream ss (str );
		ss >> w;
		int i = 0, m;
		while (ss >> m ){
			 a[i++] = m;
		} // end while
		n = i;
		make ();
		if ((double)w >= solve () ){
			printf ( "OK\n" );
		}else{
			printf ( "NA\n" );
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(true) {
			int cnt = 0;
			for (int i = 2; i < n; i++) {
				if (n % i == 0) {
					cnt++;
					break;
				}
			}
			
			if (cnt >= 1) {
				n++;
				continue;
			} else {
				break;
			}
		}
		
		System.out.println(n);
		
	}
}


Measured memory_bytes: 22612
#pragma GCC optimize("O3")

#include<stdio.h>

typedef unsigned int ll;

#define REP(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007 //10^9+7:合同式の法

ll s[2001],t[2001],dp[2001][2001],n,m={0};

signed main(){
    //入力の高速化用のコード
    scanf("%d %d",&n,&m);
    REP(i,n)scanf("%d",s+i);
    REP(i,m)scanf("%d",t+i);
    REP(i,n+1){dp[i][0]=1;}
    REP(i,m+1){dp[0][i]=1;}
    REP(i,n){
        REP(j,m){
            if(s[i]==t[j]){
                dp[i+1][j+1]+=(dp[i+1][j]+dp[i][j+1])%MOD;
            }else{
                dp[i+1][j+1]+=(dp[i+1][j]+dp[i][j+1]-dp[i][j]+MOD)%MOD;
            }
        }
    }
    printf("%d\n",dp[n][m]);
}

Measured memory_bytes: 17308
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	
	ll n , m ;
	cin>>n>> m ;
	ll ans = (n*(n-1))/2+(m*(m-1))/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int power(int x,int y){
    int res=1LL;
    while(y){
        if(y&1){
            res=(res*x)%MOD;
        }
        x=(x*x)%MOD;
        y=(y>>1);
    }
    return res;
}

signed main()
{
    
    speed
    int n;cin>>n;
    int k;cin>>k;
    vector <int> xd(k+1,0);
    for(int i=k;i>=1;i-=1){
        xd[i]=power(k/i,n);
        for(int j=2*i;j<=k;j+=i){
            xd[i]=(xd[i]-xd[j]+MOD)%MOD;
        }

    }
    int ans=0LL;
    for(int i=1;i<=k;i++){
        ans=(ans+(xd[i]*i)%MOD)%MOD;

    }
    cout<<ans%MOD<<endl;

    

    
    
    
    return 0;
}

Measured memory_bytes: 3920
#include <cstdio>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    ll n, x, cnt = 0, prev = 0, now;
    scanf("%lld%lld", &n, &x);
    for (ll i = 0; i < n; ++i) {
        scanf("%lld", &now);
        prev = now - max(prev + now - x, 0LL);
        cnt += now - prev;
    }
    printf("%lld\n", cnt);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


ll a, b, c, d, r1, r2;


ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

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

int main() {

	cin >> a >> b >> c >> d;

	--a;

	r1 = b - b / c - b / d + b / lcm(c, d);
	r2 = a - a / c - a / d + a / lcm(c, d);
	
	cout << r1 - r2 << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define bg begin()
#define ed end()
#define sz size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
bool c(string t,char m){
	rep(i,t.sz){
		if(t[i]!=m && t[i]!='-') return false;
	}
	return true; 
}

//a,b x
int main(){
	string s; cin>>s;
	ll ans=1000;
	rep(i,26){
		string t(s);
		char m='a'+i;
		if(c(t,m)){
			cout<<0<<endl;
			return 0;
		}
		for(int j=t.sz-1;j>=1;j--){
			rep(k,j)
				if(t[k]==m || t[k+1]==m) t[k]=m;

			t[j]='-';
			if(c(t,m)) ans=min((ll)t.sz-j,ans);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
import math
N = int(input())
S = input()
ans = 1
ans_base = 1
numofS = 0  # 線の左端になっている点をSとするとその数はちょうどNでないといけない
line = 0  # 左から順に線を引く。上に何本通っているかをあらわす
for i in range(2*N):
    if S[i] == "B":
        if line % 2 == 0:
            numofS += 1
            line += 1
        else:
            ans_base *= line
            line -= 1
    else:
        if line % 2 == 0:
            ans_base *= line
            line -= 1
        else:
            line += 1
            numofS += 1

    if line < 0:
        ans = 0
        break
    ans_base %= 10**9+7
if numofS != N:
    ans = 0
    # print(numofS)

if ans != 0:
    fact = math.factorial(N)
    fact %= 10**9+7
    ans = ans_base * fact
    ans %= 10**9+7
print(ans)


Measured memory_bytes: 4328
#include<iostream>
#include<string>
#include<vector>
using namespace std ;

const int N = 1e6 + 10;
vector <int> sum ;
void add(vector<int >&T)
{
    vector<int> C;
    int t = 0;
    for(int i = 0;i<T.size()||i<sum.size();i++)
    {
        if(i<T.size()) t+=T[i];
        if(i<sum.size()) t+=sum[i];
        C.push_back(t%10);
        t/=10;
    }
    if(t)C.push_back(1);
    sum = C;
}
int main ()
{

    int n ;
    cin >> n ;
    for(int i = 1;i<= n; i++)
    {
        if(i % 5!=0 && i%3!=0)
        {
            int t = i;
            vector<int >T;
            while(t!=0)
            {
                int x= t%10;
                T.push_back(x);
                t/=10;
            }
           // for(int j =T.size();j>=0;j--) cout<<T[j];
           // cout<<endl;
            add(T);
            
        }
        
    }
    for(int i =sum.size()-1;i>=0;i--) cout<<sum[i];
    return 0 ;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
using namespace std;
int n;
string t[14],s[14];
bool used[14];
int dp[1<<14][14],d[14][14];
main()
{
	while(cin>>n,n)
	{
		int sz=0;
		for(int i=0;i<n;i++)
		{
			cin>>t[i];
			used[i]=0;
		}
		for(int i=0;i<n;i++)
		{
			bool flag=0;
			for(int j=0;j<n;j++)
			{
				if(i==j||used[j])continue;
				bool f=0;
				for(int k=0;k<t[j].size();k++)
				{
					int l=0;
					for(;l<t[i].size()&&k+l<t[j].size()
						&&t[i][l]==t[j][k+l];l++);
					f|=l==t[i].size();
					if(f)break;
				}
				flag|=f;
				if(flag)break;
			}
			if(!flag)
			{
				s[sz++]=t[i];
			}
			else
			{
				used[i]=1;
			}
		}
		n=sz;
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(i!=j)
		{
			int L=0;
			for(;L<s[i].size();L++)
			{
				int k=0;
				for(;k<s[j].size()&&L+k<s[i].size()
					&&s[j][k]==s[i][L+k];k++);
				if(L+k==s[i].size())break;
			}
			d[i][j]=s[i].size()-L;
		}
		for(int i=0;i<1<<n;i++)for(int j=0;j<n;j++)dp[i][j]=1e9;
		for(int i=0;i<n;i++)dp[1<<i][i]=s[i].size();
		for(int i=1;i<1<<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(dp[i][j]==1e9)continue;
				for(int k=0;k<n;k++)
				{
					if(i>>k&1)continue;
					dp[i|1<<k][k]=min(dp[i|1<<k][k],dp[i][j]+(int)s[k].size()-d[j][k]);
				}
			}
		}
		int ans=1e9;
		for(int i=0;i<n;i++)ans=min(ans,dp[(1<<n)-1][i]);
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    string s;
    map<string, int> m;
    rep(i,n) {
        cin >> s;
        m[s]++;
    }
    int maxv = 0;
    for (auto x: m) {
        int v = x.second;
        if(v>maxv) maxv = v;
    }
    for (auto it = m.begin(); it != m.end(); it++) {
        if(it->second == maxv) cout << it->first << endl;
    }
	return 0;
}


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

int main() {
	vector<int> vec(11, 0);
	int r, D;
	cin >> r >> D >> vec.at(0);
	for (int i = 0; i < 10; i++) {
		vec.at(i + 1) = r * vec.at(i) - D;
		cout << vec.at(i + 1) << endl;
	}
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n; cin >> n;
  cout << (n + 999) / 1000 * 1000 - n << endl;
}


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

//#define DEBUG
#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int list(multiset<int, greater<int> > &s)
{
    cout << "list: ";
    for(auto itr = s.begin(); itr != s.end(); itr++) {
        cout << *itr << " ";
    }
    cout << endl;
}

int main()
{
    int N, tmp;
    int d = 0;
    multiset<int, greater<int> > s;
    int ans = 0;

    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> tmp;
        s.insert(tmp);
    }

    while(!s.empty()) {
        IFD list(s);
        long v = *s.begin();
        s.erase(s.begin());
        IFD cout << "v: " << v << endl;
        long val = 1;
        while (val <= v) {
            val *= 2;
        }
        IFD cout << "val = " << val << endl;
        auto p = s.find(val - v);
        if(p != s.end()) {
            IFD cout << "hit = " << v << ", " << val - v << endl;
            s.erase(p);
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9724
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<sstream>

using namespace std;
int max = 100000;

string IntToString(long long  number){
  stringstream ss;
  ss << number;
  return ss.str();
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  s.insert(4, " ");

  cout << s << endl;

  return 0;

}


Measured memory_bytes: 256
import sys
from collections import Counter

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    M = 10 ** 5
    n = read_int()
    a = read_int_list()
    c = Counter(a)
    res = 0
    for X in range(0, M + 1):
        r = c[X - 1] + c[X] + c[X + 1]
        if r > res:
            res = r
    print(res)


main()


Measured memory_bytes: 14556
c = [list(map(int, input().split())) for i in range(3)]
a = [0,0,0]
b = [0,0,0]
ans = "No"

for i in range(101):
        if i > c[0][0]:
                break
        a[0] = i 
        b[0] = c[0][0] - a[0]
        a[1] = c[1][0] - b[0]
        a[2] = c[2][0] - b[0]
        b[1] = c[0][1] - a[0] 
        b[2] = c[0][2] - a[0] 

        flag = 1 
        for i in range(3):
                for j in range(3):
                        if c[i][j] != a[i] + b[j]:
                                flag = 0 
        if flag:
                ans = "Yes"
                break

print(ans)

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

bool visited[MAX_N];
vector<int> v[MAX_N];

int is_in_list(int node){
    for(auto v1 : v[node]){
        if(visited[v1] == false){return v1;}
    }
    return -1;
}

void show_list(list<int> &l){
    for(auto x:l){
        cout << x << " ";
    }
    cout << endl;
}

int main() {
    for(int i = 0; i < MAX_N; i++){
        visited[i] = false;
    }
    int n, m;
    cin >> n >> m;
    int a, b, front, rear;
    cin >> a >> b;
    list<int> ans{a, b};
    v[a].push_back(b);
    v[b].push_back(a);
    front = a; rear = b;
    visited[a] = true; visited[b] = true;
    for(int i = 1; i < m; i++){
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int unvisited = is_in_list(front);
    while(!(unvisited == -1)){
        visited[unvisited] = true;
        ans.push_front(unvisited);
        front = unvisited;
        unvisited = is_in_list(front);
    }
    unvisited = is_in_list(rear);
    while(!(unvisited == -1)){
        visited[unvisited] = true;
        ans.push_back(unvisited);
        rear = unvisited;
        unvisited = is_in_list(rear);
    }
    cout << ans.size() << endl;
    show_list(ans);

    return 0;
}


Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];

    int ans=0;
    for(int i=0;i<N;)
    {
        int j=i+1,k=i+1;
        while(j<N and a[j-1]<=a[j]) j++;
        while(k<N and a[k-1]>=a[k]) k++;
        ans++; i=max(j,k);
    }
    cout<<ans<<endl;
}


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

constexpr int lim = 1e9;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k, s;
  cin >> n >> k >> s;
  vector<int> res(n, lim);
  if (s < lim) {
    fill(begin(res), begin(res) + k, s);
  } else {
    fill(begin(res) + k, end(res), 1);
  }
  for (int i = 0; i < n; ++i) {
    cout << res[i] << " \n"[i == n - 1];
  }
}


Measured memory_bytes: 1792
H,W,K=map(int,input().split())
x1,y1,x2,y2=map(lambda x:int(x)-1,input().split())

pond=[]
for _ in range(H):
    pond.append(list(input()))

inf=10**7
cost=[[inf]*W for _ in range(H)]
cost[x1][y1]=0
from heapq import heapify,heappop,heappush
hq=[(0,x1,y1)]

while hq:
    t,x,y=heappop(hq)
    #北へ
    for i in range(1,K+1):
        if x-i<0 or pond[x-i][y]=="@" or cost[x-i][y]<t+1:
            break
        if cost[x-i][y]>t+1:
            cost[x-i][y]=t+1
            heappush(hq,(t+1,x-i,y))
    #東へ
    for i in range(1,K+1):
        if y+i>W-1 or pond[x][y+i]=="@" or cost[x][y+i]<t+1:
            break
        if cost[x][y+i]>t+1:
            cost[x][y+i]=t+1
            heappush(hq,(t+1,x,y+i))
    #南へ
    for i in range(1,K+1):
        if x+i>H-1 or pond[x+i][y]=="@" or cost[x+i][y]<t+1:
            break
        if cost[x+i][y]>t+1:
            cost[x+i][y]=t+1
            heappush(hq,(t+1,x+i,y))
    #西へ
    for i in range(1,K+1):
        if y-i<0 or pond[x][y-i]=="@" or cost[x][y-i]<t+1:
            break
        if cost[x][y-i]>t+1:
            cost[x][y-i]=t+1
            heappush(hq,(t+1,x,y-i))

if cost[x2][y2]==inf:
    print(-1)
    exit()  
print(cost[x2][y2])


Measured memory_bytes: 44068
#include <iostream>
using namespace std;
int dp[100001];
int main()
{
	int n;
	cin>>n;
	int ac; cin>>ac;
	int cost[n];
	for(int i=0;i<n;i++)
	{
		cin>>cost[i];
	}
	dp[0]=0;
	dp[1]=abs(cost[1]-cost[0]);
	for(int i=2;i<n;i++)
	{
			dp[i]=dp[i-1]+abs(cost[i]-cost[i-1]);
		for(int k=2;k<=ac;k++)
		{
			if(i-k>=0){
		dp[i]=min(dp[i],dp[i-k]+abs(cost[i]-cost[i-k]));
            }
		}
	}
	cout<<dp[n-1];
	
	
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define mp make_pair
const ll MOD=1e9+7;
using vi=vector<ll>;
ll N,M,X;
vi par;
ll root(ll X){
    if(par[X]==X) return X;
    return par[X]=root(par[X]);    
}
bool same(ll X,ll Y){
    return root(X)==root(Y);
}
void unite(ll X,ll Y){
    X=root(X);
    Y=root(Y);
    if(X==Y) return;
    par[X]=Y;
}
ll modpow(ll a,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%MOD;
        a=a*a%MOD;
        n>>=1;
    }
    return res;
}
int main(){
    cin>>N>>M>>X;
    par.resize(N);
    vector<tuple<ll,ll,ll>> edge(M);
    rep(i,0,M){
        ll X,Y,Z; cin>>X>>Y>>Z;
        edge[i]=make_tuple(Z,X,Y);
    }
    sort(ALL(edge));
    vi memo(M);
    rep(i,0,M){
        ll x,y,z; tie(x,y,z)=edge[i];
        memo[i]=x;
        rep(i,0,N) par[i]=i;
        unite(z-1,y-1);
        rep(j,0,M){
            ll X,Y,Z; tie(Z,X,Y)=edge[j];
            if(!same(X-1,Y-1)){
                memo[i]+=Z;
                unite(X-1,Y-1);
            }
        }
    }
    sort(ALL(memo));
    ll ans=0;
    rep(i,1,M)if(memo[i]==X) ans=(ans+modpow(2,M-i))%MOD;
    cout<<ans;
}


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

int main()
{
    int n,k;

    cin >> n >> k;

    int cnt = 0;

    if(n == 1 && k == 1){
        cout << "YES" << endl;
        return 0;
    }
    if(n <= k){
        cout << "NO" << endl;
        return 0;
    }

    for(int i = 1;i <= n;i+=2){
        cnt++;
    }
    if(cnt >= k) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

using namespace std;

int main() {
	int W, H, N;
	cin >> W >> H >> N;

	int x, y, a;
	int x0 = 0, y0 = 0;
	for (int i = 0; i < N; i++) {
		cin >> x >> y >> a;
		if (a == 1 && x > x0) x0 = x;
		if (a == 2 && x < W) W = x;
		if (a == 3 && y > y0) y0 = y;
		if (a == 4 && y < H) H = y;
	}

	if (W - x0 > 0 && H - y0 > 0) {
		cout << (W - x0)*(H - y0) << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
from numpy import*
h,*s=open(0)
h,w=int64(h.split())
r=range
s=array([list(t[:-1])for t in s])
a,b,c,d=eval('zeros((h,w),"i"),'*4)
for i in r(w):
    a[:,i]=-~a[:,i-1]*(s[:,i]>'#')
    b[:,~i]=-~b[:,-i]*(s[:,~i]>'#')
for i in r(h):
    c[i,:]=-~c[i-1,:]*(s[i,:]>'#')
    d[~i,:]=-~d[-i,:]*(s[~i,:]>'#')
print(int((a+b+c+d).max())-3)

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

using namespace std;

struct shop {
    long long price;
    int stock;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<shop> sh(N);
    for (int i = 0; i < N; i++) cin >> sh[i].price >> sh[i].stock;

    sort(sh.begin(), sh.end(), [](shop a, shop b) {return a.price < b.price;});

    int res = M;
    long long total = 0;

    int pos = 0;
    while (res > 0) {
        int buy = min(res, sh[pos].stock);
        res -= buy;
        total += sh[pos].price*buy;
        pos++;
    }

    cout << total << endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 1e6;
const int N = 1e3 + 5, M = 35;
const ll INF = 1e15;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;

#define pi acos(-1)

set<int> st[30];

int main()
{
    int n;
    int q;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i++)
    {
        int x = s[i] - 'a';
        st[x].insert(i + 1);
    }
    cin >> q;
    while(q--)
    {
        int k, l, r;
        char c;
        scanf("%d%d", &k, &l);
        if(k == 1)
        {
            cin >> c;
            int x = s[l - 1] - 'a';
            st[x].erase(l);
            x = c - 'a';
            st[x].insert(l);
            s[l - 1] = c;
        }
        else
        {
            cin >> r;
            int cnt = 0;
            for(int i = 0; i < 26; i++)
            {
                if(st[i].lower_bound(l) != st[i].upper_bound(r))
                    cnt++;
            }
            printf("%d\n", cnt);
        }
    }
    return 0;
}

Measured memory_bytes: 24200
#include <stdio.h>

int main()
{
	char c;
	scanf("%c", &c);
	switch(c)
	{
		case 'u': case 'e' : case 'o' : case 'a' : case 'i':
			printf("vowel");
			break;
		default: printf("consonant");		
	}
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());

			var p = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
			var q = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();

			var permutationP = GetAllPermutation(p);
			var permutationQ = GetAllPermutation(q);

			Console.WriteLine(Math.Abs(permutationP.Count - permutationQ.Count));
		}

		private static List<int[]> GetAllPermutation(int[] array)
		{
			var permutations = new List<int[]>();
			permutations.Add(array);

			while(true)
			{
				int i;
				var list = permutations[permutations.Count - 1].ToList();

				for (i = list.Count - 2; i >= 0; i--)
				{
					if (list[i] < list[i + 1])
					{
						break;
					}
				}

				if (i < 0)
				{
					break;
				}

				for(var j = list.Count - 1; j > i; j--)
				{
					if(list[i] < list[j])
					{
						var tmp = list[i];
						list[i] = list[j];
						list[j] = tmp;

						list.Reverse(i + 1, list.Count - (i + 1));
						permutations.Add(list.ToArray());
						break;
					}
				}
			}

			return permutations;
		}
	}
}


Measured memory_bytes: 19932
import fractions

a,b,c,d = map(int,input().split())
tn = b-a+1

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//fractions.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

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

int main() {
	int N;
	while(cin >> N, N) {
		vector<int> a, b;
		a.resize(N);
		b.resize(N);
		for(int i = 0; i < N; i++)
			cin >> a[i];
		for(int i = 0; i < N; i++)
			cin >> b[i];
		sort(a.rbegin(), a.rend());
		sort(b.rbegin(), b.rend());
//		for(int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl;
//		for(int i = 0; i < b.size(); i++) cout << b[i] << " "; cout << endl;
		bool flg = true;
		int win = 0, j = 0;
		for(int i = 0; i < N-1 && flg; i++) {
			if(b[j] < a[i]) {
				win++;
			} else {
				j++;
			}
			if(win > (i+1)/2) {
				flg = false;
				cout << i+1 << endl;
			}
		}
		if(flg)
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 1436