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

#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
//map<int, int>::iterator itr; 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int arr[n+1];
    int co=0;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        if(i%2==1&&arr[i]%2==1){
            co++;
        }
    }
    cout<<co;
    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);
	if(a == b){
		printf("a == b\n");
	}
	else if(a < b){
		printf("a < b\n");
	}
	else {
		printf("a > b\n");
	}
	return 0;
}

Measured memory_bytes: 1008
url = "https://atcoder.jp//contests/abc129/tasks/abc129_c"

def main():
    n, m = list(map(int, input().split()))
    isbreak = [False] * (n+1)
    for _ in range(m):
        isbreak[int(input())] = True

    dp = [0] * (n + 1)
    dp[0] = 1
    for i in range(n):
        for j in range(i+1, min(i+3, n+1)):
            if not isbreak[j]:
                dp[j] += dp[i]
                dp[j] %= 1000000007
    print(dp[-1])




if __name__ == '__main__':
    main()


Measured memory_bytes: 13476
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

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

	int n, x, y;
	cin >> n >> x >> y;
	// cout << n << ' ' << x << ' ' << y << endl;
	--x, --y;
	vi res(n);
	REP(i, n) {
		vi dist(n, -1);
		queue<int> q;
		q.push(i);
		dist[i] = 0;
		while (!q.empty()) {
			int cur = q.front(); q.pop();
			if (cur + 1 < n && dist[cur + 1] == -1) {
				q.push(cur + 1);
				dist[cur + 1] = dist[cur] + 1;
			}
			if (cur - 1 >= 0 && dist[cur - 1] == -1) {
				q.push(cur - 1);
				dist[cur - 1] = dist[cur] + 1;
			}
			if (cur == x && dist[y] == -1) {
				q.push(y);
				dist[y] = dist[cur] + 1;
			}
			if (cur == y && dist[x] == -1) {
				q.push(x);
				dist[x] = dist[cur] + 1;
			}
		}
		FOR(j, i+1, n-1) {
			// printf("dist: [%d][%d] = %d\n", i, j, dist[j]);
			++res[dist[j]];
		}
	}
	FOR(i, 1, n-1) {
		cout << res[i] << endl;
	}
	
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(char a, char b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vllint a(n);
	rep(i, n) {
		cin >> a[i];
	}
	llint cnt = 0;
	llint now = 0;
	rep(i, n) {
		now += a[i];
		if (i % 2 == 0) {
			if (now <= 0) {
				cnt += 1 - now;
				now = 1;
			}
		}
		else {
			if (now >= 0) {
				cnt += now + 1;
				now = -1;
			}
		}
	}
	llint ans = cnt;
	cnt = 0;
	now = 0;
	rep(i, n) {
		now += a[i];
		if (i % 2 == 1) {
			if (now <= 0) {
				cnt += 1 - now;
				now = 1;
			}
		}
		else {
			if (now >= 0) {
				cnt += now + 1;
				now = -1;
			}
		}
	}
	ans = min(cnt, ans);
	cout << ans << endl;
	return 0;
}

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

int two(int n){
    int ans=0;
    while(true){
        if((n&1)==0) ans++;
        else break;
        n=n>>1;
    }
    return ans;
}

int main(){
    int n; cin >> n;
    int ans=0;
    for(int i=0;i<n;i++){
        int a; cin >> a;
        ans+=two(a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int t[4004];

void inc(int x, int v) {
    for (; x <= 4000; x += x & -x) t[x] += v;
}

int que(int x) {
    int z = 0;
    for (; x; x -= x & -x) z += t[x];
    return z;
}

int main() {
    ios::sync_with_stdio(false);
    int n, a[4004] = {}, z = 0, u[2019] = {}, v[2019] = {}, d[2019][2019] = {};
    char c[4004] = {};
    cin >> n;
    for (int i = 1; i <= n + n; i++) cin >> c[i] >> a[i];
    for (int i = 1; i <= n + n; i++) {
        if (c[i] == 'W') u[a[i]] = i;
        else v[a[i]] = i;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 1; j <= n + n; j++) t[j] = 0;
        for (int j = 1; j <= n + n; j++) inc(j, 1);
        for (int j = 1; j <= i; j++) inc(u[j], -1), d[i][0] += que(u[j]);
        for (int j = 1; j <= n; j++) {
            inc(v[j], -1);
            d[i][j] = d[i][j - 1] + que(v[j]);
            if (i) d[i][j] = min(d[i][j], d[i - 1][j] + que(u[i]));
        }
    }
    cout << d[n][n];
}


Measured memory_bytes: 16384
#include <math.h>

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

ll sabs(ll a, ll b) {
  if (a > b)
    return a - b;
  else {
    return b - a;
  }
}

int main() {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;

  ll bun = abs(a - b);
  ll sa = t * (v - w);

  if (sa <= 0)
    cout << "NO";
  else {
    if (sa >= bun)
      cout << "YES";
    else
      cout << "NO";
  }

  return 0;
}


Measured memory_bytes: 3652
def roll(d, cmd)
	case cmd
	when ?E
		d[0], d[2], d[5], d[3] = d[3], d[0], d[2], d[5]
	when ?N
		d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
	when ?S
		d[0], d[1], d[5], d[4] = d[4], d[0], d[1], d[5]
	when ?W
		d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]
	when ?C # clockwise
		d[1], d[2], d[4], d[3] = d[2], d[4], d[3], d[1]
	when "C2"
		d[1], d[2], d[4], d[3] = d[4], d[3], d[1], d[2]
	when "C3"
		d[1], d[2], d[4], d[3] = d[3], d[1], d[2], d[4]
	when "E2"
		d[0], d[2], d[5], d[3] = d[5], d[3], d[0], d[2]
	end
end

def format(d)
	min = d.min
	roll(d, ['', 'N', 'W', 'E', 'S', 'E2'][d.index(min)])
	min = d[1, 4].min
	roll(d, ['', 'C', 'C3', 'C2'][d[1, 4].index(min)])

	return d.join('_')
end

n = gets.to_i

dices = {}
n.times do
	id = format(gets.split.map(&:to_i))
	if dices[id]
		puts 'No'
		exit
	end
	dices[id] = true
end

puts 'Yes'



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

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N), B(M);
  vector<int64_t> a(N + 1), b(M + 1);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    a.at(i+1) = a.at(i) + A.at(i);
  }
  for(int i = 0; i < M; i++){
    cin >> B.at(i);
    b.at(i+1) = b.at(i) + B.at(i);
  }
  int s = 0;
  int x = M;
  
  for(int i = 0; i <= N; i++){
    if(a.at(i) > (int64_t)K){
      break;
    }
    while(a.at(i) + b.at(x) > K){
      x--;
    }
    s = max(i + x, s);
  }
  
  cout << s << endl;
}

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

#define LOCAL 0

#define lli long long int
#define llu unsigned long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const long double EPS = 1e-10;
const int MOD = 1000000007ll;
const int mod1 = 1000000009ll;
const int mod2 = 1100000009ll;
int INF = (int)1e9;
lli INFINF = (lli)1e18;
int debug = 0;
long double PI = acos(-1.0);

using namespace std;

int bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
int bit(lli _mask,int _i){return (_mask&(1ll<<_i))==0?0:1;}
int add(int a,int b,int m=MOD){int x=a+b;while(x>=m)x-=m;while(x<0)x+=m;return x;}
int sub(int a,int b,int m=MOD){int x=a-b;while(x<0)x+=m;while(x>=m)x-=m;return x;}
int mul(int a,int b,int m=MOD){lli x=a*1ll*b;x%=m;while(x<0)x+=m;return (int)x;}
int ldtoint(ld x){return (int)(x+0.5);}lli ldtolli(ld x){return (lli)(x+0.5);}
int powermod(lli _a,lli _b,int _m=MOD){lli _r=1;while(_b){if(_b%2==1)_r=mul(_r,_a,_m);_b>>=1;_a=mul(_a,_a,_m);}return _r;}

template<class T1,class T2>ostream&operator<<(ostream& os,const pair<T1,T2>&p){os<<"["<<p.first<<","<<p.second<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,const vector<T>&v){os << "[";bool first=true;for (T it:v){if (!first)os<<", ";first = false;os<<it;}os<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,set<T>&v){os<<"[";bool first=true;for (T it:v){if(!first)os<<", ";first=false;os<<it;}os<<"]";return os;}
template<class T1,class T2>ostream&operator<<(ostream& os,map<T1,T2>&v){os<<"[";bool first=true;for(pair<T1,T2> it:v){if(!first)os<<", ";first=false;os<<"("<<it.F<<","<<it.S<<")";}os<<"]";return os;}
template<class T>void parr(T a[],int s,int e){cout<<"[";for(int i=s;i<e;i++)cout<<a[i]<<", ";cout<<a[e]<<"]\n";}

lli N,C,K;
lli A[100010];

int main()
{
if(LOCAL){
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    debug = 1;
}
    srand (time(NULL));
    //ios::sync_with_stdio(0);cin.tie(0);

    slli(N);slli(C);slli(K);
    for(int i=1;i<=N;i++)slli(A[i]);
    sort(A+1,A+N+1);
    int ans = 0;
    for(int i=1;i<=N;i++){
        int j;
        for(j=i;j<=N;j++){
            if(A[j]-A[i]>K)
                break;
            if(j-i+1>C)
                break;
        }
        j--;
        ans ++;
        i = j;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

//-------------------------------------------------------------
void get_a(int a[], int n, int m);   
void get_b(int b[], int m);
void keisan(int a[], int b[], int n, int m);
//--------------------------------------------------------------
int main(void)
{
	int n, m; //n=???, m=???
	scanf("%d %d", &n, &m);
	
	int a[n * m];  
	int b[m];
	
	get_a(a, n, m);
	get_b(b, m);
	keisan(a, b, n, m);
	
	return 0;
}
//-------------------------------------------------------
void get_a(int a[], int n, int m)
{
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d", &a[(i * m) + j]);
		}
	}
}
//------------------------------------------------------
void get_b(int b[], int m)
{
	for(int i = 0; i < m; i++){
		scanf("%d", &b[i]);
	}
}
//------------------------------------------------------
void keisan(int a[], int b[], int n, int m)
{
	int sum = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			sum += ( a[(i*m) + j] * b[j] );
		}
		printf("%d\n", sum);
		sum = 0;
	}
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    vi v(n);
    REP(i,n) cin>>v[i];
    sort(ALL(v));
    double ans = v[0];
    FOR(i,1,n){
        ans = (ans+v[i])/2.0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
inks = {
  1 => [
              [ 0, -1],
    [-1,  0], [ 0,  0], [ 1,  0],
              [ 0,  1],
  ],
  2 => [
    [-1, -1], [ 0, -1], [ 1, -1],
    [-1,  0], [ 0,  0], [ 1,  0],
    [-1,  1], [ 0,  1], [ 1,  1],
  ],
  3 => [
                        [ 0, -2],
              [-1, -1], [ 0, -1], [ 1, -1],
    [-2,  0], [-1,  0], [ 0,  0], [ 1,  0], [ 2,  0],
              [-1,  1], [ 0,  1], [ 1,  1],
                        [ 0,  2],
  ],
}

paper = Array.new(10).map{ Array.new(10, 0) }

$<.each_line do |line|
  x, y, size = line.split(/,/).map(&:to_i)
  inks[size].each do |dx, dy|
    px, py = x+dx, y+dy
    next if px < 0 || 10 <= px || py < 0 || 10 <= py
    paper[py][px] += 1
  end
end

cells     = paper.flatten
max_depth = cells.max
n_white   = cells.select{|n| n == 0}.size

puts n_white
puts max_depth

Measured memory_bytes: 8668
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <math.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    ll a,b,c,d;
    cin >> a >> b;

    ll res;
    res = (a + b + 1)/2;

    cout <<res << endl;


    return 0;    

}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define int long long
#define endl '\n'
typedef long long ll;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    vector<bool> seen(n,false);
    int correct = 0;
    vector<int> penalty(n,0);
    int pe = 0;
    while(m--) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if(seen[p]) continue;
        if(s == "AC") {
            ++correct;
            seen[p] = true;
            pe += penalty[p];
        } else {
            ++penalty[p];
        }
    }
    cout << correct << " " << pe << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long T,x,y;
	cin>>T;
	while(T--){
		cin>>x>>y;
		long long a=(sqrt(x*y));
		int ans=2*(int)(a)-1;
		if(a*a==x*y&&x!=y)--ans;
		if(a*(a+1)>=x*y)--ans;
		cout<<ans<<endl;
	}return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if (A == 5 && B == 5 && C == 7) {
    cout << "YES" << endl;
  }
  else if (A == 5 && B == 7 && C == 5) {
    cout << "YES" << endl;
  }
  else if (A == 7 && B == 5 && C == 5) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
ans = 0
N = int(input())
a = list(map(int,input().split()))
for i in range(max(a)):
  x = 0
  z = 0
  count = 0
  for j in range(N):
    y = a[j]
    if y == 0 and x == 0:
      continue
    elif y != 0 and x == 0:
      count += 1
      a[j] -= 1
      z = 1
      x = 1
    elif y != 0 and z == 0:
      z = 1
      count += 1
      a[j] -= 1
    elif y != 0 and z == 1:
      a[j] -= 1
    elif y == 0 and z == 0:
      continue
    elif y == 0 and z == 1:
      z = 0
  ans += count
print(ans)

Measured memory_bytes: 3064
N,T = map(int,input().split())
cost_time = [list(map(int,input().split())) for i in range(N)]

#print(cost_time)

minVal = 1001

for i in  range(N):
  if cost_time[i][1] <= T:
    if  cost_time[i][0] < minVal:
      minVal = cost_time[i][0]

if minVal == 1001:
  print("TLE")
else:
  print(minVal)
		

Measured memory_bytes: 3060
K,N = map(int,input().split())
a = list(map(int, input().split()))

b=[0 for i in range(N)]
for i in range(N):
    if i ==0:
        b[i] = a[0] +(K-a[N-1])
    else:
        b[i] = a[i]-a[i-1]


minb = max(b)
print(K-minb)

Measured memory_bytes: 26060
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e5+10,mod=1e9+7;
inline void Add(int &x,int y) { x+=y; if(x>=mod) x-=mod; }
inline void Dec(int &x,int y) { x-=y; if(x<0) x+=mod; }
char S[N];
int s[N],f[N],sum[N],n;
int lb[N],rb[N];
int main() {
	scanf("%s",S+1); n=strlen(S+1);
	int flg=0;
	for(int i=1;i<n;++i) flg|=S[i]==S[i+1];
	if(!flg) {
		printf("1\n");
		return 0;
	}
	for(int i=1;i<=n;++i) s[i]=s[i-1]+(S[i]-'a'+1);
	int last[3]={0,-1,-1};
	int lst=-1;
	for(int i=1;i<=n;++i) {
		if(i>1&&S[i-1]==S[i]) lst=i-2;
		rb[i]=lst;
		lb[i]=last[s[i]%3];
		last[s[i]%3]=i;
//		cout<<i<<':'<<lb[i]<<' '<<rb[i]<<endl;
	}
	f[0]=sum[0]=1;
	for(int i=1;i<=n;++i) {
		Add(f[i],f[i-1]);
		if(lb[i]<rb[i]) {
			Add(f[i],sum[rb[i]]);
			if(lb[i]>-1) Dec(f[i],sum[lb[i]]);
		}
		sum[i]=(sum[i-1]+f[i])%mod;
	}
	int ans=0;
	for(int i=1;i<=n;++i) if((s[n]-s[i])%3==0) Add(ans,f[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2304
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        int[] A = in.ii(N);
        HashSet<Integer> hs = new HashSet<>();
        boolean flag = true;
        for(int i = 0; i < N; i++){
            flag = hs.add(A[i]);
            if (!flag) {
                break;
            }
        }
        out.println(flag ? "YES" : "NO");
    }


    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        int i() {
            return Integer.parseInt(s());
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            int i = 0;
            String s = s();
            for (int j = 0; j < a.length; j++) {
                boolean minus = s.charAt(i) == '-';
                i += minus ? 1 : 0;
                int k = 0;
                while (true) {
                    try {
                        int h = s.charAt(i++) - '0';
                        if (h < 0 || 9 < h) break;
                        k = 10 * k + h;
                    } catch (Exception e) { break; }
                }
                a[j] = minus ? -k : k;
            }
            return a;
        }
    }
}


Measured memory_bytes: 60240
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    sx, sy, tx, ty = map(int, sysread().split())

    ans = ''
    ans += 'R' * (tx-sx)
    ans += "U" * (ty-sy)
    ans += "L" * (tx-sx)
    ans += 'D' * (ty-sy)
    ans += "D"
    ans += 'R' * (tx-sx+1)
    ans += 'U' * (ty-sy+1)
    ans += 'L'
    ans += 'U'
    ans += 'L' * (tx-sx+1)
    ans += 'D' * (ty-sy+1)
    ans += 'R'
    print(ans)


if __name__ == "__main__":
    run()

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
int a[105],b[105],f[105],ans=99999999;
int main()
{
	//cout<<-1;
	//return 0;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a[i]>>b[i];
		if(f[a[i]]&&f[a[i]]!=b[i])
		{
			cout<<-1;
			return 0;
		}
		f[a[i]]=b[i];
	}
//	if(n==1)
//	{
//		cout<<b[1];
//		return 0;
//	}
int flag=0;
	for(int i=pow(10,n-1);i<=pow(10,n)-1;i++)
	{
		if(n==1&&!flag)flag=1,i--;
		for(int j=1;j<=m;j++)
		{
			int q=int(i/pow(10,n-a[j]))%10;
			if(q!=b[j])goto loop;
		}
		ans=min(i,ans);
		loop:;
	}
	if(ans!=99999999)cout<<ans;
	else cout<<-1;
}

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

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

  int size = s.size();
  string a;
  for (int i = 0; i < size; i++) {
    if (s[i] == 'B') {
      a.pop_back();
    } else {
      a.push_back(s[i]);
    }
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3132
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<string> s(m);
  rep(i, m) cin >> p[i] >> s[i];
  rep(i, m) p[i]--;
  vector<bool> aced(n, false);
  vector<int> pns(n, 0);
  int acs = 0;
  rep(i, m) {
    if(aced[p[i]])
      continue;
    if(s[i] == "AC") {
      acs++;
      aced[p[i]] = true;
    } else {
      pns[p[i]]++;
    }
  }
  int ps = 0;
  rep(i, n) if(aced[i]) ps += pns[i];
  cout << acs << ' ' << ps << endl;
  return 0;
}

Measured memory_bytes: 6528
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    double tmp = (double)(a + b) / (double)2;
    if (tmp > (int)tmp)
    {
        cout << (int)tmp + 1 << endl;
    }
    else
    {
        cout << tmp << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>

/*
 *変数
 */
int a[3];

/*
 *解 
 */
void solve(){
    std::sort(a,a+3,std::greater<>());
    printf("%d",a[1]*a[2]/2);
}

/*
 *入力 
 */
int main(){
       std::cin.tie(0);
       std::ios::sync_with_stdio(false);
       std::cin>>a[0]>>a[1]>>a[2];
       solve();
       return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    string S;
    cin >> S;

    int N = S.length();
    // start with 0
    int c0 = 0;
    REP(i, N) {
        if (i % 2 == 0 && S[i] != '0') c0++;
        else if (i % 2 == 1 && S[i] != '1') c0++;
    }
    // start with 1
    int c1 = 0;
    REP(i, N) {
        if (i % 2 == 0 && S[i] != '1') c1++;
        else if (i % 2 == 1 && S[i] != '0') c1++;
    }
    cout << min(c0, c1) << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
/**  '' "\n" ^ - **/

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    sf(n);
    ll mn=n-1;
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll sum=i+(n/i);
            sum=sum-2;
            if(sum<mn)
                mn=sum;
        }
    }
    pf(mn);
}


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

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

  int N; cin >> N;
  int ans = 0;
  int before = -2;
  rep(i, N) {
    int A; cin >> A;
    if(i + 1 == A) {
      if(before + 1 == i) {
        before = -2;
      } else {
        ans++;
        before = i;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		// input
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();

		int res = (a + b) % 24;
		// output
		System.out.println(res);
	}
}

Measured memory_bytes: 23252
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
using namespace std;
//数组不要开小了
//数组不要开反了
ll n,a,b,c,d;
int main()
{
    cin>>n>>a>>b>>c>>d;
    n--;
    if(a>b)swap(a,b);
    if(a+n*d<b){
                puts("NO");
                return 0;
    }
    a=b-a;
    b=d-c;
    for(ll i=0;i<=n;i++){
           ll r=a-i*c+(n-i)*c;
           if(r>=-b*(n-i)&&r<=b*i){
                                   puts("YES");
                                   return 0;
           }
    }
    puts("NO");
	//system("pause");
	return 0;
}


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

int main(){
    long long n, m, i, j;
    long long c = 0;
    cin >> n;
    for(i = 1; i*i<n; i++){
        if(n % i == 0){
            m = n / i - 1;
            if(n / m == n % m)
                c += m;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a[5];
int main()
{
	int ans=0;
	for(int i=1;i<=3;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+3+1);
	ans=a[3]*10+a[2]+a[1];
	printf("%d",ans);
}

Measured memory_bytes: 128
<?php
$input = STDIN;

$n = trim(fgets($input));

$min_rec = trim(fgets($input));
$R_1 = trim(fgets($input));

$ans = $R_1 - $min_rec;
if ($R_1 < $min_rec) {
    $min_rec = $R_1;
}

$n -= 2;
for ($i = 0; $i < $n; $i++) {
    $R_i = trim(fgets($input));

    if ($ans < $R_i - $min_rec) {
        $ans = $R_i - $min_rec;
    }
    
    if ($min_rec > $R_i) {
        $min_rec = $R_i;
    }
}

print $ans . "\n";


Measured memory_bytes: 9216
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	//ans= (2^(n+m) - 2^(n+m-rank))/2
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;cin>>str;
	int i,j,n;n=str.size();
	static llint dp[4001][4002]={0};
	dp[0][1]=1;
	//数、青
	int wa=0;
	for(i=1;i<=2*n;i++){
		if(i<=n){wa+=str[i-1]-'0';}
		for(j=max(0,wa-i)+1;j<=wa+1;j++){
			dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%mod;
		}
	}
	cout<<dp[n+n][wa+1]<<endl;
	return 0;
}

Measured memory_bytes: 123520
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long


class AChangingACharacter {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n, k;
      string s;
      in >> n >> k >> s;
      s[k - 1] = (s[k - 1] - 'A') + 'a';
      out << s << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  AChangingACharacter solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

list<int> li[200000];

int main() {

    int n,m,a,b;

    scanf("%d %d",&n,&m);

    for(int i=0;i<m;i++){
        scanf(" %d %d",&a,&b);
        li[a-1].push_back(b-1);
    }

    list<int>::iterator itr;

    for(itr = li[0].begin();itr!=li[0].end();itr++){
        a = *itr;
        list<int>::iterator itr2;
        for(itr2 = li[a].begin();itr2!=li[a].end();itr2++){
            if(*itr2 == n-1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1,1,-1,-1,2,2,-2,-2}; //knight moves
///int ky[]={2,-2,2,-2,1,-1,1,-1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};  //eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};  //eight direction
 
///using namespace __gnu_pbds;
using namespace std;
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
   	int n;
   	while(sf("%d",&n)==1)
   	{
   		int cnt[n+5];
   		for(int i=1;i<=n;i++)
   		{
   			int x;
   			sf("%d",&x);
   			cnt[x]=i;
   		}
   		for(int i=1;i<=n;i++)pf("%d ",cnt[i]);
   		nl;
   	}
    return 0;
}
 









 




























Measured memory_bytes: 1152
M, D = map(int, input().split())
ans = 0

for m in range(1, M + 1):
    for d in range(1, D + 1):
        d_list = divmod(d, 10)
        if d_list[0] >= 2 and d_list[1] >= 2 and d_list[0] * d_list[1] == m:
            ans += 1
print(ans)

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

long long gcd(long long x,long long y){
  if (y==0){
    return x;
  }
  return gcd(y,x%y);
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> T(N);
  for (int i=0;i<N;i++){
    cin >> T[i];
  }
  long long ans=1;
  for (int i=0;i<N;i++){
    ans=lcm(ans,T[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN3(a,b,c);
  Yes(a+b>=c);
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>

using namespace std;

int main(void) {
	int a[101],n;
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
	}
	a[n] = -1;
	int prev = -1,cnt = 0,res = 0;
	for(int i = 0;i <= n;i++) {
		if(prev != a[i]) {
			res += cnt / 2;
			cnt = 1;
			prev = a[i];
		}
		else
			cnt++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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;
}







int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(0,c-a+b) << endl;
    
    return 0;
}


Measured memory_bytes: 3652
function Main(input) {
    input = input.split("\n");
    var nk = input[0].split(" ");
    var n = parseInt(nk[0], 10);
    var k = parseInt(nk[1], 10);
    var X = input[1].split(" ").map(x => parseInt(x, 10));
    var zeroInd = -1;
    for (var i = 0; i < n; i++) {
        if (X[i] >= 0) {
            zeroInd = i;
            break;
        }
    }
    if (X[n-1] < 0) {
        zeroInd = n;
    }
    var left = Math.max(zeroInd - k, 0);
    var right = Math.min(zeroInd + k, n);
    var sofar = 1000000001;
    for (var i = left; i < right-k+1; i++) {
        var leftHalf = 0;
        var rightHalf = 0;
        if (i < zeroInd) {
            leftHalf = Math.abs(X[i]);
            rightHalf = Math.max(X[i+k-1], 0);
        } else if (i >= zeroInd) {
            leftHalf = 0;
            rightHalf = X[i+k-1];
        }
        var candid = Math.min(leftHalf*2+rightHalf, leftHalf+rightHalf*2)
        sofar = Math.min(sofar, candid);
    }
    console.log(sofar);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    priority_queue<int> q;
    ll extra=0,ans=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        if(a[i]<b) ans++,extra+=b-a[i];
        else q.push(a[i]-b);
    }
    while(extra>0){
        if(q.empty()){
            cout<<-1<<endl;
            return 0;
        }
       
        int x=q.top();
        q.pop();
       extra-=x;
        if(x!=0) ans++; 
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4188
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    sort(a, a + n);
    if(a[n-1] == 0 && (k&1)){
        cout<<"0";
    }else if(a[n-1]<0 && (k&1)){
        ll ans = 1;
        for(int i = n - 1; i >= n-k; i--){
            ans *= a[i];
            ans %= MOD;
        }
        if(ans < 0){
            ans += MOD;
        }
        cout<<ans;
    }else if(a[n-1]<0 && !(k&1)){
        ll ans = 1;
        for(int i = 0; i < k; i++){
            ans *= a[i];
            ans%=MOD;
        }
        if(ans < 0){
            ans += MOD;
        }
        cout<<ans;
    }else{
        ll ans = 1;
        int i = 0,j = n - 1;
        if(k&1){
            ans*=a[j];
            ans%=MOD;
            j--;
            k--;
        }
        k/=2;
        for(int p = 0; p<k; p++){
            ll left = a[i]*a[i+1];
            ll right = a[j]*a[j-1];
            if(left > right){
                ans=ans * a[i]%MOD * a[i+1]%MOD;
                i+=2;
            }else{
                ans=ans * a[j]%MOD * a[j-1]%MOD;
                j-=2;
            }
        }
        if(ans < 0){
            cout<<((ans%MOD) + MOD)%MOD;
        }else{
            cout<<(ans%MOD);
        }
    }
}

Measured memory_bytes: 5196
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    int n, p;
    cin >> n >> p;

    int odd_count = 0;
    int even_count = 0;
    int val;
    for(int i = 0; i < n; i++){
        cin >> val;
        if(val % 2) odd_count ++;
        else even_count++;
    }

    long long even_ans = 1;
    for(int i = 0; i < even_count; i++){
        even_ans *= 2;
    }

    long long odd_ans = 1;
    for(int i = 0; i < odd_count; i++){
        odd_ans *= 2;
    }
    if(odd_ans > 1) odd_ans /= 2;

    if(odd_count == 0 && p == 1){
        cout << 0 << endl;
    }
    else{
        cout << even_ans * odd_ans << endl;
    }






}

Measured memory_bytes: 256
N, K = map(int, input().split())

ans = 0

num = [0] * (K+1)
for i in range(1, N+1):
    num[i % K] += 1

for a in range(K+1):
    b = (K-a) % K
    c = (K-a) % K
    if ((b+c) % K) == 0:
        ans += (num[a] * num[b] * num[c])

print(ans)


Measured memory_bytes: 4596
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init(){
    c[0][0] = 1;
    for(int i=0; i<=4000; i++){
        for(int j=0; j<=i; j++){
            c[i+1][j] += c[i][j];
            c[i+1][j+1] += c[i][j];
        }
    }
}
mint comb(int n, int k){
    return c[n][k];
}
mint f2(int n, int k){
    return comb(n+k-1, k-1);
}
mint f(int n, int k){
    if(n < k) return 0;
    if(n == 0 && k== 0) return 1;
    if(k < 1) return 0;
    return f2(n-k,k);
}

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

    for(int i=1; i<=k; i++){
        mint blue = f(k,i);
        mint red = f2(n-k-(i-1),i+1);
        mint ans = blue*red;
        cout << ans.x << endl;
    }
    return 0;
}

Measured memory_bytes: 125568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ( (A + B) > (C + D) )
    cout << "Left" << endl;
  if ( (A + B) == (C + D) )
    cout << "Balanced" << endl;
  if ( (A + B) < (C + D) )
    cout << "Right" << endl;
  
}

  

Measured memory_bytes: 256
from sys import stdin



def prepare(n, p):
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    return fact, factinv


def cmb(n, r, p, fact, factinv):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


def get_result(data):
    n, k = data
    mod = 10**9+7
    fact, factinv = prepare(n, mod)
    ans = 0
    for m in range(n):
        # xHy = x+y−1Cx−1
        if m <= k:
            ans += (cmb(n, m, mod, fact, factinv) * cmb(n-1, n-m-1, mod, fact, factinv)) % mod
    ans %= mod
    return ans

if __name__ == '__main__':
    data = list(map(int, stdin.readline().split(' ')))
    result = get_result(data)
    print(result)

Measured memory_bytes: 27304
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main() {
  int n,cnt=0;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++) {
    cin >> s[i];
  }
  for(int i=0; i<n-1; i++) {
    if(s[i][s[i].size()-1]!=s[i+1][0]) {
      cnt++;
    }
  }
  for(int i=0; i<n; i++) {
    for(int j=i+1; j<n; j++) {
      if(s[i]==s[j]) {
        cnt++;
      }
    }
  }
  if(cnt!=0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vpii res;
    rep(i,0,n){
        int x,l;
        cin>>x>>l;
        pii e=make_pair(x+l,x-l);
        res.push_back(e);
    }
    sort(res.begin(),res.end());
    int l=-(1<<30);
    ll ans=0;
    rep(i,0,n){
        pii e=res[i];
        if(l<=e.second)ans++,l=e.first;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<queue>
using namespace std;
struct Process
{
	string name;
	int timeNeeded;
	int timeFinished;
};
int main()
{
	queue<Process> Q;
	int n, q,totalTime=0;
	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		string nm;
		int t;
		cin >> nm >> t;
		Process p = { nm,t,0};
		Q.push(p);
	}
	while (!Q.empty())
	{
		Process head = Q.front();
		if (head.timeNeeded <= q)
		{
			totalTime += head.timeNeeded;
			Q.pop();
			cout << head.name << " " << totalTime << endl;
		}
		else
		{
			totalTime += q;
			int remaining = head.timeNeeded - q;
			string nm = head.name;
			Process temp = {nm,remaining};
			Q.pop();
			Q.push(temp);
		}
	}
}


Measured memory_bytes: 6132
N = int(input())
h = [int(i) for i in input().split()]

zerobefore = True
times = 0
while sum(h) > 0:
    
    for i in range(len(h)):

        if h[i] == 0 and zerobefore:
            continue
        elif h[i] == 0 and not zerobefore:
            times += 1
            zerobefore = True #Trueに戻す
            break
        elif i == len(h) - 1 and not zerobefore and h[i] != 0:
            h[i] -= 1
            times += 1
            zerobefore = True  
        elif i == len(h) -1 and zerobefore and h[i] != 0:
            h[i] -= 1
            times += 1
            zerobefore = True
        else:
            h[i] -= 1
            zerobefore = False
        
        
        
    #print(h)
    #print(times)
            
print(times)            

Measured memory_bytes: 3064