akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

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

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int N; cin >> N;
    vector<int> a(N);
    int res[N]={0};
    REP(i,N){
        cin >> a[i];
        res[a[i]]++;
    }

    int ans=1;
    
    if(N%2==0){
        for(int i=1; i<N; i=i+2){
            ans *= res[i];
            ans = ans % 1000000007;
        }
    }else{
        if(res[0]!=1){
            cout << 0 << endl;
            return 0;
        }else{
            for(int i=2; i<N; i=i+2){
                ans *= res[i];
                ans = ans % 1000000007;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int max=0, cnt=0;
        
        for(int i=0; i<n; i++){
            int h = sc.nextInt();
            if(max <= h){
                max = h;
                cnt++;
            }
        }
        
        System.out.println(cnt);
    }
}


Measured memory_bytes: 25172
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char a[110][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll h, w;
	cin >> h >> w;
	vector<ll>kazu(3);
	map<char, ll>mp;
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
			mp[a[i][j]]++;
		}
	}
	for (auto p : mp) {
		ll res = p.second;
		kazu[2] += p.second / 4;
		p.second -= p.second / 4 * 4;
		kazu[1] += p.second / 2;
		p.second -= p.second / 2 * 2;
		kazu[0] += p.second;
	}
	ll res = (h / 2) * (w / 2);
	if (h % 2 == 0 && w % 2 == 0) {
		if (kazu[2] == res) {
			puts("Yes");
		}
		else {
			puts("No");
		}
	}
	else if (h % 2 && w % 2) {
		bool flag = true;
		if (kazu[0] != 1)flag = false;
		if (kazu[2] < res)flag = false;
		if (flag) {
			puts("Yes");
		}
		else {
			puts("No");
		}
	}
	else {
		bool flag = true;
		if (kazu[2] < res)flag = false;
		if (kazu[0] > 0)flag = false;
		if (flag) {
			puts("Yes");
		}
		else {
			puts("No");
		}
	}
	return 0;
}


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

int main()
{
  string s;cin>>s;
  int i=1;
  int count=1;
  char now=s.at(0);
  while(i<s.size())
  {
    if(s.at(i)!=now)
    {
      now=s.at(i);
      i++;
      count++;
    }
    else
    {
      now='.';
      i+=2;
      if(i<=s.size())count++;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rpt(n) for(register int ttxyc=0;ttxyc<n;++ttxyc)//宏定义
using namespace std;
int n,a,ans;map<int,int>m;
main()
{
    scanf("%d",&n);
    rpt(n)
	{
		scanf("%d",&a);
		if(m.count(a))++m[a];
		else m[a]=1;
	}
	for(map<int,int>::iterator i=m.begin();i!=m.end();++i)
	{
		pair<int,int>now=*i;
		if(now.first>now.second)ans+=now.second;
		else ans+=now.second-now.first;
	}
	printf("%d\n",ans);
}/**/

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

int main(){
int N; cin >> N;
int x[N], y[N]; 
long double arg; vector< pair<long double, int> > s(N);
for(int i=0; i<N; i++){
  cin >> x[i] >> y[i]; arg=atan2(y[i], x[i]);
  s[i]=make_pair(arg, i);
}
sort(s.begin(), s.end());
long double X, Y, ans=0; int u;
for(int L=0; L<N; L++){ for(int R=L; R<L+N; R++){
 X=0; Y=0;
 for(int i=L; i<=R; i++){ u=s[i%N].second; X+=x[u]; Y+=y[u]; }
 ans=max(ans, sqrt(X*X+Y*Y));
}}
cout << setprecision(30) << ans << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  int count=0;
  for(int i=a;i<=b;i++) {
    string stoi = to_string(i);
    bool flag=true;
    for(int j=0;j<stoi.size()/2;j++) {
      if(stoi[j] != stoi[stoi.size()-1-j]) {
        flag=false;
        break;
      }
    }
    if(flag) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
typedef vector<ll> vc;
typedef vector<string> vcs;
typedef vector<pair<ll, ll>> vcp;
typedef vector<tuple<ll, ll, ll>> vct;

//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll a, b, c, d, n, ans = 0;
	cin >> a >> b >> c >> d >> n;
	n *= 4;
	while (n > 0)
	{
		ll mincost = INF;
		if (n >= 8)
		{
			mincost = min(a * 8, b * 4);
			mincost = min(mincost, c * 2);
			mincost = min(mincost, d);
			ans += (n / 8)*mincost;
			n %= 8;
		}
		else if (n >= 4)
		{
			mincost = min(a * 4, b * 2);
			mincost = min(mincost, c);
			ans += (n / 4)*mincost;
			n %= 4;
		}
		else if (n >= 2)
		{
			mincost = min(a * 2, b);
			ans += (n / 2)*mincost;
			n %= 2;
		}
		else
		{
			ans += d;
			n = 0;
		}
	}
	cout << ans << endl;
}

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

#define pb push_back
#define ll long long
#define fi first
#define se second
const int N = 1e2+10;
#define MOD 1000000007
int ncr(int n,int r){if(n<r)return 0;int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int g=__gcd(p, k);p/=g;k/=g;n--;r--;}}else p=1;return p;}
void solve()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int dp[n];

	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);

	for(int i=2;i<n;i++)
	{
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]) , dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
}

int main()
{
	int t=1;
	//t=1;
	// cin>>t;
	// fibonacci();
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N, T;
    cin >> N >> T;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    vector<ll> B(N);
    ll mp = INF;
    rep(i, N){
        chmin(mp, A.at(i));
        B.at(i) = A.at(i) - mp;
    }
    ll cnt = 0;
    ll prof = -1;
    rep(i, N){
        if(B.at(i) > prof){
            cnt = 1;
            prof = B.at(i);
        }
        else if(B.at(i) == prof){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4784
#include <stdio.h>
#include <math.h>
 
int main (void)
{
    int n, s[1010], sum, j=0, i;
    double ave, dev[1010], bun;
 
 
    while(1){
        scanf("%d", &n);
        if(n==0)break;
         
        sum=0;
        for(i=0; i<n; i++){
            scanf("%d", &s[i]);
            sum += s[i];
        }
 
        ave = (double)sum / (double)n;
        bun=0.0;
 
        for(i=0; i<n; i++)
            bun+=pow(s[i]-ave,2);
 
            dev[j++] = sqrt(bun/(double)n);
    }
 
    for(i=0; i<j; i++){
        printf("%f\n", dev[i]);
    }
    return 0;
}

Measured memory_bytes: 640
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100; 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	long long sum = 0;
	cin >> n;
	for(int a = 1; a <= n; a++){
		for(int b = 1; b <= n; b++){
			for(int c = 1; c <= n; c++){
				sum += __gcd(a, __gcd(b, c));
			}
		}
	}
	cout << sum << '\n';
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(void){
  int n,hr,nr; 
  
  scanf("%d %d", &n, &hr);
  
  if(n < 10)  nr = hr + 100 * (10 - n);
  else  nr = hr;
  
  printf("%d\n", nr);
  
  return 0;
}

Measured memory_bytes: 128
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi#, gcd
from fractions import gcd
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def II(): return int(input())
def IF(): return float(input())
def IS(): return str(input())
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


def main():
    S = IS()

    ans = "Yes"
    if S[0] == S[1] and S[1] == S[2]:
        ans = "No"
    
    print(ans)


if __name__ == '__main__':
    main()


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

void func();

int main(){
    func();
}

void func(){
    int N,Y;
    cin >> N >> Y;
    for(int i = 0; i <= N; i++){
        for(int j = 0; i+j <= N; j++){
            int k = N - i -j;
            if(i*10000 + j*5000 + k*1000 == Y){
                cout << i << " " << j << " " << k << "\n";
                return;
            }else continue;
        }
    }
    cout << -1 << " " << -1 << " " << -1 << "\n";
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
int m;
int dp[2][5005];

int main(){
	cin >> n >> m;
	dp[0][0] = 1;
	int cur = 0, nxt = 1;
	for(int i=n/2;i>=1;i--){
		rep(i,n) dp[nxt][i] = 0;
		for(int j=0;j<n;j++){
			if(dp[cur][j] == 0) continue;
			for(int k=0;j+k*i<n;k++){
				dp[nxt][j+k*i] += dp[cur][j];
				if(dp[nxt][j+k*i]>=m) dp[nxt][j+k*i]-=m;
			}
		}
		swap(cur,nxt);
	}
	for(int i=n-n/2;i>=1;i--){
		rep(i,n) dp[nxt][i] = 0;
		for(int j=0;j<n;j++){
			if(dp[cur][j] == 0) continue;
			for(int k=0;j+k*i<n;k++){
				dp[nxt][j+k*i] += dp[cur][j];
				if(dp[nxt][j+k*i]>=m) dp[nxt][j+k*i]-=m;
			}
		}
		swap(cur,nxt);
	}
	ll ans = 0;
	rep(i,n) ans += dp[cur][i];
	cout << (ans%m+m)%m << endl;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>

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

int bitsNum(int bits)
{
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
	return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int main() {

	int N;
	int F[123];
	int P[123][16];

	scanf("%d", &N);

	rep(i, N) {
		F[i] = 0;
		rep(j, 10) {
			int t;
			scanf("%d", &t);
			F[i] <<= 1;
			F[i] += t;
		}
	}

	rep(i, N) {
		rep(j, 11) {
			scanf("%d", &P[i][j]);
		}
	}

	long long int ans = (-9223372036854775807 - 1);
	rep(i, 1 << 10) {
		if (!i) continue;
		long long int t = 0;
		rep(j, N) {
			t += P[j][bitsNum(F[j] & i)];
		}
		ans = max(ans, t);
	}

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

signed main(){
    fastio
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    cout<<sum<<"\n";
    return 0;
}

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

const int MOD = (int)1e9+7;

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

  vector<string> ans;
  for(int i=0;i<s.size();i++){
    string a;
    for(int j=0;j<5;j++){
      if(j+i>=s.size()) break;
      a+=s.at(i+j);
      ans.push_back(a);
    }
  }
  sort(ans.begin(),ans.end());
  ans.erase(unique(ans.begin(),ans.end()),ans.end());
  cout << ans.at(K-1) << endl;

  return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, r; cin >> n >> r;

    if(n >= 10) cout << r << endl;
    else cout << r + 100 * (10-n) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[100001];
const ll inf=1e15;
int main()
{
  ll n,W;
  cin>>n>>W;
  ll w[n];int v[n];
  for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
 for(int i=0;i<100001;i++)
   dp[i]=inf;
  dp[0]=0;
  for(int j=0;j<n;j++)
    {
     for(int i=100000;i>=0;i--)
      {
      if(i>=v[j])
        dp[i]=min(dp[i],dp[i-v[j]]+w[j]);
     }
    }
  
  int ans=0;
  for(int i=100000;i>=0;i--)
    if(dp[i]<=W)
    {
      ans=i;
      //cout<<dp[i]<<" ";
      break;
    }
  cout<<ans<<"\n";
  return 0;
}

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

using namespace std;

int main() {
  string s; cin >> s;
  int n = s.size();
  string last = "";
  string now = "";

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    now += s[i];
    if (now != last) {
      last = now;
      now = "";
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

int n, k;
string s;
int solve();

int main() {
  cin >> n >> k;
  cin >> s;
  int score = solve();
  cout << score << endl;
}

int solve() {
  int score = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == s[i]) {
      score++;
    }
  }
  int max_score = n - 1;
  return min(score + 2 * k, max_score);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
int main(){
  int n;
  cin >> n;
  cout << (n + 110) / 111 * 111 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int i,j,k,n,temp,temp1;
  int m1,m2;
  char in[2], chartemp;
  int a[26];

  while(scanf("%d",&n))
    {
      for(i=0;i<26;i++)
	{
	  a[i] = 0;
	}
      if(n==0)
	break;
      else
	{
	  k = 0;
	  for(i=0;i<n;i++)
	    {
	      scanf("%s",in);
	      temp = in[0];
	      a[temp-65]++;
	      m1 = 0;
	      for(j=0;j<26;j++)
		{
		  if(m1<=a[j])
		    {
		      m1 = a[j];
		      temp1 = j;
		    }
		}
	      m2 = 0;
	      for(j=0;j<26;j++)
		{
		  if(m2<=a[j]&&j!=temp1)
		    {
		      m2 = a[j];
		    }
		}
	      if((m1-m2)>n-(i+1)&&k==0)
		k = i+1;
	    }
	  chartemp = temp1;
	  if(k!=0) printf("%c %d\n",chartemp+65,k);
	  //else if(k==0&&m1!=m2) printf("%c %d\n",chartemp+65,n);
	  else printf("TIE\n");
	}
    }
  return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf(a) printf("%d\n",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a, b) scanf("%d%d",&a,&b)
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 1e5 + 5;
int ar[100003][3];
int main()
{

    int n;
    scanf("%d",&n);
    for(int i=0;i<=n-1;i++)
    {
        scanf("%d %d %d",&ar[i][0],&ar[i][1],&ar[i][2]);
    }

    if(n==1)
    {
        int x= max(ar[0][0],max(ar[0][1],ar[0][2]));
        printf("%d\n",x);
    }
    else
    {
        for(int i=1;i<=n-1;i++)
        {
            ar[i][0]=ar[i][0]+max(ar[i-1][1],ar[i-1][2]);
            ar[i][1]=ar[i][1]+max(ar[i-1][0],ar[i-1][2]);
            ar[i][2]= ar[i][2]+max(ar[i-1][0],ar[i-1][1]);
        }

    int y= max(ar[n-1][0],max(ar[n-1][1],ar[n-1][2]));
    printf("%d\n",y);
    }
    return 0;
}


Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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 INF=1e18;

ll mod_pow(ll x,ll n){
    if(n==0) return 1;
    ll res=mod_pow(x*x,n/2);
    if(n&1) res=res*x;
    return res;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n+1);
    cinf(n+1,a);
    ll ans=0;
    ll now;
    ll cnt=1;
    bool ok=1;
    if(n>0&&a[0]!=0) ok=0;
    V<ll> b(n+1,0);
    for(int i=n;i>=0;i--){
        if(i==n){
            b[i]=a[i];
        }else{
            b[i]=b[i+1]+a[i];
        }
    }
    for(ll i=0;i<=n;i++){
        if(i==0){
            ans++;
            now=1;
            b[i]=1;
        }else{
            if(now*2<a[i]){
                ok=0;
                break;
            }
            ll k=b[i]-a[i];
            ll m=now*2-a[i];
            if(k>m){
                ll x=k-m;
                ans+=m+a[i];
                now=m;
            }else{
                ans+=b[i];
                now=b[i]-a[i];
            }
            //b[i]=
            /*ll kk=k;
            k/=2;
            if(kk%2==1) k++;
            ans+=a[i]+k;
            now=k;*/
        }
    }
    ll sum=0;
    rep(i,n+1) sum+=b[i];
    /*for(ll i=n;i>=0;i--){
        if(i==n){
            ans+=a[i];
            now=a[i]/2;
            if(a[i]%2==1) now++;
        }else{
            ans+=now+a[i];
            now=a[i]/2;
            if(a[i]%2==1) now++;
        }
    }*/
    if(n==0){
        if(a[0]==1) ans=1;
        else ok=0;
    }
    if(ok) cout<<ans<<endl;
    else cout<<-1<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 4784
#include <iostream>

using namespace std;

int main() {
    int n, a;
    cin >> n;
    int ans = 0;
    for (int i = 1 ; i <= n ; i++) {
        cin >> a;
        if (i % 2 == 1)
            if (a % 2 == 1)
                ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    int n, h, w;
    cin >> n >> h >> w;
    vector<int> a(n), b(n);
    REP(i, n) cin >> a[i] >> b[i];

    int ans = 0;
    REP(i, n){
        ans += min(a[i] / h, b[i] / w);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, X;
    cin >> N >> X;
    int ans = 1;
    int pos = 0;
    rep(i, 0, N)
    {
        int L;
        cin >> L;
        pos += L;
        if (pos > X) break;
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
string a,b;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}

int main() {
//	freopen("in.txt","r",stdin);
	cin>>a>>b;
	cout<<b<<a<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> F(N);
	Int temp;
	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < 10; j++) {
			cin >> temp;
			if (temp) {
				F[i] += (1LL << j);
			}
		}
	}

	vector<vector<Int>> P(N, vector<Int>(11, 0));
	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < 11; j++) {
			cin >> P[i][j];
		}
	}

	Int ans = -INF;
	Int temp2;//bit用
	Int temp3;//答え用
	Int count;
	for (Int i = 1; i < (1LL<<10); i++) {
		temp3 = 0;
		for (Int j = 0; j < N; j++) {
			count = 0;
			temp2 = i & F[j];
			for (Int k = 0; k < 10; k++) {
				if (temp2 & (1LL << k))count++;
			}
			temp3 += P[j][count];
		}
		ans = max(ans, temp3);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from functools import reduce
n = int(input())
values = list(map(int, input().split()))

def minNum(a,b):
    if a < b:
        return a
    return b 

def maxNum(a,b):
    if a < b:
        return b
    return a

def sumNum(a,b):
    return a + b

print(reduce(minNum, values, 1000001), reduce(maxNum, values, -1000001), reduce(sumNum, values, 0))


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

int main() {
  string s;
  cin >> s;
  int count = 0;
  rep(i, s.size()) {
    if (s[i] == '1') count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
# 解説放送
# 写経

def main():
    from itertools import islice

    inf = 18 * (10 ** 6 + 1)

    s = '0' + input()
    n = len(s)

    s = map(int, reversed(s))  # 先に一括でintにした

    dp = [[inf] * 2 for _ in range(n + 1)]
    dp[0][0] = 0

    for i, c in enumerate(islice(s, 0, n, 1)):
        for j in range(2):
            x = c + j
            if x != 10:  # 不等号をやめた
                dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + x)  # a=x,b=0
            if x != 0:
                dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - x))  # a=0,bに繰り下がり

    print(dp[n][0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 139508
#include <iostream>

using ll = long long;

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

template<class H> void print(H head) {std::cout << head << std::endl;}

int main()
{
  ll A, B;
  std::cin >> A >> B;

  ll ans = maximum(A + B, A - B, A * B);
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	//#ifndef LOCAL
	//freopen("input.txt","r",stdin);
	//#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
 
 
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
 
	return 0;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    
    int res = 0;
    
    string temp;
    temp += s[0];
    ++res;
    int id = 1;
    while(id < n){
        if(temp.length() == 1){
            if(temp[0] == s[id]){
                ++id;
                if(id == n)     continue;
                
                temp += s[id++];
                ++res;
            }
            else{
                temp = "";
                temp += s[id++];
                ++res;
            }
        }
        else{
            temp = "";
            temp += s[id++];
            ++res;
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<long long>
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = 998244353;
const ll INF = (ll)1e9+1;
const ll N = 1e5;

ll n, m, in, ans=0, a[100001];
priority_queue<ll, vector<ll>, less<ll> > pq;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n >> m;
    for(int i=0; i<n; i++){
        cin >> in;
        pq.push(in);
    }
    for(int i=0; i<m; i++){
        auto x = pq.top();
        pq.pop();
        x/=2;
        pq.push(x);
    }
    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
    }
    cout << ans;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#define x first
#define y second
using namespace std;
typedef long long int ll;
int n;
ll mod=1e9+7;
ll lob[111111];
ll upb[111111];
ll t[111111];
ll a[111111];
ll fixd1[111111];
ll fixd2[111111];
ll ans=1;
int main(void)
{
	cin>>n;
	int i;
	for(i=1 ; i<=n ; i++)
	{
		scanf("%lld",&t[i]);
	}
	for(i=1 ; i<=n ; i++)
	{
		scanf("%lld",&a[i]);
		upb[i]=1LL<<62;
	}
	fixd1[1]=t[1];
	lob[1]=t[1];
	upb[1]=t[1];
	fixd2[n]=a[n];
	lob[n]=a[n];
	upb[n]=a[n];
	for(i=2 ; i<=n ; i++)
	{
		if(t[i]==t[i-1])
		{
			lob[i]=max(lob[i],1LL);
			upb[i]=min(upb[i],t[i]);
		}
		else
		{
			lob[i]=t[i];
			upb[i]=t[i];
			fixd1[i]=t[i];
		}
	}
	for(i=n-1 ; i>=1 ; i--)
	{
		if(a[i]==a[i+1])
		{
			lob[i]=max(lob[i],1LL);
			upb[i]=min(upb[i],a[i]);
		}
		else
		{
			lob[i]=a[i];
			upb[i]=a[i];
			fixd2[i]=a[i];
		}
	}
	for(i=1 ; i<=n ; i++)
	{
		if(fixd1[i]!=fixd2[i] && fixd1[i]!=0 && fixd2[i]!=0)
		{
			cout<<0;
			exit(0);
		}
	}
	for(i=1 ; i<=n ; i++)
	{
		//cout<<lob[i]<<" "<<upb[i]<<endl;
		if(upb[i]<lob[i])
		{
			cout<<0;
			exit(0);
		}
		ans=(ans*(upb[i]-lob[i]+1))%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
long long i,j,max_,f[101][100001],w[101],v[101],n,W,x=0;
int main()
{
	memset(f,0x7f,sizeof(f));
	scanf("%lld %lld",&n,&W);
	for(i=1;i<=n;i++)
	{
		scanf("%lld %lld",&w[i],&v[i]);
		x+=v[i];
	}
	f[0][0]=0;
	for(i=1;i<=n;i++)
		for(j=0;j<=x;j++)
		{
			f[i][j]=f[i-1][j];
			if(j>=v[i])
				f[i][j]=min(f[i][j],f[i-1][j-v[i]]+w[i]);
		}
	for(i=0;i<=x;i++)
		if(f[n][i]<=W)
			max_=max(max_,i);
	printf("%lld",max_);
	return 0;
}

Measured memory_bytes: 79232
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        GLongestPath solver = new GLongestPath();
        solver.solve(1, in, out);
        out.close();
    }

    static class GLongestPath {
        public static long[] dp;
        public static int[] inDegree;
        private static boolean[] visited;
        private static ArrayList<Integer>[] edges;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            inDegree = new int[n + 1];
            visited = new boolean[n + 1];

            edges = new ArrayList[n + 1];
            for (int i = 0; i < edges.length; i++) {
                edges[i] = new ArrayList<Integer>();
            }

            for (int i = 0; i < m; i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                edges[x].add(y);
                inDegree[y]++;
            }

            dp = new long[n + 1];
            for (int i = 1; i <= n; i++) {
                if (!visited[i] && inDegree[i] == 0) {
                    dfs(i);
                }
            }

            long ans = 0;
            for (int i = 1; i <= n; i++) {
                ans = Math.max(ans, dp[i]);
            }

            out.println(ans);
        }

        private void dfs(int i) {
            visited[i] = true;
            for (Integer e : edges[i]) {
                dp[e] = Math.max(dp[e], 1 + dp[i]);
                inDegree[e]--;
                if (inDegree[e] == 0) {
                    dfs(e);
                }
            }
        }

    }
}



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

using namespace std;

typedef long long ll;

const int inf = 1e9 + 7;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, max_w;
    cin >> n >> max_w;
    vector <vector <int> > a(n, vector <int> (2));
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1];
    }
    int max_v = 1e5 + 7;
    vector <int> dp(max_v + 1, inf);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = max_v; j >= 0; j--) {
            if (j + a[i][1] <= max_v) {
                dp[j + a[i][1]] = min(dp[j + a[i][1]], dp[j] + a[i][0]);
            }
        }
    }
    for (int i = max_v; i >= 0; i--) {
        if (dp[i] <= max_w) {
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    ll n = s.size();
    n++;
    vector<ll> a(n,-1);
    rep(i,n){
        if ( i == 0 &&  s[i] == '<') {
            a[i] = 0; 
        } else if(i == n-1 && s[i-1] == '>') {
            a[i] = 0;
        } else if(s[i-1] == '>' && s[i] == '<') {
            a[i] = 0;
        }
    }
    ll now=0;
    rep(i,n) {
        if (a[i] == 0) now=0;
        else if(i!=0&&s[i-1]=='<') {
            now++;
            a[i] = now;
        }
    }
    now = 0;
    for(int i=n-1;i>=0;i--) {
        if (a[i] == 0) now = 0;
        else if (i!=n-1&&s[i]=='>') {
            now++;
            chmax(a[i], now);
        }
    }
    if (s[0] == '>') a[0] = a[1]+1;
    if (s[n-1] == '<') a[n-1] = a[n-2]+1;
    ll res = 0;
    rep(i,n) {res += a[i];}
    cout << res << endl;
    return 0;

}


Measured memory_bytes: 4764
#include <iostream>
#include <vector>
#include <queue>
#include <deque>

using namespace std;

string S;
int Q;

int main() {
    cin >> S >> Q;
    deque<char> ans;
    for (int i = 0; i < S.length(); i++) {
        ans.push_back(S[i]);
    }
    int T, F;
    char c;
    bool reversed = false;
    for (int i = 0; i < Q; i++) {
        cin >> T;
        if (T == 1) {
            reversed = !reversed;
            continue;
        }
        cin >> F >> c;
        (F == 1) != reversed ? ans.push_front(c) : ans.push_back(c);
    }
    if (reversed) {
        while (!ans.empty()) {
            cout << ans.back();
            ans.pop_back();
        }
    } else {
        while (!ans.empty()) {
            cout << ans.front();
            ans.pop_front();
        }
    }
}


Measured memory_bytes: 896
//https://atcoder.jp/contests/aising2019/tasks/aising2019_d
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int N,Q;
LL A[112345];
LL X[112345];

LL AS[112345];
LL ASS[112345][2];
bool check(LL x,int l,int r){
    if(l<0)return false;
    return max(abs(x-A[l]),abs(x-A[r-1]))<abs(x-A[r]);
}
int main(){
    cin>>N>>Q;
    for(int i:range(N)){
        cin>>A[i];
        AS[i+1]=AS[i]+A[i];
        ASS[i+1][0]+=ASS[i][0];
        ASS[i+1][1]+=ASS[i][1];
        ASS[i+1][i%2]+=A[i];
    }
    for(int i:range(Q))cin>>X[i];
    for(int i:range(N))A[i]=A[i]*3+1;
    for(int i:range(Q))X[i]=X[i]*3;
    for(int i:range(Q)){
        int lb=0,ub=(N+1)/2+1;
        while(ub-lb>1){
            const int mid = (lb+ub)/2;
            const int r=N-mid;
            const int l=N-mid-mid;
            if(check(X[i],l,r)||check(X[i],l+1,r))lb=mid;
            else ub=mid;
        }
        //cout<<lb<<" ";
        {
            int r=N-lb;
            int l=max(N-lb-lb,0);
            LL first = AS[N]-AS[r];
            LL second = ASS[l][1-N%2];
            cout<<first+second<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5888
using System;

namespace AtCoder
{
    public class Program
    {
        public static void Main()
        {
            long i,j=0;
            long ans;
            string line = Console.ReadLine();
            string []input = line.Split(' ');
            ans = long.Parse(input[0]);
            long max;
            for(i=0;;i++){
                long diff;
                diff = expo5(i+1)-expo5(i);
                if(diff>ans) {
                    max=i;
                    break;
                }
            }
            long []ex = new long[max*2+1];
            for(i=-max;i<=max;i++){
                ex[i+max] = expo5(i);
            }
            
            bool end_flag =false;
            for(i=0;i<=max*2;i++)
            {
                for(j=0;j<=max*2;j++)
                {
                    if(ex[i]-ex[j] == ans) {end_flag=true;break;}
                }
                if(end_flag) break;
            }
            Console.WriteLine((i-max).ToString() + " " + (j-max).ToString());
        }

        public static long expo5(long a){
            return a*a*a*a*a;
        }
    }
}

Measured memory_bytes: 27244
import           Control.Monad

main :: IO ()
main = do
    [n, m] <- fmap (map read . words) getLine :: IO [Int]
    ass    <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
    print $ solve n m ass

solve :: Int -> Int -> [[Int]] -> Int
solve n m ass = length $ filter (judge n ass) [1 .. m]

judge :: Int -> [[Int]] -> Int -> Bool
judge n ass k = n == length (filter (\v -> k `elem` (tail v)) ass)


Measured memory_bytes: 1020
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string text;
    int cmd_cnt = 0;
    string cmd_str;
    int idxStart = 0;
    int idxEnd = 0;
    string replaceStr;
    
    cin >> text;
    cin >> cmd_cnt;
    for (int i = 0; i < cmd_cnt; i++)
    {
        cin >> cmd_str;
        if (cmd_str == "replace")
        {
            cin >> idxStart >> idxEnd >> replaceStr;
            for (int j = idxStart; j <= idxEnd; j++)
            {
                text[j] = replaceStr[j - idxStart];
            }
        }
        else if (cmd_str == "reverse")
        {
            cin >> idxStart >> idxEnd;
            string tmpStr;
            for (int j = idxStart, k = 0; j <= idxEnd; j++, k++)
            {
                tmpStr[k] = text[j];
            }
            
            for (int m = idxStart, n = idxEnd - idxStart; m <= idxEnd; m++, n--)
            {
                text[m] = tmpStr[n];
            }
        }
        else if (cmd_str == "print")
        {
            cin >> idxStart >> idxEnd;
            string outStr = text.substr(idxStart, idxEnd - idxStart + 1);
            cout << outStr << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3172
from fractions import *
k = int(input())
ans = 0

gcd_list = [[0] * k for i in range(k)]
for i in range(k):
    gcd_list[0][i] = 1
for b in range(1, k + 1):
    for c in range(1, k + 1):
        if not gcd_list[b - 1][c - 1]:
            gcd_list[b - 1][c - 1] = gcd(b, c)
            
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            ans += gcd_list[a - 1][gcd_list[b - 1][c - 1] - 1]
print(ans)

Measured memory_bytes: 80828
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>
using namespace std;

int dp[3000][3000];

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

    
    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < t.size(); j++){
            if(i == 0){
                if(t.substr(0, j + 1).find(s[0]) != string::npos){
                    dp[i][j] = 1;
                }
            } else if(j == 0){
                if(s.substr(0, i + 1).find(t[0]) != string::npos){
                    dp[i][j] = 1;
                }
            } else{
                dp[i][j] = 0;
            }
        }
    }

    for(int i = 1; i < s.size(); i++){
        for(int j = 1; j < t.size(); j++){
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if(s[i] == t[j]){
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }

    //cout << dp[s.size() - 1][t.size() - 1] << endl;
    string ans = "";
    if(dp[s.size() - 1][t.size() - 1] == 0){
        cout << "" << endl;
        return 0;
    }
    int cur_i = s.size() - 1;
    int cur_j = t.size() - 1;
    int prev_max;
    while(true){
        if(cur_i <= 0 || cur_j <= 0){
            break;
        }
        prev_max = max(dp[cur_i - 1][cur_j], dp[cur_i][cur_j - 1]);
        if(s[cur_i] == t[cur_j]){
            prev_max = max(prev_max, dp[cur_i - 1][cur_j - 1] + 1);
        }
        if(prev_max == dp[cur_i - 1][cur_j]){
            cur_i --;
        } else if(prev_max == dp[cur_i][cur_j - 1]){
            cur_j --;
        } else if(prev_max == dp[cur_i-1][cur_j - 1] +1){
            ans.push_back(s[cur_i]);
            cur_i --;
            cur_j --;
        }
    }
    
    if(dp[cur_i][cur_j] == 1){
        if(cur_i == 0){
            ans.push_back(s[0]);
        } else{
            ans.push_back(t[0]);
        }
    }
    
    /*for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < t.size(); j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;

}

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

# cnt = 1 # 1件目は必ず合致するので

# for i in range(1,len(P_list)) :
#     pi = P_list[i]
#     is_match = True
#     for j in range(i) : # Pi==Pjは必ず正なのでジャッジ不要
#         pj = P_list[j]
#         if (pi > pj) :
#             is_match = False
#             break
    
#     if (is_match) :
#         cnt += 1

cnt = 1 # 1件目は必ず合致するので
min_map = [P_list[0]]
min_value = P_list[0]
for i in range(1,len(P_list)) :
    min_value = min(min_value,P_list[i])
    min_map.append(min_value)

# print(min_map)
for i in range(1,len(P_list)) :
    if (min_map[i] >= P_list[i]) :
        cnt += 1



print(cnt)

Measured memory_bytes: 25768
N,M=map(int,input().split())
A=list(map(int,input().split()))
cumMods = {}
cummod = 0
cumMods[cummod] = 1
cList = [0]
for a in A:
    cummod += a
    cummod = cummod%M
    cList.append(cummod)
    if cummod in cumMods:
        cumMods[cummod] += 1
    else:
        cumMods[cummod] = 1
#print(cList)
import math
ans = 0
for key in cumMods:
    #print(key,cumMods[key])
    ans += (cumMods[key]*(cumMods[key]-1))//2
print(ans)


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

int main(){
    //入力
    int x,a,b;
    cin >> x >> a >> b;
    //出力
    if(abs(x-a)<abs(x-b)){
        cout << "A" << endl;
    }else{
        cout << "B" << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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

const ll mod=1e9+7;

const ll INF=1e10+100;

int main()
{
    ll x,y;
    cin >> x >> y;
    ll a[7]={1,3,5,7,8,10,12};
    ll b[4]={4,6,9,11};
    bool ok1=false,ok2=false,ok3=false,ok4=false;
    rep(i,7){
        if(a[i]==x) ok1=true;
        if(a[i]==y) ok2=true;
    }
    rep(i,4){
        if(b[i]==x) ok3=true;
        if(b[i]==y) ok4=true;
    }
    if((ok1 && ok2) || (ok3 && ok4)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
} 

Measured memory_bytes: 3632