akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
      



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            var sum = a.Sum();
        
            long sunuke = 0;
            long arai = sum;
            sunuke += a[0];
            arai -= a[0];
            var ans = Math.Abs(arai - sunuke);
            for (int i = 1; i < n-1; i++)
            {
                sunuke += a[i];
                arai -= a[i];
                if (Math.Abs(arai - sunuke) < ans) ans = Math.Abs(arai - sunuke);
            }
            Console.WriteLine(ans);
          

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 36548
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
    }
    cout << ceil((n - 1) / double(k - 1));

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

void solve()
{
    ll R,D,X;
    cin >> R >> D >> X;
    ll ans = 0;
    for2(i,1,11) {
        X = R * X - D;
        cout << X << endl;
    }
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}


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

// types - only for stuff used a lot 
using ll = long long;
#define vv vector
#define Pp pair

// IO
#define get(x) scanf("%d",&x)
#define getl(x) scanf("%lld",&x);

// Operations
#define pb push_back
#define pob pop_back
#define sz(a) int(a.size()) 
#define re(a,b) a=max(a,b) // relax
#define ri(a,b) a=min(a,b) // relaxi

// Debugging

#ifndef LOCAL
#define cerr if (0) cerr
#else
#define cerr cout
#endif

#define print(arr,n) {for (int _ = 0; _ < n; _++) cerr<<arr[_]<<" "; cerr << endl; }
#define printv(vec)  {for (int _ : vec) cerr<<_<<" "; cerr<<endl;}

const int mod = 1e9+7, oo = 1e9;
const ll loo = 1e18;

// Functions 
ll modpow(ll a, ll b) {
	ll ans = 1; // faster modpow than recursive
	for (; b; b/=2,a=a*a%mod)
		if (b&1) ans = (ans*a)%mod;
	return ans;
}
ll gcd(ll a, ll b) {
	while (a) b%=a,swap(a,b);
	return b;
}
#define bitcount __builtin_popcountll
#define f(i,a,b) for (int i = a; i < b; i++)
#define fr(i,a,b) for (int i = b-1; i >= a; i--)


/* 

   ALRIGHT HACKERS, THIS IS WHERE THE ACTUAL CODE BEGINS

 */

const bool DEBUG = 1;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	if (DEBUG) freopen("input.txt", "r", stdin);
	if (DEBUG) freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n;
	cin >> n;
	ll a[n];
	f(i,0,n) cin >> a[i];
	sort(a,a+n);
	if (n == 2) {
		if (a[0]-a[1]>a[1]-a[0])
			cout << a[0]-a[1] << endl << a[0] << " " << a[1] << endl;
		else 
			cout << a[1]-a[0] << endl << a[1] << " " << a[0] << endl;
	} else {
		stringstream ss;
		if (a[0] <= 0 && a[n-1] >= 0) {
			f(i,1,n-1) {
				if (a[i] <= 0) {
					ss << a[n-1] << " " << a[i] << endl;	
					a[n-1] -= a[i];
				} else {
					ss << a[0] << " " << a[i] << endl;
					a[0] -= a[i];
				}
			}	
			ss << a[n-1] << " " << a[0] << endl;
			cout << a[n-1] - a[0] << endl;
		} else {
			if (a[0] < 0) sort(a,a+n,greater<int>());
			ss << a[0] << " " << a[n-1] << endl;
			a[n-1] = a[0] - a[n-1];
			f(i,1,n-2) {
				ss << a[n-1] << " " << a[i] << endl;
				a[n-1] -= a[i];
			}
			if (a[n-1] - a[n-2] > a[n-2] - a[n-1]) {
				ss << a[n-1] << " " << a[n-2] << endl;
				cout << a[n-1] - a[n-2] << endl;	
			} else {
				ss << a[n-2] << " " << a[n-1] << endl;
				cout << a[n-2] - a[n-1] << endl;
			}
		}
		cout << ss.str() << endl;
	}

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}




Measured memory_bytes: 6148
N = int(input())
X = [0]*N
U = [0]*N

sum_ = 0
for i in range(N):
  x_tmp,u_tmp = input().split()
  x_tmp = float(x_tmp)
  if u_tmp == 'JPY':
    sum_ += x_tmp
  else:
    sum_ += x_tmp*380000

print(sum_)

Measured memory_bytes: 3060
n, m = [int(_) for _ in input().split(' ')]
a = [int(_) % m for _ in input().split(' ')]

s = [0]
for i in range(n):
    s.append((s[i] + a[i]) % m)
s.sort()
s.append(-1)

answer = 0

c = 0
for i in range(n + 1):
    if s[i + 1] == s[i]:
        c += 1
    else:
        answer += c * (c + 1) // 2
        c = 0
print(answer)

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

int main() {
int A, B, C;
cin >> A >> B >> C;
int cnt=0;
while (A%2==0 && B%2==0 && C%2==0)
{
  cnt++;
   int a=A/2, b=B/2, c=C/2;
   A=b+c; B=a+c; C=a+b;
  if(A==B && C==B)
  {
    cnt=-1;
    break;
  }
}
cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    #部分集合のサイズnの時n+1個の部分集合
    n=int(input())
    if 2*n!=int((2*n)**0.5)*(int((2*n)**0.5)+1):
        print("No")
        exit()
    print("Yes")
    l=int((2*n)**0.5)
    print(l+1)
    work=[[] for _ in range(l+1)]
    now_sub=0
    next_sub=1
    for i in range(1,n+1):
        if len(work[now_sub])==l:
            now_sub+=1
            next_sub=now_sub+1
        work[now_sub].append(i)
        work[next_sub].append(i)
        next_sub+=1
    
    for i in range(l+1):
        print("{} {}".format(l," ".join(map(str,work[i]))))

main()


Measured memory_bytes: 14096
import sys
from operator import itemgetter
import collections


def r(s):
    m = 0
    cnt = 0
    for n in s:
        if n in ['A', 'C', 'G', 'T']:
            cnt = cnt + 1
            m = max(m, cnt)
        else:
            cnt = 0
    return m


def main():
    input = sys.stdin.readline
    s = str(input()).strip()

    print(r(s))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    string S;
    int N;
    cin >> N >> S;
    vector<int> vr(N, 0), vg(N, 0), vb(N, 0);
    int rcnt = 0;
    int gcnt = 0;
    int bcnt = 0;
    rep(i, N) {
        if (S[i] == 'R') {
            rcnt++;
        }
        if (S[i] == 'G') {
            gcnt++;
        }
        if (S[i] == 'B') {
            bcnt++;
        }
        vr[i] = rcnt;
        vg[i] = gcnt;
        vb[i] = bcnt;
    }
    int tgt;
    ll ans = 0;
    rep(i, N-1) {
        rept(j, i+1, N) {
            if ((S[i] == 'G' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'G')) {
                ans += vr[j-1] - vr[i];
                if ((i+j) % 2 == 0) {
                    tgt = (i+j) / 2;
                    if (S[tgt] == 'R') ans--;
                }
            }
            if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R')) {
                ans += vg[j-1] - vg[i];
                if ((i+j) % 2 == 0) {
                    tgt = (i+j) / 2;
                    if (S[tgt] == 'G') ans--;
                }
            }
            if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
                ans += vb[j-1] - vb[i];
                if ((i+j) % 2 == 0) {
                    tgt = (i+j) / 2;
                    if (S[tgt] == 'B') ans--;
                }
            }
        }
    }
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

int main(){
    ll N; cin >> N;
    vector<ll> x(N),sorted_x(N);
    for(int i=0;i<N;++i){
        cin >> sorted_x[i];
        x[i] = sorted_x[i];
    }
    sort(sorted_x.begin(),sorted_x.end());
    if(N%2)++N;
    ll median = sorted_x[N/2-1];
    for(int i=0;i<N;++i){
        if(x[i] <= median){
            cout << sorted_x[N/2] << endl; 
        }else cout << median << endl;
    }
}

Measured memory_bytes: 5376
N = int(input())
A = list(map(int, input().split()))

D = dict()
for i in range(N):
    if A[i] not in D:
        D[A[i]] = 1
    else:
        D[A[i]] += 1
res = 0
for k,v in D.items():
    tmp = v - k 
    if tmp < 0:
        res += v
    else:
        res += tmp
print(res)

Measured memory_bytes: 18168
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;



long long int N,M,K,A[35]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    cout<<A[N-1]<<endl;
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <climits>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int array[32];
void search(int n, int depth)
{
	if(n == 0){
		rep(i, depth){
			printf("%s%d", i?" ":"", array[i]);
		}
		puts("");
	}else{
		for(int i=min(n, depth?array[depth-1]:INT_MAX); i; --i){
			array[depth] = i;
			search(n-i, depth+1);
		}
	}
}

int main()
{
	int n;
	while(scanf("%d", &n), n){
		search(n, 0);
	}

	return 0;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

yakusu = make_divisors(N)
l = len(yakusu)
if l % 2 == 0:
    i = yakusu[l//2-1]
    j = yakusu[l//2]
else:
    i = yakusu[l//2]
    j = yakusu[l//2]

ans = i + j - 2
print(ans)



Measured memory_bytes: 3272
#include <bits/stdc++.h>
#include <algorithm>
#include <stack>
using namespace std; 
int main(){
	int N; 
	string S; 
	cin >> N >> S; 
	int r = 0; int b = 0; 
	for(int i = 0; i < N; i++){
		if(S.at(i) == 'R') r++; 
		else b++; 
	}
	if(r > b) cout << "Yes" << endl; 
	else cout << "No" << endl; 
}

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

int main(){
 int n;
 double m,sig;

 while(1){
  cin >> n ;
  if(n==0)break;

  double s[n],sum=0;
  for(int i=0;i<n;i++){
   cin >> s[i] ;
   sum+=s[i];
  }

  m=sum/n;
  sum=0; 

  for(int i=0;i<n;i++){
   sum+=(s[i]-m)*(s[i]-m);
  }

  sig=sqrt(sum/n);

  cout << fixed << sig << endl;
 }

 return 0;
}

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

int main(){
	
	for(int w,d;cin>>w>>d,w;){
		int ans=0,tmp;
		map<int,int>M;
		for(int i=0;i<w;i++){
			cin>>tmp;
			M[tmp]++;
			ans+=tmp;
		}
		for(int i=0;i<d;i++){
			cin>>tmp;
			if(M[tmp]>0)M[tmp]--;
			else ans+=tmp;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			int P = sc.nextInt();
			if (N == 0 && M == 0 && P == 0) {
				break;
			}
			int a = 0;
			int b = 0;
			for (int i = 0; i < N; i++) {
				int t = sc.nextInt();
				if (i + 1 == M) {
					b = t;
				}
				a += t;
			}
			if (b == 0) {
				System.out.println(0);
			} else {
				int ans = (100 - P) * a / b;
				System.out.println(ans);
			}
		}
	}
}


Measured memory_bytes: 36900
while True:
  n = int(input())
  if n == 0:
    break

  pairs = []
  for _ in range(n):
    p, h, w = map(int, input().split())
    bmi = w / (h / 100) ** 2
    pairs.append((p, bmi))
  pairs.sort()
  print(min(pairs, key=lambda x:abs(x[1] - 22))[0])



Measured memory_bytes: 5632
#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    cout << setprecision(16);

    int N;
    cin >> N;
    vector<double> A(N), B(N);

    for (auto &a : A)
        cin >> a;

    for (auto &b : B)
        cin >> b;

    int maximum = 0;

    for (int i = 1; i < N; i++)
        if (A[i] > A[maximum])
            maximum = i;

    rotate(A.begin(), A.begin() + maximum, A.end());
    rotate(B.begin(), B.begin() + maximum, B.end());
    A.push_back(A.front());
    B.push_back(B.front());

    vector<double> C(N + 1, 0);

    for (int i = 1; i < N; i++)
        C[i + 1] = 2 * C[i] - C[i - 1] - 2 * B[i];

    dbg(A);
    dbg(B);
    dbg(C);
    vector<pair<int, double>> hull = {{0, A[0] + C[0]}};

    auto &&interpolate = [](pair<int, double> p1, pair<int, double> p2, int x) {
        int dx = p2.first - p1.first;
        int left = x - p1.first;
        int right = p2.first - x;
        return (p1.second * right + p2.second * left) / dx;
    };

    auto &&bad_middle = [&](pair<int, double> p1, pair<int, double> p2, pair<int, double> p3) {
        return p2.second <= interpolate(p1, p3, p2.first);
    };

    for (int i = 1; i <= N; i++) {
        int x = i;
        double y = A[i] + C[i];

        while (hull.size() >= 2 && bad_middle(hull[hull.size() - 2], hull.back(), {x, y}))
            hull.pop_back();

        hull.emplace_back(x, y);
    }

    dbg(hull);
    vector<double> answer(N + 1, 0);

    for (int i = 0; i < int(hull.size()) - 1; i++) {
        int x1 = hull[i].first;
        int x2 = hull[i + 1].first;

        for (int x = x1; x <= x2; x++)
            answer[x] = interpolate(hull[i], hull[i + 1], x) - C[x];
    }

    dbg(answer);
    double total = 0;

    for (int i = 0; i < N; i++)
        total += answer[i];

    cout << total / N << '\n';
}


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

long fact(long);

int main()
{
	long n;
	cin >> n;
	cout << fact(n) << endl;
	return 0;
}

long fact(long n)
{
	if (n > 0)
	{
		return n*fact(n-1);
	}
	else{
		return 1;
	}
}

Measured memory_bytes: 1160
//Vivek
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(i) int(i.size())
#define setto(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define inf LONG_MAX
const int mod = 1000000007;

using namespace std;

#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}
template<class T> void smax(T& a, T val) {if (a < val) a = val;}
template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}

const int N = 2*1e5 + 10;

int f[N];
ll ans = 0;

int main(){_

	int n, k;
	cin>>n>>k;

	for (int i = 1; i <= n; ++i)
	{
		f[i%k]++;
	}

	for (int a = 0; a < k; ++a)
	{
		int b = k-a;
		int c = k-a;
		b %= k, c %= k;
		if((b+c)%k != 0)continue;
		ans += f[a]*1LL*f[b]*1LL*f[c];
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

struct edge {
  int to, cost;
  edge(int x, int y) : to(x), cost(y) {}
};
typedef pair<int, int> P;
int main() {
  int h, w;
  cin >> h >> w;
  int ch, cw;
  cin >> ch >> cw;
  ch--; cw--;
  int dh, dw;
  cin >> dh >> dw;
  dh--; dw--;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) {
    cin >> s.at(i);
  }
  // id := i * w + j
  vector<vector<edge>> g(h*w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s.at(i).at(j) != '.') continue;
      int n = i * w + j;
      int b = n + w;
      int r = n + 1;
      if (i < h-1 && s.at(i+1).at(j) == '.') {
        g.at(n).push_back(edge(b, 0));
        g.at(b).push_back(edge(n, 0));
      }
      if (j < w - 1 && s.at(i).at(j+1) == '.') {
        g.at(n).push_back(edge(r, 0));
        g.at(r).push_back(edge(n, 0));
      }
      for (int k = -2; k <= 2; ++k) {
        for (int l = -2; l <= 2; ++l) {
          if (k == 0 && l == 0) continue;
          if (i + k < h && j + l < w && i + k >= 0 && j + l >= 0 && s.at(i + k).at(j + l) == '.') {
            int x = (i + k) * w + j + l;
            g.at(n).push_back(edge(x, 1));
            g.at(x).push_back(edge(n, 1));
          }
        }
      }
    }
  }


  priority_queue<P, vector<P>, greater<P>> que;
  vector<int> d(h*w, 1000000);
  d.at(ch * w + cw) = 0;
  que.push(P(0, ch * w + cw));

  while (!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (d.at(v) < p.first) continue;
    for (int i = 0; i < g.at(v).size(); ++i) {
      edge e = g.at(v).at(i);
      if (d.at(e.to) > d.at(v) + e.cost) {
        d.at(e.to) = d.at(v) + e.cost;
        que.push(P(d.at(e.to), e.to));
      }
    }
  }
  if (d.at(dh * w + dw) >= 1000000) {
    cout << -1 << endl;
  } else {
    cout << d.at(dh * w + dw) << endl;
  }
  return 0;
}


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

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

    int n;
    cin >> n;
    
    string s;
    cin >> s;
    
    int count = 0;
    for(int i = 1; i < n; i++){ 
        if(s[i]=='E'){
            count++;
        }
    }
    int min_count = count;
    
    for(int i = 1; i < n; i++){
        if(s[i-1]=='W'){
            count++;
        }
        if(s[i]=='E'){
            count--;
        }
        min_count = min(min_count,count);
    }
    cout << min_count << endl;
    
}


Measured memory_bytes: 720
import sys
import math

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N] = string_to_int(inputs[0])
    num = N - 1
    if num == 0:
        return 0
    if num == 1:
        return 1
    if num % 2 == 0:
        # half_l = math.floor(num / 2)
        # half = (half_l + half_l + 1) / 2
        half = num // 2
        append = num // 2
    else:
        half = (num + 1) // 2
        append = 0
        # half = math.floor(num / 2)
    return half * num + append


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064
N =int(input())
H = list(map(int,input().split(" ")))

def fun(lst):
    if len(lst) == 1:
        return "Yes"
    for i in reversed(range(1,len(lst))):
        
        if lst[i-1] - lst[i] == 1:
            lst[i-1] = lst[i-1]-1
        if lst[i-1] <= lst[i]:
            pass
        else:
            return "No"
    return "Yes"

print(fun(H))

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

using namespace std;

const int maxn = 100 + 5;

int main() {
	string s;
	cin >> s;
	for(int i = 0; i < (int)s.size(); i++) {
		if(i % 2 == 0) cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int main() {
  int r,D,x;
  cin>>r>>D>>x;
  x=r*x-D;
  
  for (int i=1;i<=10;i++) {
    cout<<x<<endl;
      
    x*=r;
    x-=D;
  
  }
}

Measured memory_bytes: 256
n,m,= map(int,input().split())  #n:カード，m:ゲートの数

l = [0]*m
r = [0]*m

for i in range(m):
    l[i],r[i] = map(int,input().split())
    


lmax = max(l)
rmin = min(r)

if (lmax<=rmin):
    print(rmin-lmax+1)
else:
    print(0)


Measured memory_bytes: 10868
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

class Edge(val node:Int, val cost:Int)
class State(val cost:Int, val position:Int, val prenode:Int) : Comparable<State> {
    override fun compareTo(other: State): Int {
        return if (cost == other.cost) position.compareTo(other.position) else cost.compareTo(other.cost)
    }
}

fun dijkstra(adj: Array<MutableList<Edge>>, start: Int): Array<Int> {
    val n = adj.count()
    val dist = Array(n) { Int.MAX_VALUE }
    val preNodes = (0 until n).toMutableList()
    val heap = PriorityQueue<State>()
    dist[start] = 0
    heap.add(State(0, start, 0))
    while (heap.count() > 0) {
        val state = heap.poll()
        val cost = state.cost
        val position = state.position
        val prenode = state.prenode
        if (cost > dist[position]) continue
        preNodes[position] = prenode
        for (edge in adj[position]) {
            val next = State(cost + edge.cost, edge.node, position)
            if (next.cost < dist[next.position]) {
                heap.add(next)
                dist[next.position] = next.cost
            }
        }
    }
    return dist
}

fun PrintWriter.solve(sc: FastScanner) {
    val v = sc.nextInt()
    val e = sc.nextInt()
    val r = sc.nextInt()
    val adj = Array(v) { mutableListOf<Edge>() }
    for (i in 0 until e) {
        val s = sc.nextInt()
        val t = sc.nextInt()
        val d = sc.nextInt()
        adj[s].add(Edge(t, d))
    }
    val dist = dijkstra(adj, r)
    for (d in dist) {
        if (d == Int.MAX_VALUE) {
            println("INF")
        } else {
            println(d)
        }
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}



Measured memory_bytes: 126500
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {

	int a, b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b << rt;
	}
	else if (a >= 6) {
		cout << b / 2 << rt;
	}
	else {
		cout << 0 << rt;
	}

	please AC;
}
//参考：---

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node 
{
	int key;
	Node *prev, *next;
};

Node *nil;

Node* listSearch(int key)
{
	Node *cur = nil->next;
	while(cur != nil && cur->key != key)
	{
		cur = cur->next;
	}
	return cur;
}

void init()
{
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key)
{
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

void printList()
{
	Node *cur = nil->next;
	int isf = 0;
	while(1)
	{
		if(cur == nil) break;
		if(isf++ > 0) printf(" ");
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t)
{
	if(t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst()
{
	deleteNode(nil->next);
}

void deleteLast()
{
	deleteNode(nil->prev);
}

void deleteKey(int key)
{
	deleteNode(listSearch(key));
}


int main()
{
	int key,n,i;
	int size = 0;
	char com[20];
	int np = 0,nd = 0;
	scanf("%d",&n);
	init();
	for(i = 0; i < n; i++)
	{
		scanf("%s%d",com,&key);
		if(com[0] == 'i')
		{
			insert(key);
			np++;
			size++;
		}
		else if(com[0] == 'd')
		{
			if(strlen(com) > 6)
			{
				if(com[6] == 'F') deleteFirst();
				else if(com[6] == 'L') deleteLast();
			} else {
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	return 0;
}

Measured memory_bytes: 33944
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>

using namespace std;


int main() {
	int i, j, k;
	vector<int> nums(200,0), numt(200,0);
	string s, t;

	cin >> s >> t;


	for (i = 0; i < s.length(); i++) {
		nums[i] = s[i];
	}

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

	for (i = 0; i < t.length(); i++) {
		numt[i] = t[i];
	}

	sort(numt.begin(), numt.end(), std::greater<int>());

	for (i = 0, j = 0 ; i < 200; i++) {
		if (nums[i] == 0) continue;
		if (nums[i] < numt[j]) {
			cout << "Yes" << endl;
			goto label;
		}
		else if (nums[i] == numt[j]) {
			for (i, j; i < 200 && j < t.length(); i++, j++) {
				if (nums[i] < numt[j]) {
					cout << "Yes" << endl;
					goto label;
				}
				else if (nums[i] > numt[j]) {
					cout << "No" << endl;
					goto label;
				}
				else if (nums[i] == numt[j]) {

				}
			}

			if (i == 200 && numt[j] > 0) {
				cout << "Yes" << endl;
				goto label;
			}
			else {
				cout << "No" << endl;
				goto label;
			}
		}

		
	}





	label:

	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t =new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
            sum +=t[i];
        }
        int m = sc.nextInt();
        int[] p = new int[m];
        int[] x = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = sc.nextInt();
            x[i] = sc.nextInt();
        }

        for (int i = 0; i < m; i++) {
            int tmp = sum - t[p[i]-1] + x[i];
            System.out.println(tmp);
        }
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {      
      Scanner sc = new Scanner(System.in);
      StringBuilder s = new StringBuilder(sc.next());
      while (true) {
        int B = s.indexOf("B"); 
        if (B == -1) break;
        if (B == 0) {
          s.deleteCharAt(B);
        } else {
          s.delete(B-1,B+1);
        }
      }
      System.out.println(s);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    constexpr ll mod = 1e9 + 7;

    int n, m; cin >> n >> m;
    vector<bool> d(n+1, false);
    REP(i, m){
        int a; cin >> a;
        d[a] = true;
    }

    vector<ll> dp(n+1, 0ll);
    dp[0] = 1;
    
    REP(i, n){
        if(i + 1 <= n && !d[i + 1]){
            (dp[i + 1] += dp[i]) %= mod;
        }
        if(i + 2 <= n && !d[i + 2]){
            (dp[i + 2] += dp[i]) %= mod;
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


#define ll int


int main(){
    ll n,m;
    while(cin>>n>>m){
        if(n==0){break;}
        vector<string> a(n);
        for(auto &I:a){cin>>I;}
        if(m<=25){
            vector<ll> dp(1LL<<m,-1000000);
            dp[0]=0;
            vector<ll> A(n);
            for(int i=0;i<n;i++){
                for(int t=0;t<m;t++){A[i]<<=1; A[i]^=(int)(a[i][t]-'0');}
            }
            for(int i=0;i<n;i++){
                for(int t=0;t<(1LL<<m);t++){
                    if((t^A[i])==t){
                        dp[t^A[i]]++;
                    }
                    else if((t^A[i])<t){
                        if(dp[t^A[i]]==dp[t]){
                            dp[t^A[i]]++;
                            dp[t]++;
                        }
                        else if(dp[t^A[i]]>dp[t]){
                            dp[t]=dp[t^A[i]]+1;
                        }
                        else{
                            dp[t^A[i]]=dp[t]+1;
                        }
                    }
                }
            }
            cout<<dp[0]<<endl;
        }
        else{
            const ll size=500;
            vector<bitset<size>> A(n);
            for(int i=0;i<n;i++){
                for(int t=0;t<m;t++){A[i]<<=1; A[i]^=(int)(a[i][t]-'0');}
            }
            vector<ll> cnt(1LL<<n,0);
            vector<bitset<size>> X(1LL<<n);
            ll ans=0;
            vector<ll> N(1LL<<n,0);
            for(ll i=0;i<n;i++){
                N[1LL<<i]=i;
            }
            for(ll i=1;i<(1LL<<n);i++){
                ll bef=i&(i-1);
                cnt[i]=cnt[bef]+1;
                X[i]=X[bef]^A[N[i^bef]];
                if(X[i].none()){ans=max(ans,cnt[i]);}
            }
            cout<<ans<<endl;
        }
    }
    
    
    
    return 0;
}



Measured memory_bytes: 152432
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int main()
{
	int n;cin>>n;
	int a[105];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		if(i%2==1&&a[i]%2==1)
		sum++;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
const int MOD=1e9+7;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}
int main(void)
{
    bool correct[4];
    memset(correct,true,sizeof(correct));
    int a,b;
    cin >> a >> b;
    correct[a]=false;
    correct[b]=false;
    if(correct[1]) cout << 1 << endl;
    else if(correct[2]) cout << 2 << endl;
    else if(correct[3]) cout << 3 << endl;
    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

int main(){
   int n,k;
   cin >> n >> k;
   vector<int> a;
   REP(i,n){
       int x;
       cin >> x;
       if(x < k) a.push_back(x);
   }

   int m = a.size();
   sort(all(a));

   // bitsetで作ることのできる部分和の位置のフラグをたてていく
   // b[i][0][j] := i番目までのカードを使って、jを作ることができるかどうか
   // b[i][1][j] := N ~ i番目までのカードを使って、jを作ることができるかどうか
   // (作れる数字セット) = (前までの和で作れるセット) | (前までの和で作れるセット + 対象の数字を選ぶことによる並行移動)
   bitset<5001> b[m][2];
   b[0][0] = 1;
   b[m - 1][1] = 1;
   REP(i, m - 1) b[i + 1][0] = b[i][0] | (b[i][0] << a[i]);
   REP(i, m - 1) b[m - i - 2][1] = b[m - i - 1][1] | (b[m - i -1][1] << a[m - i -1]);

   int ok = m, ng = -1;
   while(ok - ng > 1){
        int mid = (ok + ng) / 2;
        bool flag = false;

        for(int i = k - a[mid]; i < k; i++){
            for(int j = 0; j < i + 1; j++){
                if(b[mid][0][j] && b[mid][1][i - j]){
                    // mid 意外で k - a_mid 以上 k 以下の値を作ることができる場合
                    flag = true;
                    break;
                }
            }
        }

       if(flag) ok = mid;
       else ng = mid;
   }
   cout << ok << endl;

   return 0;
}

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

typedef pair<int, int> P;

int main() {

    int n;
    cin >> n;
    ll a[n+1];
    ll b[n];
    rep(i,n+1) cin>> a[i];
    rep(i,n) cin >> b[i];

    ll ans = 0;
    ll tmp;
    rep(i,n){
        tmp = min(a[i],b[i]);
        b[i] -= tmp;
        ans += tmp;
        tmp = min(a[i+1],b[i]);
        a[i+1] -= tmp;
        ans += tmp;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1792
# -*- coding:utf-8 -*-
import math
import sys
a, b, x = map(int,input().split())
"""
if a == b:
    if a%x == 0:
        print(1)
    else:
        print(0)
    sys.exit()
"""
if a%x == 0:
    ans= b // x - a // x + 1
else:    
    ans= b // x - a // x

print(ans)

"""
for tmp in range (a, b+1):
    if tmp % x == 0:
        ans += 1
"""

Measured memory_bytes: 3064
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
            int h = s.nextInt();
            int w = s.nextInt();
            int n = s.nextInt();
            int d = Math.max(h, w);
            if(n%d==0)
                System.out.println(n/d);
            else
                System.out.println(n/d +1);
    }
}


Measured memory_bytes: 23892
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,K = (int(_) for _ in input().split())
    S = list(int(_) for _ in input())
    now = 1
    cnt = 0
    Nums = []
    ans = 0
    left = 0
    right = 0
    tmp = 0
    for i in range(N):
        if(S[i]==now):
            cnt+=1
        else:
            Nums.append(cnt)
            now = 1 - now
            cnt=1
    if(cnt!=0):
        Nums.append(cnt)
    if(len(Nums)%2 == 0):
        Nums.append(0)
    Add = 2 * K +1
    sum = []
    sum.append(0)
    for i in range(0,len(Nums)):
        sum.append(sum[i] + Nums[i])
        
    for i in range(0,len(Nums),2):
        left = i
        right = min(i+Add,len(Nums))
        tmp = sum[right] - sum[left]
        # while(Nextleft>left):
        #     tmp -= Nums[left]
        #     left +=1
        # while(Nextright>right):
        #     tmp += Nums[right]
        #     right +=1        
        ans = max(tmp,ans)
    print(ans)
    
if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
	int n, r, p, c;

	while(true) {
		cin >> n >> r;
		if(n == 0 && r == 0) break;

		vector<int> cards(n);

		for(int i = 0; i < n; ++i) {
			cards.at(n - i - 1) = i + 1;
		}

		for(int i = 0; i < r; ++i) {
			cin >> p >> c;

			vector<int> temp_p;
			vector<int> temp_c;

			copy_n(cards.begin(), p - 1, std::back_inserter(temp_p));
			copy_n(cards.begin() + p - 1, c, std::back_inserter(temp_c));

			copy(temp_c.begin(), temp_c.end(), cards.begin());
			copy(temp_p.begin(), temp_p.end(), cards.begin() + c);
		}

		std::cout << cards.at(0) << std::endl;
	}

	return 0;
}

Measured memory_bytes: 2996
def answer(in0):

    _in = in0.split(' ')
    N = int(_in[0])
    Y = int(_in[1])

    a, b, c = 0, 0, 0

    for a in range(N + 1):
        for b in range(N + 1):
            c = N - (a + b)
            if c >= 0 and (10000 * a) + (5000 * b) + (1000 * c) == Y:
                print('{} {} {}'.format(a, b, c))
                return

    print("-1 -1 -1")


answer(input())

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1000;
int num[maxn];
int main() {
	//freopen("in","r",stdin);
	memset(num,0,sizeof(num));
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>num[i];
	for(int i=n-1;i>=0;i--) {
		printf("%d%c",num[i],(i==0)?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

vin par(200);
vin deep(200);
void init(int n);
int root(int x);
void unite(int x,int y);
bool same(int x,int y);
int a,b,c,res;

int kruskal(int n,int m){
    vector<tuple<int,int,int>> edge;
    rep(i,m){
        cin>>a>>b>>c;
        edge.push_back(make_tuple(c,a,b));
    }
    sort(all(edge));
    init(n);
    res=0;
    for(auto e:edge){
        if(!same(get<1>(e),get<2>(e))){
            unite(get<1>(e),get<2>(e));
            res+=get<0>(e);
        }
    }
    return res;
}

int main(){
    int n,m;
    queue<int> ans;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        ans.push(kruskal(n,m));
    }
    while(ans.size()){
        cout<<ans.front()<<endl;
        ans.pop();
    }
}

void init(int n){
    rep(i,n+1){
        par[i]=i;
        deep[i]=0;
    }
}
int root(int x){
    if(par[x]==x)return x;
    else return par[x]=root(par[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return;
    if(deep[x]<deep[y])par[x]=y;
    else{
        par[y]=x;
        if(deep[x]==deep[y])deep[x]++;
    }
}
bool same(int x,int y){
    return root(x)==root(y);
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    string ans = "No";
    if( (a==b) || (b==c) || (c==a) )
    {
        ans = "Yes";
        if ((a==b)&&(b==c))
        {
            ans = "No";
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    g = LIR(n)
    g.sort()
    ans = 0
    for a,b in g:
        if m <= b:
            ans += a*m
            break
        else:
            ans += a*b
            m -= b
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 55260
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k;
	cin>>k;
	if(k%10==2||k%10==4||k%10==5||k%10==7||k%10==9)cout<<"hon";
	if(k%10==0||k%10==1||k%10==6||k%10==8)cout<<"pon";
	if(k%10==3)cout<<"bon";
	return 0;
}


Measured memory_bytes: 3576