akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
tmp = list(input())

a = int(tmp[0])
b = int(tmp[1])
c = int(tmp[2])
d = int(tmp[3])

if a + b + c + d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
    exit()
if a + b + c - d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
    exit()
if a + b - c + d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
    exit()
if a - b + c + d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
    exit()
if a + b - c - d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + '=7')
    exit()
if a - b + c - d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
    exit()
if a - b - c + d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
    exit()
if a - b - c - d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + '=7')
    exit()


Measured memory_bytes: 3064
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n = I()
max_a = x =  0
for i in range(n):
    a, b = M()
    if max_a < a:
        max_a = a
        x = b
ans = max_a + x
print(ans)

Measured memory_bytes: 75384
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
string a;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a;
    if(a.length() == 3)
        reverse(all(a));
    cout<<a;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    string s;
    cin >>s;
    cout << s.substr(0,s.size()-8) << endl;
    return 0;
}


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

int main(){
  int r,D,x;
  cin>>r>>D>>x;
  int a[12];
  a[0]=x;
  for(int i=1;i<11;i++){
    a[i]=r*a[i-1]-D;
  }
  for(int i=1;i<11;i++) cout<<a[i]<<endl;
}

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

typedef long long ll;

char s[1000005];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len-8;i++)
        printf("%c",s[i]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int F[100001];
int main()
{
	int n;
	scanf("%d", &n);
	int h[n];
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &h[i]);
	}
	F[0] = 0;
	F[1] = abs(h[1]-h[0]);
	for(int i = 2; i < n; i++)
	{
		F[i] = min( abs(h[i] - h[i-1] ) + F[i-1] , abs( h[i] - h[i-2] ) + F[i - 2]);
	}

	cout<<F[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
int main() {
	int n, q;
	std::cin >> n >> q;
	std::vector<long long int> a(n + 1, 0);
	for (auto i = 1; i <= n; ++i)
		std::cin >> a[i];
	for (auto i = 1; i <= n; ++i)
		a[i] += a[i - 1];
	for (auto i = 0; i < q; ++i) {
		int left{ 0 }, right{ 0 };
		long long int sum{ 0 }, x;
		std::cin >> x;
		while (left <= n) {
			while (right <= n && a[right] - a[left] <= x) {
				++right;
			}
			sum += right - ++left;
		}
		std::cout << sum << std::endl;
	}
}


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



int main(){long N;
cin >> N;
vector<long> a(N + 1);
erep(i, N) cin >> a.at(i);
vector<bool> vis(N + 1);
long x = 1; vis.at(1) = true; long cnt = 0;
while(x != 2){
    if(vis.at(a.at(x))){
        cout << -1 << endl;
        return 0;
    }
    vis.at(a.at(x)) = true;
    x = a.at(x);
    cnt++;
}


// cout << n / 2 + 1 << endl;
// cout << (4 - n / 2) * 2 - 1 << endl;

cout << cnt << endl;
return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    REP(i, n) cin >> h[i];
    sort(ALL(h), greater<>());

    ll ret = 0;
    FOR(i, min(k, n), n) ret += h[i];
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    const ll INF = LLONG_MAX;
    ll n, s, ans = INF;
    cin >> n >> s;
    if(n == s){
        ans = n + 1;
    }
    if(n > s){
        for(ll i = 1; i*i <= n - s; ++i){
            if((n - s) % i == 0){
                ll j = (n - s) / i;
                ll a = min(i, j);
                ll b = max(i, j) + 1;
                ll c = n - a*b;
                if(c == s - a&&c >= 0 && c < b){
                    smin(ans, b);
                }
            }
        }
    }

    for(ll b = 2; b*b <= n; ++b){
        ll m = n, sm = 0;
        while(m > 0){
            sm += m%b;
            m /= b;
        }
        if(sm == s) smin(ans, b);
    }

    if(ans != INF)cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    if(b - a == c - b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include<math.h>
int main(){
  int n,x[102],y[102],i,j,k,D1=0,D4=0;
  double D2=0.0,D3=0.0;
  scanf("%d",&n);
  for(i=0; i<n; i++)scanf("%d",&x[i]);
  for(i=0; i<n; i++)scanf("%d",&y[i]);
  for(i=0; i<n; i++)D1+=abs(x[i]-y[i]);
  for(i=0; i<n; i++)D2+=pow(x[i]-y[i],2);
  D2=pow(D2,(double)1/2);
  for(i=0; i<n; i++)D3+=pow(abs(x[i]-y[i]),3);
  D3=pow(D3,(double)1/3);
  for(i=0; i<n; i++)if(D4<abs(x[i]-y[i]))D4=abs(x[i]-y[i]);
  printf("%lf\n%lf\n%lf\n%lf\n",(float)D1,D2,D3,(float)D4);
  return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int a[n+1];
    for(int i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a,a+n);
    int sum=0;
    for(int i=n-1;i>=n-k;i--)
    {
        sum+=a[i];
    }
    printf("%d\n",sum);
    return 0;
}


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

int main() {
  // ここにプログラムを追記
  
  int page = 0;
  
  int result = 0;
  
  cin >> page;
  
  if ( page % 2 != 0) {
    result = (page + 1) / 2;
  } else {
    result = page / 2;
  }
  
  cout << result << endl;
}

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

ll time_next(ll index, ll time, ll number_station, vector<ll> &board, vector<ll> &start, vector<ll> &period){
  if(time <= start[index]){
    return start[index] + board[index];
  }else{
    ll wait = (period[index] - (time % period[index])) % period[index];
    return time + wait + board[index];
  }
}

ll calc(ll index, ll time, ll number_station, vector<ll> &board, vector<ll> &start, vector<ll> &period){
  if(index == number_station){
    return time;
  }else{
    return calc(index+1, time_next(index, time, number_station, board, start, period), number_station, board, start, period);
  }
}
  
      
int main() {
  ll n;
  cin >> n;
  vector<ll> board(n+1), start(n+1), period(n+1);
  
  for(ll i=1; i<=n; i++){
    cin >> board[i] >> start[i] >> period[i];
  }
  
  for(int i=1; i<=n; i++)
    cout << calc(i, 0, n, board, start, period) << endl;

}

Measured memory_bytes: 256
import math

s=int(input())

n=math.ceil(math.sqrt(s))

if n*n-s<0:
  n+=1

x2=n
y3=n

while x2*y3-s>10**9:
  y3-=1

y2=x2*y3-s
x3=1

print(0,0,x2,y2,x3,y3)

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

int main() {
  int N,M,d;
  cin >> N >> M;
  vector<int> city(N);
  vector<int> road(M);
  
  for (int i = 0; i < M; i++) {
    for(int j = 0; j < 2; j++) {
      cin >> road.at(j);
      city.at(road.at(j)-1)++;
    }
  }
  for (int k = 0; k < N; k++) {
    cout << city.at(k) << endl;
  }
}

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

//#define TRACE
#ifdef TRACE
#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

#define FI ios::sync_with_stdio(false); cin.tie(0);

#define LL long long

const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
const int MX = 1e5 + 5;

int main() {
	string s;
	cin >> s;
	LL sum = 0;
	for(int i=0;i<s.size();i++) {
		sum = sum + (s[i] - '0');
	}
	if(sum%9 ==0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ll long long
        #define ld long double

        int main()
        {
            tani_nachi_ke  

            long long n,k;
            cin >> n >> k;
            long long h[n];
            for(int i = 0; i < n; i++)
                cin >> h[i];
            sort(h,h+n,greater<long long>());

            long long ans = 0;
            for(int i = k; i < n; i++)
                ans += h[i];
            cout << ans << endl;







           return 0;
        }

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  char buff[8][10];
  REP(i,8) fgets(buff[i],sizeof(buff[i]),stdin);
  REP(k,3){
    char ans[8][10] = {{0}};
    REP(i,8) REP(j,8)
      ans[i][j] = buff[7-j][i];
    printf("%d\n",(k+1)*90);
    REP(i,8) puts(ans[i]);

    REP(i,8) REP(j,10) buff[i][j] = ans[i][j];
  }
  return 0;
}

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

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const int N = 200000;
int n;
int p[N];

int main() {
  fscanf(stdin, "%d ", &n);
  int res = 0, m = N;
  REP(i,n) {
    fscanf(stdin, "%d ", p+i);
    m = min(m, p[i]);
    if (p[i] <= m) res++;
  }
  fprintf(stdout, "%d\n", res); 
  return 0;
}


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

const int MAX=100005;
int N;
vector<int> S[MAX],T[MAX],U(MAX,0),state(MAX,0);
queue<int> Q;

int DP(int u){
        for(int i=0;i<T[u].size();i++){
            if(U[T[u][i]]==0){
        U[u]=max(U[u],DP(T[u][i])+1);
            }
            else U[u]=max(U[u],U[T[u][i]]+1);
        }
    return U[u];
}

int main(){
   
    int M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        T[b].push_back(a);
    }
    for(int i=0;i<N;i++){
        if(T[i].size()==0){
            U[i]++;
            state[i]=1;
    }
    }
    for(int i=0;i<N;i++){
        int a;a=DP(i);
    }
    int ans=0;
    for(int i=0;i<N;i++){
        ans=max(ans,U[i]-1);
    }
    cout<<ans<<endl;
}



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

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  int disA=x-a;
  if(disA<0){
    disA*=-1;
  }
  int disB=x-b;
  if(disB<0){
    disB*=-1;
  }
  if(disA<disB){
    cout << "A" << endl;
  }else{
    cout << "B" << endl;
  }
}

Measured memory_bytes: 256
using  System;

public class Program
{
    private int N;
    private string S;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        S = sc.Next();
        var sum = new int[N + 1];
        sum[0] = 0;
        for (int i = 0; i < N; i++)
        {
            if (S[i] == '#')
            {
                sum[i + 1] = sum[i] + 1;
            }
            else
            {
                sum[i + 1] = sum[i];
            }
        }

        int ans = int.MaxValue;

        for (int i = 0; i <= N; i++)
        {
            int leftBlack = sum[i];
            int rightBlack = sum[N] - sum[i];
            int rightWhite = (N - i) - rightBlack;
            ans = Math.Min(ans, rightWhite + leftBlack);
        }
        Console.WriteLine(ans);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 15328
// 2011/12/01 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){

	string str;
	cin >> str;

	if(cin.eof())
		break;

	int joi = 0;
	int ioi = 0;

	string::size_type index = 0;
	while(true){
		index = str.find("JOI", index);
		if(index==string::npos)
			break;
		joi++;
		index++;
	}

	index = 0;
	while(true){
		index = str.find("IOI", index);
		if(index==string::npos)
			break;
		ioi++;
		index++;
	}

	cout << joi << endl;
	cout << ioi << endl;

	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
#define ll long long 

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n , x , t;
	cin >> n >> x >> t;
	
	cout << (int)ceil((double)n/x) * t << "\n";
}


Measured memory_bytes: 3544
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
ll a[200010];
ll dp[200010][5];

void solve(){
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n+1){
        rep(j,5) dp[i][j]=0;
    }
    dp[0][0]=0;
    Rep(j,1,5) dp[0][j]=INF;
    rep(i,n){
        dp[i+1][0]=dp[i][0]+a[i];
        if (a[i]==0){
            dp[i+1][1]=min(dp[i][1],dp[i][0])+2;
            dp[i+1][3]=min(dp[i][3],dp[i][2])+2;
        }
        else{
            dp[i+1][1]=min(dp[i][1],dp[i][0])+a[i]%2;
            dp[i+1][3]=min(dp[i][3],dp[i][2])+a[i]%2;
        }
        dp[i+1][2]=min(dp[i][2],min(dp[i][1],dp[i][0]))+(1-a[i]%2);
        dp[i+1][4]=min(min(dp[i][3],dp[i][1]),min(dp[i][4],dp[i][2]))+a[i];
    }
    ll ans=INF;
    rep(j,5){
        ans=min(ans,dp[n][j]);
    }
    cout << ans << endl;
}

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

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

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

  rep(i,m){
    string s; cin >> s;

    set<string> st;
    rep(j,sz(s) - 1){ // jとj+1で分ける
      string l = s.substr(0,j+1), r = s.substr(j+1,sz(s)-j);
      
      vs vsl, vsr;
      vsl.pb(l); reverse(all(l)); vsl.pb(l);
      vsr.pb(r); reverse(all(r)); vsr.pb(r);

      rep(k,sz(vsl)) rep(n,sz(vsr)){
	st.insert(vsl[k] + vsr[n]);
	st.insert(vsr[n] + vsl[k]);
      }
    }

    cout << st.size() << endl;
    //dump(st);
  }
}


Measured memory_bytes: 3108
K = int(input())

def solve(K):
    if K == 0:
        return [3, 3, 3, 3]
    if K == 1:
        return [1, 0, 3]
    if K == 2:
        return [2, 2]
    if K <= 2 * 10**16 - 10:
        if K % 2 == 0:
            return [K//2 + 1, K//2 + 1]
        else:
            return [K//2, K//2 + 3]
    N, R = divmod(K, 10**16)
    if R != 0:
        N = N + 1
    if N <= 2:
        N = 3
    a = K//N
    r = K - N * a
    if r == 0:
        return [N - 1 + a] * N
    ret = [N + a] * N
    for i in range(N - r):
        ret[i] -= (N + 1)
        for j in range(N):
            ret[j] += 1
    return ret


ans = solve(K)
print(len(ans))
print(*ans)


Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        long X = Long.parseLong(sc.next());
        long Y = Long.parseLong(sc.next());
        
        long count = 1;
        while(true){
            X *=2;
            
            if(Y > X){
                count++;
            }else if(Y == X){
                count++;
                break;
            }else{
                break;
            }
        }
        
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#if defined(_MSC_VER)
#pragma warning(disable: 4996)  // VSでscanfを使う．
#endif

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

  int t = a + b;

  cout << min(a, b) << " " << max(0, (a + b) - n) << endl;

  return 0;
}

Measured memory_bytes: 256
import sys

n, Y = map(int, input().split())

for x in range(n + 1):
    for y in range(n + 1):
        z = (Y - 10000 * x - 5000 * y) / 1000
        if x + y + z == n and z >= 0 and z.is_integer():
            print(x, y, int(z))
            sys.exit()
print("-1 -1 -1")



Measured memory_bytes: 2940
S=input()
a=int(S[:2])
b=int(S[2:])
if a>12 or a==0:
    if b>12 or b==0:
        print('NA')
    else:
        print('YYMM')
else:
    if b>12 or b==0:
        print('MMYY')
    else:
        print('AMBIGUOUS')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include<utility>
using namespace std;
using ll = long long;


int main() {
	ll n, x, a[100],ans=0;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		if (x < a[i])break;
		ans++;
		x -= a[i];
		if (i == n - 1 && x != 0)ans--;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

area = []
for i in range(h):
    array = input()
    area.append(array)


def check(i, j):
    x_1 = max(0, j-1)
    x_2 = min(j+1, w-1)
    y_1 = max(0, i-1)
    y_2 = min(i+1, h-1)
    if area[y_1][j] == '#' or area[y_2][j] == '#' or area[i][x_1] == '#' or area[i][x_2] == '#':
        a = 0
    else:
        print('No')
        exit()

for i in range(h):
    for j in range(w):
        if area[i][j] == '#':
            check(i, j)

print('Yes')


Measured memory_bytes: 3064
program answer
  implicit none

  integer :: N, i, j
  integer, allocatable :: B(:), C(:),sum(:)

  read(*,*) N
  allocate(B(N))
  allocate(C(N))
  allocate(sum(N))
  read(*,*) B
  read(*,*) C

  sum=0
  do i = 1, N
     do j = 1, i
        sum(i)=sum(i)+b(j)
     end do
     do j = i, N
	sum(i)=sum(i)+c(j)
     end do
  end do
  write(*,*) maxval(sum)

  deallocate(B)
  deallocate(C)
  deallocate(sum)
  stop
 end program answer


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int parent(int);
int left(int);
int right(int);
int main(){
  int *T, n, i;
  scanf("%d",&n);
  T = (int*)malloc(sizeof(int) * (n+1));
  for(i=1; i<=n; i++) scanf("%d",&T[i]);
  for(i=1; i<=n; i++){
    printf("node %d: key = %d, ",i,T[i]);
    if(i != 1) printf("parent key = %d, ",T[parent(i)]);
    if(left(i) <= n) printf("left key = %d, ",T[left(i)]);
    if(right(i) <= n) printf("right key = %d, ",T[right(i)]);
    printf("\n");
  }
  return 0;
}
int parent(int n){
  return n/2;
}
int left(int n){
  return 2*n;
}
int right(int n){
  return 2*n+1;
}

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

using namespace std;
int arr[200005];
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif

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


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

const int N = 500010;

int a[N], dis[N];
int n, d;
ll b[N];

int main(){
	scanf("%d%d", &n, &d);
	int _d = d;
	for (int i = 0; i < n; ++ i){
		scanf("%d", &a[i]);
		d = dis[i] = std::min(std::abs(d - a[i]), d);
	}
	b[n - 1] = 1;
	for (int i = n - 1; i; -- i){
		if (b[i] <= a[i] / 2){
			b[i - 1] = b[i];
		}
		else{
			b[i - 1] = b[i] + a[i];
		}
	}
	int q;
	scanf("%d", &q);
	while (q --){
		int x;
		scanf("%d", &x);
		-- x;
		int _dis = x ? dis[x - 1] : _d;
		printf(b[x] <= _dis ? "YES\n" : "NO\n");
	}
	return 0;
}

Measured memory_bytes: 9728
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 100005;
 
int X,Y,Z;
int n;
struct P {
    ll x,y,z;
    bool operator<(const P&a)const {
        return x+a.y>y+a.x;
    }
} p[maxn];
 
struct cmp1 {
    bool operator()(int x,int y) {
        return p[x].x+p[y].z>p[y].x+p[x].z;
    }
};
struct cmp2 {
    bool operator()(int x,int y) {
        return p[x].y+p[y].z<p[x].z+p[y].y;
    }
};
 
bool in_silver[maxn];
int main() {
  // freopen("in.cpp","r",stdin);
    cin>>X>>Y>>Z;
    n=X+Y+Z;
    for(int i=0; i<n; i++)scanf("%lld%lld%lld",&p[i].x,&p[i].y,&p[i].z);
    sort(p,p+n);
    ll ret=0;
    priority_queue<int,vector<int>,cmp1>left_gold;
    priority_queue<int,vector<int>,cmp2>right_bronze;
    for(int i=0; i<X; i++) {
        ret+=p[i].x;
        left_gold.push(i);
    }
    for(int i=n-1; i>=X; i--) {
        ret+=p[i].z;
        right_bronze.push(i);
        if(right_bronze.size()>Z) {
            int tt=right_bronze.top();
            right_bronze.pop();
            ret-=p[tt].z;
            ret+=p[tt].y;
            in_silver[tt]=true;
        }
    }
    ll cur=ret;
    for(int i=X; i<X+Z; i++) {
        ll tmp=cur;
        tmp+=p[i].x;
        left_gold.push(i);
        int tt=left_gold.top();
        left_gold.pop();
        tmp-=p[tt].x;
        tmp+=p[tt].z;
        if(in_silver[i]) {
            tmp-=p[i].y;
            while(!right_bronze.empty()) {
                int tt=right_bronze.top();
                if(tt<=i) {
                    right_bronze.pop();
                } else {
                    right_bronze.pop();
                    in_silver[tt]=true;
                    tmp-=p[tt].z;
                    tmp+=p[tt].y;
                    break;
                }
            }
        } else {
            tmp-=p[i].z;
        }
        ret=max(ret,tmp);
        cur=tmp;
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 3196
while True:
    n, x = map(int, input().split())
    count = 0
    if not(n or x):
        break
    for i in range(1, n-1, 1):
        for j in range(i+1, n, 1):
            k = x - i -j
            if k > j and k <= n:
                count += 1
    print(count)

Measured memory_bytes: 7556
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <map>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<int> skewers(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        cin >> skewers[i];
    }
    sort(skewers.begin(), skewers.end());
    int res = 0;
    for (int i = 0; i + 1 < n * 2; i+=2) {
        res += min(skewers[i], skewers[i + 1]);
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
L, R = [int(i) for i in input().split()]
if R - L < 2019:
    print(min([(i * j) % 2019 for i in range(L, R) for j in range(L + 1, R + 1)]))
else:
    print(min([(i * j) % 2019 for i in range(L, L + 2019) for j in range(L, L + 2019)]))


Measured memory_bytes: 153840
def selection_sort(A, N):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            count += 1
    return count


N = int(input())
A = list(map(int, input().split()))
count = selection_sort(A, N)

print(" ".join(list(map(str, A))))
print(count)



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

const ll MOD = 1e9 + 7LL;
ll fact[200001], fact2[200001];

ll modPow(ll a, ll n, ll m)
{
    if(n == 0)
        return 1LL;
    ll pola = modPow(a, n/2, m)%m;
    ll celo = (pola*pola)%m;

    if(n % 2 == 0)
    {
        return celo;
    }
    else
    {
        return ((a%m)*celo)%m;
    }
}

ll nCr(ll n, ll k)
{
    return (((fact[n]*fact2[k])%MOD)*fact2[n-k])%MOD;
}

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

    fact[0] = 1LL;

    for(int i = 1; i <= 200000; ++i)
        fact[i] = ((i%MOD) * fact[i-1])%MOD;

    for(int i = 0; i <= 200000; ++i)
        fact2[i] = modPow(fact[i], MOD-2 ,MOD);

    vi v(n);

    for(auto &z : v)
        cin >> z;

    sort(all(v));

    ll resenje = 0LL;

    for(int i = k-1; i < n; ++i)
    {
        resenje = (resenje + nCr(i, k-1)*v[i])%MOD;
        //cout << resenje << '\n';
    }


    for(int i = n-k; i >= 0; --i)
    {
        resenje = (resenje - nCr(n-1-i, k-1)*v[i]);

        if(resenje < 0)
        {
            resenje += ((0-resenje)/MOD+1)*MOD;
        }

        resenje %= MOD;
    }

    cout << resenje << '\n';

    return 0;
}


Measured memory_bytes: 3712
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100100;
const long long MOD = 1000000007;
typedef pair<long long,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int 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 / gcd(a, b) * b ;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;cin >> N;
    int A=0,W=0,T=0,R=0;
    for(int i = 0;i<N;i++){
        string S;cin >> S;
        if(S == "AC") A++;
        else if(S == "TLE") T++;
        else if(S == "WA") W++;
        else R++;
    }
    cout << "AC x " << A << endl;
    cout << "WA x " << W << endl;
    cout << "TLE x " << T << endl;
    cout << "RE x " << R << endl;

}


Measured memory_bytes: 3652
d=int(input())

last=[0]*26
c=list(map(int,input().split()))
s=[list(map(int, input().split())) for _ in range(d)]

ans=[]

for i in range(d):

    #何も選択しなかったときの満足度の下がり方
    down=0
    for j in range(26):
        down+=(c[j]*((i+1)-last[j]))
    #何を選ぶか

    score=-1*(10**9)
    kouho=0
    for j in range(26):
        if score<s[i][j]-down+c[j]*((i+1)-last[j]):
            score=s[i][j]-down+c[j]*((i+1)-last[j])
            kouho=j+1
    ans.append(kouho)
    last[kouho-1]=i+1

for item in ans:
    print(item)





Measured memory_bytes: 68296
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-10;
const long double PI = acosl(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 1000005;
const int MAXV = 60;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;

struct FenwickTree {
    FenwickTree() {}
    inline void increase(int r, int c, int x) {
        for (int i = r; i <= n; i += lowbit(i))
            for (int j = c; j <= m; j += lowbit(j)) {
                a[i][j] += x;
                b[i][j] += r * x;
                d[i][j] += c * x;
                e[i][j] += r * c * x;
            }
    }
    inline int getSum(int r, int c) {
        int ans = 0;
        for (int i = r; i; i -= lowbit(i))
            for (int j = c; j; j -= lowbit(j)) {
                ans += a[i][j] * (r + 1) * (c + 1);
                ans -= b[i][j] * (c + 1);
                ans -= d[i][j] * (r + 1);
                ans += e[i][j];
            }
        return ans;
    }
    int a[MAXN][MAXN], b[MAXN][MAXN], d[MAXN][MAXN], e[MAXN][MAXN];
    inline int lowbit(int x) { return x & (-x); }
};

char text[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d", &n);
    scanf("%s", text);
    int ans = 0;
    int last = 0, cnt = 0;
    vector<int> pos;
    for (int i = 0; i < n; i++) {
        if (text[i] == 'W') {
            pos.push_back(i);
        }
    }
    int j = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (text[i] == 'R' && j < pos.size()) {
            if (i <= pos[j]) break;
            swap(text[i], text[pos[j]]);
            j++;
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4404
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		Boolean isnotEnd = true;
		while (isnotEnd) {
			String[] datasetstr = str.split(" ", 3);
			int m = Integer.parseInt(datasetstr[0]);
			int f = Integer.parseInt(datasetstr[1]);
			int r = Integer.parseInt(datasetstr[2]);
			if (m == -1 && f == -1 && r == -1) {
				isnotEnd = false;
			} else if (m == -1 || f == -1) {
				System.out.println("F");
			} else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65) {
				System.out.println("B");
			} else if (m + f >= 50) {
				System.out.println("C");
			} else if (m + f >= 30) {
				if (r >= 50) {
					System.out.println("C");
				} else {
					System.out.println("D");
				}
			} else {
				System.out.println("F");
			}
			str = br.readLine();
		}
	}
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 30;
const ll MOD = 998244353;
const int INF = 1e9;
const ld PI = asin(1) * 2;

int n;
int a[MAXN];

int main()
{
    FAST_IO;

    cin >> n;
    FOR(i ,1, n) {
        cin >> a[i];
        if (a[i]%2==0) {
            if (a[i]%3!=0 && a[i]%5!=0) {
                cout <<"DENIED";
                return 0;
            }
        }
    }

    cout << "APPROVED";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
void CountingSort(int *,int *,int );

int n;
int tA[10000000],tB[10000000];

int main(){
  int i,max=0;

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

    if(max<tA[i])max=tA[i];

  }

  for(i=1;i<=n;i++){
    tB[i]=0;
  }
  CountingSort(tA,tB,max);


  return 0;
}


void CountingSort(int A[],int B[],int k){
  int i,j;
  int C[100000];

  for (i = 0 ;i<=k;i++){
    C[i] = 0;
  }

  
  for( j = 1 ;j<= n;j++){

    C[A[j]]++;
  }


   
  for (i = 1 ;i<= k;i++){

    C[i] = C[i] + C[i-1];
  }

  for( j = n ;j>= 1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n;i++){
    if(i>1){
      printf(" ");
    }
    
    printf("%d",B[i]);
  }
  printf("\n");
}



Measured memory_bytes: 17360
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007

using namespace std;

int main(){
	
	//fastio
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int h,w;
	cin>>h>>w;
	char arr[h][w];
	ll ans[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>arr[i][j];
			ans[i][j]=0;
		}
	}

	ans[0][0]=1;
	
	for(int i=1;i<h;i++){
		if(arr[i][0]=='.'){
			ans[i][0]=1;
		}
		else if(arr[i][0]=='#'){
			break;
		}
	}
	
	for(int i=1;i<w;i++){
		if(arr[0][i]=='.'){
			ans[0][i]=1;
		}
		else if(arr[0][i]=='#'){
			break;
		}
	}

	for(int i=1;i<h;i++){
		for(int j=1;j<w;j++){
			if(arr[i][j]=='.'){
				ans[i][j]=(ans[i][j-1] + ans[i-1][j])%MOD;
			}
			else if(arr[i][0]=='#'){
				ans[i][j]=0;
			}
		}
	}
	
	cout<<ans[h-1][w-1]<<endl;

	return 0;
}

Measured memory_bytes: 9088
#include<stdio.h>

int main(void)
{
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

	if((x-r>=0 && x+r<=W)&&(y-r>=0 && y+r<=H)){
		printf("Yes\n");
	} else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 584
a[11],j,x;main(N,i){for(;scanf("%d",&N),j=N;memset(a,0,sizeof(a))){
for(getchar(),i=0;(j=getchar())!='\n';i++)if(j=='M')a[i%N]++;else if(j-'L')a[N]+=a[i%N]+1,a[i%N]=0;else a[i%N]+=a[N]+1,a[N]=0;
for(i=0;i<=N;printf(i<N?"%d ":"%d\n",a[i]),i++)for(j=N-1;j>i;j--)if(a[j]<a[j-1])x=a[j],a[j]=a[j-1],a[j-1]=x;
}}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  ll n;
  ll result = 0;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<pair<ll,int>> p;
  for (ll i = 2; i*i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt != 0) {
      p.push_back(make_pair(i, cnt));
    }
  }
  if (n != 1) {
    p.push_back(make_pair(n, 1));
  }

  for (pair<ll,int> x : p) {
    int num = x.second;
    int count = 1;
    while (1) {
      num -= count;
      if (num < 0) {
        break;
      }
      result++;
      count++;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3640
n=int(input())
a=[int(input()) for _ in range(n)]
a.sort()
a.append(0)
count=1
ans=0
for i in range(n):
    if a[i]==a[i+1]:
        count+=1
    else:
        if count%2==1:
            ans+=1
        count=1
print(ans)

Measured memory_bytes: 7388
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    need = 1
    for a in A:
        if a==need:
            need+=1


    if need!=1:
        print(N-need+1)
    else:
        print(-1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 25500
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
L = [[0]*W for i in range(H)]
R = [[0]*W for i in range(H)]
U = [[0]*W for i in range(H)]
D = [[0]*W for i in range(H)]
LAMP = [[0]*W for i in range(H)]
ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      L[i][j] = 0
    elif j == 0:
      L[i][j] = 1
    else:
      L[i][j] = L[i][j-1] + 1
    if S[i][j] == "#":
      U[i][j] = 0
    elif i == 0:
      U[i][j] = 1
    else:
      U[i][j] = U[i-1][j] + 1
      
for i in range(H-1,-1,-1):
  for j in range(W-1,-1,-1):
    if S[i][j] == "#":
      R[i][j] = 0
    elif j == W-1:
      R[i][j] = 1
    else:
      R[i][j] = R[i][j+1] + 1
    if S[i][j] == "#":
      D[i][j] = 0
    elif i == H-1:
      D[i][j] = 1
    else:
      D[i][j] = D[i+1][j] + 1
    if S[i][j] != "#":
       ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  int i;
  for(i = 0; i < n; i++) cin >> h[i];
  int flag = 1;
  for(i = n - 1; i > 0; i--) {
    if(h[i - 1] > h[i]) {
      h[i - 1]--;
    }
  }
  for(i = 0; i < n - 1; i++) {
    if(h[i] > h[i + 1]) {
      flag = 0;
      break;
    }
  }
  if(flag == 1) cout << "Yes" << endl;
  else          cout << "No" << endl;
  return 0;
}

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

using namespace std;

int N;
int ans = 0;

int digit(int x) {
  int ret = 1;
  while (x / 10 != 0) {
    x /= 10;
    ret++;
  }

  return ret;
}

void dfs(string s, bool three, bool five, bool seven) {
  if (s.size() != 0 and (s.size() > digit(N) or stoi(s) > N)) return;
  else if (three && five && seven) ans++;
  dfs(s+"3", true, five, seven);
  dfs(s+"5", three, true, seven);
  dfs(s+"7", three, five, true);
}

int main()
{
  cin >> N;
  dfs("", false, false, false);
  cout << ans;
}

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

const int N = 220000;
int bin[N], pow0[N], pow1[N];
int n, cnt;

void f(int pow[], int k, int p){ 
	int pos = k >> 1;
	if (pow[pos] == -1) f(pow, pos, p);

	pow[k] = ((k & 1) == 0 ? 1ll * pow[pos] * pow[pos] % p : 1ll * pow[pos] * pow[pos] * 2 % p);
} 
int popcount(int x) { 
	if (x == 0) return 0;
	
	int num = 0, x1 = x;
	while (x1) { 
		num += x1 & 1;
		x1 >>= 1;
	} 
	
	return (popcount(x % num) + 1);
} 

int main(){ 
	//freopen("D.txt", "r", stdin);
	
	scanf("%d", &n);
	
	cnt = 0;
	char ch = getchar();
	for (int i = 1; i <= n; ++i) { 
		ch = getchar();
		if (ch == '1') { 
			bin[i] = 1;
			++cnt;
		} 
		else bin[i] = 0;
	} 
	
	int cnt0 = cnt - 1, cnt1 = cnt + 1;
	if (cnt0 > 0) { 
		memset(pow0, -1, sizeof pow0);
		pow0[0] = 1;
		pow0[1] = 2;
		for (int i = n; i > 1; --i) if (pow0[i] == -1) f(pow0, i, cnt0);
	} 
	memset(pow1, -1, sizeof pow1);
	pow1[0] = 1;
	pow1[1] = 2;
	for (int i = n; i > 1; --i) if (pow1[i] == -1) f(pow1, i, cnt1);
	
	int sum0 = 0, sum1 = 0;
	for (int i = 1; i <= n; ++i) { 
		if (bin[n - i + 1] == 0) continue;
		if (cnt0 != 0)sum0 = (sum0 + pow0[i - 1]) % cnt0;
		sum1 = (sum1 + pow1[i - 1]) % cnt1;
	} 
	
	for (int i = 1; i <= n; ++i) { 
		if (bin[i] == 0) printf ("%d\n", 1 + popcount((sum1 + pow1[n - i]) % cnt1));
		else { 
			if (cnt0 == 0) printf("0\n");
			else printf("%d\n", 1 + popcount((sum0 - pow0[n - i] + cnt0) % cnt0));
		} 
	} 
	
	return 0;
}

Measured memory_bytes: 6256
$n=<>;
chomp($n);
$d=<>;
chomp($d);
@d = split/ /,$d;
@d=sort{$a <=> $b}@d;
$count=0;
if($d[$n/2]-$d[$n/2-1] == 0){
	$count=0;
}else{
	$count=($d[$n/2]-$d[$n/2-1]);
}
print $count;


Measured memory_bytes: 18252
def main():
    S = input()
    n = len(S)
    a = {j: i for i, j in enumerate('abcdefghijklmnopqrstuvwxyz')}
    S = [a[i] for i in S]
    dp = [10**9]*(n+1)
    dp[0] = 0

    parity = 0
    dict_parity = {0: 0}

    for i, s in enumerate(S):
        parity ^= 2**s
        ans = i+1
        if parity in dict_parity:
            ans = min(ans, dp[dict_parity[parity]]+1)
        for j in range(26):
            parity2 = parity ^ 2**j
            if parity2 in dict_parity:
                ans = min(ans, dp[dict_parity[parity2]]+1)
        dp[i+1] = ans
        if parity not in dict_parity:
            dict_parity[parity] = i+1
        elif dp[dict_parity[parity]] > ans:
            dict_parity[parity] = i+1
    print(dp[-1])


main()


Measured memory_bytes: 73980