akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(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+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 1e5+11;
int n,v[N];
struct line{int a,b,c;}s[N];
bool cmp(const line&x,const line&y){
	if(1ll*x.a*y.b!=1ll*x.b*y.a)return 1.0*x.a/x.b<1.0*y.a/y.b;
	return 1.0*x.c/x.b<1.0*y.c/y.b;
}
pair<double,int>f[N];
int qry(int p){int r=0;while(p)r+=v[p],p-=p&-p;return r;}
void mdy(int p){while(p<=n)v[p]++,p+=p&-p;}
double solve(){
	sort(s+1,s+n+1,cmp);
	double l=-2e8,r=2e8;
	rep(t,1,85){
		double mid=(l+r)/2;
		rep(i,1,n)f[i]=mp((s[i].c-mid*s[i].a)/s[i].b,i);
		sort(f+1,f+n+1);
		rep(i,1,n)v[i]=0;ll res=0;
		rep(i,1,n)res+=i-1-qry(f[i].se),mdy(f[i].se);
		if(res*2<n*(n-1ll)/2)l=mid;else r=mid;
	}
	return l;
}
int main() {
	read(n);
	rep(i,1,n)read(s[i].a),read(s[i].b),read(s[i].c);
	printf("%.11lf ",solve());
	rep(i,1,n)swap(s[i].a,s[i].b);
	printf("%.11lf\n",solve());
	return 0;
}


Measured memory_bytes: 4984
#include<iostream>
#include<string>
int main(){
  std::string weather;
  std::string ans;
  std::cin>>weather;
  std::string weather_list[3]={"Sunny","Cloudy","Rainy"};
  for(int i=0;i<=2;i++){
    if(weather==weather_list[i]){
      ans=weather_list[(i+1)%3];
    }
  }
    std::cout<<ans<<std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int[] count = new int[11];
			count[scanner.nextInt()]++;
			count[scanner.nextInt()]++;
			count[scanner.nextInt()]++;

			if (count[5] == 2 && count[7] == 1) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n,m;
    cin>>n>>m;
    vi a(n);
    int sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }

    int c=0;

    rep(i,n){
       if(a[i]*4*m>=sum)c++;
    }

    if(c>=m)cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}

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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
using ll = long long;
using P = pair<int,int>;

// code starts
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int i,j;
	rep(i,n) cin >> a[i];
	vector<int> nums(1000001,0);
	rep(i,n)
	{
		nums[a[i]]++;
	}
	bool pair_judge = true;
	for(i=2;i<=1000000;i++)
	{
		int times = 0;
		for(j=i;j<=1000000;j+=i)
		{
			if(nums[j] > 0) times++;
			if(nums[j] > 1) pair_judge = false;
		}
		if(times >= 2) pair_judge = false;
	}
	if(pair_judge) cout << "pairwise coprime" << endl;
	else
	{
		int base = a[0];
		rep(i,n-1)
		{
			base = gcd(base,a[i+1]);
		}
		if(base == 1) cout << "setwise coprime" << endl;
		else cout << "not coprime" << endl;
	}
	
	//set or par, or other -> O(N)
}


Measured memory_bytes: 11172
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

struct Point {
    int x, y;

    Point(int p, int q) : x(p), y(q) {}
};

int C[500];
int S[500];
int F[500];

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

    ll X, Y;
    cin >> X >> Y;

    int ans = 1;
    ll t = X;

    for (; (t *= 2) <= Y;) {
        ++ans;
    }

    out(ans);

    int aaa;
    cin >> aaa;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <iostream>
#include<algorithm>
#include<functional>
using namespace std;

int main() {
	int n, k;
	int len[55];
	cin >> n >> k;
	for (int i = 0; i < n; ++i) cin >> len[i];

	sort(len, len + n, greater<int>());
	int sum = 0;
	for (int i = 0; i < k; i++)  sum += len[i];
	cout << sum << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int N=in.nextInt();
			if(N==0)
				return;

			int a[][]=new int[401][401];
			int maxh=1;
			int maxw=1;
			a[200][200]=1;
			for(int i=2;i<=N;i++)
			{
				int n=in.nextInt();
				int d=in.nextInt();

				for(int h=0;h<=400;h++)
					for(int w=0;w<=400;w++)
					{
						if(a[h][w]==n+1)
						{
							if(d==0)
								a[h][w-1]=i;
							if(d==1)
								a[h-1][w]=i;
							if(d==2)
								a[h][w+1]=i;
							if(d==3)
								a[h+1][w]=i;
						}
					}
			}
			for(int i=0;i<=400;i++)
			{
				int cnt=0;
				for(int j=0;j<=400;j++)
				{
					if(a[i][j]!=0)
					{
						cnt++;
						i++;
						j=-1;
						continue;
					}
				}
				maxh=Math.max(maxh, cnt);
				cnt=0;
			}
			for(int i=0;i<=400;i++)
			{
				int cnt=0;
				for(int j=0;j<=400;j++)
				{
					if(a[j][i]!=0)
					{
						cnt++;
						i++;
						j=-1;
						continue;
					}
				}
				maxw=Math.max(maxw, cnt);
				cnt=0;
			}
			System.out.println(maxw+" "+maxh);
		}
	}
}

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

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

    int ans = 0;

    for (size_t i = 0; i < a + 1; i++)
    {
        int cur = 500 * i;
        if (cur > x)
        {
            continue;
        }

        for (size_t j = 0; j < b + 1; j++)
        {
            int add = 100 * j;
            int cur2 = cur + add;
            for (size_t k = 0; k < c + 1; k++)
            {
                int add2 = 50 * k;
                if (cur2 + add2 == x)
                {
                    ans += 1;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <numeric>

using namespace std;


typedef long long ll;
const int maxn = (int) 1e5 + 1;
const int inf = (int)1e9+7;


int a[maxn], b[111], u[1111], p[1111];

int cnt[maxn];

string s, t;

int ans = 0, sum1, sum2, sum3;

ll n, k;

int dp[maxn];

vector < ll > g[maxn], v;

ll now = 0;

ll m;

int start, finish;

int go[1111][1111];


deque<int> cycle;
bool dfs(int v, int cell){
    u[v] = 1;
    for(int i : g[v]){
        if(!u[i]){
            p[i] = v;

            if(dfs(i, cell)) return true;
        }
        else if(u[i] == 1){
            start = i;
            finish = v;
            return true;
        }
    }
    u[v] = 2;
    return false;
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int x, y;
        cin >> x >> y;
        go[x][y] = 1;
        g[x].push_back(y);
    }
    for(int i = 1; i <= n; i++){
        fill(u + 1, u + 1 + n, 0);
        if(dfs(i, 0) == 0){
            continue;
        }
        for (int v=finish; v!=start; v=p[v])
            cycle.push_back (v);

        cycle.push_back (start);
        reverse(cycle.begin(), cycle.end());
        break;
    }
    int sz = cycle.size();
    while(sz--){
        vector < int > res;
        for(int j = 0; j < cycle.size();){
            res.push_back(cycle[j]);
            if(j == cycle.size() - 1)
                break;
            int edge = 0;
            for(int ij = j; ij < cycle.size(); ij++){
                if(go[cycle[j]][cycle[ij]] == 1){
                    //cout << cycle[j] << " " << cycle[ij] << endl;
                    edge = ij;
                }
            }
            j = edge;
        }

        int aw = 1;
        for(int j : res){
            int won = 0;
            for(int ij : res){
                if(go[j][ij] == 1){
                    won++;
                }
            }
            if(won >= 2){
                aw = 0;
                break;
            }
        }
        if(aw){
            cout << res.size() << endl;
            for(int j : res){
                cout << j << endl;
            }
            return 0;
        }

        int need = cycle.back();
        cycle.pop_back();
        cycle.push_front(need);
    }
    cout << -1;
    return 0;
}


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

typedef long long ll;

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll x[n];
  for(ll i=0;i<n;i++) cin >> x[i];
  ll ans=0;
  for(ll i=0;i<n-1;i++){
    ll p=min(a*(x[i+1]-x[i]),b);
    ans+=p;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001

using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
const int INF=1e9;
const ll LINF=1e18;
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(){
    string s;
    cin>>s;
    int n=s.size();
    int g=0,p=0;
    int ans=0;
    rep(i,n){
        if(s[i]=='p'){
            if(g>p)p++;
            else {
                ans--;
                g++;
            }
        }
        else{
            if(g>p){
                p++;
                ans++;
            }
            else g++;
        } 
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
int main()
{
	int i,j,k,n,m=0,x,y=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&x);
		y=max(y,x);
		m+=x;
	}
	m-=y/2;
	printf("%d",m);
	return 0;
}


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

#define INF INT_MAX

typedef long long ll;

using namespace std;

int main(void){
	ll L,R;
	cin >> L >> R;

	int ans = INF;
	for(ll i = 0;i < 2019;i++){
		for(ll j = 0;j < 2019 && (L+i) < (R-j);j++){
			int m = (((L+i)%2019)*((R-j)%2019))%2019;
			if(ans > m)ans = m;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    string s;
    cin>>s;
    int i, n = s.size();
    int out[n+5] = {};
    FOR0(i, n)
    {
        int j = i;
        int posr, posl;
        while(j < n && s[j] == 'R')
        {
            posr = j;
            j++;
        }
        posl = j;
        while(j < n && s[j] == 'L') 
        {
            j++;
        }
        //cout<<posl<<" "<<posr<<endl;
        int k;
        FORD(k, posr, i)
        {
            if((posr - k)%2 == 0)
                out[posr]++;
            else out[posl]++;
        }
        FOR(k, posl, j)
        {
            if((k - posl)%2==0)
                out[posl]++;
            else out[posr]++;
        }
        i = j-1;
    }
    FOR0(i, n) cout<<out[i]<<" ";
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 1104
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
  a, b = map(int, input().split())
  uf.union(a-1,b-1)
  
print(uf.group_count() - 1)



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

 int main() {
   int N, K, R, S, P, ans = 0;
   string T, A;
   cin >> N >> K >> R >> S >> P >> T;

   rep(i, N) {
     if (i < K) {
       if (T.at(i) == 'r') {
         A.push_back('P');
         ans += P;
       }
       else if (T.at(i) == 's') {
         A.push_back('R');
         ans += R;
       }
       else if (T.at(i) == 'p') {
         A.push_back('S');
         ans += S;
       }
     }
     else {
       if (T.at(i) == 'r') {
         if (A.at(i - K) != 'P') {
           A.push_back('P');
           ans += P;
         }
         else A.push_back('*');
       }
       if (T.at(i) == 'p') {
         if (A.at(i - K) != 'S') {
           A.push_back('S');
           ans += S;
         }
         else A.push_back('*');
       }
       if (T.at(i) == 's') {
         if (A.at(i - K) != 'R') {
           A.push_back('R');
           ans += R;
         }
         else A.push_back('*');
       }
     }
   }
   cout << ans << endl;
 }


Measured memory_bytes: 640
#include<iostream>
using namespace std;
void ad(int a,int b,int c){cout<<"+ "<<a<<" "<<b<<" "<<c<<endl;}
void lt(int a,int b,int c){cout<<"< "<<a<<" "<<b<<" "<<c<<endl;}
main()
{
	cout<<3870<<endl;
	ad(0,1,3);
	lt(2,3,3);
	for(int x=0;x<2;x++)
	{
		ad(3,x,x);
		int v=x+4;
		for(int i=0;i<30;i++)
		{
			if(i>0)ad(v,v,v);
			ad(v,3,6);
			for(int j=i;j<29;j++)ad(6,6,6);
			int u=i+7+x*30;
			lt(6,x,u);
			ad(v,u,v);
		}
	}
	for(int t=0;t<59;t++)
	{
		if(t>0)ad(2,2,2);
		for(int i=0;i<30;i++)
		{
			int j=t-i;
			if(j<0||j>=30)continue;
			ad(i+7,j+37,4);
			lt(3,4,4);
			ad(2,4,2);
		}
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define UNIQUE(v)       sort(all(v));v.erase(unique(all(v)),v.end());
#define has_str(s, c)	((s).find(c) != string::npos)
typedef long long ll;
int main() {
#ifdef online_judge
    freopen("input.txt", "wt", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    ll sum = 0;
    for(int i = 0; i < SZ(s); ++i) {
        int cur = int(s[i] - '0');
        sum += cur;
    }
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3728
// Problem A

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <limits.h>

#define MAXN 1000
#define pb push_back
#define mp make_pair

using namespace std;

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

int T;
ll N, A, B, C, D;
map<ll,ll> done;

ll solve(ll n, bool plus1allowed, bool minus1allowed) {
  //~ cout << "Solving n = " << n << endl;
  if (n <= 0) return 0;
  if (done.find(n) != done.end()) {
    //~ cout << "I already know that Solve(" << n << ") = " << done[n] << endl;
    return done[n];
  }
  
  ll res = D*n;
  if (res <= (ll)0) res = LLONG_MAX;
  ll x;
  
  if (n % (ll)2 == (ll)0) {
    x = solve(n/(ll)2, true, true);
    if (x + A >= (ll)0) res = min(res, A + x);
  }
  else {
    if (plus1allowed) {
      x = solve((n+(ll)1)/(ll)2, true, false);
      if (A + D + x >= (ll) 0) res = min(res, A + D + x);
    }
    if (minus1allowed) {
      x = solve((n-(ll)1)/(ll)2, false, true);
      if (x + A + D >= (ll) 0) res = min(res, A + D + x);
    }
  }
  
  if (n % (ll)3 == (ll)0) {
    x = solve(n/(ll)3, true, true);
    if (x + B >= (ll)0) res = min(res, B + x);
  }
  else if (n % (ll)3 == (ll)1) {
    x = solve((n-(ll)1)/(ll)3, true, true);
    if (x + B + D >= (ll)0) res = min(res, B + D + x);
  }
  else {
    x = solve((n+(ll)1)/(ll)3, true, true);
    if (x + B + D >= (ll)0) res = min(res, B + D + x);
  }
  
  if (n % (ll)5 == (ll)0) {
    x = solve(n/(ll)5, true, true);
    if (x + C >= (ll)0) res = min(res, C + x);
  }
  else if (n % (ll)5 == (ll)1) {
    x = solve((n-(ll)1)/(ll)5, true, true);
    if (x + C + D >= (ll)0) res = min(res, C + D + x);
  }
  else if (n % (ll)5 == (ll)2) {
    x = solve((n-(ll)2)/(ll)5, true, true);
    if (x + C + D + D>= (ll)0) res = min(res, C + (ll)2*D + x);
  }
  else if (n % (ll)5 == (ll)3) {
    x = solve((n+(ll)2)/(ll)5, true, true);
    if (x + C + D + D>= (ll)0) res = min(res, C + (ll)2*D + x);
  }
  else {
    x = solve((n+(ll)1)/(ll)5, true, true);
    if (x + C + D >= (ll)0) res = min(res, C + D + x);
  }
  
  done[n] = res;
  //~ cout << "Solve(" << n << ") = " << res << endl;
  return res;
}

int main() {
  cin >> T;
  for (int t=0; t<T; t++) {
    cin >> N >> A >> B >> C >> D;
    done.clear();
    done[1] = D;
    cout << solve(N, true, true) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4408
MOD = 1000000007

def modinv(a, m):
    b, u, v = m, 1, 0
    while b != 0:
        t = a // b
        a -= t * b
        a, b = b, a

        u -= t * v
        u, v = v, u
    u %= m
    if u < 0:
        u += m
    return u

a, b = 12345678900000, 100000
a %= MOD
#print(a * modinv(b, MOD) % MOD)

def solve(x, y):
    if (x + y) % 3 != 0:
        return 0
    m = (x + y) // 3
    #print(m, (x, y))
    if x < m:
        return 0
    n = m 
    k = x - m
    return C2(n, k)

def C2(n, k):
    d = 1
    for i in range(n-k+1, n+1):
        d *= i 
        d %= MOD
    r = 1
    for i in range(1, k+1):
        r *= i 
        r %= MOD
    return (d * modinv(r, MOD)) % MOD



def test(x, y):
    print((x,y), solve(x,y))
    assert solve(x,y) == solve(y,x)

x, y = map(int, input().split())
if x > y:
    x, y = y, x
answer = solve(x, y) % MOD
print(answer)


Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;
using ld = long double;

int main(void)
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    int hm_to_min = h*60 + m;
    int min_day = 12*60;
    ld h_angle = ((ld)hm_to_min / min_day);
    ld m_angle = ((ld) m / 60);

    ld angleBetween = 2 * M_PI * abs(h_angle - m_angle);
    
    ld l2 = (ld)(a*a + b*b) - (ld) (2 * a * b * cosl(angleBetween));
    cout << fixed<< setprecision(15) << sqrtl(l2) << endl;
}

Measured memory_bytes: 4164
#include <iostream>

using namespace std;

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

	if (abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7

class Array
  def modsum(m=10 ** 9 + 7); reduce(0){|s,t| s+=t; s %= m if s >= m; s } end
end

n, k = gets.split.map(&:to_i)

a = [1] * (k+1)
b = Array.new(k+1){|i| i }

(k/2).downto(1) do |i|
  cnt = ( k/i ).pow( n, mod )
  (i*2).step(k, i){|j| cnt = ( cnt - a[j] ) % mod }
  a[i] = cnt
  b[i] = i * cnt % mod
end

puts b.modsum

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

int main() {
    int H,W;
    cin >> H >> W;
    for(int i = 0; i < H; i++) {
        string S;
        for(int i = 0; i < W; i++) {
            char C;
            cin >> C;
            S += C;
            cout << C;
        }
        cout << endl;
        cout << S << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(i=a;i<=n;i++)
#define ll long long
#define test(a) cout << "*" << a << endl
int main(){
  ll i,j;
  ll N,X;
  ll x[100001];
  ll dl[100001];
  ll dlMin = 1000000000;
  ll modMax;
  bool existBreak = false;
  
  cin >> N >> X;
  rep(i,1,N){  
    cin >> x[i];
    dl[i] = abs(x[i]-X);
    dlMin = min(dlMin,dl[i]);    
  }
  for(i=dlMin;0<i;i--){
  //rep(i,1,dlMin){
    if(existBreak==true)
      break;
    rep(j,1,N){
      if(dl[j]%i!=0)
        break;
      else{
        if(j==N){
          modMax = i;
          existBreak = true;
          break;
        }
      }
    }
  }    
  cout << modMax << endl;
}

Measured memory_bytes: 1792
import sys

input = sys.stdin.readline

N, W = map(int, input().split())

dp = [0] * (W + 1)
def knapsack(n, w):
    for _ in range(N):
        w, v = map(int, input().split())
        for wk in range(W, w-1, -1):
            tv = dp[wk - w] + v
            if tv > dp[wk]:
                dp[wk] = tv
    return dp[-1]

print(knapsack(N, W))

Measured memory_bytes: 9716
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
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; }







void solve() {
    string s;
    cin>>s;
    ll ans=0,cnt=0;
    rep(i,3){
        if(s[i]=='R'){
            cnt++;
            chmax(ans,cnt);
        }
        else{
            chmax(ans,cnt);
            cnt=0;
        }
    }
    cout<<ans<<endl;


}






signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    ll t=1;
    rep(i,t){
        solve(); 
    }


    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

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

  int32_t N, M, X;
  cin >> N >> M >> X;

  vector<vector<int>> books(N, vector<int>(M,0));
  vector<int> book_cost(N,0);
  for (int i = 0; i < N; i++) {
    cin >> book_cost[i];
    for (int j = 0; j < M; j++) {
      cin >> books[i][j];
    }
  }

  int64_t min_cost = MOD;
  for (int i = 0; i < (1 << 12); i++) {
    int cur = i;
    int64_t cur_cost = 0;
    vector<int> cur_score(M,0);
    for (int j = 0; j < N; j++) {
      if ((cur & 1) == 1) {
        cur_cost += book_cost[j];
        for (int k = 0; k < M; k++) {
          cur_score[k] += books[j][k];
        }
      }
      cur = cur >> 1;
    }
    //check condition
    bool cond = true;
    for (int j = 0; j < M; j++) {
      if (cur_score[j] < X) {
        cond = false;
        break;
      }
    }
    //compare min
    if (cond == true) {
      min_cost = min(min_cost, cur_cost);
    }
  }
  if (min_cost == MOD)
    cout << -1 << endl;
  else
    cout << min_cost << endl;
  return 0;
}



Measured memory_bytes: 3536
N = int(input())
lists = list(map(int, input().split()))

count = 0
ans = 0
for i in range(N):
    if i == 0:
        ans = lists[i]
        count += 1
    else:
        if ans >= lists[i]:
            count += 1
            ans = min(ans, lists[i])
        else:
            ans = min(ans, lists[i])


    # lists_slice = lists[:i+1]
    # lists_min = min(lists_slice)
    # if lists_min >= lists[i]:
    #     count += 1
print(count)

Measured memory_bytes: 24744
//test

#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int main(){
int N; cin >> N;
long long a[100010][3] = {};
long long dp[100010][3] = {};
for (int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
        cin >> a[i][j];
    }
}

//ループでdpテーブルを更新する。
for (int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
            if(j == k){
            continue;
            } else {
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }
}

long long ans = 0;
for(int i = 0; i < 3; i++){
    chmax(ans, dp[N][i]);
}

cout << ans << endl;
return 0;
}


Measured memory_bytes: 4992
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans = 0;
    ll w,h;
    cin >> w >> h;
    vll p(w),q(h);
    REP(i,w) cin >> p[i];
    REP(i,h) cin >> q[i];
    sort(ALL(p));
    sort(ALL(q));
    REP(i,w) ans += p[i]*(h+1);
    REP(i,h) ans += q[i]*(w+1);
    REP(i,w){
        ll ok = h;
        ll ng = -1;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(q[mid]>=p[i]){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        ans -= p[i] * (ng+1);
    }
    REP(i,h){
        ll ok = w;
        ll ng = -1;
        while(abs(ok-ng)>1){
            ll mid = (ok+ng)/2;
            if(p[mid]>q[i]){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        ans -= q[i] * (ng+1);
    }
    cout << ans << endl;

    return 0;
}

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

int main(int argc, char **argv)
{
  string line;
  const string astr("apple"), pstr("peach");
  size_t a, p;
  while (getline(cin, line)) {
    a = line.find(astr);
    p = line.find(pstr);
    while (a != string::npos || p != string::npos) {
      if (p == string::npos || a < p) {
        line.replace(a, 5, pstr);
        a = line.find(astr, a+5);
      } else {
        line.replace(p, 5, astr);
        p = line.find(pstr, p+5);
      }
    }
    cout << line << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,int> P;

priority_queue<P, vector<P> ,greater<P> > que;

int main(void){
  long long w,h;
  cin >> w >> h;
  ++w;++h;
  for(int i = 0;i < w-1;++i){
    long long pp;
    cin >> pp;
    que.push(P(pp,0));
  }
  for(int i = 0;i < h-1;++i){
    long long qq;
    cin >> qq;
    que.push(P(qq,1));
  }
  long long tot = 0;
  long long  ww = 0;
  long long  hh = 0;
  long long res = 0;
  while(tot < w*h-1){
    P now = que.top();
    que.pop();
    //cout << now.first << " " << now.second << endl;
    if(now.second == 0){
      long long rem;
      ++ww;
      tot += h - hh;
      res += now.first * (h - hh);
    }else{
      long long rem;
      ++hh;
      tot += w - ww;
      res += now.first * (w - ww);
    }
    //cout << res << endl;
  }
  cout << res << endl;
}


Measured memory_bytes: 4464
/* C++14(GCC5.4.1) */
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(void){
    int n; cin >> n;
    vector<pair<int, int>> st(n);
    for(int i=0; i<n; i++){
        st[i].second = i;
        cin >> st[i].first;
    }
    
    sort(st.begin(),st.end());

    for(int i=0; i<n; i++){
        // 0スタートなので注意.
        cout << st[i].second+1 << " ";
    }

    return 0;
}

Measured memory_bytes: 1536
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[] a = in.ii();
        String ans;
        Arrays.sort(a);
        if(a[0] == a[1]){
            if(a[1] == a[2]){
                ans = "No";
            } else {
                ans = "Yes";
            }
        } else {
            if(a[1] == a[2]){
                ans = "Yes";
            } else {
                ans = "No";
            }
        }
        out.println(ans);   
    }

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

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

        String[] ss(){
            return s().split(" ");
        }

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

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,c;
int b[25],a[25][25];
int main()
{
    cin>>n>>m>>c;
    for(int i=1;i<=m;i++)
        cin>>b[i];
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
        cin>>a[i][j];
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        int tot=0;
        for(int j=1;j<=m;j++)
        {
            tot+=a[i][j]*b[j];
        }
        if(tot+c>0)
            sum++;
    }
    cout<<sum;
    return 0;
}

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

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

    std::vector<long> L{2, 1};

    for (int i = 2; i <= N; ++i) {
        L.push_back(L[i - 1] + L[i - 2]);
    }

    std::cout << L[N] << std::endl;
    return 0;
}


Measured memory_bytes: 256
def main(k, a, b):
    for i in range(a, b + 1):
        if i % k == 0:
            print("OK")
            return

    print("NG")


if __name__ == "__main__":
    k = int(input())
    a, b = map(int, input().split())

    main(k, a, b)


Measured memory_bytes: 9044
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 301


int main(){
	long long a[(N*N)];
	long long b[(N*N)];
	long long d[(N*N)];
	int n, m, k;
	long long x,y,z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d %d", &n, &m, &k);
	f(i, n){
		f(j, m){
			scanf("%d", &z);
			z--;
			a[z] = i;
			b[z] = j;
		}
	}

	f(i, (n*m)){
		if (i < k)d[i] = 0;
		else{
			x = a[i] - a[(i - k)];
			y = b[i] - b[(i - k)];
			if (x < 0)x = -x;
			if (y < 0)y = -y;
			d[i] = d[(i - k)] + x + y;
		}
	}
	scanf("%d", &k);
	f(i, k){
		scanf("%d %d", &n, &m);
		n--;
		m--;
		ans = d[m] - d[n];
		printf("%lld\n", ans);
	}

	return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define MAXN 206
#define pb push_back
#define sz size
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define int long long
int n;
int G[MAXN][MAXN];
int col[MAXN];
bool bfs(int s, int n) {  
    queue<int> q;  
    q.push(s);  
    col[s] = 1;  
    while(!q.empty()) {  
        int from = q.front();  
        q.pop();  
        for(int i = 1; i <= n; i++) if( from != i ) {  
            if(G[from][i] != 0x3f3f3f3f && col[i] == -1) {  
                q.push(i);  
                col[i] = !col[from];
            }  
            if(G[from][i] != 0x3f3f3f3f && col[from] == col[i])
                return false;  
        }  
    }  
    return true;       
}  
signed main() {
	cin >> n;
	memset( col , -1 , sizeof col );
	for( int i = 1 ; i <= n ; ++ i )
		for( int j = 1 ; j <= n ; ++ j ) 
			scanf("%1d",&G[i][j]) , G[i][j] = ( !G[i][j] && i != j ) ? 0x3f3f3f3f : G[i][j];
	int flg = 0;
	for( int i = 1 ; i <= n ; ++ i ) 
		if( ( col[i] == -1 ) && !bfs( i , n ) )
			{ flg = 1; break; }
	if( flg ) return puts("-1") , 0;
	
	for (int k = 1; k <= n; k++) 
	  	for (int i = 1; i <= n; i++) 
	    	for (int j = 1; j <= n; j++) 
	      		G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	int res = 0;
	for( int i = 1 ; i <= n ; ++ i )
		for( int j = 1 ; j <= n ; ++ j ) 
			res = max( res , G[i][j] );
	cout << res + 1 << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

char arr[1000000];

int main() {
    scanf("%s", arr);

    long long cb = 0, t = 0;
    for (char *p = arr; *p != '\0'; p++) {
        t += *p == 'W' ? cb : 0;
        cb += *p == 'B';
    }

    printf("%lld\n", t);
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i, JOI, IOI;
	char str[10001];
	
	while (scanf("%s", str) != EOF){
		JOI = 0;
		IOI = 0;
		
		for (i = 0; i < strlen(str) - 2; i++){
			if (strncmp(&str[i], "JOI", 3) == 0){
				JOI++;
			}
			else if (strncmp(&str[i], "IOI", 3) == 0){
				IOI++;
			}
		}
		
		printf("%d\n%d\n", JOI, IOI);
	}
	
	return (0);
}

Measured memory_bytes: 552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
const int nmax=1000010;
ll fac[nmax],finv[nmax],inv[nmax];
 
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
int main(){
  ll n;cin >> n;
  COMinit();
  vector<ll> x(n);
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  ll sum=0,cnt=fac[n-1];
  for(ll i=0;i<n-1;i++){
    ll t=x[i+1]-x[i];
    sum+=(t*cnt)%mod;
    sum%=mod;
    cnt+=fac[n-1]*inv[i+2];
    cnt%=mod;
  }
  cout << sum << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    ll ans = (ll)INF * INF;
    for (int i = 1; (ll)i * i <= N; ++i) {
        if (N % i) continue;
        ans = min(ans, i + N / i - 2);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, k = input_a
s = input_s

a = s.chars
# 0, 1の連続している個数を格納する配列(連続する個数を記録するとき、常に0,1は交互に現れる)
# 最初と最後に必ず1の個数が入るものとする(入力文字列Sがそうでない場合1の個数は0)
counts = []

before = "1"
cnt = 0
# 0, 1が切り替わる度にpush
a.each do |s|
  if s != before
    counts.push(cnt)
    cnt = 1
    before = s
    next
  end
  cnt += 1
end
# 最後の0, 1は切り替わりが行われないため個別にpush
counts.push(cnt)
# 最後が1でなかった場合にpush
if a.last == "0"
  counts.push(0)
end

# 最大K回反転可能であるということは、0のcountを最大K回1のcountに反転できるのと同義である
# countsの左端から右端まで、しゃくとり法で各区間の和を計算することで、最大値が求められる
# 1は反転する必要がないので、区間の長さは2Kとなる
# また、連続する1の個数が最大になるのは、両端が0ではなく1になるときであるため、区間は2ずつ進める
# でもしゃくとり法で計算するの混乱する。。。

# 累積和の計算
sums = Array.new(counts.size + 1)
sums[0] = 0
(counts.size).times do |i|
  sums[i + 1] = sums[i] + counts[i]
end

result = 0
left = 0
while left < sums.size do
  right = left + k * 2 + 1
  if right >= sums.size
	right = sums.size - 1
  end
  result = [result, sums[right] - sums[left]].max
  left += 2
end

p result

Measured memory_bytes: 11004
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i, s, n) for(int i=s; i<n; i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
  int D;
  cin >> D;
  string ans;
  if(D==25) ans = "Christmas";
  else if(D==24) ans = "Christmas Eve";
  else if(D==23) ans = "Christmas Eve Eve";
  else if(D==22) ans = "Christmas Eve Eve Eve";
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
l = list(map(int, input().split()))
el = []
sl = [0]*(n-k+1)
for i in l:
  el.append((1+i)/2)
sl[0] = sum(el[:k])
for i in range(n-k):
  sl[i+1] = sl[i]-el[i]+el[i+k]
print("{:.20}".format(max(sl)))

Measured memory_bytes: 24812
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int max=a+b;
      	if(max<a*b)max=a*b;
      if(max<a-b)max=a-b;
          
		// 出力
		System.out.println(max);
	}
	

}

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

int main(){
  int N,M,c = 0;
  cin >> N;
  string a[N];
  for(int i=0;i<N;i++)
    cin >> a[i];
  cin >> M;
  string b[M];
  for(int j=0;j<M;j++)
    cin >> b[j];
  for(int k=0;k<N;k++){
    int cnt = 0;
    for(int l=0;l<N;l++){
    	if(a[k] == a[l]){
        	++cnt;
        }
    }
    for(int m=0;m<M;m++){
    	if(a[k] == b[m]){
        	--cnt;
        }
    }
    c = max(c,cnt);
  }
  cout << c << endl;   
}	

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};
signed main() {
	int n;
	scnaf("%d", &n);
	vector<int> num(n);
	map<int, int> pos;
	REP(i,n){
		scanf("%d", &num[i]);
		pos[num[i]] = i;
	}

	vector<int> sorted(num);
	sort(ALL(sorted));
	int ans = 0;
	REP(i, n) {
		if (pos[sorted[i]] % 2 != i % 2) {
			ans++;
		}
	}

	printf("%d\n",ans/2);
	return 0;
}

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

typedef pair<int,bool> p;
typedef vector< vector<p> > table;

bool is_bingo(table& t)
{
    bool flag=false;
    rep(i,3)
    {
        int c=0;
        rep(j,3)
        {
            if(t[i][j].second)
            {
                flag=true;
                c++;
            }
            else
            {
                flag=false;
                break;
            }
            if(c==3)return true;
        }
    }
    rep(j,3)
    {
        int c=0;
        rep(i,3)
        {
            if(t[i][j].second)
            {
                flag=true;
                c++;
            }
            else 
            {
                flag=false;
                break;
            }
            if(c==3)return true;
        }
    }

    int d=0;
    rep(i,3)
    {
        if(t[i][i].second)
        {
            flag=true;
            d++;
        }
        else 
        {
            flag=false;
            break;
        }
        if(d==3)return true;
    }
    d=0;
    for (int i = 0; i < 3; i++)
    {
        if(t[0+i][2-i].second)
        {
            flag=true;
            d++;
        }
        else 
        {
            flag=false;
            break;
        }
        if(d==3)return true;
    }
    return false;
}

int main()
{
    table t(3,vector<p>(3));
    rep(i,3)
    {
        rep(j,3)
        {
            cin>>t[i][j].first;
            t[i][j].second=false;
        }
    }

    vector<int> num;
    int n;
    cin>>n;
    rep(i,n)
    {
        int tmp;
        cin>>tmp;
        num.push_back(tmp);
    }

    rep(k,n)
    {
        rep(i,3)
        {
            rep(j,3) if(t[i][j].first==num[k])t[i][j].second=true;
        }
    }

    bool flag=false;
    flag=is_bingo(t);

    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
/*input
8 10
1 2 0
2 3 0
3 4 0
1 5 0
2 6 0
3 7 0
4 8 0
5 6 1
6 7 1
7 8 1
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

struct edge{int a,b,c;};

int n;
int l;
vector<edge> e;

void prints(edge x){
	 cout << x.a+1 << " " << x.b+1 << " " << x.c << endl;
}

void FUCK(){
     REP(i,19){
     	e.pb({i,i+1,0});
     }
}

void THIS(){
	 int j = log2(l);
	 REP(i,j){
	 	e.pb({i,i+1,1<<i});
	 }
}

void SHIT(){
	 int j= log2(l);
	 int suf = 1<<j;
	 REPD(i,j){
	 	 if(l&(1<<i)){
	 	 	//cout << i << endl;
	 	 	e.pb({i,j,suf});
	 	 	suf += 1<<i;
	 	 }
	 }
}

void solve(){
	cin >> l;
    FUCK();THIS();SHIT();
    cout << 20 << " " << e.size() << endl;
    REP(i,e.size())prints(e[i]);
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Measured memory_bytes: 384