akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename T>
std::vector<std::vector<T>> mk2d(size_t s1, size_t s2, T const& val) {
  std::vector<T> tmp(s2, val);
  return std::vector<std::vector<T>>(s1, tmp);
}

struct V { int x, y; V(int x_=0, int y_=0): x(x_), y(y_) {} };

static int dx[4] = {-1,  0, 1, 0};
static int dy[4] = { 0, -1, 0, 1};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  auto wall = mk2d<bool>(N, N, true);
  auto dist = mk2d<int>(N, N, true);
  for(int i = 0; i < N; ++i) {
    int mi = std::min(i, N-1-i);
    for(int j = 0; j < N; ++j) {
      int mj = std::min(j, N-1-j);
      dist[i][j] = std::min(mi, mj);
    }
  }
auto f = [&]() {
std::cout << "\n"; 
for(int y = 0; y < N; ++y) {
  for(int x = 0; x < N; ++x) std::cout << dist[x][y];
  std::cout << "\n";
}
};
  int ans = 0;
  for(int n = 0; n < N*N; ++n) {
    int P; std::cin >> P; --P;
    int i = P%N, j = P/N;
    ans += dist[i][j];
    // bfs
    std::queue<V> q;
    wall[i][j] = false;
    int mi = N;
    for(int k = 0; k < 4; ++k) {
        int nx = i + dx[k];
        int ny = j + dy[k];
        if(nx < 0 || ny < 0 || nx > N-1 || ny > N-1) continue;
        mi = std::min(mi, dist[nx][ny] + (wall[nx][ny]?1:0));
    }
    dist[i][j] = std::min(dist[i][j], mi);
    for(int k = 0; k < 4; ++k) {
        int nx = i + dx[k];
        int ny = j + dy[k];
        if(nx < 0 || ny < 0 || nx > N-1 || ny > N-1) continue;
        if(dist[nx][ny] > dist[i][j]) q.emplace(nx, ny);
    }
    while(!q.empty()) {
      V v = q.front(); q.pop();
      int mi = N;
      for(int k = 0; k < 4; ++k) {
        int nx = v.x + dx[k];
        int ny = v.y + dy[k];
        if(nx < 0 || ny < 0 || nx > N-1 || ny > N-1) continue;
        mi = std::min(mi, dist[nx][ny] + (wall[nx][ny]?1:0));
      }
      if(dist[v.x][v.y] <= mi) continue;
      dist[v.x][v.y] = std::min(dist[v.x][v.y], mi);
      for(int k = 0; k < 4; ++k) {
        int nx = v.x + dx[k];
        int ny = v.y + dy[k];
        if(nx < 0 || ny < 0 || nx > N-1 || ny > N-1) continue;
        if(dist[nx][ny] > dist[v.x][v.y]) q.emplace(nx, ny);
      }
    }
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 4688
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N, K;

	cin >> N >> K;
	int cnt = 0;

	for (int i = 0; i < N; i++)
	{
		int h;

		cin >> h;
		if (h >= K)
			cnt++;
	}
	cout << cnt << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int* calc(int *l,int n,int a){
  int *dp=(int *)calloc(1<<n,sizeof(int));
  dp[0]=1000000;
  for(int i=1;i<(1<<n);i++){
    int sum=0;
    int cost=-10;
    for(int j=0;j<n;j++){
      if((i>>j)&1){
	sum+=l[j];
	cost+=10;
      }
    }
    dp[i]=ABS(sum-a)+cost;
  }
  for(int i=1;i<(1<<n);i++){
    for(int j=0;j<n;j++){
      if((i>>j)&1){
	dp[i]=MIN(dp[i],dp[i^(1<<j)]);
      }
    }
  }
  return dp;
}

void run(void){
  int n,a,b,c;
  scanf("%d%d%d%d",&n,&a,&b,&c);
  int l[8];
  for(int i=0;i<n;i++) scanf("%d",l+i);
  int *dpA=calc(l,n,a);
  int *dpB=calc(l,n,b);
  int *dpC=calc(l,n,c);
  int min=1000000;
  int bit=(1<<n)-1;
  for(int i=1;i<(1<<n);i++){
    for(int j=bit^i;j>0;j=(j-1)&(bit^i)){
      int k=bit^i^j;
      if(k){
	min=MIN(min,dpA[i]+dpB[j]+dpC[bit^i^j]);
      }
    }
  }
  printf("%d\n",min);
}

int main(void){
  run();
  return 0;
}


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


int main(){
	int N;
  double M,sum,wariai,kijun;
	cin >>N >> M;
	vector<int> vec(N);
    
	for (int i = 0; i < N; i++){
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
    sum=0;
    for (int j= 0; j< N; j++){
    	sum=sum+vec.at(j);
    }
    wariai = (vec.at(M - 1)/sum);
    kijun = 1 /(4*M);

	if (wariai >= kijun){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

}

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++)

int main() {
  int x;
  cin >> x;
  int ans;
  rep(i,8) if(400 + 200 * i <= x && x <= 599 + 200 * i) cout << 8 - i << endl;
}

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

int main() {	

	double PI = atan(1)*4;
	double r;
	cin >> r;
	
	cout << fixed << setprecision(5);	
	cout << PI*r*r << " " << 2*PI*r << endl;	
	
	return 0;
}


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

int main(){
  int A, B, K;

  cin >> A >> B >> K;
  
  int out_num = B- A + 1;

  if ( 2*K >= out_num ){
    for (int i = 0; i < out_num; i++){
      cout << A + i << " ";
    }
  } else {
    for ( int i = 0; i < K; i++ ){
      cout << A + i << " ";
    }
    for ( int i = 0; i < K; i++ ){
      cout << B - K + i + 1 << " ";
    }
  }



	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

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

    int cnt = 0;
    for (int c=1; c<=N-1; ++c) {
        int target = N - c;
        double dThr = sqrt(target);
        for (int a=1; a<=dThr; ++a) {
            //int ia = int(round(da));
            int b = target / a;
            if (a * b == target) {
                if (a == b)
                    ++cnt;
                else
                    cnt += 2;
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

int main() {
  ll n;
  cin >> n;
  if(n==3) {
    cout << "2 5 63" << endl;
  }
  else if(n%2) {
    ll temp=0;
    vector<ll> ans={6,2,10,3,9,4,8,12};
    for(ll i=0;i<n;i++) {
      if(i!=0) {
        cout << " ";
      }
      cout << ans[i%8]+temp*12;
      if(i%8==7) {
        temp++;
      }
    }
  }
  else {
    ll temp=0;
    vector<ll> ans={2,10,3,9,4,8,6,12};
    for(ll i=0;i<n;i++) {
      if(i!=0) {
        cout << " ";
      }
      cout << ans[i%8]+temp*12;
      if(i%8==7) {
        temp++;
      }
    }
  }
}

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

class State implements Comparable<State>{
	int P, Y, id;
	public State(int p, int y, int i) {
		P = p; Y = y; id = i;
	}

	public int compareTo(State o) {
		return Y - o.Y;
	}
}

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int[] city_count = new int[N];
		State[] new_city = new State[M];
		String[] ans = new String[M];
		Arrays.fill(city_count, 0);
		for(int i = 0; i < M; i++) {
			int P = sc.nextInt(), Y = sc.nextInt();
			new_city[i] = new State(P, Y, i + 1);
		}
		Arrays.sort(new_city);
		for(State s : new_city) {
			city_count[s.P - 1]++;
			//make string
			String forward = String.format("%06d", s.P);
			String backward = String.format("%06d", city_count[s.P - 1]);
			ans[s.id - 1] = forward.concat(backward);
		}
		for(String str : ans) System.out.println(str);
	}
}


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

#define db(x) if(debug) cout << x << endl

bool debug = true;

using namespace std;

int a, b, c;

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

	
	cin >> a >> b >> c;
	cout << c << ' ' << a << ' ' << b << endl;
}

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

int main(){
	lli a, b, c, k; cin >> a >> b >> c >> k;
    lli sum;
    if(a>=k){
        sum=k;
    }else{
        sum=a;
        k-=a;
        if(b>=k){
            sum+=k*0;
        }else{
            sum+=(b)*0;
            k-=b;
            if(c>=k){
                sum+=k*-1;
            }else{
                sum+=(b)*-1;
                k-=b;
            }
        }
    }
    cout << sum;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
int b[1000001];
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n,v=0,count=0,one=0;

cin>>n;
int a[n];
FOR(i,n)
{
	cin>>a[i];
	if(a[i]==1)
	{
		one++;
	}
	b[a[i]]++;
}
sort(a,a+n);
if(one>=1)
{
	if(one==1)
	{
		count++;
	}
}
else
{
	FOR(i,n)
{
	FORA(j,1,sqrt(a[i]))
	{  
	if(j==1)
	{
		if(b[a[i]]>1) 
	   {
	 	 v++;
		break;
	   }
	}
	else
	{
			if(a[i]%j==0)
		{
			if(binary_search(a,a+n,j)||binary_search(a,a+n,a[i]/j))
		{    v++;
			break;
		}
		
		}
	}	
	}
	if(v>0)
	{
		v=0;
	}
	else
	{
		count++;
		v=0;
	}
}

}

cout<<count<<endl;
return  0;
}






Measured memory_bytes: 8220
#include<iostream>
using namespace std;
int bubbleSort(int A[],int N){
int cnt=0,i,j,tmp;
for(i=0;i<N;i++){
for(j=N-1;j>0;j--){
if(A[j]<A[j-1]){
tmp=A[j];
A[j]=A[j-1];
A[j-1]=tmp;
cnt++;
}

}
}
for(i=0;i<N;i++){
if(i>0)cout<<" ";
cout<<A[i];
}
cout<<endl;
cout<<cnt<<endl;
}


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

Measured memory_bytes: 1160
let a, b = Scanf.scanf " %d %d" @@ fun a b -> a, b
let f s = s.[0] = s.[4] && s.[1] = s.[3]
let ans = ref 0
let _ = for i = a to b do if f @@ string_of_int i then incr ans done; Printf.printf "%d\n" !ans

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

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

    while(true){
        int x, y;
        std::cin >> x >> y;
        if(x==0 && y==0) break;
        std::cout << std::min(x, y) << " " << std::max(x, y) << "\n";
    }
    return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string s;
	cin >> s;

	bool flag[4];

	for(int i=0; i<4; i++){
		flag[i] = false;
	}

	for(int i=0; i<s.size(); i++){
		if(s[i] == 'N') flag[0] = true;
		if(s[i] == 'W') flag[1] = true;
		if(s[i] == 'S') flag[2] = true;
		if(s[i] == 'E') flag[3] = true;
	}
	if(flag[0] == true && flag[2] == false){
		puts("No");
		return 0;
	}
	if(flag[0] == false && flag[2] == true){
		puts("No");
		return 0;
	}
	if(flag[1] == false && flag[3] == true){
		puts("No");
		return 0;
	}
	if(flag[1] == true && flag[3] == false){
		puts("No");
		return 0;
	}

	puts("Yes");
	return 0;

	return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////


ll N,Np;
char T[202020];
ll Tn;
ll p3[30];

ll i, j, k;

void salsa(ll n,ll& c,ll& d)
{
    if(1&(n^c)){
        d = d == 0 ? 0 : 3 - d;
        c ^= 1;
    }
}

pair<vector<ll>,vector<ll>> calc(ll n,char *T){
    if(n==0){
        vector<ll> P = {0};
        vector<ll> L(Tn, 0);
        return {P, L};
    }
    ll i, j, k;
    auto r = calc(n - 1, T);
    ll N = p3[n-1];
    vector<ll> &P = r.first;
    vector<ll> &L = r.second;
    vector<ll> P2(N * 3, 0), L2(Tn, 0), C(N * 3, 0), D(N * 3, 0);
    fornum(i,0,3){
        fornum(j,0,N){
            D[i * N + j] = i;
        }
    }
    ll snum = 0;
    fornum(i,0,Tn){
        ll l = L[i];
        fornum(j,0,3){
            salsa(snum, C[l + j * N], D[l + j * N]);
            if (D[l + j * N] == 2)
                L2[i] = l + j * N;
        }
        if(T[i]=='S'){
            ++snum;
        }else{
            fornum(j,0,3)
                (D[l + j * N] += 1) %= 3;
        }
    }
    fornum(i,0,N*3){
        salsa(snum, C[i], D[i]);
        P2[i] = P[i%N] + D[i] * N;
        //printf("%lld ", P2[i]);
    }
    //printf(":%lld\n", n);
    return {P2, L2};



}
int main(){
    scanf("%lld%s", &Np, T);
    Tn = strlen(T);
    p3[0] = 1;
    fornum(j,0,Np){
        p3[j + 1] = p3[j] * 3;
    }
    N = p3[Np];
    auto ret = calc(Np, T).first;
    
    fornum(i,0,N){
        printf("%lld ", ret[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 28896
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n;
  string s,ss,sss;
  cin>>a>>n;
  vi A(n);
  for(int i=0;i<n;i++){cin>>A[i];a-=A[i];}
  if(a > 0)
    cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <unordered_set>

using namespace std;

int main() {
  int N;
  cin >> N;
  unordered_set<int> D;
  for (int i = 0; i < N; ++i) {
    int d;
    cin >> d;
    D.insert(d);
  }
  printf("%d\n", (int)D.size());
}

Measured memory_bytes: 3236
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

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<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




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

    long long a, b;
    while (cin >> a >> b) {
        b = b * 2 + 1;
        cout << (a + b - 1) / b << endl;
    }
}


















Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	int A,B,C;
	int ans;

	cin >> A >> B >> C;

	if(A==B){
		ans=C;
	}else if(B==C){
		ans=A;
	}else{
		ans=B;
	}

	cout << ans  << endl;

	return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# Tenka1 Programmer Beginner Contest
# Problem B

if __name__ == '__main__':
    n = int(input())
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]

    for i in range(n):
        ai, bi = list(map(int, input().split()))
        a[i] = ai
        b[i] = bi

    a_max = max(a)
    print(a_max + b[a.index(a_max)])


Measured memory_bytes: 11288
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    l,r = map(int, input().split())
    res = 10**10
    if r-l>=2019:
        print(0)
        exit()
    else:
        for i in range(l, r):
            n = i % 2019
            for j in range(i+1, r+1):
                p = j % 2019
                res = min(res, (n*p)%2019)
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
from math import gcd
#1≦k≦2*10^2
k = int(input())

ans = 0
#O(n^3)
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, gcd(b, c))    #O((logn)^2)

print(ans)

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

int main(){
    int n;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    int max = 0;
    int num;
    for(int j = 0; j < n; j++){
        if(max < p[j]){
            max = p[j];
            num = j;
        }
    }
    p[num] = p[num]/2;
    int sum = 0;
    for(int k = 0; k < n; k++){
        sum += p[k];
    }
    cout << sum << endl;
    return 0;
}

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

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

    int cnt = 0;
    for (int i=1; i<n-1; ++i) {
        if (p[i] == max({p[i-1], p[i], p[i+1]})) continue;
        if (p[i] == min({p[i-1], p[i], p[i+1]})) continue;
        cnt ++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
L = list(input())
MOD = 10**9 + 7
ans = 1
dp = [1 for i in range(len(L))]
pow3 = [1]
lenL = len(L)
lst = 1
for i in range(lenL):
	lst = lst*3 % MOD
	pow3.append(lst)
for i in range(lenL):
	if i == 0:
		if L[lenL-1] == "0":
			dp[i] = 1
		else:
			dp[i] = 3
	else:
		if L[lenL-i-1] == '0':
			dp[i] = dp[i-1]
		else:
			dp[i] = (pow3[i] + 2*dp[i-1]) % MOD
print(dp[lenL-1])

Measured memory_bytes: 11776
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
	int n,t,a,high,average,dif=INF,key;
	cin >> n >> t >> a;
	for(int i=1; i<=n; i++){
		cin >> high;
		average=1000*t-high*6;
		if(abs(1000*a-average)<dif){
			dif=abs(1000*a-average);
			key=i;
		}
	}
	cout << key << endl;
	return 0;
}	

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var xs = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

        var ys = xs.Select((x, i) => x - 1 - i).OrderBy(x => x).ToArray();
        var m = ys[n / 2];
        Console.WriteLine(ys.Sum(x => Math.Abs(x - m)));
    }
}

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

using namespace std;

int main()
{
   int n;
   int num = 1;

   cin >> n;
   vector<int> h(n);

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

   for(int i=1;i<n;i++){
      int max = h[0];
      for(int j=0;j<i;j++){
         if(h[j] > max) max = h[j];
      }
      if(h[i] >= max) num++;
   }

   cout << num;

   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 all(a) a.begin(),a.end()
typedef long long ll;

int N,W,w0,wi,vi;
vector<ll> v[4];

ll solve(int k,int n,ll wsum,ll vsum){
	if(wsum>W)return 0;
	if(k==4)return vsum;
	if(n==(int)v[k].size())return solve(k+1,0,wsum,vsum);
	return max(solve(k,n+1,wsum+w0+k,vsum+v[k][n]),solve(k+1,0,wsum,vsum));
}

int main(void){	
	cin>>N>>W>>w0>>vi;
	v[0].push_back(vi);
	rep(i,N-1){
		cin>>wi>>vi;
		v[wi-w0].push_back(vi);
	}
	rep(k,4)sort(all(v[k]),greater<ll>());
	cout<<solve(0,0,0,0)<<endl;
	return 0;
}


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

void dfs(vector<int> adj[],bool visited[],int s,int &count){
    visited[s]=true;
    for(auto x:adj[s]){
        if(visited[x]==false){
            count++;
            dfs(adj,visited,x,count);
        }
    }
}

int main(){
    int n,m;cin>>n>>m;
    vector<int> adj[n];
    set<pair<int,int>> soul;
    while(m--){
        int x,y;
        cin>>x>>y;
        x--;y--;
        if(soul.find(make_pair(x,y))!=soul.end())continue;
        if(soul.find(make_pair(y,x))!=soul.end())continue;
        soul.insert(make_pair(x,y));soul.insert(make_pair(y,x));
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int maxx = INT_MIN;
    bool visited[n]={false};
    for(int i=0;i<n;++i){
        int count=1;
        if(visited[i]==false)dfs(adj,visited,i,count);
        maxx = max(maxx,count);
    }
    cout<<maxx;

    return 0;
}

Measured memory_bytes: 42840
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;

i64 POW(i64 x, i64 n){
    i64 res = 1;
    while(n){
        if(n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

int main(){
    i64 L, N;
    string snake;
    cin >> L >> N >> snake;

    i64 A = 0;
    for(int i = 1; i < L; i++) {
        if(snake[i-1] == snake[i] && snake[i] == 'o') A++;
    }

    cout << L + 3ll*A*(POW(2, N) - 1ll) << endl;
}


Measured memory_bytes: 3200
#include<iostream>
using namespace std;
#define INFTY (int)(1e9)

int c;

template<class T>
void merge(T A[], int left, int mid, int right){
	int n1 = mid - left, n2 = right - mid;
	T L[n1], R[n2];
	for(int i = 0; i < n1; i++){
		L[i] = A[left + i];
	}
	for(int i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	// L[n1] = INFTY;
	// R[n2] = INFTY;
	for(int k = left, i = 0, j = 0; k < right; k++){
		c++;
		if(j == n2 || i != n1 && L[i] <= R[j]){
			A[k] = L[i];
			i++;
		} else {
			A[k] = R[j];
			j++;
		}
	}
}

template<class T>
void mergeSort(T A[], int left, int right){
	if(left+1 < right){
		int mid = (left + right)/2;
		mergeSort(A,left, mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int main(){
	int A[500010], n;
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>A[i];
	}
	
	mergeSort(A,0,n);
	
	for(int i = 0; i < n; i++){
		if(i)cout<<" ";
		cout<<A[i];
	}cout<<endl;
	
	cout<<c<<endl;
	
	return 0;
}


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

int main(){
  int n,a,b;
  cin >>n >>a >>b;
  cout << min(n*a,b) << endl;
  return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n,m,l,r,q,a,b; cin >> n >> m >> q;
    vii segment(n, vi(n));
    rep(_, m) {
        cin >> l >> r;
        --l, --r;
        segment[l][r] += 1;
    }
    vii csum(n+1, vi(n+1));
    rep(i,n)rep(j,n) {
        csum[i+1][j+1] += csum[i+1][j] + segment[i][j];
    }
    rep(i,n)rep(j,n) {
        csum[i+1][j+1] += csum[i][j+1];
    }

    rep(_, q) {
        cin >> a >> b;
        --a;
        cout << csum[b][b] - csum[a][b] - csum[b][a] + csum[a][a] << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 2944
"""
分割統治法の全探索
"""
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

MAX = 2000
check = [False]*(MAX+1)

def ExhaustiveSearch(index, tmp_sum):
    global n

    if index == n:
        check[tmp_sum] = True #ハッシュ
        return
    
    ExhaustiveSearch(index+1, tmp_sum) #足さないという選択
    if tmp_sum+a[index]<2000:
        ExhaustiveSearch(index+1, tmp_sum+a[index])

ExhaustiveSearch(0, 0)
for i in range(q):
    if check[m[i]]:
        print('yes')
    else:
        print('no')
    





Measured memory_bytes: 5640
#include<stdio.h>

int main()
{
    int n, i, count=0;

    scanf("%d", &n);

    int P[n+1];

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

    for(i=2; i<n; i++){
        if((P[i-1]<=P[i] && P[i]<P[i+1]) || (P[i-1]>P[i] && P[i]>=P[i+1]))
            count++;
    }

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

    return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define int ll
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;


#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> 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;
}

const ll N_MAX = 12;
const ll M_MAX = 12;

vector<ll> A[N_MAX];

ll Asum[M_MAX];

vector<ll> C;

ll N, M, X;

signed main() {

    cin >> N >> M >> X;

    rep(i, N) {
        ll c;
        cin >> c;
        C.push_back(c);
        rep(j, M) {
            ll m;
            cin >> m;
            A[i].push_back(m);
        }
    }

    bool res = true;
    ll costBuf = 0;
    ll cost = INF;

    rep(i, 1 << N) {
        res = true;
        costBuf = 0;
        rep(j, N) {
            if (i >> j & 1) {
                costBuf += C[j];
                rep(k, M) { Asum[k] += A[j][k]; }
            }
        }
        rep(j, M) {
            if (Asum[j] < X) {
                res = false;
            }
            Asum[j] = 0;
        }
        if (res) {
            PRINT(cost)
            PRINT(costBuf)
            chmin(cost, costBuf);
        }
    }

    if (cost == INF)
        cost = -1;
    cout << cost << endl;

    return 0;
}


Measured memory_bytes: 3644
N = int(input())
red = [tuple(map(int, input().split())) for _ in range(N)]
blue = [tuple(map(int, input().split())) for _ in range(N)]

from operator import itemgetter
red = sorted(red, reverse=True)
blue = sorted(blue, key=itemgetter(1))

seen = [0] * N
ans = 0
for i in range(N):
    for j in range(N):
        if seen[j] == 0 and red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
            seen[j] = 1
            ans += 1
            break

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



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

  cout << s.substr(0, sz(s)-8) << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
const ll inf=(1ll<<61);
const ll mod=1e9+7;
const int MX=3e5+9;
int n,k;
double ans=0;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int j=i;
        double x=1;
        while(j<k){
            j*=2;
            x*=0.5;
        }
        ans+=(1.0/n)*x;
    }
    cout<<setprecision(9)<<fixed<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
  long long int x,y,k,a,b;
  int kk,aa,bb;
  scanf("%lld %lld",&x,&y);
  
  kk = 1;
  k = x;
  while(1){
    k <<=1;
    if( k>y ){
      break;
    }
    kk ++;
  }
  printf("%d\n",kk);
  
  return 0;
}


Measured memory_bytes: 128
n, a, b, c, d = [int(_) for _ in input().split(' ')]
s = input()

c1 = all([s[x:x+2] != '##' for x in range(a, c - 2)])
c2 = all([s[x:x+2] != '##' for x in range(b, d - 2)])

if c > d:
    c3 = any([s[x:x+3] == '...' for x in range(b - 2, d - 1)])
    if c1 and c2 and c3:
        print('Yes')
    else:
        print('No')
else:
    if c1 and c2:
        print('Yes')
    else:
        print('No')


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


int main(){
    string s;
    cin>>s;
    int n=s.size();
    map<char,int> mp;

    for(int i=0;i<n;i++){
        if(mp[s[i]]<=i)
        for(int j=i+1;j<n;){
            if(s[i]==s[j]){
                cout<<i+1<<" "<<j+1<<endl;
                return 0;
            }
            else if(s[i]==s[j+1]){
                j++;
                continue;
            }
            else {
                mp[s[i]]=j;
                break;
            }

        }
    }
    cout<<-1<<" "<<-1<<endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    
    ll a,b,c;
    cin >> a >> b >> c;
    if(c-a-b < 0){
        cout << "No" << endl;
    }
    else if(a*a-2*a*c-2*b*c-2*a*b+b*b >-c*c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    
    return 0;
}

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

const int maxn = 610, P = 1000000007;
int n, K, pos[maxn], sum[maxn], f[maxn][maxn], cnt[maxn];

int main() {
    scanf("%d %d", &n, &K), n <<= 1;
    for (int i = 1, a, b; i <= K; i++) {
        scanf("%d %d", &a, &b);
        pos[a] = b, pos[b] = a;
    }
    cnt[0] = 1;
    for (int i = 2; i <= n; i += 2) {
        cnt[i] = 1LL * (i - 1) * cnt[i - 2] % P;
    }
    for (int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + !pos[i];
    }
    int ans = 0;
    for (int l = 2; l <= n; l++) {
        for (int i = 1, j = i + l - 1; j <= n; i++, j++) {
            bool flag = 0;
            if ((sum[j] - sum[i - 1]) & 1) flag = 1;
            for (int k = i; k <= j && !flag; k++) {
                if (pos[k] && (pos[k] < i || pos[k] > j)) flag = 1;
            }
            if (flag) continue;
            f[i][j] = cnt[sum[j] - sum[i - 1]];
            for (int k = i; k < j; k++) {
                f[i][j] = (f[i][j] - 1LL * f[i][k] * cnt[sum[j] - sum[k]] % P + P) % P;
            }
            int t = n - K - K - (sum[j] - sum[i - 1]);
            ans = (ans + 1LL * (f[i][j] + P) * cnt[t]) % P;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int n, m; cin >> n >> m;
  struct dem { int a, b; };
  vector<dem> d(m);
  for (int i = 0; i < m; i++) {
    cin >> d[i].a >> d[i].b;
  }
  sort(d.begin(), d.end(), [](dem x, dem y) { return x.b < y.b; });
  int res = 0, t = 0;
  for (int i = 0; i < m; i++) {
    if (d[i].a < t) continue;
    t = d[i].b;
    res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,t;
  cin >> n >> t;
  int min_cost = 10000;
  for(int i = 0; i < n; ++i) {
    int c,T;
    cin >> c >> T;
    if(T <= t) min_cost = min(min_cost, c);
  }

  if(min_cost == 10000) cout << "TLE" << endl;
  else cout << min_cost << endl;
  return 0;
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;


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

    map<string,ll> mp;
    rep(i,0,n){
        string s; cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans = 0;
    for(auto i = mp.begin(); i != mp.end(); i++){
        ans += i->second*(i->second-1)/2;
    }
    cout << ans << "\n";
}

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

int main(void){
    int n,m,l;
    cin  >> n >> m >> l;

    vector<vector<int>> matrix_a(n,vector<int>(m,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> matrix_a[i][j];
        }
    }

    vector<vector<int>> matrix_b(m,vector<int>(l,0));
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin >> matrix_b[i][j];
        }
    }

    vector<vector<long>> matrix_c(n,vector<long>(l,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                matrix_c[i][j] += matrix_a[i][k]*matrix_b[k][j];
            }
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            cout << matrix_c[i][j];
            if(j==l-1){
                cout << endl;
                break;
            }
            cout << " ";
        }
    }
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int count = 0;
	for (int i=a; i<=b; i++) {
		if (c % i ==0) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int n;
    cin>>n;
    string s;
    double u;
    double sum=0;
    for(int i=0;i<n;i++){
        cin>>u>>s;
        if(s=="JPY")sum+=u;
        else sum+=u*380000.0;
    }
    cout<<sum<<endl;
    return 0;
}

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

using namespace std;

typedef long long   ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii > vpi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define MOD 1000000007LL
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (((a)*(b))/__gcd((a), (b)))
#define MAXN 

int main() {
	cin.tie(0);
	cin.sync_with_stdio(0);
	ll a, b, c;
	
	cin >> a >> b >> c;
	
	ll res = 0LL;
	
	if(c >= 1){
		res += 1LL;
		c--;		
	}

	res += min(a, c);	
	c -= min(a, c);
	
	if(b <= c)
		res += b*2LL;
	else
		res += b + c;
	
	cout << res << endl;
		
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int A[100000];

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

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

    sort(A, A+N, greater<int>());

    long long S = 1;
    int cnt = 0;
    for(int i=0; i<N-1; i++){
        if(cnt == 2) break;
        if(A[i] == A[i+1]){
            S *= A[i];
            cnt++;
            i++;
        }
    }

    if(cnt < 2){
        cout << 0 << endl;
    }else{
        cout << S << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
//main
signed main(){
  string s;cin>>s;
  int N=s.size();
  int ans=0;int now=0;
  for(int i=0;i<N;i++){
    if(s[i]=='1'){
      ans+=pw(3,N-i-1)*pw(2,now)%MOD;
      now++;
    }
    ans%=MOD;
  }
  ans+=pw(2,now);ans%=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    char[] s = scanner.next().toCharArray();
    int cnt = 0;
    for (int i = 1; i < N; i++) {
      if (s[i] == 'E') cnt++;
    }
    int min = cnt;
    for (int i = 1; i < N; i++) {
      if (s[i - 1] == 'W') cnt++;
      if (s[i] == 'E') cnt--;
      if (cnt < min) min = cnt;
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 29872
#include <algorithm>
#include <cstring>
#include <cstdio>
typedef long long ll;
int seg[800005], app[200005], lp[100005], rp[200005], n, k, cnt;
ll dp[100005], sum[100005];
inline void push_down(int u)
{
	if (~seg[u])
	{
		seg[u << 1] = seg[u << 1 | 1] = seg[u];
		seg[u] = -1;
	}
}
void modify(int u, int l, int r, int L, int R, int x)
{
	if (L > R)
		return;
	if (L <= l && r <= R)
	{
		seg[u] = x;
		return;
	}
	push_down(u);
	int m = l + r >> 1; 
	if (L <= m)
		modify(u << 1, l, m, L, R, x);
	if (m < R)
		modify(u << 1 | 1, m + 1, r, L, R, x);
}
int query(int u, int l, int r, int pos)
{
	while (l != r)
	{
		push_down(u);
		int m = l + r >> 1;
		if (pos <= m)
		{
			r = m;
			u <<= 1;
		}
		else
		{
			l = m + 1;
			u = u << 1 | 1;
		}
	}
	return seg[u];
}
inline ll calc(int pos)
{
	int res = query(1, 0, cnt - 1, pos);
	if (-1 == res)
		return 0;
	return dp[res] + (app[lp[res]] - app[pos] + k) % k;
}
int main()
{
	// freopen("AGC011-F.in", "r", stdin);
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		int x, tp;
		scanf("%d%d", &x, &tp);
		if (x << 1 > k && tp == 1)
		{
			puts("-1");
			return 0;
		}
		sum[i] = (i ? sum[i - 1] : 0) + x;
		if (tp == 2)
		{
			lp[i] = 0;
			rp[i] = k - 1;
		}
		else
		{
			lp[i] = (-2 * (i ? sum[i - 1] : 0) % k + k) % k;
			rp[i] = (-2 * sum[i] % k + k) % k;
		}
		app[cnt++] = lp[i];
		app[cnt++] = rp[i];
	}
	std::sort(app, app + cnt);
	cnt = std::unique(app, app + cnt) - app;
	for (int i = 0; i < n; i++)
	{
		lp[i] = std::lower_bound(app, app + cnt, lp[i]) - app;
		rp[i] = std::lower_bound(app, app + cnt, rp[i]) - app;
	}
	memset(seg, -1, sizeof(seg));
	for (int i = n - 1; i >= 0; i--)
	{
		dp[i] = calc(lp[i]);
		if (lp[i] > rp[i])
			modify(1, 0, cnt - 1, rp[i] + 1, lp[i] - 1, i);
		else
		{
			modify(1, 0, cnt - 1, 0, lp[i] - 1, i);
			modify(1, 0, cnt - 1, rp[i] + 1, cnt - 1, i);
		}
	}
	ll ans = dp[0];
	for (int i = 0; i < cnt; i++)
		ans = std::min(ans, calc(i));
	printf("%lld\n", ans + sum[n - 1] * 2);
	return 0;
}


Measured memory_bytes: 6656
n=int(input())
a=list(map(int,input().split()))
x=max(a)
y=10**9
cnt=0
for i in range(n):
    if abs(a[i]-x/2)<y:
        y=abs(a[i]-x/2)
        z=a[i]
    if a[i]==x:
        cnt+=1
if z==x and cnt==1:
    print(x,0)
else:
    print(x,z)

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int main() {
    int n; cin >> n;
    int arr[3][n+1];
    memset(arr, 0, sizeof(arr));
    for (int i = 1; i <= n; i++) {
        cin >> arr[0][i];
        cin >> arr[1][i];
        cin >> arr[2][i];
    }

    //cout << arr[0][1] << " " << arr[1][1] << " " <<  arr[2][1] << "\n";

    // a = 0
    // b = 1
    // c = 2

    int dp[3][n+1]; memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
        dp[0][i] = arr[0][i] + max(dp[1][i-1], dp[2][i-1]);
        // if (i == 2) {
        //     cout << arr[0][i] << " "  << max(dp[1][i-1], dp[2][i-1]) << "\n";
        // }
        dp[1][i] = arr[1][i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = arr[2][i] + max(dp[0][i-1], dp[1][i-1]);
        // if (i == 1) {
        //     cout << dp[0][i] << " " << dp[1][i] << " " << dp[2][i] << "\n";
        // }
    }

    cout << max(dp[0][n], max(dp[1][n], dp[2][n])) << "\n";
}

Measured memory_bytes: 2688
N, L = input().split()
N = int(N)
L = int(L)

if L > 0:
    s = ( (L+2-1) + (L+N-1) )*( (N-1)/2 )
    print(int(s))

elif L <= 0 and N + L -1 >= 0:
    s = ( (L+1-1) + (L+N-1) )*( (N)/2 )
    print(int(s))

else:
    s = ( (L+1-1) + (L+N-1-1) )*( (N-1)/2 )
    print(int(s))


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=2;ii<=mx;ii++)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n,i,k,m,x,y;
    string a,b;
    cin>>n;
    if(n%1000==0) cout<<0 el;
    else cout<<1000-n%1000 el;


}

main()
{
        fastio();
//    test _case();
//    while(1) _case();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3648
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<cstdlib>
#include<unordered_map>
#include<algorithm>
 
#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
		
#define ii pair	<long long ,long long >
#define i64ii pair< long long, pair<int,int> >
#define i64i pair<long long , int >
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >	
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>
 
#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
#define mid l + ( (r-l)>>1)
 
using namespace std;
 
 
typedef long long ll;	
typedef vector< int> vi;
typedef long double ld;
 
const int MAX = 800;
const int maxn = 2e5+100;


char a[maxn], b[maxn];

int main (){
	scanf("%s", a);
	scanf("%s", b);
	
	printf("%s",b);
	printf("%s",a);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
double ans=0;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		int x=i;
		double t=1.0/n;
		while (x<k) x<<=1,t*=0.5;
		ans+=t;
	}
	printf("%.15lf",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
int main(){
    int r, g, b;
    cin >> r >> g >> b;
    int sum = 100 * r + 10 * g + b;
    if(sum % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256